webpack 5.99.8 → 5.100.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +0 -3
- package/bin/webpack.js +8 -2
- package/hot/log.js +15 -15
- package/hot/poll.js +1 -0
- package/lib/APIPlugin.js +3 -3
- package/lib/AbstractMethodError.js +1 -0
- package/lib/AutomaticPrefetchPlugin.js +1 -0
- package/lib/BannerPlugin.js +1 -1
- package/lib/CacheFacade.js +2 -1
- package/lib/CaseSensitiveModulesWarning.js +4 -4
- package/lib/Chunk.js +6 -6
- package/lib/ChunkGraph.js +37 -32
- package/lib/ChunkGroup.js +17 -10
- package/lib/ChunkTemplate.js +1 -1
- package/lib/CleanPlugin.js +94 -17
- package/lib/CodeGenerationResults.js +1 -1
- package/lib/CompatibilityPlugin.js +5 -2
- package/lib/Compilation.js +77 -71
- package/lib/Compiler.js +46 -16
- package/lib/ConcatenationScope.js +15 -6
- package/lib/ConstPlugin.js +65 -45
- package/lib/ContextModule.js +16 -12
- package/lib/ContextModuleFactory.js +4 -3
- package/lib/ContextReplacementPlugin.js +4 -2
- package/lib/CssModule.js +2 -3
- package/lib/DefinePlugin.js +111 -3
- package/lib/DelegatedModuleFactoryPlugin.js +18 -18
- package/lib/Dependency.js +16 -12
- package/lib/DependencyTemplate.js +1 -0
- package/lib/DllEntryPlugin.js +3 -1
- package/lib/DllPlugin.js +4 -3
- package/lib/DllReferencePlugin.js +2 -2
- package/lib/DynamicEntryPlugin.js +1 -1
- package/lib/EntryOptionPlugin.js +5 -0
- package/lib/ErrorHelpers.js +4 -4
- package/lib/EvalDevToolModulePlugin.js +3 -3
- package/lib/EvalSourceMapDevToolPlugin.js +7 -7
- package/lib/ExportsInfo.js +48 -39
- package/lib/ExternalModule.js +15 -11
- package/lib/ExternalModuleFactoryPlugin.js +5 -2
- package/lib/FileSystemInfo.js +51 -38
- package/lib/FlagDependencyExportsPlugin.js +14 -7
- package/lib/FlagDependencyUsagePlugin.js +1 -1
- package/lib/Generator.js +14 -1
- package/lib/HookWebpackError.js +1 -0
- package/lib/HotModuleReplacementPlugin.js +77 -50
- package/lib/IgnorePlugin.js +1 -1
- package/lib/InvalidDependenciesModuleWarning.js +1 -1
- package/lib/JavascriptMetaInfoPlugin.js +0 -1
- package/lib/LibManifestPlugin.js +4 -2
- package/lib/LoaderOptionsPlugin.js +6 -4
- package/lib/MainTemplate.js +2 -2
- package/lib/Module.js +21 -6
- package/lib/ModuleFactory.js +1 -0
- package/lib/ModuleGraph.js +24 -2
- package/lib/ModuleGraphConnection.js +5 -5
- package/lib/ModuleInfoHeaderPlugin.js +2 -1
- package/lib/ModuleParseError.js +1 -0
- package/lib/ModuleSourceTypesConstants.js +12 -12
- package/lib/ModuleTemplate.js +1 -1
- package/lib/ModuleTypeConstants.js +21 -21
- package/lib/MultiCompiler.js +6 -6
- package/lib/NormalModule.js +61 -56
- package/lib/NormalModuleFactory.js +52 -37
- package/lib/NormalModuleReplacementPlugin.js +1 -1
- package/lib/NullFactory.js +1 -0
- package/lib/OptimizationStages.js +1 -1
- package/lib/Parser.js +1 -0
- package/lib/ProgressPlugin.js +12 -5
- package/lib/ProvidePlugin.js +5 -1
- package/lib/RecordIdsPlugin.js +3 -3
- package/lib/RuntimeGlobals.js +175 -155
- package/lib/RuntimeModule.js +1 -0
- package/lib/RuntimePlugin.js +34 -8
- package/lib/RuntimeTemplate.js +111 -11
- package/lib/SourceMapDevToolModuleOptionsPlugin.js +15 -25
- package/lib/SourceMapDevToolPlugin.js +19 -17
- package/lib/Template.js +2 -2
- package/lib/TemplatedPathPlugin.js +1 -1
- package/lib/WarnDeprecatedOptionPlugin.js +7 -8
- package/lib/WatchIgnorePlugin.js +4 -3
- package/lib/WebpackIsIncludedPlugin.js +2 -1
- package/lib/WebpackOptionsApply.js +115 -27
- package/lib/asset/AssetGenerator.js +26 -21
- package/lib/asset/AssetModulesPlugin.js +19 -17
- package/lib/asset/AssetSourceGenerator.js +11 -9
- package/lib/asset/RawDataUrlModule.js +4 -2
- package/lib/async-modules/AwaitDependenciesInitFragment.js +1 -1
- package/lib/buildChunkGraph.js +6 -3
- package/lib/cache/AddBuildDependenciesPlugin.js +5 -6
- package/lib/cache/IdleFileCachePlugin.js +7 -4
- package/lib/cache/MemoryCachePlugin.js +1 -0
- package/lib/cache/MemoryWithGcCachePlugin.js +1 -0
- package/lib/cache/PackFileCacheStrategy.js +26 -20
- package/lib/cache/ResolverCachePlugin.js +16 -8
- package/lib/cli.js +15 -10
- package/lib/config/browserslistTargetHandler.js +3 -3
- package/lib/config/defaults.js +25 -17
- package/lib/config/normalization.js +2 -1
- package/lib/config/target.js +6 -5
- package/lib/container/ContainerPlugin.js +1 -1
- package/lib/container/ContainerReferencePlugin.js +1 -1
- package/lib/container/FallbackModule.js +2 -1
- package/lib/container/HoistContainerReferencesPlugin.js +1 -1
- package/lib/container/ModuleFederationPlugin.js +2 -2
- package/lib/container/RemoteModule.js +1 -1
- package/lib/css/CssGenerator.js +9 -6
- package/lib/css/CssModulesPlugin.js +44 -31
- package/lib/css/CssParser.js +6 -4
- package/lib/css/walkCssTokens.js +33 -37
- package/lib/debug/ProfilingPlugin.js +6 -6
- package/lib/dependencies/AMDDefineDependencyParserPlugin.js +8 -8
- package/lib/dependencies/AMDPlugin.js +12 -8
- package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +28 -26
- package/lib/dependencies/CachedConstDependency.js +1 -5
- package/lib/dependencies/CommonJsExportRequireDependency.js +6 -4
- package/lib/dependencies/CommonJsExportsParserPlugin.js +22 -25
- package/lib/dependencies/CommonJsFullRequireDependency.js +1 -9
- package/lib/dependencies/CommonJsImportsParserPlugin.js +100 -114
- package/lib/dependencies/CommonJsPlugin.js +15 -16
- package/lib/dependencies/ContextDependencyHelpers.js +2 -1
- package/lib/dependencies/ContextDependencyTemplateAsId.js +1 -0
- package/lib/dependencies/ContextDependencyTemplateAsRequireCall.js +1 -0
- package/lib/dependencies/CssIcssExportDependency.js +1 -1
- package/lib/dependencies/CssLocalIdentifierDependency.js +2 -2
- package/lib/dependencies/CssSelfLocalIdentifierDependency.js +2 -1
- package/lib/dependencies/CssUrlDependency.js +1 -1
- package/lib/dependencies/DynamicExports.js +9 -9
- package/lib/dependencies/ExportsInfoDependency.js +1 -1
- package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +122 -101
- package/lib/dependencies/HarmonyExportExpressionDependency.js +1 -1
- package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +95 -19
- package/lib/dependencies/HarmonyExportInitFragment.js +1 -1
- package/lib/dependencies/HarmonyImportDependency.js +11 -5
- package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +238 -162
- package/lib/dependencies/HarmonyImportSideEffectDependency.js +4 -1
- package/lib/dependencies/HarmonyImportSpecifierDependency.js +20 -9
- package/lib/dependencies/HarmonyModulesPlugin.js +23 -12
- package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +1 -0
- package/lib/dependencies/ImportMetaContextPlugin.js +2 -1
- package/lib/dependencies/ImportMetaPlugin.js +2 -2
- package/lib/dependencies/ImportParserPlugin.js +40 -9
- package/lib/dependencies/ImportPlugin.js +3 -1
- package/lib/dependencies/LoaderPlugin.js +1 -0
- package/lib/dependencies/ModuleDependency.js +1 -1
- package/lib/dependencies/ModuleDependencyTemplateAsRequireId.js +1 -0
- package/lib/dependencies/RequireContextPlugin.js +3 -1
- package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +3 -0
- package/lib/dependencies/RequireEnsurePlugin.js +6 -6
- package/lib/dependencies/RequireIncludeDependencyParserPlugin.js +33 -34
- package/lib/dependencies/RequireIncludePlugin.js +1 -0
- package/lib/dependencies/RuntimeRequirementsDependency.js +1 -1
- package/lib/dependencies/SystemPlugin.js +1 -1
- package/lib/dependencies/URLContextDependency.js +65 -0
- package/lib/dependencies/URLDependency.js +1 -1
- package/lib/dependencies/URLPlugin.js +17 -157
- package/lib/dependencies/WorkerPlugin.js +23 -10
- package/lib/dependencies/processExportInfo.js +2 -1
- package/lib/esm/ModuleChunkFormatPlugin.js +269 -185
- package/lib/esm/ModuleChunkLoadingPlugin.js +39 -1
- package/lib/esm/ModuleChunkLoadingRuntimeModule.js +73 -6
- package/lib/hmr/HotModuleReplacement.runtime.js +0 -1
- package/lib/hmr/HotModuleReplacementRuntimeModule.js +1 -1
- package/lib/hmr/JavascriptHotModuleReplacementHelper.js +37 -0
- package/lib/hmr/LazyCompilationPlugin.js +4 -2
- package/lib/hmr/lazyCompilationBackend.js +4 -2
- package/lib/ids/ChunkModuleIdRangePlugin.js +6 -3
- package/lib/ids/DeterministicChunkIdsPlugin.js +30 -35
- package/lib/ids/DeterministicModuleIdsPlugin.js +4 -3
- package/lib/ids/HashedModuleIdsPlugin.js +5 -4
- package/lib/ids/IdHelpers.js +21 -17
- package/lib/ids/NamedChunkIdsPlugin.js +5 -5
- package/lib/ids/NamedModuleIdsPlugin.js +4 -4
- package/lib/ids/NaturalChunkIdsPlugin.js +2 -1
- package/lib/ids/NaturalModuleIdsPlugin.js +1 -1
- package/lib/ids/OccurrenceChunkIdsPlugin.js +3 -2
- package/lib/ids/OccurrenceModuleIdsPlugin.js +1 -1
- package/lib/ids/SyncModuleIdsPlugin.js +1 -1
- package/lib/index.js +13 -3
- package/lib/javascript/ArrayPushCallbackChunkFormatPlugin.js +113 -119
- package/lib/javascript/BasicEvaluatedExpression.js +2 -1
- package/lib/javascript/ChunkHelpers.js +1 -0
- package/lib/javascript/CommonJsChunkFormatPlugin.js +121 -136
- package/lib/javascript/EnableChunkLoadingPlugin.js +6 -3
- package/lib/javascript/JavascriptGenerator.js +14 -2
- package/lib/javascript/JavascriptModulesPlugin.js +68 -27
- package/lib/javascript/JavascriptParser.js +136 -81
- package/lib/javascript/JavascriptParserHelpers.js +41 -41
- package/lib/javascript/StartupHelpers.js +17 -17
- package/lib/json/JsonGenerator.js +4 -2
- package/lib/json/JsonModulesPlugin.js +2 -2
- package/lib/json/JsonParser.js +1 -1
- package/lib/library/AbstractLibraryPlugin.js +6 -2
- package/lib/library/AssignLibraryPlugin.js +21 -6
- package/lib/library/EnableLibraryPlugin.js +23 -3
- package/lib/library/ModuleLibraryPlugin.js +4 -1
- package/lib/library/UmdLibraryPlugin.js +15 -6
- package/lib/logging/createConsoleLogger.js +3 -3
- package/lib/logging/runtime.js +9 -9
- package/lib/node/ReadFileChunkLoadingRuntimeModule.js +4 -22
- package/lib/node/RequireChunkLoadingRuntimeModule.js +4 -22
- package/lib/node/nodeConsole.js +4 -2
- package/lib/optimize/AggressiveMergingPlugin.js +45 -46
- package/lib/optimize/AggressiveSplittingPlugin.js +13 -12
- package/lib/optimize/ConcatenatedModule.js +227 -57
- package/lib/optimize/EnsureChunkConditionsPlugin.js +58 -58
- package/lib/optimize/FlagIncludedChunksPlugin.js +3 -1
- package/lib/optimize/InnerGraph.js +115 -112
- package/lib/optimize/InnerGraphPlugin.js +2 -2
- package/lib/optimize/LimitChunkCountPlugin.js +4 -2
- package/lib/optimize/MangleExportsPlugin.js +4 -3
- package/lib/optimize/MergeDuplicateChunksPlugin.js +80 -81
- package/lib/optimize/MinChunkSizePlugin.js +6 -3
- package/lib/optimize/ModuleConcatenationPlugin.js +31 -22
- package/lib/optimize/RealContentHashPlugin.js +26 -20
- package/lib/optimize/RemoveEmptyChunksPlugin.js +2 -1
- package/lib/optimize/RemoveParentModulesPlugin.js +1 -0
- package/lib/optimize/SideEffectsFlagPlugin.js +6 -3
- package/lib/optimize/SplitChunksPlugin.js +16 -13
- package/lib/rules/BasicEffectRulePlugin.js +4 -2
- package/lib/rules/BasicMatcherRulePlugin.js +3 -1
- package/lib/rules/ObjectMatcherRulePlugin.js +3 -1
- package/lib/rules/RuleSetCompiler.js +7 -4
- package/lib/rules/UseEffectRulePlugin.js +3 -1
- package/lib/runtime/AsyncModuleRuntimeModule.js +64 -9
- package/lib/runtime/CreateFakeNamespaceObjectRuntimeModule.js +1 -1
- package/lib/runtime/MakeDeferredNamespaceObjectRuntime.js +214 -0
- package/lib/runtime/RuntimeIdRuntimeModule.js +2 -1
- package/lib/runtime/StartupChunkDependenciesRuntimeModule.js +8 -7
- package/lib/schemes/DataUriPlugin.js +3 -1
- package/lib/schemes/FileUriPlugin.js +1 -1
- package/lib/schemes/HttpUriPlugin.js +27 -19
- package/lib/schemes/VirtualUrlPlugin.js +222 -0
- package/lib/serialization/AggregateErrorSerializer.js +1 -1
- package/lib/serialization/BinaryMiddleware.js +5 -4
- package/lib/serialization/FileMiddleware.js +7 -4
- package/lib/serialization/ObjectMiddleware.js +14 -8
- package/lib/serialization/Serializer.js +5 -3
- package/lib/serialization/SerializerMiddleware.js +2 -0
- package/lib/sharing/ConsumeSharedModule.js +1 -1
- package/lib/sharing/ConsumeSharedPlugin.js +3 -3
- package/lib/sharing/ConsumeSharedRuntimeModule.js +2 -2
- package/lib/sharing/ProvideSharedModule.js +1 -1
- package/lib/sharing/ProvideSharedPlugin.js +6 -3
- package/lib/sharing/SharePlugin.js +2 -1
- package/lib/sharing/ShareRuntimeModule.js +3 -5
- package/lib/sharing/utils.js +34 -34
- package/lib/stats/DefaultStatsFactoryPlugin.js +49 -46
- package/lib/stats/DefaultStatsPresetPlugin.js +4 -2
- package/lib/stats/DefaultStatsPrinterPlugin.js +28 -22
- package/lib/stats/StatsFactory.js +4 -2
- package/lib/stats/StatsPrinter.js +3 -2
- package/lib/url/URLParserPlugin.js +266 -0
- package/lib/util/ArrayQueue.js +1 -1
- package/lib/util/AsyncQueue.js +1 -1
- package/lib/util/Hash.js +2 -0
- package/lib/util/IterableHelpers.js +1 -1
- package/lib/util/LazyBucketSortedSet.js +2 -1
- package/lib/util/LazySet.js +11 -6
- package/lib/util/ParallelismFactorCalculator.js +1 -1
- package/lib/util/SetHelpers.js +3 -3
- package/lib/util/SortableSet.js +2 -2
- package/lib/util/StackedCacheMap.js +3 -1
- package/lib/util/StackedMap.js +2 -2
- package/lib/util/StringXor.js +1 -0
- package/lib/util/TupleSet.js +1 -0
- package/lib/util/URLAbsoluteSpecifier.js +1 -1
- package/lib/util/cleverMerge.js +12 -8
- package/lib/util/comparators.js +154 -127
- package/lib/util/compileBooleanMatcher.js +8 -3
- package/lib/util/concatenate.js +8 -7
- package/lib/util/conventions.js +72 -73
- package/lib/util/create-schema-validation.js +2 -1
- package/lib/util/createHash.js +10 -4
- package/lib/util/deprecation.js +69 -66
- package/lib/util/deterministicGrouping.js +4 -2
- package/lib/util/extractUrlAndGlobal.js +1 -1
- package/lib/util/findGraphRoots.js +2 -2
- package/lib/util/fs.js +30 -23
- package/lib/util/hash/md4.js +2 -2
- package/lib/util/hash/wasm-hash.js +4 -2
- package/lib/util/identifier.js +13 -12
- package/lib/util/internalSerializables.js +2 -0
- package/lib/util/magicComment.js +5 -5
- package/lib/util/processAsyncTree.js +1 -1
- package/lib/util/propertyAccess.js +1 -1
- package/lib/util/propertyName.js +1 -1
- package/lib/util/registerExternalSerializer.js +1 -2
- package/lib/util/removeBOM.js +1 -1
- package/lib/util/runtime.js +29 -21
- package/lib/util/semver.js +1 -1
- package/lib/util/serialization.js +3 -0
- package/lib/util/source.js +3 -2
- package/lib/validateSchema.js +1 -0
- package/lib/wasm/EnableWasmLoadingPlugin.js +6 -3
- package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +4 -1
- package/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js +46 -49
- package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +2 -2
- package/lib/wasm-sync/WebAssemblyGenerator.js +2 -3
- package/lib/wasm-sync/WebAssemblyInInitialChunkError.js +3 -2
- package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +3 -0
- package/lib/wasm-sync/WebAssemblyUtils.js +1 -1
- package/lib/web/JsonpChunkLoadingRuntimeModule.js +4 -22
- package/lib/webpack.js +4 -5
- package/lib/webworker/ImportScriptsChunkLoadingPlugin.js +1 -0
- package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +6 -24
- package/lib/webworker/WebWorkerTemplatePlugin.js +1 -0
- package/package.json +121 -114
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +17 -0
- package/schemas/plugins/schemes/VirtualUrlPlugin.check.d.ts +7 -0
- package/schemas/plugins/schemes/VirtualUrlPlugin.check.js +6 -0
- package/schemas/plugins/schemes/VirtualUrlPlugin.json +77 -0
- package/types.d.ts +1261 -366
|
@@ -5,15 +5,16 @@
|
|
|
5
5
|
|
|
6
6
|
"use strict";
|
|
7
7
|
|
|
8
|
-
const { Parser: AcornParser, tokTypes } = require("acorn");
|
|
9
|
-
const { SyncBailHook, HookMap } = require("tapable");
|
|
10
8
|
const vm = require("vm");
|
|
9
|
+
const { Parser: AcornParser, tokTypes } = require("acorn");
|
|
10
|
+
const acornImportPhases = require("acorn-import-phases");
|
|
11
|
+
const { HookMap, SyncBailHook } = require("tapable");
|
|
11
12
|
const Parser = require("../Parser");
|
|
12
13
|
const StackedMap = require("../util/StackedMap");
|
|
13
14
|
const binarySearchBounds = require("../util/binarySearchBounds");
|
|
14
15
|
const {
|
|
15
|
-
|
|
16
|
-
|
|
16
|
+
createMagicCommentContext,
|
|
17
|
+
webpackCommentRegExp
|
|
17
18
|
} = require("../util/magicComment");
|
|
18
19
|
const memoize = require("../util/memoize");
|
|
19
20
|
const BasicEvaluatedExpression = require("./BasicEvaluatedExpression");
|
|
@@ -83,6 +84,7 @@ const BasicEvaluatedExpression = require("./BasicEvaluatedExpression");
|
|
|
83
84
|
/** @typedef {import("estree").Statement} Statement */
|
|
84
85
|
/** @typedef {import("estree").ExportDefaultDeclaration} ExportDefaultDeclaration */
|
|
85
86
|
/** @typedef {import("estree").Super} Super */
|
|
87
|
+
/** @typedef {import("estree").ImportSpecifier} ImportSpecifier */
|
|
86
88
|
/** @typedef {import("estree").TaggedTemplateExpression} TaggedTemplateExpression */
|
|
87
89
|
/** @typedef {import("estree").TemplateLiteral} TemplateLiteral */
|
|
88
90
|
/** @typedef {import("estree").AssignmentProperty} AssignmentProperty */
|
|
@@ -102,10 +104,10 @@ const BasicEvaluatedExpression = require("./BasicEvaluatedExpression");
|
|
|
102
104
|
|
|
103
105
|
// TODO remove cast when @types/estree has been updated to import assertions
|
|
104
106
|
/** @typedef {import("estree").BaseNode & { type: "ImportAttribute", key: Identifier | Literal, value: Literal }} ImportAttribute */
|
|
105
|
-
/** @typedef {import("estree").ImportDeclaration & { attributes?: Array<ImportAttribute
|
|
107
|
+
/** @typedef {import("estree").ImportDeclaration & { attributes?: Array<ImportAttribute>, phase?: "defer" }} ImportDeclaration */
|
|
106
108
|
/** @typedef {import("estree").ExportNamedDeclaration & { attributes?: Array<ImportAttribute> }} ExportNamedDeclaration */
|
|
107
109
|
/** @typedef {import("estree").ExportAllDeclaration & { attributes?: Array<ImportAttribute> }} ExportAllDeclaration */
|
|
108
|
-
/** @typedef {import("estree").ImportExpression & { options?: Expression | null }} ImportExpression */
|
|
110
|
+
/** @typedef {import("estree").ImportExpression & { options?: Expression | null, phase?: "defer" }} ImportExpression */
|
|
109
111
|
/** @typedef {ImportDeclaration | ExportNamedDeclaration | ExportDefaultDeclaration | ExportAllDeclaration} ModuleDeclaration */
|
|
110
112
|
|
|
111
113
|
/** @type {string[]} */
|
|
@@ -120,7 +122,7 @@ const LEGACY_ASSERT_ATTRIBUTES = Symbol("assert");
|
|
|
120
122
|
const importAssertions = Parser =>
|
|
121
123
|
class extends Parser {
|
|
122
124
|
/**
|
|
123
|
-
* @this {
|
|
125
|
+
* @this {InstanceType<AcornParser>}
|
|
124
126
|
* @returns {ImportAttribute[]} import attributes
|
|
125
127
|
*/
|
|
126
128
|
parseWithClause() {
|
|
@@ -180,7 +182,10 @@ const importAssertions = Parser =>
|
|
|
180
182
|
};
|
|
181
183
|
|
|
182
184
|
// Syntax: https://developer.mozilla.org/en/SpiderMonkey/Parser_API
|
|
183
|
-
const parser = AcornParser.extend(
|
|
185
|
+
const parser = AcornParser.extend(
|
|
186
|
+
importAssertions,
|
|
187
|
+
acornImportPhases({ source: false })
|
|
188
|
+
);
|
|
184
189
|
|
|
185
190
|
/** @typedef {Record<string, string> & { _isLegacyAssert?: boolean }} ImportAttributes */
|
|
186
191
|
|
|
@@ -484,13 +489,15 @@ class JavascriptParser extends Parser {
|
|
|
484
489
|
preDeclarator: new SyncBailHook(["declarator", "statement"]),
|
|
485
490
|
/** @type {SyncBailHook<[VariableDeclarator, Statement], boolean | void>} */
|
|
486
491
|
declarator: new SyncBailHook(["declarator", "statement"]),
|
|
487
|
-
/** @type {HookMap<SyncBailHook<[
|
|
492
|
+
/** @type {HookMap<SyncBailHook<[Identifier], boolean | void>>} */
|
|
488
493
|
varDeclaration: new HookMap(() => new SyncBailHook(["declaration"])),
|
|
489
|
-
/** @type {HookMap<SyncBailHook<[
|
|
494
|
+
/** @type {HookMap<SyncBailHook<[Identifier], boolean | void>>} */
|
|
490
495
|
varDeclarationLet: new HookMap(() => new SyncBailHook(["declaration"])),
|
|
491
|
-
/** @type {HookMap<SyncBailHook<[
|
|
496
|
+
/** @type {HookMap<SyncBailHook<[Identifier], boolean | void>>} */
|
|
492
497
|
varDeclarationConst: new HookMap(() => new SyncBailHook(["declaration"])),
|
|
493
|
-
/** @type {HookMap<SyncBailHook<[
|
|
498
|
+
/** @type {HookMap<SyncBailHook<[Identifier], boolean | void>>} */
|
|
499
|
+
varDeclarationUsing: new HookMap(() => new SyncBailHook(["declaration"])),
|
|
500
|
+
/** @type {HookMap<SyncBailHook<[Identifier], boolean | void>>} */
|
|
494
501
|
varDeclarationVar: new HookMap(() => new SyncBailHook(["declaration"])),
|
|
495
502
|
/** @type {HookMap<SyncBailHook<[Identifier], boolean | void>>} */
|
|
496
503
|
pattern: new HookMap(() => new SyncBailHook(["pattern"])),
|
|
@@ -578,7 +585,9 @@ class JavascriptParser extends Parser {
|
|
|
578
585
|
/** @type {SyncBailHook<[ThrowStatement | ReturnStatement], boolean | void>} */
|
|
579
586
|
terminate: new SyncBailHook(["statement"]),
|
|
580
587
|
/** @type {SyncBailHook<[Program, Comment[]], boolean | void>} */
|
|
581
|
-
finish: new SyncBailHook(["ast", "comments"])
|
|
588
|
+
finish: new SyncBailHook(["ast", "comments"]),
|
|
589
|
+
/** @type {SyncBailHook<[Statement], boolean | void>} */
|
|
590
|
+
unusedStatement: new SyncBailHook(["statement"])
|
|
582
591
|
});
|
|
583
592
|
this.sourceType = sourceType;
|
|
584
593
|
/** @type {ScopeInfo} */
|
|
@@ -647,8 +656,9 @@ class JavascriptParser extends Parser {
|
|
|
647
656
|
} else if (
|
|
648
657
|
expr.arguments.length > 2 ||
|
|
649
658
|
this.getVariableInfo("RegExp") !== "RegExp"
|
|
650
|
-
)
|
|
659
|
+
) {
|
|
651
660
|
return;
|
|
661
|
+
}
|
|
652
662
|
|
|
653
663
|
let regExp;
|
|
654
664
|
const arg1 = expr.arguments[0];
|
|
@@ -688,8 +698,9 @@ class JavascriptParser extends Parser {
|
|
|
688
698
|
if (
|
|
689
699
|
flags === undefined ||
|
|
690
700
|
!BasicEvaluatedExpression.isValidRegExpFlags(flags)
|
|
691
|
-
)
|
|
701
|
+
) {
|
|
692
702
|
return;
|
|
703
|
+
}
|
|
693
704
|
}
|
|
694
705
|
}
|
|
695
706
|
|
|
@@ -706,23 +717,28 @@ class JavascriptParser extends Parser {
|
|
|
706
717
|
let allowedRight;
|
|
707
718
|
if (expr.operator === "&&") {
|
|
708
719
|
const leftAsBool = left.asBool();
|
|
709
|
-
if (leftAsBool === false)
|
|
720
|
+
if (leftAsBool === false) {
|
|
710
721
|
return left.setRange(/** @type {Range} */ (expr.range));
|
|
722
|
+
}
|
|
711
723
|
returnRight = leftAsBool === true;
|
|
712
724
|
allowedRight = false;
|
|
713
725
|
} else if (expr.operator === "||") {
|
|
714
726
|
const leftAsBool = left.asBool();
|
|
715
|
-
if (leftAsBool === true)
|
|
727
|
+
if (leftAsBool === true) {
|
|
716
728
|
return left.setRange(/** @type {Range} */ (expr.range));
|
|
729
|
+
}
|
|
717
730
|
returnRight = leftAsBool === false;
|
|
718
731
|
allowedRight = true;
|
|
719
732
|
} else if (expr.operator === "??") {
|
|
720
733
|
const leftAsNullish = left.asNullish();
|
|
721
|
-
if (leftAsNullish === false)
|
|
734
|
+
if (leftAsNullish === false) {
|
|
722
735
|
return left.setRange(/** @type {Range} */ (expr.range));
|
|
736
|
+
}
|
|
723
737
|
if (leftAsNullish !== true) return;
|
|
724
738
|
returnRight = true;
|
|
725
|
-
} else
|
|
739
|
+
} else {
|
|
740
|
+
return;
|
|
741
|
+
}
|
|
726
742
|
const right = this.evaluateExpression(expr.right);
|
|
727
743
|
if (returnRight) {
|
|
728
744
|
if (left.couldHaveSideEffects()) right.setSideEffects();
|
|
@@ -1133,11 +1149,12 @@ class JavascriptParser extends Parser {
|
|
|
1133
1149
|
left.prefix,
|
|
1134
1150
|
right.postfix,
|
|
1135
1151
|
left.wrappedInnerExpressions &&
|
|
1136
|
-
right.wrappedInnerExpressions &&
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1152
|
+
right.wrappedInnerExpressions && [
|
|
1153
|
+
...left.wrappedInnerExpressions,
|
|
1154
|
+
...(left.postfix ? [left.postfix] : []),
|
|
1155
|
+
...(right.prefix ? [right.prefix] : []),
|
|
1156
|
+
...right.wrappedInnerExpressions
|
|
1157
|
+
]
|
|
1141
1158
|
);
|
|
1142
1159
|
} else {
|
|
1143
1160
|
// ("prefix" + inner + postfix) + expr
|
|
@@ -1145,10 +1162,10 @@ class JavascriptParser extends Parser {
|
|
|
1145
1162
|
res.setWrapped(
|
|
1146
1163
|
left.prefix,
|
|
1147
1164
|
null,
|
|
1148
|
-
left.wrappedInnerExpressions &&
|
|
1149
|
-
left.wrappedInnerExpressions
|
|
1150
|
-
|
|
1151
|
-
|
|
1165
|
+
left.wrappedInnerExpressions && [
|
|
1166
|
+
...left.wrappedInnerExpressions,
|
|
1167
|
+
...(left.postfix ? [left.postfix, right] : [right])
|
|
1168
|
+
]
|
|
1152
1169
|
);
|
|
1153
1170
|
}
|
|
1154
1171
|
} else if (right.isString()) {
|
|
@@ -1161,16 +1178,17 @@ class JavascriptParser extends Parser {
|
|
|
1161
1178
|
res.setWrapped(
|
|
1162
1179
|
null,
|
|
1163
1180
|
right.postfix,
|
|
1164
|
-
right.wrappedInnerExpressions &&
|
|
1165
|
-
(right.prefix ? [left, right.prefix] : [left])
|
|
1166
|
-
|
|
1167
|
-
|
|
1181
|
+
right.wrappedInnerExpressions && [
|
|
1182
|
+
...(right.prefix ? [left, right.prefix] : [left]),
|
|
1183
|
+
...right.wrappedInnerExpressions
|
|
1184
|
+
]
|
|
1168
1185
|
);
|
|
1169
1186
|
} else {
|
|
1170
1187
|
return;
|
|
1171
1188
|
}
|
|
1172
|
-
if (left.couldHaveSideEffects() || right.couldHaveSideEffects())
|
|
1189
|
+
if (left.couldHaveSideEffects() || right.couldHaveSideEffects()) {
|
|
1173
1190
|
res.setSideEffects();
|
|
1191
|
+
}
|
|
1174
1192
|
res.setRange(/** @type {Range} */ (expr.range));
|
|
1175
1193
|
return res;
|
|
1176
1194
|
} else if (expr.operator === "-") {
|
|
@@ -1368,9 +1386,10 @@ class JavascriptParser extends Parser {
|
|
|
1368
1386
|
return this.callHooksForInfoWithFallback(
|
|
1369
1387
|
this.hooks.evaluateIdentifier,
|
|
1370
1388
|
info.name,
|
|
1371
|
-
|
|
1389
|
+
_name => {
|
|
1372
1390
|
cachedExpression = expression;
|
|
1373
1391
|
cachedInfo = info;
|
|
1392
|
+
return undefined;
|
|
1374
1393
|
},
|
|
1375
1394
|
name => {
|
|
1376
1395
|
const hook = this.hooks.evaluateDefinedIdentifier.get(name);
|
|
@@ -1422,7 +1441,7 @@ class JavascriptParser extends Parser {
|
|
|
1422
1441
|
};
|
|
1423
1442
|
}
|
|
1424
1443
|
});
|
|
1425
|
-
tapEvaluateWithVariableInfo("ThisExpression",
|
|
1444
|
+
tapEvaluateWithVariableInfo("ThisExpression", _expr => {
|
|
1426
1445
|
const info = this.getVariableInfo("this");
|
|
1427
1446
|
if (
|
|
1428
1447
|
typeof info === "string" ||
|
|
@@ -1660,6 +1679,7 @@ class JavascriptParser extends Parser {
|
|
|
1660
1679
|
if (!param.isString() && !param.isWrapped()) return;
|
|
1661
1680
|
let stringSuffix = null;
|
|
1662
1681
|
let hasUnknownParams = false;
|
|
1682
|
+
/** @type {BasicEvaluatedExpression[]} */
|
|
1663
1683
|
const innerExpressions = [];
|
|
1664
1684
|
for (let i = expr.arguments.length - 1; i >= 0; i--) {
|
|
1665
1685
|
const arg = expr.arguments[i];
|
|
@@ -1699,7 +1719,10 @@ class JavascriptParser extends Parser {
|
|
|
1699
1719
|
const prefix = param.isString() ? param : param.prefix;
|
|
1700
1720
|
const inner =
|
|
1701
1721
|
param.isWrapped() && param.wrappedInnerExpressions
|
|
1702
|
-
?
|
|
1722
|
+
? [
|
|
1723
|
+
...param.wrappedInnerExpressions,
|
|
1724
|
+
...innerExpressions.reverse()
|
|
1725
|
+
]
|
|
1703
1726
|
: innerExpressions.reverse();
|
|
1704
1727
|
return new BasicEvaluatedExpression()
|
|
1705
1728
|
.setWrapped(prefix, stringSuffix, inner)
|
|
@@ -1707,7 +1730,7 @@ class JavascriptParser extends Parser {
|
|
|
1707
1730
|
} else if (param.isWrapped()) {
|
|
1708
1731
|
const postfix = stringSuffix || param.postfix;
|
|
1709
1732
|
const inner = param.wrappedInnerExpressions
|
|
1710
|
-
? param.wrappedInnerExpressions
|
|
1733
|
+
? [...param.wrappedInnerExpressions, ...innerExpressions.reverse()]
|
|
1711
1734
|
: innerExpressions.reverse();
|
|
1712
1735
|
return new BasicEvaluatedExpression()
|
|
1713
1736
|
.setWrapped(param.prefix, postfix, inner)
|
|
@@ -1877,13 +1900,20 @@ class JavascriptParser extends Parser {
|
|
|
1877
1900
|
scopeParams.push(classy.id);
|
|
1878
1901
|
}
|
|
1879
1902
|
this.inClassScope(true, scopeParams, () => {
|
|
1880
|
-
for (const classElement of
|
|
1903
|
+
for (const classElement of classy.body.body) {
|
|
1881
1904
|
if (!this.hooks.classBodyElement.call(classElement, classy)) {
|
|
1882
|
-
if (classElement.
|
|
1883
|
-
this.
|
|
1884
|
-
|
|
1885
|
-
|
|
1905
|
+
if (classElement.type === "StaticBlock") {
|
|
1906
|
+
const wasTopLevel = this.scope.topLevelScope;
|
|
1907
|
+
this.scope.topLevelScope = false;
|
|
1908
|
+
this.walkBlockStatement(classElement);
|
|
1909
|
+
this.scope.topLevelScope = wasTopLevel;
|
|
1910
|
+
} else {
|
|
1911
|
+
if (classElement.computed && classElement.key) {
|
|
1912
|
+
this.walkExpression(classElement.key);
|
|
1913
|
+
}
|
|
1914
|
+
|
|
1886
1915
|
if (
|
|
1916
|
+
classElement.value &&
|
|
1887
1917
|
!this.hooks.classBodyValue.call(
|
|
1888
1918
|
classElement.value,
|
|
1889
1919
|
classElement,
|
|
@@ -1895,11 +1925,6 @@ class JavascriptParser extends Parser {
|
|
|
1895
1925
|
this.walkExpression(classElement.value);
|
|
1896
1926
|
this.scope.topLevelScope = wasTopLevel;
|
|
1897
1927
|
}
|
|
1898
|
-
} else if (classElement.type === "StaticBlock") {
|
|
1899
|
-
const wasTopLevel = this.scope.topLevelScope;
|
|
1900
|
-
this.scope.topLevelScope = false;
|
|
1901
|
-
this.walkBlockStatement(classElement);
|
|
1902
|
-
this.scope.topLevelScope = wasTopLevel;
|
|
1903
1928
|
}
|
|
1904
1929
|
}
|
|
1905
1930
|
}
|
|
@@ -1939,8 +1964,13 @@ class JavascriptParser extends Parser {
|
|
|
1939
1964
|
for (let index = 0, len = statements.length; index < len; index++) {
|
|
1940
1965
|
const statement = statements[index];
|
|
1941
1966
|
|
|
1942
|
-
if (
|
|
1967
|
+
if (
|
|
1968
|
+
onlyFunctionDeclaration &&
|
|
1969
|
+
statement.type !== "FunctionDeclaration" &&
|
|
1970
|
+
this.hooks.unusedStatement.call(/** @type {Statement} */ (statement))
|
|
1971
|
+
) {
|
|
1943
1972
|
continue;
|
|
1973
|
+
}
|
|
1944
1974
|
|
|
1945
1975
|
this.walkStatement(statement);
|
|
1946
1976
|
|
|
@@ -2144,7 +2174,7 @@ class JavascriptParser extends Parser {
|
|
|
2144
2174
|
}
|
|
2145
2175
|
|
|
2146
2176
|
/**
|
|
2147
|
-
* @param {BlockStatement} statement block statement
|
|
2177
|
+
* @param {BlockStatement | StaticBlock} statement block statement
|
|
2148
2178
|
*/
|
|
2149
2179
|
walkBlockStatement(statement) {
|
|
2150
2180
|
this.inBlockScope(() => {
|
|
@@ -2537,8 +2567,9 @@ class JavascriptParser extends Parser {
|
|
|
2537
2567
|
if (
|
|
2538
2568
|
expression.left.type !== "ObjectPattern" ||
|
|
2539
2569
|
!this.destructuringAssignmentProperties
|
|
2540
|
-
)
|
|
2570
|
+
) {
|
|
2541
2571
|
return;
|
|
2572
|
+
}
|
|
2542
2573
|
const keys = this._preWalkObjectPattern(expression.left);
|
|
2543
2574
|
if (!keys) return;
|
|
2544
2575
|
|
|
@@ -2808,16 +2839,19 @@ class JavascriptParser extends Parser {
|
|
|
2808
2839
|
*/
|
|
2809
2840
|
blockPreWalkVariableDeclaration(statement) {
|
|
2810
2841
|
if (statement.kind === "var") return;
|
|
2842
|
+
|
|
2811
2843
|
const hookMap =
|
|
2812
2844
|
statement.kind === "const"
|
|
2813
2845
|
? this.hooks.varDeclarationConst
|
|
2814
|
-
:
|
|
2846
|
+
: statement.kind === "using" || statement.kind === "await using"
|
|
2847
|
+
? this.hooks.varDeclarationUsing
|
|
2848
|
+
: this.hooks.varDeclarationLet;
|
|
2815
2849
|
this._preWalkVariableDeclaration(statement, hookMap);
|
|
2816
2850
|
}
|
|
2817
2851
|
|
|
2818
2852
|
/**
|
|
2819
2853
|
* @param {VariableDeclaration} statement variable declaration
|
|
2820
|
-
* @param {
|
|
2854
|
+
* @param {HookMap<SyncBailHook<[Identifier], boolean | void>>} hookMap map of hooks
|
|
2821
2855
|
*/
|
|
2822
2856
|
_preWalkVariableDeclaration(statement, hookMap) {
|
|
2823
2857
|
for (const declarator of statement.declarations) {
|
|
@@ -2825,11 +2859,11 @@ class JavascriptParser extends Parser {
|
|
|
2825
2859
|
case "VariableDeclarator": {
|
|
2826
2860
|
this.preWalkVariableDeclarator(declarator);
|
|
2827
2861
|
if (!this.hooks.preDeclarator.call(declarator, statement)) {
|
|
2828
|
-
this.enterPattern(declarator.id, (name,
|
|
2862
|
+
this.enterPattern(declarator.id, (name, ident) => {
|
|
2829
2863
|
let hook = hookMap.get(name);
|
|
2830
|
-
if (hook === undefined || !hook.call(
|
|
2864
|
+
if (hook === undefined || !hook.call(ident)) {
|
|
2831
2865
|
hook = this.hooks.varDeclaration.get(name);
|
|
2832
|
-
if (hook === undefined || !hook.call(
|
|
2866
|
+
if (hook === undefined || !hook.call(ident)) {
|
|
2833
2867
|
this.defineVariable(name);
|
|
2834
2868
|
}
|
|
2835
2869
|
}
|
|
@@ -2852,11 +2886,18 @@ class JavascriptParser extends Parser {
|
|
|
2852
2886
|
for (let i = 0; i < properties.length; i++) {
|
|
2853
2887
|
const property = properties[i];
|
|
2854
2888
|
if (property.type !== "Property") return;
|
|
2855
|
-
if (property.shorthand
|
|
2856
|
-
|
|
2889
|
+
if (property.shorthand) {
|
|
2890
|
+
if (property.value.type === "Identifier") {
|
|
2891
|
+
this.scope.inShorthand = property.value.name;
|
|
2892
|
+
} else if (
|
|
2893
|
+
property.value.type === "AssignmentPattern" &&
|
|
2894
|
+
property.value.left.type === "Identifier"
|
|
2895
|
+
) {
|
|
2896
|
+
this.scope.inShorthand = property.value.left.name;
|
|
2897
|
+
}
|
|
2857
2898
|
}
|
|
2858
2899
|
const key = property.key;
|
|
2859
|
-
if (key.type === "Identifier") {
|
|
2900
|
+
if (key.type === "Identifier" && !property.computed) {
|
|
2860
2901
|
props.add({
|
|
2861
2902
|
id: key.name,
|
|
2862
2903
|
range: key.range,
|
|
@@ -2890,8 +2931,9 @@ class JavascriptParser extends Parser {
|
|
|
2890
2931
|
!declarator.init ||
|
|
2891
2932
|
declarator.id.type !== "ObjectPattern" ||
|
|
2892
2933
|
!this.destructuringAssignmentProperties
|
|
2893
|
-
)
|
|
2934
|
+
) {
|
|
2894
2935
|
return;
|
|
2936
|
+
}
|
|
2895
2937
|
const keys = this._preWalkObjectPattern(declarator.id);
|
|
2896
2938
|
|
|
2897
2939
|
if (!keys) return;
|
|
@@ -3197,8 +3239,9 @@ class JavascriptParser extends Parser {
|
|
|
3197
3239
|
* @param {AwaitExpression} expression await expression
|
|
3198
3240
|
*/
|
|
3199
3241
|
walkAwaitExpression(expression) {
|
|
3200
|
-
if (this.scope.topLevelScope === true)
|
|
3242
|
+
if (this.scope.topLevelScope === true) {
|
|
3201
3243
|
this.hooks.topLevelAwait.call(expression);
|
|
3244
|
+
}
|
|
3202
3245
|
this.walkExpression(expression.argument);
|
|
3203
3246
|
}
|
|
3204
3247
|
|
|
@@ -3438,7 +3481,7 @@ class JavascriptParser extends Parser {
|
|
|
3438
3481
|
return;
|
|
3439
3482
|
}
|
|
3440
3483
|
this.walkExpression(expression.right);
|
|
3441
|
-
this.enterPattern(expression.left, (name,
|
|
3484
|
+
this.enterPattern(expression.left, (name, _decl) => {
|
|
3442
3485
|
if (!this.callHooksForName(this.hooks.assign, name, expression)) {
|
|
3443
3486
|
this.walkExpression(
|
|
3444
3487
|
/** @type {MemberExpression} */
|
|
@@ -3448,7 +3491,7 @@ class JavascriptParser extends Parser {
|
|
|
3448
3491
|
});
|
|
3449
3492
|
} else if (expression.left.type.endsWith("Pattern")) {
|
|
3450
3493
|
this.walkExpression(expression.right);
|
|
3451
|
-
this.enterPattern(expression.left, (name,
|
|
3494
|
+
this.enterPattern(expression.left, (name, _decl) => {
|
|
3452
3495
|
if (!this.callHooksForName(this.hooks.assign, name, expression)) {
|
|
3453
3496
|
this.defineVariable(name);
|
|
3454
3497
|
}
|
|
@@ -3751,8 +3794,9 @@ class JavascriptParser extends Parser {
|
|
|
3751
3794
|
if (expression.callee.type === "MemberExpression") {
|
|
3752
3795
|
// because of call context we need to walk the call context as expression
|
|
3753
3796
|
this.walkExpression(expression.callee.object);
|
|
3754
|
-
if (expression.callee.computed === true)
|
|
3797
|
+
if (expression.callee.computed === true) {
|
|
3755
3798
|
this.walkExpression(expression.callee.property);
|
|
3799
|
+
}
|
|
3756
3800
|
} else {
|
|
3757
3801
|
this.walkExpression(expression.callee);
|
|
3758
3802
|
}
|
|
@@ -3794,7 +3838,7 @@ class JavascriptParser extends Parser {
|
|
|
3794
3838
|
expression,
|
|
3795
3839
|
exprInfo.name,
|
|
3796
3840
|
exprInfo.rootInfo,
|
|
3797
|
-
members
|
|
3841
|
+
[...members],
|
|
3798
3842
|
() =>
|
|
3799
3843
|
this.callHooksForInfo(
|
|
3800
3844
|
this.hooks.unhandledExpressionMemberChain,
|
|
@@ -3914,7 +3958,7 @@ class JavascriptParser extends Parser {
|
|
|
3914
3958
|
* @template R
|
|
3915
3959
|
* @param {HookMap<SyncBailHook<T, R>>} hookMap hooks the should be called
|
|
3916
3960
|
* @param {Expression | Super} expr expression info
|
|
3917
|
-
* @param {((name: string, rootInfo: string | ScopeInfo | VariableInfo, getMembers: () => string[]) =>
|
|
3961
|
+
* @param {((name: string, rootInfo: string | ScopeInfo | VariableInfo, getMembers: () => string[]) => R) | undefined} fallback callback when variable in not handled by hooks
|
|
3918
3962
|
* @param {((result?: string) => R | undefined) | undefined} defined callback when variable is defined
|
|
3919
3963
|
* @param {AsArray<T>} args args for the hook
|
|
3920
3964
|
* @returns {R | undefined} result of hook
|
|
@@ -3984,7 +4028,7 @@ class JavascriptParser extends Parser {
|
|
|
3984
4028
|
* @template R
|
|
3985
4029
|
* @param {HookMap<SyncBailHook<T, R>>} hookMap hooks the should be called
|
|
3986
4030
|
* @param {ExportedVariableInfo} info variable info
|
|
3987
|
-
* @param {((name: string) =>
|
|
4031
|
+
* @param {((name: string) => R | undefined) | undefined} fallback callback when variable in not handled by hooks
|
|
3988
4032
|
* @param {((result?: string) => TODO) | undefined} defined callback when variable is defined
|
|
3989
4033
|
* @param {AsArray<T>} args args for the hook
|
|
3990
4034
|
* @returns {R | undefined} result of hook
|
|
@@ -4351,9 +4395,11 @@ class JavascriptParser extends Parser {
|
|
|
4351
4395
|
);
|
|
4352
4396
|
}
|
|
4353
4397
|
|
|
4398
|
+
/** @typedef {{ range?: Range, value: string, code: boolean, conditional: false | CalculatedStringResult[] }} CalculatedStringResult */
|
|
4399
|
+
|
|
4354
4400
|
/**
|
|
4355
4401
|
* @param {Expression} expression expression
|
|
4356
|
-
* @returns {
|
|
4402
|
+
* @returns {CalculatedStringResult} result
|
|
4357
4403
|
*/
|
|
4358
4404
|
parseCalculatedString(expression) {
|
|
4359
4405
|
switch (expression.type) {
|
|
@@ -4401,6 +4447,7 @@ class JavascriptParser extends Parser {
|
|
|
4401
4447
|
case "ConditionalExpression": {
|
|
4402
4448
|
const consequent = this.parseCalculatedString(expression.consequent);
|
|
4403
4449
|
const alternate = this.parseCalculatedString(expression.alternate);
|
|
4450
|
+
/** @type {CalculatedStringResult[]} */
|
|
4404
4451
|
const items = [];
|
|
4405
4452
|
if (consequent.conditional) {
|
|
4406
4453
|
items.push(...consequent.conditional);
|
|
@@ -4453,7 +4500,7 @@ class JavascriptParser extends Parser {
|
|
|
4453
4500
|
throw new Error("source must not be null");
|
|
4454
4501
|
}
|
|
4455
4502
|
if (Buffer.isBuffer(source)) {
|
|
4456
|
-
source = source.toString("
|
|
4503
|
+
source = source.toString("utf8");
|
|
4457
4504
|
}
|
|
4458
4505
|
if (typeof source === "object") {
|
|
4459
4506
|
ast = /** @type {Program} */ (source);
|
|
@@ -4552,14 +4599,20 @@ class JavascriptParser extends Parser {
|
|
|
4552
4599
|
) {
|
|
4553
4600
|
return false;
|
|
4554
4601
|
}
|
|
4555
|
-
const items =
|
|
4556
|
-
/** @type {TODO[]} */
|
|
4557
|
-
(expr.body.body);
|
|
4602
|
+
const items = expr.body.body;
|
|
4558
4603
|
return items.every(item => {
|
|
4604
|
+
if (item.type === "StaticBlock") {
|
|
4605
|
+
return false;
|
|
4606
|
+
}
|
|
4607
|
+
|
|
4559
4608
|
if (
|
|
4560
4609
|
item.computed &&
|
|
4561
4610
|
item.key &&
|
|
4562
|
-
!this.isPure(
|
|
4611
|
+
!this.isPure(
|
|
4612
|
+
item.key,
|
|
4613
|
+
/** @type {Range} */
|
|
4614
|
+
(item.range)[0]
|
|
4615
|
+
)
|
|
4563
4616
|
) {
|
|
4564
4617
|
return false;
|
|
4565
4618
|
}
|
|
@@ -4569,16 +4622,14 @@ class JavascriptParser extends Parser {
|
|
|
4569
4622
|
item.value &&
|
|
4570
4623
|
!this.isPure(
|
|
4571
4624
|
item.value,
|
|
4572
|
-
item.key
|
|
4625
|
+
item.key
|
|
4626
|
+
? /** @type {Range} */ (item.key.range)[1]
|
|
4627
|
+
: /** @type {Range} */ (item.range)[0]
|
|
4573
4628
|
)
|
|
4574
4629
|
) {
|
|
4575
4630
|
return false;
|
|
4576
4631
|
}
|
|
4577
4632
|
|
|
4578
|
-
if (item.type === "StaticBlock") {
|
|
4579
|
-
return false;
|
|
4580
|
-
}
|
|
4581
|
-
|
|
4582
4633
|
if (
|
|
4583
4634
|
expr.superClass &&
|
|
4584
4635
|
item.type === "MethodDefinition" &&
|
|
@@ -4802,8 +4853,12 @@ class JavascriptParser extends Parser {
|
|
|
4802
4853
|
defineVariable(name) {
|
|
4803
4854
|
const oldInfo = this.scope.definitions.get(name);
|
|
4804
4855
|
// Don't redefine variable in same scope to keep existing tags
|
|
4805
|
-
if (
|
|
4856
|
+
if (
|
|
4857
|
+
oldInfo instanceof VariableInfo &&
|
|
4858
|
+
oldInfo.declaredScope === this.scope
|
|
4859
|
+
) {
|
|
4806
4860
|
return;
|
|
4861
|
+
}
|
|
4807
4862
|
this.scope.definitions.set(name, this.scope);
|
|
4808
4863
|
}
|
|
4809
4864
|
|
|
@@ -5084,9 +5139,9 @@ class JavascriptParser extends Parser {
|
|
|
5084
5139
|
|
|
5085
5140
|
module.exports = JavascriptParser;
|
|
5086
5141
|
module.exports.ALLOWED_MEMBER_TYPES_ALL = ALLOWED_MEMBER_TYPES_ALL;
|
|
5087
|
-
module.exports.ALLOWED_MEMBER_TYPES_EXPRESSION =
|
|
5088
|
-
ALLOWED_MEMBER_TYPES_EXPRESSION;
|
|
5089
5142
|
module.exports.ALLOWED_MEMBER_TYPES_CALL_EXPRESSION =
|
|
5090
5143
|
ALLOWED_MEMBER_TYPES_CALL_EXPRESSION;
|
|
5091
|
-
module.exports.
|
|
5144
|
+
module.exports.ALLOWED_MEMBER_TYPES_EXPRESSION =
|
|
5145
|
+
ALLOWED_MEMBER_TYPES_EXPRESSION;
|
|
5092
5146
|
module.exports.VariableInfo = VariableInfo;
|
|
5147
|
+
module.exports.getImportAttributes = getImportAttributes;
|
|
@@ -15,46 +15,7 @@ const BasicEvaluatedExpression = require("./BasicEvaluatedExpression");
|
|
|
15
15
|
/** @typedef {import("./JavascriptParser")} JavascriptParser */
|
|
16
16
|
/** @typedef {import("./JavascriptParser").Range} Range */
|
|
17
17
|
|
|
18
|
-
|
|
19
|
-
* @param {JavascriptParser} parser the parser
|
|
20
|
-
* @param {string} value the const value
|
|
21
|
-
* @param {(string[] | null)=} runtimeRequirements runtime requirements
|
|
22
|
-
* @returns {(expression: Expression) => true} plugin function
|
|
23
|
-
*/
|
|
24
|
-
module.exports.toConstantDependency = (parser, value, runtimeRequirements) =>
|
|
25
|
-
function constDependency(expr) {
|
|
26
|
-
const dep = new ConstDependency(
|
|
27
|
-
value,
|
|
28
|
-
/** @type {Range} */
|
|
29
|
-
(expr.range),
|
|
30
|
-
runtimeRequirements
|
|
31
|
-
);
|
|
32
|
-
dep.loc = /** @type {SourceLocation} */ (expr.loc);
|
|
33
|
-
parser.state.module.addPresentationalDependency(dep);
|
|
34
|
-
return true;
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* @param {string} value the string value
|
|
39
|
-
* @returns {(expression: Expression) => BasicEvaluatedExpression} plugin function
|
|
40
|
-
*/
|
|
41
|
-
module.exports.evaluateToString = value =>
|
|
42
|
-
function stringExpression(expr) {
|
|
43
|
-
return new BasicEvaluatedExpression()
|
|
44
|
-
.setString(value)
|
|
45
|
-
.setRange(/** @type {Range} */ (expr.range));
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* @param {number} value the number value
|
|
50
|
-
* @returns {(expression: Expression) => BasicEvaluatedExpression} plugin function
|
|
51
|
-
*/
|
|
52
|
-
module.exports.evaluateToNumber = value =>
|
|
53
|
-
function stringExpression(expr) {
|
|
54
|
-
return new BasicEvaluatedExpression()
|
|
55
|
-
.setNumber(value)
|
|
56
|
-
.setRange(/** @type {Range} */ (expr.range));
|
|
57
|
-
};
|
|
18
|
+
module.exports.approve = () => true;
|
|
58
19
|
|
|
59
20
|
/**
|
|
60
21
|
* @param {boolean} value the boolean value
|
|
@@ -100,6 +61,28 @@ module.exports.evaluateToIdentifier = (
|
|
|
100
61
|
return evaluatedExpression;
|
|
101
62
|
};
|
|
102
63
|
|
|
64
|
+
/**
|
|
65
|
+
* @param {number} value the number value
|
|
66
|
+
* @returns {(expression: Expression) => BasicEvaluatedExpression} plugin function
|
|
67
|
+
*/
|
|
68
|
+
module.exports.evaluateToNumber = value =>
|
|
69
|
+
function stringExpression(expr) {
|
|
70
|
+
return new BasicEvaluatedExpression()
|
|
71
|
+
.setNumber(value)
|
|
72
|
+
.setRange(/** @type {Range} */ (expr.range));
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* @param {string} value the string value
|
|
77
|
+
* @returns {(expression: Expression) => BasicEvaluatedExpression} plugin function
|
|
78
|
+
*/
|
|
79
|
+
module.exports.evaluateToString = value =>
|
|
80
|
+
function stringExpression(expr) {
|
|
81
|
+
return new BasicEvaluatedExpression()
|
|
82
|
+
.setString(value)
|
|
83
|
+
.setRange(/** @type {Range} */ (expr.range));
|
|
84
|
+
};
|
|
85
|
+
|
|
103
86
|
/**
|
|
104
87
|
* @param {JavascriptParser} parser the parser
|
|
105
88
|
* @param {string} message the message
|
|
@@ -126,4 +109,21 @@ module.exports.expressionIsUnsupported = (parser, message) =>
|
|
|
126
109
|
|
|
127
110
|
module.exports.skipTraversal = () => true;
|
|
128
111
|
|
|
129
|
-
|
|
112
|
+
/**
|
|
113
|
+
* @param {JavascriptParser} parser the parser
|
|
114
|
+
* @param {string} value the const value
|
|
115
|
+
* @param {(string[] | null)=} runtimeRequirements runtime requirements
|
|
116
|
+
* @returns {(expression: Expression) => true} plugin function
|
|
117
|
+
*/
|
|
118
|
+
module.exports.toConstantDependency = (parser, value, runtimeRequirements) =>
|
|
119
|
+
function constDependency(expr) {
|
|
120
|
+
const dep = new ConstDependency(
|
|
121
|
+
value,
|
|
122
|
+
/** @type {Range} */
|
|
123
|
+
(expr.range),
|
|
124
|
+
runtimeRequirements
|
|
125
|
+
);
|
|
126
|
+
dep.loc = /** @type {SourceLocation} */ (expr.loc);
|
|
127
|
+
parser.state.module.addPresentationalDependency(dep);
|
|
128
|
+
return true;
|
|
129
|
+
};
|