webpack 5.102.1 → 5.104.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +121 -134
- package/hot/dev-server.js +18 -3
- package/hot/emitter-event-target.js +7 -0
- package/hot/lazy-compilation-node.js +45 -29
- package/hot/lazy-compilation-universal.js +18 -0
- package/hot/lazy-compilation-web.js +15 -5
- package/hot/load-http.js +7 -0
- package/hot/only-dev-server.js +19 -4
- package/lib/APIPlugin.js +6 -0
- package/lib/Chunk.js +1 -1
- package/lib/ChunkGraph.js +9 -7
- package/lib/ChunkGroup.js +8 -5
- package/lib/CleanPlugin.js +6 -3
- package/lib/CodeGenerationResults.js +2 -1
- package/lib/CompatibilityPlugin.js +28 -2
- package/lib/Compilation.js +58 -21
- package/lib/Compiler.js +3 -3
- package/lib/ConcatenationScope.js +0 -15
- package/lib/ContextModule.js +6 -3
- package/lib/ContextModuleFactory.js +6 -4
- package/lib/CssModule.js +6 -1
- package/lib/DefinePlugin.js +45 -14
- package/lib/DelegatedModule.js +7 -4
- package/lib/Dependency.js +8 -1
- package/lib/DependencyTemplate.js +1 -0
- package/lib/DllModule.js +6 -3
- package/lib/DotenvPlugin.js +462 -0
- package/lib/EnvironmentPlugin.js +19 -16
- package/lib/EvalSourceMapDevToolPlugin.js +16 -0
- package/lib/ExportsInfo.js +6 -2
- package/lib/ExternalModule.js +28 -35
- package/lib/ExternalModuleFactoryPlugin.js +11 -9
- package/lib/ExternalsPlugin.js +2 -1
- package/lib/FileSystemInfo.js +1 -1
- package/lib/Generator.js +10 -7
- package/lib/HookWebpackError.js +33 -4
- package/lib/HotModuleReplacementPlugin.js +22 -0
- package/lib/ManifestPlugin.js +235 -0
- package/lib/Module.js +27 -15
- package/lib/ModuleBuildError.js +1 -1
- package/lib/ModuleError.js +1 -1
- package/lib/ModuleFilenameHelpers.js +1 -1
- package/lib/ModuleGraph.js +29 -13
- package/lib/ModuleGraphConnection.js +2 -2
- package/lib/ModuleSourceTypeConstants.js +189 -0
- package/lib/ModuleTypeConstants.js +1 -4
- package/lib/ModuleWarning.js +1 -1
- package/lib/MultiCompiler.js +1 -1
- package/lib/NodeStuffPlugin.js +424 -116
- package/lib/NormalModule.js +23 -20
- package/lib/NormalModuleFactory.js +7 -10
- package/lib/Parser.js +1 -1
- package/lib/RawModule.js +7 -4
- package/lib/RuntimeGlobals.js +22 -4
- package/lib/RuntimeModule.js +1 -1
- package/lib/RuntimePlugin.js +27 -6
- package/lib/RuntimeTemplate.js +120 -57
- package/lib/SourceMapDevToolPlugin.js +26 -1
- package/lib/Template.js +17 -6
- package/lib/TemplatedPathPlugin.js +5 -6
- package/lib/WebpackError.js +0 -1
- package/lib/WebpackOptionsApply.js +67 -15
- package/lib/asset/AssetBytesGenerator.js +16 -12
- package/lib/asset/AssetGenerator.js +31 -26
- package/lib/asset/AssetSourceGenerator.js +16 -12
- package/lib/asset/RawDataUrlModule.js +6 -3
- package/lib/buildChunkGraph.js +4 -2
- package/lib/cache/PackFileCacheStrategy.js +6 -5
- package/lib/cli.js +2 -43
- package/lib/config/browserslistTargetHandler.js +24 -0
- package/lib/config/defaults.js +226 -61
- package/lib/config/normalization.js +4 -3
- package/lib/config/target.js +11 -0
- package/lib/container/ContainerEntryModule.js +6 -3
- package/lib/container/FallbackModule.js +6 -3
- package/lib/container/RemoteModule.js +1 -3
- package/lib/css/CssGenerator.js +304 -76
- package/lib/css/CssLoadingRuntimeModule.js +14 -4
- package/lib/css/CssMergeStyleSheetsRuntimeModule.js +56 -0
- package/lib/css/CssModulesPlugin.js +72 -67
- package/lib/css/CssParser.js +1726 -732
- package/lib/css/walkCssTokens.js +128 -11
- package/lib/dependencies/CachedConstDependency.js +24 -10
- package/lib/dependencies/CommonJsImportsParserPlugin.js +0 -9
- package/lib/dependencies/CommonJsPlugin.js +12 -0
- package/lib/dependencies/CommonJsRequireContextDependency.js +1 -1
- package/lib/dependencies/ContextDependencyHelpers.js +2 -2
- package/lib/dependencies/ContextDependencyTemplateAsRequireCall.js +3 -1
- package/lib/dependencies/CssIcssExportDependency.js +389 -12
- package/lib/dependencies/CssIcssImportDependency.js +114 -51
- package/lib/dependencies/CssIcssSymbolDependency.js +31 -33
- package/lib/dependencies/CssImportDependency.js +17 -6
- package/lib/dependencies/CssUrlDependency.js +3 -2
- package/lib/dependencies/DynamicExports.js +7 -7
- package/lib/dependencies/ExternalModuleDependency.js +7 -4
- package/lib/dependencies/ExternalModuleInitFragment.js +3 -2
- package/lib/dependencies/ExternalModuleInitFragmentDependency.js +96 -0
- package/lib/dependencies/HarmonyAcceptDependency.js +6 -1
- package/lib/dependencies/HarmonyAcceptImportDependency.js +2 -1
- package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +12 -1
- package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +35 -23
- package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +13 -9
- package/lib/dependencies/HarmonyExports.js +4 -4
- package/lib/dependencies/HarmonyImportDependency.js +28 -27
- package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +28 -69
- package/lib/dependencies/HarmonyImportSideEffectDependency.js +4 -3
- package/lib/dependencies/HarmonyImportSpecifierDependency.js +10 -8
- package/lib/dependencies/ImportDependency.js +8 -2
- package/lib/dependencies/ImportEagerDependency.js +6 -3
- package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +1 -1
- package/lib/dependencies/ImportMetaPlugin.js +154 -9
- package/lib/dependencies/ImportParserPlugin.js +21 -23
- package/lib/dependencies/ImportPhase.js +121 -0
- package/lib/dependencies/ImportWeakDependency.js +6 -3
- package/lib/dependencies/LocalModulesHelpers.js +3 -3
- package/lib/dependencies/ModuleDependency.js +5 -1
- package/lib/dependencies/ModuleHotAcceptDependency.js +1 -1
- package/lib/dependencies/WorkerPlugin.js +2 -2
- package/lib/dependencies/getFunctionExpression.js +1 -1
- package/lib/esm/ExportWebpackRequireRuntimeModule.js +1 -8
- package/lib/esm/ModuleChunkFormatPlugin.js +5 -4
- package/lib/hmr/HotModuleReplacement.runtime.js +2 -1
- package/lib/hmr/LazyCompilationPlugin.js +5 -3
- package/lib/ids/IdHelpers.js +20 -8
- package/lib/index.js +6 -0
- package/lib/javascript/ChunkHelpers.js +16 -5
- package/lib/javascript/JavascriptGenerator.js +105 -104
- package/lib/javascript/JavascriptModulesPlugin.js +80 -37
- package/lib/javascript/JavascriptParser.js +161 -44
- package/lib/json/JsonGenerator.js +5 -4
- package/lib/json/JsonParser.js +9 -2
- package/lib/library/AbstractLibraryPlugin.js +1 -1
- package/lib/library/AmdLibraryPlugin.js +4 -1
- package/lib/library/ExportPropertyLibraryPlugin.js +4 -1
- package/lib/library/ModuleLibraryPlugin.js +41 -23
- package/lib/library/SystemLibraryPlugin.js +8 -1
- package/lib/library/UmdLibraryPlugin.js +2 -2
- package/lib/logging/Logger.js +5 -4
- package/lib/logging/createConsoleLogger.js +2 -2
- package/lib/node/NodeTargetPlugin.js +9 -1
- package/lib/node/ReadFileCompileWasmPlugin.js +0 -2
- package/lib/optimize/ConcatenatedModule.js +208 -167
- package/lib/optimize/ModuleConcatenationPlugin.js +5 -4
- package/lib/optimize/SideEffectsFlagPlugin.js +3 -2
- package/lib/optimize/SplitChunksPlugin.js +60 -46
- package/lib/rules/RuleSetCompiler.js +1 -1
- package/lib/runtime/AsyncModuleRuntimeModule.js +28 -18
- package/lib/runtime/AutoPublicPathRuntimeModule.js +8 -3
- package/lib/runtime/GetChunkFilenameRuntimeModule.js +3 -2
- package/lib/runtime/MakeDeferredNamespaceObjectRuntime.js +89 -55
- package/lib/schemes/HttpUriPlugin.js +78 -7
- package/lib/serialization/AggregateErrorSerializer.js +1 -2
- package/lib/serialization/ObjectMiddleware.js +0 -2
- package/lib/serialization/SingleItemMiddleware.js +1 -1
- package/lib/sharing/ConsumeSharedModule.js +1 -1
- package/lib/sharing/ConsumeSharedPlugin.js +5 -3
- package/lib/sharing/ProvideSharedModule.js +1 -1
- package/lib/sharing/resolveMatchedConfigs.js +15 -9
- package/lib/sharing/utils.js +1 -1
- package/lib/stats/DefaultStatsFactoryPlugin.js +8 -5
- package/lib/stats/DefaultStatsPresetPlugin.js +1 -1
- package/lib/stats/DefaultStatsPrinterPlugin.js +1 -1
- package/lib/util/StringXor.js +1 -1
- package/lib/util/URLAbsoluteSpecifier.js +2 -2
- package/lib/util/binarySearchBounds.js +2 -2
- package/lib/util/comparators.js +54 -76
- package/lib/util/compileBooleanMatcher.js +78 -6
- package/lib/util/createHash.js +20 -199
- package/lib/util/deprecation.js +1 -1
- package/lib/util/deterministicGrouping.js +6 -3
- package/lib/util/fs.js +75 -75
- package/lib/util/hash/BatchedHash.js +10 -9
- package/lib/util/hash/BulkUpdateHash.js +138 -0
- package/lib/util/hash/DebugHash.js +75 -0
- package/lib/util/hash/hash-digest.js +216 -0
- package/lib/util/identifier.js +82 -17
- package/lib/util/internalSerializables.js +2 -6
- package/lib/util/runtime.js +3 -3
- package/lib/util/source.js +2 -2
- package/lib/wasm/EnableWasmLoadingPlugin.js +10 -4
- package/lib/wasm-async/AsyncWebAssemblyGenerator.js +3 -2
- package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +11 -7
- package/lib/wasm-sync/WebAssemblyGenerator.js +9 -6
- package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +11 -6
- package/lib/wasm-sync/WebAssemblyModulesPlugin.js +6 -2
- package/lib/web/FetchCompileWasmPlugin.js +0 -2
- package/lib/webpack.js +85 -82
- package/module.d.ts +5 -0
- package/package.json +34 -28
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +160 -101
- package/schemas/plugins/{css/CssAutoParserOptions.check.d.ts → ManifestPlugin.check.d.ts} +1 -1
- package/schemas/plugins/ManifestPlugin.check.js +6 -0
- package/schemas/plugins/ManifestPlugin.json +98 -0
- package/schemas/plugins/SourceMapDevToolPlugin.check.js +1 -1
- package/schemas/plugins/SourceMapDevToolPlugin.json +16 -3
- package/schemas/plugins/container/ContainerReferencePlugin.check.js +1 -1
- package/schemas/plugins/container/ContainerReferencePlugin.json +4 -1
- package/schemas/plugins/container/ExternalsType.check.js +1 -1
- package/schemas/plugins/container/ModuleFederationPlugin.check.js +1 -1
- package/schemas/plugins/container/ModuleFederationPlugin.json +4 -1
- package/schemas/plugins/css/CssModuleGeneratorOptions.check.js +1 -1
- package/schemas/plugins/css/CssModuleParserOptions.check.js +1 -1
- package/schemas/plugins/css/CssParserOptions.check.js +1 -1
- package/schemas/plugins/json/JsonModulesPluginParser.check.js +1 -1
- package/types.d.ts +771 -436
- package/lib/ModuleSourceTypesConstants.js +0 -123
- package/lib/dependencies/CssLocalIdentifierDependency.js +0 -250
- package/lib/dependencies/CssSelfLocalIdentifierDependency.js +0 -112
- package/schemas/plugins/css/CssAutoGeneratorOptions.check.d.ts +0 -7
- package/schemas/plugins/css/CssAutoGeneratorOptions.check.js +0 -6
- package/schemas/plugins/css/CssAutoGeneratorOptions.json +0 -3
- package/schemas/plugins/css/CssAutoParserOptions.check.js +0 -6
- package/schemas/plugins/css/CssAutoParserOptions.json +0 -3
- package/schemas/plugins/css/CssGlobalGeneratorOptions.check.d.ts +0 -7
- package/schemas/plugins/css/CssGlobalGeneratorOptions.check.js +0 -6
- package/schemas/plugins/css/CssGlobalGeneratorOptions.json +0 -3
- package/schemas/plugins/css/CssGlobalParserOptions.check.d.ts +0 -7
- package/schemas/plugins/css/CssGlobalParserOptions.check.js +0 -6
- package/schemas/plugins/css/CssGlobalParserOptions.json +0 -3
|
@@ -20,6 +20,7 @@ const Compilation = require("../Compilation");
|
|
|
20
20
|
const { tryRunOrWebpackError } = require("../HookWebpackError");
|
|
21
21
|
const HotUpdateChunk = require("../HotUpdateChunk");
|
|
22
22
|
const InitFragment = require("../InitFragment");
|
|
23
|
+
const { JAVASCRIPT_TYPE } = require("../ModuleSourceTypeConstants");
|
|
23
24
|
const {
|
|
24
25
|
JAVASCRIPT_MODULE_TYPE_AUTO,
|
|
25
26
|
JAVASCRIPT_MODULE_TYPE_DYNAMIC,
|
|
@@ -79,7 +80,7 @@ const chunkHasJs = (chunk, chunkGraph) => {
|
|
|
79
80
|
if (chunkGraph.getNumberOfEntryModules(chunk) > 0) return true;
|
|
80
81
|
|
|
81
82
|
return Boolean(
|
|
82
|
-
chunkGraph.getChunkModulesIterableBySourceType(chunk,
|
|
83
|
+
chunkGraph.getChunkModulesIterableBySourceType(chunk, JAVASCRIPT_TYPE)
|
|
83
84
|
);
|
|
84
85
|
};
|
|
85
86
|
|
|
@@ -99,7 +100,7 @@ const chunkHasRuntimeOrJs = (chunk, chunkGraph) => {
|
|
|
99
100
|
}
|
|
100
101
|
|
|
101
102
|
return Boolean(
|
|
102
|
-
chunkGraph.getChunkModulesIterableBySourceType(chunk,
|
|
103
|
+
chunkGraph.getChunkModulesIterableBySourceType(chunk, JAVASCRIPT_TYPE)
|
|
103
104
|
);
|
|
104
105
|
};
|
|
105
106
|
|
|
@@ -181,7 +182,7 @@ const printGeneratedCodeForStack = (module, code) => {
|
|
|
181
182
|
* @property {ChunkGraph} chunkGraph the chunk graph
|
|
182
183
|
* @property {CodeGenerationResults} codeGenerationResults results of code generation
|
|
183
184
|
* @property {boolean | undefined} strictMode rendering in strict context
|
|
184
|
-
* @property {boolean
|
|
185
|
+
* @property {boolean} inlined inlined
|
|
185
186
|
* @property {boolean=} inlinedInIIFE the inlined entry module is wrapped in an IIFE
|
|
186
187
|
*/
|
|
187
188
|
|
|
@@ -197,6 +198,7 @@ const printGeneratedCodeForStack = (module, code) => {
|
|
|
197
198
|
* @property {boolean | undefined} strictMode rendering in strict context
|
|
198
199
|
* @property {boolean} factory true: renders as factory method, false: pure module content
|
|
199
200
|
* @property {boolean=} inlinedInIIFE the inlined entry module is wrapped in an IIFE, existing only when `factory` is set to false
|
|
201
|
+
* @property {boolean=} renderInObject render module in object container
|
|
200
202
|
*/
|
|
201
203
|
|
|
202
204
|
/**
|
|
@@ -276,7 +278,7 @@ class JavascriptModulesPlugin {
|
|
|
276
278
|
|
|
277
279
|
constructor(options = {}) {
|
|
278
280
|
this.options = options;
|
|
279
|
-
/** @type {WeakMap<Source, { source: Source, needModule:boolean, needExports: boolean, needRequire: boolean, needThisAsExports: boolean, needStrict: boolean | undefined }>} */
|
|
281
|
+
/** @type {WeakMap<Source, { source: Source, needModule:boolean, needExports: boolean, needRequire: boolean, needThisAsExports: boolean, needStrict: boolean | undefined, renderShorthand: boolean }>} */
|
|
280
282
|
this._moduleFactoryCache = new WeakMap();
|
|
281
283
|
}
|
|
282
284
|
|
|
@@ -298,16 +300,20 @@ class JavascriptModulesPlugin {
|
|
|
298
300
|
]) {
|
|
299
301
|
normalModuleFactory.hooks.createParser
|
|
300
302
|
.for(type)
|
|
301
|
-
.tap(PLUGIN_NAME, (
|
|
303
|
+
.tap(PLUGIN_NAME, (options) => {
|
|
302
304
|
switch (type) {
|
|
303
305
|
case JAVASCRIPT_MODULE_TYPE_AUTO: {
|
|
304
|
-
return new JavascriptParser("auto");
|
|
306
|
+
return new JavascriptParser("auto", { parse: options.parse });
|
|
305
307
|
}
|
|
306
308
|
case JAVASCRIPT_MODULE_TYPE_DYNAMIC: {
|
|
307
|
-
return new JavascriptParser("script"
|
|
309
|
+
return new JavascriptParser("script", {
|
|
310
|
+
parse: options.parse
|
|
311
|
+
});
|
|
308
312
|
}
|
|
309
313
|
case JAVASCRIPT_MODULE_TYPE_ESM: {
|
|
310
|
-
return new JavascriptParser("module"
|
|
314
|
+
return new JavascriptParser("module", {
|
|
315
|
+
parse: options.parse
|
|
316
|
+
});
|
|
311
317
|
}
|
|
312
318
|
}
|
|
313
319
|
});
|
|
@@ -483,7 +489,7 @@ class JavascriptModulesPlugin {
|
|
|
483
489
|
});
|
|
484
490
|
const modules = chunkGraph.getChunkModulesIterableBySourceType(
|
|
485
491
|
chunk,
|
|
486
|
-
|
|
492
|
+
JAVASCRIPT_TYPE
|
|
487
493
|
);
|
|
488
494
|
if (modules) {
|
|
489
495
|
const xor = new StringXor();
|
|
@@ -523,7 +529,8 @@ class JavascriptModulesPlugin {
|
|
|
523
529
|
}
|
|
524
530
|
);
|
|
525
531
|
compilation.hooks.executeModule.tap(PLUGIN_NAME, (options, context) => {
|
|
526
|
-
const source =
|
|
532
|
+
const source =
|
|
533
|
+
options.codeGenerationResult.sources.get(JAVASCRIPT_TYPE);
|
|
527
534
|
if (source === undefined) return;
|
|
528
535
|
const { module } = options;
|
|
529
536
|
const code = source.source();
|
|
@@ -611,11 +618,12 @@ class JavascriptModulesPlugin {
|
|
|
611
618
|
runtimeTemplate,
|
|
612
619
|
codeGenerationResults,
|
|
613
620
|
strictMode,
|
|
614
|
-
factory
|
|
621
|
+
factory,
|
|
622
|
+
renderInObject
|
|
615
623
|
} = renderContext;
|
|
616
624
|
try {
|
|
617
625
|
const codeGenResult = codeGenerationResults.get(module, chunk.runtime);
|
|
618
|
-
const moduleSource = codeGenResult.sources.get(
|
|
626
|
+
const moduleSource = codeGenResult.sources.get(JAVASCRIPT_TYPE);
|
|
619
627
|
if (!moduleSource) return null;
|
|
620
628
|
if (codeGenResult.data !== undefined) {
|
|
621
629
|
const chunkInitFragments = codeGenResult.data.get("chunkInitFragments");
|
|
@@ -650,6 +658,8 @@ class JavascriptModulesPlugin {
|
|
|
650
658
|
const cacheEntry = this._moduleFactoryCache.get(
|
|
651
659
|
moduleSourcePostContent
|
|
652
660
|
);
|
|
661
|
+
const renderShorthand =
|
|
662
|
+
renderInObject === true && runtimeTemplate.supportsMethodShorthand();
|
|
653
663
|
let source;
|
|
654
664
|
if (
|
|
655
665
|
cacheEntry &&
|
|
@@ -657,7 +667,8 @@ class JavascriptModulesPlugin {
|
|
|
657
667
|
cacheEntry.needExports === needExports &&
|
|
658
668
|
cacheEntry.needRequire === needRequire &&
|
|
659
669
|
cacheEntry.needThisAsExports === needThisAsExports &&
|
|
660
|
-
cacheEntry.needStrict === needStrict
|
|
670
|
+
cacheEntry.needStrict === needStrict &&
|
|
671
|
+
cacheEntry.renderShorthand === renderShorthand
|
|
661
672
|
) {
|
|
662
673
|
source = cacheEntry.source;
|
|
663
674
|
} else {
|
|
@@ -678,16 +689,24 @@ class JavascriptModulesPlugin {
|
|
|
678
689
|
);
|
|
679
690
|
}
|
|
680
691
|
if (needRequire) args.push(RuntimeGlobals.require);
|
|
681
|
-
|
|
692
|
+
|
|
693
|
+
if (renderShorthand) {
|
|
694
|
+
// we can optimize function to methodShorthand if render module factory in object
|
|
695
|
+
factorySource.add(`(${args.join(", ")}) {\n\n`);
|
|
696
|
+
} else if (
|
|
697
|
+
!needThisAsExports &&
|
|
698
|
+
runtimeTemplate.supportsArrowFunction()
|
|
699
|
+
) {
|
|
682
700
|
factorySource.add(`/***/ ((${args.join(", ")}) => {\n\n`);
|
|
683
701
|
} else {
|
|
684
702
|
factorySource.add(`/***/ (function(${args.join(", ")}) {\n\n`);
|
|
685
703
|
}
|
|
704
|
+
|
|
686
705
|
if (needStrict) {
|
|
687
706
|
factorySource.add('"use strict";\n');
|
|
688
707
|
}
|
|
689
708
|
factorySource.add(moduleSourcePostContent);
|
|
690
|
-
factorySource.add(
|
|
709
|
+
factorySource.add(`\n\n/***/ }${renderShorthand ? "" : ")"}`);
|
|
691
710
|
source = new CachedSource(factorySource);
|
|
692
711
|
this._moduleFactoryCache.set(moduleSourcePostContent, {
|
|
693
712
|
source,
|
|
@@ -695,7 +714,8 @@ class JavascriptModulesPlugin {
|
|
|
695
714
|
needExports,
|
|
696
715
|
needRequire,
|
|
697
716
|
needThisAsExports,
|
|
698
|
-
needStrict
|
|
717
|
+
needStrict,
|
|
718
|
+
renderShorthand
|
|
699
719
|
});
|
|
700
720
|
}
|
|
701
721
|
moduleSourcePostContainer = tryRunOrWebpackError(
|
|
@@ -730,7 +750,7 @@ class JavascriptModulesPlugin {
|
|
|
730
750
|
const { chunk, chunkGraph } = renderContext;
|
|
731
751
|
const modules = chunkGraph.getOrderedChunkModulesIterableBySourceType(
|
|
732
752
|
chunk,
|
|
733
|
-
|
|
753
|
+
JAVASCRIPT_TYPE,
|
|
734
754
|
compareModulesByIdOrIdentifier(chunkGraph)
|
|
735
755
|
);
|
|
736
756
|
const allModules = modules ? [...modules] : [];
|
|
@@ -753,12 +773,15 @@ class JavascriptModulesPlugin {
|
|
|
753
773
|
strictMode: allStrict
|
|
754
774
|
};
|
|
755
775
|
const moduleSources =
|
|
756
|
-
Template.renderChunkModules(
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
776
|
+
Template.renderChunkModules(
|
|
777
|
+
chunkRenderContext,
|
|
778
|
+
allModules,
|
|
779
|
+
(module, renderInObject) =>
|
|
780
|
+
this.renderModule(
|
|
781
|
+
module,
|
|
782
|
+
{ ...chunkRenderContext, factory: true, renderInObject },
|
|
783
|
+
hooks
|
|
784
|
+
)
|
|
762
785
|
) || new RawSource("{}");
|
|
763
786
|
let source = tryRunOrWebpackError(
|
|
764
787
|
() => hooks.renderChunk.call(moduleSources, chunkRenderContext),
|
|
@@ -814,7 +837,7 @@ class JavascriptModulesPlugin {
|
|
|
814
837
|
const allModules = [
|
|
815
838
|
...(chunkGraph.getOrderedChunkModulesIterableBySourceType(
|
|
816
839
|
chunk,
|
|
817
|
-
|
|
840
|
+
JAVASCRIPT_TYPE,
|
|
818
841
|
compareModulesByIdOrIdentifier(chunkGraph)
|
|
819
842
|
) || [])
|
|
820
843
|
];
|
|
@@ -870,10 +893,10 @@ class JavascriptModulesPlugin {
|
|
|
870
893
|
(m) => !(/** @type {Set<Module>} */ (inlinedModules).has(m))
|
|
871
894
|
)
|
|
872
895
|
: allModules,
|
|
873
|
-
(module) =>
|
|
896
|
+
(module, renderInObject) =>
|
|
874
897
|
this.renderModule(
|
|
875
898
|
module,
|
|
876
|
-
{ ...chunkRenderContext, factory: true },
|
|
899
|
+
{ ...chunkRenderContext, factory: true, renderInObject },
|
|
877
900
|
hooks
|
|
878
901
|
),
|
|
879
902
|
prefix
|
|
@@ -950,7 +973,8 @@ class JavascriptModulesPlugin {
|
|
|
950
973
|
let inlinedInIIFE = false;
|
|
951
974
|
|
|
952
975
|
if (avoidEntryIife) {
|
|
953
|
-
renamedInlinedModule = this.
|
|
976
|
+
renamedInlinedModule = this._getRenamedInlineModule(
|
|
977
|
+
compilation,
|
|
954
978
|
allModules,
|
|
955
979
|
renderContext,
|
|
956
980
|
inlinedModules,
|
|
@@ -1275,7 +1299,9 @@ class JavascriptModulesPlugin {
|
|
|
1275
1299
|
entryModule,
|
|
1276
1300
|
entrypoint
|
|
1277
1301
|
] of chunkGraph.getChunkEntryModulesWithChunkGroupIterable(chunk)) {
|
|
1278
|
-
if (
|
|
1302
|
+
if (
|
|
1303
|
+
!chunkGraph.getModuleSourceTypes(entryModule).has(JAVASCRIPT_TYPE)
|
|
1304
|
+
) {
|
|
1279
1305
|
i--;
|
|
1280
1306
|
continue;
|
|
1281
1307
|
}
|
|
@@ -1535,6 +1561,19 @@ class JavascriptModulesPlugin {
|
|
|
1535
1561
|
])
|
|
1536
1562
|
: Template.indent("return cachedModule.exports;"),
|
|
1537
1563
|
"}",
|
|
1564
|
+
// Add helpful error message in development mode when module is not found
|
|
1565
|
+
...(outputOptions.pathinfo
|
|
1566
|
+
? [
|
|
1567
|
+
"// Check if module exists (development only)",
|
|
1568
|
+
"if (__webpack_modules__[moduleId] === undefined) {",
|
|
1569
|
+
Template.indent([
|
|
1570
|
+
'var e = new Error("Cannot find module \'" + moduleId + "\'");',
|
|
1571
|
+
"e.code = 'MODULE_NOT_FOUND';",
|
|
1572
|
+
"throw e;"
|
|
1573
|
+
]),
|
|
1574
|
+
"}"
|
|
1575
|
+
]
|
|
1576
|
+
: []),
|
|
1538
1577
|
"// Create a new module (and put it into the cache)",
|
|
1539
1578
|
"var module = __webpack_module_cache__[moduleId] = {",
|
|
1540
1579
|
Template.indent([
|
|
@@ -1584,10 +1623,7 @@ class JavascriptModulesPlugin {
|
|
|
1584
1623
|
"// Execute the module function",
|
|
1585
1624
|
moduleExecution,
|
|
1586
1625
|
...(needModuleDefer
|
|
1587
|
-
? [
|
|
1588
|
-
"// delete __webpack_module_deferred_exports__[module];",
|
|
1589
|
-
"// skipped because strictModuleErrorHandling is not enabled."
|
|
1590
|
-
]
|
|
1626
|
+
? ["delete __webpack_module_deferred_exports__[moduleId];"]
|
|
1591
1627
|
: [])
|
|
1592
1628
|
]),
|
|
1593
1629
|
needModuleLoaded
|
|
@@ -1608,6 +1644,7 @@ class JavascriptModulesPlugin {
|
|
|
1608
1644
|
}
|
|
1609
1645
|
|
|
1610
1646
|
/**
|
|
1647
|
+
* @param {Compilation} compilation compilation
|
|
1611
1648
|
* @param {Module[]} allModules allModules
|
|
1612
1649
|
* @param {MainRenderContext} renderContext renderContext
|
|
1613
1650
|
* @param {Set<Module>} inlinedModules inlinedModules
|
|
@@ -1617,7 +1654,8 @@ class JavascriptModulesPlugin {
|
|
|
1617
1654
|
* @param {boolean} hasChunkModules hasChunkModules
|
|
1618
1655
|
* @returns {Map<Module, Source> | false} renamed inlined modules
|
|
1619
1656
|
*/
|
|
1620
|
-
|
|
1657
|
+
_getRenamedInlineModule(
|
|
1658
|
+
compilation,
|
|
1621
1659
|
allModules,
|
|
1622
1660
|
renderContext,
|
|
1623
1661
|
inlinedModules,
|
|
@@ -1648,7 +1686,6 @@ class JavascriptModulesPlugin {
|
|
|
1648
1686
|
const inlinedModulesToInfo = new Map();
|
|
1649
1687
|
/** @type {Set<string>} */
|
|
1650
1688
|
const nonInlinedModuleThroughIdentifiers = new Set();
|
|
1651
|
-
/** @type {Map<Module, Source>} */
|
|
1652
1689
|
|
|
1653
1690
|
for (const m of allModules) {
|
|
1654
1691
|
const isInlinedModule = inlinedModules && inlinedModules.has(m);
|
|
@@ -1664,9 +1701,15 @@ class JavascriptModulesPlugin {
|
|
|
1664
1701
|
|
|
1665
1702
|
if (!moduleSource) continue;
|
|
1666
1703
|
const code = /** @type {string} */ (moduleSource.source());
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1704
|
+
|
|
1705
|
+
const { ast } = JavascriptParser._parse(
|
|
1706
|
+
code,
|
|
1707
|
+
{
|
|
1708
|
+
sourceType: "auto",
|
|
1709
|
+
ranges: true
|
|
1710
|
+
},
|
|
1711
|
+
JavascriptParser._getModuleParseFunction(compilation, m)
|
|
1712
|
+
);
|
|
1670
1713
|
|
|
1671
1714
|
const scopeManager = eslintScope.analyze(ast, {
|
|
1672
1715
|
ecmaVersion: 6,
|
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
const vm = require("vm");
|
|
9
9
|
const { Parser: AcornParser, tokTypes } = require("acorn");
|
|
10
10
|
const { HookMap, SyncBailHook } = require("tapable");
|
|
11
|
+
const NormalModule = require("../NormalModule");
|
|
11
12
|
const Parser = require("../Parser");
|
|
12
13
|
const StackedMap = require("../util/StackedMap");
|
|
13
14
|
const binarySearchBounds = require("../util/binarySearchBounds");
|
|
@@ -19,6 +20,7 @@ const memoize = require("../util/memoize");
|
|
|
19
20
|
const BasicEvaluatedExpression = require("./BasicEvaluatedExpression");
|
|
20
21
|
|
|
21
22
|
/** @typedef {import("acorn").Options} AcornOptions */
|
|
23
|
+
/** @typedef {import("acorn").ecmaVersion} EcmaVersion */
|
|
22
24
|
/** @typedef {import("estree").AssignmentExpression} AssignmentExpression */
|
|
23
25
|
/** @typedef {import("estree").BinaryExpression} BinaryExpression */
|
|
24
26
|
/** @typedef {import("estree").BlockStatement} BlockStatement */
|
|
@@ -29,7 +31,8 @@ const BasicEvaluatedExpression = require("./BasicEvaluatedExpression");
|
|
|
29
31
|
/** @typedef {import("estree").ForStatement} ForStatement */
|
|
30
32
|
/** @typedef {import("estree").SwitchStatement} SwitchStatement */
|
|
31
33
|
/** @typedef {import("estree").ClassExpression} ClassExpression */
|
|
32
|
-
/** @typedef {import("estree").
|
|
34
|
+
/** @typedef {import("estree").SourceLocation} SourceLocation */
|
|
35
|
+
/** @typedef {import("estree").Comment & { start: number, end: number, loc: SourceLocation }} Comment */
|
|
33
36
|
/** @typedef {import("estree").ConditionalExpression} ConditionalExpression */
|
|
34
37
|
/** @typedef {import("estree").Declaration} Declaration */
|
|
35
38
|
/** @typedef {import("estree").PrivateIdentifier} PrivateIdentifier */
|
|
@@ -97,6 +100,22 @@ const BasicEvaluatedExpression = require("./BasicEvaluatedExpression");
|
|
|
97
100
|
/** @typedef {import("../Parser").ParserState} ParserState */
|
|
98
101
|
/** @typedef {import("../Parser").PreparsedAst} PreparsedAst */
|
|
99
102
|
|
|
103
|
+
/** @typedef {import("../dependencies/LocalModule")} LocalModule */
|
|
104
|
+
/** @typedef {import("../dependencies/HarmonyExportImportedSpecifierDependency").HarmonyStarExportsList} HarmonyStarExportsList */
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* @typedef {object} KnownJavascriptParserState
|
|
108
|
+
* @property {Set<string>=} harmonyNamedExports
|
|
109
|
+
* @property {HarmonyStarExportsList=} harmonyStarExports
|
|
110
|
+
* @property {number=} lastHarmonyImportOrder
|
|
111
|
+
* @property {LocalModule[]=} localModules
|
|
112
|
+
*/
|
|
113
|
+
|
|
114
|
+
/** @typedef {ParserState & KnownJavascriptParserState} JavascriptParserState */
|
|
115
|
+
|
|
116
|
+
/** @typedef {import("../Compilation")} Compilation */
|
|
117
|
+
/** @typedef {import("../Module")} Module */
|
|
118
|
+
|
|
100
119
|
/** @typedef {{ name: string | VariableInfo, rootInfo: string | VariableInfo, getMembers: () => Members, getMembersOptionals: () => MembersOptionals, getMemberRanges: () => MemberRanges }} GetInfoResult */
|
|
101
120
|
/** @typedef {Statement | ModuleDeclaration | Expression | MaybeNamedFunctionDeclaration | MaybeNamedClassDeclaration} StatementPathItem */
|
|
102
121
|
/** @typedef {(ident: string) => void} OnIdentString */
|
|
@@ -297,7 +316,33 @@ class VariableInfo {
|
|
|
297
316
|
|
|
298
317
|
/** @typedef {string | ScopeInfo | VariableInfo} ExportedVariableInfo */
|
|
299
318
|
/** @typedef {Literal | string | null | undefined} ImportSource */
|
|
300
|
-
|
|
319
|
+
|
|
320
|
+
/**
|
|
321
|
+
* @typedef {Omit<ParseOptions, "sourceType"> & {sourceType: "module" | "script" | "auto"}} InternalParseOptions
|
|
322
|
+
*/
|
|
323
|
+
|
|
324
|
+
/**
|
|
325
|
+
* @typedef {object} ParseOptions
|
|
326
|
+
* @property {"module" | "script"} sourceType
|
|
327
|
+
* @property {EcmaVersion=} ecmaVersion
|
|
328
|
+
* @property {boolean=} locations
|
|
329
|
+
* @property {boolean=} comments
|
|
330
|
+
* @property {boolean=} ranges
|
|
331
|
+
* @property {boolean=} semicolons
|
|
332
|
+
* @property {boolean=} allowHashBang
|
|
333
|
+
* @property {boolean=} allowReturnOutsideFunction
|
|
334
|
+
*/
|
|
335
|
+
|
|
336
|
+
/**
|
|
337
|
+
* @typedef {object} ParseResult
|
|
338
|
+
* @property {Program} ast
|
|
339
|
+
* @property {Comment[]} comments
|
|
340
|
+
* @property {Set<number>} semicolons
|
|
341
|
+
*/
|
|
342
|
+
|
|
343
|
+
/**
|
|
344
|
+
* @typedef {(code: string, options: ParseOptions) => ParseResult} ParseFunction
|
|
345
|
+
*/
|
|
301
346
|
|
|
302
347
|
/** @typedef {symbol} Tag */
|
|
303
348
|
|
|
@@ -343,6 +388,7 @@ const SCOPE_INFO_TERMINATED_THROW = 2;
|
|
|
343
388
|
* @typedef {object} DestructuringAssignmentProperty
|
|
344
389
|
* @property {string} id
|
|
345
390
|
* @property {Range} range
|
|
391
|
+
* @property {SourceLocation} loc
|
|
346
392
|
* @property {Set<DestructuringAssignmentProperty> | undefined=} pattern
|
|
347
393
|
* @property {boolean | string} shorthand
|
|
348
394
|
*/
|
|
@@ -412,15 +458,15 @@ const getRootName = (expression) => {
|
|
|
412
458
|
}
|
|
413
459
|
};
|
|
414
460
|
|
|
415
|
-
/** @type {
|
|
461
|
+
/** @type {ParseOptions} */
|
|
416
462
|
const defaultParserOptions = {
|
|
417
|
-
ranges: true,
|
|
418
|
-
locations: true,
|
|
419
|
-
ecmaVersion: "latest",
|
|
420
463
|
sourceType: "module",
|
|
464
|
+
ecmaVersion: "latest",
|
|
465
|
+
ranges: false,
|
|
466
|
+
locations: false,
|
|
467
|
+
comments: false,
|
|
421
468
|
// https://github.com/tc39/proposal-hashbang
|
|
422
|
-
allowHashBang: true
|
|
423
|
-
onComment: undefined
|
|
469
|
+
allowHashBang: true
|
|
424
470
|
};
|
|
425
471
|
|
|
426
472
|
const EMPTY_COMMENT_OPTIONS = {
|
|
@@ -432,9 +478,10 @@ const CLASS_NAME = "JavascriptParser";
|
|
|
432
478
|
|
|
433
479
|
class JavascriptParser extends Parser {
|
|
434
480
|
/**
|
|
435
|
-
* @param {"module" | "script" | "auto"} sourceType default source type
|
|
481
|
+
* @param {"module" | "script" | "auto"=} sourceType default source type
|
|
482
|
+
* @param {{ parse?: ParseFunction }=} options parser options
|
|
436
483
|
*/
|
|
437
|
-
constructor(sourceType = "auto") {
|
|
484
|
+
constructor(sourceType = "auto", options = {}) {
|
|
438
485
|
super();
|
|
439
486
|
this.hooks = Object.freeze({
|
|
440
487
|
/** @type {HookMap<SyncBailHook<[UnaryExpression], BasicEvaluatedExpression | null | undefined>>} */
|
|
@@ -628,9 +675,11 @@ class JavascriptParser extends Parser {
|
|
|
628
675
|
unusedStatement: new SyncBailHook(["statement"])
|
|
629
676
|
});
|
|
630
677
|
this.sourceType = sourceType;
|
|
678
|
+
this.options = options;
|
|
679
|
+
|
|
631
680
|
/** @type {ScopeInfo} */
|
|
632
681
|
this.scope = /** @type {EXPECTED_ANY} */ (undefined);
|
|
633
|
-
/** @type {
|
|
682
|
+
/** @type {JavascriptParserState} */
|
|
634
683
|
this.state = /** @type {EXPECTED_ANY} */ (undefined);
|
|
635
684
|
/** @type {Comment[] | undefined} */
|
|
636
685
|
this.comments = undefined;
|
|
@@ -1862,7 +1911,7 @@ class JavascriptParser extends Parser {
|
|
|
1862
1911
|
const expr = /** @type {ChainExpression} */ (_expr);
|
|
1863
1912
|
/** @type {Expression[]} */
|
|
1864
1913
|
const optionalExpressionsStack = [];
|
|
1865
|
-
/** @type {Expression|Super} */
|
|
1914
|
+
/** @type {Expression | Super} */
|
|
1866
1915
|
let next = expr.expression;
|
|
1867
1916
|
|
|
1868
1917
|
while (
|
|
@@ -3003,6 +3052,7 @@ class JavascriptParser extends Parser {
|
|
|
3003
3052
|
props.add({
|
|
3004
3053
|
id: key.name,
|
|
3005
3054
|
range: /** @type {Range} */ (key.range),
|
|
3055
|
+
loc: /** @type {SourceLocation} */ (key.loc),
|
|
3006
3056
|
pattern,
|
|
3007
3057
|
shorthand: this.scope.inShorthand
|
|
3008
3058
|
});
|
|
@@ -3019,6 +3069,7 @@ class JavascriptParser extends Parser {
|
|
|
3019
3069
|
props.add({
|
|
3020
3070
|
id: str,
|
|
3021
3071
|
range: /** @type {Range} */ (key.range),
|
|
3072
|
+
loc: /** @type {SourceLocation} */ (key.loc),
|
|
3022
3073
|
pattern,
|
|
3023
3074
|
shorthand: this.scope.inShorthand
|
|
3024
3075
|
});
|
|
@@ -3054,6 +3105,7 @@ class JavascriptParser extends Parser {
|
|
|
3054
3105
|
props.add({
|
|
3055
3106
|
id: `${i}`,
|
|
3056
3107
|
range: /** @type {Range} */ (element.range),
|
|
3108
|
+
loc: /** @type {SourceLocation} */ (element.loc),
|
|
3057
3109
|
pattern,
|
|
3058
3110
|
shorthand: false
|
|
3059
3111
|
});
|
|
@@ -4626,17 +4678,23 @@ class JavascriptParser extends Parser {
|
|
|
4626
4678
|
* @returns {ParserState} the parser state
|
|
4627
4679
|
*/
|
|
4628
4680
|
parse(source, state) {
|
|
4629
|
-
let ast;
|
|
4630
|
-
/** @type {import("acorn").Comment[]} */
|
|
4631
|
-
let comments;
|
|
4632
|
-
const semicolons = new Set();
|
|
4633
4681
|
if (source === null) {
|
|
4634
4682
|
throw new Error("source must not be null");
|
|
4635
4683
|
}
|
|
4684
|
+
|
|
4636
4685
|
if (Buffer.isBuffer(source)) {
|
|
4637
4686
|
source = source.toString("utf8");
|
|
4638
4687
|
}
|
|
4688
|
+
|
|
4689
|
+
let ast;
|
|
4690
|
+
/** @type {Comment[]} */
|
|
4691
|
+
let comments;
|
|
4692
|
+
/** @type {Set<number>} */
|
|
4693
|
+
let semicolons;
|
|
4694
|
+
|
|
4639
4695
|
if (typeof source === "object") {
|
|
4696
|
+
semicolons = new Set();
|
|
4697
|
+
|
|
4640
4698
|
ast = /** @type {Program} */ (source);
|
|
4641
4699
|
comments = source.comments;
|
|
4642
4700
|
if (source.semicolons) {
|
|
@@ -4647,12 +4705,17 @@ class JavascriptParser extends Parser {
|
|
|
4647
4705
|
}
|
|
4648
4706
|
}
|
|
4649
4707
|
} else {
|
|
4650
|
-
comments =
|
|
4651
|
-
|
|
4652
|
-
|
|
4653
|
-
|
|
4654
|
-
|
|
4655
|
-
|
|
4708
|
+
({ ast, comments, semicolons } = JavascriptParser._parse(
|
|
4709
|
+
source,
|
|
4710
|
+
{
|
|
4711
|
+
sourceType: this.sourceType,
|
|
4712
|
+
locations: true,
|
|
4713
|
+
ranges: true,
|
|
4714
|
+
comments: true,
|
|
4715
|
+
semicolons: true
|
|
4716
|
+
},
|
|
4717
|
+
this.options.parse
|
|
4718
|
+
));
|
|
4656
4719
|
}
|
|
4657
4720
|
|
|
4658
4721
|
const oldScope = this.scope;
|
|
@@ -4702,10 +4765,11 @@ class JavascriptParser extends Parser {
|
|
|
4702
4765
|
* @returns {BasicEvaluatedExpression} evaluation result
|
|
4703
4766
|
*/
|
|
4704
4767
|
evaluate(source) {
|
|
4705
|
-
const ast = JavascriptParser._parse(
|
|
4706
|
-
|
|
4707
|
-
|
|
4708
|
-
|
|
4768
|
+
const { ast } = JavascriptParser._parse(
|
|
4769
|
+
`(${source})`,
|
|
4770
|
+
{ sourceType: this.sourceType },
|
|
4771
|
+
this.options.parse
|
|
4772
|
+
);
|
|
4709
4773
|
if (ast.body.length !== 1 || ast.body[0].type !== "ExpressionStatement") {
|
|
4710
4774
|
throw new Error("evaluate: Source is not a expression");
|
|
4711
4775
|
}
|
|
@@ -5082,7 +5146,7 @@ class JavascriptParser extends Parser {
|
|
|
5082
5146
|
if (comments.length === 0) {
|
|
5083
5147
|
return EMPTY_COMMENT_OPTIONS;
|
|
5084
5148
|
}
|
|
5085
|
-
/** @type {Record<string, EXPECTED_ANY>
|
|
5149
|
+
/** @type {Record<string, EXPECTED_ANY>} */
|
|
5086
5150
|
const options = {};
|
|
5087
5151
|
/** @type {(Error & { comment: Comment })[]} */
|
|
5088
5152
|
const errors = [];
|
|
@@ -5184,8 +5248,8 @@ class JavascriptParser extends Parser {
|
|
|
5184
5248
|
return { info, name };
|
|
5185
5249
|
}
|
|
5186
5250
|
|
|
5187
|
-
/** @typedef {{ type: "call", call: CallExpression, calleeName: string, rootInfo: string | VariableInfo, getCalleeMembers: () => CalleeMembers, name: string, getMembers: () => Members, getMembersOptionals: () => MembersOptionals, getMemberRanges: () => MemberRanges}} CallExpressionInfo */
|
|
5188
|
-
/** @typedef {{ type: "expression", rootInfo: string | VariableInfo, name: string, getMembers: () => Members, getMembersOptionals: () => MembersOptionals, getMemberRanges: () => MemberRanges}} ExpressionExpressionInfo */
|
|
5251
|
+
/** @typedef {{ type: "call", call: CallExpression, calleeName: string, rootInfo: string | VariableInfo, getCalleeMembers: () => CalleeMembers, name: string, getMembers: () => Members, getMembersOptionals: () => MembersOptionals, getMemberRanges: () => MemberRanges }} CallExpressionInfo */
|
|
5252
|
+
/** @typedef {{ type: "expression", rootInfo: string | VariableInfo, name: string, getMembers: () => Members, getMembersOptionals: () => MembersOptionals, getMemberRanges: () => MemberRanges }} ExpressionExpressionInfo */
|
|
5189
5253
|
|
|
5190
5254
|
/**
|
|
5191
5255
|
* @param {Expression | Super} expression a member expression
|
|
@@ -5246,7 +5310,7 @@ class JavascriptParser extends Parser {
|
|
|
5246
5310
|
|
|
5247
5311
|
/**
|
|
5248
5312
|
* @param {Expression} expression an expression
|
|
5249
|
-
* @returns {{ name: string, rootInfo: ExportedVariableInfo, getMembers: () => Members} | undefined} name info
|
|
5313
|
+
* @returns {{ name: string, rootInfo: ExportedVariableInfo, getMembers: () => Members } | undefined} name info
|
|
5250
5314
|
*/
|
|
5251
5315
|
getNameForExpression(expression) {
|
|
5252
5316
|
return this.getMemberExpressionInfo(
|
|
@@ -5255,27 +5319,84 @@ class JavascriptParser extends Parser {
|
|
|
5255
5319
|
);
|
|
5256
5320
|
}
|
|
5257
5321
|
|
|
5322
|
+
/**
|
|
5323
|
+
* @param {Compilation} compilation compilation
|
|
5324
|
+
* @param {Module} module module
|
|
5325
|
+
* @returns {ParseFunction | undefined} parser
|
|
5326
|
+
*/
|
|
5327
|
+
static _getModuleParseFunction(compilation, module) {
|
|
5328
|
+
// Get from module if available
|
|
5329
|
+
if (
|
|
5330
|
+
module instanceof NormalModule &&
|
|
5331
|
+
module.parser instanceof JavascriptParser
|
|
5332
|
+
) {
|
|
5333
|
+
return module.parser.options.parse;
|
|
5334
|
+
}
|
|
5335
|
+
|
|
5336
|
+
// Fallback to the global javascript parse function
|
|
5337
|
+
if (typeof compilation.options.module.parser.javascript !== "undefined") {
|
|
5338
|
+
return compilation.options.module.parser.javascript.parse;
|
|
5339
|
+
}
|
|
5340
|
+
}
|
|
5341
|
+
|
|
5258
5342
|
/**
|
|
5259
5343
|
* @param {string} code source code
|
|
5260
|
-
* @param {
|
|
5261
|
-
* @
|
|
5344
|
+
* @param {InternalParseOptions} options parsing options
|
|
5345
|
+
* @param {ParseFunction=} customParse custom function to parse
|
|
5346
|
+
* @returns {ParseResult} parse result
|
|
5262
5347
|
*/
|
|
5263
|
-
static _parse(code, options) {
|
|
5348
|
+
static _parse(code, options, customParse) {
|
|
5264
5349
|
const type = options ? options.sourceType : "module";
|
|
5265
|
-
/** @type {
|
|
5350
|
+
/** @type {ParseOptions} */
|
|
5266
5351
|
const parserOptions = {
|
|
5267
5352
|
...defaultParserOptions,
|
|
5268
5353
|
allowReturnOutsideFunction: type === "script",
|
|
5269
5354
|
...options,
|
|
5270
5355
|
sourceType: type === "auto" ? "module" : type
|
|
5271
5356
|
};
|
|
5357
|
+
/**
|
|
5358
|
+
* @param {string} code source code
|
|
5359
|
+
* @param {ParseOptions} options parsing options
|
|
5360
|
+
* @returns {ParseResult} parse result
|
|
5361
|
+
*/
|
|
5362
|
+
const internalParse = (code, options) => {
|
|
5363
|
+
if (typeof customParse === "function") {
|
|
5364
|
+
return customParse(code, options);
|
|
5365
|
+
}
|
|
5366
|
+
|
|
5367
|
+
/** @type {Comment[]} */
|
|
5368
|
+
const comments = [];
|
|
5369
|
+
|
|
5370
|
+
if (options.comments) {
|
|
5371
|
+
/** @type {AcornOptions} */
|
|
5372
|
+
(options).onComment = comments;
|
|
5373
|
+
}
|
|
5374
|
+
|
|
5375
|
+
/** @type {Set<number>} */
|
|
5376
|
+
const semicolons = new Set();
|
|
5377
|
+
|
|
5378
|
+
if (options.semicolons) {
|
|
5379
|
+
/** @type {AcornOptions} */
|
|
5380
|
+
(options).onInsertedSemicolon = (pos) => semicolons.add(pos);
|
|
5381
|
+
}
|
|
5382
|
+
|
|
5383
|
+
const ast =
|
|
5384
|
+
/** @type {Program} */
|
|
5385
|
+
(parser.parse(code, /** @type {AcornOptions} */ (options)));
|
|
5386
|
+
|
|
5387
|
+
return { ast, comments, semicolons };
|
|
5388
|
+
};
|
|
5272
5389
|
|
|
5273
|
-
/** @type {
|
|
5390
|
+
/** @type {Program | undefined} */
|
|
5274
5391
|
let ast;
|
|
5392
|
+
/** @type {Comment[] | undefined} */
|
|
5393
|
+
let comments;
|
|
5394
|
+
/** @type {Set<number> | undefined} */
|
|
5395
|
+
let semicolons;
|
|
5275
5396
|
let error;
|
|
5276
5397
|
let threw = false;
|
|
5277
5398
|
try {
|
|
5278
|
-
ast =
|
|
5399
|
+
({ ast, comments, semicolons } = internalParse(code, parserOptions));
|
|
5279
5400
|
} catch (err) {
|
|
5280
5401
|
error = err;
|
|
5281
5402
|
threw = true;
|
|
@@ -5283,14 +5404,10 @@ class JavascriptParser extends Parser {
|
|
|
5283
5404
|
|
|
5284
5405
|
if (threw && type === "auto") {
|
|
5285
5406
|
parserOptions.sourceType = "script";
|
|
5286
|
-
|
|
5287
|
-
|
|
5288
|
-
}
|
|
5289
|
-
if (Array.isArray(parserOptions.onComment)) {
|
|
5290
|
-
parserOptions.onComment.length = 0;
|
|
5291
|
-
}
|
|
5407
|
+
parserOptions.allowReturnOutsideFunction = true;
|
|
5408
|
+
|
|
5292
5409
|
try {
|
|
5293
|
-
ast =
|
|
5410
|
+
({ ast, comments, semicolons } = internalParse(code, parserOptions));
|
|
5294
5411
|
threw = false;
|
|
5295
5412
|
} catch (_err) {
|
|
5296
5413
|
// we use the error from first parse try
|
|
@@ -5302,7 +5419,7 @@ class JavascriptParser extends Parser {
|
|
|
5302
5419
|
throw error;
|
|
5303
5420
|
}
|
|
5304
5421
|
|
|
5305
|
-
return /** @type {
|
|
5422
|
+
return /** @type {ParseResult} */ ({ ast, comments, semicolons });
|
|
5306
5423
|
}
|
|
5307
5424
|
|
|
5308
5425
|
/**
|