1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 | "use strict";
|
7 |
|
8 | const InnerGraph = require("./optimize/InnerGraph");
|
9 |
|
10 |
|
11 |
|
12 |
|
13 | class JavascriptMetaInfoPlugin {
|
14 | |
15 |
|
16 |
|
17 |
|
18 |
|
19 | apply(compiler) {
|
20 | compiler.hooks.compilation.tap(
|
21 | "JavascriptMetaInfoPlugin",
|
22 | (compilation, { normalModuleFactory }) => {
|
23 | |
24 |
|
25 |
|
26 |
|
27 | const handler = parser => {
|
28 | parser.hooks.call.for("eval").tap("JavascriptMetaInfoPlugin", () => {
|
29 | parser.state.module.buildInfo.moduleConcatenationBailout = "eval()";
|
30 | parser.state.module.buildInfo.usingEval = true;
|
31 | InnerGraph.bailout(parser.state);
|
32 | });
|
33 | parser.hooks.finish.tap("JavascriptMetaInfoPlugin", () => {
|
34 | let topLevelDeclarations =
|
35 | parser.state.module.buildInfo.topLevelDeclarations;
|
36 | if (topLevelDeclarations === undefined) {
|
37 | topLevelDeclarations = parser.state.module.buildInfo.topLevelDeclarations = new Set();
|
38 | }
|
39 | for (const name of parser.scope.definitions.asSet()) {
|
40 | const freeInfo = parser.getFreeInfoFromVariable(name);
|
41 | if (freeInfo === undefined) {
|
42 | topLevelDeclarations.add(name);
|
43 | }
|
44 | }
|
45 | });
|
46 | };
|
47 |
|
48 | normalModuleFactory.hooks.parser
|
49 | .for("javascript/auto")
|
50 | .tap("JavascriptMetaInfoPlugin", handler);
|
51 | normalModuleFactory.hooks.parser
|
52 | .for("javascript/dynamic")
|
53 | .tap("JavascriptMetaInfoPlugin", handler);
|
54 | normalModuleFactory.hooks.parser
|
55 | .for("javascript/esm")
|
56 | .tap("JavascriptMetaInfoPlugin", handler);
|
57 | }
|
58 | );
|
59 | }
|
60 | }
|
61 |
|
62 | module.exports = JavascriptMetaInfoPlugin;
|