@rollup/wasm-node 4.68.2 → 4.68.4
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 +1541 -1218
- package/dist/es/shared/parseAst.js +17 -12
- package/dist/es/shared/watch.js +2 -2
- package/dist/getLogFilter.js +2 -2
- package/dist/loadConfigFile.js +2 -2
- package/dist/parseAst.js +2 -2
- package/dist/rollup.js +2 -2
- package/dist/shared/fsevents-importer.js +2 -2
- 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 +12 -2
- package/dist/shared/rollup.js +1540 -1217
- package/dist/shared/watch-cli.js +2 -2
- package/dist/shared/watch.js +2 -2
- package/dist/wasm-node/bindings_wasm_bg.wasm +0 -0
- package/package.json +10 -10
package/dist/shared/rollup.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/*
|
|
2
2
|
@license
|
|
3
|
-
Rollup.js v4.68.
|
|
4
|
-
Mon,
|
|
3
|
+
Rollup.js v4.68.4
|
|
4
|
+
Mon, 16 Nov 2026 08:59:19 GMT - commit 9b2de5068e925a3b07bea67c972de21a347af9d9
|
|
5
5
|
|
|
6
6
|
https://github.com/rollup/rollup
|
|
7
7
|
|
|
@@ -42,7 +42,7 @@ function _mergeNamespaces(n, m) {
|
|
|
42
42
|
|
|
43
43
|
const promises__namespace = /*#__PURE__*/_interopNamespaceDefault(promises);
|
|
44
44
|
|
|
45
|
-
var version = "4.68.
|
|
45
|
+
var version = "4.68.4";
|
|
46
46
|
const package_ = {
|
|
47
47
|
version: version};
|
|
48
48
|
|
|
@@ -6566,6 +6566,37 @@ function renderSystemExportSequenceAfterExpression(exportedVariable, expressionS
|
|
|
6566
6566
|
code.appendLeft(expressionEnd, ')');
|
|
6567
6567
|
}
|
|
6568
6568
|
}
|
|
6569
|
+
function renderSystemExportForLoop(left, body, code, options) {
|
|
6570
|
+
const exportedVariables = [];
|
|
6571
|
+
left.addExportedVariables(exportedVariables, options.exportNamesByVariable);
|
|
6572
|
+
if (exportedVariables.length === 0)
|
|
6573
|
+
return;
|
|
6574
|
+
const { _, getPropertyAccess } = options.snippets;
|
|
6575
|
+
const exportStatement = `${getSystemExportStatement(exportedVariables, options)};`;
|
|
6576
|
+
if (body.type === parseAst_js.EmptyStatement) {
|
|
6577
|
+
code.overwrite(body.start, body.end, exportStatement);
|
|
6578
|
+
}
|
|
6579
|
+
else if (body.type === parseAst_js.BlockStatement &&
|
|
6580
|
+
!scopeShadowsExportedBindings(body.scope, exportedVariables, getPropertyAccess)) {
|
|
6581
|
+
code.prependRight(body.start + 1, `${_}${exportStatement}`);
|
|
6582
|
+
}
|
|
6583
|
+
else {
|
|
6584
|
+
code.prependRight(body.start, `{${_}${exportStatement}${_}`);
|
|
6585
|
+
code.appendLeft(body.end, `${_}}`);
|
|
6586
|
+
}
|
|
6587
|
+
}
|
|
6588
|
+
function scopeShadowsExportedBindings(scope, exportedVariables, getPropertyAccess) {
|
|
6589
|
+
const referencedNames = new Set(['exports']);
|
|
6590
|
+
for (const variable of exportedVariables) {
|
|
6591
|
+
referencedNames.add(variable.getName(getPropertyAccess));
|
|
6592
|
+
}
|
|
6593
|
+
for (const variable of scope.variables.values()) {
|
|
6594
|
+
if (variable.included && referencedNames.has(variable.getName(getPropertyAccess))) {
|
|
6595
|
+
return true;
|
|
6596
|
+
}
|
|
6597
|
+
}
|
|
6598
|
+
return false;
|
|
6599
|
+
}
|
|
6569
6600
|
function renderSystemExportSequenceBeforeExpression(exportedVariable, expressionStart, expressionEnd, needsParens, code, options, modifier) {
|
|
6570
6601
|
const { _ } = options.snippets;
|
|
6571
6602
|
code.prependRight(expressionStart, `${getSystemExportStatement([exportedVariable], options, modifier)},${_}`);
|
|
@@ -7026,7 +7057,7 @@ class Variable extends ExpressionEntity {
|
|
|
7026
7057
|
(this.forbiddenNames ||= new Set()).add(name);
|
|
7027
7058
|
}
|
|
7028
7059
|
getBaseVariableName() {
|
|
7029
|
-
return (this.
|
|
7060
|
+
return (this.getNamingVariable()?.getBaseVariableName() ||
|
|
7030
7061
|
this.renderBaseName ||
|
|
7031
7062
|
this.renderName ||
|
|
7032
7063
|
this.name);
|
|
@@ -7038,8 +7069,9 @@ class Variable extends ExpressionEntity {
|
|
|
7038
7069
|
if (useOriginalName?.(this)) {
|
|
7039
7070
|
return this.name;
|
|
7040
7071
|
}
|
|
7041
|
-
|
|
7042
|
-
|
|
7072
|
+
const namingVariable = this.getNamingVariable();
|
|
7073
|
+
if (namingVariable) {
|
|
7074
|
+
return namingVariable.getName(getPropertyAccess, useOriginalName);
|
|
7043
7075
|
}
|
|
7044
7076
|
const name = this.renderName || this.name;
|
|
7045
7077
|
return this.renderBaseName ? `${this.renderBaseName}${getPropertyAccess(name)}` : name;
|
|
@@ -7058,12 +7090,19 @@ class Variable extends ExpressionEntity {
|
|
|
7058
7090
|
this.renderedLikeHoisted?.includePath(path, context);
|
|
7059
7091
|
}
|
|
7060
7092
|
/**
|
|
7061
|
-
* Links
|
|
7062
|
-
*
|
|
7093
|
+
* Links this variable to a hoisted variable. Including this variable then
|
|
7094
|
+
* includes the hoisted variable, and while the hoisted variable renders as an
|
|
7095
|
+
* identifier, this variable renders with its name.
|
|
7063
7096
|
*/
|
|
7064
7097
|
renderLikeHoisted(variable) {
|
|
7065
7098
|
this.renderedLikeHoisted = variable;
|
|
7066
7099
|
}
|
|
7100
|
+
getHoistedVariable() {
|
|
7101
|
+
return this.renderedLikeHoisted;
|
|
7102
|
+
}
|
|
7103
|
+
getNamingVariable() {
|
|
7104
|
+
return this.renderedLikeHoisted?.renderBaseName === null ? this.renderedLikeHoisted : undefined;
|
|
7105
|
+
}
|
|
7067
7106
|
markCalledFromTryStatement() { }
|
|
7068
7107
|
addReassignedValue(_value) { }
|
|
7069
7108
|
setRenderNames(baseName, name) {
|
|
@@ -8561,7 +8600,12 @@ class ArrayExpression extends NodeBase {
|
|
|
8561
8600
|
this.getObjectEntity().deoptimizeArgumentsOnInteractionAtPath(interaction, path, recursionTracker);
|
|
8562
8601
|
}
|
|
8563
8602
|
deoptimizePath(path) {
|
|
8564
|
-
this.getObjectEntity()
|
|
8603
|
+
const objectEntity = this.getObjectEntity();
|
|
8604
|
+
objectEntity.deoptimizePath(path);
|
|
8605
|
+
// Writing the length can remove elements or add holes
|
|
8606
|
+
if (path.length === 1 && path[0] === 'length') {
|
|
8607
|
+
objectEntity.deoptimizePath(UNKNOWN_INTEGER_PATH);
|
|
8608
|
+
}
|
|
8565
8609
|
}
|
|
8566
8610
|
getLiteralValueAtPath(path, recursionTracker, origin) {
|
|
8567
8611
|
return this.getObjectEntity().getLiteralValueAtPath(path, recursionTracker, origin);
|
|
@@ -8644,6 +8688,29 @@ const IMPURE = {
|
|
|
8644
8688
|
getLiteralValue: getUnknownValue,
|
|
8645
8689
|
hasEffectsWhenCalled: returnTrue
|
|
8646
8690
|
};
|
|
8691
|
+
// For functions that return their arguments, the arguments can be mutated via
|
|
8692
|
+
// the return value
|
|
8693
|
+
const deoptimizeArguments = ({ args }) => {
|
|
8694
|
+
for (let index = 1; index < args.length; index++) {
|
|
8695
|
+
args[index]?.deoptimizePath(UNKNOWN_PATH);
|
|
8696
|
+
}
|
|
8697
|
+
};
|
|
8698
|
+
// For functions that return values stored in their arguments (but not the
|
|
8699
|
+
// arguments themselves), those values can be mutated via the return value
|
|
8700
|
+
const UNKNOWN_VALUES_PATH = [UnknownKey, UnknownKey];
|
|
8701
|
+
const deoptimizeArgumentValues = ({ args }) => {
|
|
8702
|
+
for (let index = 1; index < args.length; index++) {
|
|
8703
|
+
args[index]?.deoptimizePath(UNKNOWN_VALUES_PATH);
|
|
8704
|
+
}
|
|
8705
|
+
};
|
|
8706
|
+
const returningArguments = (description) => ({
|
|
8707
|
+
...description,
|
|
8708
|
+
deoptimizeArgumentsOnCall: deoptimizeArguments
|
|
8709
|
+
});
|
|
8710
|
+
const returningArgumentValues = (description) => ({
|
|
8711
|
+
...description,
|
|
8712
|
+
deoptimizeArgumentsOnCall: deoptimizeArgumentValues
|
|
8713
|
+
});
|
|
8647
8714
|
const PURE_WITH_ARRAY = {
|
|
8648
8715
|
deoptimizeArgumentsOnCall: doNothing,
|
|
8649
8716
|
getLiteralValue: getUnknownValue,
|
|
@@ -8663,8 +8730,9 @@ const PURE_WITH_ARRAY_OR_LENGTH = {
|
|
|
8663
8730
|
}) !== 'number');
|
|
8664
8731
|
}
|
|
8665
8732
|
};
|
|
8733
|
+
// Used for Object.entries and Object.values, which return the property values
|
|
8666
8734
|
const GETTER_ACCESS = {
|
|
8667
|
-
deoptimizeArgumentsOnCall:
|
|
8735
|
+
deoptimizeArgumentsOnCall: deoptimizeArgumentValues,
|
|
8668
8736
|
getLiteralValue: getUnknownValue,
|
|
8669
8737
|
hasEffectsWhenCalled({ args }, context) {
|
|
8670
8738
|
const [_thisArgument, firstArgument] = args;
|
|
@@ -8683,17 +8751,60 @@ const PF = {
|
|
|
8683
8751
|
__proto__: null,
|
|
8684
8752
|
[ValueProperties]: PURE
|
|
8685
8753
|
};
|
|
8754
|
+
/* OBJECT THAT RETURNS ITS ARGUMENTS WHEN CALLED */
|
|
8755
|
+
const O_RETURNING_ARGS = {
|
|
8756
|
+
__proto__: null,
|
|
8757
|
+
[ValueProperties]: returningArguments(IMPURE)
|
|
8758
|
+
};
|
|
8759
|
+
/* OBJECT THAT RETURNS VALUES STORED IN ITS ARGUMENTS WHEN CALLED */
|
|
8760
|
+
const O_RETURNING_ARG_VALUES = {
|
|
8761
|
+
__proto__: null,
|
|
8762
|
+
[ValueProperties]: returningArgumentValues(IMPURE)
|
|
8763
|
+
};
|
|
8764
|
+
/* Array.from RETURNS THE VALUES OF THE ITERABLE OR WHATEVER THE MAPPER RETURNS */
|
|
8765
|
+
const ARRAY_FROM = {
|
|
8766
|
+
__proto__: null,
|
|
8767
|
+
[ValueProperties]: {
|
|
8768
|
+
...IMPURE,
|
|
8769
|
+
deoptimizeArgumentsOnCall({ args: [, iterable, ...otherArguments] }) {
|
|
8770
|
+
iterable?.deoptimizePath(UNKNOWN_VALUES_PATH);
|
|
8771
|
+
// The mapper is called by the global, so its return value and its
|
|
8772
|
+
// parameters, as well as the this argument, are no longer tracked.
|
|
8773
|
+
// As spread arguments mean that the mapper and this argument do not
|
|
8774
|
+
// necessarily have a fixed position, we deoptimize all remaining
|
|
8775
|
+
// arguments.
|
|
8776
|
+
for (const argument of otherArguments) {
|
|
8777
|
+
argument.deoptimizePath(UNKNOWN_PATH);
|
|
8778
|
+
}
|
|
8779
|
+
}
|
|
8780
|
+
}
|
|
8781
|
+
};
|
|
8782
|
+
/* PURE FUNCTION THAT RETURNS ITS ARGUMENTS */
|
|
8783
|
+
const PF_RETURNING_ARGS = {
|
|
8784
|
+
__proto__: null,
|
|
8785
|
+
[ValueProperties]: returningArguments(PURE)
|
|
8786
|
+
};
|
|
8787
|
+
/* PURE FUNCTION THAT RETURNS VALUES STORED IN ITS ARGUMENTS */
|
|
8788
|
+
const PF_RETURNING_ARG_VALUES = {
|
|
8789
|
+
__proto__: null,
|
|
8790
|
+
[ValueProperties]: returningArgumentValues(PURE)
|
|
8791
|
+
};
|
|
8686
8792
|
/* PURE FUNCTION IF FIRST ARG DOES NOT CONTAIN A GETTER */
|
|
8687
8793
|
const PF_NO_GETTER = {
|
|
8688
8794
|
__proto__: null,
|
|
8689
8795
|
[ValueProperties]: GETTER_ACCESS
|
|
8690
8796
|
};
|
|
8691
8797
|
/* FUNCTION THAT MUTATES FIRST ARG WITHOUT TRIGGERING ACCESSORS */
|
|
8798
|
+
// For defineProperty and defineProperties, the values of the property
|
|
8799
|
+
// descriptors also become reachable via the first argument
|
|
8692
8800
|
const MUTATES_ARG_WITHOUT_ACCESSOR = {
|
|
8693
8801
|
__proto__: null,
|
|
8694
8802
|
[ValueProperties]: {
|
|
8695
|
-
deoptimizeArgumentsOnCall({ args: [, firstArgument] }) {
|
|
8803
|
+
deoptimizeArgumentsOnCall({ args: [, firstArgument, ...otherArguments] }) {
|
|
8696
8804
|
firstArgument?.deoptimizePath(UNKNOWN_PATH);
|
|
8805
|
+
for (const argument of otherArguments) {
|
|
8806
|
+
argument.deoptimizePath(UNKNOWN_VALUES_PATH);
|
|
8807
|
+
}
|
|
8697
8808
|
},
|
|
8698
8809
|
getLiteralValue: getUnknownValue,
|
|
8699
8810
|
hasEffectsWhenCalled({ args }, context) {
|
|
@@ -8719,6 +8830,18 @@ const PC_WITH_ARRAY = {
|
|
|
8719
8830
|
[ValueProperties]: PURE_WITH_ARRAY,
|
|
8720
8831
|
prototype: O
|
|
8721
8832
|
};
|
|
8833
|
+
/* PURE CONSTRUCTOR WITH ARRAY WHOSE INSTANCES EXPOSE THE VALUES OF THE ARRAY */
|
|
8834
|
+
const PC_WITH_ARRAY_RETURNING_ARG_VALUES = {
|
|
8835
|
+
__proto__: null,
|
|
8836
|
+
[ValueProperties]: returningArgumentValues(PURE_WITH_ARRAY),
|
|
8837
|
+
prototype: O
|
|
8838
|
+
};
|
|
8839
|
+
/* PURE CONSTRUCTOR WHOSE INSTANCES EXPOSE VALUES STORED IN ITS ARGUMENTS */
|
|
8840
|
+
const PC_RETURNING_ARG_VALUES = {
|
|
8841
|
+
__proto__: null,
|
|
8842
|
+
[ValueProperties]: returningArgumentValues(PURE),
|
|
8843
|
+
prototype: O
|
|
8844
|
+
};
|
|
8722
8845
|
const ARRAY_TYPE = {
|
|
8723
8846
|
__proto__: null,
|
|
8724
8847
|
[ValueProperties]: PURE_WITH_ARRAY_OR_LENGTH,
|
|
@@ -8747,10 +8870,10 @@ const knownGlobals = {
|
|
|
8747
8870
|
[ValueProperties]: IMPURE,
|
|
8748
8871
|
Array: {
|
|
8749
8872
|
__proto__: null,
|
|
8750
|
-
[ValueProperties]: IMPURE,
|
|
8751
|
-
from:
|
|
8873
|
+
[ValueProperties]: returningArguments(IMPURE),
|
|
8874
|
+
from: ARRAY_FROM,
|
|
8752
8875
|
isArray: PF,
|
|
8753
|
-
of:
|
|
8876
|
+
of: PF_RETURNING_ARGS,
|
|
8754
8877
|
prototype: O
|
|
8755
8878
|
},
|
|
8756
8879
|
ArrayBuffer: {
|
|
@@ -8759,7 +8882,7 @@ const knownGlobals = {
|
|
|
8759
8882
|
isView: PF,
|
|
8760
8883
|
prototype: O
|
|
8761
8884
|
},
|
|
8762
|
-
AggregateError:
|
|
8885
|
+
AggregateError: PC_WITH_ARRAY_RETURNING_ARG_VALUES,
|
|
8763
8886
|
Atomics: O,
|
|
8764
8887
|
BigInt: C,
|
|
8765
8888
|
BigInt64Array: C,
|
|
@@ -8779,10 +8902,10 @@ const knownGlobals = {
|
|
|
8779
8902
|
decodeURIComponent: PF,
|
|
8780
8903
|
encodeURI: PF,
|
|
8781
8904
|
encodeURIComponent: PF,
|
|
8782
|
-
Error:
|
|
8905
|
+
Error: PC_RETURNING_ARG_VALUES,
|
|
8783
8906
|
escape: PF,
|
|
8784
8907
|
eval: O,
|
|
8785
|
-
EvalError:
|
|
8908
|
+
EvalError: PC_RETURNING_ARG_VALUES,
|
|
8786
8909
|
FinalizationRegistry: C,
|
|
8787
8910
|
Float32Array: ARRAY_TYPE,
|
|
8788
8911
|
Float64Array: ARRAY_TYPE,
|
|
@@ -8796,7 +8919,7 @@ const knownGlobals = {
|
|
|
8796
8919
|
isNaN: PF,
|
|
8797
8920
|
isPrototypeOf: O,
|
|
8798
8921
|
JSON: O,
|
|
8799
|
-
Map:
|
|
8922
|
+
Map: PC_WITH_ARRAY_RETURNING_ARG_VALUES,
|
|
8800
8923
|
Math: {
|
|
8801
8924
|
__proto__: null,
|
|
8802
8925
|
[ValueProperties]: IMPURE,
|
|
@@ -8850,16 +8973,16 @@ const knownGlobals = {
|
|
|
8850
8973
|
},
|
|
8851
8974
|
Object: {
|
|
8852
8975
|
__proto__: null,
|
|
8853
|
-
[ValueProperties]: PURE,
|
|
8854
|
-
create:
|
|
8976
|
+
[ValueProperties]: returningArguments(PURE),
|
|
8977
|
+
create: PF_RETURNING_ARG_VALUES,
|
|
8855
8978
|
// Technically those can throw in certain situations, but we ignore this as
|
|
8856
8979
|
// code that relies on this will hopefully wrap this in a try-catch, which
|
|
8857
8980
|
// deoptimizes everything anyway
|
|
8858
8981
|
defineProperty: MUTATES_ARG_WITHOUT_ACCESSOR,
|
|
8859
8982
|
defineProperties: MUTATES_ARG_WITHOUT_ACCESSOR,
|
|
8860
8983
|
freeze: MUTATES_ARG_WITHOUT_ACCESSOR,
|
|
8861
|
-
getOwnPropertyDescriptor:
|
|
8862
|
-
getOwnPropertyDescriptors:
|
|
8984
|
+
getOwnPropertyDescriptor: PF_RETURNING_ARG_VALUES,
|
|
8985
|
+
getOwnPropertyDescriptors: PF_RETURNING_ARG_VALUES,
|
|
8863
8986
|
getOwnPropertyNames: PF,
|
|
8864
8987
|
getOwnPropertySymbols: PF,
|
|
8865
8988
|
getPrototypeOf: PF,
|
|
@@ -8869,7 +8992,7 @@ const knownGlobals = {
|
|
|
8869
8992
|
isFrozen: PF,
|
|
8870
8993
|
isSealed: PF,
|
|
8871
8994
|
keys: PF,
|
|
8872
|
-
fromEntries:
|
|
8995
|
+
fromEntries: O_RETURNING_ARG_VALUES,
|
|
8873
8996
|
entries: PF_NO_GETTER,
|
|
8874
8997
|
values: PF_NO_GETTER,
|
|
8875
8998
|
prototype: O
|
|
@@ -8879,13 +9002,13 @@ const knownGlobals = {
|
|
|
8879
9002
|
Promise: {
|
|
8880
9003
|
__proto__: null,
|
|
8881
9004
|
[ValueProperties]: IMPURE,
|
|
8882
|
-
all:
|
|
8883
|
-
allSettled:
|
|
8884
|
-
any:
|
|
9005
|
+
all: O_RETURNING_ARG_VALUES,
|
|
9006
|
+
allSettled: O_RETURNING_ARG_VALUES,
|
|
9007
|
+
any: O_RETURNING_ARG_VALUES,
|
|
8885
9008
|
prototype: O,
|
|
8886
|
-
race:
|
|
8887
|
-
reject:
|
|
8888
|
-
resolve:
|
|
9009
|
+
race: O_RETURNING_ARG_VALUES,
|
|
9010
|
+
reject: O_RETURNING_ARGS,
|
|
9011
|
+
resolve: O_RETURNING_ARGS
|
|
8889
9012
|
},
|
|
8890
9013
|
propertyIsEnumerable: O,
|
|
8891
9014
|
Proxy: {
|
|
@@ -8911,11 +9034,11 @@ const knownGlobals = {
|
|
|
8911
9034
|
hasEffectsWhenCalled: returnTrue
|
|
8912
9035
|
}
|
|
8913
9036
|
},
|
|
8914
|
-
RangeError:
|
|
8915
|
-
ReferenceError:
|
|
9037
|
+
RangeError: PC_RETURNING_ARG_VALUES,
|
|
9038
|
+
ReferenceError: PC_RETURNING_ARG_VALUES,
|
|
8916
9039
|
Reflect: O,
|
|
8917
9040
|
RegExp: PC,
|
|
8918
|
-
Set:
|
|
9041
|
+
Set: PC_WITH_ARRAY_RETURNING_ARG_VALUES,
|
|
8919
9042
|
SharedArrayBuffer: C,
|
|
8920
9043
|
String: {
|
|
8921
9044
|
__proto__: null,
|
|
@@ -8936,10 +9059,10 @@ const knownGlobals = {
|
|
|
8936
9059
|
hasInstance: getWellKnownSymbol(SymbolHasInstance),
|
|
8937
9060
|
toStringTag: getWellKnownSymbol(SymbolToStringTag)
|
|
8938
9061
|
},
|
|
8939
|
-
SyntaxError:
|
|
9062
|
+
SyntaxError: PC_RETURNING_ARG_VALUES,
|
|
8940
9063
|
toLocaleString: O,
|
|
8941
9064
|
toString: O,
|
|
8942
|
-
TypeError:
|
|
9065
|
+
TypeError: PC_RETURNING_ARG_VALUES,
|
|
8943
9066
|
Uint16Array: ARRAY_TYPE,
|
|
8944
9067
|
Uint32Array: ARRAY_TYPE,
|
|
8945
9068
|
Uint8Array: ARRAY_TYPE,
|
|
@@ -8947,10 +9070,14 @@ const knownGlobals = {
|
|
|
8947
9070
|
// Technically, this is a global, but it needs special handling
|
|
8948
9071
|
// undefined: ?,
|
|
8949
9072
|
unescape: PF,
|
|
8950
|
-
URIError:
|
|
9073
|
+
URIError: PC_RETURNING_ARG_VALUES,
|
|
8951
9074
|
valueOf: O,
|
|
8952
|
-
WeakMap:
|
|
8953
|
-
WeakRef:
|
|
9075
|
+
WeakMap: PC_WITH_ARRAY_RETURNING_ARG_VALUES,
|
|
9076
|
+
WeakRef: {
|
|
9077
|
+
__proto__: null,
|
|
9078
|
+
[ValueProperties]: returningArguments(IMPURE),
|
|
9079
|
+
prototype: O
|
|
9080
|
+
},
|
|
8954
9081
|
WeakSet: PC_WITH_ARRAY,
|
|
8955
9082
|
// Additional globals shared by Node and Browser that are not strictly part of the language
|
|
8956
9083
|
clearInterval: C,
|
|
@@ -10285,15 +10412,12 @@ class ChildScope extends Scope {
|
|
|
10285
10412
|
}
|
|
10286
10413
|
addUsedOutsideNames(usedNames, format, exportNamesByVariable, accessedGlobalsByScope) {
|
|
10287
10414
|
for (const variable of this.accessedOutsideVariables.values()) {
|
|
10288
|
-
|
|
10289
|
-
|
|
10290
|
-
|
|
10291
|
-
|
|
10292
|
-
|
|
10293
|
-
|
|
10294
|
-
if (format === 'system' && exportNamesByVariable.has(variable)) {
|
|
10295
|
-
usedNames.add('exports');
|
|
10296
|
-
}
|
|
10415
|
+
this.addUsedOutsideVariableName(variable, usedNames, format, exportNamesByVariable);
|
|
10416
|
+
}
|
|
10417
|
+
// Hoisted declarations render their binding here without referencing it.
|
|
10418
|
+
if (this.hoistedVariables) {
|
|
10419
|
+
for (const variable of this.hoistedVariables.values()) {
|
|
10420
|
+
this.addUsedOutsideVariableName(variable, usedNames, format, exportNamesByVariable);
|
|
10297
10421
|
}
|
|
10298
10422
|
}
|
|
10299
10423
|
const accessedGlobals = accessedGlobalsByScope.get(this);
|
|
@@ -10325,6 +10449,17 @@ class ChildScope extends Scope {
|
|
|
10325
10449
|
scope.deconflict(format, exportNamesByVariable, accessedGlobalsByScope);
|
|
10326
10450
|
}
|
|
10327
10451
|
}
|
|
10452
|
+
addUsedOutsideVariableName(variable, usedNames, format, exportNamesByVariable) {
|
|
10453
|
+
if (!variable.included)
|
|
10454
|
+
return;
|
|
10455
|
+
usedNames.add(variable.getBaseVariableName());
|
|
10456
|
+
// In system format, exported variables are assigned via `exports(name, value)`.
|
|
10457
|
+
// Any scope that renders such a variable must treat `exports` as used so that a
|
|
10458
|
+
// nested binding of the same name does not shadow the wrapper's `exports` argument.
|
|
10459
|
+
if (format === 'system' && exportNamesByVariable.has(variable)) {
|
|
10460
|
+
usedNames.add('exports');
|
|
10461
|
+
}
|
|
10462
|
+
}
|
|
10328
10463
|
findLexicalBoundary() {
|
|
10329
10464
|
return this.parent.findLexicalBoundary();
|
|
10330
10465
|
}
|
|
@@ -10494,11 +10629,13 @@ class BlockScope extends ChildScope {
|
|
|
10494
10629
|
const name = identifier.name;
|
|
10495
10630
|
const existingVariable = this.hoistedVariables?.get(name) || this.variables.get(name);
|
|
10496
10631
|
if (existingVariable) {
|
|
10497
|
-
if (existingVariable.kind === 'var'
|
|
10498
|
-
(kind === 'var' && existingVariable.kind === 'parameter')) {
|
|
10632
|
+
if (existingVariable.kind === 'var') {
|
|
10499
10633
|
existingVariable.addDeclaration(identifier, init);
|
|
10500
10634
|
return existingVariable;
|
|
10501
10635
|
}
|
|
10636
|
+
if (existingVariable.kind === 'parameter') {
|
|
10637
|
+
return this.parent.addDeclaration(identifier, context, init, destructuredInitPath, kind);
|
|
10638
|
+
}
|
|
10502
10639
|
return context.error(parseAst_js.logRedeclarationError(name), identifier.start);
|
|
10503
10640
|
}
|
|
10504
10641
|
const declaredVariable = this.parent.addDeclaration(identifier, context, init, destructuredInitPath, kind);
|
|
@@ -11017,32 +11154,31 @@ class CatchBodyScope extends ChildScope {
|
|
|
11017
11154
|
addDeclaration(identifier, context, init, destructuredInitPath, kind) {
|
|
11018
11155
|
if (kind === 'var') {
|
|
11019
11156
|
const name = identifier.name;
|
|
11157
|
+
const parameter = this.parent.variables.get(name);
|
|
11158
|
+
if (isSimpleCatchParameter(parameter)) {
|
|
11159
|
+
// Annex B: a var redeclaring a simple catch parameter is hoisted
|
|
11160
|
+
// without assignment while its initializer assigns the parameter. As
|
|
11161
|
+
// the rendered declaration also declares the hoisted variable, the
|
|
11162
|
+
// parameter renders with the hoisted variable's name, unless that
|
|
11163
|
+
// variable is rendered as an exports member, in which case the
|
|
11164
|
+
// declaration becomes an assignment.
|
|
11165
|
+
const declaredVariable = this.parent.parent.addDeclaration(identifier, context, UNDEFINED_EXPRESSION, destructuredInitPath, kind);
|
|
11166
|
+
declaredVariable.markInitializersForDeoptimization();
|
|
11167
|
+
parameter.renderLikeHoisted(declaredVariable.getHoistedVariable() ?? declaredVariable);
|
|
11168
|
+
if (!this.isShadowedByInnerCatchParameter(identifier, name)) {
|
|
11169
|
+
parameter.addDeclaration(identifier, init);
|
|
11170
|
+
}
|
|
11171
|
+
return parameter;
|
|
11172
|
+
}
|
|
11020
11173
|
const existingVariable = this.hoistedVariables?.get(name) || this.variables.get(name);
|
|
11021
11174
|
if (existingVariable) {
|
|
11022
|
-
|
|
11023
|
-
if (existingKind === 'parameter' &&
|
|
11024
|
-
// If this is a destructured parameter, it is forbidden to redeclare
|
|
11025
|
-
existingVariable.declarations[0].parent.type === parseAst_js.CatchClause) {
|
|
11026
|
-
// If this is a var with the same name as the catch scope parameter,
|
|
11027
|
-
// the assignment actually goes to the parameter and the var is
|
|
11028
|
-
// hoisted without assignment. Locally, it is shadowed by the
|
|
11029
|
-
// parameter
|
|
11030
|
-
const declaredVariable = this.parent.parent.addDeclaration(identifier, context, UNDEFINED_EXPRESSION, destructuredInitPath, kind);
|
|
11031
|
-
// To avoid the need to rewrite the declaration, we link the variable
|
|
11032
|
-
// names. If we ever implement a logic that splits initialization and
|
|
11033
|
-
// assignment for hoisted vars, the "renderLikeHoisted" logic can be
|
|
11034
|
-
// removed again.
|
|
11035
|
-
// We do not need to check whether there already is a linked
|
|
11036
|
-
// variable because then declaredVariable would be that linked
|
|
11037
|
-
// variable.
|
|
11038
|
-
existingVariable.renderLikeHoisted(declaredVariable);
|
|
11039
|
-
this.addHoistedVariable(name, declaredVariable);
|
|
11040
|
-
return declaredVariable;
|
|
11041
|
-
}
|
|
11042
|
-
if (existingKind === 'var') {
|
|
11175
|
+
if (existingVariable.kind === 'var') {
|
|
11043
11176
|
existingVariable.addDeclaration(identifier, init);
|
|
11044
11177
|
return existingVariable;
|
|
11045
11178
|
}
|
|
11179
|
+
if (existingVariable.kind === 'parameter' && existingVariable !== parameter) {
|
|
11180
|
+
return this.parent.parent.addDeclaration(identifier, context, init, destructuredInitPath, kind);
|
|
11181
|
+
}
|
|
11046
11182
|
return context.error(parseAst_js.logRedeclarationError(name), identifier.start);
|
|
11047
11183
|
}
|
|
11048
11184
|
// We only add parameters to parameter scopes
|
|
@@ -11056,6 +11192,23 @@ class CatchBodyScope extends ChildScope {
|
|
|
11056
11192
|
}
|
|
11057
11193
|
return super.addDeclaration(identifier, context, init, destructuredInitPath, kind);
|
|
11058
11194
|
}
|
|
11195
|
+
isShadowedByInnerCatchParameter(identifier, name) {
|
|
11196
|
+
let scope = identifier.scope;
|
|
11197
|
+
while (scope !== this) {
|
|
11198
|
+
if (scope instanceof CatchBodyScope) {
|
|
11199
|
+
const parameter = scope.parent.variables.get(name);
|
|
11200
|
+
if (isSimpleCatchParameter(parameter))
|
|
11201
|
+
return true;
|
|
11202
|
+
}
|
|
11203
|
+
scope = scope.parent;
|
|
11204
|
+
}
|
|
11205
|
+
return false;
|
|
11206
|
+
}
|
|
11207
|
+
}
|
|
11208
|
+
function isSimpleCatchParameter(variable) {
|
|
11209
|
+
return (variable?.kind === 'parameter' &&
|
|
11210
|
+
// If this is a destructured parameter, it is forbidden to redeclare
|
|
11211
|
+
variable.declarations[0].parent.type === parseAst_js.CatchClause);
|
|
11059
11212
|
}
|
|
11060
11213
|
|
|
11061
11214
|
class FunctionBodyScope extends ChildScope {
|
|
@@ -12863,307 +13016,968 @@ const importMetaMechanisms = {
|
|
|
12863
13016
|
umd: getGenericImportMetaMechanism(chunkId => `(typeof document === 'undefined' && typeof location === 'undefined' ? ${getFileUrlFromFullPath('__filename', false)} : ${getUrlFromDocument(chunkId, true)})`)
|
|
12864
13017
|
};
|
|
12865
13018
|
|
|
12866
|
-
|
|
12867
|
-
|
|
12868
|
-
|
|
12869
|
-
|
|
12870
|
-
|
|
12871
|
-
|
|
12872
|
-
|
|
12873
|
-
|
|
12874
|
-
|
|
12875
|
-
|
|
12876
|
-
|
|
12877
|
-
|
|
12878
|
-
|
|
12879
|
-
|
|
12880
|
-
|
|
12881
|
-
|
|
12882
|
-
|
|
12883
|
-
|
|
12884
|
-
|
|
12885
|
-
|
|
12886
|
-
|
|
12887
|
-
|
|
12888
|
-
|
|
12889
|
-
|
|
13019
|
+
function isReassignedExportsMember(variable, exportNamesByVariable) {
|
|
13020
|
+
return (variable.renderBaseName !== null && exportNamesByVariable.has(variable) && variable.isReassigned);
|
|
13021
|
+
}
|
|
13022
|
+
function isDeclaredWithoutBinding(variable, exportNamesByVariable) {
|
|
13023
|
+
if (isReassignedExportsMember(variable, exportNamesByVariable))
|
|
13024
|
+
return true;
|
|
13025
|
+
const hoistedVariable = variable.getHoistedVariable();
|
|
13026
|
+
return hoistedVariable !== undefined && hoistedVariable.renderBaseName !== null;
|
|
13027
|
+
}
|
|
13028
|
+
|
|
13029
|
+
function markTopLevelAwait(node) {
|
|
13030
|
+
if (node.scope.context.usesTopLevelAwait)
|
|
13031
|
+
return;
|
|
13032
|
+
let parent = node.parent;
|
|
13033
|
+
do {
|
|
13034
|
+
if (parent instanceof FunctionBase)
|
|
13035
|
+
return;
|
|
13036
|
+
} while ((parent = parent.parent));
|
|
13037
|
+
node.scope.context.usesTopLevelAwait = true;
|
|
13038
|
+
}
|
|
13039
|
+
|
|
13040
|
+
class ArrayPattern extends NodeBase {
|
|
13041
|
+
addExportedVariables(variables, exportNamesByVariable) {
|
|
13042
|
+
for (const element of this.elements) {
|
|
13043
|
+
element?.addExportedVariables(variables, exportNamesByVariable);
|
|
12890
13044
|
}
|
|
12891
13045
|
}
|
|
12892
|
-
|
|
12893
|
-
|
|
12894
|
-
|
|
12895
|
-
|
|
12896
|
-
|
|
12897
|
-
|
|
12898
|
-
else if (!this.areAllMembersDeoptimized) {
|
|
12899
|
-
this.areAllMembersDeoptimized = true;
|
|
12900
|
-
for (const variable of this.module.getExportedVariablesByName().values()) {
|
|
12901
|
-
variable.deoptimizePath(UNKNOWN_PATH);
|
|
12902
|
-
}
|
|
13046
|
+
declare(kind, destructuredInitPath, init) {
|
|
13047
|
+
const variables = [];
|
|
13048
|
+
const includedPatternPath = getIncludedPatternPath(destructuredInitPath);
|
|
13049
|
+
for (const element of this.elements) {
|
|
13050
|
+
if (element !== null) {
|
|
13051
|
+
variables.push(...element.declare(kind, includedPatternPath, init));
|
|
12903
13052
|
}
|
|
12904
13053
|
}
|
|
13054
|
+
return variables;
|
|
12905
13055
|
}
|
|
12906
|
-
|
|
12907
|
-
|
|
12908
|
-
|
|
13056
|
+
deoptimizeAssignment(destructuredInitPath, init) {
|
|
13057
|
+
const includedPatternPath = getIncludedPatternPath(destructuredInitPath);
|
|
13058
|
+
for (const element of this.elements) {
|
|
13059
|
+
element?.deoptimizeAssignment(includedPatternPath, init);
|
|
12909
13060
|
}
|
|
12910
|
-
return UnknownValue;
|
|
12911
13061
|
}
|
|
12912
|
-
|
|
12913
|
-
|
|
12914
|
-
|
|
12915
|
-
|
|
12916
|
-
return true;
|
|
12917
|
-
}
|
|
12918
|
-
if (path.length === 1 && type !== INTERACTION_CALLED) {
|
|
12919
|
-
return type === INTERACTION_ASSIGNED;
|
|
12920
|
-
}
|
|
12921
|
-
const key = path[0];
|
|
12922
|
-
if (typeof key !== 'string') {
|
|
12923
|
-
return true;
|
|
13062
|
+
// Patterns can only be deoptimized at the empty path at the moment
|
|
13063
|
+
deoptimizePath() {
|
|
13064
|
+
for (const element of this.elements) {
|
|
13065
|
+
element?.deoptimizePath(EMPTY_PATH);
|
|
12924
13066
|
}
|
|
12925
|
-
const memberVariable = this.getMemberVariable(key);
|
|
12926
|
-
return (!memberVariable ||
|
|
12927
|
-
memberVariable.hasEffectsOnInteractionAtPath(path.slice(1), interaction, context));
|
|
12928
|
-
}
|
|
12929
|
-
includePath(path, context) {
|
|
12930
|
-
super.includePath(path, context);
|
|
12931
|
-
this.includeMemberPath(path, context);
|
|
12932
13067
|
}
|
|
12933
|
-
|
|
12934
|
-
|
|
12935
|
-
|
|
12936
|
-
if (
|
|
12937
|
-
|
|
12938
|
-
if (variable) {
|
|
12939
|
-
this.context.includeVariableInModule(variable, remainingPath, context);
|
|
12940
|
-
}
|
|
12941
|
-
else {
|
|
12942
|
-
this.includeNonExplicitNamespaces();
|
|
12943
|
-
}
|
|
12944
|
-
}
|
|
12945
|
-
else if (name) {
|
|
12946
|
-
this.module.includeAllExports();
|
|
12947
|
-
this.includeNonExplicitNamespaces();
|
|
13068
|
+
hasEffectsWhenDestructuring(context, destructuredInitPath, init) {
|
|
13069
|
+
const includedPatternPath = getIncludedPatternPath(destructuredInitPath);
|
|
13070
|
+
for (const element of this.elements) {
|
|
13071
|
+
if (element?.hasEffectsWhenDestructuring(context, includedPatternPath, init)) {
|
|
13072
|
+
return true;
|
|
12948
13073
|
}
|
|
12949
13074
|
}
|
|
13075
|
+
return false;
|
|
12950
13076
|
}
|
|
12951
|
-
|
|
12952
|
-
|
|
12953
|
-
|
|
13077
|
+
// Patterns are only checked at the empty path at the moment
|
|
13078
|
+
hasEffectsOnInteractionAtPath(_path, interaction, context) {
|
|
13079
|
+
for (const element of this.elements) {
|
|
13080
|
+
if (element?.hasEffectsOnInteractionAtPath(EMPTY_PATH, interaction, context))
|
|
13081
|
+
return true;
|
|
12954
13082
|
}
|
|
13083
|
+
return false;
|
|
12955
13084
|
}
|
|
12956
|
-
|
|
12957
|
-
|
|
12958
|
-
const
|
|
12959
|
-
const
|
|
12960
|
-
|
|
12961
|
-
|
|
12962
|
-
|
|
12963
|
-
|
|
12964
|
-
|
|
12965
|
-
|
|
12966
|
-
(variable.module &&
|
|
12967
|
-
!variable.module.info.isExternal &&
|
|
12968
|
-
variable.module.execIndex > this.module.execIndex)) {
|
|
12969
|
-
return [
|
|
12970
|
-
null,
|
|
12971
|
-
`get ${stringifyObjectKeyIfNeeded(key)}${_}()${_}{${_}return ${variable.getName(getPropertyAccess)}${s}${_}}`
|
|
12972
|
-
];
|
|
13085
|
+
includeDestructuredIfNecessary(context, destructuredInitPath, init) {
|
|
13086
|
+
let included = false;
|
|
13087
|
+
const includedPatternPath = getIncludedPatternPath(destructuredInitPath);
|
|
13088
|
+
for (const element of [...this.elements].reverse()) {
|
|
13089
|
+
if (element) {
|
|
13090
|
+
if (included && !element.included) {
|
|
13091
|
+
element.includeNode(context);
|
|
13092
|
+
}
|
|
13093
|
+
included =
|
|
13094
|
+
element.includeDestructuredIfNecessary(context, includedPatternPath, init) || included;
|
|
12973
13095
|
}
|
|
12974
|
-
return [key, variable.getName(getPropertyAccess)];
|
|
12975
|
-
});
|
|
12976
|
-
members.unshift([null, `__proto__:${_}null`]);
|
|
12977
|
-
let output = getObject(members, { lineBreakIndent: { base: '', t } });
|
|
12978
|
-
if (this.mergedNamespaces.length > 0) {
|
|
12979
|
-
const assignmentArguments = this.mergedNamespaces.map(variable => variable.getName(getPropertyAccess));
|
|
12980
|
-
output = `/*#__PURE__*/${MERGE_NAMESPACES_VARIABLE}(${output},${_}[${assignmentArguments.join(`,${_}`)}])`;
|
|
12981
13096
|
}
|
|
12982
|
-
|
|
12983
|
-
|
|
12984
|
-
|
|
12985
|
-
|
|
13097
|
+
if (!this.included && included) {
|
|
13098
|
+
this.includeNode(context);
|
|
13099
|
+
}
|
|
13100
|
+
return this.included;
|
|
13101
|
+
}
|
|
13102
|
+
render(code, options) {
|
|
13103
|
+
let removedStart = this.start + 1;
|
|
13104
|
+
for (const element of this.elements) {
|
|
13105
|
+
if (!element)
|
|
13106
|
+
continue;
|
|
13107
|
+
if (element.included) {
|
|
13108
|
+
element.render(code, options);
|
|
13109
|
+
removedStart = element.end;
|
|
12986
13110
|
}
|
|
12987
|
-
|
|
12988
|
-
|
|
13111
|
+
else {
|
|
13112
|
+
code.remove(removedStart, this.end - 1);
|
|
13113
|
+
break;
|
|
12989
13114
|
}
|
|
12990
13115
|
}
|
|
12991
|
-
const name = this.getName(getPropertyAccess);
|
|
12992
|
-
output = `${cnst} ${name}${_}=${_}${output};`;
|
|
12993
|
-
if (format === 'system' && exportNamesByVariable.has(this)) {
|
|
12994
|
-
output += `${n}${getSystemExportStatement([this], options)};`;
|
|
12995
|
-
}
|
|
12996
|
-
return output;
|
|
12997
|
-
}
|
|
12998
|
-
renderFirst() {
|
|
12999
|
-
return this.referencedEarly;
|
|
13000
13116
|
}
|
|
13001
|
-
|
|
13002
|
-
|
|
13003
|
-
|
|
13004
|
-
|
|
13005
|
-
|
|
13006
|
-
|
|
13007
|
-
this.referencedEarly = true;
|
|
13008
|
-
break;
|
|
13009
|
-
}
|
|
13117
|
+
setAssignedValue(value) {
|
|
13118
|
+
super.setAssignedValue(value);
|
|
13119
|
+
// Destructuring assigns each target only some subpath of the assigned
|
|
13120
|
+
// value, which is not tracked
|
|
13121
|
+
for (const element of this.elements) {
|
|
13122
|
+
element?.setAssignedValue(UNKNOWN_EXPRESSION);
|
|
13010
13123
|
}
|
|
13011
13124
|
}
|
|
13012
|
-
|
|
13013
|
-
|
|
13014
|
-
|
|
13015
|
-
includeNonExplicitNamespaces() {
|
|
13016
|
-
if (!this.nonExplicitNamespacesIncluded) {
|
|
13017
|
-
this.nonExplicitNamespacesIncluded = true;
|
|
13018
|
-
this.setMergedNamespaces(this.module.includeAndGetAdditionalMergedNamespaces());
|
|
13125
|
+
markDeclarationReached() {
|
|
13126
|
+
for (const element of this.elements) {
|
|
13127
|
+
element?.markDeclarationReached();
|
|
13019
13128
|
}
|
|
13020
13129
|
}
|
|
13021
13130
|
}
|
|
13022
|
-
|
|
13023
|
-
|
|
13024
|
-
|
|
13025
|
-
|
|
13026
|
-
value(path, context) {
|
|
13027
|
-
namespace.includeMemberPath(path, context);
|
|
13028
|
-
}
|
|
13029
|
-
}
|
|
13030
|
-
});
|
|
13131
|
+
ArrayPattern.prototype.includeNode = onlyIncludeSelf;
|
|
13132
|
+
const getIncludedPatternPath = (destructuredInitPath) => destructuredInitPath.at(-1) === UnknownKey
|
|
13133
|
+
? destructuredInitPath
|
|
13134
|
+
: [...destructuredInitPath, UnknownInteger];
|
|
13031
13135
|
|
|
13032
|
-
class
|
|
13033
|
-
|
|
13034
|
-
|
|
13035
|
-
|
|
13036
|
-
|
|
13037
|
-
this.module = context.module;
|
|
13038
|
-
this.syntheticNamespace = syntheticNamespace;
|
|
13039
|
-
}
|
|
13040
|
-
getBaseVariable() {
|
|
13041
|
-
if (this.baseVariable)
|
|
13042
|
-
return this.baseVariable;
|
|
13043
|
-
let baseVariable = this.syntheticNamespace;
|
|
13044
|
-
while (baseVariable instanceof ExportDefaultVariable ||
|
|
13045
|
-
baseVariable instanceof SyntheticNamedExportVariable) {
|
|
13046
|
-
if (baseVariable instanceof ExportDefaultVariable) {
|
|
13047
|
-
const original = baseVariable.getOriginalVariable();
|
|
13048
|
-
if (original === baseVariable)
|
|
13049
|
-
break;
|
|
13050
|
-
baseVariable = original;
|
|
13136
|
+
class ObjectPattern extends NodeBase {
|
|
13137
|
+
addExportedVariables(variables, exportNamesByVariable) {
|
|
13138
|
+
for (const property of this.properties) {
|
|
13139
|
+
if (property.type === parseAst_js.Property) {
|
|
13140
|
+
property.value.addExportedVariables(variables, exportNamesByVariable);
|
|
13051
13141
|
}
|
|
13052
|
-
|
|
13053
|
-
|
|
13142
|
+
else {
|
|
13143
|
+
property.argument.addExportedVariables(variables, exportNamesByVariable);
|
|
13054
13144
|
}
|
|
13055
13145
|
}
|
|
13056
|
-
return (this.baseVariable = baseVariable);
|
|
13057
|
-
}
|
|
13058
|
-
getBaseVariableName() {
|
|
13059
|
-
return this.syntheticNamespace.getBaseVariableName();
|
|
13060
|
-
}
|
|
13061
|
-
getName(getPropertyAccess) {
|
|
13062
|
-
return `${this.syntheticNamespace.getName(getPropertyAccess)}${getPropertyAccess(this.name)}`;
|
|
13063
13146
|
}
|
|
13064
|
-
|
|
13065
|
-
|
|
13066
|
-
|
|
13147
|
+
declare(kind, destructuredInitPath, init) {
|
|
13148
|
+
const variables = [];
|
|
13149
|
+
for (const property of this.properties) {
|
|
13150
|
+
variables.push(...property.declare(kind, destructuredInitPath, init));
|
|
13151
|
+
}
|
|
13152
|
+
return variables;
|
|
13067
13153
|
}
|
|
13068
|
-
|
|
13069
|
-
|
|
13154
|
+
deoptimizeAssignment(destructuredInitPath, init) {
|
|
13155
|
+
for (const property of this.properties) {
|
|
13156
|
+
property.deoptimizeAssignment(destructuredInitPath, init);
|
|
13157
|
+
}
|
|
13070
13158
|
}
|
|
13071
|
-
|
|
13072
|
-
|
|
13073
|
-
|
|
13074
|
-
|
|
13075
|
-
|
|
13076
|
-
|
|
13077
|
-
this.defaultVariableName = '';
|
|
13078
|
-
this.namespaceVariableName = '';
|
|
13079
|
-
this.variableName = '';
|
|
13080
|
-
this.fileName = null;
|
|
13081
|
-
this.importAttributes = null;
|
|
13082
|
-
this.id = module.id;
|
|
13083
|
-
this.moduleInfo = module.info;
|
|
13084
|
-
this.renormalizeRenderPath = module.renormalizeRenderPath;
|
|
13085
|
-
this.suggestedVariableName = module.suggestedVariableName;
|
|
13159
|
+
deoptimizePath(path) {
|
|
13160
|
+
if (path.length === 0) {
|
|
13161
|
+
for (const property of this.properties) {
|
|
13162
|
+
property.deoptimizePath(path);
|
|
13163
|
+
}
|
|
13164
|
+
}
|
|
13086
13165
|
}
|
|
13087
|
-
|
|
13088
|
-
|
|
13166
|
+
hasEffectsOnInteractionAtPath(
|
|
13167
|
+
// At the moment, this is only triggered for assignment left-hand sides,
|
|
13168
|
+
// where the path is empty
|
|
13169
|
+
_path, interaction, context) {
|
|
13170
|
+
for (const property of this.properties) {
|
|
13171
|
+
if (property.hasEffectsOnInteractionAtPath(EMPTY_PATH, interaction, context))
|
|
13172
|
+
return true;
|
|
13173
|
+
}
|
|
13174
|
+
return false;
|
|
13089
13175
|
}
|
|
13090
|
-
|
|
13091
|
-
|
|
13092
|
-
|
|
13176
|
+
hasEffectsWhenDestructuring(context, destructuredInitPath, init) {
|
|
13177
|
+
for (const property of this.properties) {
|
|
13178
|
+
if (property.hasEffectsWhenDestructuring(context, destructuredInitPath, init))
|
|
13179
|
+
return true;
|
|
13093
13180
|
}
|
|
13094
|
-
|
|
13095
|
-
return (this.fileName =
|
|
13096
|
-
(typeof paths === 'function' ? paths(this.id) : paths[this.id]) ||
|
|
13097
|
-
(this.renormalizeRenderPath ? parseAst_js.normalize(path.relative(this.inputBase, this.id)) : this.id));
|
|
13181
|
+
return false;
|
|
13098
13182
|
}
|
|
13099
|
-
|
|
13100
|
-
|
|
13101
|
-
this.
|
|
13102
|
-
|
|
13183
|
+
includeDestructuredIfNecessary(context, destructuredInitPath, init) {
|
|
13184
|
+
if (!this.properties.length)
|
|
13185
|
+
return this.included;
|
|
13186
|
+
const lastProperty = this.properties.at(-1);
|
|
13187
|
+
let included = lastProperty.includeDestructuredIfNecessary(context, destructuredInitPath, init);
|
|
13188
|
+
const lastPropertyIsRestElement = lastProperty.type === parseAst_js.RestElement;
|
|
13189
|
+
for (const property of this.properties.slice(0, -1)) {
|
|
13190
|
+
if (lastPropertyIsRestElement && included && !property.included) {
|
|
13191
|
+
property.includeNode(context);
|
|
13192
|
+
}
|
|
13193
|
+
included =
|
|
13194
|
+
property.includeDestructuredIfNecessary(context, destructuredInitPath, init) || included;
|
|
13195
|
+
}
|
|
13196
|
+
if (!this.included && included) {
|
|
13197
|
+
this.includeNode(context);
|
|
13198
|
+
}
|
|
13199
|
+
return this.included;
|
|
13103
13200
|
}
|
|
13104
|
-
|
|
13105
|
-
|
|
13106
|
-
|
|
13107
|
-
|
|
13201
|
+
markDeclarationReached() {
|
|
13202
|
+
for (const property of this.properties) {
|
|
13203
|
+
property.markDeclarationReached();
|
|
13204
|
+
}
|
|
13108
13205
|
}
|
|
13109
|
-
|
|
13110
|
-
|
|
13111
|
-
|
|
13112
|
-
|
|
13206
|
+
render(code, options) {
|
|
13207
|
+
if (this.properties.length > 0) {
|
|
13208
|
+
const separatedNodes = getCommaSeparatedNodesWithBoundaries(this.properties, code, this.start + 1, this.end - 1);
|
|
13209
|
+
let lastSeparatorPos = null;
|
|
13210
|
+
for (const { node, separator, start, end } of separatedNodes) {
|
|
13211
|
+
if (!node.included) {
|
|
13212
|
+
treeshakeNode(node, code, start, end);
|
|
13213
|
+
continue;
|
|
13214
|
+
}
|
|
13215
|
+
lastSeparatorPos = separator;
|
|
13216
|
+
node.render(code, options);
|
|
13217
|
+
}
|
|
13218
|
+
if (lastSeparatorPos) {
|
|
13219
|
+
code.remove(lastSeparatorPos, this.end - 1);
|
|
13220
|
+
}
|
|
13221
|
+
}
|
|
13113
13222
|
}
|
|
13114
|
-
|
|
13115
|
-
|
|
13116
|
-
|
|
13223
|
+
setAssignedValue(value) {
|
|
13224
|
+
super.setAssignedValue(value);
|
|
13225
|
+
// Destructuring assigns each target only some subpath of the assigned
|
|
13226
|
+
// value, which is not tracked
|
|
13227
|
+
for (const property of this.properties) {
|
|
13228
|
+
property.setAssignedValue(UNKNOWN_EXPRESSION);
|
|
13229
|
+
}
|
|
13117
13230
|
}
|
|
13118
|
-
return null;
|
|
13119
|
-
}
|
|
13120
|
-
|
|
13121
|
-
function removeJsExtension(name) {
|
|
13122
|
-
return name.endsWith('.js') ? name.slice(0, -3) : name;
|
|
13123
13231
|
}
|
|
13232
|
+
ObjectPattern.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
|
|
13233
|
+
ObjectPattern.prototype.applyDeoptimizations = doNotDeoptimize;
|
|
13124
13234
|
|
|
13125
|
-
|
|
13126
|
-
|
|
13127
|
-
|
|
13235
|
+
class VariableDeclaration extends NodeBase {
|
|
13236
|
+
addExportedVariables(variables, exportNamesByVariable) {
|
|
13237
|
+
// Only `var` is hoisted to the surrounding scope, so only those bindings can
|
|
13238
|
+
// be the exported ones. `let` and `const` in a loop head are new bindings.
|
|
13239
|
+
if (this.kind !== 'var')
|
|
13240
|
+
return;
|
|
13241
|
+
for (const declarator of this.declarations) {
|
|
13242
|
+
declarator.id.addExportedVariables(variables, exportNamesByVariable);
|
|
13243
|
+
}
|
|
13128
13244
|
}
|
|
13129
|
-
|
|
13130
|
-
|
|
13131
|
-
|
|
13132
|
-
|
|
13133
|
-
const { _, getFunctionIntro, getPropertyAccess, n, s } = snippets;
|
|
13134
|
-
if (!namedExportsMode) {
|
|
13135
|
-
return `${n}${n}${mechanism}${getSingleDefaultExport(exports, dependencies, interop, externalLiveBindings, getPropertyAccess)};`;
|
|
13245
|
+
deoptimizePath() {
|
|
13246
|
+
for (const declarator of this.declarations) {
|
|
13247
|
+
declarator.deoptimizePath(EMPTY_PATH);
|
|
13248
|
+
}
|
|
13136
13249
|
}
|
|
13137
|
-
|
|
13138
|
-
|
|
13139
|
-
|
|
13140
|
-
|
|
13141
|
-
|
|
13250
|
+
hasEffectsOnInteractionAtPath() {
|
|
13251
|
+
return false;
|
|
13252
|
+
}
|
|
13253
|
+
include(context, includeChildrenRecursively, { asSingleStatement } = parseAst_js.BLANK) {
|
|
13254
|
+
this.included = true;
|
|
13255
|
+
for (const declarator of this.declarations) {
|
|
13256
|
+
if (includeChildrenRecursively || declarator.shouldBeIncluded(context)) {
|
|
13257
|
+
declarator.include(context, includeChildrenRecursively);
|
|
13142
13258
|
}
|
|
13143
|
-
|
|
13144
|
-
|
|
13145
|
-
|
|
13146
|
-
if (exportBlock)
|
|
13147
|
-
exportBlock += n;
|
|
13148
|
-
if (specifier.imported !== '*' && specifier.needsLiveBinding) {
|
|
13149
|
-
exportBlock += `Object.defineProperty(exports,${_}${JSON.stringify(unescapeExportName(specifier.reexported))},${_}${getGetter(importName, false, t, snippets)});`;
|
|
13150
|
-
}
|
|
13151
|
-
else if (specifier.reexported === '__proto__') {
|
|
13152
|
-
exportBlock +=
|
|
13153
|
-
`Object.defineProperty(exports,${_}"__proto__",${_}{${n}` +
|
|
13154
|
-
`${t}enumerable:${_}true,${n}` +
|
|
13155
|
-
`${t}value:${_}${importName}${n}});`;
|
|
13156
|
-
}
|
|
13157
|
-
else {
|
|
13158
|
-
exportBlock += `exports${getPropertyAccess(unescapeExportName(specifier.reexported))}${_}=${_}${importName};`;
|
|
13159
|
-
}
|
|
13160
|
-
}
|
|
13259
|
+
const { id, init } = declarator;
|
|
13260
|
+
if (asSingleStatement) {
|
|
13261
|
+
id.include(context, includeChildrenRecursively);
|
|
13161
13262
|
}
|
|
13162
|
-
|
|
13163
|
-
|
|
13164
|
-
|
|
13165
|
-
|
|
13166
|
-
|
|
13263
|
+
if (init &&
|
|
13264
|
+
id.included &&
|
|
13265
|
+
!init.included &&
|
|
13266
|
+
(id instanceof ObjectPattern || id instanceof ArrayPattern)) {
|
|
13267
|
+
init.include(context, includeChildrenRecursively);
|
|
13268
|
+
}
|
|
13269
|
+
}
|
|
13270
|
+
}
|
|
13271
|
+
initialise() {
|
|
13272
|
+
super.initialise();
|
|
13273
|
+
if (this.kind === 'await using')
|
|
13274
|
+
markTopLevelAwait(this);
|
|
13275
|
+
for (const declarator of this.declarations) {
|
|
13276
|
+
declarator.declareDeclarator(this.kind);
|
|
13277
|
+
}
|
|
13278
|
+
}
|
|
13279
|
+
removeAnnotations(code) {
|
|
13280
|
+
this.declarations[0].removeAnnotations(code);
|
|
13281
|
+
}
|
|
13282
|
+
render(code, options, nodeRenderOptions = parseAst_js.BLANK) {
|
|
13283
|
+
// A `var` declaration can be the body of a for-in/of loop. Only the
|
|
13284
|
+
// left-hand side is a loop head. Rewriting that head as a statement
|
|
13285
|
+
// inserts a semicolon and turns `for (var name of ...)` into invalid code.
|
|
13286
|
+
// Exported `var` bindings are updated from the loop body instead.
|
|
13287
|
+
if (this.isForInOfHead()) {
|
|
13288
|
+
this.renderForInOfHead(code, options);
|
|
13289
|
+
return;
|
|
13290
|
+
}
|
|
13291
|
+
if (this.areAllDeclarationsIncludedAndNotExported(options.exportNamesByVariable)) {
|
|
13292
|
+
for (const declarator of this.declarations) {
|
|
13293
|
+
declarator.render(code, options);
|
|
13294
|
+
}
|
|
13295
|
+
if (!nodeRenderOptions.isNoStatement &&
|
|
13296
|
+
code.original.charCodeAt(this.end - 1) !== 59 /*";"*/) {
|
|
13297
|
+
code.appendLeft(this.end, ';');
|
|
13298
|
+
}
|
|
13299
|
+
}
|
|
13300
|
+
else if (this.isInSingleStatementPosition()) {
|
|
13301
|
+
this.renderSingleStatementDeclaration(code, options, nodeRenderOptions.isNoStatement === true);
|
|
13302
|
+
}
|
|
13303
|
+
else {
|
|
13304
|
+
this.renderReplacedDeclarations(code, options, nodeRenderOptions.isNoStatement === true);
|
|
13305
|
+
}
|
|
13306
|
+
}
|
|
13307
|
+
isForInOfHead() {
|
|
13308
|
+
const parent = this.parent;
|
|
13309
|
+
return ((parent.type === parseAst_js.ForOfStatement || parent.type === parseAst_js.ForInStatement) &&
|
|
13310
|
+
parent.left === this);
|
|
13311
|
+
}
|
|
13312
|
+
isInSingleStatementPosition() {
|
|
13313
|
+
const { type } = this.parent;
|
|
13314
|
+
return !(type === parseAst_js.Program ||
|
|
13315
|
+
type === parseAst_js.BlockStatement ||
|
|
13316
|
+
type === parseAst_js.StaticBlock ||
|
|
13317
|
+
type === parseAst_js.SwitchCase ||
|
|
13318
|
+
type === parseAst_js.ExportNamedDeclaration);
|
|
13319
|
+
}
|
|
13320
|
+
renderForInOfHead(code, options) {
|
|
13321
|
+
const declarator = this.declarations[0];
|
|
13322
|
+
if (declarator.id instanceof Identifier &&
|
|
13323
|
+
isDeclaredWithoutBinding(declarator.id.variable, options.exportNamesByVariable)) {
|
|
13324
|
+
// `for (var name of xs)` declares `name`, but a reassigned export is
|
|
13325
|
+
// rendered as `exports.name`, and a catch parameter shadowing one must
|
|
13326
|
+
// stay an assignment. Keeping `var`, or synthesizing `= void 0` because
|
|
13327
|
+
// the declarator has no initializer, is a syntax error.
|
|
13328
|
+
code.remove(this.start, declarator.id.start);
|
|
13329
|
+
declarator.id.render(code, options);
|
|
13330
|
+
return;
|
|
13331
|
+
}
|
|
13332
|
+
for (const eachDeclarator of this.declarations) {
|
|
13333
|
+
eachDeclarator.render(code, options);
|
|
13334
|
+
}
|
|
13335
|
+
}
|
|
13336
|
+
renderDeclarationEnd(code, separatorString, lastSeparatorPos, actualContentEnd, renderedContentEnd, systemPatternExports, options, omitTrailingSemicolon) {
|
|
13337
|
+
if (code.original.charCodeAt(this.end - 1) === 59 /*";"*/) {
|
|
13338
|
+
code.remove(this.end - 1, this.end);
|
|
13339
|
+
}
|
|
13340
|
+
// A for-loop initializer is not a statement. The separator after it
|
|
13341
|
+
// belongs to the for statement, so another semicolon makes the head invalid.
|
|
13342
|
+
if (!omitTrailingSemicolon) {
|
|
13343
|
+
separatorString += ';';
|
|
13344
|
+
}
|
|
13345
|
+
if (lastSeparatorPos === null) {
|
|
13346
|
+
if (separatorString) {
|
|
13347
|
+
code.appendLeft(renderedContentEnd, separatorString);
|
|
13348
|
+
}
|
|
13349
|
+
}
|
|
13350
|
+
else {
|
|
13351
|
+
if (code.original.charCodeAt(actualContentEnd - 1) === 10 /*"\n"*/ &&
|
|
13352
|
+
(code.original.charCodeAt(this.end) === 10 /*"\n"*/ ||
|
|
13353
|
+
code.original.charCodeAt(this.end) === 13) /*"\r"*/) {
|
|
13354
|
+
actualContentEnd--;
|
|
13355
|
+
if (code.original.charCodeAt(actualContentEnd) === 13 /*"\r"*/) {
|
|
13356
|
+
actualContentEnd--;
|
|
13357
|
+
}
|
|
13358
|
+
}
|
|
13359
|
+
if (actualContentEnd === lastSeparatorPos + 1) {
|
|
13360
|
+
code.overwrite(lastSeparatorPos, renderedContentEnd, separatorString);
|
|
13361
|
+
}
|
|
13362
|
+
else {
|
|
13363
|
+
code.overwrite(lastSeparatorPos, lastSeparatorPos + 1, separatorString);
|
|
13364
|
+
code.remove(actualContentEnd, renderedContentEnd);
|
|
13365
|
+
}
|
|
13366
|
+
}
|
|
13367
|
+
if (systemPatternExports.length > 0) {
|
|
13368
|
+
code.appendLeft(renderedContentEnd, ` ${getSystemExportStatement(systemPatternExports, options)};`);
|
|
13369
|
+
}
|
|
13370
|
+
}
|
|
13371
|
+
renderReplacedDeclarations(code, options, omitTrailingSemicolon) {
|
|
13372
|
+
const separatedNodes = getCommaSeparatedNodesWithBoundaries(this.declarations, code, this.start + this.kind.length, this.end - (code.original.charCodeAt(this.end - 1) === 59 /*";"*/ ? 1 : 0));
|
|
13373
|
+
let actualContentEnd, renderedContentEnd;
|
|
13374
|
+
renderedContentEnd = findNonWhiteSpace(code.original, this.start + this.kind.length);
|
|
13375
|
+
let lastSeparatorPos = renderedContentEnd - 1;
|
|
13376
|
+
code.remove(this.start, lastSeparatorPos);
|
|
13377
|
+
let isInDeclaration = false;
|
|
13378
|
+
let hasRenderedContent = false;
|
|
13379
|
+
let separatorString = '', leadingString, nextSeparatorString;
|
|
13380
|
+
const aggregatedSystemExports = [];
|
|
13381
|
+
const singleSystemExport = gatherSystemExportsAndGetSingleExport(separatedNodes, options, aggregatedSystemExports);
|
|
13382
|
+
const { exportNamesByVariable } = options;
|
|
13383
|
+
for (const { node, start, separator, contentEnd, end } of separatedNodes) {
|
|
13384
|
+
if (!node.included) {
|
|
13385
|
+
treeshakeNode(node, code, start, end);
|
|
13386
|
+
continue;
|
|
13387
|
+
}
|
|
13388
|
+
node.render(code, options);
|
|
13389
|
+
leadingString = '';
|
|
13390
|
+
nextSeparatorString = '';
|
|
13391
|
+
const rendersAsAssignment = !node.id.included ||
|
|
13392
|
+
(node.id instanceof Identifier &&
|
|
13393
|
+
isDeclaredWithoutBinding(node.id.variable, exportNamesByVariable));
|
|
13394
|
+
if (rendersAsAssignment) {
|
|
13395
|
+
if (hasRenderedContent) {
|
|
13396
|
+
separatorString += ';';
|
|
13397
|
+
}
|
|
13398
|
+
isInDeclaration = false;
|
|
13399
|
+
}
|
|
13400
|
+
else {
|
|
13401
|
+
if (singleSystemExport && singleSystemExport === node.id.variable) {
|
|
13402
|
+
const operatorPos = findFirstOccurrenceOutsideComment(code.original, '=', node.id.end);
|
|
13403
|
+
renderSystemExportExpression(singleSystemExport, findNonWhiteSpace(code.original, operatorPos + 1), separator === null ? contentEnd : separator, code, options);
|
|
13404
|
+
}
|
|
13405
|
+
if (isInDeclaration) {
|
|
13406
|
+
separatorString += ',';
|
|
13407
|
+
}
|
|
13408
|
+
else {
|
|
13409
|
+
if (hasRenderedContent) {
|
|
13410
|
+
separatorString += ';';
|
|
13411
|
+
}
|
|
13412
|
+
leadingString += `${this.kind} `;
|
|
13413
|
+
isInDeclaration = true;
|
|
13414
|
+
}
|
|
13415
|
+
}
|
|
13416
|
+
if (renderedContentEnd === lastSeparatorPos + 1) {
|
|
13417
|
+
code.overwrite(lastSeparatorPos, renderedContentEnd, separatorString + leadingString);
|
|
13418
|
+
}
|
|
13419
|
+
else {
|
|
13420
|
+
code.overwrite(lastSeparatorPos, lastSeparatorPos + 1, separatorString);
|
|
13421
|
+
code.appendLeft(renderedContentEnd, leadingString);
|
|
13422
|
+
}
|
|
13423
|
+
actualContentEnd = contentEnd;
|
|
13424
|
+
renderedContentEnd = end;
|
|
13425
|
+
hasRenderedContent = true;
|
|
13426
|
+
lastSeparatorPos = separator;
|
|
13427
|
+
separatorString = nextSeparatorString;
|
|
13428
|
+
}
|
|
13429
|
+
this.renderDeclarationEnd(code, separatorString, lastSeparatorPos, actualContentEnd, renderedContentEnd, aggregatedSystemExports, options, omitTrailingSemicolon);
|
|
13430
|
+
}
|
|
13431
|
+
renderSingleStatementDeclaration(code, options, omitTrailingSemicolon) {
|
|
13432
|
+
const separatedNodes = getCommaSeparatedNodesWithBoundaries(this.declarations, code, this.start + this.kind.length, this.end - (code.original.charCodeAt(this.end - 1) === 59 /*";"*/ ? 1 : 0));
|
|
13433
|
+
let actualContentEnd, renderedContentEnd;
|
|
13434
|
+
renderedContentEnd = findNonWhiteSpace(code.original, this.start + this.kind.length);
|
|
13435
|
+
let lastSeparatorPos = renderedContentEnd - 1;
|
|
13436
|
+
code.remove(this.start, lastSeparatorPos);
|
|
13437
|
+
let hasRenderedContent = false;
|
|
13438
|
+
let lastRenderedContentEnd = renderedContentEnd;
|
|
13439
|
+
let separatorString = '';
|
|
13440
|
+
const trailingSystemExports = [];
|
|
13441
|
+
const { exportNamesByVariable, snippets: { _, getPropertyAccess } } = options;
|
|
13442
|
+
for (const { node, start, separator, contentEnd, end } of separatedNodes) {
|
|
13443
|
+
if (!node.included) {
|
|
13444
|
+
treeshakeNode(node, code, start, end);
|
|
13445
|
+
continue;
|
|
13446
|
+
}
|
|
13447
|
+
node.render(code, options);
|
|
13448
|
+
if (options.format === 'system') {
|
|
13449
|
+
this.renderSingleStatementSystemExports(node, separator, contentEnd, code, options, trailingSystemExports);
|
|
13450
|
+
}
|
|
13451
|
+
let leadingString = '';
|
|
13452
|
+
const rendersAsAssignment = node.id instanceof Identifier &&
|
|
13453
|
+
isDeclaredWithoutBinding(node.id.variable, exportNamesByVariable);
|
|
13454
|
+
if (hasRenderedContent) {
|
|
13455
|
+
separatorString = ',';
|
|
13456
|
+
}
|
|
13457
|
+
else if (!rendersAsAssignment) {
|
|
13458
|
+
leadingString = `${this.kind} `;
|
|
13459
|
+
}
|
|
13460
|
+
if (renderedContentEnd === lastSeparatorPos + 1) {
|
|
13461
|
+
code.overwrite(lastSeparatorPos, renderedContentEnd, separatorString + leadingString);
|
|
13462
|
+
}
|
|
13463
|
+
else {
|
|
13464
|
+
code.overwrite(lastSeparatorPos, lastSeparatorPos + 1, separatorString);
|
|
13465
|
+
code.appendLeft(renderedContentEnd, leadingString);
|
|
13466
|
+
}
|
|
13467
|
+
actualContentEnd = contentEnd;
|
|
13468
|
+
renderedContentEnd = end;
|
|
13469
|
+
lastRenderedContentEnd = separator === null ? contentEnd : separator;
|
|
13470
|
+
hasRenderedContent = true;
|
|
13471
|
+
lastSeparatorPos = separator;
|
|
13472
|
+
separatorString = '';
|
|
13473
|
+
}
|
|
13474
|
+
if (trailingSystemExports.length > 0) {
|
|
13475
|
+
const name = trailingSystemExports[0].getName(getPropertyAccess);
|
|
13476
|
+
code.appendLeft(lastRenderedContentEnd, `,${_}${name}${_}=${_}(${getSystemExportStatement(trailingSystemExports, options)},${_}${name})`);
|
|
13477
|
+
}
|
|
13478
|
+
this.renderDeclarationEnd(code, separatorString, lastSeparatorPos, actualContentEnd, renderedContentEnd, [], options, omitTrailingSemicolon);
|
|
13479
|
+
}
|
|
13480
|
+
renderSingleStatementSystemExports(node, separator, contentEnd, code, options, trailingSystemExports) {
|
|
13481
|
+
const { exportNamesByVariable } = options;
|
|
13482
|
+
if (node.id instanceof Identifier) {
|
|
13483
|
+
const variable = node.id.variable;
|
|
13484
|
+
const exportNames = exportNamesByVariable.get(variable);
|
|
13485
|
+
if (!node.init || !exportNames)
|
|
13486
|
+
return;
|
|
13487
|
+
if (exportNames.length === 1) {
|
|
13488
|
+
const operatorPos = findFirstOccurrenceOutsideComment(code.original, '=', node.id.end);
|
|
13489
|
+
renderSystemExportExpression(variable, findNonWhiteSpace(code.original, operatorPos + 1), separator === null ? contentEnd : separator, code, options);
|
|
13490
|
+
}
|
|
13491
|
+
else {
|
|
13492
|
+
trailingSystemExports.push(variable);
|
|
13493
|
+
}
|
|
13494
|
+
}
|
|
13495
|
+
else {
|
|
13496
|
+
node.id.addExportedVariables(trailingSystemExports, exportNamesByVariable);
|
|
13497
|
+
}
|
|
13498
|
+
}
|
|
13499
|
+
areAllDeclarationsIncludedAndNotExported(exportNamesByVariable) {
|
|
13500
|
+
if (this.kind === 'await using' || this.kind === 'using') {
|
|
13501
|
+
return true;
|
|
13502
|
+
}
|
|
13503
|
+
for (const declarator of this.declarations) {
|
|
13504
|
+
if (!declarator.id.included)
|
|
13505
|
+
return false;
|
|
13506
|
+
if (declarator.id.type === parseAst_js.Identifier) {
|
|
13507
|
+
if (exportNamesByVariable.has(declarator.id.variable) ||
|
|
13508
|
+
isDeclaredWithoutBinding(declarator.id.variable, exportNamesByVariable)) {
|
|
13509
|
+
return false;
|
|
13510
|
+
}
|
|
13511
|
+
}
|
|
13512
|
+
else {
|
|
13513
|
+
const exportedVariables = [];
|
|
13514
|
+
declarator.id.addExportedVariables(exportedVariables, exportNamesByVariable);
|
|
13515
|
+
if (exportedVariables.length > 0)
|
|
13516
|
+
return false;
|
|
13517
|
+
}
|
|
13518
|
+
}
|
|
13519
|
+
return true;
|
|
13520
|
+
}
|
|
13521
|
+
}
|
|
13522
|
+
function gatherSystemExportsAndGetSingleExport(separatedNodes, options, aggregatedSystemExports) {
|
|
13523
|
+
let singleSystemExport = null;
|
|
13524
|
+
if (options.format === 'system') {
|
|
13525
|
+
for (const { node } of separatedNodes) {
|
|
13526
|
+
if (node.id instanceof Identifier &&
|
|
13527
|
+
node.init &&
|
|
13528
|
+
aggregatedSystemExports.length === 0 &&
|
|
13529
|
+
options.exportNamesByVariable.get(node.id.variable)?.length === 1) {
|
|
13530
|
+
singleSystemExport = node.id.variable;
|
|
13531
|
+
aggregatedSystemExports.push(singleSystemExport);
|
|
13532
|
+
}
|
|
13533
|
+
else {
|
|
13534
|
+
node.id.addExportedVariables(aggregatedSystemExports, options.exportNamesByVariable);
|
|
13535
|
+
}
|
|
13536
|
+
}
|
|
13537
|
+
if (aggregatedSystemExports.length > 1) {
|
|
13538
|
+
singleSystemExport = null;
|
|
13539
|
+
}
|
|
13540
|
+
else if (singleSystemExport) {
|
|
13541
|
+
aggregatedSystemExports.length = 0;
|
|
13542
|
+
}
|
|
13543
|
+
}
|
|
13544
|
+
return singleSystemExport;
|
|
13545
|
+
}
|
|
13546
|
+
VariableDeclaration.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
|
|
13547
|
+
VariableDeclaration.prototype.applyDeoptimizations = doNotDeoptimize;
|
|
13548
|
+
|
|
13549
|
+
class ClassExpression extends ClassNode {
|
|
13550
|
+
render(code, options, { renderedSurroundingElement } = parseAst_js.BLANK) {
|
|
13551
|
+
super.render(code, options);
|
|
13552
|
+
if (renderedSurroundingElement === parseAst_js.ExpressionStatement) {
|
|
13553
|
+
code.appendRight(this.start, '(');
|
|
13554
|
+
code.prependLeft(this.end, ')');
|
|
13555
|
+
}
|
|
13556
|
+
}
|
|
13557
|
+
}
|
|
13558
|
+
|
|
13559
|
+
class VariableDeclarator extends NodeBase {
|
|
13560
|
+
declareDeclarator(kind) {
|
|
13561
|
+
this.isUsingDeclaration = kind === 'using';
|
|
13562
|
+
this.isAsyncUsingDeclaration = kind === 'await using';
|
|
13563
|
+
this.id.declare(kind, EMPTY_PATH, this.init || UNDEFINED_EXPRESSION);
|
|
13564
|
+
}
|
|
13565
|
+
deoptimizePath(path) {
|
|
13566
|
+
this.id.deoptimizePath(path);
|
|
13567
|
+
}
|
|
13568
|
+
deoptimizeCache() {
|
|
13569
|
+
if (!this.hasDeoptimizedDisposal && this.init) {
|
|
13570
|
+
this.hasDeoptimizedDisposal = true;
|
|
13571
|
+
this.init.deoptimizePath(UNKNOWN_PATH);
|
|
13572
|
+
this.init.includePath(UNKNOWN_PATH, createInclusionContext());
|
|
13573
|
+
this.scope.context.requestTreeshakingPass();
|
|
13574
|
+
}
|
|
13575
|
+
}
|
|
13576
|
+
hasEffects(context) {
|
|
13577
|
+
const initEffect = this.init?.hasEffects(context);
|
|
13578
|
+
this.id.markDeclarationReached();
|
|
13579
|
+
return (initEffect ||
|
|
13580
|
+
this.isUsingDeclaration ||
|
|
13581
|
+
this.isAsyncUsingDeclaration ||
|
|
13582
|
+
this.id.hasEffects(context) ||
|
|
13583
|
+
(this.scope.context.options.treeshake
|
|
13584
|
+
.propertyReadSideEffects &&
|
|
13585
|
+
this.id.hasEffectsWhenDestructuring(context, EMPTY_PATH, this.init || UNDEFINED_EXPRESSION)));
|
|
13586
|
+
}
|
|
13587
|
+
include(context, includeChildrenRecursively) {
|
|
13588
|
+
const { id, init } = this;
|
|
13589
|
+
if (!this.included)
|
|
13590
|
+
this.includeNode(context);
|
|
13591
|
+
const { disposalCall, disposalFunction } = this;
|
|
13592
|
+
// Before including init so that newly included receiver paths are included in this pass
|
|
13593
|
+
if (disposalFunction && disposalCall) {
|
|
13594
|
+
disposalFunction.includeCallArgumentsWhenCalledAtPath(EMPTY_PATH, disposalCall, context);
|
|
13595
|
+
}
|
|
13596
|
+
init?.include(context, includeChildrenRecursively);
|
|
13597
|
+
id.markDeclarationReached();
|
|
13598
|
+
if (includeChildrenRecursively) {
|
|
13599
|
+
id.include(context, includeChildrenRecursively);
|
|
13600
|
+
}
|
|
13601
|
+
else {
|
|
13602
|
+
id.includeDestructuredIfNecessary(context, EMPTY_PATH, init || UNDEFINED_EXPRESSION);
|
|
13603
|
+
}
|
|
13604
|
+
}
|
|
13605
|
+
removeAnnotations(code) {
|
|
13606
|
+
this.init?.removeAnnotations(code);
|
|
13607
|
+
}
|
|
13608
|
+
render(code, options) {
|
|
13609
|
+
const { exportNamesByVariable, snippets: { _, getPropertyAccess } } = options;
|
|
13610
|
+
const { end, id, init, start } = this;
|
|
13611
|
+
const renderId = id.included || this.isUsingDeclaration || this.isAsyncUsingDeclaration;
|
|
13612
|
+
if (renderId) {
|
|
13613
|
+
id.render(code, options);
|
|
13614
|
+
}
|
|
13615
|
+
else {
|
|
13616
|
+
const operatorPos = findFirstOccurrenceOutsideComment(code.original, '=', id.end);
|
|
13617
|
+
code.remove(start, findNonWhiteSpace(code.original, operatorPos + 1));
|
|
13618
|
+
}
|
|
13619
|
+
if (init) {
|
|
13620
|
+
if (id instanceof Identifier && init instanceof ClassExpression && !init.id) {
|
|
13621
|
+
const renderedVariable = id.variable.getName(getPropertyAccess);
|
|
13622
|
+
if (renderedVariable !== id.name) {
|
|
13623
|
+
code.appendLeft(init.start + 5, ` ${id.name}`);
|
|
13624
|
+
}
|
|
13625
|
+
}
|
|
13626
|
+
init.render(code, options, renderId ? parseAst_js.BLANK : { renderedSurroundingElement: parseAst_js.ExpressionStatement });
|
|
13627
|
+
}
|
|
13628
|
+
else if (id instanceof Identifier &&
|
|
13629
|
+
isReassignedExportsMember(id.variable, exportNamesByVariable)) {
|
|
13630
|
+
code.appendLeft(end, `${_}=${_}void 0`);
|
|
13631
|
+
}
|
|
13632
|
+
}
|
|
13633
|
+
includeNode(context) {
|
|
13634
|
+
this.included = true;
|
|
13635
|
+
const { id, init } = this;
|
|
13636
|
+
if (init) {
|
|
13637
|
+
if (this.isUsingDeclaration || this.isAsyncUsingDeclaration) {
|
|
13638
|
+
const disposalInteractions = {
|
|
13639
|
+
access: { args: [init], type: INTERACTION_ACCESSED },
|
|
13640
|
+
call: { args: [init], type: INTERACTION_CALLED, withNew: false }
|
|
13641
|
+
};
|
|
13642
|
+
if (this.isUsingDeclaration ||
|
|
13643
|
+
!this.includeDisposalMethodAndCheckIfKnownFunction(init, SYMBOL_ASYNC_DISPOSE_PATH, disposalInteractions, context)) {
|
|
13644
|
+
this.includeDisposalMethodAndCheckIfKnownFunction(init, SYMBOL_DISPOSE_PATH, disposalInteractions, context);
|
|
13645
|
+
}
|
|
13646
|
+
this.scope.context.requestTreeshakingPass();
|
|
13647
|
+
}
|
|
13648
|
+
if (id instanceof Identifier && init instanceof ClassExpression && !init.id) {
|
|
13649
|
+
const { name, variable } = id;
|
|
13650
|
+
for (const accessedVariable of init.scope.accessedOutsideVariables.values()) {
|
|
13651
|
+
if (accessedVariable !== variable) {
|
|
13652
|
+
accessedVariable.forbidName(name);
|
|
13653
|
+
}
|
|
13654
|
+
}
|
|
13655
|
+
}
|
|
13656
|
+
}
|
|
13657
|
+
}
|
|
13658
|
+
includeDisposalMethodAndCheckIfKnownFunction(init, path, { access, call }, context) {
|
|
13659
|
+
init.deoptimizeArgumentsOnInteractionAtPath(access, path, SHARED_RECURSION_TRACKER);
|
|
13660
|
+
const disposalFunction = init.getKnownFunctionAtPath(path, SHARED_RECURSION_TRACKER, this);
|
|
13661
|
+
init.includePath(path, context);
|
|
13662
|
+
if (!disposalFunction) {
|
|
13663
|
+
const disposalValue = init.getLiteralValueAtPath(path, SHARED_RECURSION_TRACKER, this);
|
|
13664
|
+
if (disposalValue !== null && disposalValue !== undefined) {
|
|
13665
|
+
init.deoptimizeArgumentsOnInteractionAtPath(call, path, SHARED_RECURSION_TRACKER);
|
|
13666
|
+
init.includeCallArgumentsWhenCalledAtPath(path, call, context);
|
|
13667
|
+
}
|
|
13668
|
+
return false;
|
|
13669
|
+
}
|
|
13670
|
+
this.disposalFunction = disposalFunction;
|
|
13671
|
+
this.disposalCall = call;
|
|
13672
|
+
disposalFunction.deoptimizeArgumentsOnInteractionAtPath(call, EMPTY_PATH, SHARED_RECURSION_TRACKER);
|
|
13673
|
+
return true;
|
|
13674
|
+
}
|
|
13675
|
+
}
|
|
13676
|
+
VariableDeclarator.prototype.applyDeoptimizations = doNotDeoptimize;
|
|
13677
|
+
const SYMBOL_DISPOSE_PATH = [SymbolDispose];
|
|
13678
|
+
const SYMBOL_ASYNC_DISPOSE_PATH = [SymbolAsyncDispose];
|
|
13679
|
+
|
|
13680
|
+
class NamespaceVariable extends Variable {
|
|
13681
|
+
constructor(context) {
|
|
13682
|
+
super(context.getModuleName());
|
|
13683
|
+
this.areAllMembersDeoptimized = false;
|
|
13684
|
+
this.mergedNamespaces = [];
|
|
13685
|
+
this.nonExplicitNamespacesIncluded = false;
|
|
13686
|
+
this.referencedEarly = false;
|
|
13687
|
+
this.references = [];
|
|
13688
|
+
this.context = context;
|
|
13689
|
+
this.module = context.module;
|
|
13690
|
+
}
|
|
13691
|
+
addReference(identifier) {
|
|
13692
|
+
this.references.push(identifier);
|
|
13693
|
+
this.name = identifier.name;
|
|
13694
|
+
}
|
|
13695
|
+
deoptimizeArgumentsOnInteractionAtPath(interaction, path, recursionTracker) {
|
|
13696
|
+
if (path.length > 1 || (path.length === 1 && interaction.type === INTERACTION_CALLED)) {
|
|
13697
|
+
const key = path[0];
|
|
13698
|
+
if (typeof key === 'string') {
|
|
13699
|
+
this.getMemberVariable(key)?.deoptimizeArgumentsOnInteractionAtPath(interaction, path.slice(1), recursionTracker);
|
|
13700
|
+
}
|
|
13701
|
+
else {
|
|
13702
|
+
deoptimizeInteraction(interaction);
|
|
13703
|
+
}
|
|
13704
|
+
}
|
|
13705
|
+
}
|
|
13706
|
+
deoptimizePath(path) {
|
|
13707
|
+
if (path.length > 1) {
|
|
13708
|
+
const key = path[0];
|
|
13709
|
+
if (typeof key === 'string') {
|
|
13710
|
+
this.getMemberVariable(key)?.deoptimizePath(path.slice(1));
|
|
13711
|
+
}
|
|
13712
|
+
else if (!this.areAllMembersDeoptimized) {
|
|
13713
|
+
this.areAllMembersDeoptimized = true;
|
|
13714
|
+
for (const variable of this.module.getExportedVariablesByName().values()) {
|
|
13715
|
+
variable.deoptimizePath(UNKNOWN_PATH);
|
|
13716
|
+
}
|
|
13717
|
+
}
|
|
13718
|
+
}
|
|
13719
|
+
}
|
|
13720
|
+
getLiteralValueAtPath(path) {
|
|
13721
|
+
if (path[0] === SymbolToStringTag) {
|
|
13722
|
+
return 'Module';
|
|
13723
|
+
}
|
|
13724
|
+
return UnknownValue;
|
|
13725
|
+
}
|
|
13726
|
+
hasEffectsOnInteractionAtPath(path, interaction, context) {
|
|
13727
|
+
const { type } = interaction;
|
|
13728
|
+
if (path.length === 0) {
|
|
13729
|
+
// This can only be a call anyway
|
|
13730
|
+
return true;
|
|
13731
|
+
}
|
|
13732
|
+
if (path.length === 1 && type !== INTERACTION_CALLED) {
|
|
13733
|
+
return type === INTERACTION_ASSIGNED;
|
|
13734
|
+
}
|
|
13735
|
+
const key = path[0];
|
|
13736
|
+
if (typeof key !== 'string') {
|
|
13737
|
+
return true;
|
|
13738
|
+
}
|
|
13739
|
+
const memberVariable = this.getMemberVariable(key);
|
|
13740
|
+
return (!memberVariable ||
|
|
13741
|
+
memberVariable.hasEffectsOnInteractionAtPath(path.slice(1), interaction, context));
|
|
13742
|
+
}
|
|
13743
|
+
includePath(path, context) {
|
|
13744
|
+
super.includePath(path, context);
|
|
13745
|
+
this.includeMemberPath(path, context);
|
|
13746
|
+
}
|
|
13747
|
+
includeMemberPath(path, context) {
|
|
13748
|
+
if (path.length > 0) {
|
|
13749
|
+
const [name, ...remainingPath] = path;
|
|
13750
|
+
if (typeof name === 'string') {
|
|
13751
|
+
const variable = this.getMemberVariable(name);
|
|
13752
|
+
if (variable) {
|
|
13753
|
+
this.context.includeVariableInModule(variable, remainingPath, context);
|
|
13754
|
+
}
|
|
13755
|
+
else {
|
|
13756
|
+
this.includeNonExplicitNamespaces();
|
|
13757
|
+
}
|
|
13758
|
+
}
|
|
13759
|
+
else if (name) {
|
|
13760
|
+
this.module.includeAllExports();
|
|
13761
|
+
this.includeNonExplicitNamespaces();
|
|
13762
|
+
}
|
|
13763
|
+
}
|
|
13764
|
+
}
|
|
13765
|
+
prepare(accessedGlobalsByScope) {
|
|
13766
|
+
if (this.mergedNamespaces.length > 0) {
|
|
13767
|
+
this.module.scope.addAccessedGlobals([MERGE_NAMESPACES_VARIABLE], accessedGlobalsByScope);
|
|
13768
|
+
}
|
|
13769
|
+
}
|
|
13770
|
+
renderBlock(options) {
|
|
13771
|
+
const { exportNamesByVariable, format, freeze, indent: t, symbols, snippets: { _, cnst, getObject, getPropertyAccess, n, s } } = options;
|
|
13772
|
+
const memberVariables = this.module.getExportedVariablesByName();
|
|
13773
|
+
const members = [...memberVariables.entries()]
|
|
13774
|
+
.filter(([name, variable]) => !isNamespaceExportName(name) && variable.included)
|
|
13775
|
+
.map(([name, variable]) => {
|
|
13776
|
+
const key = unescapeExportName(name);
|
|
13777
|
+
if (this.referencedEarly ||
|
|
13778
|
+
variable.isReassigned ||
|
|
13779
|
+
variable === this ||
|
|
13780
|
+
(variable.module &&
|
|
13781
|
+
!variable.module.info.isExternal &&
|
|
13782
|
+
variable.module.execIndex > this.module.execIndex)) {
|
|
13783
|
+
return [
|
|
13784
|
+
null,
|
|
13785
|
+
`get ${stringifyObjectKeyIfNeeded(key)}${_}()${_}{${_}return ${variable.getName(getPropertyAccess)}${s}${_}}`
|
|
13786
|
+
];
|
|
13787
|
+
}
|
|
13788
|
+
return [key, variable.getName(getPropertyAccess)];
|
|
13789
|
+
});
|
|
13790
|
+
members.unshift([null, `__proto__:${_}null`]);
|
|
13791
|
+
let output = getObject(members, { lineBreakIndent: { base: '', t } });
|
|
13792
|
+
if (this.mergedNamespaces.length > 0) {
|
|
13793
|
+
const assignmentArguments = this.mergedNamespaces.map(variable => variable.getName(getPropertyAccess));
|
|
13794
|
+
output = `/*#__PURE__*/${MERGE_NAMESPACES_VARIABLE}(${output},${_}[${assignmentArguments.join(`,${_}`)}])`;
|
|
13795
|
+
}
|
|
13796
|
+
else {
|
|
13797
|
+
// The helper to merge namespaces will also take care of freezing and toStringTag
|
|
13798
|
+
if (symbols) {
|
|
13799
|
+
output = `/*#__PURE__*/Object.defineProperty(${output},${_}Symbol.toStringTag,${_}${getToStringTagValue(getObject)})`;
|
|
13800
|
+
}
|
|
13801
|
+
if (freeze) {
|
|
13802
|
+
output = `/*#__PURE__*/Object.freeze(${output})`;
|
|
13803
|
+
}
|
|
13804
|
+
}
|
|
13805
|
+
const name = this.getName(getPropertyAccess);
|
|
13806
|
+
output = `${cnst} ${name}${_}=${_}${output};`;
|
|
13807
|
+
if (format === 'system' && exportNamesByVariable.has(this)) {
|
|
13808
|
+
output += `${n}${getSystemExportStatement([this], options)};`;
|
|
13809
|
+
}
|
|
13810
|
+
return output;
|
|
13811
|
+
}
|
|
13812
|
+
renderFirst() {
|
|
13813
|
+
return this.referencedEarly;
|
|
13814
|
+
}
|
|
13815
|
+
setMergedNamespaces(mergedNamespaces) {
|
|
13816
|
+
this.mergedNamespaces = mergedNamespaces;
|
|
13817
|
+
const moduleExecIndex = this.context.getModuleExecIndex();
|
|
13818
|
+
for (const identifier of this.references) {
|
|
13819
|
+
const { context } = identifier.scope;
|
|
13820
|
+
if (context.getModuleExecIndex() <= moduleExecIndex) {
|
|
13821
|
+
this.referencedEarly = true;
|
|
13822
|
+
break;
|
|
13823
|
+
}
|
|
13824
|
+
}
|
|
13825
|
+
}
|
|
13826
|
+
getMemberVariable(name) {
|
|
13827
|
+
return this.module.getExportedVariablesByName().get(escapeExportName(name));
|
|
13828
|
+
}
|
|
13829
|
+
includeNonExplicitNamespaces() {
|
|
13830
|
+
if (!this.nonExplicitNamespacesIncluded) {
|
|
13831
|
+
this.nonExplicitNamespacesIncluded = true;
|
|
13832
|
+
this.setMergedNamespaces(this.module.includeAndGetAdditionalMergedNamespaces());
|
|
13833
|
+
}
|
|
13834
|
+
}
|
|
13835
|
+
}
|
|
13836
|
+
NamespaceVariable.prototype.isNamespace = true;
|
|
13837
|
+
// This is a proxy that does not include the namespace object when a path is included
|
|
13838
|
+
const getDynamicNamespaceVariable = (namespace) => Object.create(namespace, {
|
|
13839
|
+
includePath: {
|
|
13840
|
+
value(path, context) {
|
|
13841
|
+
namespace.includeMemberPath(path, context);
|
|
13842
|
+
}
|
|
13843
|
+
}
|
|
13844
|
+
});
|
|
13845
|
+
|
|
13846
|
+
class SyntheticNamedExportVariable extends Variable {
|
|
13847
|
+
constructor(context, name, syntheticNamespace) {
|
|
13848
|
+
super(name);
|
|
13849
|
+
this.baseVariable = null;
|
|
13850
|
+
this.context = context;
|
|
13851
|
+
this.module = context.module;
|
|
13852
|
+
this.syntheticNamespace = syntheticNamespace;
|
|
13853
|
+
}
|
|
13854
|
+
getBaseVariable() {
|
|
13855
|
+
if (this.baseVariable)
|
|
13856
|
+
return this.baseVariable;
|
|
13857
|
+
let baseVariable = this.syntheticNamespace;
|
|
13858
|
+
while (baseVariable instanceof ExportDefaultVariable ||
|
|
13859
|
+
baseVariable instanceof SyntheticNamedExportVariable) {
|
|
13860
|
+
if (baseVariable instanceof ExportDefaultVariable) {
|
|
13861
|
+
const original = baseVariable.getOriginalVariable();
|
|
13862
|
+
if (original === baseVariable)
|
|
13863
|
+
break;
|
|
13864
|
+
baseVariable = original;
|
|
13865
|
+
}
|
|
13866
|
+
if (baseVariable instanceof SyntheticNamedExportVariable) {
|
|
13867
|
+
baseVariable = baseVariable.syntheticNamespace;
|
|
13868
|
+
}
|
|
13869
|
+
}
|
|
13870
|
+
return (this.baseVariable = baseVariable);
|
|
13871
|
+
}
|
|
13872
|
+
getBaseVariableName() {
|
|
13873
|
+
return this.syntheticNamespace.getBaseVariableName();
|
|
13874
|
+
}
|
|
13875
|
+
getName(getPropertyAccess) {
|
|
13876
|
+
return `${this.syntheticNamespace.getName(getPropertyAccess)}${getPropertyAccess(this.name)}`;
|
|
13877
|
+
}
|
|
13878
|
+
includePath(path, context) {
|
|
13879
|
+
super.includePath(path, context);
|
|
13880
|
+
this.context.includeVariableInModule(this.syntheticNamespace, [this.name, ...path], context);
|
|
13881
|
+
}
|
|
13882
|
+
setRenderNames(baseName, name) {
|
|
13883
|
+
super.setRenderNames(baseName, name);
|
|
13884
|
+
}
|
|
13885
|
+
}
|
|
13886
|
+
|
|
13887
|
+
class ExternalChunk {
|
|
13888
|
+
constructor(module, options, inputBase) {
|
|
13889
|
+
this.options = options;
|
|
13890
|
+
this.inputBase = inputBase;
|
|
13891
|
+
this.defaultVariableName = '';
|
|
13892
|
+
this.namespaceVariableName = '';
|
|
13893
|
+
this.variableName = '';
|
|
13894
|
+
this.fileName = null;
|
|
13895
|
+
this.importAttributes = null;
|
|
13896
|
+
this.id = module.id;
|
|
13897
|
+
this.moduleInfo = module.info;
|
|
13898
|
+
this.renormalizeRenderPath = module.renormalizeRenderPath;
|
|
13899
|
+
this.suggestedVariableName = module.suggestedVariableName;
|
|
13900
|
+
}
|
|
13901
|
+
get moduleSideEffects() {
|
|
13902
|
+
return this.moduleInfo.moduleSideEffects;
|
|
13903
|
+
}
|
|
13904
|
+
getFileName() {
|
|
13905
|
+
if (this.fileName) {
|
|
13906
|
+
return this.fileName;
|
|
13907
|
+
}
|
|
13908
|
+
const { paths } = this.options;
|
|
13909
|
+
return (this.fileName =
|
|
13910
|
+
(typeof paths === 'function' ? paths(this.id) : paths[this.id]) ||
|
|
13911
|
+
(this.renormalizeRenderPath ? parseAst_js.normalize(path.relative(this.inputBase, this.id)) : this.id));
|
|
13912
|
+
}
|
|
13913
|
+
getImportAttributes(snippets) {
|
|
13914
|
+
return (this.importAttributes ||= formatAttributes(['es', 'cjs'].includes(this.options.format) &&
|
|
13915
|
+
this.options.externalImportAttributes &&
|
|
13916
|
+
this.moduleInfo.attributes, snippets));
|
|
13917
|
+
}
|
|
13918
|
+
getImportPath(importer) {
|
|
13919
|
+
return escapeId(this.renormalizeRenderPath
|
|
13920
|
+
? parseAst_js.getImportPath(importer, this.getFileName(), this.options.format === 'amd', false)
|
|
13921
|
+
: this.getFileName());
|
|
13922
|
+
}
|
|
13923
|
+
}
|
|
13924
|
+
function formatAttributes(attributes, { getObject }) {
|
|
13925
|
+
if (!attributes) {
|
|
13926
|
+
return null;
|
|
13927
|
+
}
|
|
13928
|
+
const assertionEntries = Object.entries(attributes).map(([key, value]) => [key, JSON.stringify(value)]);
|
|
13929
|
+
if (assertionEntries.length > 0) {
|
|
13930
|
+
return getObject(assertionEntries, { lineBreakIndent: null });
|
|
13931
|
+
}
|
|
13932
|
+
return null;
|
|
13933
|
+
}
|
|
13934
|
+
|
|
13935
|
+
function removeJsExtension(name) {
|
|
13936
|
+
return name.endsWith('.js') ? name.slice(0, -3) : name;
|
|
13937
|
+
}
|
|
13938
|
+
|
|
13939
|
+
function getCompleteAmdId(options, chunkId) {
|
|
13940
|
+
if (options.autoId) {
|
|
13941
|
+
return `${options.basePath ? options.basePath + '/' : ''}${removeJsExtension(chunkId)}`;
|
|
13942
|
+
}
|
|
13943
|
+
return options.id ?? '';
|
|
13944
|
+
}
|
|
13945
|
+
|
|
13946
|
+
function getExportBlock$1(exports, dependencies, namedExportsMode, interop, snippets, t, externalLiveBindings, reexportProtoFromExternal, mechanism = 'return ') {
|
|
13947
|
+
const { _, getFunctionIntro, getPropertyAccess, n, s } = snippets;
|
|
13948
|
+
if (!namedExportsMode) {
|
|
13949
|
+
return `${n}${n}${mechanism}${getSingleDefaultExport(exports, dependencies, interop, externalLiveBindings, getPropertyAccess)};`;
|
|
13950
|
+
}
|
|
13951
|
+
let exportBlock = '';
|
|
13952
|
+
if (namedExportsMode) {
|
|
13953
|
+
for (const { defaultVariableName, importPath, isChunk, name, namedExportsMode: dependencyNamedExportsMode, namespaceVariableName, reexports } of dependencies) {
|
|
13954
|
+
if (!reexports) {
|
|
13955
|
+
continue;
|
|
13956
|
+
}
|
|
13957
|
+
for (const specifier of reexports) {
|
|
13958
|
+
if (specifier.reexported !== '*') {
|
|
13959
|
+
const importName = getReexportedImportName(name, specifier.imported, dependencyNamedExportsMode, isChunk, defaultVariableName, namespaceVariableName, interop, importPath, externalLiveBindings, getPropertyAccess);
|
|
13960
|
+
if (exportBlock)
|
|
13961
|
+
exportBlock += n;
|
|
13962
|
+
if (specifier.imported !== '*' && specifier.needsLiveBinding) {
|
|
13963
|
+
exportBlock += `Object.defineProperty(exports,${_}${JSON.stringify(unescapeExportName(specifier.reexported))},${_}${getGetter(importName, false, t, snippets)});`;
|
|
13964
|
+
}
|
|
13965
|
+
else if (specifier.reexported === '__proto__') {
|
|
13966
|
+
exportBlock +=
|
|
13967
|
+
`Object.defineProperty(exports,${_}"__proto__",${_}{${n}` +
|
|
13968
|
+
`${t}enumerable:${_}true,${n}` +
|
|
13969
|
+
`${t}value:${_}${importName}${n}});`;
|
|
13970
|
+
}
|
|
13971
|
+
else {
|
|
13972
|
+
exportBlock += `exports${getPropertyAccess(unescapeExportName(specifier.reexported))}${_}=${_}${importName};`;
|
|
13973
|
+
}
|
|
13974
|
+
}
|
|
13975
|
+
}
|
|
13976
|
+
}
|
|
13977
|
+
}
|
|
13978
|
+
for (const { exported, local, needsLiveBinding } of exports) {
|
|
13979
|
+
const lhs = `exports${getPropertyAccess(unescapeExportName(exported))}`;
|
|
13980
|
+
const rhs = local;
|
|
13167
13981
|
if (lhs !== rhs) {
|
|
13168
13982
|
if (exportBlock)
|
|
13169
13983
|
exportBlock += n;
|
|
@@ -14206,102 +15020,6 @@ const builtins = 'arguments Infinity NaN undefined null true false eval uneval i
|
|
|
14206
15020
|
const forbiddenIdentifiers = new Set(`${reservedWords} ${builtins}`.split(' '));
|
|
14207
15021
|
forbiddenIdentifiers.add('');
|
|
14208
15022
|
|
|
14209
|
-
class ArrayPattern extends NodeBase {
|
|
14210
|
-
addExportedVariables(variables, exportNamesByVariable) {
|
|
14211
|
-
for (const element of this.elements) {
|
|
14212
|
-
element?.addExportedVariables(variables, exportNamesByVariable);
|
|
14213
|
-
}
|
|
14214
|
-
}
|
|
14215
|
-
declare(kind, destructuredInitPath, init) {
|
|
14216
|
-
const variables = [];
|
|
14217
|
-
const includedPatternPath = getIncludedPatternPath(destructuredInitPath);
|
|
14218
|
-
for (const element of this.elements) {
|
|
14219
|
-
if (element !== null) {
|
|
14220
|
-
variables.push(...element.declare(kind, includedPatternPath, init));
|
|
14221
|
-
}
|
|
14222
|
-
}
|
|
14223
|
-
return variables;
|
|
14224
|
-
}
|
|
14225
|
-
deoptimizeAssignment(destructuredInitPath, init) {
|
|
14226
|
-
const includedPatternPath = getIncludedPatternPath(destructuredInitPath);
|
|
14227
|
-
for (const element of this.elements) {
|
|
14228
|
-
element?.deoptimizeAssignment(includedPatternPath, init);
|
|
14229
|
-
}
|
|
14230
|
-
}
|
|
14231
|
-
// Patterns can only be deoptimized at the empty path at the moment
|
|
14232
|
-
deoptimizePath() {
|
|
14233
|
-
for (const element of this.elements) {
|
|
14234
|
-
element?.deoptimizePath(EMPTY_PATH);
|
|
14235
|
-
}
|
|
14236
|
-
}
|
|
14237
|
-
hasEffectsWhenDestructuring(context, destructuredInitPath, init) {
|
|
14238
|
-
const includedPatternPath = getIncludedPatternPath(destructuredInitPath);
|
|
14239
|
-
for (const element of this.elements) {
|
|
14240
|
-
if (element?.hasEffectsWhenDestructuring(context, includedPatternPath, init)) {
|
|
14241
|
-
return true;
|
|
14242
|
-
}
|
|
14243
|
-
}
|
|
14244
|
-
return false;
|
|
14245
|
-
}
|
|
14246
|
-
// Patterns are only checked at the empty path at the moment
|
|
14247
|
-
hasEffectsOnInteractionAtPath(_path, interaction, context) {
|
|
14248
|
-
for (const element of this.elements) {
|
|
14249
|
-
if (element?.hasEffectsOnInteractionAtPath(EMPTY_PATH, interaction, context))
|
|
14250
|
-
return true;
|
|
14251
|
-
}
|
|
14252
|
-
return false;
|
|
14253
|
-
}
|
|
14254
|
-
includeDestructuredIfNecessary(context, destructuredInitPath, init) {
|
|
14255
|
-
let included = false;
|
|
14256
|
-
const includedPatternPath = getIncludedPatternPath(destructuredInitPath);
|
|
14257
|
-
for (const element of [...this.elements].reverse()) {
|
|
14258
|
-
if (element) {
|
|
14259
|
-
if (included && !element.included) {
|
|
14260
|
-
element.includeNode(context);
|
|
14261
|
-
}
|
|
14262
|
-
included =
|
|
14263
|
-
element.includeDestructuredIfNecessary(context, includedPatternPath, init) || included;
|
|
14264
|
-
}
|
|
14265
|
-
}
|
|
14266
|
-
if (!this.included && included) {
|
|
14267
|
-
this.includeNode(context);
|
|
14268
|
-
}
|
|
14269
|
-
return this.included;
|
|
14270
|
-
}
|
|
14271
|
-
render(code, options) {
|
|
14272
|
-
let removedStart = this.start + 1;
|
|
14273
|
-
for (const element of this.elements) {
|
|
14274
|
-
if (!element)
|
|
14275
|
-
continue;
|
|
14276
|
-
if (element.included) {
|
|
14277
|
-
element.render(code, options);
|
|
14278
|
-
removedStart = element.end;
|
|
14279
|
-
}
|
|
14280
|
-
else {
|
|
14281
|
-
code.remove(removedStart, this.end - 1);
|
|
14282
|
-
break;
|
|
14283
|
-
}
|
|
14284
|
-
}
|
|
14285
|
-
}
|
|
14286
|
-
setAssignedValue(value) {
|
|
14287
|
-
super.setAssignedValue(value);
|
|
14288
|
-
// Destructuring assigns each target only some subpath of the assigned
|
|
14289
|
-
// value, which is not tracked
|
|
14290
|
-
for (const element of this.elements) {
|
|
14291
|
-
element?.setAssignedValue(UNKNOWN_EXPRESSION);
|
|
14292
|
-
}
|
|
14293
|
-
}
|
|
14294
|
-
markDeclarationReached() {
|
|
14295
|
-
for (const element of this.elements) {
|
|
14296
|
-
element?.markDeclarationReached();
|
|
14297
|
-
}
|
|
14298
|
-
}
|
|
14299
|
-
}
|
|
14300
|
-
ArrayPattern.prototype.includeNode = onlyIncludeSelf;
|
|
14301
|
-
const getIncludedPatternPath = (destructuredInitPath) => destructuredInitPath.at(-1) === UnknownKey
|
|
14302
|
-
? destructuredInitPath
|
|
14303
|
-
: [...destructuredInitPath, UnknownInteger];
|
|
14304
|
-
|
|
14305
15023
|
class ArrowFunctionExpression extends FunctionBase {
|
|
14306
15024
|
constructor() {
|
|
14307
15025
|
super(...arguments);
|
|
@@ -14366,112 +15084,13 @@ class ArrowFunctionExpression extends FunctionBase {
|
|
|
14366
15084
|
}
|
|
14367
15085
|
}
|
|
14368
15086
|
}
|
|
14369
|
-
getObjectEntity() {
|
|
14370
|
-
if (this.objectEntity !== null) {
|
|
14371
|
-
return this.objectEntity;
|
|
14372
|
-
}
|
|
14373
|
-
return (this.objectEntity = new ObjectEntity([], OBJECT_PROTOTYPE));
|
|
14374
|
-
}
|
|
14375
|
-
}
|
|
14376
|
-
|
|
14377
|
-
class ObjectPattern extends NodeBase {
|
|
14378
|
-
addExportedVariables(variables, exportNamesByVariable) {
|
|
14379
|
-
for (const property of this.properties) {
|
|
14380
|
-
if (property.type === parseAst_js.Property) {
|
|
14381
|
-
property.value.addExportedVariables(variables, exportNamesByVariable);
|
|
14382
|
-
}
|
|
14383
|
-
else {
|
|
14384
|
-
property.argument.addExportedVariables(variables, exportNamesByVariable);
|
|
14385
|
-
}
|
|
14386
|
-
}
|
|
14387
|
-
}
|
|
14388
|
-
declare(kind, destructuredInitPath, init) {
|
|
14389
|
-
const variables = [];
|
|
14390
|
-
for (const property of this.properties) {
|
|
14391
|
-
variables.push(...property.declare(kind, destructuredInitPath, init));
|
|
14392
|
-
}
|
|
14393
|
-
return variables;
|
|
14394
|
-
}
|
|
14395
|
-
deoptimizeAssignment(destructuredInitPath, init) {
|
|
14396
|
-
for (const property of this.properties) {
|
|
14397
|
-
property.deoptimizeAssignment(destructuredInitPath, init);
|
|
14398
|
-
}
|
|
14399
|
-
}
|
|
14400
|
-
deoptimizePath(path) {
|
|
14401
|
-
if (path.length === 0) {
|
|
14402
|
-
for (const property of this.properties) {
|
|
14403
|
-
property.deoptimizePath(path);
|
|
14404
|
-
}
|
|
14405
|
-
}
|
|
14406
|
-
}
|
|
14407
|
-
hasEffectsOnInteractionAtPath(
|
|
14408
|
-
// At the moment, this is only triggered for assignment left-hand sides,
|
|
14409
|
-
// where the path is empty
|
|
14410
|
-
_path, interaction, context) {
|
|
14411
|
-
for (const property of this.properties) {
|
|
14412
|
-
if (property.hasEffectsOnInteractionAtPath(EMPTY_PATH, interaction, context))
|
|
14413
|
-
return true;
|
|
14414
|
-
}
|
|
14415
|
-
return false;
|
|
14416
|
-
}
|
|
14417
|
-
hasEffectsWhenDestructuring(context, destructuredInitPath, init) {
|
|
14418
|
-
for (const property of this.properties) {
|
|
14419
|
-
if (property.hasEffectsWhenDestructuring(context, destructuredInitPath, init))
|
|
14420
|
-
return true;
|
|
14421
|
-
}
|
|
14422
|
-
return false;
|
|
14423
|
-
}
|
|
14424
|
-
includeDestructuredIfNecessary(context, destructuredInitPath, init) {
|
|
14425
|
-
if (!this.properties.length)
|
|
14426
|
-
return this.included;
|
|
14427
|
-
const lastProperty = this.properties.at(-1);
|
|
14428
|
-
let included = lastProperty.includeDestructuredIfNecessary(context, destructuredInitPath, init);
|
|
14429
|
-
const lastPropertyIsRestElement = lastProperty.type === parseAst_js.RestElement;
|
|
14430
|
-
for (const property of this.properties.slice(0, -1)) {
|
|
14431
|
-
if (lastPropertyIsRestElement && included && !property.included) {
|
|
14432
|
-
property.includeNode(context);
|
|
14433
|
-
}
|
|
14434
|
-
included =
|
|
14435
|
-
property.includeDestructuredIfNecessary(context, destructuredInitPath, init) || included;
|
|
14436
|
-
}
|
|
14437
|
-
if (!this.included && included) {
|
|
14438
|
-
this.includeNode(context);
|
|
14439
|
-
}
|
|
14440
|
-
return this.included;
|
|
14441
|
-
}
|
|
14442
|
-
markDeclarationReached() {
|
|
14443
|
-
for (const property of this.properties) {
|
|
14444
|
-
property.markDeclarationReached();
|
|
14445
|
-
}
|
|
14446
|
-
}
|
|
14447
|
-
render(code, options) {
|
|
14448
|
-
if (this.properties.length > 0) {
|
|
14449
|
-
const separatedNodes = getCommaSeparatedNodesWithBoundaries(this.properties, code, this.start + 1, this.end - 1);
|
|
14450
|
-
let lastSeparatorPos = null;
|
|
14451
|
-
for (const { node, separator, start, end } of separatedNodes) {
|
|
14452
|
-
if (!node.included) {
|
|
14453
|
-
treeshakeNode(node, code, start, end);
|
|
14454
|
-
continue;
|
|
14455
|
-
}
|
|
14456
|
-
lastSeparatorPos = separator;
|
|
14457
|
-
node.render(code, options);
|
|
14458
|
-
}
|
|
14459
|
-
if (lastSeparatorPos) {
|
|
14460
|
-
code.remove(lastSeparatorPos, this.end - 1);
|
|
14461
|
-
}
|
|
14462
|
-
}
|
|
14463
|
-
}
|
|
14464
|
-
setAssignedValue(value) {
|
|
14465
|
-
super.setAssignedValue(value);
|
|
14466
|
-
// Destructuring assigns each target only some subpath of the assigned
|
|
14467
|
-
// value, which is not tracked
|
|
14468
|
-
for (const property of this.properties) {
|
|
14469
|
-
property.setAssignedValue(UNKNOWN_EXPRESSION);
|
|
15087
|
+
getObjectEntity() {
|
|
15088
|
+
if (this.objectEntity !== null) {
|
|
15089
|
+
return this.objectEntity;
|
|
14470
15090
|
}
|
|
15091
|
+
return (this.objectEntity = new ObjectEntity([], OBJECT_PROTOTYPE));
|
|
14471
15092
|
}
|
|
14472
15093
|
}
|
|
14473
|
-
ObjectPattern.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
|
|
14474
|
-
ObjectPattern.prototype.applyDeoptimizations = doNotDeoptimize;
|
|
14475
15094
|
|
|
14476
15095
|
class AssignmentExpression extends NodeBase {
|
|
14477
15096
|
constructor() {
|
|
@@ -14562,7 +15181,7 @@ class AssignmentExpression extends NodeBase {
|
|
|
14562
15181
|
const systemPatternExports = [];
|
|
14563
15182
|
left.addExportedVariables(systemPatternExports, options.exportNamesByVariable);
|
|
14564
15183
|
if (systemPatternExports.length > 0) {
|
|
14565
|
-
renderSystemExportFunction(systemPatternExports, start, end, renderedSurroundingElement
|
|
15184
|
+
renderSystemExportFunction(systemPatternExports, start, end, systemExportIifeStartsStatement(parent, renderedSurroundingElement, start), code, options);
|
|
14566
15185
|
return;
|
|
14567
15186
|
}
|
|
14568
15187
|
}
|
|
@@ -14581,6 +15200,12 @@ class AssignmentExpression extends NodeBase {
|
|
|
14581
15200
|
this.scope.context.requestTreeshakingPass();
|
|
14582
15201
|
}
|
|
14583
15202
|
}
|
|
15203
|
+
// `function () {}()` is a function declaration at the first token of a statement.
|
|
15204
|
+
// `({ name } = obj)` already starts at `(`, so the inserted function stays an expression.
|
|
15205
|
+
function systemExportIifeStartsStatement(parent, renderedSurroundingElement, expressionStart) {
|
|
15206
|
+
return (renderedSurroundingElement === parseAst_js.ExpressionStatement ||
|
|
15207
|
+
(parent.type === parseAst_js.ExpressionStatement && parent.start === expressionStart));
|
|
15208
|
+
}
|
|
14584
15209
|
|
|
14585
15210
|
class AssignmentPattern extends NodeBase {
|
|
14586
15211
|
addExportedVariables(variables, exportNamesByVariable) {
|
|
@@ -14644,17 +15269,6 @@ class AssignmentPattern extends NodeBase {
|
|
|
14644
15269
|
}
|
|
14645
15270
|
}
|
|
14646
15271
|
|
|
14647
|
-
function markTopLevelAwait(node) {
|
|
14648
|
-
if (node.scope.context.usesTopLevelAwait)
|
|
14649
|
-
return;
|
|
14650
|
-
let parent = node.parent;
|
|
14651
|
-
do {
|
|
14652
|
-
if (parent instanceof FunctionBase)
|
|
14653
|
-
return;
|
|
14654
|
-
} while ((parent = parent.parent));
|
|
14655
|
-
node.scope.context.usesTopLevelAwait = true;
|
|
14656
|
-
}
|
|
14657
|
-
|
|
14658
15272
|
class AwaitExpression extends NodeBase {
|
|
14659
15273
|
deoptimizePath(path) {
|
|
14660
15274
|
this.argument.deoptimizePath(path);
|
|
@@ -15191,16 +15805,6 @@ class ClassBody extends NodeBase {
|
|
|
15191
15805
|
ClassBody.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
|
|
15192
15806
|
ClassBody.prototype.applyDeoptimizations = doNotDeoptimize;
|
|
15193
15807
|
|
|
15194
|
-
class ClassExpression extends ClassNode {
|
|
15195
|
-
render(code, options, { renderedSurroundingElement } = parseAst_js.BLANK) {
|
|
15196
|
-
super.render(code, options);
|
|
15197
|
-
if (renderedSurroundingElement === parseAst_js.ExpressionStatement) {
|
|
15198
|
-
code.appendRight(this.start, '(');
|
|
15199
|
-
code.prependLeft(this.end, ')');
|
|
15200
|
-
}
|
|
15201
|
-
}
|
|
15202
|
-
}
|
|
15203
|
-
|
|
15204
15808
|
function tryCastLiteralValueToBoolean(literalValue) {
|
|
15205
15809
|
if (typeof literalValue === 'symbol') {
|
|
15206
15810
|
if (literalValue === UnknownFalsyValue) {
|
|
@@ -15619,6 +16223,9 @@ class ForInStatement extends NodeBase {
|
|
|
15619
16223
|
code.prependLeft(this.right.start, ' ');
|
|
15620
16224
|
}
|
|
15621
16225
|
this.body.render(code, options);
|
|
16226
|
+
if (options.format === 'system') {
|
|
16227
|
+
renderSystemExportForLoop(this.left, this.body, code, options);
|
|
16228
|
+
}
|
|
15622
16229
|
}
|
|
15623
16230
|
applyDeoptimizations() {
|
|
15624
16231
|
this.deoptimized = true;
|
|
@@ -15673,6 +16280,9 @@ class ForOfStatement extends NodeBase {
|
|
|
15673
16280
|
code.prependLeft(this.right.start, ' ');
|
|
15674
16281
|
}
|
|
15675
16282
|
this.body.render(code, options);
|
|
16283
|
+
if (options.format === 'system') {
|
|
16284
|
+
renderSystemExportForLoop(this.left, this.body, code, options);
|
|
16285
|
+
}
|
|
15676
16286
|
}
|
|
15677
16287
|
applyDeoptimizations() {
|
|
15678
16288
|
this.deoptimized = true;
|
|
@@ -15884,7 +16494,7 @@ class IfStatement extends NodeBase {
|
|
|
15884
16494
|
const hoistedVariables = [
|
|
15885
16495
|
...new Set(hoistedDeclarations.map(identifier => {
|
|
15886
16496
|
const variable = identifier.variable;
|
|
15887
|
-
return variable
|
|
16497
|
+
return this.shouldHoistVariable(variable) ? variable.getName(getPropertyAccess) : '';
|
|
15888
16498
|
}))
|
|
15889
16499
|
]
|
|
15890
16500
|
.filter(Boolean)
|
|
@@ -15898,6 +16508,11 @@ class IfStatement extends NodeBase {
|
|
|
15898
16508
|
}
|
|
15899
16509
|
}
|
|
15900
16510
|
}
|
|
16511
|
+
shouldHoistVariable(variable) {
|
|
16512
|
+
return (variable.included &&
|
|
16513
|
+
variable.renderBaseName === null &&
|
|
16514
|
+
variable.getHoistedVariable()?.renderBaseName == null);
|
|
16515
|
+
}
|
|
15901
16516
|
shouldKeepAlternateBranch() {
|
|
15902
16517
|
let currentParent = this.parent;
|
|
15903
16518
|
do {
|
|
@@ -16902,7 +17517,7 @@ class LabeledStatement extends NodeBase {
|
|
|
16902
17517
|
this.includeNode(context);
|
|
16903
17518
|
const { brokenFlow, includedLabels } = context;
|
|
16904
17519
|
context.includedLabels = new Set();
|
|
16905
|
-
this.body.include(context, includeChildrenRecursively);
|
|
17520
|
+
this.body.include(context, includeChildrenRecursively, { asSingleStatement: true });
|
|
16906
17521
|
if (includeChildrenRecursively || context.includedLabels.has(this.label.name)) {
|
|
16907
17522
|
this.label.include(context, includeChildrenRecursively);
|
|
16908
17523
|
context.includedLabels.delete(this.label.name);
|
|
@@ -17731,746 +18346,434 @@ class TaggedTemplateExpression extends CallExpressionBase {
|
|
|
17731
18346
|
return true;
|
|
17732
18347
|
}
|
|
17733
18348
|
return (this.tag.hasEffects(context) ||
|
|
17734
|
-
this.tag.hasEffectsOnInteractionAtPath(EMPTY_PATH, this.interaction, context));
|
|
17735
|
-
}
|
|
17736
|
-
include(context, includeChildrenRecursively) {
|
|
17737
|
-
if (!this.included)
|
|
17738
|
-
this.includeNode(context);
|
|
17739
|
-
if (includeChildrenRecursively) {
|
|
17740
|
-
super.include(context, true);
|
|
17741
|
-
}
|
|
17742
|
-
else {
|
|
17743
|
-
this.quasi.include(context, false);
|
|
17744
|
-
this.tag.include(context, false);
|
|
17745
|
-
this.tag.includeCallArgumentsWhenCalledAtPath(EMPTY_PATH, this.interaction, context);
|
|
17746
|
-
}
|
|
17747
|
-
}
|
|
17748
|
-
initialise() {
|
|
17749
|
-
super.initialise();
|
|
17750
|
-
this.args = [UNKNOWN_EXPRESSION, ...this.quasi.expressions];
|
|
17751
|
-
this.interaction = {
|
|
17752
|
-
args: [
|
|
17753
|
-
this.tag instanceof MemberExpression && !this.tag.variable ? this.tag.object : null,
|
|
17754
|
-
...this.args
|
|
17755
|
-
],
|
|
17756
|
-
type: INTERACTION_CALLED,
|
|
17757
|
-
withNew: false
|
|
17758
|
-
};
|
|
17759
|
-
}
|
|
17760
|
-
render(code, options) {
|
|
17761
|
-
this.tag.render(code, options, { isCalleeOfRenderedParent: true });
|
|
17762
|
-
this.quasi.render(code, options);
|
|
17763
|
-
if (!this.hasCheckedForWarnings && this.tag.type === parseAst_js.Identifier) {
|
|
17764
|
-
this.hasCheckedForWarnings = true;
|
|
17765
|
-
const name = this.tag.name;
|
|
17766
|
-
const variable = this.scope.findVariable(name);
|
|
17767
|
-
if (variable.isNamespace) {
|
|
17768
|
-
this.scope.context.log(parseAst_js.LOGLEVEL_WARN, parseAst_js.logCannotCallNamespace(name), this.start);
|
|
17769
|
-
}
|
|
17770
|
-
}
|
|
17771
|
-
}
|
|
17772
|
-
applyDeoptimizations() {
|
|
17773
|
-
this.deoptimized = true;
|
|
17774
|
-
this.tag.deoptimizeArgumentsOnInteractionAtPath(this.interaction, EMPTY_PATH, SHARED_RECURSION_TRACKER);
|
|
17775
|
-
this.scope.context.requestTreeshakingPass();
|
|
17776
|
-
}
|
|
17777
|
-
getReturnExpression(recursionTracker = SHARED_RECURSION_TRACKER) {
|
|
17778
|
-
if (this.returnExpression === null) {
|
|
17779
|
-
this.returnExpression = UNKNOWN_RETURN_EXPRESSION;
|
|
17780
|
-
return (this.returnExpression = this.tag.getReturnExpressionWhenCalledAtPath(EMPTY_PATH, this.interaction, recursionTracker, this));
|
|
17781
|
-
}
|
|
17782
|
-
return this.returnExpression;
|
|
17783
|
-
}
|
|
17784
|
-
}
|
|
17785
|
-
TaggedTemplateExpression.prototype.includeNode = onlyIncludeSelf;
|
|
17786
|
-
|
|
17787
|
-
class TemplateElement extends NodeBase {
|
|
17788
|
-
get tail() {
|
|
17789
|
-
return isFlagSet(this.flags, 1048576 /* Flag.tail */);
|
|
17790
|
-
}
|
|
17791
|
-
set tail(value) {
|
|
17792
|
-
this.flags = setFlag(this.flags, 1048576 /* Flag.tail */, value);
|
|
17793
|
-
}
|
|
17794
|
-
// Do not try to bind value
|
|
17795
|
-
bind() { }
|
|
17796
|
-
hasEffects() {
|
|
17797
|
-
return false;
|
|
17798
|
-
}
|
|
17799
|
-
parseNode(esTreeNode) {
|
|
17800
|
-
this.value = esTreeNode.value;
|
|
17801
|
-
return super.parseNode(esTreeNode);
|
|
17802
|
-
}
|
|
17803
|
-
render() { }
|
|
17804
|
-
}
|
|
17805
|
-
TemplateElement.prototype.includeNode = onlyIncludeSelf;
|
|
17806
|
-
|
|
17807
|
-
class TemplateLiteral extends NodeBase {
|
|
17808
|
-
deoptimizeArgumentsOnInteractionAtPath() { }
|
|
17809
|
-
getLiteralValueAtPath(path) {
|
|
17810
|
-
if (path.length > 0 || this.quasis.length !== 1) {
|
|
17811
|
-
return UnknownValue;
|
|
17812
|
-
}
|
|
17813
|
-
return this.quasis[0].value.cooked;
|
|
17814
|
-
}
|
|
17815
|
-
getReturnExpressionWhenCalledAtPath(path) {
|
|
17816
|
-
if (path.length !== 1) {
|
|
17817
|
-
return UNKNOWN_RETURN_EXPRESSION;
|
|
17818
|
-
}
|
|
17819
|
-
return getMemberReturnExpressionWhenCalled(literalStringMembers, path[0]);
|
|
17820
|
-
}
|
|
17821
|
-
hasEffectsOnInteractionAtPath(path, interaction, context) {
|
|
17822
|
-
if (interaction.type === INTERACTION_ACCESSED) {
|
|
17823
|
-
return path.length > 1;
|
|
17824
|
-
}
|
|
17825
|
-
if (interaction.type === INTERACTION_CALLED && path.length === 1) {
|
|
17826
|
-
return hasMemberEffectWhenCalled(literalStringMembers, path[0], interaction, context);
|
|
17827
|
-
}
|
|
17828
|
-
return true;
|
|
17829
|
-
}
|
|
17830
|
-
includeNode(context) {
|
|
17831
|
-
this.included = true;
|
|
17832
|
-
if (!this.deoptimized)
|
|
17833
|
-
this.applyDeoptimizations();
|
|
17834
|
-
for (const node of this.expressions) {
|
|
17835
|
-
node.includePath(UNKNOWN_PATH, context);
|
|
17836
|
-
}
|
|
17837
|
-
}
|
|
17838
|
-
render(code, options) {
|
|
17839
|
-
this.scope.context.addIndentExclusionRange([this.start, this.end]);
|
|
17840
|
-
super.render(code, options);
|
|
17841
|
-
}
|
|
17842
|
-
}
|
|
17843
|
-
|
|
17844
|
-
class ModuleScope extends ChildScope {
|
|
17845
|
-
constructor(parent, context, importDescriptions) {
|
|
17846
|
-
super(parent, context);
|
|
17847
|
-
this.importDescriptions = importDescriptions;
|
|
17848
|
-
this.variables.set('this', new LocalVariable('this', null, UNDEFINED_EXPRESSION, EMPTY_PATH, context, 'other'));
|
|
17849
|
-
}
|
|
17850
|
-
addDeclaration(identifier, context, init, destructuredInitPath, kind) {
|
|
17851
|
-
if (this.importDescriptions.has(identifier.name)) {
|
|
17852
|
-
context.error(parseAst_js.logRedeclarationError(identifier.name), identifier.start);
|
|
17853
|
-
}
|
|
17854
|
-
return super.addDeclaration(identifier, context, init, destructuredInitPath, kind);
|
|
17855
|
-
}
|
|
17856
|
-
addExportDefaultDeclaration(exportDefaultDeclaration, context) {
|
|
17857
|
-
const variable = new ExportDefaultVariable(exportDefaultDeclaration, context);
|
|
17858
|
-
this.variables.set('default', variable);
|
|
17859
|
-
return variable;
|
|
17860
|
-
}
|
|
17861
|
-
addNamespaceMemberAccess() { }
|
|
17862
|
-
deconflict(format, exportNamesByVariable, accessedGlobalsByScope) {
|
|
17863
|
-
// all module level variables are already deconflicted when deconflicting the chunk
|
|
17864
|
-
for (const scope of this.children)
|
|
17865
|
-
scope.deconflict(format, exportNamesByVariable, accessedGlobalsByScope);
|
|
17866
|
-
}
|
|
17867
|
-
findLexicalBoundary() {
|
|
17868
|
-
return this;
|
|
17869
|
-
}
|
|
17870
|
-
findVariable(name) {
|
|
17871
|
-
const knownVariable = this.variables.get(name) || this.accessedOutsideVariables.get(name);
|
|
17872
|
-
if (knownVariable) {
|
|
17873
|
-
return knownVariable;
|
|
17874
|
-
}
|
|
17875
|
-
const variable = this.context.traceVariable(name) || this.parent.findVariable(name);
|
|
17876
|
-
if (variable instanceof GlobalVariable) {
|
|
17877
|
-
this.accessedOutsideVariables.set(name, variable);
|
|
17878
|
-
}
|
|
17879
|
-
return variable;
|
|
17880
|
-
}
|
|
17881
|
-
}
|
|
17882
|
-
|
|
17883
|
-
class ThisExpression extends NodeBase {
|
|
17884
|
-
bind() {
|
|
17885
|
-
this.variable = this.scope.findVariable('this');
|
|
17886
|
-
}
|
|
17887
|
-
deoptimizeArgumentsOnInteractionAtPath(interaction, path, recursionTracker) {
|
|
17888
|
-
this.variable.deoptimizeArgumentsOnInteractionAtPath(interaction, path, recursionTracker);
|
|
17889
|
-
}
|
|
17890
|
-
deoptimizePath(path) {
|
|
17891
|
-
this.variable.deoptimizePath(path);
|
|
17892
|
-
}
|
|
17893
|
-
hasEffectsOnInteractionAtPath(path, interaction, context) {
|
|
17894
|
-
if (path.length === 0) {
|
|
17895
|
-
return interaction.type !== INTERACTION_ACCESSED;
|
|
17896
|
-
}
|
|
17897
|
-
return this.variable.hasEffectsOnInteractionAtPath(path, interaction, context);
|
|
17898
|
-
}
|
|
17899
|
-
include(context) {
|
|
17900
|
-
if (!this.included)
|
|
17901
|
-
this.includeNode(context);
|
|
17902
|
-
}
|
|
17903
|
-
includeNode(context) {
|
|
17904
|
-
this.included = true;
|
|
17905
|
-
if (!this.deoptimized)
|
|
17906
|
-
this.applyDeoptimizations();
|
|
17907
|
-
this.scope.context.includeVariableInModule(this.variable, EMPTY_PATH, context);
|
|
17908
|
-
}
|
|
17909
|
-
includePath(path, context) {
|
|
17910
|
-
if (!this.included) {
|
|
17911
|
-
this.included = true;
|
|
17912
|
-
this.scope.context.includeVariableInModule(this.variable, path, context);
|
|
17913
|
-
}
|
|
17914
|
-
else if (path.length > 0) {
|
|
17915
|
-
this.variable.includePath(path, context);
|
|
17916
|
-
}
|
|
17917
|
-
const functionScope = findFunctionScope(this.scope, this.variable);
|
|
17918
|
-
if (functionScope &&
|
|
17919
|
-
functionScope.functionNode.parent instanceof Property &&
|
|
17920
|
-
functionScope.functionNode.parent.parent instanceof ObjectExpression) {
|
|
17921
|
-
functionScope.functionNode.parent.parent.includePath(path, context);
|
|
17922
|
-
}
|
|
17923
|
-
}
|
|
17924
|
-
initialise() {
|
|
17925
|
-
super.initialise();
|
|
17926
|
-
this.alias =
|
|
17927
|
-
this.scope.findLexicalBoundary() instanceof ModuleScope
|
|
17928
|
-
? this.scope.context.moduleContext
|
|
17929
|
-
: null;
|
|
17930
|
-
if (this.alias === 'undefined') {
|
|
17931
|
-
this.scope.context.log(parseAst_js.LOGLEVEL_WARN, parseAst_js.logThisIsUndefined(), this.start);
|
|
17932
|
-
}
|
|
17933
|
-
}
|
|
17934
|
-
render(code) {
|
|
17935
|
-
if (this.alias !== null) {
|
|
17936
|
-
code.overwrite(this.start, this.end, this.alias, {
|
|
17937
|
-
contentOnly: false,
|
|
17938
|
-
storeName: true
|
|
17939
|
-
});
|
|
17940
|
-
}
|
|
17941
|
-
}
|
|
17942
|
-
}
|
|
17943
|
-
function findFunctionScope(scope, thisVariable) {
|
|
17944
|
-
while (!(scope instanceof FunctionScope && scope.thisVariable === thisVariable)) {
|
|
17945
|
-
if (!(scope instanceof ChildScope)) {
|
|
17946
|
-
return null;
|
|
17947
|
-
}
|
|
17948
|
-
scope = scope.parent;
|
|
17949
|
-
}
|
|
17950
|
-
return scope;
|
|
17951
|
-
}
|
|
17952
|
-
|
|
17953
|
-
class ThrowStatement extends NodeBase {
|
|
17954
|
-
hasEffects() {
|
|
17955
|
-
return true;
|
|
18349
|
+
this.tag.hasEffectsOnInteractionAtPath(EMPTY_PATH, this.interaction, context));
|
|
17956
18350
|
}
|
|
17957
18351
|
include(context, includeChildrenRecursively) {
|
|
17958
18352
|
if (!this.included)
|
|
17959
18353
|
this.includeNode(context);
|
|
17960
|
-
|
|
17961
|
-
|
|
17962
|
-
}
|
|
17963
|
-
includeNode(context) {
|
|
17964
|
-
if (!this.included) {
|
|
17965
|
-
this.included = true;
|
|
17966
|
-
this.argument.includePath(UNKNOWN_PATH, context);
|
|
18354
|
+
if (includeChildrenRecursively) {
|
|
18355
|
+
super.include(context, true);
|
|
17967
18356
|
}
|
|
17968
|
-
|
|
17969
|
-
|
|
17970
|
-
|
|
17971
|
-
|
|
17972
|
-
code.prependLeft(this.start + 5, ' ');
|
|
18357
|
+
else {
|
|
18358
|
+
this.quasi.include(context, false);
|
|
18359
|
+
this.tag.include(context, false);
|
|
18360
|
+
this.tag.includeCallArgumentsWhenCalledAtPath(EMPTY_PATH, this.interaction, context);
|
|
17973
18361
|
}
|
|
17974
18362
|
}
|
|
17975
|
-
|
|
17976
|
-
|
|
17977
|
-
|
|
17978
|
-
|
|
17979
|
-
|
|
17980
|
-
|
|
17981
|
-
|
|
17982
|
-
|
|
17983
|
-
|
|
17984
|
-
|
|
17985
|
-
|
|
17986
|
-
: this.block.hasEffects(context)) || !!this.finalizer?.hasEffects(context));
|
|
18363
|
+
initialise() {
|
|
18364
|
+
super.initialise();
|
|
18365
|
+
this.args = [UNKNOWN_EXPRESSION, ...this.quasi.expressions];
|
|
18366
|
+
this.interaction = {
|
|
18367
|
+
args: [
|
|
18368
|
+
this.tag instanceof MemberExpression && !this.tag.variable ? this.tag.object : null,
|
|
18369
|
+
...this.args
|
|
18370
|
+
],
|
|
18371
|
+
type: INTERACTION_CALLED,
|
|
18372
|
+
withNew: false
|
|
18373
|
+
};
|
|
17987
18374
|
}
|
|
17988
|
-
|
|
17989
|
-
|
|
17990
|
-
|
|
17991
|
-
if (!this.
|
|
17992
|
-
this.
|
|
17993
|
-
|
|
17994
|
-
this.
|
|
17995
|
-
if (
|
|
17996
|
-
this.
|
|
17997
|
-
}
|
|
17998
|
-
context.brokenFlow = brokenFlow;
|
|
17999
|
-
}
|
|
18000
|
-
else if (this.includedLabelsAfterBlock) {
|
|
18001
|
-
for (const label of this.includedLabelsAfterBlock) {
|
|
18002
|
-
includedLabels.add(label);
|
|
18375
|
+
render(code, options) {
|
|
18376
|
+
this.tag.render(code, options, { isCalleeOfRenderedParent: true });
|
|
18377
|
+
this.quasi.render(code, options);
|
|
18378
|
+
if (!this.hasCheckedForWarnings && this.tag.type === parseAst_js.Identifier) {
|
|
18379
|
+
this.hasCheckedForWarnings = true;
|
|
18380
|
+
const name = this.tag.name;
|
|
18381
|
+
const variable = this.scope.findVariable(name);
|
|
18382
|
+
if (variable.isNamespace) {
|
|
18383
|
+
this.scope.context.log(parseAst_js.LOGLEVEL_WARN, parseAst_js.logCannotCallNamespace(name), this.start);
|
|
18003
18384
|
}
|
|
18004
18385
|
}
|
|
18005
|
-
|
|
18006
|
-
|
|
18007
|
-
|
|
18386
|
+
}
|
|
18387
|
+
applyDeoptimizations() {
|
|
18388
|
+
this.deoptimized = true;
|
|
18389
|
+
this.tag.deoptimizeArgumentsOnInteractionAtPath(this.interaction, EMPTY_PATH, SHARED_RECURSION_TRACKER);
|
|
18390
|
+
this.scope.context.requestTreeshakingPass();
|
|
18391
|
+
}
|
|
18392
|
+
getReturnExpression(recursionTracker = SHARED_RECURSION_TRACKER) {
|
|
18393
|
+
if (this.returnExpression === null) {
|
|
18394
|
+
this.returnExpression = UNKNOWN_RETURN_EXPRESSION;
|
|
18395
|
+
return (this.returnExpression = this.tag.getReturnExpressionWhenCalledAtPath(EMPTY_PATH, this.interaction, recursionTracker, this));
|
|
18008
18396
|
}
|
|
18009
|
-
this.
|
|
18397
|
+
return this.returnExpression;
|
|
18010
18398
|
}
|
|
18011
18399
|
}
|
|
18012
|
-
|
|
18013
|
-
TryStatement.prototype.applyDeoptimizations = doNotDeoptimize;
|
|
18400
|
+
TaggedTemplateExpression.prototype.includeNode = onlyIncludeSelf;
|
|
18014
18401
|
|
|
18015
|
-
|
|
18016
|
-
|
|
18017
|
-
|
|
18018
|
-
'-': value => -value,
|
|
18019
|
-
delete: () => UnknownValue,
|
|
18020
|
-
typeof: value => typeof value,
|
|
18021
|
-
void: () => undefined,
|
|
18022
|
-
'~': value => ~value
|
|
18023
|
-
};
|
|
18024
|
-
const UNASSIGNED = Symbol('Unassigned');
|
|
18025
|
-
class UnaryExpression extends NodeBase {
|
|
18026
|
-
constructor() {
|
|
18027
|
-
super(...arguments);
|
|
18028
|
-
this.renderedLiteralValue = UNASSIGNED;
|
|
18402
|
+
class TemplateElement extends NodeBase {
|
|
18403
|
+
get tail() {
|
|
18404
|
+
return isFlagSet(this.flags, 1048576 /* Flag.tail */);
|
|
18029
18405
|
}
|
|
18030
|
-
|
|
18031
|
-
|
|
18406
|
+
set tail(value) {
|
|
18407
|
+
this.flags = setFlag(this.flags, 1048576 /* Flag.tail */, value);
|
|
18032
18408
|
}
|
|
18033
|
-
|
|
18034
|
-
|
|
18409
|
+
// Do not try to bind value
|
|
18410
|
+
bind() { }
|
|
18411
|
+
hasEffects() {
|
|
18412
|
+
return false;
|
|
18035
18413
|
}
|
|
18036
|
-
|
|
18037
|
-
this.
|
|
18414
|
+
parseNode(esTreeNode) {
|
|
18415
|
+
this.value = esTreeNode.value;
|
|
18416
|
+
return super.parseNode(esTreeNode);
|
|
18038
18417
|
}
|
|
18039
|
-
|
|
18040
|
-
|
|
18041
|
-
|
|
18042
|
-
|
|
18043
|
-
|
|
18044
|
-
|
|
18045
|
-
|
|
18046
|
-
|
|
18047
|
-
if (argumentValue === UnknownFalsyValue)
|
|
18048
|
-
return true;
|
|
18049
|
-
if (argumentValue === UnknownTruthyValue)
|
|
18050
|
-
return false;
|
|
18051
|
-
}
|
|
18418
|
+
render() { }
|
|
18419
|
+
}
|
|
18420
|
+
TemplateElement.prototype.includeNode = onlyIncludeSelf;
|
|
18421
|
+
|
|
18422
|
+
class TemplateLiteral extends NodeBase {
|
|
18423
|
+
deoptimizeArgumentsOnInteractionAtPath() { }
|
|
18424
|
+
getLiteralValueAtPath(path) {
|
|
18425
|
+
if (path.length > 0 || this.quasis.length !== 1) {
|
|
18052
18426
|
return UnknownValue;
|
|
18053
18427
|
}
|
|
18054
|
-
return
|
|
18055
|
-
}
|
|
18056
|
-
hasEffects(context) {
|
|
18057
|
-
if (!this.deoptimized)
|
|
18058
|
-
this.applyDeoptimizations();
|
|
18059
|
-
if (this.operator === 'typeof' && this.argument instanceof Identifier)
|
|
18060
|
-
return false;
|
|
18061
|
-
return (this.argument.hasEffects(context) ||
|
|
18062
|
-
(this.operator === 'delete' &&
|
|
18063
|
-
this.argument.hasEffectsOnInteractionAtPath(EMPTY_PATH, NODE_INTERACTION_UNKNOWN_ASSIGNMENT, context)));
|
|
18064
|
-
}
|
|
18065
|
-
hasEffectsOnInteractionAtPath(path, { type }) {
|
|
18066
|
-
return type !== INTERACTION_ACCESSED || path.length > (this.operator === 'void' ? 0 : 1);
|
|
18428
|
+
return this.quasis[0].value.cooked;
|
|
18067
18429
|
}
|
|
18068
|
-
|
|
18069
|
-
|
|
18070
|
-
|
|
18071
|
-
this.argument.deoptimizePath(EMPTY_PATH);
|
|
18072
|
-
this.scope.context.requestTreeshakingPass();
|
|
18430
|
+
getReturnExpressionWhenCalledAtPath(path) {
|
|
18431
|
+
if (path.length !== 1) {
|
|
18432
|
+
return UNKNOWN_RETURN_EXPRESSION;
|
|
18073
18433
|
}
|
|
18434
|
+
return getMemberReturnExpressionWhenCalled(literalStringMembers, path[0]);
|
|
18074
18435
|
}
|
|
18075
|
-
|
|
18076
|
-
if (
|
|
18077
|
-
return
|
|
18078
|
-
|
|
18079
|
-
|
|
18080
|
-
|
|
18436
|
+
hasEffectsOnInteractionAtPath(path, interaction, context) {
|
|
18437
|
+
if (interaction.type === INTERACTION_ACCESSED) {
|
|
18438
|
+
return path.length > 1;
|
|
18439
|
+
}
|
|
18440
|
+
if (interaction.type === INTERACTION_CALLED && path.length === 1) {
|
|
18441
|
+
return hasMemberEffectWhenCalled(literalStringMembers, path[0], interaction, context);
|
|
18442
|
+
}
|
|
18443
|
+
return true;
|
|
18081
18444
|
}
|
|
18082
|
-
|
|
18445
|
+
includeNode(context) {
|
|
18446
|
+
this.included = true;
|
|
18083
18447
|
if (!this.deoptimized)
|
|
18084
18448
|
this.applyDeoptimizations();
|
|
18085
|
-
this.
|
|
18086
|
-
|
|
18087
|
-
const shouldPreserveArgument = this.argument instanceof Identifier && this.argument.variable?.included;
|
|
18088
|
-
if (typeof this.getRenderedLiteralValue(includeChildrenRecursively) === 'symbol' ||
|
|
18089
|
-
this.argument.shouldBeIncluded(context) ||
|
|
18090
|
-
shouldPreserveArgument) {
|
|
18091
|
-
this.argument.include(context, includeChildrenRecursively);
|
|
18092
|
-
this.renderedLiteralValue = UnknownValue;
|
|
18449
|
+
for (const node of this.expressions) {
|
|
18450
|
+
node.includePath(UNKNOWN_PATH, context);
|
|
18093
18451
|
}
|
|
18094
18452
|
}
|
|
18095
18453
|
render(code, options) {
|
|
18096
|
-
|
|
18097
|
-
|
|
18098
|
-
}
|
|
18099
|
-
else {
|
|
18100
|
-
let value = this.renderedLiteralValue;
|
|
18101
|
-
if (!CHARACTERS_THAT_DO_NOT_REQUIRE_SPACE.test(code.original[this.start - 1])) {
|
|
18102
|
-
value = ` ${value}`;
|
|
18103
|
-
}
|
|
18104
|
-
code.overwrite(this.start, this.end, value);
|
|
18105
|
-
}
|
|
18454
|
+
this.scope.context.addIndentExclusionRange([this.start, this.end]);
|
|
18455
|
+
super.render(code, options);
|
|
18106
18456
|
}
|
|
18107
18457
|
}
|
|
18108
|
-
const CHARACTERS_THAT_DO_NOT_REQUIRE_SPACE = /[\s([=%&*+-/<>^|,?:;]/;
|
|
18109
|
-
UnaryExpression.prototype.includeNode = onlyIncludeSelf;
|
|
18110
18458
|
|
|
18111
|
-
class
|
|
18112
|
-
|
|
18113
|
-
|
|
18114
|
-
|
|
18115
|
-
|
|
18459
|
+
class ModuleScope extends ChildScope {
|
|
18460
|
+
constructor(parent, context, importDescriptions) {
|
|
18461
|
+
super(parent, context);
|
|
18462
|
+
this.importDescriptions = importDescriptions;
|
|
18463
|
+
this.variables.set('this', new LocalVariable('this', null, UNDEFINED_EXPRESSION, EMPTY_PATH, context, 'other'));
|
|
18116
18464
|
}
|
|
18117
|
-
|
|
18118
|
-
|
|
18465
|
+
addDeclaration(identifier, context, init, destructuredInitPath, kind) {
|
|
18466
|
+
if (this.importDescriptions.has(identifier.name)) {
|
|
18467
|
+
context.error(parseAst_js.logRedeclarationError(identifier.name), identifier.start);
|
|
18468
|
+
}
|
|
18469
|
+
return super.addDeclaration(identifier, context, init, destructuredInitPath, kind);
|
|
18119
18470
|
}
|
|
18120
|
-
|
|
18121
|
-
|
|
18122
|
-
|
|
18123
|
-
|
|
18471
|
+
addExportDefaultDeclaration(exportDefaultDeclaration, context) {
|
|
18472
|
+
const variable = new ExportDefaultVariable(exportDefaultDeclaration, context);
|
|
18473
|
+
this.variables.set('default', variable);
|
|
18474
|
+
return variable;
|
|
18124
18475
|
}
|
|
18125
|
-
|
|
18126
|
-
|
|
18127
|
-
|
|
18476
|
+
addNamespaceMemberAccess() { }
|
|
18477
|
+
deconflict(format, exportNamesByVariable, accessedGlobalsByScope) {
|
|
18478
|
+
// all module level variables are already deconflicted when deconflicting the chunk
|
|
18479
|
+
for (const scope of this.children)
|
|
18480
|
+
scope.deconflict(format, exportNamesByVariable, accessedGlobalsByScope);
|
|
18128
18481
|
}
|
|
18129
|
-
|
|
18130
|
-
|
|
18131
|
-
this.argument.render(code, options);
|
|
18132
|
-
if (format === 'system') {
|
|
18133
|
-
const variable = this.argument.variable;
|
|
18134
|
-
const exportNames = exportNamesByVariable.get(variable);
|
|
18135
|
-
if (exportNames) {
|
|
18136
|
-
if (this.prefix) {
|
|
18137
|
-
if (exportNames.length === 1) {
|
|
18138
|
-
renderSystemExportExpression(variable, this.start, this.end, code, options);
|
|
18139
|
-
}
|
|
18140
|
-
else {
|
|
18141
|
-
renderSystemExportSequenceAfterExpression(variable, this.start, this.end, this.parent.type !== parseAst_js.ExpressionStatement, code, options);
|
|
18142
|
-
}
|
|
18143
|
-
}
|
|
18144
|
-
else {
|
|
18145
|
-
const operator = this.operator[0];
|
|
18146
|
-
renderSystemExportSequenceBeforeExpression(variable, this.start, this.end, this.parent.type !== parseAst_js.ExpressionStatement, code, options, `${_}${operator}${_}1`);
|
|
18147
|
-
}
|
|
18148
|
-
}
|
|
18149
|
-
}
|
|
18482
|
+
findLexicalBoundary() {
|
|
18483
|
+
return this;
|
|
18150
18484
|
}
|
|
18151
|
-
|
|
18152
|
-
this.
|
|
18153
|
-
|
|
18154
|
-
|
|
18155
|
-
const variable = this.scope.findVariable(this.argument.name);
|
|
18156
|
-
variable.markReassigned();
|
|
18485
|
+
findVariable(name) {
|
|
18486
|
+
const knownVariable = this.variables.get(name) || this.accessedOutsideVariables.get(name);
|
|
18487
|
+
if (knownVariable) {
|
|
18488
|
+
return knownVariable;
|
|
18157
18489
|
}
|
|
18158
|
-
this.
|
|
18490
|
+
const variable = this.context.traceVariable(name) || this.parent.findVariable(name);
|
|
18491
|
+
if (variable instanceof GlobalVariable) {
|
|
18492
|
+
this.accessedOutsideVariables.set(name, variable);
|
|
18493
|
+
}
|
|
18494
|
+
return variable;
|
|
18159
18495
|
}
|
|
18160
18496
|
}
|
|
18161
|
-
UpdateExpression.prototype.includeNode = onlyIncludeSelf;
|
|
18162
|
-
|
|
18163
|
-
function isReassignedExportsMember(variable, exportNamesByVariable) {
|
|
18164
|
-
return (variable.renderBaseName !== null && exportNamesByVariable.has(variable) && variable.isReassigned);
|
|
18165
|
-
}
|
|
18166
18497
|
|
|
18167
|
-
class
|
|
18168
|
-
|
|
18169
|
-
|
|
18170
|
-
|
|
18498
|
+
class ThisExpression extends NodeBase {
|
|
18499
|
+
bind() {
|
|
18500
|
+
this.variable = this.scope.findVariable('this');
|
|
18501
|
+
}
|
|
18502
|
+
deoptimizeArgumentsOnInteractionAtPath(interaction, path, recursionTracker) {
|
|
18503
|
+
this.variable.deoptimizeArgumentsOnInteractionAtPath(interaction, path, recursionTracker);
|
|
18504
|
+
}
|
|
18505
|
+
deoptimizePath(path) {
|
|
18506
|
+
this.variable.deoptimizePath(path);
|
|
18507
|
+
}
|
|
18508
|
+
hasEffectsOnInteractionAtPath(path, interaction, context) {
|
|
18509
|
+
if (path.length === 0) {
|
|
18510
|
+
return interaction.type !== INTERACTION_ACCESSED;
|
|
18171
18511
|
}
|
|
18512
|
+
return this.variable.hasEffectsOnInteractionAtPath(path, interaction, context);
|
|
18172
18513
|
}
|
|
18173
|
-
|
|
18174
|
-
|
|
18514
|
+
include(context) {
|
|
18515
|
+
if (!this.included)
|
|
18516
|
+
this.includeNode(context);
|
|
18175
18517
|
}
|
|
18176
|
-
|
|
18518
|
+
includeNode(context) {
|
|
18177
18519
|
this.included = true;
|
|
18178
|
-
|
|
18179
|
-
|
|
18180
|
-
|
|
18181
|
-
|
|
18182
|
-
|
|
18183
|
-
|
|
18184
|
-
|
|
18185
|
-
|
|
18186
|
-
|
|
18187
|
-
|
|
18188
|
-
|
|
18189
|
-
|
|
18190
|
-
|
|
18191
|
-
|
|
18520
|
+
if (!this.deoptimized)
|
|
18521
|
+
this.applyDeoptimizations();
|
|
18522
|
+
this.scope.context.includeVariableInModule(this.variable, EMPTY_PATH, context);
|
|
18523
|
+
}
|
|
18524
|
+
includePath(path, context) {
|
|
18525
|
+
if (!this.included) {
|
|
18526
|
+
this.included = true;
|
|
18527
|
+
this.scope.context.includeVariableInModule(this.variable, path, context);
|
|
18528
|
+
}
|
|
18529
|
+
else if (path.length > 0) {
|
|
18530
|
+
this.variable.includePath(path, context);
|
|
18531
|
+
}
|
|
18532
|
+
const functionScope = findFunctionScope(this.scope, this.variable);
|
|
18533
|
+
if (functionScope &&
|
|
18534
|
+
functionScope.functionNode.parent instanceof Property &&
|
|
18535
|
+
functionScope.functionNode.parent.parent instanceof ObjectExpression) {
|
|
18536
|
+
functionScope.functionNode.parent.parent.includePath(path, context);
|
|
18192
18537
|
}
|
|
18193
18538
|
}
|
|
18194
18539
|
initialise() {
|
|
18195
18540
|
super.initialise();
|
|
18196
|
-
|
|
18197
|
-
|
|
18198
|
-
|
|
18199
|
-
|
|
18541
|
+
this.alias =
|
|
18542
|
+
this.scope.findLexicalBoundary() instanceof ModuleScope
|
|
18543
|
+
? this.scope.context.moduleContext
|
|
18544
|
+
: null;
|
|
18545
|
+
if (this.alias === 'undefined') {
|
|
18546
|
+
this.scope.context.log(parseAst_js.LOGLEVEL_WARN, parseAst_js.logThisIsUndefined(), this.start);
|
|
18200
18547
|
}
|
|
18201
18548
|
}
|
|
18202
|
-
|
|
18203
|
-
this.
|
|
18204
|
-
|
|
18205
|
-
|
|
18206
|
-
|
|
18207
|
-
|
|
18208
|
-
declarator.render(code, options);
|
|
18209
|
-
}
|
|
18210
|
-
if (!nodeRenderOptions.isNoStatement &&
|
|
18211
|
-
code.original.charCodeAt(this.end - 1) !== 59 /*";"*/) {
|
|
18212
|
-
code.appendLeft(this.end, ';');
|
|
18213
|
-
}
|
|
18214
|
-
}
|
|
18215
|
-
else {
|
|
18216
|
-
this.renderReplacedDeclarations(code, options);
|
|
18549
|
+
render(code) {
|
|
18550
|
+
if (this.alias !== null) {
|
|
18551
|
+
code.overwrite(this.start, this.end, this.alias, {
|
|
18552
|
+
contentOnly: false,
|
|
18553
|
+
storeName: true
|
|
18554
|
+
});
|
|
18217
18555
|
}
|
|
18218
18556
|
}
|
|
18219
|
-
|
|
18220
|
-
|
|
18221
|
-
|
|
18222
|
-
|
|
18223
|
-
|
|
18224
|
-
if (lastSeparatorPos === null) {
|
|
18225
|
-
code.appendLeft(renderedContentEnd, separatorString);
|
|
18226
|
-
}
|
|
18227
|
-
else {
|
|
18228
|
-
if (code.original.charCodeAt(actualContentEnd - 1) === 10 /*"\n"*/ &&
|
|
18229
|
-
(code.original.charCodeAt(this.end) === 10 /*"\n"*/ ||
|
|
18230
|
-
code.original.charCodeAt(this.end) === 13) /*"\r"*/) {
|
|
18231
|
-
actualContentEnd--;
|
|
18232
|
-
if (code.original.charCodeAt(actualContentEnd) === 13 /*"\r"*/) {
|
|
18233
|
-
actualContentEnd--;
|
|
18234
|
-
}
|
|
18235
|
-
}
|
|
18236
|
-
if (actualContentEnd === lastSeparatorPos + 1) {
|
|
18237
|
-
code.overwrite(lastSeparatorPos, renderedContentEnd, separatorString);
|
|
18238
|
-
}
|
|
18239
|
-
else {
|
|
18240
|
-
code.overwrite(lastSeparatorPos, lastSeparatorPos + 1, separatorString);
|
|
18241
|
-
code.remove(actualContentEnd, renderedContentEnd);
|
|
18242
|
-
}
|
|
18243
|
-
}
|
|
18244
|
-
if (systemPatternExports.length > 0) {
|
|
18245
|
-
code.appendLeft(renderedContentEnd, ` ${getSystemExportStatement(systemPatternExports, options)};`);
|
|
18557
|
+
}
|
|
18558
|
+
function findFunctionScope(scope, thisVariable) {
|
|
18559
|
+
while (!(scope instanceof FunctionScope && scope.thisVariable === thisVariable)) {
|
|
18560
|
+
if (!(scope instanceof ChildScope)) {
|
|
18561
|
+
return null;
|
|
18246
18562
|
}
|
|
18563
|
+
scope = scope.parent;
|
|
18247
18564
|
}
|
|
18248
|
-
|
|
18249
|
-
|
|
18250
|
-
|
|
18251
|
-
|
|
18252
|
-
|
|
18253
|
-
|
|
18254
|
-
let isInDeclaration = false;
|
|
18255
|
-
let hasRenderedContent = false;
|
|
18256
|
-
let separatorString = '', leadingString, nextSeparatorString;
|
|
18257
|
-
const aggregatedSystemExports = [];
|
|
18258
|
-
const singleSystemExport = gatherSystemExportsAndGetSingleExport(separatedNodes, options, aggregatedSystemExports);
|
|
18259
|
-
for (const { node, start, separator, contentEnd, end } of separatedNodes) {
|
|
18260
|
-
if (!node.included) {
|
|
18261
|
-
treeshakeNode(node, code, start, end);
|
|
18262
|
-
continue;
|
|
18263
|
-
}
|
|
18264
|
-
node.render(code, options);
|
|
18265
|
-
leadingString = '';
|
|
18266
|
-
nextSeparatorString = '';
|
|
18267
|
-
if (!node.id.included ||
|
|
18268
|
-
(node.id instanceof Identifier &&
|
|
18269
|
-
isReassignedExportsMember(node.id.variable, options.exportNamesByVariable))) {
|
|
18270
|
-
if (hasRenderedContent) {
|
|
18271
|
-
separatorString += ';';
|
|
18272
|
-
}
|
|
18273
|
-
isInDeclaration = false;
|
|
18274
|
-
}
|
|
18275
|
-
else {
|
|
18276
|
-
if (singleSystemExport && singleSystemExport === node.id.variable) {
|
|
18277
|
-
const operatorPos = findFirstOccurrenceOutsideComment(code.original, '=', node.id.end);
|
|
18278
|
-
renderSystemExportExpression(singleSystemExport, findNonWhiteSpace(code.original, operatorPos + 1), separator === null ? contentEnd : separator, code, options);
|
|
18279
|
-
}
|
|
18280
|
-
if (isInDeclaration) {
|
|
18281
|
-
separatorString += ',';
|
|
18282
|
-
}
|
|
18283
|
-
else {
|
|
18284
|
-
if (hasRenderedContent) {
|
|
18285
|
-
separatorString += ';';
|
|
18286
|
-
}
|
|
18287
|
-
leadingString += `${this.kind} `;
|
|
18288
|
-
isInDeclaration = true;
|
|
18289
|
-
}
|
|
18290
|
-
}
|
|
18291
|
-
if (renderedContentEnd === lastSeparatorPos + 1) {
|
|
18292
|
-
code.overwrite(lastSeparatorPos, renderedContentEnd, separatorString + leadingString);
|
|
18293
|
-
}
|
|
18294
|
-
else {
|
|
18295
|
-
code.overwrite(lastSeparatorPos, lastSeparatorPos + 1, separatorString);
|
|
18296
|
-
code.appendLeft(renderedContentEnd, leadingString);
|
|
18297
|
-
}
|
|
18298
|
-
actualContentEnd = contentEnd;
|
|
18299
|
-
renderedContentEnd = end;
|
|
18300
|
-
hasRenderedContent = true;
|
|
18301
|
-
lastSeparatorPos = separator;
|
|
18302
|
-
separatorString = nextSeparatorString;
|
|
18303
|
-
}
|
|
18304
|
-
this.renderDeclarationEnd(code, separatorString, lastSeparatorPos, actualContentEnd, renderedContentEnd, aggregatedSystemExports, options);
|
|
18565
|
+
return scope;
|
|
18566
|
+
}
|
|
18567
|
+
|
|
18568
|
+
class ThrowStatement extends NodeBase {
|
|
18569
|
+
hasEffects() {
|
|
18570
|
+
return true;
|
|
18305
18571
|
}
|
|
18306
|
-
|
|
18307
|
-
if (this.
|
|
18308
|
-
|
|
18572
|
+
include(context, includeChildrenRecursively) {
|
|
18573
|
+
if (!this.included)
|
|
18574
|
+
this.includeNode(context);
|
|
18575
|
+
this.argument.include(context, includeChildrenRecursively);
|
|
18576
|
+
context.brokenFlow = true;
|
|
18577
|
+
}
|
|
18578
|
+
includeNode(context) {
|
|
18579
|
+
if (!this.included) {
|
|
18580
|
+
this.included = true;
|
|
18581
|
+
this.argument.includePath(UNKNOWN_PATH, context);
|
|
18309
18582
|
}
|
|
18310
|
-
|
|
18311
|
-
|
|
18312
|
-
|
|
18313
|
-
|
|
18314
|
-
|
|
18315
|
-
return false;
|
|
18316
|
-
}
|
|
18317
|
-
else {
|
|
18318
|
-
const exportedVariables = [];
|
|
18319
|
-
declarator.id.addExportedVariables(exportedVariables, exportNamesByVariable);
|
|
18320
|
-
if (exportedVariables.length > 0)
|
|
18321
|
-
return false;
|
|
18322
|
-
}
|
|
18583
|
+
}
|
|
18584
|
+
render(code, options) {
|
|
18585
|
+
this.argument.render(code, options, { preventASI: true });
|
|
18586
|
+
if (this.argument.start === this.start + 5 /* 'throw'.length */) {
|
|
18587
|
+
code.prependLeft(this.start + 5, ' ');
|
|
18323
18588
|
}
|
|
18324
|
-
return true;
|
|
18325
18589
|
}
|
|
18326
18590
|
}
|
|
18327
|
-
|
|
18328
|
-
|
|
18329
|
-
|
|
18330
|
-
|
|
18331
|
-
|
|
18332
|
-
|
|
18333
|
-
|
|
18334
|
-
|
|
18335
|
-
|
|
18336
|
-
|
|
18337
|
-
|
|
18338
|
-
|
|
18339
|
-
|
|
18591
|
+
|
|
18592
|
+
class TryStatement extends NodeBase {
|
|
18593
|
+
constructor() {
|
|
18594
|
+
super(...arguments);
|
|
18595
|
+
this.directlyIncluded = false;
|
|
18596
|
+
this.includedLabelsAfterBlock = null;
|
|
18597
|
+
}
|
|
18598
|
+
hasEffects(context) {
|
|
18599
|
+
return ((this.scope.context.options.treeshake.tryCatchDeoptimization
|
|
18600
|
+
? this.block.body.length > 0
|
|
18601
|
+
: this.block.hasEffects(context)) || !!this.finalizer?.hasEffects(context));
|
|
18602
|
+
}
|
|
18603
|
+
include(context, includeChildrenRecursively) {
|
|
18604
|
+
const tryCatchDeoptimization = this.scope.context.options.treeshake?.tryCatchDeoptimization;
|
|
18605
|
+
const { brokenFlow, includedLabels } = context;
|
|
18606
|
+
if (!this.directlyIncluded || !tryCatchDeoptimization) {
|
|
18607
|
+
this.included = true;
|
|
18608
|
+
this.directlyIncluded = true;
|
|
18609
|
+
this.block.include(context, tryCatchDeoptimization ? INCLUDE_PARAMETERS : includeChildrenRecursively);
|
|
18610
|
+
if (includedLabels.size > 0) {
|
|
18611
|
+
this.includedLabelsAfterBlock = [...includedLabels];
|
|
18340
18612
|
}
|
|
18613
|
+
context.brokenFlow = brokenFlow;
|
|
18341
18614
|
}
|
|
18342
|
-
if (
|
|
18343
|
-
|
|
18615
|
+
else if (this.includedLabelsAfterBlock) {
|
|
18616
|
+
for (const label of this.includedLabelsAfterBlock) {
|
|
18617
|
+
includedLabels.add(label);
|
|
18618
|
+
}
|
|
18344
18619
|
}
|
|
18345
|
-
|
|
18346
|
-
|
|
18620
|
+
if (this.handler !== null) {
|
|
18621
|
+
this.handler.include(context, includeChildrenRecursively);
|
|
18622
|
+
context.brokenFlow = brokenFlow;
|
|
18347
18623
|
}
|
|
18624
|
+
this.finalizer?.include(context, includeChildrenRecursively);
|
|
18348
18625
|
}
|
|
18349
|
-
return singleSystemExport;
|
|
18350
18626
|
}
|
|
18351
|
-
|
|
18352
|
-
|
|
18627
|
+
TryStatement.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
|
|
18628
|
+
TryStatement.prototype.applyDeoptimizations = doNotDeoptimize;
|
|
18353
18629
|
|
|
18354
|
-
|
|
18355
|
-
|
|
18356
|
-
|
|
18357
|
-
|
|
18358
|
-
|
|
18630
|
+
const unaryOperators = {
|
|
18631
|
+
'!': value => !value,
|
|
18632
|
+
'+': value => +value,
|
|
18633
|
+
'-': value => -value,
|
|
18634
|
+
delete: () => UnknownValue,
|
|
18635
|
+
typeof: value => typeof value,
|
|
18636
|
+
void: () => undefined,
|
|
18637
|
+
'~': value => ~value
|
|
18638
|
+
};
|
|
18639
|
+
const UNASSIGNED = Symbol('Unassigned');
|
|
18640
|
+
class UnaryExpression extends NodeBase {
|
|
18641
|
+
constructor() {
|
|
18642
|
+
super(...arguments);
|
|
18643
|
+
this.renderedLiteralValue = UNASSIGNED;
|
|
18359
18644
|
}
|
|
18360
|
-
|
|
18361
|
-
this.
|
|
18645
|
+
get prefix() {
|
|
18646
|
+
return isFlagSet(this.flags, 2097152 /* Flag.prefix */);
|
|
18647
|
+
}
|
|
18648
|
+
set prefix(value) {
|
|
18649
|
+
this.flags = setFlag(this.flags, 2097152 /* Flag.prefix */, value);
|
|
18362
18650
|
}
|
|
18363
18651
|
deoptimizeCache() {
|
|
18364
|
-
|
|
18365
|
-
|
|
18366
|
-
|
|
18367
|
-
|
|
18368
|
-
|
|
18652
|
+
this.renderedLiteralValue = UnknownValue;
|
|
18653
|
+
}
|
|
18654
|
+
getLiteralValueAtPath(path, recursionTracker, origin) {
|
|
18655
|
+
if (path.length > 0)
|
|
18656
|
+
return UnknownValue;
|
|
18657
|
+
const argumentValue = this.argument.getLiteralValueAtPath(EMPTY_PATH, recursionTracker, origin);
|
|
18658
|
+
if (typeof argumentValue === 'symbol') {
|
|
18659
|
+
if (this.operator === 'void')
|
|
18660
|
+
return undefined;
|
|
18661
|
+
if (this.operator === '!') {
|
|
18662
|
+
if (argumentValue === UnknownFalsyValue)
|
|
18663
|
+
return true;
|
|
18664
|
+
if (argumentValue === UnknownTruthyValue)
|
|
18665
|
+
return false;
|
|
18666
|
+
}
|
|
18667
|
+
return UnknownValue;
|
|
18369
18668
|
}
|
|
18669
|
+
return unaryOperators[this.operator](argumentValue);
|
|
18370
18670
|
}
|
|
18371
18671
|
hasEffects(context) {
|
|
18372
|
-
|
|
18373
|
-
|
|
18374
|
-
|
|
18375
|
-
|
|
18376
|
-
|
|
18377
|
-
this.
|
|
18378
|
-
|
|
18379
|
-
.propertyReadSideEffects &&
|
|
18380
|
-
this.id.hasEffectsWhenDestructuring(context, EMPTY_PATH, this.init || UNDEFINED_EXPRESSION)));
|
|
18672
|
+
if (!this.deoptimized)
|
|
18673
|
+
this.applyDeoptimizations();
|
|
18674
|
+
if (this.operator === 'typeof' && this.argument instanceof Identifier)
|
|
18675
|
+
return false;
|
|
18676
|
+
return (this.argument.hasEffects(context) ||
|
|
18677
|
+
(this.operator === 'delete' &&
|
|
18678
|
+
this.argument.hasEffectsOnInteractionAtPath(EMPTY_PATH, NODE_INTERACTION_UNKNOWN_ASSIGNMENT, context)));
|
|
18381
18679
|
}
|
|
18382
|
-
|
|
18383
|
-
|
|
18384
|
-
|
|
18385
|
-
|
|
18386
|
-
|
|
18387
|
-
|
|
18388
|
-
|
|
18389
|
-
|
|
18390
|
-
}
|
|
18391
|
-
init?.include(context, includeChildrenRecursively);
|
|
18392
|
-
id.markDeclarationReached();
|
|
18393
|
-
if (includeChildrenRecursively) {
|
|
18394
|
-
id.include(context, includeChildrenRecursively);
|
|
18395
|
-
}
|
|
18396
|
-
else {
|
|
18397
|
-
id.includeDestructuredIfNecessary(context, EMPTY_PATH, init || UNDEFINED_EXPRESSION);
|
|
18680
|
+
hasEffectsOnInteractionAtPath(path, { type }) {
|
|
18681
|
+
return type !== INTERACTION_ACCESSED || path.length > (this.operator === 'void' ? 0 : 1);
|
|
18682
|
+
}
|
|
18683
|
+
applyDeoptimizations() {
|
|
18684
|
+
this.deoptimized = true;
|
|
18685
|
+
if (this.operator === 'delete') {
|
|
18686
|
+
this.argument.deoptimizePath(EMPTY_PATH);
|
|
18687
|
+
this.scope.context.requestTreeshakingPass();
|
|
18398
18688
|
}
|
|
18399
18689
|
}
|
|
18400
|
-
|
|
18401
|
-
this.
|
|
18690
|
+
getRenderedLiteralValue(includeChildrenRecursively) {
|
|
18691
|
+
if (this.renderedLiteralValue !== UNASSIGNED)
|
|
18692
|
+
return this.renderedLiteralValue;
|
|
18693
|
+
return (this.renderedLiteralValue = includeChildrenRecursively
|
|
18694
|
+
? UnknownValue
|
|
18695
|
+
: getRenderedLiteralValue(this.getLiteralValueAtPath(EMPTY_PATH, SHARED_RECURSION_TRACKER, this)));
|
|
18696
|
+
}
|
|
18697
|
+
include(context, includeChildrenRecursively, _options) {
|
|
18698
|
+
if (!this.deoptimized)
|
|
18699
|
+
this.applyDeoptimizations();
|
|
18700
|
+
this.included = true;
|
|
18701
|
+
// Check if the argument is an identifier that should be preserved as a reference for readability
|
|
18702
|
+
const shouldPreserveArgument = this.argument instanceof Identifier && this.argument.variable?.included;
|
|
18703
|
+
if (typeof this.getRenderedLiteralValue(includeChildrenRecursively) === 'symbol' ||
|
|
18704
|
+
this.argument.shouldBeIncluded(context) ||
|
|
18705
|
+
shouldPreserveArgument) {
|
|
18706
|
+
this.argument.include(context, includeChildrenRecursively);
|
|
18707
|
+
this.renderedLiteralValue = UnknownValue;
|
|
18708
|
+
}
|
|
18402
18709
|
}
|
|
18403
18710
|
render(code, options) {
|
|
18404
|
-
|
|
18405
|
-
|
|
18406
|
-
const renderId = id.included || this.isUsingDeclaration || this.isAsyncUsingDeclaration;
|
|
18407
|
-
if (renderId) {
|
|
18408
|
-
id.render(code, options);
|
|
18711
|
+
if (typeof this.renderedLiteralValue === 'symbol') {
|
|
18712
|
+
super.render(code, options);
|
|
18409
18713
|
}
|
|
18410
18714
|
else {
|
|
18411
|
-
|
|
18412
|
-
|
|
18413
|
-
|
|
18414
|
-
if (init) {
|
|
18415
|
-
if (id instanceof Identifier && init instanceof ClassExpression && !init.id) {
|
|
18416
|
-
const renderedVariable = id.variable.getName(getPropertyAccess);
|
|
18417
|
-
if (renderedVariable !== id.name) {
|
|
18418
|
-
code.appendLeft(init.start + 5, ` ${id.name}`);
|
|
18419
|
-
}
|
|
18715
|
+
let value = this.renderedLiteralValue;
|
|
18716
|
+
if (!CHARACTERS_THAT_DO_NOT_REQUIRE_SPACE.test(code.original[this.start - 1])) {
|
|
18717
|
+
value = ` ${value}`;
|
|
18420
18718
|
}
|
|
18421
|
-
|
|
18422
|
-
}
|
|
18423
|
-
else if (id instanceof Identifier &&
|
|
18424
|
-
isReassignedExportsMember(id.variable, exportNamesByVariable)) {
|
|
18425
|
-
code.appendLeft(end, `${_}=${_}void 0`);
|
|
18719
|
+
code.overwrite(this.start, this.end, value);
|
|
18426
18720
|
}
|
|
18427
18721
|
}
|
|
18428
|
-
|
|
18429
|
-
|
|
18430
|
-
|
|
18431
|
-
|
|
18432
|
-
|
|
18433
|
-
|
|
18434
|
-
|
|
18435
|
-
|
|
18436
|
-
|
|
18437
|
-
|
|
18438
|
-
|
|
18439
|
-
|
|
18440
|
-
|
|
18441
|
-
|
|
18442
|
-
|
|
18443
|
-
|
|
18444
|
-
|
|
18445
|
-
|
|
18446
|
-
|
|
18447
|
-
|
|
18722
|
+
}
|
|
18723
|
+
const CHARACTERS_THAT_DO_NOT_REQUIRE_SPACE = /[\s([=%&*+-/<>^|,?:;]/;
|
|
18724
|
+
UnaryExpression.prototype.includeNode = onlyIncludeSelf;
|
|
18725
|
+
|
|
18726
|
+
class UpdateExpression extends NodeBase {
|
|
18727
|
+
hasEffects(context) {
|
|
18728
|
+
if (!this.deoptimized)
|
|
18729
|
+
this.applyDeoptimizations();
|
|
18730
|
+
return this.argument.hasEffectsAsAssignmentTarget(context, true);
|
|
18731
|
+
}
|
|
18732
|
+
hasEffectsOnInteractionAtPath(path, { type }) {
|
|
18733
|
+
return path.length > 1 || type !== INTERACTION_ACCESSED;
|
|
18734
|
+
}
|
|
18735
|
+
include(context, includeChildrenRecursively) {
|
|
18736
|
+
if (!this.included)
|
|
18737
|
+
this.includeNode(context);
|
|
18738
|
+
this.argument.includeAsAssignmentTarget(context, includeChildrenRecursively, true);
|
|
18739
|
+
}
|
|
18740
|
+
initialise() {
|
|
18741
|
+
super.initialise();
|
|
18742
|
+
this.argument.setAssignedValue(UNKNOWN_EXPRESSION);
|
|
18743
|
+
}
|
|
18744
|
+
render(code, options) {
|
|
18745
|
+
const { exportNamesByVariable, format, snippets: { _ } } = options;
|
|
18746
|
+
this.argument.render(code, options);
|
|
18747
|
+
if (format === 'system') {
|
|
18748
|
+
const variable = this.argument.variable;
|
|
18749
|
+
const exportNames = exportNamesByVariable.get(variable);
|
|
18750
|
+
if (exportNames) {
|
|
18751
|
+
if (this.prefix) {
|
|
18752
|
+
if (exportNames.length === 1) {
|
|
18753
|
+
renderSystemExportExpression(variable, this.start, this.end, code, options);
|
|
18754
|
+
}
|
|
18755
|
+
else {
|
|
18756
|
+
renderSystemExportSequenceAfterExpression(variable, this.start, this.end, this.parent.type !== parseAst_js.ExpressionStatement, code, options);
|
|
18448
18757
|
}
|
|
18449
18758
|
}
|
|
18759
|
+
else {
|
|
18760
|
+
const operator = this.operator[0];
|
|
18761
|
+
renderSystemExportSequenceBeforeExpression(variable, this.start, this.end, this.parent.type !== parseAst_js.ExpressionStatement, code, options, `${_}${operator}${_}1`);
|
|
18762
|
+
}
|
|
18450
18763
|
}
|
|
18451
18764
|
}
|
|
18452
18765
|
}
|
|
18453
|
-
|
|
18454
|
-
|
|
18455
|
-
|
|
18456
|
-
|
|
18457
|
-
|
|
18458
|
-
|
|
18459
|
-
if (disposalValue !== null && disposalValue !== undefined) {
|
|
18460
|
-
init.deoptimizeArgumentsOnInteractionAtPath(call, path, SHARED_RECURSION_TRACKER);
|
|
18461
|
-
init.includeCallArgumentsWhenCalledAtPath(path, call, context);
|
|
18462
|
-
}
|
|
18463
|
-
return false;
|
|
18766
|
+
applyDeoptimizations() {
|
|
18767
|
+
this.deoptimized = true;
|
|
18768
|
+
this.argument.deoptimizePath(EMPTY_PATH);
|
|
18769
|
+
if (this.argument instanceof Identifier) {
|
|
18770
|
+
const variable = this.scope.findVariable(this.argument.name);
|
|
18771
|
+
variable.markReassigned();
|
|
18464
18772
|
}
|
|
18465
|
-
this.
|
|
18466
|
-
this.disposalCall = call;
|
|
18467
|
-
disposalFunction.deoptimizeArgumentsOnInteractionAtPath(call, EMPTY_PATH, SHARED_RECURSION_TRACKER);
|
|
18468
|
-
return true;
|
|
18773
|
+
this.scope.context.requestTreeshakingPass();
|
|
18469
18774
|
}
|
|
18470
18775
|
}
|
|
18471
|
-
|
|
18472
|
-
const SYMBOL_DISPOSE_PATH = [SymbolDispose];
|
|
18473
|
-
const SYMBOL_ASYNC_DISPOSE_PATH = [SymbolAsyncDispose];
|
|
18776
|
+
UpdateExpression.prototype.includeNode = onlyIncludeSelf;
|
|
18474
18777
|
|
|
18475
18778
|
class WhileStatement extends NodeBase {
|
|
18476
18779
|
hasEffects(context) {
|
|
@@ -19862,13 +20165,15 @@ class Module {
|
|
|
19862
20165
|
code: null,
|
|
19863
20166
|
get dynamicallyImportedIdResolutions() {
|
|
19864
20167
|
return dynamicImports
|
|
19865
|
-
.map(({
|
|
19866
|
-
.filter(
|
|
20168
|
+
.map(({ resolution }) => resolution)
|
|
20169
|
+
.filter((resolution) => resolution !== null);
|
|
19867
20170
|
},
|
|
19868
20171
|
get dynamicallyImportedIds() {
|
|
19869
20172
|
// We cannot use this.dynamicDependencies because this is needed before
|
|
19870
20173
|
// dynamicDependencies are populated
|
|
19871
|
-
return dynamicImports
|
|
20174
|
+
return dynamicImports
|
|
20175
|
+
.map(({ resolution }) => resolution?.id)
|
|
20176
|
+
.filter((id) => id != null);
|
|
19872
20177
|
},
|
|
19873
20178
|
get dynamicImporters() {
|
|
19874
20179
|
return dynamicImporters.sort();
|
|
@@ -20427,7 +20732,7 @@ class Module {
|
|
|
20427
20732
|
typeof argument.value === 'string') {
|
|
20428
20733
|
argument = argument.value;
|
|
20429
20734
|
}
|
|
20430
|
-
this.dynamicImports.push({ argument,
|
|
20735
|
+
this.dynamicImports.push({ argument, node, resolution: null });
|
|
20431
20736
|
}
|
|
20432
20737
|
assertUniqueExportName(name, nodeStart) {
|
|
20433
20738
|
if (this.exportDescriptions.has(name) || this.reexportDescriptions.has(name)) {
|
|
@@ -21647,7 +21952,7 @@ class Chunk {
|
|
|
21647
21952
|
needsLiveBinding: (variable.isReassigned && this.exportNamesByVariable.get(variable).length > 1) ||
|
|
21648
21953
|
// Pattern bindings are plain locals; a trailing assignment
|
|
21649
21954
|
// would lose later reassignments.
|
|
21650
|
-
(variable.isTargetOfAssignment &&
|
|
21955
|
+
(variable.isTargetOfAssignment && cannotBeRenderedAsExportsMember(variable))
|
|
21651
21956
|
});
|
|
21652
21957
|
}
|
|
21653
21958
|
return exports;
|
|
@@ -22089,7 +22394,7 @@ class Chunk {
|
|
|
22089
22394
|
format !== 'system' &&
|
|
22090
22395
|
exportVariable.isReassigned &&
|
|
22091
22396
|
!exportVariable.isId &&
|
|
22092
|
-
!
|
|
22397
|
+
!cannotBeRenderedAsExportsMember(exportVariable)) {
|
|
22093
22398
|
exportVariable.setRenderNames('exports', unescapeExportName(exportName));
|
|
22094
22399
|
}
|
|
22095
22400
|
else if (exportVariable instanceof SyntheticNamedExportVariable) {
|
|
@@ -22175,10 +22480,27 @@ class Chunk {
|
|
|
22175
22480
|
function getChunkNameFromModule(module) {
|
|
22176
22481
|
return getPredefinedChunkNameFromModule(module) ?? parseAst_js.getAliasName(module.id);
|
|
22177
22482
|
}
|
|
22483
|
+
function cannotBeRenderedAsExportsMember(variable) {
|
|
22484
|
+
return (isDeclaredInDestructuringPattern(variable) ||
|
|
22485
|
+
isDeclaredInMultiDeclaratorSingleStatement(variable));
|
|
22486
|
+
}
|
|
22178
22487
|
function isDeclaredInDestructuringPattern(variable) {
|
|
22179
22488
|
return (variable instanceof LocalVariable &&
|
|
22180
22489
|
variable.declarations.some(declaration => declaration instanceof Identifier && declaration.isDeclarationInDestructuringPattern()));
|
|
22181
22490
|
}
|
|
22491
|
+
function isDeclaredInMultiDeclaratorSingleStatement(variable) {
|
|
22492
|
+
return (variable instanceof LocalVariable &&
|
|
22493
|
+
variable.declarations.some(declaration => {
|
|
22494
|
+
const declarator = declaration.parent;
|
|
22495
|
+
if (!(declarator instanceof VariableDeclarator) || declarator.id !== declaration) {
|
|
22496
|
+
return false;
|
|
22497
|
+
}
|
|
22498
|
+
const declarationNode = declarator.parent;
|
|
22499
|
+
return (declarationNode instanceof VariableDeclaration &&
|
|
22500
|
+
declarationNode.declarations.length > 1 &&
|
|
22501
|
+
declarationNode.isInSingleStatementPosition());
|
|
22502
|
+
}));
|
|
22503
|
+
}
|
|
22182
22504
|
function getPredefinedChunkNameFromModule(module) {
|
|
22183
22505
|
return (module.chunkNames.find(({ isUserDefined }) => isUserDefined)?.name ?? module.chunkNames[0]?.name);
|
|
22184
22506
|
}
|
|
@@ -23947,19 +24269,12 @@ async function resolveId(source, importer, preserveSymlinks, pluginDriver, modul
|
|
|
23947
24269
|
const pluginResult = await resolveIdViaPlugins(source, importer, pluginDriver, moduleLoaderResolveId, skip, customOptions, isEntry, attributes, importerAttributes);
|
|
23948
24270
|
if (pluginResult != null) {
|
|
23949
24271
|
const [resolveIdResult, plugin] = pluginResult;
|
|
23950
|
-
if (typeof resolveIdResult === 'object' && !resolveIdResult.resolvedBy) {
|
|
23951
|
-
return {
|
|
23952
|
-
...resolveIdResult,
|
|
23953
|
-
resolvedBy: plugin.name
|
|
23954
|
-
};
|
|
23955
|
-
}
|
|
23956
24272
|
if (typeof resolveIdResult === 'string') {
|
|
23957
|
-
return {
|
|
23958
|
-
id: resolveIdResult,
|
|
23959
|
-
resolvedBy: plugin.name
|
|
23960
|
-
};
|
|
24273
|
+
return { id: resolveIdResult, resolvedBy: plugin.name };
|
|
23961
24274
|
}
|
|
23962
|
-
return resolveIdResult
|
|
24275
|
+
return typeof resolveIdResult === 'object'
|
|
24276
|
+
? withDefaultResolvedBy(resolveIdResult, plugin.name)
|
|
24277
|
+
: resolveIdResult;
|
|
23963
24278
|
}
|
|
23964
24279
|
// external modules (non-entry modules that start with neither '.' or '/')
|
|
23965
24280
|
// are skipped at this stage.
|
|
@@ -23993,6 +24308,11 @@ async function findFile(file, preserveSymlinks, fs) {
|
|
|
23993
24308
|
// suppress
|
|
23994
24309
|
}
|
|
23995
24310
|
}
|
|
24311
|
+
function withDefaultResolvedBy(resolution, pluginName) {
|
|
24312
|
+
return resolution.resolvedBy || !pluginName
|
|
24313
|
+
? resolution
|
|
24314
|
+
: { ...resolution, resolvedBy: pluginName };
|
|
24315
|
+
}
|
|
23996
24316
|
|
|
23997
24317
|
function stripBom(content) {
|
|
23998
24318
|
if (content.charCodeAt(0) === 0xfe_ff) {
|
|
@@ -24455,7 +24775,7 @@ class ModuleLoader {
|
|
|
24455
24775
|
}
|
|
24456
24776
|
else {
|
|
24457
24777
|
dynamicImport.node.shouldIncludeDynamicAttributes = !!resolvedId.external;
|
|
24458
|
-
dynamicImport.
|
|
24778
|
+
dynamicImport.resolution = resolvedId;
|
|
24459
24779
|
}
|
|
24460
24780
|
return [dynamicImport, resolvedId];
|
|
24461
24781
|
});
|
|
@@ -24543,11 +24863,13 @@ class ModuleLoader {
|
|
|
24543
24863
|
: { id: resolveIdResult }, parseAst_js.EMPTY_OBJECT), undefined, isEntry, false);
|
|
24544
24864
|
}
|
|
24545
24865
|
async resolveDynamicImport(module, specifier, importer, attributes) {
|
|
24546
|
-
const
|
|
24866
|
+
const pluginResult = await this.pluginDriver.hookFirstAndGetPlugin('resolveDynamicImport', [
|
|
24547
24867
|
specifier,
|
|
24548
24868
|
importer,
|
|
24549
24869
|
{ attributes, importerAttributes: module.info.attributes }
|
|
24550
24870
|
]);
|
|
24871
|
+
const resolution = pluginResult && pluginResult[0];
|
|
24872
|
+
const resolvedBy = resolution ? pluginResult[1].name : undefined;
|
|
24551
24873
|
if (typeof specifier !== 'string') {
|
|
24552
24874
|
if (typeof resolution === 'string') {
|
|
24553
24875
|
return resolution;
|
|
@@ -24555,7 +24877,7 @@ class ModuleLoader {
|
|
|
24555
24877
|
if (!resolution) {
|
|
24556
24878
|
return null;
|
|
24557
24879
|
}
|
|
24558
|
-
return this.getResolvedIdWithDefaults(resolution, attributes);
|
|
24880
|
+
return this.getResolvedIdWithDefaults(withDefaultResolvedBy(resolution, resolvedBy), attributes);
|
|
24559
24881
|
}
|
|
24560
24882
|
if (resolution == null) {
|
|
24561
24883
|
const existingResolution = module.resolvedIds[specifier];
|
|
@@ -24567,7 +24889,8 @@ class ModuleLoader {
|
|
|
24567
24889
|
}
|
|
24568
24890
|
return (module.resolvedIds[specifier] = this.handleInvalidResolvedId(await this.resolveId(specifier, module.id, parseAst_js.EMPTY_OBJECT, false, attributes, module.info.attributes), specifier, module.id, attributes));
|
|
24569
24891
|
}
|
|
24570
|
-
|
|
24892
|
+
const normalizedResolution = this.getNormalizedResolvedIdWithoutDefaults(resolution, importer, specifier);
|
|
24893
|
+
return this.handleInvalidResolvedId(this.getResolvedIdWithDefaults(normalizedResolution && withDefaultResolvedBy(normalizedResolution, resolvedBy), attributes), specifier, importer, attributes);
|
|
24571
24894
|
}
|
|
24572
24895
|
}
|
|
24573
24896
|
function normalizeRelativeExternalId(source, importer) {
|