webpack 5.106.2 → 5.107.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 +2 -2
- package/lib/APIPlugin.js +1 -1
- package/lib/Cache.js +3 -6
- package/lib/CompatibilityPlugin.js +8 -7
- package/lib/Compilation.js +34 -26
- package/lib/Compiler.js +4 -13
- package/lib/ContextModule.js +2 -2
- package/lib/DefinePlugin.js +2 -2
- package/lib/Dependency.js +22 -1
- package/lib/DependencyTemplate.js +2 -1
- package/lib/EnvironmentPlugin.js +1 -1
- package/lib/EvalSourceMapDevToolPlugin.js +8 -9
- package/lib/ExternalModule.js +76 -15
- package/lib/ExternalModuleFactoryPlugin.js +5 -0
- package/lib/FileSystemInfo.js +187 -72
- package/lib/Generator.js +3 -3
- package/lib/HotModuleReplacementPlugin.js +26 -8
- package/lib/IgnorePlugin.js +2 -1
- package/lib/Module.js +19 -18
- package/lib/ModuleFactory.js +1 -1
- package/lib/ModuleSourceTypeConstants.js +31 -1
- package/lib/ModuleTypeConstants.js +12 -3
- package/lib/MultiCompiler.js +2 -2
- package/lib/NodeStuffPlugin.js +1 -1
- package/lib/NormalModule.js +13 -31
- package/lib/NormalModuleFactory.js +10 -2
- package/lib/Parser.js +1 -1
- package/lib/ProgressPlugin.js +129 -56
- package/lib/RuntimeGlobals.js +5 -5
- package/lib/RuntimeModule.js +9 -7
- package/lib/RuntimePlugin.js +11 -0
- package/lib/WarnCaseSensitiveModulesPlugin.js +70 -2
- package/lib/WarnDeprecatedOptionPlugin.js +1 -1
- package/lib/WarnNoModeSetPlugin.js +16 -1
- package/lib/Watching.js +2 -3
- package/lib/WebpackError.js +3 -77
- package/lib/WebpackIsIncludedPlugin.js +1 -1
- package/lib/WebpackOptionsApply.js +13 -1
- package/lib/asset/AssetBytesGenerator.js +6 -2
- package/lib/asset/AssetGenerator.js +22 -8
- package/lib/asset/AssetModulesPlugin.js +3 -1
- package/lib/asset/AssetSourceGenerator.js +6 -2
- package/lib/buildChunkGraph.js +4 -6
- package/lib/cache/PackFileCacheStrategy.js +4 -4
- package/lib/cli.js +3 -1
- package/lib/config/defaults.js +197 -10
- package/lib/config/normalization.js +3 -1
- package/lib/css/CssGenerator.js +320 -105
- package/lib/css/CssInjectStyleRuntimeModule.js +44 -42
- package/lib/css/CssLoadingRuntimeModule.js +22 -4
- package/lib/{CssModule.js → css/CssModule.js} +15 -15
- package/lib/css/CssModulesPlugin.js +166 -86
- package/lib/css/CssParser.js +566 -269
- package/lib/css/walkCssTokens.js +148 -2
- package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +1 -1
- package/lib/dependencies/CommonJsDependencyHelpers.js +63 -0
- package/lib/dependencies/CommonJsExportRequireDependency.js +54 -10
- package/lib/dependencies/CommonJsExportsParserPlugin.js +1 -1
- package/lib/dependencies/CommonJsFullRequireDependency.js +32 -9
- package/lib/dependencies/CommonJsImportsParserPlugin.js +4 -3
- package/lib/dependencies/CommonJsRequireDependency.js +67 -4
- package/lib/dependencies/ContextDependency.js +1 -1
- package/lib/dependencies/ContextDependencyHelpers.js +1 -1
- package/lib/dependencies/CreateRequireParserPlugin.js +1 -1
- package/lib/dependencies/CriticalDependencyWarning.js +1 -1
- package/lib/dependencies/CssIcssExportDependency.js +332 -67
- package/lib/dependencies/CssIcssImportDependency.js +49 -7
- package/lib/dependencies/CssIcssSymbolDependency.js +11 -3
- package/lib/dependencies/CssImportDependency.js +8 -0
- package/lib/dependencies/CssUrlDependency.js +25 -0
- package/lib/dependencies/HarmonyDetectionParserPlugin.js +1 -1
- package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +8 -7
- package/lib/dependencies/HarmonyExportExpressionDependency.js +22 -14
- package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +110 -3
- package/lib/dependencies/HarmonyImportDependency.js +10 -2
- package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +22 -1
- package/lib/dependencies/HarmonyImportSpecifierDependency.js +1 -1
- package/lib/{HarmonyLinkingError.js → dependencies/HarmonyLinkingError.js} +5 -3
- package/lib/dependencies/HtmlInlineScriptDependency.js +133 -0
- package/lib/dependencies/HtmlInlineStyleDependency.js +101 -0
- package/lib/dependencies/HtmlScriptSrcDependency.js +318 -0
- package/lib/dependencies/HtmlSourceDependency.js +127 -0
- package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +1 -1
- package/lib/dependencies/ImportParserPlugin.js +2 -2
- package/lib/dependencies/ImportPhase.js +1 -1
- package/lib/dependencies/RequireIncludeDependencyParserPlugin.js +1 -1
- package/lib/{RequireJsStuffPlugin.js → dependencies/RequireJsStuffPlugin.js} +7 -7
- package/lib/dependencies/SystemPlugin.js +1 -1
- package/lib/dependencies/WebAssemblyImportDependency.js +1 -1
- package/lib/dependencies/WorkerPlugin.js +2 -2
- package/lib/{DelegatedModule.js → dll/DelegatedModule.js} +31 -31
- package/lib/{DelegatedModuleFactoryPlugin.js → dll/DelegatedModuleFactoryPlugin.js} +4 -4
- package/lib/{DelegatedPlugin.js → dll/DelegatedPlugin.js} +2 -2
- package/lib/{DllEntryPlugin.js → dll/DllEntryPlugin.js} +4 -4
- package/lib/{DllModule.js → dll/DllModule.js} +24 -24
- package/lib/{DllModuleFactory.js → dll/DllModuleFactory.js} +4 -4
- package/lib/{DllPlugin.js → dll/DllPlugin.js} +6 -5
- package/lib/{DllReferencePlugin.js → dll/DllReferencePlugin.js} +14 -14
- package/lib/{LibManifestPlugin.js → dll/LibManifestPlugin.js} +9 -9
- package/lib/{AsyncDependencyToInitialChunkError.js → errors/AsyncDependencyToInitialChunkError.js} +2 -2
- package/lib/errors/BuildCycleError.js +1 -1
- package/lib/{ChunkRenderError.js → errors/ChunkRenderError.js} +1 -1
- package/lib/{CodeGenerationError.js → errors/CodeGenerationError.js} +1 -1
- package/lib/{CommentCompilationWarning.js → errors/CommentCompilationWarning.js} +3 -3
- package/lib/{ConcurrentCompilationError.js → errors/ConcurrentCompilationError.js} +4 -2
- package/lib/{EnvironmentNotSupportAsyncWarning.js → errors/EnvironmentNotSupportAsyncWarning.js} +4 -4
- package/lib/{HookWebpackError.js → errors/HookWebpackError.js} +5 -5
- package/lib/{IgnoreErrorModuleFactory.js → errors/IgnoreErrorModuleFactory.js} +4 -4
- package/lib/{InvalidDependenciesModuleWarning.js → errors/InvalidDependenciesModuleWarning.js} +3 -3
- package/lib/errors/JSONParseError.js +114 -0
- package/lib/{ModuleBuildError.js → errors/ModuleBuildError.js} +5 -5
- package/lib/{ModuleDependencyError.js → errors/ModuleDependencyError.js} +2 -2
- package/lib/{ModuleDependencyWarning.js → errors/ModuleDependencyWarning.js} +4 -4
- package/lib/{ModuleError.js → errors/ModuleError.js} +5 -5
- package/lib/{ModuleHashingError.js → errors/ModuleHashingError.js} +1 -1
- package/lib/{ModuleNotFoundError.js → errors/ModuleNotFoundError.js} +2 -2
- package/lib/{ModuleParseError.js → errors/ModuleParseError.js} +8 -6
- package/lib/{ModuleRestoreError.js → errors/ModuleRestoreError.js} +1 -1
- package/lib/{ModuleStoreError.js → errors/ModuleStoreError.js} +1 -1
- package/lib/{ModuleWarning.js → errors/ModuleWarning.js} +5 -5
- package/lib/{NodeStuffInWebError.js → errors/NodeStuffInWebError.js} +4 -4
- package/lib/errors/NonErrorEmittedError.js +28 -0
- package/lib/{UnhandledSchemeError.js → errors/UnhandledSchemeError.js} +2 -2
- package/lib/{UnsupportedFeatureWarning.js → errors/UnsupportedFeatureWarning.js} +3 -3
- package/lib/errors/WebpackError.js +84 -0
- package/lib/html/HtmlGenerator.js +379 -0
- package/lib/html/HtmlModulesPlugin.js +433 -0
- package/lib/html/HtmlParser.js +1489 -0
- package/lib/html/walkHtmlTokens.js +2733 -0
- package/lib/ids/IdHelpers.js +2 -1
- package/lib/index.js +34 -15
- package/lib/javascript/JavascriptModulesPlugin.js +89 -8
- package/lib/javascript/JavascriptParser.js +197 -16
- package/lib/javascript/JavascriptParserHelpers.js +1 -1
- package/lib/json/JsonParser.js +7 -16
- package/lib/library/AbstractLibraryPlugin.js +1 -1
- package/lib/library/EnableLibraryPlugin.js +1 -1
- package/lib/{FalseIIFEUmdWarning.js → library/FalseIIFEUmdWarning.js} +1 -1
- package/lib/library/ModuleLibraryPlugin.js +74 -0
- package/lib/node/NodeEnvironmentPlugin.js +4 -2
- package/lib/node/nodeConsole.js +113 -64
- package/lib/optimize/ConcatenatedModule.js +51 -6
- package/lib/optimize/InnerGraph.js +1 -1
- package/lib/optimize/InnerGraphPlugin.js +11 -1
- package/lib/optimize/MinMaxSizeWarning.js +4 -4
- package/lib/optimize/ModuleConcatenationPlugin.js +15 -7
- package/lib/optimize/RealContentHashPlugin.js +89 -26
- package/lib/optimize/SideEffectsFlagPlugin.js +111 -3
- package/lib/optimize/SplitChunksPlugin.js +1 -1
- package/lib/performance/AssetsOverSizeLimitWarning.js +2 -2
- package/lib/performance/EntrypointsOverSizeLimitWarning.js +2 -2
- package/lib/performance/NoAsyncChunksWarning.js +5 -3
- package/lib/performance/SizeLimitsPlugin.js +1 -1
- package/lib/prefetch/ChunkPrefetchTriggerRuntimeModule.js +4 -1
- package/lib/rules/UseEffectRulePlugin.js +4 -3
- package/lib/runtime/MakeDeferredNamespaceObjectRuntime.js +119 -13
- package/lib/runtime/SetAnonymousDefaultNameRuntimeModule.js +35 -0
- package/lib/schemes/DataUriPlugin.js +13 -1
- package/lib/schemes/VirtualUrlPlugin.js +1 -1
- package/lib/serialization/SerializerMiddleware.js +2 -2
- package/lib/sharing/ConsumeSharedPlugin.js +2 -2
- package/lib/sharing/ConsumeSharedRuntimeModule.js +8 -4
- package/lib/sharing/ProvideSharedModule.js +1 -1
- package/lib/sharing/ProvideSharedPlugin.js +1 -1
- package/lib/sharing/resolveMatchedConfigs.js +1 -1
- package/lib/stats/DefaultStatsFactoryPlugin.js +2 -2
- package/lib/stats/DefaultStatsPresetPlugin.js +1 -1
- package/lib/stats/DefaultStatsPrinterPlugin.js +1 -1
- package/lib/stats/StatsFactory.js +1 -1
- package/lib/typescript/TypeScriptPlugin.js +210 -0
- package/lib/url/URLParserPlugin.js +2 -2
- package/lib/util/AsyncQueue.js +2 -2
- package/lib/util/Hash.js +2 -2
- package/lib/util/LocConverter.js +53 -0
- package/lib/util/SortableSet.js +1 -1
- package/lib/util/cleverMerge.js +2 -2
- package/lib/util/comparators.js +3 -3
- package/lib/util/concatenate.js +3 -3
- package/lib/util/conventions.js +42 -1
- package/lib/util/createMappings.js +118 -0
- package/lib/{formatLocation.js → util/formatLocation.js} +2 -2
- package/lib/{SizeFormatHelpers.js → util/formatSize.js} +3 -1
- package/lib/util/fs.js +8 -8
- package/lib/util/hash/md4.js +1 -1
- package/lib/util/hash/xxhash64.js +1 -1
- package/lib/util/identifier.js +48 -0
- package/lib/util/internalSerializables.js +35 -19
- package/lib/util/magicComment.js +10 -7
- package/lib/util/parseJson.js +2 -73
- package/lib/util/source.js +21 -0
- package/lib/util/topologicalSort.js +69 -0
- package/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js +2 -2
- package/lib/wasm-async/AsyncWebAssemblyParser.js +1 -1
- package/lib/wasm-sync/UnsupportedWebAssemblyFeatureError.js +5 -3
- package/lib/wasm-sync/WasmFinalizeExportsPlugin.js +1 -1
- package/lib/wasm-sync/WebAssemblyInInitialChunkError.js +5 -3
- package/lib/webpack.js +3 -1
- package/package.json +22 -20
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +118 -3
- package/schemas/plugins/{DllPlugin.check.d.ts → HtmlGeneratorOptions.check.d.ts} +1 -1
- package/schemas/plugins/HtmlGeneratorOptions.check.js +6 -0
- package/schemas/plugins/HtmlGeneratorOptions.json +3 -0
- package/schemas/plugins/ProgressPlugin.check.js +1 -1
- package/schemas/plugins/ProgressPlugin.json +22 -0
- package/schemas/plugins/{DllReferencePlugin.check.d.ts → css/CssAutoOrModuleParserOptions.check.d.ts} +1 -1
- package/schemas/plugins/css/CssAutoOrModuleParserOptions.check.js +6 -0
- package/schemas/plugins/css/CssAutoOrModuleParserOptions.json +3 -0
- package/schemas/plugins/dll/DllPlugin.check.d.ts +7 -0
- package/schemas/plugins/dll/DllReferencePlugin.check.d.ts +7 -0
- package/types.d.ts +810 -101
- package/lib/CaseSensitiveModulesWarning.js +0 -80
- package/lib/GraphHelpers.js +0 -49
- package/lib/NoModeWarning.js +0 -23
- package/lib/css/CssMergeStyleSheetsRuntimeModule.js +0 -57
- /package/lib/{AbstractMethodError.js → errors/AbstractMethodError.js} +0 -0
- /package/schemas/plugins/{DllPlugin.check.js → dll/DllPlugin.check.js} +0 -0
- /package/schemas/plugins/{DllPlugin.json → dll/DllPlugin.json} +0 -0
- /package/schemas/plugins/{DllReferencePlugin.check.js → dll/DllReferencePlugin.check.js} +0 -0
- /package/schemas/plugins/{DllReferencePlugin.json → dll/DllReferencePlugin.json} +0 -0
package/lib/ids/IdHelpers.js
CHANGED
|
@@ -263,7 +263,8 @@ const getUsedModuleIdsAndModules = (compilation, filter) => {
|
|
|
263
263
|
(!filter || filter(module)) &&
|
|
264
264
|
(chunkGraph.getNumberOfModuleChunks(module) !== 0 ||
|
|
265
265
|
// CSS modules need IDs even when not in chunks, for generating CSS class names(i.e. [id]-[local])
|
|
266
|
-
/** @type {BuildMeta} */ (module.buildMeta).
|
|
266
|
+
/** @type {BuildMeta} */ (module.buildMeta).isCssModule ||
|
|
267
|
+
/** @type {BuildMeta} */ (module.buildMeta).needIdInConcatenation)
|
|
267
268
|
) {
|
|
268
269
|
modules.push(module);
|
|
269
270
|
}
|
package/lib/index.js
CHANGED
|
@@ -160,7 +160,9 @@ module.exports = mergeExports(fn, {
|
|
|
160
160
|
*/
|
|
161
161
|
() => {
|
|
162
162
|
const validateSchema = require("./validateSchema");
|
|
163
|
-
const webpackOptionsSchema =
|
|
163
|
+
const webpackOptionsSchema =
|
|
164
|
+
/** @type {EXPECTED_ANY} */
|
|
165
|
+
(require("../schemas/WebpackOptions.json"));
|
|
164
166
|
|
|
165
167
|
return (options) => validateSchema(webpackOptionsSchema, options);
|
|
166
168
|
}
|
|
@@ -222,18 +224,9 @@ module.exports = mergeExports(fn, {
|
|
|
222
224
|
get DefinePlugin() {
|
|
223
225
|
return require("./DefinePlugin");
|
|
224
226
|
},
|
|
225
|
-
get DelegatedPlugin() {
|
|
226
|
-
return require("./DelegatedPlugin");
|
|
227
|
-
},
|
|
228
227
|
get Dependency() {
|
|
229
228
|
return require("./Dependency");
|
|
230
229
|
},
|
|
231
|
-
get DllPlugin() {
|
|
232
|
-
return require("./DllPlugin");
|
|
233
|
-
},
|
|
234
|
-
get DllReferencePlugin() {
|
|
235
|
-
return require("./DllReferencePlugin");
|
|
236
|
-
},
|
|
237
230
|
get DynamicEntryPlugin() {
|
|
238
231
|
return require("./DynamicEntryPlugin");
|
|
239
232
|
},
|
|
@@ -283,9 +276,6 @@ module.exports = mergeExports(fn, {
|
|
|
283
276
|
"DEP_WEBPACK_JAVASCRIPT_MODULES_PLUGIN"
|
|
284
277
|
)();
|
|
285
278
|
},
|
|
286
|
-
get LibManifestPlugin() {
|
|
287
|
-
return require("./LibManifestPlugin");
|
|
288
|
-
},
|
|
289
279
|
get LibraryTemplatePlugin() {
|
|
290
280
|
return util.deprecate(
|
|
291
281
|
() => require("./LibraryTemplatePlugin"),
|
|
@@ -376,7 +366,7 @@ module.exports = mergeExports(fn, {
|
|
|
376
366
|
return require("./WatchIgnorePlugin");
|
|
377
367
|
},
|
|
378
368
|
get WebpackError() {
|
|
379
|
-
return require("./WebpackError");
|
|
369
|
+
return require("./errors/WebpackError");
|
|
380
370
|
},
|
|
381
371
|
get WebpackOptionsApply() {
|
|
382
372
|
return require("./WebpackOptionsApply");
|
|
@@ -388,7 +378,7 @@ module.exports = mergeExports(fn, {
|
|
|
388
378
|
"DEP_WEBPACK_OPTIONS_DEFAULTER"
|
|
389
379
|
)();
|
|
390
380
|
},
|
|
391
|
-
// TODO webpack 6
|
|
381
|
+
// TODO webpack 6 remove
|
|
392
382
|
get WebpackOptionsValidationError() {
|
|
393
383
|
return require("schema-utils").ValidationError;
|
|
394
384
|
},
|
|
@@ -604,6 +594,35 @@ module.exports = mergeExports(fn, {
|
|
|
604
594
|
}
|
|
605
595
|
},
|
|
606
596
|
|
|
597
|
+
// TODO remove in webpack 6 in favor of `dll` scope
|
|
598
|
+
get DelegatedPlugin() {
|
|
599
|
+
return require("./dll/DelegatedPlugin");
|
|
600
|
+
},
|
|
601
|
+
get DllPlugin() {
|
|
602
|
+
return require("./dll/DllPlugin");
|
|
603
|
+
},
|
|
604
|
+
get DllReferencePlugin() {
|
|
605
|
+
return require("./dll/DllReferencePlugin");
|
|
606
|
+
},
|
|
607
|
+
get LibManifestPlugin() {
|
|
608
|
+
return require("./dll/LibManifestPlugin");
|
|
609
|
+
},
|
|
610
|
+
|
|
611
|
+
dll: {
|
|
612
|
+
get DelegatedPlugin() {
|
|
613
|
+
return require("./dll/DelegatedPlugin");
|
|
614
|
+
},
|
|
615
|
+
get DllPlugin() {
|
|
616
|
+
return require("./dll/DllPlugin");
|
|
617
|
+
},
|
|
618
|
+
get DllReferencePlugin() {
|
|
619
|
+
return require("./dll/DllReferencePlugin");
|
|
620
|
+
},
|
|
621
|
+
get LibManifestPlugin() {
|
|
622
|
+
return require("./dll/LibManifestPlugin");
|
|
623
|
+
}
|
|
624
|
+
},
|
|
625
|
+
|
|
607
626
|
container: {
|
|
608
627
|
get ContainerPlugin() {
|
|
609
628
|
return require("./container/ContainerPlugin");
|
|
@@ -17,7 +17,6 @@ const {
|
|
|
17
17
|
ReplaceSource
|
|
18
18
|
} = require("webpack-sources");
|
|
19
19
|
const Compilation = require("../Compilation");
|
|
20
|
-
const { tryRunOrWebpackError } = require("../HookWebpackError");
|
|
21
20
|
const HotUpdateChunk = require("../HotUpdateChunk");
|
|
22
21
|
const InitFragment = require("../InitFragment");
|
|
23
22
|
const { JAVASCRIPT_TYPE } = require("../ModuleSourceTypeConstants");
|
|
@@ -30,6 +29,7 @@ const {
|
|
|
30
29
|
const NormalModule = require("../NormalModule");
|
|
31
30
|
const RuntimeGlobals = require("../RuntimeGlobals");
|
|
32
31
|
const Template = require("../Template");
|
|
32
|
+
const { tryRunOrWebpackError } = require("../errors/HookWebpackError");
|
|
33
33
|
const { last, someInIterable } = require("../util/IterableHelpers");
|
|
34
34
|
const StringXor = require("../util/StringXor");
|
|
35
35
|
const { compareModulesByFullName } = require("../util/comparators");
|
|
@@ -48,10 +48,24 @@ const { intersectRuntime } = require("../util/runtime");
|
|
|
48
48
|
const JavascriptGenerator = require("./JavascriptGenerator");
|
|
49
49
|
const JavascriptParser = require("./JavascriptParser");
|
|
50
50
|
|
|
51
|
-
/** @typedef {import("eslint-scope").Reference} Reference */
|
|
52
|
-
/** @typedef {import("eslint-scope").Scope} Scope */
|
|
53
|
-
/** @typedef {import("eslint-scope").Variable} Variable */
|
|
54
51
|
/** @typedef {import("estree").Program} Program */
|
|
52
|
+
/** @typedef {import("estree").Node} Node */
|
|
53
|
+
/** @typedef {import("estree").Identifier} Identifier */
|
|
54
|
+
/** @typedef {import("estree").CatchClause} CatchClause */
|
|
55
|
+
/** @typedef {import("estree").ClassDeclaration} ClassDeclaration */
|
|
56
|
+
/** @typedef {import("estree").ClassExpression} ClassExpression */
|
|
57
|
+
/** @typedef {import("estree").FunctionDeclaration} FunctionDeclaration */
|
|
58
|
+
/** @typedef {import("estree").FunctionExpression} FunctionExpression */
|
|
59
|
+
/** @typedef {import("estree").ArrowFunctionExpression} ArrowFunctionExpression */
|
|
60
|
+
/** @typedef {import("estree").VariableDeclarator} VariableDeclarator */
|
|
61
|
+
/** @typedef {import("estree").VariableDeclaration} VariableDeclaration */
|
|
62
|
+
/** @typedef {import("estree").ImportDeclaration} ImportDeclaration */
|
|
63
|
+
/** @typedef {import("estree").ImportSpecifier} ImportSpecifier */
|
|
64
|
+
/** @typedef {import("estree").ImportDefaultSpecifier} ImportDefaultSpecifier */
|
|
65
|
+
/** @typedef {import("estree").ImportNamespaceSpecifier} ImportNamespaceSpecifier */
|
|
66
|
+
/** @typedef {import("estree").AssignmentExpression} AssignmentExpression */
|
|
67
|
+
/** @typedef {import("estree").ForInStatement} ForInStatement */
|
|
68
|
+
/** @typedef {import("estree").ForOfStatement} ForOfStatement */
|
|
55
69
|
/** @typedef {import("webpack-sources").Source} Source */
|
|
56
70
|
/** @typedef {import("../config/defaults").OutputNormalizedWithDefaults} OutputOptions */
|
|
57
71
|
/** @typedef {import("../Chunk")} Chunk */
|
|
@@ -70,12 +84,67 @@ const JavascriptParser = require("./JavascriptParser");
|
|
|
70
84
|
/** @typedef {import("../ModuleGraph")} ModuleGraph */
|
|
71
85
|
/** @typedef {import("../RuntimeTemplate")} RuntimeTemplate */
|
|
72
86
|
/** @typedef {import("../TemplatedPathPlugin").TemplatePath} TemplatePath */
|
|
73
|
-
/** @typedef {import("../WebpackError")} WebpackError */
|
|
87
|
+
/** @typedef {import("../errors/WebpackError")} WebpackError */
|
|
74
88
|
/** @typedef {import("../javascript/JavascriptParser").Range} Range */
|
|
75
89
|
/** @typedef {import("../util/Hash")} Hash */
|
|
76
90
|
/** @typedef {import("../util/concatenate").ScopeSet} ScopeSet */
|
|
77
91
|
/** @typedef {import("../util/concatenate").UsedNamesInScopeInfo} UsedNamesInScopeInfo */
|
|
78
92
|
|
|
93
|
+
// TODO remove these types when we will update `eslint-scope` to the latest version and import them from `eslint-scope`
|
|
94
|
+
/**
|
|
95
|
+
* @typedef {object} Scope
|
|
96
|
+
* @property {"block" | "catch" | "class" | "class-field-initializer" | "class-static-block" | "for" | "function" | "function-expression-name" | "global" | "module" | "switch" | "with" | "TDZ"} type
|
|
97
|
+
* @property {boolean} isStrict
|
|
98
|
+
* @property {Scope | null} upper
|
|
99
|
+
* @property {Scope[]} childScopes
|
|
100
|
+
* @property {Scope} variableScope
|
|
101
|
+
* @property {Node} block
|
|
102
|
+
* @property {Variable[]} variables
|
|
103
|
+
* @property {Map<string, Variable>} set
|
|
104
|
+
* @property {Reference[]} references
|
|
105
|
+
* @property {Reference[]} through
|
|
106
|
+
* @property {boolean} functionExpressionScope
|
|
107
|
+
* @property {{ variables: Variable[], set: Map<string, Variable> }=} implicit
|
|
108
|
+
*/
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* @typedef {
|
|
112
|
+
* | { type: "CatchClause", node: CatchClause, parent: null }
|
|
113
|
+
* | { type: "ClassName", node: ClassDeclaration | ClassExpression, parent: null }
|
|
114
|
+
* | { type: "FunctionName", node: FunctionDeclaration | FunctionExpression, parent: null }
|
|
115
|
+
* | { type: "ImplicitGlobalVariable", node: AssignmentExpression | ForInStatement | ForOfStatement, parent: null }
|
|
116
|
+
* | { type: "ImportBinding", node: ImportSpecifier | ImportDefaultSpecifier | ImportNamespaceSpecifier, parent: ImportDeclaration }
|
|
117
|
+
* | { type: "Parameter", node: FunctionDeclaration | FunctionExpression | ArrowFunctionExpression, parent: null }
|
|
118
|
+
* | { type: "TDZ", node: any, parent: null }
|
|
119
|
+
* | { type: "Variable", node: VariableDeclarator, parent: VariableDeclaration }
|
|
120
|
+
* } DefinitionType
|
|
121
|
+
*/
|
|
122
|
+
|
|
123
|
+
/** @typedef {DefinitionType & { name: Identifier }} Definition */
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* @typedef {object} Variable
|
|
127
|
+
* @property {string} name
|
|
128
|
+
* @property {Scope} scope
|
|
129
|
+
* @property {Identifier[]} identifiers
|
|
130
|
+
* @property {Reference[]} references
|
|
131
|
+
* @property {Definition[]} defs
|
|
132
|
+
*/
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* @typedef {object} Reference
|
|
136
|
+
* @property {Identifier} identifier
|
|
137
|
+
* @property {Scope} from
|
|
138
|
+
* @property {Variable | null} resolved
|
|
139
|
+
* @property {Node | null} writeExpr
|
|
140
|
+
* @property {boolean} init
|
|
141
|
+
* @property {() => boolean} isWrite
|
|
142
|
+
* @property {() => boolean} isRead
|
|
143
|
+
* @property {() => boolean} isWriteOnly
|
|
144
|
+
* @property {() => boolean} isReadOnly
|
|
145
|
+
* @property {() => boolean} isReadWrite
|
|
146
|
+
*/
|
|
147
|
+
|
|
79
148
|
/** @type {WeakMap<ChunkGraph, WeakMap<Chunk, boolean>>} */
|
|
80
149
|
const chunkHasJsCache = new WeakMap();
|
|
81
150
|
|
|
@@ -360,16 +429,21 @@ class JavascriptModulesPlugin {
|
|
|
360
429
|
.tap(PLUGIN_NAME, (options) => {
|
|
361
430
|
switch (type) {
|
|
362
431
|
case JAVASCRIPT_MODULE_TYPE_AUTO: {
|
|
363
|
-
return new JavascriptParser("auto", {
|
|
432
|
+
return new JavascriptParser("auto", {
|
|
433
|
+
parse: options.parse,
|
|
434
|
+
typescript: options.typescript
|
|
435
|
+
});
|
|
364
436
|
}
|
|
365
437
|
case JAVASCRIPT_MODULE_TYPE_DYNAMIC: {
|
|
366
438
|
return new JavascriptParser("script", {
|
|
367
|
-
parse: options.parse
|
|
439
|
+
parse: options.parse,
|
|
440
|
+
typescript: options.typescript
|
|
368
441
|
});
|
|
369
442
|
}
|
|
370
443
|
case JAVASCRIPT_MODULE_TYPE_ESM: {
|
|
371
444
|
return new JavascriptParser("module", {
|
|
372
|
-
parse: options.parse
|
|
445
|
+
parse: options.parse,
|
|
446
|
+
typescript: options.typescript
|
|
373
447
|
});
|
|
374
448
|
}
|
|
375
449
|
}
|
|
@@ -1353,6 +1427,13 @@ class JavascriptModulesPlugin {
|
|
|
1353
1427
|
// is evaluated.
|
|
1354
1428
|
buf.push("// The deferred module cache");
|
|
1355
1429
|
buf.push("var __webpack_module_deferred_exports__ = {};");
|
|
1430
|
+
// Per the TC39 import-defer spec, every defer-import call site for
|
|
1431
|
+
// the same module must yield the same Deferred Module Namespace
|
|
1432
|
+
// Exotic Object (and a distinct one from any eager namespace).
|
|
1433
|
+
// Cache the deferred namespace proxy here so calls from different
|
|
1434
|
+
// files share identity.
|
|
1435
|
+
buf.push("// The deferred namespace cache");
|
|
1436
|
+
buf.push("var __webpack_module_deferred_namespace_cache__ = {};");
|
|
1356
1437
|
buf.push("");
|
|
1357
1438
|
}
|
|
1358
1439
|
|
|
@@ -13,6 +13,7 @@ const Parser = require("../Parser");
|
|
|
13
13
|
const StackedMap = require("../util/StackedMap");
|
|
14
14
|
const binarySearchBounds = require("../util/binarySearchBounds");
|
|
15
15
|
const {
|
|
16
|
+
CompilerHintNotationRegExp,
|
|
16
17
|
createMagicCommentContext,
|
|
17
18
|
webpackCommentRegExp
|
|
18
19
|
} = require("../util/magicComment");
|
|
@@ -495,7 +496,7 @@ class JavascriptParser extends Parser {
|
|
|
495
496
|
/**
|
|
496
497
|
* Creates an instance of JavascriptParser.
|
|
497
498
|
* @param {"module" | "script" | "auto"=} sourceType default source type
|
|
498
|
-
* @param {{ parse?: ParseFunction }=} options parser options
|
|
499
|
+
* @param {{ parse?: ParseFunction, typescript?: boolean }=} options parser options
|
|
499
500
|
*/
|
|
500
501
|
constructor(sourceType = "auto", options = {}) {
|
|
501
502
|
super();
|
|
@@ -584,7 +585,7 @@ class JavascriptParser extends Parser {
|
|
|
584
585
|
"exportName",
|
|
585
586
|
"index"
|
|
586
587
|
]),
|
|
587
|
-
/** @type {SyncBailHook<[VariableDeclarator,
|
|
588
|
+
/** @type {SyncBailHook<[VariableDeclarator, VariableDeclaration], boolean | void>} */
|
|
588
589
|
preDeclarator: new SyncBailHook(["declarator", "statement"]),
|
|
589
590
|
/** @type {SyncBailHook<[VariableDeclarator, Statement], boolean | void>} */
|
|
590
591
|
declarator: new SyncBailHook(["declarator", "statement"]),
|
|
@@ -1584,8 +1585,8 @@ class JavascriptParser extends Parser {
|
|
|
1584
1585
|
)
|
|
1585
1586
|
);
|
|
1586
1587
|
|
|
1587
|
-
this.hooks.evaluate.for("CallExpression").tap(CLASS_NAME, (
|
|
1588
|
-
const expr = /** @type {CallExpression} */ (
|
|
1588
|
+
this.hooks.evaluate.for("CallExpression").tap(CLASS_NAME, (expression) => {
|
|
1589
|
+
const expr = /** @type {CallExpression} */ (expression);
|
|
1589
1590
|
if (
|
|
1590
1591
|
expr.callee.type === "MemberExpression" &&
|
|
1591
1592
|
expr.callee.property.type ===
|
|
@@ -1979,6 +1980,21 @@ class JavascriptParser extends Parser {
|
|
|
1979
1980
|
}
|
|
1980
1981
|
return this.evaluateExpression(expr.expression);
|
|
1981
1982
|
});
|
|
1983
|
+
this.hooks.evaluate.for("SequenceExpression").tap(CLASS_NAME, (_expr) => {
|
|
1984
|
+
const expr = /** @type {SequenceExpression} */ (_expr);
|
|
1985
|
+
if (!expr.range) return;
|
|
1986
|
+
let commentsStartPos = /** @type {Range} */ (expr.range)[0];
|
|
1987
|
+
for (let i = 0; i < expr.expressions.length - 1; i++) {
|
|
1988
|
+
const item = expr.expressions[i];
|
|
1989
|
+
if (!item.range) return;
|
|
1990
|
+
if (!this.isPure(item, commentsStartPos)) return;
|
|
1991
|
+
commentsStartPos = /** @type {Range} */ (item.range)[1];
|
|
1992
|
+
}
|
|
1993
|
+
const last = expr.expressions[expr.expressions.length - 1];
|
|
1994
|
+
const evaluated = this.evaluateExpression(last);
|
|
1995
|
+
if (!evaluated.isCompileTimeValue()) return;
|
|
1996
|
+
return evaluated.setRange(/** @type {Range} */ (expr.range));
|
|
1997
|
+
});
|
|
1982
1998
|
}
|
|
1983
1999
|
|
|
1984
2000
|
/**
|
|
@@ -3848,6 +3864,37 @@ class JavascriptParser extends Parser {
|
|
|
3848
3864
|
* @param {NewExpression} expression new expression
|
|
3849
3865
|
*/
|
|
3850
3866
|
walkNewExpression(expression) {
|
|
3867
|
+
// TODO: not a webpack bug — `acorn-import-phases` accepts
|
|
3868
|
+
// `new import.defer(...)` / `new import.source(...)` even though
|
|
3869
|
+
// `ImportCall` is a `CallExpression` per spec and is therefore not a
|
|
3870
|
+
// valid `new` operand. Acorn rejects bare `new import(...)` correctly.
|
|
3871
|
+
// Drop this block once the upstream plugin (or acorn itself) reports
|
|
3872
|
+
// the SyntaxError. Parenthesized forms (`new (import.defer(...))`)
|
|
3873
|
+
// produce the same AST shape, so we look at the source between `new`
|
|
3874
|
+
// and the callee (with comments stripped) to keep them valid.
|
|
3875
|
+
if (
|
|
3876
|
+
expression.callee.type === "ImportExpression" &&
|
|
3877
|
+
typeof this.state.source === "string"
|
|
3878
|
+
) {
|
|
3879
|
+
const newStart = /** @type {Range} */ (expression.range)[0];
|
|
3880
|
+
const calleeStart = /** @type {Range} */ (expression.callee.range)[0];
|
|
3881
|
+
const between = this.state.source
|
|
3882
|
+
.slice(newStart, calleeStart)
|
|
3883
|
+
.replace(/\/\*[\s\S]*?\*\//g, "")
|
|
3884
|
+
.replace(/\/\/[^\n]*/g, "");
|
|
3885
|
+
if (!between.includes("(")) {
|
|
3886
|
+
const err =
|
|
3887
|
+
/** @type {SyntaxError & { loc?: { line: number, column: number } }} */
|
|
3888
|
+
(new SyntaxError("import call cannot be the target of `new`"));
|
|
3889
|
+
if (expression.loc) {
|
|
3890
|
+
err.loc = {
|
|
3891
|
+
line: expression.loc.start.line,
|
|
3892
|
+
column: expression.loc.start.column
|
|
3893
|
+
};
|
|
3894
|
+
}
|
|
3895
|
+
throw err;
|
|
3896
|
+
}
|
|
3897
|
+
}
|
|
3851
3898
|
const result = this.callHooksForExpression(
|
|
3852
3899
|
this.hooks.new,
|
|
3853
3900
|
expression.callee,
|
|
@@ -4214,10 +4261,10 @@ class JavascriptParser extends Parser {
|
|
|
4214
4261
|
if (expression.object.type === "MemberExpression") {
|
|
4215
4262
|
// optimize the case where expression.object is a MemberExpression too.
|
|
4216
4263
|
// we can keep info here when calling walkMemberExpression directly
|
|
4217
|
-
|
|
4218
|
-
|
|
4219
|
-
|
|
4220
|
-
|
|
4264
|
+
// Read the property from `members` (already extracted by
|
|
4265
|
+
// extractMemberExpressionChain) since the AST node may be a
|
|
4266
|
+
// TemplateLiteral, which has neither .name nor .value.
|
|
4267
|
+
const property = members[members.length - 1];
|
|
4221
4268
|
name = name.slice(0, -property.length - 1);
|
|
4222
4269
|
members.pop();
|
|
4223
4270
|
const result = this.callHooksForInfo(
|
|
@@ -4849,6 +4896,9 @@ class JavascriptParser extends Parser {
|
|
|
4849
4896
|
|
|
4850
4897
|
if (Buffer.isBuffer(source)) {
|
|
4851
4898
|
source = source.toString("utf8");
|
|
4899
|
+
// Keep `state.source` as a string so downstream walkers can read
|
|
4900
|
+
// the original text without re-decoding the Buffer on every use.
|
|
4901
|
+
state.source = source;
|
|
4852
4902
|
}
|
|
4853
4903
|
|
|
4854
4904
|
let ast;
|
|
@@ -4908,6 +4958,7 @@ class JavascriptParser extends Parser {
|
|
|
4908
4958
|
this.destructuringAssignmentProperties = new WeakMap();
|
|
4909
4959
|
this.detectMode(ast.body);
|
|
4910
4960
|
this.modulePreWalkStatements(ast.body);
|
|
4961
|
+
this.prevStatement = undefined;
|
|
4911
4962
|
this.preWalkStatements(ast.body);
|
|
4912
4963
|
this.prevStatement = undefined;
|
|
4913
4964
|
this.blockPreWalkStatements(ast.body);
|
|
@@ -4954,8 +5005,8 @@ class JavascriptParser extends Parser {
|
|
|
4954
5005
|
.for(expr.type)
|
|
4955
5006
|
.call(expr, commentsStartPos);
|
|
4956
5007
|
if (typeof result === "boolean") return result;
|
|
5008
|
+
// TODO handle more cases
|
|
4957
5009
|
switch (expr.type) {
|
|
4958
|
-
// TODO handle more cases
|
|
4959
5010
|
case "ClassDeclaration":
|
|
4960
5011
|
case "ClassExpression": {
|
|
4961
5012
|
if (expr.body.type !== "ClassBody") return false;
|
|
@@ -5008,9 +5059,15 @@ class JavascriptParser extends Parser {
|
|
|
5008
5059
|
});
|
|
5009
5060
|
}
|
|
5010
5061
|
case "TemplateLiteral":
|
|
5011
|
-
|
|
5012
|
-
|
|
5013
|
-
)
|
|
5062
|
+
// Thread `commentsStartPos` through the interpolations so a
|
|
5063
|
+
// /*#__PURE__*/ comment that sits inside `${ ... }` (or before
|
|
5064
|
+
// the first interpolation) is part of the scanned range when
|
|
5065
|
+
// the inner expression's purity is evaluated.
|
|
5066
|
+
return expr.expressions.every((e) => {
|
|
5067
|
+
const pureFlag = this.isPure(e, commentsStartPos);
|
|
5068
|
+
commentsStartPos = /** @type {Range} */ (e.range)[1];
|
|
5069
|
+
return pureFlag;
|
|
5070
|
+
});
|
|
5014
5071
|
case "FunctionDeclaration":
|
|
5015
5072
|
case "FunctionExpression":
|
|
5016
5073
|
case "ArrowFunctionExpression":
|
|
@@ -5025,6 +5082,78 @@ class JavascriptParser extends Parser {
|
|
|
5025
5082
|
this.isPure(decl.init, /** @type {Range} */ (decl.range)[0])
|
|
5026
5083
|
);
|
|
5027
5084
|
|
|
5085
|
+
case "ArrayExpression":
|
|
5086
|
+
return expr.elements.every((element) => {
|
|
5087
|
+
if (element === null) return true;
|
|
5088
|
+
if (element.type === "SpreadElement") return false;
|
|
5089
|
+
const pureFlag = this.isPure(element, commentsStartPos);
|
|
5090
|
+
commentsStartPos = /** @type {Range} */ (element.range)[1];
|
|
5091
|
+
return pureFlag;
|
|
5092
|
+
});
|
|
5093
|
+
|
|
5094
|
+
case "ObjectExpression": {
|
|
5095
|
+
return expr.properties.every((property) => {
|
|
5096
|
+
if (property.type === "SpreadElement") return false;
|
|
5097
|
+
|
|
5098
|
+
if (
|
|
5099
|
+
property.computed &&
|
|
5100
|
+
!this.isPure(property.key, commentsStartPos)
|
|
5101
|
+
) {
|
|
5102
|
+
return false;
|
|
5103
|
+
}
|
|
5104
|
+
|
|
5105
|
+
const pureFlag = this.isPure(
|
|
5106
|
+
/** @type {Exclude<Property["value"], AssignmentPattern | ObjectPattern | ArrayPattern | RestElement>} */
|
|
5107
|
+
(property.value),
|
|
5108
|
+
/** @type {Range} */ (property.key.range)[1]
|
|
5109
|
+
);
|
|
5110
|
+
commentsStartPos = /** @type {Range} */ (property.range)[1];
|
|
5111
|
+
return pureFlag;
|
|
5112
|
+
});
|
|
5113
|
+
}
|
|
5114
|
+
|
|
5115
|
+
case "ChainExpression":
|
|
5116
|
+
return this.isPure(expr.expression, commentsStartPos);
|
|
5117
|
+
|
|
5118
|
+
case "UnaryExpression":
|
|
5119
|
+
// Safe unary operators — produce their result without invoking
|
|
5120
|
+
// user code on the operand:
|
|
5121
|
+
// - `typeof` returns a type tag and never throws, even for
|
|
5122
|
+
// undeclared identifiers; no coercion.
|
|
5123
|
+
// - `void` evaluates the operand and discards it, returning
|
|
5124
|
+
// `undefined`; pure iff the operand is pure.
|
|
5125
|
+
// - `!` coerces via ToBoolean, which is defined to not call
|
|
5126
|
+
// any user code (objects → true, etc.).
|
|
5127
|
+
// Other operators (`+`, `-`, `~`, `delete`) fall through to
|
|
5128
|
+
// the generic evaluator which can still recognize literal
|
|
5129
|
+
// cases (e.g. `-1`, `+5`).
|
|
5130
|
+
if (
|
|
5131
|
+
expr.operator === "typeof" ||
|
|
5132
|
+
expr.operator === "void" ||
|
|
5133
|
+
expr.operator === "!"
|
|
5134
|
+
) {
|
|
5135
|
+
return this.isPure(expr.argument, commentsStartPos);
|
|
5136
|
+
}
|
|
5137
|
+
break;
|
|
5138
|
+
|
|
5139
|
+
case "MetaProperty":
|
|
5140
|
+
return true;
|
|
5141
|
+
|
|
5142
|
+
case "BinaryExpression":
|
|
5143
|
+
// Strict (in)equality compares without coercion and never invokes
|
|
5144
|
+
// user code on its operands, so the result is pure iff both sides
|
|
5145
|
+
// are pure. All other binary operators may invoke `valueOf` /
|
|
5146
|
+
// `toString` / `[Symbol.hasInstance]` / Proxy traps and fall through
|
|
5147
|
+
// to the generic evaluator, which can still recognize the cases
|
|
5148
|
+
// where both sides evaluate to known primitive literals.
|
|
5149
|
+
if (expr.operator === "===" || expr.operator === "!==") {
|
|
5150
|
+
return (
|
|
5151
|
+
this.isPure(expr.left, commentsStartPos) &&
|
|
5152
|
+
this.isPure(expr.right, /** @type {Range} */ (expr.left.range)[1])
|
|
5153
|
+
);
|
|
5154
|
+
}
|
|
5155
|
+
break;
|
|
5156
|
+
|
|
5028
5157
|
case "ConditionalExpression":
|
|
5029
5158
|
return (
|
|
5030
5159
|
this.isPure(expr.test, commentsStartPos) &&
|
|
@@ -5060,7 +5189,28 @@ class JavascriptParser extends Parser {
|
|
|
5060
5189
|
]).some(
|
|
5061
5190
|
(comment) =>
|
|
5062
5191
|
comment.type === "Block" &&
|
|
5063
|
-
|
|
5192
|
+
CompilerHintNotationRegExp.Pure.test(comment.value)
|
|
5193
|
+
);
|
|
5194
|
+
if (!pureFlag) return false;
|
|
5195
|
+
commentsStartPos = /** @type {Range} */ (expr.callee.range)[1];
|
|
5196
|
+
return expr.arguments.every((arg) => {
|
|
5197
|
+
if (arg.type === "SpreadElement") return false;
|
|
5198
|
+
const pureFlag = this.isPure(arg, commentsStartPos);
|
|
5199
|
+
commentsStartPos = /** @type {Range} */ (arg.range)[1];
|
|
5200
|
+
return pureFlag;
|
|
5201
|
+
});
|
|
5202
|
+
}
|
|
5203
|
+
|
|
5204
|
+
case "NewExpression": {
|
|
5205
|
+
const pureFlag =
|
|
5206
|
+
/** @type {Range} */ (expr.range)[0] - commentsStartPos > 12 &&
|
|
5207
|
+
this.getComments([
|
|
5208
|
+
commentsStartPos,
|
|
5209
|
+
/** @type {Range} */ (expr.range)[0]
|
|
5210
|
+
]).some(
|
|
5211
|
+
(comment) =>
|
|
5212
|
+
comment.type === "Block" &&
|
|
5213
|
+
CompilerHintNotationRegExp.Pure.test(comment.value)
|
|
5064
5214
|
);
|
|
5065
5215
|
if (!pureFlag) return false;
|
|
5066
5216
|
commentsStartPos = /** @type {Range} */ (expr.callee.range)[1];
|
|
@@ -5071,6 +5221,26 @@ class JavascriptParser extends Parser {
|
|
|
5071
5221
|
return pureFlag;
|
|
5072
5222
|
});
|
|
5073
5223
|
}
|
|
5224
|
+
|
|
5225
|
+
case "TaggedTemplateExpression": {
|
|
5226
|
+
const pureFlag =
|
|
5227
|
+
/** @type {Range} */ (expr.range)[0] - commentsStartPos > 12 &&
|
|
5228
|
+
this.getComments([
|
|
5229
|
+
commentsStartPos,
|
|
5230
|
+
/** @type {Range} */ (expr.range)[0]
|
|
5231
|
+
]).some(
|
|
5232
|
+
(comment) =>
|
|
5233
|
+
comment.type === "Block" &&
|
|
5234
|
+
CompilerHintNotationRegExp.Pure.test(comment.value)
|
|
5235
|
+
);
|
|
5236
|
+
if (!pureFlag) return false;
|
|
5237
|
+
commentsStartPos = /** @type {Range} */ (expr.tag.range)[1];
|
|
5238
|
+
return expr.quasi.expressions.every((e) => {
|
|
5239
|
+
const pureFlag = this.isPure(e, commentsStartPos);
|
|
5240
|
+
commentsStartPos = /** @type {Range} */ (e.range)[1];
|
|
5241
|
+
return pureFlag;
|
|
5242
|
+
});
|
|
5243
|
+
}
|
|
5074
5244
|
}
|
|
5075
5245
|
const evaluated = this.evaluateExpression(expr);
|
|
5076
5246
|
return !evaluated.couldHaveSideEffects();
|
|
@@ -5380,9 +5550,20 @@ class JavascriptParser extends Parser {
|
|
|
5380
5550
|
const memberRanges = [];
|
|
5381
5551
|
while (expr.type === "MemberExpression") {
|
|
5382
5552
|
if (expr.computed) {
|
|
5383
|
-
|
|
5384
|
-
|
|
5385
|
-
|
|
5553
|
+
const prop = expr.property;
|
|
5554
|
+
if (prop.type === "Literal") {
|
|
5555
|
+
members.push(`${prop.value}`); // the literal
|
|
5556
|
+
} else if (
|
|
5557
|
+
prop.type === "TemplateLiteral" &&
|
|
5558
|
+
prop.expressions.length === 0 &&
|
|
5559
|
+
typeof prop.quasis[0].value.cooked === "string"
|
|
5560
|
+
) {
|
|
5561
|
+
// `[`url`]` is statically a string just like `["url"]`
|
|
5562
|
+
members.push(prop.quasis[0].value.cooked);
|
|
5563
|
+
} else {
|
|
5564
|
+
break;
|
|
5565
|
+
}
|
|
5566
|
+
memberRanges.push(/** @type {Range} */ (expr.object.range)); // the range of the expression fragment before the property
|
|
5386
5567
|
} else {
|
|
5387
5568
|
if (expr.property.type !== "Identifier") break;
|
|
5388
5569
|
members.push(expr.property.name); // the identifier
|
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
|
|
6
6
|
"use strict";
|
|
7
7
|
|
|
8
|
-
const UnsupportedFeatureWarning = require("../UnsupportedFeatureWarning");
|
|
9
8
|
const ConstDependency = require("../dependencies/ConstDependency");
|
|
9
|
+
const UnsupportedFeatureWarning = require("../errors/UnsupportedFeatureWarning");
|
|
10
10
|
const BasicEvaluatedExpression = require("./BasicEvaluatedExpression");
|
|
11
11
|
|
|
12
12
|
/** @typedef {import("estree").Expression} Expression */
|
package/lib/json/JsonParser.js
CHANGED
|
@@ -10,7 +10,7 @@ const JsonExportsDependency = require("../dependencies/JsonExportsDependency");
|
|
|
10
10
|
const parseJson = require("../util/parseJson");
|
|
11
11
|
const JsonData = require("./JsonData");
|
|
12
12
|
|
|
13
|
-
/** @typedef {import("../../declarations/
|
|
13
|
+
/** @typedef {import("../../declarations/WebpackOptions").JsonParserOptions} JsonParserOptions */
|
|
14
14
|
/** @typedef {import("../Module").BuildInfo} BuildInfo */
|
|
15
15
|
/** @typedef {import("../Module").BuildMeta} BuildMeta */
|
|
16
16
|
/** @typedef {import("../Parser").ParserState} ParserState */
|
|
@@ -28,11 +28,11 @@ const JsonData = require("./JsonData");
|
|
|
28
28
|
class JsonParser extends Parser {
|
|
29
29
|
/**
|
|
30
30
|
* Creates an instance of JsonParser.
|
|
31
|
-
* @param {
|
|
31
|
+
* @param {JsonParserOptions} options parser options
|
|
32
32
|
*/
|
|
33
33
|
constructor(options = {}) {
|
|
34
34
|
super();
|
|
35
|
-
/** @type {
|
|
35
|
+
/** @type {JsonParserOptions} */
|
|
36
36
|
this.options = options;
|
|
37
37
|
}
|
|
38
38
|
|
|
@@ -47,22 +47,13 @@ class JsonParser extends Parser {
|
|
|
47
47
|
source = source.toString("utf8");
|
|
48
48
|
}
|
|
49
49
|
|
|
50
|
-
/** @type {typeof parseJson} */
|
|
51
50
|
const parseFn =
|
|
52
51
|
typeof this.options.parse === "function" ? this.options.parse : parseJson;
|
|
53
52
|
/** @type {Buffer | JsonValue | undefined} */
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
? source
|
|
59
|
-
: parseFn(source[0] === "\uFEFF" ? source.slice(1) : source);
|
|
60
|
-
} catch (err) {
|
|
61
|
-
throw new Error(
|
|
62
|
-
`Cannot parse JSON: ${/** @type {Error} */ (err).message}`,
|
|
63
|
-
{ cause: err }
|
|
64
|
-
);
|
|
65
|
-
}
|
|
53
|
+
const data =
|
|
54
|
+
typeof source === "object"
|
|
55
|
+
? source
|
|
56
|
+
: parseFn(source[0] === "\uFEFF" ? source.slice(1) : source);
|
|
66
57
|
const jsonData = new JsonData(/** @type {Buffer | JsonValue} */ (data));
|
|
67
58
|
const buildInfo = /** @type {BuildInfo} */ (state.module.buildInfo);
|
|
68
59
|
buildInfo.jsonData = jsonData;
|
|
@@ -249,7 +249,7 @@ class AbstractLibraryPlugin {
|
|
|
249
249
|
* @returns {T} preprocess as needed by overriding
|
|
250
250
|
*/
|
|
251
251
|
parseOptions(library) {
|
|
252
|
-
const AbstractMethodError = require("../AbstractMethodError");
|
|
252
|
+
const AbstractMethodError = require("../errors/AbstractMethodError");
|
|
253
253
|
|
|
254
254
|
throw new AbstractMethodError();
|
|
255
255
|
}
|
|
@@ -249,7 +249,7 @@ class EnableLibraryPlugin {
|
|
|
249
249
|
compiler.hooks.thisCompilation.tap(
|
|
250
250
|
"WarnFalseIifeUmdPlugin",
|
|
251
251
|
(compilation) => {
|
|
252
|
-
const FalseIIFEUmdWarning = require("
|
|
252
|
+
const FalseIIFEUmdWarning = require("./FalseIIFEUmdWarning");
|
|
253
253
|
|
|
254
254
|
compilation.warnings.push(new FalseIIFEUmdWarning());
|
|
255
255
|
}
|