@rollup/wasm-node 5.0.0-0 → 5.0.0-1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bin/rollup +3 -3
- package/dist/es/getLogFilter.js +2 -2
- package/dist/es/parseAst.js +2 -2
- package/dist/es/rollup.js +2 -2
- package/dist/es/shared/node-entry.js +893 -689
- package/dist/es/shared/parseAst.js +113 -29
- package/dist/es/shared/watch.js +2 -2
- package/dist/getLogFilter.js +2 -2
- package/dist/loadConfigFile.js +2 -2
- package/dist/native.js +19 -3
- package/dist/parseAst.js +2 -2
- package/dist/rollup.android-arm-eabi.node +0 -0
- package/dist/rollup.android-arm64.node +0 -0
- package/dist/rollup.darwin-arm64.node +0 -0
- package/dist/rollup.darwin-x64.node +0 -0
- package/dist/rollup.freebsd-arm64.node +0 -0
- package/dist/rollup.freebsd-x64.node +0 -0
- package/dist/rollup.js +2 -2
- package/dist/rollup.linux-arm-gnueabihf.node +0 -0
- package/dist/rollup.linux-arm-musleabihf.node +0 -0
- package/dist/rollup.linux-arm64-gnu.node +0 -0
- package/dist/rollup.linux-arm64-musl.node +0 -0
- package/dist/rollup.linux-loong64-gnu.node +0 -0
- package/dist/rollup.linux-loong64-musl.node +0 -0
- package/dist/rollup.linux-ppc64-gnu.node +0 -0
- package/dist/rollup.linux-ppc64-musl.node +0 -0
- package/dist/rollup.linux-riscv64-gnu.node +0 -0
- package/dist/rollup.linux-riscv64-musl.node +0 -0
- package/dist/rollup.linux-s390x-gnu.node +0 -0
- package/dist/rollup.linux-x64-gnu.node +0 -0
- package/dist/rollup.linux-x64-musl.node +0 -0
- package/dist/rollup.openbsd-x64.node +0 -0
- package/dist/rollup.openharmony-arm64.node +0 -0
- package/dist/rollup.win32-arm64-msvc.node +0 -0
- package/dist/rollup.win32-ia32-msvc.node +0 -0
- package/dist/rollup.win32-x64-gnu.node +0 -0
- package/dist/rollup.win32-x64-msvc.node +0 -0
- package/dist/shared/index.js +2 -2
- package/dist/shared/loadConfigFile.js +2 -2
- package/dist/shared/node-entry.js +2 -2
- package/dist/shared/parseAst.js +119 -35
- package/dist/shared/rollup.js +892 -688
- package/dist/shared/watch-cli.js +2 -2
- package/dist/shared/watch.js +2 -2
- package/dist/wasm-node/bindings_wasm.js +2 -18
- package/dist/wasm-node/bindings_wasm_bg.wasm +0 -0
- package/package.json +16 -16
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
/*
|
|
2
2
|
@license
|
|
3
|
-
Rollup.js v5.0.0-
|
|
4
|
-
|
|
3
|
+
Rollup.js v5.0.0-1
|
|
4
|
+
Sun, 18 Oct 2026 06:06:25 GMT - commit ed75a6895d5bc62fdbff91b9d48e22e6e281e3bc
|
|
5
5
|
|
|
6
6
|
https://github.com/rollup/rollup
|
|
7
7
|
|
|
8
8
|
Released under the MIT License.
|
|
9
9
|
*/
|
|
10
|
-
import { EMPTY_OBJECT,
|
|
10
|
+
import { EMPTY_OBJECT, ArrowFunctionExpression as ArrowFunctionExpression$1, FunctionExpression as FunctionExpression$1, Identifier as Identifier$1, ObjectExpression as ObjectExpression$1, ExportDefaultDeclaration as ExportDefaultDeclaration$1, CallExpression as CallExpression$1, EMPTY_ARRAY, Program as Program$1, logRedeclarationError, LOGLEVEL_WARN, logUnusedExternalImports, Property as Property$1, logIllegalImportReassignment, BLANK, StaticBlock as StaticBlock$1, CatchClause as CatchClause$1, logDuplicateArgumentNameError, logModuleLevelDirective, ReturnStatement as ReturnStatement$1, VariableDeclarator as VariableDeclarator$1, ExpressionStatement as ExpressionStatement$1, logMissingExport, normalize, getImportPath, error, logSourcePhaseFormatUnsupported, logMissingNodeBuiltins, logReservedNamespace, logIllegalIdentifierAsName, logMissingNameOptionForIifeExport, logMissingNameOptionForUmdExport, RestElement as RestElement$1, logConstVariableReassignError, FunctionDeclaration as FunctionDeclaration$1, EMPTY_SET, logCannotCallNamespace, logEval, IfStatement as IfStatement$1, BlockStatement as BlockStatement$1, AwaitExpression as AwaitExpression$1, MemberExpression as MemberExpression$1, getRollupError, logParseError, logModuleParseError, LOGLEVEL_INFO, logFirstSideEffect, locate, logInvalidAnnotation, logThisIsUndefined, getAstBuffer, nodeTypeStrings, convertAnnotations, FIXED_STRINGS, convertNode as convertNode$1, logImportAttributeIsInvalid, logImportOptionsAreInvalid, logMissingEntryExport, logSyntheticNamedExportsNeedNamespaceExport, logDuplicateExportError, logInvalidSourcemapForError, augmentCodeLocation, logMissingJsxExport, logNamespaceConflict, logAmbiguousExternalNamespaces, logShimmedExport, deserializeLazyAst, TemplateLiteral as TemplateLiteral$1, Literal as Literal$1, logCircularReexport, logInvalidFormatForTopLevelAwait, logAddonNotGenerated, logIncompatibleExportOptionValue, logMixedExport, logFailedValidation, isPathFragment, logCyclicCrossChunkReexport, getAliasName, logUnexpectedNamedImport, isAbsolute as isAbsolute$1, relative as relative$1, logUnexpectedNamespaceReexport, logEmptyChunk, logMissingGlobalName, logAmbiguousGlobalName, logEmptyManualChunk, logOptimizeChunkStatus, logSourcemapBroken, logConflictingSourcemapSources, parseAst, logChunkInvalid, logInvalidOption, URL_OUTPUT_FORMAT, URL_OUTPUT_DIR, URL_OUTPUT_SOURCEMAPFILE, URL_OUTPUT_AMD_ID, logFileNameOutsideOutputDirectory, logCannotAssignModuleToChunk, logCircularChunk, logUnknownOption, printQuotedStringList, LOGLEVEL_ERROR, logLevelPriority, LOGLEVEL_DEBUG, logInvalidLogPosition, logAnonymousPluginCache, logDuplicatePluginName, parseAndWalk, logPluginError, warnDeprecation, URL_THIS_RESOLVE, logInvalidSetAssetSourceCall, serializeAst, logNoTransformMapOrAstWithoutCode, URL_TRANSFORM, relativeId, logBadLoader, logNonExternalSourcePhaseImport, logInternalIdCannotBeExternal, isRelative, logUnresolvedImport, logUnresolvedImportTreatedAsExternal, logExternalSyntheticExports, logUnresolvedEntry, logUnresolvedImplicitDependant, logExternalModulesCannotBeIncludedInManualChunks, logEntryCannotBeExternal, logImplicitDependantCannotBeExternal, logExternalModulesCannotBeTransformedToModules, URL_LOAD, logNoAssetSourceSet, logFileReferenceIdNotFoundForFilename, logAssetReferenceIdNotFoundForSetSource, logAssetSourceAlreadySet, logInvalidRollupPhaseForChunkEmission, logChunkNotGeneratedForFileName, logAssetNotFinalisedForFileName, logFileNameConflict, URL_GENERATEBUNDLE, logInputHookInOutputPlugin, logInvalidAddonPluginHook, logInvalidFunctionPluginHook, logImplicitDependantIsNotIncluded, logCircularDependency, augmentLogMessage, URL_JSX, URL_TREESHAKE, URL_TREESHAKE_MODULESIDEEFFECTS, URL_OUTPUT_INLINEDYNAMICIMPORTS, URL_PRESERVEENTRYSIGNATURES, URL_OUTPUT_GENERATEDCODE, isValidUrl, addTrailingSlashIfMissed, URL_OUTPUT_SOURCEMAPBASEURL, URL_OUTPUT_MANUALCHUNKS, logInvalidExportOptionValue, URL_OUTPUT_AMD_BASEPATH, URL_OUTPUT_INTEROP, URL_OUTPUT_EXTERNALIMPORTATTRIBUTES, URL_OUTPUT_IMPORTATTRIBUTESKEY, logAlreadyClosed, logMissingFileOrDirOption, logCannotEmitFromOptionsHook, URL_WATCH } from './parseAst.js';
|
|
11
11
|
import { relative, dirname, basename, extname, resolve as resolve$1, join } from 'node:path';
|
|
12
12
|
import { posix, isAbsolute, resolve, win32 } from 'path';
|
|
13
13
|
import process$1, { env } from 'node:process';
|
|
@@ -27,7 +27,7 @@ function _mergeNamespaces(n, m) {
|
|
|
27
27
|
return Object.defineProperty(n, Symbol.toStringTag, { value: 'Module' });
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
-
var version = "5.0.0-
|
|
30
|
+
var version = "5.0.0-1";
|
|
31
31
|
const pkg = {
|
|
32
32
|
version: version};
|
|
33
33
|
|
|
@@ -1248,7 +1248,7 @@ var MagicString = class MagicString {
|
|
|
1248
1248
|
while (chunk !== last) {
|
|
1249
1249
|
if (chunk.next !== this.byStart.get(chunk.end)) throw new MagicStringError("cannot overwrite across a split point");
|
|
1250
1250
|
chunk = chunk.next;
|
|
1251
|
-
chunk.edit("", false);
|
|
1251
|
+
chunk.edit("", false, !overwrite);
|
|
1252
1252
|
}
|
|
1253
1253
|
first.edit(content, storeName, !overwrite);
|
|
1254
1254
|
} else {
|
|
@@ -1602,8 +1602,8 @@ var MagicString = class MagicString {
|
|
|
1602
1602
|
if (this._hasRemovedContent(match.index, match.index + match[0].length)) return false;
|
|
1603
1603
|
const replacement = getReplacement(match, this.original);
|
|
1604
1604
|
if (replacement === match[0]) return true;
|
|
1605
|
-
if (match[0].length === 0) this.appendRight(match.index, replacement);
|
|
1606
|
-
else this.overwrite(match.index, match.index + match[0].length, replacement);
|
|
1605
|
+
if (match[0].length === 0) this.appendRight(match.index - this.offset, replacement);
|
|
1606
|
+
else this.overwrite(match.index - this.offset, match.index + match[0].length - this.offset, replacement);
|
|
1607
1607
|
return true;
|
|
1608
1608
|
};
|
|
1609
1609
|
if (searchValue.global) {
|
|
@@ -1630,8 +1630,8 @@ var MagicString = class MagicString {
|
|
|
1630
1630
|
if (typeof replacement === "function") replacement = replacement(string, index, original);
|
|
1631
1631
|
else replacement = expandReplacement(replacement, string, index, original, [], void 0);
|
|
1632
1632
|
if (string !== replacement) {
|
|
1633
|
-
if (string.length === 0) this.appendRight(index, replacement);
|
|
1634
|
-
else this.overwrite(index, index + string.length, replacement);
|
|
1633
|
+
if (string.length === 0) this.appendRight(index - this.offset, replacement);
|
|
1634
|
+
else this.overwrite(index - this.offset, index + string.length - this.offset, replacement);
|
|
1635
1635
|
}
|
|
1636
1636
|
break;
|
|
1637
1637
|
}
|
|
@@ -1652,7 +1652,7 @@ var MagicString = class MagicString {
|
|
|
1652
1652
|
for (let index = 0; index <= original.length; index += 1) {
|
|
1653
1653
|
if (this._hasRemovedContent(index, index)) continue;
|
|
1654
1654
|
const _replacement = typeof replacement === "function" ? replacement("", index, original) : expandReplacement(replacement, "", index, original, [], void 0);
|
|
1655
|
-
if (_replacement !== "") this.appendRight(index, _replacement);
|
|
1655
|
+
if (_replacement !== "") this.appendRight(index - this.offset, _replacement);
|
|
1656
1656
|
}
|
|
1657
1657
|
return this;
|
|
1658
1658
|
}
|
|
@@ -1660,7 +1660,7 @@ var MagicString = class MagicString {
|
|
|
1660
1660
|
if (this._hasRemovedContent(index, index + stringLength)) continue;
|
|
1661
1661
|
const previous = original.slice(index, index + stringLength);
|
|
1662
1662
|
const _replacement = typeof replacement === "function" ? replacement(previous, index, original) : expandReplacement(replacement, previous, index, original, [], void 0);
|
|
1663
|
-
if (previous !== _replacement) this.overwrite(index, index + stringLength, _replacement);
|
|
1663
|
+
if (previous !== _replacement) this.overwrite(index - this.offset, index + stringLength - this.offset, _replacement);
|
|
1664
1664
|
}
|
|
1665
1665
|
return this;
|
|
1666
1666
|
}
|
|
@@ -2560,228 +2560,343 @@ function getSafeName(baseName, usedNames, forbiddenNames) {
|
|
|
2560
2560
|
return safeName;
|
|
2561
2561
|
}
|
|
2562
2562
|
|
|
2563
|
-
//
|
|
2564
|
-
|
|
2565
|
-
|
|
2566
|
-
|
|
2567
|
-
|
|
2568
|
-
|
|
2569
|
-
|
|
2570
|
-
|
|
2571
|
-
|
|
2572
|
-
|
|
2573
|
-
|
|
2574
|
-
|
|
2575
|
-
|
|
2576
|
-
|
|
2563
|
+
// This file is generated by scripts/generate-child-node-keys.ts.
|
|
2564
|
+
// Do not edit this file directly.
|
|
2565
|
+
const childNodeKeys = {
|
|
2566
|
+
ArrayExpression: ['elements'],
|
|
2567
|
+
ArrayPattern: ['elements'],
|
|
2568
|
+
ArrowFunctionExpression: ['params', 'body'],
|
|
2569
|
+
AssignmentExpression: ['left', 'right'],
|
|
2570
|
+
AssignmentPattern: ['left', 'right'],
|
|
2571
|
+
AwaitExpression: ['argument'],
|
|
2572
|
+
BinaryExpression: ['left', 'right'],
|
|
2573
|
+
BlockStatement: ['body'],
|
|
2574
|
+
BreakStatement: ['label'],
|
|
2575
|
+
CallExpression: ['callee', 'arguments'],
|
|
2576
|
+
CatchClause: ['param', 'body'],
|
|
2577
|
+
ChainExpression: ['expression'],
|
|
2578
|
+
ClassBody: ['body'],
|
|
2579
|
+
ClassDeclaration: ['decorators', 'id', 'superClass', 'body'],
|
|
2580
|
+
ClassExpression: ['decorators', 'id', 'superClass', 'body'],
|
|
2581
|
+
ConditionalExpression: ['test', 'consequent', 'alternate'],
|
|
2582
|
+
ContinueStatement: ['label'],
|
|
2583
|
+
DebuggerStatement: [],
|
|
2584
|
+
Decorator: ['expression'],
|
|
2585
|
+
DoWhileStatement: ['body', 'test'],
|
|
2586
|
+
EmptyStatement: [],
|
|
2587
|
+
ExportAllDeclaration: ['exported', 'source', 'attributes'],
|
|
2588
|
+
ExportDefaultDeclaration: ['declaration'],
|
|
2589
|
+
ExportNamedDeclaration: ['specifiers', 'source', 'attributes', 'declaration'],
|
|
2590
|
+
ExportSpecifier: ['local', 'exported'],
|
|
2591
|
+
ExpressionStatement: ['expression'],
|
|
2592
|
+
ForInStatement: ['left', 'right', 'body'],
|
|
2593
|
+
ForOfStatement: ['left', 'right', 'body'],
|
|
2594
|
+
ForStatement: ['init', 'test', 'update', 'body'],
|
|
2595
|
+
FunctionDeclaration: ['id', 'params', 'body'],
|
|
2596
|
+
FunctionExpression: ['id', 'params', 'body'],
|
|
2597
|
+
Identifier: [],
|
|
2598
|
+
IfStatement: ['test', 'consequent', 'alternate'],
|
|
2599
|
+
ImportAttribute: ['key', 'value'],
|
|
2600
|
+
ImportDeclaration: ['specifiers', 'source', 'attributes'],
|
|
2601
|
+
ImportDefaultSpecifier: ['local'],
|
|
2602
|
+
ImportExpression: ['source', 'options'],
|
|
2603
|
+
ImportNamespaceSpecifier: ['local'],
|
|
2604
|
+
ImportSpecifier: ['imported', 'local'],
|
|
2605
|
+
JSXAttribute: ['name', 'value'],
|
|
2606
|
+
JSXClosingElement: ['name'],
|
|
2607
|
+
JSXClosingFragment: [],
|
|
2608
|
+
JSXElement: ['openingElement', 'children', 'closingElement'],
|
|
2609
|
+
JSXEmptyExpression: [],
|
|
2610
|
+
JSXExpressionContainer: ['expression'],
|
|
2611
|
+
JSXFragment: ['openingFragment', 'children', 'closingFragment'],
|
|
2612
|
+
JSXIdentifier: [],
|
|
2613
|
+
JSXMemberExpression: ['object', 'property'],
|
|
2614
|
+
JSXNamespacedName: ['namespace', 'name'],
|
|
2615
|
+
JSXOpeningElement: ['name', 'attributes'],
|
|
2616
|
+
JSXOpeningFragment: [],
|
|
2617
|
+
JSXSpreadAttribute: ['argument'],
|
|
2618
|
+
JSXSpreadChild: ['expression'],
|
|
2619
|
+
JSXText: [],
|
|
2620
|
+
LabeledStatement: ['label', 'body'],
|
|
2621
|
+
Literal: [],
|
|
2622
|
+
LogicalExpression: ['left', 'right'],
|
|
2623
|
+
MemberExpression: ['object', 'property'],
|
|
2624
|
+
MetaProperty: ['meta', 'property'],
|
|
2625
|
+
MethodDefinition: ['decorators', 'key', 'value'],
|
|
2626
|
+
NewExpression: ['callee', 'arguments'],
|
|
2627
|
+
ObjectExpression: ['properties'],
|
|
2628
|
+
ObjectPattern: ['properties'],
|
|
2629
|
+
PanicError: [],
|
|
2630
|
+
ParseError: [],
|
|
2631
|
+
PrivateIdentifier: [],
|
|
2632
|
+
Program: ['body'],
|
|
2633
|
+
Property: ['key', 'value'],
|
|
2634
|
+
PropertyDefinition: ['decorators', 'key', 'value'],
|
|
2635
|
+
RestElement: ['argument'],
|
|
2636
|
+
ReturnStatement: ['argument'],
|
|
2637
|
+
SequenceExpression: ['expressions'],
|
|
2638
|
+
SpreadElement: ['argument'],
|
|
2639
|
+
StaticBlock: ['body'],
|
|
2640
|
+
Super: [],
|
|
2641
|
+
SwitchCase: ['test', 'consequent'],
|
|
2642
|
+
SwitchStatement: ['discriminant', 'cases'],
|
|
2643
|
+
TaggedTemplateExpression: ['tag', 'quasi'],
|
|
2644
|
+
TemplateElement: [],
|
|
2645
|
+
TemplateLiteral: ['quasis', 'expressions'],
|
|
2646
|
+
ThisExpression: [],
|
|
2647
|
+
ThrowStatement: ['argument'],
|
|
2648
|
+
TryStatement: ['block', 'handler', 'finalizer'],
|
|
2649
|
+
UnaryExpression: ['argument'],
|
|
2650
|
+
UpdateExpression: ['argument'],
|
|
2651
|
+
VariableDeclaration: ['declarations'],
|
|
2652
|
+
VariableDeclarator: ['id', 'init'],
|
|
2653
|
+
WhileStatement: ['test', 'body'],
|
|
2654
|
+
YieldExpression: ['argument']
|
|
2577
2655
|
};
|
|
2578
2656
|
|
|
2579
|
-
function
|
|
2580
|
-
return
|
|
2657
|
+
function createInclusionContext() {
|
|
2658
|
+
return {
|
|
2659
|
+
brokenFlow: false,
|
|
2660
|
+
hasBreak: false,
|
|
2661
|
+
hasContinue: false,
|
|
2662
|
+
includedCallArguments: new Set(),
|
|
2663
|
+
includedLabels: new Set()
|
|
2664
|
+
};
|
|
2581
2665
|
}
|
|
2582
|
-
|
|
2583
|
-
|
|
2584
|
-
|
|
2666
|
+
function createHasEffectsContext() {
|
|
2667
|
+
return {
|
|
2668
|
+
accessed: new EntityPathTracker(),
|
|
2669
|
+
assigned: new EntityPathTracker(),
|
|
2670
|
+
brokenFlow: false,
|
|
2671
|
+
called: new DiscriminatedPathTracker(),
|
|
2672
|
+
hasBreak: false,
|
|
2673
|
+
hasContinue: false,
|
|
2674
|
+
ignore: {
|
|
2675
|
+
breaks: false,
|
|
2676
|
+
continues: false,
|
|
2677
|
+
labels: new Set(),
|
|
2678
|
+
returnYield: false,
|
|
2679
|
+
this: false
|
|
2680
|
+
},
|
|
2681
|
+
includedLabels: new Set(),
|
|
2682
|
+
instantiated: new DiscriminatedPathTracker(),
|
|
2683
|
+
replacedVariableInits: new Map()
|
|
2684
|
+
};
|
|
2685
|
+
}
|
|
2686
|
+
|
|
2687
|
+
const INCLUDE_PARAMETERS = 'variables';
|
|
2688
|
+
const IS_SKIPPED_CHAIN = Symbol('IS_SKIPPED_CHAIN');
|
|
2689
|
+
class NodeBase extends ExpressionEntity {
|
|
2690
|
+
/**
|
|
2691
|
+
* Nodes can apply custom deoptimizations once they become part of the
|
|
2692
|
+
* executed code. To do this, they must initialize this as false, implement
|
|
2693
|
+
* applyDeoptimizations and call this from include and hasEffects if they have
|
|
2694
|
+
* custom handlers
|
|
2695
|
+
*/
|
|
2696
|
+
get deoptimized() {
|
|
2697
|
+
return isFlagSet(this.flags, 2 /* Flag.deoptimized */);
|
|
2585
2698
|
}
|
|
2586
|
-
|
|
2587
|
-
|
|
2588
|
-
value: {
|
|
2589
|
-
hasEffectsWhenCalled: null,
|
|
2590
|
-
returns: UNKNOWN_EXPRESSION
|
|
2699
|
+
set deoptimized(value) {
|
|
2700
|
+
this.flags = setFlag(this.flags, 2 /* Flag.deoptimized */, value);
|
|
2591
2701
|
}
|
|
2592
|
-
|
|
2593
|
-
|
|
2594
|
-
|
|
2595
|
-
|
|
2596
|
-
|
|
2597
|
-
}
|
|
2598
|
-
return UNKNOWN_RETURN_EXPRESSION;
|
|
2702
|
+
constructor(parent, parentScope) {
|
|
2703
|
+
super();
|
|
2704
|
+
this.parent = parent;
|
|
2705
|
+
this.scope = parentScope;
|
|
2706
|
+
this.createScope(parentScope);
|
|
2599
2707
|
}
|
|
2600
|
-
|
|
2601
|
-
|
|
2602
|
-
|
|
2603
|
-
|
|
2604
|
-
|
|
2605
|
-
|
|
2708
|
+
addExportedVariables(_variables, _exportNamesByVariable) { }
|
|
2709
|
+
/**
|
|
2710
|
+
* Override this to bind assignments to variables and do any initialisations
|
|
2711
|
+
* that require the scopes to be populated with variables.
|
|
2712
|
+
*/
|
|
2713
|
+
bind() {
|
|
2714
|
+
for (const key of childNodeKeys[this.type]) {
|
|
2715
|
+
const value = this[key];
|
|
2716
|
+
if (Array.isArray(value)) {
|
|
2717
|
+
for (const child of value) {
|
|
2718
|
+
child?.bind();
|
|
2719
|
+
}
|
|
2720
|
+
}
|
|
2721
|
+
else if (value) {
|
|
2722
|
+
value.bind();
|
|
2723
|
+
}
|
|
2606
2724
|
}
|
|
2607
|
-
return true;
|
|
2608
2725
|
}
|
|
2609
|
-
|
|
2610
|
-
|
|
2611
|
-
|
|
2612
|
-
|
|
2613
|
-
|
|
2726
|
+
/**
|
|
2727
|
+
* Override if this node should receive a different scope than the parent
|
|
2728
|
+
* scope.
|
|
2729
|
+
*/
|
|
2730
|
+
createScope(parentScope) {
|
|
2731
|
+
this.scope = parentScope;
|
|
2614
2732
|
}
|
|
2615
|
-
|
|
2616
|
-
|
|
2617
|
-
|
|
2618
|
-
|
|
2619
|
-
|
|
2733
|
+
hasEffects(context) {
|
|
2734
|
+
if (!this.deoptimized)
|
|
2735
|
+
this.applyDeoptimizations();
|
|
2736
|
+
for (const key of childNodeKeys[this.type]) {
|
|
2737
|
+
const value = this[key];
|
|
2738
|
+
if (value === null)
|
|
2739
|
+
continue;
|
|
2740
|
+
if (Array.isArray(value)) {
|
|
2741
|
+
for (const child of value) {
|
|
2742
|
+
if (child?.hasEffects(context))
|
|
2743
|
+
return true;
|
|
2744
|
+
}
|
|
2745
|
+
}
|
|
2746
|
+
else if (value.hasEffects(context))
|
|
2747
|
+
return true;
|
|
2620
2748
|
}
|
|
2621
|
-
return
|
|
2749
|
+
return false;
|
|
2622
2750
|
}
|
|
2623
|
-
|
|
2624
|
-
|
|
2625
|
-
|
|
2751
|
+
hasEffectsAsAssignmentTarget(context, _checkAccess) {
|
|
2752
|
+
return (this.hasEffects(context) ||
|
|
2753
|
+
this.hasEffectsOnInteractionAtPath(EMPTY_PATH, this.assignmentInteraction, context));
|
|
2754
|
+
}
|
|
2755
|
+
include(context, includeChildrenRecursively, _options) {
|
|
2756
|
+
if (!this.included)
|
|
2757
|
+
this.includeNode(context);
|
|
2758
|
+
for (const key of childNodeKeys[this.type]) {
|
|
2759
|
+
const value = this[key];
|
|
2760
|
+
if (value === null)
|
|
2761
|
+
continue;
|
|
2762
|
+
if (Array.isArray(value)) {
|
|
2763
|
+
for (const child of value) {
|
|
2764
|
+
child?.include(context, includeChildrenRecursively);
|
|
2765
|
+
}
|
|
2766
|
+
}
|
|
2767
|
+
else {
|
|
2768
|
+
value.include(context, includeChildrenRecursively);
|
|
2769
|
+
}
|
|
2626
2770
|
}
|
|
2627
|
-
|
|
2628
|
-
|
|
2771
|
+
}
|
|
2772
|
+
includeNode(context) {
|
|
2773
|
+
this.included = true;
|
|
2774
|
+
if (!this.deoptimized)
|
|
2775
|
+
this.applyDeoptimizations();
|
|
2776
|
+
for (const key of childNodeKeys[this.type]) {
|
|
2777
|
+
const value = this[key];
|
|
2778
|
+
if (value === null)
|
|
2779
|
+
continue;
|
|
2780
|
+
if (Array.isArray(value)) {
|
|
2781
|
+
for (const child of value) {
|
|
2782
|
+
child?.includePath(UNKNOWN_PATH, context);
|
|
2783
|
+
}
|
|
2784
|
+
}
|
|
2785
|
+
else {
|
|
2786
|
+
value.includePath(UNKNOWN_PATH, context);
|
|
2787
|
+
}
|
|
2629
2788
|
}
|
|
2630
|
-
return true;
|
|
2631
2789
|
}
|
|
2632
|
-
|
|
2633
|
-
|
|
2634
|
-
value: {
|
|
2635
|
-
hasEffectsWhenCalled: null,
|
|
2636
|
-
returns: UNKNOWN_LITERAL_NUMBER
|
|
2790
|
+
includeAsAssignmentTarget(context, includeChildrenRecursively, _deoptimizeAccess) {
|
|
2791
|
+
this.include(context, includeChildrenRecursively);
|
|
2637
2792
|
}
|
|
2638
|
-
|
|
2639
|
-
|
|
2640
|
-
|
|
2641
|
-
|
|
2642
|
-
|
|
2643
|
-
|
|
2644
|
-
|
|
2793
|
+
/**
|
|
2794
|
+
* Override to perform special initialisation steps after the scope is
|
|
2795
|
+
* initialised
|
|
2796
|
+
*/
|
|
2797
|
+
initialise() {
|
|
2798
|
+
this.scope.context.magicString.addSourcemapLocation(this.start);
|
|
2799
|
+
this.scope.context.magicString.addSourcemapLocation(this.end);
|
|
2645
2800
|
}
|
|
2646
|
-
|
|
2647
|
-
if (
|
|
2648
|
-
|
|
2649
|
-
|
|
2650
|
-
|
|
2651
|
-
return hasMemberEffectWhenCalled(literalStringMembers, path[0], interaction, context);
|
|
2801
|
+
removeAnnotations(code) {
|
|
2802
|
+
if (this.annotations) {
|
|
2803
|
+
for (const annotation of this.annotations) {
|
|
2804
|
+
code.remove(annotation.start, annotation.end);
|
|
2805
|
+
}
|
|
2652
2806
|
}
|
|
2653
|
-
return true;
|
|
2654
2807
|
}
|
|
2655
|
-
|
|
2656
|
-
const
|
|
2657
|
-
|
|
2658
|
-
|
|
2659
|
-
|
|
2808
|
+
render(code, options) {
|
|
2809
|
+
for (const key of childNodeKeys[this.type]) {
|
|
2810
|
+
const value = this[key];
|
|
2811
|
+
if (value === null)
|
|
2812
|
+
continue;
|
|
2813
|
+
if (Array.isArray(value)) {
|
|
2814
|
+
for (const child of value) {
|
|
2815
|
+
child?.render(code, options);
|
|
2816
|
+
}
|
|
2817
|
+
}
|
|
2818
|
+
else {
|
|
2819
|
+
value.render(code, options);
|
|
2820
|
+
}
|
|
2821
|
+
}
|
|
2660
2822
|
}
|
|
2661
|
-
|
|
2662
|
-
|
|
2663
|
-
value: {
|
|
2664
|
-
hasEffectsWhenCalled({ args }, context) {
|
|
2665
|
-
const argument1 = args[2];
|
|
2666
|
-
return (args.length < 3 ||
|
|
2667
|
-
(typeof argument1.getLiteralValueAtPath(EMPTY_PATH, SHARED_RECURSION_TRACKER, {
|
|
2668
|
-
deoptimizeCache() { }
|
|
2669
|
-
}) === 'symbol' &&
|
|
2670
|
-
argument1.hasEffectsOnInteractionAtPath(EMPTY_PATH, NODE_INTERACTION_UNKNOWN_CALL, context)));
|
|
2671
|
-
},
|
|
2672
|
-
returns: UNKNOWN_LITERAL_STRING
|
|
2823
|
+
setAssignedValue(value) {
|
|
2824
|
+
this.assignmentInteraction = { args: [null, value], type: INTERACTION_ASSIGNED };
|
|
2673
2825
|
}
|
|
2674
|
-
|
|
2675
|
-
|
|
2676
|
-
hasOwnProperty: returnsBoolean,
|
|
2677
|
-
isPrototypeOf: returnsBoolean,
|
|
2678
|
-
propertyIsEnumerable: returnsBoolean,
|
|
2679
|
-
toLocaleString: returnsString,
|
|
2680
|
-
toString: returnsString,
|
|
2681
|
-
valueOf: returnsUnknown
|
|
2682
|
-
});
|
|
2683
|
-
const literalBooleanMembers = assembleMemberDescriptions({
|
|
2684
|
-
valueOf: returnsBoolean
|
|
2685
|
-
}, objectMembers);
|
|
2686
|
-
const literalNumberMembers = assembleMemberDescriptions({
|
|
2687
|
-
toExponential: returnsString,
|
|
2688
|
-
toFixed: returnsString,
|
|
2689
|
-
toLocaleString: returnsString,
|
|
2690
|
-
toPrecision: returnsString,
|
|
2691
|
-
valueOf: returnsNumber
|
|
2692
|
-
}, objectMembers);
|
|
2693
|
-
/**
|
|
2694
|
-
* RegExp are stateful when they have the global or sticky flags set.
|
|
2695
|
-
* But if we actually don't use them, the side effect does not matter.
|
|
2696
|
-
* the check logic in `hasEffectsOnInteractionAtPath`.
|
|
2697
|
-
*/
|
|
2698
|
-
const literalRegExpMembers = assembleMemberDescriptions({
|
|
2699
|
-
exec: returnsUnknown,
|
|
2700
|
-
test: returnsBoolean
|
|
2701
|
-
}, objectMembers);
|
|
2702
|
-
const literalStringMembers = assembleMemberDescriptions({
|
|
2703
|
-
anchor: returnsString,
|
|
2704
|
-
at: returnsUnknown,
|
|
2705
|
-
big: returnsString,
|
|
2706
|
-
blink: returnsString,
|
|
2707
|
-
bold: returnsString,
|
|
2708
|
-
charAt: returnsString,
|
|
2709
|
-
charCodeAt: returnsNumber,
|
|
2710
|
-
codePointAt: returnsUnknown,
|
|
2711
|
-
concat: returnsString,
|
|
2712
|
-
endsWith: returnsBoolean,
|
|
2713
|
-
fixed: returnsString,
|
|
2714
|
-
fontcolor: returnsString,
|
|
2715
|
-
fontsize: returnsString,
|
|
2716
|
-
includes: returnsBoolean,
|
|
2717
|
-
indexOf: returnsNumber,
|
|
2718
|
-
italics: returnsString,
|
|
2719
|
-
lastIndexOf: returnsNumber,
|
|
2720
|
-
link: returnsString,
|
|
2721
|
-
localeCompare: returnsNumber,
|
|
2722
|
-
match: returnsUnknown,
|
|
2723
|
-
matchAll: returnsUnknown,
|
|
2724
|
-
normalize: returnsString,
|
|
2725
|
-
padEnd: returnsString,
|
|
2726
|
-
padStart: returnsString,
|
|
2727
|
-
repeat: returnsString,
|
|
2728
|
-
replace: stringReplace,
|
|
2729
|
-
replaceAll: stringReplace,
|
|
2730
|
-
search: returnsNumber,
|
|
2731
|
-
slice: returnsString,
|
|
2732
|
-
small: returnsString,
|
|
2733
|
-
split: returnsUnknown,
|
|
2734
|
-
startsWith: returnsBoolean,
|
|
2735
|
-
strike: returnsString,
|
|
2736
|
-
sub: returnsString,
|
|
2737
|
-
substr: returnsString,
|
|
2738
|
-
substring: returnsString,
|
|
2739
|
-
sup: returnsString,
|
|
2740
|
-
toLocaleLowerCase: returnsString,
|
|
2741
|
-
toLocaleUpperCase: returnsString,
|
|
2742
|
-
toLowerCase: returnsString,
|
|
2743
|
-
toString: returnsString, // overrides the toString() method of the Object object; it does not inherit Object.prototype.toString()
|
|
2744
|
-
toUpperCase: returnsString,
|
|
2745
|
-
trim: returnsString,
|
|
2746
|
-
trimEnd: returnsString,
|
|
2747
|
-
trimLeft: returnsString,
|
|
2748
|
-
trimRight: returnsString,
|
|
2749
|
-
trimStart: returnsString,
|
|
2750
|
-
valueOf: returnsString
|
|
2751
|
-
}, objectMembers);
|
|
2752
|
-
function getLiteralMembersForValue(value) {
|
|
2753
|
-
if (value instanceof RegExp) {
|
|
2754
|
-
return literalRegExpMembers;
|
|
2826
|
+
shouldBeIncluded(context) {
|
|
2827
|
+
return this.included || (!context.brokenFlow && this.hasEffects(createHasEffectsContext()));
|
|
2755
2828
|
}
|
|
2756
|
-
|
|
2757
|
-
|
|
2758
|
-
|
|
2759
|
-
|
|
2760
|
-
|
|
2761
|
-
|
|
2762
|
-
|
|
2763
|
-
|
|
2764
|
-
|
|
2829
|
+
/**
|
|
2830
|
+
* Just deoptimize everything by default so that when e.g. we do not track
|
|
2831
|
+
* something properly, it is deoptimized.
|
|
2832
|
+
* @protected
|
|
2833
|
+
*/
|
|
2834
|
+
applyDeoptimizations() {
|
|
2835
|
+
this.deoptimized = true;
|
|
2836
|
+
for (const key of childNodeKeys[this.type]) {
|
|
2837
|
+
const value = this[key];
|
|
2838
|
+
if (value === null)
|
|
2839
|
+
continue;
|
|
2840
|
+
if (Array.isArray(value)) {
|
|
2841
|
+
for (const child of value) {
|
|
2842
|
+
child?.deoptimizePath(UNKNOWN_PATH);
|
|
2843
|
+
}
|
|
2844
|
+
}
|
|
2845
|
+
else {
|
|
2846
|
+
value.deoptimizePath(UNKNOWN_PATH);
|
|
2847
|
+
}
|
|
2765
2848
|
}
|
|
2849
|
+
this.scope.context.requestTreeshakingPass();
|
|
2766
2850
|
}
|
|
2767
|
-
return Object.create(null);
|
|
2768
2851
|
}
|
|
2769
|
-
function
|
|
2770
|
-
|
|
2771
|
-
|
|
2772
|
-
|
|
2773
|
-
return members[memberName].hasEffectsWhenCalled?.(interaction, context) || false;
|
|
2852
|
+
function onlyIncludeSelf() {
|
|
2853
|
+
this.included = true;
|
|
2854
|
+
if (!this.deoptimized)
|
|
2855
|
+
this.applyDeoptimizations();
|
|
2774
2856
|
}
|
|
2775
|
-
function
|
|
2776
|
-
|
|
2777
|
-
|
|
2778
|
-
|
|
2857
|
+
function onlyIncludeSelfNoDeoptimize() {
|
|
2858
|
+
this.included = true;
|
|
2859
|
+
}
|
|
2860
|
+
function doNotDeoptimize() {
|
|
2861
|
+
this.deoptimized = true;
|
|
2862
|
+
}
|
|
2863
|
+
|
|
2864
|
+
function isObjectExpressionNode(node) {
|
|
2865
|
+
return node instanceof NodeBase && node.type === ObjectExpression$1;
|
|
2866
|
+
}
|
|
2867
|
+
function isArrowFunctionExpressionNode(node) {
|
|
2868
|
+
return node instanceof NodeBase && node.type === ArrowFunctionExpression$1;
|
|
2869
|
+
}
|
|
2870
|
+
function isFunctionExpressionNode(node) {
|
|
2871
|
+
return node instanceof NodeBase && node.type === FunctionExpression$1;
|
|
2872
|
+
}
|
|
2873
|
+
function isIdentifierNode(node) {
|
|
2874
|
+
return node instanceof NodeBase && node.type === Identifier$1;
|
|
2779
2875
|
}
|
|
2780
2876
|
|
|
2877
|
+
// To avoid infinite recursions
|
|
2878
|
+
const MAX_PATH_DEPTH = 6;
|
|
2879
|
+
// If a path is longer than MAX_PATH_DEPTH, it is truncated so that it is at
|
|
2880
|
+
// most MAX_PATH_DEPTH long. The last element is always UnknownKey
|
|
2881
|
+
const limitConcatenatedPathDepth = (path1, path2) => {
|
|
2882
|
+
const { length: length1 } = path1;
|
|
2883
|
+
const { length: length2 } = path2;
|
|
2884
|
+
return length1 === 0
|
|
2885
|
+
? path2
|
|
2886
|
+
: length2 === 0
|
|
2887
|
+
? path1
|
|
2888
|
+
: length1 + length2 > MAX_PATH_DEPTH
|
|
2889
|
+
? [...path1, ...path2.slice(0, MAX_PATH_DEPTH - 1 - path1.length), 'UnknownKey']
|
|
2890
|
+
: [...path1, ...path2];
|
|
2891
|
+
};
|
|
2892
|
+
|
|
2781
2893
|
class Variable extends ExpressionEntity {
|
|
2782
2894
|
markReassigned() {
|
|
2783
2895
|
this.isReassigned = true;
|
|
2784
2896
|
}
|
|
2897
|
+
markTargetOfAssignment() {
|
|
2898
|
+
this.isTargetOfAssignment = true;
|
|
2899
|
+
}
|
|
2785
2900
|
constructor(name) {
|
|
2786
2901
|
super();
|
|
2787
2902
|
this.name = name;
|
|
@@ -2794,6 +2909,9 @@ class Variable extends ExpressionEntity {
|
|
|
2794
2909
|
this.renderBaseName = null;
|
|
2795
2910
|
this.renderName = null;
|
|
2796
2911
|
this.isReassigned = false;
|
|
2912
|
+
// Unlike isReassigned, set eagerly during binding for every assignment,
|
|
2913
|
+
// including ones that are never included
|
|
2914
|
+
this.isTargetOfAssignment = false;
|
|
2797
2915
|
this.onlyFunctionCallUsed = true;
|
|
2798
2916
|
}
|
|
2799
2917
|
/**
|
|
@@ -2882,10 +3000,9 @@ class LocalVariable extends Variable {
|
|
|
2882
3000
|
this.kind = kind;
|
|
2883
3001
|
this.calledFromTryStatement = false;
|
|
2884
3002
|
this.additionalInitializers = null;
|
|
2885
|
-
// A possibly incomplete list of
|
|
2886
|
-
//
|
|
2887
|
-
|
|
2888
|
-
this.reassignedValues = null;
|
|
3003
|
+
// A possibly incomplete list of functions assigned to this variable; only used
|
|
3004
|
+
// to retain call arguments of assigned try-catch helpers, never for value queries
|
|
3005
|
+
this.assignedFunctions = null;
|
|
2889
3006
|
this.includedPathTracker = new IncludedFullPathTracker();
|
|
2890
3007
|
this.expressionsToBeDeoptimized = [];
|
|
2891
3008
|
this.declarations = declarator ? [declarator] : [];
|
|
@@ -3011,16 +3128,12 @@ class LocalVariable extends Variable {
|
|
|
3011
3128
|
}
|
|
3012
3129
|
includeCallArgumentsWhenCalledAtPath(path, interaction, context) {
|
|
3013
3130
|
if (this.isReassigned) {
|
|
3014
|
-
//
|
|
3015
|
-
//
|
|
3131
|
+
// The value may still be one of the assigned functions, whose try-catch
|
|
3132
|
+
// helpers need their call arguments retained
|
|
3016
3133
|
includeInteraction(interaction, context);
|
|
3017
|
-
|
|
3018
|
-
|
|
3019
|
-
|
|
3020
|
-
const previousTracker = context.includedCallArgumentsOfPossibleValues;
|
|
3021
|
-
context.includedCallArgumentsOfPossibleValues ??= new DiscriminatedPathTracker();
|
|
3022
|
-
this.includeCallArgumentsOfPossibleValues(path, interaction, context, context.includedCallArgumentsOfPossibleValues);
|
|
3023
|
-
context.includedCallArgumentsOfPossibleValues = previousTracker;
|
|
3134
|
+
if (path.length === 0) {
|
|
3135
|
+
this.includeCallArgumentsOfAssignedTryCatchHelpers(interaction, context);
|
|
3136
|
+
}
|
|
3024
3137
|
return;
|
|
3025
3138
|
}
|
|
3026
3139
|
if (context.includedCallArguments.has(this.init) ||
|
|
@@ -3032,25 +3145,25 @@ class LocalVariable extends Variable {
|
|
|
3032
3145
|
this.init.includeCallArgumentsWhenCalledAtPath([...this.initPath, ...path], interaction, context);
|
|
3033
3146
|
context.includedCallArguments.delete(this.init);
|
|
3034
3147
|
}
|
|
3035
|
-
|
|
3036
|
-
if (this.
|
|
3037
|
-
|
|
3148
|
+
includeCallArgumentsOfAssignedTryCatchHelpers(interaction, context) {
|
|
3149
|
+
if (this.initPath.length === 0) {
|
|
3150
|
+
this.includeCallArgumentsOfTryCatchHelper(this.init, interaction, context);
|
|
3038
3151
|
}
|
|
3039
|
-
|
|
3040
|
-
|
|
3041
|
-
this.includeCallArgumentsOfPossibleValue(entity, path, interaction, context, tracker);
|
|
3152
|
+
for (const assignedFunction of this.assignedFunctions ?? EMPTY_ARRAY) {
|
|
3153
|
+
this.includeCallArgumentsOfTryCatchHelper(assignedFunction, interaction, context);
|
|
3042
3154
|
}
|
|
3043
3155
|
}
|
|
3044
|
-
|
|
3045
|
-
if (
|
|
3046
|
-
|
|
3047
|
-
|
|
3048
|
-
|
|
3156
|
+
includeCallArgumentsOfTryCatchHelper(value, interaction, context) {
|
|
3157
|
+
if (isArrowFunctionExpressionNode(value) || isFunctionExpressionNode(value)) {
|
|
3158
|
+
if (value.scope.hasParameterCalledFromTryStatement()) {
|
|
3159
|
+
value.scope.includeCallArguments(interaction, context);
|
|
3160
|
+
}
|
|
3049
3161
|
}
|
|
3050
|
-
entity.includeCallArgumentsWhenCalledAtPath(path, interaction, context);
|
|
3051
3162
|
}
|
|
3052
3163
|
addReassignedValue(value) {
|
|
3053
|
-
(
|
|
3164
|
+
if (isArrowFunctionExpressionNode(value) || isFunctionExpressionNode(value)) {
|
|
3165
|
+
(this.assignedFunctions ??= []).push(value);
|
|
3166
|
+
}
|
|
3054
3167
|
}
|
|
3055
3168
|
markCalledFromTryStatement() {
|
|
3056
3169
|
this.calledFromTryStatement = true;
|
|
@@ -3263,37 +3376,6 @@ function is_reference(node, parent) {
|
|
|
3263
3376
|
}
|
|
3264
3377
|
}
|
|
3265
3378
|
|
|
3266
|
-
function createInclusionContext() {
|
|
3267
|
-
return {
|
|
3268
|
-
brokenFlow: false,
|
|
3269
|
-
hasBreak: false,
|
|
3270
|
-
hasContinue: false,
|
|
3271
|
-
includedCallArguments: new Set(),
|
|
3272
|
-
includedCallArgumentsOfPossibleValues: null,
|
|
3273
|
-
includedLabels: new Set()
|
|
3274
|
-
};
|
|
3275
|
-
}
|
|
3276
|
-
function createHasEffectsContext() {
|
|
3277
|
-
return {
|
|
3278
|
-
accessed: new EntityPathTracker(),
|
|
3279
|
-
assigned: new EntityPathTracker(),
|
|
3280
|
-
brokenFlow: false,
|
|
3281
|
-
called: new DiscriminatedPathTracker(),
|
|
3282
|
-
hasBreak: false,
|
|
3283
|
-
hasContinue: false,
|
|
3284
|
-
ignore: {
|
|
3285
|
-
breaks: false,
|
|
3286
|
-
continues: false,
|
|
3287
|
-
labels: new Set(),
|
|
3288
|
-
returnYield: false,
|
|
3289
|
-
this: false
|
|
3290
|
-
},
|
|
3291
|
-
includedLabels: new Set(),
|
|
3292
|
-
instantiated: new DiscriminatedPathTracker(),
|
|
3293
|
-
replacedVariableInits: new Map()
|
|
3294
|
-
};
|
|
3295
|
-
}
|
|
3296
|
-
|
|
3297
3379
|
const PureFunctionKey = Symbol('PureFunction');
|
|
3298
3380
|
const getPureFunctions = ({ treeshake }) => {
|
|
3299
3381
|
const pureFunctions = Object.create(null);
|
|
@@ -3488,297 +3570,215 @@ function markModuleAndImpureDependenciesAsExecuted(baseModule) {
|
|
|
3488
3570
|
(dependency.info.moduleSideEffects || module.implicitlyLoadedBefore.has(dependency)) &&
|
|
3489
3571
|
!visitedModules.has(dependency.id)) {
|
|
3490
3572
|
dependency.isExecuted = true;
|
|
3491
|
-
visitedModules.add(dependency.id);
|
|
3492
|
-
modules.push(dependency);
|
|
3493
|
-
}
|
|
3494
|
-
}
|
|
3495
|
-
}
|
|
3496
|
-
}
|
|
3497
|
-
|
|
3498
|
-
const doNothing = () => { };
|
|
3499
|
-
|
|
3500
|
-
// This file is generated by scripts/generate-child-node-keys.ts.
|
|
3501
|
-
// Do not edit this file directly.
|
|
3502
|
-
const childNodeKeys = {
|
|
3503
|
-
ArrayExpression: ['elements'],
|
|
3504
|
-
ArrayPattern: ['elements'],
|
|
3505
|
-
ArrowFunctionExpression: ['params', 'body'],
|
|
3506
|
-
AssignmentExpression: ['left', 'right'],
|
|
3507
|
-
AssignmentPattern: ['left', 'right'],
|
|
3508
|
-
AwaitExpression: ['argument'],
|
|
3509
|
-
BinaryExpression: ['left', 'right'],
|
|
3510
|
-
BlockStatement: ['body'],
|
|
3511
|
-
BreakStatement: ['label'],
|
|
3512
|
-
CallExpression: ['callee', 'arguments'],
|
|
3513
|
-
CatchClause: ['param', 'body'],
|
|
3514
|
-
ChainExpression: ['expression'],
|
|
3515
|
-
ClassBody: ['body'],
|
|
3516
|
-
ClassDeclaration: ['decorators', 'id', 'superClass', 'body'],
|
|
3517
|
-
ClassExpression: ['decorators', 'id', 'superClass', 'body'],
|
|
3518
|
-
ConditionalExpression: ['test', 'consequent', 'alternate'],
|
|
3519
|
-
ContinueStatement: ['label'],
|
|
3520
|
-
DebuggerStatement: [],
|
|
3521
|
-
Decorator: ['expression'],
|
|
3522
|
-
DoWhileStatement: ['body', 'test'],
|
|
3523
|
-
EmptyStatement: [],
|
|
3524
|
-
ExportAllDeclaration: ['exported', 'source', 'attributes'],
|
|
3525
|
-
ExportDefaultDeclaration: ['declaration'],
|
|
3526
|
-
ExportNamedDeclaration: ['specifiers', 'source', 'attributes', 'declaration'],
|
|
3527
|
-
ExportSpecifier: ['local', 'exported'],
|
|
3528
|
-
ExpressionStatement: ['expression'],
|
|
3529
|
-
ForInStatement: ['left', 'right', 'body'],
|
|
3530
|
-
ForOfStatement: ['left', 'right', 'body'],
|
|
3531
|
-
ForStatement: ['init', 'test', 'update', 'body'],
|
|
3532
|
-
FunctionDeclaration: ['id', 'params', 'body'],
|
|
3533
|
-
FunctionExpression: ['id', 'params', 'body'],
|
|
3534
|
-
Identifier: [],
|
|
3535
|
-
IfStatement: ['test', 'consequent', 'alternate'],
|
|
3536
|
-
ImportAttribute: ['key', 'value'],
|
|
3537
|
-
ImportDeclaration: ['specifiers', 'source', 'attributes'],
|
|
3538
|
-
ImportDefaultSpecifier: ['local'],
|
|
3539
|
-
ImportExpression: ['source', 'options'],
|
|
3540
|
-
ImportNamespaceSpecifier: ['local'],
|
|
3541
|
-
ImportSpecifier: ['imported', 'local'],
|
|
3542
|
-
JSXAttribute: ['name', 'value'],
|
|
3543
|
-
JSXClosingElement: ['name'],
|
|
3544
|
-
JSXClosingFragment: [],
|
|
3545
|
-
JSXElement: ['openingElement', 'children', 'closingElement'],
|
|
3546
|
-
JSXEmptyExpression: [],
|
|
3547
|
-
JSXExpressionContainer: ['expression'],
|
|
3548
|
-
JSXFragment: ['openingFragment', 'children', 'closingFragment'],
|
|
3549
|
-
JSXIdentifier: [],
|
|
3550
|
-
JSXMemberExpression: ['object', 'property'],
|
|
3551
|
-
JSXNamespacedName: ['namespace', 'name'],
|
|
3552
|
-
JSXOpeningElement: ['name', 'attributes'],
|
|
3553
|
-
JSXOpeningFragment: [],
|
|
3554
|
-
JSXSpreadAttribute: ['argument'],
|
|
3555
|
-
JSXSpreadChild: ['expression'],
|
|
3556
|
-
JSXText: [],
|
|
3557
|
-
LabeledStatement: ['label', 'body'],
|
|
3558
|
-
Literal: [],
|
|
3559
|
-
LogicalExpression: ['left', 'right'],
|
|
3560
|
-
MemberExpression: ['object', 'property'],
|
|
3561
|
-
MetaProperty: ['meta', 'property'],
|
|
3562
|
-
MethodDefinition: ['decorators', 'key', 'value'],
|
|
3563
|
-
NewExpression: ['callee', 'arguments'],
|
|
3564
|
-
ObjectExpression: ['properties'],
|
|
3565
|
-
ObjectPattern: ['properties'],
|
|
3566
|
-
PanicError: [],
|
|
3567
|
-
ParseError: [],
|
|
3568
|
-
PrivateIdentifier: [],
|
|
3569
|
-
Program: ['body'],
|
|
3570
|
-
Property: ['key', 'value'],
|
|
3571
|
-
PropertyDefinition: ['decorators', 'key', 'value'],
|
|
3572
|
-
RestElement: ['argument'],
|
|
3573
|
-
ReturnStatement: ['argument'],
|
|
3574
|
-
SequenceExpression: ['expressions'],
|
|
3575
|
-
SpreadElement: ['argument'],
|
|
3576
|
-
StaticBlock: ['body'],
|
|
3577
|
-
Super: [],
|
|
3578
|
-
SwitchCase: ['test', 'consequent'],
|
|
3579
|
-
SwitchStatement: ['discriminant', 'cases'],
|
|
3580
|
-
TaggedTemplateExpression: ['tag', 'quasi'],
|
|
3581
|
-
TemplateElement: [],
|
|
3582
|
-
TemplateLiteral: ['quasis', 'expressions'],
|
|
3583
|
-
ThisExpression: [],
|
|
3584
|
-
ThrowStatement: ['argument'],
|
|
3585
|
-
TryStatement: ['block', 'handler', 'finalizer'],
|
|
3586
|
-
UnaryExpression: ['argument'],
|
|
3587
|
-
UpdateExpression: ['argument'],
|
|
3588
|
-
VariableDeclaration: ['declarations'],
|
|
3589
|
-
VariableDeclarator: ['id', 'init'],
|
|
3590
|
-
WhileStatement: ['test', 'body'],
|
|
3591
|
-
YieldExpression: ['argument']
|
|
3592
|
-
};
|
|
3593
|
-
|
|
3594
|
-
const INCLUDE_PARAMETERS = 'variables';
|
|
3595
|
-
const IS_SKIPPED_CHAIN = Symbol('IS_SKIPPED_CHAIN');
|
|
3596
|
-
class NodeBase extends ExpressionEntity {
|
|
3597
|
-
/**
|
|
3598
|
-
* Nodes can apply custom deoptimizations once they become part of the
|
|
3599
|
-
* executed code. To do this, they must initialize this as false, implement
|
|
3600
|
-
* applyDeoptimizations and call this from include and hasEffects if they have
|
|
3601
|
-
* custom handlers
|
|
3602
|
-
*/
|
|
3603
|
-
get deoptimized() {
|
|
3604
|
-
return isFlagSet(this.flags, 2 /* Flag.deoptimized */);
|
|
3605
|
-
}
|
|
3606
|
-
set deoptimized(value) {
|
|
3607
|
-
this.flags = setFlag(this.flags, 2 /* Flag.deoptimized */, value);
|
|
3608
|
-
}
|
|
3609
|
-
constructor(parent, parentScope) {
|
|
3610
|
-
super();
|
|
3611
|
-
this.parent = parent;
|
|
3612
|
-
this.scope = parentScope;
|
|
3613
|
-
this.createScope(parentScope);
|
|
3614
|
-
}
|
|
3615
|
-
addExportedVariables(_variables, _exportNamesByVariable) { }
|
|
3616
|
-
/**
|
|
3617
|
-
* Override this to bind assignments to variables and do any initialisations
|
|
3618
|
-
* that require the scopes to be populated with variables.
|
|
3619
|
-
*/
|
|
3620
|
-
bind() {
|
|
3621
|
-
for (const key of childNodeKeys[this.type]) {
|
|
3622
|
-
const value = this[key];
|
|
3623
|
-
if (Array.isArray(value)) {
|
|
3624
|
-
for (const child of value) {
|
|
3625
|
-
child?.bind();
|
|
3626
|
-
}
|
|
3627
|
-
}
|
|
3628
|
-
else if (value) {
|
|
3629
|
-
value.bind();
|
|
3630
|
-
}
|
|
3631
|
-
}
|
|
3632
|
-
}
|
|
3633
|
-
/**
|
|
3634
|
-
* Override if this node should receive a different scope than the parent
|
|
3635
|
-
* scope.
|
|
3636
|
-
*/
|
|
3637
|
-
createScope(parentScope) {
|
|
3638
|
-
this.scope = parentScope;
|
|
3639
|
-
}
|
|
3640
|
-
hasEffects(context) {
|
|
3641
|
-
if (!this.deoptimized)
|
|
3642
|
-
this.applyDeoptimizations();
|
|
3643
|
-
for (const key of childNodeKeys[this.type]) {
|
|
3644
|
-
const value = this[key];
|
|
3645
|
-
if (value === null)
|
|
3646
|
-
continue;
|
|
3647
|
-
if (Array.isArray(value)) {
|
|
3648
|
-
for (const child of value) {
|
|
3649
|
-
if (child?.hasEffects(context))
|
|
3650
|
-
return true;
|
|
3651
|
-
}
|
|
3573
|
+
visitedModules.add(dependency.id);
|
|
3574
|
+
modules.push(dependency);
|
|
3652
3575
|
}
|
|
3653
|
-
else if (value.hasEffects(context))
|
|
3654
|
-
return true;
|
|
3655
3576
|
}
|
|
3656
|
-
return false;
|
|
3657
3577
|
}
|
|
3658
|
-
|
|
3659
|
-
|
|
3660
|
-
|
|
3578
|
+
}
|
|
3579
|
+
|
|
3580
|
+
const doNothing = () => { };
|
|
3581
|
+
|
|
3582
|
+
function assembleMemberDescriptions(memberDescriptions, inheritedDescriptions = null) {
|
|
3583
|
+
return Object.create(inheritedDescriptions, memberDescriptions);
|
|
3584
|
+
}
|
|
3585
|
+
const UNDEFINED_EXPRESSION = new (class UndefinedExpression extends ExpressionEntity {
|
|
3586
|
+
getLiteralValueAtPath(path) {
|
|
3587
|
+
return path.length > 0 ? UnknownValue : undefined;
|
|
3661
3588
|
}
|
|
3662
|
-
|
|
3663
|
-
|
|
3664
|
-
|
|
3665
|
-
|
|
3666
|
-
|
|
3667
|
-
|
|
3668
|
-
|
|
3669
|
-
|
|
3670
|
-
|
|
3671
|
-
|
|
3672
|
-
|
|
3673
|
-
}
|
|
3674
|
-
else {
|
|
3675
|
-
value.include(context, includeChildrenRecursively);
|
|
3676
|
-
}
|
|
3589
|
+
})();
|
|
3590
|
+
const returnsUnknown = {
|
|
3591
|
+
value: {
|
|
3592
|
+
hasEffectsWhenCalled: null,
|
|
3593
|
+
returns: UNKNOWN_EXPRESSION
|
|
3594
|
+
}
|
|
3595
|
+
};
|
|
3596
|
+
const UNKNOWN_LITERAL_BOOLEAN = new (class UnknownBoolean extends ExpressionEntity {
|
|
3597
|
+
getReturnExpressionWhenCalledAtPath(path) {
|
|
3598
|
+
if (path.length === 1) {
|
|
3599
|
+
return getMemberReturnExpressionWhenCalled(literalBooleanMembers, path[0]);
|
|
3677
3600
|
}
|
|
3601
|
+
return UNKNOWN_RETURN_EXPRESSION;
|
|
3678
3602
|
}
|
|
3679
|
-
|
|
3680
|
-
|
|
3681
|
-
|
|
3682
|
-
this.applyDeoptimizations();
|
|
3683
|
-
for (const key of childNodeKeys[this.type]) {
|
|
3684
|
-
const value = this[key];
|
|
3685
|
-
if (value === null)
|
|
3686
|
-
continue;
|
|
3687
|
-
if (Array.isArray(value)) {
|
|
3688
|
-
for (const child of value) {
|
|
3689
|
-
child?.includePath(UNKNOWN_PATH, context);
|
|
3690
|
-
}
|
|
3691
|
-
}
|
|
3692
|
-
else {
|
|
3693
|
-
value.includePath(UNKNOWN_PATH, context);
|
|
3694
|
-
}
|
|
3603
|
+
hasEffectsOnInteractionAtPath(path, interaction, context) {
|
|
3604
|
+
if (interaction.type === INTERACTION_ACCESSED) {
|
|
3605
|
+
return path.length > 1;
|
|
3695
3606
|
}
|
|
3607
|
+
if (interaction.type === INTERACTION_CALLED && path.length === 1) {
|
|
3608
|
+
return hasMemberEffectWhenCalled(literalBooleanMembers, path[0], interaction, context);
|
|
3609
|
+
}
|
|
3610
|
+
return true;
|
|
3696
3611
|
}
|
|
3697
|
-
|
|
3698
|
-
|
|
3612
|
+
})();
|
|
3613
|
+
const returnsBoolean = {
|
|
3614
|
+
value: {
|
|
3615
|
+
hasEffectsWhenCalled: null,
|
|
3616
|
+
returns: UNKNOWN_LITERAL_BOOLEAN
|
|
3699
3617
|
}
|
|
3700
|
-
|
|
3701
|
-
|
|
3702
|
-
|
|
3703
|
-
|
|
3704
|
-
|
|
3705
|
-
|
|
3706
|
-
|
|
3618
|
+
};
|
|
3619
|
+
const UNKNOWN_LITERAL_NUMBER = new (class UnknownNumber extends ExpressionEntity {
|
|
3620
|
+
getReturnExpressionWhenCalledAtPath(path) {
|
|
3621
|
+
if (path.length === 1) {
|
|
3622
|
+
return getMemberReturnExpressionWhenCalled(literalNumberMembers, path[0]);
|
|
3623
|
+
}
|
|
3624
|
+
return UNKNOWN_RETURN_EXPRESSION;
|
|
3707
3625
|
}
|
|
3708
|
-
|
|
3709
|
-
if (
|
|
3710
|
-
|
|
3711
|
-
|
|
3712
|
-
|
|
3626
|
+
hasEffectsOnInteractionAtPath(path, interaction, context) {
|
|
3627
|
+
if (interaction.type === INTERACTION_ACCESSED) {
|
|
3628
|
+
return path.length > 1;
|
|
3629
|
+
}
|
|
3630
|
+
if (interaction.type === INTERACTION_CALLED && path.length === 1) {
|
|
3631
|
+
return hasMemberEffectWhenCalled(literalNumberMembers, path[0], interaction, context);
|
|
3713
3632
|
}
|
|
3633
|
+
return true;
|
|
3714
3634
|
}
|
|
3715
|
-
|
|
3716
|
-
|
|
3717
|
-
|
|
3718
|
-
|
|
3719
|
-
|
|
3720
|
-
|
|
3721
|
-
|
|
3722
|
-
|
|
3723
|
-
|
|
3724
|
-
|
|
3725
|
-
|
|
3726
|
-
value.render(code, options);
|
|
3727
|
-
}
|
|
3635
|
+
})();
|
|
3636
|
+
const returnsNumber = {
|
|
3637
|
+
value: {
|
|
3638
|
+
hasEffectsWhenCalled: null,
|
|
3639
|
+
returns: UNKNOWN_LITERAL_NUMBER
|
|
3640
|
+
}
|
|
3641
|
+
};
|
|
3642
|
+
const UNKNOWN_LITERAL_STRING = new (class UnknownString extends ExpressionEntity {
|
|
3643
|
+
getReturnExpressionWhenCalledAtPath(path) {
|
|
3644
|
+
if (path.length === 1) {
|
|
3645
|
+
return getMemberReturnExpressionWhenCalled(literalStringMembers, path[0]);
|
|
3728
3646
|
}
|
|
3647
|
+
return UNKNOWN_RETURN_EXPRESSION;
|
|
3729
3648
|
}
|
|
3730
|
-
|
|
3731
|
-
|
|
3649
|
+
hasEffectsOnInteractionAtPath(path, interaction, context) {
|
|
3650
|
+
if (interaction.type === INTERACTION_ACCESSED) {
|
|
3651
|
+
return path.length > 1;
|
|
3652
|
+
}
|
|
3653
|
+
if (interaction.type === INTERACTION_CALLED && path.length === 1) {
|
|
3654
|
+
return hasMemberEffectWhenCalled(literalStringMembers, path[0], interaction, context);
|
|
3655
|
+
}
|
|
3656
|
+
return true;
|
|
3732
3657
|
}
|
|
3733
|
-
|
|
3734
|
-
|
|
3658
|
+
})();
|
|
3659
|
+
const returnsString = {
|
|
3660
|
+
value: {
|
|
3661
|
+
hasEffectsWhenCalled: null,
|
|
3662
|
+
returns: UNKNOWN_LITERAL_STRING
|
|
3735
3663
|
}
|
|
3736
|
-
|
|
3737
|
-
|
|
3738
|
-
|
|
3739
|
-
|
|
3740
|
-
|
|
3741
|
-
|
|
3742
|
-
|
|
3743
|
-
|
|
3744
|
-
|
|
3745
|
-
|
|
3746
|
-
|
|
3747
|
-
|
|
3748
|
-
|
|
3749
|
-
|
|
3750
|
-
|
|
3751
|
-
|
|
3752
|
-
|
|
3753
|
-
|
|
3754
|
-
|
|
3664
|
+
};
|
|
3665
|
+
const stringReplace = {
|
|
3666
|
+
value: {
|
|
3667
|
+
hasEffectsWhenCalled({ args }, context) {
|
|
3668
|
+
const argument1 = args[2];
|
|
3669
|
+
return (args.length < 3 ||
|
|
3670
|
+
(typeof argument1.getLiteralValueAtPath(EMPTY_PATH, SHARED_RECURSION_TRACKER, {
|
|
3671
|
+
deoptimizeCache() { }
|
|
3672
|
+
}) === 'symbol' &&
|
|
3673
|
+
argument1.hasEffectsOnInteractionAtPath(EMPTY_PATH, NODE_INTERACTION_UNKNOWN_CALL, context)));
|
|
3674
|
+
},
|
|
3675
|
+
returns: UNKNOWN_LITERAL_STRING
|
|
3676
|
+
}
|
|
3677
|
+
};
|
|
3678
|
+
const objectMembers = assembleMemberDescriptions({
|
|
3679
|
+
hasOwnProperty: returnsBoolean,
|
|
3680
|
+
isPrototypeOf: returnsBoolean,
|
|
3681
|
+
propertyIsEnumerable: returnsBoolean,
|
|
3682
|
+
toLocaleString: returnsString,
|
|
3683
|
+
toString: returnsString,
|
|
3684
|
+
valueOf: returnsUnknown
|
|
3685
|
+
});
|
|
3686
|
+
const literalBooleanMembers = assembleMemberDescriptions({
|
|
3687
|
+
valueOf: returnsBoolean
|
|
3688
|
+
}, objectMembers);
|
|
3689
|
+
const literalNumberMembers = assembleMemberDescriptions({
|
|
3690
|
+
toExponential: returnsString,
|
|
3691
|
+
toFixed: returnsString,
|
|
3692
|
+
toLocaleString: returnsString,
|
|
3693
|
+
toPrecision: returnsString,
|
|
3694
|
+
valueOf: returnsNumber
|
|
3695
|
+
}, objectMembers);
|
|
3696
|
+
/**
|
|
3697
|
+
* RegExp are stateful when they have the global or sticky flags set.
|
|
3698
|
+
* But if we actually don't use them, the side effect does not matter.
|
|
3699
|
+
* the check logic in `hasEffectsOnInteractionAtPath`.
|
|
3700
|
+
*/
|
|
3701
|
+
const literalRegExpMembers = assembleMemberDescriptions({
|
|
3702
|
+
exec: returnsUnknown,
|
|
3703
|
+
test: returnsBoolean
|
|
3704
|
+
}, objectMembers);
|
|
3705
|
+
const literalStringMembers = assembleMemberDescriptions({
|
|
3706
|
+
anchor: returnsString,
|
|
3707
|
+
at: returnsUnknown,
|
|
3708
|
+
big: returnsString,
|
|
3709
|
+
blink: returnsString,
|
|
3710
|
+
bold: returnsString,
|
|
3711
|
+
charAt: returnsString,
|
|
3712
|
+
charCodeAt: returnsNumber,
|
|
3713
|
+
codePointAt: returnsUnknown,
|
|
3714
|
+
concat: returnsString,
|
|
3715
|
+
endsWith: returnsBoolean,
|
|
3716
|
+
fixed: returnsString,
|
|
3717
|
+
fontcolor: returnsString,
|
|
3718
|
+
fontsize: returnsString,
|
|
3719
|
+
includes: returnsBoolean,
|
|
3720
|
+
indexOf: returnsNumber,
|
|
3721
|
+
italics: returnsString,
|
|
3722
|
+
lastIndexOf: returnsNumber,
|
|
3723
|
+
link: returnsString,
|
|
3724
|
+
localeCompare: returnsNumber,
|
|
3725
|
+
match: returnsUnknown,
|
|
3726
|
+
matchAll: returnsUnknown,
|
|
3727
|
+
normalize: returnsString,
|
|
3728
|
+
padEnd: returnsString,
|
|
3729
|
+
padStart: returnsString,
|
|
3730
|
+
repeat: returnsString,
|
|
3731
|
+
replace: stringReplace,
|
|
3732
|
+
replaceAll: stringReplace,
|
|
3733
|
+
search: returnsNumber,
|
|
3734
|
+
slice: returnsString,
|
|
3735
|
+
small: returnsString,
|
|
3736
|
+
split: returnsUnknown,
|
|
3737
|
+
startsWith: returnsBoolean,
|
|
3738
|
+
strike: returnsString,
|
|
3739
|
+
sub: returnsString,
|
|
3740
|
+
substr: returnsString,
|
|
3741
|
+
substring: returnsString,
|
|
3742
|
+
sup: returnsString,
|
|
3743
|
+
toLocaleLowerCase: returnsString,
|
|
3744
|
+
toLocaleUpperCase: returnsString,
|
|
3745
|
+
toLowerCase: returnsString,
|
|
3746
|
+
toString: returnsString, // overrides the toString() method of the Object object; it does not inherit Object.prototype.toString()
|
|
3747
|
+
toUpperCase: returnsString,
|
|
3748
|
+
trim: returnsString,
|
|
3749
|
+
trimEnd: returnsString,
|
|
3750
|
+
trimLeft: returnsString,
|
|
3751
|
+
trimRight: returnsString,
|
|
3752
|
+
trimStart: returnsString,
|
|
3753
|
+
valueOf: returnsString
|
|
3754
|
+
}, objectMembers);
|
|
3755
|
+
function getLiteralMembersForValue(value) {
|
|
3756
|
+
if (value instanceof RegExp) {
|
|
3757
|
+
return literalRegExpMembers;
|
|
3758
|
+
}
|
|
3759
|
+
switch (typeof value) {
|
|
3760
|
+
case 'boolean': {
|
|
3761
|
+
return literalBooleanMembers;
|
|
3762
|
+
}
|
|
3763
|
+
case 'number': {
|
|
3764
|
+
return literalNumberMembers;
|
|
3765
|
+
}
|
|
3766
|
+
case 'string': {
|
|
3767
|
+
return literalStringMembers;
|
|
3755
3768
|
}
|
|
3756
|
-
this.scope.context.requestTreeshakingPass();
|
|
3757
3769
|
}
|
|
3770
|
+
return Object.create(null);
|
|
3758
3771
|
}
|
|
3759
|
-
function
|
|
3760
|
-
|
|
3761
|
-
|
|
3762
|
-
|
|
3763
|
-
|
|
3764
|
-
function onlyIncludeSelfNoDeoptimize() {
|
|
3765
|
-
this.included = true;
|
|
3766
|
-
}
|
|
3767
|
-
function doNotDeoptimize() {
|
|
3768
|
-
this.deoptimized = true;
|
|
3769
|
-
}
|
|
3770
|
-
|
|
3771
|
-
function isObjectExpressionNode(node) {
|
|
3772
|
-
return node instanceof NodeBase && node.type === ObjectExpression$1;
|
|
3773
|
-
}
|
|
3774
|
-
function isArrowFunctionExpressionNode(node) {
|
|
3775
|
-
return node instanceof NodeBase && node.type === ArrowFunctionExpression$1;
|
|
3776
|
-
}
|
|
3777
|
-
function isFunctionExpressionNode(node) {
|
|
3778
|
-
return node instanceof NodeBase && node.type === FunctionExpression$1;
|
|
3772
|
+
function hasMemberEffectWhenCalled(members, memberName, interaction, context) {
|
|
3773
|
+
if (typeof memberName !== 'string' || !members[memberName]) {
|
|
3774
|
+
return true;
|
|
3775
|
+
}
|
|
3776
|
+
return members[memberName].hasEffectsWhenCalled?.(interaction, context) || false;
|
|
3779
3777
|
}
|
|
3780
|
-
function
|
|
3781
|
-
|
|
3778
|
+
function getMemberReturnExpressionWhenCalled(members, memberName) {
|
|
3779
|
+
if (typeof memberName !== 'string' || !members[memberName])
|
|
3780
|
+
return UNKNOWN_RETURN_EXPRESSION;
|
|
3781
|
+
return [members[memberName].returns, false];
|
|
3782
3782
|
}
|
|
3783
3783
|
|
|
3784
3784
|
class Method extends ExpressionEntity {
|
|
@@ -4618,6 +4618,18 @@ const PURE_WITH_ARRAY = {
|
|
|
4618
4618
|
return args.length > 1 && !(args[1] instanceof ArrayExpression);
|
|
4619
4619
|
}
|
|
4620
4620
|
};
|
|
4621
|
+
const PURE_WITH_ARRAY_OR_LENGTH = {
|
|
4622
|
+
deoptimizeArgumentsOnCall: doNothing,
|
|
4623
|
+
getLiteralValue: getUnknownValue,
|
|
4624
|
+
hasEffectsWhenCalled({ args }) {
|
|
4625
|
+
const [_thisArgument, firstArgument] = args;
|
|
4626
|
+
return (firstArgument !== undefined &&
|
|
4627
|
+
!(firstArgument instanceof ArrayExpression) &&
|
|
4628
|
+
typeof firstArgument.getLiteralValueAtPath(EMPTY_PATH, SHARED_RECURSION_TRACKER, {
|
|
4629
|
+
deoptimizeCache: doNothing
|
|
4630
|
+
}) !== 'number');
|
|
4631
|
+
}
|
|
4632
|
+
};
|
|
4621
4633
|
const GETTER_ACCESS = {
|
|
4622
4634
|
deoptimizeArgumentsOnCall: doNothing,
|
|
4623
4635
|
getLiteralValue: getUnknownValue,
|
|
@@ -4676,7 +4688,7 @@ const PC_WITH_ARRAY = {
|
|
|
4676
4688
|
};
|
|
4677
4689
|
const ARRAY_TYPE = {
|
|
4678
4690
|
__proto__: null,
|
|
4679
|
-
[ValueProperties]:
|
|
4691
|
+
[ValueProperties]: PURE_WITH_ARRAY_OR_LENGTH,
|
|
4680
4692
|
from: O,
|
|
4681
4693
|
of: PF,
|
|
4682
4694
|
prototype: O
|
|
@@ -5844,6 +5856,9 @@ class Identifier extends IdentifierBase {
|
|
|
5844
5856
|
this.variable = this.scope.findVariable(this.name);
|
|
5845
5857
|
this.variable.addReference(this);
|
|
5846
5858
|
this.isVariableReference = true;
|
|
5859
|
+
if (this.assignmentInteraction) {
|
|
5860
|
+
this.variable.markTargetOfAssignment();
|
|
5861
|
+
}
|
|
5847
5862
|
}
|
|
5848
5863
|
}
|
|
5849
5864
|
declare(kind, destructuredInitPath, init) {
|
|
@@ -6010,9 +6025,51 @@ class MethodDefinition extends PropertyBase {
|
|
|
6010
6025
|
}
|
|
6011
6026
|
}
|
|
6012
6027
|
|
|
6028
|
+
class PropertyDefinition extends NodeBase {
|
|
6029
|
+
get computed() {
|
|
6030
|
+
return isFlagSet(this.flags, 1024 /* Flag.computed */);
|
|
6031
|
+
}
|
|
6032
|
+
set computed(value) {
|
|
6033
|
+
this.flags = setFlag(this.flags, 1024 /* Flag.computed */, value);
|
|
6034
|
+
}
|
|
6035
|
+
deoptimizeArgumentsOnInteractionAtPath(interaction, path, recursionTracker) {
|
|
6036
|
+
this.value?.deoptimizeArgumentsOnInteractionAtPath(interaction, path, recursionTracker);
|
|
6037
|
+
}
|
|
6038
|
+
deoptimizePath(path) {
|
|
6039
|
+
this.value?.deoptimizePath(path);
|
|
6040
|
+
}
|
|
6041
|
+
getLiteralValueAtPath(path, recursionTracker, origin) {
|
|
6042
|
+
return this.value
|
|
6043
|
+
? this.value.getLiteralValueAtPath(path, recursionTracker, origin)
|
|
6044
|
+
: UnknownValue;
|
|
6045
|
+
}
|
|
6046
|
+
getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin) {
|
|
6047
|
+
return this.value
|
|
6048
|
+
? this.value.getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin)
|
|
6049
|
+
: UNKNOWN_RETURN_EXPRESSION;
|
|
6050
|
+
}
|
|
6051
|
+
hasEffects(context) {
|
|
6052
|
+
return (this.key.hasEffects(context) ||
|
|
6053
|
+
(this.static && !!this.value?.hasEffects(context)) ||
|
|
6054
|
+
checkEffectForNodes(this.decorators, context));
|
|
6055
|
+
}
|
|
6056
|
+
hasEffectsOnInteractionAtPath(path, interaction, context) {
|
|
6057
|
+
return !this.value || this.value.hasEffectsOnInteractionAtPath(path, interaction, context);
|
|
6058
|
+
}
|
|
6059
|
+
includeNode(context) {
|
|
6060
|
+
this.included = true;
|
|
6061
|
+
this.value?.includePath(UNKNOWN_PATH, context);
|
|
6062
|
+
for (const decorator of this.decorators) {
|
|
6063
|
+
decorator.includePath(UNKNOWN_PATH, context);
|
|
6064
|
+
}
|
|
6065
|
+
}
|
|
6066
|
+
}
|
|
6067
|
+
PropertyDefinition.prototype.applyDeoptimizations = doNotDeoptimize;
|
|
6068
|
+
|
|
6013
6069
|
class ClassNode extends NodeBase {
|
|
6014
6070
|
constructor() {
|
|
6015
6071
|
super(...arguments);
|
|
6072
|
+
this.instanceFieldValues = null;
|
|
6016
6073
|
this.objectEntity = null;
|
|
6017
6074
|
}
|
|
6018
6075
|
createScope(parentScope) {
|
|
@@ -6046,7 +6103,7 @@ class ClassNode extends NodeBase {
|
|
|
6046
6103
|
(this.classConstructor === null
|
|
6047
6104
|
? this.superClass?.hasEffectsOnInteractionAtPath(path, interaction, context)
|
|
6048
6105
|
: this.classConstructor.hasEffectsOnInteractionAtPath(path, interaction, context)) ||
|
|
6049
|
-
|
|
6106
|
+
this.hasEffectsOnInstanceFieldInitialization(context)
|
|
6050
6107
|
: this.getObjectEntity().hasEffectsOnInteractionAtPath(path, interaction, context);
|
|
6051
6108
|
}
|
|
6052
6109
|
include(context, includeChildrenRecursively) {
|
|
@@ -6064,6 +6121,10 @@ class ClassNode extends NodeBase {
|
|
|
6064
6121
|
initialise() {
|
|
6065
6122
|
super.initialise();
|
|
6066
6123
|
this.id?.declare('class', EMPTY_PATH, this);
|
|
6124
|
+
this.instanceEntity = new ObjectEntity(new Map(), new ObjectMember(this, ['prototype']));
|
|
6125
|
+
// This makes sure that all deoptimizations of "this" are applied to the
|
|
6126
|
+
// instance entity, even if the class is only instantiated by unknown code.
|
|
6127
|
+
this.body.scope.instanceThisVariable.addArgumentForDeoptimization(this.instanceEntity);
|
|
6067
6128
|
for (const method of this.body.body) {
|
|
6068
6129
|
if (method instanceof MethodDefinition && method.kind === 'constructor') {
|
|
6069
6130
|
this.classConstructor = method;
|
|
@@ -6084,6 +6145,36 @@ class ClassNode extends NodeBase {
|
|
|
6084
6145
|
}
|
|
6085
6146
|
this.scope.context.requestTreeshakingPass();
|
|
6086
6147
|
}
|
|
6148
|
+
hasEffectsOnInstanceFieldInitialization(context) {
|
|
6149
|
+
const fieldValues = this.getInstanceFieldValues();
|
|
6150
|
+
if (fieldValues.length === 0)
|
|
6151
|
+
return false;
|
|
6152
|
+
const { replacedVariableInits } = context;
|
|
6153
|
+
const thisVariable = this.body.scope.instanceThisVariable;
|
|
6154
|
+
const thisInit = replacedVariableInits.get(thisVariable);
|
|
6155
|
+
replacedVariableInits.set(thisVariable, this.instanceEntity);
|
|
6156
|
+
const hasEffects = fieldValues.some(value => value.hasEffects(context));
|
|
6157
|
+
if (thisInit) {
|
|
6158
|
+
replacedVariableInits.set(thisVariable, thisInit);
|
|
6159
|
+
}
|
|
6160
|
+
else {
|
|
6161
|
+
replacedVariableInits.delete(thisVariable);
|
|
6162
|
+
}
|
|
6163
|
+
return hasEffects;
|
|
6164
|
+
}
|
|
6165
|
+
getInstanceFieldValues() {
|
|
6166
|
+
if (this.instanceFieldValues === null) {
|
|
6167
|
+
this.instanceFieldValues = [];
|
|
6168
|
+
for (const definition of this.body.body) {
|
|
6169
|
+
if (definition instanceof PropertyDefinition &&
|
|
6170
|
+
!definition.static &&
|
|
6171
|
+
definition.value !== null) {
|
|
6172
|
+
this.instanceFieldValues.push(definition.value);
|
|
6173
|
+
}
|
|
6174
|
+
}
|
|
6175
|
+
}
|
|
6176
|
+
return this.instanceFieldValues;
|
|
6177
|
+
}
|
|
6087
6178
|
getObjectEntity() {
|
|
6088
6179
|
if (this.objectEntity !== null) {
|
|
6089
6180
|
return this.objectEntity;
|
|
@@ -6404,6 +6495,31 @@ class ThisVariable extends ParameterVariable {
|
|
|
6404
6495
|
}
|
|
6405
6496
|
}
|
|
6406
6497
|
|
|
6498
|
+
/**
|
|
6499
|
+
* Represents the return value of a function where all return statements return
|
|
6500
|
+
* the same variable that is the target of an assignment. As the assigned value
|
|
6501
|
+
* may replace the declaration initializer before the function returns, value
|
|
6502
|
+
* queries resolve to unknown, and call arguments are deoptimized directly
|
|
6503
|
+
* instead of being forwarded to the initializer alone.
|
|
6504
|
+
*/
|
|
6505
|
+
class ReturnedIdentifier extends ExpressionEntity {
|
|
6506
|
+
constructor(returnedIdentifier) {
|
|
6507
|
+
super();
|
|
6508
|
+
this.returnedIdentifier = returnedIdentifier;
|
|
6509
|
+
}
|
|
6510
|
+
deoptimizeArgumentsOnInteractionAtPath(interaction, path, recursionTracker) {
|
|
6511
|
+
// The initializer may never be the value that is returned
|
|
6512
|
+
deoptimizeInteraction(interaction);
|
|
6513
|
+
this.returnedIdentifier.deoptimizeArgumentsOnInteractionAtPath(interaction, path, recursionTracker);
|
|
6514
|
+
}
|
|
6515
|
+
deoptimizePath(path) {
|
|
6516
|
+
this.returnedIdentifier.deoptimizePath(path);
|
|
6517
|
+
}
|
|
6518
|
+
includeCallArgumentsWhenCalledAtPath(path, interaction, context) {
|
|
6519
|
+
this.returnedIdentifier.includeCallArgumentsWhenCalledAtPath(path, interaction, context);
|
|
6520
|
+
}
|
|
6521
|
+
}
|
|
6522
|
+
|
|
6407
6523
|
class CatchBodyScope extends ChildScope {
|
|
6408
6524
|
constructor(parent) {
|
|
6409
6525
|
super(parent, parent.context);
|
|
@@ -6512,6 +6628,9 @@ class ParameterScope extends ChildScope {
|
|
|
6512
6628
|
}
|
|
6513
6629
|
this.hasRest = hasRest;
|
|
6514
6630
|
}
|
|
6631
|
+
hasParameterCalledFromTryStatement() {
|
|
6632
|
+
return this.parameters.some(parameterVariables => parameterVariables.some(variable => variable.calledFromTryStatement));
|
|
6633
|
+
}
|
|
6515
6634
|
includeCallArguments({ args }, context) {
|
|
6516
6635
|
let calledFromTryStatement = false;
|
|
6517
6636
|
let argumentIncluded = false;
|
|
@@ -6635,21 +6754,21 @@ class ReturnValueScope extends ParameterScope {
|
|
|
6635
6754
|
addArgumentToBeDeoptimized(_argument) { }
|
|
6636
6755
|
updateReturnExpression() {
|
|
6637
6756
|
const { returnExpressions } = this;
|
|
6638
|
-
|
|
6639
|
-
|
|
6757
|
+
const [firstExpression] = returnExpressions;
|
|
6758
|
+
// A single return, or the same variable returned on all paths, can be
|
|
6759
|
+
// resolved to that variable
|
|
6760
|
+
if (firstExpression && this.returnExpressionsResolveToSameVariable(firstExpression)) {
|
|
6761
|
+
this.returnExpression = firstExpression.variable.isTargetOfAssignment
|
|
6762
|
+
? new ReturnedIdentifier(firstExpression)
|
|
6763
|
+
: firstExpression;
|
|
6764
|
+
}
|
|
6765
|
+
else if (returnExpressions.length === 1) {
|
|
6766
|
+
this.returnExpression = firstExpression;
|
|
6640
6767
|
}
|
|
6641
6768
|
else {
|
|
6642
|
-
|
|
6643
|
-
|
|
6644
|
-
|
|
6645
|
-
if (firstExpression && this.returnExpressionsResolveToSameVariable(firstExpression)) {
|
|
6646
|
-
this.returnExpression = firstExpression;
|
|
6647
|
-
}
|
|
6648
|
-
else {
|
|
6649
|
-
this.returnExpression = UNKNOWN_EXPRESSION;
|
|
6650
|
-
for (const expression of returnExpressions) {
|
|
6651
|
-
expression.deoptimizePath(UNKNOWN_PATH);
|
|
6652
|
-
}
|
|
6769
|
+
this.returnExpression = UNKNOWN_EXPRESSION;
|
|
6770
|
+
for (const expression of returnExpressions) {
|
|
6771
|
+
expression.deoptimizePath(UNKNOWN_PATH);
|
|
6653
6772
|
}
|
|
6654
6773
|
}
|
|
6655
6774
|
}
|
|
@@ -8395,7 +8514,7 @@ function getCompleteAmdId(options, chunkId) {
|
|
|
8395
8514
|
}
|
|
8396
8515
|
|
|
8397
8516
|
function getExportBlock$1(exports, dependencies, namedExportsMode, interop, snippets, t, externalLiveBindings, reexportProtoFromExternal, mechanism = 'return ') {
|
|
8398
|
-
const { _,
|
|
8517
|
+
const { _, getFunctionIntro, getPropertyAccess, n, s } = snippets;
|
|
8399
8518
|
if (!namedExportsMode) {
|
|
8400
8519
|
return `${n}${n}${mechanism}${getSingleDefaultExport(exports, dependencies, interop, externalLiveBindings, getPropertyAccess)};`;
|
|
8401
8520
|
}
|
|
@@ -8411,15 +8530,7 @@ function getExportBlock$1(exports, dependencies, namedExportsMode, interop, snip
|
|
|
8411
8530
|
if (exportBlock)
|
|
8412
8531
|
exportBlock += n;
|
|
8413
8532
|
if (specifier.imported !== '*' && specifier.needsLiveBinding) {
|
|
8414
|
-
|
|
8415
|
-
functionReturn: true,
|
|
8416
|
-
lineBreakIndent: null,
|
|
8417
|
-
name: null
|
|
8418
|
-
});
|
|
8419
|
-
exportBlock +=
|
|
8420
|
-
`Object.defineProperty(exports,${_}${JSON.stringify(specifier.reexported)},${_}{${n}` +
|
|
8421
|
-
`${t}enumerable:${_}true,${n}` +
|
|
8422
|
-
`${t}get:${_}${left}${importName}${right}${n}});`;
|
|
8533
|
+
exportBlock += `Object.defineProperty(exports,${_}${JSON.stringify(specifier.reexported)},${_}${getGetter(importName, false, t, snippets)});`;
|
|
8423
8534
|
}
|
|
8424
8535
|
else if (specifier.reexported === '__proto__') {
|
|
8425
8536
|
exportBlock +=
|
|
@@ -8434,12 +8545,16 @@ function getExportBlock$1(exports, dependencies, namedExportsMode, interop, snip
|
|
|
8434
8545
|
}
|
|
8435
8546
|
}
|
|
8436
8547
|
}
|
|
8437
|
-
for (const { exported, local } of exports) {
|
|
8548
|
+
for (const { exported, local, needsLiveBinding } of exports) {
|
|
8438
8549
|
const lhs = `exports${getPropertyAccess(exported)}`;
|
|
8439
8550
|
const rhs = local;
|
|
8440
8551
|
if (lhs !== rhs) {
|
|
8441
8552
|
if (exportBlock)
|
|
8442
8553
|
exportBlock += n;
|
|
8554
|
+
if (needsLiveBinding) {
|
|
8555
|
+
exportBlock += `Object.defineProperty(exports,${_}${JSON.stringify(exported)},${_}${getGetter(rhs, true, t, snippets)});`;
|
|
8556
|
+
continue;
|
|
8557
|
+
}
|
|
8443
8558
|
exportBlock +=
|
|
8444
8559
|
exported === '__proto__'
|
|
8445
8560
|
? `Object.defineProperty(exports,${_}"__proto__",${_}{${n}` +
|
|
@@ -8541,19 +8656,27 @@ function getNamespaceMarkers(hasNamedExports, addEsModule, addNamespaceToStringT
|
|
|
8541
8656
|
}
|
|
8542
8657
|
return '';
|
|
8543
8658
|
}
|
|
8544
|
-
const getDefineProperty = (name, needsLiveBinding, t,
|
|
8659
|
+
const getDefineProperty = (name, needsLiveBinding, t, snippets) => {
|
|
8660
|
+
const { _ } = snippets;
|
|
8545
8661
|
if (needsLiveBinding) {
|
|
8546
|
-
|
|
8547
|
-
functionReturn: true,
|
|
8548
|
-
lineBreakIndent: null,
|
|
8549
|
-
name: null
|
|
8550
|
-
});
|
|
8551
|
-
return (`Object.defineProperty(exports,${_}k,${_}{${n}` +
|
|
8552
|
-
`${t}${t}enumerable:${_}true,${n}` +
|
|
8553
|
-
`${t}${t}get:${_}${left}${name}[k]${right}${n}${t}})`);
|
|
8662
|
+
return `Object.defineProperty(exports,${_}k,${_}${getGetter(`${name}[k]`, false, t, snippets, t)})`;
|
|
8554
8663
|
}
|
|
8555
8664
|
return `exports[k]${_}=${_}${name}[k]`;
|
|
8556
8665
|
};
|
|
8666
|
+
const getGetter = (expression, configurable, t, { getDirectReturnFunction, getObject }, base = '') => {
|
|
8667
|
+
const [left, right] = getDirectReturnFunction([], {
|
|
8668
|
+
functionReturn: true,
|
|
8669
|
+
lineBreakIndent: null,
|
|
8670
|
+
name: null
|
|
8671
|
+
});
|
|
8672
|
+
const fields = [
|
|
8673
|
+
['enumerable', 'true'],
|
|
8674
|
+
['get', `${left}${expression}${right}`]
|
|
8675
|
+
];
|
|
8676
|
+
if (configurable)
|
|
8677
|
+
fields.unshift(['configurable', 'true']);
|
|
8678
|
+
return getObject(fields, { lineBreakIndent: { base, t } });
|
|
8679
|
+
};
|
|
8557
8680
|
|
|
8558
8681
|
function getInteropBlock(dependencies, interop, externalLiveBindings, freeze, symbols, accessedGlobals, indent, snippets) {
|
|
8559
8682
|
const { _, cnst, n } = snippets;
|
|
@@ -12043,6 +12166,14 @@ class ArrayPattern extends NodeBase {
|
|
|
12043
12166
|
}
|
|
12044
12167
|
}
|
|
12045
12168
|
}
|
|
12169
|
+
setAssignedValue(value) {
|
|
12170
|
+
super.setAssignedValue(value);
|
|
12171
|
+
// Destructuring assigns each target only some subpath of the assigned
|
|
12172
|
+
// value, which is not tracked
|
|
12173
|
+
for (const element of this.elements) {
|
|
12174
|
+
element?.setAssignedValue(UNKNOWN_EXPRESSION);
|
|
12175
|
+
}
|
|
12176
|
+
}
|
|
12046
12177
|
markDeclarationReached() {
|
|
12047
12178
|
for (const element of this.elements) {
|
|
12048
12179
|
element?.markDeclarationReached();
|
|
@@ -12212,6 +12343,14 @@ class ObjectPattern extends NodeBase {
|
|
|
12212
12343
|
}
|
|
12213
12344
|
}
|
|
12214
12345
|
}
|
|
12346
|
+
setAssignedValue(value) {
|
|
12347
|
+
super.setAssignedValue(value);
|
|
12348
|
+
// Destructuring assigns each target only some subpath of the assigned
|
|
12349
|
+
// value, which is not tracked
|
|
12350
|
+
for (const property of this.properties) {
|
|
12351
|
+
property.setAssignedValue(UNKNOWN_EXPRESSION);
|
|
12352
|
+
}
|
|
12353
|
+
}
|
|
12215
12354
|
}
|
|
12216
12355
|
ObjectPattern.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
|
|
12217
12356
|
ObjectPattern.prototype.applyDeoptimizations = doNotDeoptimize;
|
|
@@ -12376,6 +12515,9 @@ class AssignmentPattern extends NodeBase {
|
|
|
12376
12515
|
this.left.render(code, options, { isShorthandProperty });
|
|
12377
12516
|
this.right.render(code, options);
|
|
12378
12517
|
}
|
|
12518
|
+
setAssignedValue(value) {
|
|
12519
|
+
this.left.setAssignedValue(value);
|
|
12520
|
+
}
|
|
12379
12521
|
applyDeoptimizations() {
|
|
12380
12522
|
this.deoptimized = true;
|
|
12381
12523
|
this.left.deoptimizePath(EMPTY_PATH);
|
|
@@ -12384,6 +12526,22 @@ class AssignmentPattern extends NodeBase {
|
|
|
12384
12526
|
}
|
|
12385
12527
|
}
|
|
12386
12528
|
|
|
12529
|
+
function markTopLevelAwait(node) {
|
|
12530
|
+
if (node.scope.context.usesTopLevelAwait)
|
|
12531
|
+
return;
|
|
12532
|
+
let parent = node.parent;
|
|
12533
|
+
while (parent) {
|
|
12534
|
+
const { type } = parent;
|
|
12535
|
+
if (type === ArrowFunctionExpression$1 ||
|
|
12536
|
+
type === FunctionExpression$1 ||
|
|
12537
|
+
type === FunctionDeclaration$1) {
|
|
12538
|
+
return;
|
|
12539
|
+
}
|
|
12540
|
+
parent = parent.parent;
|
|
12541
|
+
}
|
|
12542
|
+
node.scope.context.usesTopLevelAwait = true;
|
|
12543
|
+
}
|
|
12544
|
+
|
|
12387
12545
|
class AwaitExpression extends NodeBase {
|
|
12388
12546
|
deoptimizePath(path) {
|
|
12389
12547
|
this.argument.deoptimizePath(path);
|
|
@@ -12395,16 +12553,7 @@ class AwaitExpression extends NodeBase {
|
|
|
12395
12553
|
}
|
|
12396
12554
|
initialise() {
|
|
12397
12555
|
super.initialise();
|
|
12398
|
-
|
|
12399
|
-
do {
|
|
12400
|
-
const { type } = parent;
|
|
12401
|
-
if (type === ArrowFunctionExpression$1 ||
|
|
12402
|
-
type === FunctionExpression$1 ||
|
|
12403
|
-
type === FunctionDeclaration$1) {
|
|
12404
|
-
return;
|
|
12405
|
-
}
|
|
12406
|
-
} while ((parent = parent.parent));
|
|
12407
|
-
this.scope.context.usesTopLevelAwait = true;
|
|
12556
|
+
markTopLevelAwait(this);
|
|
12408
12557
|
}
|
|
12409
12558
|
include(context, includeChildrenRecursively) {
|
|
12410
12559
|
if (!this.included)
|
|
@@ -12885,7 +13034,8 @@ class ClassBodyScope extends ChildScope {
|
|
|
12885
13034
|
super(parent, context);
|
|
12886
13035
|
this.variables.set('this', (this.thisVariable = new LocalVariable('this', null, classNode, EMPTY_PATH, context, 'other')));
|
|
12887
13036
|
this.instanceScope = new ChildScope(this, context);
|
|
12888
|
-
this.
|
|
13037
|
+
this.instanceThisVariable = new ThisVariable(context);
|
|
13038
|
+
this.instanceScope.variables.set('this', this.instanceThisVariable);
|
|
12889
13039
|
}
|
|
12890
13040
|
findLexicalBoundary() {
|
|
12891
13041
|
return this;
|
|
@@ -13377,6 +13527,8 @@ class ForOfStatement extends NodeBase {
|
|
|
13377
13527
|
}
|
|
13378
13528
|
initialise() {
|
|
13379
13529
|
super.initialise();
|
|
13530
|
+
if (this.await)
|
|
13531
|
+
markTopLevelAwait(this);
|
|
13380
13532
|
this.left.setAssignedValue(UNKNOWN_EXPRESSION);
|
|
13381
13533
|
}
|
|
13382
13534
|
render(code, options) {
|
|
@@ -15133,6 +15285,9 @@ class Property extends PropertyBase {
|
|
|
15133
15285
|
}
|
|
15134
15286
|
this.value.render(code, options, { isShorthandProperty: this.shorthand });
|
|
15135
15287
|
}
|
|
15288
|
+
setAssignedValue(value) {
|
|
15289
|
+
this.value.setAssignedValue(value);
|
|
15290
|
+
}
|
|
15136
15291
|
getPathInProperty(destructuredInitPath) {
|
|
15137
15292
|
return destructuredInitPath.at(-1) === UnknownKey
|
|
15138
15293
|
? destructuredInitPath
|
|
@@ -15148,47 +15303,6 @@ class Property extends PropertyBase {
|
|
|
15148
15303
|
Property.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
|
|
15149
15304
|
Property.prototype.applyDeoptimizations = doNotDeoptimize;
|
|
15150
15305
|
|
|
15151
|
-
class PropertyDefinition extends NodeBase {
|
|
15152
|
-
get computed() {
|
|
15153
|
-
return isFlagSet(this.flags, 1024 /* Flag.computed */);
|
|
15154
|
-
}
|
|
15155
|
-
set computed(value) {
|
|
15156
|
-
this.flags = setFlag(this.flags, 1024 /* Flag.computed */, value);
|
|
15157
|
-
}
|
|
15158
|
-
deoptimizeArgumentsOnInteractionAtPath(interaction, path, recursionTracker) {
|
|
15159
|
-
this.value?.deoptimizeArgumentsOnInteractionAtPath(interaction, path, recursionTracker);
|
|
15160
|
-
}
|
|
15161
|
-
deoptimizePath(path) {
|
|
15162
|
-
this.value?.deoptimizePath(path);
|
|
15163
|
-
}
|
|
15164
|
-
getLiteralValueAtPath(path, recursionTracker, origin) {
|
|
15165
|
-
return this.value
|
|
15166
|
-
? this.value.getLiteralValueAtPath(path, recursionTracker, origin)
|
|
15167
|
-
: UnknownValue;
|
|
15168
|
-
}
|
|
15169
|
-
getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin) {
|
|
15170
|
-
return this.value
|
|
15171
|
-
? this.value.getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin)
|
|
15172
|
-
: UNKNOWN_RETURN_EXPRESSION;
|
|
15173
|
-
}
|
|
15174
|
-
hasEffects(context) {
|
|
15175
|
-
return (this.key.hasEffects(context) ||
|
|
15176
|
-
(this.static && !!this.value?.hasEffects(context)) ||
|
|
15177
|
-
checkEffectForNodes(this.decorators, context));
|
|
15178
|
-
}
|
|
15179
|
-
hasEffectsOnInteractionAtPath(path, interaction, context) {
|
|
15180
|
-
return !this.value || this.value.hasEffectsOnInteractionAtPath(path, interaction, context);
|
|
15181
|
-
}
|
|
15182
|
-
includeNode(context) {
|
|
15183
|
-
this.included = true;
|
|
15184
|
-
this.value?.includePath(UNKNOWN_PATH, context);
|
|
15185
|
-
for (const decorator of this.decorators) {
|
|
15186
|
-
decorator.includePath(UNKNOWN_PATH, context);
|
|
15187
|
-
}
|
|
15188
|
-
}
|
|
15189
|
-
}
|
|
15190
|
-
PropertyDefinition.prototype.applyDeoptimizations = doNotDeoptimize;
|
|
15191
|
-
|
|
15192
15306
|
class RestElement extends NodeBase {
|
|
15193
15307
|
constructor() {
|
|
15194
15308
|
super(...arguments);
|
|
@@ -15233,6 +15347,9 @@ class RestElement extends NodeBase {
|
|
|
15233
15347
|
markDeclarationReached() {
|
|
15234
15348
|
this.argument.markDeclarationReached();
|
|
15235
15349
|
}
|
|
15350
|
+
setAssignedValue(value) {
|
|
15351
|
+
this.argument.setAssignedValue(value);
|
|
15352
|
+
}
|
|
15236
15353
|
applyDeoptimizations() {
|
|
15237
15354
|
this.deoptimized = true;
|
|
15238
15355
|
if (this.declarationInit !== null) {
|
|
@@ -15996,6 +16113,8 @@ class VariableDeclaration extends NodeBase {
|
|
|
15996
16113
|
}
|
|
15997
16114
|
initialise() {
|
|
15998
16115
|
super.initialise();
|
|
16116
|
+
if (this.kind === 'await using')
|
|
16117
|
+
markTopLevelAwait(this);
|
|
15999
16118
|
for (const declarator of this.declarations) {
|
|
16000
16119
|
declarator.declareDeclarator(this.kind);
|
|
16001
16120
|
}
|
|
@@ -16764,7 +16883,7 @@ const bufferParsers = [
|
|
|
16764
16883
|
function literalNumber(node, position, buffer) {
|
|
16765
16884
|
const rawPosition = buffer[position];
|
|
16766
16885
|
node.raw = rawPosition === 0 ? undefined : buffer.convertString(rawPosition);
|
|
16767
|
-
node.value =
|
|
16886
|
+
node.value = buffer.convertFloat64(position + 1);
|
|
16768
16887
|
},
|
|
16769
16888
|
function literalRegExp(node, position, buffer) {
|
|
16770
16889
|
const flags = buffer.convertString(buffer[position]);
|
|
@@ -17756,6 +17875,9 @@ class Module {
|
|
|
17756
17875
|
hasEffects() {
|
|
17757
17876
|
return this.info.moduleSideEffects === 'no-treeshake' || this.ast.hasCachedEffects();
|
|
17758
17877
|
}
|
|
17878
|
+
hasTopLevelAwait() {
|
|
17879
|
+
return this.astContext.usesTopLevelAwait;
|
|
17880
|
+
}
|
|
17759
17881
|
include() {
|
|
17760
17882
|
const context = createInclusionContext();
|
|
17761
17883
|
if (this.ast.shouldBeIncluded(context))
|
|
@@ -19144,6 +19266,7 @@ class Chunk {
|
|
|
19144
19266
|
const { accessedGlobals, indent, magicString, renderedSource, usedModules, usesTopLevelAwait } = this.renderModules(preliminaryFileName.fileName);
|
|
19145
19267
|
const renderedDependencies = [...this.getRenderedDependencies().values()];
|
|
19146
19268
|
const renderedExports = exportMode === 'none' ? [] : this.getChunkExportDeclarations(format);
|
|
19269
|
+
const renderedExportNames = format === 'es' && new Set(renderedExports.map(({ exported }) => exported));
|
|
19147
19270
|
let hasExports = renderedExports.length > 0;
|
|
19148
19271
|
let hasDefaultExport = false;
|
|
19149
19272
|
for (const renderedDependency of renderedDependencies) {
|
|
@@ -19153,8 +19276,8 @@ class Chunk {
|
|
|
19153
19276
|
if (!hasDefaultExport && reexports.some(reexport => reexport.reexported === 'default')) {
|
|
19154
19277
|
hasDefaultExport = true;
|
|
19155
19278
|
}
|
|
19156
|
-
if (
|
|
19157
|
-
renderedDependency.reexports = reexports.filter(({ reexported }) => !
|
|
19279
|
+
if (renderedExportNames) {
|
|
19280
|
+
renderedDependency.reexports = reexports.filter(({ reexported }) => !renderedExportNames.has(reexported));
|
|
19158
19281
|
}
|
|
19159
19282
|
}
|
|
19160
19283
|
}
|
|
@@ -19343,7 +19466,8 @@ class Chunk {
|
|
|
19343
19466
|
exported: exportName,
|
|
19344
19467
|
expression,
|
|
19345
19468
|
hoisted,
|
|
19346
|
-
local
|
|
19469
|
+
local,
|
|
19470
|
+
needsLiveBinding: variable.isReassigned && this.exportNamesByVariable.get(variable).length > 1
|
|
19347
19471
|
});
|
|
19348
19472
|
}
|
|
19349
19473
|
return exports;
|
|
@@ -20046,7 +20170,8 @@ function getChunkAssignments(entries, manualChunkAliasByEntry, minChunkSize, log
|
|
|
20046
20170
|
// Warning: This will consume dynamicallyDependentEntriesByDynamicEntry.
|
|
20047
20171
|
// If we no longer want this, we should make a copy here.
|
|
20048
20172
|
const alreadyLoadedAtomsByEntry = getAlreadyLoadedAtomsByEntry(staticDependencyAtomsByEntry, dynamicallyDependentEntriesByDynamicEntry, dynamicImportsByEntry, entriesAndManualChunksCount);
|
|
20049
|
-
|
|
20173
|
+
// Warning: This will consume dynamicallyDependentEntriesByAwaitedDynamicEntry.
|
|
20174
|
+
const awaitedAlreadyLoadedAtomsByEntry = getAwaitedAlreadyLoadedAtomsByEntry(staticDependencyAtomsByEntry, dynamicallyDependentEntriesByAwaitedDynamicEntry, awaitedDynamicImportsByEntry, entriesAndManualChunksCount);
|
|
20050
20175
|
// A manual chunk only behaves like a dynamic entry if its whole member atom
|
|
20051
20176
|
// is not already loaded whenever any entry dynamically loads it. Otherwise
|
|
20052
20177
|
// there is nothing to gain (and cycles could be created) and the manual
|
|
@@ -20149,9 +20274,11 @@ function analyzeModuleGraph(entries, manualChunks, manualChunkByModule, manualCh
|
|
|
20149
20274
|
dynamicManualChunksForCurrentEntry;
|
|
20150
20275
|
awaitedLoadedManualChunksByEntry[entryOrManualChunkIndex] = awaitedManualChunksForCurrentEntry;
|
|
20151
20276
|
const staticDependencies = new Set(currentEntryModules);
|
|
20277
|
+
let hasTopLevelAwait = false;
|
|
20152
20278
|
// If we have a very large manual chunk, tracking if it is already added to the dependencies will improve performance
|
|
20153
20279
|
const addedManualChunks = new Set();
|
|
20154
20280
|
for (const module of staticDependencies) {
|
|
20281
|
+
hasTopLevelAwait ||= module.hasTopLevelAwait();
|
|
20155
20282
|
getOrCreate(dependentEntriesByModule, module, (getNewSet)).add(entryOrManualChunkIndex);
|
|
20156
20283
|
const manualChunk = manualChunkByModule.get(module);
|
|
20157
20284
|
if (manualChunk && !addedManualChunks.has(manualChunk)) {
|
|
@@ -20166,7 +20293,6 @@ function analyzeModuleGraph(entries, manualChunks, manualChunkByModule, manualCh
|
|
|
20166
20293
|
}
|
|
20167
20294
|
}
|
|
20168
20295
|
for (const { node: { resolution } } of module.dynamicImports) {
|
|
20169
|
-
let manuallyLoadedChunk = null;
|
|
20170
20296
|
if (resolution instanceof Module && resolution.includedDynamicImporters.length > 0) {
|
|
20171
20297
|
if (!allEntriesSet.has(resolution)) {
|
|
20172
20298
|
dynamicEntryModules.add(resolution);
|
|
@@ -20174,25 +20300,13 @@ function analyzeModuleGraph(entries, manualChunks, manualChunkByModule, manualCh
|
|
|
20174
20300
|
allEntriesAndManualChunks.push([resolution]);
|
|
20175
20301
|
}
|
|
20176
20302
|
else if (!dynamicEntryModules.has(resolution)) {
|
|
20177
|
-
manuallyLoadedChunk = manualChunkByModule.get(resolution)
|
|
20303
|
+
const manuallyLoadedChunk = manualChunkByModule.get(resolution);
|
|
20178
20304
|
if (!manuallyLoadedChunk) {
|
|
20179
20305
|
continue;
|
|
20180
20306
|
}
|
|
20181
20307
|
dynamicManualChunksForCurrentEntry.add(manuallyLoadedChunk);
|
|
20182
20308
|
}
|
|
20183
20309
|
dynamicImportsForCurrentEntry.add(resolution);
|
|
20184
|
-
for (const includedTopLevelAwaitingDynamicImporter of resolution.includedTopLevelAwaitingDynamicImporters) {
|
|
20185
|
-
if (staticDependencies.has(includedTopLevelAwaitingDynamicImporter)) {
|
|
20186
|
-
awaitedDynamicImportsForCurrentEntry.add(resolution);
|
|
20187
|
-
if (manuallyLoadedChunk) {
|
|
20188
|
-
awaitedManualChunksForCurrentEntry.add(manuallyLoadedChunk);
|
|
20189
|
-
}
|
|
20190
|
-
else {
|
|
20191
|
-
awaitedDynamicEntryModules.add(resolution);
|
|
20192
|
-
}
|
|
20193
|
-
break;
|
|
20194
|
-
}
|
|
20195
|
-
}
|
|
20196
20310
|
}
|
|
20197
20311
|
}
|
|
20198
20312
|
for (const dependency of module.implicitlyLoadedBefore) {
|
|
@@ -20210,13 +20324,30 @@ function analyzeModuleGraph(entries, manualChunks, manualChunkByModule, manualCh
|
|
|
20210
20324
|
}
|
|
20211
20325
|
}
|
|
20212
20326
|
}
|
|
20327
|
+
// A dynamic import can be awaited indirectly through a static dependency:
|
|
20328
|
+
// if any module of this entry uses a top-level await, the entry may
|
|
20329
|
+
// still be evaluating when any of its dynamic imports runs, so all of
|
|
20330
|
+
// them are awaited. This includes manual chunks that are loaded
|
|
20331
|
+
// dynamically or implicitly, which behave like dynamic entries here.
|
|
20332
|
+
if (hasTopLevelAwait) {
|
|
20333
|
+
for (const dynamicImportTarget of dynamicImportsForCurrentEntry) {
|
|
20334
|
+
const manualChunk = manualChunkByModule.get(dynamicImportTarget);
|
|
20335
|
+
if (manualChunk) {
|
|
20336
|
+
awaitedManualChunksForCurrentEntry.add(manualChunk);
|
|
20337
|
+
}
|
|
20338
|
+
else {
|
|
20339
|
+
awaitedDynamicEntryModules.add(dynamicImportTarget);
|
|
20340
|
+
}
|
|
20341
|
+
awaitedDynamicImportsForCurrentEntry.add(dynamicImportTarget);
|
|
20342
|
+
}
|
|
20343
|
+
}
|
|
20213
20344
|
entryOrManualChunkIndex++;
|
|
20214
20345
|
}
|
|
20215
20346
|
const { awaitedDynamicEntries, awaitedDynamicImportsByEntry, dynamicEntries, dynamicImportsByEntry } = getDynamicEntries(allEntriesAndManualChunks, dynamicEntryModules, dynamicImportModulesByEntry, awaitedDynamicEntryModules, awaitedDynamicImportModulesByEntry, dynamicallyLoadedManualChunksByEntry, awaitedLoadedManualChunksByEntry, manualChunkIndexByChunk);
|
|
20216
20347
|
return {
|
|
20217
20348
|
awaitedDynamicImportsByEntry,
|
|
20218
20349
|
dependentEntriesByModule,
|
|
20219
|
-
dynamicallyDependentEntriesByAwaitedDynamicEntry: getDynamicallyDependentEntriesByDynamicEntry(dependentEntriesByModule, awaitedDynamicEntries, allEntriesAndManualChunks, dynamicEntry => dynamicEntry.includedTopLevelAwaitingDynamicImporters),
|
|
20350
|
+
dynamicallyDependentEntriesByAwaitedDynamicEntry: addAwaitingEntries(getDynamicallyDependentEntriesByDynamicEntry(dependentEntriesByModule, awaitedDynamicEntries, allEntriesAndManualChunks, dynamicEntry => dynamicEntry.includedTopLevelAwaitingDynamicImporters), awaitedDynamicImportsByEntry),
|
|
20220
20351
|
dynamicallyDependentEntriesByDynamicEntry: getDynamicallyDependentEntriesByDynamicEntry(dependentEntriesByModule, dynamicEntries, allEntriesAndManualChunks, dynamicEntry => dynamicEntry.includedDynamicImporters),
|
|
20221
20352
|
dynamicImportsByEntry,
|
|
20222
20353
|
entriesAndManualChunksCount: allEntriesAndManualChunks.length
|
|
@@ -20270,6 +20401,18 @@ function getDynamicImportsByEntry(dynamicImportModulesByEntry, entryIndexByModul
|
|
|
20270
20401
|
}
|
|
20271
20402
|
return dynamicImportsByEntry;
|
|
20272
20403
|
}
|
|
20404
|
+
// A dynamic entry can be awaited by an entry even if the importing module does
|
|
20405
|
+
// not have a top-level await itself, e.g. if the import is inside a function
|
|
20406
|
+
// that is awaited in the entry. In that case, the entry is still evaluating
|
|
20407
|
+
// when the dynamic entry is executed, so we add all awaiting entries here.
|
|
20408
|
+
function addAwaitingEntries(dynamicallyDependentEntriesByAwaitedDynamicEntry, awaitedDynamicImportsByEntry) {
|
|
20409
|
+
for (const [entryIndex, awaitedDynamicImports] of awaitedDynamicImportsByEntry.entries()) {
|
|
20410
|
+
for (const dynamicEntryIndex of awaitedDynamicImports) {
|
|
20411
|
+
getOrCreate(dynamicallyDependentEntriesByAwaitedDynamicEntry, dynamicEntryIndex, (getNewSet)).add(entryIndex);
|
|
20412
|
+
}
|
|
20413
|
+
}
|
|
20414
|
+
return dynamicallyDependentEntriesByAwaitedDynamicEntry;
|
|
20415
|
+
}
|
|
20273
20416
|
function getDynamicallyDependentEntriesByDynamicEntry(dependentEntriesByModule, dynamicEntries, allEntriesAndManualChunks, getDynamicImporters) {
|
|
20274
20417
|
const dynamicallyDependentEntriesByDynamicEntry = new Map();
|
|
20275
20418
|
for (const dynamicEntryIndex of dynamicEntries) {
|
|
@@ -20365,6 +20508,34 @@ function getAlreadyLoadedAtomsByEntry(staticDependencyAtomsByEntry, dynamicallyD
|
|
|
20365
20508
|
}
|
|
20366
20509
|
return alreadyLoadedAtomsByEntry;
|
|
20367
20510
|
}
|
|
20511
|
+
// Warning: This will consume dynamicallyDependentEntriesByAwaitedDynamicEntry.
|
|
20512
|
+
function getAwaitedAlreadyLoadedAtomsByEntry(staticDependencyAtomsByEntry, dynamicallyDependentEntriesByAwaitedDynamicEntry, awaitedDynamicImportsByEntry, allEntriesCount) {
|
|
20513
|
+
// Unlike already loaded atoms, this is a union and not an intersection: If
|
|
20514
|
+
// any importer that is still evaluating while it awaits a dynamic entry has
|
|
20515
|
+
// loaded an atom, merging that atom into the chunk of this importer would
|
|
20516
|
+
// create a cycle. Entries that are not awaited have no such atoms.
|
|
20517
|
+
const awaitedAlreadyLoadedAtomsByEntry = new Array(allEntriesCount).fill(0n);
|
|
20518
|
+
for (const [dynamicEntryIndex, dynamicallyDependentEntries] of dynamicallyDependentEntriesByAwaitedDynamicEntry) {
|
|
20519
|
+
// We delete here so that they can be added again if necessary to be handled
|
|
20520
|
+
// again by the loop
|
|
20521
|
+
dynamicallyDependentEntriesByAwaitedDynamicEntry.delete(dynamicEntryIndex);
|
|
20522
|
+
const knownLoadedAtoms = awaitedAlreadyLoadedAtomsByEntry[dynamicEntryIndex];
|
|
20523
|
+
let updatedLoadedAtoms = knownLoadedAtoms;
|
|
20524
|
+
for (const entryIndex of dynamicallyDependentEntries) {
|
|
20525
|
+
updatedLoadedAtoms |=
|
|
20526
|
+
staticDependencyAtomsByEntry[entryIndex] | awaitedAlreadyLoadedAtomsByEntry[entryIndex];
|
|
20527
|
+
}
|
|
20528
|
+
// If the knownLoadedAtoms changed, all awaited dynamic imports of this
|
|
20529
|
+
// entry need to be updated again
|
|
20530
|
+
if (updatedLoadedAtoms !== knownLoadedAtoms) {
|
|
20531
|
+
awaitedAlreadyLoadedAtomsByEntry[dynamicEntryIndex] = updatedLoadedAtoms;
|
|
20532
|
+
for (const dynamicImport of awaitedDynamicImportsByEntry[dynamicEntryIndex]) {
|
|
20533
|
+
getOrCreate(dynamicallyDependentEntriesByAwaitedDynamicEntry, dynamicImport, (getNewSet)).add(dynamicEntryIndex);
|
|
20534
|
+
}
|
|
20535
|
+
}
|
|
20536
|
+
}
|
|
20537
|
+
return awaitedAlreadyLoadedAtomsByEntry;
|
|
20538
|
+
}
|
|
20368
20539
|
/**
|
|
20369
20540
|
* Manual chunks whose member atom is already loaded in every context that
|
|
20370
20541
|
* dynamically loads them must not be treated like dynamic entries as that
|
|
@@ -21076,8 +21247,8 @@ async function renderChunks(chunks, bundle, pluginDriver, outputOptions, log) {
|
|
|
21076
21247
|
timeStart('transform chunks', 2);
|
|
21077
21248
|
const getHash = hasherByType[outputOptions.hashCharacters];
|
|
21078
21249
|
const chunkGraph = getChunkGraph(chunks);
|
|
21079
|
-
const { hashDependenciesByPlaceholder, initialHashesByPlaceholder, nonHashedChunksWithPlaceholders, placeholders, renderedChunksByPlaceholder } = await transformChunksAndGenerateContentHashes(renderedChunks, chunkGraph, outputOptions, pluginDriver, getHash, log);
|
|
21080
|
-
const hashesByPlaceholder = generateFinalHashes(renderedChunksByPlaceholder, hashDependenciesByPlaceholder, initialHashesByPlaceholder, placeholders, bundle, getHash);
|
|
21250
|
+
const { hashDependenciesByPlaceholder, initialHashesByPlaceholder, nonHashedChunksWithPlaceholders, placeholders, renderedChunksByPlaceholder, usedFileNames } = await transformChunksAndGenerateContentHashes(renderedChunks, chunkGraph, outputOptions, pluginDriver, getHash, log, bundle);
|
|
21251
|
+
const hashesByPlaceholder = generateFinalHashes(renderedChunksByPlaceholder, hashDependenciesByPlaceholder, initialHashesByPlaceholder, placeholders, bundle, usedFileNames, getHash);
|
|
21081
21252
|
addChunksToBundle(renderedChunksByPlaceholder, hashesByPlaceholder, bundle, nonHashedChunksWithPlaceholders, pluginDriver, outputOptions);
|
|
21082
21253
|
timeEnd('transform chunks', 2);
|
|
21083
21254
|
}
|
|
@@ -21157,7 +21328,7 @@ async function transformChunk(magicString, fileName, usedModules, chunkGraph, op
|
|
|
21157
21328
|
map
|
|
21158
21329
|
};
|
|
21159
21330
|
}
|
|
21160
|
-
async function transformChunksAndGenerateContentHashes(renderedChunks, chunkGraph, outputOptions, pluginDriver, getHash, log) {
|
|
21331
|
+
async function transformChunksAndGenerateContentHashes(renderedChunks, chunkGraph, outputOptions, pluginDriver, getHash, log, bundle) {
|
|
21161
21332
|
const nonHashedChunksWithPlaceholders = [];
|
|
21162
21333
|
const renderedChunksByPlaceholder = new Map();
|
|
21163
21334
|
const hashDependenciesByPlaceholder = new Map();
|
|
@@ -21167,51 +21338,93 @@ async function transformChunksAndGenerateContentHashes(renderedChunks, chunkGrap
|
|
|
21167
21338
|
if (hashPlaceholder)
|
|
21168
21339
|
placeholders.add(hashPlaceholder);
|
|
21169
21340
|
}
|
|
21170
|
-
await Promise.all(renderedChunks.map(async ({ chunk, preliminaryFileName: { fileName, hashPlaceholder }, preliminarySourcemapFileName, magicString, usedModules }) => {
|
|
21341
|
+
const transformedChunks = await Promise.all(renderedChunks.map(async ({ chunk, preliminaryFileName: { fileName, hashPlaceholder }, preliminarySourcemapFileName, magicString, usedModules }) => {
|
|
21171
21342
|
const transformedChunk = {
|
|
21172
21343
|
chunk,
|
|
21173
21344
|
fileName,
|
|
21174
21345
|
sourcemapFileName: preliminarySourcemapFileName?.fileName ?? null,
|
|
21175
21346
|
...(await transformChunk(magicString, fileName, usedModules, chunkGraph, outputOptions, pluginDriver, log))
|
|
21176
21347
|
};
|
|
21177
|
-
const
|
|
21348
|
+
const hashAugmentation = hashPlaceholder
|
|
21349
|
+
? pluginDriver.hookReduceValueSync('augmentChunkHash', '', [chunk.getRenderedChunkInfo()], (augmentation, pluginHash) => augmentation + (pluginHash || ''))
|
|
21350
|
+
: '';
|
|
21351
|
+
return {
|
|
21352
|
+
hashAugmentation,
|
|
21353
|
+
hashPlaceholder,
|
|
21354
|
+
preliminarySourcemapFileName,
|
|
21355
|
+
transformedChunk
|
|
21356
|
+
};
|
|
21357
|
+
}));
|
|
21358
|
+
const usedFileNames = new Set(bundle[lowercaseBundleKeys]);
|
|
21359
|
+
for (const { transformedChunk, hashPlaceholder, preliminarySourcemapFileName, hashAugmentation } of transformedChunks) {
|
|
21360
|
+
const { map } = transformedChunk;
|
|
21361
|
+
const sourcemapHashPlaceholder = preliminarySourcemapFileName?.hashPlaceholder;
|
|
21362
|
+
if (map && sourcemapHashPlaceholder) {
|
|
21363
|
+
const { transformedCode: normalizedSourcemap } = replacePlaceholdersWithDefaultAndGetContainedPlaceholders(map.toString(), placeholders);
|
|
21364
|
+
initialHashesByPlaceholder.set(sourcemapHashPlaceholder, outputOptions.sourcemap === 'inline'
|
|
21365
|
+
? getHash(normalizedSourcemap).slice(0, sourcemapHashPlaceholder.length)
|
|
21366
|
+
: getUniqueHash(normalizedSourcemap, preliminarySourcemapFileName.fileName, sourcemapHashPlaceholder, usedFileNames, getHash));
|
|
21367
|
+
}
|
|
21178
21368
|
if (hashPlaceholder) {
|
|
21179
|
-
// To create a reproducible content-only hash, all placeholders are
|
|
21180
|
-
// replaced with the same value before hashing
|
|
21181
|
-
const { containedPlaceholders, transformedCode } = replacePlaceholdersWithDefaultAndGetContainedPlaceholders(code, placeholders);
|
|
21182
|
-
let contentToHash = transformedCode;
|
|
21183
|
-
const hashAugmentation = pluginDriver.hookReduceValueSync('augmentChunkHash', '', [chunk.getRenderedChunkInfo()], (augmentation, pluginHash) => {
|
|
21184
|
-
if (pluginHash) {
|
|
21185
|
-
augmentation += pluginHash;
|
|
21186
|
-
}
|
|
21187
|
-
return augmentation;
|
|
21188
|
-
});
|
|
21189
|
-
if (hashAugmentation) {
|
|
21190
|
-
contentToHash += hashAugmentation;
|
|
21191
|
-
}
|
|
21192
21369
|
renderedChunksByPlaceholder.set(hashPlaceholder, transformedChunk);
|
|
21193
|
-
hashDependenciesByPlaceholder.set(hashPlaceholder,
|
|
21194
|
-
containedPlaceholders,
|
|
21195
|
-
contentHash: getHash(contentToHash)
|
|
21196
|
-
});
|
|
21370
|
+
hashDependenciesByPlaceholder.set(hashPlaceholder, getChunkHash(transformedChunk, outputOptions, getHash, placeholders, initialHashesByPlaceholder, hashAugmentation));
|
|
21197
21371
|
}
|
|
21198
21372
|
else {
|
|
21199
21373
|
nonHashedChunksWithPlaceholders.push(transformedChunk);
|
|
21200
21374
|
}
|
|
21201
|
-
|
|
21202
|
-
if (map && sourcemapHashPlaceholder) {
|
|
21203
|
-
initialHashesByPlaceholder.set(preliminarySourcemapFileName.hashPlaceholder, getHash(map.toString()).slice(0, preliminarySourcemapFileName.hashPlaceholder.length));
|
|
21204
|
-
}
|
|
21205
|
-
}));
|
|
21375
|
+
}
|
|
21206
21376
|
return {
|
|
21207
21377
|
hashDependenciesByPlaceholder,
|
|
21208
21378
|
initialHashesByPlaceholder,
|
|
21209
21379
|
nonHashedChunksWithPlaceholders,
|
|
21210
21380
|
placeholders,
|
|
21211
|
-
renderedChunksByPlaceholder
|
|
21381
|
+
renderedChunksByPlaceholder,
|
|
21382
|
+
usedFileNames
|
|
21212
21383
|
};
|
|
21213
21384
|
}
|
|
21214
|
-
function
|
|
21385
|
+
function getChunkHash({ code, map, fileName, sourcemapFileName }, outputOptions, getHash, placeholders, initialHashesByPlaceholder, hashAugmentation) {
|
|
21386
|
+
// To create a reproducible content-only hash, all placeholders are
|
|
21387
|
+
// replaced with the same value before hashing
|
|
21388
|
+
const { containedPlaceholders, transformedCode } = replacePlaceholdersWithDefaultAndGetContainedPlaceholders(code, placeholders);
|
|
21389
|
+
let contentToHash = transformedCode;
|
|
21390
|
+
if (map && outputOptions.sourcemap !== 'hidden') {
|
|
21391
|
+
// Normalize raw map data and file names before base64 or URL encoding
|
|
21392
|
+
// can hide placeholders and make hashes depend on chunk order.
|
|
21393
|
+
let sourcemapPlaceholders;
|
|
21394
|
+
if (outputOptions.sourcemap === 'inline') {
|
|
21395
|
+
const { containedPlaceholders: inlinePlaceholders, transformedCode: sourcemapJson } = replacePlaceholdersWithDefaultAndGetContainedPlaceholders(map.toString(), placeholders);
|
|
21396
|
+
sourcemapPlaceholders = inlinePlaceholders;
|
|
21397
|
+
contentToHash += `//# ${SOURCEMAPPING_URL}=data:application/json,${sourcemapJson}\n`;
|
|
21398
|
+
}
|
|
21399
|
+
else {
|
|
21400
|
+
const { containedPlaceholders: externalPlaceholders, transformedCode: normalizedFileName } = replacePlaceholdersWithDefaultAndGetContainedPlaceholders(replacePlaceholders(sourcemapFileName ?? `${fileName}.map`, initialHashesByPlaceholder), placeholders);
|
|
21401
|
+
sourcemapPlaceholders = externalPlaceholders;
|
|
21402
|
+
contentToHash += getSourceMapComment(normalizedFileName, map, outputOptions.sourcemap, outputOptions.sourcemapBaseUrl);
|
|
21403
|
+
}
|
|
21404
|
+
for (const placeholder of sourcemapPlaceholders) {
|
|
21405
|
+
containedPlaceholders.add(placeholder);
|
|
21406
|
+
}
|
|
21407
|
+
}
|
|
21408
|
+
if (hashAugmentation) {
|
|
21409
|
+
contentToHash += hashAugmentation;
|
|
21410
|
+
}
|
|
21411
|
+
return { containedPlaceholders, contentHash: getHash(contentToHash) };
|
|
21412
|
+
}
|
|
21413
|
+
function getUniqueHash(contentToHash, fileName, placeholder, usedFileNames, getHash) {
|
|
21414
|
+
let finalFileName;
|
|
21415
|
+
let finalHash;
|
|
21416
|
+
do {
|
|
21417
|
+
// In case of a hash collision, create a hash of the hash
|
|
21418
|
+
if (finalHash) {
|
|
21419
|
+
contentToHash = finalHash;
|
|
21420
|
+
}
|
|
21421
|
+
finalHash = getHash(contentToHash).slice(0, placeholder.length);
|
|
21422
|
+
finalFileName = replaceSinglePlaceholder(fileName, placeholder, finalHash).toLowerCase();
|
|
21423
|
+
} while (usedFileNames.has(finalFileName));
|
|
21424
|
+
usedFileNames.add(finalFileName);
|
|
21425
|
+
return finalHash;
|
|
21426
|
+
}
|
|
21427
|
+
function generateFinalHashes(renderedChunksByPlaceholder, hashDependenciesByPlaceholder, initialHashesByPlaceholder, placeholders, bundle, usedFileNames, getHash) {
|
|
21215
21428
|
const hashesByPlaceholder = new Map(initialHashesByPlaceholder);
|
|
21216
21429
|
for (const placeholder of placeholders) {
|
|
21217
21430
|
const { fileName } = renderedChunksByPlaceholder.get(placeholder);
|
|
@@ -21225,17 +21438,8 @@ function generateFinalHashes(renderedChunksByPlaceholder, hashDependenciesByPlac
|
|
|
21225
21438
|
hashDependencyPlaceholders.add(containedPlaceholder);
|
|
21226
21439
|
}
|
|
21227
21440
|
}
|
|
21228
|
-
|
|
21229
|
-
|
|
21230
|
-
do {
|
|
21231
|
-
// In case of a hash collision, create a hash of the hash
|
|
21232
|
-
if (finalHash) {
|
|
21233
|
-
contentToHash = finalHash;
|
|
21234
|
-
}
|
|
21235
|
-
finalHash = getHash(contentToHash).slice(0, placeholder.length);
|
|
21236
|
-
finalFileName = replaceSinglePlaceholder(fileName, placeholder, finalHash);
|
|
21237
|
-
} while (bundle[lowercaseBundleKeys].has(finalFileName.toLowerCase()));
|
|
21238
|
-
bundle[finalFileName] = FILE_PLACEHOLDER;
|
|
21441
|
+
const finalHash = getUniqueHash(contentToHash, fileName, placeholder, usedFileNames, getHash);
|
|
21442
|
+
bundle[replaceSinglePlaceholder(fileName, placeholder, finalHash)] = FILE_PLACEHOLDER;
|
|
21239
21443
|
hashesByPlaceholder.set(placeholder, finalHash);
|
|
21240
21444
|
}
|
|
21241
21445
|
return hashesByPlaceholder;
|
|
@@ -21273,15 +21477,7 @@ function addChunksToBundle(renderedChunksByPlaceholder, hashesByPlaceholder, bun
|
|
|
21273
21477
|
}
|
|
21274
21478
|
}
|
|
21275
21479
|
function emitSourceMapAndGetComment(fileName, map, pluginDriver, { sourcemap, sourcemapBaseUrl }) {
|
|
21276
|
-
|
|
21277
|
-
if (sourcemap === 'inline') {
|
|
21278
|
-
url = map.toUrl();
|
|
21279
|
-
}
|
|
21280
|
-
else {
|
|
21281
|
-
const sourcemapFileName = basename(fileName);
|
|
21282
|
-
url = sourcemapBaseUrl
|
|
21283
|
-
? new URL(sourcemapFileName, sourcemapBaseUrl).toString()
|
|
21284
|
-
: sourcemapFileName;
|
|
21480
|
+
if (sourcemap !== 'inline') {
|
|
21285
21481
|
pluginDriver.emitFile({
|
|
21286
21482
|
fileName,
|
|
21287
21483
|
originalFileName: null,
|
|
@@ -21289,6 +21485,14 @@ function emitSourceMapAndGetComment(fileName, map, pluginDriver, { sourcemap, so
|
|
|
21289
21485
|
type: 'asset'
|
|
21290
21486
|
});
|
|
21291
21487
|
}
|
|
21488
|
+
return getSourceMapComment(fileName, map, sourcemap, sourcemapBaseUrl);
|
|
21489
|
+
}
|
|
21490
|
+
function getSourceMapComment(fileName, map, sourcemap, sourcemapBaseUrl) {
|
|
21491
|
+
const url = sourcemap === 'inline'
|
|
21492
|
+
? map.toUrl()
|
|
21493
|
+
: sourcemapBaseUrl
|
|
21494
|
+
? new URL(basename(fileName), sourcemapBaseUrl).toString()
|
|
21495
|
+
: basename(fileName);
|
|
21292
21496
|
return sourcemap === 'hidden' ? '' : `//# ${SOURCEMAPPING_URL}=${url}\n`;
|
|
21293
21497
|
}
|
|
21294
21498
|
function calculateDebugIdAndGetComment(code, map) {
|
|
@@ -24243,17 +24447,17 @@ async function rollupInternal(rawInputOptions, registerWatchHooks) {
|
|
|
24243
24447
|
...error_,
|
|
24244
24448
|
message: `There was an error during the build:\n ${error_.message}\nAdditionally, handling the error in the 'buildEnd' hook caused the following error:\n ${buildEndError.message}`
|
|
24245
24449
|
});
|
|
24246
|
-
await graph.pluginDriver.hookParallel('closeBundle', [compoundError]);
|
|
24450
|
+
await graph.pluginDriver.hookParallel('closeBundle', [compoundError]).catch(() => { });
|
|
24247
24451
|
throw compoundError;
|
|
24248
24452
|
}
|
|
24249
|
-
await graph.pluginDriver.hookParallel('closeBundle', [error_]);
|
|
24453
|
+
await graph.pluginDriver.hookParallel('closeBundle', [error_]).catch(() => { });
|
|
24250
24454
|
throw error_;
|
|
24251
24455
|
}
|
|
24252
24456
|
try {
|
|
24253
24457
|
await graph.pluginDriver.hookParallel('buildEnd', []);
|
|
24254
24458
|
}
|
|
24255
24459
|
catch (buildEndError) {
|
|
24256
|
-
await graph.pluginDriver.hookParallel('closeBundle', [buildEndError]);
|
|
24460
|
+
await graph.pluginDriver.hookParallel('closeBundle', [buildEndError]).catch(() => { });
|
|
24257
24461
|
throw buildEndError;
|
|
24258
24462
|
}
|
|
24259
24463
|
});
|