webpack 5.85.0 → 5.88.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.
Potentially problematic release.
This version of webpack might be problematic. Click here for more details.
- package/README.md +5 -2
- package/lib/APIPlugin.js +150 -99
- package/lib/AsyncDependenciesBlock.js +3 -3
- package/lib/BannerPlugin.js +2 -1
- package/lib/CaseSensitiveModulesWarning.js +3 -1
- package/lib/Chunk.js +35 -17
- package/lib/ChunkGraph.js +4 -4
- package/lib/ChunkGroup.js +20 -9
- package/lib/CompatibilityPlugin.js +50 -30
- package/lib/Compilation.js +2 -1
- package/lib/Compiler.js +10 -9
- package/lib/ConcatenationScope.js +2 -2
- package/lib/ConditionalInitFragment.js +11 -1
- package/lib/ConstPlugin.js +73 -32
- package/lib/ContextModule.js +8 -3
- package/lib/ContextModuleFactory.js +1 -0
- package/lib/ContextReplacementPlugin.js +13 -0
- package/lib/DelegatedModule.js +15 -3
- package/lib/DelegatedModuleFactoryPlugin.js +6 -0
- package/lib/DependenciesBlock.js +1 -1
- package/lib/Dependency.js +11 -5
- package/lib/DependencyTemplates.js +1 -1
- package/lib/DllEntryPlugin.js +11 -1
- package/lib/DllModule.js +6 -0
- package/lib/DllReferencePlugin.js +13 -1
- package/lib/Entrypoint.js +1 -1
- package/lib/ErrorHelpers.js +1 -0
- package/lib/EvalSourceMapDevToolPlugin.js +6 -1
- package/lib/ExportsInfo.js +22 -4
- package/lib/ExportsInfoApiPlugin.js +14 -5
- package/lib/ExternalModule.js +20 -8
- package/lib/FileSystemInfo.js +52 -24
- package/lib/FlagAllModulesAsUsedPlugin.js +6 -1
- package/lib/FlagDependencyUsagePlugin.js +3 -1
- package/lib/FlagEntryExportAsUsedPlugin.js +4 -0
- package/lib/Generator.js +7 -0
- package/lib/HotModuleReplacementPlugin.js +8 -0
- package/lib/InitFragment.js +28 -5
- package/lib/JavascriptMetaInfoPlugin.js +11 -6
- package/lib/LibManifestPlugin.js +20 -4
- package/lib/Module.js +14 -3
- package/lib/ModuleDependencyError.js +4 -2
- package/lib/ModuleDependencyWarning.js +4 -2
- package/lib/ModuleGraph.js +31 -24
- package/lib/ModuleGraphConnection.js +19 -6
- package/lib/ModuleInfoHeaderPlugin.js +9 -2
- package/lib/ModuleNotFoundError.js +5 -2
- package/lib/ModuleProfile.js +1 -0
- package/lib/ModuleRestoreError.js +2 -0
- package/lib/ModuleStoreError.js +2 -1
- package/lib/ModuleTypeConstants.js +7 -0
- package/lib/MultiWatching.js +4 -0
- package/lib/NodeStuffPlugin.js +32 -6
- package/lib/ProgressPlugin.js +71 -15
- package/lib/ProvidePlugin.js +13 -4
- package/lib/RawModule.js +3 -1
- package/lib/RequireJsStuffPlugin.js +7 -0
- package/lib/RuntimeGlobals.js +5 -0
- package/lib/RuntimeModule.js +3 -3
- package/lib/RuntimePlugin.js +6 -3
- package/lib/RuntimeTemplate.js +22 -4
- package/lib/SourceMapDevToolModuleOptionsPlugin.js +4 -0
- package/lib/SourceMapDevToolPlugin.js +7 -2
- package/lib/UseStrictPlugin.js +10 -3
- package/lib/Watching.js +62 -25
- package/lib/WebpackError.js +6 -5
- package/lib/WebpackIsIncludedPlugin.js +6 -4
- package/lib/WebpackOptionsApply.js +4 -2
- package/lib/WebpackOptionsDefaulter.js +10 -3
- package/lib/asset/AssetGenerator.js +2 -1
- package/lib/asset/AssetParser.js +11 -6
- package/lib/asset/AssetSourceParser.js +8 -3
- package/lib/async-modules/AwaitDependenciesInitFragment.js +4 -0
- package/lib/buildChunkGraph.js +37 -21
- package/lib/cache/IdleFileCachePlugin.js +2 -1
- package/lib/cache/PackFileCacheStrategy.js +53 -22
- package/lib/config/browserslistTargetHandler.js +7 -7
- package/lib/config/defaults.js +43 -26
- package/lib/container/RemoteRuntimeModule.js +1 -1
- package/lib/css/CssExportsGenerator.js +9 -0
- package/lib/css/CssGenerator.js +1 -1
- package/lib/css/CssLoadingRuntimeModule.js +43 -19
- package/lib/css/CssModulesPlugin.js +42 -14
- package/lib/css/CssParser.js +22 -0
- package/lib/dependencies/AMDDefineDependency.js +34 -4
- package/lib/dependencies/AMDDefineDependencyParserPlugin.js +5 -0
- package/lib/dependencies/AMDRuntimeModules.js +2 -2
- package/lib/dependencies/CommonJsExportsParserPlugin.js +14 -4
- package/lib/dependencies/CommonJsImportsParserPlugin.js +169 -59
- package/lib/dependencies/CommonJsPlugin.js +13 -8
- package/lib/dependencies/CommonJsRequireContextDependency.js +2 -2
- package/lib/dependencies/ConstDependency.js +2 -2
- package/lib/dependencies/ContextDependency.js +7 -2
- package/lib/dependencies/CssImportDependency.js +1 -1
- package/lib/dependencies/CssLocalIdentifierDependency.js +5 -0
- package/lib/dependencies/CssUrlDependency.js +3 -3
- package/lib/dependencies/DllEntryDependency.js +5 -0
- package/lib/dependencies/DynamicExports.js +10 -6
- package/lib/dependencies/ExportsInfoDependency.js +14 -4
- package/lib/dependencies/HarmonyCompatibilityDependency.js +2 -1
- package/lib/dependencies/HarmonyDetectionParserPlugin.js +3 -1
- package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +12 -5
- package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +2 -0
- package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +4 -4
- package/lib/dependencies/HarmonyExports.js +9 -5
- package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +40 -27
- package/lib/dependencies/HarmonyImportSideEffectDependency.js +1 -2
- package/lib/dependencies/HarmonyImportSpecifierDependency.js +31 -21
- package/lib/dependencies/HarmonyTopLevelThisParserPlugin.js +15 -3
- package/lib/dependencies/ImportDependency.js +5 -3
- package/lib/dependencies/ImportEagerDependency.js +5 -3
- package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +19 -0
- package/lib/dependencies/ImportMetaPlugin.js +31 -15
- package/lib/dependencies/ImportParserPlugin.js +62 -25
- package/lib/dependencies/ImportWeakDependency.js +5 -3
- package/lib/dependencies/JsonExportsDependency.js +1 -1
- package/lib/dependencies/ModuleDependency.js +1 -1
- package/lib/dependencies/ModuleDependencyTemplateAsId.js +2 -1
- package/lib/dependencies/ProvidedDependency.js +4 -1
- package/lib/dependencies/RequireContextDependencyParserPlugin.js +13 -5
- package/lib/dependencies/RequireEnsureDependenciesBlock.js +5 -2
- package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +6 -1
- package/lib/dependencies/RequireHeaderDependency.js +4 -0
- package/lib/dependencies/RequireIncludeDependencyParserPlugin.js +26 -5
- package/lib/dependencies/RequireResolveHeaderDependency.js +9 -0
- package/lib/dependencies/SystemPlugin.js +17 -5
- package/lib/dependencies/SystemRuntimeModule.js +1 -1
- package/lib/dependencies/URLDependency.js +2 -2
- package/lib/dependencies/URLPlugin.js +9 -4
- package/lib/dependencies/WebAssemblyImportDependency.js +1 -1
- package/lib/dependencies/WorkerPlugin.js +59 -22
- package/lib/esm/ExportWebpackRequireRuntimeModule.js +1 -1
- package/lib/esm/ModuleChunkLoadingRuntimeModule.js +1 -1
- package/lib/hmr/HotModuleReplacementRuntimeModule.js +1 -1
- package/lib/ids/HashedModuleIdsPlugin.js +1 -1
- package/lib/ids/SyncModuleIdsPlugin.js +1 -0
- package/lib/javascript/BasicEvaluatedExpression.js +28 -19
- package/lib/javascript/CommonJsChunkFormatPlugin.js +6 -2
- package/lib/javascript/JavascriptModulesPlugin.js +25 -5
- package/lib/javascript/JavascriptParser.js +157 -85
- package/lib/javascript/JavascriptParserHelpers.js +37 -15
- package/lib/json/JsonData.js +2 -2
- package/lib/json/JsonParser.js +25 -12
- package/lib/library/AmdLibraryPlugin.js +2 -2
- package/lib/library/AssignLibraryPlugin.js +13 -1
- package/lib/library/EnableLibraryPlugin.js +4 -0
- package/lib/library/SystemLibraryPlugin.js +1 -1
- package/lib/library/UmdLibraryPlugin.js +20 -2
- package/lib/logging/runtime.js +1 -1
- package/lib/logging/truncateArgs.js +4 -0
- package/lib/node/ReadFileChunkLoadingRuntimeModule.js +10 -6
- package/lib/node/ReadFileCompileAsyncWasmPlugin.js +2 -1
- package/lib/node/RequireChunkLoadingRuntimeModule.js +10 -6
- package/lib/optimize/AggressiveMergingPlugin.js +8 -0
- package/lib/optimize/AggressiveSplittingPlugin.js +9 -2
- package/lib/optimize/EnsureChunkConditionsPlugin.js +3 -0
- package/lib/optimize/FlagIncludedChunksPlugin.js +11 -5
- package/lib/optimize/InnerGraph.js +5 -5
- package/lib/optimize/InnerGraphPlugin.js +2 -1
- package/lib/optimize/LimitChunkCountPlugin.js +29 -4
- package/lib/optimize/MangleExportsPlugin.js +1 -1
- package/lib/optimize/MinMaxSizeWarning.js +5 -0
- package/lib/optimize/ModuleConcatenationPlugin.js +59 -2
- package/lib/optimize/RealContentHashPlugin.js +80 -30
- package/lib/optimize/RemoveParentModulesPlugin.js +6 -0
- package/lib/optimize/RuntimeChunkPlugin.js +9 -1
- package/lib/optimize/SideEffectsFlagPlugin.js +10 -1
- package/lib/optimize/SplitChunksPlugin.js +71 -31
- package/lib/performance/SizeLimitsPlugin.js +7 -4
- package/lib/prefetch/ChunkPrefetchFunctionRuntimeModule.js +4 -2
- package/lib/prefetch/ChunkPrefetchPreloadPlugin.js +3 -1
- package/lib/prefetch/ChunkPrefetchStartupRuntimeModule.js +6 -3
- package/lib/prefetch/ChunkPrefetchTriggerRuntimeModule.js +4 -2
- package/lib/prefetch/ChunkPreloadTriggerRuntimeModule.js +4 -2
- package/lib/rules/BasicEffectRulePlugin.js +4 -0
- package/lib/rules/BasicMatcherRulePlugin.js +5 -0
- package/lib/rules/RuleSetCompiler.js +3 -3
- package/lib/rules/UseEffectRulePlugin.js +6 -4
- package/lib/runtime/AsyncModuleRuntimeModule.js +8 -5
- package/lib/runtime/AutoPublicPathRuntimeModule.js +4 -2
- package/lib/runtime/BaseUriRuntimeModule.js +3 -3
- package/lib/runtime/ChunkNameRuntimeModule.js +1 -1
- package/lib/runtime/CompatGetDefaultExportRuntimeModule.js +5 -2
- package/lib/runtime/CompatRuntimeModule.js +7 -2
- package/lib/runtime/CreateFakeNamespaceObjectRuntimeModule.js +5 -2
- package/lib/runtime/CreateScriptRuntimeModule.js +4 -2
- package/lib/runtime/CreateScriptUrlRuntimeModule.js +4 -2
- package/lib/runtime/DefinePropertyGettersRuntimeModule.js +5 -2
- package/lib/runtime/EnsureChunkRuntimeModule.js +15 -4
- package/lib/runtime/GetChunkFilenameRuntimeModule.js +6 -10
- package/lib/runtime/GetFullHashRuntimeModule.js +4 -3
- package/lib/runtime/GetMainFilenameRuntimeModule.js +5 -2
- package/lib/runtime/GetTrustedTypesPolicyRuntimeModule.js +4 -2
- package/lib/runtime/GlobalRuntimeModule.js +1 -1
- package/lib/runtime/HasOwnPropertyRuntimeModule.js +5 -2
- package/lib/runtime/LoadScriptRuntimeModule.js +64 -48
- package/lib/runtime/MakeNamespaceObjectRuntimeModule.js +5 -2
- package/lib/runtime/NonceRuntimeModule.js +1 -1
- package/lib/runtime/OnChunksLoadedRuntimeModule.js +4 -2
- package/lib/runtime/PublicPathRuntimeModule.js +4 -2
- package/lib/runtime/RelativeUrlRuntimeModule.js +5 -2
- package/lib/runtime/RuntimeIdRuntimeModule.js +6 -2
- package/lib/runtime/StartupChunkDependenciesRuntimeModule.js +9 -3
- package/lib/runtime/StartupEntrypointRuntimeModule.js +3 -2
- package/lib/runtime/SystemContextRuntimeModule.js +1 -1
- package/lib/serialization/BinaryMiddleware.js +143 -1
- package/lib/serialization/ErrorObjectSerializer.js +3 -0
- package/lib/serialization/ObjectMiddleware.js +9 -3
- package/lib/serialization/types.js +1 -1
- package/lib/sharing/ConsumeSharedFallbackDependency.js +3 -0
- package/lib/sharing/ConsumeSharedRuntimeModule.js +14 -5
- package/lib/sharing/ProvideSharedDependency.js +11 -0
- package/lib/sharing/ProvideSharedModule.js +4 -0
- package/lib/sharing/ProvideSharedPlugin.js +22 -21
- package/lib/sharing/ShareRuntimeModule.js +12 -5
- package/lib/sharing/resolveMatchedConfigs.js +1 -1
- package/lib/sharing/utils.js +32 -5
- package/lib/util/AsyncQueue.js +4 -2
- package/lib/util/ParallelismFactorCalculator.js +10 -0
- package/lib/util/Semaphore.js +1 -1
- package/lib/util/StackedCacheMap.js +1 -1
- package/lib/util/URLAbsoluteSpecifier.js +1 -1
- package/lib/util/createHash.js +30 -9
- package/lib/util/deprecation.js +10 -3
- package/lib/util/deterministicGrouping.js +50 -11
- package/lib/util/findGraphRoots.js +4 -2
- package/lib/util/memoize.js +3 -3
- package/lib/util/processAsyncTree.js +7 -1
- package/lib/util/registerExternalSerializer.js +1 -1
- package/lib/util/runtime.js +84 -21
- package/lib/util/semver.js +1 -0
- package/lib/util/smartGrouping.js +1 -1
- package/lib/validateSchema.js +6 -2
- package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +6 -2
- package/lib/wasm-async/AsyncWebAssemblyParser.js +7 -3
- package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +14 -7
- package/lib/wasm-sync/WasmFinalizeExportsPlugin.js +3 -1
- package/lib/wasm-sync/WebAssemblyGenerator.js +1 -0
- package/lib/wasm-sync/WebAssemblyParser.js +6 -2
- package/lib/web/JsonpChunkLoadingRuntimeModule.js +14 -4
- package/lib/webpack.js +11 -2
- package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +15 -16
- package/module.d.ts +1 -0
- package/package.json +5 -4
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +52 -6
- package/schemas/plugins/css/CssGeneratorOptions.json +1 -1
- package/schemas/plugins/css/CssParserOptions.json +1 -1
- package/types.d.ts +606 -292
@@ -47,6 +47,7 @@ const BasicEvaluatedExpression = require("./BasicEvaluatedExpression");
|
|
47
47
|
/** @typedef {import("estree").MetaProperty} MetaProperty */
|
48
48
|
/** @typedef {import("estree").Property} Property */
|
49
49
|
/** @typedef {import("estree").AssignmentPattern} AssignmentPattern */
|
50
|
+
/** @typedef {import("estree").ChainElement} ChainElement */
|
50
51
|
/** @typedef {import("estree").Pattern} Pattern */
|
51
52
|
/** @typedef {import("estree").UpdateExpression} UpdateExpression */
|
52
53
|
/** @typedef {import("estree").ObjectExpression} ObjectExpression */
|
@@ -91,7 +92,7 @@ const BasicEvaluatedExpression = require("./BasicEvaluatedExpression");
|
|
91
92
|
/** @typedef {import("../Parser").ParserState} ParserState */
|
92
93
|
/** @typedef {import("../Parser").PreparsedAst} PreparsedAst */
|
93
94
|
/** @typedef {{declaredScope: ScopeInfo, freeName: string | true, tagInfo: TagInfo | undefined}} VariableInfoInterface */
|
94
|
-
/** @typedef {{ name: string | VariableInfo, rootInfo: string | VariableInfo, getMembers: () => string[], getMembersOptionals: () => boolean[],
|
95
|
+
/** @typedef {{ name: string | VariableInfo, rootInfo: string | VariableInfo, getMembers: () => string[], getMembersOptionals: () => boolean[], getMemberRanges: () => Range[] }} GetInfoResult */
|
95
96
|
|
96
97
|
const EMPTY_ARRAY = [];
|
97
98
|
const ALLOWED_MEMBER_TYPES_CALL_EXPRESSION = 0b01;
|
@@ -105,7 +106,7 @@ const parser = AcornParser.extend(importAssertions);
|
|
105
106
|
class VariableInfo {
|
106
107
|
/**
|
107
108
|
* @param {ScopeInfo} declaredScope scope in which the variable is declared
|
108
|
-
* @param {string | true} freeName which free name the variable aliases, or true when none
|
109
|
+
* @param {string | true | undefined} freeName which free name the variable aliases, or true when none
|
109
110
|
* @param {TagInfo | undefined} tagInfo info about tags
|
110
111
|
*/
|
111
112
|
constructor(declaredScope, freeName, tagInfo) {
|
@@ -131,9 +132,10 @@ class VariableInfo {
|
|
131
132
|
* @property {StackedMap<string, VariableInfo | ScopeInfo>} definitions
|
132
133
|
* @property {boolean | "arrow"} topLevelScope
|
133
134
|
* @property {boolean | string} inShorthand
|
135
|
+
* @property {boolean} inTaggedTemplateTag
|
136
|
+
* @property {boolean} inTry
|
134
137
|
* @property {boolean} isStrict
|
135
138
|
* @property {boolean} isAsmJs
|
136
|
-
* @property {boolean} inTry
|
137
139
|
*/
|
138
140
|
|
139
141
|
/** @typedef {[number, number]} Range */
|
@@ -347,17 +349,17 @@ class JavascriptParser extends Parser {
|
|
347
349
|
importCall: new SyncBailHook(["expression"]),
|
348
350
|
/** @type {SyncBailHook<[Expression], boolean | void>} */
|
349
351
|
topLevelAwait: new SyncBailHook(["expression"]),
|
350
|
-
/** @type {HookMap<SyncBailHook<[
|
352
|
+
/** @type {HookMap<SyncBailHook<[CallExpression], boolean | void>>} */
|
351
353
|
call: new HookMap(() => new SyncBailHook(["expression"])),
|
352
354
|
/** Something like "a.b()" */
|
353
|
-
/** @type {HookMap<SyncBailHook<[CallExpression, string[], boolean[],
|
355
|
+
/** @type {HookMap<SyncBailHook<[CallExpression, string[], boolean[], Range[]], boolean | void>>} */
|
354
356
|
callMemberChain: new HookMap(
|
355
357
|
() =>
|
356
358
|
new SyncBailHook([
|
357
359
|
"expression",
|
358
360
|
"members",
|
359
361
|
"membersOptionals",
|
360
|
-
"
|
362
|
+
"memberRanges"
|
361
363
|
])
|
362
364
|
),
|
363
365
|
/** Something like "a.b().c.d" */
|
@@ -372,7 +374,7 @@ class JavascriptParser extends Parser {
|
|
372
374
|
])
|
373
375
|
),
|
374
376
|
/** Something like "a.b().c.d()"" */
|
375
|
-
/** @type {HookMap<SyncBailHook<[
|
377
|
+
/** @type {HookMap<SyncBailHook<[CallExpression, string[], CallExpression, string[]], boolean | void>>} */
|
376
378
|
callMemberChainOfCallMemberChain: new HookMap(
|
377
379
|
() =>
|
378
380
|
new SyncBailHook([
|
@@ -390,23 +392,23 @@ class JavascriptParser extends Parser {
|
|
390
392
|
binaryExpression: new SyncBailHook(["binaryExpression"]),
|
391
393
|
/** @type {HookMap<SyncBailHook<[Expression], boolean | void>>} */
|
392
394
|
expression: new HookMap(() => new SyncBailHook(["expression"])),
|
393
|
-
/** @type {HookMap<SyncBailHook<[
|
395
|
+
/** @type {HookMap<SyncBailHook<[MemberExpression, string[], boolean[], Range[]], boolean | void>>} */
|
394
396
|
expressionMemberChain: new HookMap(
|
395
397
|
() =>
|
396
398
|
new SyncBailHook([
|
397
399
|
"expression",
|
398
400
|
"members",
|
399
401
|
"membersOptionals",
|
400
|
-
"
|
402
|
+
"memberRanges"
|
401
403
|
])
|
402
404
|
),
|
403
|
-
/** @type {HookMap<SyncBailHook<[
|
405
|
+
/** @type {HookMap<SyncBailHook<[MemberExpression, string[]], boolean | void>>} */
|
404
406
|
unhandledExpressionMemberChain: new HookMap(
|
405
407
|
() => new SyncBailHook(["expression", "members"])
|
406
408
|
),
|
407
|
-
/** @type {SyncBailHook<[
|
409
|
+
/** @type {SyncBailHook<[ConditionalExpression], boolean | void>} */
|
408
410
|
expressionConditionalOperator: new SyncBailHook(["expression"]),
|
409
|
-
/** @type {SyncBailHook<[
|
411
|
+
/** @type {SyncBailHook<[LogicalExpression], boolean | void>} */
|
410
412
|
expressionLogicalOperator: new SyncBailHook(["expression"]),
|
411
413
|
/** @type {SyncBailHook<[Program, Comment[]], boolean | void>} */
|
412
414
|
program: new SyncBailHook(["ast", "comments"]),
|
@@ -422,7 +424,7 @@ class JavascriptParser extends Parser {
|
|
422
424
|
this.semicolons = undefined;
|
423
425
|
/** @type {(Statement | ModuleDeclaration | Expression)[]} */
|
424
426
|
this.statementPath = undefined;
|
425
|
-
/** @type {Statement | ModuleDeclaration | Expression} */
|
427
|
+
/** @type {Statement | ModuleDeclaration | Expression | undefined} */
|
426
428
|
this.prevStatement = undefined;
|
427
429
|
/** @type {WeakMap<Expression, Set<string>>} */
|
428
430
|
this.destructuringAssignmentProperties = undefined;
|
@@ -438,27 +440,29 @@ class JavascriptParser extends Parser {
|
|
438
440
|
case "number":
|
439
441
|
return new BasicEvaluatedExpression()
|
440
442
|
.setNumber(expr.value)
|
441
|
-
.setRange(expr.range);
|
443
|
+
.setRange(/** @type {Range} */ (expr.range));
|
442
444
|
case "bigint":
|
443
445
|
return new BasicEvaluatedExpression()
|
444
446
|
.setBigInt(expr.value)
|
445
|
-
.setRange(expr.range);
|
447
|
+
.setRange(/** @type {Range} */ (expr.range));
|
446
448
|
case "string":
|
447
449
|
return new BasicEvaluatedExpression()
|
448
450
|
.setString(expr.value)
|
449
|
-
.setRange(expr.range);
|
451
|
+
.setRange(/** @type {Range} */ (expr.range));
|
450
452
|
case "boolean":
|
451
453
|
return new BasicEvaluatedExpression()
|
452
454
|
.setBoolean(expr.value)
|
453
|
-
.setRange(expr.range);
|
455
|
+
.setRange(/** @type {Range} */ (expr.range));
|
454
456
|
}
|
455
457
|
if (expr.value === null) {
|
456
|
-
return new BasicEvaluatedExpression()
|
458
|
+
return new BasicEvaluatedExpression()
|
459
|
+
.setNull()
|
460
|
+
.setRange(/** @type {Range} */ (expr.range));
|
457
461
|
}
|
458
462
|
if (expr.value instanceof RegExp) {
|
459
463
|
return new BasicEvaluatedExpression()
|
460
464
|
.setRegExp(expr.value)
|
461
|
-
.setRange(expr.range);
|
465
|
+
.setRange(/** @type {Range} */ (expr.range));
|
462
466
|
}
|
463
467
|
});
|
464
468
|
this.hooks.evaluate.for("NewExpression").tap("JavascriptParser", _expr => {
|
@@ -493,7 +497,7 @@ class JavascriptParser extends Parser {
|
|
493
497
|
} else {
|
494
498
|
return new BasicEvaluatedExpression()
|
495
499
|
.setRegExp(new RegExp(""))
|
496
|
-
.setRange(expr.range);
|
500
|
+
.setRange(/** @type {Range} */ (expr.range));
|
497
501
|
}
|
498
502
|
|
499
503
|
const arg2 = expr.arguments[1];
|
@@ -518,7 +522,7 @@ class JavascriptParser extends Parser {
|
|
518
522
|
|
519
523
|
return new BasicEvaluatedExpression()
|
520
524
|
.setRegExp(flags ? new RegExp(regExp, flags) : new RegExp(regExp))
|
521
|
-
.setRange(expr.range);
|
525
|
+
.setRange(/** @type {Range} */ (expr.range));
|
522
526
|
});
|
523
527
|
this.hooks.evaluate
|
524
528
|
.for("LogicalExpression")
|
@@ -584,7 +588,7 @@ class JavascriptParser extends Parser {
|
|
584
588
|
* @param {boolean | number | BigInt | string} value the value to convert to an expression
|
585
589
|
* @param {BinaryExpression | UnaryExpression} expr the expression being evaluated
|
586
590
|
* @param {boolean} sideEffects whether the expression has side effects
|
587
|
-
* @returns {BasicEvaluatedExpression} the evaluated expression
|
591
|
+
* @returns {BasicEvaluatedExpression | undefined} the evaluated expression
|
588
592
|
* @example
|
589
593
|
*
|
590
594
|
* ```js
|
@@ -611,22 +615,22 @@ class JavascriptParser extends Parser {
|
|
611
615
|
return new BasicEvaluatedExpression()
|
612
616
|
.setBoolean(value)
|
613
617
|
.setSideEffects(sideEffects)
|
614
|
-
.setRange(expr.range);
|
618
|
+
.setRange(/** @type {Range} */ (expr.range));
|
615
619
|
case "number":
|
616
620
|
return new BasicEvaluatedExpression()
|
617
621
|
.setNumber(value)
|
618
622
|
.setSideEffects(sideEffects)
|
619
|
-
.setRange(expr.range);
|
623
|
+
.setRange(/** @type {Range} */ (expr.range));
|
620
624
|
case "bigint":
|
621
625
|
return new BasicEvaluatedExpression()
|
622
626
|
.setBigInt(value)
|
623
627
|
.setSideEffects(sideEffects)
|
624
|
-
.setRange(expr.range);
|
628
|
+
.setRange(/** @type {Range} */ (expr.range));
|
625
629
|
case "string":
|
626
630
|
return new BasicEvaluatedExpression()
|
627
631
|
.setString(value)
|
628
632
|
.setSideEffects(sideEffects)
|
629
|
-
.setRange(expr.range);
|
633
|
+
.setRange(/** @type {Range} */ (expr.range));
|
630
634
|
}
|
631
635
|
};
|
632
636
|
|
@@ -720,7 +724,7 @@ class JavascriptParser extends Parser {
|
|
720
724
|
const left = this.evaluateExpression(expr.left);
|
721
725
|
const right = this.evaluateExpression(expr.right);
|
722
726
|
const res = new BasicEvaluatedExpression();
|
723
|
-
res.setRange(expr.range);
|
727
|
+
res.setRange(/** @type {Range} */ (expr.range));
|
724
728
|
|
725
729
|
const leftConst = left.isCompileTimeValue();
|
726
730
|
const rightConst = right.isCompileTimeValue();
|
@@ -758,8 +762,14 @@ class JavascriptParser extends Parser {
|
|
758
762
|
(rightPrimitive === false &&
|
759
763
|
(rightConst || leftPrimitive === true)) ||
|
760
764
|
// Different nullish or boolish status also means not equal
|
761
|
-
isAlwaysDifferent(
|
762
|
-
|
765
|
+
isAlwaysDifferent(
|
766
|
+
/** @type {boolean} */ (left.asBool()),
|
767
|
+
/** @type {boolean} */ (right.asBool())
|
768
|
+
) ||
|
769
|
+
isAlwaysDifferent(
|
770
|
+
/** @type {boolean} */ (left.asNullish()),
|
771
|
+
/** @type {boolean} */ (right.asNullish())
|
772
|
+
)
|
763
773
|
) {
|
764
774
|
return res
|
765
775
|
.setBoolean(!eql)
|
@@ -1163,7 +1173,7 @@ class JavascriptParser extends Parser {
|
|
1163
1173
|
info.rootInfo,
|
1164
1174
|
info.getMembers,
|
1165
1175
|
info.getMembersOptionals,
|
1166
|
-
info.
|
1176
|
+
info.getMemberRanges
|
1167
1177
|
)
|
1168
1178
|
.setRange(expr.range);
|
1169
1179
|
}
|
@@ -1184,7 +1194,7 @@ class JavascriptParser extends Parser {
|
|
1184
1194
|
rootInfo: info,
|
1185
1195
|
getMembers: () => [],
|
1186
1196
|
getMembersOptionals: () => [],
|
1187
|
-
|
1197
|
+
getMemberRanges: () => []
|
1188
1198
|
};
|
1189
1199
|
}
|
1190
1200
|
});
|
@@ -1199,7 +1209,7 @@ class JavascriptParser extends Parser {
|
|
1199
1209
|
rootInfo: info,
|
1200
1210
|
getMembers: () => [],
|
1201
1211
|
getMembersOptionals: () => [],
|
1202
|
-
|
1212
|
+
getMemberRanges: () => []
|
1203
1213
|
};
|
1204
1214
|
}
|
1205
1215
|
});
|
@@ -1363,7 +1373,7 @@ class JavascriptParser extends Parser {
|
|
1363
1373
|
|
1364
1374
|
const part = new BasicEvaluatedExpression()
|
1365
1375
|
.setString(quasi)
|
1366
|
-
.setRange(quasiExpr.range)
|
1376
|
+
.setRange(/** @type {Range} */ (quasiExpr.range))
|
1367
1377
|
.setExpression(quasiExpr);
|
1368
1378
|
quasis.push(part);
|
1369
1379
|
parts.push(part);
|
@@ -1381,11 +1391,11 @@ class JavascriptParser extends Parser {
|
|
1381
1391
|
|
1382
1392
|
const { quasis, parts } = getSimplifiedTemplateResult("cooked", node);
|
1383
1393
|
if (parts.length === 1) {
|
1384
|
-
return parts[0].setRange(node.range);
|
1394
|
+
return parts[0].setRange(/** @type {Range} */ (node.range));
|
1385
1395
|
}
|
1386
1396
|
return new BasicEvaluatedExpression()
|
1387
1397
|
.setTemplateString(quasis, parts, "cooked")
|
1388
|
-
.setRange(node.range);
|
1398
|
+
.setRange(/** @type {Range} */ (node.range));
|
1389
1399
|
});
|
1390
1400
|
this.hooks.evaluate
|
1391
1401
|
.for("TaggedTemplateExpression")
|
@@ -1400,7 +1410,7 @@ class JavascriptParser extends Parser {
|
|
1400
1410
|
);
|
1401
1411
|
return new BasicEvaluatedExpression()
|
1402
1412
|
.setTemplateString(quasis, parts, "raw")
|
1403
|
-
.setRange(node.range);
|
1413
|
+
.setRange(/** @type {Range} */ (node.range));
|
1404
1414
|
}
|
1405
1415
|
});
|
1406
1416
|
|
@@ -1490,7 +1500,7 @@ class JavascriptParser extends Parser {
|
|
1490
1500
|
return new BasicEvaluatedExpression()
|
1491
1501
|
.setArray(result)
|
1492
1502
|
.setSideEffects(param.couldHaveSideEffects())
|
1493
|
-
.setRange(expr.range);
|
1503
|
+
.setRange(/** @type {Range} */ (expr.range));
|
1494
1504
|
});
|
1495
1505
|
this.hooks.evaluate
|
1496
1506
|
.for("ConditionalExpression")
|
@@ -1505,12 +1515,16 @@ class JavascriptParser extends Parser {
|
|
1505
1515
|
const alternate = this.evaluateExpression(expr.alternate);
|
1506
1516
|
res = new BasicEvaluatedExpression();
|
1507
1517
|
if (consequent.isConditional()) {
|
1508
|
-
res.setOptions(
|
1518
|
+
res.setOptions(
|
1519
|
+
/** @type {BasicEvaluatedExpression[]} */ (consequent.options)
|
1520
|
+
);
|
1509
1521
|
} else {
|
1510
1522
|
res.setOptions([consequent]);
|
1511
1523
|
}
|
1512
1524
|
if (alternate.isConditional()) {
|
1513
|
-
res.addOptions(
|
1525
|
+
res.addOptions(
|
1526
|
+
/** @type {BasicEvaluatedExpression[]} */ (alternate.options)
|
1527
|
+
);
|
1514
1528
|
} else {
|
1515
1529
|
res.addOptions([alternate]);
|
1516
1530
|
}
|
@@ -1520,7 +1534,7 @@ class JavascriptParser extends Parser {
|
|
1520
1534
|
);
|
1521
1535
|
if (condition.couldHaveSideEffects()) res.setSideEffects();
|
1522
1536
|
}
|
1523
|
-
res.setRange(expr.range);
|
1537
|
+
res.setRange(/** @type {Range} */ (expr.range));
|
1524
1538
|
return res;
|
1525
1539
|
});
|
1526
1540
|
this.hooks.evaluate
|
@@ -1538,7 +1552,7 @@ class JavascriptParser extends Parser {
|
|
1538
1552
|
if (!items.every(Boolean)) return;
|
1539
1553
|
return new BasicEvaluatedExpression()
|
1540
1554
|
.setItems(items)
|
1541
|
-
.setRange(expr.range);
|
1555
|
+
.setRange(/** @type {Range} */ (expr.range));
|
1542
1556
|
});
|
1543
1557
|
this.hooks.evaluate
|
1544
1558
|
.for("ChainExpression")
|
@@ -1573,11 +1587,13 @@ class JavascriptParser extends Parser {
|
|
1573
1587
|
}
|
1574
1588
|
|
1575
1589
|
while (optionalExpressionsStack.length > 0) {
|
1576
|
-
const expression =
|
1590
|
+
const expression =
|
1591
|
+
/** @type {Expression} */
|
1592
|
+
(optionalExpressionsStack.pop());
|
1577
1593
|
const evaluated = this.evaluateExpression(expression);
|
1578
1594
|
|
1579
1595
|
if (evaluated.asNullish()) {
|
1580
|
-
return evaluated.setRange(_expr.range);
|
1596
|
+
return evaluated.setRange(/** @type {Range} */ (_expr.range));
|
1581
1597
|
}
|
1582
1598
|
}
|
1583
1599
|
return this.evaluateExpression(expr.expression);
|
@@ -2458,6 +2474,10 @@ class JavascriptParser extends Parser {
|
|
2458
2474
|
}
|
2459
2475
|
}
|
2460
2476
|
|
2477
|
+
/**
|
2478
|
+
* @param {ObjectPattern} objectPattern object pattern
|
2479
|
+
* @returns {Set<string> | undefined} set of names or undefined if not all keys are identifiers
|
2480
|
+
*/
|
2461
2481
|
_preWalkObjectPattern(objectPattern) {
|
2462
2482
|
const ids = new Set();
|
2463
2483
|
const properties = objectPattern.properties;
|
@@ -2696,6 +2716,9 @@ class JavascriptParser extends Parser {
|
|
2696
2716
|
}
|
2697
2717
|
}
|
2698
2718
|
|
2719
|
+
/**
|
2720
|
+
* @param {TODO} expression expression
|
2721
|
+
*/
|
2699
2722
|
walkExpression(expression) {
|
2700
2723
|
switch (expression.type) {
|
2701
2724
|
case "ArrayExpression":
|
@@ -3108,7 +3131,9 @@ class JavascriptParser extends Parser {
|
|
3108
3131
|
*/
|
3109
3132
|
walkTaggedTemplateExpression(expression) {
|
3110
3133
|
if (expression.tag) {
|
3134
|
+
this.scope.inTaggedTemplateTag = true;
|
3111
3135
|
this.walkExpression(expression.tag);
|
3136
|
+
this.scope.inTaggedTemplateTag = false;
|
3112
3137
|
}
|
3113
3138
|
if (expression.quasi && expression.quasi.expressions) {
|
3114
3139
|
this.walkExpressions(expression.quasi.expressions);
|
@@ -3264,7 +3289,7 @@ class JavascriptParser extends Parser {
|
|
3264
3289
|
callee.getMembersOptionals
|
3265
3290
|
? callee.getMembersOptionals()
|
3266
3291
|
: callee.getMembers().map(() => false),
|
3267
|
-
callee.
|
3292
|
+
callee.getMemberRanges ? callee.getMemberRanges() : []
|
3268
3293
|
);
|
3269
3294
|
if (result1 === true) return;
|
3270
3295
|
const result2 = this.callHooksForInfo(
|
@@ -3308,14 +3333,14 @@ class JavascriptParser extends Parser {
|
|
3308
3333
|
if (result1 === true) return;
|
3309
3334
|
const members = exprInfo.getMembers();
|
3310
3335
|
const membersOptionals = exprInfo.getMembersOptionals();
|
3311
|
-
const
|
3336
|
+
const memberRanges = exprInfo.getMemberRanges();
|
3312
3337
|
const result2 = this.callHooksForInfo(
|
3313
3338
|
this.hooks.expressionMemberChain,
|
3314
3339
|
exprInfo.rootInfo,
|
3315
3340
|
expression,
|
3316
3341
|
members,
|
3317
3342
|
membersOptionals,
|
3318
|
-
|
3343
|
+
memberRanges
|
3319
3344
|
);
|
3320
3345
|
if (result2 === true) return;
|
3321
3346
|
this.walkMemberExpressionWithExpressionName(
|
@@ -3423,10 +3448,10 @@ class JavascriptParser extends Parser {
|
|
3423
3448
|
* @template R
|
3424
3449
|
* @param {HookMap<SyncBailHook<T, R>>} hookMap hooks the should be called
|
3425
3450
|
* @param {MemberExpression} expr expression info
|
3426
|
-
* @param {function(string, string | ScopeInfo | VariableInfo, function(): string[]): any} fallback callback when variable in not handled by hooks
|
3427
|
-
* @param {function(string): any} defined callback when variable is defined
|
3451
|
+
* @param {(function(string, string | ScopeInfo | VariableInfo, function(): string[]): any) | undefined} fallback callback when variable in not handled by hooks
|
3452
|
+
* @param {(function(string): any) | undefined} defined callback when variable is defined
|
3428
3453
|
* @param {AsArray<T>} args args for the hook
|
3429
|
-
* @returns {R} result of hook
|
3454
|
+
* @returns {R | undefined} result of hook
|
3430
3455
|
*/
|
3431
3456
|
callHooksForExpressionWithFallback(
|
3432
3457
|
hookMap,
|
@@ -3458,7 +3483,7 @@ class JavascriptParser extends Parser {
|
|
3458
3483
|
* @param {HookMap<SyncBailHook<T, R>>} hookMap hooks the should be called
|
3459
3484
|
* @param {string} name key in map
|
3460
3485
|
* @param {AsArray<T>} args args for the hook
|
3461
|
-
* @returns {R} result of hook
|
3486
|
+
* @returns {R | undefined} result of hook
|
3462
3487
|
*/
|
3463
3488
|
callHooksForName(hookMap, name, ...args) {
|
3464
3489
|
return this.callHooksForNameWithFallback(
|
@@ -3476,7 +3501,7 @@ class JavascriptParser extends Parser {
|
|
3476
3501
|
* @param {HookMap<SyncBailHook<T, R>>} hookMap hooks that should be called
|
3477
3502
|
* @param {ExportedVariableInfo} info variable info
|
3478
3503
|
* @param {AsArray<T>} args args for the hook
|
3479
|
-
* @returns {R} result of hook
|
3504
|
+
* @returns {R | undefined} result of hook
|
3480
3505
|
*/
|
3481
3506
|
callHooksForInfo(hookMap, info, ...args) {
|
3482
3507
|
return this.callHooksForInfoWithFallback(
|
@@ -3493,10 +3518,10 @@ class JavascriptParser extends Parser {
|
|
3493
3518
|
* @template R
|
3494
3519
|
* @param {HookMap<SyncBailHook<T, R>>} hookMap hooks the should be called
|
3495
3520
|
* @param {ExportedVariableInfo} info variable info
|
3496
|
-
* @param {function(string): any} fallback callback when variable in not handled by hooks
|
3497
|
-
* @param {function(): any} defined callback when variable is defined
|
3521
|
+
* @param {(function(string): any) | undefined} fallback callback when variable in not handled by hooks
|
3522
|
+
* @param {(function(): any) | undefined} defined callback when variable is defined
|
3498
3523
|
* @param {AsArray<T>} args args for the hook
|
3499
|
-
* @returns {R} result of hook
|
3524
|
+
* @returns {R | undefined} result of hook
|
3500
3525
|
*/
|
3501
3526
|
callHooksForInfoWithFallback(hookMap, info, fallback, defined, ...args) {
|
3502
3527
|
let name;
|
@@ -3543,10 +3568,10 @@ class JavascriptParser extends Parser {
|
|
3543
3568
|
* @template R
|
3544
3569
|
* @param {HookMap<SyncBailHook<T, R>>} hookMap hooks the should be called
|
3545
3570
|
* @param {string} name key in map
|
3546
|
-
* @param {function(string): any} fallback callback when variable in not handled by hooks
|
3547
|
-
* @param {function(): any} defined callback when variable is defined
|
3571
|
+
* @param {(function(string): any) | undefined} fallback callback when variable in not handled by hooks
|
3572
|
+
* @param {(function(): any) | undefined} defined callback when variable is defined
|
3548
3573
|
* @param {AsArray<T>} args args for the hook
|
3549
|
-
* @returns {R} result of hook
|
3574
|
+
* @returns {R | undefined} result of hook
|
3550
3575
|
*/
|
3551
3576
|
callHooksForNameWithFallback(hookMap, name, fallback, defined, ...args) {
|
3552
3577
|
return this.callHooksForInfoWithFallback(
|
@@ -3570,6 +3595,7 @@ class JavascriptParser extends Parser {
|
|
3570
3595
|
topLevelScope: oldScope.topLevelScope,
|
3571
3596
|
inTry: false,
|
3572
3597
|
inShorthand: false,
|
3598
|
+
inTaggedTemplateTag: false,
|
3573
3599
|
isStrict: oldScope.isStrict,
|
3574
3600
|
isAsmJs: oldScope.isAsmJs,
|
3575
3601
|
definitions: oldScope.definitions.createChild()
|
@@ -3586,12 +3612,19 @@ class JavascriptParser extends Parser {
|
|
3586
3612
|
this.scope = oldScope;
|
3587
3613
|
}
|
3588
3614
|
|
3615
|
+
/**
|
3616
|
+
* @param {boolean} hasThis true, when this is defined
|
3617
|
+
* @param {any} params scope params
|
3618
|
+
* @param {function(): void} fn inner function
|
3619
|
+
* @returns {void}
|
3620
|
+
*/
|
3589
3621
|
inClassScope(hasThis, params, fn) {
|
3590
3622
|
const oldScope = this.scope;
|
3591
3623
|
this.scope = {
|
3592
3624
|
topLevelScope: oldScope.topLevelScope,
|
3593
3625
|
inTry: false,
|
3594
3626
|
inShorthand: false,
|
3627
|
+
inTaggedTemplateTag: false,
|
3595
3628
|
isStrict: oldScope.isStrict,
|
3596
3629
|
isAsmJs: oldScope.isAsmJs,
|
3597
3630
|
definitions: oldScope.definitions.createChild()
|
@@ -3610,12 +3643,19 @@ class JavascriptParser extends Parser {
|
|
3610
3643
|
this.scope = oldScope;
|
3611
3644
|
}
|
3612
3645
|
|
3646
|
+
/**
|
3647
|
+
* @param {boolean} hasThis true, when this is defined
|
3648
|
+
* @param {any} params scope params
|
3649
|
+
* @param {function(): void} fn inner function
|
3650
|
+
* @returns {void}
|
3651
|
+
*/
|
3613
3652
|
inFunctionScope(hasThis, params, fn) {
|
3614
3653
|
const oldScope = this.scope;
|
3615
3654
|
this.scope = {
|
3616
3655
|
topLevelScope: oldScope.topLevelScope,
|
3617
3656
|
inTry: false,
|
3618
3657
|
inShorthand: false,
|
3658
|
+
inTaggedTemplateTag: false,
|
3619
3659
|
isStrict: oldScope.isStrict,
|
3620
3660
|
isAsmJs: oldScope.isAsmJs,
|
3621
3661
|
definitions: oldScope.definitions.createChild()
|
@@ -3634,12 +3674,17 @@ class JavascriptParser extends Parser {
|
|
3634
3674
|
this.scope = oldScope;
|
3635
3675
|
}
|
3636
3676
|
|
3677
|
+
/**
|
3678
|
+
* @param {function(): void} fn inner function
|
3679
|
+
* @returns {void}
|
3680
|
+
*/
|
3637
3681
|
inBlockScope(fn) {
|
3638
3682
|
const oldScope = this.scope;
|
3639
3683
|
this.scope = {
|
3640
3684
|
topLevelScope: oldScope.topLevelScope,
|
3641
3685
|
inTry: oldScope.inTry,
|
3642
3686
|
inShorthand: false,
|
3687
|
+
inTaggedTemplateTag: false,
|
3643
3688
|
isStrict: oldScope.isStrict,
|
3644
3689
|
isAsmJs: oldScope.isAsmJs,
|
3645
3690
|
definitions: oldScope.definitions.createChild()
|
@@ -3650,15 +3695,28 @@ class JavascriptParser extends Parser {
|
|
3650
3695
|
this.scope = oldScope;
|
3651
3696
|
}
|
3652
3697
|
|
3698
|
+
/**
|
3699
|
+
* @param {Array<Directive | Statement | ModuleDeclaration>} statements statements
|
3700
|
+
*/
|
3653
3701
|
detectMode(statements) {
|
3654
3702
|
const isLiteral =
|
3655
3703
|
statements.length >= 1 &&
|
3656
3704
|
statements[0].type === "ExpressionStatement" &&
|
3657
3705
|
statements[0].expression.type === "Literal";
|
3658
|
-
if (
|
3706
|
+
if (
|
3707
|
+
isLiteral &&
|
3708
|
+
/** @type {Literal} */
|
3709
|
+
(/** @type {ExpressionStatement} */ (statements[0]).expression).value ===
|
3710
|
+
"use strict"
|
3711
|
+
) {
|
3659
3712
|
this.scope.isStrict = true;
|
3660
3713
|
}
|
3661
|
-
if (
|
3714
|
+
if (
|
3715
|
+
isLiteral &&
|
3716
|
+
/** @type {Literal} */
|
3717
|
+
(/** @type {ExpressionStatement} */ (statements[0]).expression).value ===
|
3718
|
+
"use asm"
|
3719
|
+
) {
|
3662
3720
|
this.scope.isAsmJs = true;
|
3663
3721
|
}
|
3664
3722
|
}
|
@@ -3761,7 +3819,7 @@ class JavascriptParser extends Parser {
|
|
3761
3819
|
}
|
3762
3820
|
|
3763
3821
|
/**
|
3764
|
-
* @param {
|
3822
|
+
* @param {TODO} expression expression node
|
3765
3823
|
* @returns {BasicEvaluatedExpression} evaluation result
|
3766
3824
|
*/
|
3767
3825
|
evaluateExpression(expression) {
|
@@ -3779,7 +3837,7 @@ class JavascriptParser extends Parser {
|
|
3779
3837
|
// ignore error
|
3780
3838
|
}
|
3781
3839
|
return new BasicEvaluatedExpression()
|
3782
|
-
.setRange(expression.range)
|
3840
|
+
.setRange(/** @type {Range} */ (expression.range))
|
3783
3841
|
.setExpression(expression);
|
3784
3842
|
}
|
3785
3843
|
|
@@ -3916,6 +3974,7 @@ class JavascriptParser extends Parser {
|
|
3916
3974
|
topLevelScope: true,
|
3917
3975
|
inTry: false,
|
3918
3976
|
inShorthand: false,
|
3977
|
+
inTaggedTemplateTag: false,
|
3919
3978
|
isStrict: false,
|
3920
3979
|
isAsmJs: false,
|
3921
3980
|
definitions: new StackedMap()
|
@@ -4024,43 +4083,52 @@ class JavascriptParser extends Parser {
|
|
4024
4083
|
|
4025
4084
|
case "VariableDeclaration":
|
4026
4085
|
return expr.declarations.every(decl =>
|
4027
|
-
this.isPure(decl.init, decl.range[0])
|
4086
|
+
this.isPure(decl.init, /** @type {Range} */ (decl.range)[0])
|
4028
4087
|
);
|
4029
4088
|
|
4030
4089
|
case "ConditionalExpression":
|
4031
4090
|
return (
|
4032
4091
|
this.isPure(expr.test, commentsStartPos) &&
|
4033
|
-
this.isPure(
|
4034
|
-
|
4092
|
+
this.isPure(
|
4093
|
+
expr.consequent,
|
4094
|
+
/** @type {Range} */ (expr.test.range)[1]
|
4095
|
+
) &&
|
4096
|
+
this.isPure(
|
4097
|
+
expr.alternate,
|
4098
|
+
/** @type {Range} */ (expr.consequent.range)[1]
|
4099
|
+
)
|
4035
4100
|
);
|
4036
4101
|
|
4037
4102
|
case "LogicalExpression":
|
4038
4103
|
return (
|
4039
4104
|
this.isPure(expr.left, commentsStartPos) &&
|
4040
|
-
this.isPure(expr.right, expr.left.range[1])
|
4105
|
+
this.isPure(expr.right, /** @type {Range} */ (expr.left.range)[1])
|
4041
4106
|
);
|
4042
4107
|
|
4043
4108
|
case "SequenceExpression":
|
4044
4109
|
return expr.expressions.every(expr => {
|
4045
4110
|
const pureFlag = this.isPure(expr, commentsStartPos);
|
4046
|
-
commentsStartPos = expr.range[1];
|
4111
|
+
commentsStartPos = /** @type {Range} */ (expr.range)[1];
|
4047
4112
|
return pureFlag;
|
4048
4113
|
});
|
4049
4114
|
|
4050
4115
|
case "CallExpression": {
|
4051
4116
|
const pureFlag =
|
4052
|
-
expr.range[0] - commentsStartPos > 12 &&
|
4053
|
-
this.getComments([
|
4117
|
+
/** @type {Range} */ (expr.range)[0] - commentsStartPos > 12 &&
|
4118
|
+
this.getComments([
|
4119
|
+
commentsStartPos,
|
4120
|
+
/** @type {Range} */ (expr.range)[0]
|
4121
|
+
]).some(
|
4054
4122
|
comment =>
|
4055
4123
|
comment.type === "Block" &&
|
4056
4124
|
/^\s*(#|@)__PURE__\s*$/.test(comment.value)
|
4057
4125
|
);
|
4058
4126
|
if (!pureFlag) return false;
|
4059
|
-
commentsStartPos = expr.callee.range[1];
|
4127
|
+
commentsStartPos = /** @type {Range} */ (expr.callee.range)[1];
|
4060
4128
|
return expr.arguments.every(arg => {
|
4061
4129
|
if (arg.type === "SpreadElement") return false;
|
4062
4130
|
const pureFlag = this.isPure(arg, commentsStartPos);
|
4063
|
-
commentsStartPos = arg.range[1];
|
4131
|
+
commentsStartPos = /** @type {Range} */ (arg.range)[1];
|
4064
4132
|
return pureFlag;
|
4065
4133
|
});
|
4066
4134
|
}
|
@@ -4114,6 +4182,10 @@ class JavascriptParser extends Parser {
|
|
4114
4182
|
this.semicolons.delete(pos);
|
4115
4183
|
}
|
4116
4184
|
|
4185
|
+
/**
|
4186
|
+
* @param {Expression} expr expression
|
4187
|
+
* @returns {boolean} true, when the expression is a statement level expression
|
4188
|
+
*/
|
4117
4189
|
isStatementLevelExpression(expr) {
|
4118
4190
|
const currentStatement = this.statementPath[this.statementPath.length - 1];
|
4119
4191
|
return (
|
@@ -4271,23 +4343,23 @@ class JavascriptParser extends Parser {
|
|
4271
4343
|
|
4272
4344
|
/**
|
4273
4345
|
* @param {MemberExpression} expression a member expression
|
4274
|
-
* @returns {{ members: string[], object: Expression | Super, membersOptionals: boolean[],
|
4346
|
+
* @returns {{ members: string[], object: Expression | Super, membersOptionals: boolean[], memberRanges: Range[] }} member names (reverse order) and remaining object
|
4275
4347
|
*/
|
4276
4348
|
extractMemberExpressionChain(expression) {
|
4277
4349
|
/** @type {AnyNode} */
|
4278
4350
|
let expr = expression;
|
4279
4351
|
const members = [];
|
4280
4352
|
const membersOptionals = [];
|
4281
|
-
const
|
4353
|
+
const memberRanges = [];
|
4282
4354
|
while (expr.type === "MemberExpression") {
|
4283
4355
|
if (expr.computed) {
|
4284
4356
|
if (expr.property.type !== "Literal") break;
|
4285
|
-
members.push(`${expr.property.value}`);
|
4286
|
-
|
4357
|
+
members.push(`${expr.property.value}`); // the literal
|
4358
|
+
memberRanges.push(expr.object.range); // the range of the expression fragment before the literal
|
4287
4359
|
} else {
|
4288
4360
|
if (expr.property.type !== "Identifier") break;
|
4289
|
-
members.push(expr.property.name);
|
4290
|
-
|
4361
|
+
members.push(expr.property.name); // the identifier
|
4362
|
+
memberRanges.push(expr.object.range); // the range of the expression fragment before the identifier
|
4291
4363
|
}
|
4292
4364
|
membersOptionals.push(expr.optional);
|
4293
4365
|
expr = expr.object;
|
@@ -4296,14 +4368,14 @@ class JavascriptParser extends Parser {
|
|
4296
4368
|
return {
|
4297
4369
|
members,
|
4298
4370
|
membersOptionals,
|
4299
|
-
|
4371
|
+
memberRanges,
|
4300
4372
|
object: expr
|
4301
4373
|
};
|
4302
4374
|
}
|
4303
4375
|
|
4304
4376
|
/**
|
4305
4377
|
* @param {string} varName variable name
|
4306
|
-
* @returns {{name: string, info: VariableInfo | string}} name of the free variable and variable info for that
|
4378
|
+
* @returns {{name: string, info: VariableInfo | string} | undefined} name of the free variable and variable info for that
|
4307
4379
|
*/
|
4308
4380
|
getFreeInfoFromVariable(varName) {
|
4309
4381
|
const info = this.getVariableInfo(varName);
|
@@ -4319,8 +4391,8 @@ class JavascriptParser extends Parser {
|
|
4319
4391
|
return { info, name };
|
4320
4392
|
}
|
4321
4393
|
|
4322
|
-
/** @typedef {{ type: "call", call: CallExpression, calleeName: string, rootInfo: string | VariableInfo, getCalleeMembers: () => string[], name: string, getMembers: () => string[], getMembersOptionals: () => boolean[],
|
4323
|
-
/** @typedef {{ type: "expression", rootInfo: string | VariableInfo, name: string, getMembers: () => string[], getMembersOptionals: () => boolean[],
|
4394
|
+
/** @typedef {{ type: "call", call: CallExpression, calleeName: string, rootInfo: string | VariableInfo, getCalleeMembers: () => string[], name: string, getMembers: () => string[], getMembersOptionals: () => boolean[], getMemberRanges: () => Range[]}} CallExpressionInfo */
|
4395
|
+
/** @typedef {{ type: "expression", rootInfo: string | VariableInfo, name: string, getMembers: () => string[], getMembersOptionals: () => boolean[], getMemberRanges: () => Range[]}} ExpressionExpressionInfo */
|
4324
4396
|
|
4325
4397
|
/**
|
4326
4398
|
* @param {MemberExpression} expression a member expression
|
@@ -4328,7 +4400,7 @@ class JavascriptParser extends Parser {
|
|
4328
4400
|
* @returns {CallExpressionInfo | ExpressionExpressionInfo | undefined} expression info
|
4329
4401
|
*/
|
4330
4402
|
getMemberExpressionInfo(expression, allowedTypes) {
|
4331
|
-
const { object, members, membersOptionals,
|
4403
|
+
const { object, members, membersOptionals, memberRanges } =
|
4332
4404
|
this.extractMemberExpressionChain(expression);
|
4333
4405
|
switch (object.type) {
|
4334
4406
|
case "CallExpression": {
|
@@ -4355,7 +4427,7 @@ class JavascriptParser extends Parser {
|
|
4355
4427
|
name: objectAndMembersToName(`${calleeName}()`, members),
|
4356
4428
|
getMembers: memoize(() => members.reverse()),
|
4357
4429
|
getMembersOptionals: memoize(() => membersOptionals.reverse()),
|
4358
|
-
|
4430
|
+
getMemberRanges: memoize(() => memberRanges.reverse())
|
4359
4431
|
};
|
4360
4432
|
}
|
4361
4433
|
case "Identifier":
|
@@ -4375,7 +4447,7 @@ class JavascriptParser extends Parser {
|
|
4375
4447
|
rootInfo,
|
4376
4448
|
getMembers: memoize(() => members.reverse()),
|
4377
4449
|
getMembersOptionals: memoize(() => membersOptionals.reverse()),
|
4378
|
-
|
4450
|
+
getMemberRanges: memoize(() => memberRanges.reverse())
|
4379
4451
|
};
|
4380
4452
|
}
|
4381
4453
|
}
|
@@ -4383,7 +4455,7 @@ class JavascriptParser extends Parser {
|
|
4383
4455
|
|
4384
4456
|
/**
|
4385
4457
|
* @param {MemberExpression} expression an expression
|
4386
|
-
* @returns {{ name: string, rootInfo: ExportedVariableInfo, getMembers: () => string[]}} name info
|
4458
|
+
* @returns {{ name: string, rootInfo: ExportedVariableInfo, getMembers: () => string[]} | undefined} name info
|
4387
4459
|
*/
|
4388
4460
|
getNameForExpression(expression) {
|
4389
4461
|
return this.getMemberExpressionInfo(
|
@@ -4407,7 +4479,7 @@ class JavascriptParser extends Parser {
|
|
4407
4479
|
sourceType: type === "auto" ? "module" : type
|
4408
4480
|
};
|
4409
4481
|
|
4410
|
-
/** @type {AnyNode} */
|
4482
|
+
/** @type {AnyNode | undefined} */
|
4411
4483
|
let ast;
|
4412
4484
|
let error;
|
4413
4485
|
let threw = false;
|