Skip to content

Commit 6e9739c

Browse files
committed
refactor: inner graph per compilation
1 parent 235a160 commit 6e9739c

8 files changed

Lines changed: 483 additions & 394 deletions

lib/JavascriptMetaInfoPlugin.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ class JavascriptMetaInfoPlugin {
2828
compiler.hooks.compilation.tap(
2929
PLUGIN_NAME,
3030
(compilation, { normalModuleFactory }) => {
31+
const innerGraph = InnerGraph.getInnerGraph(compilation);
3132
/**
3233
* Handles the hook callback for this code path.
3334
* @param {JavascriptParser} parser the parser
@@ -39,11 +40,11 @@ class JavascriptMetaInfoPlugin {
3940
/** @type {BuildInfo} */
4041
(parser.state.module.buildInfo);
4142
buildInfo.moduleConcatenationBailout = "eval()";
42-
const currentSymbol = InnerGraph.getTopLevelSymbol(parser.state);
43+
const currentSymbol = innerGraph.getTopLevelSymbol(parser.state);
4344
if (currentSymbol) {
44-
InnerGraph.addUsage(parser.state, null, currentSymbol);
45+
innerGraph.addUsage(parser.state, null, currentSymbol);
4546
} else {
46-
InnerGraph.bailout(parser.state);
47+
innerGraph.bailout(parser.state);
4748
}
4849
});
4950
parser.hooks.finish.tap(PLUGIN_NAME, () => {

lib/dependencies/HarmonyExportDependencyParserPlugin.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ module.exports = class HarmonyExportDependencyParserPlugin {
155155
);
156156
dep.loc.index = -1;
157157
parser.state.current.addDependency(dep);
158-
InnerGraph.addVariableUsage(
158+
InnerGraph.getInnerGraph(parser.state.compilation).addVariableUsage(
159159
parser,
160160
node.type.endsWith("Declaration") &&
161161
/** @type {FunctionDeclaration | ClassDeclaration} */ (node).id
@@ -186,7 +186,11 @@ module.exports = class HarmonyExportDependencyParserPlugin {
186186
const harmonyNamedExports = (parser.state.harmonyNamedExports =
187187
parser.state.harmonyNamedExports || new Set());
188188
harmonyNamedExports.add(name);
189-
InnerGraph.addVariableUsage(parser, id, name);
189+
InnerGraph.getInnerGraph(parser.state.compilation).addVariableUsage(
190+
parser,
191+
id,
192+
name
193+
);
190194
const dep = settings
191195
? new HarmonyExportImportedSpecifierDependency(
192196
settings.source,

lib/dependencies/HarmonyImportDependencyParserPlugin.js

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,10 @@ module.exports = class HarmonyImportDependencyParserPlugin {
263263
);
264264
dep.loc = /** @type {DependencyLocation} */ (expression.loc);
265265
parser.state.module.addDependency(dep);
266-
InnerGraph.onUsage(parser.state, (e) => (dep.usedByExports = e));
266+
InnerGraph.getInnerGraph(parser.state.compilation).onUsage(
267+
parser.state,
268+
(e) => (dep.usedByExports = e)
269+
);
267270
return true;
268271
});
269272
parser.hooks.collectDestructuringAssignmentProperties.tap(
@@ -307,7 +310,10 @@ module.exports = class HarmonyImportDependencyParserPlugin {
307310
dep.loc = /** @type {DependencyLocation} */ (expr.loc);
308311
dep.call = parser.scope.inTaggedTemplateTag;
309312
parser.state.module.addDependency(dep);
310-
InnerGraph.onUsage(parser.state, (e) => (dep.usedByExports = e));
313+
InnerGraph.getInnerGraph(parser.state.compilation).onUsage(
314+
parser.state,
315+
(e) => (dep.usedByExports = e)
316+
);
311317
return true;
312318
});
313319
parser.hooks.expressionMemberChain
@@ -355,7 +361,10 @@ module.exports = class HarmonyImportDependencyParserPlugin {
355361
);
356362
dep.loc = /** @type {DependencyLocation} */ (expr.loc);
357363
parser.state.module.addDependency(dep);
358-
InnerGraph.onUsage(parser.state, (e) => (dep.usedByExports = e));
364+
InnerGraph.getInnerGraph(parser.state.compilation).onUsage(
365+
parser.state,
366+
(e) => (dep.usedByExports = e)
367+
);
359368
return true;
360369
}
361370
);
@@ -409,7 +418,10 @@ module.exports = class HarmonyImportDependencyParserPlugin {
409418
dep.loc = /** @type {DependencyLocation} */ (expr.loc);
410419
parser.state.module.addDependency(dep);
411420
if (args) parser.walkExpressions(args);
412-
InnerGraph.onUsage(parser.state, (e) => (dep.usedByExports = e));
421+
InnerGraph.getInnerGraph(parser.state.compilation).onUsage(
422+
parser.state,
423+
(e) => (dep.usedByExports = e)
424+
);
413425
return true;
414426
}
415427
);

lib/dependencies/HarmonyImportSpecifierDependency.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -151,11 +151,7 @@ class HarmonyImportSpecifierDependency extends HarmonyImportDependency {
151151
* @returns {null | false | GetConditionFn} function to determine if the connection is active
152152
*/
153153
getCondition(moduleGraph) {
154-
return getDependencyUsedByExportsCondition(
155-
this,
156-
this.usedByExports,
157-
moduleGraph
158-
);
154+
return getDependencyUsedByExportsCondition(this, moduleGraph);
159155
}
160156

161157
/**

lib/dependencies/URLDependency.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,7 @@ class URLDependency extends ModuleDependency {
6060
* @returns {null | false | GetConditionFn} function to determine if the connection is active
6161
*/
6262
getCondition(moduleGraph) {
63-
return getDependencyUsedByExportsCondition(
64-
this,
65-
this.usedByExports,
66-
moduleGraph
67-
);
63+
return getDependencyUsedByExportsCondition(this, moduleGraph);
6864
}
6965

7066
/**

0 commit comments

Comments
 (0)