webpack 5.95.0 → 5.96.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/README.md +1 -1
- package/lib/AsyncDependenciesBlock.js +1 -1
- package/lib/BannerPlugin.js +2 -1
- package/lib/Chunk.js +30 -0
- package/lib/ChunkGraph.js +11 -6
- package/lib/ChunkGroup.js +2 -2
- package/lib/CleanPlugin.js +4 -5
- package/lib/CodeGenerationResults.js +6 -5
- package/lib/Compilation.js +71 -48
- package/lib/Compiler.js +7 -5
- package/lib/ConcatenationScope.js +7 -20
- package/lib/ContextModule.js +7 -8
- package/lib/CssModule.js +25 -21
- package/lib/DefinePlugin.js +14 -8
- package/lib/DelegatedModule.js +3 -3
- package/lib/DllModule.js +4 -4
- package/lib/DynamicEntryPlugin.js +29 -22
- package/lib/EvalDevToolModulePlugin.js +5 -2
- package/lib/EvalSourceMapDevToolPlugin.js +5 -2
- package/lib/ExternalModule.js +40 -7
- package/lib/ExternalModuleFactoryPlugin.js +33 -9
- package/lib/FileSystemInfo.js +12 -8
- package/lib/Generator.js +5 -4
- package/lib/HotModuleReplacementPlugin.js +8 -6
- package/lib/IgnorePlugin.js +19 -1
- package/lib/LoaderOptionsPlugin.js +3 -1
- package/lib/Module.js +9 -8
- package/lib/ModuleSourceTypesConstants.js +100 -0
- package/lib/NormalModule.js +27 -17
- package/lib/NormalModuleFactory.js +38 -22
- package/lib/OptionsApply.js +12 -1
- package/lib/ProgressPlugin.js +50 -10
- package/lib/RawModule.js +3 -4
- package/lib/RuntimeModule.js +3 -4
- package/lib/RuntimePlugin.js +11 -4
- package/lib/RuntimeTemplate.js +13 -42
- package/lib/SourceMapDevToolPlugin.js +10 -7
- package/lib/Watching.js +2 -2
- package/lib/WebpackOptionsApply.js +42 -21
- package/lib/asset/AssetGenerator.js +347 -194
- package/lib/asset/AssetModulesPlugin.js +2 -1
- package/lib/asset/AssetSourceGenerator.js +82 -27
- package/lib/asset/RawDataUrlModule.js +5 -4
- package/lib/buildChunkGraph.js +2 -2
- package/lib/cache/PackFileCacheStrategy.js +69 -31
- package/lib/cache/ResolverCachePlugin.js +248 -173
- package/lib/config/defaults.js +134 -126
- package/lib/container/ContainerEntryModule.js +3 -4
- package/lib/container/ContainerPlugin.js +8 -0
- package/lib/container/FallbackModule.js +2 -2
- package/lib/container/HoistContainerReferencesPlugin.js +250 -0
- package/lib/container/ModuleFederationPlugin.js +38 -1
- package/lib/container/RemoteModule.js +4 -2
- package/lib/container/RemoteRuntimeModule.js +4 -2
- package/lib/css/CssExportsGenerator.js +16 -12
- package/lib/css/CssGenerator.js +22 -16
- package/lib/css/CssLoadingRuntimeModule.js +7 -6
- package/lib/css/CssModulesPlugin.js +122 -77
- package/lib/css/CssParser.js +655 -526
- package/lib/css/walkCssTokens.js +1168 -338
- package/lib/debug/ProfilingPlugin.js +5 -0
- package/lib/dependencies/CommonJsExportsParserPlugin.js +5 -2
- package/lib/dependencies/CommonJsImportsParserPlugin.js +3 -6
- package/lib/dependencies/CssExportDependency.js +3 -3
- package/lib/dependencies/CssLocalIdentifierDependency.js +26 -17
- package/lib/dependencies/CssUrlDependency.js +33 -3
- package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +3 -3
- package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +39 -14
- package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +15 -82
- package/lib/dependencies/HarmonyImportSpecifierDependency.js +5 -2
- package/lib/dependencies/ImportParserPlugin.js +9 -7
- package/lib/dependencies/LoaderPlugin.js +19 -0
- package/lib/dependencies/SystemPlugin.js +2 -1
- package/lib/dependencies/URLPlugin.js +7 -1
- package/lib/dependencies/WorkerPlugin.js +1 -1
- package/lib/esm/ModuleChunkLoadingRuntimeModule.js +4 -2
- package/lib/hmr/HotModuleReplacement.runtime.js +1 -0
- package/lib/hmr/JavascriptHotModuleReplacement.runtime.js +1 -0
- package/lib/hmr/LazyCompilationPlugin.js +16 -4
- package/lib/hmr/lazyCompilationBackend.js +1 -7
- package/lib/index.js +37 -7
- package/lib/javascript/EnableChunkLoadingPlugin.js +2 -2
- package/lib/javascript/JavascriptGenerator.js +8 -8
- package/lib/javascript/JavascriptModulesPlugin.js +126 -73
- package/lib/javascript/JavascriptParser.js +338 -117
- package/lib/json/JsonGenerator.js +5 -5
- package/lib/library/EnableLibraryPlugin.js +2 -2
- package/lib/library/ExportPropertyLibraryPlugin.js +1 -1
- package/lib/library/UmdLibraryPlugin.js +16 -8
- package/lib/logging/Logger.js +11 -11
- package/lib/logging/createConsoleLogger.js +14 -14
- package/lib/logging/truncateArgs.js +1 -1
- package/lib/node/NodeWatchFileSystem.js +3 -1
- package/lib/node/ReadFileCompileAsyncWasmPlugin.js +20 -18
- package/lib/node/ReadFileCompileWasmPlugin.js +1 -2
- package/lib/node/nodeConsole.js +11 -8
- package/lib/optimize/AggressiveSplittingPlugin.js +21 -7
- package/lib/optimize/ConcatenatedModule.js +43 -145
- package/lib/optimize/FlagIncludedChunksPlugin.js +6 -0
- package/lib/optimize/InnerGraphPlugin.js +57 -16
- package/lib/optimize/LimitChunkCountPlugin.js +2 -4
- package/lib/optimize/ModuleConcatenationPlugin.js +4 -2
- package/lib/optimize/RealContentHashPlugin.js +1 -1
- package/lib/optimize/SideEffectsFlagPlugin.js +6 -3
- package/lib/rules/RuleSetCompiler.js +2 -2
- package/lib/runtime/GetChunkFilenameRuntimeModule.js +2 -2
- package/lib/schemes/DataUriPlugin.js +1 -1
- package/lib/serialization/BinaryMiddleware.js +32 -19
- package/lib/serialization/ObjectMiddleware.js +23 -9
- package/lib/serialization/SerializerMiddleware.js +3 -2
- package/lib/serialization/types.js +2 -2
- package/lib/sharing/ConsumeSharedModule.js +2 -3
- package/lib/sharing/ConsumeSharedRuntimeModule.js +3 -1
- package/lib/sharing/ProvideSharedModule.js +2 -3
- package/lib/stats/DefaultStatsFactoryPlugin.js +22 -20
- package/lib/stats/StatsFactory.js +12 -12
- package/lib/stats/StatsPrinter.js +7 -7
- package/lib/util/AsyncQueue.js +17 -1
- package/lib/util/IterableHelpers.js +1 -1
- package/lib/util/SetHelpers.js +1 -1
- package/lib/util/cleverMerge.js +48 -24
- package/lib/util/concatenate.js +227 -0
- package/lib/util/create-schema-validation.js +22 -9
- package/lib/util/deprecation.js +86 -28
- package/lib/util/fs.js +9 -9
- package/lib/util/hash/wasm-hash.js +12 -1
- package/lib/util/magicComment.js +21 -0
- package/lib/util/makeSerializable.js +24 -1
- package/lib/util/memoize.js +2 -1
- package/lib/util/runtime.js +4 -1
- package/lib/util/semver.js +130 -23
- package/lib/wasm/EnableWasmLoadingPlugin.js +2 -2
- package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +3 -3
- package/lib/wasm-async/AsyncWebAssemblyGenerator.js +5 -5
- package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +5 -5
- package/lib/wasm-sync/WebAssemblyGenerator.js +8 -9
- package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +5 -5
- package/lib/web/FetchCompileAsyncWasmPlugin.js +1 -2
- package/lib/web/FetchCompileWasmPlugin.js +1 -2
- package/lib/web/JsonpChunkLoadingRuntimeModule.js +6 -6
- package/package.json +18 -19
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +8 -2
- package/types.d.ts +801 -259
- package/lib/util/mergeScope.js +0 -76
@@ -5,13 +5,16 @@
|
|
5
5
|
|
6
6
|
"use strict";
|
7
7
|
|
8
|
-
const { Parser: AcornParser } = require("acorn");
|
9
|
-
const { importAttributesOrAssertions } = require("acorn-import-attributes");
|
8
|
+
const { Parser: AcornParser, tokTypes } = require("acorn");
|
10
9
|
const { SyncBailHook, HookMap } = require("tapable");
|
11
10
|
const vm = require("vm");
|
12
11
|
const Parser = require("../Parser");
|
13
12
|
const StackedMap = require("../util/StackedMap");
|
14
13
|
const binarySearchBounds = require("../util/binarySearchBounds");
|
14
|
+
const {
|
15
|
+
webpackCommentRegExp,
|
16
|
+
createMagicCommentContext
|
17
|
+
} = require("../util/magicComment");
|
15
18
|
const memoize = require("../util/memoize");
|
16
19
|
const BasicEvaluatedExpression = require("./BasicEvaluatedExpression");
|
17
20
|
|
@@ -23,11 +26,9 @@ const BasicEvaluatedExpression = require("./BasicEvaluatedExpression");
|
|
23
26
|
/** @typedef {import("estree").CallExpression} CallExpression */
|
24
27
|
/** @typedef {import("estree").BaseCallExpression} BaseCallExpression */
|
25
28
|
/** @typedef {import("estree").StaticBlock} StaticBlock */
|
26
|
-
/** @typedef {import("estree").ImportExpression} ImportExpression */
|
27
29
|
/** @typedef {import("estree").ClassDeclaration} ClassDeclaration */
|
28
30
|
/** @typedef {import("estree").ForStatement} ForStatement */
|
29
31
|
/** @typedef {import("estree").SwitchStatement} SwitchStatement */
|
30
|
-
/** @typedef {import("estree").ExportNamedDeclaration} ExportNamedDeclaration */
|
31
32
|
/** @typedef {import("estree").ClassExpression} ClassExpression */
|
32
33
|
/** @typedef {import("estree").Comment} Comment */
|
33
34
|
/** @typedef {import("estree").ConditionalExpression} ConditionalExpression */
|
@@ -67,7 +68,6 @@ const BasicEvaluatedExpression = require("./BasicEvaluatedExpression");
|
|
67
68
|
/** @typedef {import("estree").WithStatement} WithStatement */
|
68
69
|
/** @typedef {import("estree").ThrowStatement} ThrowStatement */
|
69
70
|
/** @typedef {import("estree").MethodDefinition} MethodDefinition */
|
70
|
-
/** @typedef {import("estree").ModuleDeclaration} ModuleDeclaration */
|
71
71
|
/** @typedef {import("estree").NewExpression} NewExpression */
|
72
72
|
/** @typedef {import("estree").SpreadElement} SpreadElement */
|
73
73
|
/** @typedef {import("estree").FunctionExpression} FunctionExpression */
|
@@ -77,13 +77,11 @@ const BasicEvaluatedExpression = require("./BasicEvaluatedExpression");
|
|
77
77
|
/** @typedef {import("estree").FunctionDeclaration} FunctionDeclaration */
|
78
78
|
/** @typedef {import("estree").DoWhileStatement} DoWhileStatement */
|
79
79
|
/** @typedef {import("estree").TryStatement} TryStatement */
|
80
|
-
/** @typedef {import("estree").Node}
|
80
|
+
/** @typedef {import("estree").Node} Node */
|
81
81
|
/** @typedef {import("estree").Program} Program */
|
82
82
|
/** @typedef {import("estree").Directive} Directive */
|
83
83
|
/** @typedef {import("estree").Statement} Statement */
|
84
|
-
/** @typedef {import("estree").ImportDeclaration} ImportDeclaration */
|
85
84
|
/** @typedef {import("estree").ExportDefaultDeclaration} ExportDefaultDeclaration */
|
86
|
-
/** @typedef {import("estree").ExportAllDeclaration} ExportAllDeclaration */
|
87
85
|
/** @typedef {import("estree").Super} Super */
|
88
86
|
/** @typedef {import("estree").TaggedTemplateExpression} TaggedTemplateExpression */
|
89
87
|
/** @typedef {import("estree").TemplateLiteral} TemplateLiteral */
|
@@ -94,12 +92,20 @@ const BasicEvaluatedExpression = require("./BasicEvaluatedExpression");
|
|
94
92
|
*/
|
95
93
|
/** @typedef {import("../Parser").ParserState} ParserState */
|
96
94
|
/** @typedef {import("../Parser").PreparsedAst} PreparsedAst */
|
97
|
-
/** @typedef {{declaredScope: ScopeInfo, freeName: string | true, tagInfo: TagInfo | undefined}} VariableInfoInterface */
|
95
|
+
/** @typedef {{declaredScope: ScopeInfo, freeName: string | true | undefined, tagInfo: TagInfo | undefined}} VariableInfoInterface */
|
98
96
|
/** @typedef {{ name: string | VariableInfo, rootInfo: string | VariableInfo, getMembers: () => string[], getMembersOptionals: () => boolean[], getMemberRanges: () => Range[] }} GetInfoResult */
|
99
97
|
/** @typedef {Statement | ModuleDeclaration | Expression} StatementPathItem */
|
100
|
-
/** @typedef {
|
101
|
-
|
102
|
-
/** @typedef {
|
98
|
+
/** @typedef {function(string): void} OnIdentString */
|
99
|
+
/** @typedef {function(string, Identifier): void} OnIdent */
|
100
|
+
/** @typedef {StatementPathItem[]} StatementPath */
|
101
|
+
|
102
|
+
// TODO remove cast when @types/estree has been updated to import assertions
|
103
|
+
/** @typedef {import("estree").BaseNode & { type: "ImportAttribute", key: Identifier | Literal, value: Literal }} ImportAttribute */
|
104
|
+
/** @typedef {import("estree").ImportDeclaration & { attributes?: Array<ImportAttribute> }} ImportDeclaration */
|
105
|
+
/** @typedef {import("estree").ExportNamedDeclaration & { attributes?: Array<ImportAttribute> }} ExportNamedDeclaration */
|
106
|
+
/** @typedef {import("estree").ExportAllDeclaration & { attributes?: Array<ImportAttribute> }} ExportAllDeclaration */
|
107
|
+
/** @typedef {import("estree").ImportExpression & { options?: Expression | null }} ImportExpression */
|
108
|
+
/** @typedef {ImportDeclaration | ExportNamedDeclaration | ExportDefaultDeclaration | ExportAllDeclaration} ModuleDeclaration */
|
103
109
|
|
104
110
|
/** @type {string[]} */
|
105
111
|
const EMPTY_ARRAY = [];
|
@@ -107,9 +113,146 @@ const ALLOWED_MEMBER_TYPES_CALL_EXPRESSION = 0b01;
|
|
107
113
|
const ALLOWED_MEMBER_TYPES_EXPRESSION = 0b10;
|
108
114
|
const ALLOWED_MEMBER_TYPES_ALL = 0b11;
|
109
115
|
|
116
|
+
const LEGACY_ASSERT_ATTRIBUTES = Symbol("assert");
|
117
|
+
|
118
|
+
/**
|
119
|
+
* @param {any} Parser parser
|
120
|
+
* @returns {typeof AcornParser} extender acorn parser
|
121
|
+
*/
|
122
|
+
const importAssertions = Parser =>
|
123
|
+
/** @type {typeof AcornParser} */ (
|
124
|
+
/** @type {unknown} */ (
|
125
|
+
class extends Parser {
|
126
|
+
parseWithClause() {
|
127
|
+
const nodes = [];
|
128
|
+
|
129
|
+
const isAssertLegacy = this.value === "assert";
|
130
|
+
|
131
|
+
if (isAssertLegacy) {
|
132
|
+
if (!this.eat(tokTypes.name)) {
|
133
|
+
return nodes;
|
134
|
+
}
|
135
|
+
} else if (!this.eat(tokTypes._with)) {
|
136
|
+
return nodes;
|
137
|
+
}
|
138
|
+
|
139
|
+
this.expect(tokTypes.braceL);
|
140
|
+
|
141
|
+
const attributeKeys = {};
|
142
|
+
let first = true;
|
143
|
+
|
144
|
+
while (!this.eat(tokTypes.braceR)) {
|
145
|
+
if (!first) {
|
146
|
+
this.expect(tokTypes.comma);
|
147
|
+
if (this.afterTrailingComma(tokTypes.braceR)) {
|
148
|
+
break;
|
149
|
+
}
|
150
|
+
} else {
|
151
|
+
first = false;
|
152
|
+
}
|
153
|
+
|
154
|
+
const attr = this.parseImportAttribute();
|
155
|
+
const keyName =
|
156
|
+
attr.key.type === "Identifier" ? attr.key.name : attr.key.value;
|
157
|
+
|
158
|
+
if (Object.prototype.hasOwnProperty.call(attributeKeys, keyName)) {
|
159
|
+
this.raiseRecoverable(
|
160
|
+
attr.key.start,
|
161
|
+
`Duplicate attribute key '${keyName}'`
|
162
|
+
);
|
163
|
+
}
|
164
|
+
|
165
|
+
attributeKeys[keyName] = true;
|
166
|
+
nodes.push(attr);
|
167
|
+
}
|
168
|
+
|
169
|
+
if (isAssertLegacy) {
|
170
|
+
nodes[LEGACY_ASSERT_ATTRIBUTES] = true;
|
171
|
+
}
|
172
|
+
|
173
|
+
return nodes;
|
174
|
+
}
|
175
|
+
}
|
176
|
+
)
|
177
|
+
);
|
178
|
+
|
110
179
|
// Syntax: https://developer.mozilla.org/en/SpiderMonkey/Parser_API
|
180
|
+
const parser = AcornParser.extend(importAssertions);
|
111
181
|
|
112
|
-
|
182
|
+
/** @typedef {Record<string, string> & { _isLegacyAssert?: boolean }} ImportAttributes */
|
183
|
+
|
184
|
+
/**
|
185
|
+
* @param {ImportDeclaration | ExportNamedDeclaration | ExportAllDeclaration | ImportExpression} node node with assertions
|
186
|
+
* @returns {ImportAttributes | undefined} import attributes
|
187
|
+
*/
|
188
|
+
const getImportAttributes = node => {
|
189
|
+
if (node.type === "ImportExpression") {
|
190
|
+
if (
|
191
|
+
node.options &&
|
192
|
+
node.options.type === "ObjectExpression" &&
|
193
|
+
node.options.properties[0] &&
|
194
|
+
node.options.properties[0].type === "Property" &&
|
195
|
+
node.options.properties[0].key.type === "Identifier" &&
|
196
|
+
(node.options.properties[0].key.name === "with" ||
|
197
|
+
node.options.properties[0].key.name === "assert") &&
|
198
|
+
node.options.properties[0].value.type === "ObjectExpression" &&
|
199
|
+
node.options.properties[0].value.properties.length > 0
|
200
|
+
) {
|
201
|
+
const properties =
|
202
|
+
/** @type {Property[]} */
|
203
|
+
(node.options.properties[0].value.properties);
|
204
|
+
const result = /** @type {ImportAttributes} */ ({});
|
205
|
+
for (const property of properties) {
|
206
|
+
const key =
|
207
|
+
/** @type {string} */
|
208
|
+
(
|
209
|
+
property.key.type === "Identifier"
|
210
|
+
? property.key.name
|
211
|
+
: /** @type {Literal} */ (property.key).value
|
212
|
+
);
|
213
|
+
result[key] =
|
214
|
+
/** @type {string} */
|
215
|
+
(/** @type {Literal} */ (property.value).value);
|
216
|
+
}
|
217
|
+
const key =
|
218
|
+
node.options.properties[0].key.type === "Identifier"
|
219
|
+
? node.options.properties[0].key.name
|
220
|
+
: /** @type {Literal} */ (node.options.properties[0].key).value;
|
221
|
+
|
222
|
+
if (key === "assert") {
|
223
|
+
result._isLegacyAssert = true;
|
224
|
+
}
|
225
|
+
|
226
|
+
return result;
|
227
|
+
}
|
228
|
+
|
229
|
+
return;
|
230
|
+
}
|
231
|
+
|
232
|
+
if (node.attributes === undefined || node.attributes.length === 0) {
|
233
|
+
return;
|
234
|
+
}
|
235
|
+
|
236
|
+
const result = /** @type {ImportAttributes} */ ({});
|
237
|
+
|
238
|
+
for (const attribute of node.attributes) {
|
239
|
+
const key =
|
240
|
+
/** @type {string} */
|
241
|
+
(
|
242
|
+
attribute.key.type === "Identifier"
|
243
|
+
? attribute.key.name
|
244
|
+
: attribute.key.value
|
245
|
+
);
|
246
|
+
|
247
|
+
result[key] = /** @type {string} */ (attribute.value.value);
|
248
|
+
}
|
249
|
+
|
250
|
+
if (node.attributes[LEGACY_ASSERT_ATTRIBUTES]) {
|
251
|
+
result._isLegacyAssert = true;
|
252
|
+
}
|
253
|
+
|
254
|
+
return result;
|
255
|
+
};
|
113
256
|
|
114
257
|
class VariableInfo {
|
115
258
|
/**
|
@@ -228,12 +371,9 @@ const defaultParserOptions = {
|
|
228
371
|
sourceType: "module",
|
229
372
|
// https://github.com/tc39/proposal-hashbang
|
230
373
|
allowHashBang: true,
|
231
|
-
onComment:
|
374
|
+
onComment: undefined
|
232
375
|
};
|
233
376
|
|
234
|
-
// regexp to match at least one "magic comment"
|
235
|
-
const webpackCommentRegExp = new RegExp(/(^|\W)webpack[A-Z]{1,}[A-Za-z]{1,}:/);
|
236
|
-
|
237
377
|
const EMPTY_COMMENT_OPTIONS = {
|
238
378
|
options: null,
|
239
379
|
errors: null
|
@@ -246,25 +386,25 @@ class JavascriptParser extends Parser {
|
|
246
386
|
constructor(sourceType = "auto") {
|
247
387
|
super();
|
248
388
|
this.hooks = Object.freeze({
|
249
|
-
/** @type {HookMap<SyncBailHook<[UnaryExpression], BasicEvaluatedExpression |
|
389
|
+
/** @type {HookMap<SyncBailHook<[UnaryExpression], BasicEvaluatedExpression | null | undefined>>} */
|
250
390
|
evaluateTypeof: new HookMap(() => new SyncBailHook(["expression"])),
|
251
|
-
/** @type {HookMap<SyncBailHook<[Expression | SpreadElement], BasicEvaluatedExpression |
|
391
|
+
/** @type {HookMap<SyncBailHook<[Expression | SpreadElement | PrivateIdentifier], BasicEvaluatedExpression | null | undefined>>} */
|
252
392
|
evaluate: new HookMap(() => new SyncBailHook(["expression"])),
|
253
|
-
/** @type {HookMap<SyncBailHook<[Identifier | ThisExpression | MemberExpression | MetaProperty], BasicEvaluatedExpression |
|
393
|
+
/** @type {HookMap<SyncBailHook<[Identifier | ThisExpression | MemberExpression | MetaProperty], BasicEvaluatedExpression | null | undefined>>} */
|
254
394
|
evaluateIdentifier: new HookMap(() => new SyncBailHook(["expression"])),
|
255
|
-
/** @type {HookMap<SyncBailHook<[Identifier | ThisExpression | MemberExpression], BasicEvaluatedExpression |
|
395
|
+
/** @type {HookMap<SyncBailHook<[Identifier | ThisExpression | MemberExpression], BasicEvaluatedExpression | null | undefined>>} */
|
256
396
|
evaluateDefinedIdentifier: new HookMap(
|
257
397
|
() => new SyncBailHook(["expression"])
|
258
398
|
),
|
259
|
-
/** @type {HookMap<SyncBailHook<[NewExpression], BasicEvaluatedExpression |
|
399
|
+
/** @type {HookMap<SyncBailHook<[NewExpression], BasicEvaluatedExpression | null | undefined>>} */
|
260
400
|
evaluateNewExpression: new HookMap(
|
261
401
|
() => new SyncBailHook(["expression"])
|
262
402
|
),
|
263
|
-
/** @type {HookMap<SyncBailHook<[CallExpression], BasicEvaluatedExpression |
|
403
|
+
/** @type {HookMap<SyncBailHook<[CallExpression], BasicEvaluatedExpression | null | undefined>>} */
|
264
404
|
evaluateCallExpression: new HookMap(
|
265
405
|
() => new SyncBailHook(["expression"])
|
266
406
|
),
|
267
|
-
/** @type {HookMap<SyncBailHook<[CallExpression, BasicEvaluatedExpression], BasicEvaluatedExpression |
|
407
|
+
/** @type {HookMap<SyncBailHook<[CallExpression, BasicEvaluatedExpression], BasicEvaluatedExpression | null | undefined>>} */
|
268
408
|
evaluateCallExpressionMember: new HookMap(
|
269
409
|
() => new SyncBailHook(["expression", "param"])
|
270
410
|
),
|
@@ -298,7 +438,7 @@ class JavascriptParser extends Parser {
|
|
298
438
|
label: new HookMap(() => new SyncBailHook(["statement"])),
|
299
439
|
/** @type {SyncBailHook<[ImportDeclaration, ImportSource], boolean | void>} */
|
300
440
|
import: new SyncBailHook(["statement", "source"]),
|
301
|
-
/** @type {SyncBailHook<[ImportDeclaration, ImportSource, string, string], boolean | void>} */
|
441
|
+
/** @type {SyncBailHook<[ImportDeclaration, ImportSource, string | null, string], boolean | void>} */
|
302
442
|
importSpecifier: new SyncBailHook([
|
303
443
|
"statement",
|
304
444
|
"source",
|
@@ -320,7 +460,7 @@ class JavascriptParser extends Parser {
|
|
320
460
|
"exportName",
|
321
461
|
"index"
|
322
462
|
]),
|
323
|
-
/** @type {SyncBailHook<[ExportNamedDeclaration | ExportAllDeclaration, ImportSource, string, string, number | undefined], boolean | void>} */
|
463
|
+
/** @type {SyncBailHook<[ExportNamedDeclaration | ExportAllDeclaration, ImportSource, string | null, string | null, number | undefined], boolean | void>} */
|
324
464
|
exportImportSpecifier: new SyncBailHook([
|
325
465
|
"statement",
|
326
466
|
"source",
|
@@ -435,17 +575,14 @@ class JavascriptParser extends Parser {
|
|
435
575
|
this.comments = undefined;
|
436
576
|
/** @type {Set<number> | undefined} */
|
437
577
|
this.semicolons = undefined;
|
438
|
-
/** @type {
|
578
|
+
/** @type {StatementPath | undefined} */
|
439
579
|
this.statementPath = undefined;
|
440
580
|
/** @type {Statement | ModuleDeclaration | Expression | undefined} */
|
441
581
|
this.prevStatement = undefined;
|
442
582
|
/** @type {WeakMap<Expression, Set<DestructuringAssignmentProperty>> | undefined} */
|
443
583
|
this.destructuringAssignmentProperties = undefined;
|
444
584
|
this.currentTagData = undefined;
|
445
|
-
this.magicCommentContext =
|
446
|
-
name: "Webpack Magic Comment Parser",
|
447
|
-
codeGeneration: { strings: false, wasm: false }
|
448
|
-
});
|
585
|
+
this.magicCommentContext = createMagicCommentContext();
|
449
586
|
this._initializeEvaluating();
|
450
587
|
}
|
451
588
|
|
@@ -552,7 +689,7 @@ class JavascriptParser extends Parser {
|
|
552
689
|
|
553
690
|
const left = this.evaluateExpression(expr.left);
|
554
691
|
let returnRight = false;
|
555
|
-
/** @type {boolean|undefined} */
|
692
|
+
/** @type {boolean | undefined} */
|
556
693
|
let allowedRight;
|
557
694
|
if (expr.operator === "&&") {
|
558
695
|
const leftAsBool = left.asBool();
|
@@ -1105,7 +1242,7 @@ class JavascriptParser extends Parser {
|
|
1105
1242
|
case "MetaProperty": {
|
1106
1243
|
const res = this.callHooksForName(
|
1107
1244
|
this.hooks.evaluateTypeof,
|
1108
|
-
getRootName(expr.argument),
|
1245
|
+
/** @type {string} */ (getRootName(expr.argument)),
|
1109
1246
|
expr
|
1110
1247
|
);
|
1111
1248
|
if (res !== undefined) return res;
|
@@ -1211,7 +1348,7 @@ class JavascriptParser extends Parser {
|
|
1211
1348
|
}
|
1212
1349
|
});
|
1213
1350
|
/**
|
1214
|
-
* @param {
|
1351
|
+
* @param {"Identifier" | "ThisExpression" | "MemberExpression"} exprType expression type name
|
1215
1352
|
* @param {function(Expression | SpreadElement): GetInfoResult | undefined} getInfo get info
|
1216
1353
|
* @returns {void}
|
1217
1354
|
*/
|
@@ -1221,9 +1358,10 @@ class JavascriptParser extends Parser {
|
|
1221
1358
|
/** @type {GetInfoResult | undefined} */
|
1222
1359
|
let cachedInfo;
|
1223
1360
|
this.hooks.evaluate.for(exprType).tap("JavascriptParser", expr => {
|
1224
|
-
const expression =
|
1361
|
+
const expression =
|
1362
|
+
/** @type {Identifier | ThisExpression | MemberExpression} */ (expr);
|
1225
1363
|
|
1226
|
-
const info = getInfo(
|
1364
|
+
const info = getInfo(expression);
|
1227
1365
|
if (info !== undefined) {
|
1228
1366
|
return this.callHooksForInfoWithFallback(
|
1229
1367
|
this.hooks.evaluateIdentifier,
|
@@ -1245,7 +1383,11 @@ class JavascriptParser extends Parser {
|
|
1245
1383
|
this.hooks.evaluate
|
1246
1384
|
.for(exprType)
|
1247
1385
|
.tap({ name: "JavascriptParser", stage: 100 }, expr => {
|
1248
|
-
const
|
1386
|
+
const expression =
|
1387
|
+
/** @type {Identifier | ThisExpression | MemberExpression} */
|
1388
|
+
(expr);
|
1389
|
+
const info =
|
1390
|
+
cachedExpression === expression ? cachedInfo : getInfo(expression);
|
1249
1391
|
if (info !== undefined) {
|
1250
1392
|
return new BasicEvaluatedExpression()
|
1251
1393
|
.setIdentifier(
|
@@ -1255,7 +1397,7 @@ class JavascriptParser extends Parser {
|
|
1255
1397
|
info.getMembersOptionals,
|
1256
1398
|
info.getMemberRanges
|
1257
1399
|
)
|
1258
|
-
.setRange(/** @type {Range} */ (
|
1400
|
+
.setRange(/** @type {Range} */ (expression.range));
|
1259
1401
|
}
|
1260
1402
|
});
|
1261
1403
|
this.hooks.finish.tap("JavascriptParser", () => {
|
@@ -1298,7 +1440,7 @@ class JavascriptParser extends Parser {
|
|
1298
1440
|
|
1299
1441
|
return this.callHooksForName(
|
1300
1442
|
this.hooks.evaluateIdentifier,
|
1301
|
-
getRootName(
|
1443
|
+
/** @type {string} */ (getRootName(metaProperty)),
|
1302
1444
|
metaProperty
|
1303
1445
|
);
|
1304
1446
|
});
|
@@ -1711,7 +1853,7 @@ class JavascriptParser extends Parser {
|
|
1711
1853
|
}
|
1712
1854
|
|
1713
1855
|
/**
|
1714
|
-
* @param {Expression} expr expression
|
1856
|
+
* @param {Expression | SpreadElement} expr expression
|
1715
1857
|
* @returns {string | VariableInfoInterface | undefined} identifier
|
1716
1858
|
*/
|
1717
1859
|
getRenameIdentifier(expr) {
|
@@ -1807,9 +1949,12 @@ class JavascriptParser extends Parser {
|
|
1807
1949
|
* @param {Statement | ModuleDeclaration} statement statement
|
1808
1950
|
*/
|
1809
1951
|
preWalkStatement(statement) {
|
1810
|
-
|
1952
|
+
/** @type {StatementPath} */
|
1953
|
+
(this.statementPath).push(statement);
|
1811
1954
|
if (this.hooks.preStatement.call(statement)) {
|
1812
|
-
this.prevStatement =
|
1955
|
+
this.prevStatement =
|
1956
|
+
/** @type {StatementPath} */
|
1957
|
+
(this.statementPath).pop();
|
1813
1958
|
return;
|
1814
1959
|
}
|
1815
1960
|
switch (statement.type) {
|
@@ -1853,16 +1998,21 @@ class JavascriptParser extends Parser {
|
|
1853
1998
|
this.preWalkWithStatement(statement);
|
1854
1999
|
break;
|
1855
2000
|
}
|
1856
|
-
this.prevStatement =
|
2001
|
+
this.prevStatement =
|
2002
|
+
/** @type {StatementPath} */
|
2003
|
+
(this.statementPath).pop();
|
1857
2004
|
}
|
1858
2005
|
|
1859
2006
|
/**
|
1860
2007
|
* @param {Statement | ModuleDeclaration} statement statement
|
1861
2008
|
*/
|
1862
2009
|
blockPreWalkStatement(statement) {
|
1863
|
-
|
2010
|
+
/** @type {StatementPath} */
|
2011
|
+
(this.statementPath).push(statement);
|
1864
2012
|
if (this.hooks.blockPreStatement.call(statement)) {
|
1865
|
-
this.prevStatement =
|
2013
|
+
this.prevStatement =
|
2014
|
+
/** @type {StatementPath} */
|
2015
|
+
(this.statementPath).pop();
|
1866
2016
|
return;
|
1867
2017
|
}
|
1868
2018
|
switch (statement.type) {
|
@@ -1887,16 +2037,21 @@ class JavascriptParser extends Parser {
|
|
1887
2037
|
case "ExpressionStatement":
|
1888
2038
|
this.blockPreWalkExpressionStatement(statement);
|
1889
2039
|
}
|
1890
|
-
this.prevStatement =
|
2040
|
+
this.prevStatement =
|
2041
|
+
/** @type {StatementPath} */
|
2042
|
+
(this.statementPath).pop();
|
1891
2043
|
}
|
1892
2044
|
|
1893
2045
|
/**
|
1894
2046
|
* @param {Statement | ModuleDeclaration} statement statement
|
1895
2047
|
*/
|
1896
2048
|
walkStatement(statement) {
|
1897
|
-
|
2049
|
+
/** @type {StatementPath} */
|
2050
|
+
(this.statementPath).push(statement);
|
1898
2051
|
if (this.hooks.statement.call(statement) !== undefined) {
|
1899
|
-
this.prevStatement =
|
2052
|
+
this.prevStatement =
|
2053
|
+
/** @type {StatementPath} */
|
2054
|
+
(this.statementPath).pop();
|
1900
2055
|
return;
|
1901
2056
|
}
|
1902
2057
|
switch (statement.type) {
|
@@ -1958,7 +2113,9 @@ class JavascriptParser extends Parser {
|
|
1958
2113
|
this.walkWithStatement(statement);
|
1959
2114
|
break;
|
1960
2115
|
}
|
1961
|
-
this.prevStatement =
|
2116
|
+
this.prevStatement =
|
2117
|
+
/** @type {StatementPath} */
|
2118
|
+
(this.statementPath).pop();
|
1962
2119
|
}
|
1963
2120
|
|
1964
2121
|
/**
|
@@ -2365,12 +2522,13 @@ class JavascriptParser extends Parser {
|
|
2365
2522
|
!this.hooks.importSpecifier.call(
|
2366
2523
|
statement,
|
2367
2524
|
source,
|
2368
|
-
|
2369
|
-
|
2370
|
-
|
2371
|
-
|
2372
|
-
|
2373
|
-
|
2525
|
+
/** @type {Identifier} */
|
2526
|
+
(specifier.imported).name ||
|
2527
|
+
/** @type {string} */
|
2528
|
+
(
|
2529
|
+
/** @type {Literal} */
|
2530
|
+
(specifier.imported).value
|
2531
|
+
),
|
2374
2532
|
name
|
2375
2533
|
)
|
2376
2534
|
) {
|
@@ -2446,25 +2604,28 @@ class JavascriptParser extends Parser {
|
|
2446
2604
|
const specifier = statement.specifiers[specifierIndex];
|
2447
2605
|
switch (specifier.type) {
|
2448
2606
|
case "ExportSpecifier": {
|
2607
|
+
const localName =
|
2608
|
+
/** @type {Identifier} */ (specifier.local).name ||
|
2609
|
+
/** @type {string} */ (
|
2610
|
+
/** @type {Literal} */ (specifier.local).value
|
2611
|
+
);
|
2449
2612
|
const name =
|
2450
|
-
|
2451
|
-
|
2452
|
-
|
2453
|
-
|
2454
|
-
// TODO drop it in webpack@6
|
2455
|
-
specifier.exported.value;
|
2613
|
+
/** @type {Identifier} */
|
2614
|
+
(specifier.exported).name ||
|
2615
|
+
/** @type {string} */
|
2616
|
+
(/** @type {Literal} */ (specifier.exported).value);
|
2456
2617
|
if (source) {
|
2457
2618
|
this.hooks.exportImportSpecifier.call(
|
2458
2619
|
statement,
|
2459
2620
|
source,
|
2460
|
-
|
2621
|
+
localName,
|
2461
2622
|
name,
|
2462
2623
|
specifierIndex
|
2463
2624
|
);
|
2464
2625
|
} else {
|
2465
2626
|
this.hooks.exportSpecifier.call(
|
2466
2627
|
statement,
|
2467
|
-
|
2628
|
+
localName,
|
2468
2629
|
name,
|
2469
2630
|
specifierIndex
|
2470
2631
|
);
|
@@ -2567,7 +2728,12 @@ class JavascriptParser extends Parser {
|
|
2567
2728
|
*/
|
2568
2729
|
blockPreWalkExportAllDeclaration(statement) {
|
2569
2730
|
const source = /** @type {ImportSource} */ (statement.source.value);
|
2570
|
-
const name = statement.exported
|
2731
|
+
const name = statement.exported
|
2732
|
+
? /** @type {Identifier} */
|
2733
|
+
(statement.exported).name ||
|
2734
|
+
/** @type {string} */
|
2735
|
+
(/** @type {Literal} */ (statement.exported).value)
|
2736
|
+
: null;
|
2571
2737
|
this.hooks.exportImport.call(statement, source);
|
2572
2738
|
this.hooks.exportImportSpecifier.call(statement, source, null, name, 0);
|
2573
2739
|
}
|
@@ -2640,7 +2806,7 @@ class JavascriptParser extends Parser {
|
|
2640
2806
|
shorthand: this.scope.inShorthand
|
2641
2807
|
});
|
2642
2808
|
} else {
|
2643
|
-
const id = this.evaluateExpression(
|
2809
|
+
const id = this.evaluateExpression(key);
|
2644
2810
|
const str = id.asString();
|
2645
2811
|
if (str) {
|
2646
2812
|
props.add({
|
@@ -3089,21 +3255,32 @@ class JavascriptParser extends Parser {
|
|
3089
3255
|
if (!expression.expressions) return;
|
3090
3256
|
// We treat sequence expressions like statements when they are one statement level
|
3091
3257
|
// This has some benefits for optimizations that only work on statement level
|
3092
|
-
const currentStatement =
|
3258
|
+
const currentStatement =
|
3259
|
+
/** @type {StatementPath} */
|
3260
|
+
(this.statementPath)[
|
3261
|
+
/** @type {StatementPath} */
|
3262
|
+
(this.statementPath).length - 1
|
3263
|
+
];
|
3093
3264
|
if (
|
3094
3265
|
currentStatement === expression ||
|
3095
3266
|
(currentStatement.type === "ExpressionStatement" &&
|
3096
3267
|
currentStatement.expression === expression)
|
3097
3268
|
) {
|
3098
|
-
const old =
|
3269
|
+
const old =
|
3270
|
+
/** @type {StatementPathItem} */
|
3271
|
+
(/** @type {StatementPath} */ (this.statementPath).pop());
|
3099
3272
|
const prev = this.prevStatement;
|
3100
3273
|
for (const expr of expression.expressions) {
|
3101
|
-
|
3274
|
+
/** @type {StatementPath} */
|
3275
|
+
(this.statementPath).push(expr);
|
3102
3276
|
this.walkExpression(expr);
|
3103
|
-
this.prevStatement =
|
3277
|
+
this.prevStatement =
|
3278
|
+
/** @type {StatementPath} */
|
3279
|
+
(this.statementPath).pop();
|
3104
3280
|
}
|
3105
3281
|
this.prevStatement = prev;
|
3106
|
-
|
3282
|
+
/** @type {StatementPath} */
|
3283
|
+
(this.statementPath).push(old);
|
3107
3284
|
} else {
|
3108
3285
|
this.walkExpressions(expression.expressions);
|
3109
3286
|
}
|
@@ -3339,17 +3516,21 @@ class JavascriptParser extends Parser {
|
|
3339
3516
|
* @returns {string | VariableInfoInterface | undefined} var info
|
3340
3517
|
*/
|
3341
3518
|
const getVarInfo = argOrThis => {
|
3342
|
-
const renameIdentifier = this.getRenameIdentifier(
|
3343
|
-
/** @type {Expression} */ (argOrThis)
|
3344
|
-
);
|
3519
|
+
const renameIdentifier = this.getRenameIdentifier(argOrThis);
|
3345
3520
|
if (
|
3346
3521
|
renameIdentifier &&
|
3347
3522
|
this.callHooksForInfo(
|
3348
3523
|
this.hooks.canRename,
|
3349
3524
|
renameIdentifier,
|
3350
|
-
|
3525
|
+
/** @type {Expression} */
|
3526
|
+
(argOrThis)
|
3351
3527
|
) &&
|
3352
|
-
!this.callHooksForInfo(
|
3528
|
+
!this.callHooksForInfo(
|
3529
|
+
this.hooks.rename,
|
3530
|
+
renameIdentifier,
|
3531
|
+
/** @type {Expression} */
|
3532
|
+
(argOrThis)
|
3533
|
+
)
|
3353
3534
|
) {
|
3354
3535
|
return typeof renameIdentifier === "string"
|
3355
3536
|
? /** @type {string} */ (this.getVariableInfo(renameIdentifier))
|
@@ -3412,6 +3593,10 @@ class JavascriptParser extends Parser {
|
|
3412
3593
|
* @param {CallExpression} expression expression
|
3413
3594
|
*/
|
3414
3595
|
walkCallExpression(expression) {
|
3596
|
+
/**
|
3597
|
+
* @param {FunctionExpression | ArrowFunctionExpression} fn function
|
3598
|
+
* @returns {boolean} true when simple function
|
3599
|
+
*/
|
3415
3600
|
const isSimpleFunction = fn =>
|
3416
3601
|
fn.params.every(p => p.type === "Identifier");
|
3417
3602
|
if (
|
@@ -3426,7 +3611,10 @@ class JavascriptParser extends Parser {
|
|
3426
3611
|
// @ts-ignore
|
3427
3612
|
expression.callee.property.name === "bind") &&
|
3428
3613
|
expression.arguments.length > 0 &&
|
3429
|
-
isSimpleFunction(
|
3614
|
+
isSimpleFunction(
|
3615
|
+
/** @type {FunctionExpression | ArrowFunctionExpression} */
|
3616
|
+
(expression.callee.object)
|
3617
|
+
)
|
3430
3618
|
) {
|
3431
3619
|
// (function(…) { }.call/bind(?, …))
|
3432
3620
|
this._walkIIFE(
|
@@ -3437,7 +3625,10 @@ class JavascriptParser extends Parser {
|
|
3437
3625
|
);
|
3438
3626
|
} else if (
|
3439
3627
|
expression.callee.type.endsWith("FunctionExpression") &&
|
3440
|
-
isSimpleFunction(
|
3628
|
+
isSimpleFunction(
|
3629
|
+
/** @type {FunctionExpression | ArrowFunctionExpression} */
|
3630
|
+
(expression.callee)
|
3631
|
+
)
|
3441
3632
|
) {
|
3442
3633
|
// (function(…) { }(…))
|
3443
3634
|
this._walkIIFE(
|
@@ -3471,18 +3662,22 @@ class JavascriptParser extends Parser {
|
|
3471
3662
|
if (callee.isIdentifier()) {
|
3472
3663
|
const result1 = this.callHooksForInfo(
|
3473
3664
|
this.hooks.callMemberChain,
|
3474
|
-
|
3665
|
+
/** @type {NonNullable<BasicEvaluatedExpression["rootInfo"]>} */
|
3666
|
+
(callee.rootInfo),
|
3475
3667
|
expression,
|
3476
|
-
|
3668
|
+
/** @type {NonNullable<BasicEvaluatedExpression["getMembers"]>} */
|
3669
|
+
(callee.getMembers)(),
|
3477
3670
|
callee.getMembersOptionals
|
3478
3671
|
? callee.getMembersOptionals()
|
3479
|
-
:
|
3672
|
+
: /** @type {NonNullable<BasicEvaluatedExpression["getMembers"]>} */
|
3673
|
+
(callee.getMembers)().map(() => false),
|
3480
3674
|
callee.getMemberRanges ? callee.getMemberRanges() : []
|
3481
3675
|
);
|
3482
3676
|
if (result1 === true) return;
|
3483
3677
|
const result2 = this.callHooksForInfo(
|
3484
3678
|
this.hooks.call,
|
3485
|
-
|
3679
|
+
/** @type {NonNullable<BasicEvaluatedExpression["identifier"]>} */
|
3680
|
+
(callee.identifier),
|
3486
3681
|
expression
|
3487
3682
|
);
|
3488
3683
|
if (result2 === true) return;
|
@@ -3633,7 +3828,7 @@ class JavascriptParser extends Parser {
|
|
3633
3828
|
* @template T
|
3634
3829
|
* @template R
|
3635
3830
|
* @param {HookMap<SyncBailHook<T, R>>} hookMap hooks the should be called
|
3636
|
-
* @param {
|
3831
|
+
* @param {Expression | Super} expr expression
|
3637
3832
|
* @param {AsArray<T>} args args for the hook
|
3638
3833
|
* @returns {R | undefined} result of hook
|
3639
3834
|
*/
|
@@ -3651,7 +3846,7 @@ class JavascriptParser extends Parser {
|
|
3651
3846
|
* @template T
|
3652
3847
|
* @template R
|
3653
3848
|
* @param {HookMap<SyncBailHook<T, R>>} hookMap hooks the should be called
|
3654
|
-
* @param {
|
3849
|
+
* @param {Expression | Super} expr expression info
|
3655
3850
|
* @param {(function(string, string | ScopeInfo | VariableInfo, function(): string[]): any) | undefined} fallback callback when variable in not handled by hooks
|
3656
3851
|
* @param {(function(string): any) | undefined} defined callback when variable is defined
|
3657
3852
|
* @param {AsArray<T>} args args for the hook
|
@@ -3723,7 +3918,7 @@ class JavascriptParser extends Parser {
|
|
3723
3918
|
* @param {HookMap<SyncBailHook<T, R>>} hookMap hooks the should be called
|
3724
3919
|
* @param {ExportedVariableInfo} info variable info
|
3725
3920
|
* @param {(function(string): any) | undefined} fallback callback when variable in not handled by hooks
|
3726
|
-
* @param {(function(): any) | undefined} defined callback when variable is defined
|
3921
|
+
* @param {(function(string=): any) | undefined} defined callback when variable is defined
|
3727
3922
|
* @param {AsArray<T>} args args for the hook
|
3728
3923
|
* @returns {R | undefined} result of hook
|
3729
3924
|
*/
|
@@ -3763,7 +3958,7 @@ class JavascriptParser extends Parser {
|
|
3763
3958
|
if (result !== undefined) return result;
|
3764
3959
|
}
|
3765
3960
|
if (fallback !== undefined) {
|
3766
|
-
return fallback(name);
|
3961
|
+
return fallback(/** @type {string} */ (name));
|
3767
3962
|
}
|
3768
3963
|
}
|
3769
3964
|
|
@@ -3807,7 +4002,7 @@ class JavascriptParser extends Parser {
|
|
3807
4002
|
|
3808
4003
|
this.undefineVariable("this");
|
3809
4004
|
|
3810
|
-
this.enterPatterns(params,
|
4005
|
+
this.enterPatterns(params, ident => {
|
3811
4006
|
this.defineVariable(ident);
|
3812
4007
|
});
|
3813
4008
|
|
@@ -3818,7 +4013,7 @@ class JavascriptParser extends Parser {
|
|
3818
4013
|
|
3819
4014
|
/**
|
3820
4015
|
* @param {boolean} hasThis true, when this is defined
|
3821
|
-
* @param {
|
4016
|
+
* @param {Identifier[]} params scope params
|
3822
4017
|
* @param {function(): void} fn inner function
|
3823
4018
|
* @returns {void}
|
3824
4019
|
*/
|
@@ -3838,7 +4033,7 @@ class JavascriptParser extends Parser {
|
|
3838
4033
|
this.undefineVariable("this");
|
3839
4034
|
}
|
3840
4035
|
|
3841
|
-
this.enterPatterns(params,
|
4036
|
+
this.enterPatterns(params, ident => {
|
3842
4037
|
this.defineVariable(ident);
|
3843
4038
|
});
|
3844
4039
|
|
@@ -3849,7 +4044,7 @@ class JavascriptParser extends Parser {
|
|
3849
4044
|
|
3850
4045
|
/**
|
3851
4046
|
* @param {boolean} hasThis true, when this is defined
|
3852
|
-
* @param {
|
4047
|
+
* @param {(Pattern | string)[]} params scope params
|
3853
4048
|
* @param {function(): void} fn inner function
|
3854
4049
|
* @returns {void}
|
3855
4050
|
*/
|
@@ -3869,7 +4064,7 @@ class JavascriptParser extends Parser {
|
|
3869
4064
|
this.undefineVariable("this");
|
3870
4065
|
}
|
3871
4066
|
|
3872
|
-
this.enterPatterns(params,
|
4067
|
+
this.enterPatterns(params, ident => {
|
3873
4068
|
this.defineVariable(ident);
|
3874
4069
|
});
|
3875
4070
|
|
@@ -3927,7 +4122,7 @@ class JavascriptParser extends Parser {
|
|
3927
4122
|
|
3928
4123
|
/**
|
3929
4124
|
* @param {(string | Pattern | Property)[]} patterns patterns
|
3930
|
-
* @param {
|
4125
|
+
* @param {OnIdentString} onIdent on ident callback
|
3931
4126
|
*/
|
3932
4127
|
enterPatterns(patterns, onIdent) {
|
3933
4128
|
for (const pattern of patterns) {
|
@@ -3967,7 +4162,7 @@ class JavascriptParser extends Parser {
|
|
3967
4162
|
this.enterIdentifier(pattern.value, onIdent);
|
3968
4163
|
this.scope.inShorthand = false;
|
3969
4164
|
} else {
|
3970
|
-
this.enterPattern(/** @type {
|
4165
|
+
this.enterPattern(/** @type {Pattern} */ (pattern.value), onIdent);
|
3971
4166
|
}
|
3972
4167
|
break;
|
3973
4168
|
}
|
@@ -4033,7 +4228,7 @@ class JavascriptParser extends Parser {
|
|
4033
4228
|
}
|
4034
4229
|
|
4035
4230
|
/**
|
4036
|
-
* @param {Expression | SpreadElement} expression expression node
|
4231
|
+
* @param {Expression | SpreadElement | PrivateIdentifier} expression expression node
|
4037
4232
|
* @returns {BasicEvaluatedExpression} evaluation result
|
4038
4233
|
*/
|
4039
4234
|
evaluateExpression(expression) {
|
@@ -4064,7 +4259,7 @@ class JavascriptParser extends Parser {
|
|
4064
4259
|
case "BinaryExpression":
|
4065
4260
|
if (expression.operator === "+") {
|
4066
4261
|
return (
|
4067
|
-
this.parseString(expression.left) +
|
4262
|
+
this.parseString(/** @type {Expression} */ (expression.left)) +
|
4068
4263
|
this.parseString(expression.right)
|
4069
4264
|
);
|
4070
4265
|
}
|
@@ -4079,13 +4274,16 @@ class JavascriptParser extends Parser {
|
|
4079
4274
|
|
4080
4275
|
/**
|
4081
4276
|
* @param {Expression} expression expression
|
4082
|
-
* @returns {TODO} result
|
4277
|
+
* @returns {{ range?: Range, value: string, code: boolean, conditional: TODO }} result
|
4083
4278
|
*/
|
4084
4279
|
parseCalculatedString(expression) {
|
4085
4280
|
switch (expression.type) {
|
4086
4281
|
case "BinaryExpression":
|
4087
4282
|
if (expression.operator === "+") {
|
4088
|
-
const left = this.parseCalculatedString(
|
4283
|
+
const left = this.parseCalculatedString(
|
4284
|
+
/** @type {Expression} */
|
4285
|
+
(expression.left)
|
4286
|
+
);
|
4089
4287
|
const right = this.parseCalculatedString(expression.right);
|
4090
4288
|
if (left.code) {
|
4091
4289
|
return {
|
@@ -4097,8 +4295,11 @@ class JavascriptParser extends Parser {
|
|
4097
4295
|
} else if (right.code) {
|
4098
4296
|
return {
|
4099
4297
|
range: [
|
4100
|
-
|
4101
|
-
|
4298
|
+
/** @type {Range} */
|
4299
|
+
(left.range)[0],
|
4300
|
+
right.range
|
4301
|
+
? right.range[1]
|
4302
|
+
: /** @type {Range} */ (left.range)[1]
|
4102
4303
|
],
|
4103
4304
|
value: left.value + right.value,
|
4104
4305
|
code: true,
|
@@ -4106,7 +4307,12 @@ class JavascriptParser extends Parser {
|
|
4106
4307
|
};
|
4107
4308
|
}
|
4108
4309
|
return {
|
4109
|
-
range: [
|
4310
|
+
range: [
|
4311
|
+
/** @type {Range} */
|
4312
|
+
(left.range)[0],
|
4313
|
+
/** @type {Range} */
|
4314
|
+
(right.range)[1]
|
4315
|
+
],
|
4110
4316
|
value: left.value + right.value,
|
4111
4317
|
code: false,
|
4112
4318
|
conditional: false
|
@@ -4161,6 +4367,7 @@ class JavascriptParser extends Parser {
|
|
4161
4367
|
*/
|
4162
4368
|
parse(source, state) {
|
4163
4369
|
let ast;
|
4370
|
+
/** @type {import("acorn").Comment[]} */
|
4164
4371
|
let comments;
|
4165
4372
|
const semicolons = new Set();
|
4166
4373
|
if (source === null) {
|
@@ -4398,20 +4605,27 @@ class JavascriptParser extends Parser {
|
|
4398
4605
|
* @returns {boolean} true when a semicolon has been inserted before this position, false if not
|
4399
4606
|
*/
|
4400
4607
|
isAsiPosition(pos) {
|
4401
|
-
const currentStatement =
|
4608
|
+
const currentStatement =
|
4609
|
+
/** @type {StatementPath} */
|
4610
|
+
(this.statementPath)[
|
4611
|
+
/** @type {StatementPath} */
|
4612
|
+
(this.statementPath).length - 1
|
4613
|
+
];
|
4402
4614
|
if (currentStatement === undefined) throw new Error("Not in statement");
|
4615
|
+
const range = /** @type {Range} */ (currentStatement.range);
|
4616
|
+
|
4403
4617
|
return (
|
4404
4618
|
// Either asking directly for the end position of the current statement
|
4405
|
-
(
|
4619
|
+
(range[1] === pos &&
|
4406
4620
|
/** @type {Set<number>} */ (this.semicolons).has(pos)) ||
|
4407
4621
|
// Or asking for the start position of the current statement,
|
4408
4622
|
// here we have to check multiple things
|
4409
|
-
(
|
4623
|
+
(range[0] === pos &&
|
4410
4624
|
// is there a previous statement which might be relevant?
|
4411
4625
|
this.prevStatement !== undefined &&
|
4412
4626
|
// is the end position of the previous statement an ASI position?
|
4413
4627
|
/** @type {Set<number>} */ (this.semicolons).has(
|
4414
|
-
this.prevStatement.range[1]
|
4628
|
+
/** @type {Range} */ (this.prevStatement.range)[1]
|
4415
4629
|
))
|
4416
4630
|
);
|
4417
4631
|
}
|
@@ -4437,7 +4651,12 @@ class JavascriptParser extends Parser {
|
|
4437
4651
|
* @returns {boolean} true, when the expression is a statement level expression
|
4438
4652
|
*/
|
4439
4653
|
isStatementLevelExpression(expr) {
|
4440
|
-
const currentStatement =
|
4654
|
+
const currentStatement =
|
4655
|
+
/** @type {StatementPath} */
|
4656
|
+
(this.statementPath)[
|
4657
|
+
/** @type {StatementPath} */
|
4658
|
+
(this.statementPath).length - 1
|
4659
|
+
];
|
4441
4660
|
return (
|
4442
4661
|
expr === currentStatement ||
|
4443
4662
|
(currentStatement.type === "ExpressionStatement" &&
|
@@ -4447,7 +4666,7 @@ class JavascriptParser extends Parser {
|
|
4447
4666
|
|
4448
4667
|
/**
|
4449
4668
|
* @param {string} name name
|
4450
|
-
* @param {
|
4669
|
+
* @param {symbol} tag tag info
|
4451
4670
|
* @returns {TODO} tag data
|
4452
4671
|
*/
|
4453
4672
|
getTagData(name, tag) {
|
@@ -4463,7 +4682,7 @@ class JavascriptParser extends Parser {
|
|
4463
4682
|
|
4464
4683
|
/**
|
4465
4684
|
* @param {string} name name
|
4466
|
-
* @param {
|
4685
|
+
* @param {symbol} tag tag info
|
4467
4686
|
* @param {TODO=} data data
|
4468
4687
|
*/
|
4469
4688
|
tagVariable(name, tag, data) {
|
@@ -4565,15 +4784,16 @@ class JavascriptParser extends Parser {
|
|
4565
4784
|
|
4566
4785
|
/**
|
4567
4786
|
* @param {Range} range range of the comment
|
4568
|
-
* @returns {
|
4787
|
+
* @returns {{ options: Record<string, any> | null, errors: (Error & { comment: Comment })[] | null }} result
|
4569
4788
|
*/
|
4570
4789
|
parseCommentOptions(range) {
|
4571
4790
|
const comments = this.getComments(range);
|
4572
4791
|
if (comments.length === 0) {
|
4573
4792
|
return EMPTY_COMMENT_OPTIONS;
|
4574
4793
|
}
|
4794
|
+
/** @type {Record<string, EXPECTED_ANY> } */
|
4575
4795
|
const options = {};
|
4576
|
-
/** @type {
|
4796
|
+
/** @type {(Error & { comment: Comment })[]} */
|
4577
4797
|
const errors = [];
|
4578
4798
|
for (const comment of comments) {
|
4579
4799
|
const { value } = comment;
|
@@ -4595,10 +4815,10 @@ class JavascriptParser extends Parser {
|
|
4595
4815
|
options[key] = val;
|
4596
4816
|
}
|
4597
4817
|
} catch (err) {
|
4598
|
-
const newErr = new Error(String(err.message));
|
4599
|
-
newErr.stack = String(err.stack);
|
4818
|
+
const newErr = new Error(String(/** @type {Error} */ (err).message));
|
4819
|
+
newErr.stack = String(/** @type {Error} */ (err).stack);
|
4600
4820
|
Object.assign(newErr, { comment });
|
4601
|
-
errors.push(newErr);
|
4821
|
+
errors.push(/** @type {(Error & { comment: Comment })} */ (newErr));
|
4602
4822
|
}
|
4603
4823
|
}
|
4604
4824
|
}
|
@@ -4606,11 +4826,11 @@ class JavascriptParser extends Parser {
|
|
4606
4826
|
}
|
4607
4827
|
|
4608
4828
|
/**
|
4609
|
-
* @param {
|
4829
|
+
* @param {Expression | Super} expression a member expression
|
4610
4830
|
* @returns {{ members: string[], object: Expression | Super, membersOptionals: boolean[], memberRanges: Range[] }} member names (reverse order) and remaining object
|
4611
4831
|
*/
|
4612
4832
|
extractMemberExpressionChain(expression) {
|
4613
|
-
/** @type {
|
4833
|
+
/** @type {Node} */
|
4614
4834
|
let expr = expression;
|
4615
4835
|
const members = [];
|
4616
4836
|
const membersOptionals = [];
|
@@ -4659,7 +4879,7 @@ class JavascriptParser extends Parser {
|
|
4659
4879
|
/** @typedef {{ type: "expression", rootInfo: string | VariableInfo, name: string, getMembers: () => string[], getMembersOptionals: () => boolean[], getMemberRanges: () => Range[]}} ExpressionExpressionInfo */
|
4660
4880
|
|
4661
4881
|
/**
|
4662
|
-
* @param {
|
4882
|
+
* @param {Expression | Super} expression a member expression
|
4663
4883
|
* @param {number} allowedTypes which types should be returned, presented in bit mask
|
4664
4884
|
* @returns {CallExpressionInfo | ExpressionExpressionInfo | undefined} expression info
|
4665
4885
|
*/
|
@@ -4741,12 +4961,12 @@ class JavascriptParser extends Parser {
|
|
4741
4961
|
sourceType: type === "auto" ? "module" : type
|
4742
4962
|
};
|
4743
4963
|
|
4744
|
-
/** @type {
|
4964
|
+
/** @type {import("acorn").Program | undefined} */
|
4745
4965
|
let ast;
|
4746
4966
|
let error;
|
4747
4967
|
let threw = false;
|
4748
4968
|
try {
|
4749
|
-
ast =
|
4969
|
+
ast = parser.parse(code, parserOptions);
|
4750
4970
|
} catch (err) {
|
4751
4971
|
error = err;
|
4752
4972
|
threw = true;
|
@@ -4761,7 +4981,7 @@ class JavascriptParser extends Parser {
|
|
4761
4981
|
parserOptions.onComment.length = 0;
|
4762
4982
|
}
|
4763
4983
|
try {
|
4764
|
-
ast =
|
4984
|
+
ast = parser.parse(code, parserOptions);
|
4765
4985
|
threw = false;
|
4766
4986
|
} catch (_err) {
|
4767
4987
|
// we use the error from first parse try
|
@@ -4783,3 +5003,4 @@ module.exports.ALLOWED_MEMBER_TYPES_EXPRESSION =
|
|
4783
5003
|
ALLOWED_MEMBER_TYPES_EXPRESSION;
|
4784
5004
|
module.exports.ALLOWED_MEMBER_TYPES_CALL_EXPRESSION =
|
4785
5005
|
ALLOWED_MEMBER_TYPES_CALL_EXPRESSION;
|
5006
|
+
module.exports.getImportAttributes = getImportAttributes;
|