webpack 5.83.1 → 5.85.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of webpack might be problematic. Click here for more details.
- package/README.md +2 -2
- package/lib/AsyncDependenciesBlock.js +2 -2
- package/lib/AutomaticPrefetchPlugin.js +1 -0
- package/lib/BannerPlugin.js +4 -0
- package/lib/CacheFacade.js +4 -0
- package/lib/ChunkGroup.js +5 -1
- package/lib/CleanPlugin.js +30 -7
- package/lib/CompatibilityPlugin.js +4 -3
- package/lib/Compilation.js +3 -3
- package/lib/Compiler.js +1 -1
- package/lib/ContextModule.js +3 -3
- package/lib/ContextModuleFactory.js +1 -1
- package/lib/DefinePlugin.js +11 -2
- package/lib/DllEntryPlugin.js +5 -0
- package/lib/DllModule.js +1 -1
- package/lib/DllModuleFactory.js +1 -1
- package/lib/EvalSourceMapDevToolPlugin.js +3 -1
- package/lib/HookWebpackError.js +1 -1
- package/lib/IgnoreErrorModuleFactory.js +1 -1
- package/lib/MainTemplate.js +2 -2
- package/lib/Module.js +21 -9
- package/lib/ModuleFactory.js +1 -1
- package/lib/ModuleTypeConstants.js +2 -1
- package/lib/NormalModuleFactory.js +1 -1
- package/lib/NormalModuleReplacementPlugin.js +4 -2
- package/lib/NullFactory.js +1 -1
- package/lib/PrefetchPlugin.js +4 -0
- package/lib/RecordIdsPlugin.js +4 -4
- package/lib/RuntimeModule.js +5 -5
- package/lib/RuntimePlugin.js +4 -0
- package/lib/RuntimeTemplate.js +7 -7
- package/lib/SelfModuleFactory.js +12 -0
- package/lib/SourceMapDevToolPlugin.js +9 -2
- package/lib/Template.js +3 -2
- package/lib/UseStrictPlugin.js +4 -0
- package/lib/WarnDeprecatedOptionPlugin.js +7 -0
- package/lib/WatchIgnorePlugin.js +4 -0
- package/lib/WebpackOptionsApply.js +2 -1
- package/lib/asset/AssetGenerator.js +7 -2
- package/lib/asset/AssetModulesPlugin.js +7 -1
- package/lib/asset/AssetParser.js +4 -1
- package/lib/asset/RawDataUrlModule.js +5 -3
- package/lib/async-modules/InferAsyncModulesPlugin.js +1 -1
- package/lib/cache/PackFileCacheStrategy.js +7 -1
- package/lib/config/browserslistTargetHandler.js +3 -3
- package/lib/config/defaults.js +240 -73
- package/lib/config/normalization.js +104 -71
- package/lib/config/target.js +37 -10
- package/lib/container/ContainerEntryModule.js +4 -0
- package/lib/container/ContainerEntryModuleFactory.js +1 -1
- package/lib/container/FallbackDependency.js +7 -0
- package/lib/container/FallbackItemDependency.js +3 -0
- package/lib/container/FallbackModule.js +5 -1
- package/lib/container/FallbackModuleFactory.js +1 -1
- package/lib/container/RemoteModule.js +4 -0
- package/lib/container/RemoteRuntimeModule.js +2 -1
- package/lib/container/RemoteToExternalDependency.js +3 -0
- package/lib/css/CssParser.js +168 -73
- package/lib/debug/ProfilingPlugin.js +11 -0
- package/lib/dependencies/AMDDefineDependency.js +12 -6
- package/lib/dependencies/AMDDefineDependencyParserPlugin.js +8 -2
- package/lib/dependencies/AMDPlugin.js +7 -0
- package/lib/dependencies/AMDRequireArrayDependency.js +5 -0
- package/lib/dependencies/AMDRequireContextDependency.js +6 -0
- package/lib/dependencies/AMDRequireDependenciesBlock.js +6 -0
- package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +8 -2
- package/lib/dependencies/AMDRequireDependency.js +8 -1
- package/lib/dependencies/AMDRequireItemDependency.js +6 -0
- package/lib/dependencies/CachedConstDependency.js +6 -0
- package/lib/dependencies/CommonJsExportRequireDependency.js +11 -0
- package/lib/dependencies/CommonJsExportsDependency.js +8 -0
- package/lib/dependencies/CommonJsExportsParserPlugin.js +2 -2
- package/lib/dependencies/CommonJsFullRequireDependency.js +2 -1
- package/lib/dependencies/CommonJsPlugin.js +28 -12
- package/lib/dependencies/CommonJsRequireContextDependency.js +8 -0
- package/lib/dependencies/CommonJsRequireDependency.js +7 -0
- package/lib/dependencies/CommonJsSelfReferenceDependency.js +8 -0
- package/lib/dependencies/ConstDependency.js +2 -1
- package/lib/dependencies/ContextDependencyHelpers.js +3 -3
- package/lib/dependencies/CreateScriptUrlDependency.js +2 -1
- package/lib/dependencies/CriticalDependencyWarning.js +3 -0
- package/lib/dependencies/CssImportDependency.js +2 -1
- package/lib/dependencies/CssLocalIdentifierDependency.js +2 -1
- package/lib/dependencies/CssSelfLocalIdentifierDependency.js +2 -1
- package/lib/dependencies/CssUrlDependency.js +12 -2
- package/lib/dependencies/DelegatedSourceDependency.js +3 -0
- package/lib/dependencies/ExportsInfoDependency.js +6 -0
- package/lib/dependencies/HarmonyAcceptDependency.js +2 -1
- package/lib/dependencies/HarmonyAcceptImportDependency.js +3 -0
- package/lib/dependencies/HarmonyDetectionParserPlugin.js +16 -0
- package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +12 -1
- package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +3 -0
- package/lib/dependencies/HarmonyExportExpressionDependency.js +8 -0
- package/lib/dependencies/HarmonyExportHeaderDependency.js +5 -0
- package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +2 -1
- package/lib/dependencies/HarmonyExportSpecifierDependency.js +4 -0
- package/lib/dependencies/HarmonyExports.js +3 -1
- package/lib/dependencies/HarmonyImportDependency.js +2 -1
- package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +18 -5
- package/lib/dependencies/HarmonyImportSideEffectDependency.js +6 -0
- package/lib/dependencies/HarmonyImportSpecifierDependency.js +86 -6
- package/lib/dependencies/HarmonyModulesPlugin.js +12 -0
- package/lib/dependencies/ImportContextDependency.js +6 -0
- package/lib/dependencies/ImportDependency.js +2 -1
- package/lib/dependencies/ImportEagerDependency.js +2 -1
- package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +32 -13
- package/lib/dependencies/ImportMetaContextPlugin.js +7 -0
- package/lib/dependencies/ImportMetaHotAcceptDependency.js +6 -0
- package/lib/dependencies/ImportMetaHotDeclineDependency.js +6 -0
- package/lib/dependencies/ImportParserPlugin.js +5 -0
- package/lib/dependencies/ImportPlugin.js +7 -0
- package/lib/dependencies/ImportWeakDependency.js +2 -1
- package/lib/dependencies/LocalModule.js +16 -0
- package/lib/dependencies/LocalModuleDependency.js +7 -0
- package/lib/dependencies/LocalModulesHelpers.js +18 -0
- package/lib/dependencies/ModuleHotAcceptDependency.js +6 -0
- package/lib/dependencies/ModuleHotDeclineDependency.js +6 -0
- package/lib/dependencies/PrefetchDependency.js +3 -0
- package/lib/dependencies/ProvidedDependency.js +2 -1
- package/lib/dependencies/PureExpressionDependency.js +2 -1
- package/lib/dependencies/RequireContextDependency.js +6 -0
- package/lib/dependencies/RequireContextPlugin.js +7 -0
- package/lib/dependencies/RequireEnsureDependenciesBlock.js +4 -0
- package/lib/dependencies/RequireEnsureDependency.js +8 -2
- package/lib/dependencies/RequireEnsureItemDependency.js +3 -0
- package/lib/dependencies/RequireEnsurePlugin.js +14 -0
- package/lib/dependencies/RequireHeaderDependency.js +5 -1
- package/lib/dependencies/RequireIncludeDependency.js +5 -0
- package/lib/dependencies/RequireIncludeDependencyParserPlugin.js +3 -0
- package/lib/dependencies/RequireIncludePlugin.js +14 -0
- package/lib/dependencies/RequireResolveContextDependency.js +8 -0
- package/lib/dependencies/RequireResolveDependency.js +6 -0
- package/lib/dependencies/RequireResolveHeaderDependency.js +4 -0
- package/lib/dependencies/SystemPlugin.js +10 -1
- package/lib/dependencies/URLDependency.js +3 -2
- package/lib/dependencies/URLPlugin.js +7 -5
- package/lib/dependencies/UnsupportedDependency.js +5 -0
- package/lib/dependencies/WebAssemblyExportImportedDependency.js +6 -0
- package/lib/dependencies/WebpackIsIncludedDependency.js +5 -0
- package/lib/dependencies/WorkerDependency.js +2 -1
- package/lib/dependencies/WorkerPlugin.js +30 -3
- package/lib/dependencies/getFunctionExpression.js +7 -0
- package/lib/esm/ExportWebpackRequireRuntimeModule.js +2 -1
- package/lib/esm/ModuleChunkFormatPlugin.js +15 -7
- package/lib/esm/ModuleChunkLoadingPlugin.js +9 -0
- package/lib/esm/ModuleChunkLoadingRuntimeModule.js +14 -9
- package/lib/hmr/LazyCompilationPlugin.js +1 -1
- package/lib/ids/ChunkModuleIdRangePlugin.js +11 -0
- package/lib/ids/DeterministicChunkIdsPlugin.js +11 -2
- package/lib/ids/DeterministicModuleIdsPlugin.js +11 -7
- package/lib/ids/HashedModuleIdsPlugin.js +8 -1
- package/lib/ids/IdHelpers.js +6 -0
- package/lib/ids/NamedChunkIdsPlugin.js +13 -1
- package/lib/ids/NamedModuleIdsPlugin.js +14 -3
- package/lib/ids/OccurrenceChunkIdsPlugin.js +6 -2
- package/lib/ids/SyncModuleIdsPlugin.js +2 -2
- package/lib/javascript/ArrayPushCallbackChunkFormatPlugin.js +3 -3
- package/lib/javascript/BasicEvaluatedExpression.js +11 -1
- package/lib/javascript/ChunkHelpers.js +2 -2
- package/lib/javascript/CommonJsChunkFormatPlugin.js +1 -1
- package/lib/javascript/EnableChunkLoadingPlugin.js +4 -0
- package/lib/javascript/JavascriptModulesPlugin.js +36 -31
- package/lib/javascript/JavascriptParser.js +586 -192
- package/lib/javascript/StartupHelpers.js +2 -2
- package/lib/json/JsonGenerator.js +7 -5
- package/lib/json/JsonParser.js +1 -1
- package/lib/library/AbstractLibraryPlugin.js +4 -0
- package/lib/library/AssignLibraryPlugin.js +6 -4
- package/lib/library/ExportPropertyLibraryPlugin.js +4 -1
- package/lib/library/ModuleLibraryPlugin.js +6 -3
- package/lib/library/SystemLibraryPlugin.js +1 -0
- package/lib/library/UmdLibraryPlugin.js +4 -0
- package/lib/node/CommonJsChunkLoadingPlugin.js +17 -2
- package/lib/node/NodeTemplatePlugin.js +10 -2
- package/lib/node/NodeWatchFileSystem.js +1 -1
- package/lib/node/ReadFileChunkLoadingRuntimeModule.js +6 -3
- package/lib/node/ReadFileCompileAsyncWasmPlugin.js +8 -0
- package/lib/node/ReadFileCompileWasmPlugin.js +19 -2
- package/lib/node/RequireChunkLoadingRuntimeModule.js +6 -3
- package/lib/optimize/ConcatenatedModule.js +1 -1
- package/lib/optimize/InnerGraphPlugin.js +11 -4
- package/lib/runtime/AsyncModuleRuntimeModule.js +1 -1
- package/lib/runtime/AutoPublicPathRuntimeModule.js +5 -1
- package/lib/runtime/BaseUriRuntimeModule.js +5 -1
- package/lib/runtime/EnsureChunkRuntimeModule.js +3 -0
- package/lib/runtime/GetChunkFilenameRuntimeModule.js +35 -16
- package/lib/runtime/GetTrustedTypesPolicyRuntimeModule.js +1 -1
- package/lib/runtime/LoadScriptRuntimeModule.js +1 -1
- package/lib/runtime/PublicPathRuntimeModule.js +5 -0
- package/lib/runtime/StartupChunkDependenciesPlugin.js +15 -0
- package/lib/runtime/StartupChunkDependenciesRuntimeModule.js +4 -1
- package/lib/runtime/StartupEntrypointRuntimeModule.js +8 -5
- package/lib/serialization/ArraySerializer.js +22 -6
- package/lib/serialization/BinaryMiddleware.js +21 -0
- package/lib/serialization/DateObjectSerializer.js +15 -4
- package/lib/serialization/ErrorObjectSerializer.js +20 -8
- package/lib/serialization/FileMiddleware.js +17 -0
- package/lib/serialization/MapObjectSerializer.js +24 -8
- package/lib/serialization/NullPrototypeObjectSerializer.js +25 -8
- package/lib/serialization/ObjectMiddleware.js +23 -0
- package/lib/serialization/PlainObjectSerializer.js +23 -12
- package/lib/serialization/RegExpObjectSerializer.js +16 -5
- package/lib/serialization/SetObjectSerializer.js +21 -6
- package/lib/sharing/ProvideSharedModuleFactory.js +1 -1
- package/lib/sharing/ShareRuntimeModule.js +1 -1
- package/lib/util/createHash.js +1 -1
- package/lib/util/makeSerializable.js +7 -0
- package/lib/util/serialization.js +10 -0
- package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +9 -0
- package/lib/wasm-async/AsyncWebAssemblyGenerator.js +9 -1
- package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +13 -3
- package/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js +19 -2
- package/lib/wasm-async/AsyncWebAssemblyParser.js +3 -0
- package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +25 -1
- package/lib/wasm-sync/WasmFinalizeExportsPlugin.js +14 -5
- package/lib/wasm-sync/WebAssemblyGenerator.js +18 -5
- package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +1 -1
- package/lib/wasm-sync/WebAssemblyModulesPlugin.js +12 -1
- package/lib/wasm-sync/WebAssemblyParser.js +9 -2
- package/lib/wasm-sync/WebAssemblyUtils.js +1 -1
- package/lib/web/FetchCompileAsyncWasmPlugin.js +9 -0
- package/lib/web/FetchCompileWasmPlugin.js +19 -2
- package/lib/web/JsonpChunkLoadingPlugin.js +9 -0
- package/lib/web/JsonpChunkLoadingRuntimeModule.js +4 -1
- package/lib/webworker/ImportScriptsChunkLoadingPlugin.js +9 -0
- package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +6 -2
- package/package.json +3 -3
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +12 -0
- package/schemas/plugins/SourceMapDevToolPlugin.check.js +1 -1
- package/schemas/plugins/SourceMapDevToolPlugin.json +4 -0
- package/types.d.ts +655 -290
@@ -16,48 +16,82 @@ const memoize = require("../util/memoize");
|
|
16
16
|
const BasicEvaluatedExpression = require("./BasicEvaluatedExpression");
|
17
17
|
|
18
18
|
/** @typedef {import("acorn").Options} AcornOptions */
|
19
|
-
/** @typedef {import("estree").
|
20
|
-
/** @typedef {import("estree").BinaryExpression}
|
21
|
-
/** @typedef {import("estree").BlockStatement}
|
22
|
-
/** @typedef {import("estree").SequenceExpression}
|
23
|
-
/** @typedef {import("estree").CallExpression}
|
24
|
-
/** @typedef {import("estree").
|
25
|
-
/** @typedef {import("estree").
|
26
|
-
/** @typedef {import("estree").
|
27
|
-
/** @typedef {import("estree").
|
28
|
-
/** @typedef {import("estree").
|
29
|
-
/** @typedef {import("estree").
|
30
|
-
/** @typedef {import("estree").
|
31
|
-
/** @typedef {import("estree").
|
32
|
-
/** @typedef {import("estree").
|
33
|
-
/** @typedef {import("estree").
|
34
|
-
/** @typedef {import("estree").
|
35
|
-
/** @typedef {import("estree").
|
36
|
-
/** @typedef {import("estree").
|
37
|
-
/** @typedef {import("estree").
|
38
|
-
/** @typedef {import("estree").
|
39
|
-
/** @typedef {import("estree").
|
40
|
-
/** @typedef {import("estree").
|
41
|
-
/** @typedef {import("estree").
|
42
|
-
/** @typedef {import("estree").
|
19
|
+
/** @typedef {import("estree").AssignmentExpression} AssignmentExpression */
|
20
|
+
/** @typedef {import("estree").BinaryExpression} BinaryExpression */
|
21
|
+
/** @typedef {import("estree").BlockStatement} BlockStatement */
|
22
|
+
/** @typedef {import("estree").SequenceExpression} SequenceExpression */
|
23
|
+
/** @typedef {import("estree").CallExpression} CallExpression */
|
24
|
+
/** @typedef {import("estree").BaseCallExpression} BaseCallExpression */
|
25
|
+
/** @typedef {import("estree").StaticBlock} StaticBlock */
|
26
|
+
/** @typedef {import("estree").ImportExpression} ImportExpression */
|
27
|
+
/** @typedef {import("estree").ClassDeclaration} ClassDeclaration */
|
28
|
+
/** @typedef {import("estree").ForStatement} ForStatement */
|
29
|
+
/** @typedef {import("estree").SwitchStatement} SwitchStatement */
|
30
|
+
/** @typedef {import("estree").ExportNamedDeclaration} ExportNamedDeclaration */
|
31
|
+
/** @typedef {import("estree").ClassExpression} ClassExpression */
|
32
|
+
/** @typedef {import("estree").Comment} Comment */
|
33
|
+
/** @typedef {import("estree").ConditionalExpression} ConditionalExpression */
|
34
|
+
/** @typedef {import("estree").Declaration} Declaration */
|
35
|
+
/** @typedef {import("estree").PrivateIdentifier} PrivateIdentifier */
|
36
|
+
/** @typedef {import("estree").PropertyDefinition} PropertyDefinition */
|
37
|
+
/** @typedef {import("estree").Expression} Expression */
|
38
|
+
/** @typedef {import("estree").Identifier} Identifier */
|
39
|
+
/** @typedef {import("estree").VariableDeclaration} VariableDeclaration */
|
40
|
+
/** @typedef {import("estree").IfStatement} IfStatement */
|
41
|
+
/** @typedef {import("estree").LabeledStatement} LabeledStatement */
|
42
|
+
/** @typedef {import("estree").Literal} Literal */
|
43
|
+
/** @typedef {import("estree").LogicalExpression} LogicalExpression */
|
44
|
+
/** @typedef {import("estree").ChainExpression} ChainExpression */
|
45
|
+
/** @typedef {import("estree").MemberExpression} MemberExpression */
|
46
|
+
/** @typedef {import("estree").YieldExpression} YieldExpression */
|
47
|
+
/** @typedef {import("estree").MetaProperty} MetaProperty */
|
48
|
+
/** @typedef {import("estree").Property} Property */
|
49
|
+
/** @typedef {import("estree").AssignmentPattern} AssignmentPattern */
|
50
|
+
/** @typedef {import("estree").Pattern} Pattern */
|
51
|
+
/** @typedef {import("estree").UpdateExpression} UpdateExpression */
|
52
|
+
/** @typedef {import("estree").ObjectExpression} ObjectExpression */
|
53
|
+
/** @typedef {import("estree").UnaryExpression} UnaryExpression */
|
54
|
+
/** @typedef {import("estree").ArrayExpression} ArrayExpression */
|
55
|
+
/** @typedef {import("estree").ArrayPattern} ArrayPattern */
|
56
|
+
/** @typedef {import("estree").AwaitExpression} AwaitExpression */
|
57
|
+
/** @typedef {import("estree").ThisExpression} ThisExpression */
|
58
|
+
/** @typedef {import("estree").RestElement} RestElement */
|
59
|
+
/** @typedef {import("estree").ObjectPattern} ObjectPattern */
|
60
|
+
/** @typedef {import("estree").SwitchCase} SwitchCase */
|
61
|
+
/** @typedef {import("estree").CatchClause} CatchClause */
|
62
|
+
/** @typedef {import("estree").VariableDeclarator} VariableDeclarator */
|
63
|
+
/** @typedef {import("estree").ForInStatement} ForInStatement */
|
64
|
+
/** @typedef {import("estree").ForOfStatement} ForOfStatement */
|
65
|
+
/** @typedef {import("estree").ReturnStatement} ReturnStatement */
|
66
|
+
/** @typedef {import("estree").WithStatement} WithStatement */
|
67
|
+
/** @typedef {import("estree").ThrowStatement} ThrowStatement */
|
68
|
+
/** @typedef {import("estree").MethodDefinition} MethodDefinition */
|
69
|
+
/** @typedef {import("estree").ModuleDeclaration} ModuleDeclaration */
|
70
|
+
/** @typedef {import("estree").NewExpression} NewExpression */
|
71
|
+
/** @typedef {import("estree").SpreadElement} SpreadElement */
|
72
|
+
/** @typedef {import("estree").FunctionExpression} FunctionExpression */
|
73
|
+
/** @typedef {import("estree").WhileStatement} WhileStatement */
|
74
|
+
/** @typedef {import("estree").ArrowFunctionExpression} ArrowFunctionExpression */
|
75
|
+
/** @typedef {import("estree").ExpressionStatement} ExpressionStatement */
|
76
|
+
/** @typedef {import("estree").FunctionDeclaration} FunctionDeclaration */
|
77
|
+
/** @typedef {import("estree").DoWhileStatement} DoWhileStatement */
|
78
|
+
/** @typedef {import("estree").TryStatement} TryStatement */
|
43
79
|
/** @typedef {import("estree").Node} AnyNode */
|
44
|
-
/** @typedef {import("estree").Program}
|
45
|
-
/** @typedef {import("estree").
|
46
|
-
/** @typedef {import("estree").
|
47
|
-
/** @typedef {import("estree").
|
48
|
-
/** @typedef {import("estree").ExportDefaultDeclaration}
|
49
|
-
/** @typedef {import("estree").ExportAllDeclaration}
|
50
|
-
/** @typedef {import("estree").Super}
|
51
|
-
/** @typedef {import("estree").TaggedTemplateExpression}
|
52
|
-
/** @typedef {import("estree").TemplateLiteral}
|
53
|
-
/** @typedef {
|
54
|
-
/** @typedef {import("estree").UnaryExpression} UnaryExpressionNode */
|
55
|
-
/** @typedef {import("estree").VariableDeclarator} VariableDeclaratorNode */
|
80
|
+
/** @typedef {import("estree").Program} Program */
|
81
|
+
/** @typedef {import("estree").Directive} Directive */
|
82
|
+
/** @typedef {import("estree").Statement} Statement */
|
83
|
+
/** @typedef {import("estree").ImportDeclaration} ImportDeclaration */
|
84
|
+
/** @typedef {import("estree").ExportDefaultDeclaration} ExportDefaultDeclaration */
|
85
|
+
/** @typedef {import("estree").ExportAllDeclaration} ExportAllDeclaration */
|
86
|
+
/** @typedef {import("estree").Super} Super */
|
87
|
+
/** @typedef {import("estree").TaggedTemplateExpression} TaggedTemplateExpression */
|
88
|
+
/** @typedef {import("estree").TemplateLiteral} TemplateLiteral */
|
89
|
+
/** @typedef {Record<string, any>} Assertions */
|
56
90
|
/** @template T @typedef {import("tapable").AsArray<T>} AsArray<T> */
|
57
91
|
/** @typedef {import("../Parser").ParserState} ParserState */
|
58
92
|
/** @typedef {import("../Parser").PreparsedAst} PreparsedAst */
|
59
93
|
/** @typedef {{declaredScope: ScopeInfo, freeName: string | true, tagInfo: TagInfo | undefined}} VariableInfoInterface */
|
60
|
-
/** @typedef {{ name: string | VariableInfo, rootInfo: string | VariableInfo, getMembers: () => string[], getMembersOptionals: () => boolean[] }} GetInfoResult */
|
94
|
+
/** @typedef {{ name: string | VariableInfo, rootInfo: string | VariableInfo, getMembers: () => string[], getMembersOptionals: () => boolean[], getMemberRangeStarts: () => number[] }} GetInfoResult */
|
61
95
|
|
62
96
|
const EMPTY_ARRAY = [];
|
63
97
|
const ALLOWED_MEMBER_TYPES_CALL_EXPRESSION = 0b01;
|
@@ -82,7 +116,7 @@ class VariableInfo {
|
|
82
116
|
}
|
83
117
|
|
84
118
|
/** @typedef {string | ScopeInfo | VariableInfo} ExportedVariableInfo */
|
85
|
-
/** @typedef {
|
119
|
+
/** @typedef {Literal | string | null | undefined} ImportSource */
|
86
120
|
/** @typedef {Omit<AcornOptions, "sourceType" | "ecmaVersion"> & { sourceType: "module" | "script" | "auto", ecmaVersion?: AcornOptions["ecmaVersion"] }} ParseOptions */
|
87
121
|
|
88
122
|
/**
|
@@ -96,12 +130,14 @@ class VariableInfo {
|
|
96
130
|
* @typedef {Object} ScopeInfo
|
97
131
|
* @property {StackedMap<string, VariableInfo | ScopeInfo>} definitions
|
98
132
|
* @property {boolean | "arrow"} topLevelScope
|
99
|
-
* @property {boolean} inShorthand
|
133
|
+
* @property {boolean | string} inShorthand
|
100
134
|
* @property {boolean} isStrict
|
101
135
|
* @property {boolean} isAsmJs
|
102
136
|
* @property {boolean} inTry
|
103
137
|
*/
|
104
138
|
|
139
|
+
/** @typedef {[number, number]} Range */
|
140
|
+
|
105
141
|
/**
|
106
142
|
* Helper function for joining two ranges into a single range. This is useful
|
107
143
|
* when working with AST nodes, as it allows you to combine the ranges of child nodes
|
@@ -157,7 +193,7 @@ const objectAndMembersToName = (object, membersReversed) => {
|
|
157
193
|
* [MetaProperties](https://github.com/estree/estree/blob/master/es2015.md#metaproperty) which is
|
158
194
|
* specifically for handling the `new.target` meta property.
|
159
195
|
*
|
160
|
-
* @param {
|
196
|
+
* @param {Expression | Super} expression expression
|
161
197
|
* @returns {string | "this" | undefined} name or variable info
|
162
198
|
*/
|
163
199
|
const getRootName = expression => {
|
@@ -199,81 +235,81 @@ class JavascriptParser extends Parser {
|
|
199
235
|
constructor(sourceType = "auto") {
|
200
236
|
super();
|
201
237
|
this.hooks = Object.freeze({
|
202
|
-
/** @type {HookMap<SyncBailHook<[
|
238
|
+
/** @type {HookMap<SyncBailHook<[UnaryExpression], BasicEvaluatedExpression | undefined | null>>} */
|
203
239
|
evaluateTypeof: new HookMap(() => new SyncBailHook(["expression"])),
|
204
|
-
/** @type {HookMap<SyncBailHook<[
|
240
|
+
/** @type {HookMap<SyncBailHook<[Expression], BasicEvaluatedExpression | undefined | null>>} */
|
205
241
|
evaluate: new HookMap(() => new SyncBailHook(["expression"])),
|
206
|
-
/** @type {HookMap<SyncBailHook<[
|
242
|
+
/** @type {HookMap<SyncBailHook<[Identifier | ThisExpression | MemberExpression | MetaProperty], BasicEvaluatedExpression | undefined | null>>} */
|
207
243
|
evaluateIdentifier: new HookMap(() => new SyncBailHook(["expression"])),
|
208
|
-
/** @type {HookMap<SyncBailHook<[
|
244
|
+
/** @type {HookMap<SyncBailHook<[Identifier | ThisExpression | MemberExpression], BasicEvaluatedExpression | undefined | null>>} */
|
209
245
|
evaluateDefinedIdentifier: new HookMap(
|
210
246
|
() => new SyncBailHook(["expression"])
|
211
247
|
),
|
212
|
-
/** @type {HookMap<SyncBailHook<[
|
248
|
+
/** @type {HookMap<SyncBailHook<[NewExpression], BasicEvaluatedExpression | undefined | null>>} */
|
213
249
|
evaluateNewExpression: new HookMap(
|
214
250
|
() => new SyncBailHook(["expression"])
|
215
251
|
),
|
216
|
-
/** @type {HookMap<SyncBailHook<[
|
252
|
+
/** @type {HookMap<SyncBailHook<[CallExpression], BasicEvaluatedExpression | undefined | null>>} */
|
217
253
|
evaluateCallExpression: new HookMap(
|
218
254
|
() => new SyncBailHook(["expression"])
|
219
255
|
),
|
220
|
-
/** @type {HookMap<SyncBailHook<[
|
256
|
+
/** @type {HookMap<SyncBailHook<[CallExpression, BasicEvaluatedExpression | undefined], BasicEvaluatedExpression | undefined | null>>} */
|
221
257
|
evaluateCallExpressionMember: new HookMap(
|
222
258
|
() => new SyncBailHook(["expression", "param"])
|
223
259
|
),
|
224
|
-
/** @type {HookMap<SyncBailHook<[
|
260
|
+
/** @type {HookMap<SyncBailHook<[Expression | Declaration | PrivateIdentifier, number], boolean | void>>} */
|
225
261
|
isPure: new HookMap(
|
226
262
|
() => new SyncBailHook(["expression", "commentsStartPosition"])
|
227
263
|
),
|
228
|
-
/** @type {SyncBailHook<[
|
264
|
+
/** @type {SyncBailHook<[Statement | ModuleDeclaration], boolean | void>} */
|
229
265
|
preStatement: new SyncBailHook(["statement"]),
|
230
266
|
|
231
|
-
/** @type {SyncBailHook<[
|
267
|
+
/** @type {SyncBailHook<[Statement | ModuleDeclaration], boolean | void>} */
|
232
268
|
blockPreStatement: new SyncBailHook(["declaration"]),
|
233
|
-
/** @type {SyncBailHook<[
|
269
|
+
/** @type {SyncBailHook<[Statement | ModuleDeclaration], boolean | void>} */
|
234
270
|
statement: new SyncBailHook(["statement"]),
|
235
|
-
/** @type {SyncBailHook<[
|
271
|
+
/** @type {SyncBailHook<[IfStatement], boolean | void>} */
|
236
272
|
statementIf: new SyncBailHook(["statement"]),
|
237
|
-
/** @type {SyncBailHook<[
|
273
|
+
/** @type {SyncBailHook<[Expression, ClassExpression | ClassDeclaration], boolean | void>} */
|
238
274
|
classExtendsExpression: new SyncBailHook([
|
239
275
|
"expression",
|
240
276
|
"classDefinition"
|
241
277
|
]),
|
242
|
-
/** @type {SyncBailHook<[
|
278
|
+
/** @type {SyncBailHook<[MethodDefinition | PropertyDefinition | StaticBlock, ClassExpression | ClassDeclaration], boolean | void>} */
|
243
279
|
classBodyElement: new SyncBailHook(["element", "classDefinition"]),
|
244
|
-
/** @type {SyncBailHook<[
|
280
|
+
/** @type {SyncBailHook<[Expression, MethodDefinition | PropertyDefinition, ClassExpression | ClassDeclaration], boolean | void>} */
|
245
281
|
classBodyValue: new SyncBailHook([
|
246
282
|
"expression",
|
247
283
|
"element",
|
248
284
|
"classDefinition"
|
249
285
|
]),
|
250
|
-
/** @type {HookMap<SyncBailHook<[
|
286
|
+
/** @type {HookMap<SyncBailHook<[LabeledStatement], boolean | void>>} */
|
251
287
|
label: new HookMap(() => new SyncBailHook(["statement"])),
|
252
|
-
/** @type {SyncBailHook<[
|
288
|
+
/** @type {SyncBailHook<[ImportDeclaration, ImportSource], boolean | void>} */
|
253
289
|
import: new SyncBailHook(["statement", "source"]),
|
254
|
-
/** @type {SyncBailHook<[
|
290
|
+
/** @type {SyncBailHook<[ImportDeclaration, ImportSource, string, string], boolean | void>} */
|
255
291
|
importSpecifier: new SyncBailHook([
|
256
292
|
"statement",
|
257
293
|
"source",
|
258
294
|
"exportName",
|
259
295
|
"identifierName"
|
260
296
|
]),
|
261
|
-
/** @type {SyncBailHook<[
|
297
|
+
/** @type {SyncBailHook<[ExportNamedDeclaration | ExportAllDeclaration], boolean | void>} */
|
262
298
|
export: new SyncBailHook(["statement"]),
|
263
|
-
/** @type {SyncBailHook<[
|
299
|
+
/** @type {SyncBailHook<[ExportNamedDeclaration | ExportAllDeclaration, ImportSource], boolean | void>} */
|
264
300
|
exportImport: new SyncBailHook(["statement", "source"]),
|
265
|
-
/** @type {SyncBailHook<[
|
301
|
+
/** @type {SyncBailHook<[ExportNamedDeclaration | ExportAllDeclaration, Declaration], boolean | void>} */
|
266
302
|
exportDeclaration: new SyncBailHook(["statement", "declaration"]),
|
267
|
-
/** @type {SyncBailHook<[
|
303
|
+
/** @type {SyncBailHook<[ExportDefaultDeclaration, Declaration], boolean | void>} */
|
268
304
|
exportExpression: new SyncBailHook(["statement", "declaration"]),
|
269
|
-
/** @type {SyncBailHook<[
|
305
|
+
/** @type {SyncBailHook<[ExportNamedDeclaration | ExportAllDeclaration, string, string, number | undefined], boolean | void>} */
|
270
306
|
exportSpecifier: new SyncBailHook([
|
271
307
|
"statement",
|
272
308
|
"identifierName",
|
273
309
|
"exportName",
|
274
310
|
"index"
|
275
311
|
]),
|
276
|
-
/** @type {SyncBailHook<[
|
312
|
+
/** @type {SyncBailHook<[ExportNamedDeclaration | ExportAllDeclaration, ImportSource, string, string, number | undefined], boolean | void>} */
|
277
313
|
exportImportSpecifier: new SyncBailHook([
|
278
314
|
"statement",
|
279
315
|
"source",
|
@@ -281,45 +317,51 @@ class JavascriptParser extends Parser {
|
|
281
317
|
"exportName",
|
282
318
|
"index"
|
283
319
|
]),
|
284
|
-
/** @type {SyncBailHook<[
|
320
|
+
/** @type {SyncBailHook<[VariableDeclarator, Statement], boolean | void>} */
|
285
321
|
preDeclarator: new SyncBailHook(["declarator", "statement"]),
|
286
|
-
/** @type {SyncBailHook<[
|
322
|
+
/** @type {SyncBailHook<[VariableDeclarator, Statement], boolean | void>} */
|
287
323
|
declarator: new SyncBailHook(["declarator", "statement"]),
|
288
|
-
/** @type {HookMap<SyncBailHook<[
|
324
|
+
/** @type {HookMap<SyncBailHook<[Declaration], boolean | void>>} */
|
289
325
|
varDeclaration: new HookMap(() => new SyncBailHook(["declaration"])),
|
290
|
-
/** @type {HookMap<SyncBailHook<[
|
326
|
+
/** @type {HookMap<SyncBailHook<[Declaration], boolean | void>>} */
|
291
327
|
varDeclarationLet: new HookMap(() => new SyncBailHook(["declaration"])),
|
292
|
-
/** @type {HookMap<SyncBailHook<[
|
328
|
+
/** @type {HookMap<SyncBailHook<[Declaration], boolean | void>>} */
|
293
329
|
varDeclarationConst: new HookMap(() => new SyncBailHook(["declaration"])),
|
294
|
-
/** @type {HookMap<SyncBailHook<[
|
330
|
+
/** @type {HookMap<SyncBailHook<[Declaration], boolean | void>>} */
|
295
331
|
varDeclarationVar: new HookMap(() => new SyncBailHook(["declaration"])),
|
296
|
-
/** @type {HookMap<SyncBailHook<[
|
332
|
+
/** @type {HookMap<SyncBailHook<[Identifier], boolean | void>>} */
|
297
333
|
pattern: new HookMap(() => new SyncBailHook(["pattern"])),
|
298
|
-
/** @type {HookMap<SyncBailHook<[
|
334
|
+
/** @type {HookMap<SyncBailHook<[Expression], boolean | void>>} */
|
299
335
|
canRename: new HookMap(() => new SyncBailHook(["initExpression"])),
|
300
|
-
/** @type {HookMap<SyncBailHook<[
|
336
|
+
/** @type {HookMap<SyncBailHook<[Expression], boolean | void>>} */
|
301
337
|
rename: new HookMap(() => new SyncBailHook(["initExpression"])),
|
302
|
-
/** @type {HookMap<SyncBailHook<[
|
338
|
+
/** @type {HookMap<SyncBailHook<[AssignmentExpression], boolean | void>>} */
|
303
339
|
assign: new HookMap(() => new SyncBailHook(["expression"])),
|
304
|
-
/** @type {HookMap<SyncBailHook<[
|
340
|
+
/** @type {HookMap<SyncBailHook<[AssignmentExpression, string[]], boolean | void>>} */
|
305
341
|
assignMemberChain: new HookMap(
|
306
342
|
() => new SyncBailHook(["expression", "members"])
|
307
343
|
),
|
308
|
-
/** @type {HookMap<SyncBailHook<[
|
344
|
+
/** @type {HookMap<SyncBailHook<[Expression], boolean | void>>} */
|
309
345
|
typeof: new HookMap(() => new SyncBailHook(["expression"])),
|
310
|
-
/** @type {SyncBailHook<[
|
346
|
+
/** @type {SyncBailHook<[ImportExpression], boolean | void>} */
|
311
347
|
importCall: new SyncBailHook(["expression"]),
|
312
|
-
/** @type {SyncBailHook<[
|
348
|
+
/** @type {SyncBailHook<[Expression], boolean | void>} */
|
313
349
|
topLevelAwait: new SyncBailHook(["expression"]),
|
314
|
-
/** @type {HookMap<SyncBailHook<[
|
350
|
+
/** @type {HookMap<SyncBailHook<[BaseCallExpression], boolean | void>>} */
|
315
351
|
call: new HookMap(() => new SyncBailHook(["expression"])),
|
316
352
|
/** Something like "a.b()" */
|
317
|
-
/** @type {HookMap<SyncBailHook<[
|
353
|
+
/** @type {HookMap<SyncBailHook<[CallExpression, string[], boolean[], number[]], boolean | void>>} */
|
318
354
|
callMemberChain: new HookMap(
|
319
|
-
() =>
|
355
|
+
() =>
|
356
|
+
new SyncBailHook([
|
357
|
+
"expression",
|
358
|
+
"members",
|
359
|
+
"membersOptionals",
|
360
|
+
"memberRangeStarts"
|
361
|
+
])
|
320
362
|
),
|
321
363
|
/** Something like "a.b().c.d" */
|
322
|
-
/** @type {HookMap<SyncBailHook<[
|
364
|
+
/** @type {HookMap<SyncBailHook<[Expression, string[], CallExpression, string[]], boolean | void>>} */
|
323
365
|
memberChainOfCallMemberChain: new HookMap(
|
324
366
|
() =>
|
325
367
|
new SyncBailHook([
|
@@ -330,7 +372,7 @@ class JavascriptParser extends Parser {
|
|
330
372
|
])
|
331
373
|
),
|
332
374
|
/** Something like "a.b().c.d()"" */
|
333
|
-
/** @type {HookMap<SyncBailHook<[
|
375
|
+
/** @type {HookMap<SyncBailHook<[Expression, string[], CallExpression, string[]], boolean | void>>} */
|
334
376
|
callMemberChainOfCallMemberChain: new HookMap(
|
335
377
|
() =>
|
336
378
|
new SyncBailHook([
|
@@ -340,29 +382,35 @@ class JavascriptParser extends Parser {
|
|
340
382
|
"members"
|
341
383
|
])
|
342
384
|
),
|
343
|
-
/** @type {SyncBailHook<[
|
385
|
+
/** @type {SyncBailHook<[ChainExpression], boolean | void>} */
|
344
386
|
optionalChaining: new SyncBailHook(["optionalChaining"]),
|
345
|
-
/** @type {HookMap<SyncBailHook<[
|
387
|
+
/** @type {HookMap<SyncBailHook<[NewExpression], boolean | void>>} */
|
346
388
|
new: new HookMap(() => new SyncBailHook(["expression"])),
|
347
|
-
/** @type {SyncBailHook<[
|
389
|
+
/** @type {SyncBailHook<[BinaryExpression], boolean | void>} */
|
348
390
|
binaryExpression: new SyncBailHook(["binaryExpression"]),
|
349
|
-
/** @type {HookMap<SyncBailHook<[
|
391
|
+
/** @type {HookMap<SyncBailHook<[Expression], boolean | void>>} */
|
350
392
|
expression: new HookMap(() => new SyncBailHook(["expression"])),
|
351
|
-
/** @type {HookMap<SyncBailHook<[
|
393
|
+
/** @type {HookMap<SyncBailHook<[Expression, string[], boolean[], number[]], boolean | void>>} */
|
352
394
|
expressionMemberChain: new HookMap(
|
353
|
-
() =>
|
395
|
+
() =>
|
396
|
+
new SyncBailHook([
|
397
|
+
"expression",
|
398
|
+
"members",
|
399
|
+
"membersOptionals",
|
400
|
+
"memberRangeStarts"
|
401
|
+
])
|
354
402
|
),
|
355
|
-
/** @type {HookMap<SyncBailHook<[
|
403
|
+
/** @type {HookMap<SyncBailHook<[Expression, string[]], boolean | void>>} */
|
356
404
|
unhandledExpressionMemberChain: new HookMap(
|
357
405
|
() => new SyncBailHook(["expression", "members"])
|
358
406
|
),
|
359
|
-
/** @type {SyncBailHook<[
|
407
|
+
/** @type {SyncBailHook<[Expression], boolean | void>} */
|
360
408
|
expressionConditionalOperator: new SyncBailHook(["expression"]),
|
361
|
-
/** @type {SyncBailHook<[
|
409
|
+
/** @type {SyncBailHook<[Expression], boolean | void>} */
|
362
410
|
expressionLogicalOperator: new SyncBailHook(["expression"]),
|
363
|
-
/** @type {SyncBailHook<[
|
411
|
+
/** @type {SyncBailHook<[Program, Comment[]], boolean | void>} */
|
364
412
|
program: new SyncBailHook(["ast", "comments"]),
|
365
|
-
/** @type {SyncBailHook<[
|
413
|
+
/** @type {SyncBailHook<[Program, Comment[]], boolean | void>} */
|
366
414
|
finish: new SyncBailHook(["ast", "comments"])
|
367
415
|
});
|
368
416
|
this.sourceType = sourceType;
|
@@ -372,10 +420,11 @@ class JavascriptParser extends Parser {
|
|
372
420
|
this.state = undefined;
|
373
421
|
this.comments = undefined;
|
374
422
|
this.semicolons = undefined;
|
375
|
-
/** @type {(
|
423
|
+
/** @type {(Statement | ModuleDeclaration | Expression)[]} */
|
376
424
|
this.statementPath = undefined;
|
425
|
+
/** @type {Statement | ModuleDeclaration | Expression} */
|
377
426
|
this.prevStatement = undefined;
|
378
|
-
/** @type {WeakMap<
|
427
|
+
/** @type {WeakMap<Expression, Set<string>>} */
|
379
428
|
this.destructuringAssignmentProperties = undefined;
|
380
429
|
this.currentTagData = undefined;
|
381
430
|
this._initializeEvaluating();
|
@@ -383,7 +432,7 @@ class JavascriptParser extends Parser {
|
|
383
432
|
|
384
433
|
_initializeEvaluating() {
|
385
434
|
this.hooks.evaluate.for("Literal").tap("JavascriptParser", _expr => {
|
386
|
-
const expr = /** @type {
|
435
|
+
const expr = /** @type {Literal} */ (_expr);
|
387
436
|
|
388
437
|
switch (typeof expr.value) {
|
389
438
|
case "number":
|
@@ -413,7 +462,7 @@ class JavascriptParser extends Parser {
|
|
413
462
|
}
|
414
463
|
});
|
415
464
|
this.hooks.evaluate.for("NewExpression").tap("JavascriptParser", _expr => {
|
416
|
-
const expr = /** @type {
|
465
|
+
const expr = /** @type {NewExpression} */ (_expr);
|
417
466
|
const callee = expr.callee;
|
418
467
|
if (callee.type !== "Identifier") return;
|
419
468
|
if (callee.name !== "RegExp") {
|
@@ -474,7 +523,7 @@ class JavascriptParser extends Parser {
|
|
474
523
|
this.hooks.evaluate
|
475
524
|
.for("LogicalExpression")
|
476
525
|
.tap("JavascriptParser", _expr => {
|
477
|
-
const expr = /** @type {
|
526
|
+
const expr = /** @type {LogicalExpression} */ (_expr);
|
478
527
|
|
479
528
|
const left = this.evaluateExpression(expr.left);
|
480
529
|
let returnRight = false;
|
@@ -533,13 +582,13 @@ class JavascriptParser extends Parser {
|
|
533
582
|
* import("./" + foo + bar); // webpack will auto evaluate this into import("./foobar")
|
534
583
|
* ```
|
535
584
|
* @param {boolean | number | BigInt | string} value the value to convert to an expression
|
536
|
-
* @param {
|
585
|
+
* @param {BinaryExpression | UnaryExpression} expr the expression being evaluated
|
537
586
|
* @param {boolean} sideEffects whether the expression has side effects
|
538
587
|
* @returns {BasicEvaluatedExpression} the evaluated expression
|
539
588
|
* @example
|
540
589
|
*
|
541
590
|
* ```js
|
542
|
-
* const binaryExpr = new
|
591
|
+
* const binaryExpr = new BinaryExpression("+",
|
543
592
|
* { type: "Literal", value: 2 },
|
544
593
|
* { type: "Literal", value: 3 }
|
545
594
|
* );
|
@@ -584,7 +633,7 @@ class JavascriptParser extends Parser {
|
|
584
633
|
this.hooks.evaluate
|
585
634
|
.for("BinaryExpression")
|
586
635
|
.tap("JavascriptParser", _expr => {
|
587
|
-
const expr = /** @type {
|
636
|
+
const expr = /** @type {BinaryExpression} */ (_expr);
|
588
637
|
|
589
638
|
/**
|
590
639
|
* Evaluates a binary expression if and only if it is a const operation (e.g. 1 + 2, "a" + "b", etc.).
|
@@ -935,7 +984,7 @@ class JavascriptParser extends Parser {
|
|
935
984
|
this.hooks.evaluate
|
936
985
|
.for("UnaryExpression")
|
937
986
|
.tap("JavascriptParser", _expr => {
|
938
|
-
const expr = /** @type {
|
987
|
+
const expr = /** @type {UnaryExpression} */ (_expr);
|
939
988
|
|
940
989
|
/**
|
941
990
|
* Evaluates a UnaryExpression if and only if it is a basic const operator (e.g. +a, -a, ~a).
|
@@ -1065,7 +1114,7 @@ class JavascriptParser extends Parser {
|
|
1065
1114
|
.setRange(expr.range);
|
1066
1115
|
});
|
1067
1116
|
this.hooks.evaluate.for("Identifier").tap("JavascriptParser", expr => {
|
1068
|
-
if (/** @type {
|
1117
|
+
if (/** @type {Identifier} */ (expr).name === "undefined") {
|
1069
1118
|
return new BasicEvaluatedExpression()
|
1070
1119
|
.setUndefined()
|
1071
1120
|
.setRange(expr.range);
|
@@ -1073,16 +1122,16 @@ class JavascriptParser extends Parser {
|
|
1073
1122
|
});
|
1074
1123
|
/**
|
1075
1124
|
* @param {string} exprType expression type name
|
1076
|
-
* @param {function(
|
1125
|
+
* @param {function(Expression): GetInfoResult | undefined} getInfo get info
|
1077
1126
|
* @returns {void}
|
1078
1127
|
*/
|
1079
1128
|
const tapEvaluateWithVariableInfo = (exprType, getInfo) => {
|
1080
|
-
/** @type {
|
1129
|
+
/** @type {Expression | undefined} */
|
1081
1130
|
let cachedExpression = undefined;
|
1082
1131
|
/** @type {GetInfoResult | undefined} */
|
1083
1132
|
let cachedInfo = undefined;
|
1084
1133
|
this.hooks.evaluate.for(exprType).tap("JavascriptParser", expr => {
|
1085
|
-
const expression = /** @type {
|
1134
|
+
const expression = /** @type {MemberExpression} */ (expr);
|
1086
1135
|
|
1087
1136
|
const info = getInfo(expr);
|
1088
1137
|
if (info !== undefined) {
|
@@ -1113,7 +1162,8 @@ class JavascriptParser extends Parser {
|
|
1113
1162
|
info.name,
|
1114
1163
|
info.rootInfo,
|
1115
1164
|
info.getMembers,
|
1116
|
-
info.getMembersOptionals
|
1165
|
+
info.getMembersOptionals,
|
1166
|
+
info.getMemberRangeStarts
|
1117
1167
|
)
|
1118
1168
|
.setRange(expr.range);
|
1119
1169
|
}
|
@@ -1124,9 +1174,7 @@ class JavascriptParser extends Parser {
|
|
1124
1174
|
});
|
1125
1175
|
};
|
1126
1176
|
tapEvaluateWithVariableInfo("Identifier", expr => {
|
1127
|
-
const info = this.getVariableInfo(
|
1128
|
-
/** @type {IdentifierNode} */ (expr).name
|
1129
|
-
);
|
1177
|
+
const info = this.getVariableInfo(/** @type {Identifier} */ (expr).name);
|
1130
1178
|
if (
|
1131
1179
|
typeof info === "string" ||
|
1132
1180
|
(info instanceof VariableInfo && typeof info.freeName === "string")
|
@@ -1135,7 +1183,8 @@ class JavascriptParser extends Parser {
|
|
1135
1183
|
name: info,
|
1136
1184
|
rootInfo: info,
|
1137
1185
|
getMembers: () => [],
|
1138
|
-
getMembersOptionals: () => []
|
1186
|
+
getMembersOptionals: () => [],
|
1187
|
+
getMemberRangeStarts: () => []
|
1139
1188
|
};
|
1140
1189
|
}
|
1141
1190
|
});
|
@@ -1149,12 +1198,13 @@ class JavascriptParser extends Parser {
|
|
1149
1198
|
name: info,
|
1150
1199
|
rootInfo: info,
|
1151
1200
|
getMembers: () => [],
|
1152
|
-
getMembersOptionals: () => []
|
1201
|
+
getMembersOptionals: () => [],
|
1202
|
+
getMemberRangeStarts: () => []
|
1153
1203
|
};
|
1154
1204
|
}
|
1155
1205
|
});
|
1156
1206
|
this.hooks.evaluate.for("MetaProperty").tap("JavascriptParser", expr => {
|
1157
|
-
const metaProperty = /** @type {
|
1207
|
+
const metaProperty = /** @type {MetaProperty} */ (expr);
|
1158
1208
|
|
1159
1209
|
return this.callHooksForName(
|
1160
1210
|
this.hooks.evaluateIdentifier,
|
@@ -1164,13 +1214,13 @@ class JavascriptParser extends Parser {
|
|
1164
1214
|
});
|
1165
1215
|
tapEvaluateWithVariableInfo("MemberExpression", expr =>
|
1166
1216
|
this.getMemberExpressionInfo(
|
1167
|
-
/** @type {
|
1217
|
+
/** @type {MemberExpression} */ (expr),
|
1168
1218
|
ALLOWED_MEMBER_TYPES_EXPRESSION
|
1169
1219
|
)
|
1170
1220
|
);
|
1171
1221
|
|
1172
1222
|
this.hooks.evaluate.for("CallExpression").tap("JavascriptParser", _expr => {
|
1173
|
-
const expr = /** @type {
|
1223
|
+
const expr = /** @type {CallExpression} */ (_expr);
|
1174
1224
|
if (
|
1175
1225
|
expr.callee.type === "MemberExpression" &&
|
1176
1226
|
expr.callee.property.type ===
|
@@ -1178,7 +1228,7 @@ class JavascriptParser extends Parser {
|
|
1178
1228
|
) {
|
1179
1229
|
// type Super also possible here
|
1180
1230
|
const param = this.evaluateExpression(
|
1181
|
-
/** @type {
|
1231
|
+
/** @type {Expression} */ (expr.callee.object)
|
1182
1232
|
);
|
1183
1233
|
const property =
|
1184
1234
|
expr.callee.property.type === "Literal"
|
@@ -1276,7 +1326,7 @@ class JavascriptParser extends Parser {
|
|
1276
1326
|
|
1277
1327
|
/**
|
1278
1328
|
* @param {"cooked" | "raw"} kind kind of values to get
|
1279
|
-
* @param {
|
1329
|
+
* @param {TemplateLiteral} templateLiteralExpr TemplateLiteral expr
|
1280
1330
|
* @returns {{quasis: BasicEvaluatedExpression[], parts: BasicEvaluatedExpression[]}} Simplified template
|
1281
1331
|
*/
|
1282
1332
|
const getSimplifiedTemplateResult = (kind, templateLiteralExpr) => {
|
@@ -1327,7 +1377,7 @@ class JavascriptParser extends Parser {
|
|
1327
1377
|
this.hooks.evaluate
|
1328
1378
|
.for("TemplateLiteral")
|
1329
1379
|
.tap("JavascriptParser", _node => {
|
1330
|
-
const node = /** @type {
|
1380
|
+
const node = /** @type {TemplateLiteral} */ (_node);
|
1331
1381
|
|
1332
1382
|
const { quasis, parts } = getSimplifiedTemplateResult("cooked", node);
|
1333
1383
|
if (parts.length === 1) {
|
@@ -1340,7 +1390,7 @@ class JavascriptParser extends Parser {
|
|
1340
1390
|
this.hooks.evaluate
|
1341
1391
|
.for("TaggedTemplateExpression")
|
1342
1392
|
.tap("JavascriptParser", _node => {
|
1343
|
-
const node = /** @type {
|
1393
|
+
const node = /** @type {TaggedTemplateExpression} */ (_node);
|
1344
1394
|
const tag = this.evaluateExpression(node.tag);
|
1345
1395
|
|
1346
1396
|
if (tag.isIdentifier() && tag.identifier === "String.raw") {
|
@@ -1380,7 +1430,7 @@ class JavascriptParser extends Parser {
|
|
1380
1430
|
: "" + argExpr.number;
|
1381
1431
|
|
1382
1432
|
const newString = value + (stringSuffix ? stringSuffix.string : "");
|
1383
|
-
const newRange = /** @type {
|
1433
|
+
const newRange = /** @type {Range} */ ([
|
1384
1434
|
argExpr.range[0],
|
1385
1435
|
(stringSuffix || argExpr).range[1]
|
1386
1436
|
]);
|
@@ -1445,7 +1495,7 @@ class JavascriptParser extends Parser {
|
|
1445
1495
|
this.hooks.evaluate
|
1446
1496
|
.for("ConditionalExpression")
|
1447
1497
|
.tap("JavascriptParser", _expr => {
|
1448
|
-
const expr = /** @type {
|
1498
|
+
const expr = /** @type {ConditionalExpression} */ (_expr);
|
1449
1499
|
|
1450
1500
|
const condition = this.evaluateExpression(expr.test);
|
1451
1501
|
const conditionValue = condition.asBool();
|
@@ -1476,7 +1526,7 @@ class JavascriptParser extends Parser {
|
|
1476
1526
|
this.hooks.evaluate
|
1477
1527
|
.for("ArrayExpression")
|
1478
1528
|
.tap("JavascriptParser", _expr => {
|
1479
|
-
const expr = /** @type {
|
1529
|
+
const expr = /** @type {ArrayExpression} */ (_expr);
|
1480
1530
|
|
1481
1531
|
const items = expr.elements.map(element => {
|
1482
1532
|
return (
|
@@ -1493,10 +1543,10 @@ class JavascriptParser extends Parser {
|
|
1493
1543
|
this.hooks.evaluate
|
1494
1544
|
.for("ChainExpression")
|
1495
1545
|
.tap("JavascriptParser", _expr => {
|
1496
|
-
const expr = /** @type {
|
1497
|
-
/** @type {
|
1546
|
+
const expr = /** @type {ChainExpression} */ (_expr);
|
1547
|
+
/** @type {Expression[]} */
|
1498
1548
|
const optionalExpressionsStack = [];
|
1499
|
-
/** @type {
|
1549
|
+
/** @type {Expression|Super} */
|
1500
1550
|
let next = expr.expression;
|
1501
1551
|
|
1502
1552
|
while (
|
@@ -1507,7 +1557,7 @@ class JavascriptParser extends Parser {
|
|
1507
1557
|
if (next.optional) {
|
1508
1558
|
// SuperNode can not be optional
|
1509
1559
|
optionalExpressionsStack.push(
|
1510
|
-
/** @type {
|
1560
|
+
/** @type {Expression} */ (next.object)
|
1511
1561
|
);
|
1512
1562
|
}
|
1513
1563
|
next = next.object;
|
@@ -1515,7 +1565,7 @@ class JavascriptParser extends Parser {
|
|
1515
1565
|
if (next.optional) {
|
1516
1566
|
// SuperNode can not be optional
|
1517
1567
|
optionalExpressionsStack.push(
|
1518
|
-
/** @type {
|
1568
|
+
/** @type {Expression} */ (next.callee)
|
1519
1569
|
);
|
1520
1570
|
}
|
1521
1571
|
next = next.callee;
|
@@ -1535,7 +1585,7 @@ class JavascriptParser extends Parser {
|
|
1535
1585
|
}
|
1536
1586
|
|
1537
1587
|
/**
|
1538
|
-
* @param {
|
1588
|
+
* @param {Expression} node node
|
1539
1589
|
* @returns {Set<string>|undefined} destructured identifiers
|
1540
1590
|
*/
|
1541
1591
|
destructuringAssignmentPropertiesFor(node) {
|
@@ -1543,6 +1593,10 @@ class JavascriptParser extends Parser {
|
|
1543
1593
|
return this.destructuringAssignmentProperties.get(node);
|
1544
1594
|
}
|
1545
1595
|
|
1596
|
+
/**
|
1597
|
+
* @param {Expression} expr expression
|
1598
|
+
* @returns {string | VariableInfoInterface | undefined} identifier
|
1599
|
+
*/
|
1546
1600
|
getRenameIdentifier(expr) {
|
1547
1601
|
const result = this.evaluateExpression(expr);
|
1548
1602
|
if (result.isIdentifier()) {
|
@@ -1551,7 +1605,7 @@ class JavascriptParser extends Parser {
|
|
1551
1605
|
}
|
1552
1606
|
|
1553
1607
|
/**
|
1554
|
-
* @param {
|
1608
|
+
* @param {ClassExpression | ClassDeclaration} classy a class node
|
1555
1609
|
* @returns {void}
|
1556
1610
|
*/
|
1557
1611
|
walkClass(classy) {
|
@@ -1561,36 +1615,47 @@ class JavascriptParser extends Parser {
|
|
1561
1615
|
}
|
1562
1616
|
}
|
1563
1617
|
if (classy.body && classy.body.type === "ClassBody") {
|
1564
|
-
|
1565
|
-
|
1566
|
-
|
1567
|
-
|
1568
|
-
|
1569
|
-
|
1570
|
-
|
1571
|
-
|
1572
|
-
|
1573
|
-
|
1574
|
-
|
1575
|
-
|
1576
|
-
|
1618
|
+
const scopeParams = [];
|
1619
|
+
// Add class name in scope for recursive calls
|
1620
|
+
if (classy.id) {
|
1621
|
+
scopeParams.push(classy.id);
|
1622
|
+
}
|
1623
|
+
this.inClassScope(true, scopeParams, () => {
|
1624
|
+
for (const classElement of /** @type {TODO} */ (classy.body.body)) {
|
1625
|
+
if (!this.hooks.classBodyElement.call(classElement, classy)) {
|
1626
|
+
if (classElement.computed && classElement.key) {
|
1627
|
+
this.walkExpression(classElement.key);
|
1628
|
+
}
|
1629
|
+
if (classElement.value) {
|
1630
|
+
if (
|
1631
|
+
!this.hooks.classBodyValue.call(
|
1632
|
+
classElement.value,
|
1633
|
+
classElement,
|
1634
|
+
classy
|
1635
|
+
)
|
1636
|
+
) {
|
1637
|
+
const wasTopLevel = this.scope.topLevelScope;
|
1638
|
+
this.scope.topLevelScope = false;
|
1639
|
+
this.walkExpression(classElement.value);
|
1640
|
+
this.scope.topLevelScope = wasTopLevel;
|
1641
|
+
}
|
1642
|
+
} else if (classElement.type === "StaticBlock") {
|
1577
1643
|
const wasTopLevel = this.scope.topLevelScope;
|
1578
1644
|
this.scope.topLevelScope = false;
|
1579
|
-
this.
|
1645
|
+
this.walkBlockStatement(classElement);
|
1580
1646
|
this.scope.topLevelScope = wasTopLevel;
|
1581
1647
|
}
|
1582
|
-
} else if (classElement.type === "StaticBlock") {
|
1583
|
-
const wasTopLevel = this.scope.topLevelScope;
|
1584
|
-
this.scope.topLevelScope = false;
|
1585
|
-
this.walkBlockStatement(classElement);
|
1586
|
-
this.scope.topLevelScope = wasTopLevel;
|
1587
1648
|
}
|
1588
1649
|
}
|
1589
|
-
}
|
1650
|
+
});
|
1590
1651
|
}
|
1591
1652
|
}
|
1592
1653
|
|
1593
|
-
|
1654
|
+
/**
|
1655
|
+
* Pre walking iterates the scope for variable declarations
|
1656
|
+
*
|
1657
|
+
* @param {(Statement | ModuleDeclaration)[]} statements statements
|
1658
|
+
*/
|
1594
1659
|
preWalkStatements(statements) {
|
1595
1660
|
for (let index = 0, len = statements.length; index < len; index++) {
|
1596
1661
|
const statement = statements[index];
|
@@ -1598,7 +1663,11 @@ class JavascriptParser extends Parser {
|
|
1598
1663
|
}
|
1599
1664
|
}
|
1600
1665
|
|
1601
|
-
|
1666
|
+
/**
|
1667
|
+
* Block pre walking iterates the scope for block variable declarations
|
1668
|
+
*
|
1669
|
+
* @param {(Statement | ModuleDeclaration)[]} statements statements
|
1670
|
+
*/
|
1602
1671
|
blockPreWalkStatements(statements) {
|
1603
1672
|
for (let index = 0, len = statements.length; index < len; index++) {
|
1604
1673
|
const statement = statements[index];
|
@@ -1606,7 +1675,11 @@ class JavascriptParser extends Parser {
|
|
1606
1675
|
}
|
1607
1676
|
}
|
1608
1677
|
|
1609
|
-
|
1678
|
+
/**
|
1679
|
+
* Walking iterates the statements and expressions and processes them
|
1680
|
+
*
|
1681
|
+
* @param {(Statement | ModuleDeclaration)[]} statements statements
|
1682
|
+
*/
|
1610
1683
|
walkStatements(statements) {
|
1611
1684
|
for (let index = 0, len = statements.length; index < len; index++) {
|
1612
1685
|
const statement = statements[index];
|
@@ -1614,6 +1687,11 @@ class JavascriptParser extends Parser {
|
|
1614
1687
|
}
|
1615
1688
|
}
|
1616
1689
|
|
1690
|
+
/**
|
1691
|
+
* Walking iterates the statements and expressions and processes them
|
1692
|
+
*
|
1693
|
+
* @param {Statement | ModuleDeclaration} statement statement
|
1694
|
+
*/
|
1617
1695
|
preWalkStatement(statement) {
|
1618
1696
|
this.statementPath.push(statement);
|
1619
1697
|
if (this.hooks.preStatement.call(statement)) {
|
@@ -1664,6 +1742,9 @@ class JavascriptParser extends Parser {
|
|
1664
1742
|
this.prevStatement = this.statementPath.pop();
|
1665
1743
|
}
|
1666
1744
|
|
1745
|
+
/**
|
1746
|
+
* @param {Statement | ModuleDeclaration} statement statement
|
1747
|
+
*/
|
1667
1748
|
blockPreWalkStatement(statement) {
|
1668
1749
|
this.statementPath.push(statement);
|
1669
1750
|
if (this.hooks.blockPreStatement.call(statement)) {
|
@@ -1695,6 +1776,9 @@ class JavascriptParser extends Parser {
|
|
1695
1776
|
this.prevStatement = this.statementPath.pop();
|
1696
1777
|
}
|
1697
1778
|
|
1779
|
+
/**
|
1780
|
+
* @param {Statement | ModuleDeclaration} statement statement
|
1781
|
+
*/
|
1698
1782
|
walkStatement(statement) {
|
1699
1783
|
this.statementPath.push(statement);
|
1700
1784
|
if (this.hooks.statement.call(statement) !== undefined) {
|
@@ -1767,8 +1851,8 @@ class JavascriptParser extends Parser {
|
|
1767
1851
|
* Walks a statements that is nested within a parent statement
|
1768
1852
|
* and can potentially be a non-block statement.
|
1769
1853
|
* This enforces the nested statement to never be in ASI position.
|
1770
|
-
*
|
1771
|
-
* @
|
1854
|
+
*
|
1855
|
+
* @param {Statement} statement the nested statement
|
1772
1856
|
*/
|
1773
1857
|
walkNestedStatement(statement) {
|
1774
1858
|
this.prevStatement = undefined;
|
@@ -1776,10 +1860,16 @@ class JavascriptParser extends Parser {
|
|
1776
1860
|
}
|
1777
1861
|
|
1778
1862
|
// Real Statements
|
1863
|
+
/**
|
1864
|
+
* @param {BlockStatement} statement block statement
|
1865
|
+
*/
|
1779
1866
|
preWalkBlockStatement(statement) {
|
1780
1867
|
this.preWalkStatements(statement.body);
|
1781
1868
|
}
|
1782
1869
|
|
1870
|
+
/**
|
1871
|
+
* @param {BlockStatement} statement block statement
|
1872
|
+
*/
|
1783
1873
|
walkBlockStatement(statement) {
|
1784
1874
|
this.inBlockScope(() => {
|
1785
1875
|
const body = statement.body;
|
@@ -1790,10 +1880,16 @@ class JavascriptParser extends Parser {
|
|
1790
1880
|
});
|
1791
1881
|
}
|
1792
1882
|
|
1883
|
+
/**
|
1884
|
+
* @param {ExpressionStatement} statement expression statement
|
1885
|
+
*/
|
1793
1886
|
walkExpressionStatement(statement) {
|
1794
1887
|
this.walkExpression(statement.expression);
|
1795
1888
|
}
|
1796
1889
|
|
1890
|
+
/**
|
1891
|
+
* @param {IfStatement} statement if statement
|
1892
|
+
*/
|
1797
1893
|
preWalkIfStatement(statement) {
|
1798
1894
|
this.preWalkStatement(statement.consequent);
|
1799
1895
|
if (statement.alternate) {
|
@@ -1801,6 +1897,9 @@ class JavascriptParser extends Parser {
|
|
1801
1897
|
}
|
1802
1898
|
}
|
1803
1899
|
|
1900
|
+
/**
|
1901
|
+
* @param {IfStatement} statement if statement
|
1902
|
+
*/
|
1804
1903
|
walkIfStatement(statement) {
|
1805
1904
|
const result = this.hooks.statementIf.call(statement);
|
1806
1905
|
if (result === undefined) {
|
@@ -1818,10 +1917,16 @@ class JavascriptParser extends Parser {
|
|
1818
1917
|
}
|
1819
1918
|
}
|
1820
1919
|
|
1920
|
+
/**
|
1921
|
+
* @param {LabeledStatement} statement with statement
|
1922
|
+
*/
|
1821
1923
|
preWalkLabeledStatement(statement) {
|
1822
1924
|
this.preWalkStatement(statement.body);
|
1823
1925
|
}
|
1824
1926
|
|
1927
|
+
/**
|
1928
|
+
* @param {LabeledStatement} statement with statement
|
1929
|
+
*/
|
1825
1930
|
walkLabeledStatement(statement) {
|
1826
1931
|
const hook = this.hooks.label.get(statement.label.name);
|
1827
1932
|
if (hook !== undefined) {
|
@@ -1831,42 +1936,69 @@ class JavascriptParser extends Parser {
|
|
1831
1936
|
this.walkNestedStatement(statement.body);
|
1832
1937
|
}
|
1833
1938
|
|
1939
|
+
/**
|
1940
|
+
* @param {WithStatement} statement with statement
|
1941
|
+
*/
|
1834
1942
|
preWalkWithStatement(statement) {
|
1835
1943
|
this.preWalkStatement(statement.body);
|
1836
1944
|
}
|
1837
1945
|
|
1946
|
+
/**
|
1947
|
+
* @param {WithStatement} statement with statement
|
1948
|
+
*/
|
1838
1949
|
walkWithStatement(statement) {
|
1839
1950
|
this.walkExpression(statement.object);
|
1840
1951
|
this.walkNestedStatement(statement.body);
|
1841
1952
|
}
|
1842
1953
|
|
1954
|
+
/**
|
1955
|
+
* @param {SwitchStatement} statement switch statement
|
1956
|
+
*/
|
1843
1957
|
preWalkSwitchStatement(statement) {
|
1844
1958
|
this.preWalkSwitchCases(statement.cases);
|
1845
1959
|
}
|
1846
1960
|
|
1961
|
+
/**
|
1962
|
+
* @param {SwitchStatement} statement switch statement
|
1963
|
+
*/
|
1847
1964
|
walkSwitchStatement(statement) {
|
1848
1965
|
this.walkExpression(statement.discriminant);
|
1849
1966
|
this.walkSwitchCases(statement.cases);
|
1850
1967
|
}
|
1851
1968
|
|
1969
|
+
/**
|
1970
|
+
* @param {ReturnStatement | ThrowStatement} statement return or throw statement
|
1971
|
+
*/
|
1852
1972
|
walkTerminatingStatement(statement) {
|
1853
1973
|
if (statement.argument) this.walkExpression(statement.argument);
|
1854
1974
|
}
|
1855
1975
|
|
1976
|
+
/**
|
1977
|
+
* @param {ReturnStatement} statement return statement
|
1978
|
+
*/
|
1856
1979
|
walkReturnStatement(statement) {
|
1857
1980
|
this.walkTerminatingStatement(statement);
|
1858
1981
|
}
|
1859
1982
|
|
1983
|
+
/**
|
1984
|
+
* @param {ThrowStatement} statement return statement
|
1985
|
+
*/
|
1860
1986
|
walkThrowStatement(statement) {
|
1861
1987
|
this.walkTerminatingStatement(statement);
|
1862
1988
|
}
|
1863
1989
|
|
1990
|
+
/**
|
1991
|
+
* @param {TryStatement} statement try statement
|
1992
|
+
*/
|
1864
1993
|
preWalkTryStatement(statement) {
|
1865
1994
|
this.preWalkStatement(statement.block);
|
1866
1995
|
if (statement.handler) this.preWalkCatchClause(statement.handler);
|
1867
1996
|
if (statement.finalizer) this.preWalkStatement(statement.finalizer);
|
1868
1997
|
}
|
1869
1998
|
|
1999
|
+
/**
|
2000
|
+
* @param {TryStatement} statement try statement
|
2001
|
+
*/
|
1870
2002
|
walkTryStatement(statement) {
|
1871
2003
|
if (this.scope.inTry) {
|
1872
2004
|
this.walkStatement(statement.block);
|
@@ -1879,24 +2011,39 @@ class JavascriptParser extends Parser {
|
|
1879
2011
|
if (statement.finalizer) this.walkStatement(statement.finalizer);
|
1880
2012
|
}
|
1881
2013
|
|
2014
|
+
/**
|
2015
|
+
* @param {WhileStatement} statement while statement
|
2016
|
+
*/
|
1882
2017
|
preWalkWhileStatement(statement) {
|
1883
2018
|
this.preWalkStatement(statement.body);
|
1884
2019
|
}
|
1885
2020
|
|
2021
|
+
/**
|
2022
|
+
* @param {WhileStatement} statement while statement
|
2023
|
+
*/
|
1886
2024
|
walkWhileStatement(statement) {
|
1887
2025
|
this.walkExpression(statement.test);
|
1888
2026
|
this.walkNestedStatement(statement.body);
|
1889
2027
|
}
|
1890
2028
|
|
2029
|
+
/**
|
2030
|
+
* @param {DoWhileStatement} statement do while statement
|
2031
|
+
*/
|
1891
2032
|
preWalkDoWhileStatement(statement) {
|
1892
2033
|
this.preWalkStatement(statement.body);
|
1893
2034
|
}
|
1894
2035
|
|
2036
|
+
/**
|
2037
|
+
* @param {DoWhileStatement} statement do while statement
|
2038
|
+
*/
|
1895
2039
|
walkDoWhileStatement(statement) {
|
1896
2040
|
this.walkNestedStatement(statement.body);
|
1897
2041
|
this.walkExpression(statement.test);
|
1898
2042
|
}
|
1899
2043
|
|
2044
|
+
/**
|
2045
|
+
* @param {ForStatement} statement for statement
|
2046
|
+
*/
|
1900
2047
|
preWalkForStatement(statement) {
|
1901
2048
|
if (statement.init) {
|
1902
2049
|
if (statement.init.type === "VariableDeclaration") {
|
@@ -1906,6 +2053,9 @@ class JavascriptParser extends Parser {
|
|
1906
2053
|
this.preWalkStatement(statement.body);
|
1907
2054
|
}
|
1908
2055
|
|
2056
|
+
/**
|
2057
|
+
* @param {ForStatement} statement for statement
|
2058
|
+
*/
|
1909
2059
|
walkForStatement(statement) {
|
1910
2060
|
this.inBlockScope(() => {
|
1911
2061
|
if (statement.init) {
|
@@ -1936,6 +2086,9 @@ class JavascriptParser extends Parser {
|
|
1936
2086
|
});
|
1937
2087
|
}
|
1938
2088
|
|
2089
|
+
/**
|
2090
|
+
* @param {ForInStatement} statement for statement
|
2091
|
+
*/
|
1939
2092
|
preWalkForInStatement(statement) {
|
1940
2093
|
if (statement.left.type === "VariableDeclaration") {
|
1941
2094
|
this.preWalkVariableDeclaration(statement.left);
|
@@ -1943,6 +2096,9 @@ class JavascriptParser extends Parser {
|
|
1943
2096
|
this.preWalkStatement(statement.body);
|
1944
2097
|
}
|
1945
2098
|
|
2099
|
+
/**
|
2100
|
+
* @param {ForInStatement} statement for statement
|
2101
|
+
*/
|
1946
2102
|
walkForInStatement(statement) {
|
1947
2103
|
this.inBlockScope(() => {
|
1948
2104
|
if (statement.left.type === "VariableDeclaration") {
|
@@ -1975,6 +2131,9 @@ class JavascriptParser extends Parser {
|
|
1975
2131
|
this.preWalkStatement(statement.body);
|
1976
2132
|
}
|
1977
2133
|
|
2134
|
+
/**
|
2135
|
+
* @param {ForOfStatement} statement for statement
|
2136
|
+
*/
|
1978
2137
|
walkForOfStatement(statement) {
|
1979
2138
|
this.inBlockScope(() => {
|
1980
2139
|
if (statement.left.type === "VariableDeclaration") {
|
@@ -1997,13 +2156,18 @@ class JavascriptParser extends Parser {
|
|
1997
2156
|
});
|
1998
2157
|
}
|
1999
2158
|
|
2000
|
-
|
2159
|
+
/**
|
2160
|
+
* @param {FunctionDeclaration} statement function declaration
|
2161
|
+
*/
|
2001
2162
|
preWalkFunctionDeclaration(statement) {
|
2002
2163
|
if (statement.id) {
|
2003
2164
|
this.defineVariable(statement.id.name);
|
2004
2165
|
}
|
2005
2166
|
}
|
2006
2167
|
|
2168
|
+
/**
|
2169
|
+
* @param {FunctionDeclaration} statement function declaration
|
2170
|
+
*/
|
2007
2171
|
walkFunctionDeclaration(statement) {
|
2008
2172
|
const wasTopLevel = this.scope.topLevelScope;
|
2009
2173
|
this.scope.topLevelScope = false;
|
@@ -2024,6 +2188,9 @@ class JavascriptParser extends Parser {
|
|
2024
2188
|
this.scope.topLevelScope = wasTopLevel;
|
2025
2189
|
}
|
2026
2190
|
|
2191
|
+
/**
|
2192
|
+
* @param {ExpressionStatement} statement expression statement
|
2193
|
+
*/
|
2027
2194
|
blockPreWalkExpressionStatement(statement) {
|
2028
2195
|
const expression = statement.expression;
|
2029
2196
|
switch (expression.type) {
|
@@ -2032,6 +2199,9 @@ class JavascriptParser extends Parser {
|
|
2032
2199
|
}
|
2033
2200
|
}
|
2034
2201
|
|
2202
|
+
/**
|
2203
|
+
* @param {AssignmentExpression} expression assignment expression
|
2204
|
+
*/
|
2035
2205
|
preWalkAssignmentExpression(expression) {
|
2036
2206
|
if (
|
2037
2207
|
expression.left.type !== "ObjectPattern" ||
|
@@ -2172,6 +2342,9 @@ class JavascriptParser extends Parser {
|
|
2172
2342
|
}
|
2173
2343
|
}
|
2174
2344
|
|
2345
|
+
/**
|
2346
|
+
* @param {ExportNamedDeclaration} statement the statement
|
2347
|
+
*/
|
2175
2348
|
walkExportNamedDeclaration(statement) {
|
2176
2349
|
if (statement.declaration) {
|
2177
2350
|
this.walkStatement(statement.declaration);
|
@@ -2239,11 +2412,17 @@ class JavascriptParser extends Parser {
|
|
2239
2412
|
this.hooks.exportImportSpecifier.call(statement, source, null, name, 0);
|
2240
2413
|
}
|
2241
2414
|
|
2415
|
+
/**
|
2416
|
+
* @param {VariableDeclaration} statement variable declaration
|
2417
|
+
*/
|
2242
2418
|
preWalkVariableDeclaration(statement) {
|
2243
2419
|
if (statement.kind !== "var") return;
|
2244
2420
|
this._preWalkVariableDeclaration(statement, this.hooks.varDeclarationVar);
|
2245
2421
|
}
|
2246
2422
|
|
2423
|
+
/**
|
2424
|
+
* @param {VariableDeclaration} statement variable declaration
|
2425
|
+
*/
|
2247
2426
|
blockPreWalkVariableDeclaration(statement) {
|
2248
2427
|
if (statement.kind === "var") return;
|
2249
2428
|
const hookMap =
|
@@ -2253,6 +2432,10 @@ class JavascriptParser extends Parser {
|
|
2253
2432
|
this._preWalkVariableDeclaration(statement, hookMap);
|
2254
2433
|
}
|
2255
2434
|
|
2435
|
+
/**
|
2436
|
+
* @param {VariableDeclaration} statement variable declaration
|
2437
|
+
* @param {TODO} hookMap map of hooks
|
2438
|
+
*/
|
2256
2439
|
_preWalkVariableDeclaration(statement, hookMap) {
|
2257
2440
|
for (const declarator of statement.declarations) {
|
2258
2441
|
switch (declarator.type) {
|
@@ -2299,6 +2482,9 @@ class JavascriptParser extends Parser {
|
|
2299
2482
|
return ids;
|
2300
2483
|
}
|
2301
2484
|
|
2485
|
+
/**
|
2486
|
+
* @param {VariableDeclarator} declarator variable declarator
|
2487
|
+
*/
|
2302
2488
|
preWalkVariableDeclarator(declarator) {
|
2303
2489
|
if (
|
2304
2490
|
!declarator.init ||
|
@@ -2321,6 +2507,9 @@ class JavascriptParser extends Parser {
|
|
2321
2507
|
}
|
2322
2508
|
}
|
2323
2509
|
|
2510
|
+
/**
|
2511
|
+
* @param {VariableDeclaration} statement variable declaration
|
2512
|
+
*/
|
2324
2513
|
walkVariableDeclaration(statement) {
|
2325
2514
|
for (const declarator of statement.declarations) {
|
2326
2515
|
switch (declarator.type) {
|
@@ -2348,16 +2537,25 @@ class JavascriptParser extends Parser {
|
|
2348
2537
|
}
|
2349
2538
|
}
|
2350
2539
|
|
2540
|
+
/**
|
2541
|
+
* @param {ClassDeclaration} statement class declaration
|
2542
|
+
*/
|
2351
2543
|
blockPreWalkClassDeclaration(statement) {
|
2352
2544
|
if (statement.id) {
|
2353
2545
|
this.defineVariable(statement.id.name);
|
2354
2546
|
}
|
2355
2547
|
}
|
2356
2548
|
|
2549
|
+
/**
|
2550
|
+
* @param {ClassDeclaration} statement class declaration
|
2551
|
+
*/
|
2357
2552
|
walkClassDeclaration(statement) {
|
2358
2553
|
this.walkClass(statement);
|
2359
2554
|
}
|
2360
2555
|
|
2556
|
+
/**
|
2557
|
+
* @param {SwitchCase[]} switchCases switch statement
|
2558
|
+
*/
|
2361
2559
|
preWalkSwitchCases(switchCases) {
|
2362
2560
|
for (let index = 0, len = switchCases.length; index < len; index++) {
|
2363
2561
|
const switchCase = switchCases[index];
|
@@ -2365,6 +2563,9 @@ class JavascriptParser extends Parser {
|
|
2365
2563
|
}
|
2366
2564
|
}
|
2367
2565
|
|
2566
|
+
/**
|
2567
|
+
* @param {SwitchCase[]} switchCases switch statement
|
2568
|
+
*/
|
2368
2569
|
walkSwitchCases(switchCases) {
|
2369
2570
|
this.inBlockScope(() => {
|
2370
2571
|
const len = switchCases.length;
|
@@ -2400,10 +2601,16 @@ class JavascriptParser extends Parser {
|
|
2400
2601
|
});
|
2401
2602
|
}
|
2402
2603
|
|
2604
|
+
/**
|
2605
|
+
* @param {CatchClause} catchClause catch clause
|
2606
|
+
*/
|
2403
2607
|
preWalkCatchClause(catchClause) {
|
2404
2608
|
this.preWalkStatement(catchClause.body);
|
2405
2609
|
}
|
2406
2610
|
|
2611
|
+
/**
|
2612
|
+
* @param {CatchClause} catchClause catch clause
|
2613
|
+
*/
|
2407
2614
|
walkCatchClause(catchClause) {
|
2408
2615
|
this.inBlockScope(() => {
|
2409
2616
|
// Error binding is optional in catch clause since ECMAScript 2019
|
@@ -2420,6 +2627,9 @@ class JavascriptParser extends Parser {
|
|
2420
2627
|
});
|
2421
2628
|
}
|
2422
2629
|
|
2630
|
+
/**
|
2631
|
+
* @param {Pattern} pattern pattern
|
2632
|
+
*/
|
2423
2633
|
walkPattern(pattern) {
|
2424
2634
|
switch (pattern.type) {
|
2425
2635
|
case "ArrayPattern":
|
@@ -2440,6 +2650,9 @@ class JavascriptParser extends Parser {
|
|
2440
2650
|
}
|
2441
2651
|
}
|
2442
2652
|
|
2653
|
+
/**
|
2654
|
+
* @param {AssignmentPattern} pattern assignment pattern
|
2655
|
+
*/
|
2443
2656
|
walkAssignmentPattern(pattern) {
|
2444
2657
|
this.walkExpression(pattern.right);
|
2445
2658
|
this.walkPattern(pattern.left);
|
@@ -2455,6 +2668,9 @@ class JavascriptParser extends Parser {
|
|
2455
2668
|
}
|
2456
2669
|
}
|
2457
2670
|
|
2671
|
+
/**
|
2672
|
+
* @param {ArrayPattern} pattern array pattern
|
2673
|
+
*/
|
2458
2674
|
walkArrayPattern(pattern) {
|
2459
2675
|
for (let i = 0, len = pattern.elements.length; i < len; i++) {
|
2460
2676
|
const element = pattern.elements[i];
|
@@ -2462,10 +2678,16 @@ class JavascriptParser extends Parser {
|
|
2462
2678
|
}
|
2463
2679
|
}
|
2464
2680
|
|
2681
|
+
/**
|
2682
|
+
* @param {RestElement} pattern rest element
|
2683
|
+
*/
|
2465
2684
|
walkRestElement(pattern) {
|
2466
2685
|
this.walkPattern(pattern.argument);
|
2467
2686
|
}
|
2468
2687
|
|
2688
|
+
/**
|
2689
|
+
* @param {(Expression | SpreadElement | null)[]} expressions expressions
|
2690
|
+
*/
|
2469
2691
|
walkExpressions(expressions) {
|
2470
2692
|
for (const expression of expressions) {
|
2471
2693
|
if (expression) {
|
@@ -2554,24 +2776,36 @@ class JavascriptParser extends Parser {
|
|
2554
2776
|
}
|
2555
2777
|
}
|
2556
2778
|
|
2779
|
+
/**
|
2780
|
+
* @param {AwaitExpression} expression await expression
|
2781
|
+
*/
|
2557
2782
|
walkAwaitExpression(expression) {
|
2558
2783
|
if (this.scope.topLevelScope === true)
|
2559
2784
|
this.hooks.topLevelAwait.call(expression);
|
2560
2785
|
this.walkExpression(expression.argument);
|
2561
2786
|
}
|
2562
2787
|
|
2788
|
+
/**
|
2789
|
+
* @param {ArrayExpression} expression array expression
|
2790
|
+
*/
|
2563
2791
|
walkArrayExpression(expression) {
|
2564
2792
|
if (expression.elements) {
|
2565
2793
|
this.walkExpressions(expression.elements);
|
2566
2794
|
}
|
2567
2795
|
}
|
2568
2796
|
|
2797
|
+
/**
|
2798
|
+
* @param {SpreadElement} expression spread element
|
2799
|
+
*/
|
2569
2800
|
walkSpreadElement(expression) {
|
2570
2801
|
if (expression.argument) {
|
2571
2802
|
this.walkExpression(expression.argument);
|
2572
2803
|
}
|
2573
2804
|
}
|
2574
2805
|
|
2806
|
+
/**
|
2807
|
+
* @param {ObjectExpression} expression object expression
|
2808
|
+
*/
|
2575
2809
|
walkObjectExpression(expression) {
|
2576
2810
|
for (
|
2577
2811
|
let propIndex = 0, len = expression.properties.length;
|
@@ -2583,6 +2817,9 @@ class JavascriptParser extends Parser {
|
|
2583
2817
|
}
|
2584
2818
|
}
|
2585
2819
|
|
2820
|
+
/**
|
2821
|
+
* @param {Property | SpreadElement} prop property or spread element
|
2822
|
+
*/
|
2586
2823
|
walkProperty(prop) {
|
2587
2824
|
if (prop.type === "SpreadElement") {
|
2588
2825
|
this.walkExpression(prop.argument);
|
@@ -2600,6 +2837,9 @@ class JavascriptParser extends Parser {
|
|
2600
2837
|
}
|
2601
2838
|
}
|
2602
2839
|
|
2840
|
+
/**
|
2841
|
+
* @param {FunctionExpression} expression arrow function expression
|
2842
|
+
*/
|
2603
2843
|
walkFunctionExpression(expression) {
|
2604
2844
|
const wasTopLevel = this.scope.topLevelScope;
|
2605
2845
|
this.scope.topLevelScope = false;
|
@@ -2607,7 +2847,7 @@ class JavascriptParser extends Parser {
|
|
2607
2847
|
|
2608
2848
|
// Add function name in scope for recursive calls
|
2609
2849
|
if (expression.id) {
|
2610
|
-
scopeParams.push(expression.id
|
2850
|
+
scopeParams.push(expression.id);
|
2611
2851
|
}
|
2612
2852
|
|
2613
2853
|
this.inFunctionScope(true, scopeParams, () => {
|
@@ -2627,6 +2867,9 @@ class JavascriptParser extends Parser {
|
|
2627
2867
|
this.scope.topLevelScope = wasTopLevel;
|
2628
2868
|
}
|
2629
2869
|
|
2870
|
+
/**
|
2871
|
+
* @param {ArrowFunctionExpression} expression arrow function expression
|
2872
|
+
*/
|
2630
2873
|
walkArrowFunctionExpression(expression) {
|
2631
2874
|
const wasTopLevel = this.scope.topLevelScope;
|
2632
2875
|
this.scope.topLevelScope = wasTopLevel ? "arrow" : false;
|
@@ -2648,7 +2891,7 @@ class JavascriptParser extends Parser {
|
|
2648
2891
|
}
|
2649
2892
|
|
2650
2893
|
/**
|
2651
|
-
* @param {
|
2894
|
+
* @param {SequenceExpression} expression the sequence
|
2652
2895
|
*/
|
2653
2896
|
walkSequenceExpression(expression) {
|
2654
2897
|
if (!expression.expressions) return;
|
@@ -2672,10 +2915,16 @@ class JavascriptParser extends Parser {
|
|
2672
2915
|
}
|
2673
2916
|
}
|
2674
2917
|
|
2918
|
+
/**
|
2919
|
+
* @param {UpdateExpression} expression the update expression
|
2920
|
+
*/
|
2675
2921
|
walkUpdateExpression(expression) {
|
2676
2922
|
this.walkExpression(expression.argument);
|
2677
2923
|
}
|
2678
2924
|
|
2925
|
+
/**
|
2926
|
+
* @param {UnaryExpression} expression the unary expression
|
2927
|
+
*/
|
2679
2928
|
walkUnaryExpression(expression) {
|
2680
2929
|
if (expression.operator === "typeof") {
|
2681
2930
|
const result = this.callHooksForExpression(
|
@@ -2696,17 +2945,26 @@ class JavascriptParser extends Parser {
|
|
2696
2945
|
this.walkExpression(expression.argument);
|
2697
2946
|
}
|
2698
2947
|
|
2948
|
+
/**
|
2949
|
+
* @param {LogicalExpression | BinaryExpression} expression the expression
|
2950
|
+
*/
|
2699
2951
|
walkLeftRightExpression(expression) {
|
2700
2952
|
this.walkExpression(expression.left);
|
2701
2953
|
this.walkExpression(expression.right);
|
2702
2954
|
}
|
2703
2955
|
|
2956
|
+
/**
|
2957
|
+
* @param {BinaryExpression} expression the binary expression
|
2958
|
+
*/
|
2704
2959
|
walkBinaryExpression(expression) {
|
2705
2960
|
if (this.hooks.binaryExpression.call(expression) === undefined) {
|
2706
2961
|
this.walkLeftRightExpression(expression);
|
2707
2962
|
}
|
2708
2963
|
}
|
2709
2964
|
|
2965
|
+
/**
|
2966
|
+
* @param {LogicalExpression} expression the logical expression
|
2967
|
+
*/
|
2710
2968
|
walkLogicalExpression(expression) {
|
2711
2969
|
const result = this.hooks.expressionLogicalOperator.call(expression);
|
2712
2970
|
if (result === undefined) {
|
@@ -2718,6 +2976,9 @@ class JavascriptParser extends Parser {
|
|
2718
2976
|
}
|
2719
2977
|
}
|
2720
2978
|
|
2979
|
+
/**
|
2980
|
+
* @param {AssignmentExpression} expression assignment expression
|
2981
|
+
*/
|
2721
2982
|
walkAssignmentExpression(expression) {
|
2722
2983
|
if (expression.left.type === "Identifier") {
|
2723
2984
|
const renameIdentifier = this.getRenameIdentifier(expression.right);
|
@@ -2788,6 +3049,9 @@ class JavascriptParser extends Parser {
|
|
2788
3049
|
}
|
2789
3050
|
}
|
2790
3051
|
|
3052
|
+
/**
|
3053
|
+
* @param {ConditionalExpression} expression conditional expression
|
3054
|
+
*/
|
2791
3055
|
walkConditionalExpression(expression) {
|
2792
3056
|
const result = this.hooks.expressionConditionalOperator.call(expression);
|
2793
3057
|
if (result === undefined) {
|
@@ -2805,6 +3069,9 @@ class JavascriptParser extends Parser {
|
|
2805
3069
|
}
|
2806
3070
|
}
|
2807
3071
|
|
3072
|
+
/**
|
3073
|
+
* @param {NewExpression} expression new expression
|
3074
|
+
*/
|
2808
3075
|
walkNewExpression(expression) {
|
2809
3076
|
const result = this.callHooksForExpression(
|
2810
3077
|
this.hooks.new,
|
@@ -2818,18 +3085,27 @@ class JavascriptParser extends Parser {
|
|
2818
3085
|
}
|
2819
3086
|
}
|
2820
3087
|
|
3088
|
+
/**
|
3089
|
+
* @param {YieldExpression} expression yield expression
|
3090
|
+
*/
|
2821
3091
|
walkYieldExpression(expression) {
|
2822
3092
|
if (expression.argument) {
|
2823
3093
|
this.walkExpression(expression.argument);
|
2824
3094
|
}
|
2825
3095
|
}
|
2826
3096
|
|
3097
|
+
/**
|
3098
|
+
* @param {TemplateLiteral} expression template literal
|
3099
|
+
*/
|
2827
3100
|
walkTemplateLiteral(expression) {
|
2828
3101
|
if (expression.expressions) {
|
2829
3102
|
this.walkExpressions(expression.expressions);
|
2830
3103
|
}
|
2831
3104
|
}
|
2832
3105
|
|
3106
|
+
/**
|
3107
|
+
* @param {TaggedTemplateExpression} expression tagged template expression
|
3108
|
+
*/
|
2833
3109
|
walkTaggedTemplateExpression(expression) {
|
2834
3110
|
if (expression.tag) {
|
2835
3111
|
this.walkExpression(expression.tag);
|
@@ -2839,12 +3115,15 @@ class JavascriptParser extends Parser {
|
|
2839
3115
|
}
|
2840
3116
|
}
|
2841
3117
|
|
3118
|
+
/**
|
3119
|
+
* @param {ClassExpression} expression the class expression
|
3120
|
+
*/
|
2842
3121
|
walkClassExpression(expression) {
|
2843
3122
|
this.walkClass(expression);
|
2844
3123
|
}
|
2845
3124
|
|
2846
3125
|
/**
|
2847
|
-
* @param {
|
3126
|
+
* @param {ChainExpression} expression expression
|
2848
3127
|
*/
|
2849
3128
|
walkChainExpression(expression) {
|
2850
3129
|
const result = this.hooks.optionalChaining.call(expression);
|
@@ -2922,6 +3201,9 @@ class JavascriptParser extends Parser {
|
|
2922
3201
|
this.scope.topLevelScope = wasTopLevel;
|
2923
3202
|
}
|
2924
3203
|
|
3204
|
+
/**
|
3205
|
+
* @param {ImportExpression} expression import expression
|
3206
|
+
*/
|
2925
3207
|
walkImportExpression(expression) {
|
2926
3208
|
let result = this.hooks.importCall.call(expression);
|
2927
3209
|
if (result === true) return;
|
@@ -2981,7 +3263,8 @@ class JavascriptParser extends Parser {
|
|
2981
3263
|
callee.getMembers(),
|
2982
3264
|
callee.getMembersOptionals
|
2983
3265
|
? callee.getMembersOptionals()
|
2984
|
-
: callee.getMembers().map(() => false)
|
3266
|
+
: callee.getMembers().map(() => false),
|
3267
|
+
callee.getMemberRangeStarts ? callee.getMemberRangeStarts() : []
|
2985
3268
|
);
|
2986
3269
|
if (result1 === true) return;
|
2987
3270
|
const result2 = this.callHooksForInfo(
|
@@ -3006,6 +3289,9 @@ class JavascriptParser extends Parser {
|
|
3006
3289
|
}
|
3007
3290
|
}
|
3008
3291
|
|
3292
|
+
/**
|
3293
|
+
* @param {MemberExpression} expression member expression
|
3294
|
+
*/
|
3009
3295
|
walkMemberExpression(expression) {
|
3010
3296
|
const exprInfo = this.getMemberExpressionInfo(
|
3011
3297
|
expression,
|
@@ -3022,12 +3308,14 @@ class JavascriptParser extends Parser {
|
|
3022
3308
|
if (result1 === true) return;
|
3023
3309
|
const members = exprInfo.getMembers();
|
3024
3310
|
const membersOptionals = exprInfo.getMembersOptionals();
|
3311
|
+
const memberRangeStarts = exprInfo.getMemberRangeStarts();
|
3025
3312
|
const result2 = this.callHooksForInfo(
|
3026
3313
|
this.hooks.expressionMemberChain,
|
3027
3314
|
exprInfo.rootInfo,
|
3028
3315
|
expression,
|
3029
3316
|
members,
|
3030
|
-
membersOptionals
|
3317
|
+
membersOptionals,
|
3318
|
+
memberRangeStarts
|
3031
3319
|
);
|
3032
3320
|
if (result2 === true) return;
|
3033
3321
|
this.walkMemberExpressionWithExpressionName(
|
@@ -3099,16 +3387,22 @@ class JavascriptParser extends Parser {
|
|
3099
3387
|
if (expression.computed === true) this.walkExpression(expression.property);
|
3100
3388
|
}
|
3101
3389
|
|
3390
|
+
/**
|
3391
|
+
* @param {ThisExpression} expression this expression
|
3392
|
+
*/
|
3102
3393
|
walkThisExpression(expression) {
|
3103
3394
|
this.callHooksForName(this.hooks.expression, "this", expression);
|
3104
3395
|
}
|
3105
3396
|
|
3397
|
+
/**
|
3398
|
+
* @param {Identifier} expression identifier
|
3399
|
+
*/
|
3106
3400
|
walkIdentifier(expression) {
|
3107
3401
|
this.callHooksForName(this.hooks.expression, expression.name, expression);
|
3108
3402
|
}
|
3109
3403
|
|
3110
3404
|
/**
|
3111
|
-
* @param {
|
3405
|
+
* @param {MetaProperty} metaProperty meta property
|
3112
3406
|
*/
|
3113
3407
|
walkMetaProperty(metaProperty) {
|
3114
3408
|
this.hooks.expression.for(getRootName(metaProperty)).call(metaProperty);
|
@@ -3128,7 +3422,7 @@ class JavascriptParser extends Parser {
|
|
3128
3422
|
* @template T
|
3129
3423
|
* @template R
|
3130
3424
|
* @param {HookMap<SyncBailHook<T, R>>} hookMap hooks the should be called
|
3131
|
-
* @param {
|
3425
|
+
* @param {MemberExpression} expr expression info
|
3132
3426
|
* @param {function(string, string | ScopeInfo | VariableInfo, function(): string[]): any} fallback callback when variable in not handled by hooks
|
3133
3427
|
* @param {function(string): any} defined callback when variable is defined
|
3134
3428
|
* @param {AsArray<T>} args args for the hook
|
@@ -3292,6 +3586,30 @@ class JavascriptParser extends Parser {
|
|
3292
3586
|
this.scope = oldScope;
|
3293
3587
|
}
|
3294
3588
|
|
3589
|
+
inClassScope(hasThis, params, fn) {
|
3590
|
+
const oldScope = this.scope;
|
3591
|
+
this.scope = {
|
3592
|
+
topLevelScope: oldScope.topLevelScope,
|
3593
|
+
inTry: false,
|
3594
|
+
inShorthand: false,
|
3595
|
+
isStrict: oldScope.isStrict,
|
3596
|
+
isAsmJs: oldScope.isAsmJs,
|
3597
|
+
definitions: oldScope.definitions.createChild()
|
3598
|
+
};
|
3599
|
+
|
3600
|
+
if (hasThis) {
|
3601
|
+
this.undefineVariable("this");
|
3602
|
+
}
|
3603
|
+
|
3604
|
+
this.enterPatterns(params, (ident, pattern) => {
|
3605
|
+
this.defineVariable(ident);
|
3606
|
+
});
|
3607
|
+
|
3608
|
+
fn();
|
3609
|
+
|
3610
|
+
this.scope = oldScope;
|
3611
|
+
}
|
3612
|
+
|
3295
3613
|
inFunctionScope(hasThis, params, fn) {
|
3296
3614
|
const oldScope = this.scope;
|
3297
3615
|
this.scope = {
|
@@ -3385,12 +3703,20 @@ class JavascriptParser extends Parser {
|
|
3385
3703
|
}
|
3386
3704
|
}
|
3387
3705
|
|
3706
|
+
/**
|
3707
|
+
* @param {Identifier} pattern identifier pattern
|
3708
|
+
* @param {TODO} onIdent callback
|
3709
|
+
*/
|
3388
3710
|
enterIdentifier(pattern, onIdent) {
|
3389
3711
|
if (!this.callHooksForName(this.hooks.pattern, pattern.name, pattern)) {
|
3390
3712
|
onIdent(pattern.name, pattern);
|
3391
3713
|
}
|
3392
3714
|
}
|
3393
3715
|
|
3716
|
+
/**
|
3717
|
+
* @param {ObjectPattern} pattern object pattern
|
3718
|
+
* @param {TODO} onIdent callback
|
3719
|
+
*/
|
3394
3720
|
enterObjectPattern(pattern, onIdent) {
|
3395
3721
|
for (
|
3396
3722
|
let propIndex = 0, len = pattern.properties.length;
|
@@ -3402,6 +3728,10 @@ class JavascriptParser extends Parser {
|
|
3402
3728
|
}
|
3403
3729
|
}
|
3404
3730
|
|
3731
|
+
/**
|
3732
|
+
* @param {ArrayPattern} pattern object pattern
|
3733
|
+
* @param {TODO} onIdent callback
|
3734
|
+
*/
|
3405
3735
|
enterArrayPattern(pattern, onIdent) {
|
3406
3736
|
for (
|
3407
3737
|
let elementIndex = 0, len = pattern.elements.length;
|
@@ -3409,20 +3739,29 @@ class JavascriptParser extends Parser {
|
|
3409
3739
|
elementIndex++
|
3410
3740
|
) {
|
3411
3741
|
const element = pattern.elements[elementIndex];
|
3742
|
+
// TODO check on `null`?
|
3412
3743
|
this.enterPattern(element, onIdent);
|
3413
3744
|
}
|
3414
3745
|
}
|
3415
3746
|
|
3747
|
+
/**
|
3748
|
+
* @param {RestElement} pattern object pattern
|
3749
|
+
* @param {TODO} onIdent callback
|
3750
|
+
*/
|
3416
3751
|
enterRestElement(pattern, onIdent) {
|
3417
3752
|
this.enterPattern(pattern.argument, onIdent);
|
3418
3753
|
}
|
3419
3754
|
|
3755
|
+
/**
|
3756
|
+
* @param {AssignmentPattern} pattern object pattern
|
3757
|
+
* @param {TODO} onIdent callback
|
3758
|
+
*/
|
3420
3759
|
enterAssignmentPattern(pattern, onIdent) {
|
3421
3760
|
this.enterPattern(pattern.left, onIdent);
|
3422
3761
|
}
|
3423
3762
|
|
3424
3763
|
/**
|
3425
|
-
* @param {
|
3764
|
+
* @param {Expression} expression expression node
|
3426
3765
|
* @returns {BasicEvaluatedExpression} evaluation result
|
3427
3766
|
*/
|
3428
3767
|
evaluateExpression(expression) {
|
@@ -3444,6 +3783,10 @@ class JavascriptParser extends Parser {
|
|
3444
3783
|
.setExpression(expression);
|
3445
3784
|
}
|
3446
3785
|
|
3786
|
+
/**
|
3787
|
+
* @param {Expression} expression expression
|
3788
|
+
* @returns {string} parsed string
|
3789
|
+
*/
|
3447
3790
|
parseString(expression) {
|
3448
3791
|
switch (expression.type) {
|
3449
3792
|
case "BinaryExpression":
|
@@ -3552,7 +3895,7 @@ class JavascriptParser extends Parser {
|
|
3552
3895
|
source = source.toString("utf-8");
|
3553
3896
|
}
|
3554
3897
|
if (typeof source === "object") {
|
3555
|
-
ast = /** @type {
|
3898
|
+
ast = /** @type {Program} */ (source);
|
3556
3899
|
comments = source.comments;
|
3557
3900
|
} else {
|
3558
3901
|
comments = [];
|
@@ -3620,7 +3963,7 @@ class JavascriptParser extends Parser {
|
|
3620
3963
|
}
|
3621
3964
|
|
3622
3965
|
/**
|
3623
|
-
* @param {
|
3966
|
+
* @param {Expression | Declaration | PrivateIdentifier | null | undefined} expr an expression
|
3624
3967
|
* @param {number} commentsStartPos source position from which annotation comments are checked
|
3625
3968
|
* @returns {boolean} true, when the expression is pure
|
3626
3969
|
*/
|
@@ -3631,6 +3974,7 @@ class JavascriptParser extends Parser {
|
|
3631
3974
|
.call(expr, commentsStartPos);
|
3632
3975
|
if (typeof result === "boolean") return result;
|
3633
3976
|
switch (expr.type) {
|
3977
|
+
// TODO handle more cases
|
3634
3978
|
case "ClassDeclaration":
|
3635
3979
|
case "ClassExpression": {
|
3636
3980
|
if (expr.body.type !== "ClassBody") return false;
|
@@ -3638,27 +3982,43 @@ class JavascriptParser extends Parser {
|
|
3638
3982
|
return false;
|
3639
3983
|
}
|
3640
3984
|
const items =
|
3641
|
-
/** @type {
|
3642
|
-
|
3643
|
-
|
3644
|
-
|
3645
|
-
|
3646
|
-
|
3647
|
-
|
3648
|
-
|
3649
|
-
|
3650
|
-
|
3651
|
-
|
3652
|
-
|
3653
|
-
|
3654
|
-
|
3655
|
-
|
3985
|
+
/** @type {TODO[]} */
|
3986
|
+
(expr.body.body);
|
3987
|
+
return items.every(item => {
|
3988
|
+
if (
|
3989
|
+
item.computed &&
|
3990
|
+
item.key &&
|
3991
|
+
!this.isPure(item.key, item.range[0])
|
3992
|
+
) {
|
3993
|
+
return false;
|
3994
|
+
}
|
3995
|
+
|
3996
|
+
if (
|
3997
|
+
item.static &&
|
3998
|
+
item.value &&
|
3999
|
+
!this.isPure(
|
4000
|
+
item.value,
|
4001
|
+
item.key ? item.key.range[1] : item.range[0]
|
4002
|
+
)
|
4003
|
+
) {
|
4004
|
+
return false;
|
4005
|
+
}
|
4006
|
+
|
4007
|
+
if (item.type === "StaticBlock") {
|
4008
|
+
return false;
|
4009
|
+
}
|
4010
|
+
|
4011
|
+
return true;
|
4012
|
+
});
|
3656
4013
|
}
|
3657
4014
|
|
3658
4015
|
case "FunctionDeclaration":
|
3659
4016
|
case "FunctionExpression":
|
3660
4017
|
case "ArrowFunctionExpression":
|
4018
|
+
case "ThisExpression":
|
3661
4019
|
case "Literal":
|
4020
|
+
case "TemplateLiteral":
|
4021
|
+
case "Identifier":
|
3662
4022
|
case "PrivateIdentifier":
|
3663
4023
|
return true;
|
3664
4024
|
|
@@ -3674,6 +4034,12 @@ class JavascriptParser extends Parser {
|
|
3674
4034
|
this.isPure(expr.alternate, expr.consequent.range[1])
|
3675
4035
|
);
|
3676
4036
|
|
4037
|
+
case "LogicalExpression":
|
4038
|
+
return (
|
4039
|
+
this.isPure(expr.left, commentsStartPos) &&
|
4040
|
+
this.isPure(expr.right, expr.left.range[1])
|
4041
|
+
);
|
4042
|
+
|
3677
4043
|
case "SequenceExpression":
|
3678
4044
|
return expr.expressions.every(expr => {
|
3679
4045
|
const pureFlag = this.isPure(expr, commentsStartPos);
|
@@ -3703,6 +4069,10 @@ class JavascriptParser extends Parser {
|
|
3703
4069
|
return !evaluated.couldHaveSideEffects();
|
3704
4070
|
}
|
3705
4071
|
|
4072
|
+
/**
|
4073
|
+
* @param {Range} range range
|
4074
|
+
* @returns {TODO[]} comments in the range
|
4075
|
+
*/
|
3706
4076
|
getComments(range) {
|
3707
4077
|
const [rangeStart, rangeEnd] = range;
|
3708
4078
|
const compare = (comment, needle) => comment.range[0] - needle;
|
@@ -3790,6 +4160,9 @@ class JavascriptParser extends Parser {
|
|
3790
4160
|
this.scope.definitions.set(name, newInfo);
|
3791
4161
|
}
|
3792
4162
|
|
4163
|
+
/**
|
4164
|
+
* @param {string} name variable name
|
4165
|
+
*/
|
3793
4166
|
defineVariable(name) {
|
3794
4167
|
const oldInfo = this.scope.definitions.get(name);
|
3795
4168
|
// Don't redefine variable in same scope to keep existing tags
|
@@ -3798,10 +4171,17 @@ class JavascriptParser extends Parser {
|
|
3798
4171
|
this.scope.definitions.set(name, this.scope);
|
3799
4172
|
}
|
3800
4173
|
|
4174
|
+
/**
|
4175
|
+
* @param {string} name variable name
|
4176
|
+
*/
|
3801
4177
|
undefineVariable(name) {
|
3802
4178
|
this.scope.definitions.delete(name);
|
3803
4179
|
}
|
3804
4180
|
|
4181
|
+
/**
|
4182
|
+
* @param {string} name variable name
|
4183
|
+
* @returns {boolean} true, when variable is defined
|
4184
|
+
*/
|
3805
4185
|
isVariableDefined(name) {
|
3806
4186
|
const info = this.scope.definitions.get(name);
|
3807
4187
|
if (info === undefined) return false;
|
@@ -3844,10 +4224,18 @@ class JavascriptParser extends Parser {
|
|
3844
4224
|
}
|
3845
4225
|
}
|
3846
4226
|
|
4227
|
+
/**
|
4228
|
+
* @param {TagInfo} tagInfo tag info
|
4229
|
+
* @returns {VariableInfo} variable info
|
4230
|
+
*/
|
3847
4231
|
evaluatedVariable(tagInfo) {
|
3848
4232
|
return new VariableInfo(this.scope, undefined, tagInfo);
|
3849
4233
|
}
|
3850
4234
|
|
4235
|
+
/**
|
4236
|
+
* @param {Range} range range of the comment
|
4237
|
+
* @returns {TODO} TODO
|
4238
|
+
*/
|
3851
4239
|
parseCommentOptions(range) {
|
3852
4240
|
const comments = this.getComments(range);
|
3853
4241
|
if (comments.length === 0) {
|
@@ -3882,21 +4270,24 @@ class JavascriptParser extends Parser {
|
|
3882
4270
|
}
|
3883
4271
|
|
3884
4272
|
/**
|
3885
|
-
* @param {
|
3886
|
-
* @returns {{ members: string[], object:
|
4273
|
+
* @param {MemberExpression} expression a member expression
|
4274
|
+
* @returns {{ members: string[], object: Expression | Super, membersOptionals: boolean[], memberRangeStarts: number[] }} member names (reverse order) and remaining object
|
3887
4275
|
*/
|
3888
4276
|
extractMemberExpressionChain(expression) {
|
3889
4277
|
/** @type {AnyNode} */
|
3890
4278
|
let expr = expression;
|
3891
4279
|
const members = [];
|
3892
4280
|
const membersOptionals = [];
|
4281
|
+
const memberRangeStarts = [];
|
3893
4282
|
while (expr.type === "MemberExpression") {
|
3894
4283
|
if (expr.computed) {
|
3895
4284
|
if (expr.property.type !== "Literal") break;
|
3896
4285
|
members.push(`${expr.property.value}`);
|
4286
|
+
memberRangeStarts.push(expr.object.range[1]);
|
3897
4287
|
} else {
|
3898
4288
|
if (expr.property.type !== "Identifier") break;
|
3899
4289
|
members.push(expr.property.name);
|
4290
|
+
memberRangeStarts.push(expr.object.range[1]);
|
3900
4291
|
}
|
3901
4292
|
membersOptionals.push(expr.optional);
|
3902
4293
|
expr = expr.object;
|
@@ -3905,6 +4296,7 @@ class JavascriptParser extends Parser {
|
|
3905
4296
|
return {
|
3906
4297
|
members,
|
3907
4298
|
membersOptionals,
|
4299
|
+
memberRangeStarts,
|
3908
4300
|
object: expr
|
3909
4301
|
};
|
3910
4302
|
}
|
@@ -3927,16 +4319,16 @@ class JavascriptParser extends Parser {
|
|
3927
4319
|
return { info, name };
|
3928
4320
|
}
|
3929
4321
|
|
3930
|
-
/** @typedef {{ type: "call", call:
|
3931
|
-
/** @typedef {{ type: "expression", rootInfo: string | VariableInfo, name: string, getMembers: () => string[], getMembersOptionals: () => boolean[]}} ExpressionExpressionInfo */
|
4322
|
+
/** @typedef {{ type: "call", call: CallExpression, calleeName: string, rootInfo: string | VariableInfo, getCalleeMembers: () => string[], name: string, getMembers: () => string[], getMembersOptionals: () => boolean[], getMemberRangeStarts: () => number[]}} CallExpressionInfo */
|
4323
|
+
/** @typedef {{ type: "expression", rootInfo: string | VariableInfo, name: string, getMembers: () => string[], getMembersOptionals: () => boolean[], getMemberRangeStarts: () => number[]}} ExpressionExpressionInfo */
|
3932
4324
|
|
3933
4325
|
/**
|
3934
|
-
* @param {
|
4326
|
+
* @param {MemberExpression} expression a member expression
|
3935
4327
|
* @param {number} allowedTypes which types should be returned, presented in bit mask
|
3936
4328
|
* @returns {CallExpressionInfo | ExpressionExpressionInfo | undefined} expression info
|
3937
4329
|
*/
|
3938
4330
|
getMemberExpressionInfo(expression, allowedTypes) {
|
3939
|
-
const { object, members, membersOptionals } =
|
4331
|
+
const { object, members, membersOptionals, memberRangeStarts } =
|
3940
4332
|
this.extractMemberExpressionChain(expression);
|
3941
4333
|
switch (object.type) {
|
3942
4334
|
case "CallExpression": {
|
@@ -3962,7 +4354,8 @@ class JavascriptParser extends Parser {
|
|
3962
4354
|
getCalleeMembers: memoize(() => rootMembers.reverse()),
|
3963
4355
|
name: objectAndMembersToName(`${calleeName}()`, members),
|
3964
4356
|
getMembers: memoize(() => members.reverse()),
|
3965
|
-
getMembersOptionals: memoize(() => membersOptionals.reverse())
|
4357
|
+
getMembersOptionals: memoize(() => membersOptionals.reverse()),
|
4358
|
+
getMemberRangeStarts: memoize(() => memberRangeStarts.reverse())
|
3966
4359
|
};
|
3967
4360
|
}
|
3968
4361
|
case "Identifier":
|
@@ -3981,14 +4374,15 @@ class JavascriptParser extends Parser {
|
|
3981
4374
|
name: objectAndMembersToName(resolvedRoot, members),
|
3982
4375
|
rootInfo,
|
3983
4376
|
getMembers: memoize(() => members.reverse()),
|
3984
|
-
getMembersOptionals: memoize(() => membersOptionals.reverse())
|
4377
|
+
getMembersOptionals: memoize(() => membersOptionals.reverse()),
|
4378
|
+
getMemberRangeStarts: memoize(() => memberRangeStarts.reverse())
|
3985
4379
|
};
|
3986
4380
|
}
|
3987
4381
|
}
|
3988
4382
|
}
|
3989
4383
|
|
3990
4384
|
/**
|
3991
|
-
* @param {
|
4385
|
+
* @param {MemberExpression} expression an expression
|
3992
4386
|
* @returns {{ name: string, rootInfo: ExportedVariableInfo, getMembers: () => string[]}} name info
|
3993
4387
|
*/
|
3994
4388
|
getNameForExpression(expression) {
|
@@ -4001,7 +4395,7 @@ class JavascriptParser extends Parser {
|
|
4001
4395
|
/**
|
4002
4396
|
* @param {string} code source code
|
4003
4397
|
* @param {ParseOptions} options parsing options
|
4004
|
-
* @returns {
|
4398
|
+
* @returns {Program} parsed ast
|
4005
4399
|
*/
|
4006
4400
|
static _parse(code, options) {
|
4007
4401
|
const type = options ? options.sourceType : "module";
|
@@ -4045,7 +4439,7 @@ class JavascriptParser extends Parser {
|
|
4045
4439
|
throw error;
|
4046
4440
|
}
|
4047
4441
|
|
4048
|
-
return /** @type {
|
4442
|
+
return /** @type {Program} */ (ast);
|
4049
4443
|
}
|
4050
4444
|
}
|
4051
4445
|
|