@rollup/wasm-node 4.29.0-1 → 4.29.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,7 +1,7 @@
1
1
  /*
2
2
  @license
3
- Rollup.js v4.29.0-1
4
- Thu, 19 Dec 2024 06:37:00 GMT - commit fa5064084196636acd98263f95ffea59f8362e32
3
+ Rollup.js v4.29.0
4
+ Fri, 20 Dec 2024 18:36:54 GMT - commit dadd4882c4984d7875af799ad56e506784d50e1c
5
5
 
6
6
  https://github.com/rollup/rollup
7
7
 
@@ -31,7 +31,7 @@ function _interopNamespaceDefault(e) {
31
31
 
32
32
  const tty__namespace = /*#__PURE__*/_interopNamespaceDefault(tty);
33
33
 
34
- var version = "4.29.0-1";
34
+ var version = "4.29.0";
35
35
 
36
36
  function ensureArray$1(items) {
37
37
  if (Array.isArray(items)) {
@@ -1501,8 +1501,48 @@ const createColors = ({ useColor = isColorSupported } = {}) =>
1501
1501
  );
1502
1502
 
1503
1503
  const {
1504
+ reset,
1505
+ bold: bold$1,
1506
+ dim: dim$1,
1507
+ italic,
1508
+ underline: underline$1,
1509
+ inverse,
1510
+ hidden,
1511
+ strikethrough,
1512
+ black,
1513
+ red: red$1,
1514
+ green: green$1,
1515
+ yellow: yellow$1,
1504
1516
  blue,
1505
- cyan: cyan$1} = createColors();
1517
+ magenta,
1518
+ cyan: cyan$1,
1519
+ white,
1520
+ gray: gray$1,
1521
+ bgBlack,
1522
+ bgRed,
1523
+ bgGreen,
1524
+ bgYellow,
1525
+ bgBlue,
1526
+ bgMagenta,
1527
+ bgCyan,
1528
+ bgWhite,
1529
+ blackBright,
1530
+ redBright,
1531
+ greenBright,
1532
+ yellowBright,
1533
+ blueBright,
1534
+ magentaBright,
1535
+ cyanBright,
1536
+ whiteBright,
1537
+ bgBlackBright,
1538
+ bgRedBright,
1539
+ bgGreenBright,
1540
+ bgYellowBright,
1541
+ bgBlueBright,
1542
+ bgMagentaBright,
1543
+ bgCyanBright,
1544
+ bgWhiteBright,
1545
+ } = createColors();
1506
1546
 
1507
1547
  // @see https://no-color.org
1508
1548
  // @see https://www.npmjs.com/package/chalk
@@ -1862,7 +1902,7 @@ let Chunk$1 = class Chunk {
1862
1902
  // ' test'.trim()
1863
1903
  // split -> ' ' + 'test'
1864
1904
  // ✔️ edit -> '' + 'test'
1865
- // ✖️ edit -> 'test' + ''
1905
+ // ✖️ edit -> 'test' + ''
1866
1906
  // TODO is this block necessary?...
1867
1907
  newChunk.edit('', false);
1868
1908
  this.content = '';
@@ -2109,6 +2149,7 @@ class Mappings {
2109
2149
  this.raw[this.generatedCodeLine] = this.rawSegments = [];
2110
2150
  this.generatedCodeColumn = 0;
2111
2151
  first = true;
2152
+ charInHiresBoundary = false;
2112
2153
  } else {
2113
2154
  if (this.hires || first || sourcemapLocations.has(originalCharIndex)) {
2114
2155
  const segment = [this.generatedCodeColumn, sourceIndex, loc.line, loc.column];
@@ -2186,6 +2227,7 @@ class MagicString {
2186
2227
  storedNames: { writable: true, value: {} },
2187
2228
  indentStr: { writable: true, value: undefined },
2188
2229
  ignoreList: { writable: true, value: options.ignoreList },
2230
+ offset: { writable: true, value: options.offset || 0 },
2189
2231
  });
2190
2232
 
2191
2233
  this.byStart[0] = chunk;
@@ -2204,6 +2246,8 @@ class MagicString {
2204
2246
  }
2205
2247
 
2206
2248
  appendLeft(index, content) {
2249
+ index = index + this.offset;
2250
+
2207
2251
  if (typeof content !== 'string') throw new TypeError('inserted content must be a string');
2208
2252
 
2209
2253
  this._split(index);
@@ -2219,6 +2263,8 @@ class MagicString {
2219
2263
  }
2220
2264
 
2221
2265
  appendRight(index, content) {
2266
+ index = index + this.offset;
2267
+
2222
2268
  if (typeof content !== 'string') throw new TypeError('inserted content must be a string');
2223
2269
 
2224
2270
  this._split(index);
@@ -2234,7 +2280,7 @@ class MagicString {
2234
2280
  }
2235
2281
 
2236
2282
  clone() {
2237
- const cloned = new MagicString(this.original, { filename: this.filename });
2283
+ const cloned = new MagicString(this.original, { filename: this.filename, offset: this.offset });
2238
2284
 
2239
2285
  let originalChunk = this.firstChunk;
2240
2286
  let clonedChunk = (cloned.firstChunk = cloned.lastSearchedChunk = originalChunk.clone());
@@ -2432,7 +2478,7 @@ class MagicString {
2432
2478
  if (!warned.insertLeft) {
2433
2479
  console.warn(
2434
2480
  'magicString.insertLeft(...) is deprecated. Use magicString.appendLeft(...) instead',
2435
- ); // eslint-disable-line no-console
2481
+ );
2436
2482
  warned.insertLeft = true;
2437
2483
  }
2438
2484
 
@@ -2443,7 +2489,7 @@ class MagicString {
2443
2489
  if (!warned.insertRight) {
2444
2490
  console.warn(
2445
2491
  'magicString.insertRight(...) is deprecated. Use magicString.prependRight(...) instead',
2446
- ); // eslint-disable-line no-console
2492
+ );
2447
2493
  warned.insertRight = true;
2448
2494
  }
2449
2495
 
@@ -2451,6 +2497,10 @@ class MagicString {
2451
2497
  }
2452
2498
 
2453
2499
  move(start, end, index) {
2500
+ start = start + this.offset;
2501
+ end = end + this.offset;
2502
+ index = index + this.offset;
2503
+
2454
2504
  if (index >= start && index <= end) throw new Error('Cannot move a selection inside itself');
2455
2505
 
2456
2506
  this._split(start);
@@ -2493,6 +2543,9 @@ class MagicString {
2493
2543
  }
2494
2544
 
2495
2545
  update(start, end, content, options) {
2546
+ start = start + this.offset;
2547
+ end = end + this.offset;
2548
+
2496
2549
  if (typeof content !== 'string') throw new TypeError('replacement content must be a string');
2497
2550
 
2498
2551
  if (this.original.length !== 0) {
@@ -2513,7 +2566,7 @@ class MagicString {
2513
2566
  if (!warned.storeName) {
2514
2567
  console.warn(
2515
2568
  'The final argument to magicString.overwrite(...) should be an options object. See https://github.com/rich-harris/magic-string',
2516
- ); // eslint-disable-line no-console
2569
+ );
2517
2570
  warned.storeName = true;
2518
2571
  }
2519
2572
 
@@ -2564,6 +2617,8 @@ class MagicString {
2564
2617
  }
2565
2618
 
2566
2619
  prependLeft(index, content) {
2620
+ index = index + this.offset;
2621
+
2567
2622
  if (typeof content !== 'string') throw new TypeError('inserted content must be a string');
2568
2623
 
2569
2624
  this._split(index);
@@ -2579,6 +2634,8 @@ class MagicString {
2579
2634
  }
2580
2635
 
2581
2636
  prependRight(index, content) {
2637
+ index = index + this.offset;
2638
+
2582
2639
  if (typeof content !== 'string') throw new TypeError('inserted content must be a string');
2583
2640
 
2584
2641
  this._split(index);
@@ -2594,6 +2651,9 @@ class MagicString {
2594
2651
  }
2595
2652
 
2596
2653
  remove(start, end) {
2654
+ start = start + this.offset;
2655
+ end = end + this.offset;
2656
+
2597
2657
  if (this.original.length !== 0) {
2598
2658
  while (start < 0) start += this.original.length;
2599
2659
  while (end < 0) end += this.original.length;
@@ -2620,6 +2680,9 @@ class MagicString {
2620
2680
  }
2621
2681
 
2622
2682
  reset(start, end) {
2683
+ start = start + this.offset;
2684
+ end = end + this.offset;
2685
+
2623
2686
  if (this.original.length !== 0) {
2624
2687
  while (start < 0) start += this.original.length;
2625
2688
  while (end < 0) end += this.original.length;
@@ -2684,7 +2747,10 @@ class MagicString {
2684
2747
  return this.intro + lineStr;
2685
2748
  }
2686
2749
 
2687
- slice(start = 0, end = this.original.length) {
2750
+ slice(start = 0, end = this.original.length - this.offset) {
2751
+ start = start + this.offset;
2752
+ end = end + this.offset;
2753
+
2688
2754
  if (this.original.length !== 0) {
2689
2755
  while (start < 0) start += this.original.length;
2690
2756
  while (end < 0) end += this.original.length;
@@ -2920,11 +2986,7 @@ class MagicString {
2920
2986
  if (match.index != null) {
2921
2987
  const replacement = getReplacement(match, this.original);
2922
2988
  if (replacement !== match[0]) {
2923
- this.overwrite(
2924
- match.index,
2925
- match.index + match[0].length,
2926
- replacement
2927
- );
2989
+ this.overwrite(match.index, match.index + match[0].length, replacement);
2928
2990
  }
2929
2991
  }
2930
2992
  });
@@ -2933,11 +2995,7 @@ class MagicString {
2933
2995
  if (match && match.index != null) {
2934
2996
  const replacement = getReplacement(match, this.original);
2935
2997
  if (replacement !== match[0]) {
2936
- this.overwrite(
2937
- match.index,
2938
- match.index + match[0].length,
2939
- replacement
2940
- );
2998
+ this.overwrite(match.index, match.index + match[0].length, replacement);
2941
2999
  }
2942
3000
  }
2943
3001
  }
@@ -2972,8 +3030,7 @@ class MagicString {
2972
3030
  index = original.indexOf(string, index + stringLength)
2973
3031
  ) {
2974
3032
  const previous = original.slice(index, index + stringLength);
2975
- if (previous !== replacement)
2976
- this.overwrite(index, index + stringLength, replacement);
3033
+ if (previous !== replacement) this.overwrite(index, index + stringLength, replacement);
2977
3034
  }
2978
3035
 
2979
3036
  return this;
@@ -3482,6 +3539,71 @@ function renderSystemExportSequenceBeforeExpression(exportedVariable, expression
3482
3539
  }
3483
3540
  }
3484
3541
 
3542
+ /** @import { Node } from 'estree' */
3543
+
3544
+ /**
3545
+ * @param {Node} node
3546
+ * @param {Node} parent
3547
+ * @returns {boolean}
3548
+ */
3549
+ function is_reference(node, parent) {
3550
+ if (node.type === 'MemberExpression') {
3551
+ return !node.computed && is_reference(node.object, node);
3552
+ }
3553
+
3554
+ if (node.type !== 'Identifier') return false;
3555
+
3556
+ switch (parent?.type) {
3557
+ // disregard `bar` in `foo.bar`
3558
+ case 'MemberExpression':
3559
+ return parent.computed || node === parent.object;
3560
+
3561
+ // disregard the `foo` in `class {foo(){}}` but keep it in `class {[foo](){}}`
3562
+ case 'MethodDefinition':
3563
+ return parent.computed;
3564
+
3565
+ // disregard the `meta` in `import.meta`
3566
+ case 'MetaProperty':
3567
+ return parent.meta === node;
3568
+
3569
+ // disregard the `foo` in `class {foo=bar}` but keep it in `class {[foo]=bar}` and `class {bar=foo}`
3570
+ case 'PropertyDefinition':
3571
+ return parent.computed || node === parent.value;
3572
+
3573
+ // disregard the `bar` in `{ bar: foo }`, but keep it in `{ [bar]: foo }`
3574
+ case 'Property':
3575
+ return parent.computed || node === parent.value;
3576
+
3577
+ // disregard the `bar` in `export { foo as bar }` or
3578
+ // the foo in `import { foo as bar }`
3579
+ case 'ExportSpecifier':
3580
+ case 'ImportSpecifier':
3581
+ return node === parent.local;
3582
+
3583
+ // disregard the `foo` in `foo: while (...) { ... break foo; ... continue foo;}`
3584
+ case 'LabeledStatement':
3585
+ case 'BreakStatement':
3586
+ case 'ContinueStatement':
3587
+ return false;
3588
+
3589
+ default:
3590
+ return true;
3591
+ }
3592
+ }
3593
+
3594
+ const PureFunctionKey = Symbol('PureFunction');
3595
+ const getPureFunctions = ({ treeshake }) => {
3596
+ const pureFunctions = Object.create(null);
3597
+ for (const functionName of treeshake ? treeshake.manualPureFunctions : []) {
3598
+ let currentFunctions = pureFunctions;
3599
+ for (const pathSegment of functionName.split('.')) {
3600
+ currentFunctions = currentFunctions[pathSegment] ||= Object.create(null);
3601
+ }
3602
+ currentFunctions[PureFunctionKey] = true;
3603
+ }
3604
+ return pureFunctions;
3605
+ };
3606
+
3485
3607
  const UnknownKey = Symbol('Unknown Key');
3486
3608
  const UnknownNonAccessorKey = Symbol('Unknown Non-Accessor Key');
3487
3609
  const UnknownInteger = Symbol('Unknown Integer');
@@ -3496,7 +3618,7 @@ const UNKNOWN_PATH = [UnknownKey];
3496
3618
  const UNKNOWN_NON_ACCESSOR_PATH = [UnknownNonAccessorKey];
3497
3619
  const UNKNOWN_INTEGER_PATH = [UnknownInteger];
3498
3620
  const EntitiesKey = Symbol('Entities');
3499
- class EntityPathTracker {
3621
+ class PathTracker {
3500
3622
  constructor() {
3501
3623
  this.entityPaths = Object.create(null, {
3502
3624
  [EntitiesKey]: { value: new Set() }
@@ -3521,14 +3643,14 @@ class EntityPathTracker {
3521
3643
  getEntities(path) {
3522
3644
  let currentPaths = this.entityPaths;
3523
3645
  for (const pathSegment of path) {
3524
- currentPaths = currentPaths[pathSegment] ||= Object.create(null, {
3525
- [EntitiesKey]: { value: new Set() }
3526
- });
3646
+ currentPaths = currentPaths[pathSegment] =
3647
+ currentPaths[pathSegment] ||
3648
+ Object.create(null, { [EntitiesKey]: { value: new Set() } });
3527
3649
  }
3528
3650
  return currentPaths[EntitiesKey];
3529
3651
  }
3530
3652
  }
3531
- const SHARED_RECURSION_TRACKER = new EntityPathTracker();
3653
+ const SHARED_RECURSION_TRACKER = new PathTracker();
3532
3654
  class DiscriminatedPathTracker {
3533
3655
  constructor() {
3534
3656
  this.entityPaths = Object.create(null, {
@@ -3538,9 +3660,9 @@ class DiscriminatedPathTracker {
3538
3660
  trackEntityAtPathAndGetIfTracked(path, discriminator, entity) {
3539
3661
  let currentPaths = this.entityPaths;
3540
3662
  for (const pathSegment of path) {
3541
- currentPaths = currentPaths[pathSegment] ||= Object.create(null, {
3542
- [EntitiesKey]: { value: new Map() }
3543
- });
3663
+ currentPaths = currentPaths[pathSegment] =
3664
+ currentPaths[pathSegment] ||
3665
+ Object.create(null, { [EntitiesKey]: { value: new Map() } });
3544
3666
  }
3545
3667
  const trackedEntities = getOrCreate(currentPaths[EntitiesKey], discriminator, (getNewSet));
3546
3668
  if (trackedEntities.has(entity))
@@ -3549,137 +3671,6 @@ class DiscriminatedPathTracker {
3549
3671
  return false;
3550
3672
  }
3551
3673
  }
3552
- const UNKNOWN_INCLUDED_PATH = Object.freeze({ [UnknownKey]: parseAst_js.EMPTY_OBJECT });
3553
- class IncludedPathTracker {
3554
- constructor() {
3555
- this.includedPaths = null;
3556
- }
3557
- includePathAndGetIfIncluded(path) {
3558
- let included = true;
3559
- let parent = this;
3560
- let parentSegment = 'includedPaths';
3561
- let currentPaths = (this.includedPaths ||=
3562
- ((included = false), Object.create(null)));
3563
- for (const pathSegment of path) {
3564
- // This means from here, all paths are included
3565
- if (currentPaths[UnknownKey]) {
3566
- return true;
3567
- }
3568
- // Including UnknownKey automatically includes all nested paths.
3569
- // From above, we know that UnknownKey is not included yet.
3570
- if (typeof pathSegment === 'symbol') {
3571
- // Hopefully, this saves some memory over just setting
3572
- // currentPaths[UnknownKey] = EMPTY_OBJECT
3573
- parent[parentSegment] = UNKNOWN_INCLUDED_PATH;
3574
- return false;
3575
- }
3576
- parent = currentPaths;
3577
- parentSegment = pathSegment;
3578
- currentPaths = currentPaths[pathSegment] ||= ((included = false), Object.create(null));
3579
- }
3580
- return included;
3581
- }
3582
- includeAllPaths(entity, context, basePath) {
3583
- const { includedPaths } = this;
3584
- if (includedPaths) {
3585
- includeAllPaths(entity, context, basePath, includedPaths);
3586
- }
3587
- }
3588
- }
3589
- function includeAllPaths(entity, context, basePath, currentPaths) {
3590
- if (currentPaths[UnknownKey]) {
3591
- return entity.includePath([...basePath, UnknownKey], context);
3592
- }
3593
- const keys = Object.keys(currentPaths);
3594
- if (keys.length === 0) {
3595
- return entity.includePath(basePath, context);
3596
- }
3597
- for (const key of keys) {
3598
- includeAllPaths(entity, context, [...basePath, key], currentPaths[key]);
3599
- }
3600
- }
3601
-
3602
- /** @import { Node } from 'estree' */
3603
-
3604
- /**
3605
- * @param {Node} node
3606
- * @param {Node} parent
3607
- * @returns {boolean}
3608
- */
3609
- function is_reference(node, parent) {
3610
- if (node.type === 'MemberExpression') {
3611
- return !node.computed && is_reference(node.object, node);
3612
- }
3613
-
3614
- if (node.type !== 'Identifier') return false;
3615
-
3616
- switch (parent?.type) {
3617
- // disregard `bar` in `foo.bar`
3618
- case 'MemberExpression':
3619
- return parent.computed || node === parent.object;
3620
-
3621
- // disregard the `foo` in `class {foo(){}}` but keep it in `class {[foo](){}}`
3622
- case 'MethodDefinition':
3623
- return parent.computed;
3624
-
3625
- // disregard the `meta` in `import.meta`
3626
- case 'MetaProperty':
3627
- return parent.meta === node;
3628
-
3629
- // disregard the `foo` in `class {foo=bar}` but keep it in `class {[foo]=bar}` and `class {bar=foo}`
3630
- case 'PropertyDefinition':
3631
- return parent.computed || node === parent.value;
3632
-
3633
- // disregard the `bar` in `{ bar: foo }`, but keep it in `{ [bar]: foo }`
3634
- case 'Property':
3635
- return parent.computed || node === parent.value;
3636
-
3637
- // disregard the `bar` in `export { foo as bar }` or
3638
- // the foo in `import { foo as bar }`
3639
- case 'ExportSpecifier':
3640
- case 'ImportSpecifier':
3641
- return node === parent.local;
3642
-
3643
- // disregard the `foo` in `foo: while (...) { ... break foo; ... continue foo;}`
3644
- case 'LabeledStatement':
3645
- case 'BreakStatement':
3646
- case 'ContinueStatement':
3647
- return false;
3648
-
3649
- default:
3650
- return true;
3651
- }
3652
- }
3653
-
3654
- function createInclusionContext() {
3655
- return {
3656
- brokenFlow: false,
3657
- hasBreak: false,
3658
- hasContinue: false,
3659
- includedCallArguments: new Set(),
3660
- includedLabels: new Set()
3661
- };
3662
- }
3663
- function createHasEffectsContext() {
3664
- return {
3665
- accessed: new EntityPathTracker(),
3666
- assigned: new EntityPathTracker(),
3667
- brokenFlow: false,
3668
- called: new DiscriminatedPathTracker(),
3669
- hasBreak: false,
3670
- hasContinue: false,
3671
- ignore: {
3672
- breaks: false,
3673
- continues: false,
3674
- labels: new Set(),
3675
- returnYield: false,
3676
- this: false
3677
- },
3678
- includedLabels: new Set(),
3679
- instantiated: new DiscriminatedPathTracker(),
3680
- replacedVariableInits: new Map()
3681
- };
3682
- }
3683
3674
 
3684
3675
  function isFlagSet(flags, flag) {
3685
3676
  return (flags & flag) !== 0;
@@ -3690,6 +3681,7 @@ function setFlag(flags, flag, value) {
3690
3681
 
3691
3682
  const UnknownValue = Symbol('Unknown Value');
3692
3683
  const UnknownTruthyValue = Symbol('Unknown Truthy Value');
3684
+ const UnknownFalsyValue = Symbol('Unknown Falsy Value');
3693
3685
  class ExpressionEntity {
3694
3686
  constructor() {
3695
3687
  this.flags = 0;
@@ -3718,25 +3710,12 @@ class ExpressionEntity {
3718
3710
  hasEffectsOnInteractionAtPath(_path, _interaction, _context) {
3719
3711
  return true;
3720
3712
  }
3721
- include(context, _includeChildrenRecursively, _options) {
3722
- if (!this.included)
3723
- this.includeNode(context);
3724
- }
3725
- includeNode(_context) {
3713
+ include(_context, _includeChildrenRecursively, _options) {
3726
3714
  this.included = true;
3727
3715
  }
3728
- includePath(_path, context) {
3729
- if (!this.included)
3730
- this.includeNode(context);
3731
- }
3732
- /* We are both including and including an unknown path here as the former
3733
- * ensures that nested nodes are included while the latter ensures that all
3734
- * paths of the expression are included.
3735
- * */
3736
- includeCallArguments(context, interaction) {
3737
- for (const argument of interaction.args) {
3738
- argument?.includePath(UNKNOWN_PATH, context);
3739
- argument?.include(context, false);
3716
+ includeCallArguments(context, parameters) {
3717
+ for (const argument of parameters) {
3718
+ argument.include(context, false);
3740
3719
  }
3741
3720
  }
3742
3721
  shouldBeIncluded(_context) {
@@ -3775,19 +3754,6 @@ const NODE_INTERACTION_UNKNOWN_CALL = {
3775
3754
  withNew: false
3776
3755
  };
3777
3756
 
3778
- const PureFunctionKey = Symbol('PureFunction');
3779
- const getPureFunctions = ({ treeshake }) => {
3780
- const pureFunctions = Object.create(null);
3781
- for (const functionName of treeshake ? treeshake.manualPureFunctions : []) {
3782
- let currentFunctions = pureFunctions;
3783
- for (const pathSegment of functionName.split('.')) {
3784
- currentFunctions = currentFunctions[pathSegment] ||= Object.create(null);
3785
- }
3786
- currentFunctions[PureFunctionKey] = true;
3787
- }
3788
- return pureFunctions;
3789
- };
3790
-
3791
3757
  class Variable extends ExpressionEntity {
3792
3758
  markReassigned() {
3793
3759
  this.isReassigned = true;
@@ -3864,9 +3830,9 @@ class Variable extends ExpressionEntity {
3864
3830
  * has not been included previously. Once a variable is included, it should
3865
3831
  * take care all its declarations are included.
3866
3832
  */
3867
- includePath(path, context) {
3833
+ include() {
3868
3834
  this.included = true;
3869
- this.renderedLikeHoisted?.includePath(path, context);
3835
+ this.renderedLikeHoisted?.include();
3870
3836
  }
3871
3837
  /**
3872
3838
  * Links the rendered name of this variable to another variable and includes
@@ -3898,8 +3864,8 @@ class ExternalVariable extends Variable {
3898
3864
  hasEffectsOnInteractionAtPath(path, { type }) {
3899
3865
  return type !== INTERACTION_ACCESSED || path.length > (this.isNamespace ? 1 : 0);
3900
3866
  }
3901
- includePath(path, context) {
3902
- super.includePath(path, context);
3867
+ include() {
3868
+ super.include();
3903
3869
  this.module.used = true;
3904
3870
  }
3905
3871
  }
@@ -4198,6 +4164,36 @@ const childNodeKeys = {
4198
4164
  YieldExpression: ['argument']
4199
4165
  };
4200
4166
 
4167
+ function createInclusionContext() {
4168
+ return {
4169
+ brokenFlow: false,
4170
+ hasBreak: false,
4171
+ hasContinue: false,
4172
+ includedCallArguments: new Set(),
4173
+ includedLabels: new Set()
4174
+ };
4175
+ }
4176
+ function createHasEffectsContext() {
4177
+ return {
4178
+ accessed: new PathTracker(),
4179
+ assigned: new PathTracker(),
4180
+ brokenFlow: false,
4181
+ called: new DiscriminatedPathTracker(),
4182
+ hasBreak: false,
4183
+ hasContinue: false,
4184
+ ignore: {
4185
+ breaks: false,
4186
+ continues: false,
4187
+ labels: new Set(),
4188
+ returnYield: false,
4189
+ this: false
4190
+ },
4191
+ includedLabels: new Set(),
4192
+ instantiated: new DiscriminatedPathTracker(),
4193
+ replacedVariableInits: new Map()
4194
+ };
4195
+ }
4196
+
4201
4197
  const INCLUDE_PARAMETERS = 'variables';
4202
4198
  const IS_SKIPPED_CHAIN = Symbol('IS_SKIPPED_CHAIN');
4203
4199
  class NodeBase extends ExpressionEntity {
@@ -4267,37 +4263,20 @@ class NodeBase extends ExpressionEntity {
4267
4263
  this.hasEffectsOnInteractionAtPath(EMPTY_PATH, this.assignmentInteraction, context));
4268
4264
  }
4269
4265
  include(context, includeChildrenRecursively, _options) {
4270
- if (!this.included)
4271
- this.includeNode(context);
4272
- for (const key of childNodeKeys[this.type]) {
4273
- const value = this[key];
4274
- if (value === null)
4275
- continue;
4276
- if (Array.isArray(value)) {
4277
- for (const child of value) {
4278
- child?.include(context, includeChildrenRecursively);
4279
- }
4280
- }
4281
- else {
4282
- value.include(context, includeChildrenRecursively);
4283
- }
4284
- }
4285
- }
4286
- includeNode(context) {
4287
- this.included = true;
4288
4266
  if (!this.deoptimized)
4289
4267
  this.applyDeoptimizations();
4268
+ this.included = true;
4290
4269
  for (const key of childNodeKeys[this.type]) {
4291
4270
  const value = this[key];
4292
4271
  if (value === null)
4293
4272
  continue;
4294
4273
  if (Array.isArray(value)) {
4295
4274
  for (const child of value) {
4296
- child?.includePath(UNKNOWN_PATH, context);
4275
+ child?.include(context, includeChildrenRecursively);
4297
4276
  }
4298
4277
  }
4299
4278
  else {
4300
- value.includePath(UNKNOWN_PATH, context);
4279
+ value.include(context, includeChildrenRecursively);
4301
4280
  }
4302
4281
  }
4303
4282
  }
@@ -4404,17 +4383,6 @@ class NodeBase extends ExpressionEntity {
4404
4383
  function createChildNodeKeysForNode(esTreeNode) {
4405
4384
  return Object.keys(esTreeNode).filter(key => typeof esTreeNode[key] === 'object' && key.charCodeAt(0) !== 95 /* _ */);
4406
4385
  }
4407
- function onlyIncludeSelf() {
4408
- this.included = true;
4409
- if (!this.deoptimized)
4410
- this.applyDeoptimizations();
4411
- }
4412
- function onlyIncludeSelfNoDeoptimize() {
4413
- this.included = true;
4414
- }
4415
- function doNotDeoptimize() {
4416
- this.deoptimized = true;
4417
- }
4418
4386
 
4419
4387
  function isObjectExpressionNode(node) {
4420
4388
  return node instanceof NodeBase && node.type === parseAst_js.ObjectExpression;
@@ -4427,8 +4395,8 @@ function assembleMemberDescriptions(memberDescriptions, inheritedDescriptions =
4427
4395
  return Object.create(inheritedDescriptions, memberDescriptions);
4428
4396
  }
4429
4397
  const UNDEFINED_EXPRESSION = new (class UndefinedExpression extends ExpressionEntity {
4430
- getLiteralValueAtPath(path) {
4431
- return path.length > 0 ? UnknownValue : undefined;
4398
+ getLiteralValueAtPath() {
4399
+ return undefined;
4432
4400
  }
4433
4401
  })();
4434
4402
  const returnsUnknown = {
@@ -4625,6 +4593,31 @@ function getMemberReturnExpressionWhenCalled(members, memberName) {
4625
4593
  return [members[memberName].returns, false];
4626
4594
  }
4627
4595
 
4596
+ class SpreadElement extends NodeBase {
4597
+ deoptimizeArgumentsOnInteractionAtPath(interaction, path, recursionTracker) {
4598
+ if (path.length > 0) {
4599
+ this.argument.deoptimizeArgumentsOnInteractionAtPath(interaction, UNKNOWN_PATH, recursionTracker);
4600
+ }
4601
+ }
4602
+ hasEffects(context) {
4603
+ if (!this.deoptimized)
4604
+ this.applyDeoptimizations();
4605
+ const { propertyReadSideEffects } = this.scope.context.options
4606
+ .treeshake;
4607
+ return (this.argument.hasEffects(context) ||
4608
+ (propertyReadSideEffects &&
4609
+ (propertyReadSideEffects === 'always' ||
4610
+ this.argument.hasEffectsOnInteractionAtPath(UNKNOWN_PATH, NODE_INTERACTION_UNKNOWN_ACCESS, context))));
4611
+ }
4612
+ applyDeoptimizations() {
4613
+ this.deoptimized = true;
4614
+ // Only properties of properties of the argument could become subject to reassignment
4615
+ // This will also reassign the return values of iterators
4616
+ this.argument.deoptimizePath([UnknownKey, UnknownKey]);
4617
+ this.scope.context.requestTreeshakingPass();
4618
+ }
4619
+ }
4620
+
4628
4621
  class Method extends ExpressionEntity {
4629
4622
  constructor(description) {
4630
4623
  super();
@@ -4750,7 +4743,6 @@ class ObjectEntity extends ExpressionEntity {
4750
4743
  this.unknownIntegerProps = [];
4751
4744
  this.unmatchableGetters = [];
4752
4745
  this.unmatchablePropertiesAndGetters = [];
4753
- this.unmatchablePropertiesAndSetters = [];
4754
4746
  this.unmatchableSetters = [];
4755
4747
  if (Array.isArray(properties)) {
4756
4748
  this.buildPropertyMaps(properties);
@@ -4985,38 +4977,9 @@ class ObjectEntity extends ExpressionEntity {
4985
4977
  }
4986
4978
  return false;
4987
4979
  }
4988
- include(context, includeChildrenRecursively) {
4989
- this.included = true;
4990
- for (const property of this.allProperties) {
4991
- if (includeChildrenRecursively || property.shouldBeIncluded(context)) {
4992
- property.include(context, includeChildrenRecursively);
4993
- }
4994
- }
4995
- this.prototypeExpression?.include(context, includeChildrenRecursively);
4996
- }
4997
- includePath(path, context) {
4998
- this.included = true;
4999
- if (path.length === 0)
5000
- return;
5001
- const [key, ...subPath] = path;
5002
- const [includedMembers, includedPath] = typeof key === 'string'
5003
- ? [
5004
- [
5005
- ...new Set([
5006
- ...(this.propertiesAndGettersByKey[key] || this.unmatchablePropertiesAndGetters),
5007
- ...(this.propertiesAndSettersByKey[key] || this.unmatchablePropertiesAndSetters)
5008
- ])
5009
- ],
5010
- subPath
5011
- ]
5012
- : [this.allProperties, UNKNOWN_PATH];
5013
- for (const property of includedMembers) {
5014
- property.includePath(includedPath, context);
5015
- }
5016
- this.prototypeExpression?.includePath(path, context);
5017
- }
5018
4980
  buildPropertyMaps(properties) {
5019
- const { allProperties, propertiesAndGettersByKey, propertiesAndSettersByKey, settersByKey, gettersByKey, unknownIntegerProps, unmatchablePropertiesAndGetters, unmatchablePropertiesAndSetters, unmatchableGetters, unmatchableSetters } = this;
4981
+ const { allProperties, propertiesAndGettersByKey, propertiesAndSettersByKey, settersByKey, gettersByKey, unknownIntegerProps, unmatchablePropertiesAndGetters, unmatchableGetters, unmatchableSetters } = this;
4982
+ const unmatchablePropertiesAndSetters = [];
5020
4983
  for (let index = properties.length - 1; index >= 0; index--) {
5021
4984
  const { key, kind, property } = properties[index];
5022
4985
  allProperties.push(property);
@@ -5286,37 +5249,6 @@ const ARRAY_PROTOTYPE = new ObjectEntity({
5286
5249
  values: METHOD_DEOPTS_SELF_RETURNS_UNKNOWN
5287
5250
  }, OBJECT_PROTOTYPE, true);
5288
5251
 
5289
- class SpreadElement extends NodeBase {
5290
- deoptimizeArgumentsOnInteractionAtPath(interaction, path, recursionTracker) {
5291
- if (path.length > 0) {
5292
- this.argument.deoptimizeArgumentsOnInteractionAtPath(interaction, UNKNOWN_PATH, recursionTracker);
5293
- }
5294
- }
5295
- hasEffects(context) {
5296
- if (!this.deoptimized)
5297
- this.applyDeoptimizations();
5298
- const { propertyReadSideEffects } = this.scope.context.options
5299
- .treeshake;
5300
- return (this.argument.hasEffects(context) ||
5301
- (propertyReadSideEffects &&
5302
- (propertyReadSideEffects === 'always' ||
5303
- this.argument.hasEffectsOnInteractionAtPath(UNKNOWN_PATH, NODE_INTERACTION_UNKNOWN_ACCESS, context))));
5304
- }
5305
- includeNode(context) {
5306
- this.included = true;
5307
- if (!this.deoptimized)
5308
- this.applyDeoptimizations();
5309
- this.argument.includePath(UNKNOWN_PATH, context);
5310
- }
5311
- applyDeoptimizations() {
5312
- this.deoptimized = true;
5313
- // Only properties of properties of the argument could become subject to reassignment
5314
- // This will also reassign the return values of iterators
5315
- this.argument.deoptimizePath([UnknownKey, UnknownKey]);
5316
- this.scope.context.requestTreeshakingPass();
5317
- }
5318
- }
5319
-
5320
5252
  class ArrayExpression extends NodeBase {
5321
5253
  constructor() {
5322
5254
  super(...arguments);
@@ -5337,16 +5269,6 @@ class ArrayExpression extends NodeBase {
5337
5269
  hasEffectsOnInteractionAtPath(path, interaction, context) {
5338
5270
  return this.getObjectEntity().hasEffectsOnInteractionAtPath(path, interaction, context);
5339
5271
  }
5340
- includeNode(context) {
5341
- this.included = true;
5342
- if (!this.deoptimized)
5343
- this.applyDeoptimizations();
5344
- for (const element of this.elements) {
5345
- if (element) {
5346
- element?.includePath(UNKNOWN_PATH, context);
5347
- }
5348
- }
5349
- }
5350
5272
  applyDeoptimizations() {
5351
5273
  this.deoptimized = true;
5352
5274
  let hasSpread = false;
@@ -5388,29 +5310,29 @@ class ArrayExpression extends NodeBase {
5388
5310
 
5389
5311
  /* eslint sort-keys: "off" */
5390
5312
  const ValueProperties = Symbol('Value Properties');
5391
- const getTruthyLiteralValue = () => UnknownTruthyValue;
5313
+ const getUnknownValue = () => UnknownValue;
5392
5314
  const returnFalse = () => false;
5393
5315
  const returnTrue = () => true;
5394
5316
  const PURE = {
5395
5317
  deoptimizeArgumentsOnCall: doNothing,
5396
- getLiteralValue: getTruthyLiteralValue,
5318
+ getLiteralValue: getUnknownValue,
5397
5319
  hasEffectsWhenCalled: returnFalse
5398
5320
  };
5399
5321
  const IMPURE = {
5400
5322
  deoptimizeArgumentsOnCall: doNothing,
5401
- getLiteralValue: getTruthyLiteralValue,
5323
+ getLiteralValue: getUnknownValue,
5402
5324
  hasEffectsWhenCalled: returnTrue
5403
5325
  };
5404
5326
  const PURE_WITH_ARRAY = {
5405
5327
  deoptimizeArgumentsOnCall: doNothing,
5406
- getLiteralValue: getTruthyLiteralValue,
5328
+ getLiteralValue: getUnknownValue,
5407
5329
  hasEffectsWhenCalled({ args }) {
5408
5330
  return args.length > 1 && !(args[1] instanceof ArrayExpression);
5409
5331
  }
5410
5332
  };
5411
5333
  const GETTER_ACCESS = {
5412
5334
  deoptimizeArgumentsOnCall: doNothing,
5413
- getLiteralValue: getTruthyLiteralValue,
5335
+ getLiteralValue: getUnknownValue,
5414
5336
  hasEffectsWhenCalled({ args }, context) {
5415
5337
  const [_thisArgument, firstArgument] = args;
5416
5338
  return (!(firstArgument instanceof ExpressionEntity) ||
@@ -5440,7 +5362,7 @@ const MUTATES_ARG_WITHOUT_ACCESSOR = {
5440
5362
  deoptimizeArgumentsOnCall({ args: [, firstArgument] }) {
5441
5363
  firstArgument?.deoptimizePath(UNKNOWN_PATH);
5442
5364
  },
5443
- getLiteralValue: getTruthyLiteralValue,
5365
+ getLiteralValue: getUnknownValue,
5444
5366
  hasEffectsWhenCalled({ args }, context) {
5445
5367
  return (args.length <= 1 ||
5446
5368
  args[1].hasEffectsOnInteractionAtPath(UNKNOWN_NON_ACCESSOR_PATH, NODE_INTERACTION_UNKNOWN_ASSIGNMENT, context));
@@ -5647,7 +5569,7 @@ const knownGlobals = {
5647
5569
  }
5648
5570
  target.deoptimizePath(UNKNOWN_PATH);
5649
5571
  },
5650
- getLiteralValue: getTruthyLiteralValue,
5572
+ getLiteralValue: getUnknownValue,
5651
5573
  hasEffectsWhenCalled: returnTrue
5652
5574
  }
5653
5575
  },
@@ -5837,7 +5759,7 @@ const knownGlobals = {
5837
5759
  deoptimizeArgumentsOnCall({ args }) {
5838
5760
  args[2]?.deoptimizePath(['detail']);
5839
5761
  },
5840
- getLiteralValue: getTruthyLiteralValue,
5762
+ getLiteralValue: getUnknownValue,
5841
5763
  hasEffectsWhenCalled: returnFalse
5842
5764
  },
5843
5765
  prototype: O
@@ -6414,37 +6336,17 @@ class GlobalVariable extends Variable {
6414
6336
  }
6415
6337
  }
6416
6338
 
6417
- // To avoid infinite recursions
6418
- const MAX_PATH_DEPTH = 6;
6419
- // If a path is longer than MAX_PATH_DEPTH, it is truncated so that it is at
6420
- // most MAX_PATH_DEPTH long. The last element is always UnknownKey
6421
- const limitConcatenatedPathDepth = (path1, path2) => {
6422
- const { length: length1 } = path1;
6423
- const { length: length2 } = path2;
6424
- return length1 === 0
6425
- ? path2
6426
- : length2 === 0
6427
- ? path1
6428
- : length1 + length2 > MAX_PATH_DEPTH
6429
- ? [...path1, ...path2.slice(0, MAX_PATH_DEPTH - 1 - path1.length), 'UnknownKey']
6430
- : [...path1, ...path2];
6431
- };
6432
-
6433
6339
  class LocalVariable extends Variable {
6434
- constructor(name, declarator, init,
6435
- /** if this is non-empty, the actual init is this path of this.init */
6436
- initPath, context, kind) {
6340
+ constructor(name, declarator, init, context, kind) {
6437
6341
  super(name);
6438
6342
  this.init = init;
6439
- this.initPath = initPath;
6440
- this.kind = kind;
6441
6343
  this.calledFromTryStatement = false;
6442
6344
  this.additionalInitializers = null;
6443
- this.includedPathTracker = new IncludedPathTracker();
6444
6345
  this.expressionsToBeDeoptimized = [];
6445
6346
  this.declarations = declarator ? [declarator] : [];
6446
6347
  this.deoptimizationTracker = context.deoptimizationTracker;
6447
6348
  this.module = context.module;
6349
+ this.kind = kind;
6448
6350
  }
6449
6351
  addDeclaration(identifier, init) {
6450
6352
  this.declarations.push(identifier);
@@ -6455,16 +6357,15 @@ class LocalVariable extends Variable {
6455
6357
  for (const initializer of this.additionalInitializers) {
6456
6358
  initializer.deoptimizePath(UNKNOWN_PATH);
6457
6359
  }
6360
+ this.additionalInitializers = null;
6458
6361
  }
6459
6362
  }
6460
6363
  deoptimizeArgumentsOnInteractionAtPath(interaction, path, recursionTracker) {
6461
- if (this.isReassigned || path.length + this.initPath.length > MAX_PATH_DEPTH) {
6364
+ if (this.isReassigned) {
6462
6365
  deoptimizeInteraction(interaction);
6463
6366
  return;
6464
6367
  }
6465
- recursionTracker.withTrackedEntityAtPath(path, this.init, () => {
6466
- this.init.deoptimizeArgumentsOnInteractionAtPath(interaction, [...this.initPath, ...path], recursionTracker);
6467
- }, undefined);
6368
+ recursionTracker.withTrackedEntityAtPath(path, this.init, () => this.init.deoptimizeArgumentsOnInteractionAtPath(interaction, path, recursionTracker), undefined);
6468
6369
  }
6469
6370
  deoptimizePath(path) {
6470
6371
  if (this.isReassigned ||
@@ -6478,40 +6379,37 @@ class LocalVariable extends Variable {
6478
6379
  for (const expression of expressionsToBeDeoptimized) {
6479
6380
  expression.deoptimizeCache();
6480
6381
  }
6481
- this.init.deoptimizePath([...this.initPath, UnknownKey]);
6382
+ this.init.deoptimizePath(UNKNOWN_PATH);
6482
6383
  }
6483
6384
  else {
6484
- this.init.deoptimizePath(limitConcatenatedPathDepth(this.initPath, path));
6385
+ this.init.deoptimizePath(path);
6485
6386
  }
6486
6387
  }
6487
6388
  getLiteralValueAtPath(path, recursionTracker, origin) {
6488
- if (this.isReassigned || path.length + this.initPath.length > MAX_PATH_DEPTH) {
6389
+ if (this.isReassigned) {
6489
6390
  return UnknownValue;
6490
6391
  }
6491
6392
  return recursionTracker.withTrackedEntityAtPath(path, this.init, () => {
6492
6393
  this.expressionsToBeDeoptimized.push(origin);
6493
- return this.init.getLiteralValueAtPath([...this.initPath, ...path], recursionTracker, origin);
6394
+ return this.init.getLiteralValueAtPath(path, recursionTracker, origin);
6494
6395
  }, UnknownValue);
6495
6396
  }
6496
6397
  getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin) {
6497
- if (this.isReassigned || path.length + this.initPath.length > MAX_PATH_DEPTH) {
6398
+ if (this.isReassigned) {
6498
6399
  return UNKNOWN_RETURN_EXPRESSION;
6499
6400
  }
6500
6401
  return recursionTracker.withTrackedEntityAtPath(path, this.init, () => {
6501
6402
  this.expressionsToBeDeoptimized.push(origin);
6502
- return this.init.getReturnExpressionWhenCalledAtPath([...this.initPath, ...path], interaction, recursionTracker, origin);
6403
+ return this.init.getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin);
6503
6404
  }, UNKNOWN_RETURN_EXPRESSION);
6504
6405
  }
6505
6406
  hasEffectsOnInteractionAtPath(path, interaction, context) {
6506
- if (path.length + this.initPath.length > MAX_PATH_DEPTH) {
6507
- return true;
6508
- }
6509
6407
  switch (interaction.type) {
6510
6408
  case INTERACTION_ACCESSED: {
6511
6409
  if (this.isReassigned)
6512
6410
  return true;
6513
6411
  return (!context.accessed.trackEntityAtPathAndGetIfTracked(path, this) &&
6514
- this.init.hasEffectsOnInteractionAtPath([...this.initPath, ...path], interaction, context));
6412
+ this.init.hasEffectsOnInteractionAtPath(path, interaction, context));
6515
6413
  }
6516
6414
  case INTERACTION_ASSIGNED: {
6517
6415
  if (this.included)
@@ -6521,63 +6419,44 @@ class LocalVariable extends Variable {
6521
6419
  if (this.isReassigned)
6522
6420
  return true;
6523
6421
  return (!context.assigned.trackEntityAtPathAndGetIfTracked(path, this) &&
6524
- this.init.hasEffectsOnInteractionAtPath([...this.initPath, ...path], interaction, context));
6422
+ this.init.hasEffectsOnInteractionAtPath(path, interaction, context));
6525
6423
  }
6526
6424
  case INTERACTION_CALLED: {
6527
6425
  if (this.isReassigned)
6528
6426
  return true;
6529
6427
  return (!(interaction.withNew ? context.instantiated : context.called).trackEntityAtPathAndGetIfTracked(path, interaction.args, this) &&
6530
- this.init.hasEffectsOnInteractionAtPath([...this.initPath, ...path], interaction, context));
6428
+ this.init.hasEffectsOnInteractionAtPath(path, interaction, context));
6531
6429
  }
6532
6430
  }
6533
6431
  }
6534
- includePath(path, context) {
6535
- if (!this.includedPathTracker.includePathAndGetIfIncluded(path)) {
6536
- this.module.scope.context.requestTreeshakingPass();
6537
- if (!this.included) {
6538
- // This will reduce the number of tree-shaking passes by eagerly
6539
- // including inits. By pushing this here instead of directly including
6540
- // we avoid deep call stacks.
6541
- this.module.scope.context.newlyIncludedVariableInits.add(this.init);
6542
- }
6543
- super.includePath(path, context);
6432
+ include() {
6433
+ if (!this.included) {
6434
+ super.include();
6544
6435
  for (const declaration of this.declarations) {
6545
6436
  // If node is a default export, it can save a tree-shaking run to include the full declaration now
6546
6437
  if (!declaration.included)
6547
- declaration.include(context, false);
6438
+ declaration.include(createInclusionContext(), false);
6548
6439
  let node = declaration.parent;
6549
6440
  while (!node.included) {
6550
6441
  // We do not want to properly include parents in case they are part of a dead branch
6551
6442
  // in which case .include() might pull in more dead code
6552
- node.includeNode(context);
6443
+ node.included = true;
6553
6444
  if (node.type === parseAst_js.Program)
6554
6445
  break;
6555
6446
  node = node.parent;
6556
6447
  }
6557
6448
  }
6558
- // We need to make sure we include the correct path of the init
6559
- if (path.length > 0) {
6560
- this.init.includePath(limitConcatenatedPathDepth(this.initPath, path), context);
6561
- this.additionalInitializers?.forEach(initializer => initializer.includePath(UNKNOWN_PATH, context));
6562
- }
6563
6449
  }
6564
6450
  }
6565
- includeCallArguments(context, interaction) {
6566
- if (this.isReassigned ||
6567
- context.includedCallArguments.has(this.init) ||
6568
- // This can be removed again once we can include arguments when called at
6569
- // a specific path
6570
- this.initPath.length > 0) {
6571
- for (const argument of interaction.args) {
6572
- if (argument) {
6573
- argument.includePath(UNKNOWN_PATH, context);
6574
- argument.include(context, false);
6575
- }
6451
+ includeCallArguments(context, parameters) {
6452
+ if (this.isReassigned || context.includedCallArguments.has(this.init)) {
6453
+ for (const argument of parameters) {
6454
+ argument.include(context, false);
6576
6455
  }
6577
6456
  }
6578
6457
  else {
6579
6458
  context.includedCallArguments.add(this.init);
6580
- this.init.includeCallArguments(context, interaction);
6459
+ this.init.includeCallArguments(context, parameters);
6581
6460
  context.includedCallArguments.delete(this.init);
6582
6461
  }
6583
6462
  }
@@ -6657,31 +6536,18 @@ class IdentifierBase extends NodeBase {
6657
6536
  }
6658
6537
  }
6659
6538
  }
6660
- include(context) {
6661
- if (!this.included)
6662
- this.includeNode(context);
6663
- }
6664
- includeNode(context) {
6665
- this.included = true;
6539
+ include() {
6666
6540
  if (!this.deoptimized)
6667
6541
  this.applyDeoptimizations();
6668
- if (this.variable !== null) {
6669
- this.scope.context.includeVariableInModule(this.variable, EMPTY_PATH, context);
6670
- }
6671
- }
6672
- includePath(path, context) {
6673
6542
  if (!this.included) {
6674
6543
  this.included = true;
6675
6544
  if (this.variable !== null) {
6676
- this.scope.context.includeVariableInModule(this.variable, path, context);
6545
+ this.scope.context.includeVariableInModule(this.variable);
6677
6546
  }
6678
6547
  }
6679
- else if (path.length > 0) {
6680
- this.variable?.includePath(path, context);
6681
- }
6682
6548
  }
6683
- includeCallArguments(context, interaction) {
6684
- this.variable.includeCallArguments(context, interaction);
6549
+ includeCallArguments(context, parameters) {
6550
+ this.variable.includeCallArguments(context, parameters);
6685
6551
  }
6686
6552
  isPossibleTDZ() {
6687
6553
  // return cached value to avoid issues with the next tree-shaking pass
@@ -6764,39 +6630,10 @@ function closestParentFunctionOrProgram(node) {
6764
6630
  return node;
6765
6631
  }
6766
6632
 
6767
- class ObjectMember extends ExpressionEntity {
6768
- constructor(object, path) {
6769
- super();
6770
- this.object = object;
6771
- this.path = path;
6772
- }
6773
- deoptimizeArgumentsOnInteractionAtPath(interaction, path, recursionTracker) {
6774
- this.object.deoptimizeArgumentsOnInteractionAtPath(interaction, [...this.path, ...path], recursionTracker);
6775
- }
6776
- deoptimizePath(path) {
6777
- this.object.deoptimizePath([...this.path, ...path]);
6778
- }
6779
- getLiteralValueAtPath(path, recursionTracker, origin) {
6780
- return this.object.getLiteralValueAtPath([...this.path, ...path], recursionTracker, origin);
6781
- }
6782
- getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin) {
6783
- return this.object.getReturnExpressionWhenCalledAtPath([...this.path, ...path], interaction, recursionTracker, origin);
6784
- }
6785
- hasEffectsOnInteractionAtPath(path, interaction, context) {
6786
- return this.object.hasEffectsOnInteractionAtPath([...this.path, ...path], interaction, context);
6787
- }
6788
- }
6789
-
6790
6633
  class Identifier extends IdentifierBase {
6791
6634
  constructor() {
6792
6635
  super(...arguments);
6793
- this.variable = null;
6794
- }
6795
- get isDestructuringDeoptimized() {
6796
- return isFlagSet(this.flags, 8388608 /* Flag.destructuringDeoptimized */);
6797
- }
6798
- set isDestructuringDeoptimized(value) {
6799
- this.flags = setFlag(this.flags, 8388608 /* Flag.destructuringDeoptimized */, value);
6636
+ this.variable = null;
6800
6637
  }
6801
6638
  addExportedVariables(variables, exportNamesByVariable) {
6802
6639
  if (exportNamesByVariable.has(this.variable)) {
@@ -6810,52 +6647,42 @@ class Identifier extends IdentifierBase {
6810
6647
  this.isVariableReference = true;
6811
6648
  }
6812
6649
  }
6813
- declare(kind, destructuredInitPath, init) {
6650
+ declare(kind, init) {
6814
6651
  let variable;
6815
6652
  const { treeshake } = this.scope.context.options;
6816
- if (kind === 'parameter') {
6817
- variable = this.scope.addParameterDeclaration(this, destructuredInitPath);
6818
- }
6819
- else {
6820
- variable = this.scope.addDeclaration(this, this.scope.context, init, destructuredInitPath, kind);
6821
- if (kind === 'var' && treeshake && treeshake.correctVarValueBeforeDeclaration) {
6822
- // Necessary to make sure the init is deoptimized. We cannot call deoptimizePath here.
6823
- variable.markInitializersForDeoptimization();
6653
+ switch (kind) {
6654
+ case 'var': {
6655
+ variable = this.scope.addDeclaration(this, this.scope.context, init, kind);
6656
+ if (treeshake && treeshake.correctVarValueBeforeDeclaration) {
6657
+ // Necessary to make sure the init is deoptimized. We cannot call deoptimizePath here.
6658
+ variable.markInitializersForDeoptimization();
6659
+ }
6660
+ break;
6824
6661
  }
6825
- }
6826
- return [(this.variable = variable)];
6827
- }
6828
- deoptimizeAssignment(destructuredInitPath, init) {
6829
- this.deoptimizePath(EMPTY_PATH);
6830
- init.deoptimizePath([...destructuredInitPath, UnknownKey]);
6831
- }
6832
- hasEffectsWhenDestructuring(context, destructuredInitPath, init) {
6833
- return (destructuredInitPath.length > 0 &&
6834
- init.hasEffectsOnInteractionAtPath(destructuredInitPath, NODE_INTERACTION_UNKNOWN_ACCESS, context));
6835
- }
6836
- includeDestructuredIfNecessary(context, destructuredInitPath, init) {
6837
- if (destructuredInitPath.length > 0 && !this.isDestructuringDeoptimized) {
6838
- this.isDestructuringDeoptimized = true;
6839
- init.deoptimizeArgumentsOnInteractionAtPath({
6840
- args: [new ObjectMember(init, destructuredInitPath.slice(0, -1))],
6841
- type: INTERACTION_ACCESSED
6842
- }, destructuredInitPath, SHARED_RECURSION_TRACKER);
6843
- }
6844
- const { propertyReadSideEffects } = this.scope.context.options
6845
- .treeshake;
6846
- if ((this.included ||=
6847
- destructuredInitPath.length > 0 &&
6848
- !context.brokenFlow &&
6849
- propertyReadSideEffects &&
6850
- (propertyReadSideEffects === 'always' ||
6851
- init.hasEffectsOnInteractionAtPath(destructuredInitPath, NODE_INTERACTION_UNKNOWN_ACCESS, createHasEffectsContext())))) {
6852
- if (this.variable && !this.variable.included) {
6853
- this.scope.context.includeVariableInModule(this.variable, EMPTY_PATH, context);
6662
+ case 'function': {
6663
+ // in strict mode, functions are only hoisted within a scope but not across block scopes
6664
+ variable = this.scope.addDeclaration(this, this.scope.context, init, kind);
6665
+ break;
6666
+ }
6667
+ case 'let':
6668
+ case 'const':
6669
+ case 'using':
6670
+ case 'await using':
6671
+ case 'class': {
6672
+ variable = this.scope.addDeclaration(this, this.scope.context, init, kind);
6673
+ break;
6674
+ }
6675
+ case 'parameter': {
6676
+ variable = this.scope.addParameterDeclaration(this);
6677
+ break;
6678
+ }
6679
+ /* istanbul ignore next */
6680
+ default: {
6681
+ /* istanbul ignore next */
6682
+ throw new Error(`Internal Error: Unexpected identifier kind ${kind}.`);
6854
6683
  }
6855
- init.includePath(destructuredInitPath, context);
6856
- return true;
6857
6684
  }
6858
- return false;
6685
+ return [(this.variable = variable)];
6859
6686
  }
6860
6687
  markDeclarationReached() {
6861
6688
  this.variable.initReached = true;
@@ -6909,17 +6736,18 @@ class Scope {
6909
6736
  - then the variable is still declared in the hoisted outer scope, but the initializer is assigned to the parameter
6910
6737
  - const, let, class, and function except in the cases above cannot redeclare anything
6911
6738
  */
6912
- addDeclaration(identifier, context, init, destructuredInitPath, kind) {
6739
+ addDeclaration(identifier, context, init, kind) {
6913
6740
  const name = identifier.name;
6914
6741
  const existingVariable = this.hoistedVariables?.get(name) || this.variables.get(name);
6915
6742
  if (existingVariable) {
6916
- if (kind === 'var' && existingVariable.kind === 'var') {
6743
+ const existingKind = existingVariable.kind;
6744
+ if (kind === 'var' && existingKind === 'var') {
6917
6745
  existingVariable.addDeclaration(identifier, init);
6918
6746
  return existingVariable;
6919
6747
  }
6920
6748
  context.error(parseAst_js.logRedeclarationError(name), identifier.start);
6921
6749
  }
6922
- const newVariable = new LocalVariable(identifier.name, identifier, init, destructuredInitPath, context, kind);
6750
+ const newVariable = new LocalVariable(identifier.name, identifier, init, context, kind);
6923
6751
  this.variables.set(name, newVariable);
6924
6752
  return newVariable;
6925
6753
  }
@@ -7095,6 +6923,7 @@ class MethodBase extends NodeBase {
7095
6923
  }
7096
6924
  return this.getAccessedValue()[0].hasEffectsOnInteractionAtPath(path, interaction, context);
7097
6925
  }
6926
+ applyDeoptimizations() { }
7098
6927
  getAccessedValue() {
7099
6928
  if (this.accessedValue === null) {
7100
6929
  if (this.kind === 'get') {
@@ -7108,20 +6937,19 @@ class MethodBase extends NodeBase {
7108
6937
  return this.accessedValue;
7109
6938
  }
7110
6939
  }
7111
- MethodBase.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
7112
- MethodBase.prototype.applyDeoptimizations = doNotDeoptimize;
7113
6940
 
7114
6941
  class MethodDefinition extends MethodBase {
7115
6942
  hasEffects(context) {
7116
6943
  return super.hasEffects(context) || checkEffectForNodes(this.decorators, context);
7117
6944
  }
6945
+ applyDeoptimizations() { }
7118
6946
  }
7119
6947
 
7120
6948
  class BlockScope extends ChildScope {
7121
6949
  constructor(parent) {
7122
6950
  super(parent, parent.context);
7123
6951
  }
7124
- addDeclaration(identifier, context, init, destructuredInitPath, kind) {
6952
+ addDeclaration(identifier, context, init, kind) {
7125
6953
  if (kind === 'var') {
7126
6954
  const name = identifier.name;
7127
6955
  const existingVariable = this.hoistedVariables?.get(name) || this.variables.get(name);
@@ -7133,7 +6961,7 @@ class BlockScope extends ChildScope {
7133
6961
  }
7134
6962
  return context.error(parseAst_js.logRedeclarationError(name), identifier.start);
7135
6963
  }
7136
- const declaredVariable = this.parent.addDeclaration(identifier, context, init, destructuredInitPath, kind);
6964
+ const declaredVariable = this.parent.addDeclaration(identifier, context, init, kind);
7137
6965
  // Necessary to make sure the init is deoptimized for conditional declarations.
7138
6966
  // We cannot call deoptimizePath here.
7139
6967
  declaredVariable.markInitializersForDeoptimization();
@@ -7141,7 +6969,7 @@ class BlockScope extends ChildScope {
7141
6969
  this.addHoistedVariable(name, declaredVariable);
7142
6970
  return declaredVariable;
7143
6971
  }
7144
- return super.addDeclaration(identifier, context, init, destructuredInitPath, kind);
6972
+ return super.addDeclaration(identifier, context, init, kind);
7145
6973
  }
7146
6974
  }
7147
6975
 
@@ -7173,12 +7001,33 @@ class StaticBlock extends NodeBase {
7173
7001
  }
7174
7002
  }
7175
7003
  }
7176
- StaticBlock.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
7177
- StaticBlock.prototype.applyDeoptimizations = doNotDeoptimize;
7178
7004
  function isStaticBlock(statement) {
7179
7005
  return statement.type === parseAst_js.StaticBlock;
7180
7006
  }
7181
7007
 
7008
+ class ObjectMember extends ExpressionEntity {
7009
+ constructor(object, key) {
7010
+ super();
7011
+ this.object = object;
7012
+ this.key = key;
7013
+ }
7014
+ deoptimizeArgumentsOnInteractionAtPath(interaction, path, recursionTracker) {
7015
+ this.object.deoptimizeArgumentsOnInteractionAtPath(interaction, [this.key, ...path], recursionTracker);
7016
+ }
7017
+ deoptimizePath(path) {
7018
+ this.object.deoptimizePath([this.key, ...path]);
7019
+ }
7020
+ getLiteralValueAtPath(path, recursionTracker, origin) {
7021
+ return this.object.getLiteralValueAtPath([this.key, ...path], recursionTracker, origin);
7022
+ }
7023
+ getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin) {
7024
+ return this.object.getReturnExpressionWhenCalledAtPath([this.key, ...path], interaction, recursionTracker, origin);
7025
+ }
7026
+ hasEffectsOnInteractionAtPath(path, interaction, context) {
7027
+ return this.object.hasEffectsOnInteractionAtPath([this.key, ...path], interaction, context);
7028
+ }
7029
+ }
7030
+
7182
7031
  class ClassNode extends NodeBase {
7183
7032
  constructor() {
7184
7033
  super(...arguments);
@@ -7219,20 +7068,21 @@ class ClassNode extends NodeBase {
7219
7068
  : this.getObjectEntity().hasEffectsOnInteractionAtPath(path, interaction, context);
7220
7069
  }
7221
7070
  include(context, includeChildrenRecursively) {
7222
- if (!this.included)
7223
- this.includeNode(context);
7071
+ if (!this.deoptimized)
7072
+ this.applyDeoptimizations();
7073
+ this.included = true;
7224
7074
  this.superClass?.include(context, includeChildrenRecursively);
7225
7075
  this.body.include(context, includeChildrenRecursively);
7226
7076
  for (const decorator of this.decorators)
7227
7077
  decorator.include(context, includeChildrenRecursively);
7228
7078
  if (this.id) {
7229
7079
  this.id.markDeclarationReached();
7230
- this.id.include(context);
7080
+ this.id.include();
7231
7081
  }
7232
7082
  }
7233
7083
  initialise() {
7234
7084
  super.initialise();
7235
- this.id?.declare('class', EMPTY_PATH, this);
7085
+ this.id?.declare('class', this);
7236
7086
  for (const method of this.body.body) {
7237
7087
  if (method instanceof MethodDefinition && method.kind === 'constructor') {
7238
7088
  this.classConstructor = method;
@@ -7290,12 +7140,11 @@ class ClassNode extends NodeBase {
7290
7140
  staticProperties.unshift({
7291
7141
  key: 'prototype',
7292
7142
  kind: 'init',
7293
- property: new ObjectEntity(dynamicMethods, this.superClass ? new ObjectMember(this.superClass, ['prototype']) : OBJECT_PROTOTYPE)
7143
+ property: new ObjectEntity(dynamicMethods, this.superClass ? new ObjectMember(this.superClass, 'prototype') : OBJECT_PROTOTYPE)
7294
7144
  });
7295
7145
  return (this.objectEntity = new ObjectEntity(staticProperties, this.superClass || OBJECT_PROTOTYPE));
7296
7146
  }
7297
7147
  }
7298
- ClassNode.prototype.includeNode = onlyIncludeSelf;
7299
7148
 
7300
7149
  class ClassDeclaration extends ClassNode {
7301
7150
  initialise() {
@@ -7348,7 +7197,7 @@ class ClassDeclaration extends ClassNode {
7348
7197
 
7349
7198
  class ArgumentsVariable extends LocalVariable {
7350
7199
  constructor(context) {
7351
- super('arguments', null, UNKNOWN_EXPRESSION, EMPTY_PATH, context, 'other');
7200
+ super('arguments', null, UNKNOWN_EXPRESSION, context, 'other');
7352
7201
  this.deoptimizedArguments = [];
7353
7202
  }
7354
7203
  addArgumentToBeDeoptimized(argument) {
@@ -7362,8 +7211,8 @@ class ArgumentsVariable extends LocalVariable {
7362
7211
  hasEffectsOnInteractionAtPath(path, { type }) {
7363
7212
  return type !== INTERACTION_ACCESSED || path.length > 1;
7364
7213
  }
7365
- includePath(path, context) {
7366
- super.includePath(path, context);
7214
+ include() {
7215
+ super.include();
7367
7216
  for (const argument of this.deoptimizedArguments) {
7368
7217
  argument.deoptimizePath(UNKNOWN_PATH);
7369
7218
  }
@@ -7374,28 +7223,27 @@ class ArgumentsVariable extends LocalVariable {
7374
7223
  const MAX_TRACKED_INTERACTIONS = 20;
7375
7224
  const NO_INTERACTIONS = parseAst_js.EMPTY_ARRAY;
7376
7225
  const UNKNOWN_DEOPTIMIZED_FIELD = new Set([UnknownKey]);
7377
- const EMPTY_PATH_TRACKER = new EntityPathTracker();
7226
+ const EMPTY_PATH_TRACKER = new PathTracker();
7378
7227
  const UNKNOWN_DEOPTIMIZED_ENTITY = new Set([UNKNOWN_EXPRESSION]);
7379
7228
  class ParameterVariable extends LocalVariable {
7380
- constructor(name, declarator, argumentPath, context) {
7381
- super(name, declarator, UNKNOWN_EXPRESSION, argumentPath, context, 'parameter');
7229
+ constructor(name, declarator, context) {
7230
+ super(name, declarator, UNKNOWN_EXPRESSION, context, 'parameter');
7382
7231
  this.deoptimizationInteractions = [];
7383
- this.deoptimizations = new EntityPathTracker();
7232
+ this.deoptimizations = new PathTracker();
7384
7233
  this.deoptimizedFields = new Set();
7385
- this.argumentsToBeDeoptimized = new Set();
7386
- this.expressionsDependingOnKnownValue = [];
7234
+ this.entitiesToBeDeoptimized = new Set();
7235
+ this.expressionsUseTheKnownValue = [];
7387
7236
  this.knownValue = null;
7388
7237
  this.knownValueLiteral = UnknownValue;
7389
7238
  this.frozenValue = null;
7390
7239
  }
7391
- addArgumentValue(entity) {
7392
- this.updateKnownValue(entity);
7240
+ addEntityToBeDeoptimized(entity) {
7393
7241
  if (entity === UNKNOWN_EXPRESSION) {
7394
7242
  // As unknown expressions fully deoptimize all interactions, we can clear
7395
7243
  // the interaction cache at this point provided we keep this optimization
7396
7244
  // in mind when adding new interactions
7397
- if (!this.argumentsToBeDeoptimized.has(UNKNOWN_EXPRESSION)) {
7398
- this.argumentsToBeDeoptimized.add(UNKNOWN_EXPRESSION);
7245
+ if (!this.entitiesToBeDeoptimized.has(UNKNOWN_EXPRESSION)) {
7246
+ this.entitiesToBeDeoptimized.add(UNKNOWN_EXPRESSION);
7399
7247
  for (const { interaction } of this.deoptimizationInteractions) {
7400
7248
  deoptimizeInteraction(interaction);
7401
7249
  }
@@ -7405,34 +7253,27 @@ class ParameterVariable extends LocalVariable {
7405
7253
  else if (this.deoptimizedFields.has(UnknownKey)) {
7406
7254
  // This means that we already deoptimized all interactions and no longer
7407
7255
  // track them
7408
- entity.deoptimizePath([...this.initPath, UnknownKey]);
7256
+ entity.deoptimizePath(UNKNOWN_PATH);
7409
7257
  }
7410
- else if (!this.argumentsToBeDeoptimized.has(entity)) {
7411
- this.argumentsToBeDeoptimized.add(entity);
7258
+ else if (!this.entitiesToBeDeoptimized.has(entity)) {
7259
+ this.entitiesToBeDeoptimized.add(entity);
7412
7260
  for (const field of this.deoptimizedFields) {
7413
- entity.deoptimizePath([...this.initPath, field]);
7261
+ entity.deoptimizePath([field]);
7414
7262
  }
7415
7263
  for (const { interaction, path } of this.deoptimizationInteractions) {
7416
- if (this.initPath.length + path.length > MAX_PATH_DEPTH) {
7417
- deoptimizeInteraction(interaction);
7418
- continue;
7419
- }
7420
- entity.deoptimizeArgumentsOnInteractionAtPath(interaction, [...this.initPath, ...path], SHARED_RECURSION_TRACKER);
7264
+ entity.deoptimizeArgumentsOnInteractionAtPath(interaction, path, SHARED_RECURSION_TRACKER);
7421
7265
  }
7422
7266
  }
7423
7267
  }
7424
- /** This says we should not make assumptions about the value of the parameter.
7425
- * This is different from deoptimization that will also cause argument values
7426
- * to be deoptimized. */
7427
7268
  markReassigned() {
7428
7269
  if (this.isReassigned) {
7429
7270
  return;
7430
7271
  }
7431
7272
  super.markReassigned();
7432
- for (const expression of this.expressionsDependingOnKnownValue) {
7273
+ for (const expression of this.expressionsUseTheKnownValue) {
7433
7274
  expression.deoptimizeCache();
7434
7275
  }
7435
- this.expressionsDependingOnKnownValue = parseAst_js.EMPTY_ARRAY;
7276
+ this.expressionsUseTheKnownValue = parseAst_js.EMPTY_ARRAY;
7436
7277
  }
7437
7278
  deoptimizeCache() {
7438
7279
  this.markReassigned();
@@ -7449,7 +7290,7 @@ class ParameterVariable extends LocalVariable {
7449
7290
  }
7450
7291
  if (this.knownValue === null) {
7451
7292
  this.knownValue = argument;
7452
- this.knownValueLiteral = argument.getLiteralValueAtPath(this.initPath, SHARED_RECURSION_TRACKER, this);
7293
+ this.knownValueLiteral = argument.getLiteralValueAtPath(EMPTY_PATH, SHARED_RECURSION_TRACKER, this);
7453
7294
  return;
7454
7295
  }
7455
7296
  // the same literal or identifier, do nothing
@@ -7465,7 +7306,7 @@ class ParameterVariable extends LocalVariable {
7465
7306
  return;
7466
7307
  }
7467
7308
  // add tracking for the new argument
7468
- const newValue = argument.getLiteralValueAtPath(this.initPath, SHARED_RECURSION_TRACKER, this);
7309
+ const newValue = argument.getLiteralValueAtPath(EMPTY_PATH, SHARED_RECURSION_TRACKER, this);
7469
7310
  if (newValue !== oldValue) {
7470
7311
  this.markReassigned();
7471
7312
  }
@@ -7483,31 +7324,24 @@ class ParameterVariable extends LocalVariable {
7483
7324
  return this.frozenValue;
7484
7325
  }
7485
7326
  getLiteralValueAtPath(path, recursionTracker, origin) {
7486
- if (this.isReassigned || path.length + this.initPath.length > MAX_PATH_DEPTH) {
7327
+ if (this.isReassigned) {
7487
7328
  return UnknownValue;
7488
7329
  }
7489
7330
  const knownValue = this.getKnownValue();
7490
- this.expressionsDependingOnKnownValue.push(origin);
7491
- return recursionTracker.withTrackedEntityAtPath(path, knownValue, () => knownValue.getLiteralValueAtPath([...this.initPath, ...path], recursionTracker, origin), UnknownValue);
7331
+ this.expressionsUseTheKnownValue.push(origin);
7332
+ return recursionTracker.withTrackedEntityAtPath(path, knownValue, () => knownValue.getLiteralValueAtPath(path, recursionTracker, origin), UnknownValue);
7492
7333
  }
7493
7334
  hasEffectsOnInteractionAtPath(path, interaction, context) {
7494
- const { type } = interaction;
7495
- if (this.isReassigned ||
7496
- type === INTERACTION_ASSIGNED ||
7497
- path.length + this.initPath.length > MAX_PATH_DEPTH) {
7335
+ if (this.isReassigned || interaction.type === INTERACTION_ASSIGNED) {
7498
7336
  return super.hasEffectsOnInteractionAtPath(path, interaction, context);
7499
7337
  }
7500
- return (!(type === INTERACTION_CALLED
7501
- ? (interaction.withNew
7502
- ? context.instantiated
7503
- : context.called).trackEntityAtPathAndGetIfTracked(path, interaction.args, this)
7504
- : context.accessed.trackEntityAtPathAndGetIfTracked(path, this)) &&
7505
- this.getKnownValue().hasEffectsOnInteractionAtPath([...this.initPath, ...path], interaction, context));
7338
+ const knownValue = this.getKnownValue();
7339
+ return knownValue.hasEffectsOnInteractionAtPath(path, interaction, context);
7506
7340
  }
7507
7341
  deoptimizeArgumentsOnInteractionAtPath(interaction, path) {
7508
7342
  // For performance reasons, we fully deoptimize all deeper interactions
7509
7343
  if (path.length >= 2 ||
7510
- this.argumentsToBeDeoptimized.has(UNKNOWN_EXPRESSION) ||
7344
+ this.entitiesToBeDeoptimized.has(UNKNOWN_EXPRESSION) ||
7511
7345
  this.deoptimizationInteractions.length >= MAX_TRACKED_INTERACTIONS ||
7512
7346
  (path.length === 1 &&
7513
7347
  (this.deoptimizedFields.has(UnknownKey) ||
@@ -7516,10 +7350,10 @@ class ParameterVariable extends LocalVariable {
7516
7350
  return;
7517
7351
  }
7518
7352
  if (!this.deoptimizations.trackEntityAtPathAndGetIfTracked(path, interaction.args)) {
7519
- for (const entity of this.argumentsToBeDeoptimized) {
7520
- entity.deoptimizeArgumentsOnInteractionAtPath(interaction, [...this.initPath, ...path], SHARED_RECURSION_TRACKER);
7353
+ for (const entity of this.entitiesToBeDeoptimized) {
7354
+ entity.deoptimizeArgumentsOnInteractionAtPath(interaction, path, SHARED_RECURSION_TRACKER);
7521
7355
  }
7522
- if (!this.argumentsToBeDeoptimized.has(UNKNOWN_EXPRESSION)) {
7356
+ if (!this.entitiesToBeDeoptimized.has(UNKNOWN_EXPRESSION)) {
7523
7357
  this.deoptimizationInteractions.push({
7524
7358
  interaction,
7525
7359
  path
@@ -7540,17 +7374,17 @@ class ParameterVariable extends LocalVariable {
7540
7374
  return;
7541
7375
  }
7542
7376
  this.deoptimizedFields.add(key);
7543
- for (const entity of this.argumentsToBeDeoptimized) {
7377
+ for (const entity of this.entitiesToBeDeoptimized) {
7544
7378
  // We do not need a recursion tracker here as we already track whether
7545
7379
  // this field is deoptimized
7546
- entity.deoptimizePath([...this.initPath, key]);
7380
+ entity.deoptimizePath([key]);
7547
7381
  }
7548
7382
  if (key === UnknownKey) {
7549
7383
  // save some memory
7550
7384
  this.deoptimizationInteractions = NO_INTERACTIONS;
7551
7385
  this.deoptimizations = EMPTY_PATH_TRACKER;
7552
7386
  this.deoptimizedFields = UNKNOWN_DEOPTIMIZED_FIELD;
7553
- this.argumentsToBeDeoptimized = UNKNOWN_DEOPTIMIZED_ENTITY;
7387
+ this.entitiesToBeDeoptimized = UNKNOWN_DEOPTIMIZED_ENTITY;
7554
7388
  }
7555
7389
  }
7556
7390
  getReturnExpressionWhenCalledAtPath(path) {
@@ -7565,14 +7399,11 @@ class ParameterVariable extends LocalVariable {
7565
7399
  }
7566
7400
  return UNKNOWN_RETURN_EXPRESSION;
7567
7401
  }
7568
- includeArgumentPaths(entity, context) {
7569
- this.includedPathTracker.includeAllPaths(entity, context, this.initPath);
7570
- }
7571
7402
  }
7572
7403
 
7573
7404
  class ThisVariable extends ParameterVariable {
7574
7405
  constructor(context) {
7575
- super('this', null, EMPTY_PATH, context);
7406
+ super('this', null, context);
7576
7407
  }
7577
7408
  hasEffectsOnInteractionAtPath(path, interaction, context) {
7578
7409
  return (context.replacedVariableInits.get(this) || UNKNOWN_EXPRESSION).hasEffectsOnInteractionAtPath(path, interaction, context);
@@ -7584,7 +7415,7 @@ class CatchBodyScope extends ChildScope {
7584
7415
  super(parent, parent.context);
7585
7416
  this.parent = parent;
7586
7417
  }
7587
- addDeclaration(identifier, context, init, destructuredInitPath, kind) {
7418
+ addDeclaration(identifier, context, init, kind) {
7588
7419
  if (kind === 'var') {
7589
7420
  const name = identifier.name;
7590
7421
  const existingVariable = this.hoistedVariables?.get(name) || this.variables.get(name);
@@ -7597,7 +7428,7 @@ class CatchBodyScope extends ChildScope {
7597
7428
  // the assignment actually goes to the parameter and the var is
7598
7429
  // hoisted without assignment. Locally, it is shadowed by the
7599
7430
  // parameter
7600
- const declaredVariable = this.parent.parent.addDeclaration(identifier, context, UNDEFINED_EXPRESSION, destructuredInitPath, kind);
7431
+ const declaredVariable = this.parent.parent.addDeclaration(identifier, context, UNDEFINED_EXPRESSION, kind);
7601
7432
  // To avoid the need to rewrite the declaration, we link the variable
7602
7433
  // names. If we ever implement a logic that splits initialization and
7603
7434
  // assignment for hoisted vars, the "renderLikeHoisted" logic can be
@@ -7616,7 +7447,7 @@ class CatchBodyScope extends ChildScope {
7616
7447
  return context.error(parseAst_js.logRedeclarationError(name), identifier.start);
7617
7448
  }
7618
7449
  // We only add parameters to parameter scopes
7619
- const declaredVariable = this.parent.parent.addDeclaration(identifier, context, init, destructuredInitPath, kind);
7450
+ const declaredVariable = this.parent.parent.addDeclaration(identifier, context, init, kind);
7620
7451
  // Necessary to make sure the init is deoptimized for conditional declarations.
7621
7452
  // We cannot call deoptimizePath here.
7622
7453
  declaredVariable.markInitializersForDeoptimization();
@@ -7624,7 +7455,7 @@ class CatchBodyScope extends ChildScope {
7624
7455
  this.addHoistedVariable(name, declaredVariable);
7625
7456
  return declaredVariable;
7626
7457
  }
7627
- return super.addDeclaration(identifier, context, init, destructuredInitPath, kind);
7458
+ return super.addDeclaration(identifier, context, init, kind);
7628
7459
  }
7629
7460
  }
7630
7461
 
@@ -7634,7 +7465,7 @@ class FunctionBodyScope extends ChildScope {
7634
7465
  }
7635
7466
  // There is stuff that is only allowed in function scopes, i.e. functions can
7636
7467
  // be redeclared, functions and var can redeclare each other
7637
- addDeclaration(identifier, context, init, destructuredInitPath, kind) {
7468
+ addDeclaration(identifier, context, init, kind) {
7638
7469
  const name = identifier.name;
7639
7470
  const existingVariable = this.hoistedVariables?.get(name) || this.variables.get(name);
7640
7471
  if (existingVariable) {
@@ -7646,7 +7477,7 @@ class FunctionBodyScope extends ChildScope {
7646
7477
  }
7647
7478
  context.error(parseAst_js.logRedeclarationError(name), identifier.start);
7648
7479
  }
7649
- const newVariable = new LocalVariable(identifier.name, identifier, init, destructuredInitPath, context, kind);
7480
+ const newVariable = new LocalVariable(identifier.name, identifier, init, context, kind);
7650
7481
  this.variables.set(name, newVariable);
7651
7482
  return newVariable;
7652
7483
  }
@@ -7655,21 +7486,21 @@ class FunctionBodyScope extends ChildScope {
7655
7486
  class ParameterScope extends ChildScope {
7656
7487
  constructor(parent, isCatchScope) {
7657
7488
  super(parent, parent.context);
7658
- this.hasRest = false;
7659
7489
  this.parameters = [];
7490
+ this.hasRest = false;
7660
7491
  this.bodyScope = isCatchScope ? new CatchBodyScope(this) : new FunctionBodyScope(this);
7661
7492
  }
7662
7493
  /**
7663
7494
  * Adds a parameter to this scope. Parameters must be added in the correct
7664
7495
  * order, i.e. from left to right.
7665
7496
  */
7666
- addParameterDeclaration(identifier, argumentPath) {
7497
+ addParameterDeclaration(identifier) {
7667
7498
  const { name, start } = identifier;
7668
7499
  const existingParameter = this.variables.get(name);
7669
7500
  if (existingParameter) {
7670
7501
  return this.context.error(parseAst_js.logDuplicateArgumentNameError(name), start);
7671
7502
  }
7672
- const variable = new ParameterVariable(name, identifier, argumentPath, this.context);
7503
+ const variable = new ParameterVariable(name, identifier, this.context);
7673
7504
  this.variables.set(name, variable);
7674
7505
  // We also add it to the body scope to detect name conflicts with local
7675
7506
  // variables. We still need the intermediate scope, though, as parameter
@@ -7687,56 +7518,42 @@ class ParameterScope extends ChildScope {
7687
7518
  }
7688
7519
  this.hasRest = hasRest;
7689
7520
  }
7690
- includeCallArguments(context, interaction) {
7521
+ includeCallArguments(context, parameters) {
7691
7522
  let calledFromTryStatement = false;
7692
7523
  let argumentIncluded = false;
7693
7524
  const restParameter = this.hasRest && this.parameters[this.parameters.length - 1];
7694
- const { args } = interaction;
7695
- let lastExplicitlyIncludedIndex = args.length - 1;
7696
- // If there is a SpreadElement, we need to include all arguments after it
7697
- // because we no longer know which argument corresponds to which parameter.
7698
- for (let argumentIndex = 1; argumentIndex < args.length; argumentIndex++) {
7699
- const argument = args[argumentIndex];
7700
- if (argument instanceof SpreadElement && !argumentIncluded) {
7701
- argumentIncluded = true;
7702
- lastExplicitlyIncludedIndex = argumentIndex - 1;
7703
- }
7704
- if (argumentIncluded) {
7705
- argument.includePath(UNKNOWN_PATH, context);
7706
- argument.include(context, false);
7525
+ for (const checkedArgument of parameters) {
7526
+ if (checkedArgument instanceof SpreadElement) {
7527
+ for (const argument of parameters) {
7528
+ argument.include(context, false);
7529
+ }
7530
+ break;
7707
7531
  }
7708
7532
  }
7709
- // Now we go backwards either starting from the last argument or before the
7710
- // first SpreadElement to ensure all arguments before are included as needed
7711
- for (let index = lastExplicitlyIncludedIndex; index >= 1; index--) {
7712
- const parameterVariables = this.parameters[index - 1] || restParameter;
7713
- const argument = args[index];
7533
+ for (let index = parameters.length - 1; index >= 0; index--) {
7534
+ const parameterVariables = this.parameters[index] || restParameter;
7535
+ const argument = parameters[index];
7714
7536
  if (parameterVariables) {
7715
7537
  calledFromTryStatement = false;
7716
7538
  if (parameterVariables.length === 0) {
7717
- // handle empty destructuring to avoid destructuring undefined
7539
+ // handle empty destructuring
7718
7540
  argumentIncluded = true;
7719
7541
  }
7720
7542
  else {
7721
7543
  for (const variable of parameterVariables) {
7722
- if (variable.calledFromTryStatement) {
7723
- calledFromTryStatement = true;
7724
- }
7725
7544
  if (variable.included) {
7726
7545
  argumentIncluded = true;
7727
- if (calledFromTryStatement) {
7728
- argument.include(context, true);
7729
- }
7730
- else {
7731
- variable.includeArgumentPaths(argument, context);
7732
- argument.include(context, false);
7733
- }
7546
+ }
7547
+ if (variable.calledFromTryStatement) {
7548
+ calledFromTryStatement = true;
7734
7549
  }
7735
7550
  }
7736
7551
  }
7737
7552
  }
7738
- if (!argument.included && (argumentIncluded || argument.shouldBeIncluded(context))) {
7553
+ if (!argumentIncluded && argument.shouldBeIncluded(context)) {
7739
7554
  argumentIncluded = true;
7555
+ }
7556
+ if (argumentIncluded) {
7740
7557
  argument.include(context, calledFromTryStatement);
7741
7558
  }
7742
7559
  }
@@ -7752,62 +7569,11 @@ class ReturnValueScope extends ParameterScope {
7752
7569
  addReturnExpression(expression) {
7753
7570
  this.returnExpressions.push(expression);
7754
7571
  }
7755
- deoptimizeArgumentsOnCall(interaction) {
7756
- const { parameters } = this;
7757
- const { args } = interaction;
7758
- let position = 0;
7759
- for (; position < args.length - 1; position++) {
7760
- // Only the "this" argument arg[0] can be null
7761
- const argument = args[position + 1];
7762
- if (argument instanceof SpreadElement) {
7763
- // This deoptimizes the current and remaining parameters and arguments
7764
- for (; position < parameters.length; position++) {
7765
- args[position + 1]?.deoptimizePath(UNKNOWN_PATH);
7766
- parameters[position].forEach(variable => variable.markReassigned());
7767
- }
7768
- break;
7769
- }
7770
- if (this.hasRest && position >= parameters.length - 1) {
7771
- argument.deoptimizePath(UNKNOWN_PATH);
7772
- }
7773
- else {
7774
- const variables = parameters[position];
7775
- if (variables) {
7776
- for (const variable of variables) {
7777
- variable.addArgumentValue(argument);
7778
- }
7779
- }
7780
- this.addArgumentToBeDeoptimized(argument);
7781
- }
7782
- }
7783
- const nonRestParameterLength = this.hasRest ? parameters.length - 1 : parameters.length;
7784
- for (; position < nonRestParameterLength; position++) {
7785
- for (const variable of parameters[position]) {
7786
- variable.addArgumentValue(UNDEFINED_EXPRESSION);
7787
- }
7788
- }
7789
- }
7790
7572
  getReturnExpression() {
7791
7573
  if (this.returnExpression === null)
7792
7574
  this.updateReturnExpression();
7793
7575
  return this.returnExpression;
7794
7576
  }
7795
- deoptimizeAllParameters() {
7796
- for (const parameter of this.parameters) {
7797
- for (const variable of parameter) {
7798
- variable.deoptimizePath(UNKNOWN_PATH);
7799
- variable.markReassigned();
7800
- }
7801
- }
7802
- }
7803
- reassignAllParameters() {
7804
- for (const parameter of this.parameters) {
7805
- for (const variable of parameter) {
7806
- variable.markReassigned();
7807
- }
7808
- }
7809
- }
7810
- addArgumentToBeDeoptimized(_argument) { }
7811
7577
  updateReturnExpression() {
7812
7578
  if (this.returnExpressions.length === 1) {
7813
7579
  this.returnExpression = this.returnExpressions[0];
@@ -7823,30 +7589,24 @@ class ReturnValueScope extends ParameterScope {
7823
7589
 
7824
7590
  class FunctionScope extends ReturnValueScope {
7825
7591
  constructor(parent) {
7826
- super(parent, false);
7827
7592
  const { context } = parent;
7593
+ super(parent, false);
7828
7594
  this.variables.set('arguments', (this.argumentsVariable = new ArgumentsVariable(context)));
7829
7595
  this.variables.set('this', (this.thisVariable = new ThisVariable(context)));
7830
7596
  }
7831
7597
  findLexicalBoundary() {
7832
7598
  return this;
7833
7599
  }
7834
- includeCallArguments(context, interaction) {
7835
- super.includeCallArguments(context, interaction);
7600
+ includeCallArguments(context, parameters) {
7601
+ super.includeCallArguments(context, parameters);
7836
7602
  if (this.argumentsVariable.included) {
7837
- const { args } = interaction;
7838
- for (let argumentIndex = 1; argumentIndex < args.length; argumentIndex++) {
7839
- const argument = args[argumentIndex];
7840
- if (argument) {
7841
- argument.includePath(UNKNOWN_PATH, context);
7603
+ for (const argument of parameters) {
7604
+ if (!argument.included) {
7842
7605
  argument.include(context, false);
7843
7606
  }
7844
7607
  }
7845
7608
  }
7846
7609
  }
7847
- addArgumentToBeDeoptimized(argument) {
7848
- this.argumentsVariable.addArgumentToBeDeoptimized(argument);
7849
- }
7850
7610
  }
7851
7611
 
7852
7612
  class ExpressionStatement extends NodeBase {
@@ -7874,9 +7634,8 @@ class ExpressionStatement extends NodeBase {
7874
7634
  return this.parent.type !== parseAst_js.Program;
7875
7635
  return super.shouldBeIncluded(context);
7876
7636
  }
7637
+ applyDeoptimizations() { }
7877
7638
  }
7878
- ExpressionStatement.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
7879
- ExpressionStatement.prototype.applyDeoptimizations = doNotDeoptimize;
7880
7639
 
7881
7640
  class BlockStatement extends NodeBase {
7882
7641
  get deoptimizeBody() {
@@ -7941,8 +7700,6 @@ class BlockStatement extends NodeBase {
7941
7700
  }
7942
7701
  }
7943
7702
  }
7944
- BlockStatement.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
7945
- BlockStatement.prototype.applyDeoptimizations = doNotDeoptimize;
7946
7703
 
7947
7704
  class RestElement extends NodeBase {
7948
7705
  constructor() {
@@ -7952,12 +7709,9 @@ class RestElement extends NodeBase {
7952
7709
  addExportedVariables(variables, exportNamesByVariable) {
7953
7710
  this.argument.addExportedVariables(variables, exportNamesByVariable);
7954
7711
  }
7955
- declare(kind, destructuredInitPath, init) {
7712
+ declare(kind, init) {
7956
7713
  this.declarationInit = init;
7957
- return this.argument.declare(kind, getIncludedPatternPath$1(destructuredInitPath), init);
7958
- }
7959
- deoptimizeAssignment(destructuredInitPath, init) {
7960
- this.argument.deoptimizeAssignment(getIncludedPatternPath$1(destructuredInitPath), init);
7714
+ return this.argument.declare(kind, UNKNOWN_EXPRESSION);
7961
7715
  }
7962
7716
  deoptimizePath(path) {
7963
7717
  if (path.length === 0) {
@@ -7968,20 +7722,6 @@ class RestElement extends NodeBase {
7968
7722
  return (path.length > 0 ||
7969
7723
  this.argument.hasEffectsOnInteractionAtPath(EMPTY_PATH, interaction, context));
7970
7724
  }
7971
- hasEffectsWhenDestructuring(context, destructuredInitPath, init) {
7972
- return this.argument.hasEffectsWhenDestructuring(context, getIncludedPatternPath$1(destructuredInitPath), init);
7973
- }
7974
- includeDestructuredIfNecessary(context, destructuredInitPath, init) {
7975
- return (this.included =
7976
- this.argument.includeDestructuredIfNecessary(context, getIncludedPatternPath$1(destructuredInitPath), init) || this.included);
7977
- }
7978
- include(context, includeChildrenRecursively) {
7979
- if (!this.included)
7980
- this.includeNode(context);
7981
- // This should just include the identifier, its properties should be
7982
- // included where the variable is used.
7983
- this.argument.include(context, includeChildrenRecursively);
7984
- }
7985
7725
  markDeclarationReached() {
7986
7726
  this.argument.markDeclarationReached();
7987
7727
  }
@@ -7993,16 +7733,12 @@ class RestElement extends NodeBase {
7993
7733
  }
7994
7734
  }
7995
7735
  }
7996
- RestElement.prototype.includeNode = onlyIncludeSelf;
7997
- const getIncludedPatternPath$1 = (destructuredInitPath) => destructuredInitPath.at(-1) === UnknownKey
7998
- ? destructuredInitPath
7999
- : [...destructuredInitPath, UnknownKey];
8000
7736
 
8001
7737
  class FunctionBase extends NodeBase {
8002
7738
  constructor() {
8003
7739
  super(...arguments);
7740
+ this.objectEntity = null;
8004
7741
  this.parameterVariableValuesDeoptimized = false;
8005
- this.includeCallArguments = this.scope.includeCallArguments.bind(this.scope);
8006
7742
  }
8007
7743
  get async() {
8008
7744
  return isFlagSet(this.flags, 256 /* Flag.async */);
@@ -8022,9 +7758,53 @@ class FunctionBase extends NodeBase {
8022
7758
  set generator(value) {
8023
7759
  this.flags = setFlag(this.flags, 4194304 /* Flag.generator */, value);
8024
7760
  }
7761
+ updateParameterVariableValues(_arguments) {
7762
+ for (let position = 0; position < this.params.length; position++) {
7763
+ const parameter = this.params[position];
7764
+ if (!(parameter instanceof Identifier)) {
7765
+ continue;
7766
+ }
7767
+ const parameterVariable = parameter.variable;
7768
+ const argument = _arguments[position + 1] ?? UNDEFINED_EXPRESSION;
7769
+ parameterVariable.updateKnownValue(argument);
7770
+ }
7771
+ }
7772
+ deoptimizeParameterVariableValues() {
7773
+ for (const parameter of this.params) {
7774
+ if (parameter instanceof Identifier) {
7775
+ const parameterVariable = parameter.variable;
7776
+ parameterVariable.markReassigned();
7777
+ }
7778
+ }
7779
+ }
8025
7780
  deoptimizeArgumentsOnInteractionAtPath(interaction, path, recursionTracker) {
8026
- if (interaction.type === INTERACTION_CALLED && path.length === 0) {
8027
- this.scope.deoptimizeArgumentsOnCall(interaction);
7781
+ if (interaction.type === INTERACTION_CALLED) {
7782
+ const { parameters } = this.scope;
7783
+ const { args } = interaction;
7784
+ let hasRest = false;
7785
+ for (let position = 0; position < args.length - 1; position++) {
7786
+ const parameter = this.params[position];
7787
+ // Only the "this" argument arg[0] can be null
7788
+ const argument = args[position + 1];
7789
+ if (argument instanceof SpreadElement) {
7790
+ this.deoptimizeParameterVariableValues();
7791
+ }
7792
+ if (hasRest || parameter instanceof RestElement) {
7793
+ hasRest = true;
7794
+ argument.deoptimizePath(UNKNOWN_PATH);
7795
+ }
7796
+ else if (parameter instanceof Identifier) {
7797
+ parameters[position][0].addEntityToBeDeoptimized(argument);
7798
+ this.addArgumentToBeDeoptimized(argument);
7799
+ }
7800
+ else if (parameter) {
7801
+ argument.deoptimizePath(UNKNOWN_PATH);
7802
+ }
7803
+ else {
7804
+ this.addArgumentToBeDeoptimized(argument);
7805
+ }
7806
+ }
7807
+ this.updateParameterVariableValues(args);
8028
7808
  }
8029
7809
  else {
8030
7810
  this.getObjectEntity().deoptimizeArgumentsOnInteractionAtPath(interaction, path, recursionTracker);
@@ -8036,7 +7816,12 @@ class FunctionBase extends NodeBase {
8036
7816
  // A reassignment of UNKNOWN_PATH is considered equivalent to having lost track
8037
7817
  // which means the return expression and parameters need to be reassigned
8038
7818
  this.scope.getReturnExpression().deoptimizePath(UNKNOWN_PATH);
8039
- this.scope.deoptimizeAllParameters();
7819
+ for (const parameterList of this.scope.parameters) {
7820
+ for (const parameter of parameterList) {
7821
+ parameter.deoptimizePath(UNKNOWN_PATH);
7822
+ parameter.markReassigned();
7823
+ }
7824
+ }
8040
7825
  }
8041
7826
  }
8042
7827
  getLiteralValueAtPath(path, recursionTracker, origin) {
@@ -8074,13 +7859,8 @@ class FunctionBase extends NodeBase {
8074
7859
  return true;
8075
7860
  }
8076
7861
  }
8077
- const { propertyReadSideEffects } = this.scope.context.options
8078
- .treeshake;
8079
- for (let index = 0; index < this.params.length; index++) {
8080
- const parameter = this.params[index];
8081
- if (parameter.hasEffects(context) ||
8082
- (propertyReadSideEffects &&
8083
- parameter.hasEffectsWhenDestructuring(context, EMPTY_PATH, interaction.args[index + 1] || UNDEFINED_EXPRESSION)))
7862
+ for (const parameter of this.params) {
7863
+ if (parameter.hasEffects(context))
8084
7864
  return true;
8085
7865
  }
8086
7866
  return false;
@@ -8099,17 +7879,21 @@ class FunctionBase extends NodeBase {
8099
7879
  return variable?.getOnlyFunctionCallUsed() ?? false;
8100
7880
  }
8101
7881
  include(context, includeChildrenRecursively) {
8102
- if (!this.included)
8103
- this.includeNode(context);
8104
- if (!(this.parameterVariableValuesDeoptimized || this.onlyFunctionCallUsed())) {
7882
+ if (!this.parameterVariableValuesDeoptimized && !this.onlyFunctionCallUsed()) {
8105
7883
  this.parameterVariableValuesDeoptimized = true;
8106
- this.scope.reassignAllParameters();
7884
+ this.deoptimizeParameterVariableValues();
8107
7885
  }
7886
+ if (!this.deoptimized)
7887
+ this.applyDeoptimizations();
7888
+ this.included = true;
8108
7889
  const { brokenFlow } = context;
8109
7890
  context.brokenFlow = false;
8110
7891
  this.body.include(context, includeChildrenRecursively);
8111
7892
  context.brokenFlow = brokenFlow;
8112
7893
  }
7894
+ includeCallArguments(context, parameters) {
7895
+ this.scope.includeCallArguments(context, parameters);
7896
+ }
8113
7897
  initialise() {
8114
7898
  super.initialise();
8115
7899
  if (this.body instanceof BlockStatement) {
@@ -8131,14 +7915,14 @@ class FunctionBase extends NodeBase {
8131
7915
  // so that the scope already knows all parameters and can detect conflicts
8132
7916
  // when parsing the body.
8133
7917
  const parameters = (this.params = params.map((parameter) => new (context.getNodeConstructor(parameter.type))(this, scope).parseNode(parameter)));
8134
- scope.addParameterVariables(parameters.map(parameter => parameter.declare('parameter', EMPTY_PATH, UNKNOWN_EXPRESSION)), parameters[parameters.length - 1] instanceof RestElement);
7918
+ scope.addParameterVariables(parameters.map(parameter => parameter.declare('parameter', UNKNOWN_EXPRESSION)), parameters[parameters.length - 1] instanceof RestElement);
8135
7919
  this.body = new (context.getNodeConstructor(body.type))(this, bodyScope).parseNode(body);
8136
7920
  return super.parseNode(esTreeNode);
8137
7921
  }
7922
+ addArgumentToBeDeoptimized(_argument) { }
7923
+ applyDeoptimizations() { }
8138
7924
  }
8139
7925
  FunctionBase.prototype.preventChildBlockScope = true;
8140
- FunctionBase.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
8141
- FunctionBase.prototype.applyDeoptimizations = doNotDeoptimize;
8142
7926
 
8143
7927
  class FunctionNode extends FunctionBase {
8144
7928
  constructor() {
@@ -8150,16 +7934,18 @@ class FunctionNode extends FunctionBase {
8150
7934
  this.constructedEntity = new ObjectEntity(Object.create(null), OBJECT_PROTOTYPE);
8151
7935
  // This makes sure that all deoptimizations of "this" are applied to the
8152
7936
  // constructed entity.
8153
- this.scope.thisVariable.addArgumentValue(this.constructedEntity);
7937
+ this.scope.thisVariable.addEntityToBeDeoptimized(this.constructedEntity);
8154
7938
  }
8155
7939
  deoptimizeArgumentsOnInteractionAtPath(interaction, path, recursionTracker) {
8156
7940
  super.deoptimizeArgumentsOnInteractionAtPath(interaction, path, recursionTracker);
8157
7941
  if (interaction.type === INTERACTION_CALLED && path.length === 0 && interaction.args[0]) {
8158
7942
  // args[0] is the "this" argument
8159
- this.scope.thisVariable.addArgumentValue(interaction.args[0]);
7943
+ this.scope.thisVariable.addEntityToBeDeoptimized(interaction.args[0]);
8160
7944
  }
8161
7945
  }
8162
7946
  hasEffects(context) {
7947
+ if (!this.deoptimized)
7948
+ this.applyDeoptimizations();
8163
7949
  if (this.annotationNoSideEffects) {
8164
7950
  return false;
8165
7951
  }
@@ -8197,7 +7983,7 @@ class FunctionNode extends FunctionBase {
8197
7983
  }
8198
7984
  include(context, includeChildrenRecursively) {
8199
7985
  super.include(context, includeChildrenRecursively);
8200
- this.id?.include(context);
7986
+ this.id?.include();
8201
7987
  const hasArguments = this.scope.argumentsVariable.included;
8202
7988
  for (const parameter of this.params) {
8203
7989
  if (!(parameter instanceof Identifier) || hasArguments) {
@@ -8205,18 +7991,12 @@ class FunctionNode extends FunctionBase {
8205
7991
  }
8206
7992
  }
8207
7993
  }
8208
- includeNode(context) {
8209
- this.included = true;
8210
- const hasArguments = this.scope.argumentsVariable.included;
8211
- for (const parameter of this.params) {
8212
- if (!(parameter instanceof Identifier) || hasArguments) {
8213
- parameter.includePath(UNKNOWN_PATH, context);
8214
- }
8215
- }
8216
- }
8217
7994
  initialise() {
8218
7995
  super.initialise();
8219
- this.id?.declare('function', EMPTY_PATH, this);
7996
+ this.id?.declare('function', this);
7997
+ }
7998
+ addArgumentToBeDeoptimized(argument) {
7999
+ this.scope.argumentsVariable.addArgumentToBeDeoptimized(argument);
8220
8000
  }
8221
8001
  getObjectEntity() {
8222
8002
  if (this.objectEntity !== null) {
@@ -8266,16 +8046,11 @@ function getFunctionIdInsertPosition(code, start) {
8266
8046
  }
8267
8047
  class ExportDefaultDeclaration extends NodeBase {
8268
8048
  include(context, includeChildrenRecursively) {
8269
- this.included = true;
8270
- this.declaration.include(context, includeChildrenRecursively);
8049
+ super.include(context, includeChildrenRecursively);
8271
8050
  if (includeChildrenRecursively) {
8272
- this.scope.context.includeVariableInModule(this.variable, UNKNOWN_PATH, context);
8051
+ this.scope.context.includeVariableInModule(this.variable);
8273
8052
  }
8274
8053
  }
8275
- includePath(path, context) {
8276
- this.included = true;
8277
- this.declaration.includePath(path, context);
8278
- }
8279
8054
  initialise() {
8280
8055
  super.initialise();
8281
8056
  const declaration = this.declaration;
@@ -8320,6 +8095,7 @@ class ExportDefaultDeclaration extends NodeBase {
8320
8095
  }
8321
8096
  this.declaration.render(code, options);
8322
8097
  }
8098
+ applyDeoptimizations() { }
8323
8099
  renderNamedDeclaration(code, declarationStart, idInsertPosition, options) {
8324
8100
  const { exportNamesByVariable, format, snippets: { getPropertyAccess } } = options;
8325
8101
  const name = this.variable.getName(getPropertyAccess);
@@ -8350,8 +8126,6 @@ class ExportDefaultDeclaration extends NodeBase {
8350
8126
  }
8351
8127
  }
8352
8128
  ExportDefaultDeclaration.prototype.needsBoundaries = true;
8353
- ExportDefaultDeclaration.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
8354
- ExportDefaultDeclaration.prototype.applyDeoptimizations = doNotDeoptimize;
8355
8129
 
8356
8130
  const needsEscapeRegEx = /[\n\r'\\\u2028\u2029]/;
8357
8131
  const quoteNewlineRegEx = /([\n\r'\u2028\u2029])/g;
@@ -8621,7 +8395,6 @@ class Literal extends NodeBase {
8621
8395
  }
8622
8396
  }
8623
8397
  }
8624
- Literal.prototype.includeNode = onlyIncludeSelf;
8625
8398
 
8626
8399
  function getChainElementLiteralValueAtPath(element, object, path, recursionTracker, origin) {
8627
8400
  if ('getLiteralValueAtPathAsChainElement' in object) {
@@ -8637,6 +8410,8 @@ function getChainElementLiteralValueAtPath(element, object, path, recursionTrack
8637
8410
  return element.getLiteralValueAtPath(path, recursionTracker, origin);
8638
8411
  }
8639
8412
 
8413
+ // To avoid infinite recursions
8414
+ const MAX_PATH_DEPTH = 7;
8640
8415
  function getResolvablePropertyKey(memberExpression) {
8641
8416
  return memberExpression.computed
8642
8417
  ? getResolvableComputedPropertyKey(memberExpression.property)
@@ -8735,27 +8510,18 @@ class MemberExpression extends NodeBase {
8735
8510
  }
8736
8511
  else if (!this.isUndefined) {
8737
8512
  if (path.length < MAX_PATH_DEPTH) {
8738
- this.object.deoptimizeArgumentsOnInteractionAtPath(interaction, this.propertyKey === UnknownKey ? UNKNOWN_PATH : [this.propertyKey, ...path], recursionTracker);
8513
+ this.object.deoptimizeArgumentsOnInteractionAtPath(interaction, [this.getPropertyKey(), ...path], recursionTracker);
8739
8514
  }
8740
8515
  else {
8741
8516
  deoptimizeInteraction(interaction);
8742
8517
  }
8743
8518
  }
8744
8519
  }
8745
- deoptimizeAssignment(destructuredInitPath, init) {
8746
- this.deoptimizePath(EMPTY_PATH);
8747
- init.deoptimizePath([...destructuredInitPath, UnknownKey]);
8748
- }
8749
8520
  deoptimizeCache() {
8750
- if (this.propertyKey === this.dynamicPropertyKey)
8751
- return;
8752
8521
  const { expressionsToBeDeoptimized, object } = this;
8753
8522
  this.expressionsToBeDeoptimized = parseAst_js.EMPTY_ARRAY;
8754
- this.dynamicPropertyKey = this.propertyKey;
8523
+ this.propertyKey = UnknownKey;
8755
8524
  object.deoptimizePath(UNKNOWN_PATH);
8756
- if (this.included) {
8757
- object.includePath(UNKNOWN_PATH, createInclusionContext());
8758
- }
8759
8525
  for (const expression of expressionsToBeDeoptimized) {
8760
8526
  expression.deoptimizeCache();
8761
8527
  }
@@ -8766,13 +8532,11 @@ class MemberExpression extends NodeBase {
8766
8532
  if (this.variable) {
8767
8533
  this.variable.deoptimizePath(path);
8768
8534
  }
8769
- else if (!this.isUndefined) {
8770
- const { propertyKey } = this;
8535
+ else if (!this.isUndefined && path.length < MAX_PATH_DEPTH) {
8536
+ const propertyKey = this.getPropertyKey();
8771
8537
  this.object.deoptimizePath([
8772
8538
  propertyKey === UnknownKey ? UnknownNonAccessorKey : propertyKey,
8773
- ...(path.length < MAX_PATH_DEPTH
8774
- ? path
8775
- : [...path.slice(0, MAX_PATH_DEPTH), UnknownKey])
8539
+ ...path
8776
8540
  ]);
8777
8541
  }
8778
8542
  }
@@ -8783,11 +8547,9 @@ class MemberExpression extends NodeBase {
8783
8547
  if (this.isUndefined) {
8784
8548
  return undefined;
8785
8549
  }
8786
- const propertyKey = this.getDynamicPropertyKey();
8787
- if (propertyKey !== UnknownKey && path.length < MAX_PATH_DEPTH) {
8788
- if (propertyKey !== this.propertyKey)
8789
- this.expressionsToBeDeoptimized.push(origin);
8790
- return this.object.getLiteralValueAtPath([propertyKey, ...path], recursionTracker, origin);
8550
+ if (this.propertyKey !== UnknownKey && path.length < MAX_PATH_DEPTH) {
8551
+ this.expressionsToBeDeoptimized.push(origin);
8552
+ return this.object.getLiteralValueAtPath([this.getPropertyKey(), ...path], recursionTracker, origin);
8791
8553
  }
8792
8554
  return UnknownValue;
8793
8555
  }
@@ -8807,11 +8569,9 @@ class MemberExpression extends NodeBase {
8807
8569
  if (this.isUndefined) {
8808
8570
  return [UNDEFINED_EXPRESSION, false];
8809
8571
  }
8810
- const propertyKey = this.getDynamicPropertyKey();
8811
- if (propertyKey !== UnknownKey && path.length < MAX_PATH_DEPTH) {
8812
- if (propertyKey !== this.propertyKey)
8813
- this.expressionsToBeDeoptimized.push(origin);
8814
- return this.object.getReturnExpressionWhenCalledAtPath([propertyKey, ...path], interaction, recursionTracker, origin);
8572
+ if (this.propertyKey !== UnknownKey && path.length < MAX_PATH_DEPTH) {
8573
+ this.expressionsToBeDeoptimized.push(origin);
8574
+ return this.object.getReturnExpressionWhenCalledAtPath([this.getPropertyKey(), ...path], interaction, recursionTracker, origin);
8815
8575
  }
8816
8576
  return UNKNOWN_RETURN_EXPRESSION;
8817
8577
  }
@@ -8857,45 +8617,14 @@ class MemberExpression extends NodeBase {
8857
8617
  return true;
8858
8618
  }
8859
8619
  if (path.length < MAX_PATH_DEPTH) {
8860
- return this.object.hasEffectsOnInteractionAtPath([this.getDynamicPropertyKey(), ...path], interaction, context);
8620
+ return this.object.hasEffectsOnInteractionAtPath([this.getPropertyKey(), ...path], interaction, context);
8861
8621
  }
8862
8622
  return true;
8863
8623
  }
8864
- hasEffectsWhenDestructuring(context, destructuredInitPath, init) {
8865
- return (destructuredInitPath.length > 0 &&
8866
- init.hasEffectsOnInteractionAtPath(destructuredInitPath, NODE_INTERACTION_UNKNOWN_ACCESS, context));
8867
- }
8868
8624
  include(context, includeChildrenRecursively) {
8869
- if (!this.included)
8870
- this.includeNode(context);
8871
- this.object.include(context, includeChildrenRecursively);
8872
- this.property.include(context, includeChildrenRecursively);
8873
- }
8874
- includeNode(context) {
8875
- this.included = true;
8876
8625
  if (!this.deoptimized)
8877
8626
  this.applyDeoptimizations();
8878
- if (this.variable) {
8879
- this.scope.context.includeVariableInModule(this.variable, EMPTY_PATH, context);
8880
- }
8881
- else if (!this.isUndefined) {
8882
- this.object.includePath([this.propertyKey], context);
8883
- }
8884
- }
8885
- includePath(path, context) {
8886
- if (!this.included)
8887
- this.includeNode(context);
8888
- if (this.variable) {
8889
- this.variable?.includePath(path, context);
8890
- }
8891
- else if (!this.isUndefined) {
8892
- this.object.includePath([
8893
- this.propertyKey,
8894
- ...(path.length < MAX_PATH_DEPTH
8895
- ? path
8896
- : [...path.slice(0, MAX_PATH_DEPTH), UnknownKey])
8897
- ], context);
8898
- }
8627
+ this.includeProperties(context, includeChildrenRecursively);
8899
8628
  }
8900
8629
  includeAsAssignmentTarget(context, includeChildrenRecursively, deoptimizeAccess) {
8901
8630
  if (!this.assignmentDeoptimized)
@@ -8904,34 +8633,20 @@ class MemberExpression extends NodeBase {
8904
8633
  this.include(context, includeChildrenRecursively);
8905
8634
  }
8906
8635
  else {
8907
- if (!this.included)
8908
- this.includeNode(context);
8909
- this.object.include(context, includeChildrenRecursively);
8910
- this.property.include(context, includeChildrenRecursively);
8636
+ this.includeProperties(context, includeChildrenRecursively);
8911
8637
  }
8912
8638
  }
8913
- includeCallArguments(context, interaction) {
8639
+ includeCallArguments(context, parameters) {
8914
8640
  if (this.variable) {
8915
- this.variable.includeCallArguments(context, interaction);
8641
+ this.variable.includeCallArguments(context, parameters);
8916
8642
  }
8917
8643
  else {
8918
- super.includeCallArguments(context, interaction);
8919
- }
8920
- }
8921
- includeDestructuredIfNecessary(context, destructuredInitPath, init) {
8922
- if ((this.included ||=
8923
- destructuredInitPath.length > 0 &&
8924
- !context.brokenFlow &&
8925
- init.hasEffectsOnInteractionAtPath(destructuredInitPath, NODE_INTERACTION_UNKNOWN_ACCESS, createHasEffectsContext()))) {
8926
- init.include(context, false);
8927
- return true;
8644
+ super.includeCallArguments(context, parameters);
8928
8645
  }
8929
- return false;
8930
8646
  }
8931
8647
  initialise() {
8932
8648
  super.initialise();
8933
- this.dynamicPropertyKey = getResolvablePropertyKey(this);
8934
- this.propertyKey = this.dynamicPropertyKey === null ? UnknownKey : this.dynamicPropertyKey;
8649
+ this.propertyKey = getResolvablePropertyKey(this);
8935
8650
  this.accessInteraction = { args: [this.object], type: INTERACTION_ACCESSED };
8936
8651
  }
8937
8652
  render(code, options, { renderedParentType, isCalleeOfRenderedParent, renderedSurroundingElement } = parseAst_js.BLANK) {
@@ -8968,7 +8683,8 @@ class MemberExpression extends NodeBase {
8968
8683
  this.bound &&
8969
8684
  propertyReadSideEffects &&
8970
8685
  !(this.variable || this.isUndefined)) {
8971
- this.object.deoptimizeArgumentsOnInteractionAtPath(this.accessInteraction, [this.propertyKey], SHARED_RECURSION_TRACKER);
8686
+ const propertyKey = this.getPropertyKey();
8687
+ this.object.deoptimizeArgumentsOnInteractionAtPath(this.accessInteraction, [propertyKey], SHARED_RECURSION_TRACKER);
8972
8688
  this.scope.context.requestTreeshakingPass();
8973
8689
  }
8974
8690
  if (this.variable) {
@@ -8985,7 +8701,7 @@ class MemberExpression extends NodeBase {
8985
8701
  this.bound &&
8986
8702
  propertyReadSideEffects &&
8987
8703
  !(this.variable || this.isUndefined)) {
8988
- this.object.deoptimizeArgumentsOnInteractionAtPath(this.assignmentInteraction, [this.propertyKey], SHARED_RECURSION_TRACKER);
8704
+ this.object.deoptimizeArgumentsOnInteractionAtPath(this.assignmentInteraction, [this.getPropertyKey()], SHARED_RECURSION_TRACKER);
8989
8705
  this.scope.context.requestTreeshakingPass();
8990
8706
  }
8991
8707
  }
@@ -8994,24 +8710,24 @@ class MemberExpression extends NodeBase {
8994
8710
  const variable = this.scope.findVariable(this.object.name);
8995
8711
  if (variable.isNamespace) {
8996
8712
  if (this.variable) {
8997
- this.scope.context.includeVariableInModule(this.variable, UNKNOWN_PATH, createInclusionContext());
8713
+ this.scope.context.includeVariableInModule(this.variable);
8998
8714
  }
8999
8715
  this.scope.context.log(parseAst_js.LOGLEVEL_WARN, parseAst_js.logIllegalImportReassignment(this.object.name, this.scope.context.module.id), this.start);
9000
8716
  }
9001
8717
  }
9002
8718
  }
9003
- getDynamicPropertyKey() {
9004
- if (this.dynamicPropertyKey === null) {
9005
- this.dynamicPropertyKey = this.propertyKey;
8719
+ getPropertyKey() {
8720
+ if (this.propertyKey === null) {
8721
+ this.propertyKey = UnknownKey;
9006
8722
  const value = this.property.getLiteralValueAtPath(EMPTY_PATH, SHARED_RECURSION_TRACKER, this);
9007
- return (this.dynamicPropertyKey =
8723
+ return (this.propertyKey =
9008
8724
  value === SymbolToStringTag
9009
8725
  ? value
9010
8726
  : typeof value === 'symbol'
9011
8727
  ? UnknownKey
9012
8728
  : String(value));
9013
8729
  }
9014
- return this.dynamicPropertyKey;
8730
+ return this.propertyKey;
9015
8731
  }
9016
8732
  hasAccessEffect(context) {
9017
8733
  const { propertyReadSideEffects } = this.scope.context.options
@@ -9019,7 +8735,17 @@ class MemberExpression extends NodeBase {
9019
8735
  return (!(this.variable || this.isUndefined) &&
9020
8736
  propertyReadSideEffects &&
9021
8737
  (propertyReadSideEffects === 'always' ||
9022
- this.object.hasEffectsOnInteractionAtPath([this.getDynamicPropertyKey()], this.accessInteraction, context)));
8738
+ this.object.hasEffectsOnInteractionAtPath([this.getPropertyKey()], this.accessInteraction, context)));
8739
+ }
8740
+ includeProperties(context, includeChildrenRecursively) {
8741
+ if (!this.included) {
8742
+ this.included = true;
8743
+ if (this.variable) {
8744
+ this.scope.context.includeVariableInModule(this.variable);
8745
+ }
8746
+ }
8747
+ this.object.include(context, includeChildrenRecursively);
8748
+ this.property.include(context, includeChildrenRecursively);
9023
8749
  }
9024
8750
  }
9025
8751
  function resolveNamespaceVariables(baseVariable, path, astContext) {
@@ -9063,20 +8789,18 @@ class MetaProperty extends NodeBase {
9063
8789
  return path.length > 1 || type !== INTERACTION_ACCESSED;
9064
8790
  }
9065
8791
  include() {
9066
- if (!this.included)
9067
- this.includeNode();
9068
- }
9069
- includeNode() {
9070
- this.included = true;
9071
- if (this.meta.name === IMPORT) {
9072
- this.scope.context.addImportMeta(this);
9073
- const parent = this.parent;
9074
- const metaProperty = (this.metaProperty =
9075
- parent instanceof MemberExpression && typeof parent.propertyKey === 'string'
9076
- ? parent.propertyKey
9077
- : null);
9078
- if (metaProperty?.startsWith(FILE_PREFIX)) {
9079
- this.referenceId = metaProperty.slice(FILE_PREFIX.length);
8792
+ if (!this.included) {
8793
+ this.included = true;
8794
+ if (this.meta.name === IMPORT) {
8795
+ this.scope.context.addImportMeta(this);
8796
+ const parent = this.parent;
8797
+ const metaProperty = (this.metaProperty =
8798
+ parent instanceof MemberExpression && typeof parent.propertyKey === 'string'
8799
+ ? parent.propertyKey
8800
+ : null);
8801
+ if (metaProperty?.startsWith(FILE_PREFIX)) {
8802
+ this.referenceId = metaProperty.slice(FILE_PREFIX.length);
8803
+ }
9080
8804
  }
9081
8805
  }
9082
8806
  }
@@ -9183,7 +8907,7 @@ class UndefinedVariable extends Variable {
9183
8907
 
9184
8908
  class ExportDefaultVariable extends LocalVariable {
9185
8909
  constructor(name, exportDefaultDeclaration, context) {
9186
- super(name, exportDefaultDeclaration, exportDefaultDeclaration.declaration, EMPTY_PATH, context, 'other');
8910
+ super(name, exportDefaultDeclaration, exportDefaultDeclaration.declaration, context, 'other');
9187
8911
  this.hasId = false;
9188
8912
  this.originalId = null;
9189
8913
  this.originalVariable = null;
@@ -9332,8 +9056,8 @@ class NamespaceVariable extends Variable {
9332
9056
  return (!memberVariable ||
9333
9057
  memberVariable.hasEffectsOnInteractionAtPath(path.slice(1), interaction, context));
9334
9058
  }
9335
- includePath(path, context) {
9336
- super.includePath(path, context);
9059
+ include() {
9060
+ super.include();
9337
9061
  this.context.includeAllExports();
9338
9062
  }
9339
9063
  prepare(accessedGlobalsByScope) {
@@ -9426,9 +9150,9 @@ class SyntheticNamedExportVariable extends Variable {
9426
9150
  getName(getPropertyAccess) {
9427
9151
  return `${this.syntheticNamespace.getName(getPropertyAccess)}${getPropertyAccess(this.name)}`;
9428
9152
  }
9429
- includePath(path, context) {
9430
- super.includePath(path, context);
9431
- this.context.includeVariableInModule(this.syntheticNamespace, path, context);
9153
+ include() {
9154
+ super.include();
9155
+ this.context.includeVariableInModule(this.syntheticNamespace);
9432
9156
  }
9433
9157
  setRenderNames(baseName, name) {
9434
9158
  super.setRenderNames(baseName, name);
@@ -12604,11 +12328,17 @@ const createFilter = function createFilter(include, exclude, options) {
12604
12328
  const pathId = normalizePath(id);
12605
12329
  for (let i = 0; i < excludeMatchers.length; ++i) {
12606
12330
  const matcher = excludeMatchers[i];
12331
+ if (matcher instanceof RegExp) {
12332
+ matcher.lastIndex = 0;
12333
+ }
12607
12334
  if (matcher.test(pathId))
12608
12335
  return false;
12609
12336
  }
12610
12337
  for (let i = 0; i < includeMatchers.length; ++i) {
12611
12338
  const matcher = includeMatchers[i];
12339
+ if (matcher instanceof RegExp) {
12340
+ matcher.lastIndex = 0;
12341
+ }
12612
12342
  if (matcher.test(pathId))
12613
12343
  return true;
12614
12344
  }
@@ -12627,37 +12357,21 @@ class ArrayPattern extends NodeBase {
12627
12357
  element?.addExportedVariables(variables, exportNamesByVariable);
12628
12358
  }
12629
12359
  }
12630
- declare(kind, destructuredInitPath, init) {
12360
+ declare(kind) {
12631
12361
  const variables = [];
12632
- const includedPatternPath = getIncludedPatternPath(destructuredInitPath);
12633
12362
  for (const element of this.elements) {
12634
12363
  if (element !== null) {
12635
- variables.push(...element.declare(kind, includedPatternPath, init));
12364
+ variables.push(...element.declare(kind, UNKNOWN_EXPRESSION));
12636
12365
  }
12637
12366
  }
12638
12367
  return variables;
12639
12368
  }
12640
- deoptimizeAssignment(destructuredInitPath, init) {
12641
- const includedPatternPath = getIncludedPatternPath(destructuredInitPath);
12642
- for (const element of this.elements) {
12643
- element?.deoptimizeAssignment(includedPatternPath, init);
12644
- }
12645
- }
12646
12369
  // Patterns can only be deoptimized at the empty path at the moment
12647
12370
  deoptimizePath() {
12648
12371
  for (const element of this.elements) {
12649
12372
  element?.deoptimizePath(EMPTY_PATH);
12650
12373
  }
12651
12374
  }
12652
- hasEffectsWhenDestructuring(context, destructuredInitPath, init) {
12653
- const includedPatternPath = getIncludedPatternPath(destructuredInitPath);
12654
- for (const element of this.elements) {
12655
- if (element?.hasEffectsWhenDestructuring(context, includedPatternPath, init)) {
12656
- return true;
12657
- }
12658
- }
12659
- return false;
12660
- }
12661
12375
  // Patterns are only checked at the empty path at the moment
12662
12376
  hasEffectsOnInteractionAtPath(_path, interaction, context) {
12663
12377
  for (const element of this.elements) {
@@ -12666,38 +12380,12 @@ class ArrayPattern extends NodeBase {
12666
12380
  }
12667
12381
  return false;
12668
12382
  }
12669
- includeDestructuredIfNecessary(context, destructuredInitPath, init) {
12670
- let included = false;
12671
- const includedPatternPath = getIncludedPatternPath(destructuredInitPath);
12672
- for (const element of this.elements) {
12673
- if (element) {
12674
- element.included ||= included;
12675
- included =
12676
- element.includeDestructuredIfNecessary(context, includedPatternPath, init) || included;
12677
- }
12678
- }
12679
- if (included) {
12680
- // This is necessary so that if any pattern element is included, all are
12681
- // included for proper deconflicting
12682
- for (const element of this.elements) {
12683
- if (element && !element.included) {
12684
- element.included = true;
12685
- element.includeDestructuredIfNecessary(context, includedPatternPath, init);
12686
- }
12687
- }
12688
- }
12689
- return (this.included ||= included);
12690
- }
12691
12383
  markDeclarationReached() {
12692
12384
  for (const element of this.elements) {
12693
12385
  element?.markDeclarationReached();
12694
12386
  }
12695
12387
  }
12696
12388
  }
12697
- ArrayPattern.prototype.includeNode = onlyIncludeSelf;
12698
- const getIncludedPatternPath = (destructuredInitPath) => destructuredInitPath.at(-1) === UnknownKey
12699
- ? destructuredInitPath
12700
- : [...destructuredInitPath, UnknownInteger];
12701
12389
 
12702
12390
  class ArrowFunctionExpression extends FunctionBase {
12703
12391
  constructor() {
@@ -12714,6 +12402,8 @@ class ArrowFunctionExpression extends FunctionBase {
12714
12402
  this.scope = new ReturnValueScope(parentScope, false);
12715
12403
  }
12716
12404
  hasEffects() {
12405
+ if (!this.deoptimized)
12406
+ this.applyDeoptimizations();
12717
12407
  return false;
12718
12408
  }
12719
12409
  hasEffectsOnInteractionAtPath(path, interaction, context) {
@@ -12752,15 +12442,6 @@ class ArrowFunctionExpression extends FunctionBase {
12752
12442
  }
12753
12443
  }
12754
12444
  }
12755
- includeNode(context) {
12756
- this.included = true;
12757
- this.body.includePath(UNKNOWN_PATH, context);
12758
- for (const parameter of this.params) {
12759
- if (!(parameter instanceof Identifier)) {
12760
- parameter.includePath(UNKNOWN_PATH, context);
12761
- }
12762
- }
12763
- }
12764
12445
  getObjectEntity() {
12765
12446
  if (this.objectEntity !== null) {
12766
12447
  return this.objectEntity;
@@ -12780,18 +12461,13 @@ class ObjectPattern extends NodeBase {
12780
12461
  }
12781
12462
  }
12782
12463
  }
12783
- declare(kind, destructuredInitPath, init) {
12464
+ declare(kind, init) {
12784
12465
  const variables = [];
12785
12466
  for (const property of this.properties) {
12786
- variables.push(...property.declare(kind, destructuredInitPath, init));
12467
+ variables.push(...property.declare(kind, init));
12787
12468
  }
12788
12469
  return variables;
12789
12470
  }
12790
- deoptimizeAssignment(destructuredInitPath, init) {
12791
- for (const property of this.properties) {
12792
- property.deoptimizeAssignment(destructuredInitPath, init);
12793
- }
12794
- }
12795
12471
  deoptimizePath(path) {
12796
12472
  if (path.length === 0) {
12797
12473
  for (const property of this.properties) {
@@ -12809,46 +12485,12 @@ class ObjectPattern extends NodeBase {
12809
12485
  }
12810
12486
  return false;
12811
12487
  }
12812
- hasEffectsWhenDestructuring(context, destructuredInitPath, init) {
12813
- for (const property of this.properties) {
12814
- if (property.hasEffectsWhenDestructuring(context, destructuredInitPath, init))
12815
- return true;
12816
- }
12817
- return false;
12818
- }
12819
- includeDestructuredIfNecessary(context, destructuredInitPath, init) {
12820
- let included = false;
12821
- for (const property of this.properties) {
12822
- included =
12823
- property.includeDestructuredIfNecessary(context, destructuredInitPath, init) || included;
12824
- }
12825
- return (this.included ||= included);
12826
- }
12827
12488
  markDeclarationReached() {
12828
12489
  for (const property of this.properties) {
12829
12490
  property.markDeclarationReached();
12830
12491
  }
12831
12492
  }
12832
- render(code, options) {
12833
- if (this.properties.length > 0) {
12834
- const separatedNodes = getCommaSeparatedNodesWithBoundaries(this.properties, code, this.start + 1, this.end - 1);
12835
- let lastSeparatorPos = null;
12836
- for (const { node, separator, start, end } of separatedNodes) {
12837
- if (!node.included) {
12838
- treeshakeNode(node, code, start, end);
12839
- continue;
12840
- }
12841
- lastSeparatorPos = separator;
12842
- node.render(code, options);
12843
- }
12844
- if (lastSeparatorPos) {
12845
- code.remove(lastSeparatorPos, this.end - 1);
12846
- }
12847
- }
12848
- }
12849
12493
  }
12850
- ObjectPattern.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
12851
- ObjectPattern.prototype.applyDeoptimizations = doNotDeoptimize;
12852
12494
 
12853
12495
  class AssignmentExpression extends NodeBase {
12854
12496
  hasEffects(context) {
@@ -12857,9 +12499,7 @@ class AssignmentExpression extends NodeBase {
12857
12499
  this.applyDeoptimizations();
12858
12500
  // MemberExpressions do not access the property before assignments if the
12859
12501
  // operator is '='.
12860
- return (right.hasEffects(context) ||
12861
- left.hasEffectsAsAssignmentTarget(context, operator !== '=') ||
12862
- this.left.hasEffectsWhenDestructuring?.(context, EMPTY_PATH, right));
12502
+ return (right.hasEffects(context) || left.hasEffectsAsAssignmentTarget(context, operator !== '='));
12863
12503
  }
12864
12504
  hasEffectsOnInteractionAtPath(path, interaction, context) {
12865
12505
  return this.right.hasEffectsOnInteractionAtPath(path, interaction, context);
@@ -12868,24 +12508,15 @@ class AssignmentExpression extends NodeBase {
12868
12508
  const { deoptimized, left, right, operator } = this;
12869
12509
  if (!deoptimized)
12870
12510
  this.applyDeoptimizations();
12871
- if (!this.included)
12872
- this.includeNode(context);
12873
- const hasEffectsContext = createHasEffectsContext();
12511
+ this.included = true;
12874
12512
  if (includeChildrenRecursively ||
12875
12513
  operator !== '=' ||
12876
12514
  left.included ||
12877
- left.hasEffectsAsAssignmentTarget(hasEffectsContext, false) ||
12878
- left.hasEffectsWhenDestructuring?.(hasEffectsContext, EMPTY_PATH, right)) {
12515
+ left.hasEffectsAsAssignmentTarget(createHasEffectsContext(), false)) {
12879
12516
  left.includeAsAssignmentTarget(context, includeChildrenRecursively, operator !== '=');
12880
12517
  }
12881
12518
  right.include(context, includeChildrenRecursively);
12882
12519
  }
12883
- includeNode(context) {
12884
- this.included = true;
12885
- if (!this.deoptimized)
12886
- this.applyDeoptimizations();
12887
- this.right.includePath(UNKNOWN_PATH, context);
12888
- }
12889
12520
  initialise() {
12890
12521
  super.initialise();
12891
12522
  if (this.left instanceof Identifier) {
@@ -12946,7 +12577,8 @@ class AssignmentExpression extends NodeBase {
12946
12577
  }
12947
12578
  applyDeoptimizations() {
12948
12579
  this.deoptimized = true;
12949
- this.left.deoptimizeAssignment(EMPTY_PATH, this.right);
12580
+ this.left.deoptimizePath(EMPTY_PATH);
12581
+ this.right.deoptimizePath(UNKNOWN_PATH);
12950
12582
  this.scope.context.requestTreeshakingPass();
12951
12583
  }
12952
12584
  }
@@ -12955,42 +12587,16 @@ class AssignmentPattern extends NodeBase {
12955
12587
  addExportedVariables(variables, exportNamesByVariable) {
12956
12588
  this.left.addExportedVariables(variables, exportNamesByVariable);
12957
12589
  }
12958
- declare(kind, destructuredInitPath, init) {
12959
- return this.left.declare(kind, destructuredInitPath, init);
12960
- }
12961
- deoptimizeAssignment(destructuredInitPath, init) {
12962
- this.left.deoptimizeAssignment(destructuredInitPath, init);
12590
+ declare(kind, init) {
12591
+ return this.left.declare(kind, init);
12963
12592
  }
12964
12593
  deoptimizePath(path) {
12965
12594
  if (path.length === 0) {
12966
12595
  this.left.deoptimizePath(path);
12967
- }
12968
- }
12969
- hasEffectsOnInteractionAtPath(path, interaction, context) {
12970
- return (path.length > 0 || this.left.hasEffectsOnInteractionAtPath(EMPTY_PATH, interaction, context));
12971
- }
12972
- hasEffectsWhenDestructuring(context, destructuredInitPath, init) {
12973
- return this.left.hasEffectsWhenDestructuring(context, destructuredInitPath, init);
12974
- }
12975
- includeDestructuredIfNecessary(context, destructuredInitPath, init) {
12976
- let included = this.left.includeDestructuredIfNecessary(context, destructuredInitPath, init) ||
12977
- this.included;
12978
- if ((included ||= this.right.shouldBeIncluded(context))) {
12979
- this.right.include(context, false);
12980
- if (!this.left.included) {
12981
- this.left.included = true;
12982
- // Unfortunately, we need to include the left side again now, so that
12983
- // any declared variables are properly included.
12984
- this.left.includeDestructuredIfNecessary(context, destructuredInitPath, init);
12985
- }
12986
- }
12987
- return (this.included = included);
12988
- }
12989
- includeNode(context) {
12990
- this.included = true;
12991
- if (!this.deoptimized)
12992
- this.applyDeoptimizations();
12993
- this.right.includePath(UNKNOWN_PATH, context);
12596
+ }
12597
+ }
12598
+ hasEffectsOnInteractionAtPath(path, interaction, context) {
12599
+ return (path.length > 0 || this.left.hasEffectsOnInteractionAtPath(EMPTY_PATH, interaction, context));
12994
12600
  }
12995
12601
  markDeclarationReached() {
12996
12602
  this.left.markDeclarationReached();
@@ -13014,34 +12620,22 @@ class AwaitExpression extends NodeBase {
13014
12620
  return true;
13015
12621
  }
13016
12622
  include(context, includeChildrenRecursively) {
13017
- if (!this.included)
13018
- this.includeNode(context);
13019
- this.argument.include(context, includeChildrenRecursively);
13020
- }
13021
- includeNode(context) {
13022
- this.included = true;
13023
12623
  if (!this.deoptimized)
13024
12624
  this.applyDeoptimizations();
13025
- checkTopLevelAwait: if (!this.scope.context.usesTopLevelAwait) {
13026
- let parent = this.parent;
13027
- do {
13028
- if (parent instanceof FunctionNode || parent instanceof ArrowFunctionExpression)
13029
- break checkTopLevelAwait;
13030
- } while ((parent = parent.parent));
13031
- this.scope.context.usesTopLevelAwait = true;
12625
+ if (!this.included) {
12626
+ this.included = true;
12627
+ checkTopLevelAwait: if (!this.scope.context.usesTopLevelAwait) {
12628
+ let parent = this.parent;
12629
+ do {
12630
+ if (parent instanceof FunctionNode || parent instanceof ArrowFunctionExpression)
12631
+ break checkTopLevelAwait;
12632
+ } while ((parent = parent.parent));
12633
+ this.scope.context.usesTopLevelAwait = true;
12634
+ }
13032
12635
  }
13033
- // Thenables need to be included
13034
- this.argument.includePath(THEN_PATH, context);
13035
- }
13036
- includePath(path, context) {
13037
- if (!this.deoptimized)
13038
- this.applyDeoptimizations();
13039
- if (!this.included)
13040
- this.includeNode(context);
13041
- this.argument.includePath(path, context);
12636
+ this.argument.include(context, includeChildrenRecursively);
13042
12637
  }
13043
12638
  }
13044
- const THEN_PATH = ['then'];
13045
12639
 
13046
12640
  const binaryOperators = {
13047
12641
  '!=': (left, right) => left != right,
@@ -13105,8 +12699,6 @@ class BinaryExpression extends NodeBase {
13105
12699
  this.right.render(code, options);
13106
12700
  }
13107
12701
  }
13108
- BinaryExpression.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
13109
- BinaryExpression.prototype.applyDeoptimizations = doNotDeoptimize;
13110
12702
 
13111
12703
  class BreakStatement extends NodeBase {
13112
12704
  hasEffects(context) {
@@ -13126,7 +12718,7 @@ class BreakStatement extends NodeBase {
13126
12718
  include(context) {
13127
12719
  this.included = true;
13128
12720
  if (this.label) {
13129
- this.label.include(context);
12721
+ this.label.include();
13130
12722
  context.includedLabels.add(this.label.name);
13131
12723
  }
13132
12724
  else {
@@ -13135,8 +12727,6 @@ class BreakStatement extends NodeBase {
13135
12727
  context.brokenFlow = true;
13136
12728
  }
13137
12729
  }
13138
- BreakStatement.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
13139
- BreakStatement.prototype.applyDeoptimizations = doNotDeoptimize;
13140
12730
 
13141
12731
  function renderCallArguments(code, options, node) {
13142
12732
  if (node.arguments.length > 0) {
@@ -13323,6 +12913,8 @@ class CallExpression extends CallExpressionBase {
13323
12913
  this.callee.hasEffectsOnInteractionAtPath(EMPTY_PATH, this.interaction, context)));
13324
12914
  }
13325
12915
  include(context, includeChildrenRecursively) {
12916
+ if (!this.deoptimized)
12917
+ this.applyDeoptimizations();
13326
12918
  if (includeChildrenRecursively) {
13327
12919
  super.include(context, includeChildrenRecursively);
13328
12920
  if (includeChildrenRecursively === INCLUDE_PARAMETERS &&
@@ -13332,26 +12924,10 @@ class CallExpression extends CallExpressionBase {
13332
12924
  }
13333
12925
  }
13334
12926
  else {
13335
- if (!this.included)
13336
- this.includeNode(context);
13337
- // If the callee is a member expression and does not have a variable, its
13338
- // object will already be included via the first argument of the
13339
- // interaction in includeCallArguments. Including it again can lead to
13340
- // severe performance problems.
13341
- if (this.callee instanceof MemberExpression && !this.callee.variable) {
13342
- this.callee.property.include(context, false);
13343
- }
13344
- else {
13345
- this.callee.include(context, false);
13346
- }
13347
- this.callee.includeCallArguments(context, this.interaction);
12927
+ this.included = true;
12928
+ this.callee.include(context, false);
13348
12929
  }
13349
- }
13350
- includeNode(context) {
13351
- this.included = true;
13352
- if (!this.deoptimized)
13353
- this.applyDeoptimizations();
13354
- this.callee.includePath(UNKNOWN_PATH, context);
12930
+ this.callee.includeCallArguments(context, this.arguments);
13355
12931
  }
13356
12932
  initialise() {
13357
12933
  super.initialise();
@@ -13390,14 +12966,13 @@ class CatchClause extends NodeBase {
13390
12966
  this.type = type;
13391
12967
  if (param) {
13392
12968
  this.param = new (this.scope.context.getNodeConstructor(param.type))(this, this.scope).parseNode(param);
13393
- this.param.declare('parameter', EMPTY_PATH, UNKNOWN_EXPRESSION);
12969
+ this.param.declare('parameter', UNKNOWN_EXPRESSION);
13394
12970
  }
13395
12971
  this.body = new BlockStatement(this, this.scope.bodyScope).parseNode(body);
13396
12972
  return super.parseNode(esTreeNode);
13397
12973
  }
13398
12974
  }
13399
12975
  CatchClause.prototype.preventChildBlockScope = true;
13400
- CatchClause.prototype.includeNode = onlyIncludeSelf;
13401
12976
 
13402
12977
  class ChainExpression extends NodeBase {
13403
12978
  // deoptimizations are not relevant as we are not caching values
@@ -13409,22 +12984,17 @@ class ChainExpression extends NodeBase {
13409
12984
  hasEffects(context) {
13410
12985
  return this.expression.hasEffectsAsChainElement(context) === true;
13411
12986
  }
13412
- includePath(path, context) {
13413
- this.included = true;
13414
- this.expression.includePath(path, context);
13415
- }
13416
12987
  removeAnnotations(code) {
13417
12988
  this.expression.removeAnnotations(code);
13418
12989
  }
12990
+ applyDeoptimizations() { }
13419
12991
  }
13420
- ChainExpression.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
13421
- ChainExpression.prototype.applyDeoptimizations = doNotDeoptimize;
13422
12992
 
13423
12993
  class ClassBodyScope extends ChildScope {
13424
12994
  constructor(parent, classNode) {
13425
12995
  const { context } = parent;
13426
12996
  super(parent, context);
13427
- this.variables.set('this', (this.thisVariable = new LocalVariable('this', null, classNode, EMPTY_PATH, context, 'other')));
12997
+ this.variables.set('this', (this.thisVariable = new LocalVariable('this', null, classNode, context, 'other')));
13428
12998
  this.instanceScope = new ChildScope(this, context);
13429
12999
  this.instanceScope.variables.set('this', new ThisVariable(context));
13430
13000
  }
@@ -13439,7 +13009,7 @@ class ClassBody extends NodeBase {
13439
13009
  }
13440
13010
  include(context, includeChildrenRecursively) {
13441
13011
  this.included = true;
13442
- this.scope.context.includeVariableInModule(this.scope.thisVariable, UNKNOWN_PATH, context);
13012
+ this.scope.context.includeVariableInModule(this.scope.thisVariable);
13443
13013
  for (const definition of this.body) {
13444
13014
  definition.include(context, includeChildrenRecursively);
13445
13015
  }
@@ -13452,9 +13022,8 @@ class ClassBody extends NodeBase {
13452
13022
  }
13453
13023
  return super.parseNode(esTreeNode);
13454
13024
  }
13025
+ applyDeoptimizations() { }
13455
13026
  }
13456
- ClassBody.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
13457
- ClassBody.prototype.applyDeoptimizations = doNotDeoptimize;
13458
13027
 
13459
13028
  class ClassExpression extends ClassNode {
13460
13029
  render(code, options, { renderedSurroundingElement } = parseAst_js.BLANK) {
@@ -13466,6 +13035,19 @@ class ClassExpression extends ClassNode {
13466
13035
  }
13467
13036
  }
13468
13037
 
13038
+ function tryCastLiteralValueToBoolean(literalValue) {
13039
+ if (typeof literalValue === 'symbol') {
13040
+ if (literalValue === UnknownFalsyValue) {
13041
+ return false;
13042
+ }
13043
+ if (literalValue === UnknownTruthyValue) {
13044
+ return true;
13045
+ }
13046
+ return UnknownValue;
13047
+ }
13048
+ return !!literalValue;
13049
+ }
13050
+
13469
13051
  class MultiExpression extends ExpressionEntity {
13470
13052
  constructor(expressions) {
13471
13053
  super();
@@ -13512,9 +13094,6 @@ class ConditionalExpression extends NodeBase {
13512
13094
  const unusedBranch = this.usedBranch === this.consequent ? this.alternate : this.consequent;
13513
13095
  this.usedBranch = null;
13514
13096
  unusedBranch.deoptimizePath(UNKNOWN_PATH);
13515
- if (this.included) {
13516
- unusedBranch.includePath(UNKNOWN_PATH, createInclusionContext());
13517
- }
13518
13097
  const { expressionsToBeDeoptimized } = this;
13519
13098
  this.expressionsToBeDeoptimized = parseAst_js.EMPTY_ARRAY;
13520
13099
  for (const expression of expressionsToBeDeoptimized) {
@@ -13572,7 +13151,7 @@ class ConditionalExpression extends NodeBase {
13572
13151
  include(context, includeChildrenRecursively) {
13573
13152
  this.included = true;
13574
13153
  const usedBranch = this.getUsedBranch();
13575
- if (usedBranch === null || includeChildrenRecursively || this.test.shouldBeIncluded(context)) {
13154
+ if (includeChildrenRecursively || this.test.shouldBeIncluded(context) || usedBranch === null) {
13576
13155
  this.test.include(context, includeChildrenRecursively);
13577
13156
  this.consequent.include(context, includeChildrenRecursively);
13578
13157
  this.alternate.include(context, includeChildrenRecursively);
@@ -13581,38 +13160,27 @@ class ConditionalExpression extends NodeBase {
13581
13160
  usedBranch.include(context, includeChildrenRecursively);
13582
13161
  }
13583
13162
  }
13584
- includePath(path, context) {
13585
- this.included = true;
13586
- const usedBranch = this.getUsedBranch();
13587
- if (usedBranch === null || this.test.shouldBeIncluded(context)) {
13588
- this.consequent.includePath(path, context);
13589
- this.alternate.includePath(path, context);
13590
- }
13591
- else {
13592
- usedBranch.includePath(path, context);
13593
- }
13594
- }
13595
- includeCallArguments(context, interaction) {
13163
+ includeCallArguments(context, parameters) {
13596
13164
  const usedBranch = this.getUsedBranch();
13597
13165
  if (usedBranch) {
13598
- usedBranch.includeCallArguments(context, interaction);
13166
+ usedBranch.includeCallArguments(context, parameters);
13599
13167
  }
13600
13168
  else {
13601
- this.consequent.includeCallArguments(context, interaction);
13602
- this.alternate.includeCallArguments(context, interaction);
13169
+ this.consequent.includeCallArguments(context, parameters);
13170
+ this.alternate.includeCallArguments(context, parameters);
13603
13171
  }
13604
13172
  }
13605
13173
  removeAnnotations(code) {
13606
13174
  this.test.removeAnnotations(code);
13607
13175
  }
13608
13176
  render(code, options, { isCalleeOfRenderedParent, preventASI, renderedParentType, renderedSurroundingElement } = parseAst_js.BLANK) {
13177
+ const usedBranch = this.getUsedBranch();
13609
13178
  if (this.test.included) {
13610
13179
  this.test.render(code, options, { renderedSurroundingElement });
13611
13180
  this.consequent.render(code, options);
13612
13181
  this.alternate.render(code, options);
13613
13182
  }
13614
13183
  else {
13615
- const usedBranch = this.getUsedBranch();
13616
13184
  const colonPos = findFirstOccurrenceOutsideComment(code.original, ':', this.consequent.end);
13617
13185
  const inclusionStart = findNonWhiteSpace(code.original, (this.consequent.included
13618
13186
  ? findFirstOccurrenceOutsideComment(code.original, '?', this.test.end)
@@ -13638,14 +13206,12 @@ class ConditionalExpression extends NodeBase {
13638
13206
  return this.usedBranch;
13639
13207
  }
13640
13208
  this.isBranchResolutionAnalysed = true;
13641
- const testValue = this.test.getLiteralValueAtPath(EMPTY_PATH, SHARED_RECURSION_TRACKER, this);
13209
+ const testValue = tryCastLiteralValueToBoolean(this.test.getLiteralValueAtPath(EMPTY_PATH, SHARED_RECURSION_TRACKER, this));
13642
13210
  return typeof testValue === 'symbol'
13643
13211
  ? null
13644
13212
  : (this.usedBranch = testValue ? this.consequent : this.alternate);
13645
13213
  }
13646
13214
  }
13647
- ConditionalExpression.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
13648
- ConditionalExpression.prototype.applyDeoptimizations = doNotDeoptimize;
13649
13215
 
13650
13216
  class ContinueStatement extends NodeBase {
13651
13217
  hasEffects(context) {
@@ -13665,7 +13231,7 @@ class ContinueStatement extends NodeBase {
13665
13231
  include(context) {
13666
13232
  this.included = true;
13667
13233
  if (this.label) {
13668
- this.label.include(context);
13234
+ this.label.include();
13669
13235
  context.includedLabels.add(this.label.name);
13670
13236
  }
13671
13237
  else {
@@ -13674,15 +13240,12 @@ class ContinueStatement extends NodeBase {
13674
13240
  context.brokenFlow = true;
13675
13241
  }
13676
13242
  }
13677
- ContinueStatement.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
13678
- ContinueStatement.prototype.applyDeoptimizations = doNotDeoptimize;
13679
13243
 
13680
13244
  class DebuggerStatement extends NodeBase {
13681
13245
  hasEffects() {
13682
13246
  return true;
13683
13247
  }
13684
13248
  }
13685
- DebuggerStatement.prototype.includeNode = onlyIncludeSelf;
13686
13249
 
13687
13250
  class Decorator extends NodeBase {
13688
13251
  hasEffects(context) {
@@ -13690,7 +13253,6 @@ class Decorator extends NodeBase {
13690
13253
  this.expression.hasEffectsOnInteractionAtPath(EMPTY_PATH, NODE_INTERACTION_UNKNOWN_CALL, context));
13691
13254
  }
13692
13255
  }
13693
- Decorator.prototype.includeNode = onlyIncludeSelf;
13694
13256
 
13695
13257
  function hasLoopBodyEffects(context, body) {
13696
13258
  const { brokenFlow, hasBreak, hasContinue, ignore } = context;
@@ -13730,15 +13292,12 @@ class DoWhileStatement extends NodeBase {
13730
13292
  includeLoopBody(context, this.body, includeChildrenRecursively);
13731
13293
  }
13732
13294
  }
13733
- DoWhileStatement.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
13734
- DoWhileStatement.prototype.applyDeoptimizations = doNotDeoptimize;
13735
13295
 
13736
13296
  class EmptyStatement extends NodeBase {
13737
13297
  hasEffects() {
13738
13298
  return false;
13739
13299
  }
13740
13300
  }
13741
- EmptyStatement.prototype.includeNode = onlyIncludeSelf;
13742
13301
 
13743
13302
  class ExportAllDeclaration extends NodeBase {
13744
13303
  hasEffects() {
@@ -13751,10 +13310,9 @@ class ExportAllDeclaration extends NodeBase {
13751
13310
  render(code, _options, nodeRenderOptions) {
13752
13311
  code.remove(nodeRenderOptions.start, nodeRenderOptions.end);
13753
13312
  }
13313
+ applyDeoptimizations() { }
13754
13314
  }
13755
13315
  ExportAllDeclaration.prototype.needsBoundaries = true;
13756
- ExportAllDeclaration.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
13757
- ExportAllDeclaration.prototype.applyDeoptimizations = doNotDeoptimize;
13758
13316
 
13759
13317
  class ExportNamedDeclaration extends NodeBase {
13760
13318
  bind() {
@@ -13781,15 +13339,13 @@ class ExportNamedDeclaration extends NodeBase {
13781
13339
  this.declaration.render(code, options, { end, start });
13782
13340
  }
13783
13341
  }
13342
+ applyDeoptimizations() { }
13784
13343
  }
13785
13344
  ExportNamedDeclaration.prototype.needsBoundaries = true;
13786
- ExportNamedDeclaration.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
13787
- ExportNamedDeclaration.prototype.applyDeoptimizations = doNotDeoptimize;
13788
13345
 
13789
13346
  class ExportSpecifier extends NodeBase {
13347
+ applyDeoptimizations() { }
13790
13348
  }
13791
- ExportSpecifier.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
13792
- ExportSpecifier.prototype.applyDeoptimizations = doNotDeoptimize;
13793
13349
 
13794
13350
  class ForInStatement extends NodeBase {
13795
13351
  createScope(parentScope) {
@@ -13807,18 +13363,11 @@ class ForInStatement extends NodeBase {
13807
13363
  const { body, deoptimized, left, right } = this;
13808
13364
  if (!deoptimized)
13809
13365
  this.applyDeoptimizations();
13810
- if (!this.included)
13811
- this.includeNode(context);
13366
+ this.included = true;
13812
13367
  left.includeAsAssignmentTarget(context, includeChildrenRecursively || true, false);
13813
13368
  right.include(context, includeChildrenRecursively);
13814
13369
  includeLoopBody(context, body, includeChildrenRecursively);
13815
13370
  }
13816
- includeNode(context) {
13817
- this.included = true;
13818
- if (!this.deoptimized)
13819
- this.applyDeoptimizations();
13820
- this.right.includePath(UNKNOWN_PATH, context);
13821
- }
13822
13371
  initialise() {
13823
13372
  super.initialise();
13824
13373
  this.left.setAssignedValue(UNKNOWN_EXPRESSION);
@@ -13859,18 +13408,11 @@ class ForOfStatement extends NodeBase {
13859
13408
  const { body, deoptimized, left, right } = this;
13860
13409
  if (!deoptimized)
13861
13410
  this.applyDeoptimizations();
13862
- if (!this.included)
13863
- this.includeNode(context);
13411
+ this.included = true;
13864
13412
  left.includeAsAssignmentTarget(context, includeChildrenRecursively || true, false);
13865
13413
  right.include(context, includeChildrenRecursively);
13866
13414
  includeLoopBody(context, body, includeChildrenRecursively);
13867
13415
  }
13868
- includeNode(context) {
13869
- this.included = true;
13870
- if (!this.deoptimized)
13871
- this.applyDeoptimizations();
13872
- this.right.includePath(UNKNOWN_PATH, context);
13873
- }
13874
13416
  initialise() {
13875
13417
  super.initialise();
13876
13418
  this.left.setAssignedValue(UNKNOWN_EXPRESSION);
@@ -13906,9 +13448,7 @@ class ForStatement extends NodeBase {
13906
13448
  }
13907
13449
  include(context, includeChildrenRecursively) {
13908
13450
  this.included = true;
13909
- this.init?.include(context, includeChildrenRecursively, {
13910
- asSingleStatement: true
13911
- });
13451
+ this.init?.include(context, includeChildrenRecursively, { asSingleStatement: true });
13912
13452
  this.test?.include(context, includeChildrenRecursively);
13913
13453
  this.update?.include(context, includeChildrenRecursively);
13914
13454
  includeLoopBody(context, this.body, includeChildrenRecursively);
@@ -13920,8 +13460,6 @@ class ForStatement extends NodeBase {
13920
13460
  this.body.render(code, options);
13921
13461
  }
13922
13462
  }
13923
- ForStatement.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
13924
- ForStatement.prototype.applyDeoptimizations = doNotDeoptimize;
13925
13463
 
13926
13464
  class FunctionExpression extends FunctionNode {
13927
13465
  createScope(parentScope) {
@@ -13953,9 +13491,9 @@ class TrackingScope extends BlockScope {
13953
13491
  super(...arguments);
13954
13492
  this.hoistedDeclarations = [];
13955
13493
  }
13956
- addDeclaration(identifier, context, init, destructuredInitPath, kind) {
13494
+ addDeclaration(identifier, context, init, kind) {
13957
13495
  this.hoistedDeclarations.push(identifier);
13958
- return super.addDeclaration(identifier, context, init, destructuredInitPath, kind);
13496
+ return super.addDeclaration(identifier, context, init, kind);
13959
13497
  }
13960
13498
  }
13961
13499
 
@@ -14054,9 +13592,10 @@ class IfStatement extends NodeBase {
14054
13592
  }
14055
13593
  this.renderHoistedDeclarations(hoistedDeclarations, code, getPropertyAccess);
14056
13594
  }
13595
+ applyDeoptimizations() { }
14057
13596
  getTestValue() {
14058
13597
  if (this.testValue === unset) {
14059
- return (this.testValue = this.test.getLiteralValueAtPath(EMPTY_PATH, SHARED_RECURSION_TRACKER, this));
13598
+ return (this.testValue = tryCastLiteralValueToBoolean(this.test.getLiteralValueAtPath(EMPTY_PATH, SHARED_RECURSION_TRACKER, this)));
14060
13599
  }
14061
13600
  return this.testValue;
14062
13601
  }
@@ -14122,8 +13661,6 @@ class IfStatement extends NodeBase {
14122
13661
  return false;
14123
13662
  }
14124
13663
  }
14125
- IfStatement.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
14126
- IfStatement.prototype.applyDeoptimizations = doNotDeoptimize;
14127
13664
 
14128
13665
  class ImportAttribute extends NodeBase {
14129
13666
  }
@@ -14141,15 +13678,13 @@ class ImportDeclaration extends NodeBase {
14141
13678
  render(code, _options, nodeRenderOptions) {
14142
13679
  code.remove(nodeRenderOptions.start, nodeRenderOptions.end);
14143
13680
  }
13681
+ applyDeoptimizations() { }
14144
13682
  }
14145
13683
  ImportDeclaration.prototype.needsBoundaries = true;
14146
- ImportDeclaration.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
14147
- ImportDeclaration.prototype.applyDeoptimizations = doNotDeoptimize;
14148
13684
 
14149
13685
  class ImportDefaultSpecifier extends NodeBase {
13686
+ applyDeoptimizations() { }
14150
13687
  }
14151
- ImportDefaultSpecifier.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
14152
- ImportDefaultSpecifier.prototype.applyDeoptimizations = doNotDeoptimize;
14153
13688
 
14154
13689
  function isReassignedExportsMember(variable, exportNamesByVariable) {
14155
13690
  return (variable.renderBaseName !== null && exportNamesByVariable.has(variable) && variable.isReassigned);
@@ -14158,33 +13693,28 @@ function isReassignedExportsMember(variable, exportNamesByVariable) {
14158
13693
  class VariableDeclarator extends NodeBase {
14159
13694
  declareDeclarator(kind, isUsingDeclaration) {
14160
13695
  this.isUsingDeclaration = isUsingDeclaration;
14161
- this.id.declare(kind, EMPTY_PATH, this.init || UNDEFINED_EXPRESSION);
13696
+ this.id.declare(kind, this.init || UNDEFINED_EXPRESSION);
14162
13697
  }
14163
13698
  deoptimizePath(path) {
14164
13699
  this.id.deoptimizePath(path);
14165
13700
  }
14166
13701
  hasEffects(context) {
13702
+ if (!this.deoptimized)
13703
+ this.applyDeoptimizations();
14167
13704
  const initEffect = this.init?.hasEffects(context);
14168
13705
  this.id.markDeclarationReached();
14169
- return (initEffect ||
14170
- this.isUsingDeclaration ||
14171
- this.id.hasEffects(context) ||
14172
- (this.scope.context.options.treeshake
14173
- .propertyReadSideEffects &&
14174
- this.id.hasEffectsWhenDestructuring(context, EMPTY_PATH, this.init || UNDEFINED_EXPRESSION)));
13706
+ return initEffect || this.id.hasEffects(context) || this.isUsingDeclaration;
14175
13707
  }
14176
13708
  include(context, includeChildrenRecursively) {
14177
- const { id, init } = this;
14178
- if (!this.included)
14179
- this.includeNode();
13709
+ const { deoptimized, id, init } = this;
13710
+ if (!deoptimized)
13711
+ this.applyDeoptimizations();
13712
+ this.included = true;
14180
13713
  init?.include(context, includeChildrenRecursively);
14181
13714
  id.markDeclarationReached();
14182
- if (includeChildrenRecursively) {
13715
+ if (includeChildrenRecursively || id.shouldBeIncluded(context)) {
14183
13716
  id.include(context, includeChildrenRecursively);
14184
13717
  }
14185
- else {
14186
- id.includeDestructuredIfNecessary(context, EMPTY_PATH, init || UNDEFINED_EXPRESSION);
14187
- }
14188
13718
  }
14189
13719
  removeAnnotations(code) {
14190
13720
  this.init?.removeAnnotations(code);
@@ -14214,8 +13744,8 @@ class VariableDeclarator extends NodeBase {
14214
13744
  code.appendLeft(end, `${_}=${_}void 0`);
14215
13745
  }
14216
13746
  }
14217
- includeNode() {
14218
- this.included = true;
13747
+ applyDeoptimizations() {
13748
+ this.deoptimized = true;
14219
13749
  const { id, init } = this;
14220
13750
  if (init && id instanceof Identifier && init instanceof ClassExpression && !init.id) {
14221
13751
  const { name, variable } = id;
@@ -14227,14 +13757,11 @@ class VariableDeclarator extends NodeBase {
14227
13757
  }
14228
13758
  }
14229
13759
  }
14230
- VariableDeclarator.prototype.applyDeoptimizations = doNotDeoptimize;
14231
13760
 
14232
13761
  class ImportExpression extends NodeBase {
14233
13762
  constructor() {
14234
13763
  super(...arguments);
14235
13764
  this.inlineNamespace = null;
14236
- this.hasUnknownAccessedKey = false;
14237
- this.accessedPropKey = new Set();
14238
13765
  this.attributes = null;
14239
13766
  this.mechanism = null;
14240
13767
  this.namespaceExportName = undefined;
@@ -14267,15 +13794,12 @@ class ImportExpression extends NodeBase {
14267
13794
  if (parent2 instanceof ExpressionStatement) {
14268
13795
  return parseAst_js.EMPTY_ARRAY;
14269
13796
  }
14270
- // Case 1: const { foo } / module = await import('bar')
13797
+ // Case 1: const { foo } = await import('bar')
14271
13798
  if (parent2 instanceof VariableDeclarator) {
14272
13799
  const declaration = parent2.id;
14273
- if (declaration instanceof Identifier) {
14274
- return this.hasUnknownAccessedKey ? undefined : [...this.accessedPropKey];
14275
- }
14276
- if (declaration instanceof ObjectPattern) {
14277
- return getDeterministicObjectDestructure(declaration);
14278
- }
13800
+ return declaration instanceof ObjectPattern
13801
+ ? getDeterministicObjectDestructure(declaration)
13802
+ : undefined;
14279
13803
  }
14280
13804
  // Case 2: (await import('bar')).foo
14281
13805
  if (parent2 instanceof MemberExpression) {
@@ -14325,29 +13849,12 @@ class ImportExpression extends NodeBase {
14325
13849
  return true;
14326
13850
  }
14327
13851
  include(context, includeChildrenRecursively) {
14328
- if (!this.included)
14329
- this.includeNode();
14330
- this.source.include(context, includeChildrenRecursively);
14331
- }
14332
- includeNode() {
14333
- this.included = true;
14334
- this.scope.context.includeDynamicImport(this);
14335
- this.scope.addAccessedDynamicImport(this);
14336
- }
14337
- includePath(path) {
14338
- if (!this.included)
14339
- this.includeNode();
14340
- // Technically, this is not correct as dynamic imports return a Promise.
14341
- if (this.hasUnknownAccessedKey)
14342
- return;
14343
- if (path[0] === UnknownKey) {
14344
- this.hasUnknownAccessedKey = true;
14345
- }
14346
- else if (typeof path[0] === 'string') {
14347
- this.accessedPropKey.add(path[0]);
13852
+ if (!this.included) {
13853
+ this.included = true;
13854
+ this.scope.context.includeDynamicImport(this);
13855
+ this.scope.addAccessedDynamicImport(this);
14348
13856
  }
14349
- // Update included paths
14350
- this.scope.context.includeDynamicImport(this);
13857
+ this.source.include(context, includeChildrenRecursively);
14351
13858
  }
14352
13859
  initialise() {
14353
13860
  super.initialise();
@@ -14417,6 +13924,7 @@ class ImportExpression extends NodeBase {
14417
13924
  setInternalResolution(inlineNamespace) {
14418
13925
  this.inlineNamespace = inlineNamespace;
14419
13926
  }
13927
+ applyDeoptimizations() { }
14420
13928
  getDynamicImportMechanismAndHelper(resolution, exportMode, { compact, dynamicImportInCjs, format, generatedCode: { arrowFunctions }, interop }, { _, getDirectReturnFunction, getDirectReturnIifeLeft }, pluginDriver) {
14421
13929
  const mechanism = pluginDriver.hookFirstSync('renderDynamicImport', [
14422
13930
  {
@@ -14506,7 +14014,6 @@ class ImportExpression extends NodeBase {
14506
14014
  return { helper: null, mechanism: null };
14507
14015
  }
14508
14016
  }
14509
- ImportExpression.prototype.applyDeoptimizations = doNotDeoptimize;
14510
14017
  function getInteropHelper(resolution, exportMode, interop) {
14511
14018
  return exportMode === 'external'
14512
14019
  ? namespaceInteropHelpersByInteropType[interop(resolution instanceof ExternalModule ? resolution.id : null)]
@@ -14530,14 +14037,12 @@ function getDeterministicObjectDestructure(objectPattern) {
14530
14037
  }
14531
14038
 
14532
14039
  class ImportNamespaceSpecifier extends NodeBase {
14040
+ applyDeoptimizations() { }
14533
14041
  }
14534
- ImportNamespaceSpecifier.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
14535
- ImportNamespaceSpecifier.prototype.applyDeoptimizations = doNotDeoptimize;
14536
14042
 
14537
14043
  class ImportSpecifier extends NodeBase {
14044
+ applyDeoptimizations() { }
14538
14045
  }
14539
- ImportSpecifier.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
14540
- ImportSpecifier.prototype.applyDeoptimizations = doNotDeoptimize;
14541
14046
 
14542
14047
  class JSXIdentifier extends IdentifierBase {
14543
14048
  constructor() {
@@ -14554,29 +14059,6 @@ class JSXIdentifier extends IdentifierBase {
14554
14059
  this.isNativeElement = true;
14555
14060
  }
14556
14061
  }
14557
- include(context) {
14558
- if (!this.included)
14559
- this.includeNode(context);
14560
- }
14561
- includeNode(context) {
14562
- this.included = true;
14563
- if (!this.deoptimized)
14564
- this.applyDeoptimizations();
14565
- if (this.variable !== null) {
14566
- this.scope.context.includeVariableInModule(this.variable, EMPTY_PATH, context);
14567
- }
14568
- }
14569
- includePath(path, context) {
14570
- if (!this.included) {
14571
- this.included = true;
14572
- if (this.variable !== null) {
14573
- this.scope.context.includeVariableInModule(this.variable, path, context);
14574
- }
14575
- }
14576
- else if (path.length > 0) {
14577
- this.variable?.includePath(path, context);
14578
- }
14579
- }
14580
14062
  render(code, { snippets: { getPropertyAccess }, useOriginalName }) {
14581
14063
  if (this.variable) {
14582
14064
  const name = this.variable.getName(getPropertyAccess, useOriginalName);
@@ -14638,7 +14120,6 @@ class JSXAttribute extends NodeBase {
14638
14120
  }
14639
14121
  }
14640
14122
  }
14641
- JSXAttribute.prototype.includeNode = onlyIncludeSelf;
14642
14123
 
14643
14124
  class JSXClosingBase extends NodeBase {
14644
14125
  render(code, options) {
@@ -14651,7 +14132,6 @@ class JSXClosingBase extends NodeBase {
14651
14132
  }
14652
14133
  }
14653
14134
  }
14654
- JSXClosingBase.prototype.includeNode = onlyIncludeSelf;
14655
14135
 
14656
14136
  class JSXClosingElement extends JSXClosingBase {
14657
14137
  }
@@ -14672,15 +14152,8 @@ class JSXSpreadAttribute extends NodeBase {
14672
14152
 
14673
14153
  class JSXEmptyExpression extends NodeBase {
14674
14154
  }
14675
- JSXEmptyExpression.prototype.includeNode = onlyIncludeSelf;
14676
14155
 
14677
14156
  class JSXExpressionContainer extends NodeBase {
14678
- includeNode(context) {
14679
- this.included = true;
14680
- if (!this.deoptimized)
14681
- this.applyDeoptimizations();
14682
- this.expression.includePath(UNKNOWN_PATH, context);
14683
- }
14684
14157
  render(code, options) {
14685
14158
  const { mode } = this.scope.context.options.jsx;
14686
14159
  if (mode !== 'preserve') {
@@ -14701,7 +14174,7 @@ function getRenderedJsxChildren(children) {
14701
14174
  return renderedChildren;
14702
14175
  }
14703
14176
 
14704
- function getAndIncludeFactoryVariable(factory, preserve, importSource, node, context) {
14177
+ function getAndIncludeFactoryVariable(factory, preserve, importSource, node) {
14705
14178
  const [baseName, nestedName] = factory.split('.');
14706
14179
  let factoryVariable;
14707
14180
  if (importSource) {
@@ -14709,7 +14182,7 @@ function getAndIncludeFactoryVariable(factory, preserve, importSource, node, con
14709
14182
  if (preserve) {
14710
14183
  // This pretends we are accessing an included global variable of the same name
14711
14184
  const globalVariable = node.scope.findGlobal(baseName);
14712
- globalVariable.includePath(UNKNOWN_PATH, context);
14185
+ globalVariable.include();
14713
14186
  // This excludes this variable from renaming
14714
14187
  factoryVariable.globalName = baseName;
14715
14188
  }
@@ -14717,7 +14190,7 @@ function getAndIncludeFactoryVariable(factory, preserve, importSource, node, con
14717
14190
  else {
14718
14191
  factoryVariable = node.scope.findGlobal(baseName);
14719
14192
  }
14720
- node.scope.context.includeVariableInModule(factoryVariable, UNKNOWN_PATH, context);
14193
+ node.scope.context.includeVariableInModule(factoryVariable);
14721
14194
  if (factoryVariable instanceof LocalVariable) {
14722
14195
  factoryVariable.consolidateInitializers();
14723
14196
  factoryVariable.addUsedPlace(node);
@@ -14740,20 +14213,16 @@ class JSXElementBase extends NodeBase {
14740
14213
  }
14741
14214
  }
14742
14215
  include(context, includeChildrenRecursively) {
14743
- if (!this.included)
14744
- this.includeNode(context);
14745
- for (const child of this.children) {
14746
- child.include(context, includeChildrenRecursively);
14747
- }
14748
- }
14749
- includeNode(context) {
14750
- this.included = true;
14751
- const { factory, importSource, mode } = this.jsxMode;
14752
- if (factory) {
14753
- this.factory = factory;
14754
- this.factoryVariable = getAndIncludeFactoryVariable(factory, mode === 'preserve', importSource, this, context);
14216
+ if (!this.included) {
14217
+ const { factory, importSource, mode } = this.jsxMode;
14218
+ if (factory) {
14219
+ this.factory = factory;
14220
+ this.factoryVariable = getAndIncludeFactoryVariable(factory, mode === 'preserve', importSource, this);
14221
+ }
14755
14222
  }
14223
+ super.include(context, includeChildrenRecursively);
14756
14224
  }
14225
+ applyDeoptimizations() { }
14757
14226
  getRenderingMode() {
14758
14227
  const jsx = this.scope.context.options.jsx;
14759
14228
  const { mode, factory, importSource } = jsx;
@@ -14791,14 +14260,8 @@ class JSXElementBase extends NodeBase {
14791
14260
  return { childrenEnd, firstChild, hasMultipleChildren };
14792
14261
  }
14793
14262
  }
14794
- JSXElementBase.prototype.applyDeoptimizations = doNotDeoptimize;
14795
14263
 
14796
14264
  class JSXElement extends JSXElementBase {
14797
- include(context, includeChildrenRecursively) {
14798
- super.include(context, includeChildrenRecursively);
14799
- this.openingElement.include(context, includeChildrenRecursively);
14800
- this.closingElement?.include(context, includeChildrenRecursively);
14801
- }
14802
14265
  render(code, options) {
14803
14266
  switch (this.jsxMode.mode) {
14804
14267
  case 'classic': {
@@ -14950,11 +14413,6 @@ class JSXElement extends JSXElementBase {
14950
14413
  }
14951
14414
 
14952
14415
  class JSXFragment extends JSXElementBase {
14953
- include(context, includeChildrenRecursively) {
14954
- super.include(context, includeChildrenRecursively);
14955
- this.openingFragment.include(context, includeChildrenRecursively);
14956
- this.closingFragment.include(context, includeChildrenRecursively);
14957
- }
14958
14416
  render(code, options) {
14959
14417
  switch (this.jsxMode.mode) {
14960
14418
  case 'classic': {
@@ -15004,22 +14462,10 @@ class JSXFragment extends JSXElementBase {
15004
14462
  }
15005
14463
 
15006
14464
  class JSXMemberExpression extends NodeBase {
15007
- includeNode(context) {
15008
- this.included = true;
15009
- if (!this.deoptimized)
15010
- this.applyDeoptimizations();
15011
- this.object.includePath([this.property.name], context);
15012
- }
15013
- includePath(path, context) {
15014
- if (!this.included)
15015
- this.includeNode(context);
15016
- this.object.includePath([this.property.name, ...path], context);
15017
- }
15018
14465
  }
15019
14466
 
15020
14467
  class JSXNamespacedName extends NodeBase {
15021
14468
  }
15022
- JSXNamespacedName.prototype.includeNode = onlyIncludeSelf;
15023
14469
 
15024
14470
  class JSXOpeningElement extends NodeBase {
15025
14471
  render(code, options, { jsxMode = this.scope.context.options.jsx.mode } = {}) {
@@ -15029,7 +14475,6 @@ class JSXOpeningElement extends NodeBase {
15029
14475
  }
15030
14476
  }
15031
14477
  }
15032
- JSXOpeningElement.prototype.includeNode = onlyIncludeSelf;
15033
14478
 
15034
14479
  class JSXOpeningFragment extends NodeBase {
15035
14480
  constructor() {
@@ -15037,22 +14482,22 @@ class JSXOpeningFragment extends NodeBase {
15037
14482
  this.fragment = null;
15038
14483
  this.fragmentVariable = null;
15039
14484
  }
15040
- includeNode(context) {
15041
- this.included = true;
15042
- if (!this.deoptimized)
15043
- this.applyDeoptimizations();
15044
- const jsx = this.scope.context.options.jsx;
15045
- if (jsx.mode === 'automatic') {
15046
- this.fragment = 'Fragment';
15047
- this.fragmentVariable = getAndIncludeFactoryVariable('Fragment', false, jsx.jsxImportSource, this, context);
15048
- }
15049
- else {
15050
- const { fragment, importSource, mode } = jsx;
15051
- if (fragment != null) {
15052
- this.fragment = fragment;
15053
- this.fragmentVariable = getAndIncludeFactoryVariable(fragment, mode === 'preserve', importSource, this, context);
14485
+ include(context, includeChildrenRecursively) {
14486
+ if (!this.included) {
14487
+ const jsx = this.scope.context.options.jsx;
14488
+ if (jsx.mode === 'automatic') {
14489
+ this.fragment = 'Fragment';
14490
+ this.fragmentVariable = getAndIncludeFactoryVariable('Fragment', false, jsx.jsxImportSource, this);
14491
+ }
14492
+ else {
14493
+ const { fragment, importSource, mode } = jsx;
14494
+ if (fragment != null) {
14495
+ this.fragment = fragment;
14496
+ this.fragmentVariable = getAndIncludeFactoryVariable(fragment, mode === 'preserve', importSource, this);
14497
+ }
15054
14498
  }
15055
14499
  }
14500
+ super.include(context, includeChildrenRecursively);
15056
14501
  }
15057
14502
  render(code, options) {
15058
14503
  const { mode } = this.scope.context.options.jsx;
@@ -15089,7 +14534,6 @@ class JSXText extends NodeBase {
15089
14534
  }
15090
14535
  }
15091
14536
  }
15092
- JSXText.prototype.includeNode = onlyIncludeSelf;
15093
14537
 
15094
14538
  class LabeledStatement extends NodeBase {
15095
14539
  hasEffects(context) {
@@ -15111,22 +14555,17 @@ class LabeledStatement extends NodeBase {
15111
14555
  return bodyHasEffects;
15112
14556
  }
15113
14557
  include(context, includeChildrenRecursively) {
15114
- if (!this.included)
15115
- this.includeNode(context);
14558
+ this.included = true;
15116
14559
  const { brokenFlow, includedLabels } = context;
15117
14560
  context.includedLabels = new Set();
15118
14561
  this.body.include(context, includeChildrenRecursively);
15119
14562
  if (includeChildrenRecursively || context.includedLabels.has(this.label.name)) {
15120
- this.label.include(context);
14563
+ this.label.include();
15121
14564
  context.includedLabels.delete(this.label.name);
15122
14565
  context.brokenFlow = brokenFlow;
15123
14566
  }
15124
14567
  context.includedLabels = new Set([...includedLabels, ...context.includedLabels]);
15125
14568
  }
15126
- includeNode(context) {
15127
- this.included = true;
15128
- this.body.includePath(UNKNOWN_PATH, context);
15129
- }
15130
14569
  render(code, options) {
15131
14570
  if (this.label.included) {
15132
14571
  this.label.render(code, options);
@@ -15137,7 +14576,6 @@ class LabeledStatement extends NodeBase {
15137
14576
  this.body.render(code, options);
15138
14577
  }
15139
14578
  }
15140
- LabeledStatement.prototype.applyDeoptimizations = doNotDeoptimize;
15141
14579
 
15142
14580
  class LogicalExpression extends NodeBase {
15143
14581
  constructor() {
@@ -15162,10 +14600,6 @@ class LogicalExpression extends NodeBase {
15162
14600
  const unusedBranch = this.usedBranch === this.left ? this.right : this.left;
15163
14601
  this.usedBranch = null;
15164
14602
  unusedBranch.deoptimizePath(UNKNOWN_PATH);
15165
- if (this.included) {
15166
- // As we are not tracking inclusions, we just include everything
15167
- unusedBranch.includePath(UNKNOWN_PATH, createInclusionContext());
15168
- }
15169
14603
  const { scope: { context }, expressionsToBeDeoptimized } = this;
15170
14604
  this.expressionsToBeDeoptimized = parseAst_js.EMPTY_ARRAY;
15171
14605
  for (const expression of expressionsToBeDeoptimized) {
@@ -15192,21 +14626,33 @@ class LogicalExpression extends NodeBase {
15192
14626
  this.expressionsToBeDeoptimized.push(origin);
15193
14627
  return usedBranch.getLiteralValueAtPath(path, recursionTracker, origin);
15194
14628
  }
14629
+ else {
14630
+ const rightValue = this.right.getLiteralValueAtPath(path, recursionTracker, origin);
14631
+ const booleanOrUnknown = tryCastLiteralValueToBoolean(rightValue);
14632
+ if (typeof booleanOrUnknown !== 'symbol') {
14633
+ if (!booleanOrUnknown && this.operator === '&&') {
14634
+ this.expressionsToBeDeoptimized.push(origin);
14635
+ return UnknownFalsyValue;
14636
+ }
14637
+ if (booleanOrUnknown && this.operator === '||') {
14638
+ return UnknownTruthyValue;
14639
+ }
14640
+ }
14641
+ }
15195
14642
  return UnknownValue;
15196
14643
  }
15197
14644
  getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin) {
15198
14645
  const usedBranch = this.getUsedBranch();
15199
- if (usedBranch) {
15200
- this.expressionsToBeDeoptimized.push(origin);
15201
- return usedBranch.getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin);
15202
- }
15203
- return [
15204
- new MultiExpression([
15205
- this.left.getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin)[0],
15206
- this.right.getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin)[0]
15207
- ]),
15208
- false
15209
- ];
14646
+ if (!usedBranch)
14647
+ return [
14648
+ new MultiExpression([
14649
+ this.left.getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin)[0],
14650
+ this.right.getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin)[0]
14651
+ ]),
14652
+ false
14653
+ ];
14654
+ this.expressionsToBeDeoptimized.push(origin);
14655
+ return usedBranch.getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin);
15210
14656
  }
15211
14657
  hasEffects(context) {
15212
14658
  if (this.left.hasEffects(context)) {
@@ -15219,18 +14665,18 @@ class LogicalExpression extends NodeBase {
15219
14665
  }
15220
14666
  hasEffectsOnInteractionAtPath(path, interaction, context) {
15221
14667
  const usedBranch = this.getUsedBranch();
15222
- if (usedBranch) {
15223
- return usedBranch.hasEffectsOnInteractionAtPath(path, interaction, context);
14668
+ if (!usedBranch) {
14669
+ return (this.left.hasEffectsOnInteractionAtPath(path, interaction, context) ||
14670
+ this.right.hasEffectsOnInteractionAtPath(path, interaction, context));
15224
14671
  }
15225
- return (this.left.hasEffectsOnInteractionAtPath(path, interaction, context) ||
15226
- this.right.hasEffectsOnInteractionAtPath(path, interaction, context));
14672
+ return usedBranch.hasEffectsOnInteractionAtPath(path, interaction, context);
15227
14673
  }
15228
14674
  include(context, includeChildrenRecursively) {
15229
14675
  this.included = true;
15230
14676
  const usedBranch = this.getUsedBranch();
15231
14677
  if (includeChildrenRecursively ||
15232
- !usedBranch ||
15233
- (usedBranch === this.right && this.left.shouldBeIncluded(context))) {
14678
+ (usedBranch === this.right && this.left.shouldBeIncluded(context)) ||
14679
+ !usedBranch) {
15234
14680
  this.left.include(context, includeChildrenRecursively);
15235
14681
  this.right.include(context, includeChildrenRecursively);
15236
14682
  }
@@ -15238,17 +14684,6 @@ class LogicalExpression extends NodeBase {
15238
14684
  usedBranch.include(context, includeChildrenRecursively);
15239
14685
  }
15240
14686
  }
15241
- includePath(path, context) {
15242
- this.included = true;
15243
- const usedBranch = this.getUsedBranch();
15244
- if (!usedBranch || (usedBranch === this.right && this.left.shouldBeIncluded(context))) {
15245
- this.left.includePath(path, context);
15246
- this.right.includePath(path, context);
15247
- }
15248
- else {
15249
- usedBranch.includePath(path, context);
15250
- }
15251
- }
15252
14687
  removeAnnotations(code) {
15253
14688
  this.left.removeAnnotations(code);
15254
14689
  }
@@ -15285,13 +14720,14 @@ class LogicalExpression extends NodeBase {
15285
14720
  if (!this.isBranchResolutionAnalysed) {
15286
14721
  this.isBranchResolutionAnalysed = true;
15287
14722
  const leftValue = this.left.getLiteralValueAtPath(EMPTY_PATH, SHARED_RECURSION_TRACKER, this);
15288
- if (typeof leftValue === 'symbol') {
14723
+ const booleanOrUnknown = tryCastLiteralValueToBoolean(leftValue);
14724
+ if (typeof booleanOrUnknown === 'symbol') {
15289
14725
  return null;
15290
14726
  }
15291
14727
  else {
15292
14728
  this.usedBranch =
15293
- (this.operator === '||' && leftValue) ||
15294
- (this.operator === '&&' && !leftValue) ||
14729
+ (this.operator === '||' && booleanOrUnknown) ||
14730
+ (this.operator === '&&' && !booleanOrUnknown) ||
15295
14731
  (this.operator === '??' && leftValue != null)
15296
14732
  ? this.left
15297
14733
  : this.right;
@@ -15300,8 +14736,6 @@ class LogicalExpression extends NodeBase {
15300
14736
  return this.usedBranch;
15301
14737
  }
15302
14738
  }
15303
- LogicalExpression.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
15304
- LogicalExpression.prototype.applyDeoptimizations = doNotDeoptimize;
15305
14739
 
15306
14740
  class NewExpression extends NodeBase {
15307
14741
  hasEffects(context) {
@@ -15321,21 +14755,16 @@ class NewExpression extends NodeBase {
15321
14755
  return path.length > 0 || type !== INTERACTION_ACCESSED;
15322
14756
  }
15323
14757
  include(context, includeChildrenRecursively) {
14758
+ if (!this.deoptimized)
14759
+ this.applyDeoptimizations();
15324
14760
  if (includeChildrenRecursively) {
15325
14761
  super.include(context, includeChildrenRecursively);
15326
14762
  }
15327
14763
  else {
15328
- if (!this.included)
15329
- this.includeNode(context);
14764
+ this.included = true;
15330
14765
  this.callee.include(context, false);
15331
14766
  }
15332
- this.callee.includeCallArguments(context, this.interaction);
15333
- }
15334
- includeNode(context) {
15335
- this.included = true;
15336
- if (!this.deoptimized)
15337
- this.applyDeoptimizations();
15338
- this.callee.includePath(UNKNOWN_PATH, context);
14767
+ this.callee.includeCallArguments(context, this.arguments);
15339
14768
  }
15340
14769
  initialise() {
15341
14770
  super.initialise();
@@ -15364,7 +14793,6 @@ class ObjectExpression extends NodeBase {
15364
14793
  constructor() {
15365
14794
  super(...arguments);
15366
14795
  this.objectEntity = null;
15367
- this.protoProp = null;
15368
14796
  }
15369
14797
  deoptimizeArgumentsOnInteractionAtPath(interaction, path, recursionTracker) {
15370
14798
  this.getObjectEntity().deoptimizeArgumentsOnInteractionAtPath(interaction, path, recursionTracker);
@@ -15384,43 +14812,15 @@ class ObjectExpression extends NodeBase {
15384
14812
  hasEffectsOnInteractionAtPath(path, interaction, context) {
15385
14813
  return this.getObjectEntity().hasEffectsOnInteractionAtPath(path, interaction, context);
15386
14814
  }
15387
- include(context, includeChildrenRecursively) {
15388
- if (!this.included)
15389
- this.includeNode(context);
15390
- this.getObjectEntity().include(context, includeChildrenRecursively);
15391
- this.protoProp?.include(context, includeChildrenRecursively);
15392
- }
15393
- includeNode(context) {
15394
- this.included = true;
15395
- this.protoProp?.includePath(UNKNOWN_PATH, context);
15396
- }
15397
- includePath(path, context) {
15398
- if (!this.included)
15399
- this.includeNode(context);
15400
- this.getObjectEntity().includePath(path, context);
15401
- }
15402
14815
  render(code, options, { renderedSurroundingElement } = parseAst_js.BLANK) {
14816
+ super.render(code, options);
15403
14817
  if (renderedSurroundingElement === parseAst_js.ExpressionStatement ||
15404
14818
  renderedSurroundingElement === parseAst_js.ArrowFunctionExpression) {
15405
14819
  code.appendRight(this.start, '(');
15406
14820
  code.prependLeft(this.end, ')');
15407
14821
  }
15408
- if (this.properties.length > 0) {
15409
- const separatedNodes = getCommaSeparatedNodesWithBoundaries(this.properties, code, this.start + 1, this.end - 1);
15410
- let lastSeparatorPos = null;
15411
- for (const { node, separator, start, end } of separatedNodes) {
15412
- if (!node.included) {
15413
- treeshakeNode(node, code, start, end);
15414
- continue;
15415
- }
15416
- lastSeparatorPos = separator;
15417
- node.render(code, options);
15418
- }
15419
- if (lastSeparatorPos) {
15420
- code.remove(lastSeparatorPos, this.end - 1);
15421
- }
15422
- }
15423
14822
  }
14823
+ applyDeoptimizations() { }
15424
14824
  getObjectEntity() {
15425
14825
  if (this.objectEntity !== null) {
15426
14826
  return this.objectEntity;
@@ -15449,7 +14849,6 @@ class ObjectExpression extends NodeBase {
15449
14849
  ? property.key.name
15450
14850
  : String(property.key.value);
15451
14851
  if (key === '__proto__' && property.kind === 'init') {
15452
- this.protoProp = property;
15453
14852
  prototype =
15454
14853
  property.value instanceof Literal && property.value.value === null
15455
14854
  ? null
@@ -15462,7 +14861,6 @@ class ObjectExpression extends NodeBase {
15462
14861
  return (this.objectEntity = new ObjectEntity(properties, prototype));
15463
14862
  }
15464
14863
  }
15465
- ObjectExpression.prototype.applyDeoptimizations = doNotDeoptimize;
15466
14864
 
15467
14865
  class PanicError extends NodeBase {
15468
14866
  initialise() {
@@ -15489,7 +14887,6 @@ class ParseError extends NodeBase {
15489
14887
 
15490
14888
  class PrivateIdentifier extends NodeBase {
15491
14889
  }
15492
- PrivateIdentifier.prototype.includeNode = onlyIncludeSelf;
15493
14890
 
15494
14891
  class Program extends NodeBase {
15495
14892
  constructor() {
@@ -15557,11 +14954,14 @@ class Program extends NodeBase {
15557
14954
  super.render(code, options);
15558
14955
  }
15559
14956
  }
14957
+ applyDeoptimizations() { }
15560
14958
  }
15561
- Program.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
15562
- Program.prototype.applyDeoptimizations = doNotDeoptimize;
15563
14959
 
15564
14960
  class Property extends MethodBase {
14961
+ constructor() {
14962
+ super(...arguments);
14963
+ this.declarationInit = null;
14964
+ }
15565
14965
  //declare method: boolean;
15566
14966
  get method() {
15567
14967
  return isFlagSet(this.flags, 262144 /* Flag.method */);
@@ -15576,41 +14976,17 @@ class Property extends MethodBase {
15576
14976
  set shorthand(value) {
15577
14977
  this.flags = setFlag(this.flags, 524288 /* Flag.shorthand */, value);
15578
14978
  }
15579
- declare(kind, destructuredInitPath, init) {
15580
- return this.value.declare(kind, this.getPathInProperty(destructuredInitPath), init);
15581
- }
15582
- deoptimizeAssignment(destructuredInitPath, init) {
15583
- this.value.deoptimizeAssignment?.(this.getPathInProperty(destructuredInitPath), init);
14979
+ declare(kind, init) {
14980
+ this.declarationInit = init;
14981
+ return this.value.declare(kind, UNKNOWN_EXPRESSION);
15584
14982
  }
15585
14983
  hasEffects(context) {
15586
- return this.key.hasEffects(context) || this.value.hasEffects(context);
15587
- }
15588
- hasEffectsWhenDestructuring(context, destructuredInitPath, init) {
15589
- return this.value.hasEffectsWhenDestructuring?.(context, this.getPathInProperty(destructuredInitPath), init);
15590
- }
15591
- includeDestructuredIfNecessary(context, destructuredInitPath, init) {
15592
- const path = this.getPathInProperty(destructuredInitPath);
15593
- let included = this.value.includeDestructuredIfNecessary(context, path, init) ||
15594
- this.included;
15595
- if ((included ||= this.key.hasEffects(createHasEffectsContext()))) {
15596
- this.key.include(context, false);
15597
- if (!this.value.included) {
15598
- this.value.included = true;
15599
- // Unfortunately, we need to include the value again now, so that any
15600
- // declared variables are properly included.
15601
- this.value.includeDestructuredIfNecessary(context, path, init);
15602
- }
15603
- }
15604
- return (this.included = included);
15605
- }
15606
- include(context, includeChildrenRecursively) {
15607
- this.included = true;
15608
- this.key.include(context, includeChildrenRecursively);
15609
- this.value.include(context, includeChildrenRecursively);
15610
- }
15611
- includePath(path, context) {
15612
- this.included = true;
15613
- this.value.includePath(path, context);
14984
+ if (!this.deoptimized)
14985
+ this.applyDeoptimizations();
14986
+ const propertyReadSideEffects = this.scope.context.options.treeshake.propertyReadSideEffects;
14987
+ return ((this.parent.type === 'ObjectPattern' && propertyReadSideEffects === 'always') ||
14988
+ this.key.hasEffects(context) ||
14989
+ this.value.hasEffects(context));
15614
14990
  }
15615
14991
  markDeclarationReached() {
15616
14992
  this.value.markDeclarationReached();
@@ -15621,20 +14997,14 @@ class Property extends MethodBase {
15621
14997
  }
15622
14998
  this.value.render(code, options, { isShorthandProperty: this.shorthand });
15623
14999
  }
15624
- getPathInProperty(destructuredInitPath) {
15625
- return destructuredInitPath.at(-1) === UnknownKey
15626
- ? destructuredInitPath
15627
- : // For now, we only consider static paths as we do not know how to
15628
- // deoptimize the path in the dynamic case.
15629
- this.computed
15630
- ? [...destructuredInitPath, UnknownKey]
15631
- : this.key instanceof Identifier
15632
- ? [...destructuredInitPath, this.key.name]
15633
- : [...destructuredInitPath, String(this.key.value)];
15000
+ applyDeoptimizations() {
15001
+ this.deoptimized = true;
15002
+ if (this.declarationInit !== null) {
15003
+ this.declarationInit.deoptimizePath([UnknownKey, UnknownKey]);
15004
+ this.scope.context.requestTreeshakingPass();
15005
+ }
15634
15006
  }
15635
15007
  }
15636
- Property.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
15637
- Property.prototype.applyDeoptimizations = doNotDeoptimize;
15638
15008
 
15639
15009
  class PropertyDefinition extends NodeBase {
15640
15010
  get computed() {
@@ -15667,15 +15037,8 @@ class PropertyDefinition extends NodeBase {
15667
15037
  hasEffectsOnInteractionAtPath(path, interaction, context) {
15668
15038
  return !this.value || this.value.hasEffectsOnInteractionAtPath(path, interaction, context);
15669
15039
  }
15670
- includeNode(context) {
15671
- this.included = true;
15672
- this.value?.includePath(UNKNOWN_PATH, context);
15673
- for (const decorator of this.decorators) {
15674
- decorator.includePath(UNKNOWN_PATH, context);
15675
- }
15676
- }
15040
+ applyDeoptimizations() { }
15677
15041
  }
15678
- PropertyDefinition.prototype.applyDeoptimizations = doNotDeoptimize;
15679
15042
 
15680
15043
  class ReturnStatement extends NodeBase {
15681
15044
  hasEffects(context) {
@@ -15685,15 +15048,10 @@ class ReturnStatement extends NodeBase {
15685
15048
  return false;
15686
15049
  }
15687
15050
  include(context, includeChildrenRecursively) {
15688
- if (!this.included)
15689
- this.includeNode(context);
15051
+ this.included = true;
15690
15052
  this.argument?.include(context, includeChildrenRecursively);
15691
15053
  context.brokenFlow = true;
15692
15054
  }
15693
- includeNode(context) {
15694
- this.included = true;
15695
- this.argument?.includePath(UNKNOWN_PATH, context);
15696
- }
15697
15055
  initialise() {
15698
15056
  super.initialise();
15699
15057
  this.scope.addReturnExpression(this.argument || UNKNOWN_EXPRESSION);
@@ -15707,7 +15065,6 @@ class ReturnStatement extends NodeBase {
15707
15065
  }
15708
15066
  }
15709
15067
  }
15710
- ReturnStatement.prototype.applyDeoptimizations = doNotDeoptimize;
15711
15068
 
15712
15069
  class SequenceExpression extends NodeBase {
15713
15070
  deoptimizeArgumentsOnInteractionAtPath(interaction, path, recursionTracker) {
@@ -15735,15 +15092,10 @@ class SequenceExpression extends NodeBase {
15735
15092
  for (const expression of this.expressions) {
15736
15093
  if (includeChildrenRecursively ||
15737
15094
  (expression === lastExpression && !(this.parent instanceof ExpressionStatement)) ||
15738
- expression.shouldBeIncluded(context)) {
15095
+ expression.shouldBeIncluded(context))
15739
15096
  expression.include(context, includeChildrenRecursively);
15740
- }
15741
15097
  }
15742
15098
  }
15743
- includePath(path, context) {
15744
- this.included = true;
15745
- this.expressions[this.expressions.length - 1].includePath(path, context);
15746
- }
15747
15099
  removeAnnotations(code) {
15748
15100
  this.expressions[0].removeAnnotations(code);
15749
15101
  }
@@ -15778,8 +15130,6 @@ class SequenceExpression extends NodeBase {
15778
15130
  }
15779
15131
  }
15780
15132
  }
15781
- SequenceExpression.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
15782
- SequenceExpression.prototype.applyDeoptimizations = doNotDeoptimize;
15783
15133
 
15784
15134
  class Super extends NodeBase {
15785
15135
  bind() {
@@ -15791,15 +15141,11 @@ class Super extends NodeBase {
15791
15141
  deoptimizePath(path) {
15792
15142
  this.variable.deoptimizePath(path);
15793
15143
  }
15794
- include(context) {
15795
- if (!this.included)
15796
- this.includeNode(context);
15797
- }
15798
- includeNode(context) {
15799
- this.included = true;
15800
- if (!this.deoptimized)
15801
- this.applyDeoptimizations();
15802
- this.scope.context.includeVariableInModule(this.variable, EMPTY_PATH, context);
15144
+ include() {
15145
+ if (!this.included) {
15146
+ this.included = true;
15147
+ this.scope.context.includeVariableInModule(this.variable);
15148
+ }
15803
15149
  }
15804
15150
  }
15805
15151
 
@@ -15840,8 +15186,6 @@ class SwitchCase extends NodeBase {
15840
15186
  }
15841
15187
  }
15842
15188
  SwitchCase.prototype.needsBoundaries = true;
15843
- SwitchCase.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
15844
- SwitchCase.prototype.applyDeoptimizations = doNotDeoptimize;
15845
15189
 
15846
15190
  class SwitchStatement extends NodeBase {
15847
15191
  createScope(parentScope) {
@@ -15924,8 +15268,6 @@ class SwitchStatement extends NodeBase {
15924
15268
  }
15925
15269
  }
15926
15270
  }
15927
- SwitchStatement.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
15928
- SwitchStatement.prototype.applyDeoptimizations = doNotDeoptimize;
15929
15271
 
15930
15272
  class TaggedTemplateExpression extends CallExpressionBase {
15931
15273
  bind() {
@@ -15949,8 +15291,8 @@ class TaggedTemplateExpression extends CallExpressionBase {
15949
15291
  this.tag.hasEffectsOnInteractionAtPath(EMPTY_PATH, this.interaction, context));
15950
15292
  }
15951
15293
  include(context, includeChildrenRecursively) {
15952
- if (!this.included)
15953
- this.includeNode(context);
15294
+ if (!this.deoptimized)
15295
+ this.applyDeoptimizations();
15954
15296
  if (includeChildrenRecursively) {
15955
15297
  super.include(context, includeChildrenRecursively);
15956
15298
  }
@@ -15959,7 +15301,7 @@ class TaggedTemplateExpression extends CallExpressionBase {
15959
15301
  this.tag.include(context, includeChildrenRecursively);
15960
15302
  this.quasi.include(context, includeChildrenRecursively);
15961
15303
  }
15962
- this.tag.includeCallArguments(context, this.interaction);
15304
+ this.tag.includeCallArguments(context, this.args);
15963
15305
  const [returnExpression] = this.getReturnExpression();
15964
15306
  if (!returnExpression.included) {
15965
15307
  returnExpression.include(context, false);
@@ -15994,7 +15336,6 @@ class TaggedTemplateExpression extends CallExpressionBase {
15994
15336
  return this.returnExpression;
15995
15337
  }
15996
15338
  }
15997
- TaggedTemplateExpression.prototype.includeNode = onlyIncludeSelf;
15998
15339
 
15999
15340
  class TemplateElement extends NodeBase {
16000
15341
  get tail() {
@@ -16008,13 +15349,15 @@ class TemplateElement extends NodeBase {
16008
15349
  hasEffects() {
16009
15350
  return false;
16010
15351
  }
15352
+ include() {
15353
+ this.included = true;
15354
+ }
16011
15355
  parseNode(esTreeNode) {
16012
15356
  this.value = esTreeNode.value;
16013
15357
  return super.parseNode(esTreeNode);
16014
15358
  }
16015
15359
  render() { }
16016
15360
  }
16017
- TemplateElement.prototype.includeNode = onlyIncludeSelf;
16018
15361
 
16019
15362
  class TemplateLiteral extends NodeBase {
16020
15363
  deoptimizeArgumentsOnInteractionAtPath() { }
@@ -16039,14 +15382,6 @@ class TemplateLiteral extends NodeBase {
16039
15382
  }
16040
15383
  return true;
16041
15384
  }
16042
- includeNode(context) {
16043
- this.included = true;
16044
- if (!this.deoptimized)
16045
- this.applyDeoptimizations();
16046
- for (const node of this.expressions) {
16047
- node.includePath(UNKNOWN_PATH, context);
16048
- }
16049
- }
16050
15385
  render(code, options) {
16051
15386
  code.indentExclusionRanges.push([this.start, this.end]);
16052
15387
  super.render(code, options);
@@ -16056,13 +15391,13 @@ class TemplateLiteral extends NodeBase {
16056
15391
  class ModuleScope extends ChildScope {
16057
15392
  constructor(parent, context) {
16058
15393
  super(parent, context);
16059
- this.variables.set('this', new LocalVariable('this', null, UNDEFINED_EXPRESSION, EMPTY_PATH, context, 'other'));
15394
+ this.variables.set('this', new LocalVariable('this', null, UNDEFINED_EXPRESSION, context, 'other'));
16060
15395
  }
16061
- addDeclaration(identifier, context, init, destructuredInitPath, kind) {
15396
+ addDeclaration(identifier, context, init, kind) {
16062
15397
  if (this.context.module.importDescriptions.has(identifier.name)) {
16063
15398
  context.error(parseAst_js.logRedeclarationError(identifier.name), identifier.start);
16064
15399
  }
16065
- return super.addDeclaration(identifier, context, init, destructuredInitPath, kind);
15400
+ return super.addDeclaration(identifier, context, init, kind);
16066
15401
  }
16067
15402
  addExportDefaultDeclaration(name, exportDefaultDeclaration, context) {
16068
15403
  const variable = new ExportDefaultVariable(name, exportDefaultDeclaration, context);
@@ -16107,23 +15442,10 @@ class ThisExpression extends NodeBase {
16107
15442
  }
16108
15443
  return this.variable.hasEffectsOnInteractionAtPath(path, interaction, context);
16109
15444
  }
16110
- include(context) {
16111
- if (!this.included)
16112
- this.includeNode(context);
16113
- }
16114
- includeNode(context) {
16115
- this.included = true;
16116
- if (!this.deoptimized)
16117
- this.applyDeoptimizations();
16118
- this.scope.context.includeVariableInModule(this.variable, EMPTY_PATH, context);
16119
- }
16120
- includePath(path, context) {
15445
+ include() {
16121
15446
  if (!this.included) {
16122
15447
  this.included = true;
16123
- this.scope.context.includeVariableInModule(this.variable, path, context);
16124
- }
16125
- else if (path.length > 0) {
16126
- this.variable.includePath(path, context);
15448
+ this.scope.context.includeVariableInModule(this.variable);
16127
15449
  }
16128
15450
  }
16129
15451
  initialise() {
@@ -16151,8 +15473,7 @@ class ThrowStatement extends NodeBase {
16151
15473
  return true;
16152
15474
  }
16153
15475
  include(context, includeChildrenRecursively) {
16154
- if (!this.included)
16155
- this.includeNode(context);
15476
+ this.included = true;
16156
15477
  this.argument.include(context, includeChildrenRecursively);
16157
15478
  context.brokenFlow = true;
16158
15479
  }
@@ -16163,7 +15484,6 @@ class ThrowStatement extends NodeBase {
16163
15484
  }
16164
15485
  }
16165
15486
  }
16166
- ThrowStatement.prototype.includeNode = onlyIncludeSelf;
16167
15487
 
16168
15488
  class TryStatement extends NodeBase {
16169
15489
  constructor() {
@@ -16200,8 +15520,6 @@ class TryStatement extends NodeBase {
16200
15520
  this.finalizer?.include(context, includeChildrenRecursively);
16201
15521
  }
16202
15522
  }
16203
- TryStatement.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
16204
- TryStatement.prototype.applyDeoptimizations = doNotDeoptimize;
16205
15523
 
16206
15524
  const unaryOperators = {
16207
15525
  '!': value => !value,
@@ -16247,7 +15565,6 @@ class UnaryExpression extends NodeBase {
16247
15565
  }
16248
15566
  }
16249
15567
  }
16250
- UnaryExpression.prototype.includeNode = onlyIncludeSelf;
16251
15568
 
16252
15569
  class UpdateExpression extends NodeBase {
16253
15570
  hasEffects(context) {
@@ -16259,8 +15576,9 @@ class UpdateExpression extends NodeBase {
16259
15576
  return path.length > 1 || type !== INTERACTION_ACCESSED;
16260
15577
  }
16261
15578
  include(context, includeChildrenRecursively) {
16262
- if (!this.included)
16263
- this.includeNode(context);
15579
+ if (!this.deoptimized)
15580
+ this.applyDeoptimizations();
15581
+ this.included = true;
16264
15582
  this.argument.includeAsAssignmentTarget(context, includeChildrenRecursively, true);
16265
15583
  }
16266
15584
  initialise() {
@@ -16299,7 +15617,6 @@ class UpdateExpression extends NodeBase {
16299
15617
  this.scope.context.requestTreeshakingPass();
16300
15618
  }
16301
15619
  }
16302
- UpdateExpression.prototype.includeNode = onlyIncludeSelf;
16303
15620
 
16304
15621
  function areAllDeclarationsIncludedAndNotExported(declarations, exportNamesByVariable) {
16305
15622
  for (const declarator of declarations) {
@@ -16330,9 +15647,8 @@ class VariableDeclaration extends NodeBase {
16330
15647
  include(context, includeChildrenRecursively, { asSingleStatement } = parseAst_js.BLANK) {
16331
15648
  this.included = true;
16332
15649
  for (const declarator of this.declarations) {
16333
- if (includeChildrenRecursively || declarator.shouldBeIncluded(context)) {
15650
+ if (includeChildrenRecursively || declarator.shouldBeIncluded(context))
16334
15651
  declarator.include(context, includeChildrenRecursively);
16335
- }
16336
15652
  const { id, init } = declarator;
16337
15653
  if (asSingleStatement) {
16338
15654
  id.include(context, includeChildrenRecursively);
@@ -16370,6 +15686,7 @@ class VariableDeclaration extends NodeBase {
16370
15686
  this.renderReplacedDeclarations(code, options);
16371
15687
  }
16372
15688
  }
15689
+ applyDeoptimizations() { }
16373
15690
  renderDeclarationEnd(code, separatorString, lastSeparatorPos, actualContentEnd, renderedContentEnd, systemPatternExports, options) {
16374
15691
  if (code.original.charCodeAt(this.end - 1) === 59 /*";"*/) {
16375
15692
  code.remove(this.end - 1, this.end);
@@ -16412,7 +15729,8 @@ class VariableDeclaration extends NodeBase {
16412
15729
  const singleSystemExport = gatherSystemExportsAndGetSingleExport(separatedNodes, options, aggregatedSystemExports);
16413
15730
  for (const { node, start, separator, contentEnd, end } of separatedNodes) {
16414
15731
  if (!node.included) {
16415
- treeshakeNode(node, code, start, end);
15732
+ code.remove(start, end);
15733
+ node.removeAnnotations(code);
16416
15734
  continue;
16417
15735
  }
16418
15736
  node.render(code, options);
@@ -16482,8 +15800,6 @@ function gatherSystemExportsAndGetSingleExport(separatedNodes, options, aggregat
16482
15800
  }
16483
15801
  return singleSystemExport;
16484
15802
  }
16485
- VariableDeclaration.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
16486
- VariableDeclaration.prototype.applyDeoptimizations = doNotDeoptimize;
16487
15803
 
16488
15804
  class WhileStatement extends NodeBase {
16489
15805
  hasEffects(context) {
@@ -16497,25 +15813,13 @@ class WhileStatement extends NodeBase {
16497
15813
  includeLoopBody(context, this.body, includeChildrenRecursively);
16498
15814
  }
16499
15815
  }
16500
- WhileStatement.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
16501
- WhileStatement.prototype.applyDeoptimizations = doNotDeoptimize;
16502
15816
 
16503
15817
  class YieldExpression extends NodeBase {
16504
- applyDeoptimizations() {
16505
- this.deoptimized = true;
16506
- this.argument?.deoptimizePath(UNKNOWN_PATH);
16507
- }
16508
15818
  hasEffects(context) {
16509
15819
  if (!this.deoptimized)
16510
15820
  this.applyDeoptimizations();
16511
15821
  return !(context.ignore.returnYield && !this.argument?.hasEffects(context));
16512
15822
  }
16513
- includeNode(context) {
16514
- this.included = true;
16515
- if (!this.deoptimized)
16516
- this.applyDeoptimizations();
16517
- this.argument?.includePath(UNKNOWN_PATH, context);
16518
- }
16519
15823
  render(code, options) {
16520
15824
  if (this.argument) {
16521
15825
  this.argument.render(code, options, { preventASI: true });
@@ -16749,7 +16053,7 @@ const bufferParsers = [
16749
16053
  const annotations = (node.annotations = parseAst_js.convertAnnotations(buffer[position + 1], buffer));
16750
16054
  node.annotationNoSideEffects = annotations.some(comment => comment.type === 'noSideEffects');
16751
16055
  const parameters = (node.params = convertNodeList(node, scope, buffer[position + 2], buffer));
16752
- scope.addParameterVariables(parameters.map(parameter => parameter.declare('parameter', EMPTY_PATH, UNKNOWN_EXPRESSION)), parameters[parameters.length - 1] instanceof RestElement);
16056
+ scope.addParameterVariables(parameters.map(parameter => parameter.declare('parameter', UNKNOWN_EXPRESSION)), parameters[parameters.length - 1] instanceof RestElement);
16753
16057
  node.body = convertNode(node, scope.bodyScope, buffer[position + 3], buffer);
16754
16058
  },
16755
16059
  function assignmentExpression(node, position, buffer) {
@@ -16795,7 +16099,7 @@ const bufferParsers = [
16795
16099
  const parameterPosition = buffer[position];
16796
16100
  const parameter = (node.param =
16797
16101
  parameterPosition === 0 ? null : convertNode(node, scope, parameterPosition, buffer));
16798
- parameter?.declare('parameter', EMPTY_PATH, UNKNOWN_EXPRESSION);
16102
+ parameter?.declare('parameter', UNKNOWN_EXPRESSION);
16799
16103
  node.body = convertNode(node, scope.bodyScope, buffer[position + 1], buffer);
16800
16104
  },
16801
16105
  function chainExpression(node, position, buffer) {
@@ -16933,7 +16237,7 @@ const bufferParsers = [
16933
16237
  node.id =
16934
16238
  idPosition === 0 ? null : convertNode(node, scope.parent, idPosition, buffer);
16935
16239
  const parameters = (node.params = convertNodeList(node, scope, buffer[position + 3], buffer));
16936
- scope.addParameterVariables(parameters.map(parameter => parameter.declare('parameter', EMPTY_PATH, UNKNOWN_EXPRESSION)), parameters[parameters.length - 1] instanceof RestElement);
16240
+ scope.addParameterVariables(parameters.map(parameter => parameter.declare('parameter', UNKNOWN_EXPRESSION)), parameters[parameters.length - 1] instanceof RestElement);
16937
16241
  node.body = convertNode(node, scope.bodyScope, buffer[position + 4], buffer);
16938
16242
  },
16939
16243
  function functionExpression(node, position, buffer) {
@@ -16946,7 +16250,7 @@ const bufferParsers = [
16946
16250
  const idPosition = buffer[position + 2];
16947
16251
  node.id = idPosition === 0 ? null : convertNode(node, node.idScope, idPosition, buffer);
16948
16252
  const parameters = (node.params = convertNodeList(node, scope, buffer[position + 3], buffer));
16949
- scope.addParameterVariables(parameters.map(parameter => parameter.declare('parameter', EMPTY_PATH, UNKNOWN_EXPRESSION)), parameters[parameters.length - 1] instanceof RestElement);
16253
+ scope.addParameterVariables(parameters.map(parameter => parameter.declare('parameter', UNKNOWN_EXPRESSION)), parameters[parameters.length - 1] instanceof RestElement);
16950
16254
  node.body = convertNode(node, scope.bodyScope, buffer[position + 4], buffer);
16951
16255
  },
16952
16256
  function identifier(node, position, buffer) {
@@ -17410,8 +16714,8 @@ class ExportShimVariable extends Variable {
17410
16714
  super(MISSING_EXPORT_SHIM_VARIABLE);
17411
16715
  this.module = module;
17412
16716
  }
17413
- includePath(path, context) {
17414
- super.includePath(path, context);
16717
+ include() {
16718
+ super.include();
17415
16719
  this.module.needsExportShim = true;
17416
16720
  }
17417
16721
  }
@@ -18102,15 +17406,16 @@ class Module {
18102
17406
  markModuleAndImpureDependenciesAsExecuted(this);
18103
17407
  this.graph.needsTreeshakingPass = true;
18104
17408
  }
18105
- const inclusionContext = createInclusionContext();
18106
17409
  for (const exportName of this.exports.keys()) {
18107
17410
  if (includeNamespaceMembers || exportName !== this.info.syntheticNamedExports) {
18108
17411
  const variable = this.getVariableForExportName(exportName)[0];
18109
17412
  if (!variable) {
18110
17413
  return parseAst_js.error(parseAst_js.logMissingEntryExport(exportName, this.id));
18111
17414
  }
18112
- this.includeVariable(variable, UNKNOWN_PATH, inclusionContext);
18113
17415
  variable.deoptimizePath(UNKNOWN_PATH);
17416
+ if (!variable.included) {
17417
+ this.includeVariable(variable);
17418
+ }
18114
17419
  }
18115
17420
  }
18116
17421
  for (const name of this.getReexports()) {
@@ -18118,7 +17423,7 @@ class Module {
18118
17423
  if (variable) {
18119
17424
  variable.deoptimizePath(UNKNOWN_PATH);
18120
17425
  if (!variable.included) {
18121
- this.includeVariable(variable, UNKNOWN_PATH, inclusionContext);
17426
+ this.includeVariable(variable);
18122
17427
  }
18123
17428
  if (variable instanceof ExternalVariable) {
18124
17429
  variable.module.reexported = true;
@@ -18139,12 +17444,13 @@ class Module {
18139
17444
  this.graph.needsTreeshakingPass = true;
18140
17445
  }
18141
17446
  let includeNamespaceMembers = false;
18142
- const inclusionContext = createInclusionContext();
18143
17447
  for (const name of names) {
18144
17448
  const variable = this.getVariableForExportName(name)[0];
18145
17449
  if (variable) {
18146
17450
  variable.deoptimizePath(UNKNOWN_PATH);
18147
- this.includeVariable(variable, UNKNOWN_PATH, inclusionContext);
17451
+ if (!variable.included) {
17452
+ this.includeVariable(variable);
17453
+ }
18148
17454
  }
18149
17455
  if (!this.exports.has(name) && !this.reexportDescriptions.has(name)) {
18150
17456
  includeNamespaceMembers = true;
@@ -18245,7 +17551,6 @@ class Module {
18245
17551
  manualPureFunctions: this.graph.pureFunctions,
18246
17552
  module: this,
18247
17553
  moduleContext: this.context,
18248
- newlyIncludedVariableInits: this.graph.newlyIncludedVariableInits,
18249
17554
  options: this.options,
18250
17555
  requestTreeshakingPass: () => (this.graph.needsTreeshakingPass = true),
18251
17556
  traceExport: (name) => this.getVariableForExportName(name)[0],
@@ -18586,13 +17891,13 @@ class Module {
18586
17891
  for (const module of [this, ...this.exportAllModules]) {
18587
17892
  if (module instanceof ExternalModule) {
18588
17893
  const [externalVariable] = module.getVariableForExportName('*');
18589
- externalVariable.includePath(UNKNOWN_PATH, createInclusionContext());
17894
+ externalVariable.include();
18590
17895
  this.includedImports.add(externalVariable);
18591
17896
  externalNamespaces.add(externalVariable);
18592
17897
  }
18593
17898
  else if (module.info.syntheticNamedExports) {
18594
17899
  const syntheticNamespace = module.getSyntheticNamespace();
18595
- syntheticNamespace.includePath(UNKNOWN_PATH, createInclusionContext());
17900
+ syntheticNamespace.include();
18596
17901
  this.includedImports.add(syntheticNamespace);
18597
17902
  syntheticNamespaces.add(syntheticNamespace);
18598
17903
  }
@@ -18602,9 +17907,7 @@ class Module {
18602
17907
  includeDynamicImport(node) {
18603
17908
  const resolution = this.dynamicImports.find(dynamicImport => dynamicImport.node === node).resolution;
18604
17909
  if (resolution instanceof Module) {
18605
- if (!resolution.includedDynamicImporters.includes(this)) {
18606
- resolution.includedDynamicImporters.push(this);
18607
- }
17910
+ resolution.includedDynamicImporters.push(this);
18608
17911
  const importedNames = this.options.treeshake
18609
17912
  ? node.getDeterministicImportedNames()
18610
17913
  : undefined;
@@ -18616,15 +17919,15 @@ class Module {
18616
17919
  }
18617
17920
  }
18618
17921
  }
18619
- includeVariable(variable, path, context) {
18620
- const { included, module: variableModule } = variable;
18621
- variable.includePath(path, context);
18622
- if (included) {
17922
+ includeVariable(variable) {
17923
+ const variableModule = variable.module;
17924
+ if (variable.included) {
18623
17925
  if (variableModule instanceof Module && variableModule !== this) {
18624
17926
  getAndExtendSideEffectModules(variable, this);
18625
17927
  }
18626
17928
  }
18627
17929
  else {
17930
+ variable.include();
18628
17931
  this.graph.needsTreeshakingPass = true;
18629
17932
  if (variableModule instanceof Module) {
18630
17933
  if (!variableModule.isExecuted) {
@@ -18641,8 +17944,8 @@ class Module {
18641
17944
  }
18642
17945
  }
18643
17946
  }
18644
- includeVariableInModule(variable, path, context) {
18645
- this.includeVariable(variable, path, context);
17947
+ includeVariableInModule(variable) {
17948
+ this.includeVariable(variable);
18646
17949
  const variableModule = variable.module;
18647
17950
  if (variableModule && variableModule !== this) {
18648
17951
  this.includedImports.add(variable);
@@ -22145,11 +21448,10 @@ class Graph {
22145
21448
  this.options = options;
22146
21449
  this.astLru = flru(5);
22147
21450
  this.cachedModules = new Map();
22148
- this.deoptimizationTracker = new EntityPathTracker();
21451
+ this.deoptimizationTracker = new PathTracker();
22149
21452
  this.entryModules = [];
22150
21453
  this.modulesById = new Map();
22151
21454
  this.needsTreeshakingPass = false;
22152
- this.newlyIncludedVariableInits = new Set();
22153
21455
  this.phase = BuildPhase.LOAD_AND_PARSE;
22154
21456
  this.scope = new GlobalScope();
22155
21457
  this.watchFiles = Object.create(null);
@@ -22243,7 +21545,6 @@ class Graph {
22243
21545
  }
22244
21546
  if (this.options.treeshake) {
22245
21547
  let treeshakingPass = 1;
22246
- this.newlyIncludedVariableInits.clear();
22247
21548
  do {
22248
21549
  timeStart(`treeshaking pass ${treeshakingPass}`, 3);
22249
21550
  this.needsTreeshakingPass = false;
@@ -22268,10 +21569,6 @@ class Graph {
22268
21569
  }
22269
21570
  }
22270
21571
  }
22271
- for (const entity of this.newlyIncludedVariableInits) {
22272
- this.newlyIncludedVariableInits.delete(entity);
22273
- entity.include(createInclusionContext(), false);
22274
- }
22275
21572
  timeEnd(`treeshaking pass ${treeshakingPass++}`, 3);
22276
21573
  } while (this.needsTreeshakingPass);
22277
21574
  }