MCPcopy
hub / github.com/webpack/webpack / handler

Method handler

lib/CompatibilityPlugin.js:123–238  ·  view source on GitHub ↗
(parser)

Source from the content-addressed store, hash-verified

121 * @returns {void}
122 */
123 const handler = (parser) => {
124 // Handle nested requires
125 parser.hooks.preStatement.tap(PLUGIN_NAME, (statement) => {
126 if (
127 statement.type === "FunctionDeclaration" &&
128 statement.id &&
129 statement.id.name === RuntimeGlobals.require
130 ) {
131 const newName = `__nested_webpack_require_${
132 /** @type {Range} */
133 (statement.range)[0]
134 }__`;
135 parser.tagVariable(
136 statement.id.name,
137 nestedWebpackIdentifierTag,
138 {
139 name: newName,
140 declaration: {
141 updated: false,
142 loc: /** @type {DependencyLocation} */ (statement.id.loc),
143 range: /** @type {Range} */ (statement.id.range)
144 }
145 }
146 );
147 return true;
148 }
149 });
150 parser.hooks.pattern
151 .for(RuntimeGlobals.require)
152 .tap(PLUGIN_NAME, (pattern) => {
153 const newName = `__nested_webpack_require_${
154 /** @type {Range} */ (pattern.range)[0]
155 }__`;
156 parser.tagVariable(pattern.name, nestedWebpackIdentifierTag, {
157 name: newName,
158 declaration: {
159 updated: false,
160 loc: /** @type {DependencyLocation} */ (pattern.loc),
161 range: /** @type {Range} */ (pattern.range)
162 }
163 });
164 if (parser.scope.topLevelScope !== true) {
165 return true;
166 }
167 });
168 parser.hooks.pattern
169 .for(RuntimeGlobals.exports)
170 .tap(PLUGIN_NAME, (pattern) => {
171 const newName = "__nested_webpack_exports__";
172 parser.tagVariable(pattern.name, nestedWebpackIdentifierTag, {
173 name: newName,
174 declaration: {
175 updated: false,
176 loc: /** @type {DependencyLocation} */ (pattern.loc),
177 range: /** @type {Range} */ (pattern.range)
178 }
179 });
180 return true;

Callers

nothing calls this directly

Calls 6

tapMethod · 0.80
tagVariableMethod · 0.80
getTagDataMethod · 0.80
sliceMethod · 0.80
toStringMethod · 0.45

Tested by

no test coverage detected