webpack 5.112.0 → 5.112.1
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/bin/webpack.js +13 -7
- package/lib/Compilation.js +152 -60
- package/lib/Compiler.js +12 -25
- package/lib/asset/AssetBytesGenerator.js +14 -6
- package/lib/asset/AssetBytesParser.js +10 -8
- package/lib/asset/AssetGenerator.js +36 -48
- package/lib/asset/AssetModule.js +11 -0
- package/lib/asset/AssetModulesPlugin.js +5 -4
- package/lib/asset/AssetParser.js +8 -8
- package/lib/asset/AssetSourceGenerator.js +16 -8
- package/lib/asset/AssetSourceParser.js +10 -8
- package/lib/asset/WebManifestGenerator.js +11 -6
- package/lib/asset/WebManifestParser.js +3 -3
- package/lib/async-modules/AsyncModuleHelpers.js +8 -2
- package/lib/async-modules/InferAsyncModulesPlugin.js +7 -2
- package/lib/cache/CacheFacade.js +1 -1
- package/lib/cache/PackFileCacheStrategy.js +6 -10
- package/lib/cache/ResolverCachePlugin.js +58 -8
- package/lib/config/WebpackOptionsApply.js +8 -28
- package/lib/config/cli.js +9 -6
- package/lib/config/defaults.js +24 -13
- package/lib/config/getClaimedAssetTypes.js +2 -2
- package/lib/config/target.js +1 -1
- package/lib/context/ContextModule.js +1 -1
- package/lib/context/ContextModuleFactory.js +1 -1
- package/lib/context/ContextReplacementPlugin.js +3 -9
- package/lib/css/CssGenerator.js +40 -37
- package/lib/css/CssModule.js +10 -0
- package/lib/css/CssModulesPlugin.js +2 -2
- package/lib/css/CssParser.js +33 -32
- package/lib/css/conventions.js +1 -1
- package/lib/css/data.js +224 -219
- package/lib/css/syntax-parser.js +1159 -298
- package/lib/css/syntax-printer.js +90 -35
- package/lib/debug/ProfilingPlugin.js +65 -43
- package/lib/define/DefinePlugin.js +10 -15
- package/lib/define/DotenvPlugin.js +10 -6
- package/lib/define/EnvironmentPlugin.js +4 -2
- package/lib/dependencies/amd/AMDDefineDependencyParserPlugin.js +1 -2
- package/lib/dependencies/amd/AMDRequireDependenciesBlockParserPlugin.js +4 -1
- package/lib/dependencies/commonjs/CommonJsExportRequireDependency.js +1 -4
- package/lib/dependencies/commonjs/CommonJsExportsParserPlugin.js +18 -33
- package/lib/dependencies/commonjs/CommonJsImportsParserPlugin.js +1 -3
- package/lib/dependencies/commonjs/CommonJsObjectExportDependency.js +4 -4
- package/lib/dependencies/commonjs/CommonJsPlugin.js +2 -5
- package/lib/dependencies/commonjs/RequireEnsureDependenciesBlockParserPlugin.js +4 -1
- package/lib/dependencies/context/ImportMetaContextDependencyParserPlugin.js +1 -2
- package/lib/dependencies/context/ImportMetaGlobDependencyParserPlugin.js +4 -7
- package/lib/dependencies/context/ImportMetaGlobHelpers.js +8 -10
- package/lib/dependencies/core/CachedConstDependency.js +9 -6
- package/lib/dependencies/css/CssIcssExportDependency.js +6 -7
- package/lib/dependencies/css/CssIcssImportDependency.js +1 -3
- package/lib/dependencies/css/CssUrlDependency.js +2 -6
- package/lib/dependencies/esm/ESMDetectionParserPlugin.js +2 -4
- package/lib/dependencies/esm/ESMExportExpressionDependency.js +2 -2
- package/lib/dependencies/esm/ESMExportImportedSpecifierDependency.js +16 -18
- package/lib/dependencies/esm/ESMExportSpecifierDependency.js +20 -3
- package/lib/dependencies/esm/ESMExports.js +2 -10
- package/lib/dependencies/esm/ESMImportDependency.js +17 -2
- package/lib/dependencies/esm/ESMImportDependencyParserPlugin.js +6 -17
- package/lib/dependencies/esm/ESMImportGuard.js +11 -23
- package/lib/dependencies/esm/ESMImportSideEffectDependency.js +1 -1
- package/lib/dependencies/esm/ESMImportSpecifierDependency.js +4 -1
- package/lib/dependencies/esm/ESMLiveExportDependency.js +311 -0
- package/lib/dependencies/esm/ESMLiveExportParserPlugin.js +862 -0
- package/lib/dependencies/esm/ESMModulesPlugin.js +1 -3
- package/lib/dependencies/esm/TopLevelAwaitDependency.js +1 -8
- package/lib/dependencies/helpers/DynamicExports.js +4 -6
- package/lib/dependencies/html/HtmlEntryDependency.js +5 -14
- package/lib/dependencies/html/HtmlInlineHtmlDependency.js +1 -4
- package/lib/dependencies/html/HtmlInlineScriptDependency.js +2 -6
- package/lib/dependencies/html/HtmlInlineStyleDependency.js +1 -4
- package/lib/dependencies/import/ImportParserPlugin.js +3 -6
- package/lib/dependencies/import-meta/ImportMetaPlugin.js +4 -6
- package/lib/dependencies/url/URLParserPlugin.js +1 -1
- package/lib/dependencies/worker/WorkerAndWorkletPlugin.js +51 -20
- package/lib/devtool/ModuleFilenameHelpers.js +1 -1
- package/lib/devtool/SourceMapDevToolPlugin.js +1 -1
- package/lib/dll/DelegatedModule.js +3 -3
- package/lib/dll/DllModule.js +3 -1
- package/lib/dll/DllReferencePlugin.js +1 -4
- package/lib/errors/AbstractMethodError.js +1 -1
- package/lib/errors/ErrorHelpers.js +2 -1
- package/lib/errors/HookWebpackError.js +2 -1
- package/lib/errors/JSONParseError.js +4 -4
- package/lib/errors/WebpackError.js +3 -2
- package/lib/esm/ModuleChunkFormatPlugin.js +36 -1
- package/lib/externals/ExternalModule.js +12 -9
- package/lib/externals/ExternalModuleFactoryPlugin.js +1 -2
- package/lib/externals/ExternalsPlugin.js +1 -1
- package/lib/fs/FileSystemInfo.js +4 -4
- package/lib/graph/AsyncDependenciesBlock.js +1 -1
- package/lib/graph/ChunkGraph.js +5 -0
- package/lib/graph/Dependency.js +8 -2
- package/lib/graph/ExportsInfo.js +1 -1
- package/lib/graph/ModuleGraph.js +14 -3
- package/lib/graph/buildChunkGraph.js +17 -19
- package/lib/graph/findGraphRoots.js +1 -1
- package/lib/hmr/HotModuleReplacement.runtime.js +10 -9
- package/lib/hmr/HotModuleReplacementPlugin.js +5 -11
- package/lib/hmr/JavascriptHotModuleReplacement.runtime.js +16 -19
- package/lib/hmr/LazyCompilationPlugin.js +1 -7
- package/lib/html/HtmlGenerator.js +25 -17
- package/lib/html/HtmlModule.js +11 -1
- package/lib/html/HtmlModulesPlugin.js +12 -11
- package/lib/html/HtmlParser.js +10 -9
- package/lib/html/builtinEmbeddedRenderer.js +31 -33
- package/lib/html/data.js +42 -21
- package/lib/html/htmlMinify.js +4 -1
- package/lib/html/syntax-parser.js +34 -35
- package/lib/html/syntax-printer.js +2 -3
- package/lib/html/xmlMinify.js +4 -1
- package/lib/ids/HashedModuleIdsPlugin.js +1 -1
- package/lib/index.js +13 -12
- package/lib/javascript/APIPlugin.js +7 -13
- package/lib/javascript/BasicEvaluatedExpression.js +5 -5
- package/lib/javascript/CommonJsChunkFormatPlugin.js +2 -7
- package/lib/javascript/ConstPlugin.js +1 -1
- package/lib/javascript/JavascriptGenerator.js +16 -11
- package/lib/javascript/JavascriptMetaInfoPlugin.js +3 -15
- package/lib/javascript/JavascriptModule.js +10 -0
- package/lib/javascript/JavascriptModulesPlugin.js +2 -4
- package/lib/javascript/JavascriptParser.js +99 -11
- package/lib/javascript/ScopeAnalyzer.js +183 -107
- package/lib/javascript/UseStrictPlugin.js +2 -5
- package/lib/javascript/jsMinify.js +1 -1
- package/lib/javascript/regexp.js +2 -2
- package/lib/javascript/syntax-parser.js +2114 -1506
- package/lib/javascript/syntax-printer-data.js +167 -1
- package/lib/javascript/syntax-printer.js +9554 -2782
- package/lib/json/JsonGenerator.js +15 -7
- package/lib/json/JsonModule.js +11 -0
- package/lib/json/JsonParser.js +7 -6
- package/lib/library/AssignLibraryPlugin.js +1 -1
- package/lib/library/JsonpLibraryPlugin.js +1 -1
- package/lib/library/ModuleLibraryPlugin.js +399 -23
- package/lib/loaders/LoaderRunner.js +76 -38
- package/lib/loaders/loadLoader.js +16 -10
- package/lib/module/Generator.js +17 -9
- package/lib/module/Module.js +2 -2
- package/lib/module/NormalModule.js +7 -5
- package/lib/module/NormalModuleFactory.js +11 -17
- package/lib/module/Parser.js +9 -2
- package/lib/module/extractSourceMap.js +69 -18
- package/lib/module/findCaseMismatch.js +2 -2
- package/lib/node/ExternalModuleInitFragment.js +2 -2
- package/lib/node/ReadFileCompileAsyncWasmPlugin.js +4 -12
- package/lib/node/ReadFileCompileWasmPlugin.js +2 -6
- package/lib/node/nodeConsole.js +4 -3
- package/lib/optimize/CircularModulesPlugin.js +1 -1
- package/lib/optimize/ConcatenatedModule.js +2 -6
- package/lib/optimize/FlagDependencyExportsPlugin.js +6 -11
- package/lib/optimize/FlagDependencyUsagePlugin.js +28 -3
- package/lib/optimize/InlineExports.js +4 -7
- package/lib/optimize/LazyBarrels.js +41 -5
- package/lib/optimize/ModuleConcatenationPlugin.js +8 -10
- package/lib/optimize/RealContentHashPlugin.js +2 -6
- package/lib/optimize/SideEffectsFlagPlugin.js +7 -21
- package/lib/optimize/SplitChunksPlugin.js +11 -24
- package/lib/optimize/TupleQueue.js +1 -1
- package/lib/output/CleanPlugin.js +3 -1
- package/lib/output/CopyPlugin.js +3 -4
- package/lib/performance/EvalUsagePlugin.js +1 -3
- package/lib/performance/HotspotsPlugin.js +33 -9
- package/lib/performance/PureAnnotationsPlugin.js +16 -10
- package/lib/performance/TopLevelThisPlugin.js +17 -9
- package/lib/prefetch/ResourceHintPlugin.js +1 -1
- package/lib/provide/ProvidedDependency.js +36 -4
- package/lib/rules/BasicEffectRulePlugin.js +1 -1
- package/lib/rules/RuleSetCompiler.js +15 -5
- package/lib/rules/UseEffectRulePlugin.js +1 -3
- package/lib/runtime/AsyncModuleRuntimeModule.js +7 -1
- package/lib/runtime/GetChunkFilenameRuntimeModule.js +1 -5
- package/lib/runtime/RuntimeGlobals.js +6 -0
- package/lib/runtime/RuntimePlugin.js +2 -0
- package/lib/schemes/HttpUriPlugin.js +1 -2
- package/lib/schemes/VirtualUrlPlugin.js +3 -1
- package/lib/serialization/AggregateErrorSerializer.js +3 -3
- package/lib/serialization/BinaryMiddleware.js +4 -1
- package/lib/serialization/ErrorObjectSerializer.js +2 -5
- package/lib/serialization/ObjectMiddleware.js +17 -15
- package/lib/serialization/PlainObjectSerializer.js +3 -7
- package/lib/serialization/Serializer.js +21 -11
- package/lib/serialization/SerializerMiddleware.js +8 -6
- package/lib/stats/DefaultStatsFactoryPlugin.js +35 -35
- package/lib/stats/DefaultStatsPresetPlugin.js +2 -6
- package/lib/stats/DefaultStatsPrinterPlugin.js +12 -11
- package/lib/stats/StatsFactory.js +194 -24
- package/lib/stats/StatsPrinter.js +126 -13
- package/lib/template/DependencyTemplate.js +1 -1
- package/lib/template/RuntimeTemplate.js +13 -32
- package/lib/template/Template.js +1 -1
- package/lib/util/SourceProcessor.js +98 -15
- package/lib/util/WeakTupleMap.js +10 -4
- package/lib/util/cleverMerge.js +61 -33
- package/lib/util/comparators.js +9 -5
- package/lib/util/dataURL.js +2 -0
- package/lib/util/deprecation.js +4 -3
- package/lib/util/globUtils.js +1 -4
- package/lib/util/internalSerializables.js +2 -0
- package/lib/util/makeSerializable.js +6 -4
- package/lib/util/memoize.js +1 -1
- package/lib/util/parseJson.js +2 -2
- package/lib/util/serialization.js +31 -27
- package/lib/wasm/AsyncWasmModule.js +12 -2
- package/lib/wasm/AsyncWebAssemblyGenerator.js +12 -4
- package/lib/wasm/AsyncWebAssemblyJavascriptGenerator.js +13 -5
- package/lib/wasm/AsyncWebAssemblyParser.js +7 -5
- package/lib/wasm/UniversalCompileAsyncWasmPlugin.js +2 -6
- package/lib/wasm-sync/SyncWasmModule.js +16 -1
- package/lib/wasm-sync/WebAssemblyGenerator.js +15 -10
- package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +13 -5
- package/lib/wasm-sync/WebAssemblyParser.js +10 -12
- package/lib/web/FetchCompileAsyncWasmPlugin.js +4 -12
- package/lib/web/FetchCompileWasmPlugin.js +2 -6
- package/package.json +16 -18
- package/schemas/WebpackOptions.check.js +3 -3
- package/schemas/WebpackOptions.json +2 -2
- package/schemas/plugins/BannerPlugin.check.js +3 -3
- package/schemas/plugins/HtmlGeneratorOptions.check.js +3 -3
- package/schemas/plugins/HtmlParserOptions.check.js +3 -3
- package/schemas/plugins/IgnorePlugin.check.js +3 -3
- package/schemas/plugins/LoaderOptionsPlugin.check.js +3 -3
- package/schemas/plugins/ManifestPlugin.check.js +3 -3
- package/schemas/plugins/ProgressPlugin.check.js +3 -3
- package/schemas/plugins/SSRManifestPlugin.check.js +3 -3
- package/schemas/plugins/SourceMapDevToolPlugin.check.js +3 -3
- package/schemas/plugins/WatchIgnorePlugin.check.js +3 -3
- package/schemas/plugins/asset/AssetGeneratorOptions.check.js +3 -3
- package/schemas/plugins/asset/AssetInlineGeneratorOptions.check.js +3 -3
- package/schemas/plugins/asset/AssetParserOptions.check.js +3 -3
- package/schemas/plugins/asset/AssetResourceGeneratorOptions.check.js +3 -3
- package/schemas/plugins/container/ContainerPlugin.check.js +3 -3
- package/schemas/plugins/container/ContainerReferencePlugin.check.js +3 -3
- package/schemas/plugins/container/ExternalsType.check.js +3 -3
- package/schemas/plugins/container/ModuleFederationPlugin.check.js +3 -3
- package/schemas/plugins/css/CssAutoOrModuleParserOptions.check.js +3 -3
- package/schemas/plugins/css/CssGeneratorOptions.check.js +3 -3
- package/schemas/plugins/css/CssModuleGeneratorOptions.check.js +3 -3
- package/schemas/plugins/css/CssModuleParserOptions.check.js +3 -3
- package/schemas/plugins/css/CssParserOptions.check.js +3 -3
- package/schemas/plugins/debug/ProfilingPlugin.check.js +3 -3
- package/schemas/plugins/define/DotenvPluginOptions.check.js +7 -0
- package/schemas/plugins/define/DotenvPluginOptions.json +3 -0
- package/schemas/plugins/dll/DllPlugin.check.js +3 -3
- package/schemas/plugins/dll/DllReferencePlugin.check.js +3 -3
- package/schemas/plugins/ids/HashedModuleIdsPlugin.check.js +3 -3
- package/schemas/plugins/ids/OccurrenceChunkIdsPlugin.check.js +3 -3
- package/schemas/plugins/ids/OccurrenceModuleIdsPlugin.check.js +3 -3
- package/schemas/plugins/json/JsonModulesPluginGenerator.check.js +3 -3
- package/schemas/plugins/json/JsonModulesPluginParser.check.js +3 -3
- package/schemas/plugins/optimize/AggressiveSplittingPlugin.check.js +3 -3
- package/schemas/plugins/optimize/LimitChunkCountPlugin.check.js +3 -3
- package/schemas/plugins/optimize/MergeDuplicateChunksPlugin.check.js +3 -3
- package/schemas/plugins/optimize/MinChunkSizePlugin.check.js +3 -3
- package/schemas/plugins/output/CleanOptions.check.js +7 -0
- package/schemas/plugins/output/CleanOptions.json +3 -0
- package/schemas/plugins/schemes/HttpUriPlugin.check.js +3 -3
- package/schemas/plugins/schemes/VirtualUrlPlugin.check.js +3 -3
- package/schemas/plugins/sharing/ConsumeSharedPlugin.check.js +3 -3
- package/schemas/plugins/sharing/ProvideSharedPlugin.check.js +3 -3
- package/schemas/plugins/sharing/SharePlugin.check.js +3 -3
- package/types.d.ts +1482 -358
|
@@ -33,6 +33,7 @@ const {
|
|
|
33
33
|
positionAt
|
|
34
34
|
} = require("./syntax-parser");
|
|
35
35
|
|
|
36
|
+
/** @import { BuiltJavascriptModule } from "./JavascriptModule" */
|
|
36
37
|
/** @import { EcmaVersion, ParserOptions, ParserPlugin } from "./syntax-parser" */
|
|
37
38
|
/**
|
|
38
39
|
* @import {
|
|
@@ -138,7 +139,7 @@ const {
|
|
|
138
139
|
* @property {number=} lastHarmonyImportOrder deprecated, use `lastESMImportOrder`
|
|
139
140
|
*/
|
|
140
141
|
|
|
141
|
-
/** @typedef {ParserState & KnownJavascriptParserState} JavascriptParserState */
|
|
142
|
+
/** @typedef {ParserState<BuiltJavascriptModule> & KnownJavascriptParserState} JavascriptParserState */
|
|
142
143
|
|
|
143
144
|
/** @import Compilation from "../Compilation" */
|
|
144
145
|
/** @import Module from "../module/Module" */
|
|
@@ -181,6 +182,7 @@ const EMPTY_MODULE_DECLARATIONS = [];
|
|
|
181
182
|
// object pattern, so a tap on that type is not served from the list.
|
|
182
183
|
const BLOCK_DECLARATION_TYPES = new Set([
|
|
183
184
|
"VariableDeclaration",
|
|
185
|
+
"FunctionDeclaration",
|
|
184
186
|
"ClassDeclaration",
|
|
185
187
|
"ExportNamedDeclaration",
|
|
186
188
|
"ExportDefaultDeclaration"
|
|
@@ -387,7 +389,8 @@ class VariableInfo {
|
|
|
387
389
|
/** @import { TopLevelSymbol } from "../optimize/InnerGraph" */
|
|
388
390
|
|
|
389
391
|
/** @typedef {ESMSettings | ImportSettings | CommonJsImportSettings | TopLevelSymbol | CompatibilitySettings} KnownTagData */
|
|
390
|
-
|
|
392
|
+
// The open branch is whatever a plugin tags a variable with.
|
|
393
|
+
/** @typedef {KnownTagData | EXPECTED_OBJECT} TagData */
|
|
391
394
|
|
|
392
395
|
/**
|
|
393
396
|
* Defines the tag info type used by this module.
|
|
@@ -1120,6 +1123,35 @@ const hoistedDeclarationsOf = (node, trusted) => {
|
|
|
1120
1123
|
return collectHoistedDeclarations(node.body, EMPTY_HOISTED_DECLARATIONS);
|
|
1121
1124
|
};
|
|
1122
1125
|
|
|
1126
|
+
/**
|
|
1127
|
+
* Whether a statement is one of the list's own, or the declaration of an
|
|
1128
|
+
* `export` that is, rather than nested in one of them. It is found by its start
|
|
1129
|
+
* offset since the list is in source order.
|
|
1130
|
+
* @param {(Statement | ModuleDeclaration)[]} statements the list
|
|
1131
|
+
* @param {Statement | ModuleDeclaration | MaybeNamedFunctionDeclaration} statement the statement to find
|
|
1132
|
+
* @returns {boolean} whether the list holds it directly
|
|
1133
|
+
*/
|
|
1134
|
+
const holdsStatement = (statements, statement) => {
|
|
1135
|
+
const start = /** @type {Range} */ (statement.range)[0];
|
|
1136
|
+
let low = 0;
|
|
1137
|
+
let high = statements.length - 1;
|
|
1138
|
+
while (low <= high) {
|
|
1139
|
+
const middle = (low + high) >>> 1;
|
|
1140
|
+
const candidate = statements[middle];
|
|
1141
|
+
if (candidate === statement) return true;
|
|
1142
|
+
if (/** @type {Range} */ (candidate.range)[0] < start) low = middle + 1;
|
|
1143
|
+
else high = middle - 1;
|
|
1144
|
+
}
|
|
1145
|
+
// the last statement starting before it is the one that could hold it
|
|
1146
|
+
const holder = high >= 0 ? statements[high] : undefined;
|
|
1147
|
+
return (
|
|
1148
|
+
holder !== undefined &&
|
|
1149
|
+
(holder.type === "ExportNamedDeclaration" ||
|
|
1150
|
+
holder.type === "ExportDefaultDeclaration") &&
|
|
1151
|
+
holder.declaration === statement
|
|
1152
|
+
);
|
|
1153
|
+
};
|
|
1154
|
+
|
|
1123
1155
|
/**
|
|
1124
1156
|
* Which statements of a list declare into its block scope, scanned for an AST
|
|
1125
1157
|
* some other parser built. The parser's own record is read instead when there
|
|
@@ -1193,6 +1225,9 @@ const STRICT_MODE_OUTPUT_REASON =
|
|
|
1193
1225
|
const MODULE_GOAL_OUTPUT_REASON =
|
|
1194
1226
|
'The output is an ES module, where "await" is a reserved word.';
|
|
1195
1227
|
|
|
1228
|
+
/**
|
|
1229
|
+
* @extends {Parser<BuiltJavascriptModule>}
|
|
1230
|
+
*/
|
|
1196
1231
|
class JavascriptParser extends Parser {
|
|
1197
1232
|
/**
|
|
1198
1233
|
* Creates an instance of JavascriptParser.
|
|
@@ -1459,9 +1494,13 @@ class JavascriptParser extends Parser {
|
|
|
1459
1494
|
this.options = options;
|
|
1460
1495
|
|
|
1461
1496
|
/** @type {ScopeInfo} */
|
|
1462
|
-
this.scope = /** @type {
|
|
1497
|
+
this.scope = /** @type {ScopeInfo} */ (
|
|
1498
|
+
/** @type {ScopeInfo | undefined} */ (undefined)
|
|
1499
|
+
);
|
|
1463
1500
|
/** @type {JavascriptParserState} */
|
|
1464
|
-
this.state = /** @type {
|
|
1501
|
+
this.state = /** @type {JavascriptParserState} */ (
|
|
1502
|
+
/** @type {JavascriptParserState | undefined} */ (undefined)
|
|
1503
|
+
);
|
|
1465
1504
|
/** @type {Comment[] | undefined} */
|
|
1466
1505
|
this.comments = undefined;
|
|
1467
1506
|
// ASI overrides keyed by statement-end offset: true forces an ASI
|
|
@@ -1475,6 +1514,9 @@ class JavascriptParser extends Parser {
|
|
|
1475
1514
|
this.prevStatement = undefined;
|
|
1476
1515
|
/** @type {boolean} */
|
|
1477
1516
|
this._hasParserRecord = false;
|
|
1517
|
+
// the statements of the scope last hoisted into, which its block pass reads next
|
|
1518
|
+
/** @type {(Statement | ModuleDeclaration)[] | undefined} */
|
|
1519
|
+
this._scopeStatements = undefined;
|
|
1478
1520
|
// BACKWARD-COMPAT START
|
|
1479
1521
|
|
|
1480
1522
|
// WHY: the hoisting pass reaches declarations alone, so a tap that
|
|
@@ -2720,6 +2762,7 @@ class JavascriptParser extends Parser {
|
|
|
2720
2762
|
* @param {Program | BlockStatement} node the node owning the scope
|
|
2721
2763
|
*/
|
|
2722
2764
|
_preWalkScope(node) {
|
|
2765
|
+
this._scopeStatements = node.body;
|
|
2723
2766
|
// BACKWARD-COMPAT START
|
|
2724
2767
|
if (this._needsFullPreWalk || this.hooks.preStatement.taps.length !== 0) {
|
|
2725
2768
|
if (node.type === "Program") this.preWalkStatements(node.body);
|
|
@@ -2747,6 +2790,25 @@ class JavascriptParser extends Parser {
|
|
|
2747
2790
|
}
|
|
2748
2791
|
}
|
|
2749
2792
|
|
|
2793
|
+
/**
|
|
2794
|
+
* Whether a function declaration stays in its block rather than hoisting to
|
|
2795
|
+
* the scope last pre-walked, which only sloppy-mode Annex B lets it do.
|
|
2796
|
+
* @param {FunctionDeclaration | MaybeNamedFunctionDeclaration} statement function declaration
|
|
2797
|
+
* @returns {boolean} whether its block, not the scope, binds it
|
|
2798
|
+
*/
|
|
2799
|
+
_isBlockScopedFunction(statement) {
|
|
2800
|
+
const statements = this._scopeStatements;
|
|
2801
|
+
// WHY: strictness is read here, not in the parser: `javascript/auto`
|
|
2802
|
+
// reads a script as a strict module first.
|
|
2803
|
+
return (
|
|
2804
|
+
statements !== undefined &&
|
|
2805
|
+
(this.scope.isStrict ||
|
|
2806
|
+
statement.generator === true ||
|
|
2807
|
+
statement.async === true) &&
|
|
2808
|
+
!holdsStatement(statements, statement)
|
|
2809
|
+
);
|
|
2810
|
+
}
|
|
2811
|
+
|
|
2750
2812
|
// BACKWARD-COMPAT START
|
|
2751
2813
|
/**
|
|
2752
2814
|
* Walk every statement of a scope to declare what hoists to it. Only a tap
|
|
@@ -3032,8 +3094,18 @@ class JavascriptParser extends Parser {
|
|
|
3032
3094
|
let bail =
|
|
3033
3095
|
preStatement.taps.length !== 0 ? preStatement.call(statement) : undefined;
|
|
3034
3096
|
if (!bail) {
|
|
3035
|
-
|
|
3036
|
-
|
|
3097
|
+
// WHY: a block-scoped function is the block pass's; the full pre-walk
|
|
3098
|
+
// still shows it to `preStatement`, but not to the typed hooks, which
|
|
3099
|
+
// would declare it in the scope (`InnerGraphPlugin` tags it top-level).
|
|
3100
|
+
if (
|
|
3101
|
+
statement.type === "FunctionDeclaration" &&
|
|
3102
|
+
this._isBlockScopedFunction(statement)
|
|
3103
|
+
) {
|
|
3104
|
+
bail = true;
|
|
3105
|
+
} else {
|
|
3106
|
+
const typed = preStatementByType.get(statement.type);
|
|
3107
|
+
if (typed !== undefined) bail = typed.call(statement);
|
|
3108
|
+
}
|
|
3037
3109
|
}
|
|
3038
3110
|
if (bail) {
|
|
3039
3111
|
this.prevStatement =
|
|
@@ -3123,6 +3195,9 @@ class JavascriptParser extends Parser {
|
|
|
3123
3195
|
case "ClassDeclaration":
|
|
3124
3196
|
this.blockPreWalkClassDeclaration(statement);
|
|
3125
3197
|
break;
|
|
3198
|
+
case "FunctionDeclaration":
|
|
3199
|
+
this.blockPreWalkFunctionDeclaration(statement);
|
|
3200
|
+
break;
|
|
3126
3201
|
case "ExportNamedDeclaration":
|
|
3127
3202
|
this.blockPreWalkExportNamedDeclaration(statement);
|
|
3128
3203
|
break;
|
|
@@ -3569,6 +3644,17 @@ class JavascriptParser extends Parser {
|
|
|
3569
3644
|
}
|
|
3570
3645
|
}
|
|
3571
3646
|
|
|
3647
|
+
/**
|
|
3648
|
+
* Bind a function declaration in the block holding it, when it does not
|
|
3649
|
+
* hoist to the enclosing scope.
|
|
3650
|
+
* @param {FunctionDeclaration | MaybeNamedFunctionDeclaration} statement function declaration
|
|
3651
|
+
*/
|
|
3652
|
+
blockPreWalkFunctionDeclaration(statement) {
|
|
3653
|
+
if (statement.id && this._isBlockScopedFunction(statement)) {
|
|
3654
|
+
this.defineVariable(statement.id.name);
|
|
3655
|
+
}
|
|
3656
|
+
}
|
|
3657
|
+
|
|
3572
3658
|
/**
|
|
3573
3659
|
* Walk function declaration.
|
|
3574
3660
|
* @param {FunctionDeclaration | MaybeNamedFunctionDeclaration} statement function declaration
|
|
@@ -4409,7 +4495,7 @@ class JavascriptParser extends Parser {
|
|
|
4409
4495
|
* @param {Literal} expression literal
|
|
4410
4496
|
*/
|
|
4411
4497
|
_checkStrictModeLiteral(expression) {
|
|
4412
|
-
const raw =
|
|
4498
|
+
const raw = expression.raw;
|
|
4413
4499
|
if (raw === undefined) return;
|
|
4414
4500
|
if (typeof expression.value === "number") {
|
|
4415
4501
|
// Legacy octal (`0777`) or non-octal decimal (`08`) integer literal.
|
|
@@ -4666,7 +4752,7 @@ class JavascriptParser extends Parser {
|
|
|
4666
4752
|
this._walkPatternWriteMembers(
|
|
4667
4753
|
property.type === "RestElement"
|
|
4668
4754
|
? property.argument
|
|
4669
|
-
:
|
|
4755
|
+
: property.value,
|
|
4670
4756
|
node
|
|
4671
4757
|
);
|
|
4672
4758
|
}
|
|
@@ -6316,7 +6402,7 @@ class JavascriptParser extends Parser {
|
|
|
6316
6402
|
terminated: undefined,
|
|
6317
6403
|
definitions: new StackedMap()
|
|
6318
6404
|
};
|
|
6319
|
-
this.state = state;
|
|
6405
|
+
this.state = /** @type {JavascriptParserState} */ (state);
|
|
6320
6406
|
this.comments = comments;
|
|
6321
6407
|
this.semicolons = undefined;
|
|
6322
6408
|
// evaluating a defined, untagged identifier can only fall through when
|
|
@@ -6703,7 +6789,9 @@ class JavascriptParser extends Parser {
|
|
|
6703
6789
|
}
|
|
6704
6790
|
const loc = node.loc;
|
|
6705
6791
|
if (!loc) {
|
|
6706
|
-
return /** @type {DependencyLocation} */ (
|
|
6792
|
+
return /** @type {DependencyLocation} */ (
|
|
6793
|
+
/** @type {DependencyLocation | null | undefined} */ (loc)
|
|
6794
|
+
);
|
|
6707
6795
|
}
|
|
6708
6796
|
// a plain copy: a foreign parser's location class must not reach the cache
|
|
6709
6797
|
return {
|
|
@@ -7475,7 +7563,7 @@ class JavascriptParser extends Parser {
|
|
|
7475
7563
|
|
|
7476
7564
|
/**
|
|
7477
7565
|
* Whether a definition is a variable rather than a free name or a scope.
|
|
7478
|
-
* @param {
|
|
7566
|
+
* @param {ExportedVariableInfo | undefined} value a scope definition
|
|
7479
7567
|
* @returns {value is VariableInfo} true when the value is a variable
|
|
7480
7568
|
*/
|
|
7481
7569
|
static isVariableInfo(value) {
|