webpack 5.100.1 → 5.101.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 +12 -10
- package/bin/webpack.js +7 -7
- package/lib/APIPlugin.js +12 -14
- package/lib/AutomaticPrefetchPlugin.js +2 -2
- package/lib/BannerPlugin.js +4 -4
- package/lib/Cache.js +1 -1
- package/lib/CacheFacade.js +7 -7
- package/lib/CaseSensitiveModulesWarning.js +2 -2
- package/lib/Chunk.js +3 -3
- package/lib/ChunkGraph.js +21 -18
- package/lib/ChunkGroup.js +4 -4
- package/lib/CleanPlugin.js +19 -53
- package/lib/CodeGenerationResults.js +3 -3
- package/lib/CompatibilityPlugin.js +6 -6
- package/lib/Compilation.js +127 -114
- package/lib/Compiler.js +37 -37
- package/lib/ConcatenationScope.js +39 -1
- package/lib/ConstPlugin.js +11 -11
- package/lib/ContextExclusionPlugin.js +3 -3
- package/lib/ContextModule.js +12 -11
- package/lib/ContextModuleFactory.js +11 -11
- package/lib/ContextReplacementPlugin.js +5 -5
- package/lib/DefinePlugin.js +24 -22
- package/lib/DelegatedModuleFactoryPlugin.js +1 -1
- package/lib/DllEntryPlugin.js +1 -1
- package/lib/DllReferencePlugin.js +1 -1
- package/lib/DynamicEntryPlugin.js +3 -3
- package/lib/EntryPlugin.js +1 -1
- package/lib/EnvironmentPlugin.js +1 -1
- package/lib/ErrorHelpers.js +2 -2
- package/lib/EvalDevToolModulePlugin.js +2 -2
- package/lib/EvalSourceMapDevToolPlugin.js +5 -5
- package/lib/ExportsInfo.js +9 -9
- package/lib/ExportsInfoApiPlugin.js +2 -2
- package/lib/ExternalModule.js +163 -48
- package/lib/ExternalModuleFactoryPlugin.js +2 -2
- package/lib/ExternalsPlugin.js +45 -0
- package/lib/FileSystemInfo.js +64 -61
- package/lib/FlagAllModulesAsUsedPlugin.js +2 -2
- package/lib/FlagDependencyExportsPlugin.js +7 -7
- package/lib/FlagDependencyUsagePlugin.js +4 -4
- package/lib/FlagEntryExportAsUsedPlugin.js +1 -1
- package/lib/HotModuleReplacementPlugin.js +27 -27
- package/lib/IgnorePlugin.js +3 -3
- package/lib/IgnoreWarningsPlugin.js +4 -4
- package/lib/InitFragment.js +6 -0
- package/lib/InvalidDependenciesModuleWarning.js +1 -1
- package/lib/JavascriptMetaInfoPlugin.js +1 -1
- package/lib/LibManifestPlugin.js +2 -2
- package/lib/LoaderOptionsPlugin.js +1 -1
- package/lib/LoaderTargetPlugin.js +2 -2
- package/lib/MainTemplate.js +1 -1
- package/lib/Module.js +1 -1
- package/lib/ModuleFilenameHelpers.js +3 -3
- package/lib/ModuleGraph.js +86 -5
- package/lib/ModuleInfoHeaderPlugin.js +3 -3
- package/lib/ModuleParseError.js +5 -3
- package/lib/MultiCompiler.js +29 -24
- package/lib/MultiStats.js +18 -13
- package/lib/MultiWatching.js +1 -1
- package/lib/NoEmitOnErrorsPlugin.js +2 -2
- package/lib/NodeStuffPlugin.js +27 -15
- package/lib/NormalModule.js +28 -24
- package/lib/NormalModuleFactory.js +23 -21
- package/lib/NormalModuleReplacementPlugin.js +3 -3
- package/lib/PrefetchPlugin.js +1 -1
- package/lib/ProgressPlugin.js +11 -11
- package/lib/ProvidePlugin.js +2 -2
- package/lib/RecordIdsPlugin.js +3 -3
- package/lib/ResolverFactory.js +3 -3
- package/lib/RuntimeGlobals.js +20 -0
- package/lib/RuntimePlugin.js +16 -16
- package/lib/RuntimeTemplate.js +42 -44
- package/lib/SizeFormatHelpers.js +1 -1
- package/lib/SourceMapDevToolModuleOptionsPlugin.js +4 -4
- package/lib/SourceMapDevToolPlugin.js +9 -9
- package/lib/Stats.js +2 -2
- package/lib/Template.js +1 -1
- package/lib/TemplatedPathPlugin.js +2 -2
- package/lib/UseStrictPlugin.js +1 -1
- package/lib/WarnCaseSensitiveModulesPlugin.js +1 -1
- package/lib/WarnDeprecatedOptionPlugin.js +1 -1
- package/lib/WarnNoModeSetPlugin.js +1 -1
- package/lib/WatchIgnorePlugin.js +2 -2
- package/lib/Watching.js +12 -12
- package/lib/WebpackIsIncludedPlugin.js +2 -2
- package/lib/WebpackOptionsApply.js +10 -3
- package/lib/asset/AssetGenerator.js +3 -3
- package/lib/asset/AssetModulesPlugin.js +6 -6
- package/lib/async-modules/AsyncModuleHelpers.js +50 -0
- package/lib/async-modules/AwaitDependenciesInitFragment.js +36 -24
- package/lib/async-modules/InferAsyncModulesPlugin.js +3 -3
- package/lib/buildChunkGraph.js +5 -5
- package/lib/cache/AddBuildDependenciesPlugin.js +1 -1
- package/lib/cache/IdleFileCachePlugin.js +5 -5
- package/lib/cache/PackFileCacheStrategy.js +20 -20
- package/lib/cache/ResolverCachePlugin.js +4 -4
- package/lib/cli.js +196 -14
- package/lib/config/browserslistTargetHandler.js +6 -6
- package/lib/config/defaults.js +23 -14
- package/lib/config/normalization.js +41 -38
- package/lib/config/target.js +4 -4
- package/lib/container/ContainerEntryModule.js +3 -3
- package/lib/container/ContainerPlugin.js +3 -3
- package/lib/container/ContainerReferencePlugin.js +3 -3
- package/lib/container/FallbackModule.js +1 -1
- package/lib/container/HoistContainerReferencesPlugin.js +7 -7
- package/lib/container/options.js +4 -4
- package/lib/css/CssGenerator.js +5 -3
- package/lib/css/CssLoadingRuntimeModule.js +1 -1
- package/lib/css/CssModulesPlugin.js +25 -22
- package/lib/css/CssParser.js +5 -5
- package/lib/css/walkCssTokens.js +9 -9
- package/lib/debug/ProfilingPlugin.js +5 -5
- package/lib/dependencies/AMDDefineDependencyParserPlugin.js +4 -4
- package/lib/dependencies/AMDPlugin.js +3 -3
- package/lib/dependencies/AMDRequireArrayDependency.js +1 -1
- package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +3 -3
- package/lib/dependencies/CommonJsExportRequireDependency.js +2 -2
- package/lib/dependencies/CommonJsExportsParserPlugin.js +12 -10
- package/lib/dependencies/CommonJsImportsParserPlugin.js +21 -19
- package/lib/dependencies/CommonJsPlugin.js +2 -2
- package/lib/dependencies/ContextDependency.js +1 -1
- package/lib/dependencies/ContextDependencyHelpers.js +3 -3
- package/lib/dependencies/CssIcssExportDependency.js +2 -2
- package/lib/dependencies/CssLocalIdentifierDependency.js +2 -2
- package/lib/dependencies/CssUrlDependency.js +4 -4
- package/lib/dependencies/DynamicExports.js +5 -5
- package/lib/dependencies/HarmonyAcceptDependency.js +39 -5
- package/lib/dependencies/HarmonyDetectionParserPlugin.js +2 -2
- package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +17 -23
- package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +7 -8
- package/lib/dependencies/HarmonyExportInitFragment.js +1 -1
- package/lib/dependencies/HarmonyExports.js +1 -1
- package/lib/dependencies/HarmonyImportDependency.js +28 -9
- package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +59 -75
- package/lib/dependencies/HarmonyImportSideEffectDependency.js +4 -5
- package/lib/dependencies/HarmonyImportSpecifierDependency.js +3 -4
- package/lib/dependencies/HarmonyModulesPlugin.js +2 -8
- package/lib/dependencies/HarmonyTopLevelThisParserPlugin.js +1 -1
- package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +4 -4
- package/lib/dependencies/ImportMetaPlugin.js +7 -7
- package/lib/dependencies/ImportParserPlugin.js +4 -4
- package/lib/dependencies/JsonExportsDependency.js +1 -1
- package/lib/dependencies/LoaderPlugin.js +4 -4
- package/lib/dependencies/ProvidedDependency.js +2 -2
- package/lib/dependencies/PureExpressionDependency.js +1 -1
- package/lib/dependencies/RequireContextDependencyParserPlugin.js +1 -1
- package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +1 -1
- package/lib/dependencies/RequireIncludeDependencyParserPlugin.js +3 -3
- package/lib/dependencies/SystemPlugin.js +3 -3
- package/lib/dependencies/WorkerPlugin.js +5 -5
- package/lib/dependencies/getFunctionExpression.js +1 -1
- package/lib/esm/ModuleChunkFormatPlugin.js +5 -5
- package/lib/esm/ModuleChunkLoadingPlugin.js +2 -2
- package/lib/esm/ModuleChunkLoadingRuntimeModule.js +15 -11
- package/lib/formatLocation.js +2 -2
- package/lib/hmr/HotModuleReplacement.runtime.js +39 -27
- package/lib/hmr/JavascriptHotModuleReplacement.runtime.js +43 -32
- package/lib/hmr/JavascriptHotModuleReplacementHelper.js +1 -1
- package/lib/hmr/LazyCompilationPlugin.js +6 -6
- package/lib/hmr/lazyCompilationBackend.js +6 -6
- package/lib/ids/ChunkModuleIdRangePlugin.js +4 -4
- package/lib/ids/DeterministicChunkIdsPlugin.js +5 -4
- package/lib/ids/DeterministicModuleIdsPlugin.js +2 -2
- package/lib/ids/HashedModuleIdsPlugin.js +1 -1
- package/lib/ids/IdHelpers.js +9 -9
- package/lib/ids/NamedChunkIdsPlugin.js +5 -5
- package/lib/ids/NamedModuleIdsPlugin.js +2 -2
- package/lib/ids/NaturalChunkIdsPlugin.js +2 -2
- package/lib/ids/NaturalModuleIdsPlugin.js +1 -1
- package/lib/ids/OccurrenceChunkIdsPlugin.js +2 -2
- package/lib/ids/OccurrenceModuleIdsPlugin.js +4 -4
- package/lib/ids/SyncModuleIdsPlugin.js +4 -4
- package/lib/index.js +10 -6
- package/lib/javascript/ArrayPushCallbackChunkFormatPlugin.js +1 -1
- package/lib/javascript/BasicEvaluatedExpression.js +3 -3
- package/lib/javascript/CommonJsChunkFormatPlugin.js +1 -1
- package/lib/javascript/EnableChunkLoadingPlugin.js +1 -1
- package/lib/javascript/JavascriptGenerator.js +1 -1
- package/lib/javascript/JavascriptModulesPlugin.js +16 -16
- package/lib/javascript/JavascriptParser.js +90 -83
- package/lib/javascript/JavascriptParserHelpers.js +3 -3
- package/lib/javascript/StartupHelpers.js +2 -2
- package/lib/json/JsonGenerator.js +2 -2
- package/lib/json/JsonModulesPlugin.js +2 -2
- package/lib/library/AbstractLibraryPlugin.js +3 -3
- package/lib/library/AmdLibraryPlugin.js +3 -3
- package/lib/library/AssignLibraryPlugin.js +2 -2
- package/lib/library/EnableLibraryPlugin.js +2 -2
- package/lib/library/ModuleLibraryPlugin.js +7 -2
- package/lib/library/SystemLibraryPlugin.js +6 -4
- package/lib/library/UmdLibraryPlugin.js +14 -14
- package/lib/logging/createConsoleLogger.js +4 -4
- package/lib/logging/runtime.js +3 -3
- package/lib/logging/truncateArgs.js +4 -4
- package/lib/node/CommonJsChunkLoadingPlugin.js +2 -2
- package/lib/node/NodeEnvironmentPlugin.js +1 -1
- package/lib/node/ReadFileChunkLoadingRuntimeModule.js +16 -14
- package/lib/node/ReadFileCompileAsyncWasmPlugin.js +7 -7
- package/lib/node/ReadFileCompileWasmPlugin.js +7 -7
- package/lib/node/RequireChunkLoadingRuntimeModule.js +6 -4
- package/lib/node/nodeConsole.js +2 -2
- package/lib/optimize/AggressiveMergingPlugin.js +2 -2
- package/lib/optimize/AggressiveSplittingPlugin.js +10 -10
- package/lib/optimize/ConcatenatedModule.js +161 -52
- package/lib/optimize/EnsureChunkConditionsPlugin.js +2 -2
- package/lib/optimize/FlagIncludedChunksPlugin.js +2 -2
- package/lib/optimize/InnerGraph.js +5 -5
- package/lib/optimize/InnerGraphPlugin.js +14 -12
- package/lib/optimize/LimitChunkCountPlugin.js +5 -5
- package/lib/optimize/MangleExportsPlugin.js +5 -5
- package/lib/optimize/MergeDuplicateChunksPlugin.js +2 -2
- package/lib/optimize/MinChunkSizePlugin.js +3 -3
- package/lib/optimize/ModuleConcatenationPlugin.js +45 -38
- package/lib/optimize/RealContentHashPlugin.js +23 -23
- package/lib/optimize/RemoveEmptyChunksPlugin.js +2 -2
- package/lib/optimize/RemoveParentModulesPlugin.js +3 -3
- package/lib/optimize/RuntimeChunkPlugin.js +2 -2
- package/lib/optimize/SideEffectsFlagPlugin.js +22 -6
- package/lib/optimize/SplitChunksPlugin.js +20 -20
- package/lib/performance/AssetsOverSizeLimitWarning.js +1 -1
- package/lib/performance/EntrypointsOverSizeLimitWarning.js +2 -2
- package/lib/performance/SizeLimitsPlugin.js +4 -4
- package/lib/prefetch/ChunkPrefetchPreloadPlugin.js +1 -1
- package/lib/prefetch/ChunkPrefetchStartupRuntimeModule.js +3 -3
- package/lib/rules/BasicMatcherRulePlugin.js +1 -1
- package/lib/rules/RuleSetCompiler.js +10 -10
- package/lib/rules/UseEffectRulePlugin.js +2 -2
- package/lib/runtime/GetChunkFilenameRuntimeModule.js +15 -15
- package/lib/runtime/GetMainFilenameRuntimeModule.js +1 -1
- package/lib/runtime/GetTrustedTypesPolicyRuntimeModule.js +1 -1
- package/lib/runtime/MakeDeferredNamespaceObjectRuntime.js +1 -1
- package/lib/runtime/StartupChunkDependenciesPlugin.js +2 -2
- package/lib/runtime/StartupChunkDependenciesRuntimeModule.js +3 -3
- package/lib/schemes/DataUriPlugin.js +3 -3
- package/lib/schemes/FileUriPlugin.js +1 -1
- package/lib/schemes/HttpUriPlugin.js +40 -36
- package/lib/schemes/VirtualUrlPlugin.js +1 -1
- package/lib/serialization/BinaryMiddleware.js +11 -11
- package/lib/serialization/FileMiddleware.js +17 -17
- package/lib/serialization/ObjectMiddleware.js +8 -8
- package/lib/serialization/Serializer.js +2 -2
- package/lib/serialization/SerializerMiddleware.js +2 -2
- package/lib/sharing/ConsumeSharedPlugin.js +4 -4
- package/lib/sharing/ProvideSharedPlugin.js +4 -4
- package/lib/sharing/SharePlugin.js +1 -1
- package/lib/sharing/resolveMatchedConfigs.js +1 -1
- package/lib/stats/DefaultStatsFactoryPlugin.js +86 -80
- package/lib/stats/DefaultStatsPresetPlugin.js +15 -15
- package/lib/stats/DefaultStatsPrinterPlugin.js +87 -87
- package/lib/stats/StatsFactory.js +7 -7
- package/lib/stats/StatsPrinter.js +9 -9
- package/lib/url/URLParserPlugin.js +5 -5
- package/lib/util/AsyncQueue.js +4 -4
- package/lib/util/IterableHelpers.js +2 -2
- package/lib/util/LazyBucketSortedSet.js +3 -3
- package/lib/util/SetHelpers.js +2 -2
- package/lib/util/StackedCacheMap.js +1 -1
- package/lib/util/StackedMap.js +1 -1
- package/lib/util/TupleSet.js +1 -1
- package/lib/util/WeakTupleMap.js +1 -1
- package/lib/util/cleverMerge.js +8 -8
- package/lib/util/comparators.js +107 -8
- package/lib/util/compileBooleanMatcher.js +20 -20
- package/lib/util/concatenate.js +3 -3
- package/lib/util/conventions.js +4 -4
- package/lib/util/create-schema-validation.js +1 -1
- package/lib/util/createHash.js +1 -1
- package/lib/util/deprecation.js +4 -4
- package/lib/util/deterministicGrouping.js +7 -7
- package/lib/util/findGraphRoots.js +1 -1
- package/lib/util/fs.js +3 -3
- package/lib/util/identifier.js +14 -14
- package/lib/util/magicComment.js +5 -1
- package/lib/util/memoize.js +1 -1
- package/lib/util/processAsyncTree.js +2 -2
- package/lib/util/propertyName.js +1 -1
- package/lib/util/removeBOM.js +1 -1
- package/lib/util/runtime.js +6 -6
- package/lib/util/semver.js +16 -16
- package/lib/util/serialization.js +5 -5
- package/lib/util/smartGrouping.js +1 -1
- package/lib/validateSchema.js +2 -2
- package/lib/wasm/EnableWasmLoadingPlugin.js +1 -1
- package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +1 -1
- package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +1 -1
- package/lib/wasm-async/UniversalCompileAsyncWasmPlugin.js +4 -4
- package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +13 -9
- package/lib/wasm-sync/WasmFinalizeExportsPlugin.js +2 -2
- package/lib/wasm-sync/WebAssemblyGenerator.js +14 -14
- package/lib/wasm-sync/WebAssemblyInInitialChunkError.js +4 -2
- package/lib/wasm-sync/WebAssemblyParser.js +2 -2
- package/lib/web/FetchCompileAsyncWasmPlugin.js +4 -4
- package/lib/web/FetchCompileWasmPlugin.js +4 -4
- package/lib/web/JsonpChunkLoadingPlugin.js +2 -2
- package/lib/web/JsonpChunkLoadingRuntimeModule.js +1 -1
- package/lib/webpack.js +17 -12
- package/lib/webworker/ImportScriptsChunkLoadingPlugin.js +2 -2
- package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +1 -1
- package/package.json +13 -13
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +4 -0
- package/types.d.ts +186 -54
|
@@ -186,7 +186,7 @@ const printGeneratedCodeForStack = (module, code) => {
|
|
|
186
186
|
* @property {SyncWaterfallHook<[Source, RenderContext]>} render
|
|
187
187
|
* @property {SyncWaterfallHook<[Source, Module, StartupRenderContext]>} renderStartup
|
|
188
188
|
* @property {SyncWaterfallHook<[string, RenderBootstrapContext]>} renderRequire
|
|
189
|
-
* @property {SyncBailHook<[Module, RenderBootstrapContext], string | void>} inlineInRuntimeBailout
|
|
189
|
+
* @property {SyncBailHook<[Module, Partial<RenderBootstrapContext>], string | void>} inlineInRuntimeBailout
|
|
190
190
|
* @property {SyncBailHook<[Module, RenderContext], string | void>} embedInRuntimeBailout
|
|
191
191
|
* @property {SyncBailHook<[RenderContext], string | void>} strictRuntimeBailout
|
|
192
192
|
* @property {SyncHook<[Chunk, Hash, ChunkHashContext]>} chunkHash
|
|
@@ -274,7 +274,7 @@ class JavascriptModulesPlugin {
|
|
|
274
274
|
]) {
|
|
275
275
|
normalModuleFactory.hooks.createParser
|
|
276
276
|
.for(type)
|
|
277
|
-
.tap(PLUGIN_NAME, _options => {
|
|
277
|
+
.tap(PLUGIN_NAME, (_options) => {
|
|
278
278
|
switch (type) {
|
|
279
279
|
case JAVASCRIPT_MODULE_TYPE_AUTO: {
|
|
280
280
|
return new JavascriptParser("auto");
|
|
@@ -417,7 +417,7 @@ class JavascriptModulesPlugin {
|
|
|
417
417
|
);
|
|
418
418
|
}
|
|
419
419
|
});
|
|
420
|
-
compilation.hooks.contentHash.tap(PLUGIN_NAME, chunk => {
|
|
420
|
+
compilation.hooks.contentHash.tap(PLUGIN_NAME, (chunk) => {
|
|
421
421
|
const {
|
|
422
422
|
chunkGraph,
|
|
423
423
|
codeGenerationResults,
|
|
@@ -713,7 +713,7 @@ class JavascriptModulesPlugin {
|
|
|
713
713
|
let allStrict = renderContext.strictMode;
|
|
714
714
|
if (
|
|
715
715
|
!allStrict &&
|
|
716
|
-
allModules.every(m => /** @type {BuildInfo} */ (m.buildInfo).strict)
|
|
716
|
+
allModules.every((m) => /** @type {BuildInfo} */ (m.buildInfo).strict)
|
|
717
717
|
) {
|
|
718
718
|
const strictBailout = hooks.strictRuntimeBailout.call(renderContext);
|
|
719
719
|
strictHeader = strictBailout
|
|
@@ -728,7 +728,7 @@ class JavascriptModulesPlugin {
|
|
|
728
728
|
strictMode: allStrict
|
|
729
729
|
};
|
|
730
730
|
const moduleSources =
|
|
731
|
-
Template.renderChunkModules(chunkRenderContext, allModules, module =>
|
|
731
|
+
Template.renderChunkModules(chunkRenderContext, allModules, (module) =>
|
|
732
732
|
this.renderModule(module, chunkRenderContext, hooks, true)
|
|
733
733
|
) || new RawSource("{}");
|
|
734
734
|
let source = tryRunOrWebpackError(
|
|
@@ -812,7 +812,7 @@ class JavascriptModulesPlugin {
|
|
|
812
812
|
let allStrict = renderContext.strictMode;
|
|
813
813
|
if (
|
|
814
814
|
!allStrict &&
|
|
815
|
-
allModules.every(m => /** @type {BuildInfo} */ (m.buildInfo).strict)
|
|
815
|
+
allModules.every((m) => /** @type {BuildInfo} */ (m.buildInfo).strict)
|
|
816
816
|
) {
|
|
817
817
|
const strictBailout = hooks.strictRuntimeBailout.call(renderContext);
|
|
818
818
|
if (strictBailout) {
|
|
@@ -838,10 +838,10 @@ class JavascriptModulesPlugin {
|
|
|
838
838
|
chunkRenderContext,
|
|
839
839
|
inlinedModules
|
|
840
840
|
? allModules.filter(
|
|
841
|
-
m => !(/** @type {Set<Module>} */ (inlinedModules).has(m))
|
|
841
|
+
(m) => !(/** @type {Set<Module>} */ (inlinedModules).has(m))
|
|
842
842
|
)
|
|
843
843
|
: allModules,
|
|
844
|
-
module => this.renderModule(module, chunkRenderContext, hooks, true),
|
|
844
|
+
(module) => this.renderModule(module, chunkRenderContext, hooks, true),
|
|
845
845
|
prefix
|
|
846
846
|
);
|
|
847
847
|
if (
|
|
@@ -1011,7 +1011,7 @@ class JavascriptModulesPlugin {
|
|
|
1011
1011
|
const toSource = useSourceMap
|
|
1012
1012
|
? (content, name) =>
|
|
1013
1013
|
new OriginalSource(Template.asString(content), name)
|
|
1014
|
-
: content => new RawSource(Template.asString(content));
|
|
1014
|
+
: (content) => new RawSource(Template.asString(content));
|
|
1015
1015
|
source.add(
|
|
1016
1016
|
new PrefixSource(
|
|
1017
1017
|
prefix,
|
|
@@ -1229,7 +1229,7 @@ class JavascriptModulesPlugin {
|
|
|
1229
1229
|
}
|
|
1230
1230
|
const chunks =
|
|
1231
1231
|
/** @type {Entrypoint} */
|
|
1232
|
-
(entrypoint).chunks.filter(c => c !== chunk);
|
|
1232
|
+
(entrypoint).chunks.filter((c) => c !== chunk);
|
|
1233
1233
|
if (result.allowInlineStartup && chunks.length > 0) {
|
|
1234
1234
|
buf2.push(
|
|
1235
1235
|
"// This entry module depends on other loaded chunks and execution need to be delayed"
|
|
@@ -1242,10 +1242,10 @@ class JavascriptModulesPlugin {
|
|
|
1242
1242
|
moduleGraph.getIncomingConnectionsByOriginModule(entryModule),
|
|
1243
1243
|
([originModule, connections]) =>
|
|
1244
1244
|
originModule &&
|
|
1245
|
-
connections.some(c => c.isTargetActive(chunk.runtime)) &&
|
|
1245
|
+
connections.some((c) => c.isTargetActive(chunk.runtime)) &&
|
|
1246
1246
|
someInIterable(
|
|
1247
1247
|
chunkGraph.getModuleRuntimes(originModule),
|
|
1248
|
-
runtime =>
|
|
1248
|
+
(runtime) =>
|
|
1249
1249
|
intersectRuntime(runtime, chunk.runtime) !== undefined
|
|
1250
1250
|
)
|
|
1251
1251
|
)
|
|
@@ -1309,7 +1309,7 @@ class JavascriptModulesPlugin {
|
|
|
1309
1309
|
`${i === 0 ? `var ${RuntimeGlobals.exports} = ` : ""}${
|
|
1310
1310
|
RuntimeGlobals.onChunksLoaded
|
|
1311
1311
|
}(undefined, ${JSON.stringify(
|
|
1312
|
-
chunks.map(c => c.id)
|
|
1312
|
+
chunks.map((c) => c.id)
|
|
1313
1313
|
)}, ${runtimeTemplate.returningFunction(
|
|
1314
1314
|
`${RuntimeGlobals.require}(${moduleIdExpr})`
|
|
1315
1315
|
)})`
|
|
@@ -1554,7 +1554,7 @@ class JavascriptModulesPlugin {
|
|
|
1554
1554
|
) {
|
|
1555
1555
|
const innerStrict =
|
|
1556
1556
|
!allStrict &&
|
|
1557
|
-
allModules.every(m => /** @type {BuildInfo} */ (m.buildInfo).strict);
|
|
1557
|
+
allModules.every((m) => /** @type {BuildInfo} */ (m.buildInfo).strict);
|
|
1558
1558
|
const isMultipleEntries = inlinedModules.size > 1;
|
|
1559
1559
|
const singleEntryWithModules = inlinedModules.size === 1 && hasChunkModules;
|
|
1560
1560
|
|
|
@@ -1639,7 +1639,7 @@ class JavascriptModulesPlugin {
|
|
|
1639
1639
|
|
|
1640
1640
|
const info = /** @type {Info} */ (inlinedModulesToInfo.get(m));
|
|
1641
1641
|
const allUsedNames = new Set(
|
|
1642
|
-
Array.from(info.through, v => v.identifier.name)
|
|
1642
|
+
Array.from(info.through, (v) => v.identifier.name)
|
|
1643
1643
|
);
|
|
1644
1644
|
|
|
1645
1645
|
for (const variable of usedInNonInlined) {
|
|
@@ -1660,7 +1660,7 @@ class JavascriptModulesPlugin {
|
|
|
1660
1660
|
if (allUsedNames.has(name) || usedNames.has(name)) {
|
|
1661
1661
|
const references = getAllReferences(variable);
|
|
1662
1662
|
const allIdentifiers = new Set([
|
|
1663
|
-
...references.map(r => r.identifier),
|
|
1663
|
+
...references.map((r) => r.identifier),
|
|
1664
1664
|
...variable.identifiers
|
|
1665
1665
|
]);
|
|
1666
1666
|
for (const ref of references) {
|
|
@@ -7,7 +7,6 @@
|
|
|
7
7
|
|
|
8
8
|
const vm = require("vm");
|
|
9
9
|
const { Parser: AcornParser, tokTypes } = require("acorn");
|
|
10
|
-
const acornImportPhases = require("acorn-import-phases");
|
|
11
10
|
const { HookMap, SyncBailHook } = require("tapable");
|
|
12
11
|
const Parser = require("../Parser");
|
|
13
12
|
const StackedMap = require("../util/StackedMap");
|
|
@@ -119,7 +118,7 @@ const ALLOWED_MEMBER_TYPES_ALL = 0b11;
|
|
|
119
118
|
const LEGACY_ASSERT_ATTRIBUTES = Symbol("assert");
|
|
120
119
|
|
|
121
120
|
/** @type {(BaseParser: typeof AcornParser) => typeof AcornParser} */
|
|
122
|
-
const importAssertions = Parser =>
|
|
121
|
+
const importAssertions = (Parser) =>
|
|
123
122
|
class extends Parser {
|
|
124
123
|
/**
|
|
125
124
|
* @this {InstanceType<AcornParser>}
|
|
@@ -182,10 +181,7 @@ const importAssertions = Parser =>
|
|
|
182
181
|
};
|
|
183
182
|
|
|
184
183
|
// Syntax: https://developer.mozilla.org/en/SpiderMonkey/Parser_API
|
|
185
|
-
|
|
186
|
-
importAssertions,
|
|
187
|
-
acornImportPhases({ source: false })
|
|
188
|
-
);
|
|
184
|
+
let parser = AcornParser.extend(importAssertions);
|
|
189
185
|
|
|
190
186
|
/** @typedef {Record<string, string> & { _isLegacyAssert?: boolean }} ImportAttributes */
|
|
191
187
|
|
|
@@ -193,7 +189,7 @@ const parser = AcornParser.extend(
|
|
|
193
189
|
* @param {ImportDeclaration | ExportNamedDeclaration | ExportAllDeclaration | ImportExpression} node node with assertions
|
|
194
190
|
* @returns {ImportAttributes | undefined} import attributes
|
|
195
191
|
*/
|
|
196
|
-
const getImportAttributes = node => {
|
|
192
|
+
const getImportAttributes = (node) => {
|
|
197
193
|
if (node.type === "ImportExpression") {
|
|
198
194
|
if (
|
|
199
195
|
node.options &&
|
|
@@ -365,7 +361,7 @@ const objectAndMembersToName = (object, membersReversed) => {
|
|
|
365
361
|
* @param {Expression | SpreadElement | Super} expression expression
|
|
366
362
|
* @returns {string | "this" | undefined} name or variable info
|
|
367
363
|
*/
|
|
368
|
-
const getRootName = expression => {
|
|
364
|
+
const getRootName = (expression) => {
|
|
369
365
|
switch (expression.type) {
|
|
370
366
|
case "Identifier":
|
|
371
367
|
return expression.name;
|
|
@@ -611,7 +607,7 @@ class JavascriptParser extends Parser {
|
|
|
611
607
|
}
|
|
612
608
|
|
|
613
609
|
_initializeEvaluating() {
|
|
614
|
-
this.hooks.evaluate.for("Literal").tap(CLASS_NAME, _expr => {
|
|
610
|
+
this.hooks.evaluate.for("Literal").tap(CLASS_NAME, (_expr) => {
|
|
615
611
|
const expr = /** @type {Literal} */ (_expr);
|
|
616
612
|
|
|
617
613
|
switch (typeof expr.value) {
|
|
@@ -643,7 +639,7 @@ class JavascriptParser extends Parser {
|
|
|
643
639
|
.setRange(/** @type {Range} */ (expr.range));
|
|
644
640
|
}
|
|
645
641
|
});
|
|
646
|
-
this.hooks.evaluate.for("NewExpression").tap(CLASS_NAME, _expr => {
|
|
642
|
+
this.hooks.evaluate.for("NewExpression").tap(CLASS_NAME, (_expr) => {
|
|
647
643
|
const expr = /** @type {NewExpression} */ (_expr);
|
|
648
644
|
const callee = expr.callee;
|
|
649
645
|
if (callee.type !== "Identifier") return;
|
|
@@ -708,7 +704,7 @@ class JavascriptParser extends Parser {
|
|
|
708
704
|
.setRegExp(flags ? new RegExp(regExp, flags) : new RegExp(regExp))
|
|
709
705
|
.setRange(/** @type {Range} */ (expr.range));
|
|
710
706
|
});
|
|
711
|
-
this.hooks.evaluate.for("LogicalExpression").tap(CLASS_NAME, _expr => {
|
|
707
|
+
this.hooks.evaluate.for("LogicalExpression").tap(CLASS_NAME, (_expr) => {
|
|
712
708
|
const expr = /** @type {LogicalExpression} */ (_expr);
|
|
713
709
|
|
|
714
710
|
const left = this.evaluateExpression(expr.left);
|
|
@@ -826,7 +822,7 @@ class JavascriptParser extends Parser {
|
|
|
826
822
|
}
|
|
827
823
|
};
|
|
828
824
|
|
|
829
|
-
this.hooks.evaluate.for("BinaryExpression").tap(CLASS_NAME, _expr => {
|
|
825
|
+
this.hooks.evaluate.for("BinaryExpression").tap(CLASS_NAME, (_expr) => {
|
|
830
826
|
const expr = /** @type {BinaryExpression} */ (_expr);
|
|
831
827
|
|
|
832
828
|
/**
|
|
@@ -835,7 +831,7 @@ class JavascriptParser extends Parser {
|
|
|
835
831
|
* @param {(leftOperand: T, rightOperand: T) => boolean | number | bigint | string} operandHandler the handler for the operation (e.g. (a, b) => a + b)
|
|
836
832
|
* @returns {BasicEvaluatedExpression | undefined} the evaluated expression
|
|
837
833
|
*/
|
|
838
|
-
const handleConstOperation = operandHandler => {
|
|
834
|
+
const handleConstOperation = (operandHandler) => {
|
|
839
835
|
const left = this.evaluateExpression(expr.left);
|
|
840
836
|
if (!left.isCompileTimeValue()) return;
|
|
841
837
|
|
|
@@ -875,7 +871,7 @@ class JavascriptParser extends Parser {
|
|
|
875
871
|
* @param {BasicEvaluatedExpression[]} parts parts
|
|
876
872
|
* @returns {string} value
|
|
877
873
|
*/
|
|
878
|
-
const getPrefix = parts => {
|
|
874
|
+
const getPrefix = (parts) => {
|
|
879
875
|
let value = "";
|
|
880
876
|
for (const p of parts) {
|
|
881
877
|
const v = p.asString();
|
|
@@ -888,7 +884,7 @@ class JavascriptParser extends Parser {
|
|
|
888
884
|
* @param {BasicEvaluatedExpression[]} parts parts
|
|
889
885
|
* @returns {string} value
|
|
890
886
|
*/
|
|
891
|
-
const getSuffix = parts => {
|
|
887
|
+
const getSuffix = (parts) => {
|
|
892
888
|
let value = "";
|
|
893
889
|
for (let i = parts.length - 1; i >= 0; i--) {
|
|
894
890
|
const v = parts[i].asString();
|
|
@@ -931,7 +927,7 @@ class JavascriptParser extends Parser {
|
|
|
931
927
|
* @param {boolean} eql true for "===" and false for "!=="
|
|
932
928
|
* @returns {BasicEvaluatedExpression | undefined} the evaluated expression
|
|
933
929
|
*/
|
|
934
|
-
const handleStrictEqualityComparison = eql => {
|
|
930
|
+
const handleStrictEqualityComparison = (eql) => {
|
|
935
931
|
const left = this.evaluateExpression(expr.left);
|
|
936
932
|
const right = this.evaluateExpression(expr.right);
|
|
937
933
|
const res = new BasicEvaluatedExpression();
|
|
@@ -993,7 +989,7 @@ class JavascriptParser extends Parser {
|
|
|
993
989
|
* @param {boolean} eql true for "==" and false for "!="
|
|
994
990
|
* @returns {BasicEvaluatedExpression | undefined} the evaluated expression
|
|
995
991
|
*/
|
|
996
|
-
const handleAbstractEqualityComparison = eql => {
|
|
992
|
+
const handleAbstractEqualityComparison = (eql) => {
|
|
997
993
|
const left = this.evaluateExpression(expr.left);
|
|
998
994
|
const right = this.evaluateExpression(expr.right);
|
|
999
995
|
const res = new BasicEvaluatedExpression();
|
|
@@ -1229,7 +1225,7 @@ class JavascriptParser extends Parser {
|
|
|
1229
1225
|
return handleConstOperation((l, r) => l >= r);
|
|
1230
1226
|
}
|
|
1231
1227
|
});
|
|
1232
|
-
this.hooks.evaluate.for("UnaryExpression").tap(CLASS_NAME, _expr => {
|
|
1228
|
+
this.hooks.evaluate.for("UnaryExpression").tap(CLASS_NAME, (_expr) => {
|
|
1233
1229
|
const expr = /** @type {UnaryExpression} */ (_expr);
|
|
1234
1230
|
|
|
1235
1231
|
/**
|
|
@@ -1238,7 +1234,7 @@ class JavascriptParser extends Parser {
|
|
|
1238
1234
|
* @param {(operand: T) => boolean | number | bigint | string} operandHandler handler for the operand
|
|
1239
1235
|
* @returns {BasicEvaluatedExpression | undefined} evaluated expression
|
|
1240
1236
|
*/
|
|
1241
|
-
const handleConstOperation = operandHandler => {
|
|
1237
|
+
const handleConstOperation = (operandHandler) => {
|
|
1242
1238
|
const argument = this.evaluateExpression(expr.argument);
|
|
1243
1239
|
if (!argument.isCompileTimeValue()) return;
|
|
1244
1240
|
const result = operandHandler(
|
|
@@ -1345,22 +1341,22 @@ class JavascriptParser extends Parser {
|
|
|
1345
1341
|
.setSideEffects(argument.couldHaveSideEffects())
|
|
1346
1342
|
.setRange(/** @type {Range} */ (expr.range));
|
|
1347
1343
|
} else if (expr.operator === "~") {
|
|
1348
|
-
return handleConstOperation(v => ~v);
|
|
1344
|
+
return handleConstOperation((v) => ~v);
|
|
1349
1345
|
} else if (expr.operator === "+") {
|
|
1350
1346
|
// eslint-disable-next-line no-implicit-coercion
|
|
1351
|
-
return handleConstOperation(v => +v);
|
|
1347
|
+
return handleConstOperation((v) => +v);
|
|
1352
1348
|
} else if (expr.operator === "-") {
|
|
1353
|
-
return handleConstOperation(v => -v);
|
|
1349
|
+
return handleConstOperation((v) => -v);
|
|
1354
1350
|
}
|
|
1355
1351
|
});
|
|
1356
1352
|
this.hooks.evaluateTypeof
|
|
1357
1353
|
.for("undefined")
|
|
1358
|
-
.tap(CLASS_NAME, expr =>
|
|
1354
|
+
.tap(CLASS_NAME, (expr) =>
|
|
1359
1355
|
new BasicEvaluatedExpression()
|
|
1360
1356
|
.setString("undefined")
|
|
1361
1357
|
.setRange(/** @type {Range} */ (expr.range))
|
|
1362
1358
|
);
|
|
1363
|
-
this.hooks.evaluate.for("Identifier").tap(CLASS_NAME, expr => {
|
|
1359
|
+
this.hooks.evaluate.for("Identifier").tap(CLASS_NAME, (expr) => {
|
|
1364
1360
|
if (/** @type {Identifier} */ (expr).name === "undefined") {
|
|
1365
1361
|
return new BasicEvaluatedExpression()
|
|
1366
1362
|
.setUndefined()
|
|
@@ -1377,7 +1373,7 @@ class JavascriptParser extends Parser {
|
|
|
1377
1373
|
let cachedExpression;
|
|
1378
1374
|
/** @type {GetInfoResult | undefined} */
|
|
1379
1375
|
let cachedInfo;
|
|
1380
|
-
this.hooks.evaluate.for(exprType).tap(CLASS_NAME, expr => {
|
|
1376
|
+
this.hooks.evaluate.for(exprType).tap(CLASS_NAME, (expr) => {
|
|
1381
1377
|
const expression =
|
|
1382
1378
|
/** @type {Identifier | ThisExpression | MemberExpression} */ (expr);
|
|
1383
1379
|
|
|
@@ -1386,12 +1382,12 @@ class JavascriptParser extends Parser {
|
|
|
1386
1382
|
return this.callHooksForInfoWithFallback(
|
|
1387
1383
|
this.hooks.evaluateIdentifier,
|
|
1388
1384
|
info.name,
|
|
1389
|
-
_name => {
|
|
1385
|
+
(_name) => {
|
|
1390
1386
|
cachedExpression = expression;
|
|
1391
1387
|
cachedInfo = info;
|
|
1392
1388
|
return undefined;
|
|
1393
1389
|
},
|
|
1394
|
-
name => {
|
|
1390
|
+
(name) => {
|
|
1395
1391
|
const hook = this.hooks.evaluateDefinedIdentifier.get(name);
|
|
1396
1392
|
if (hook !== undefined) {
|
|
1397
1393
|
return hook.call(expression);
|
|
@@ -1403,7 +1399,7 @@ class JavascriptParser extends Parser {
|
|
|
1403
1399
|
});
|
|
1404
1400
|
this.hooks.evaluate
|
|
1405
1401
|
.for(exprType)
|
|
1406
|
-
.tap({ name: CLASS_NAME, stage: 100 }, expr => {
|
|
1402
|
+
.tap({ name: CLASS_NAME, stage: 100 }, (expr) => {
|
|
1407
1403
|
const expression =
|
|
1408
1404
|
/** @type {Identifier | ThisExpression | MemberExpression} */
|
|
1409
1405
|
(expr);
|
|
@@ -1426,7 +1422,7 @@ class JavascriptParser extends Parser {
|
|
|
1426
1422
|
cachedExpression = cachedInfo = undefined;
|
|
1427
1423
|
});
|
|
1428
1424
|
};
|
|
1429
|
-
tapEvaluateWithVariableInfo("Identifier", expr => {
|
|
1425
|
+
tapEvaluateWithVariableInfo("Identifier", (expr) => {
|
|
1430
1426
|
const info = this.getVariableInfo(/** @type {Identifier} */ (expr).name);
|
|
1431
1427
|
if (
|
|
1432
1428
|
typeof info === "string" ||
|
|
@@ -1441,7 +1437,7 @@ class JavascriptParser extends Parser {
|
|
|
1441
1437
|
};
|
|
1442
1438
|
}
|
|
1443
1439
|
});
|
|
1444
|
-
tapEvaluateWithVariableInfo("ThisExpression", _expr => {
|
|
1440
|
+
tapEvaluateWithVariableInfo("ThisExpression", (_expr) => {
|
|
1445
1441
|
const info = this.getVariableInfo("this");
|
|
1446
1442
|
if (
|
|
1447
1443
|
typeof info === "string" ||
|
|
@@ -1456,7 +1452,7 @@ class JavascriptParser extends Parser {
|
|
|
1456
1452
|
};
|
|
1457
1453
|
}
|
|
1458
1454
|
});
|
|
1459
|
-
this.hooks.evaluate.for("MetaProperty").tap(CLASS_NAME, expr => {
|
|
1455
|
+
this.hooks.evaluate.for("MetaProperty").tap(CLASS_NAME, (expr) => {
|
|
1460
1456
|
const metaProperty = /** @type {MetaProperty} */ (expr);
|
|
1461
1457
|
|
|
1462
1458
|
return this.callHooksForName(
|
|
@@ -1466,14 +1462,14 @@ class JavascriptParser extends Parser {
|
|
|
1466
1462
|
metaProperty
|
|
1467
1463
|
);
|
|
1468
1464
|
});
|
|
1469
|
-
tapEvaluateWithVariableInfo("MemberExpression", expr =>
|
|
1465
|
+
tapEvaluateWithVariableInfo("MemberExpression", (expr) =>
|
|
1470
1466
|
this.getMemberExpressionInfo(
|
|
1471
1467
|
/** @type {MemberExpression} */ (expr),
|
|
1472
1468
|
ALLOWED_MEMBER_TYPES_EXPRESSION
|
|
1473
1469
|
)
|
|
1474
1470
|
);
|
|
1475
1471
|
|
|
1476
|
-
this.hooks.evaluate.for("CallExpression").tap(CLASS_NAME, _expr => {
|
|
1472
|
+
this.hooks.evaluate.for("CallExpression").tap(CLASS_NAME, (_expr) => {
|
|
1477
1473
|
const expr = /** @type {CallExpression} */ (_expr);
|
|
1478
1474
|
if (
|
|
1479
1475
|
expr.callee.type === "MemberExpression" &&
|
|
@@ -1645,7 +1641,7 @@ class JavascriptParser extends Parser {
|
|
|
1645
1641
|
};
|
|
1646
1642
|
};
|
|
1647
1643
|
|
|
1648
|
-
this.hooks.evaluate.for("TemplateLiteral").tap(CLASS_NAME, _node => {
|
|
1644
|
+
this.hooks.evaluate.for("TemplateLiteral").tap(CLASS_NAME, (_node) => {
|
|
1649
1645
|
const node = /** @type {TemplateLiteral} */ (_node);
|
|
1650
1646
|
|
|
1651
1647
|
const { quasis, parts } = getSimplifiedTemplateResult("cooked", node);
|
|
@@ -1658,7 +1654,7 @@ class JavascriptParser extends Parser {
|
|
|
1658
1654
|
});
|
|
1659
1655
|
this.hooks.evaluate
|
|
1660
1656
|
.for("TaggedTemplateExpression")
|
|
1661
|
-
.tap(CLASS_NAME, _node => {
|
|
1657
|
+
.tap(CLASS_NAME, (_node) => {
|
|
1662
1658
|
const node = /** @type {TaggedTemplateExpression} */ (_node);
|
|
1663
1659
|
const tag = this.evaluateExpression(node.tag);
|
|
1664
1660
|
|
|
@@ -1771,44 +1767,46 @@ class JavascriptParser extends Parser {
|
|
|
1771
1767
|
.setSideEffects(param.couldHaveSideEffects())
|
|
1772
1768
|
.setRange(/** @type {Range} */ (expr.range));
|
|
1773
1769
|
});
|
|
1774
|
-
this.hooks.evaluate
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
|
|
1779
|
-
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
|
|
1784
|
-
|
|
1785
|
-
res
|
|
1786
|
-
|
|
1787
|
-
|
|
1770
|
+
this.hooks.evaluate
|
|
1771
|
+
.for("ConditionalExpression")
|
|
1772
|
+
.tap(CLASS_NAME, (_expr) => {
|
|
1773
|
+
const expr = /** @type {ConditionalExpression} */ (_expr);
|
|
1774
|
+
|
|
1775
|
+
const condition = this.evaluateExpression(expr.test);
|
|
1776
|
+
const conditionValue = condition.asBool();
|
|
1777
|
+
let res;
|
|
1778
|
+
if (conditionValue === undefined) {
|
|
1779
|
+
const consequent = this.evaluateExpression(expr.consequent);
|
|
1780
|
+
const alternate = this.evaluateExpression(expr.alternate);
|
|
1781
|
+
res = new BasicEvaluatedExpression();
|
|
1782
|
+
if (consequent.isConditional()) {
|
|
1783
|
+
res.setOptions(
|
|
1784
|
+
/** @type {BasicEvaluatedExpression[]} */ (consequent.options)
|
|
1785
|
+
);
|
|
1786
|
+
} else {
|
|
1787
|
+
res.setOptions([consequent]);
|
|
1788
|
+
}
|
|
1789
|
+
if (alternate.isConditional()) {
|
|
1790
|
+
res.addOptions(
|
|
1791
|
+
/** @type {BasicEvaluatedExpression[]} */ (alternate.options)
|
|
1792
|
+
);
|
|
1793
|
+
} else {
|
|
1794
|
+
res.addOptions([alternate]);
|
|
1795
|
+
}
|
|
1788
1796
|
} else {
|
|
1789
|
-
res.
|
|
1790
|
-
|
|
1791
|
-
if (alternate.isConditional()) {
|
|
1792
|
-
res.addOptions(
|
|
1793
|
-
/** @type {BasicEvaluatedExpression[]} */ (alternate.options)
|
|
1797
|
+
res = this.evaluateExpression(
|
|
1798
|
+
conditionValue ? expr.consequent : expr.alternate
|
|
1794
1799
|
);
|
|
1795
|
-
|
|
1796
|
-
res.addOptions([alternate]);
|
|
1800
|
+
if (condition.couldHaveSideEffects()) res.setSideEffects();
|
|
1797
1801
|
}
|
|
1798
|
-
|
|
1799
|
-
res
|
|
1800
|
-
|
|
1801
|
-
|
|
1802
|
-
if (condition.couldHaveSideEffects()) res.setSideEffects();
|
|
1803
|
-
}
|
|
1804
|
-
res.setRange(/** @type {Range} */ (expr.range));
|
|
1805
|
-
return res;
|
|
1806
|
-
});
|
|
1807
|
-
this.hooks.evaluate.for("ArrayExpression").tap(CLASS_NAME, _expr => {
|
|
1802
|
+
res.setRange(/** @type {Range} */ (expr.range));
|
|
1803
|
+
return res;
|
|
1804
|
+
});
|
|
1805
|
+
this.hooks.evaluate.for("ArrayExpression").tap(CLASS_NAME, (_expr) => {
|
|
1808
1806
|
const expr = /** @type {ArrayExpression} */ (_expr);
|
|
1809
1807
|
|
|
1810
1808
|
const items = expr.elements.map(
|
|
1811
|
-
element =>
|
|
1809
|
+
(element) =>
|
|
1812
1810
|
element !== null &&
|
|
1813
1811
|
element.type !== "SpreadElement" &&
|
|
1814
1812
|
this.evaluateExpression(element)
|
|
@@ -1818,7 +1816,7 @@ class JavascriptParser extends Parser {
|
|
|
1818
1816
|
.setItems(/** @type {BasicEvaluatedExpression[]} */ (items))
|
|
1819
1817
|
.setRange(/** @type {Range} */ (expr.range));
|
|
1820
1818
|
});
|
|
1821
|
-
this.hooks.evaluate.for("ChainExpression").tap(CLASS_NAME, _expr => {
|
|
1819
|
+
this.hooks.evaluate.for("ChainExpression").tap(CLASS_NAME, (_expr) => {
|
|
1822
1820
|
const expr = /** @type {ChainExpression} */ (_expr);
|
|
1823
1821
|
/** @type {Expression[]} */
|
|
1824
1822
|
const optionalExpressionsStack = [];
|
|
@@ -2684,7 +2682,7 @@ class JavascriptParser extends Parser {
|
|
|
2684
2682
|
this.prevStatement = prev;
|
|
2685
2683
|
this.blockPreWalkStatement(statement.declaration);
|
|
2686
2684
|
let index = 0;
|
|
2687
|
-
this.enterDeclaration(statement.declaration, def => {
|
|
2685
|
+
this.enterDeclaration(statement.declaration, (def) => {
|
|
2688
2686
|
this.hooks.exportSpecifier.call(statement, def, def, index++);
|
|
2689
2687
|
});
|
|
2690
2688
|
}
|
|
@@ -3065,7 +3063,7 @@ class JavascriptParser extends Parser {
|
|
|
3065
3063
|
this.inBlockScope(() => {
|
|
3066
3064
|
// Error binding is optional in catch clause since ECMAScript 2019
|
|
3067
3065
|
if (catchClause.param !== null) {
|
|
3068
|
-
this.enterPattern(catchClause.param, ident => {
|
|
3066
|
+
this.enterPattern(catchClause.param, (ident) => {
|
|
3069
3067
|
this.defineVariable(ident);
|
|
3070
3068
|
});
|
|
3071
3069
|
this.walkPattern(catchClause.param);
|
|
@@ -3624,7 +3622,7 @@ class JavascriptParser extends Parser {
|
|
|
3624
3622
|
* @param {Expression | SpreadElement} argOrThis arg or this
|
|
3625
3623
|
* @returns {string | VariableInfo | undefined} var info
|
|
3626
3624
|
*/
|
|
3627
|
-
const getVarInfo = argOrThis => {
|
|
3625
|
+
const getVarInfo = (argOrThis) => {
|
|
3628
3626
|
const renameIdentifier = this.getRenameIdentifier(argOrThis);
|
|
3629
3627
|
if (
|
|
3630
3628
|
renameIdentifier &&
|
|
@@ -3706,8 +3704,8 @@ class JavascriptParser extends Parser {
|
|
|
3706
3704
|
* @param {FunctionExpression | ArrowFunctionExpression} fn function
|
|
3707
3705
|
* @returns {boolean} true when simple function
|
|
3708
3706
|
*/
|
|
3709
|
-
const isSimpleFunction = fn =>
|
|
3710
|
-
fn.params.every(p => p.type === "Identifier");
|
|
3707
|
+
const isSimpleFunction = (fn) =>
|
|
3708
|
+
fn.params.every((p) => p.type === "Identifier");
|
|
3711
3709
|
if (
|
|
3712
3710
|
expression.callee.type === "MemberExpression" &&
|
|
3713
3711
|
expression.callee.object.type.endsWith("FunctionExpression") &&
|
|
@@ -3980,7 +3978,7 @@ class JavascriptParser extends Parser {
|
|
|
3980
3978
|
hookMap,
|
|
3981
3979
|
members.length === 0 ? exprName.rootInfo : exprName.name,
|
|
3982
3980
|
fallback &&
|
|
3983
|
-
(name => fallback(name, exprName.rootInfo, exprName.getMembers)),
|
|
3981
|
+
((name) => fallback(name, exprName.rootInfo, exprName.getMembers)),
|
|
3984
3982
|
defined && (() => defined(exprName.name)),
|
|
3985
3983
|
...args
|
|
3986
3984
|
);
|
|
@@ -4114,7 +4112,7 @@ class JavascriptParser extends Parser {
|
|
|
4114
4112
|
|
|
4115
4113
|
this.undefineVariable("this");
|
|
4116
4114
|
|
|
4117
|
-
this.enterPatterns(params, ident => {
|
|
4115
|
+
this.enterPatterns(params, (ident) => {
|
|
4118
4116
|
this.defineVariable(ident);
|
|
4119
4117
|
});
|
|
4120
4118
|
|
|
@@ -4146,7 +4144,7 @@ class JavascriptParser extends Parser {
|
|
|
4146
4144
|
this.undefineVariable("this");
|
|
4147
4145
|
}
|
|
4148
4146
|
|
|
4149
|
-
this.enterPatterns(params, ident => {
|
|
4147
|
+
this.enterPatterns(params, (ident) => {
|
|
4150
4148
|
this.defineVariable(ident);
|
|
4151
4149
|
});
|
|
4152
4150
|
|
|
@@ -4178,7 +4176,7 @@ class JavascriptParser extends Parser {
|
|
|
4178
4176
|
this.undefineVariable("this");
|
|
4179
4177
|
}
|
|
4180
4178
|
|
|
4181
|
-
this.enterPatterns(params, ident => {
|
|
4179
|
+
this.enterPatterns(params, (ident) => {
|
|
4182
4180
|
this.defineVariable(ident);
|
|
4183
4181
|
});
|
|
4184
4182
|
|
|
@@ -4517,7 +4515,7 @@ class JavascriptParser extends Parser {
|
|
|
4517
4515
|
ast = JavascriptParser._parse(source, {
|
|
4518
4516
|
sourceType: this.sourceType,
|
|
4519
4517
|
onComment: comments,
|
|
4520
|
-
onInsertedSemicolon: pos => semicolons.add(pos)
|
|
4518
|
+
onInsertedSemicolon: (pos) => semicolons.add(pos)
|
|
4521
4519
|
});
|
|
4522
4520
|
}
|
|
4523
4521
|
|
|
@@ -4600,7 +4598,7 @@ class JavascriptParser extends Parser {
|
|
|
4600
4598
|
return false;
|
|
4601
4599
|
}
|
|
4602
4600
|
const items = expr.body.body;
|
|
4603
|
-
return items.every(item => {
|
|
4601
|
+
return items.every((item) => {
|
|
4604
4602
|
if (item.type === "StaticBlock") {
|
|
4605
4603
|
return false;
|
|
4606
4604
|
}
|
|
@@ -4653,7 +4651,7 @@ class JavascriptParser extends Parser {
|
|
|
4653
4651
|
return true;
|
|
4654
4652
|
|
|
4655
4653
|
case "VariableDeclaration":
|
|
4656
|
-
return expr.declarations.every(decl =>
|
|
4654
|
+
return expr.declarations.every((decl) =>
|
|
4657
4655
|
this.isPure(decl.init, /** @type {Range} */ (decl.range)[0])
|
|
4658
4656
|
);
|
|
4659
4657
|
|
|
@@ -4677,7 +4675,7 @@ class JavascriptParser extends Parser {
|
|
|
4677
4675
|
);
|
|
4678
4676
|
|
|
4679
4677
|
case "SequenceExpression":
|
|
4680
|
-
return expr.expressions.every(expr => {
|
|
4678
|
+
return expr.expressions.every((expr) => {
|
|
4681
4679
|
const pureFlag = this.isPure(expr, commentsStartPos);
|
|
4682
4680
|
commentsStartPos = /** @type {Range} */ (expr.range)[1];
|
|
4683
4681
|
return pureFlag;
|
|
@@ -4690,13 +4688,13 @@ class JavascriptParser extends Parser {
|
|
|
4690
4688
|
commentsStartPos,
|
|
4691
4689
|
/** @type {Range} */ (expr.range)[0]
|
|
4692
4690
|
]).some(
|
|
4693
|
-
comment =>
|
|
4691
|
+
(comment) =>
|
|
4694
4692
|
comment.type === "Block" &&
|
|
4695
4693
|
/^\s*(#|@)__PURE__\s*$/.test(comment.value)
|
|
4696
4694
|
);
|
|
4697
4695
|
if (!pureFlag) return false;
|
|
4698
4696
|
commentsStartPos = /** @type {Range} */ (expr.callee.range)[1];
|
|
4699
|
-
return expr.arguments.every(arg => {
|
|
4697
|
+
return expr.arguments.every((arg) => {
|
|
4700
4698
|
if (arg.type === "SpreadElement") return false;
|
|
4701
4699
|
const pureFlag = this.isPure(arg, commentsStartPos);
|
|
4702
4700
|
commentsStartPos = /** @type {Range} */ (arg.range)[1];
|
|
@@ -5135,6 +5133,15 @@ class JavascriptParser extends Parser {
|
|
|
5135
5133
|
|
|
5136
5134
|
return /** @type {Program} */ (ast);
|
|
5137
5135
|
}
|
|
5136
|
+
|
|
5137
|
+
/**
|
|
5138
|
+
* @param {((BaseParser: typeof AcornParser) => typeof AcornParser)[]} plugins parser plugin
|
|
5139
|
+
* @returns {typeof JavascriptParser} parser
|
|
5140
|
+
*/
|
|
5141
|
+
static extend(...plugins) {
|
|
5142
|
+
parser = parser.extend(...plugins);
|
|
5143
|
+
return JavascriptParser;
|
|
5144
|
+
}
|
|
5138
5145
|
}
|
|
5139
5146
|
|
|
5140
5147
|
module.exports = JavascriptParser;
|
|
@@ -21,7 +21,7 @@ module.exports.approve = () => true;
|
|
|
21
21
|
* @param {boolean} value the boolean value
|
|
22
22
|
* @returns {(expression: Expression) => BasicEvaluatedExpression} plugin function
|
|
23
23
|
*/
|
|
24
|
-
module.exports.evaluateToBoolean = value =>
|
|
24
|
+
module.exports.evaluateToBoolean = (value) =>
|
|
25
25
|
function booleanExpression(expr) {
|
|
26
26
|
return new BasicEvaluatedExpression()
|
|
27
27
|
.setBoolean(value)
|
|
@@ -65,7 +65,7 @@ module.exports.evaluateToIdentifier = (
|
|
|
65
65
|
* @param {number} value the number value
|
|
66
66
|
* @returns {(expression: Expression) => BasicEvaluatedExpression} plugin function
|
|
67
67
|
*/
|
|
68
|
-
module.exports.evaluateToNumber = value =>
|
|
68
|
+
module.exports.evaluateToNumber = (value) =>
|
|
69
69
|
function stringExpression(expr) {
|
|
70
70
|
return new BasicEvaluatedExpression()
|
|
71
71
|
.setNumber(value)
|
|
@@ -76,7 +76,7 @@ module.exports.evaluateToNumber = value =>
|
|
|
76
76
|
* @param {string} value the string value
|
|
77
77
|
* @returns {(expression: Expression) => BasicEvaluatedExpression} plugin function
|
|
78
78
|
*/
|
|
79
|
-
module.exports.evaluateToString = value =>
|
|
79
|
+
module.exports.evaluateToString = (value) =>
|
|
80
80
|
function stringExpression(expr) {
|
|
81
81
|
return new BasicEvaluatedExpression()
|
|
82
82
|
.setString(value)
|
|
@@ -54,7 +54,7 @@ module.exports.generateEntryStartup = (
|
|
|
54
54
|
* @param {ModuleId} id id
|
|
55
55
|
* @returns {string} fn to execute
|
|
56
56
|
*/
|
|
57
|
-
const runModule = id => `__webpack_exec__(${JSON.stringify(id)})`;
|
|
57
|
+
const runModule = (id) => `__webpack_exec__(${JSON.stringify(id)})`;
|
|
58
58
|
/**
|
|
59
59
|
* @param {Chunks} chunks chunks
|
|
60
60
|
* @param {ModuleIds} moduleIds module ids
|
|
@@ -74,7 +74,7 @@ module.exports.generateEntryStartup = (
|
|
|
74
74
|
passive
|
|
75
75
|
? RuntimeGlobals.onChunksLoaded
|
|
76
76
|
: RuntimeGlobals.startupEntrypoint
|
|
77
|
-
}(0, ${JSON.stringify(Array.from(chunks, c => c.id))}, ${fn});`
|
|
77
|
+
}(0, ${JSON.stringify(Array.from(chunks, (c) => c.id))}, ${fn});`
|
|
78
78
|
);
|
|
79
79
|
if (final && passive) {
|
|
80
80
|
runtime.push(`${EXPORT_PREFIX}${RuntimeGlobals.onChunksLoaded}();`);
|
|
@@ -29,13 +29,13 @@ const RuntimeGlobals = require("../RuntimeGlobals");
|
|
|
29
29
|
* @param {JsonValue} data Raw JSON data
|
|
30
30
|
* @returns {undefined|string} stringified data
|
|
31
31
|
*/
|
|
32
|
-
const stringifySafe = data => {
|
|
32
|
+
const stringifySafe = (data) => {
|
|
33
33
|
const stringified = JSON.stringify(data);
|
|
34
34
|
if (!stringified) {
|
|
35
35
|
return; // Invalid JSON
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
-
return stringified.replace(/\u2028|\u2029/g, str =>
|
|
38
|
+
return stringified.replace(/\u2028|\u2029/g, (str) =>
|
|
39
39
|
str === "\u2029" ? "\\u2029" : "\\u2028"
|
|
40
40
|
); // invalid in JavaScript but valid JSON
|
|
41
41
|
};
|