webpack 5.59.0 → 5.76.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 +22 -24
- package/bin/webpack.js +0 -0
- package/hot/dev-server.js +17 -4
- package/hot/lazy-compilation-node.js +3 -1
- package/hot/poll.js +1 -1
- package/hot/signal.js +1 -1
- package/lib/APIPlugin.js +33 -0
- package/lib/BannerPlugin.js +13 -5
- package/lib/Cache.js +1 -1
- package/lib/CacheFacade.js +4 -11
- package/lib/Chunk.js +6 -3
- package/lib/ChunkGraph.js +94 -8
- package/lib/ChunkGroup.js +1 -1
- package/lib/CleanPlugin.js +81 -20
- package/lib/Compilation.js +188 -93
- package/lib/Compiler.js +87 -18
- package/lib/ConstPlugin.js +2 -2
- package/lib/ContextModule.js +142 -51
- package/lib/ContextModuleFactory.js +65 -25
- package/lib/DelegatedModule.js +1 -1
- package/lib/DelegatedModuleFactoryPlugin.js +1 -1
- package/lib/Dependency.js +17 -0
- package/lib/DependencyTemplate.js +9 -0
- package/lib/DependencyTemplates.js +1 -1
- package/lib/DllModule.js +1 -1
- package/lib/DllReferencePlugin.js +1 -1
- package/lib/EntryOptionPlugin.js +2 -0
- package/lib/ErrorHelpers.js +2 -2
- package/lib/EvalDevToolModulePlugin.js +16 -1
- package/lib/EvalSourceMapDevToolPlugin.js +25 -4
- package/lib/ExportsInfo.js +5 -5
- package/lib/ExternalModule.js +94 -54
- package/lib/ExternalModuleFactoryPlugin.js +5 -5
- package/lib/FileSystemInfo.js +124 -58
- package/lib/Generator.js +3 -0
- package/lib/HookWebpackError.js +1 -1
- package/lib/HotModuleReplacementPlugin.js +3 -1
- package/lib/LoaderOptionsPlugin.js +1 -1
- package/lib/Module.js +28 -4
- package/lib/ModuleFilenameHelpers.js +8 -4
- package/lib/ModuleHashingError.js +29 -0
- package/lib/MultiCompiler.js +1 -1
- package/lib/MultiWatching.js +1 -1
- package/lib/NodeStuffPlugin.js +13 -3
- package/lib/NormalModule.js +51 -33
- package/lib/NormalModuleFactory.js +42 -37
- package/lib/ProgressPlugin.js +4 -5
- package/lib/RawModule.js +1 -1
- package/lib/RuntimeGlobals.js +29 -1
- package/lib/RuntimeModule.js +1 -1
- package/lib/RuntimePlugin.js +84 -1
- package/lib/RuntimeTemplate.js +114 -2
- package/lib/Template.js +3 -2
- package/lib/TemplatedPathPlugin.js +48 -23
- package/lib/WatchIgnorePlugin.js +19 -7
- package/lib/Watching.js +33 -19
- package/lib/WebpackOptionsApply.js +79 -11
- package/lib/asset/AssetGenerator.js +228 -71
- package/lib/asset/AssetModulesPlugin.js +3 -0
- package/lib/asset/AssetParser.js +1 -0
- package/lib/asset/AssetSourceGenerator.js +31 -6
- package/lib/asset/AssetSourceParser.js +1 -0
- package/lib/asset/RawDataUrlModule.js +148 -0
- package/lib/async-modules/AwaitDependenciesInitFragment.js +4 -4
- package/lib/buildChunkGraph.js +38 -7
- package/lib/cache/PackFileCacheStrategy.js +15 -8
- package/lib/cache/ResolverCachePlugin.js +90 -29
- package/lib/cli.js +44 -3
- package/lib/config/browserslistTargetHandler.js +41 -6
- package/lib/config/defaults.js +123 -19
- package/lib/config/normalization.js +10 -2
- package/lib/config/target.js +10 -0
- package/lib/container/ContainerEntryModule.js +8 -5
- package/lib/container/FallbackModule.js +4 -4
- package/lib/container/ModuleFederationPlugin.js +2 -0
- package/lib/container/RemoteModule.js +4 -2
- package/lib/container/RemoteRuntimeModule.js +8 -7
- package/lib/css/CssExportsGenerator.js +139 -0
- package/lib/css/CssGenerator.js +109 -0
- package/lib/css/CssLoadingRuntimeModule.js +442 -0
- package/lib/css/CssModulesPlugin.js +462 -0
- package/lib/css/CssParser.js +618 -0
- package/lib/css/walkCssTokens.js +659 -0
- package/lib/debug/ProfilingPlugin.js +24 -21
- package/lib/dependencies/AMDRequireDependency.js +6 -6
- package/lib/dependencies/CommonJsExportsParserPlugin.js +1 -2
- package/lib/dependencies/CommonJsFullRequireDependency.js +5 -1
- package/lib/dependencies/CommonJsImportsParserPlugin.js +344 -61
- package/lib/dependencies/CommonJsRequireContextDependency.js +6 -2
- package/lib/dependencies/CommonJsRequireDependency.js +2 -1
- package/lib/dependencies/ContextDependency.js +16 -2
- package/lib/dependencies/ContextDependencyHelpers.js +21 -8
- package/lib/dependencies/ContextDependencyTemplateAsRequireCall.js +4 -1
- package/lib/dependencies/ContextElementDependency.js +25 -3
- package/lib/dependencies/CreateScriptUrlDependency.js +12 -0
- package/lib/dependencies/CssExportDependency.js +85 -0
- package/lib/dependencies/CssImportDependency.js +75 -0
- package/lib/dependencies/CssLocalIdentifierDependency.js +119 -0
- package/lib/dependencies/CssSelfLocalIdentifierDependency.js +101 -0
- package/lib/dependencies/CssUrlDependency.js +132 -0
- package/lib/dependencies/ExportsInfoDependency.js +6 -0
- package/lib/dependencies/HarmonyAcceptImportDependency.js +5 -3
- package/lib/dependencies/HarmonyCompatibilityDependency.js +5 -5
- package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +127 -0
- package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +12 -3
- package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +25 -17
- package/lib/dependencies/HarmonyExportInitFragment.js +4 -1
- package/lib/dependencies/HarmonyImportDependency.js +23 -0
- package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +142 -45
- package/lib/dependencies/HarmonyImportSpecifierDependency.js +46 -22
- package/lib/dependencies/HarmonyModulesPlugin.js +10 -0
- package/lib/dependencies/ImportContextDependency.js +0 -2
- package/lib/dependencies/ImportMetaContextDependency.js +35 -0
- package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +252 -0
- package/lib/dependencies/ImportMetaContextPlugin.js +59 -0
- package/lib/dependencies/ImportMetaPlugin.js +22 -3
- package/lib/dependencies/ImportParserPlugin.js +35 -29
- package/lib/dependencies/JsonExportsDependency.js +17 -21
- package/lib/dependencies/LoaderDependency.js +13 -0
- package/lib/dependencies/LoaderImportDependency.js +13 -0
- package/lib/dependencies/LoaderPlugin.js +4 -2
- package/lib/dependencies/ModuleDependency.js +11 -1
- package/lib/dependencies/ProvidedDependency.js +31 -8
- package/lib/dependencies/RequireContextDependency.js +0 -16
- package/lib/dependencies/RequireEnsureDependency.js +2 -2
- package/lib/dependencies/RequireResolveContextDependency.js +2 -2
- package/lib/dependencies/RequireResolveDependency.js +2 -1
- package/lib/dependencies/URLDependency.js +3 -8
- package/lib/dependencies/URLPlugin.js +22 -1
- package/lib/dependencies/WorkerPlugin.js +2 -0
- package/lib/esm/ModuleChunkFormatPlugin.js +74 -49
- package/lib/esm/ModuleChunkLoadingPlugin.js +3 -1
- package/lib/esm/ModuleChunkLoadingRuntimeModule.js +25 -9
- package/lib/hmr/HotModuleReplacement.runtime.js +29 -14
- package/lib/hmr/JavascriptHotModuleReplacement.runtime.js +4 -3
- package/lib/hmr/LazyCompilationPlugin.js +54 -26
- package/lib/hmr/lazyCompilationBackend.js +51 -12
- package/lib/ids/DeterministicModuleIdsPlugin.js +55 -35
- package/lib/ids/HashedModuleIdsPlugin.js +11 -14
- package/lib/ids/IdHelpers.js +26 -12
- package/lib/ids/NamedModuleIdsPlugin.js +6 -9
- package/lib/ids/NaturalModuleIdsPlugin.js +10 -13
- package/lib/ids/OccurrenceModuleIdsPlugin.js +13 -10
- package/lib/ids/SyncModuleIdsPlugin.js +140 -0
- package/lib/index.js +20 -0
- package/lib/javascript/ArrayPushCallbackChunkFormatPlugin.js +2 -2
- package/lib/javascript/BasicEvaluatedExpression.js +5 -2
- package/lib/javascript/ChunkHelpers.js +33 -0
- package/lib/javascript/JavascriptGenerator.js +1 -0
- package/lib/javascript/JavascriptModulesPlugin.js +27 -2
- package/lib/javascript/JavascriptParser.js +143 -73
- package/lib/javascript/StartupHelpers.js +7 -30
- package/lib/json/JsonData.js +8 -0
- package/lib/json/JsonParser.js +4 -6
- package/lib/library/AssignLibraryPlugin.js +39 -15
- package/lib/library/EnableLibraryPlugin.js +11 -0
- package/lib/library/UmdLibraryPlugin.js +5 -3
- package/lib/node/NodeTargetPlugin.js +3 -0
- package/lib/node/NodeWatchFileSystem.js +85 -31
- package/lib/node/ReadFileChunkLoadingRuntimeModule.js +23 -8
- package/lib/node/RequireChunkLoadingRuntimeModule.js +24 -9
- package/lib/optimize/ConcatenatedModule.js +62 -26
- package/lib/optimize/ModuleConcatenationPlugin.js +26 -4
- package/lib/optimize/RealContentHashPlugin.js +45 -15
- package/lib/optimize/SplitChunksPlugin.js +8 -1
- package/lib/runtime/AsyncModuleRuntimeModule.js +50 -66
- package/lib/runtime/BaseUriRuntimeModule.js +31 -0
- package/lib/runtime/CreateScriptRuntimeModule.js +36 -0
- package/lib/runtime/CreateScriptUrlRuntimeModule.js +9 -34
- package/lib/runtime/GetTrustedTypesPolicyRuntimeModule.js +76 -0
- package/lib/runtime/LoadScriptRuntimeModule.js +11 -9
- package/lib/runtime/NonceRuntimeModule.js +24 -0
- package/lib/schemes/HttpUriPlugin.js +77 -14
- package/lib/serialization/FileMiddleware.js +44 -9
- package/lib/sharing/ConsumeSharedModule.js +8 -2
- package/lib/sharing/ConsumeSharedRuntimeModule.js +26 -5
- package/lib/sharing/ProvideSharedModule.js +4 -2
- package/lib/sharing/ProvideSharedPlugin.js +1 -2
- package/lib/sharing/ShareRuntimeModule.js +1 -1
- package/lib/sharing/utils.js +1 -1
- package/lib/stats/DefaultStatsFactoryPlugin.js +113 -68
- package/lib/stats/DefaultStatsPrinterPlugin.js +90 -25
- package/lib/util/ArrayHelpers.js +30 -0
- package/lib/util/AsyncQueue.js +1 -1
- package/lib/util/compileBooleanMatcher.js +1 -1
- package/lib/util/create-schema-validation.js +9 -2
- package/lib/util/createHash.js +12 -0
- package/lib/util/deprecation.js +10 -2
- package/lib/util/deterministicGrouping.js +1 -1
- package/lib/util/extractUrlAndGlobal.js +3 -0
- package/lib/util/fs.js +11 -0
- package/lib/util/hash/BatchedHash.js +7 -4
- package/lib/util/hash/md4.js +20 -0
- package/lib/util/hash/wasm-hash.js +163 -0
- package/lib/util/hash/xxhash64.js +5 -139
- package/lib/util/identifier.js +65 -44
- package/lib/util/internalSerializables.js +15 -0
- package/lib/util/nonNumericOnlyHash.js +22 -0
- package/lib/util/semver.js +17 -10
- package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +9 -3
- package/lib/wasm-sync/WebAssemblyParser.js +1 -1
- package/lib/web/JsonpChunkLoadingRuntimeModule.js +31 -18
- package/lib/webpack.js +10 -3
- package/lib/webworker/ImportScriptsChunkLoadingPlugin.js +3 -11
- package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +33 -22
- package/module.d.ts +215 -0
- package/package.json +28 -32
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +321 -30
- package/schemas/plugins/BannerPlugin.check.js +1 -1
- package/schemas/plugins/BannerPlugin.json +4 -0
- package/schemas/plugins/DllReferencePlugin.check.js +1 -1
- package/schemas/plugins/HashedModuleIdsPlugin.check.js +1 -1
- package/schemas/plugins/ProgressPlugin.check.js +1 -1
- package/schemas/plugins/asset/AssetGeneratorOptions.check.js +1 -1
- package/schemas/plugins/asset/AssetParserOptions.check.js +1 -1
- package/schemas/plugins/asset/AssetResourceGeneratorOptions.check.js +1 -1
- package/schemas/plugins/container/ContainerPlugin.check.js +1 -1
- package/schemas/plugins/container/ContainerPlugin.json +2 -1
- package/schemas/plugins/container/ContainerReferencePlugin.check.js +1 -1
- package/schemas/plugins/container/ContainerReferencePlugin.json +1 -0
- package/schemas/plugins/container/ExternalsType.check.js +1 -1
- package/schemas/plugins/container/ModuleFederationPlugin.check.js +1 -1
- package/schemas/plugins/container/ModuleFederationPlugin.json +3 -1
- package/schemas/plugins/css/CssGeneratorOptions.check.d.ts +7 -0
- package/schemas/plugins/css/CssGeneratorOptions.check.js +6 -0
- package/schemas/plugins/css/CssGeneratorOptions.json +3 -0
- package/schemas/plugins/css/CssParserOptions.check.d.ts +7 -0
- package/schemas/plugins/css/CssParserOptions.check.js +6 -0
- package/schemas/plugins/css/CssParserOptions.json +3 -0
- package/schemas/plugins/optimize/AggressiveSplittingPlugin.check.js +1 -1
- package/schemas/plugins/optimize/LimitChunkCountPlugin.check.js +1 -1
- package/schemas/plugins/optimize/MinChunkSizePlugin.check.js +1 -1
- package/schemas/plugins/schemes/HttpUriPlugin.check.js +1 -1
- package/schemas/plugins/schemes/HttpUriPlugin.json +4 -0
- package/types.d.ts +869 -296
@@ -0,0 +1,33 @@
|
|
1
|
+
/*
|
2
|
+
MIT License http://www.opensource.org/licenses/mit-license.php
|
3
|
+
Author Tobias Koppers @sokra
|
4
|
+
*/
|
5
|
+
|
6
|
+
"use strict";
|
7
|
+
|
8
|
+
const Entrypoint = require("../Entrypoint");
|
9
|
+
|
10
|
+
/** @typedef {import("../Chunk")} Chunk */
|
11
|
+
|
12
|
+
/**
|
13
|
+
* @param {Entrypoint} entrypoint a chunk group
|
14
|
+
* @param {Chunk} excludedChunk1 current chunk which is excluded
|
15
|
+
* @param {Chunk} excludedChunk2 runtime chunk which is excluded
|
16
|
+
* @returns {Set<Chunk>} chunks
|
17
|
+
*/
|
18
|
+
const getAllChunks = (entrypoint, excludedChunk1, excludedChunk2) => {
|
19
|
+
const queue = new Set([entrypoint]);
|
20
|
+
const chunks = new Set();
|
21
|
+
for (const entrypoint of queue) {
|
22
|
+
for (const chunk of entrypoint.chunks) {
|
23
|
+
if (chunk === excludedChunk1) continue;
|
24
|
+
if (chunk === excludedChunk2) continue;
|
25
|
+
chunks.add(chunk);
|
26
|
+
}
|
27
|
+
for (const parent of entrypoint.parentsIterable) {
|
28
|
+
if (parent instanceof Entrypoint) queue.add(parent);
|
29
|
+
}
|
30
|
+
}
|
31
|
+
return chunks;
|
32
|
+
};
|
33
|
+
exports.getAllChunks = getAllChunks;
|
@@ -199,6 +199,7 @@ class JavascriptGenerator extends Generator {
|
|
199
199
|
runtime: generateContext.runtime,
|
200
200
|
runtimeRequirements: generateContext.runtimeRequirements,
|
201
201
|
concatenationScope: generateContext.concatenationScope,
|
202
|
+
codeGenerationResults: generateContext.codeGenerationResults,
|
202
203
|
initFragments
|
203
204
|
};
|
204
205
|
|
@@ -24,6 +24,7 @@ const { last, someInIterable } = require("../util/IterableHelpers");
|
|
24
24
|
const StringXor = require("../util/StringXor");
|
25
25
|
const { compareModulesByIdentifier } = require("../util/comparators");
|
26
26
|
const createHash = require("../util/createHash");
|
27
|
+
const nonNumericOnlyHash = require("../util/nonNumericOnlyHash");
|
27
28
|
const { intersectRuntime } = require("../util/runtime");
|
28
29
|
const JavascriptGenerator = require("./JavascriptGenerator");
|
29
30
|
const JavascriptParser = require("./JavascriptParser");
|
@@ -102,6 +103,7 @@ const printGeneratedCodeForStack = (module, code) => {
|
|
102
103
|
/**
|
103
104
|
* @typedef {Object} RenderBootstrapContext
|
104
105
|
* @property {Chunk} chunk the chunk
|
106
|
+
* @property {CodeGenerationResults} codeGenerationResults results of code generation
|
105
107
|
* @property {RuntimeTemplate} runtimeTemplate the runtime template
|
106
108
|
* @property {ModuleGraph} moduleGraph the module graph
|
107
109
|
* @property {ChunkGraph} chunkGraph the chunk graph
|
@@ -331,6 +333,7 @@ class JavascriptModulesPlugin {
|
|
331
333
|
{
|
332
334
|
hash: "0000",
|
333
335
|
chunk,
|
336
|
+
codeGenerationResults: context.codeGenerationResults,
|
334
337
|
chunkGraph: context.chunkGraph,
|
335
338
|
moduleGraph: context.moduleGraph,
|
336
339
|
runtimeTemplate: context.runtimeTemplate
|
@@ -343,6 +346,7 @@ class JavascriptModulesPlugin {
|
|
343
346
|
compilation.hooks.contentHash.tap("JavascriptModulesPlugin", chunk => {
|
344
347
|
const {
|
345
348
|
chunkGraph,
|
349
|
+
codeGenerationResults,
|
346
350
|
moduleGraph,
|
347
351
|
runtimeTemplate,
|
348
352
|
outputOptions: {
|
@@ -360,6 +364,7 @@ class JavascriptModulesPlugin {
|
|
360
364
|
{
|
361
365
|
hash: "0000",
|
362
366
|
chunk,
|
367
|
+
codeGenerationResults,
|
363
368
|
chunkGraph: compilation.chunkGraph,
|
364
369
|
moduleGraph: compilation.moduleGraph,
|
365
370
|
runtimeTemplate: compilation.runtimeTemplate
|
@@ -372,6 +377,7 @@ class JavascriptModulesPlugin {
|
|
372
377
|
}
|
373
378
|
hooks.chunkHash.call(chunk, hash, {
|
374
379
|
chunkGraph,
|
380
|
+
codeGenerationResults,
|
375
381
|
moduleGraph,
|
376
382
|
runtimeTemplate
|
377
383
|
});
|
@@ -398,7 +404,10 @@ class JavascriptModulesPlugin {
|
|
398
404
|
xor.updateHash(hash);
|
399
405
|
}
|
400
406
|
const digest = /** @type {string} */ (hash.digest(hashDigest));
|
401
|
-
chunk.contentHash.javascript =
|
407
|
+
chunk.contentHash.javascript = nonNumericOnlyHash(
|
408
|
+
digest,
|
409
|
+
hashDigestLength
|
410
|
+
);
|
402
411
|
});
|
403
412
|
compilation.hooks.additionalTreeRuntimeRequirements.tap(
|
404
413
|
"JavascriptModulesPlugin",
|
@@ -974,7 +983,13 @@ class JavascriptModulesPlugin {
|
|
974
983
|
* @returns {{ header: string[], beforeStartup: string[], startup: string[], afterStartup: string[], allowInlineStartup: boolean }} the generated source of the bootstrap code
|
975
984
|
*/
|
976
985
|
renderBootstrap(renderContext, hooks) {
|
977
|
-
const {
|
986
|
+
const {
|
987
|
+
chunkGraph,
|
988
|
+
codeGenerationResults,
|
989
|
+
moduleGraph,
|
990
|
+
chunk,
|
991
|
+
runtimeTemplate
|
992
|
+
} = renderContext;
|
978
993
|
|
979
994
|
const runtimeRequirements = chunkGraph.getTreeRuntimeRequirements(chunk);
|
980
995
|
|
@@ -1098,8 +1113,18 @@ class JavascriptModulesPlugin {
|
|
1098
1113
|
);
|
1099
1114
|
result.allowInlineStartup = false;
|
1100
1115
|
}
|
1116
|
+
|
1117
|
+
let data;
|
1118
|
+
if (codeGenerationResults.has(entryModule, chunk.runtime)) {
|
1119
|
+
const result = codeGenerationResults.get(
|
1120
|
+
entryModule,
|
1121
|
+
chunk.runtime
|
1122
|
+
);
|
1123
|
+
data = result.data;
|
1124
|
+
}
|
1101
1125
|
if (
|
1102
1126
|
result.allowInlineStartup &&
|
1127
|
+
(!data || !data.get("topLevelDeclarations")) &&
|
1103
1128
|
(!entryModule.buildInfo ||
|
1104
1129
|
!entryModule.buildInfo.topLevelDeclarations)
|
1105
1130
|
) {
|
@@ -57,7 +57,7 @@ const BasicEvaluatedExpression = require("./BasicEvaluatedExpression");
|
|
57
57
|
/** @typedef {import("../Parser").ParserState} ParserState */
|
58
58
|
/** @typedef {import("../Parser").PreparsedAst} PreparsedAst */
|
59
59
|
/** @typedef {{declaredScope: ScopeInfo, freeName: string | true, tagInfo: TagInfo | undefined}} VariableInfoInterface */
|
60
|
-
/** @typedef {{ name: string | VariableInfo, rootInfo: string | VariableInfo, getMembers: () => string[] }} GetInfoResult */
|
60
|
+
/** @typedef {{ name: string | VariableInfo, rootInfo: string | VariableInfo, getMembers: () => string[], getMembersOptionals: () => boolean[] }} GetInfoResult */
|
61
61
|
|
62
62
|
const EMPTY_ARRAY = [];
|
63
63
|
const ALLOWED_MEMBER_TYPES_CALL_EXPRESSION = 0b01;
|
@@ -165,6 +165,14 @@ class JavascriptParser extends Parser {
|
|
165
165
|
evaluateDefinedIdentifier: new HookMap(
|
166
166
|
() => new SyncBailHook(["expression"])
|
167
167
|
),
|
168
|
+
/** @type {HookMap<SyncBailHook<[NewExpressionNode], BasicEvaluatedExpression | undefined | null>>} */
|
169
|
+
evaluateNewExpression: new HookMap(
|
170
|
+
() => new SyncBailHook(["expression"])
|
171
|
+
),
|
172
|
+
/** @type {HookMap<SyncBailHook<[CallExpressionNode], BasicEvaluatedExpression | undefined | null>>} */
|
173
|
+
evaluateCallExpression: new HookMap(
|
174
|
+
() => new SyncBailHook(["expression"])
|
175
|
+
),
|
168
176
|
/** @type {HookMap<SyncBailHook<[CallExpressionNode, BasicEvaluatedExpression | undefined], BasicEvaluatedExpression | undefined | null>>} */
|
169
177
|
evaluateCallExpressionMember: new HookMap(
|
170
178
|
() => new SyncBailHook(["expression", "param"])
|
@@ -262,9 +270,9 @@ class JavascriptParser extends Parser {
|
|
262
270
|
/** @type {HookMap<SyncBailHook<[ExpressionNode], boolean | void>>} */
|
263
271
|
call: new HookMap(() => new SyncBailHook(["expression"])),
|
264
272
|
/** Something like "a.b()" */
|
265
|
-
/** @type {HookMap<SyncBailHook<[CallExpressionNode, string[]], boolean | void>>} */
|
273
|
+
/** @type {HookMap<SyncBailHook<[CallExpressionNode, string[], boolean[]], boolean | void>>} */
|
266
274
|
callMemberChain: new HookMap(
|
267
|
-
() => new SyncBailHook(["expression", "members"])
|
275
|
+
() => new SyncBailHook(["expression", "members", "membersOptionals"])
|
268
276
|
),
|
269
277
|
/** Something like "a.b().c.d" */
|
270
278
|
/** @type {HookMap<SyncBailHook<[ExpressionNode, string[], CallExpressionNode, string[]], boolean | void>>} */
|
@@ -292,11 +300,13 @@ class JavascriptParser extends Parser {
|
|
292
300
|
optionalChaining: new SyncBailHook(["optionalChaining"]),
|
293
301
|
/** @type {HookMap<SyncBailHook<[NewExpressionNode], boolean | void>>} */
|
294
302
|
new: new HookMap(() => new SyncBailHook(["expression"])),
|
303
|
+
/** @type {SyncBailHook<[BinaryExpressionNode], boolean | void>} */
|
304
|
+
binaryExpression: new SyncBailHook(["binaryExpression"]),
|
295
305
|
/** @type {HookMap<SyncBailHook<[ExpressionNode], boolean | void>>} */
|
296
306
|
expression: new HookMap(() => new SyncBailHook(["expression"])),
|
297
|
-
/** @type {HookMap<SyncBailHook<[ExpressionNode, string[]], boolean | void>>} */
|
307
|
+
/** @type {HookMap<SyncBailHook<[ExpressionNode, string[], boolean[]], boolean | void>>} */
|
298
308
|
expressionMemberChain: new HookMap(
|
299
|
-
() => new SyncBailHook(["expression", "members"])
|
309
|
+
() => new SyncBailHook(["expression", "members", "membersOptionals"])
|
300
310
|
),
|
301
311
|
/** @type {HookMap<SyncBailHook<[ExpressionNode, string[]], boolean | void>>} */
|
302
312
|
unhandledExpressionMemberChain: new HookMap(
|
@@ -359,9 +369,14 @@ class JavascriptParser extends Parser {
|
|
359
369
|
this.hooks.evaluate.for("NewExpression").tap("JavascriptParser", _expr => {
|
360
370
|
const expr = /** @type {NewExpressionNode} */ (_expr);
|
361
371
|
const callee = expr.callee;
|
362
|
-
if (
|
363
|
-
|
364
|
-
|
372
|
+
if (callee.type !== "Identifier") return;
|
373
|
+
if (callee.name !== "RegExp") {
|
374
|
+
return this.callHooksForName(
|
375
|
+
this.hooks.evaluateNewExpression,
|
376
|
+
callee.name,
|
377
|
+
expr
|
378
|
+
);
|
379
|
+
} else if (
|
365
380
|
expr.arguments.length > 2 ||
|
366
381
|
this.getVariableInfo("RegExp") !== "RegExp"
|
367
382
|
)
|
@@ -416,7 +431,6 @@ class JavascriptParser extends Parser {
|
|
416
431
|
const expr = /** @type {LogicalExpressionNode} */ (_expr);
|
417
432
|
|
418
433
|
const left = this.evaluateExpression(expr.left);
|
419
|
-
if (!left) return;
|
420
434
|
let returnRight = false;
|
421
435
|
/** @type {boolean|undefined} */
|
422
436
|
let allowedRight;
|
@@ -437,7 +451,6 @@ class JavascriptParser extends Parser {
|
|
437
451
|
returnRight = true;
|
438
452
|
} else return;
|
439
453
|
const right = this.evaluateExpression(expr.right);
|
440
|
-
if (!right) return;
|
441
454
|
if (returnRight) {
|
442
455
|
if (left.couldHaveSideEffects()) right.setSideEffects();
|
443
456
|
return right.setRange(expr.range);
|
@@ -486,10 +499,10 @@ class JavascriptParser extends Parser {
|
|
486
499
|
|
487
500
|
const handleConstOperation = fn => {
|
488
501
|
const left = this.evaluateExpression(expr.left);
|
489
|
-
if (!left
|
502
|
+
if (!left.isCompileTimeValue()) return;
|
490
503
|
|
491
504
|
const right = this.evaluateExpression(expr.right);
|
492
|
-
if (!right
|
505
|
+
if (!right.isCompileTimeValue()) return;
|
493
506
|
|
494
507
|
const result = fn(
|
495
508
|
left.asCompileTimeValue(),
|
@@ -545,9 +558,7 @@ class JavascriptParser extends Parser {
|
|
545
558
|
|
546
559
|
const handleStrictEqualityComparison = eql => {
|
547
560
|
const left = this.evaluateExpression(expr.left);
|
548
|
-
if (!left) return;
|
549
561
|
const right = this.evaluateExpression(expr.right);
|
550
|
-
if (!right) return;
|
551
562
|
const res = new BasicEvaluatedExpression();
|
552
563
|
res.setRange(expr.range);
|
553
564
|
|
@@ -600,9 +611,7 @@ class JavascriptParser extends Parser {
|
|
600
611
|
|
601
612
|
const handleAbstractEqualityComparison = eql => {
|
602
613
|
const left = this.evaluateExpression(expr.left);
|
603
|
-
if (!left) return;
|
604
614
|
const right = this.evaluateExpression(expr.right);
|
605
|
-
if (!right) return;
|
606
615
|
const res = new BasicEvaluatedExpression();
|
607
616
|
res.setRange(expr.range);
|
608
617
|
|
@@ -635,9 +644,7 @@ class JavascriptParser extends Parser {
|
|
635
644
|
|
636
645
|
if (expr.operator === "+") {
|
637
646
|
const left = this.evaluateExpression(expr.left);
|
638
|
-
if (!left) return;
|
639
647
|
const right = this.evaluateExpression(expr.right);
|
640
|
-
if (!right) return;
|
641
648
|
const res = new BasicEvaluatedExpression();
|
642
649
|
if (left.isString()) {
|
643
650
|
if (right.isString()) {
|
@@ -816,7 +823,7 @@ class JavascriptParser extends Parser {
|
|
816
823
|
|
817
824
|
const handleConstOperation = fn => {
|
818
825
|
const argument = this.evaluateExpression(expr.argument);
|
819
|
-
if (!argument
|
826
|
+
if (!argument.isCompileTimeValue()) return;
|
820
827
|
const result = fn(argument.asCompileTimeValue());
|
821
828
|
return valueAsExpression(
|
822
829
|
result,
|
@@ -915,7 +922,6 @@ class JavascriptParser extends Parser {
|
|
915
922
|
}
|
916
923
|
} else if (expr.operator === "!") {
|
917
924
|
const argument = this.evaluateExpression(expr.argument);
|
918
|
-
if (!argument) return;
|
919
925
|
const bool = argument.asBool();
|
920
926
|
if (typeof bool !== "boolean") return;
|
921
927
|
return new BasicEvaluatedExpression()
|
@@ -935,6 +941,13 @@ class JavascriptParser extends Parser {
|
|
935
941
|
.setString("undefined")
|
936
942
|
.setRange(expr.range);
|
937
943
|
});
|
944
|
+
this.hooks.evaluate.for("Identifier").tap("JavascriptParser", expr => {
|
945
|
+
if (/** @type {IdentifierNode} */ (expr).name === "undefined") {
|
946
|
+
return new BasicEvaluatedExpression()
|
947
|
+
.setUndefined()
|
948
|
+
.setRange(expr.range);
|
949
|
+
}
|
950
|
+
});
|
938
951
|
/**
|
939
952
|
* @param {string} exprType expression type name
|
940
953
|
* @param {function(ExpressionNode): GetInfoResult | undefined} getInfo get info
|
@@ -973,7 +986,12 @@ class JavascriptParser extends Parser {
|
|
973
986
|
const info = cachedExpression === expr ? cachedInfo : getInfo(expr);
|
974
987
|
if (info !== undefined) {
|
975
988
|
return new BasicEvaluatedExpression()
|
976
|
-
.setIdentifier(
|
989
|
+
.setIdentifier(
|
990
|
+
info.name,
|
991
|
+
info.rootInfo,
|
992
|
+
info.getMembers,
|
993
|
+
info.getMembersOptionals
|
994
|
+
)
|
977
995
|
.setRange(expr.range);
|
978
996
|
}
|
979
997
|
});
|
@@ -990,7 +1008,12 @@ class JavascriptParser extends Parser {
|
|
990
1008
|
typeof info === "string" ||
|
991
1009
|
(info instanceof VariableInfo && typeof info.freeName === "string")
|
992
1010
|
) {
|
993
|
-
return {
|
1011
|
+
return {
|
1012
|
+
name: info,
|
1013
|
+
rootInfo: info,
|
1014
|
+
getMembers: () => [],
|
1015
|
+
getMembersOptionals: () => []
|
1016
|
+
};
|
994
1017
|
}
|
995
1018
|
});
|
996
1019
|
tapEvaluateWithVariableInfo("ThisExpression", expr => {
|
@@ -999,7 +1022,12 @@ class JavascriptParser extends Parser {
|
|
999
1022
|
typeof info === "string" ||
|
1000
1023
|
(info instanceof VariableInfo && typeof info.freeName === "string")
|
1001
1024
|
) {
|
1002
|
-
return {
|
1025
|
+
return {
|
1026
|
+
name: info,
|
1027
|
+
rootInfo: info,
|
1028
|
+
getMembers: () => [],
|
1029
|
+
getMembersOptionals: () => []
|
1030
|
+
};
|
1003
1031
|
}
|
1004
1032
|
});
|
1005
1033
|
this.hooks.evaluate.for("MetaProperty").tap("JavascriptParser", expr => {
|
@@ -1021,25 +1049,28 @@ class JavascriptParser extends Parser {
|
|
1021
1049
|
this.hooks.evaluate.for("CallExpression").tap("JavascriptParser", _expr => {
|
1022
1050
|
const expr = /** @type {CallExpressionNode} */ (_expr);
|
1023
1051
|
if (
|
1024
|
-
expr.callee.type
|
1025
|
-
expr.callee.property.type
|
1052
|
+
expr.callee.type === "MemberExpression" &&
|
1053
|
+
expr.callee.property.type ===
|
1026
1054
|
(expr.callee.computed ? "Literal" : "Identifier")
|
1027
1055
|
) {
|
1028
|
-
|
1029
|
-
|
1030
|
-
|
1031
|
-
|
1032
|
-
|
1033
|
-
|
1034
|
-
|
1035
|
-
|
1036
|
-
|
1037
|
-
|
1038
|
-
|
1039
|
-
|
1040
|
-
|
1041
|
-
|
1042
|
-
|
1056
|
+
// type Super also possible here
|
1057
|
+
const param = this.evaluateExpression(
|
1058
|
+
/** @type {ExpressionNode} */ (expr.callee.object)
|
1059
|
+
);
|
1060
|
+
const property =
|
1061
|
+
expr.callee.property.type === "Literal"
|
1062
|
+
? `${expr.callee.property.value}`
|
1063
|
+
: expr.callee.property.name;
|
1064
|
+
const hook = this.hooks.evaluateCallExpressionMember.get(property);
|
1065
|
+
if (hook !== undefined) {
|
1066
|
+
return hook.call(expr, param);
|
1067
|
+
}
|
1068
|
+
} else if (expr.callee.type === "Identifier") {
|
1069
|
+
return this.callHooksForName(
|
1070
|
+
this.hooks.evaluateCallExpression,
|
1071
|
+
expr.callee.name,
|
1072
|
+
expr
|
1073
|
+
);
|
1043
1074
|
}
|
1044
1075
|
});
|
1045
1076
|
this.hooks.evaluateCallExpressionMember
|
@@ -1189,14 +1220,15 @@ class JavascriptParser extends Parser {
|
|
1189
1220
|
const node = /** @type {TaggedTemplateExpressionNode} */ (_node);
|
1190
1221
|
const tag = this.evaluateExpression(node.tag);
|
1191
1222
|
|
1192
|
-
if (tag.isIdentifier() && tag.identifier
|
1193
|
-
|
1194
|
-
|
1195
|
-
|
1196
|
-
|
1197
|
-
|
1198
|
-
|
1199
|
-
|
1223
|
+
if (tag.isIdentifier() && tag.identifier === "String.raw") {
|
1224
|
+
const { quasis, parts } = getSimplifiedTemplateResult(
|
1225
|
+
"raw",
|
1226
|
+
node.quasi
|
1227
|
+
);
|
1228
|
+
return new BasicEvaluatedExpression()
|
1229
|
+
.setTemplateString(quasis, parts, "raw")
|
1230
|
+
.setRange(node.range);
|
1231
|
+
}
|
1200
1232
|
});
|
1201
1233
|
|
1202
1234
|
this.hooks.evaluateCallExpressionMember
|
@@ -1298,7 +1330,6 @@ class JavascriptParser extends Parser {
|
|
1298
1330
|
if (conditionValue === undefined) {
|
1299
1331
|
const consequent = this.evaluateExpression(expr.consequent);
|
1300
1332
|
const alternate = this.evaluateExpression(expr.alternate);
|
1301
|
-
if (!consequent || !alternate) return;
|
1302
1333
|
res = new BasicEvaluatedExpression();
|
1303
1334
|
if (consequent.isConditional()) {
|
1304
1335
|
res.setOptions(consequent.options);
|
@@ -1372,7 +1403,7 @@ class JavascriptParser extends Parser {
|
|
1372
1403
|
const expression = optionalExpressionsStack.pop();
|
1373
1404
|
const evaluated = this.evaluateExpression(expression);
|
1374
1405
|
|
1375
|
-
if (evaluated
|
1406
|
+
if (evaluated.asNullish()) {
|
1376
1407
|
return evaluated.setRange(_expr.range);
|
1377
1408
|
}
|
1378
1409
|
}
|
@@ -1382,7 +1413,7 @@ class JavascriptParser extends Parser {
|
|
1382
1413
|
|
1383
1414
|
getRenameIdentifier(expr) {
|
1384
1415
|
const result = this.evaluateExpression(expr);
|
1385
|
-
if (result
|
1416
|
+
if (result.isIdentifier()) {
|
1386
1417
|
return result.identifier;
|
1387
1418
|
}
|
1388
1419
|
}
|
@@ -1416,6 +1447,11 @@ class JavascriptParser extends Parser {
|
|
1416
1447
|
this.walkExpression(classElement.value);
|
1417
1448
|
this.scope.topLevelScope = wasTopLevel;
|
1418
1449
|
}
|
1450
|
+
} else if (classElement.type === "StaticBlock") {
|
1451
|
+
const wasTopLevel = this.scope.topLevelScope;
|
1452
|
+
this.scope.topLevelScope = false;
|
1453
|
+
this.walkBlockStatement(classElement);
|
1454
|
+
this.scope.topLevelScope = wasTopLevel;
|
1419
1455
|
}
|
1420
1456
|
}
|
1421
1457
|
}
|
@@ -1872,7 +1908,7 @@ class JavascriptParser extends Parser {
|
|
1872
1908
|
!this.hooks.importSpecifier.call(
|
1873
1909
|
statement,
|
1874
1910
|
source,
|
1875
|
-
specifier.imported.name,
|
1911
|
+
specifier.imported.name || specifier.imported.value,
|
1876
1912
|
name
|
1877
1913
|
)
|
1878
1914
|
) {
|
@@ -1942,7 +1978,7 @@ class JavascriptParser extends Parser {
|
|
1942
1978
|
const specifier = statement.specifiers[specifierIndex];
|
1943
1979
|
switch (specifier.type) {
|
1944
1980
|
case "ExportSpecifier": {
|
1945
|
-
const name = specifier.exported.name;
|
1981
|
+
const name = specifier.exported.name || specifier.exported.value;
|
1946
1982
|
if (source) {
|
1947
1983
|
this.hooks.exportImportSpecifier.call(
|
1948
1984
|
statement,
|
@@ -2449,7 +2485,9 @@ class JavascriptParser extends Parser {
|
|
2449
2485
|
}
|
2450
2486
|
|
2451
2487
|
walkBinaryExpression(expression) {
|
2452
|
-
this.
|
2488
|
+
if (this.hooks.binaryExpression.call(expression) === undefined) {
|
2489
|
+
this.walkLeftRightExpression(expression);
|
2490
|
+
}
|
2453
2491
|
}
|
2454
2492
|
|
2455
2493
|
walkLogicalExpression(expression) {
|
@@ -2484,7 +2522,9 @@ class JavascriptParser extends Parser {
|
|
2484
2522
|
) {
|
2485
2523
|
this.setVariable(
|
2486
2524
|
expression.left.name,
|
2487
|
-
|
2525
|
+
typeof renameIdentifier === "string"
|
2526
|
+
? this.getVariableInfo(renameIdentifier)
|
2527
|
+
: renameIdentifier
|
2488
2528
|
);
|
2489
2529
|
}
|
2490
2530
|
return;
|
@@ -2619,7 +2659,9 @@ class JavascriptParser extends Parser {
|
|
2619
2659
|
argOrThis
|
2620
2660
|
)
|
2621
2661
|
) {
|
2622
|
-
return
|
2662
|
+
return typeof renameIdentifier === "string"
|
2663
|
+
? this.getVariableInfo(renameIdentifier)
|
2664
|
+
: renameIdentifier;
|
2623
2665
|
}
|
2624
2666
|
}
|
2625
2667
|
}
|
@@ -2719,7 +2761,10 @@ class JavascriptParser extends Parser {
|
|
2719
2761
|
this.hooks.callMemberChain,
|
2720
2762
|
callee.rootInfo,
|
2721
2763
|
expression,
|
2722
|
-
callee.getMembers()
|
2764
|
+
callee.getMembers(),
|
2765
|
+
callee.getMembersOptionals
|
2766
|
+
? callee.getMembersOptionals()
|
2767
|
+
: callee.getMembers().map(() => false)
|
2723
2768
|
);
|
2724
2769
|
if (result1 === true) return;
|
2725
2770
|
const result2 = this.callHooksForInfo(
|
@@ -2759,11 +2804,13 @@ class JavascriptParser extends Parser {
|
|
2759
2804
|
);
|
2760
2805
|
if (result1 === true) return;
|
2761
2806
|
const members = exprInfo.getMembers();
|
2807
|
+
const membersOptionals = exprInfo.getMembersOptionals();
|
2762
2808
|
const result2 = this.callHooksForInfo(
|
2763
2809
|
this.hooks.expressionMemberChain,
|
2764
2810
|
exprInfo.rootInfo,
|
2765
2811
|
expression,
|
2766
|
-
members
|
2812
|
+
members,
|
2813
|
+
membersOptionals
|
2767
2814
|
);
|
2768
2815
|
if (result2 === true) return;
|
2769
2816
|
this.walkMemberExpressionWithExpressionName(
|
@@ -3159,17 +3206,15 @@ class JavascriptParser extends Parser {
|
|
3159
3206
|
|
3160
3207
|
/**
|
3161
3208
|
* @param {ExpressionNode} expression expression node
|
3162
|
-
* @returns {BasicEvaluatedExpression
|
3209
|
+
* @returns {BasicEvaluatedExpression} evaluation result
|
3163
3210
|
*/
|
3164
3211
|
evaluateExpression(expression) {
|
3165
3212
|
try {
|
3166
3213
|
const hook = this.hooks.evaluate.get(expression.type);
|
3167
3214
|
if (hook !== undefined) {
|
3168
3215
|
const result = hook.call(expression);
|
3169
|
-
if (result !== undefined) {
|
3170
|
-
|
3171
|
-
result.setExpression(expression);
|
3172
|
-
}
|
3216
|
+
if (result !== undefined && result !== null) {
|
3217
|
+
result.setExpression(expression);
|
3173
3218
|
return result;
|
3174
3219
|
}
|
3175
3220
|
}
|
@@ -3340,6 +3385,10 @@ class JavascriptParser extends Parser {
|
|
3340
3385
|
return state;
|
3341
3386
|
}
|
3342
3387
|
|
3388
|
+
/**
|
3389
|
+
* @param {string} source source code
|
3390
|
+
* @returns {BasicEvaluatedExpression} evaluation result
|
3391
|
+
*/
|
3343
3392
|
evaluate(source) {
|
3344
3393
|
const ast = JavascriptParser._parse("(" + source + ")", {
|
3345
3394
|
sourceType: this.sourceType,
|
@@ -3576,23 +3625,37 @@ class JavascriptParser extends Parser {
|
|
3576
3625
|
}
|
3577
3626
|
}
|
3578
3627
|
|
3628
|
+
evaluatedVariable(tagInfo) {
|
3629
|
+
return new VariableInfo(this.scope, undefined, tagInfo);
|
3630
|
+
}
|
3631
|
+
|
3579
3632
|
parseCommentOptions(range) {
|
3580
3633
|
const comments = this.getComments(range);
|
3581
3634
|
if (comments.length === 0) {
|
3582
3635
|
return EMPTY_COMMENT_OPTIONS;
|
3583
3636
|
}
|
3584
3637
|
let options = {};
|
3638
|
+
/** @type {unknown[]} */
|
3585
3639
|
let errors = [];
|
3586
3640
|
for (const comment of comments) {
|
3587
3641
|
const { value } = comment;
|
3588
3642
|
if (value && webpackCommentRegExp.test(value)) {
|
3589
3643
|
// try compile only if webpack options comment is present
|
3590
3644
|
try {
|
3591
|
-
|
3592
|
-
|
3645
|
+
for (let [key, val] of Object.entries(
|
3646
|
+
vm.runInNewContext(`(function(){return {${value}};})()`)
|
3647
|
+
)) {
|
3648
|
+
if (typeof val === "object" && val !== null) {
|
3649
|
+
if (val.constructor.name === "RegExp") val = new RegExp(val);
|
3650
|
+
else val = JSON.parse(JSON.stringify(val));
|
3651
|
+
}
|
3652
|
+
options[key] = val;
|
3653
|
+
}
|
3593
3654
|
} catch (e) {
|
3594
|
-
|
3595
|
-
|
3655
|
+
const newErr = new Error(String(e.message));
|
3656
|
+
newErr.stack = String(e.stack);
|
3657
|
+
Object.assign(newErr, { comment });
|
3658
|
+
errors.push(newErr);
|
3596
3659
|
}
|
3597
3660
|
}
|
3598
3661
|
}
|
@@ -3601,12 +3664,13 @@ class JavascriptParser extends Parser {
|
|
3601
3664
|
|
3602
3665
|
/**
|
3603
3666
|
* @param {MemberExpressionNode} expression a member expression
|
3604
|
-
* @returns {{ members: string[], object: ExpressionNode | SuperNode }} member names (reverse order) and remaining object
|
3667
|
+
* @returns {{ members: string[], object: ExpressionNode | SuperNode, membersOptionals: boolean[] }} member names (reverse order) and remaining object
|
3605
3668
|
*/
|
3606
3669
|
extractMemberExpressionChain(expression) {
|
3607
3670
|
/** @type {AnyNode} */
|
3608
3671
|
let expr = expression;
|
3609
3672
|
const members = [];
|
3673
|
+
const membersOptionals = [];
|
3610
3674
|
while (expr.type === "MemberExpression") {
|
3611
3675
|
if (expr.computed) {
|
3612
3676
|
if (expr.property.type !== "Literal") break;
|
@@ -3615,10 +3679,13 @@ class JavascriptParser extends Parser {
|
|
3615
3679
|
if (expr.property.type !== "Identifier") break;
|
3616
3680
|
members.push(expr.property.name);
|
3617
3681
|
}
|
3682
|
+
membersOptionals.push(expr.optional);
|
3618
3683
|
expr = expr.object;
|
3619
3684
|
}
|
3685
|
+
|
3620
3686
|
return {
|
3621
3687
|
members,
|
3688
|
+
membersOptionals,
|
3622
3689
|
object: expr
|
3623
3690
|
};
|
3624
3691
|
}
|
@@ -3641,8 +3708,8 @@ class JavascriptParser extends Parser {
|
|
3641
3708
|
return { info, name };
|
3642
3709
|
}
|
3643
3710
|
|
3644
|
-
/** @typedef {{ type: "call", call: CallExpressionNode, calleeName: string, rootInfo: string | VariableInfo, getCalleeMembers: () => string[], name: string, getMembers: () => string[]}} CallExpressionInfo */
|
3645
|
-
/** @typedef {{ type: "expression", rootInfo: string | VariableInfo, name: string, getMembers: () => string[]}} ExpressionExpressionInfo */
|
3711
|
+
/** @typedef {{ type: "call", call: CallExpressionNode, calleeName: string, rootInfo: string | VariableInfo, getCalleeMembers: () => string[], name: string, getMembers: () => string[], getMembersOptionals: () => boolean[]}} CallExpressionInfo */
|
3712
|
+
/** @typedef {{ type: "expression", rootInfo: string | VariableInfo, name: string, getMembers: () => string[], getMembersOptionals: () => boolean[]}} ExpressionExpressionInfo */
|
3646
3713
|
|
3647
3714
|
/**
|
3648
3715
|
* @param {MemberExpressionNode} expression a member expression
|
@@ -3650,7 +3717,8 @@ class JavascriptParser extends Parser {
|
|
3650
3717
|
* @returns {CallExpressionInfo | ExpressionExpressionInfo | undefined} expression info
|
3651
3718
|
*/
|
3652
3719
|
getMemberExpressionInfo(expression, allowedTypes) {
|
3653
|
-
const { object, members } =
|
3720
|
+
const { object, members, membersOptionals } =
|
3721
|
+
this.extractMemberExpressionChain(expression);
|
3654
3722
|
switch (object.type) {
|
3655
3723
|
case "CallExpression": {
|
3656
3724
|
if ((allowedTypes & ALLOWED_MEMBER_TYPES_CALL_EXPRESSION) === 0)
|
@@ -3674,7 +3742,8 @@ class JavascriptParser extends Parser {
|
|
3674
3742
|
rootInfo,
|
3675
3743
|
getCalleeMembers: memoize(() => rootMembers.reverse()),
|
3676
3744
|
name: objectAndMembersToName(`${calleeName}()`, members),
|
3677
|
-
getMembers: memoize(() => members.reverse())
|
3745
|
+
getMembers: memoize(() => members.reverse()),
|
3746
|
+
getMembersOptionals: memoize(() => membersOptionals.reverse())
|
3678
3747
|
};
|
3679
3748
|
}
|
3680
3749
|
case "Identifier":
|
@@ -3692,7 +3761,8 @@ class JavascriptParser extends Parser {
|
|
3692
3761
|
type: "expression",
|
3693
3762
|
name: objectAndMembersToName(resolvedRoot, members),
|
3694
3763
|
rootInfo,
|
3695
|
-
getMembers: memoize(() => members.reverse())
|
3764
|
+
getMembers: memoize(() => members.reverse()),
|
3765
|
+
getMembersOptionals: memoize(() => membersOptionals.reverse())
|
3696
3766
|
};
|
3697
3767
|
}
|
3698
3768
|
}
|