MCPcopy
hub / github.com/webpack/webpack / use

Method use

lib/util/SourceProcessor.js:70–89  ·  view source on GitHub ↗

* Register a Babel-style visitor map; calls accumulate per node type. * A bucket is a function (= `{ enter }`) or `{ enter?, exit? }`. * @param {VisitorMap<TNode>} map visitor map keyed by node type * @returns {SourceProcessor<TNode, TProcessOptions>} `this`, for chaining

(map)

Source from the content-addressed store, hash-verified

68 * @returns {SourceProcessor<TNode, TProcessOptions>} `this`, for chaining
69 */
70 use(map) {
71 // `map`'s keys are node-type enum members; `Object.keys` stringifies them,
72 // so index the compiled array by the number to match the numeric `node.type`.
73 for (const type of Object.keys(map)) {
74 const key = Number(type);
75 const v = map[key];
76 let bucket = this._visitors[key];
77 if (!bucket) {
78 bucket = { enter: [], exit: [] };
79 this._visitors[key] = bucket;
80 }
81 if (typeof v === "function") {
82 bucket.enter.push(v);
83 } else {
84 if (v.enter) bucket.enter.push(v.enter);
85 if (v.exit) bucket.exit.push(v.exit);
86 }
87 }
88 return this;
89 }
90
91 /**
92 * Run the grammar over `input`, firing visitors in source order. No

Callers 6

parseMethod · 0.80
parseMethod · 0.80
countFunction · 0.80
webpack.config.mjsFile · 0.80

Calls 2

keysMethod · 0.65
pushMethod · 0.45

Tested by

no test coverage detected