@rollup/wasm-node 4.30.0-1 → 4.30.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,7 +1,7 @@
1
1
  /*
2
2
  @license
3
- Rollup.js v4.30.0-1
4
- Mon, 30 Dec 2024 06:51:45 GMT - commit 41ab39a6e4a5181e9be21e816dd6f11c57e1c52a
3
+ Rollup.js v4.30.1
4
+ Tue, 07 Jan 2025 10:35:22 GMT - commit 94917087deb9103fbf605c68670ceb3e71a67bf7
5
5
 
6
6
  https://github.com/rollup/rollup
7
7
 
@@ -11,27 +11,13 @@
11
11
 
12
12
  const parseAst_js = require('./parseAst.js');
13
13
  const process$1 = require('node:process');
14
- const tty = require('tty');
15
14
  const path = require('node:path');
16
15
  const require$$0 = require('path');
17
16
  const native_js = require('../native.js');
18
17
  const node_perf_hooks = require('node:perf_hooks');
19
18
  const promises = require('node:fs/promises');
20
19
 
21
- function _interopNamespaceDefault(e) {
22
- const n = Object.create(null, { [Symbol.toStringTag]: { value: 'Module' } });
23
- if (e) {
24
- for (const k in e) {
25
- n[k] = e[k];
26
- }
27
- }
28
- n.default = e;
29
- return n;
30
- }
31
-
32
- const tty__namespace = /*#__PURE__*/_interopNamespaceDefault(tty);
33
-
34
- var version = "4.30.0-1";
20
+ var version = "4.30.1";
35
21
 
36
22
  function ensureArray$1(items) {
37
23
  if (Array.isArray(items)) {
@@ -1395,120 +1381,126 @@ async function mergeOutputOptions(config, overrides, log) {
1395
1381
  return outputOptions;
1396
1382
  }
1397
1383
 
1398
- const {
1399
- env = {},
1400
- argv = [],
1401
- platform = "",
1402
- } = typeof process === "undefined" ? {} : process;
1403
-
1404
- const isDisabled = "NO_COLOR" in env || argv.includes("--no-color");
1405
- const isForced = "FORCE_COLOR" in env || argv.includes("--color");
1406
- const isWindows = platform === "win32";
1407
- const isDumbTerminal = env.TERM === "dumb";
1408
-
1409
- const isCompatibleTerminal =
1410
- tty__namespace && tty__namespace.isatty && tty__namespace.isatty(1) && env.TERM && !isDumbTerminal;
1411
-
1412
- const isCI =
1413
- "CI" in env &&
1414
- ("GITHUB_ACTIONS" in env || "GITLAB_CI" in env || "CIRCLECI" in env);
1415
-
1416
- const isColorSupported =
1417
- !isDisabled &&
1418
- (isForced || (isWindows && !isDumbTerminal) || isCompatibleTerminal || isCI);
1419
-
1420
- const replaceClose = (
1421
- index,
1422
- string,
1423
- close,
1424
- replace,
1425
- head = string.substring(0, index) + replace,
1426
- tail = string.substring(index + close.length),
1427
- next = tail.indexOf(close)
1428
- ) => head + (next < 0 ? tail : replaceClose(next, tail, close, replace));
1429
-
1430
- const clearBleed = (index, string, open, close, replace) =>
1431
- index < 0
1432
- ? open + string + close
1433
- : open + replaceClose(index, string, close, replace) + close;
1434
-
1435
- const filterEmpty =
1436
- (open, close, replace = open, at = open.length + 1) =>
1437
- (string) =>
1438
- string || !(string === "" || string === undefined)
1439
- ? clearBleed(
1440
- ("" + string).indexOf(close, at),
1441
- string,
1442
- open,
1443
- close,
1444
- replace
1445
- )
1446
- : "";
1447
-
1448
- const init = (open, close, replace) =>
1449
- filterEmpty(`\x1b[${open}m`, `\x1b[${close}m`, replace);
1450
-
1451
- const colors = {
1452
- reset: init(0, 0),
1453
- bold: init(1, 22, "\x1b[22m\x1b[1m"),
1454
- dim: init(2, 22, "\x1b[22m\x1b[2m"),
1455
- italic: init(3, 23),
1456
- underline: init(4, 24),
1457
- inverse: init(7, 27),
1458
- hidden: init(8, 28),
1459
- strikethrough: init(9, 29),
1460
- black: init(30, 39),
1461
- red: init(31, 39),
1462
- green: init(32, 39),
1463
- yellow: init(33, 39),
1464
- blue: init(34, 39),
1465
- magenta: init(35, 39),
1466
- cyan: init(36, 39),
1467
- white: init(37, 39),
1468
- gray: init(90, 39),
1469
- bgBlack: init(40, 49),
1470
- bgRed: init(41, 49),
1471
- bgGreen: init(42, 49),
1472
- bgYellow: init(43, 49),
1473
- bgBlue: init(44, 49),
1474
- bgMagenta: init(45, 49),
1475
- bgCyan: init(46, 49),
1476
- bgWhite: init(47, 49),
1477
- blackBright: init(90, 39),
1478
- redBright: init(91, 39),
1479
- greenBright: init(92, 39),
1480
- yellowBright: init(93, 39),
1481
- blueBright: init(94, 39),
1482
- magentaBright: init(95, 39),
1483
- cyanBright: init(96, 39),
1484
- whiteBright: init(97, 39),
1485
- bgBlackBright: init(100, 49),
1486
- bgRedBright: init(101, 49),
1487
- bgGreenBright: init(102, 49),
1488
- bgYellowBright: init(103, 49),
1489
- bgBlueBright: init(104, 49),
1490
- bgMagentaBright: init(105, 49),
1491
- bgCyanBright: init(106, 49),
1492
- bgWhiteBright: init(107, 49),
1493
- };
1384
+ function getDefaultExportFromCjs (x) {
1385
+ return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
1386
+ }
1494
1387
 
1495
- const createColors = ({ useColor = isColorSupported } = {}) =>
1496
- useColor
1497
- ? colors
1498
- : Object.keys(colors).reduce(
1499
- (colors, key) => ({ ...colors, [key]: String }),
1500
- {}
1501
- );
1388
+ function getAugmentedNamespace(n) {
1389
+ if (n.__esModule) return n;
1390
+ var f = n.default;
1391
+ if (typeof f == "function") {
1392
+ var a = function a () {
1393
+ if (this instanceof a) {
1394
+ return Reflect.construct(f, arguments, this.constructor);
1395
+ }
1396
+ return f.apply(this, arguments);
1397
+ };
1398
+ a.prototype = f.prototype;
1399
+ } else a = {};
1400
+ Object.defineProperty(a, '__esModule', {value: true});
1401
+ Object.keys(n).forEach(function (k) {
1402
+ var d = Object.getOwnPropertyDescriptor(n, k);
1403
+ Object.defineProperty(a, k, d.get ? d : {
1404
+ enumerable: true,
1405
+ get: function () {
1406
+ return n[k];
1407
+ }
1408
+ });
1409
+ });
1410
+ return a;
1411
+ }
1412
+
1413
+ var picocolors = {exports: {}};
1414
+
1415
+ var hasRequiredPicocolors;
1416
+
1417
+ function requirePicocolors () {
1418
+ if (hasRequiredPicocolors) return picocolors.exports;
1419
+ hasRequiredPicocolors = 1;
1420
+ let p = process || {}, argv = p.argv || [], env = p.env || {};
1421
+ let isColorSupported =
1422
+ !(!!env.NO_COLOR || argv.includes("--no-color")) &&
1423
+ (!!env.FORCE_COLOR || argv.includes("--color") || p.platform === "win32" || ((p.stdout || {}).isTTY && env.TERM !== "dumb") || !!env.CI);
1502
1424
 
1503
- const {
1504
- blue,
1505
- cyan: cyan$1} = createColors();
1425
+ let formatter = (open, close, replace = open) =>
1426
+ input => {
1427
+ let string = "" + input, index = string.indexOf(close, open.length);
1428
+ return ~index ? open + replaceClose(string, close, replace, index) + close : open + string + close
1429
+ };
1430
+
1431
+ let replaceClose = (string, close, replace, index) => {
1432
+ let result = "", cursor = 0;
1433
+ do {
1434
+ result += string.substring(cursor, index) + replace;
1435
+ cursor = index + close.length;
1436
+ index = string.indexOf(close, cursor);
1437
+ } while (~index)
1438
+ return result + string.substring(cursor)
1439
+ };
1440
+
1441
+ let createColors = (enabled = isColorSupported) => {
1442
+ let f = enabled ? formatter : () => String;
1443
+ return {
1444
+ isColorSupported: enabled,
1445
+ reset: f("\x1b[0m", "\x1b[0m"),
1446
+ bold: f("\x1b[1m", "\x1b[22m", "\x1b[22m\x1b[1m"),
1447
+ dim: f("\x1b[2m", "\x1b[22m", "\x1b[22m\x1b[2m"),
1448
+ italic: f("\x1b[3m", "\x1b[23m"),
1449
+ underline: f("\x1b[4m", "\x1b[24m"),
1450
+ inverse: f("\x1b[7m", "\x1b[27m"),
1451
+ hidden: f("\x1b[8m", "\x1b[28m"),
1452
+ strikethrough: f("\x1b[9m", "\x1b[29m"),
1453
+
1454
+ black: f("\x1b[30m", "\x1b[39m"),
1455
+ red: f("\x1b[31m", "\x1b[39m"),
1456
+ green: f("\x1b[32m", "\x1b[39m"),
1457
+ yellow: f("\x1b[33m", "\x1b[39m"),
1458
+ blue: f("\x1b[34m", "\x1b[39m"),
1459
+ magenta: f("\x1b[35m", "\x1b[39m"),
1460
+ cyan: f("\x1b[36m", "\x1b[39m"),
1461
+ white: f("\x1b[37m", "\x1b[39m"),
1462
+ gray: f("\x1b[90m", "\x1b[39m"),
1463
+
1464
+ bgBlack: f("\x1b[40m", "\x1b[49m"),
1465
+ bgRed: f("\x1b[41m", "\x1b[49m"),
1466
+ bgGreen: f("\x1b[42m", "\x1b[49m"),
1467
+ bgYellow: f("\x1b[43m", "\x1b[49m"),
1468
+ bgBlue: f("\x1b[44m", "\x1b[49m"),
1469
+ bgMagenta: f("\x1b[45m", "\x1b[49m"),
1470
+ bgCyan: f("\x1b[46m", "\x1b[49m"),
1471
+ bgWhite: f("\x1b[47m", "\x1b[49m"),
1472
+
1473
+ blackBright: f("\x1b[90m", "\x1b[39m"),
1474
+ redBright: f("\x1b[91m", "\x1b[39m"),
1475
+ greenBright: f("\x1b[92m", "\x1b[39m"),
1476
+ yellowBright: f("\x1b[93m", "\x1b[39m"),
1477
+ blueBright: f("\x1b[94m", "\x1b[39m"),
1478
+ magentaBright: f("\x1b[95m", "\x1b[39m"),
1479
+ cyanBright: f("\x1b[96m", "\x1b[39m"),
1480
+ whiteBright: f("\x1b[97m", "\x1b[39m"),
1481
+
1482
+ bgBlackBright: f("\x1b[100m", "\x1b[49m"),
1483
+ bgRedBright: f("\x1b[101m", "\x1b[49m"),
1484
+ bgGreenBright: f("\x1b[102m", "\x1b[49m"),
1485
+ bgYellowBright: f("\x1b[103m", "\x1b[49m"),
1486
+ bgBlueBright: f("\x1b[104m", "\x1b[49m"),
1487
+ bgMagentaBright: f("\x1b[105m", "\x1b[49m"),
1488
+ bgCyanBright: f("\x1b[106m", "\x1b[49m"),
1489
+ bgWhiteBright: f("\x1b[107m", "\x1b[49m"),
1490
+ }
1491
+ };
1492
+
1493
+ picocolors.exports = createColors();
1494
+ picocolors.exports.createColors = createColors;
1495
+ return picocolors.exports;
1496
+ }
1497
+
1498
+ var picocolorsExports = /*@__PURE__*/ requirePicocolors();
1499
+ const pc = /*@__PURE__*/getDefaultExportFromCjs(picocolorsExports);
1506
1500
 
1507
1501
  // @see https://no-color.org
1508
1502
  // @see https://www.npmjs.com/package/chalk
1509
- const { bold, cyan, dim, gray, green, red, underline, yellow } = createColors({
1510
- useColor: process$1.env.FORCE_COLOR !== '0' && !process$1.env.NO_COLOR
1511
- });
1503
+ const { bold, cyan, dim, gray, green, red, underline, yellow } = pc.createColors(process$1.env.FORCE_COLOR !== '0' && !process$1.env.NO_COLOR);
1512
1504
 
1513
1505
  // log to stderr to keep `rollup main.js > bundle.js` from breaking
1514
1506
  const stderr = (...parameters) => process$1.stderr.write(`${parameters.join('')}\n`);
@@ -1575,7 +1567,7 @@ function decodeInteger(reader, relative) {
1575
1567
  const shouldNegate = value & 1;
1576
1568
  value >>>= 1;
1577
1569
  if (shouldNegate) {
1578
- value = -0x80000000 | -value;
1570
+ value = -2147483648 | -value;
1579
1571
  }
1580
1572
  return relative + value;
1581
1573
  }
@@ -3499,6 +3491,71 @@ function renderSystemExportSequenceBeforeExpression(exportedVariable, expression
3499
3491
  }
3500
3492
  }
3501
3493
 
3494
+ /** @import { Node } from 'estree' */
3495
+
3496
+ /**
3497
+ * @param {Node} node
3498
+ * @param {Node} parent
3499
+ * @returns {boolean}
3500
+ */
3501
+ function is_reference(node, parent) {
3502
+ if (node.type === 'MemberExpression') {
3503
+ return !node.computed && is_reference(node.object, node);
3504
+ }
3505
+
3506
+ if (node.type !== 'Identifier') return false;
3507
+
3508
+ switch (parent?.type) {
3509
+ // disregard `bar` in `foo.bar`
3510
+ case 'MemberExpression':
3511
+ return parent.computed || node === parent.object;
3512
+
3513
+ // disregard the `foo` in `class {foo(){}}` but keep it in `class {[foo](){}}`
3514
+ case 'MethodDefinition':
3515
+ return parent.computed;
3516
+
3517
+ // disregard the `meta` in `import.meta`
3518
+ case 'MetaProperty':
3519
+ return parent.meta === node;
3520
+
3521
+ // disregard the `foo` in `class {foo=bar}` but keep it in `class {[foo]=bar}` and `class {bar=foo}`
3522
+ case 'PropertyDefinition':
3523
+ return parent.computed || node === parent.value;
3524
+
3525
+ // disregard the `bar` in `{ bar: foo }`, but keep it in `{ [bar]: foo }`
3526
+ case 'Property':
3527
+ return parent.computed || node === parent.value;
3528
+
3529
+ // disregard the `bar` in `export { foo as bar }` or
3530
+ // the foo in `import { foo as bar }`
3531
+ case 'ExportSpecifier':
3532
+ case 'ImportSpecifier':
3533
+ return node === parent.local;
3534
+
3535
+ // disregard the `foo` in `foo: while (...) { ... break foo; ... continue foo;}`
3536
+ case 'LabeledStatement':
3537
+ case 'BreakStatement':
3538
+ case 'ContinueStatement':
3539
+ return false;
3540
+
3541
+ default:
3542
+ return true;
3543
+ }
3544
+ }
3545
+
3546
+ const PureFunctionKey = Symbol('PureFunction');
3547
+ const getPureFunctions = ({ treeshake }) => {
3548
+ const pureFunctions = Object.create(null);
3549
+ for (const functionName of treeshake ? treeshake.manualPureFunctions : []) {
3550
+ let currentFunctions = pureFunctions;
3551
+ for (const pathSegment of functionName.split('.')) {
3552
+ currentFunctions = currentFunctions[pathSegment] ||= Object.create(null);
3553
+ }
3554
+ currentFunctions[PureFunctionKey] = true;
3555
+ }
3556
+ return pureFunctions;
3557
+ };
3558
+
3502
3559
  const UnknownKey = Symbol('Unknown Key');
3503
3560
  const UnknownNonAccessorKey = Symbol('Unknown Non-Accessor Key');
3504
3561
  const UnknownInteger = Symbol('Unknown Integer');
@@ -3513,7 +3570,7 @@ const UNKNOWN_PATH = [UnknownKey];
3513
3570
  const UNKNOWN_NON_ACCESSOR_PATH = [UnknownNonAccessorKey];
3514
3571
  const UNKNOWN_INTEGER_PATH = [UnknownInteger];
3515
3572
  const EntitiesKey = Symbol('Entities');
3516
- class EntityPathTracker {
3573
+ class PathTracker {
3517
3574
  constructor() {
3518
3575
  this.entityPaths = Object.create(null, {
3519
3576
  [EntitiesKey]: { value: new Set() }
@@ -3538,14 +3595,14 @@ class EntityPathTracker {
3538
3595
  getEntities(path) {
3539
3596
  let currentPaths = this.entityPaths;
3540
3597
  for (const pathSegment of path) {
3541
- currentPaths = currentPaths[pathSegment] ||= Object.create(null, {
3542
- [EntitiesKey]: { value: new Set() }
3543
- });
3598
+ currentPaths = currentPaths[pathSegment] =
3599
+ currentPaths[pathSegment] ||
3600
+ Object.create(null, { [EntitiesKey]: { value: new Set() } });
3544
3601
  }
3545
3602
  return currentPaths[EntitiesKey];
3546
3603
  }
3547
3604
  }
3548
- const SHARED_RECURSION_TRACKER = new EntityPathTracker();
3605
+ const SHARED_RECURSION_TRACKER = new PathTracker();
3549
3606
  class DiscriminatedPathTracker {
3550
3607
  constructor() {
3551
3608
  this.entityPaths = Object.create(null, {
@@ -3555,9 +3612,9 @@ class DiscriminatedPathTracker {
3555
3612
  trackEntityAtPathAndGetIfTracked(path, discriminator, entity) {
3556
3613
  let currentPaths = this.entityPaths;
3557
3614
  for (const pathSegment of path) {
3558
- currentPaths = currentPaths[pathSegment] ||= Object.create(null, {
3559
- [EntitiesKey]: { value: new Map() }
3560
- });
3615
+ currentPaths = currentPaths[pathSegment] =
3616
+ currentPaths[pathSegment] ||
3617
+ Object.create(null, { [EntitiesKey]: { value: new Map() } });
3561
3618
  }
3562
3619
  const trackedEntities = getOrCreate(currentPaths[EntitiesKey], discriminator, (getNewSet));
3563
3620
  if (trackedEntities.has(entity))
@@ -3566,137 +3623,6 @@ class DiscriminatedPathTracker {
3566
3623
  return false;
3567
3624
  }
3568
3625
  }
3569
- const UNKNOWN_INCLUDED_PATH = Object.freeze({ [UnknownKey]: parseAst_js.EMPTY_OBJECT });
3570
- class IncludedPathTracker {
3571
- constructor() {
3572
- this.includedPaths = null;
3573
- }
3574
- includePathAndGetIfIncluded(path) {
3575
- let included = true;
3576
- let parent = this;
3577
- let parentSegment = 'includedPaths';
3578
- let currentPaths = (this.includedPaths ||=
3579
- ((included = false), Object.create(null)));
3580
- for (const pathSegment of path) {
3581
- // This means from here, all paths are included
3582
- if (currentPaths[UnknownKey]) {
3583
- return true;
3584
- }
3585
- // Including UnknownKey automatically includes all nested paths.
3586
- // From above, we know that UnknownKey is not included yet.
3587
- if (typeof pathSegment === 'symbol') {
3588
- // Hopefully, this saves some memory over just setting
3589
- // currentPaths[UnknownKey] = EMPTY_OBJECT
3590
- parent[parentSegment] = UNKNOWN_INCLUDED_PATH;
3591
- return false;
3592
- }
3593
- parent = currentPaths;
3594
- parentSegment = pathSegment;
3595
- currentPaths = currentPaths[pathSegment] ||= ((included = false), Object.create(null));
3596
- }
3597
- return included;
3598
- }
3599
- includeAllPaths(entity, context, basePath) {
3600
- const { includedPaths } = this;
3601
- if (includedPaths) {
3602
- includeAllPaths(entity, context, basePath, includedPaths);
3603
- }
3604
- }
3605
- }
3606
- function includeAllPaths(entity, context, basePath, currentPaths) {
3607
- if (currentPaths[UnknownKey]) {
3608
- return entity.includePath([...basePath, UnknownKey], context);
3609
- }
3610
- const keys = Object.keys(currentPaths);
3611
- if (keys.length === 0) {
3612
- return entity.includePath(basePath, context);
3613
- }
3614
- for (const key of keys) {
3615
- includeAllPaths(entity, context, [...basePath, key], currentPaths[key]);
3616
- }
3617
- }
3618
-
3619
- /** @import { Node } from 'estree' */
3620
-
3621
- /**
3622
- * @param {Node} node
3623
- * @param {Node} parent
3624
- * @returns {boolean}
3625
- */
3626
- function is_reference(node, parent) {
3627
- if (node.type === 'MemberExpression') {
3628
- return !node.computed && is_reference(node.object, node);
3629
- }
3630
-
3631
- if (node.type !== 'Identifier') return false;
3632
-
3633
- switch (parent?.type) {
3634
- // disregard `bar` in `foo.bar`
3635
- case 'MemberExpression':
3636
- return parent.computed || node === parent.object;
3637
-
3638
- // disregard the `foo` in `class {foo(){}}` but keep it in `class {[foo](){}}`
3639
- case 'MethodDefinition':
3640
- return parent.computed;
3641
-
3642
- // disregard the `meta` in `import.meta`
3643
- case 'MetaProperty':
3644
- return parent.meta === node;
3645
-
3646
- // disregard the `foo` in `class {foo=bar}` but keep it in `class {[foo]=bar}` and `class {bar=foo}`
3647
- case 'PropertyDefinition':
3648
- return parent.computed || node === parent.value;
3649
-
3650
- // disregard the `bar` in `{ bar: foo }`, but keep it in `{ [bar]: foo }`
3651
- case 'Property':
3652
- return parent.computed || node === parent.value;
3653
-
3654
- // disregard the `bar` in `export { foo as bar }` or
3655
- // the foo in `import { foo as bar }`
3656
- case 'ExportSpecifier':
3657
- case 'ImportSpecifier':
3658
- return node === parent.local;
3659
-
3660
- // disregard the `foo` in `foo: while (...) { ... break foo; ... continue foo;}`
3661
- case 'LabeledStatement':
3662
- case 'BreakStatement':
3663
- case 'ContinueStatement':
3664
- return false;
3665
-
3666
- default:
3667
- return true;
3668
- }
3669
- }
3670
-
3671
- function createInclusionContext() {
3672
- return {
3673
- brokenFlow: false,
3674
- hasBreak: false,
3675
- hasContinue: false,
3676
- includedCallArguments: new Set(),
3677
- includedLabels: new Set()
3678
- };
3679
- }
3680
- function createHasEffectsContext() {
3681
- return {
3682
- accessed: new EntityPathTracker(),
3683
- assigned: new EntityPathTracker(),
3684
- brokenFlow: false,
3685
- called: new DiscriminatedPathTracker(),
3686
- hasBreak: false,
3687
- hasContinue: false,
3688
- ignore: {
3689
- breaks: false,
3690
- continues: false,
3691
- labels: new Set(),
3692
- returnYield: false,
3693
- this: false
3694
- },
3695
- includedLabels: new Set(),
3696
- instantiated: new DiscriminatedPathTracker(),
3697
- replacedVariableInits: new Map()
3698
- };
3699
- }
3700
3626
 
3701
3627
  function isFlagSet(flags, flag) {
3702
3628
  return (flags & flag) !== 0;
@@ -3736,25 +3662,12 @@ class ExpressionEntity {
3736
3662
  hasEffectsOnInteractionAtPath(_path, _interaction, _context) {
3737
3663
  return true;
3738
3664
  }
3739
- include(context, _includeChildrenRecursively, _options) {
3740
- if (!this.included)
3741
- this.includeNode(context);
3742
- }
3743
- includeNode(_context) {
3665
+ include(_context, _includeChildrenRecursively, _options) {
3744
3666
  this.included = true;
3745
3667
  }
3746
- includePath(_path, context) {
3747
- if (!this.included)
3748
- this.includeNode(context);
3749
- }
3750
- /* We are both including and including an unknown path here as the former
3751
- * ensures that nested nodes are included while the latter ensures that all
3752
- * paths of the expression are included.
3753
- * */
3754
- includeCallArguments(context, interaction) {
3755
- for (const argument of interaction.args) {
3756
- argument?.includePath(UNKNOWN_PATH, context);
3757
- argument?.include(context, false);
3668
+ includeCallArguments(context, parameters) {
3669
+ for (const argument of parameters) {
3670
+ argument.include(context, false);
3758
3671
  }
3759
3672
  }
3760
3673
  shouldBeIncluded(_context) {
@@ -3793,19 +3706,6 @@ const NODE_INTERACTION_UNKNOWN_CALL = {
3793
3706
  withNew: false
3794
3707
  };
3795
3708
 
3796
- const PureFunctionKey = Symbol('PureFunction');
3797
- const getPureFunctions = ({ treeshake }) => {
3798
- const pureFunctions = Object.create(null);
3799
- for (const functionName of treeshake ? treeshake.manualPureFunctions : []) {
3800
- let currentFunctions = pureFunctions;
3801
- for (const pathSegment of functionName.split('.')) {
3802
- currentFunctions = currentFunctions[pathSegment] ||= Object.create(null);
3803
- }
3804
- currentFunctions[PureFunctionKey] = true;
3805
- }
3806
- return pureFunctions;
3807
- };
3808
-
3809
3709
  class Variable extends ExpressionEntity {
3810
3710
  markReassigned() {
3811
3711
  this.isReassigned = true;
@@ -3882,9 +3782,9 @@ class Variable extends ExpressionEntity {
3882
3782
  * has not been included previously. Once a variable is included, it should
3883
3783
  * take care all its declarations are included.
3884
3784
  */
3885
- includePath(path, context) {
3785
+ include() {
3886
3786
  this.included = true;
3887
- this.renderedLikeHoisted?.includePath(path, context);
3787
+ this.renderedLikeHoisted?.include();
3888
3788
  }
3889
3789
  /**
3890
3790
  * Links the rendered name of this variable to another variable and includes
@@ -3916,8 +3816,8 @@ class ExternalVariable extends Variable {
3916
3816
  hasEffectsOnInteractionAtPath(path, { type }) {
3917
3817
  return type !== INTERACTION_ACCESSED || path.length > (this.isNamespace ? 1 : 0);
3918
3818
  }
3919
- includePath(path, context) {
3920
- super.includePath(path, context);
3819
+ include() {
3820
+ super.include();
3921
3821
  this.module.used = true;
3922
3822
  }
3923
3823
  }
@@ -4216,6 +4116,36 @@ const childNodeKeys = {
4216
4116
  YieldExpression: ['argument']
4217
4117
  };
4218
4118
 
4119
+ function createInclusionContext() {
4120
+ return {
4121
+ brokenFlow: false,
4122
+ hasBreak: false,
4123
+ hasContinue: false,
4124
+ includedCallArguments: new Set(),
4125
+ includedLabels: new Set()
4126
+ };
4127
+ }
4128
+ function createHasEffectsContext() {
4129
+ return {
4130
+ accessed: new PathTracker(),
4131
+ assigned: new PathTracker(),
4132
+ brokenFlow: false,
4133
+ called: new DiscriminatedPathTracker(),
4134
+ hasBreak: false,
4135
+ hasContinue: false,
4136
+ ignore: {
4137
+ breaks: false,
4138
+ continues: false,
4139
+ labels: new Set(),
4140
+ returnYield: false,
4141
+ this: false
4142
+ },
4143
+ includedLabels: new Set(),
4144
+ instantiated: new DiscriminatedPathTracker(),
4145
+ replacedVariableInits: new Map()
4146
+ };
4147
+ }
4148
+
4219
4149
  const INCLUDE_PARAMETERS = 'variables';
4220
4150
  const IS_SKIPPED_CHAIN = Symbol('IS_SKIPPED_CHAIN');
4221
4151
  class NodeBase extends ExpressionEntity {
@@ -4285,37 +4215,20 @@ class NodeBase extends ExpressionEntity {
4285
4215
  this.hasEffectsOnInteractionAtPath(EMPTY_PATH, this.assignmentInteraction, context));
4286
4216
  }
4287
4217
  include(context, includeChildrenRecursively, _options) {
4288
- if (!this.included)
4289
- this.includeNode(context);
4290
- for (const key of childNodeKeys[this.type]) {
4291
- const value = this[key];
4292
- if (value === null)
4293
- continue;
4294
- if (Array.isArray(value)) {
4295
- for (const child of value) {
4296
- child?.include(context, includeChildrenRecursively);
4297
- }
4298
- }
4299
- else {
4300
- value.include(context, includeChildrenRecursively);
4301
- }
4302
- }
4303
- }
4304
- includeNode(context) {
4305
- this.included = true;
4306
4218
  if (!this.deoptimized)
4307
4219
  this.applyDeoptimizations();
4220
+ this.included = true;
4308
4221
  for (const key of childNodeKeys[this.type]) {
4309
4222
  const value = this[key];
4310
4223
  if (value === null)
4311
4224
  continue;
4312
4225
  if (Array.isArray(value)) {
4313
4226
  for (const child of value) {
4314
- child?.includePath(UNKNOWN_PATH, context);
4227
+ child?.include(context, includeChildrenRecursively);
4315
4228
  }
4316
4229
  }
4317
4230
  else {
4318
- value.includePath(UNKNOWN_PATH, context);
4231
+ value.include(context, includeChildrenRecursively);
4319
4232
  }
4320
4233
  }
4321
4234
  }
@@ -4422,17 +4335,6 @@ class NodeBase extends ExpressionEntity {
4422
4335
  function createChildNodeKeysForNode(esTreeNode) {
4423
4336
  return Object.keys(esTreeNode).filter(key => typeof esTreeNode[key] === 'object' && key.charCodeAt(0) !== 95 /* _ */);
4424
4337
  }
4425
- function onlyIncludeSelf() {
4426
- this.included = true;
4427
- if (!this.deoptimized)
4428
- this.applyDeoptimizations();
4429
- }
4430
- function onlyIncludeSelfNoDeoptimize() {
4431
- this.included = true;
4432
- }
4433
- function doNotDeoptimize() {
4434
- this.deoptimized = true;
4435
- }
4436
4338
 
4437
4339
  function isObjectExpressionNode(node) {
4438
4340
  return node instanceof NodeBase && node.type === parseAst_js.ObjectExpression;
@@ -4445,8 +4347,8 @@ function assembleMemberDescriptions(memberDescriptions, inheritedDescriptions =
4445
4347
  return Object.create(inheritedDescriptions, memberDescriptions);
4446
4348
  }
4447
4349
  const UNDEFINED_EXPRESSION = new (class UndefinedExpression extends ExpressionEntity {
4448
- getLiteralValueAtPath(path) {
4449
- return path.length > 0 ? UnknownValue : undefined;
4350
+ getLiteralValueAtPath() {
4351
+ return undefined;
4450
4352
  }
4451
4353
  })();
4452
4354
  const returnsUnknown = {
@@ -4643,6 +4545,31 @@ function getMemberReturnExpressionWhenCalled(members, memberName) {
4643
4545
  return [members[memberName].returns, false];
4644
4546
  }
4645
4547
 
4548
+ class SpreadElement extends NodeBase {
4549
+ deoptimizeArgumentsOnInteractionAtPath(interaction, path, recursionTracker) {
4550
+ if (path.length > 0) {
4551
+ this.argument.deoptimizeArgumentsOnInteractionAtPath(interaction, UNKNOWN_PATH, recursionTracker);
4552
+ }
4553
+ }
4554
+ hasEffects(context) {
4555
+ if (!this.deoptimized)
4556
+ this.applyDeoptimizations();
4557
+ const { propertyReadSideEffects } = this.scope.context.options
4558
+ .treeshake;
4559
+ return (this.argument.hasEffects(context) ||
4560
+ (propertyReadSideEffects &&
4561
+ (propertyReadSideEffects === 'always' ||
4562
+ this.argument.hasEffectsOnInteractionAtPath(UNKNOWN_PATH, NODE_INTERACTION_UNKNOWN_ACCESS, context))));
4563
+ }
4564
+ applyDeoptimizations() {
4565
+ this.deoptimized = true;
4566
+ // Only properties of properties of the argument could become subject to reassignment
4567
+ // This will also reassign the return values of iterators
4568
+ this.argument.deoptimizePath([UnknownKey, UnknownKey]);
4569
+ this.scope.context.requestTreeshakingPass();
4570
+ }
4571
+ }
4572
+
4646
4573
  class Method extends ExpressionEntity {
4647
4574
  constructor(description) {
4648
4575
  super();
@@ -4768,7 +4695,6 @@ class ObjectEntity extends ExpressionEntity {
4768
4695
  this.unknownIntegerProps = [];
4769
4696
  this.unmatchableGetters = [];
4770
4697
  this.unmatchablePropertiesAndGetters = [];
4771
- this.unmatchablePropertiesAndSetters = [];
4772
4698
  this.unmatchableSetters = [];
4773
4699
  if (Array.isArray(properties)) {
4774
4700
  this.buildPropertyMaps(properties);
@@ -4925,12 +4851,7 @@ class ObjectEntity extends ExpressionEntity {
4925
4851
  }
4926
4852
  getLiteralValueAtPath(path, recursionTracker, origin) {
4927
4853
  if (path.length === 0) {
4928
- // This should actually be "UnknownTruthyValue". However, this currently
4929
- // causes an issue with TypeScript enums in files with moduleSideEffects:
4930
- // false because we cannot properly track whether a "var" has been
4931
- // initialized. This should be reverted once we can properly track this.
4932
- // return UnknownTruthyValue;
4933
- return UnknownValue;
4854
+ return UnknownTruthyValue;
4934
4855
  }
4935
4856
  const key = path[0];
4936
4857
  const expressionAtPath = this.getMemberExpressionAndTrackDeopt(key, origin);
@@ -5008,38 +4929,9 @@ class ObjectEntity extends ExpressionEntity {
5008
4929
  }
5009
4930
  return false;
5010
4931
  }
5011
- include(context, includeChildrenRecursively) {
5012
- this.included = true;
5013
- for (const property of this.allProperties) {
5014
- if (includeChildrenRecursively || property.shouldBeIncluded(context)) {
5015
- property.include(context, includeChildrenRecursively);
5016
- }
5017
- }
5018
- this.prototypeExpression?.include(context, includeChildrenRecursively);
5019
- }
5020
- includePath(path, context) {
5021
- this.included = true;
5022
- if (path.length === 0)
5023
- return;
5024
- const [key, ...subPath] = path;
5025
- const [includedMembers, includedPath] = typeof key === 'string'
5026
- ? [
5027
- [
5028
- ...new Set([
5029
- ...(this.propertiesAndGettersByKey[key] || this.unmatchablePropertiesAndGetters),
5030
- ...(this.propertiesAndSettersByKey[key] || this.unmatchablePropertiesAndSetters)
5031
- ])
5032
- ],
5033
- subPath
5034
- ]
5035
- : [this.allProperties, UNKNOWN_PATH];
5036
- for (const property of includedMembers) {
5037
- property.includePath(includedPath, context);
5038
- }
5039
- this.prototypeExpression?.includePath(path, context);
5040
- }
5041
4932
  buildPropertyMaps(properties) {
5042
- const { allProperties, propertiesAndGettersByKey, propertiesAndSettersByKey, settersByKey, gettersByKey, unknownIntegerProps, unmatchablePropertiesAndGetters, unmatchablePropertiesAndSetters, unmatchableGetters, unmatchableSetters } = this;
4933
+ const { allProperties, propertiesAndGettersByKey, propertiesAndSettersByKey, settersByKey, gettersByKey, unknownIntegerProps, unmatchablePropertiesAndGetters, unmatchableGetters, unmatchableSetters } = this;
4934
+ const unmatchablePropertiesAndSetters = [];
5043
4935
  for (let index = properties.length - 1; index >= 0; index--) {
5044
4936
  const { key, kind, property } = properties[index];
5045
4937
  allProperties.push(property);
@@ -5309,37 +5201,6 @@ const ARRAY_PROTOTYPE = new ObjectEntity({
5309
5201
  values: METHOD_DEOPTS_SELF_RETURNS_UNKNOWN
5310
5202
  }, OBJECT_PROTOTYPE, true);
5311
5203
 
5312
- class SpreadElement extends NodeBase {
5313
- deoptimizeArgumentsOnInteractionAtPath(interaction, path, recursionTracker) {
5314
- if (path.length > 0) {
5315
- this.argument.deoptimizeArgumentsOnInteractionAtPath(interaction, UNKNOWN_PATH, recursionTracker);
5316
- }
5317
- }
5318
- hasEffects(context) {
5319
- if (!this.deoptimized)
5320
- this.applyDeoptimizations();
5321
- const { propertyReadSideEffects } = this.scope.context.options
5322
- .treeshake;
5323
- return (this.argument.hasEffects(context) ||
5324
- (propertyReadSideEffects &&
5325
- (propertyReadSideEffects === 'always' ||
5326
- this.argument.hasEffectsOnInteractionAtPath(UNKNOWN_PATH, NODE_INTERACTION_UNKNOWN_ACCESS, context))));
5327
- }
5328
- includeNode(context) {
5329
- this.included = true;
5330
- if (!this.deoptimized)
5331
- this.applyDeoptimizations();
5332
- this.argument.includePath(UNKNOWN_PATH, context);
5333
- }
5334
- applyDeoptimizations() {
5335
- this.deoptimized = true;
5336
- // Only properties of properties of the argument could become subject to reassignment
5337
- // This will also reassign the return values of iterators
5338
- this.argument.deoptimizePath([UnknownKey, UnknownKey]);
5339
- this.scope.context.requestTreeshakingPass();
5340
- }
5341
- }
5342
-
5343
5204
  class ArrayExpression extends NodeBase {
5344
5205
  constructor() {
5345
5206
  super(...arguments);
@@ -5360,16 +5221,6 @@ class ArrayExpression extends NodeBase {
5360
5221
  hasEffectsOnInteractionAtPath(path, interaction, context) {
5361
5222
  return this.getObjectEntity().hasEffectsOnInteractionAtPath(path, interaction, context);
5362
5223
  }
5363
- includeNode(context) {
5364
- this.included = true;
5365
- if (!this.deoptimized)
5366
- this.applyDeoptimizations();
5367
- for (const element of this.elements) {
5368
- if (element) {
5369
- element?.includePath(UNKNOWN_PATH, context);
5370
- }
5371
- }
5372
- }
5373
5224
  applyDeoptimizations() {
5374
5225
  this.deoptimized = true;
5375
5226
  let hasSpread = false;
@@ -6437,37 +6288,17 @@ class GlobalVariable extends Variable {
6437
6288
  }
6438
6289
  }
6439
6290
 
6440
- // To avoid infinite recursions
6441
- const MAX_PATH_DEPTH = 6;
6442
- // If a path is longer than MAX_PATH_DEPTH, it is truncated so that it is at
6443
- // most MAX_PATH_DEPTH long. The last element is always UnknownKey
6444
- const limitConcatenatedPathDepth = (path1, path2) => {
6445
- const { length: length1 } = path1;
6446
- const { length: length2 } = path2;
6447
- return length1 === 0
6448
- ? path2
6449
- : length2 === 0
6450
- ? path1
6451
- : length1 + length2 > MAX_PATH_DEPTH
6452
- ? [...path1, ...path2.slice(0, MAX_PATH_DEPTH - 1 - path1.length), 'UnknownKey']
6453
- : [...path1, ...path2];
6454
- };
6455
-
6456
6291
  class LocalVariable extends Variable {
6457
- constructor(name, declarator, init,
6458
- /** if this is non-empty, the actual init is this path of this.init */
6459
- initPath, context, kind) {
6292
+ constructor(name, declarator, init, context, kind) {
6460
6293
  super(name);
6461
6294
  this.init = init;
6462
- this.initPath = initPath;
6463
- this.kind = kind;
6464
6295
  this.calledFromTryStatement = false;
6465
6296
  this.additionalInitializers = null;
6466
- this.includedPathTracker = new IncludedPathTracker();
6467
6297
  this.expressionsToBeDeoptimized = [];
6468
6298
  this.declarations = declarator ? [declarator] : [];
6469
6299
  this.deoptimizationTracker = context.deoptimizationTracker;
6470
6300
  this.module = context.module;
6301
+ this.kind = kind;
6471
6302
  }
6472
6303
  addDeclaration(identifier, init) {
6473
6304
  this.declarations.push(identifier);
@@ -6478,16 +6309,15 @@ class LocalVariable extends Variable {
6478
6309
  for (const initializer of this.additionalInitializers) {
6479
6310
  initializer.deoptimizePath(UNKNOWN_PATH);
6480
6311
  }
6312
+ this.additionalInitializers = null;
6481
6313
  }
6482
6314
  }
6483
6315
  deoptimizeArgumentsOnInteractionAtPath(interaction, path, recursionTracker) {
6484
- if (this.isReassigned || path.length + this.initPath.length > MAX_PATH_DEPTH) {
6316
+ if (this.isReassigned) {
6485
6317
  deoptimizeInteraction(interaction);
6486
6318
  return;
6487
6319
  }
6488
- recursionTracker.withTrackedEntityAtPath(path, this.init, () => {
6489
- this.init.deoptimizeArgumentsOnInteractionAtPath(interaction, [...this.initPath, ...path], recursionTracker);
6490
- }, undefined);
6320
+ recursionTracker.withTrackedEntityAtPath(path, this.init, () => this.init.deoptimizeArgumentsOnInteractionAtPath(interaction, path, recursionTracker), undefined);
6491
6321
  }
6492
6322
  deoptimizePath(path) {
6493
6323
  if (this.isReassigned ||
@@ -6501,40 +6331,37 @@ class LocalVariable extends Variable {
6501
6331
  for (const expression of expressionsToBeDeoptimized) {
6502
6332
  expression.deoptimizeCache();
6503
6333
  }
6504
- this.init.deoptimizePath([...this.initPath, UnknownKey]);
6334
+ this.init.deoptimizePath(UNKNOWN_PATH);
6505
6335
  }
6506
6336
  else {
6507
- this.init.deoptimizePath(limitConcatenatedPathDepth(this.initPath, path));
6337
+ this.init.deoptimizePath(path);
6508
6338
  }
6509
6339
  }
6510
6340
  getLiteralValueAtPath(path, recursionTracker, origin) {
6511
- if (this.isReassigned || path.length + this.initPath.length > MAX_PATH_DEPTH) {
6341
+ if (this.isReassigned) {
6512
6342
  return UnknownValue;
6513
6343
  }
6514
6344
  return recursionTracker.withTrackedEntityAtPath(path, this.init, () => {
6515
6345
  this.expressionsToBeDeoptimized.push(origin);
6516
- return this.init.getLiteralValueAtPath([...this.initPath, ...path], recursionTracker, origin);
6346
+ return this.init.getLiteralValueAtPath(path, recursionTracker, origin);
6517
6347
  }, UnknownValue);
6518
6348
  }
6519
6349
  getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin) {
6520
- if (this.isReassigned || path.length + this.initPath.length > MAX_PATH_DEPTH) {
6350
+ if (this.isReassigned) {
6521
6351
  return UNKNOWN_RETURN_EXPRESSION;
6522
6352
  }
6523
6353
  return recursionTracker.withTrackedEntityAtPath(path, this.init, () => {
6524
6354
  this.expressionsToBeDeoptimized.push(origin);
6525
- return this.init.getReturnExpressionWhenCalledAtPath([...this.initPath, ...path], interaction, recursionTracker, origin);
6355
+ return this.init.getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin);
6526
6356
  }, UNKNOWN_RETURN_EXPRESSION);
6527
6357
  }
6528
6358
  hasEffectsOnInteractionAtPath(path, interaction, context) {
6529
- if (path.length + this.initPath.length > MAX_PATH_DEPTH) {
6530
- return true;
6531
- }
6532
6359
  switch (interaction.type) {
6533
6360
  case INTERACTION_ACCESSED: {
6534
6361
  if (this.isReassigned)
6535
6362
  return true;
6536
6363
  return (!context.accessed.trackEntityAtPathAndGetIfTracked(path, this) &&
6537
- this.init.hasEffectsOnInteractionAtPath([...this.initPath, ...path], interaction, context));
6364
+ this.init.hasEffectsOnInteractionAtPath(path, interaction, context));
6538
6365
  }
6539
6366
  case INTERACTION_ASSIGNED: {
6540
6367
  if (this.included)
@@ -6544,63 +6371,44 @@ class LocalVariable extends Variable {
6544
6371
  if (this.isReassigned)
6545
6372
  return true;
6546
6373
  return (!context.assigned.trackEntityAtPathAndGetIfTracked(path, this) &&
6547
- this.init.hasEffectsOnInteractionAtPath([...this.initPath, ...path], interaction, context));
6374
+ this.init.hasEffectsOnInteractionAtPath(path, interaction, context));
6548
6375
  }
6549
6376
  case INTERACTION_CALLED: {
6550
6377
  if (this.isReassigned)
6551
6378
  return true;
6552
6379
  return (!(interaction.withNew ? context.instantiated : context.called).trackEntityAtPathAndGetIfTracked(path, interaction.args, this) &&
6553
- this.init.hasEffectsOnInteractionAtPath([...this.initPath, ...path], interaction, context));
6380
+ this.init.hasEffectsOnInteractionAtPath(path, interaction, context));
6554
6381
  }
6555
6382
  }
6556
6383
  }
6557
- includePath(path, context) {
6558
- if (!this.includedPathTracker.includePathAndGetIfIncluded(path)) {
6559
- this.module.scope.context.requestTreeshakingPass();
6560
- if (!this.included) {
6561
- // This will reduce the number of tree-shaking passes by eagerly
6562
- // including inits. By pushing this here instead of directly including
6563
- // we avoid deep call stacks.
6564
- this.module.scope.context.newlyIncludedVariableInits.add(this.init);
6565
- }
6566
- super.includePath(path, context);
6384
+ include() {
6385
+ if (!this.included) {
6386
+ super.include();
6567
6387
  for (const declaration of this.declarations) {
6568
6388
  // If node is a default export, it can save a tree-shaking run to include the full declaration now
6569
6389
  if (!declaration.included)
6570
- declaration.include(context, false);
6390
+ declaration.include(createInclusionContext(), false);
6571
6391
  let node = declaration.parent;
6572
6392
  while (!node.included) {
6573
6393
  // We do not want to properly include parents in case they are part of a dead branch
6574
6394
  // in which case .include() might pull in more dead code
6575
- node.includeNode(context);
6395
+ node.included = true;
6576
6396
  if (node.type === parseAst_js.Program)
6577
6397
  break;
6578
6398
  node = node.parent;
6579
6399
  }
6580
6400
  }
6581
- // We need to make sure we include the correct path of the init
6582
- if (path.length > 0) {
6583
- this.init.includePath(limitConcatenatedPathDepth(this.initPath, path), context);
6584
- this.additionalInitializers?.forEach(initializer => initializer.includePath(UNKNOWN_PATH, context));
6585
- }
6586
6401
  }
6587
6402
  }
6588
- includeCallArguments(context, interaction) {
6589
- if (this.isReassigned ||
6590
- context.includedCallArguments.has(this.init) ||
6591
- // This can be removed again once we can include arguments when called at
6592
- // a specific path
6593
- this.initPath.length > 0) {
6594
- for (const argument of interaction.args) {
6595
- if (argument) {
6596
- argument.includePath(UNKNOWN_PATH, context);
6597
- argument.include(context, false);
6598
- }
6403
+ includeCallArguments(context, parameters) {
6404
+ if (this.isReassigned || context.includedCallArguments.has(this.init)) {
6405
+ for (const argument of parameters) {
6406
+ argument.include(context, false);
6599
6407
  }
6600
6408
  }
6601
6409
  else {
6602
6410
  context.includedCallArguments.add(this.init);
6603
- this.init.includeCallArguments(context, interaction);
6411
+ this.init.includeCallArguments(context, parameters);
6604
6412
  context.includedCallArguments.delete(this.init);
6605
6413
  }
6606
6414
  }
@@ -6680,31 +6488,18 @@ class IdentifierBase extends NodeBase {
6680
6488
  }
6681
6489
  }
6682
6490
  }
6683
- include(context) {
6684
- if (!this.included)
6685
- this.includeNode(context);
6686
- }
6687
- includeNode(context) {
6688
- this.included = true;
6491
+ include() {
6689
6492
  if (!this.deoptimized)
6690
6493
  this.applyDeoptimizations();
6691
- if (this.variable !== null) {
6692
- this.scope.context.includeVariableInModule(this.variable, EMPTY_PATH, context);
6693
- }
6694
- }
6695
- includePath(path, context) {
6696
6494
  if (!this.included) {
6697
6495
  this.included = true;
6698
6496
  if (this.variable !== null) {
6699
- this.scope.context.includeVariableInModule(this.variable, path, context);
6497
+ this.scope.context.includeVariableInModule(this.variable);
6700
6498
  }
6701
6499
  }
6702
- else if (path.length > 0) {
6703
- this.variable?.includePath(path, context);
6704
- }
6705
6500
  }
6706
- includeCallArguments(context, interaction) {
6707
- this.variable.includeCallArguments(context, interaction);
6501
+ includeCallArguments(context, parameters) {
6502
+ this.variable.includeCallArguments(context, parameters);
6708
6503
  }
6709
6504
  isPossibleTDZ() {
6710
6505
  // return cached value to avoid issues with the next tree-shaking pass
@@ -6787,40 +6582,11 @@ function closestParentFunctionOrProgram(node) {
6787
6582
  return node;
6788
6583
  }
6789
6584
 
6790
- class ObjectMember extends ExpressionEntity {
6791
- constructor(object, path) {
6792
- super();
6793
- this.object = object;
6794
- this.path = path;
6795
- }
6796
- deoptimizeArgumentsOnInteractionAtPath(interaction, path, recursionTracker) {
6797
- this.object.deoptimizeArgumentsOnInteractionAtPath(interaction, [...this.path, ...path], recursionTracker);
6798
- }
6799
- deoptimizePath(path) {
6800
- this.object.deoptimizePath([...this.path, ...path]);
6801
- }
6802
- getLiteralValueAtPath(path, recursionTracker, origin) {
6803
- return this.object.getLiteralValueAtPath([...this.path, ...path], recursionTracker, origin);
6804
- }
6805
- getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin) {
6806
- return this.object.getReturnExpressionWhenCalledAtPath([...this.path, ...path], interaction, recursionTracker, origin);
6807
- }
6808
- hasEffectsOnInteractionAtPath(path, interaction, context) {
6809
- return this.object.hasEffectsOnInteractionAtPath([...this.path, ...path], interaction, context);
6810
- }
6811
- }
6812
-
6813
6585
  class Identifier extends IdentifierBase {
6814
6586
  constructor() {
6815
6587
  super(...arguments);
6816
6588
  this.variable = null;
6817
6589
  }
6818
- get isDestructuringDeoptimized() {
6819
- return isFlagSet(this.flags, 16777216 /* Flag.destructuringDeoptimized */);
6820
- }
6821
- set isDestructuringDeoptimized(value) {
6822
- this.flags = setFlag(this.flags, 16777216 /* Flag.destructuringDeoptimized */, value);
6823
- }
6824
6590
  addExportedVariables(variables, exportNamesByVariable) {
6825
6591
  if (exportNamesByVariable.has(this.variable)) {
6826
6592
  variables.push(this.variable);
@@ -6833,52 +6599,42 @@ class Identifier extends IdentifierBase {
6833
6599
  this.isVariableReference = true;
6834
6600
  }
6835
6601
  }
6836
- declare(kind, destructuredInitPath, init) {
6602
+ declare(kind, init) {
6837
6603
  let variable;
6838
6604
  const { treeshake } = this.scope.context.options;
6839
- if (kind === 'parameter') {
6840
- variable = this.scope.addParameterDeclaration(this, destructuredInitPath);
6841
- }
6842
- else {
6843
- variable = this.scope.addDeclaration(this, this.scope.context, init, destructuredInitPath, kind);
6844
- if (kind === 'var' && treeshake && treeshake.correctVarValueBeforeDeclaration) {
6845
- // Necessary to make sure the init is deoptimized. We cannot call deoptimizePath here.
6846
- variable.markInitializersForDeoptimization();
6605
+ switch (kind) {
6606
+ case 'var': {
6607
+ variable = this.scope.addDeclaration(this, this.scope.context, init, kind);
6608
+ if (treeshake && treeshake.correctVarValueBeforeDeclaration) {
6609
+ // Necessary to make sure the init is deoptimized. We cannot call deoptimizePath here.
6610
+ variable.markInitializersForDeoptimization();
6611
+ }
6612
+ break;
6847
6613
  }
6848
- }
6849
- return [(this.variable = variable)];
6850
- }
6851
- deoptimizeAssignment(destructuredInitPath, init) {
6852
- this.deoptimizePath(EMPTY_PATH);
6853
- init.deoptimizePath([...destructuredInitPath, UnknownKey]);
6854
- }
6855
- hasEffectsWhenDestructuring(context, destructuredInitPath, init) {
6856
- return (destructuredInitPath.length > 0 &&
6857
- init.hasEffectsOnInteractionAtPath(destructuredInitPath, NODE_INTERACTION_UNKNOWN_ACCESS, context));
6858
- }
6859
- includeDestructuredIfNecessary(context, destructuredInitPath, init) {
6860
- if (destructuredInitPath.length > 0 && !this.isDestructuringDeoptimized) {
6861
- this.isDestructuringDeoptimized = true;
6862
- init.deoptimizeArgumentsOnInteractionAtPath({
6863
- args: [new ObjectMember(init, destructuredInitPath.slice(0, -1))],
6864
- type: INTERACTION_ACCESSED
6865
- }, destructuredInitPath, SHARED_RECURSION_TRACKER);
6866
- }
6867
- const { propertyReadSideEffects } = this.scope.context.options
6868
- .treeshake;
6869
- if ((this.included ||=
6870
- destructuredInitPath.length > 0 &&
6871
- !context.brokenFlow &&
6872
- propertyReadSideEffects &&
6873
- (propertyReadSideEffects === 'always' ||
6874
- init.hasEffectsOnInteractionAtPath(destructuredInitPath, NODE_INTERACTION_UNKNOWN_ACCESS, createHasEffectsContext())))) {
6875
- if (this.variable && !this.variable.included) {
6876
- this.scope.context.includeVariableInModule(this.variable, EMPTY_PATH, context);
6614
+ case 'function': {
6615
+ // in strict mode, functions are only hoisted within a scope but not across block scopes
6616
+ variable = this.scope.addDeclaration(this, this.scope.context, init, kind);
6617
+ break;
6618
+ }
6619
+ case 'let':
6620
+ case 'const':
6621
+ case 'using':
6622
+ case 'await using':
6623
+ case 'class': {
6624
+ variable = this.scope.addDeclaration(this, this.scope.context, init, kind);
6625
+ break;
6626
+ }
6627
+ case 'parameter': {
6628
+ variable = this.scope.addParameterDeclaration(this);
6629
+ break;
6630
+ }
6631
+ /* istanbul ignore next */
6632
+ default: {
6633
+ /* istanbul ignore next */
6634
+ throw new Error(`Internal Error: Unexpected identifier kind ${kind}.`);
6877
6635
  }
6878
- init.includePath(destructuredInitPath, context);
6879
- return true;
6880
6636
  }
6881
- return false;
6637
+ return [(this.variable = variable)];
6882
6638
  }
6883
6639
  markDeclarationReached() {
6884
6640
  this.variable.initReached = true;
@@ -6932,17 +6688,18 @@ class Scope {
6932
6688
  - then the variable is still declared in the hoisted outer scope, but the initializer is assigned to the parameter
6933
6689
  - const, let, class, and function except in the cases above cannot redeclare anything
6934
6690
  */
6935
- addDeclaration(identifier, context, init, destructuredInitPath, kind) {
6691
+ addDeclaration(identifier, context, init, kind) {
6936
6692
  const name = identifier.name;
6937
6693
  const existingVariable = this.hoistedVariables?.get(name) || this.variables.get(name);
6938
6694
  if (existingVariable) {
6939
- if (kind === 'var' && existingVariable.kind === 'var') {
6695
+ const existingKind = existingVariable.kind;
6696
+ if (kind === 'var' && existingKind === 'var') {
6940
6697
  existingVariable.addDeclaration(identifier, init);
6941
6698
  return existingVariable;
6942
6699
  }
6943
6700
  context.error(parseAst_js.logRedeclarationError(name), identifier.start);
6944
6701
  }
6945
- const newVariable = new LocalVariable(identifier.name, identifier, init, destructuredInitPath, context, kind);
6702
+ const newVariable = new LocalVariable(identifier.name, identifier, init, context, kind);
6946
6703
  this.variables.set(name, newVariable);
6947
6704
  return newVariable;
6948
6705
  }
@@ -7118,6 +6875,7 @@ class MethodBase extends NodeBase {
7118
6875
  }
7119
6876
  return this.getAccessedValue()[0].hasEffectsOnInteractionAtPath(path, interaction, context);
7120
6877
  }
6878
+ applyDeoptimizations() { }
7121
6879
  getAccessedValue() {
7122
6880
  if (this.accessedValue === null) {
7123
6881
  if (this.kind === 'get') {
@@ -7131,20 +6889,19 @@ class MethodBase extends NodeBase {
7131
6889
  return this.accessedValue;
7132
6890
  }
7133
6891
  }
7134
- MethodBase.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
7135
- MethodBase.prototype.applyDeoptimizations = doNotDeoptimize;
7136
6892
 
7137
6893
  class MethodDefinition extends MethodBase {
7138
6894
  hasEffects(context) {
7139
6895
  return super.hasEffects(context) || checkEffectForNodes(this.decorators, context);
7140
6896
  }
6897
+ applyDeoptimizations() { }
7141
6898
  }
7142
6899
 
7143
6900
  class BlockScope extends ChildScope {
7144
6901
  constructor(parent) {
7145
6902
  super(parent, parent.context);
7146
6903
  }
7147
- addDeclaration(identifier, context, init, destructuredInitPath, kind) {
6904
+ addDeclaration(identifier, context, init, kind) {
7148
6905
  if (kind === 'var') {
7149
6906
  const name = identifier.name;
7150
6907
  const existingVariable = this.hoistedVariables?.get(name) || this.variables.get(name);
@@ -7156,7 +6913,7 @@ class BlockScope extends ChildScope {
7156
6913
  }
7157
6914
  return context.error(parseAst_js.logRedeclarationError(name), identifier.start);
7158
6915
  }
7159
- const declaredVariable = this.parent.addDeclaration(identifier, context, init, destructuredInitPath, kind);
6916
+ const declaredVariable = this.parent.addDeclaration(identifier, context, init, kind);
7160
6917
  // Necessary to make sure the init is deoptimized for conditional declarations.
7161
6918
  // We cannot call deoptimizePath here.
7162
6919
  declaredVariable.markInitializersForDeoptimization();
@@ -7164,7 +6921,7 @@ class BlockScope extends ChildScope {
7164
6921
  this.addHoistedVariable(name, declaredVariable);
7165
6922
  return declaredVariable;
7166
6923
  }
7167
- return super.addDeclaration(identifier, context, init, destructuredInitPath, kind);
6924
+ return super.addDeclaration(identifier, context, init, kind);
7168
6925
  }
7169
6926
  }
7170
6927
 
@@ -7196,12 +6953,33 @@ class StaticBlock extends NodeBase {
7196
6953
  }
7197
6954
  }
7198
6955
  }
7199
- StaticBlock.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
7200
- StaticBlock.prototype.applyDeoptimizations = doNotDeoptimize;
7201
6956
  function isStaticBlock(statement) {
7202
6957
  return statement.type === parseAst_js.StaticBlock;
7203
6958
  }
7204
6959
 
6960
+ class ObjectMember extends ExpressionEntity {
6961
+ constructor(object, key) {
6962
+ super();
6963
+ this.object = object;
6964
+ this.key = key;
6965
+ }
6966
+ deoptimizeArgumentsOnInteractionAtPath(interaction, path, recursionTracker) {
6967
+ this.object.deoptimizeArgumentsOnInteractionAtPath(interaction, [this.key, ...path], recursionTracker);
6968
+ }
6969
+ deoptimizePath(path) {
6970
+ this.object.deoptimizePath([this.key, ...path]);
6971
+ }
6972
+ getLiteralValueAtPath(path, recursionTracker, origin) {
6973
+ return this.object.getLiteralValueAtPath([this.key, ...path], recursionTracker, origin);
6974
+ }
6975
+ getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin) {
6976
+ return this.object.getReturnExpressionWhenCalledAtPath([this.key, ...path], interaction, recursionTracker, origin);
6977
+ }
6978
+ hasEffectsOnInteractionAtPath(path, interaction, context) {
6979
+ return this.object.hasEffectsOnInteractionAtPath([this.key, ...path], interaction, context);
6980
+ }
6981
+ }
6982
+
7205
6983
  class ClassNode extends NodeBase {
7206
6984
  constructor() {
7207
6985
  super(...arguments);
@@ -7242,20 +7020,21 @@ class ClassNode extends NodeBase {
7242
7020
  : this.getObjectEntity().hasEffectsOnInteractionAtPath(path, interaction, context);
7243
7021
  }
7244
7022
  include(context, includeChildrenRecursively) {
7245
- if (!this.included)
7246
- this.includeNode(context);
7023
+ if (!this.deoptimized)
7024
+ this.applyDeoptimizations();
7025
+ this.included = true;
7247
7026
  this.superClass?.include(context, includeChildrenRecursively);
7248
7027
  this.body.include(context, includeChildrenRecursively);
7249
7028
  for (const decorator of this.decorators)
7250
7029
  decorator.include(context, includeChildrenRecursively);
7251
7030
  if (this.id) {
7252
7031
  this.id.markDeclarationReached();
7253
- this.id.include(context);
7032
+ this.id.include();
7254
7033
  }
7255
7034
  }
7256
7035
  initialise() {
7257
7036
  super.initialise();
7258
- this.id?.declare('class', EMPTY_PATH, this);
7037
+ this.id?.declare('class', this);
7259
7038
  for (const method of this.body.body) {
7260
7039
  if (method instanceof MethodDefinition && method.kind === 'constructor') {
7261
7040
  this.classConstructor = method;
@@ -7313,12 +7092,11 @@ class ClassNode extends NodeBase {
7313
7092
  staticProperties.unshift({
7314
7093
  key: 'prototype',
7315
7094
  kind: 'init',
7316
- property: new ObjectEntity(dynamicMethods, this.superClass ? new ObjectMember(this.superClass, ['prototype']) : OBJECT_PROTOTYPE)
7095
+ property: new ObjectEntity(dynamicMethods, this.superClass ? new ObjectMember(this.superClass, 'prototype') : OBJECT_PROTOTYPE)
7317
7096
  });
7318
7097
  return (this.objectEntity = new ObjectEntity(staticProperties, this.superClass || OBJECT_PROTOTYPE));
7319
7098
  }
7320
7099
  }
7321
- ClassNode.prototype.includeNode = onlyIncludeSelf;
7322
7100
 
7323
7101
  class ClassDeclaration extends ClassNode {
7324
7102
  initialise() {
@@ -7371,7 +7149,7 @@ class ClassDeclaration extends ClassNode {
7371
7149
 
7372
7150
  class ArgumentsVariable extends LocalVariable {
7373
7151
  constructor(context) {
7374
- super('arguments', null, UNKNOWN_EXPRESSION, EMPTY_PATH, context, 'other');
7152
+ super('arguments', null, UNKNOWN_EXPRESSION, context, 'other');
7375
7153
  this.deoptimizedArguments = [];
7376
7154
  }
7377
7155
  addArgumentToBeDeoptimized(argument) {
@@ -7385,8 +7163,8 @@ class ArgumentsVariable extends LocalVariable {
7385
7163
  hasEffectsOnInteractionAtPath(path, { type }) {
7386
7164
  return type !== INTERACTION_ACCESSED || path.length > 1;
7387
7165
  }
7388
- includePath(path, context) {
7389
- super.includePath(path, context);
7166
+ include() {
7167
+ super.include();
7390
7168
  for (const argument of this.deoptimizedArguments) {
7391
7169
  argument.deoptimizePath(UNKNOWN_PATH);
7392
7170
  }
@@ -7397,28 +7175,27 @@ class ArgumentsVariable extends LocalVariable {
7397
7175
  const MAX_TRACKED_INTERACTIONS = 20;
7398
7176
  const NO_INTERACTIONS = parseAst_js.EMPTY_ARRAY;
7399
7177
  const UNKNOWN_DEOPTIMIZED_FIELD = new Set([UnknownKey]);
7400
- const EMPTY_PATH_TRACKER = new EntityPathTracker();
7178
+ const EMPTY_PATH_TRACKER = new PathTracker();
7401
7179
  const UNKNOWN_DEOPTIMIZED_ENTITY = new Set([UNKNOWN_EXPRESSION]);
7402
7180
  class ParameterVariable extends LocalVariable {
7403
- constructor(name, declarator, argumentPath, context) {
7404
- super(name, declarator, UNKNOWN_EXPRESSION, argumentPath, context, 'parameter');
7181
+ constructor(name, declarator, context) {
7182
+ super(name, declarator, UNKNOWN_EXPRESSION, context, 'parameter');
7405
7183
  this.deoptimizationInteractions = [];
7406
- this.deoptimizations = new EntityPathTracker();
7184
+ this.deoptimizations = new PathTracker();
7407
7185
  this.deoptimizedFields = new Set();
7408
- this.argumentsToBeDeoptimized = new Set();
7409
- this.expressionsDependingOnKnownValue = [];
7186
+ this.entitiesToBeDeoptimized = new Set();
7187
+ this.expressionsUseTheKnownValue = [];
7410
7188
  this.knownValue = null;
7411
7189
  this.knownValueLiteral = UnknownValue;
7412
7190
  this.frozenValue = null;
7413
7191
  }
7414
- addArgumentValue(entity) {
7415
- this.updateKnownValue(entity);
7192
+ addEntityToBeDeoptimized(entity) {
7416
7193
  if (entity === UNKNOWN_EXPRESSION) {
7417
7194
  // As unknown expressions fully deoptimize all interactions, we can clear
7418
7195
  // the interaction cache at this point provided we keep this optimization
7419
7196
  // in mind when adding new interactions
7420
- if (!this.argumentsToBeDeoptimized.has(UNKNOWN_EXPRESSION)) {
7421
- this.argumentsToBeDeoptimized.add(UNKNOWN_EXPRESSION);
7197
+ if (!this.entitiesToBeDeoptimized.has(UNKNOWN_EXPRESSION)) {
7198
+ this.entitiesToBeDeoptimized.add(UNKNOWN_EXPRESSION);
7422
7199
  for (const { interaction } of this.deoptimizationInteractions) {
7423
7200
  deoptimizeInteraction(interaction);
7424
7201
  }
@@ -7428,34 +7205,27 @@ class ParameterVariable extends LocalVariable {
7428
7205
  else if (this.deoptimizedFields.has(UnknownKey)) {
7429
7206
  // This means that we already deoptimized all interactions and no longer
7430
7207
  // track them
7431
- entity.deoptimizePath([...this.initPath, UnknownKey]);
7208
+ entity.deoptimizePath(UNKNOWN_PATH);
7432
7209
  }
7433
- else if (!this.argumentsToBeDeoptimized.has(entity)) {
7434
- this.argumentsToBeDeoptimized.add(entity);
7210
+ else if (!this.entitiesToBeDeoptimized.has(entity)) {
7211
+ this.entitiesToBeDeoptimized.add(entity);
7435
7212
  for (const field of this.deoptimizedFields) {
7436
- entity.deoptimizePath([...this.initPath, field]);
7213
+ entity.deoptimizePath([field]);
7437
7214
  }
7438
7215
  for (const { interaction, path } of this.deoptimizationInteractions) {
7439
- if (this.initPath.length + path.length > MAX_PATH_DEPTH) {
7440
- deoptimizeInteraction(interaction);
7441
- continue;
7442
- }
7443
- entity.deoptimizeArgumentsOnInteractionAtPath(interaction, [...this.initPath, ...path], SHARED_RECURSION_TRACKER);
7216
+ entity.deoptimizeArgumentsOnInteractionAtPath(interaction, path, SHARED_RECURSION_TRACKER);
7444
7217
  }
7445
7218
  }
7446
7219
  }
7447
- /** This says we should not make assumptions about the value of the parameter.
7448
- * This is different from deoptimization that will also cause argument values
7449
- * to be deoptimized. */
7450
7220
  markReassigned() {
7451
7221
  if (this.isReassigned) {
7452
7222
  return;
7453
7223
  }
7454
7224
  super.markReassigned();
7455
- for (const expression of this.expressionsDependingOnKnownValue) {
7225
+ for (const expression of this.expressionsUseTheKnownValue) {
7456
7226
  expression.deoptimizeCache();
7457
7227
  }
7458
- this.expressionsDependingOnKnownValue = parseAst_js.EMPTY_ARRAY;
7228
+ this.expressionsUseTheKnownValue = parseAst_js.EMPTY_ARRAY;
7459
7229
  }
7460
7230
  deoptimizeCache() {
7461
7231
  this.markReassigned();
@@ -7472,7 +7242,7 @@ class ParameterVariable extends LocalVariable {
7472
7242
  }
7473
7243
  if (this.knownValue === null) {
7474
7244
  this.knownValue = argument;
7475
- this.knownValueLiteral = argument.getLiteralValueAtPath(this.initPath, SHARED_RECURSION_TRACKER, this);
7245
+ this.knownValueLiteral = argument.getLiteralValueAtPath(EMPTY_PATH, SHARED_RECURSION_TRACKER, this);
7476
7246
  return;
7477
7247
  }
7478
7248
  // the same literal or identifier, do nothing
@@ -7488,7 +7258,7 @@ class ParameterVariable extends LocalVariable {
7488
7258
  return;
7489
7259
  }
7490
7260
  // add tracking for the new argument
7491
- const newValue = argument.getLiteralValueAtPath(this.initPath, SHARED_RECURSION_TRACKER, this);
7261
+ const newValue = argument.getLiteralValueAtPath(EMPTY_PATH, SHARED_RECURSION_TRACKER, this);
7492
7262
  if (newValue !== oldValue) {
7493
7263
  this.markReassigned();
7494
7264
  }
@@ -7506,31 +7276,24 @@ class ParameterVariable extends LocalVariable {
7506
7276
  return this.frozenValue;
7507
7277
  }
7508
7278
  getLiteralValueAtPath(path, recursionTracker, origin) {
7509
- if (this.isReassigned || path.length + this.initPath.length > MAX_PATH_DEPTH) {
7279
+ if (this.isReassigned) {
7510
7280
  return UnknownValue;
7511
7281
  }
7512
7282
  const knownValue = this.getKnownValue();
7513
- this.expressionsDependingOnKnownValue.push(origin);
7514
- return recursionTracker.withTrackedEntityAtPath(path, knownValue, () => knownValue.getLiteralValueAtPath([...this.initPath, ...path], recursionTracker, origin), UnknownValue);
7283
+ this.expressionsUseTheKnownValue.push(origin);
7284
+ return recursionTracker.withTrackedEntityAtPath(path, knownValue, () => knownValue.getLiteralValueAtPath(path, recursionTracker, origin), UnknownValue);
7515
7285
  }
7516
7286
  hasEffectsOnInteractionAtPath(path, interaction, context) {
7517
- const { type } = interaction;
7518
- if (this.isReassigned ||
7519
- type === INTERACTION_ASSIGNED ||
7520
- path.length + this.initPath.length > MAX_PATH_DEPTH) {
7287
+ if (this.isReassigned || interaction.type === INTERACTION_ASSIGNED) {
7521
7288
  return super.hasEffectsOnInteractionAtPath(path, interaction, context);
7522
7289
  }
7523
- return (!(type === INTERACTION_CALLED
7524
- ? (interaction.withNew
7525
- ? context.instantiated
7526
- : context.called).trackEntityAtPathAndGetIfTracked(path, interaction.args, this)
7527
- : context.accessed.trackEntityAtPathAndGetIfTracked(path, this)) &&
7528
- this.getKnownValue().hasEffectsOnInteractionAtPath([...this.initPath, ...path], interaction, context));
7290
+ const knownValue = this.getKnownValue();
7291
+ return knownValue.hasEffectsOnInteractionAtPath(path, interaction, context);
7529
7292
  }
7530
7293
  deoptimizeArgumentsOnInteractionAtPath(interaction, path) {
7531
7294
  // For performance reasons, we fully deoptimize all deeper interactions
7532
7295
  if (path.length >= 2 ||
7533
- this.argumentsToBeDeoptimized.has(UNKNOWN_EXPRESSION) ||
7296
+ this.entitiesToBeDeoptimized.has(UNKNOWN_EXPRESSION) ||
7534
7297
  this.deoptimizationInteractions.length >= MAX_TRACKED_INTERACTIONS ||
7535
7298
  (path.length === 1 &&
7536
7299
  (this.deoptimizedFields.has(UnknownKey) ||
@@ -7539,10 +7302,10 @@ class ParameterVariable extends LocalVariable {
7539
7302
  return;
7540
7303
  }
7541
7304
  if (!this.deoptimizations.trackEntityAtPathAndGetIfTracked(path, interaction.args)) {
7542
- for (const entity of this.argumentsToBeDeoptimized) {
7543
- entity.deoptimizeArgumentsOnInteractionAtPath(interaction, [...this.initPath, ...path], SHARED_RECURSION_TRACKER);
7305
+ for (const entity of this.entitiesToBeDeoptimized) {
7306
+ entity.deoptimizeArgumentsOnInteractionAtPath(interaction, path, SHARED_RECURSION_TRACKER);
7544
7307
  }
7545
- if (!this.argumentsToBeDeoptimized.has(UNKNOWN_EXPRESSION)) {
7308
+ if (!this.entitiesToBeDeoptimized.has(UNKNOWN_EXPRESSION)) {
7546
7309
  this.deoptimizationInteractions.push({
7547
7310
  interaction,
7548
7311
  path
@@ -7563,17 +7326,17 @@ class ParameterVariable extends LocalVariable {
7563
7326
  return;
7564
7327
  }
7565
7328
  this.deoptimizedFields.add(key);
7566
- for (const entity of this.argumentsToBeDeoptimized) {
7329
+ for (const entity of this.entitiesToBeDeoptimized) {
7567
7330
  // We do not need a recursion tracker here as we already track whether
7568
7331
  // this field is deoptimized
7569
- entity.deoptimizePath([...this.initPath, key]);
7332
+ entity.deoptimizePath([key]);
7570
7333
  }
7571
7334
  if (key === UnknownKey) {
7572
7335
  // save some memory
7573
7336
  this.deoptimizationInteractions = NO_INTERACTIONS;
7574
7337
  this.deoptimizations = EMPTY_PATH_TRACKER;
7575
7338
  this.deoptimizedFields = UNKNOWN_DEOPTIMIZED_FIELD;
7576
- this.argumentsToBeDeoptimized = UNKNOWN_DEOPTIMIZED_ENTITY;
7339
+ this.entitiesToBeDeoptimized = UNKNOWN_DEOPTIMIZED_ENTITY;
7577
7340
  }
7578
7341
  }
7579
7342
  getReturnExpressionWhenCalledAtPath(path) {
@@ -7588,14 +7351,11 @@ class ParameterVariable extends LocalVariable {
7588
7351
  }
7589
7352
  return UNKNOWN_RETURN_EXPRESSION;
7590
7353
  }
7591
- includeArgumentPaths(entity, context) {
7592
- this.includedPathTracker.includeAllPaths(entity, context, this.initPath);
7593
- }
7594
7354
  }
7595
7355
 
7596
7356
  class ThisVariable extends ParameterVariable {
7597
7357
  constructor(context) {
7598
- super('this', null, EMPTY_PATH, context);
7358
+ super('this', null, context);
7599
7359
  }
7600
7360
  hasEffectsOnInteractionAtPath(path, interaction, context) {
7601
7361
  return (context.replacedVariableInits.get(this) || UNKNOWN_EXPRESSION).hasEffectsOnInteractionAtPath(path, interaction, context);
@@ -7607,7 +7367,7 @@ class CatchBodyScope extends ChildScope {
7607
7367
  super(parent, parent.context);
7608
7368
  this.parent = parent;
7609
7369
  }
7610
- addDeclaration(identifier, context, init, destructuredInitPath, kind) {
7370
+ addDeclaration(identifier, context, init, kind) {
7611
7371
  if (kind === 'var') {
7612
7372
  const name = identifier.name;
7613
7373
  const existingVariable = this.hoistedVariables?.get(name) || this.variables.get(name);
@@ -7620,7 +7380,7 @@ class CatchBodyScope extends ChildScope {
7620
7380
  // the assignment actually goes to the parameter and the var is
7621
7381
  // hoisted without assignment. Locally, it is shadowed by the
7622
7382
  // parameter
7623
- const declaredVariable = this.parent.parent.addDeclaration(identifier, context, UNDEFINED_EXPRESSION, destructuredInitPath, kind);
7383
+ const declaredVariable = this.parent.parent.addDeclaration(identifier, context, UNDEFINED_EXPRESSION, kind);
7624
7384
  // To avoid the need to rewrite the declaration, we link the variable
7625
7385
  // names. If we ever implement a logic that splits initialization and
7626
7386
  // assignment for hoisted vars, the "renderLikeHoisted" logic can be
@@ -7639,7 +7399,7 @@ class CatchBodyScope extends ChildScope {
7639
7399
  return context.error(parseAst_js.logRedeclarationError(name), identifier.start);
7640
7400
  }
7641
7401
  // We only add parameters to parameter scopes
7642
- const declaredVariable = this.parent.parent.addDeclaration(identifier, context, init, destructuredInitPath, kind);
7402
+ const declaredVariable = this.parent.parent.addDeclaration(identifier, context, init, kind);
7643
7403
  // Necessary to make sure the init is deoptimized for conditional declarations.
7644
7404
  // We cannot call deoptimizePath here.
7645
7405
  declaredVariable.markInitializersForDeoptimization();
@@ -7647,7 +7407,7 @@ class CatchBodyScope extends ChildScope {
7647
7407
  this.addHoistedVariable(name, declaredVariable);
7648
7408
  return declaredVariable;
7649
7409
  }
7650
- return super.addDeclaration(identifier, context, init, destructuredInitPath, kind);
7410
+ return super.addDeclaration(identifier, context, init, kind);
7651
7411
  }
7652
7412
  }
7653
7413
 
@@ -7657,7 +7417,7 @@ class FunctionBodyScope extends ChildScope {
7657
7417
  }
7658
7418
  // There is stuff that is only allowed in function scopes, i.e. functions can
7659
7419
  // be redeclared, functions and var can redeclare each other
7660
- addDeclaration(identifier, context, init, destructuredInitPath, kind) {
7420
+ addDeclaration(identifier, context, init, kind) {
7661
7421
  const name = identifier.name;
7662
7422
  const existingVariable = this.hoistedVariables?.get(name) || this.variables.get(name);
7663
7423
  if (existingVariable) {
@@ -7669,7 +7429,7 @@ class FunctionBodyScope extends ChildScope {
7669
7429
  }
7670
7430
  context.error(parseAst_js.logRedeclarationError(name), identifier.start);
7671
7431
  }
7672
- const newVariable = new LocalVariable(identifier.name, identifier, init, destructuredInitPath, context, kind);
7432
+ const newVariable = new LocalVariable(identifier.name, identifier, init, context, kind);
7673
7433
  this.variables.set(name, newVariable);
7674
7434
  return newVariable;
7675
7435
  }
@@ -7678,21 +7438,21 @@ class FunctionBodyScope extends ChildScope {
7678
7438
  class ParameterScope extends ChildScope {
7679
7439
  constructor(parent, isCatchScope) {
7680
7440
  super(parent, parent.context);
7681
- this.hasRest = false;
7682
7441
  this.parameters = [];
7442
+ this.hasRest = false;
7683
7443
  this.bodyScope = isCatchScope ? new CatchBodyScope(this) : new FunctionBodyScope(this);
7684
7444
  }
7685
7445
  /**
7686
7446
  * Adds a parameter to this scope. Parameters must be added in the correct
7687
7447
  * order, i.e. from left to right.
7688
7448
  */
7689
- addParameterDeclaration(identifier, argumentPath) {
7449
+ addParameterDeclaration(identifier) {
7690
7450
  const { name, start } = identifier;
7691
7451
  const existingParameter = this.variables.get(name);
7692
7452
  if (existingParameter) {
7693
7453
  return this.context.error(parseAst_js.logDuplicateArgumentNameError(name), start);
7694
7454
  }
7695
- const variable = new ParameterVariable(name, identifier, argumentPath, this.context);
7455
+ const variable = new ParameterVariable(name, identifier, this.context);
7696
7456
  this.variables.set(name, variable);
7697
7457
  // We also add it to the body scope to detect name conflicts with local
7698
7458
  // variables. We still need the intermediate scope, though, as parameter
@@ -7710,56 +7470,42 @@ class ParameterScope extends ChildScope {
7710
7470
  }
7711
7471
  this.hasRest = hasRest;
7712
7472
  }
7713
- includeCallArguments(context, interaction) {
7473
+ includeCallArguments(context, parameters) {
7714
7474
  let calledFromTryStatement = false;
7715
7475
  let argumentIncluded = false;
7716
7476
  const restParameter = this.hasRest && this.parameters[this.parameters.length - 1];
7717
- const { args } = interaction;
7718
- let lastExplicitlyIncludedIndex = args.length - 1;
7719
- // If there is a SpreadElement, we need to include all arguments after it
7720
- // because we no longer know which argument corresponds to which parameter.
7721
- for (let argumentIndex = 1; argumentIndex < args.length; argumentIndex++) {
7722
- const argument = args[argumentIndex];
7723
- if (argument instanceof SpreadElement && !argumentIncluded) {
7724
- argumentIncluded = true;
7725
- lastExplicitlyIncludedIndex = argumentIndex - 1;
7726
- }
7727
- if (argumentIncluded) {
7728
- argument.includePath(UNKNOWN_PATH, context);
7729
- argument.include(context, false);
7477
+ for (const checkedArgument of parameters) {
7478
+ if (checkedArgument instanceof SpreadElement) {
7479
+ for (const argument of parameters) {
7480
+ argument.include(context, false);
7481
+ }
7482
+ break;
7730
7483
  }
7731
7484
  }
7732
- // Now we go backwards either starting from the last argument or before the
7733
- // first SpreadElement to ensure all arguments before are included as needed
7734
- for (let index = lastExplicitlyIncludedIndex; index >= 1; index--) {
7735
- const parameterVariables = this.parameters[index - 1] || restParameter;
7736
- const argument = args[index];
7485
+ for (let index = parameters.length - 1; index >= 0; index--) {
7486
+ const parameterVariables = this.parameters[index] || restParameter;
7487
+ const argument = parameters[index];
7737
7488
  if (parameterVariables) {
7738
7489
  calledFromTryStatement = false;
7739
7490
  if (parameterVariables.length === 0) {
7740
- // handle empty destructuring to avoid destructuring undefined
7491
+ // handle empty destructuring
7741
7492
  argumentIncluded = true;
7742
7493
  }
7743
7494
  else {
7744
7495
  for (const variable of parameterVariables) {
7745
- if (variable.calledFromTryStatement) {
7746
- calledFromTryStatement = true;
7747
- }
7748
7496
  if (variable.included) {
7749
7497
  argumentIncluded = true;
7750
- if (calledFromTryStatement) {
7751
- argument.include(context, true);
7752
- }
7753
- else {
7754
- variable.includeArgumentPaths(argument, context);
7755
- argument.include(context, false);
7756
- }
7498
+ }
7499
+ if (variable.calledFromTryStatement) {
7500
+ calledFromTryStatement = true;
7757
7501
  }
7758
7502
  }
7759
7503
  }
7760
7504
  }
7761
- if (!argument.included && (argumentIncluded || argument.shouldBeIncluded(context))) {
7505
+ if (!argumentIncluded && argument.shouldBeIncluded(context)) {
7762
7506
  argumentIncluded = true;
7507
+ }
7508
+ if (argumentIncluded) {
7763
7509
  argument.include(context, calledFromTryStatement);
7764
7510
  }
7765
7511
  }
@@ -7775,62 +7521,11 @@ class ReturnValueScope extends ParameterScope {
7775
7521
  addReturnExpression(expression) {
7776
7522
  this.returnExpressions.push(expression);
7777
7523
  }
7778
- deoptimizeArgumentsOnCall(interaction) {
7779
- const { parameters } = this;
7780
- const { args } = interaction;
7781
- let position = 0;
7782
- for (; position < args.length - 1; position++) {
7783
- // Only the "this" argument arg[0] can be null
7784
- const argument = args[position + 1];
7785
- if (argument instanceof SpreadElement) {
7786
- // This deoptimizes the current and remaining parameters and arguments
7787
- for (; position < parameters.length; position++) {
7788
- args[position + 1]?.deoptimizePath(UNKNOWN_PATH);
7789
- parameters[position].forEach(variable => variable.markReassigned());
7790
- }
7791
- break;
7792
- }
7793
- if (this.hasRest && position >= parameters.length - 1) {
7794
- argument.deoptimizePath(UNKNOWN_PATH);
7795
- }
7796
- else {
7797
- const variables = parameters[position];
7798
- if (variables) {
7799
- for (const variable of variables) {
7800
- variable.addArgumentValue(argument);
7801
- }
7802
- }
7803
- this.addArgumentToBeDeoptimized(argument);
7804
- }
7805
- }
7806
- const nonRestParameterLength = this.hasRest ? parameters.length - 1 : parameters.length;
7807
- for (; position < nonRestParameterLength; position++) {
7808
- for (const variable of parameters[position]) {
7809
- variable.addArgumentValue(UNDEFINED_EXPRESSION);
7810
- }
7811
- }
7812
- }
7813
7524
  getReturnExpression() {
7814
7525
  if (this.returnExpression === null)
7815
7526
  this.updateReturnExpression();
7816
7527
  return this.returnExpression;
7817
7528
  }
7818
- deoptimizeAllParameters() {
7819
- for (const parameter of this.parameters) {
7820
- for (const variable of parameter) {
7821
- variable.deoptimizePath(UNKNOWN_PATH);
7822
- variable.markReassigned();
7823
- }
7824
- }
7825
- }
7826
- reassignAllParameters() {
7827
- for (const parameter of this.parameters) {
7828
- for (const variable of parameter) {
7829
- variable.markReassigned();
7830
- }
7831
- }
7832
- }
7833
- addArgumentToBeDeoptimized(_argument) { }
7834
7529
  updateReturnExpression() {
7835
7530
  if (this.returnExpressions.length === 1) {
7836
7531
  this.returnExpression = this.returnExpressions[0];
@@ -7846,30 +7541,24 @@ class ReturnValueScope extends ParameterScope {
7846
7541
 
7847
7542
  class FunctionScope extends ReturnValueScope {
7848
7543
  constructor(parent) {
7849
- super(parent, false);
7850
7544
  const { context } = parent;
7545
+ super(parent, false);
7851
7546
  this.variables.set('arguments', (this.argumentsVariable = new ArgumentsVariable(context)));
7852
7547
  this.variables.set('this', (this.thisVariable = new ThisVariable(context)));
7853
7548
  }
7854
7549
  findLexicalBoundary() {
7855
7550
  return this;
7856
7551
  }
7857
- includeCallArguments(context, interaction) {
7858
- super.includeCallArguments(context, interaction);
7552
+ includeCallArguments(context, parameters) {
7553
+ super.includeCallArguments(context, parameters);
7859
7554
  if (this.argumentsVariable.included) {
7860
- const { args } = interaction;
7861
- for (let argumentIndex = 1; argumentIndex < args.length; argumentIndex++) {
7862
- const argument = args[argumentIndex];
7863
- if (argument) {
7864
- argument.includePath(UNKNOWN_PATH, context);
7555
+ for (const argument of parameters) {
7556
+ if (!argument.included) {
7865
7557
  argument.include(context, false);
7866
7558
  }
7867
7559
  }
7868
7560
  }
7869
7561
  }
7870
- addArgumentToBeDeoptimized(argument) {
7871
- this.argumentsVariable.addArgumentToBeDeoptimized(argument);
7872
- }
7873
7562
  }
7874
7563
 
7875
7564
  class ExpressionStatement extends NodeBase {
@@ -7897,9 +7586,8 @@ class ExpressionStatement extends NodeBase {
7897
7586
  return this.parent.type !== parseAst_js.Program;
7898
7587
  return super.shouldBeIncluded(context);
7899
7588
  }
7589
+ applyDeoptimizations() { }
7900
7590
  }
7901
- ExpressionStatement.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
7902
- ExpressionStatement.prototype.applyDeoptimizations = doNotDeoptimize;
7903
7591
 
7904
7592
  class BlockStatement extends NodeBase {
7905
7593
  get deoptimizeBody() {
@@ -7964,8 +7652,6 @@ class BlockStatement extends NodeBase {
7964
7652
  }
7965
7653
  }
7966
7654
  }
7967
- BlockStatement.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
7968
- BlockStatement.prototype.applyDeoptimizations = doNotDeoptimize;
7969
7655
 
7970
7656
  class RestElement extends NodeBase {
7971
7657
  constructor() {
@@ -7975,12 +7661,9 @@ class RestElement extends NodeBase {
7975
7661
  addExportedVariables(variables, exportNamesByVariable) {
7976
7662
  this.argument.addExportedVariables(variables, exportNamesByVariable);
7977
7663
  }
7978
- declare(kind, destructuredInitPath, init) {
7664
+ declare(kind, init) {
7979
7665
  this.declarationInit = init;
7980
- return this.argument.declare(kind, getIncludedPatternPath$1(destructuredInitPath), init);
7981
- }
7982
- deoptimizeAssignment(destructuredInitPath, init) {
7983
- this.argument.deoptimizeAssignment(getIncludedPatternPath$1(destructuredInitPath), init);
7666
+ return this.argument.declare(kind, UNKNOWN_EXPRESSION);
7984
7667
  }
7985
7668
  deoptimizePath(path) {
7986
7669
  if (path.length === 0) {
@@ -7991,20 +7674,6 @@ class RestElement extends NodeBase {
7991
7674
  return (path.length > 0 ||
7992
7675
  this.argument.hasEffectsOnInteractionAtPath(EMPTY_PATH, interaction, context));
7993
7676
  }
7994
- hasEffectsWhenDestructuring(context, destructuredInitPath, init) {
7995
- return this.argument.hasEffectsWhenDestructuring(context, getIncludedPatternPath$1(destructuredInitPath), init);
7996
- }
7997
- includeDestructuredIfNecessary(context, destructuredInitPath, init) {
7998
- return (this.included =
7999
- this.argument.includeDestructuredIfNecessary(context, getIncludedPatternPath$1(destructuredInitPath), init) || this.included);
8000
- }
8001
- include(context, includeChildrenRecursively) {
8002
- if (!this.included)
8003
- this.includeNode(context);
8004
- // This should just include the identifier, its properties should be
8005
- // included where the variable is used.
8006
- this.argument.include(context, includeChildrenRecursively);
8007
- }
8008
7677
  markDeclarationReached() {
8009
7678
  this.argument.markDeclarationReached();
8010
7679
  }
@@ -8016,16 +7685,12 @@ class RestElement extends NodeBase {
8016
7685
  }
8017
7686
  }
8018
7687
  }
8019
- RestElement.prototype.includeNode = onlyIncludeSelf;
8020
- const getIncludedPatternPath$1 = (destructuredInitPath) => destructuredInitPath.at(-1) === UnknownKey
8021
- ? destructuredInitPath
8022
- : [...destructuredInitPath, UnknownKey];
8023
7688
 
8024
7689
  class FunctionBase extends NodeBase {
8025
7690
  constructor() {
8026
7691
  super(...arguments);
7692
+ this.objectEntity = null;
8027
7693
  this.parameterVariableValuesDeoptimized = false;
8028
- this.includeCallArguments = this.scope.includeCallArguments.bind(this.scope);
8029
7694
  }
8030
7695
  get async() {
8031
7696
  return isFlagSet(this.flags, 256 /* Flag.async */);
@@ -8045,9 +7710,53 @@ class FunctionBase extends NodeBase {
8045
7710
  set generator(value) {
8046
7711
  this.flags = setFlag(this.flags, 4194304 /* Flag.generator */, value);
8047
7712
  }
7713
+ updateParameterVariableValues(_arguments) {
7714
+ for (let position = 0; position < this.params.length; position++) {
7715
+ const parameter = this.params[position];
7716
+ if (!(parameter instanceof Identifier)) {
7717
+ continue;
7718
+ }
7719
+ const parameterVariable = parameter.variable;
7720
+ const argument = _arguments[position + 1] ?? UNDEFINED_EXPRESSION;
7721
+ parameterVariable.updateKnownValue(argument);
7722
+ }
7723
+ }
7724
+ deoptimizeParameterVariableValues() {
7725
+ for (const parameter of this.params) {
7726
+ if (parameter instanceof Identifier) {
7727
+ const parameterVariable = parameter.variable;
7728
+ parameterVariable.markReassigned();
7729
+ }
7730
+ }
7731
+ }
8048
7732
  deoptimizeArgumentsOnInteractionAtPath(interaction, path, recursionTracker) {
8049
- if (interaction.type === INTERACTION_CALLED && path.length === 0) {
8050
- this.scope.deoptimizeArgumentsOnCall(interaction);
7733
+ if (interaction.type === INTERACTION_CALLED) {
7734
+ const { parameters } = this.scope;
7735
+ const { args } = interaction;
7736
+ let hasRest = false;
7737
+ for (let position = 0; position < args.length - 1; position++) {
7738
+ const parameter = this.params[position];
7739
+ // Only the "this" argument arg[0] can be null
7740
+ const argument = args[position + 1];
7741
+ if (argument instanceof SpreadElement) {
7742
+ this.deoptimizeParameterVariableValues();
7743
+ }
7744
+ if (hasRest || parameter instanceof RestElement) {
7745
+ hasRest = true;
7746
+ argument.deoptimizePath(UNKNOWN_PATH);
7747
+ }
7748
+ else if (parameter instanceof Identifier) {
7749
+ parameters[position][0].addEntityToBeDeoptimized(argument);
7750
+ this.addArgumentToBeDeoptimized(argument);
7751
+ }
7752
+ else if (parameter) {
7753
+ argument.deoptimizePath(UNKNOWN_PATH);
7754
+ }
7755
+ else {
7756
+ this.addArgumentToBeDeoptimized(argument);
7757
+ }
7758
+ }
7759
+ this.updateParameterVariableValues(args);
8051
7760
  }
8052
7761
  else {
8053
7762
  this.getObjectEntity().deoptimizeArgumentsOnInteractionAtPath(interaction, path, recursionTracker);
@@ -8059,7 +7768,12 @@ class FunctionBase extends NodeBase {
8059
7768
  // A reassignment of UNKNOWN_PATH is considered equivalent to having lost track
8060
7769
  // which means the return expression and parameters need to be reassigned
8061
7770
  this.scope.getReturnExpression().deoptimizePath(UNKNOWN_PATH);
8062
- this.scope.deoptimizeAllParameters();
7771
+ for (const parameterList of this.scope.parameters) {
7772
+ for (const parameter of parameterList) {
7773
+ parameter.deoptimizePath(UNKNOWN_PATH);
7774
+ parameter.markReassigned();
7775
+ }
7776
+ }
8063
7777
  }
8064
7778
  }
8065
7779
  getLiteralValueAtPath(path, recursionTracker, origin) {
@@ -8097,13 +7811,8 @@ class FunctionBase extends NodeBase {
8097
7811
  return true;
8098
7812
  }
8099
7813
  }
8100
- const { propertyReadSideEffects } = this.scope.context.options
8101
- .treeshake;
8102
- for (let index = 0; index < this.params.length; index++) {
8103
- const parameter = this.params[index];
8104
- if (parameter.hasEffects(context) ||
8105
- (propertyReadSideEffects &&
8106
- parameter.hasEffectsWhenDestructuring(context, EMPTY_PATH, interaction.args[index + 1] || UNDEFINED_EXPRESSION)))
7814
+ for (const parameter of this.params) {
7815
+ if (parameter.hasEffects(context))
8107
7816
  return true;
8108
7817
  }
8109
7818
  return false;
@@ -8122,17 +7831,21 @@ class FunctionBase extends NodeBase {
8122
7831
  return variable?.getOnlyFunctionCallUsed() ?? false;
8123
7832
  }
8124
7833
  include(context, includeChildrenRecursively) {
8125
- if (!this.included)
8126
- this.includeNode(context);
8127
- if (!(this.parameterVariableValuesDeoptimized || this.onlyFunctionCallUsed())) {
7834
+ if (!this.parameterVariableValuesDeoptimized && !this.onlyFunctionCallUsed()) {
8128
7835
  this.parameterVariableValuesDeoptimized = true;
8129
- this.scope.reassignAllParameters();
7836
+ this.deoptimizeParameterVariableValues();
8130
7837
  }
7838
+ if (!this.deoptimized)
7839
+ this.applyDeoptimizations();
7840
+ this.included = true;
8131
7841
  const { brokenFlow } = context;
8132
7842
  context.brokenFlow = false;
8133
7843
  this.body.include(context, includeChildrenRecursively);
8134
7844
  context.brokenFlow = brokenFlow;
8135
7845
  }
7846
+ includeCallArguments(context, parameters) {
7847
+ this.scope.includeCallArguments(context, parameters);
7848
+ }
8136
7849
  initialise() {
8137
7850
  super.initialise();
8138
7851
  if (this.body instanceof BlockStatement) {
@@ -8154,14 +7867,14 @@ class FunctionBase extends NodeBase {
8154
7867
  // so that the scope already knows all parameters and can detect conflicts
8155
7868
  // when parsing the body.
8156
7869
  const parameters = (this.params = params.map((parameter) => new (context.getNodeConstructor(parameter.type))(this, scope).parseNode(parameter)));
8157
- scope.addParameterVariables(parameters.map(parameter => parameter.declare('parameter', EMPTY_PATH, UNKNOWN_EXPRESSION)), parameters[parameters.length - 1] instanceof RestElement);
7870
+ scope.addParameterVariables(parameters.map(parameter => parameter.declare('parameter', UNKNOWN_EXPRESSION)), parameters[parameters.length - 1] instanceof RestElement);
8158
7871
  this.body = new (context.getNodeConstructor(body.type))(this, bodyScope).parseNode(body);
8159
7872
  return super.parseNode(esTreeNode);
8160
7873
  }
7874
+ addArgumentToBeDeoptimized(_argument) { }
7875
+ applyDeoptimizations() { }
8161
7876
  }
8162
7877
  FunctionBase.prototype.preventChildBlockScope = true;
8163
- FunctionBase.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
8164
- FunctionBase.prototype.applyDeoptimizations = doNotDeoptimize;
8165
7878
 
8166
7879
  class FunctionNode extends FunctionBase {
8167
7880
  constructor() {
@@ -8173,16 +7886,18 @@ class FunctionNode extends FunctionBase {
8173
7886
  this.constructedEntity = new ObjectEntity(Object.create(null), OBJECT_PROTOTYPE);
8174
7887
  // This makes sure that all deoptimizations of "this" are applied to the
8175
7888
  // constructed entity.
8176
- this.scope.thisVariable.addArgumentValue(this.constructedEntity);
7889
+ this.scope.thisVariable.addEntityToBeDeoptimized(this.constructedEntity);
8177
7890
  }
8178
7891
  deoptimizeArgumentsOnInteractionAtPath(interaction, path, recursionTracker) {
8179
7892
  super.deoptimizeArgumentsOnInteractionAtPath(interaction, path, recursionTracker);
8180
7893
  if (interaction.type === INTERACTION_CALLED && path.length === 0 && interaction.args[0]) {
8181
7894
  // args[0] is the "this" argument
8182
- this.scope.thisVariable.addArgumentValue(interaction.args[0]);
7895
+ this.scope.thisVariable.addEntityToBeDeoptimized(interaction.args[0]);
8183
7896
  }
8184
7897
  }
8185
7898
  hasEffects(context) {
7899
+ if (!this.deoptimized)
7900
+ this.applyDeoptimizations();
8186
7901
  if (this.annotationNoSideEffects) {
8187
7902
  return false;
8188
7903
  }
@@ -8220,7 +7935,7 @@ class FunctionNode extends FunctionBase {
8220
7935
  }
8221
7936
  include(context, includeChildrenRecursively) {
8222
7937
  super.include(context, includeChildrenRecursively);
8223
- this.id?.include(context);
7938
+ this.id?.include();
8224
7939
  const hasArguments = this.scope.argumentsVariable.included;
8225
7940
  for (const parameter of this.params) {
8226
7941
  if (!(parameter instanceof Identifier) || hasArguments) {
@@ -8228,18 +7943,12 @@ class FunctionNode extends FunctionBase {
8228
7943
  }
8229
7944
  }
8230
7945
  }
8231
- includeNode(context) {
8232
- this.included = true;
8233
- const hasArguments = this.scope.argumentsVariable.included;
8234
- for (const parameter of this.params) {
8235
- if (!(parameter instanceof Identifier) || hasArguments) {
8236
- parameter.includePath(UNKNOWN_PATH, context);
8237
- }
8238
- }
8239
- }
8240
7946
  initialise() {
8241
7947
  super.initialise();
8242
- this.id?.declare('function', EMPTY_PATH, this);
7948
+ this.id?.declare('function', this);
7949
+ }
7950
+ addArgumentToBeDeoptimized(argument) {
7951
+ this.scope.argumentsVariable.addArgumentToBeDeoptimized(argument);
8243
7952
  }
8244
7953
  getObjectEntity() {
8245
7954
  if (this.objectEntity !== null) {
@@ -8289,16 +7998,11 @@ function getFunctionIdInsertPosition(code, start) {
8289
7998
  }
8290
7999
  class ExportDefaultDeclaration extends NodeBase {
8291
8000
  include(context, includeChildrenRecursively) {
8292
- this.included = true;
8293
- this.declaration.include(context, includeChildrenRecursively);
8001
+ super.include(context, includeChildrenRecursively);
8294
8002
  if (includeChildrenRecursively) {
8295
- this.scope.context.includeVariableInModule(this.variable, UNKNOWN_PATH, context);
8003
+ this.scope.context.includeVariableInModule(this.variable);
8296
8004
  }
8297
8005
  }
8298
- includePath(path, context) {
8299
- this.included = true;
8300
- this.declaration.includePath(path, context);
8301
- }
8302
8006
  initialise() {
8303
8007
  super.initialise();
8304
8008
  const declaration = this.declaration;
@@ -8343,6 +8047,7 @@ class ExportDefaultDeclaration extends NodeBase {
8343
8047
  }
8344
8048
  this.declaration.render(code, options);
8345
8049
  }
8050
+ applyDeoptimizations() { }
8346
8051
  renderNamedDeclaration(code, declarationStart, idInsertPosition, options) {
8347
8052
  const { exportNamesByVariable, format, snippets: { getPropertyAccess } } = options;
8348
8053
  const name = this.variable.getName(getPropertyAccess);
@@ -8373,8 +8078,6 @@ class ExportDefaultDeclaration extends NodeBase {
8373
8078
  }
8374
8079
  }
8375
8080
  ExportDefaultDeclaration.prototype.needsBoundaries = true;
8376
- ExportDefaultDeclaration.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
8377
- ExportDefaultDeclaration.prototype.applyDeoptimizations = doNotDeoptimize;
8378
8081
 
8379
8082
  const needsEscapeRegEx = /[\n\r'\\\u2028\u2029]/;
8380
8083
  const quoteNewlineRegEx = /([\n\r'\u2028\u2029])/g;
@@ -8644,7 +8347,6 @@ class Literal extends NodeBase {
8644
8347
  }
8645
8348
  }
8646
8349
  }
8647
- Literal.prototype.includeNode = onlyIncludeSelf;
8648
8350
 
8649
8351
  function getChainElementLiteralValueAtPath(element, object, path, recursionTracker, origin) {
8650
8352
  if ('getLiteralValueAtPathAsChainElement' in object) {
@@ -8660,6 +8362,8 @@ function getChainElementLiteralValueAtPath(element, object, path, recursionTrack
8660
8362
  return element.getLiteralValueAtPath(path, recursionTracker, origin);
8661
8363
  }
8662
8364
 
8365
+ // To avoid infinite recursions
8366
+ const MAX_PATH_DEPTH = 7;
8663
8367
  function getResolvablePropertyKey(memberExpression) {
8664
8368
  return memberExpression.computed
8665
8369
  ? getResolvableComputedPropertyKey(memberExpression.property)
@@ -8758,27 +8462,18 @@ class MemberExpression extends NodeBase {
8758
8462
  }
8759
8463
  else if (!this.isUndefined) {
8760
8464
  if (path.length < MAX_PATH_DEPTH) {
8761
- this.object.deoptimizeArgumentsOnInteractionAtPath(interaction, this.propertyKey === UnknownKey ? UNKNOWN_PATH : [this.propertyKey, ...path], recursionTracker);
8465
+ this.object.deoptimizeArgumentsOnInteractionAtPath(interaction, [this.getPropertyKey(), ...path], recursionTracker);
8762
8466
  }
8763
8467
  else {
8764
8468
  deoptimizeInteraction(interaction);
8765
8469
  }
8766
8470
  }
8767
8471
  }
8768
- deoptimizeAssignment(destructuredInitPath, init) {
8769
- this.deoptimizePath(EMPTY_PATH);
8770
- init.deoptimizePath([...destructuredInitPath, UnknownKey]);
8771
- }
8772
8472
  deoptimizeCache() {
8773
- if (this.propertyKey === this.dynamicPropertyKey)
8774
- return;
8775
8473
  const { expressionsToBeDeoptimized, object } = this;
8776
8474
  this.expressionsToBeDeoptimized = parseAst_js.EMPTY_ARRAY;
8777
- this.dynamicPropertyKey = this.propertyKey;
8475
+ this.propertyKey = UnknownKey;
8778
8476
  object.deoptimizePath(UNKNOWN_PATH);
8779
- if (this.included) {
8780
- object.includePath(UNKNOWN_PATH, createInclusionContext());
8781
- }
8782
8477
  for (const expression of expressionsToBeDeoptimized) {
8783
8478
  expression.deoptimizeCache();
8784
8479
  }
@@ -8789,13 +8484,11 @@ class MemberExpression extends NodeBase {
8789
8484
  if (this.variable) {
8790
8485
  this.variable.deoptimizePath(path);
8791
8486
  }
8792
- else if (!this.isUndefined) {
8793
- const { propertyKey } = this;
8487
+ else if (!this.isUndefined && path.length < MAX_PATH_DEPTH) {
8488
+ const propertyKey = this.getPropertyKey();
8794
8489
  this.object.deoptimizePath([
8795
8490
  propertyKey === UnknownKey ? UnknownNonAccessorKey : propertyKey,
8796
- ...(path.length < MAX_PATH_DEPTH
8797
- ? path
8798
- : [...path.slice(0, MAX_PATH_DEPTH), UnknownKey])
8491
+ ...path
8799
8492
  ]);
8800
8493
  }
8801
8494
  }
@@ -8806,11 +8499,9 @@ class MemberExpression extends NodeBase {
8806
8499
  if (this.isUndefined) {
8807
8500
  return undefined;
8808
8501
  }
8809
- const propertyKey = this.getDynamicPropertyKey();
8810
- if (propertyKey !== UnknownKey && path.length < MAX_PATH_DEPTH) {
8811
- if (propertyKey !== this.propertyKey)
8812
- this.expressionsToBeDeoptimized.push(origin);
8813
- return this.object.getLiteralValueAtPath([propertyKey, ...path], recursionTracker, origin);
8502
+ if (this.propertyKey !== UnknownKey && path.length < MAX_PATH_DEPTH) {
8503
+ this.expressionsToBeDeoptimized.push(origin);
8504
+ return this.object.getLiteralValueAtPath([this.getPropertyKey(), ...path], recursionTracker, origin);
8814
8505
  }
8815
8506
  return UnknownValue;
8816
8507
  }
@@ -8830,11 +8521,9 @@ class MemberExpression extends NodeBase {
8830
8521
  if (this.isUndefined) {
8831
8522
  return [UNDEFINED_EXPRESSION, false];
8832
8523
  }
8833
- const propertyKey = this.getDynamicPropertyKey();
8834
- if (propertyKey !== UnknownKey && path.length < MAX_PATH_DEPTH) {
8835
- if (propertyKey !== this.propertyKey)
8836
- this.expressionsToBeDeoptimized.push(origin);
8837
- return this.object.getReturnExpressionWhenCalledAtPath([propertyKey, ...path], interaction, recursionTracker, origin);
8524
+ if (this.propertyKey !== UnknownKey && path.length < MAX_PATH_DEPTH) {
8525
+ this.expressionsToBeDeoptimized.push(origin);
8526
+ return this.object.getReturnExpressionWhenCalledAtPath([this.getPropertyKey(), ...path], interaction, recursionTracker, origin);
8838
8527
  }
8839
8528
  return UNKNOWN_RETURN_EXPRESSION;
8840
8529
  }
@@ -8880,45 +8569,14 @@ class MemberExpression extends NodeBase {
8880
8569
  return true;
8881
8570
  }
8882
8571
  if (path.length < MAX_PATH_DEPTH) {
8883
- return this.object.hasEffectsOnInteractionAtPath([this.getDynamicPropertyKey(), ...path], interaction, context);
8572
+ return this.object.hasEffectsOnInteractionAtPath([this.getPropertyKey(), ...path], interaction, context);
8884
8573
  }
8885
8574
  return true;
8886
8575
  }
8887
- hasEffectsWhenDestructuring(context, destructuredInitPath, init) {
8888
- return (destructuredInitPath.length > 0 &&
8889
- init.hasEffectsOnInteractionAtPath(destructuredInitPath, NODE_INTERACTION_UNKNOWN_ACCESS, context));
8890
- }
8891
8576
  include(context, includeChildrenRecursively) {
8892
- if (!this.included)
8893
- this.includeNode(context);
8894
- this.object.include(context, includeChildrenRecursively);
8895
- this.property.include(context, includeChildrenRecursively);
8896
- }
8897
- includeNode(context) {
8898
- this.included = true;
8899
8577
  if (!this.deoptimized)
8900
8578
  this.applyDeoptimizations();
8901
- if (this.variable) {
8902
- this.scope.context.includeVariableInModule(this.variable, EMPTY_PATH, context);
8903
- }
8904
- else if (!this.isUndefined) {
8905
- this.object.includePath([this.propertyKey], context);
8906
- }
8907
- }
8908
- includePath(path, context) {
8909
- if (!this.included)
8910
- this.includeNode(context);
8911
- if (this.variable) {
8912
- this.variable?.includePath(path, context);
8913
- }
8914
- else if (!this.isUndefined) {
8915
- this.object.includePath([
8916
- this.propertyKey,
8917
- ...(path.length < MAX_PATH_DEPTH
8918
- ? path
8919
- : [...path.slice(0, MAX_PATH_DEPTH), UnknownKey])
8920
- ], context);
8921
- }
8579
+ this.includeProperties(context, includeChildrenRecursively);
8922
8580
  }
8923
8581
  includeAsAssignmentTarget(context, includeChildrenRecursively, deoptimizeAccess) {
8924
8582
  if (!this.assignmentDeoptimized)
@@ -8927,34 +8585,20 @@ class MemberExpression extends NodeBase {
8927
8585
  this.include(context, includeChildrenRecursively);
8928
8586
  }
8929
8587
  else {
8930
- if (!this.included)
8931
- this.includeNode(context);
8932
- this.object.include(context, includeChildrenRecursively);
8933
- this.property.include(context, includeChildrenRecursively);
8588
+ this.includeProperties(context, includeChildrenRecursively);
8934
8589
  }
8935
8590
  }
8936
- includeCallArguments(context, interaction) {
8591
+ includeCallArguments(context, parameters) {
8937
8592
  if (this.variable) {
8938
- this.variable.includeCallArguments(context, interaction);
8593
+ this.variable.includeCallArguments(context, parameters);
8939
8594
  }
8940
8595
  else {
8941
- super.includeCallArguments(context, interaction);
8942
- }
8943
- }
8944
- includeDestructuredIfNecessary(context, destructuredInitPath, init) {
8945
- if ((this.included ||=
8946
- destructuredInitPath.length > 0 &&
8947
- !context.brokenFlow &&
8948
- init.hasEffectsOnInteractionAtPath(destructuredInitPath, NODE_INTERACTION_UNKNOWN_ACCESS, createHasEffectsContext()))) {
8949
- init.include(context, false);
8950
- return true;
8596
+ super.includeCallArguments(context, parameters);
8951
8597
  }
8952
- return false;
8953
8598
  }
8954
8599
  initialise() {
8955
8600
  super.initialise();
8956
- this.dynamicPropertyKey = getResolvablePropertyKey(this);
8957
- this.propertyKey = this.dynamicPropertyKey === null ? UnknownKey : this.dynamicPropertyKey;
8601
+ this.propertyKey = getResolvablePropertyKey(this);
8958
8602
  this.accessInteraction = { args: [this.object], type: INTERACTION_ACCESSED };
8959
8603
  }
8960
8604
  render(code, options, { renderedParentType, isCalleeOfRenderedParent, renderedSurroundingElement } = parseAst_js.BLANK) {
@@ -8991,7 +8635,8 @@ class MemberExpression extends NodeBase {
8991
8635
  this.bound &&
8992
8636
  propertyReadSideEffects &&
8993
8637
  !(this.variable || this.isUndefined)) {
8994
- this.object.deoptimizeArgumentsOnInteractionAtPath(this.accessInteraction, [this.propertyKey], SHARED_RECURSION_TRACKER);
8638
+ const propertyKey = this.getPropertyKey();
8639
+ this.object.deoptimizeArgumentsOnInteractionAtPath(this.accessInteraction, [propertyKey], SHARED_RECURSION_TRACKER);
8995
8640
  this.scope.context.requestTreeshakingPass();
8996
8641
  }
8997
8642
  if (this.variable) {
@@ -9008,7 +8653,7 @@ class MemberExpression extends NodeBase {
9008
8653
  this.bound &&
9009
8654
  propertyReadSideEffects &&
9010
8655
  !(this.variable || this.isUndefined)) {
9011
- this.object.deoptimizeArgumentsOnInteractionAtPath(this.assignmentInteraction, [this.propertyKey], SHARED_RECURSION_TRACKER);
8656
+ this.object.deoptimizeArgumentsOnInteractionAtPath(this.assignmentInteraction, [this.getPropertyKey()], SHARED_RECURSION_TRACKER);
9012
8657
  this.scope.context.requestTreeshakingPass();
9013
8658
  }
9014
8659
  }
@@ -9017,24 +8662,24 @@ class MemberExpression extends NodeBase {
9017
8662
  const variable = this.scope.findVariable(this.object.name);
9018
8663
  if (variable.isNamespace) {
9019
8664
  if (this.variable) {
9020
- this.scope.context.includeVariableInModule(this.variable, UNKNOWN_PATH, createInclusionContext());
8665
+ this.scope.context.includeVariableInModule(this.variable);
9021
8666
  }
9022
8667
  this.scope.context.log(parseAst_js.LOGLEVEL_WARN, parseAst_js.logIllegalImportReassignment(this.object.name, this.scope.context.module.id), this.start);
9023
8668
  }
9024
8669
  }
9025
8670
  }
9026
- getDynamicPropertyKey() {
9027
- if (this.dynamicPropertyKey === null) {
9028
- this.dynamicPropertyKey = this.propertyKey;
8671
+ getPropertyKey() {
8672
+ if (this.propertyKey === null) {
8673
+ this.propertyKey = UnknownKey;
9029
8674
  const value = this.property.getLiteralValueAtPath(EMPTY_PATH, SHARED_RECURSION_TRACKER, this);
9030
- return (this.dynamicPropertyKey =
8675
+ return (this.propertyKey =
9031
8676
  value === SymbolToStringTag
9032
8677
  ? value
9033
8678
  : typeof value === 'symbol'
9034
8679
  ? UnknownKey
9035
8680
  : String(value));
9036
8681
  }
9037
- return this.dynamicPropertyKey;
8682
+ return this.propertyKey;
9038
8683
  }
9039
8684
  hasAccessEffect(context) {
9040
8685
  const { propertyReadSideEffects } = this.scope.context.options
@@ -9042,7 +8687,17 @@ class MemberExpression extends NodeBase {
9042
8687
  return (!(this.variable || this.isUndefined) &&
9043
8688
  propertyReadSideEffects &&
9044
8689
  (propertyReadSideEffects === 'always' ||
9045
- this.object.hasEffectsOnInteractionAtPath([this.getDynamicPropertyKey()], this.accessInteraction, context)));
8690
+ this.object.hasEffectsOnInteractionAtPath([this.getPropertyKey()], this.accessInteraction, context)));
8691
+ }
8692
+ includeProperties(context, includeChildrenRecursively) {
8693
+ if (!this.included) {
8694
+ this.included = true;
8695
+ if (this.variable) {
8696
+ this.scope.context.includeVariableInModule(this.variable);
8697
+ }
8698
+ }
8699
+ this.object.include(context, includeChildrenRecursively);
8700
+ this.property.include(context, includeChildrenRecursively);
9046
8701
  }
9047
8702
  }
9048
8703
  function resolveNamespaceVariables(baseVariable, path, astContext) {
@@ -9086,20 +8741,18 @@ class MetaProperty extends NodeBase {
9086
8741
  return path.length > 1 || type !== INTERACTION_ACCESSED;
9087
8742
  }
9088
8743
  include() {
9089
- if (!this.included)
9090
- this.includeNode();
9091
- }
9092
- includeNode() {
9093
- this.included = true;
9094
- if (this.meta.name === IMPORT) {
9095
- this.scope.context.addImportMeta(this);
9096
- const parent = this.parent;
9097
- const metaProperty = (this.metaProperty =
9098
- parent instanceof MemberExpression && typeof parent.propertyKey === 'string'
9099
- ? parent.propertyKey
9100
- : null);
9101
- if (metaProperty?.startsWith(FILE_PREFIX)) {
9102
- this.referenceId = metaProperty.slice(FILE_PREFIX.length);
8744
+ if (!this.included) {
8745
+ this.included = true;
8746
+ if (this.meta.name === IMPORT) {
8747
+ this.scope.context.addImportMeta(this);
8748
+ const parent = this.parent;
8749
+ const metaProperty = (this.metaProperty =
8750
+ parent instanceof MemberExpression && typeof parent.propertyKey === 'string'
8751
+ ? parent.propertyKey
8752
+ : null);
8753
+ if (metaProperty?.startsWith(FILE_PREFIX)) {
8754
+ this.referenceId = metaProperty.slice(FILE_PREFIX.length);
8755
+ }
9103
8756
  }
9104
8757
  }
9105
8758
  }
@@ -9206,7 +8859,7 @@ class UndefinedVariable extends Variable {
9206
8859
 
9207
8860
  class ExportDefaultVariable extends LocalVariable {
9208
8861
  constructor(name, exportDefaultDeclaration, context) {
9209
- super(name, exportDefaultDeclaration, exportDefaultDeclaration.declaration, EMPTY_PATH, context, 'other');
8862
+ super(name, exportDefaultDeclaration, exportDefaultDeclaration.declaration, context, 'other');
9210
8863
  this.hasId = false;
9211
8864
  this.originalId = null;
9212
8865
  this.originalVariable = null;
@@ -9355,8 +9008,8 @@ class NamespaceVariable extends Variable {
9355
9008
  return (!memberVariable ||
9356
9009
  memberVariable.hasEffectsOnInteractionAtPath(path.slice(1), interaction, context));
9357
9010
  }
9358
- includePath(path, context) {
9359
- super.includePath(path, context);
9011
+ include() {
9012
+ super.include();
9360
9013
  this.context.includeAllExports();
9361
9014
  }
9362
9015
  prepare(accessedGlobalsByScope) {
@@ -9449,9 +9102,9 @@ class SyntheticNamedExportVariable extends Variable {
9449
9102
  getName(getPropertyAccess) {
9450
9103
  return `${this.syntheticNamespace.getName(getPropertyAccess)}${getPropertyAccess(this.name)}`;
9451
9104
  }
9452
- includePath(path, context) {
9453
- super.includePath(path, context);
9454
- this.context.includeVariableInModule(this.syntheticNamespace, path, context);
9105
+ include() {
9106
+ super.include();
9107
+ this.context.includeVariableInModule(this.syntheticNamespace);
9455
9108
  }
9456
9109
  setRenderNames(baseName, name) {
9457
9110
  super.setRenderNames(baseName, name);
@@ -9482,7 +9135,7 @@ class ExternalChunk {
9482
9135
  (this.renormalizeRenderPath ? parseAst_js.normalize(path.relative(this.inputBase, this.id)) : this.id));
9483
9136
  }
9484
9137
  getImportAttributes(snippets) {
9485
- return (this.importAttributes ||= formatAttributes(this.options.format === 'es' &&
9138
+ return (this.importAttributes ||= formatAttributes(['es', 'cjs'].includes(this.options.format) &&
9486
9139
  this.options.externalImportAttributes &&
9487
9140
  this.moduleInfo.attributes, snippets));
9488
9141
  }
@@ -10374,35 +10027,6 @@ function umd(magicString, { accessedGlobals, dependencies, exports, hasDefaultEx
10374
10027
 
10375
10028
  const finalisers = { amd, cjs, es, iife, system, umd };
10376
10029
 
10377
- function getDefaultExportFromCjs (x) {
10378
- return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
10379
- }
10380
-
10381
- function getAugmentedNamespace(n) {
10382
- if (n.__esModule) return n;
10383
- var f = n.default;
10384
- if (typeof f == "function") {
10385
- var a = function a () {
10386
- if (this instanceof a) {
10387
- return Reflect.construct(f, arguments, this.constructor);
10388
- }
10389
- return f.apply(this, arguments);
10390
- };
10391
- a.prototype = f.prototype;
10392
- } else a = {};
10393
- Object.defineProperty(a, '__esModule', {value: true});
10394
- Object.keys(n).forEach(function (k) {
10395
- var d = Object.getOwnPropertyDescriptor(n, k);
10396
- Object.defineProperty(a, k, d.get ? d : {
10397
- enumerable: true,
10398
- get: function () {
10399
- return n[k];
10400
- }
10401
- });
10402
- });
10403
- return a;
10404
- }
10405
-
10406
10030
  var utils = {};
10407
10031
 
10408
10032
  var constants;
@@ -11941,7 +11565,7 @@ function requireParse () {
11941
11565
  }
11942
11566
 
11943
11567
  if (prior.type === 'slash' && prior.prev.type !== 'bos' && rest[0] === '/') {
11944
- const end = rest[1] !== void 0 ? '|$' : '';
11568
+ const end = rest[1] !== undefined ? '|$' : '';
11945
11569
 
11946
11570
  state.output = state.output.slice(0, -(prior.output + prev.output).length);
11947
11571
  prior.output = `(?:${prior.output}`;
@@ -12656,37 +12280,21 @@ class ArrayPattern extends NodeBase {
12656
12280
  element?.addExportedVariables(variables, exportNamesByVariable);
12657
12281
  }
12658
12282
  }
12659
- declare(kind, destructuredInitPath, init) {
12283
+ declare(kind) {
12660
12284
  const variables = [];
12661
- const includedPatternPath = getIncludedPatternPath(destructuredInitPath);
12662
12285
  for (const element of this.elements) {
12663
12286
  if (element !== null) {
12664
- variables.push(...element.declare(kind, includedPatternPath, init));
12287
+ variables.push(...element.declare(kind, UNKNOWN_EXPRESSION));
12665
12288
  }
12666
12289
  }
12667
12290
  return variables;
12668
12291
  }
12669
- deoptimizeAssignment(destructuredInitPath, init) {
12670
- const includedPatternPath = getIncludedPatternPath(destructuredInitPath);
12671
- for (const element of this.elements) {
12672
- element?.deoptimizeAssignment(includedPatternPath, init);
12673
- }
12674
- }
12675
12292
  // Patterns can only be deoptimized at the empty path at the moment
12676
12293
  deoptimizePath() {
12677
12294
  for (const element of this.elements) {
12678
12295
  element?.deoptimizePath(EMPTY_PATH);
12679
12296
  }
12680
12297
  }
12681
- hasEffectsWhenDestructuring(context, destructuredInitPath, init) {
12682
- const includedPatternPath = getIncludedPatternPath(destructuredInitPath);
12683
- for (const element of this.elements) {
12684
- if (element?.hasEffectsWhenDestructuring(context, includedPatternPath, init)) {
12685
- return true;
12686
- }
12687
- }
12688
- return false;
12689
- }
12690
12298
  // Patterns are only checked at the empty path at the moment
12691
12299
  hasEffectsOnInteractionAtPath(_path, interaction, context) {
12692
12300
  for (const element of this.elements) {
@@ -12695,38 +12303,12 @@ class ArrayPattern extends NodeBase {
12695
12303
  }
12696
12304
  return false;
12697
12305
  }
12698
- includeDestructuredIfNecessary(context, destructuredInitPath, init) {
12699
- let included = false;
12700
- const includedPatternPath = getIncludedPatternPath(destructuredInitPath);
12701
- for (const element of this.elements) {
12702
- if (element) {
12703
- element.included ||= included;
12704
- included =
12705
- element.includeDestructuredIfNecessary(context, includedPatternPath, init) || included;
12706
- }
12707
- }
12708
- if (included) {
12709
- // This is necessary so that if any pattern element is included, all are
12710
- // included for proper deconflicting
12711
- for (const element of this.elements) {
12712
- if (element && !element.included) {
12713
- element.included = true;
12714
- element.includeDestructuredIfNecessary(context, includedPatternPath, init);
12715
- }
12716
- }
12717
- }
12718
- return (this.included ||= included);
12719
- }
12720
12306
  markDeclarationReached() {
12721
12307
  for (const element of this.elements) {
12722
12308
  element?.markDeclarationReached();
12723
12309
  }
12724
12310
  }
12725
12311
  }
12726
- ArrayPattern.prototype.includeNode = onlyIncludeSelf;
12727
- const getIncludedPatternPath = (destructuredInitPath) => destructuredInitPath.at(-1) === UnknownKey
12728
- ? destructuredInitPath
12729
- : [...destructuredInitPath, UnknownInteger];
12730
12312
 
12731
12313
  class ArrowFunctionExpression extends FunctionBase {
12732
12314
  constructor() {
@@ -12743,6 +12325,8 @@ class ArrowFunctionExpression extends FunctionBase {
12743
12325
  this.scope = new ReturnValueScope(parentScope, false);
12744
12326
  }
12745
12327
  hasEffects() {
12328
+ if (!this.deoptimized)
12329
+ this.applyDeoptimizations();
12746
12330
  return false;
12747
12331
  }
12748
12332
  hasEffectsOnInteractionAtPath(path, interaction, context) {
@@ -12781,15 +12365,6 @@ class ArrowFunctionExpression extends FunctionBase {
12781
12365
  }
12782
12366
  }
12783
12367
  }
12784
- includeNode(context) {
12785
- this.included = true;
12786
- this.body.includePath(UNKNOWN_PATH, context);
12787
- for (const parameter of this.params) {
12788
- if (!(parameter instanceof Identifier)) {
12789
- parameter.includePath(UNKNOWN_PATH, context);
12790
- }
12791
- }
12792
- }
12793
12368
  getObjectEntity() {
12794
12369
  if (this.objectEntity !== null) {
12795
12370
  return this.objectEntity;
@@ -12809,18 +12384,13 @@ class ObjectPattern extends NodeBase {
12809
12384
  }
12810
12385
  }
12811
12386
  }
12812
- declare(kind, destructuredInitPath, init) {
12387
+ declare(kind, init) {
12813
12388
  const variables = [];
12814
12389
  for (const property of this.properties) {
12815
- variables.push(...property.declare(kind, destructuredInitPath, init));
12390
+ variables.push(...property.declare(kind, init));
12816
12391
  }
12817
12392
  return variables;
12818
12393
  }
12819
- deoptimizeAssignment(destructuredInitPath, init) {
12820
- for (const property of this.properties) {
12821
- property.deoptimizeAssignment(destructuredInitPath, init);
12822
- }
12823
- }
12824
12394
  deoptimizePath(path) {
12825
12395
  if (path.length === 0) {
12826
12396
  for (const property of this.properties) {
@@ -12838,46 +12408,12 @@ class ObjectPattern extends NodeBase {
12838
12408
  }
12839
12409
  return false;
12840
12410
  }
12841
- hasEffectsWhenDestructuring(context, destructuredInitPath, init) {
12842
- for (const property of this.properties) {
12843
- if (property.hasEffectsWhenDestructuring(context, destructuredInitPath, init))
12844
- return true;
12845
- }
12846
- return false;
12847
- }
12848
- includeDestructuredIfNecessary(context, destructuredInitPath, init) {
12849
- let included = false;
12850
- for (const property of this.properties) {
12851
- included =
12852
- property.includeDestructuredIfNecessary(context, destructuredInitPath, init) || included;
12853
- }
12854
- return (this.included ||= included);
12855
- }
12856
12411
  markDeclarationReached() {
12857
12412
  for (const property of this.properties) {
12858
12413
  property.markDeclarationReached();
12859
12414
  }
12860
12415
  }
12861
- render(code, options) {
12862
- if (this.properties.length > 0) {
12863
- const separatedNodes = getCommaSeparatedNodesWithBoundaries(this.properties, code, this.start + 1, this.end - 1);
12864
- let lastSeparatorPos = null;
12865
- for (const { node, separator, start, end } of separatedNodes) {
12866
- if (!node.included) {
12867
- treeshakeNode(node, code, start, end);
12868
- continue;
12869
- }
12870
- lastSeparatorPos = separator;
12871
- node.render(code, options);
12872
- }
12873
- if (lastSeparatorPos) {
12874
- code.remove(lastSeparatorPos, this.end - 1);
12875
- }
12876
- }
12877
- }
12878
12416
  }
12879
- ObjectPattern.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
12880
- ObjectPattern.prototype.applyDeoptimizations = doNotDeoptimize;
12881
12417
 
12882
12418
  class AssignmentExpression extends NodeBase {
12883
12419
  hasEffects(context) {
@@ -12886,9 +12422,7 @@ class AssignmentExpression extends NodeBase {
12886
12422
  this.applyDeoptimizations();
12887
12423
  // MemberExpressions do not access the property before assignments if the
12888
12424
  // operator is '='.
12889
- return (right.hasEffects(context) ||
12890
- left.hasEffectsAsAssignmentTarget(context, operator !== '=') ||
12891
- this.left.hasEffectsWhenDestructuring?.(context, EMPTY_PATH, right));
12425
+ return (right.hasEffects(context) || left.hasEffectsAsAssignmentTarget(context, operator !== '='));
12892
12426
  }
12893
12427
  hasEffectsOnInteractionAtPath(path, interaction, context) {
12894
12428
  return this.right.hasEffectsOnInteractionAtPath(path, interaction, context);
@@ -12897,24 +12431,15 @@ class AssignmentExpression extends NodeBase {
12897
12431
  const { deoptimized, left, right, operator } = this;
12898
12432
  if (!deoptimized)
12899
12433
  this.applyDeoptimizations();
12900
- if (!this.included)
12901
- this.includeNode(context);
12902
- const hasEffectsContext = createHasEffectsContext();
12434
+ this.included = true;
12903
12435
  if (includeChildrenRecursively ||
12904
12436
  operator !== '=' ||
12905
12437
  left.included ||
12906
- left.hasEffectsAsAssignmentTarget(hasEffectsContext, false) ||
12907
- left.hasEffectsWhenDestructuring?.(hasEffectsContext, EMPTY_PATH, right)) {
12438
+ left.hasEffectsAsAssignmentTarget(createHasEffectsContext(), false)) {
12908
12439
  left.includeAsAssignmentTarget(context, includeChildrenRecursively, operator !== '=');
12909
12440
  }
12910
12441
  right.include(context, includeChildrenRecursively);
12911
12442
  }
12912
- includeNode(context) {
12913
- this.included = true;
12914
- if (!this.deoptimized)
12915
- this.applyDeoptimizations();
12916
- this.right.includePath(UNKNOWN_PATH, context);
12917
- }
12918
12443
  initialise() {
12919
12444
  super.initialise();
12920
12445
  if (this.left instanceof Identifier) {
@@ -12975,7 +12500,8 @@ class AssignmentExpression extends NodeBase {
12975
12500
  }
12976
12501
  applyDeoptimizations() {
12977
12502
  this.deoptimized = true;
12978
- this.left.deoptimizeAssignment(EMPTY_PATH, this.right);
12503
+ this.left.deoptimizePath(EMPTY_PATH);
12504
+ this.right.deoptimizePath(UNKNOWN_PATH);
12979
12505
  this.scope.context.requestTreeshakingPass();
12980
12506
  }
12981
12507
  }
@@ -12984,11 +12510,8 @@ class AssignmentPattern extends NodeBase {
12984
12510
  addExportedVariables(variables, exportNamesByVariable) {
12985
12511
  this.left.addExportedVariables(variables, exportNamesByVariable);
12986
12512
  }
12987
- declare(kind, destructuredInitPath, init) {
12988
- return this.left.declare(kind, destructuredInitPath, init);
12989
- }
12990
- deoptimizeAssignment(destructuredInitPath, init) {
12991
- this.left.deoptimizeAssignment(destructuredInitPath, init);
12513
+ declare(kind, init) {
12514
+ return this.left.declare(kind, init);
12992
12515
  }
12993
12516
  deoptimizePath(path) {
12994
12517
  if (path.length === 0) {
@@ -12998,29 +12521,6 @@ class AssignmentPattern extends NodeBase {
12998
12521
  hasEffectsOnInteractionAtPath(path, interaction, context) {
12999
12522
  return (path.length > 0 || this.left.hasEffectsOnInteractionAtPath(EMPTY_PATH, interaction, context));
13000
12523
  }
13001
- hasEffectsWhenDestructuring(context, destructuredInitPath, init) {
13002
- return this.left.hasEffectsWhenDestructuring(context, destructuredInitPath, init);
13003
- }
13004
- includeDestructuredIfNecessary(context, destructuredInitPath, init) {
13005
- let included = this.left.includeDestructuredIfNecessary(context, destructuredInitPath, init) ||
13006
- this.included;
13007
- if ((included ||= this.right.shouldBeIncluded(context))) {
13008
- this.right.include(context, false);
13009
- if (!this.left.included) {
13010
- this.left.included = true;
13011
- // Unfortunately, we need to include the left side again now, so that
13012
- // any declared variables are properly included.
13013
- this.left.includeDestructuredIfNecessary(context, destructuredInitPath, init);
13014
- }
13015
- }
13016
- return (this.included = included);
13017
- }
13018
- includeNode(context) {
13019
- this.included = true;
13020
- if (!this.deoptimized)
13021
- this.applyDeoptimizations();
13022
- this.right.includePath(UNKNOWN_PATH, context);
13023
- }
13024
12524
  markDeclarationReached() {
13025
12525
  this.left.markDeclarationReached();
13026
12526
  }
@@ -13043,34 +12543,22 @@ class AwaitExpression extends NodeBase {
13043
12543
  return true;
13044
12544
  }
13045
12545
  include(context, includeChildrenRecursively) {
13046
- if (!this.included)
13047
- this.includeNode(context);
13048
- this.argument.include(context, includeChildrenRecursively);
13049
- }
13050
- includeNode(context) {
13051
- this.included = true;
13052
12546
  if (!this.deoptimized)
13053
12547
  this.applyDeoptimizations();
13054
- checkTopLevelAwait: if (!this.scope.context.usesTopLevelAwait) {
13055
- let parent = this.parent;
13056
- do {
13057
- if (parent instanceof FunctionNode || parent instanceof ArrowFunctionExpression)
13058
- break checkTopLevelAwait;
13059
- } while ((parent = parent.parent));
13060
- this.scope.context.usesTopLevelAwait = true;
12548
+ if (!this.included) {
12549
+ this.included = true;
12550
+ checkTopLevelAwait: if (!this.scope.context.usesTopLevelAwait) {
12551
+ let parent = this.parent;
12552
+ do {
12553
+ if (parent instanceof FunctionNode || parent instanceof ArrowFunctionExpression)
12554
+ break checkTopLevelAwait;
12555
+ } while ((parent = parent.parent));
12556
+ this.scope.context.usesTopLevelAwait = true;
12557
+ }
13061
12558
  }
13062
- // Thenables need to be included
13063
- this.argument.includePath(THEN_PATH, context);
13064
- }
13065
- includePath(path, context) {
13066
- if (!this.deoptimized)
13067
- this.applyDeoptimizations();
13068
- if (!this.included)
13069
- this.includeNode(context);
13070
- this.argument.includePath(path, context);
12559
+ this.argument.include(context, includeChildrenRecursively);
13071
12560
  }
13072
12561
  }
13073
- const THEN_PATH = ['then'];
13074
12562
 
13075
12563
  const binaryOperators = {
13076
12564
  '!=': (left, right) => left != right,
@@ -13126,12 +12614,6 @@ class BinaryExpression extends NodeBase {
13126
12614
  hasEffectsOnInteractionAtPath(path, { type }) {
13127
12615
  return type !== INTERACTION_ACCESSED || path.length > 1;
13128
12616
  }
13129
- includeNode(context) {
13130
- this.included = true;
13131
- if (this.operator === 'in') {
13132
- this.right.includePath(UNKNOWN_PATH, context);
13133
- }
13134
- }
13135
12617
  removeAnnotations(code) {
13136
12618
  this.left.removeAnnotations(code);
13137
12619
  }
@@ -13140,7 +12622,6 @@ class BinaryExpression extends NodeBase {
13140
12622
  this.right.render(code, options);
13141
12623
  }
13142
12624
  }
13143
- BinaryExpression.prototype.applyDeoptimizations = doNotDeoptimize;
13144
12625
 
13145
12626
  class BreakStatement extends NodeBase {
13146
12627
  hasEffects(context) {
@@ -13160,7 +12641,7 @@ class BreakStatement extends NodeBase {
13160
12641
  include(context) {
13161
12642
  this.included = true;
13162
12643
  if (this.label) {
13163
- this.label.include(context);
12644
+ this.label.include();
13164
12645
  context.includedLabels.add(this.label.name);
13165
12646
  }
13166
12647
  else {
@@ -13169,8 +12650,6 @@ class BreakStatement extends NodeBase {
13169
12650
  context.brokenFlow = true;
13170
12651
  }
13171
12652
  }
13172
- BreakStatement.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
13173
- BreakStatement.prototype.applyDeoptimizations = doNotDeoptimize;
13174
12653
 
13175
12654
  function renderCallArguments(code, options, node) {
13176
12655
  if (node.arguments.length > 0) {
@@ -13357,14 +12836,10 @@ class CallExpression extends CallExpressionBase {
13357
12836
  this.callee.hasEffectsOnInteractionAtPath(EMPTY_PATH, this.interaction, context)));
13358
12837
  }
13359
12838
  include(context, includeChildrenRecursively) {
13360
- if (!this.included)
13361
- this.includeNode(context);
12839
+ if (!this.deoptimized)
12840
+ this.applyDeoptimizations();
13362
12841
  if (includeChildrenRecursively) {
13363
- this.callee.include(context, true);
13364
- for (const argument of this.arguments) {
13365
- argument.includePath(UNKNOWN_PATH, context);
13366
- argument.include(context, true);
13367
- }
12842
+ super.include(context, includeChildrenRecursively);
13368
12843
  if (includeChildrenRecursively === INCLUDE_PARAMETERS &&
13369
12844
  this.callee instanceof Identifier &&
13370
12845
  this.callee.variable) {
@@ -13372,24 +12847,10 @@ class CallExpression extends CallExpressionBase {
13372
12847
  }
13373
12848
  }
13374
12849
  else {
13375
- // If the callee is a member expression and does not have a variable, its
13376
- // object will already be included via the first argument of the
13377
- // interaction in includeCallArguments. Including it again can lead to
13378
- // severe performance problems.
13379
- if (this.callee instanceof MemberExpression && !this.callee.variable) {
13380
- this.callee.property.include(context, false);
13381
- }
13382
- else {
13383
- this.callee.include(context, false);
13384
- }
13385
- this.callee.includeCallArguments(context, this.interaction);
12850
+ this.included = true;
12851
+ this.callee.include(context, false);
13386
12852
  }
13387
- }
13388
- includeNode(context) {
13389
- this.included = true;
13390
- if (!this.deoptimized)
13391
- this.applyDeoptimizations();
13392
- this.callee.includePath(UNKNOWN_PATH, context);
12853
+ this.callee.includeCallArguments(context, this.arguments);
13393
12854
  }
13394
12855
  initialise() {
13395
12856
  super.initialise();
@@ -13428,14 +12889,13 @@ class CatchClause extends NodeBase {
13428
12889
  this.type = type;
13429
12890
  if (param) {
13430
12891
  this.param = new (this.scope.context.getNodeConstructor(param.type))(this, this.scope).parseNode(param);
13431
- this.param.declare('parameter', EMPTY_PATH, UNKNOWN_EXPRESSION);
12892
+ this.param.declare('parameter', UNKNOWN_EXPRESSION);
13432
12893
  }
13433
12894
  this.body = new BlockStatement(this, this.scope.bodyScope).parseNode(body);
13434
12895
  return super.parseNode(esTreeNode);
13435
12896
  }
13436
12897
  }
13437
12898
  CatchClause.prototype.preventChildBlockScope = true;
13438
- CatchClause.prototype.includeNode = onlyIncludeSelf;
13439
12899
 
13440
12900
  class ChainExpression extends NodeBase {
13441
12901
  // deoptimizations are not relevant as we are not caching values
@@ -13447,22 +12907,17 @@ class ChainExpression extends NodeBase {
13447
12907
  hasEffects(context) {
13448
12908
  return this.expression.hasEffectsAsChainElement(context) === true;
13449
12909
  }
13450
- includePath(path, context) {
13451
- this.included = true;
13452
- this.expression.includePath(path, context);
13453
- }
13454
12910
  removeAnnotations(code) {
13455
12911
  this.expression.removeAnnotations(code);
13456
12912
  }
12913
+ applyDeoptimizations() { }
13457
12914
  }
13458
- ChainExpression.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
13459
- ChainExpression.prototype.applyDeoptimizations = doNotDeoptimize;
13460
12915
 
13461
12916
  class ClassBodyScope extends ChildScope {
13462
12917
  constructor(parent, classNode) {
13463
12918
  const { context } = parent;
13464
12919
  super(parent, context);
13465
- this.variables.set('this', (this.thisVariable = new LocalVariable('this', null, classNode, EMPTY_PATH, context, 'other')));
12920
+ this.variables.set('this', (this.thisVariable = new LocalVariable('this', null, classNode, context, 'other')));
13466
12921
  this.instanceScope = new ChildScope(this, context);
13467
12922
  this.instanceScope.variables.set('this', new ThisVariable(context));
13468
12923
  }
@@ -13477,7 +12932,7 @@ class ClassBody extends NodeBase {
13477
12932
  }
13478
12933
  include(context, includeChildrenRecursively) {
13479
12934
  this.included = true;
13480
- this.scope.context.includeVariableInModule(this.scope.thisVariable, UNKNOWN_PATH, context);
12935
+ this.scope.context.includeVariableInModule(this.scope.thisVariable);
13481
12936
  for (const definition of this.body) {
13482
12937
  definition.include(context, includeChildrenRecursively);
13483
12938
  }
@@ -13490,9 +12945,8 @@ class ClassBody extends NodeBase {
13490
12945
  }
13491
12946
  return super.parseNode(esTreeNode);
13492
12947
  }
12948
+ applyDeoptimizations() { }
13493
12949
  }
13494
- ClassBody.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
13495
- ClassBody.prototype.applyDeoptimizations = doNotDeoptimize;
13496
12950
 
13497
12951
  class ClassExpression extends ClassNode {
13498
12952
  render(code, options, { renderedSurroundingElement } = parseAst_js.BLANK) {
@@ -13563,9 +13017,6 @@ class ConditionalExpression extends NodeBase {
13563
13017
  const unusedBranch = this.usedBranch === this.consequent ? this.alternate : this.consequent;
13564
13018
  this.usedBranch = null;
13565
13019
  unusedBranch.deoptimizePath(UNKNOWN_PATH);
13566
- if (this.included) {
13567
- unusedBranch.includePath(UNKNOWN_PATH, createInclusionContext());
13568
- }
13569
13020
  const { expressionsToBeDeoptimized } = this;
13570
13021
  this.expressionsToBeDeoptimized = parseAst_js.EMPTY_ARRAY;
13571
13022
  for (const expression of expressionsToBeDeoptimized) {
@@ -13623,7 +13074,7 @@ class ConditionalExpression extends NodeBase {
13623
13074
  include(context, includeChildrenRecursively) {
13624
13075
  this.included = true;
13625
13076
  const usedBranch = this.getUsedBranch();
13626
- if (usedBranch === null || includeChildrenRecursively || this.test.shouldBeIncluded(context)) {
13077
+ if (includeChildrenRecursively || this.test.shouldBeIncluded(context) || usedBranch === null) {
13627
13078
  this.test.include(context, includeChildrenRecursively);
13628
13079
  this.consequent.include(context, includeChildrenRecursively);
13629
13080
  this.alternate.include(context, includeChildrenRecursively);
@@ -13632,38 +13083,27 @@ class ConditionalExpression extends NodeBase {
13632
13083
  usedBranch.include(context, includeChildrenRecursively);
13633
13084
  }
13634
13085
  }
13635
- includePath(path, context) {
13636
- this.included = true;
13637
- const usedBranch = this.getUsedBranch();
13638
- if (usedBranch === null || this.test.shouldBeIncluded(context)) {
13639
- this.consequent.includePath(path, context);
13640
- this.alternate.includePath(path, context);
13641
- }
13642
- else {
13643
- usedBranch.includePath(path, context);
13644
- }
13645
- }
13646
- includeCallArguments(context, interaction) {
13086
+ includeCallArguments(context, parameters) {
13647
13087
  const usedBranch = this.getUsedBranch();
13648
13088
  if (usedBranch) {
13649
- usedBranch.includeCallArguments(context, interaction);
13089
+ usedBranch.includeCallArguments(context, parameters);
13650
13090
  }
13651
13091
  else {
13652
- this.consequent.includeCallArguments(context, interaction);
13653
- this.alternate.includeCallArguments(context, interaction);
13092
+ this.consequent.includeCallArguments(context, parameters);
13093
+ this.alternate.includeCallArguments(context, parameters);
13654
13094
  }
13655
13095
  }
13656
13096
  removeAnnotations(code) {
13657
13097
  this.test.removeAnnotations(code);
13658
13098
  }
13659
13099
  render(code, options, { isCalleeOfRenderedParent, preventASI, renderedParentType, renderedSurroundingElement } = parseAst_js.BLANK) {
13100
+ const usedBranch = this.getUsedBranch();
13660
13101
  if (this.test.included) {
13661
13102
  this.test.render(code, options, { renderedSurroundingElement });
13662
13103
  this.consequent.render(code, options);
13663
13104
  this.alternate.render(code, options);
13664
13105
  }
13665
13106
  else {
13666
- const usedBranch = this.getUsedBranch();
13667
13107
  const colonPos = findFirstOccurrenceOutsideComment(code.original, ':', this.consequent.end);
13668
13108
  const inclusionStart = findNonWhiteSpace(code.original, (this.consequent.included
13669
13109
  ? findFirstOccurrenceOutsideComment(code.original, '?', this.test.end)
@@ -13695,8 +13135,6 @@ class ConditionalExpression extends NodeBase {
13695
13135
  : (this.usedBranch = testValue ? this.consequent : this.alternate);
13696
13136
  }
13697
13137
  }
13698
- ConditionalExpression.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
13699
- ConditionalExpression.prototype.applyDeoptimizations = doNotDeoptimize;
13700
13138
 
13701
13139
  class ContinueStatement extends NodeBase {
13702
13140
  hasEffects(context) {
@@ -13716,7 +13154,7 @@ class ContinueStatement extends NodeBase {
13716
13154
  include(context) {
13717
13155
  this.included = true;
13718
13156
  if (this.label) {
13719
- this.label.include(context);
13157
+ this.label.include();
13720
13158
  context.includedLabels.add(this.label.name);
13721
13159
  }
13722
13160
  else {
@@ -13725,15 +13163,12 @@ class ContinueStatement extends NodeBase {
13725
13163
  context.brokenFlow = true;
13726
13164
  }
13727
13165
  }
13728
- ContinueStatement.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
13729
- ContinueStatement.prototype.applyDeoptimizations = doNotDeoptimize;
13730
13166
 
13731
13167
  class DebuggerStatement extends NodeBase {
13732
13168
  hasEffects() {
13733
13169
  return true;
13734
13170
  }
13735
13171
  }
13736
- DebuggerStatement.prototype.includeNode = onlyIncludeSelf;
13737
13172
 
13738
13173
  class Decorator extends NodeBase {
13739
13174
  hasEffects(context) {
@@ -13741,7 +13176,6 @@ class Decorator extends NodeBase {
13741
13176
  this.expression.hasEffectsOnInteractionAtPath(EMPTY_PATH, NODE_INTERACTION_UNKNOWN_CALL, context));
13742
13177
  }
13743
13178
  }
13744
- Decorator.prototype.includeNode = onlyIncludeSelf;
13745
13179
 
13746
13180
  function hasLoopBodyEffects(context, body) {
13747
13181
  const { brokenFlow, hasBreak, hasContinue, ignore } = context;
@@ -13781,15 +13215,12 @@ class DoWhileStatement extends NodeBase {
13781
13215
  includeLoopBody(context, this.body, includeChildrenRecursively);
13782
13216
  }
13783
13217
  }
13784
- DoWhileStatement.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
13785
- DoWhileStatement.prototype.applyDeoptimizations = doNotDeoptimize;
13786
13218
 
13787
13219
  class EmptyStatement extends NodeBase {
13788
13220
  hasEffects() {
13789
13221
  return false;
13790
13222
  }
13791
13223
  }
13792
- EmptyStatement.prototype.includeNode = onlyIncludeSelf;
13793
13224
 
13794
13225
  class ExportAllDeclaration extends NodeBase {
13795
13226
  hasEffects() {
@@ -13802,10 +13233,9 @@ class ExportAllDeclaration extends NodeBase {
13802
13233
  render(code, _options, nodeRenderOptions) {
13803
13234
  code.remove(nodeRenderOptions.start, nodeRenderOptions.end);
13804
13235
  }
13236
+ applyDeoptimizations() { }
13805
13237
  }
13806
13238
  ExportAllDeclaration.prototype.needsBoundaries = true;
13807
- ExportAllDeclaration.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
13808
- ExportAllDeclaration.prototype.applyDeoptimizations = doNotDeoptimize;
13809
13239
 
13810
13240
  class ExportNamedDeclaration extends NodeBase {
13811
13241
  bind() {
@@ -13832,15 +13262,13 @@ class ExportNamedDeclaration extends NodeBase {
13832
13262
  this.declaration.render(code, options, { end, start });
13833
13263
  }
13834
13264
  }
13265
+ applyDeoptimizations() { }
13835
13266
  }
13836
13267
  ExportNamedDeclaration.prototype.needsBoundaries = true;
13837
- ExportNamedDeclaration.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
13838
- ExportNamedDeclaration.prototype.applyDeoptimizations = doNotDeoptimize;
13839
13268
 
13840
13269
  class ExportSpecifier extends NodeBase {
13270
+ applyDeoptimizations() { }
13841
13271
  }
13842
- ExportSpecifier.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
13843
- ExportSpecifier.prototype.applyDeoptimizations = doNotDeoptimize;
13844
13272
 
13845
13273
  class ForInStatement extends NodeBase {
13846
13274
  createScope(parentScope) {
@@ -13858,18 +13286,11 @@ class ForInStatement extends NodeBase {
13858
13286
  const { body, deoptimized, left, right } = this;
13859
13287
  if (!deoptimized)
13860
13288
  this.applyDeoptimizations();
13861
- if (!this.included)
13862
- this.includeNode(context);
13289
+ this.included = true;
13863
13290
  left.includeAsAssignmentTarget(context, includeChildrenRecursively || true, false);
13864
13291
  right.include(context, includeChildrenRecursively);
13865
13292
  includeLoopBody(context, body, includeChildrenRecursively);
13866
13293
  }
13867
- includeNode(context) {
13868
- this.included = true;
13869
- if (!this.deoptimized)
13870
- this.applyDeoptimizations();
13871
- this.right.includePath(UNKNOWN_PATH, context);
13872
- }
13873
13294
  initialise() {
13874
13295
  super.initialise();
13875
13296
  this.left.setAssignedValue(UNKNOWN_EXPRESSION);
@@ -13910,18 +13331,11 @@ class ForOfStatement extends NodeBase {
13910
13331
  const { body, deoptimized, left, right } = this;
13911
13332
  if (!deoptimized)
13912
13333
  this.applyDeoptimizations();
13913
- if (!this.included)
13914
- this.includeNode(context);
13334
+ this.included = true;
13915
13335
  left.includeAsAssignmentTarget(context, includeChildrenRecursively || true, false);
13916
13336
  right.include(context, includeChildrenRecursively);
13917
13337
  includeLoopBody(context, body, includeChildrenRecursively);
13918
13338
  }
13919
- includeNode(context) {
13920
- this.included = true;
13921
- if (!this.deoptimized)
13922
- this.applyDeoptimizations();
13923
- this.right.includePath(UNKNOWN_PATH, context);
13924
- }
13925
13339
  initialise() {
13926
13340
  super.initialise();
13927
13341
  this.left.setAssignedValue(UNKNOWN_EXPRESSION);
@@ -13957,9 +13371,7 @@ class ForStatement extends NodeBase {
13957
13371
  }
13958
13372
  include(context, includeChildrenRecursively) {
13959
13373
  this.included = true;
13960
- this.init?.include(context, includeChildrenRecursively, {
13961
- asSingleStatement: true
13962
- });
13374
+ this.init?.include(context, includeChildrenRecursively, { asSingleStatement: true });
13963
13375
  this.test?.include(context, includeChildrenRecursively);
13964
13376
  this.update?.include(context, includeChildrenRecursively);
13965
13377
  includeLoopBody(context, this.body, includeChildrenRecursively);
@@ -13971,8 +13383,6 @@ class ForStatement extends NodeBase {
13971
13383
  this.body.render(code, options);
13972
13384
  }
13973
13385
  }
13974
- ForStatement.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
13975
- ForStatement.prototype.applyDeoptimizations = doNotDeoptimize;
13976
13386
 
13977
13387
  class FunctionExpression extends FunctionNode {
13978
13388
  createScope(parentScope) {
@@ -14004,9 +13414,9 @@ class TrackingScope extends BlockScope {
14004
13414
  super(...arguments);
14005
13415
  this.hoistedDeclarations = [];
14006
13416
  }
14007
- addDeclaration(identifier, context, init, destructuredInitPath, kind) {
13417
+ addDeclaration(identifier, context, init, kind) {
14008
13418
  this.hoistedDeclarations.push(identifier);
14009
- return super.addDeclaration(identifier, context, init, destructuredInitPath, kind);
13419
+ return super.addDeclaration(identifier, context, init, kind);
14010
13420
  }
14011
13421
  }
14012
13422
 
@@ -14105,6 +13515,7 @@ class IfStatement extends NodeBase {
14105
13515
  }
14106
13516
  this.renderHoistedDeclarations(hoistedDeclarations, code, getPropertyAccess);
14107
13517
  }
13518
+ applyDeoptimizations() { }
14108
13519
  getTestValue() {
14109
13520
  if (this.testValue === unset) {
14110
13521
  return (this.testValue = tryCastLiteralValueToBoolean(this.test.getLiteralValueAtPath(EMPTY_PATH, SHARED_RECURSION_TRACKER, this)));
@@ -14173,8 +13584,6 @@ class IfStatement extends NodeBase {
14173
13584
  return false;
14174
13585
  }
14175
13586
  }
14176
- IfStatement.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
14177
- IfStatement.prototype.applyDeoptimizations = doNotDeoptimize;
14178
13587
 
14179
13588
  class ImportAttribute extends NodeBase {
14180
13589
  }
@@ -14192,15 +13601,13 @@ class ImportDeclaration extends NodeBase {
14192
13601
  render(code, _options, nodeRenderOptions) {
14193
13602
  code.remove(nodeRenderOptions.start, nodeRenderOptions.end);
14194
13603
  }
13604
+ applyDeoptimizations() { }
14195
13605
  }
14196
13606
  ImportDeclaration.prototype.needsBoundaries = true;
14197
- ImportDeclaration.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
14198
- ImportDeclaration.prototype.applyDeoptimizations = doNotDeoptimize;
14199
13607
 
14200
13608
  class ImportDefaultSpecifier extends NodeBase {
13609
+ applyDeoptimizations() { }
14201
13610
  }
14202
- ImportDefaultSpecifier.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
14203
- ImportDefaultSpecifier.prototype.applyDeoptimizations = doNotDeoptimize;
14204
13611
 
14205
13612
  function isReassignedExportsMember(variable, exportNamesByVariable) {
14206
13613
  return (variable.renderBaseName !== null && exportNamesByVariable.has(variable) && variable.isReassigned);
@@ -14209,33 +13616,28 @@ function isReassignedExportsMember(variable, exportNamesByVariable) {
14209
13616
  class VariableDeclarator extends NodeBase {
14210
13617
  declareDeclarator(kind, isUsingDeclaration) {
14211
13618
  this.isUsingDeclaration = isUsingDeclaration;
14212
- this.id.declare(kind, EMPTY_PATH, this.init || UNDEFINED_EXPRESSION);
13619
+ this.id.declare(kind, this.init || UNDEFINED_EXPRESSION);
14213
13620
  }
14214
13621
  deoptimizePath(path) {
14215
13622
  this.id.deoptimizePath(path);
14216
13623
  }
14217
13624
  hasEffects(context) {
13625
+ if (!this.deoptimized)
13626
+ this.applyDeoptimizations();
14218
13627
  const initEffect = this.init?.hasEffects(context);
14219
13628
  this.id.markDeclarationReached();
14220
- return (initEffect ||
14221
- this.isUsingDeclaration ||
14222
- this.id.hasEffects(context) ||
14223
- (this.scope.context.options.treeshake
14224
- .propertyReadSideEffects &&
14225
- this.id.hasEffectsWhenDestructuring(context, EMPTY_PATH, this.init || UNDEFINED_EXPRESSION)));
13629
+ return initEffect || this.id.hasEffects(context) || this.isUsingDeclaration;
14226
13630
  }
14227
13631
  include(context, includeChildrenRecursively) {
14228
- const { id, init } = this;
14229
- if (!this.included)
14230
- this.includeNode();
13632
+ const { deoptimized, id, init } = this;
13633
+ if (!deoptimized)
13634
+ this.applyDeoptimizations();
13635
+ this.included = true;
14231
13636
  init?.include(context, includeChildrenRecursively);
14232
13637
  id.markDeclarationReached();
14233
- if (includeChildrenRecursively) {
13638
+ if (includeChildrenRecursively || id.shouldBeIncluded(context)) {
14234
13639
  id.include(context, includeChildrenRecursively);
14235
13640
  }
14236
- else {
14237
- id.includeDestructuredIfNecessary(context, EMPTY_PATH, init || UNDEFINED_EXPRESSION);
14238
- }
14239
13641
  }
14240
13642
  removeAnnotations(code) {
14241
13643
  this.init?.removeAnnotations(code);
@@ -14265,8 +13667,8 @@ class VariableDeclarator extends NodeBase {
14265
13667
  code.appendLeft(end, `${_}=${_}void 0`);
14266
13668
  }
14267
13669
  }
14268
- includeNode() {
14269
- this.included = true;
13670
+ applyDeoptimizations() {
13671
+ this.deoptimized = true;
14270
13672
  const { id, init } = this;
14271
13673
  if (init && id instanceof Identifier && init instanceof ClassExpression && !init.id) {
14272
13674
  const { name, variable } = id;
@@ -14278,14 +13680,11 @@ class VariableDeclarator extends NodeBase {
14278
13680
  }
14279
13681
  }
14280
13682
  }
14281
- VariableDeclarator.prototype.applyDeoptimizations = doNotDeoptimize;
14282
13683
 
14283
13684
  class ImportExpression extends NodeBase {
14284
13685
  constructor() {
14285
13686
  super(...arguments);
14286
13687
  this.inlineNamespace = null;
14287
- this.hasUnknownAccessedKey = false;
14288
- this.accessedPropKey = new Set();
14289
13688
  this.attributes = null;
14290
13689
  this.mechanism = null;
14291
13690
  this.namespaceExportName = undefined;
@@ -14318,15 +13717,12 @@ class ImportExpression extends NodeBase {
14318
13717
  if (parent2 instanceof ExpressionStatement) {
14319
13718
  return parseAst_js.EMPTY_ARRAY;
14320
13719
  }
14321
- // Case 1: const { foo } / module = await import('bar')
13720
+ // Case 1: const { foo } = await import('bar')
14322
13721
  if (parent2 instanceof VariableDeclarator) {
14323
13722
  const declaration = parent2.id;
14324
- if (declaration instanceof Identifier) {
14325
- return this.hasUnknownAccessedKey ? undefined : [...this.accessedPropKey];
14326
- }
14327
- if (declaration instanceof ObjectPattern) {
14328
- return getDeterministicObjectDestructure(declaration);
14329
- }
13723
+ return declaration instanceof ObjectPattern
13724
+ ? getDeterministicObjectDestructure(declaration)
13725
+ : undefined;
14330
13726
  }
14331
13727
  // Case 2: (await import('bar')).foo
14332
13728
  if (parent2 instanceof MemberExpression) {
@@ -14376,29 +13772,12 @@ class ImportExpression extends NodeBase {
14376
13772
  return true;
14377
13773
  }
14378
13774
  include(context, includeChildrenRecursively) {
14379
- if (!this.included)
14380
- this.includeNode();
14381
- this.source.include(context, includeChildrenRecursively);
14382
- }
14383
- includeNode() {
14384
- this.included = true;
14385
- this.scope.context.includeDynamicImport(this);
14386
- this.scope.addAccessedDynamicImport(this);
14387
- }
14388
- includePath(path) {
14389
- if (!this.included)
14390
- this.includeNode();
14391
- // Technically, this is not correct as dynamic imports return a Promise.
14392
- if (this.hasUnknownAccessedKey)
14393
- return;
14394
- if (path[0] === UnknownKey) {
14395
- this.hasUnknownAccessedKey = true;
14396
- }
14397
- else if (typeof path[0] === 'string') {
14398
- this.accessedPropKey.add(path[0]);
13775
+ if (!this.included) {
13776
+ this.included = true;
13777
+ this.scope.context.includeDynamicImport(this);
13778
+ this.scope.addAccessedDynamicImport(this);
14399
13779
  }
14400
- // Update included paths
14401
- this.scope.context.includeDynamicImport(this);
13780
+ this.source.include(context, includeChildrenRecursively);
14402
13781
  }
14403
13782
  initialise() {
14404
13783
  super.initialise();
@@ -14468,6 +13847,7 @@ class ImportExpression extends NodeBase {
14468
13847
  setInternalResolution(inlineNamespace) {
14469
13848
  this.inlineNamespace = inlineNamespace;
14470
13849
  }
13850
+ applyDeoptimizations() { }
14471
13851
  getDynamicImportMechanismAndHelper(resolution, exportMode, { compact, dynamicImportInCjs, format, generatedCode: { arrowFunctions }, interop }, { _, getDirectReturnFunction, getDirectReturnIifeLeft }, pluginDriver) {
14472
13852
  const mechanism = pluginDriver.hookFirstSync('renderDynamicImport', [
14473
13853
  {
@@ -14557,7 +13937,6 @@ class ImportExpression extends NodeBase {
14557
13937
  return { helper: null, mechanism: null };
14558
13938
  }
14559
13939
  }
14560
- ImportExpression.prototype.applyDeoptimizations = doNotDeoptimize;
14561
13940
  function getInteropHelper(resolution, exportMode, interop) {
14562
13941
  return exportMode === 'external'
14563
13942
  ? namespaceInteropHelpersByInteropType[interop(resolution instanceof ExternalModule ? resolution.id : null)]
@@ -14581,14 +13960,12 @@ function getDeterministicObjectDestructure(objectPattern) {
14581
13960
  }
14582
13961
 
14583
13962
  class ImportNamespaceSpecifier extends NodeBase {
13963
+ applyDeoptimizations() { }
14584
13964
  }
14585
- ImportNamespaceSpecifier.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
14586
- ImportNamespaceSpecifier.prototype.applyDeoptimizations = doNotDeoptimize;
14587
13965
 
14588
13966
  class ImportSpecifier extends NodeBase {
13967
+ applyDeoptimizations() { }
14589
13968
  }
14590
- ImportSpecifier.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
14591
- ImportSpecifier.prototype.applyDeoptimizations = doNotDeoptimize;
14592
13969
 
14593
13970
  class JSXIdentifier extends IdentifierBase {
14594
13971
  constructor() {
@@ -14605,29 +13982,6 @@ class JSXIdentifier extends IdentifierBase {
14605
13982
  this.isNativeElement = true;
14606
13983
  }
14607
13984
  }
14608
- include(context) {
14609
- if (!this.included)
14610
- this.includeNode(context);
14611
- }
14612
- includeNode(context) {
14613
- this.included = true;
14614
- if (!this.deoptimized)
14615
- this.applyDeoptimizations();
14616
- if (this.variable !== null) {
14617
- this.scope.context.includeVariableInModule(this.variable, EMPTY_PATH, context);
14618
- }
14619
- }
14620
- includePath(path, context) {
14621
- if (!this.included) {
14622
- this.included = true;
14623
- if (this.variable !== null) {
14624
- this.scope.context.includeVariableInModule(this.variable, path, context);
14625
- }
14626
- }
14627
- else if (path.length > 0) {
14628
- this.variable?.includePath(path, context);
14629
- }
14630
- }
14631
13985
  render(code, { snippets: { getPropertyAccess }, useOriginalName }) {
14632
13986
  if (this.variable) {
14633
13987
  const name = this.variable.getName(getPropertyAccess, useOriginalName);
@@ -14689,7 +14043,6 @@ class JSXAttribute extends NodeBase {
14689
14043
  }
14690
14044
  }
14691
14045
  }
14692
- JSXAttribute.prototype.includeNode = onlyIncludeSelf;
14693
14046
 
14694
14047
  class JSXClosingBase extends NodeBase {
14695
14048
  render(code, options) {
@@ -14702,7 +14055,6 @@ class JSXClosingBase extends NodeBase {
14702
14055
  }
14703
14056
  }
14704
14057
  }
14705
- JSXClosingBase.prototype.includeNode = onlyIncludeSelf;
14706
14058
 
14707
14059
  class JSXClosingElement extends JSXClosingBase {
14708
14060
  }
@@ -14723,15 +14075,8 @@ class JSXSpreadAttribute extends NodeBase {
14723
14075
 
14724
14076
  class JSXEmptyExpression extends NodeBase {
14725
14077
  }
14726
- JSXEmptyExpression.prototype.includeNode = onlyIncludeSelf;
14727
14078
 
14728
14079
  class JSXExpressionContainer extends NodeBase {
14729
- includeNode(context) {
14730
- this.included = true;
14731
- if (!this.deoptimized)
14732
- this.applyDeoptimizations();
14733
- this.expression.includePath(UNKNOWN_PATH, context);
14734
- }
14735
14080
  render(code, options) {
14736
14081
  const { mode } = this.scope.context.options.jsx;
14737
14082
  if (mode !== 'preserve') {
@@ -14752,7 +14097,7 @@ function getRenderedJsxChildren(children) {
14752
14097
  return renderedChildren;
14753
14098
  }
14754
14099
 
14755
- function getAndIncludeFactoryVariable(factory, preserve, importSource, node, context) {
14100
+ function getAndIncludeFactoryVariable(factory, preserve, importSource, node) {
14756
14101
  const [baseName, nestedName] = factory.split('.');
14757
14102
  let factoryVariable;
14758
14103
  if (importSource) {
@@ -14760,7 +14105,7 @@ function getAndIncludeFactoryVariable(factory, preserve, importSource, node, con
14760
14105
  if (preserve) {
14761
14106
  // This pretends we are accessing an included global variable of the same name
14762
14107
  const globalVariable = node.scope.findGlobal(baseName);
14763
- globalVariable.includePath(UNKNOWN_PATH, context);
14108
+ globalVariable.include();
14764
14109
  // This excludes this variable from renaming
14765
14110
  factoryVariable.globalName = baseName;
14766
14111
  }
@@ -14768,7 +14113,7 @@ function getAndIncludeFactoryVariable(factory, preserve, importSource, node, con
14768
14113
  else {
14769
14114
  factoryVariable = node.scope.findGlobal(baseName);
14770
14115
  }
14771
- node.scope.context.includeVariableInModule(factoryVariable, UNKNOWN_PATH, context);
14116
+ node.scope.context.includeVariableInModule(factoryVariable);
14772
14117
  if (factoryVariable instanceof LocalVariable) {
14773
14118
  factoryVariable.consolidateInitializers();
14774
14119
  factoryVariable.addUsedPlace(node);
@@ -14791,20 +14136,16 @@ class JSXElementBase extends NodeBase {
14791
14136
  }
14792
14137
  }
14793
14138
  include(context, includeChildrenRecursively) {
14794
- if (!this.included)
14795
- this.includeNode(context);
14796
- for (const child of this.children) {
14797
- child.include(context, includeChildrenRecursively);
14798
- }
14799
- }
14800
- includeNode(context) {
14801
- this.included = true;
14802
- const { factory, importSource, mode } = this.jsxMode;
14803
- if (factory) {
14804
- this.factory = factory;
14805
- this.factoryVariable = getAndIncludeFactoryVariable(factory, mode === 'preserve', importSource, this, context);
14139
+ if (!this.included) {
14140
+ const { factory, importSource, mode } = this.jsxMode;
14141
+ if (factory) {
14142
+ this.factory = factory;
14143
+ this.factoryVariable = getAndIncludeFactoryVariable(factory, mode === 'preserve', importSource, this);
14144
+ }
14806
14145
  }
14146
+ super.include(context, includeChildrenRecursively);
14807
14147
  }
14148
+ applyDeoptimizations() { }
14808
14149
  getRenderingMode() {
14809
14150
  const jsx = this.scope.context.options.jsx;
14810
14151
  const { mode, factory, importSource } = jsx;
@@ -14842,14 +14183,8 @@ class JSXElementBase extends NodeBase {
14842
14183
  return { childrenEnd, firstChild, hasMultipleChildren };
14843
14184
  }
14844
14185
  }
14845
- JSXElementBase.prototype.applyDeoptimizations = doNotDeoptimize;
14846
14186
 
14847
14187
  class JSXElement extends JSXElementBase {
14848
- include(context, includeChildrenRecursively) {
14849
- super.include(context, includeChildrenRecursively);
14850
- this.openingElement.include(context, includeChildrenRecursively);
14851
- this.closingElement?.include(context, includeChildrenRecursively);
14852
- }
14853
14188
  render(code, options) {
14854
14189
  switch (this.jsxMode.mode) {
14855
14190
  case 'classic': {
@@ -15001,11 +14336,6 @@ class JSXElement extends JSXElementBase {
15001
14336
  }
15002
14337
 
15003
14338
  class JSXFragment extends JSXElementBase {
15004
- include(context, includeChildrenRecursively) {
15005
- super.include(context, includeChildrenRecursively);
15006
- this.openingFragment.include(context, includeChildrenRecursively);
15007
- this.closingFragment.include(context, includeChildrenRecursively);
15008
- }
15009
14339
  render(code, options) {
15010
14340
  switch (this.jsxMode.mode) {
15011
14341
  case 'classic': {
@@ -15055,22 +14385,10 @@ class JSXFragment extends JSXElementBase {
15055
14385
  }
15056
14386
 
15057
14387
  class JSXMemberExpression extends NodeBase {
15058
- includeNode(context) {
15059
- this.included = true;
15060
- if (!this.deoptimized)
15061
- this.applyDeoptimizations();
15062
- this.object.includePath([this.property.name], context);
15063
- }
15064
- includePath(path, context) {
15065
- if (!this.included)
15066
- this.includeNode(context);
15067
- this.object.includePath([this.property.name, ...path], context);
15068
- }
15069
14388
  }
15070
14389
 
15071
14390
  class JSXNamespacedName extends NodeBase {
15072
14391
  }
15073
- JSXNamespacedName.prototype.includeNode = onlyIncludeSelf;
15074
14392
 
15075
14393
  class JSXOpeningElement extends NodeBase {
15076
14394
  render(code, options, { jsxMode = this.scope.context.options.jsx.mode } = {}) {
@@ -15080,7 +14398,6 @@ class JSXOpeningElement extends NodeBase {
15080
14398
  }
15081
14399
  }
15082
14400
  }
15083
- JSXOpeningElement.prototype.includeNode = onlyIncludeSelf;
15084
14401
 
15085
14402
  class JSXOpeningFragment extends NodeBase {
15086
14403
  constructor() {
@@ -15088,22 +14405,22 @@ class JSXOpeningFragment extends NodeBase {
15088
14405
  this.fragment = null;
15089
14406
  this.fragmentVariable = null;
15090
14407
  }
15091
- includeNode(context) {
15092
- this.included = true;
15093
- if (!this.deoptimized)
15094
- this.applyDeoptimizations();
15095
- const jsx = this.scope.context.options.jsx;
15096
- if (jsx.mode === 'automatic') {
15097
- this.fragment = 'Fragment';
15098
- this.fragmentVariable = getAndIncludeFactoryVariable('Fragment', false, jsx.jsxImportSource, this, context);
15099
- }
15100
- else {
15101
- const { fragment, importSource, mode } = jsx;
15102
- if (fragment != null) {
15103
- this.fragment = fragment;
15104
- this.fragmentVariable = getAndIncludeFactoryVariable(fragment, mode === 'preserve', importSource, this, context);
14408
+ include(context, includeChildrenRecursively) {
14409
+ if (!this.included) {
14410
+ const jsx = this.scope.context.options.jsx;
14411
+ if (jsx.mode === 'automatic') {
14412
+ this.fragment = 'Fragment';
14413
+ this.fragmentVariable = getAndIncludeFactoryVariable('Fragment', false, jsx.jsxImportSource, this);
14414
+ }
14415
+ else {
14416
+ const { fragment, importSource, mode } = jsx;
14417
+ if (fragment != null) {
14418
+ this.fragment = fragment;
14419
+ this.fragmentVariable = getAndIncludeFactoryVariable(fragment, mode === 'preserve', importSource, this);
14420
+ }
15105
14421
  }
15106
14422
  }
14423
+ super.include(context, includeChildrenRecursively);
15107
14424
  }
15108
14425
  render(code, options) {
15109
14426
  const { mode } = this.scope.context.options.jsx;
@@ -15140,7 +14457,6 @@ class JSXText extends NodeBase {
15140
14457
  }
15141
14458
  }
15142
14459
  }
15143
- JSXText.prototype.includeNode = onlyIncludeSelf;
15144
14460
 
15145
14461
  class LabeledStatement extends NodeBase {
15146
14462
  hasEffects(context) {
@@ -15162,22 +14478,17 @@ class LabeledStatement extends NodeBase {
15162
14478
  return bodyHasEffects;
15163
14479
  }
15164
14480
  include(context, includeChildrenRecursively) {
15165
- if (!this.included)
15166
- this.includeNode(context);
14481
+ this.included = true;
15167
14482
  const { brokenFlow, includedLabels } = context;
15168
14483
  context.includedLabels = new Set();
15169
14484
  this.body.include(context, includeChildrenRecursively);
15170
14485
  if (includeChildrenRecursively || context.includedLabels.has(this.label.name)) {
15171
- this.label.include(context);
14486
+ this.label.include();
15172
14487
  context.includedLabels.delete(this.label.name);
15173
14488
  context.brokenFlow = brokenFlow;
15174
14489
  }
15175
14490
  context.includedLabels = new Set([...includedLabels, ...context.includedLabels]);
15176
14491
  }
15177
- includeNode(context) {
15178
- this.included = true;
15179
- this.body.includePath(UNKNOWN_PATH, context);
15180
- }
15181
14492
  render(code, options) {
15182
14493
  if (this.label.included) {
15183
14494
  this.label.render(code, options);
@@ -15188,7 +14499,6 @@ class LabeledStatement extends NodeBase {
15188
14499
  this.body.render(code, options);
15189
14500
  }
15190
14501
  }
15191
- LabeledStatement.prototype.applyDeoptimizations = doNotDeoptimize;
15192
14502
 
15193
14503
  class LogicalExpression extends NodeBase {
15194
14504
  constructor() {
@@ -15205,10 +14515,10 @@ class LogicalExpression extends NodeBase {
15205
14515
  this.flags = setFlag(this.flags, 65536 /* Flag.isBranchResolutionAnalysed */, value);
15206
14516
  }
15207
14517
  get hasDeoptimizedCache() {
15208
- return isFlagSet(this.flags, 33554432 /* Flag.hasDeoptimizedCache */);
14518
+ return isFlagSet(this.flags, 16777216 /* Flag.hasDeoptimizedCache */);
15209
14519
  }
15210
14520
  set hasDeoptimizedCache(value) {
15211
- this.flags = setFlag(this.flags, 33554432 /* Flag.hasDeoptimizedCache */, value);
14521
+ this.flags = setFlag(this.flags, 16777216 /* Flag.hasDeoptimizedCache */, value);
15212
14522
  }
15213
14523
  deoptimizeArgumentsOnInteractionAtPath(interaction, path, recursionTracker) {
15214
14524
  this.left.deoptimizeArgumentsOnInteractionAtPath(interaction, path, recursionTracker);
@@ -15221,10 +14531,6 @@ class LogicalExpression extends NodeBase {
15221
14531
  const unusedBranch = this.usedBranch === this.left ? this.right : this.left;
15222
14532
  this.usedBranch = null;
15223
14533
  unusedBranch.deoptimizePath(UNKNOWN_PATH);
15224
- if (this.included) {
15225
- // As we are not tracking inclusions, we just include everything
15226
- unusedBranch.includePath(UNKNOWN_PATH, createInclusionContext());
15227
- }
15228
14534
  }
15229
14535
  const { scope: { context }, expressionsToBeDeoptimized } = this;
15230
14536
  this.expressionsToBeDeoptimized = parseAst_js.EMPTY_ARRAY;
@@ -15270,17 +14576,16 @@ class LogicalExpression extends NodeBase {
15270
14576
  }
15271
14577
  getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin) {
15272
14578
  const usedBranch = this.getUsedBranch();
15273
- if (usedBranch) {
15274
- this.expressionsToBeDeoptimized.push(origin);
15275
- return usedBranch.getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin);
15276
- }
15277
- return [
15278
- new MultiExpression([
15279
- this.left.getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin)[0],
15280
- this.right.getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin)[0]
15281
- ]),
15282
- false
15283
- ];
14579
+ if (!usedBranch)
14580
+ return [
14581
+ new MultiExpression([
14582
+ this.left.getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin)[0],
14583
+ this.right.getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin)[0]
14584
+ ]),
14585
+ false
14586
+ ];
14587
+ this.expressionsToBeDeoptimized.push(origin);
14588
+ return usedBranch.getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin);
15284
14589
  }
15285
14590
  hasEffects(context) {
15286
14591
  if (this.left.hasEffects(context)) {
@@ -15293,18 +14598,18 @@ class LogicalExpression extends NodeBase {
15293
14598
  }
15294
14599
  hasEffectsOnInteractionAtPath(path, interaction, context) {
15295
14600
  const usedBranch = this.getUsedBranch();
15296
- if (usedBranch) {
15297
- return usedBranch.hasEffectsOnInteractionAtPath(path, interaction, context);
14601
+ if (!usedBranch) {
14602
+ return (this.left.hasEffectsOnInteractionAtPath(path, interaction, context) ||
14603
+ this.right.hasEffectsOnInteractionAtPath(path, interaction, context));
15298
14604
  }
15299
- return (this.left.hasEffectsOnInteractionAtPath(path, interaction, context) ||
15300
- this.right.hasEffectsOnInteractionAtPath(path, interaction, context));
14605
+ return usedBranch.hasEffectsOnInteractionAtPath(path, interaction, context);
15301
14606
  }
15302
14607
  include(context, includeChildrenRecursively) {
15303
14608
  this.included = true;
15304
14609
  const usedBranch = this.getUsedBranch();
15305
14610
  if (includeChildrenRecursively ||
15306
- !usedBranch ||
15307
- (usedBranch === this.right && this.left.shouldBeIncluded(context))) {
14611
+ (usedBranch === this.right && this.left.shouldBeIncluded(context)) ||
14612
+ !usedBranch) {
15308
14613
  this.left.include(context, includeChildrenRecursively);
15309
14614
  this.right.include(context, includeChildrenRecursively);
15310
14615
  }
@@ -15312,17 +14617,6 @@ class LogicalExpression extends NodeBase {
15312
14617
  usedBranch.include(context, includeChildrenRecursively);
15313
14618
  }
15314
14619
  }
15315
- includePath(path, context) {
15316
- this.included = true;
15317
- const usedBranch = this.getUsedBranch();
15318
- if (!usedBranch || (usedBranch === this.right && this.left.shouldBeIncluded(context))) {
15319
- this.left.includePath(path, context);
15320
- this.right.includePath(path, context);
15321
- }
15322
- else {
15323
- usedBranch.includePath(path, context);
15324
- }
15325
- }
15326
14620
  removeAnnotations(code) {
15327
14621
  this.left.removeAnnotations(code);
15328
14622
  }
@@ -15375,8 +14669,6 @@ class LogicalExpression extends NodeBase {
15375
14669
  return this.usedBranch;
15376
14670
  }
15377
14671
  }
15378
- LogicalExpression.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
15379
- LogicalExpression.prototype.applyDeoptimizations = doNotDeoptimize;
15380
14672
 
15381
14673
  class NewExpression extends NodeBase {
15382
14674
  hasEffects(context) {
@@ -15396,21 +14688,16 @@ class NewExpression extends NodeBase {
15396
14688
  return path.length > 0 || type !== INTERACTION_ACCESSED;
15397
14689
  }
15398
14690
  include(context, includeChildrenRecursively) {
14691
+ if (!this.deoptimized)
14692
+ this.applyDeoptimizations();
15399
14693
  if (includeChildrenRecursively) {
15400
14694
  super.include(context, includeChildrenRecursively);
15401
14695
  }
15402
14696
  else {
15403
- if (!this.included)
15404
- this.includeNode(context);
14697
+ this.included = true;
15405
14698
  this.callee.include(context, false);
15406
14699
  }
15407
- this.callee.includeCallArguments(context, this.interaction);
15408
- }
15409
- includeNode(context) {
15410
- this.included = true;
15411
- if (!this.deoptimized)
15412
- this.applyDeoptimizations();
15413
- this.callee.includePath(UNKNOWN_PATH, context);
14700
+ this.callee.includeCallArguments(context, this.arguments);
15414
14701
  }
15415
14702
  initialise() {
15416
14703
  super.initialise();
@@ -15439,7 +14726,6 @@ class ObjectExpression extends NodeBase {
15439
14726
  constructor() {
15440
14727
  super(...arguments);
15441
14728
  this.objectEntity = null;
15442
- this.protoProp = null;
15443
14729
  }
15444
14730
  deoptimizeArgumentsOnInteractionAtPath(interaction, path, recursionTracker) {
15445
14731
  this.getObjectEntity().deoptimizeArgumentsOnInteractionAtPath(interaction, path, recursionTracker);
@@ -15459,43 +14745,15 @@ class ObjectExpression extends NodeBase {
15459
14745
  hasEffectsOnInteractionAtPath(path, interaction, context) {
15460
14746
  return this.getObjectEntity().hasEffectsOnInteractionAtPath(path, interaction, context);
15461
14747
  }
15462
- include(context, includeChildrenRecursively) {
15463
- if (!this.included)
15464
- this.includeNode(context);
15465
- this.getObjectEntity().include(context, includeChildrenRecursively);
15466
- this.protoProp?.include(context, includeChildrenRecursively);
15467
- }
15468
- includeNode(context) {
15469
- this.included = true;
15470
- this.protoProp?.includePath(UNKNOWN_PATH, context);
15471
- }
15472
- includePath(path, context) {
15473
- if (!this.included)
15474
- this.includeNode(context);
15475
- this.getObjectEntity().includePath(path, context);
15476
- }
15477
14748
  render(code, options, { renderedSurroundingElement } = parseAst_js.BLANK) {
14749
+ super.render(code, options);
15478
14750
  if (renderedSurroundingElement === parseAst_js.ExpressionStatement ||
15479
14751
  renderedSurroundingElement === parseAst_js.ArrowFunctionExpression) {
15480
14752
  code.appendRight(this.start, '(');
15481
14753
  code.prependLeft(this.end, ')');
15482
14754
  }
15483
- if (this.properties.length > 0) {
15484
- const separatedNodes = getCommaSeparatedNodesWithBoundaries(this.properties, code, this.start + 1, this.end - 1);
15485
- let lastSeparatorPos = null;
15486
- for (const { node, separator, start, end } of separatedNodes) {
15487
- if (!node.included) {
15488
- treeshakeNode(node, code, start, end);
15489
- continue;
15490
- }
15491
- lastSeparatorPos = separator;
15492
- node.render(code, options);
15493
- }
15494
- if (lastSeparatorPos) {
15495
- code.remove(lastSeparatorPos, this.end - 1);
15496
- }
15497
- }
15498
14755
  }
14756
+ applyDeoptimizations() { }
15499
14757
  getObjectEntity() {
15500
14758
  if (this.objectEntity !== null) {
15501
14759
  return this.objectEntity;
@@ -15524,7 +14782,6 @@ class ObjectExpression extends NodeBase {
15524
14782
  ? property.key.name
15525
14783
  : String(property.key.value);
15526
14784
  if (key === '__proto__' && property.kind === 'init') {
15527
- this.protoProp = property;
15528
14785
  prototype =
15529
14786
  property.value instanceof Literal && property.value.value === null
15530
14787
  ? null
@@ -15537,7 +14794,6 @@ class ObjectExpression extends NodeBase {
15537
14794
  return (this.objectEntity = new ObjectEntity(properties, prototype));
15538
14795
  }
15539
14796
  }
15540
- ObjectExpression.prototype.applyDeoptimizations = doNotDeoptimize;
15541
14797
 
15542
14798
  class PanicError extends NodeBase {
15543
14799
  initialise() {
@@ -15564,7 +14820,6 @@ class ParseError extends NodeBase {
15564
14820
 
15565
14821
  class PrivateIdentifier extends NodeBase {
15566
14822
  }
15567
- PrivateIdentifier.prototype.includeNode = onlyIncludeSelf;
15568
14823
 
15569
14824
  class Program extends NodeBase {
15570
14825
  constructor() {
@@ -15632,11 +14887,14 @@ class Program extends NodeBase {
15632
14887
  super.render(code, options);
15633
14888
  }
15634
14889
  }
14890
+ applyDeoptimizations() { }
15635
14891
  }
15636
- Program.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
15637
- Program.prototype.applyDeoptimizations = doNotDeoptimize;
15638
14892
 
15639
14893
  class Property extends MethodBase {
14894
+ constructor() {
14895
+ super(...arguments);
14896
+ this.declarationInit = null;
14897
+ }
15640
14898
  //declare method: boolean;
15641
14899
  get method() {
15642
14900
  return isFlagSet(this.flags, 262144 /* Flag.method */);
@@ -15651,41 +14909,17 @@ class Property extends MethodBase {
15651
14909
  set shorthand(value) {
15652
14910
  this.flags = setFlag(this.flags, 524288 /* Flag.shorthand */, value);
15653
14911
  }
15654
- declare(kind, destructuredInitPath, init) {
15655
- return this.value.declare(kind, this.getPathInProperty(destructuredInitPath), init);
15656
- }
15657
- deoptimizeAssignment(destructuredInitPath, init) {
15658
- this.value.deoptimizeAssignment?.(this.getPathInProperty(destructuredInitPath), init);
14912
+ declare(kind, init) {
14913
+ this.declarationInit = init;
14914
+ return this.value.declare(kind, UNKNOWN_EXPRESSION);
15659
14915
  }
15660
14916
  hasEffects(context) {
15661
- return this.key.hasEffects(context) || this.value.hasEffects(context);
15662
- }
15663
- hasEffectsWhenDestructuring(context, destructuredInitPath, init) {
15664
- return this.value.hasEffectsWhenDestructuring?.(context, this.getPathInProperty(destructuredInitPath), init);
15665
- }
15666
- includeDestructuredIfNecessary(context, destructuredInitPath, init) {
15667
- const path = this.getPathInProperty(destructuredInitPath);
15668
- let included = this.value.includeDestructuredIfNecessary(context, path, init) ||
15669
- this.included;
15670
- if ((included ||= this.key.hasEffects(createHasEffectsContext()))) {
15671
- this.key.include(context, false);
15672
- if (!this.value.included) {
15673
- this.value.included = true;
15674
- // Unfortunately, we need to include the value again now, so that any
15675
- // declared variables are properly included.
15676
- this.value.includeDestructuredIfNecessary(context, path, init);
15677
- }
15678
- }
15679
- return (this.included = included);
15680
- }
15681
- include(context, includeChildrenRecursively) {
15682
- this.included = true;
15683
- this.key.include(context, includeChildrenRecursively);
15684
- this.value.include(context, includeChildrenRecursively);
15685
- }
15686
- includePath(path, context) {
15687
- this.included = true;
15688
- this.value.includePath(path, context);
14917
+ if (!this.deoptimized)
14918
+ this.applyDeoptimizations();
14919
+ const propertyReadSideEffects = this.scope.context.options.treeshake.propertyReadSideEffects;
14920
+ return ((this.parent.type === 'ObjectPattern' && propertyReadSideEffects === 'always') ||
14921
+ this.key.hasEffects(context) ||
14922
+ this.value.hasEffects(context));
15689
14923
  }
15690
14924
  markDeclarationReached() {
15691
14925
  this.value.markDeclarationReached();
@@ -15696,20 +14930,14 @@ class Property extends MethodBase {
15696
14930
  }
15697
14931
  this.value.render(code, options, { isShorthandProperty: this.shorthand });
15698
14932
  }
15699
- getPathInProperty(destructuredInitPath) {
15700
- return destructuredInitPath.at(-1) === UnknownKey
15701
- ? destructuredInitPath
15702
- : // For now, we only consider static paths as we do not know how to
15703
- // deoptimize the path in the dynamic case.
15704
- this.computed
15705
- ? [...destructuredInitPath, UnknownKey]
15706
- : this.key instanceof Identifier
15707
- ? [...destructuredInitPath, this.key.name]
15708
- : [...destructuredInitPath, String(this.key.value)];
14933
+ applyDeoptimizations() {
14934
+ this.deoptimized = true;
14935
+ if (this.declarationInit !== null) {
14936
+ this.declarationInit.deoptimizePath([UnknownKey, UnknownKey]);
14937
+ this.scope.context.requestTreeshakingPass();
14938
+ }
15709
14939
  }
15710
14940
  }
15711
- Property.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
15712
- Property.prototype.applyDeoptimizations = doNotDeoptimize;
15713
14941
 
15714
14942
  class PropertyDefinition extends NodeBase {
15715
14943
  get computed() {
@@ -15742,15 +14970,8 @@ class PropertyDefinition extends NodeBase {
15742
14970
  hasEffectsOnInteractionAtPath(path, interaction, context) {
15743
14971
  return !this.value || this.value.hasEffectsOnInteractionAtPath(path, interaction, context);
15744
14972
  }
15745
- includeNode(context) {
15746
- this.included = true;
15747
- this.value?.includePath(UNKNOWN_PATH, context);
15748
- for (const decorator of this.decorators) {
15749
- decorator.includePath(UNKNOWN_PATH, context);
15750
- }
15751
- }
14973
+ applyDeoptimizations() { }
15752
14974
  }
15753
- PropertyDefinition.prototype.applyDeoptimizations = doNotDeoptimize;
15754
14975
 
15755
14976
  class ReturnStatement extends NodeBase {
15756
14977
  hasEffects(context) {
@@ -15760,15 +14981,10 @@ class ReturnStatement extends NodeBase {
15760
14981
  return false;
15761
14982
  }
15762
14983
  include(context, includeChildrenRecursively) {
15763
- if (!this.included)
15764
- this.includeNode(context);
14984
+ this.included = true;
15765
14985
  this.argument?.include(context, includeChildrenRecursively);
15766
14986
  context.brokenFlow = true;
15767
14987
  }
15768
- includeNode(context) {
15769
- this.included = true;
15770
- this.argument?.includePath(UNKNOWN_PATH, context);
15771
- }
15772
14988
  initialise() {
15773
14989
  super.initialise();
15774
14990
  this.scope.addReturnExpression(this.argument || UNKNOWN_EXPRESSION);
@@ -15782,7 +14998,6 @@ class ReturnStatement extends NodeBase {
15782
14998
  }
15783
14999
  }
15784
15000
  }
15785
- ReturnStatement.prototype.applyDeoptimizations = doNotDeoptimize;
15786
15001
 
15787
15002
  class SequenceExpression extends NodeBase {
15788
15003
  deoptimizeArgumentsOnInteractionAtPath(interaction, path, recursionTracker) {
@@ -15810,15 +15025,10 @@ class SequenceExpression extends NodeBase {
15810
15025
  for (const expression of this.expressions) {
15811
15026
  if (includeChildrenRecursively ||
15812
15027
  (expression === lastExpression && !(this.parent instanceof ExpressionStatement)) ||
15813
- expression.shouldBeIncluded(context)) {
15028
+ expression.shouldBeIncluded(context))
15814
15029
  expression.include(context, includeChildrenRecursively);
15815
- }
15816
15030
  }
15817
15031
  }
15818
- includePath(path, context) {
15819
- this.included = true;
15820
- this.expressions[this.expressions.length - 1].includePath(path, context);
15821
- }
15822
15032
  removeAnnotations(code) {
15823
15033
  this.expressions[0].removeAnnotations(code);
15824
15034
  }
@@ -15853,8 +15063,6 @@ class SequenceExpression extends NodeBase {
15853
15063
  }
15854
15064
  }
15855
15065
  }
15856
- SequenceExpression.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
15857
- SequenceExpression.prototype.applyDeoptimizations = doNotDeoptimize;
15858
15066
 
15859
15067
  class Super extends NodeBase {
15860
15068
  bind() {
@@ -15866,15 +15074,11 @@ class Super extends NodeBase {
15866
15074
  deoptimizePath(path) {
15867
15075
  this.variable.deoptimizePath(path);
15868
15076
  }
15869
- include(context) {
15870
- if (!this.included)
15871
- this.includeNode(context);
15872
- }
15873
- includeNode(context) {
15874
- this.included = true;
15875
- if (!this.deoptimized)
15876
- this.applyDeoptimizations();
15877
- this.scope.context.includeVariableInModule(this.variable, EMPTY_PATH, context);
15077
+ include() {
15078
+ if (!this.included) {
15079
+ this.included = true;
15080
+ this.scope.context.includeVariableInModule(this.variable);
15081
+ }
15878
15082
  }
15879
15083
  }
15880
15084
 
@@ -15899,24 +15103,22 @@ class SwitchCase extends NodeBase {
15899
15103
  }
15900
15104
  }
15901
15105
  render(code, options, nodeRenderOptions) {
15902
- if (this.consequent.length > 0) {
15903
- if (this.test) {
15904
- this.test.render(code, options);
15106
+ if (this.test) {
15107
+ this.test.render(code, options);
15108
+ if (this.test.start === this.start + 4) {
15109
+ code.prependLeft(this.test.start, ' ');
15905
15110
  }
15111
+ }
15112
+ if (this.consequent.length > 0) {
15906
15113
  const testEnd = this.test
15907
15114
  ? this.test.end
15908
15115
  : findFirstOccurrenceOutsideComment(code.original, 'default', this.start) + 7;
15909
15116
  const consequentStart = findFirstOccurrenceOutsideComment(code.original, ':', testEnd) + 1;
15910
15117
  renderStatementList(this.consequent, code, consequentStart, nodeRenderOptions.end, options);
15911
15118
  }
15912
- else {
15913
- super.render(code, options);
15914
- }
15915
15119
  }
15916
15120
  }
15917
15121
  SwitchCase.prototype.needsBoundaries = true;
15918
- SwitchCase.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
15919
- SwitchCase.prototype.applyDeoptimizations = doNotDeoptimize;
15920
15122
 
15921
15123
  class SwitchStatement extends NodeBase {
15922
15124
  createScope(parentScope) {
@@ -15999,8 +15201,6 @@ class SwitchStatement extends NodeBase {
15999
15201
  }
16000
15202
  }
16001
15203
  }
16002
- SwitchStatement.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
16003
- SwitchStatement.prototype.applyDeoptimizations = doNotDeoptimize;
16004
15204
 
16005
15205
  class TaggedTemplateExpression extends CallExpressionBase {
16006
15206
  bind() {
@@ -16024,8 +15224,8 @@ class TaggedTemplateExpression extends CallExpressionBase {
16024
15224
  this.tag.hasEffectsOnInteractionAtPath(EMPTY_PATH, this.interaction, context));
16025
15225
  }
16026
15226
  include(context, includeChildrenRecursively) {
16027
- if (!this.included)
16028
- this.includeNode(context);
15227
+ if (!this.deoptimized)
15228
+ this.applyDeoptimizations();
16029
15229
  if (includeChildrenRecursively) {
16030
15230
  super.include(context, includeChildrenRecursively);
16031
15231
  }
@@ -16034,7 +15234,7 @@ class TaggedTemplateExpression extends CallExpressionBase {
16034
15234
  this.tag.include(context, includeChildrenRecursively);
16035
15235
  this.quasi.include(context, includeChildrenRecursively);
16036
15236
  }
16037
- this.tag.includeCallArguments(context, this.interaction);
15237
+ this.tag.includeCallArguments(context, this.args);
16038
15238
  const [returnExpression] = this.getReturnExpression();
16039
15239
  if (!returnExpression.included) {
16040
15240
  returnExpression.include(context, false);
@@ -16069,7 +15269,6 @@ class TaggedTemplateExpression extends CallExpressionBase {
16069
15269
  return this.returnExpression;
16070
15270
  }
16071
15271
  }
16072
- TaggedTemplateExpression.prototype.includeNode = onlyIncludeSelf;
16073
15272
 
16074
15273
  class TemplateElement extends NodeBase {
16075
15274
  get tail() {
@@ -16083,13 +15282,15 @@ class TemplateElement extends NodeBase {
16083
15282
  hasEffects() {
16084
15283
  return false;
16085
15284
  }
15285
+ include() {
15286
+ this.included = true;
15287
+ }
16086
15288
  parseNode(esTreeNode) {
16087
15289
  this.value = esTreeNode.value;
16088
15290
  return super.parseNode(esTreeNode);
16089
15291
  }
16090
15292
  render() { }
16091
15293
  }
16092
- TemplateElement.prototype.includeNode = onlyIncludeSelf;
16093
15294
 
16094
15295
  class TemplateLiteral extends NodeBase {
16095
15296
  deoptimizeArgumentsOnInteractionAtPath() { }
@@ -16114,14 +15315,6 @@ class TemplateLiteral extends NodeBase {
16114
15315
  }
16115
15316
  return true;
16116
15317
  }
16117
- includeNode(context) {
16118
- this.included = true;
16119
- if (!this.deoptimized)
16120
- this.applyDeoptimizations();
16121
- for (const node of this.expressions) {
16122
- node.includePath(UNKNOWN_PATH, context);
16123
- }
16124
- }
16125
15318
  render(code, options) {
16126
15319
  code.indentExclusionRanges.push([this.start, this.end]);
16127
15320
  super.render(code, options);
@@ -16131,13 +15324,13 @@ class TemplateLiteral extends NodeBase {
16131
15324
  class ModuleScope extends ChildScope {
16132
15325
  constructor(parent, context) {
16133
15326
  super(parent, context);
16134
- this.variables.set('this', new LocalVariable('this', null, UNDEFINED_EXPRESSION, EMPTY_PATH, context, 'other'));
15327
+ this.variables.set('this', new LocalVariable('this', null, UNDEFINED_EXPRESSION, context, 'other'));
16135
15328
  }
16136
- addDeclaration(identifier, context, init, destructuredInitPath, kind) {
15329
+ addDeclaration(identifier, context, init, kind) {
16137
15330
  if (this.context.module.importDescriptions.has(identifier.name)) {
16138
15331
  context.error(parseAst_js.logRedeclarationError(identifier.name), identifier.start);
16139
15332
  }
16140
- return super.addDeclaration(identifier, context, init, destructuredInitPath, kind);
15333
+ return super.addDeclaration(identifier, context, init, kind);
16141
15334
  }
16142
15335
  addExportDefaultDeclaration(name, exportDefaultDeclaration, context) {
16143
15336
  const variable = new ExportDefaultVariable(name, exportDefaultDeclaration, context);
@@ -16182,23 +15375,10 @@ class ThisExpression extends NodeBase {
16182
15375
  }
16183
15376
  return this.variable.hasEffectsOnInteractionAtPath(path, interaction, context);
16184
15377
  }
16185
- include(context) {
16186
- if (!this.included)
16187
- this.includeNode(context);
16188
- }
16189
- includeNode(context) {
16190
- this.included = true;
16191
- if (!this.deoptimized)
16192
- this.applyDeoptimizations();
16193
- this.scope.context.includeVariableInModule(this.variable, EMPTY_PATH, context);
16194
- }
16195
- includePath(path, context) {
15378
+ include() {
16196
15379
  if (!this.included) {
16197
15380
  this.included = true;
16198
- this.scope.context.includeVariableInModule(this.variable, path, context);
16199
- }
16200
- else if (path.length > 0) {
16201
- this.variable.includePath(path, context);
15381
+ this.scope.context.includeVariableInModule(this.variable);
16202
15382
  }
16203
15383
  }
16204
15384
  initialise() {
@@ -16226,8 +15406,7 @@ class ThrowStatement extends NodeBase {
16226
15406
  return true;
16227
15407
  }
16228
15408
  include(context, includeChildrenRecursively) {
16229
- if (!this.included)
16230
- this.includeNode(context);
15409
+ this.included = true;
16231
15410
  this.argument.include(context, includeChildrenRecursively);
16232
15411
  context.brokenFlow = true;
16233
15412
  }
@@ -16238,7 +15417,6 @@ class ThrowStatement extends NodeBase {
16238
15417
  }
16239
15418
  }
16240
15419
  }
16241
- ThrowStatement.prototype.includeNode = onlyIncludeSelf;
16242
15420
 
16243
15421
  class TryStatement extends NodeBase {
16244
15422
  constructor() {
@@ -16275,8 +15453,6 @@ class TryStatement extends NodeBase {
16275
15453
  this.finalizer?.include(context, includeChildrenRecursively);
16276
15454
  }
16277
15455
  }
16278
- TryStatement.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
16279
- TryStatement.prototype.applyDeoptimizations = doNotDeoptimize;
16280
15456
 
16281
15457
  const unaryOperators = {
16282
15458
  '!': value => !value,
@@ -16287,13 +15463,21 @@ const unaryOperators = {
16287
15463
  void: () => undefined,
16288
15464
  '~': value => ~value
16289
15465
  };
15466
+ const UNASSIGNED = Symbol('Unassigned');
16290
15467
  class UnaryExpression extends NodeBase {
15468
+ constructor() {
15469
+ super(...arguments);
15470
+ this.renderedLiteralValue = UNASSIGNED;
15471
+ }
16291
15472
  get prefix() {
16292
15473
  return isFlagSet(this.flags, 2097152 /* Flag.prefix */);
16293
15474
  }
16294
15475
  set prefix(value) {
16295
15476
  this.flags = setFlag(this.flags, 2097152 /* Flag.prefix */, value);
16296
15477
  }
15478
+ deoptimizeCache() {
15479
+ this.renderedLiteralValue = UnknownValue;
15480
+ }
16297
15481
  getLiteralValueAtPath(path, recursionTracker, origin) {
16298
15482
  if (path.length > 0)
16299
15483
  return UnknownValue;
@@ -16321,8 +15505,60 @@ class UnaryExpression extends NodeBase {
16321
15505
  this.scope.context.requestTreeshakingPass();
16322
15506
  }
16323
15507
  }
15508
+ getRenderedLiteralValue(includeChildrenRecursively) {
15509
+ if (this.renderedLiteralValue !== UNASSIGNED)
15510
+ return this.renderedLiteralValue;
15511
+ return (this.renderedLiteralValue = includeChildrenRecursively
15512
+ ? UnknownValue
15513
+ : getRenderedLiteralValue(this.getLiteralValueAtPath(EMPTY_PATH, SHARED_RECURSION_TRACKER, this)));
15514
+ }
15515
+ include(context, includeChildrenRecursively, _options) {
15516
+ if (!this.deoptimized)
15517
+ this.applyDeoptimizations();
15518
+ this.included = true;
15519
+ if (typeof this.getRenderedLiteralValue(includeChildrenRecursively) === 'symbol' ||
15520
+ this.argument.shouldBeIncluded(context)) {
15521
+ this.argument.include(context, includeChildrenRecursively);
15522
+ this.renderedLiteralValue = UnknownValue;
15523
+ }
15524
+ }
15525
+ render(code, options) {
15526
+ if (typeof this.renderedLiteralValue === 'symbol') {
15527
+ super.render(code, options);
15528
+ }
15529
+ else {
15530
+ let value = this.renderedLiteralValue;
15531
+ if (!CHARACTERS_THAT_DO_NOT_REQUIRE_SPACE.test(code.original[this.start - 1])) {
15532
+ value = ` ${value}`;
15533
+ }
15534
+ code.overwrite(this.start, this.end, value);
15535
+ }
15536
+ }
15537
+ }
15538
+ const CHARACTERS_THAT_DO_NOT_REQUIRE_SPACE = /[\s([=%&*+-/<>^|,?:;]/;
15539
+ function getRenderedLiteralValue(value) {
15540
+ if (value === undefined || typeof value === 'boolean') {
15541
+ return String(value);
15542
+ }
15543
+ if (typeof value === 'string') {
15544
+ return JSON.stringify(value);
15545
+ }
15546
+ if (typeof value === 'number') {
15547
+ return getSimplifiedNumber(value);
15548
+ }
15549
+ return UnknownValue;
15550
+ }
15551
+ function getSimplifiedNumber(value) {
15552
+ if (Object.is(-0, value)) {
15553
+ return '-0';
15554
+ }
15555
+ const exp = value.toExponential();
15556
+ const [base, exponent] = exp.split('e');
15557
+ const floatLength = base.split('.')[1]?.length || 0;
15558
+ const finalizedExp = `${base.replace('.', '')}e${parseInt(exponent) - floatLength}`;
15559
+ const stringifiedValue = String(value).replace('+', '');
15560
+ return finalizedExp.length < stringifiedValue.length ? finalizedExp : stringifiedValue;
16324
15561
  }
16325
- UnaryExpression.prototype.includeNode = onlyIncludeSelf;
16326
15562
 
16327
15563
  class UpdateExpression extends NodeBase {
16328
15564
  hasEffects(context) {
@@ -16334,8 +15570,9 @@ class UpdateExpression extends NodeBase {
16334
15570
  return path.length > 1 || type !== INTERACTION_ACCESSED;
16335
15571
  }
16336
15572
  include(context, includeChildrenRecursively) {
16337
- if (!this.included)
16338
- this.includeNode(context);
15573
+ if (!this.deoptimized)
15574
+ this.applyDeoptimizations();
15575
+ this.included = true;
16339
15576
  this.argument.includeAsAssignmentTarget(context, includeChildrenRecursively, true);
16340
15577
  }
16341
15578
  initialise() {
@@ -16374,7 +15611,6 @@ class UpdateExpression extends NodeBase {
16374
15611
  this.scope.context.requestTreeshakingPass();
16375
15612
  }
16376
15613
  }
16377
- UpdateExpression.prototype.includeNode = onlyIncludeSelf;
16378
15614
 
16379
15615
  function areAllDeclarationsIncludedAndNotExported(declarations, exportNamesByVariable) {
16380
15616
  for (const declarator of declarations) {
@@ -16405,9 +15641,8 @@ class VariableDeclaration extends NodeBase {
16405
15641
  include(context, includeChildrenRecursively, { asSingleStatement } = parseAst_js.BLANK) {
16406
15642
  this.included = true;
16407
15643
  for (const declarator of this.declarations) {
16408
- if (includeChildrenRecursively || declarator.shouldBeIncluded(context)) {
15644
+ if (includeChildrenRecursively || declarator.shouldBeIncluded(context))
16409
15645
  declarator.include(context, includeChildrenRecursively);
16410
- }
16411
15646
  const { id, init } = declarator;
16412
15647
  if (asSingleStatement) {
16413
15648
  id.include(context, includeChildrenRecursively);
@@ -16445,6 +15680,7 @@ class VariableDeclaration extends NodeBase {
16445
15680
  this.renderReplacedDeclarations(code, options);
16446
15681
  }
16447
15682
  }
15683
+ applyDeoptimizations() { }
16448
15684
  renderDeclarationEnd(code, separatorString, lastSeparatorPos, actualContentEnd, renderedContentEnd, systemPatternExports, options) {
16449
15685
  if (code.original.charCodeAt(this.end - 1) === 59 /*";"*/) {
16450
15686
  code.remove(this.end - 1, this.end);
@@ -16487,7 +15723,8 @@ class VariableDeclaration extends NodeBase {
16487
15723
  const singleSystemExport = gatherSystemExportsAndGetSingleExport(separatedNodes, options, aggregatedSystemExports);
16488
15724
  for (const { node, start, separator, contentEnd, end } of separatedNodes) {
16489
15725
  if (!node.included) {
16490
- treeshakeNode(node, code, start, end);
15726
+ code.remove(start, end);
15727
+ node.removeAnnotations(code);
16491
15728
  continue;
16492
15729
  }
16493
15730
  node.render(code, options);
@@ -16557,8 +15794,6 @@ function gatherSystemExportsAndGetSingleExport(separatedNodes, options, aggregat
16557
15794
  }
16558
15795
  return singleSystemExport;
16559
15796
  }
16560
- VariableDeclaration.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
16561
- VariableDeclaration.prototype.applyDeoptimizations = doNotDeoptimize;
16562
15797
 
16563
15798
  class WhileStatement extends NodeBase {
16564
15799
  hasEffects(context) {
@@ -16572,25 +15807,13 @@ class WhileStatement extends NodeBase {
16572
15807
  includeLoopBody(context, this.body, includeChildrenRecursively);
16573
15808
  }
16574
15809
  }
16575
- WhileStatement.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
16576
- WhileStatement.prototype.applyDeoptimizations = doNotDeoptimize;
16577
15810
 
16578
15811
  class YieldExpression extends NodeBase {
16579
- applyDeoptimizations() {
16580
- this.deoptimized = true;
16581
- this.argument?.deoptimizePath(UNKNOWN_PATH);
16582
- }
16583
15812
  hasEffects(context) {
16584
15813
  if (!this.deoptimized)
16585
15814
  this.applyDeoptimizations();
16586
15815
  return !(context.ignore.returnYield && !this.argument?.hasEffects(context));
16587
15816
  }
16588
- includeNode(context) {
16589
- this.included = true;
16590
- if (!this.deoptimized)
16591
- this.applyDeoptimizations();
16592
- this.argument?.includePath(UNKNOWN_PATH, context);
16593
- }
16594
15817
  render(code, options) {
16595
15818
  if (this.argument) {
16596
15819
  this.argument.render(code, options, { preventASI: true });
@@ -16824,7 +16047,7 @@ const bufferParsers = [
16824
16047
  const annotations = (node.annotations = parseAst_js.convertAnnotations(buffer[position + 1], buffer));
16825
16048
  node.annotationNoSideEffects = annotations.some(comment => comment.type === 'noSideEffects');
16826
16049
  const parameters = (node.params = convertNodeList(node, scope, buffer[position + 2], buffer));
16827
- scope.addParameterVariables(parameters.map(parameter => parameter.declare('parameter', EMPTY_PATH, UNKNOWN_EXPRESSION)), parameters[parameters.length - 1] instanceof RestElement);
16050
+ scope.addParameterVariables(parameters.map(parameter => parameter.declare('parameter', UNKNOWN_EXPRESSION)), parameters[parameters.length - 1] instanceof RestElement);
16828
16051
  node.body = convertNode(node, scope.bodyScope, buffer[position + 3], buffer);
16829
16052
  },
16830
16053
  function assignmentExpression(node, position, buffer) {
@@ -16870,7 +16093,7 @@ const bufferParsers = [
16870
16093
  const parameterPosition = buffer[position];
16871
16094
  const parameter = (node.param =
16872
16095
  parameterPosition === 0 ? null : convertNode(node, scope, parameterPosition, buffer));
16873
- parameter?.declare('parameter', EMPTY_PATH, UNKNOWN_EXPRESSION);
16096
+ parameter?.declare('parameter', UNKNOWN_EXPRESSION);
16874
16097
  node.body = convertNode(node, scope.bodyScope, buffer[position + 1], buffer);
16875
16098
  },
16876
16099
  function chainExpression(node, position, buffer) {
@@ -17008,7 +16231,7 @@ const bufferParsers = [
17008
16231
  node.id =
17009
16232
  idPosition === 0 ? null : convertNode(node, scope.parent, idPosition, buffer);
17010
16233
  const parameters = (node.params = convertNodeList(node, scope, buffer[position + 3], buffer));
17011
- scope.addParameterVariables(parameters.map(parameter => parameter.declare('parameter', EMPTY_PATH, UNKNOWN_EXPRESSION)), parameters[parameters.length - 1] instanceof RestElement);
16234
+ scope.addParameterVariables(parameters.map(parameter => parameter.declare('parameter', UNKNOWN_EXPRESSION)), parameters[parameters.length - 1] instanceof RestElement);
17012
16235
  node.body = convertNode(node, scope.bodyScope, buffer[position + 4], buffer);
17013
16236
  },
17014
16237
  function functionExpression(node, position, buffer) {
@@ -17021,7 +16244,7 @@ const bufferParsers = [
17021
16244
  const idPosition = buffer[position + 2];
17022
16245
  node.id = idPosition === 0 ? null : convertNode(node, node.idScope, idPosition, buffer);
17023
16246
  const parameters = (node.params = convertNodeList(node, scope, buffer[position + 3], buffer));
17024
- scope.addParameterVariables(parameters.map(parameter => parameter.declare('parameter', EMPTY_PATH, UNKNOWN_EXPRESSION)), parameters[parameters.length - 1] instanceof RestElement);
16247
+ scope.addParameterVariables(parameters.map(parameter => parameter.declare('parameter', UNKNOWN_EXPRESSION)), parameters[parameters.length - 1] instanceof RestElement);
17025
16248
  node.body = convertNode(node, scope.bodyScope, buffer[position + 4], buffer);
17026
16249
  },
17027
16250
  function identifier(node, position, buffer) {
@@ -17485,8 +16708,8 @@ class ExportShimVariable extends Variable {
17485
16708
  super(MISSING_EXPORT_SHIM_VARIABLE);
17486
16709
  this.module = module;
17487
16710
  }
17488
- includePath(path, context) {
17489
- super.includePath(path, context);
16711
+ include() {
16712
+ super.include();
17490
16713
  this.module.needsExportShim = true;
17491
16714
  }
17492
16715
  }
@@ -18177,15 +17400,16 @@ class Module {
18177
17400
  markModuleAndImpureDependenciesAsExecuted(this);
18178
17401
  this.graph.needsTreeshakingPass = true;
18179
17402
  }
18180
- const inclusionContext = createInclusionContext();
18181
17403
  for (const exportName of this.exports.keys()) {
18182
17404
  if (includeNamespaceMembers || exportName !== this.info.syntheticNamedExports) {
18183
17405
  const variable = this.getVariableForExportName(exportName)[0];
18184
17406
  if (!variable) {
18185
17407
  return parseAst_js.error(parseAst_js.logMissingEntryExport(exportName, this.id));
18186
17408
  }
18187
- this.includeVariable(variable, UNKNOWN_PATH, inclusionContext);
18188
17409
  variable.deoptimizePath(UNKNOWN_PATH);
17410
+ if (!variable.included) {
17411
+ this.includeVariable(variable);
17412
+ }
18189
17413
  }
18190
17414
  }
18191
17415
  for (const name of this.getReexports()) {
@@ -18193,7 +17417,7 @@ class Module {
18193
17417
  if (variable) {
18194
17418
  variable.deoptimizePath(UNKNOWN_PATH);
18195
17419
  if (!variable.included) {
18196
- this.includeVariable(variable, UNKNOWN_PATH, inclusionContext);
17420
+ this.includeVariable(variable);
18197
17421
  }
18198
17422
  if (variable instanceof ExternalVariable) {
18199
17423
  variable.module.reexported = true;
@@ -18214,12 +17438,13 @@ class Module {
18214
17438
  this.graph.needsTreeshakingPass = true;
18215
17439
  }
18216
17440
  let includeNamespaceMembers = false;
18217
- const inclusionContext = createInclusionContext();
18218
17441
  for (const name of names) {
18219
17442
  const variable = this.getVariableForExportName(name)[0];
18220
17443
  if (variable) {
18221
17444
  variable.deoptimizePath(UNKNOWN_PATH);
18222
- this.includeVariable(variable, UNKNOWN_PATH, inclusionContext);
17445
+ if (!variable.included) {
17446
+ this.includeVariable(variable);
17447
+ }
18223
17448
  }
18224
17449
  if (!this.exports.has(name) && !this.reexportDescriptions.has(name)) {
18225
17450
  includeNamespaceMembers = true;
@@ -18320,7 +17545,6 @@ class Module {
18320
17545
  manualPureFunctions: this.graph.pureFunctions,
18321
17546
  module: this,
18322
17547
  moduleContext: this.context,
18323
- newlyIncludedVariableInits: this.graph.newlyIncludedVariableInits,
18324
17548
  options: this.options,
18325
17549
  requestTreeshakingPass: () => (this.graph.needsTreeshakingPass = true),
18326
17550
  traceExport: (name) => this.getVariableForExportName(name)[0],
@@ -18661,13 +17885,13 @@ class Module {
18661
17885
  for (const module of [this, ...this.exportAllModules]) {
18662
17886
  if (module instanceof ExternalModule) {
18663
17887
  const [externalVariable] = module.getVariableForExportName('*');
18664
- externalVariable.includePath(UNKNOWN_PATH, createInclusionContext());
17888
+ externalVariable.include();
18665
17889
  this.includedImports.add(externalVariable);
18666
17890
  externalNamespaces.add(externalVariable);
18667
17891
  }
18668
17892
  else if (module.info.syntheticNamedExports) {
18669
17893
  const syntheticNamespace = module.getSyntheticNamespace();
18670
- syntheticNamespace.includePath(UNKNOWN_PATH, createInclusionContext());
17894
+ syntheticNamespace.include();
18671
17895
  this.includedImports.add(syntheticNamespace);
18672
17896
  syntheticNamespaces.add(syntheticNamespace);
18673
17897
  }
@@ -18677,9 +17901,7 @@ class Module {
18677
17901
  includeDynamicImport(node) {
18678
17902
  const resolution = this.dynamicImports.find(dynamicImport => dynamicImport.node === node).resolution;
18679
17903
  if (resolution instanceof Module) {
18680
- if (!resolution.includedDynamicImporters.includes(this)) {
18681
- resolution.includedDynamicImporters.push(this);
18682
- }
17904
+ resolution.includedDynamicImporters.push(this);
18683
17905
  const importedNames = this.options.treeshake
18684
17906
  ? node.getDeterministicImportedNames()
18685
17907
  : undefined;
@@ -18691,15 +17913,15 @@ class Module {
18691
17913
  }
18692
17914
  }
18693
17915
  }
18694
- includeVariable(variable, path, context) {
18695
- const { included, module: variableModule } = variable;
18696
- variable.includePath(path, context);
18697
- if (included) {
17916
+ includeVariable(variable) {
17917
+ const variableModule = variable.module;
17918
+ if (variable.included) {
18698
17919
  if (variableModule instanceof Module && variableModule !== this) {
18699
17920
  getAndExtendSideEffectModules(variable, this);
18700
17921
  }
18701
17922
  }
18702
17923
  else {
17924
+ variable.include();
18703
17925
  this.graph.needsTreeshakingPass = true;
18704
17926
  if (variableModule instanceof Module) {
18705
17927
  if (!variableModule.isExecuted) {
@@ -18716,8 +17938,8 @@ class Module {
18716
17938
  }
18717
17939
  }
18718
17940
  }
18719
- includeVariableInModule(variable, path, context) {
18720
- this.includeVariable(variable, path, context);
17941
+ includeVariableInModule(variable) {
17942
+ this.includeVariable(variable);
18721
17943
  const variableModule = variable.module;
18722
17944
  if (variableModule && variableModule !== this) {
18723
17945
  this.includedImports.add(variable);
@@ -19654,7 +18876,9 @@ class Chunk {
19654
18876
  }
19655
18877
  return [
19656
18878
  resolution || '',
19657
- (this.outputOptions.format === 'es' && this.outputOptions.externalImportAttributes) || null
18879
+ (['es', 'cjs'].includes(this.outputOptions.format) &&
18880
+ this.outputOptions.externalImportAttributes) ||
18881
+ null
19658
18882
  ];
19659
18883
  }
19660
18884
  getFallbackChunkName() {
@@ -21487,18 +20711,18 @@ function flru (max) {
21487
20711
  return {
21488
20712
  clear: reset,
21489
20713
  has: function (key) {
21490
- return curr[key] !== void 0 || prev[key] !== void 0;
20714
+ return curr[key] !== undefined || prev[key] !== undefined;
21491
20715
  },
21492
20716
  get: function (key) {
21493
20717
  var val = curr[key];
21494
- if (val !== void 0) return val;
21495
- if ((val=prev[key]) !== void 0) {
20718
+ if (val !== undefined) return val;
20719
+ if ((val=prev[key]) !== undefined) {
21496
20720
  keep(key, val);
21497
20721
  return val;
21498
20722
  }
21499
20723
  },
21500
20724
  set: function (key, value) {
21501
- if (curr[key] !== void 0) {
20725
+ if (curr[key] !== undefined) {
21502
20726
  curr[key] = value;
21503
20727
  } else {
21504
20728
  keep(key, value);
@@ -22220,11 +21444,10 @@ class Graph {
22220
21444
  this.options = options;
22221
21445
  this.astLru = flru(5);
22222
21446
  this.cachedModules = new Map();
22223
- this.deoptimizationTracker = new EntityPathTracker();
21447
+ this.deoptimizationTracker = new PathTracker();
22224
21448
  this.entryModules = [];
22225
21449
  this.modulesById = new Map();
22226
21450
  this.needsTreeshakingPass = false;
22227
- this.newlyIncludedVariableInits = new Set();
22228
21451
  this.phase = BuildPhase.LOAD_AND_PARSE;
22229
21452
  this.scope = new GlobalScope();
22230
21453
  this.watchFiles = Object.create(null);
@@ -22318,7 +21541,6 @@ class Graph {
22318
21541
  }
22319
21542
  if (this.options.treeshake) {
22320
21543
  let treeshakingPass = 1;
22321
- this.newlyIncludedVariableInits.clear();
22322
21544
  do {
22323
21545
  timeStart(`treeshaking pass ${treeshakingPass}`, 3);
22324
21546
  this.needsTreeshakingPass = false;
@@ -22343,10 +21565,6 @@ class Graph {
22343
21565
  }
22344
21566
  }
22345
21567
  }
22346
- for (const entity of this.newlyIncludedVariableInits) {
22347
- this.newlyIncludedVariableInits.delete(entity);
22348
- entity.include(createInclusionContext(), false);
22349
- }
22350
21568
  timeEnd(`treeshaking pass ${treeshakingPass++}`, 3);
22351
21569
  } while (this.needsTreeshakingPass);
22352
21570
  }
@@ -23072,12 +22290,10 @@ function defineConfig(options) {
23072
22290
  return options;
23073
22291
  }
23074
22292
 
23075
- exports.blue = blue;
23076
22293
  exports.bold = bold;
23077
22294
  exports.commandAliases = commandAliases;
23078
22295
  exports.createFilter = createFilter;
23079
- exports.cyan = cyan$1;
23080
- exports.cyan$1 = cyan;
22296
+ exports.cyan = cyan;
23081
22297
  exports.defineConfig = defineConfig;
23082
22298
  exports.ensureArray = ensureArray$1;
23083
22299
  exports.getAugmentedNamespace = getAugmentedNamespace;
@@ -23090,6 +22306,7 @@ exports.handleError = handleError;
23090
22306
  exports.isWatchEnabled = isWatchEnabled;
23091
22307
  exports.mergeOptions = mergeOptions;
23092
22308
  exports.normalizePluginOption = normalizePluginOption;
22309
+ exports.pc = pc;
23093
22310
  exports.rollup = rollup;
23094
22311
  exports.rollupInternal = rollupInternal;
23095
22312
  exports.stderr = stderr;