@rollup/wasm-node 4.30.0-0 → 4.30.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,7 +1,7 @@
1
1
  /*
2
2
  @license
3
- Rollup.js v4.30.0-0
4
- Sat, 21 Dec 2024 07:16:43 GMT - commit 2339f1d8384a8999645823f83f9042a9fc7b3bf7
3
+ Rollup.js v4.30.0
4
+ Mon, 06 Jan 2025 06:36:11 GMT - commit 958d5ebabd49297e9a4b78ad34ac0a0132305dea
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-0";
20
+ var version = "4.30.0";
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);
@@ -5003,38 +4929,9 @@ class ObjectEntity extends ExpressionEntity {
5003
4929
  }
5004
4930
  return false;
5005
4931
  }
5006
- include(context, includeChildrenRecursively) {
5007
- this.included = true;
5008
- for (const property of this.allProperties) {
5009
- if (includeChildrenRecursively || property.shouldBeIncluded(context)) {
5010
- property.include(context, includeChildrenRecursively);
5011
- }
5012
- }
5013
- this.prototypeExpression?.include(context, includeChildrenRecursively);
5014
- }
5015
- includePath(path, context) {
5016
- this.included = true;
5017
- if (path.length === 0)
5018
- return;
5019
- const [key, ...subPath] = path;
5020
- const [includedMembers, includedPath] = typeof key === 'string'
5021
- ? [
5022
- [
5023
- ...new Set([
5024
- ...(this.propertiesAndGettersByKey[key] || this.unmatchablePropertiesAndGetters),
5025
- ...(this.propertiesAndSettersByKey[key] || this.unmatchablePropertiesAndSetters)
5026
- ])
5027
- ],
5028
- subPath
5029
- ]
5030
- : [this.allProperties, UNKNOWN_PATH];
5031
- for (const property of includedMembers) {
5032
- property.includePath(includedPath, context);
5033
- }
5034
- this.prototypeExpression?.includePath(path, context);
5035
- }
5036
4932
  buildPropertyMaps(properties) {
5037
- 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 = [];
5038
4935
  for (let index = properties.length - 1; index >= 0; index--) {
5039
4936
  const { key, kind, property } = properties[index];
5040
4937
  allProperties.push(property);
@@ -5304,37 +5201,6 @@ const ARRAY_PROTOTYPE = new ObjectEntity({
5304
5201
  values: METHOD_DEOPTS_SELF_RETURNS_UNKNOWN
5305
5202
  }, OBJECT_PROTOTYPE, true);
5306
5203
 
5307
- class SpreadElement extends NodeBase {
5308
- deoptimizeArgumentsOnInteractionAtPath(interaction, path, recursionTracker) {
5309
- if (path.length > 0) {
5310
- this.argument.deoptimizeArgumentsOnInteractionAtPath(interaction, UNKNOWN_PATH, recursionTracker);
5311
- }
5312
- }
5313
- hasEffects(context) {
5314
- if (!this.deoptimized)
5315
- this.applyDeoptimizations();
5316
- const { propertyReadSideEffects } = this.scope.context.options
5317
- .treeshake;
5318
- return (this.argument.hasEffects(context) ||
5319
- (propertyReadSideEffects &&
5320
- (propertyReadSideEffects === 'always' ||
5321
- this.argument.hasEffectsOnInteractionAtPath(UNKNOWN_PATH, NODE_INTERACTION_UNKNOWN_ACCESS, context))));
5322
- }
5323
- includeNode(context) {
5324
- this.included = true;
5325
- if (!this.deoptimized)
5326
- this.applyDeoptimizations();
5327
- this.argument.includePath(UNKNOWN_PATH, context);
5328
- }
5329
- applyDeoptimizations() {
5330
- this.deoptimized = true;
5331
- // Only properties of properties of the argument could become subject to reassignment
5332
- // This will also reassign the return values of iterators
5333
- this.argument.deoptimizePath([UnknownKey, UnknownKey]);
5334
- this.scope.context.requestTreeshakingPass();
5335
- }
5336
- }
5337
-
5338
5204
  class ArrayExpression extends NodeBase {
5339
5205
  constructor() {
5340
5206
  super(...arguments);
@@ -5355,16 +5221,6 @@ class ArrayExpression extends NodeBase {
5355
5221
  hasEffectsOnInteractionAtPath(path, interaction, context) {
5356
5222
  return this.getObjectEntity().hasEffectsOnInteractionAtPath(path, interaction, context);
5357
5223
  }
5358
- includeNode(context) {
5359
- this.included = true;
5360
- if (!this.deoptimized)
5361
- this.applyDeoptimizations();
5362
- for (const element of this.elements) {
5363
- if (element) {
5364
- element?.includePath(UNKNOWN_PATH, context);
5365
- }
5366
- }
5367
- }
5368
5224
  applyDeoptimizations() {
5369
5225
  this.deoptimized = true;
5370
5226
  let hasSpread = false;
@@ -6432,37 +6288,17 @@ class GlobalVariable extends Variable {
6432
6288
  }
6433
6289
  }
6434
6290
 
6435
- // To avoid infinite recursions
6436
- const MAX_PATH_DEPTH = 6;
6437
- // If a path is longer than MAX_PATH_DEPTH, it is truncated so that it is at
6438
- // most MAX_PATH_DEPTH long. The last element is always UnknownKey
6439
- const limitConcatenatedPathDepth = (path1, path2) => {
6440
- const { length: length1 } = path1;
6441
- const { length: length2 } = path2;
6442
- return length1 === 0
6443
- ? path2
6444
- : length2 === 0
6445
- ? path1
6446
- : length1 + length2 > MAX_PATH_DEPTH
6447
- ? [...path1, ...path2.slice(0, MAX_PATH_DEPTH - 1 - path1.length), 'UnknownKey']
6448
- : [...path1, ...path2];
6449
- };
6450
-
6451
6291
  class LocalVariable extends Variable {
6452
- constructor(name, declarator, init,
6453
- /** if this is non-empty, the actual init is this path of this.init */
6454
- initPath, context, kind) {
6292
+ constructor(name, declarator, init, context, kind) {
6455
6293
  super(name);
6456
6294
  this.init = init;
6457
- this.initPath = initPath;
6458
- this.kind = kind;
6459
6295
  this.calledFromTryStatement = false;
6460
6296
  this.additionalInitializers = null;
6461
- this.includedPathTracker = new IncludedPathTracker();
6462
6297
  this.expressionsToBeDeoptimized = [];
6463
6298
  this.declarations = declarator ? [declarator] : [];
6464
6299
  this.deoptimizationTracker = context.deoptimizationTracker;
6465
6300
  this.module = context.module;
6301
+ this.kind = kind;
6466
6302
  }
6467
6303
  addDeclaration(identifier, init) {
6468
6304
  this.declarations.push(identifier);
@@ -6473,16 +6309,15 @@ class LocalVariable extends Variable {
6473
6309
  for (const initializer of this.additionalInitializers) {
6474
6310
  initializer.deoptimizePath(UNKNOWN_PATH);
6475
6311
  }
6312
+ this.additionalInitializers = null;
6476
6313
  }
6477
6314
  }
6478
6315
  deoptimizeArgumentsOnInteractionAtPath(interaction, path, recursionTracker) {
6479
- if (this.isReassigned || path.length + this.initPath.length > MAX_PATH_DEPTH) {
6316
+ if (this.isReassigned) {
6480
6317
  deoptimizeInteraction(interaction);
6481
6318
  return;
6482
6319
  }
6483
- recursionTracker.withTrackedEntityAtPath(path, this.init, () => {
6484
- this.init.deoptimizeArgumentsOnInteractionAtPath(interaction, [...this.initPath, ...path], recursionTracker);
6485
- }, undefined);
6320
+ recursionTracker.withTrackedEntityAtPath(path, this.init, () => this.init.deoptimizeArgumentsOnInteractionAtPath(interaction, path, recursionTracker), undefined);
6486
6321
  }
6487
6322
  deoptimizePath(path) {
6488
6323
  if (this.isReassigned ||
@@ -6496,40 +6331,37 @@ class LocalVariable extends Variable {
6496
6331
  for (const expression of expressionsToBeDeoptimized) {
6497
6332
  expression.deoptimizeCache();
6498
6333
  }
6499
- this.init.deoptimizePath([...this.initPath, UnknownKey]);
6334
+ this.init.deoptimizePath(UNKNOWN_PATH);
6500
6335
  }
6501
6336
  else {
6502
- this.init.deoptimizePath(limitConcatenatedPathDepth(this.initPath, path));
6337
+ this.init.deoptimizePath(path);
6503
6338
  }
6504
6339
  }
6505
6340
  getLiteralValueAtPath(path, recursionTracker, origin) {
6506
- if (this.isReassigned || path.length + this.initPath.length > MAX_PATH_DEPTH) {
6341
+ if (this.isReassigned) {
6507
6342
  return UnknownValue;
6508
6343
  }
6509
6344
  return recursionTracker.withTrackedEntityAtPath(path, this.init, () => {
6510
6345
  this.expressionsToBeDeoptimized.push(origin);
6511
- return this.init.getLiteralValueAtPath([...this.initPath, ...path], recursionTracker, origin);
6346
+ return this.init.getLiteralValueAtPath(path, recursionTracker, origin);
6512
6347
  }, UnknownValue);
6513
6348
  }
6514
6349
  getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin) {
6515
- if (this.isReassigned || path.length + this.initPath.length > MAX_PATH_DEPTH) {
6350
+ if (this.isReassigned) {
6516
6351
  return UNKNOWN_RETURN_EXPRESSION;
6517
6352
  }
6518
6353
  return recursionTracker.withTrackedEntityAtPath(path, this.init, () => {
6519
6354
  this.expressionsToBeDeoptimized.push(origin);
6520
- return this.init.getReturnExpressionWhenCalledAtPath([...this.initPath, ...path], interaction, recursionTracker, origin);
6355
+ return this.init.getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin);
6521
6356
  }, UNKNOWN_RETURN_EXPRESSION);
6522
6357
  }
6523
6358
  hasEffectsOnInteractionAtPath(path, interaction, context) {
6524
- if (path.length + this.initPath.length > MAX_PATH_DEPTH) {
6525
- return true;
6526
- }
6527
6359
  switch (interaction.type) {
6528
6360
  case INTERACTION_ACCESSED: {
6529
6361
  if (this.isReassigned)
6530
6362
  return true;
6531
6363
  return (!context.accessed.trackEntityAtPathAndGetIfTracked(path, this) &&
6532
- this.init.hasEffectsOnInteractionAtPath([...this.initPath, ...path], interaction, context));
6364
+ this.init.hasEffectsOnInteractionAtPath(path, interaction, context));
6533
6365
  }
6534
6366
  case INTERACTION_ASSIGNED: {
6535
6367
  if (this.included)
@@ -6539,63 +6371,44 @@ class LocalVariable extends Variable {
6539
6371
  if (this.isReassigned)
6540
6372
  return true;
6541
6373
  return (!context.assigned.trackEntityAtPathAndGetIfTracked(path, this) &&
6542
- this.init.hasEffectsOnInteractionAtPath([...this.initPath, ...path], interaction, context));
6374
+ this.init.hasEffectsOnInteractionAtPath(path, interaction, context));
6543
6375
  }
6544
6376
  case INTERACTION_CALLED: {
6545
6377
  if (this.isReassigned)
6546
6378
  return true;
6547
6379
  return (!(interaction.withNew ? context.instantiated : context.called).trackEntityAtPathAndGetIfTracked(path, interaction.args, this) &&
6548
- this.init.hasEffectsOnInteractionAtPath([...this.initPath, ...path], interaction, context));
6380
+ this.init.hasEffectsOnInteractionAtPath(path, interaction, context));
6549
6381
  }
6550
6382
  }
6551
6383
  }
6552
- includePath(path, context) {
6553
- if (!this.includedPathTracker.includePathAndGetIfIncluded(path)) {
6554
- this.module.scope.context.requestTreeshakingPass();
6555
- if (!this.included) {
6556
- // This will reduce the number of tree-shaking passes by eagerly
6557
- // including inits. By pushing this here instead of directly including
6558
- // we avoid deep call stacks.
6559
- this.module.scope.context.newlyIncludedVariableInits.add(this.init);
6560
- }
6561
- super.includePath(path, context);
6384
+ include() {
6385
+ if (!this.included) {
6386
+ super.include();
6562
6387
  for (const declaration of this.declarations) {
6563
6388
  // If node is a default export, it can save a tree-shaking run to include the full declaration now
6564
6389
  if (!declaration.included)
6565
- declaration.include(context, false);
6390
+ declaration.include(createInclusionContext(), false);
6566
6391
  let node = declaration.parent;
6567
6392
  while (!node.included) {
6568
6393
  // We do not want to properly include parents in case they are part of a dead branch
6569
6394
  // in which case .include() might pull in more dead code
6570
- node.includeNode(context);
6395
+ node.included = true;
6571
6396
  if (node.type === parseAst_js.Program)
6572
6397
  break;
6573
6398
  node = node.parent;
6574
6399
  }
6575
6400
  }
6576
- // We need to make sure we include the correct path of the init
6577
- if (path.length > 0) {
6578
- this.init.includePath(limitConcatenatedPathDepth(this.initPath, path), context);
6579
- this.additionalInitializers?.forEach(initializer => initializer.includePath(UNKNOWN_PATH, context));
6580
- }
6581
6401
  }
6582
6402
  }
6583
- includeCallArguments(context, interaction) {
6584
- if (this.isReassigned ||
6585
- context.includedCallArguments.has(this.init) ||
6586
- // This can be removed again once we can include arguments when called at
6587
- // a specific path
6588
- this.initPath.length > 0) {
6589
- for (const argument of interaction.args) {
6590
- if (argument) {
6591
- argument.includePath(UNKNOWN_PATH, context);
6592
- argument.include(context, false);
6593
- }
6403
+ includeCallArguments(context, parameters) {
6404
+ if (this.isReassigned || context.includedCallArguments.has(this.init)) {
6405
+ for (const argument of parameters) {
6406
+ argument.include(context, false);
6594
6407
  }
6595
6408
  }
6596
6409
  else {
6597
6410
  context.includedCallArguments.add(this.init);
6598
- this.init.includeCallArguments(context, interaction);
6411
+ this.init.includeCallArguments(context, parameters);
6599
6412
  context.includedCallArguments.delete(this.init);
6600
6413
  }
6601
6414
  }
@@ -6675,31 +6488,18 @@ class IdentifierBase extends NodeBase {
6675
6488
  }
6676
6489
  }
6677
6490
  }
6678
- include(context) {
6679
- if (!this.included)
6680
- this.includeNode(context);
6681
- }
6682
- includeNode(context) {
6683
- this.included = true;
6491
+ include() {
6684
6492
  if (!this.deoptimized)
6685
6493
  this.applyDeoptimizations();
6686
- if (this.variable !== null) {
6687
- this.scope.context.includeVariableInModule(this.variable, EMPTY_PATH, context);
6688
- }
6689
- }
6690
- includePath(path, context) {
6691
6494
  if (!this.included) {
6692
6495
  this.included = true;
6693
6496
  if (this.variable !== null) {
6694
- this.scope.context.includeVariableInModule(this.variable, path, context);
6497
+ this.scope.context.includeVariableInModule(this.variable);
6695
6498
  }
6696
6499
  }
6697
- else if (path.length > 0) {
6698
- this.variable?.includePath(path, context);
6699
- }
6700
6500
  }
6701
- includeCallArguments(context, interaction) {
6702
- this.variable.includeCallArguments(context, interaction);
6501
+ includeCallArguments(context, parameters) {
6502
+ this.variable.includeCallArguments(context, parameters);
6703
6503
  }
6704
6504
  isPossibleTDZ() {
6705
6505
  // return cached value to avoid issues with the next tree-shaking pass
@@ -6782,40 +6582,11 @@ function closestParentFunctionOrProgram(node) {
6782
6582
  return node;
6783
6583
  }
6784
6584
 
6785
- class ObjectMember extends ExpressionEntity {
6786
- constructor(object, path) {
6787
- super();
6788
- this.object = object;
6789
- this.path = path;
6790
- }
6791
- deoptimizeArgumentsOnInteractionAtPath(interaction, path, recursionTracker) {
6792
- this.object.deoptimizeArgumentsOnInteractionAtPath(interaction, [...this.path, ...path], recursionTracker);
6793
- }
6794
- deoptimizePath(path) {
6795
- this.object.deoptimizePath([...this.path, ...path]);
6796
- }
6797
- getLiteralValueAtPath(path, recursionTracker, origin) {
6798
- return this.object.getLiteralValueAtPath([...this.path, ...path], recursionTracker, origin);
6799
- }
6800
- getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin) {
6801
- return this.object.getReturnExpressionWhenCalledAtPath([...this.path, ...path], interaction, recursionTracker, origin);
6802
- }
6803
- hasEffectsOnInteractionAtPath(path, interaction, context) {
6804
- return this.object.hasEffectsOnInteractionAtPath([...this.path, ...path], interaction, context);
6805
- }
6806
- }
6807
-
6808
6585
  class Identifier extends IdentifierBase {
6809
6586
  constructor() {
6810
6587
  super(...arguments);
6811
6588
  this.variable = null;
6812
6589
  }
6813
- get isDestructuringDeoptimized() {
6814
- return isFlagSet(this.flags, 16777216 /* Flag.destructuringDeoptimized */);
6815
- }
6816
- set isDestructuringDeoptimized(value) {
6817
- this.flags = setFlag(this.flags, 16777216 /* Flag.destructuringDeoptimized */, value);
6818
- }
6819
6590
  addExportedVariables(variables, exportNamesByVariable) {
6820
6591
  if (exportNamesByVariable.has(this.variable)) {
6821
6592
  variables.push(this.variable);
@@ -6828,52 +6599,42 @@ class Identifier extends IdentifierBase {
6828
6599
  this.isVariableReference = true;
6829
6600
  }
6830
6601
  }
6831
- declare(kind, destructuredInitPath, init) {
6602
+ declare(kind, init) {
6832
6603
  let variable;
6833
6604
  const { treeshake } = this.scope.context.options;
6834
- if (kind === 'parameter') {
6835
- variable = this.scope.addParameterDeclaration(this, destructuredInitPath);
6836
- }
6837
- else {
6838
- variable = this.scope.addDeclaration(this, this.scope.context, init, destructuredInitPath, kind);
6839
- if (kind === 'var' && treeshake && treeshake.correctVarValueBeforeDeclaration) {
6840
- // Necessary to make sure the init is deoptimized. We cannot call deoptimizePath here.
6841
- 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;
6842
6613
  }
6843
- }
6844
- return [(this.variable = variable)];
6845
- }
6846
- deoptimizeAssignment(destructuredInitPath, init) {
6847
- this.deoptimizePath(EMPTY_PATH);
6848
- init.deoptimizePath([...destructuredInitPath, UnknownKey]);
6849
- }
6850
- hasEffectsWhenDestructuring(context, destructuredInitPath, init) {
6851
- return (destructuredInitPath.length > 0 &&
6852
- init.hasEffectsOnInteractionAtPath(destructuredInitPath, NODE_INTERACTION_UNKNOWN_ACCESS, context));
6853
- }
6854
- includeDestructuredIfNecessary(context, destructuredInitPath, init) {
6855
- if (destructuredInitPath.length > 0 && !this.isDestructuringDeoptimized) {
6856
- this.isDestructuringDeoptimized = true;
6857
- init.deoptimizeArgumentsOnInteractionAtPath({
6858
- args: [new ObjectMember(init, destructuredInitPath.slice(0, -1))],
6859
- type: INTERACTION_ACCESSED
6860
- }, destructuredInitPath, SHARED_RECURSION_TRACKER);
6861
- }
6862
- const { propertyReadSideEffects } = this.scope.context.options
6863
- .treeshake;
6864
- if ((this.included ||=
6865
- destructuredInitPath.length > 0 &&
6866
- !context.brokenFlow &&
6867
- propertyReadSideEffects &&
6868
- (propertyReadSideEffects === 'always' ||
6869
- init.hasEffectsOnInteractionAtPath(destructuredInitPath, NODE_INTERACTION_UNKNOWN_ACCESS, createHasEffectsContext())))) {
6870
- if (this.variable && !this.variable.included) {
6871
- 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}.`);
6872
6635
  }
6873
- init.includePath(destructuredInitPath, context);
6874
- return true;
6875
6636
  }
6876
- return false;
6637
+ return [(this.variable = variable)];
6877
6638
  }
6878
6639
  markDeclarationReached() {
6879
6640
  this.variable.initReached = true;
@@ -6927,17 +6688,18 @@ class Scope {
6927
6688
  - then the variable is still declared in the hoisted outer scope, but the initializer is assigned to the parameter
6928
6689
  - const, let, class, and function except in the cases above cannot redeclare anything
6929
6690
  */
6930
- addDeclaration(identifier, context, init, destructuredInitPath, kind) {
6691
+ addDeclaration(identifier, context, init, kind) {
6931
6692
  const name = identifier.name;
6932
6693
  const existingVariable = this.hoistedVariables?.get(name) || this.variables.get(name);
6933
6694
  if (existingVariable) {
6934
- if (kind === 'var' && existingVariable.kind === 'var') {
6695
+ const existingKind = existingVariable.kind;
6696
+ if (kind === 'var' && existingKind === 'var') {
6935
6697
  existingVariable.addDeclaration(identifier, init);
6936
6698
  return existingVariable;
6937
6699
  }
6938
6700
  context.error(parseAst_js.logRedeclarationError(name), identifier.start);
6939
6701
  }
6940
- const newVariable = new LocalVariable(identifier.name, identifier, init, destructuredInitPath, context, kind);
6702
+ const newVariable = new LocalVariable(identifier.name, identifier, init, context, kind);
6941
6703
  this.variables.set(name, newVariable);
6942
6704
  return newVariable;
6943
6705
  }
@@ -7113,6 +6875,7 @@ class MethodBase extends NodeBase {
7113
6875
  }
7114
6876
  return this.getAccessedValue()[0].hasEffectsOnInteractionAtPath(path, interaction, context);
7115
6877
  }
6878
+ applyDeoptimizations() { }
7116
6879
  getAccessedValue() {
7117
6880
  if (this.accessedValue === null) {
7118
6881
  if (this.kind === 'get') {
@@ -7126,20 +6889,19 @@ class MethodBase extends NodeBase {
7126
6889
  return this.accessedValue;
7127
6890
  }
7128
6891
  }
7129
- MethodBase.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
7130
- MethodBase.prototype.applyDeoptimizations = doNotDeoptimize;
7131
6892
 
7132
6893
  class MethodDefinition extends MethodBase {
7133
6894
  hasEffects(context) {
7134
6895
  return super.hasEffects(context) || checkEffectForNodes(this.decorators, context);
7135
6896
  }
6897
+ applyDeoptimizations() { }
7136
6898
  }
7137
6899
 
7138
6900
  class BlockScope extends ChildScope {
7139
6901
  constructor(parent) {
7140
6902
  super(parent, parent.context);
7141
6903
  }
7142
- addDeclaration(identifier, context, init, destructuredInitPath, kind) {
6904
+ addDeclaration(identifier, context, init, kind) {
7143
6905
  if (kind === 'var') {
7144
6906
  const name = identifier.name;
7145
6907
  const existingVariable = this.hoistedVariables?.get(name) || this.variables.get(name);
@@ -7151,7 +6913,7 @@ class BlockScope extends ChildScope {
7151
6913
  }
7152
6914
  return context.error(parseAst_js.logRedeclarationError(name), identifier.start);
7153
6915
  }
7154
- const declaredVariable = this.parent.addDeclaration(identifier, context, init, destructuredInitPath, kind);
6916
+ const declaredVariable = this.parent.addDeclaration(identifier, context, init, kind);
7155
6917
  // Necessary to make sure the init is deoptimized for conditional declarations.
7156
6918
  // We cannot call deoptimizePath here.
7157
6919
  declaredVariable.markInitializersForDeoptimization();
@@ -7159,7 +6921,7 @@ class BlockScope extends ChildScope {
7159
6921
  this.addHoistedVariable(name, declaredVariable);
7160
6922
  return declaredVariable;
7161
6923
  }
7162
- return super.addDeclaration(identifier, context, init, destructuredInitPath, kind);
6924
+ return super.addDeclaration(identifier, context, init, kind);
7163
6925
  }
7164
6926
  }
7165
6927
 
@@ -7191,11 +6953,32 @@ class StaticBlock extends NodeBase {
7191
6953
  }
7192
6954
  }
7193
6955
  }
7194
- StaticBlock.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
7195
- StaticBlock.prototype.applyDeoptimizations = doNotDeoptimize;
7196
- function isStaticBlock(statement) {
7197
- return statement.type === parseAst_js.StaticBlock;
7198
- }
6956
+ function isStaticBlock(statement) {
6957
+ return statement.type === parseAst_js.StaticBlock;
6958
+ }
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
+ }
7199
6982
 
7200
6983
  class ClassNode extends NodeBase {
7201
6984
  constructor() {
@@ -7237,20 +7020,21 @@ class ClassNode extends NodeBase {
7237
7020
  : this.getObjectEntity().hasEffectsOnInteractionAtPath(path, interaction, context);
7238
7021
  }
7239
7022
  include(context, includeChildrenRecursively) {
7240
- if (!this.included)
7241
- this.includeNode(context);
7023
+ if (!this.deoptimized)
7024
+ this.applyDeoptimizations();
7025
+ this.included = true;
7242
7026
  this.superClass?.include(context, includeChildrenRecursively);
7243
7027
  this.body.include(context, includeChildrenRecursively);
7244
7028
  for (const decorator of this.decorators)
7245
7029
  decorator.include(context, includeChildrenRecursively);
7246
7030
  if (this.id) {
7247
7031
  this.id.markDeclarationReached();
7248
- this.id.include(context);
7032
+ this.id.include();
7249
7033
  }
7250
7034
  }
7251
7035
  initialise() {
7252
7036
  super.initialise();
7253
- this.id?.declare('class', EMPTY_PATH, this);
7037
+ this.id?.declare('class', this);
7254
7038
  for (const method of this.body.body) {
7255
7039
  if (method instanceof MethodDefinition && method.kind === 'constructor') {
7256
7040
  this.classConstructor = method;
@@ -7308,12 +7092,11 @@ class ClassNode extends NodeBase {
7308
7092
  staticProperties.unshift({
7309
7093
  key: 'prototype',
7310
7094
  kind: 'init',
7311
- 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)
7312
7096
  });
7313
7097
  return (this.objectEntity = new ObjectEntity(staticProperties, this.superClass || OBJECT_PROTOTYPE));
7314
7098
  }
7315
7099
  }
7316
- ClassNode.prototype.includeNode = onlyIncludeSelf;
7317
7100
 
7318
7101
  class ClassDeclaration extends ClassNode {
7319
7102
  initialise() {
@@ -7366,7 +7149,7 @@ class ClassDeclaration extends ClassNode {
7366
7149
 
7367
7150
  class ArgumentsVariable extends LocalVariable {
7368
7151
  constructor(context) {
7369
- super('arguments', null, UNKNOWN_EXPRESSION, EMPTY_PATH, context, 'other');
7152
+ super('arguments', null, UNKNOWN_EXPRESSION, context, 'other');
7370
7153
  this.deoptimizedArguments = [];
7371
7154
  }
7372
7155
  addArgumentToBeDeoptimized(argument) {
@@ -7380,8 +7163,8 @@ class ArgumentsVariable extends LocalVariable {
7380
7163
  hasEffectsOnInteractionAtPath(path, { type }) {
7381
7164
  return type !== INTERACTION_ACCESSED || path.length > 1;
7382
7165
  }
7383
- includePath(path, context) {
7384
- super.includePath(path, context);
7166
+ include() {
7167
+ super.include();
7385
7168
  for (const argument of this.deoptimizedArguments) {
7386
7169
  argument.deoptimizePath(UNKNOWN_PATH);
7387
7170
  }
@@ -7392,28 +7175,27 @@ class ArgumentsVariable extends LocalVariable {
7392
7175
  const MAX_TRACKED_INTERACTIONS = 20;
7393
7176
  const NO_INTERACTIONS = parseAst_js.EMPTY_ARRAY;
7394
7177
  const UNKNOWN_DEOPTIMIZED_FIELD = new Set([UnknownKey]);
7395
- const EMPTY_PATH_TRACKER = new EntityPathTracker();
7178
+ const EMPTY_PATH_TRACKER = new PathTracker();
7396
7179
  const UNKNOWN_DEOPTIMIZED_ENTITY = new Set([UNKNOWN_EXPRESSION]);
7397
7180
  class ParameterVariable extends LocalVariable {
7398
- constructor(name, declarator, argumentPath, context) {
7399
- super(name, declarator, UNKNOWN_EXPRESSION, argumentPath, context, 'parameter');
7181
+ constructor(name, declarator, context) {
7182
+ super(name, declarator, UNKNOWN_EXPRESSION, context, 'parameter');
7400
7183
  this.deoptimizationInteractions = [];
7401
- this.deoptimizations = new EntityPathTracker();
7184
+ this.deoptimizations = new PathTracker();
7402
7185
  this.deoptimizedFields = new Set();
7403
- this.argumentsToBeDeoptimized = new Set();
7404
- this.expressionsDependingOnKnownValue = [];
7186
+ this.entitiesToBeDeoptimized = new Set();
7187
+ this.expressionsUseTheKnownValue = [];
7405
7188
  this.knownValue = null;
7406
7189
  this.knownValueLiteral = UnknownValue;
7407
7190
  this.frozenValue = null;
7408
7191
  }
7409
- addArgumentValue(entity) {
7410
- this.updateKnownValue(entity);
7192
+ addEntityToBeDeoptimized(entity) {
7411
7193
  if (entity === UNKNOWN_EXPRESSION) {
7412
7194
  // As unknown expressions fully deoptimize all interactions, we can clear
7413
7195
  // the interaction cache at this point provided we keep this optimization
7414
7196
  // in mind when adding new interactions
7415
- if (!this.argumentsToBeDeoptimized.has(UNKNOWN_EXPRESSION)) {
7416
- this.argumentsToBeDeoptimized.add(UNKNOWN_EXPRESSION);
7197
+ if (!this.entitiesToBeDeoptimized.has(UNKNOWN_EXPRESSION)) {
7198
+ this.entitiesToBeDeoptimized.add(UNKNOWN_EXPRESSION);
7417
7199
  for (const { interaction } of this.deoptimizationInteractions) {
7418
7200
  deoptimizeInteraction(interaction);
7419
7201
  }
@@ -7423,34 +7205,27 @@ class ParameterVariable extends LocalVariable {
7423
7205
  else if (this.deoptimizedFields.has(UnknownKey)) {
7424
7206
  // This means that we already deoptimized all interactions and no longer
7425
7207
  // track them
7426
- entity.deoptimizePath([...this.initPath, UnknownKey]);
7208
+ entity.deoptimizePath(UNKNOWN_PATH);
7427
7209
  }
7428
- else if (!this.argumentsToBeDeoptimized.has(entity)) {
7429
- this.argumentsToBeDeoptimized.add(entity);
7210
+ else if (!this.entitiesToBeDeoptimized.has(entity)) {
7211
+ this.entitiesToBeDeoptimized.add(entity);
7430
7212
  for (const field of this.deoptimizedFields) {
7431
- entity.deoptimizePath([...this.initPath, field]);
7213
+ entity.deoptimizePath([field]);
7432
7214
  }
7433
7215
  for (const { interaction, path } of this.deoptimizationInteractions) {
7434
- if (this.initPath.length + path.length > MAX_PATH_DEPTH) {
7435
- deoptimizeInteraction(interaction);
7436
- continue;
7437
- }
7438
- entity.deoptimizeArgumentsOnInteractionAtPath(interaction, [...this.initPath, ...path], SHARED_RECURSION_TRACKER);
7216
+ entity.deoptimizeArgumentsOnInteractionAtPath(interaction, path, SHARED_RECURSION_TRACKER);
7439
7217
  }
7440
7218
  }
7441
7219
  }
7442
- /** This says we should not make assumptions about the value of the parameter.
7443
- * This is different from deoptimization that will also cause argument values
7444
- * to be deoptimized. */
7445
7220
  markReassigned() {
7446
7221
  if (this.isReassigned) {
7447
7222
  return;
7448
7223
  }
7449
7224
  super.markReassigned();
7450
- for (const expression of this.expressionsDependingOnKnownValue) {
7225
+ for (const expression of this.expressionsUseTheKnownValue) {
7451
7226
  expression.deoptimizeCache();
7452
7227
  }
7453
- this.expressionsDependingOnKnownValue = parseAst_js.EMPTY_ARRAY;
7228
+ this.expressionsUseTheKnownValue = parseAst_js.EMPTY_ARRAY;
7454
7229
  }
7455
7230
  deoptimizeCache() {
7456
7231
  this.markReassigned();
@@ -7467,7 +7242,7 @@ class ParameterVariable extends LocalVariable {
7467
7242
  }
7468
7243
  if (this.knownValue === null) {
7469
7244
  this.knownValue = argument;
7470
- this.knownValueLiteral = argument.getLiteralValueAtPath(this.initPath, SHARED_RECURSION_TRACKER, this);
7245
+ this.knownValueLiteral = argument.getLiteralValueAtPath(EMPTY_PATH, SHARED_RECURSION_TRACKER, this);
7471
7246
  return;
7472
7247
  }
7473
7248
  // the same literal or identifier, do nothing
@@ -7483,7 +7258,7 @@ class ParameterVariable extends LocalVariable {
7483
7258
  return;
7484
7259
  }
7485
7260
  // add tracking for the new argument
7486
- const newValue = argument.getLiteralValueAtPath(this.initPath, SHARED_RECURSION_TRACKER, this);
7261
+ const newValue = argument.getLiteralValueAtPath(EMPTY_PATH, SHARED_RECURSION_TRACKER, this);
7487
7262
  if (newValue !== oldValue) {
7488
7263
  this.markReassigned();
7489
7264
  }
@@ -7501,31 +7276,24 @@ class ParameterVariable extends LocalVariable {
7501
7276
  return this.frozenValue;
7502
7277
  }
7503
7278
  getLiteralValueAtPath(path, recursionTracker, origin) {
7504
- if (this.isReassigned || path.length + this.initPath.length > MAX_PATH_DEPTH) {
7279
+ if (this.isReassigned) {
7505
7280
  return UnknownValue;
7506
7281
  }
7507
7282
  const knownValue = this.getKnownValue();
7508
- this.expressionsDependingOnKnownValue.push(origin);
7509
- 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);
7510
7285
  }
7511
7286
  hasEffectsOnInteractionAtPath(path, interaction, context) {
7512
- const { type } = interaction;
7513
- if (this.isReassigned ||
7514
- type === INTERACTION_ASSIGNED ||
7515
- path.length + this.initPath.length > MAX_PATH_DEPTH) {
7287
+ if (this.isReassigned || interaction.type === INTERACTION_ASSIGNED) {
7516
7288
  return super.hasEffectsOnInteractionAtPath(path, interaction, context);
7517
7289
  }
7518
- return (!(type === INTERACTION_CALLED
7519
- ? (interaction.withNew
7520
- ? context.instantiated
7521
- : context.called).trackEntityAtPathAndGetIfTracked(path, interaction.args, this)
7522
- : context.accessed.trackEntityAtPathAndGetIfTracked(path, this)) &&
7523
- this.getKnownValue().hasEffectsOnInteractionAtPath([...this.initPath, ...path], interaction, context));
7290
+ const knownValue = this.getKnownValue();
7291
+ return knownValue.hasEffectsOnInteractionAtPath(path, interaction, context);
7524
7292
  }
7525
7293
  deoptimizeArgumentsOnInteractionAtPath(interaction, path) {
7526
7294
  // For performance reasons, we fully deoptimize all deeper interactions
7527
7295
  if (path.length >= 2 ||
7528
- this.argumentsToBeDeoptimized.has(UNKNOWN_EXPRESSION) ||
7296
+ this.entitiesToBeDeoptimized.has(UNKNOWN_EXPRESSION) ||
7529
7297
  this.deoptimizationInteractions.length >= MAX_TRACKED_INTERACTIONS ||
7530
7298
  (path.length === 1 &&
7531
7299
  (this.deoptimizedFields.has(UnknownKey) ||
@@ -7534,10 +7302,10 @@ class ParameterVariable extends LocalVariable {
7534
7302
  return;
7535
7303
  }
7536
7304
  if (!this.deoptimizations.trackEntityAtPathAndGetIfTracked(path, interaction.args)) {
7537
- for (const entity of this.argumentsToBeDeoptimized) {
7538
- entity.deoptimizeArgumentsOnInteractionAtPath(interaction, [...this.initPath, ...path], SHARED_RECURSION_TRACKER);
7305
+ for (const entity of this.entitiesToBeDeoptimized) {
7306
+ entity.deoptimizeArgumentsOnInteractionAtPath(interaction, path, SHARED_RECURSION_TRACKER);
7539
7307
  }
7540
- if (!this.argumentsToBeDeoptimized.has(UNKNOWN_EXPRESSION)) {
7308
+ if (!this.entitiesToBeDeoptimized.has(UNKNOWN_EXPRESSION)) {
7541
7309
  this.deoptimizationInteractions.push({
7542
7310
  interaction,
7543
7311
  path
@@ -7558,17 +7326,17 @@ class ParameterVariable extends LocalVariable {
7558
7326
  return;
7559
7327
  }
7560
7328
  this.deoptimizedFields.add(key);
7561
- for (const entity of this.argumentsToBeDeoptimized) {
7329
+ for (const entity of this.entitiesToBeDeoptimized) {
7562
7330
  // We do not need a recursion tracker here as we already track whether
7563
7331
  // this field is deoptimized
7564
- entity.deoptimizePath([...this.initPath, key]);
7332
+ entity.deoptimizePath([key]);
7565
7333
  }
7566
7334
  if (key === UnknownKey) {
7567
7335
  // save some memory
7568
7336
  this.deoptimizationInteractions = NO_INTERACTIONS;
7569
7337
  this.deoptimizations = EMPTY_PATH_TRACKER;
7570
7338
  this.deoptimizedFields = UNKNOWN_DEOPTIMIZED_FIELD;
7571
- this.argumentsToBeDeoptimized = UNKNOWN_DEOPTIMIZED_ENTITY;
7339
+ this.entitiesToBeDeoptimized = UNKNOWN_DEOPTIMIZED_ENTITY;
7572
7340
  }
7573
7341
  }
7574
7342
  getReturnExpressionWhenCalledAtPath(path) {
@@ -7583,14 +7351,11 @@ class ParameterVariable extends LocalVariable {
7583
7351
  }
7584
7352
  return UNKNOWN_RETURN_EXPRESSION;
7585
7353
  }
7586
- includeArgumentPaths(entity, context) {
7587
- this.includedPathTracker.includeAllPaths(entity, context, this.initPath);
7588
- }
7589
7354
  }
7590
7355
 
7591
7356
  class ThisVariable extends ParameterVariable {
7592
7357
  constructor(context) {
7593
- super('this', null, EMPTY_PATH, context);
7358
+ super('this', null, context);
7594
7359
  }
7595
7360
  hasEffectsOnInteractionAtPath(path, interaction, context) {
7596
7361
  return (context.replacedVariableInits.get(this) || UNKNOWN_EXPRESSION).hasEffectsOnInteractionAtPath(path, interaction, context);
@@ -7602,7 +7367,7 @@ class CatchBodyScope extends ChildScope {
7602
7367
  super(parent, parent.context);
7603
7368
  this.parent = parent;
7604
7369
  }
7605
- addDeclaration(identifier, context, init, destructuredInitPath, kind) {
7370
+ addDeclaration(identifier, context, init, kind) {
7606
7371
  if (kind === 'var') {
7607
7372
  const name = identifier.name;
7608
7373
  const existingVariable = this.hoistedVariables?.get(name) || this.variables.get(name);
@@ -7615,7 +7380,7 @@ class CatchBodyScope extends ChildScope {
7615
7380
  // the assignment actually goes to the parameter and the var is
7616
7381
  // hoisted without assignment. Locally, it is shadowed by the
7617
7382
  // parameter
7618
- const declaredVariable = this.parent.parent.addDeclaration(identifier, context, UNDEFINED_EXPRESSION, destructuredInitPath, kind);
7383
+ const declaredVariable = this.parent.parent.addDeclaration(identifier, context, UNDEFINED_EXPRESSION, kind);
7619
7384
  // To avoid the need to rewrite the declaration, we link the variable
7620
7385
  // names. If we ever implement a logic that splits initialization and
7621
7386
  // assignment for hoisted vars, the "renderLikeHoisted" logic can be
@@ -7634,7 +7399,7 @@ class CatchBodyScope extends ChildScope {
7634
7399
  return context.error(parseAst_js.logRedeclarationError(name), identifier.start);
7635
7400
  }
7636
7401
  // We only add parameters to parameter scopes
7637
- const declaredVariable = this.parent.parent.addDeclaration(identifier, context, init, destructuredInitPath, kind);
7402
+ const declaredVariable = this.parent.parent.addDeclaration(identifier, context, init, kind);
7638
7403
  // Necessary to make sure the init is deoptimized for conditional declarations.
7639
7404
  // We cannot call deoptimizePath here.
7640
7405
  declaredVariable.markInitializersForDeoptimization();
@@ -7642,7 +7407,7 @@ class CatchBodyScope extends ChildScope {
7642
7407
  this.addHoistedVariable(name, declaredVariable);
7643
7408
  return declaredVariable;
7644
7409
  }
7645
- return super.addDeclaration(identifier, context, init, destructuredInitPath, kind);
7410
+ return super.addDeclaration(identifier, context, init, kind);
7646
7411
  }
7647
7412
  }
7648
7413
 
@@ -7652,7 +7417,7 @@ class FunctionBodyScope extends ChildScope {
7652
7417
  }
7653
7418
  // There is stuff that is only allowed in function scopes, i.e. functions can
7654
7419
  // be redeclared, functions and var can redeclare each other
7655
- addDeclaration(identifier, context, init, destructuredInitPath, kind) {
7420
+ addDeclaration(identifier, context, init, kind) {
7656
7421
  const name = identifier.name;
7657
7422
  const existingVariable = this.hoistedVariables?.get(name) || this.variables.get(name);
7658
7423
  if (existingVariable) {
@@ -7664,7 +7429,7 @@ class FunctionBodyScope extends ChildScope {
7664
7429
  }
7665
7430
  context.error(parseAst_js.logRedeclarationError(name), identifier.start);
7666
7431
  }
7667
- const newVariable = new LocalVariable(identifier.name, identifier, init, destructuredInitPath, context, kind);
7432
+ const newVariable = new LocalVariable(identifier.name, identifier, init, context, kind);
7668
7433
  this.variables.set(name, newVariable);
7669
7434
  return newVariable;
7670
7435
  }
@@ -7673,21 +7438,21 @@ class FunctionBodyScope extends ChildScope {
7673
7438
  class ParameterScope extends ChildScope {
7674
7439
  constructor(parent, isCatchScope) {
7675
7440
  super(parent, parent.context);
7676
- this.hasRest = false;
7677
7441
  this.parameters = [];
7442
+ this.hasRest = false;
7678
7443
  this.bodyScope = isCatchScope ? new CatchBodyScope(this) : new FunctionBodyScope(this);
7679
7444
  }
7680
7445
  /**
7681
7446
  * Adds a parameter to this scope. Parameters must be added in the correct
7682
7447
  * order, i.e. from left to right.
7683
7448
  */
7684
- addParameterDeclaration(identifier, argumentPath) {
7449
+ addParameterDeclaration(identifier) {
7685
7450
  const { name, start } = identifier;
7686
7451
  const existingParameter = this.variables.get(name);
7687
7452
  if (existingParameter) {
7688
7453
  return this.context.error(parseAst_js.logDuplicateArgumentNameError(name), start);
7689
7454
  }
7690
- const variable = new ParameterVariable(name, identifier, argumentPath, this.context);
7455
+ const variable = new ParameterVariable(name, identifier, this.context);
7691
7456
  this.variables.set(name, variable);
7692
7457
  // We also add it to the body scope to detect name conflicts with local
7693
7458
  // variables. We still need the intermediate scope, though, as parameter
@@ -7705,56 +7470,42 @@ class ParameterScope extends ChildScope {
7705
7470
  }
7706
7471
  this.hasRest = hasRest;
7707
7472
  }
7708
- includeCallArguments(context, interaction) {
7473
+ includeCallArguments(context, parameters) {
7709
7474
  let calledFromTryStatement = false;
7710
7475
  let argumentIncluded = false;
7711
7476
  const restParameter = this.hasRest && this.parameters[this.parameters.length - 1];
7712
- const { args } = interaction;
7713
- let lastExplicitlyIncludedIndex = args.length - 1;
7714
- // If there is a SpreadElement, we need to include all arguments after it
7715
- // because we no longer know which argument corresponds to which parameter.
7716
- for (let argumentIndex = 1; argumentIndex < args.length; argumentIndex++) {
7717
- const argument = args[argumentIndex];
7718
- if (argument instanceof SpreadElement && !argumentIncluded) {
7719
- argumentIncluded = true;
7720
- lastExplicitlyIncludedIndex = argumentIndex - 1;
7721
- }
7722
- if (argumentIncluded) {
7723
- argument.includePath(UNKNOWN_PATH, context);
7724
- 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;
7725
7483
  }
7726
7484
  }
7727
- // Now we go backwards either starting from the last argument or before the
7728
- // first SpreadElement to ensure all arguments before are included as needed
7729
- for (let index = lastExplicitlyIncludedIndex; index >= 1; index--) {
7730
- const parameterVariables = this.parameters[index - 1] || restParameter;
7731
- 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];
7732
7488
  if (parameterVariables) {
7733
7489
  calledFromTryStatement = false;
7734
7490
  if (parameterVariables.length === 0) {
7735
- // handle empty destructuring to avoid destructuring undefined
7491
+ // handle empty destructuring
7736
7492
  argumentIncluded = true;
7737
7493
  }
7738
7494
  else {
7739
7495
  for (const variable of parameterVariables) {
7740
- if (variable.calledFromTryStatement) {
7741
- calledFromTryStatement = true;
7742
- }
7743
7496
  if (variable.included) {
7744
7497
  argumentIncluded = true;
7745
- if (calledFromTryStatement) {
7746
- argument.include(context, true);
7747
- }
7748
- else {
7749
- variable.includeArgumentPaths(argument, context);
7750
- argument.include(context, false);
7751
- }
7498
+ }
7499
+ if (variable.calledFromTryStatement) {
7500
+ calledFromTryStatement = true;
7752
7501
  }
7753
7502
  }
7754
7503
  }
7755
7504
  }
7756
- if (!argument.included && (argumentIncluded || argument.shouldBeIncluded(context))) {
7505
+ if (!argumentIncluded && argument.shouldBeIncluded(context)) {
7757
7506
  argumentIncluded = true;
7507
+ }
7508
+ if (argumentIncluded) {
7758
7509
  argument.include(context, calledFromTryStatement);
7759
7510
  }
7760
7511
  }
@@ -7770,62 +7521,11 @@ class ReturnValueScope extends ParameterScope {
7770
7521
  addReturnExpression(expression) {
7771
7522
  this.returnExpressions.push(expression);
7772
7523
  }
7773
- deoptimizeArgumentsOnCall(interaction) {
7774
- const { parameters } = this;
7775
- const { args } = interaction;
7776
- let position = 0;
7777
- for (; position < args.length - 1; position++) {
7778
- // Only the "this" argument arg[0] can be null
7779
- const argument = args[position + 1];
7780
- if (argument instanceof SpreadElement) {
7781
- // This deoptimizes the current and remaining parameters and arguments
7782
- for (; position < parameters.length; position++) {
7783
- args[position + 1]?.deoptimizePath(UNKNOWN_PATH);
7784
- parameters[position].forEach(variable => variable.markReassigned());
7785
- }
7786
- break;
7787
- }
7788
- if (this.hasRest && position >= parameters.length - 1) {
7789
- argument.deoptimizePath(UNKNOWN_PATH);
7790
- }
7791
- else {
7792
- const variables = parameters[position];
7793
- if (variables) {
7794
- for (const variable of variables) {
7795
- variable.addArgumentValue(argument);
7796
- }
7797
- }
7798
- this.addArgumentToBeDeoptimized(argument);
7799
- }
7800
- }
7801
- const nonRestParameterLength = this.hasRest ? parameters.length - 1 : parameters.length;
7802
- for (; position < nonRestParameterLength; position++) {
7803
- for (const variable of parameters[position]) {
7804
- variable.addArgumentValue(UNDEFINED_EXPRESSION);
7805
- }
7806
- }
7807
- }
7808
7524
  getReturnExpression() {
7809
7525
  if (this.returnExpression === null)
7810
7526
  this.updateReturnExpression();
7811
7527
  return this.returnExpression;
7812
7528
  }
7813
- deoptimizeAllParameters() {
7814
- for (const parameter of this.parameters) {
7815
- for (const variable of parameter) {
7816
- variable.deoptimizePath(UNKNOWN_PATH);
7817
- variable.markReassigned();
7818
- }
7819
- }
7820
- }
7821
- reassignAllParameters() {
7822
- for (const parameter of this.parameters) {
7823
- for (const variable of parameter) {
7824
- variable.markReassigned();
7825
- }
7826
- }
7827
- }
7828
- addArgumentToBeDeoptimized(_argument) { }
7829
7529
  updateReturnExpression() {
7830
7530
  if (this.returnExpressions.length === 1) {
7831
7531
  this.returnExpression = this.returnExpressions[0];
@@ -7841,30 +7541,24 @@ class ReturnValueScope extends ParameterScope {
7841
7541
 
7842
7542
  class FunctionScope extends ReturnValueScope {
7843
7543
  constructor(parent) {
7844
- super(parent, false);
7845
7544
  const { context } = parent;
7545
+ super(parent, false);
7846
7546
  this.variables.set('arguments', (this.argumentsVariable = new ArgumentsVariable(context)));
7847
7547
  this.variables.set('this', (this.thisVariable = new ThisVariable(context)));
7848
7548
  }
7849
7549
  findLexicalBoundary() {
7850
7550
  return this;
7851
7551
  }
7852
- includeCallArguments(context, interaction) {
7853
- super.includeCallArguments(context, interaction);
7552
+ includeCallArguments(context, parameters) {
7553
+ super.includeCallArguments(context, parameters);
7854
7554
  if (this.argumentsVariable.included) {
7855
- const { args } = interaction;
7856
- for (let argumentIndex = 1; argumentIndex < args.length; argumentIndex++) {
7857
- const argument = args[argumentIndex];
7858
- if (argument) {
7859
- argument.includePath(UNKNOWN_PATH, context);
7555
+ for (const argument of parameters) {
7556
+ if (!argument.included) {
7860
7557
  argument.include(context, false);
7861
7558
  }
7862
7559
  }
7863
7560
  }
7864
7561
  }
7865
- addArgumentToBeDeoptimized(argument) {
7866
- this.argumentsVariable.addArgumentToBeDeoptimized(argument);
7867
- }
7868
7562
  }
7869
7563
 
7870
7564
  class ExpressionStatement extends NodeBase {
@@ -7892,9 +7586,8 @@ class ExpressionStatement extends NodeBase {
7892
7586
  return this.parent.type !== parseAst_js.Program;
7893
7587
  return super.shouldBeIncluded(context);
7894
7588
  }
7589
+ applyDeoptimizations() { }
7895
7590
  }
7896
- ExpressionStatement.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
7897
- ExpressionStatement.prototype.applyDeoptimizations = doNotDeoptimize;
7898
7591
 
7899
7592
  class BlockStatement extends NodeBase {
7900
7593
  get deoptimizeBody() {
@@ -7959,8 +7652,6 @@ class BlockStatement extends NodeBase {
7959
7652
  }
7960
7653
  }
7961
7654
  }
7962
- BlockStatement.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
7963
- BlockStatement.prototype.applyDeoptimizations = doNotDeoptimize;
7964
7655
 
7965
7656
  class RestElement extends NodeBase {
7966
7657
  constructor() {
@@ -7970,12 +7661,9 @@ class RestElement extends NodeBase {
7970
7661
  addExportedVariables(variables, exportNamesByVariable) {
7971
7662
  this.argument.addExportedVariables(variables, exportNamesByVariable);
7972
7663
  }
7973
- declare(kind, destructuredInitPath, init) {
7664
+ declare(kind, init) {
7974
7665
  this.declarationInit = init;
7975
- return this.argument.declare(kind, getIncludedPatternPath$1(destructuredInitPath), init);
7976
- }
7977
- deoptimizeAssignment(destructuredInitPath, init) {
7978
- this.argument.deoptimizeAssignment(getIncludedPatternPath$1(destructuredInitPath), init);
7666
+ return this.argument.declare(kind, UNKNOWN_EXPRESSION);
7979
7667
  }
7980
7668
  deoptimizePath(path) {
7981
7669
  if (path.length === 0) {
@@ -7986,20 +7674,6 @@ class RestElement extends NodeBase {
7986
7674
  return (path.length > 0 ||
7987
7675
  this.argument.hasEffectsOnInteractionAtPath(EMPTY_PATH, interaction, context));
7988
7676
  }
7989
- hasEffectsWhenDestructuring(context, destructuredInitPath, init) {
7990
- return this.argument.hasEffectsWhenDestructuring(context, getIncludedPatternPath$1(destructuredInitPath), init);
7991
- }
7992
- includeDestructuredIfNecessary(context, destructuredInitPath, init) {
7993
- return (this.included =
7994
- this.argument.includeDestructuredIfNecessary(context, getIncludedPatternPath$1(destructuredInitPath), init) || this.included);
7995
- }
7996
- include(context, includeChildrenRecursively) {
7997
- if (!this.included)
7998
- this.includeNode(context);
7999
- // This should just include the identifier, its properties should be
8000
- // included where the variable is used.
8001
- this.argument.include(context, includeChildrenRecursively);
8002
- }
8003
7677
  markDeclarationReached() {
8004
7678
  this.argument.markDeclarationReached();
8005
7679
  }
@@ -8011,16 +7685,12 @@ class RestElement extends NodeBase {
8011
7685
  }
8012
7686
  }
8013
7687
  }
8014
- RestElement.prototype.includeNode = onlyIncludeSelf;
8015
- const getIncludedPatternPath$1 = (destructuredInitPath) => destructuredInitPath.at(-1) === UnknownKey
8016
- ? destructuredInitPath
8017
- : [...destructuredInitPath, UnknownKey];
8018
7688
 
8019
7689
  class FunctionBase extends NodeBase {
8020
7690
  constructor() {
8021
7691
  super(...arguments);
7692
+ this.objectEntity = null;
8022
7693
  this.parameterVariableValuesDeoptimized = false;
8023
- this.includeCallArguments = this.scope.includeCallArguments.bind(this.scope);
8024
7694
  }
8025
7695
  get async() {
8026
7696
  return isFlagSet(this.flags, 256 /* Flag.async */);
@@ -8040,9 +7710,53 @@ class FunctionBase extends NodeBase {
8040
7710
  set generator(value) {
8041
7711
  this.flags = setFlag(this.flags, 4194304 /* Flag.generator */, value);
8042
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
+ }
8043
7732
  deoptimizeArgumentsOnInteractionAtPath(interaction, path, recursionTracker) {
8044
- if (interaction.type === INTERACTION_CALLED && path.length === 0) {
8045
- 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);
8046
7760
  }
8047
7761
  else {
8048
7762
  this.getObjectEntity().deoptimizeArgumentsOnInteractionAtPath(interaction, path, recursionTracker);
@@ -8054,7 +7768,12 @@ class FunctionBase extends NodeBase {
8054
7768
  // A reassignment of UNKNOWN_PATH is considered equivalent to having lost track
8055
7769
  // which means the return expression and parameters need to be reassigned
8056
7770
  this.scope.getReturnExpression().deoptimizePath(UNKNOWN_PATH);
8057
- 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
+ }
8058
7777
  }
8059
7778
  }
8060
7779
  getLiteralValueAtPath(path, recursionTracker, origin) {
@@ -8092,13 +7811,8 @@ class FunctionBase extends NodeBase {
8092
7811
  return true;
8093
7812
  }
8094
7813
  }
8095
- const { propertyReadSideEffects } = this.scope.context.options
8096
- .treeshake;
8097
- for (let index = 0; index < this.params.length; index++) {
8098
- const parameter = this.params[index];
8099
- if (parameter.hasEffects(context) ||
8100
- (propertyReadSideEffects &&
8101
- parameter.hasEffectsWhenDestructuring(context, EMPTY_PATH, interaction.args[index + 1] || UNDEFINED_EXPRESSION)))
7814
+ for (const parameter of this.params) {
7815
+ if (parameter.hasEffects(context))
8102
7816
  return true;
8103
7817
  }
8104
7818
  return false;
@@ -8117,17 +7831,21 @@ class FunctionBase extends NodeBase {
8117
7831
  return variable?.getOnlyFunctionCallUsed() ?? false;
8118
7832
  }
8119
7833
  include(context, includeChildrenRecursively) {
8120
- if (!this.included)
8121
- this.includeNode(context);
8122
- if (!(this.parameterVariableValuesDeoptimized || this.onlyFunctionCallUsed())) {
7834
+ if (!this.parameterVariableValuesDeoptimized && !this.onlyFunctionCallUsed()) {
8123
7835
  this.parameterVariableValuesDeoptimized = true;
8124
- this.scope.reassignAllParameters();
7836
+ this.deoptimizeParameterVariableValues();
8125
7837
  }
7838
+ if (!this.deoptimized)
7839
+ this.applyDeoptimizations();
7840
+ this.included = true;
8126
7841
  const { brokenFlow } = context;
8127
7842
  context.brokenFlow = false;
8128
7843
  this.body.include(context, includeChildrenRecursively);
8129
7844
  context.brokenFlow = brokenFlow;
8130
7845
  }
7846
+ includeCallArguments(context, parameters) {
7847
+ this.scope.includeCallArguments(context, parameters);
7848
+ }
8131
7849
  initialise() {
8132
7850
  super.initialise();
8133
7851
  if (this.body instanceof BlockStatement) {
@@ -8149,14 +7867,14 @@ class FunctionBase extends NodeBase {
8149
7867
  // so that the scope already knows all parameters and can detect conflicts
8150
7868
  // when parsing the body.
8151
7869
  const parameters = (this.params = params.map((parameter) => new (context.getNodeConstructor(parameter.type))(this, scope).parseNode(parameter)));
8152
- 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);
8153
7871
  this.body = new (context.getNodeConstructor(body.type))(this, bodyScope).parseNode(body);
8154
7872
  return super.parseNode(esTreeNode);
8155
7873
  }
7874
+ addArgumentToBeDeoptimized(_argument) { }
7875
+ applyDeoptimizations() { }
8156
7876
  }
8157
7877
  FunctionBase.prototype.preventChildBlockScope = true;
8158
- FunctionBase.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
8159
- FunctionBase.prototype.applyDeoptimizations = doNotDeoptimize;
8160
7878
 
8161
7879
  class FunctionNode extends FunctionBase {
8162
7880
  constructor() {
@@ -8168,16 +7886,18 @@ class FunctionNode extends FunctionBase {
8168
7886
  this.constructedEntity = new ObjectEntity(Object.create(null), OBJECT_PROTOTYPE);
8169
7887
  // This makes sure that all deoptimizations of "this" are applied to the
8170
7888
  // constructed entity.
8171
- this.scope.thisVariable.addArgumentValue(this.constructedEntity);
7889
+ this.scope.thisVariable.addEntityToBeDeoptimized(this.constructedEntity);
8172
7890
  }
8173
7891
  deoptimizeArgumentsOnInteractionAtPath(interaction, path, recursionTracker) {
8174
7892
  super.deoptimizeArgumentsOnInteractionAtPath(interaction, path, recursionTracker);
8175
7893
  if (interaction.type === INTERACTION_CALLED && path.length === 0 && interaction.args[0]) {
8176
7894
  // args[0] is the "this" argument
8177
- this.scope.thisVariable.addArgumentValue(interaction.args[0]);
7895
+ this.scope.thisVariable.addEntityToBeDeoptimized(interaction.args[0]);
8178
7896
  }
8179
7897
  }
8180
7898
  hasEffects(context) {
7899
+ if (!this.deoptimized)
7900
+ this.applyDeoptimizations();
8181
7901
  if (this.annotationNoSideEffects) {
8182
7902
  return false;
8183
7903
  }
@@ -8215,7 +7935,7 @@ class FunctionNode extends FunctionBase {
8215
7935
  }
8216
7936
  include(context, includeChildrenRecursively) {
8217
7937
  super.include(context, includeChildrenRecursively);
8218
- this.id?.include(context);
7938
+ this.id?.include();
8219
7939
  const hasArguments = this.scope.argumentsVariable.included;
8220
7940
  for (const parameter of this.params) {
8221
7941
  if (!(parameter instanceof Identifier) || hasArguments) {
@@ -8223,18 +7943,12 @@ class FunctionNode extends FunctionBase {
8223
7943
  }
8224
7944
  }
8225
7945
  }
8226
- includeNode(context) {
8227
- this.included = true;
8228
- const hasArguments = this.scope.argumentsVariable.included;
8229
- for (const parameter of this.params) {
8230
- if (!(parameter instanceof Identifier) || hasArguments) {
8231
- parameter.includePath(UNKNOWN_PATH, context);
8232
- }
8233
- }
8234
- }
8235
7946
  initialise() {
8236
7947
  super.initialise();
8237
- this.id?.declare('function', EMPTY_PATH, this);
7948
+ this.id?.declare('function', this);
7949
+ }
7950
+ addArgumentToBeDeoptimized(argument) {
7951
+ this.scope.argumentsVariable.addArgumentToBeDeoptimized(argument);
8238
7952
  }
8239
7953
  getObjectEntity() {
8240
7954
  if (this.objectEntity !== null) {
@@ -8284,16 +7998,11 @@ function getFunctionIdInsertPosition(code, start) {
8284
7998
  }
8285
7999
  class ExportDefaultDeclaration extends NodeBase {
8286
8000
  include(context, includeChildrenRecursively) {
8287
- this.included = true;
8288
- this.declaration.include(context, includeChildrenRecursively);
8001
+ super.include(context, includeChildrenRecursively);
8289
8002
  if (includeChildrenRecursively) {
8290
- this.scope.context.includeVariableInModule(this.variable, UNKNOWN_PATH, context);
8003
+ this.scope.context.includeVariableInModule(this.variable);
8291
8004
  }
8292
8005
  }
8293
- includePath(path, context) {
8294
- this.included = true;
8295
- this.declaration.includePath(path, context);
8296
- }
8297
8006
  initialise() {
8298
8007
  super.initialise();
8299
8008
  const declaration = this.declaration;
@@ -8338,6 +8047,7 @@ class ExportDefaultDeclaration extends NodeBase {
8338
8047
  }
8339
8048
  this.declaration.render(code, options);
8340
8049
  }
8050
+ applyDeoptimizations() { }
8341
8051
  renderNamedDeclaration(code, declarationStart, idInsertPosition, options) {
8342
8052
  const { exportNamesByVariable, format, snippets: { getPropertyAccess } } = options;
8343
8053
  const name = this.variable.getName(getPropertyAccess);
@@ -8368,8 +8078,6 @@ class ExportDefaultDeclaration extends NodeBase {
8368
8078
  }
8369
8079
  }
8370
8080
  ExportDefaultDeclaration.prototype.needsBoundaries = true;
8371
- ExportDefaultDeclaration.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
8372
- ExportDefaultDeclaration.prototype.applyDeoptimizations = doNotDeoptimize;
8373
8081
 
8374
8082
  const needsEscapeRegEx = /[\n\r'\\\u2028\u2029]/;
8375
8083
  const quoteNewlineRegEx = /([\n\r'\u2028\u2029])/g;
@@ -8639,7 +8347,6 @@ class Literal extends NodeBase {
8639
8347
  }
8640
8348
  }
8641
8349
  }
8642
- Literal.prototype.includeNode = onlyIncludeSelf;
8643
8350
 
8644
8351
  function getChainElementLiteralValueAtPath(element, object, path, recursionTracker, origin) {
8645
8352
  if ('getLiteralValueAtPathAsChainElement' in object) {
@@ -8655,6 +8362,8 @@ function getChainElementLiteralValueAtPath(element, object, path, recursionTrack
8655
8362
  return element.getLiteralValueAtPath(path, recursionTracker, origin);
8656
8363
  }
8657
8364
 
8365
+ // To avoid infinite recursions
8366
+ const MAX_PATH_DEPTH = 7;
8658
8367
  function getResolvablePropertyKey(memberExpression) {
8659
8368
  return memberExpression.computed
8660
8369
  ? getResolvableComputedPropertyKey(memberExpression.property)
@@ -8753,27 +8462,18 @@ class MemberExpression extends NodeBase {
8753
8462
  }
8754
8463
  else if (!this.isUndefined) {
8755
8464
  if (path.length < MAX_PATH_DEPTH) {
8756
- this.object.deoptimizeArgumentsOnInteractionAtPath(interaction, this.propertyKey === UnknownKey ? UNKNOWN_PATH : [this.propertyKey, ...path], recursionTracker);
8465
+ this.object.deoptimizeArgumentsOnInteractionAtPath(interaction, [this.getPropertyKey(), ...path], recursionTracker);
8757
8466
  }
8758
8467
  else {
8759
8468
  deoptimizeInteraction(interaction);
8760
8469
  }
8761
8470
  }
8762
8471
  }
8763
- deoptimizeAssignment(destructuredInitPath, init) {
8764
- this.deoptimizePath(EMPTY_PATH);
8765
- init.deoptimizePath([...destructuredInitPath, UnknownKey]);
8766
- }
8767
8472
  deoptimizeCache() {
8768
- if (this.propertyKey === this.dynamicPropertyKey)
8769
- return;
8770
8473
  const { expressionsToBeDeoptimized, object } = this;
8771
8474
  this.expressionsToBeDeoptimized = parseAst_js.EMPTY_ARRAY;
8772
- this.dynamicPropertyKey = this.propertyKey;
8475
+ this.propertyKey = UnknownKey;
8773
8476
  object.deoptimizePath(UNKNOWN_PATH);
8774
- if (this.included) {
8775
- object.includePath(UNKNOWN_PATH, createInclusionContext());
8776
- }
8777
8477
  for (const expression of expressionsToBeDeoptimized) {
8778
8478
  expression.deoptimizeCache();
8779
8479
  }
@@ -8784,13 +8484,11 @@ class MemberExpression extends NodeBase {
8784
8484
  if (this.variable) {
8785
8485
  this.variable.deoptimizePath(path);
8786
8486
  }
8787
- else if (!this.isUndefined) {
8788
- const { propertyKey } = this;
8487
+ else if (!this.isUndefined && path.length < MAX_PATH_DEPTH) {
8488
+ const propertyKey = this.getPropertyKey();
8789
8489
  this.object.deoptimizePath([
8790
8490
  propertyKey === UnknownKey ? UnknownNonAccessorKey : propertyKey,
8791
- ...(path.length < MAX_PATH_DEPTH
8792
- ? path
8793
- : [...path.slice(0, MAX_PATH_DEPTH), UnknownKey])
8491
+ ...path
8794
8492
  ]);
8795
8493
  }
8796
8494
  }
@@ -8801,11 +8499,9 @@ class MemberExpression extends NodeBase {
8801
8499
  if (this.isUndefined) {
8802
8500
  return undefined;
8803
8501
  }
8804
- const propertyKey = this.getDynamicPropertyKey();
8805
- if (propertyKey !== UnknownKey && path.length < MAX_PATH_DEPTH) {
8806
- if (propertyKey !== this.propertyKey)
8807
- this.expressionsToBeDeoptimized.push(origin);
8808
- 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);
8809
8505
  }
8810
8506
  return UnknownValue;
8811
8507
  }
@@ -8825,11 +8521,9 @@ class MemberExpression extends NodeBase {
8825
8521
  if (this.isUndefined) {
8826
8522
  return [UNDEFINED_EXPRESSION, false];
8827
8523
  }
8828
- const propertyKey = this.getDynamicPropertyKey();
8829
- if (propertyKey !== UnknownKey && path.length < MAX_PATH_DEPTH) {
8830
- if (propertyKey !== this.propertyKey)
8831
- this.expressionsToBeDeoptimized.push(origin);
8832
- 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);
8833
8527
  }
8834
8528
  return UNKNOWN_RETURN_EXPRESSION;
8835
8529
  }
@@ -8875,45 +8569,14 @@ class MemberExpression extends NodeBase {
8875
8569
  return true;
8876
8570
  }
8877
8571
  if (path.length < MAX_PATH_DEPTH) {
8878
- return this.object.hasEffectsOnInteractionAtPath([this.getDynamicPropertyKey(), ...path], interaction, context);
8572
+ return this.object.hasEffectsOnInteractionAtPath([this.getPropertyKey(), ...path], interaction, context);
8879
8573
  }
8880
8574
  return true;
8881
8575
  }
8882
- hasEffectsWhenDestructuring(context, destructuredInitPath, init) {
8883
- return (destructuredInitPath.length > 0 &&
8884
- init.hasEffectsOnInteractionAtPath(destructuredInitPath, NODE_INTERACTION_UNKNOWN_ACCESS, context));
8885
- }
8886
8576
  include(context, includeChildrenRecursively) {
8887
- if (!this.included)
8888
- this.includeNode(context);
8889
- this.object.include(context, includeChildrenRecursively);
8890
- this.property.include(context, includeChildrenRecursively);
8891
- }
8892
- includeNode(context) {
8893
- this.included = true;
8894
8577
  if (!this.deoptimized)
8895
8578
  this.applyDeoptimizations();
8896
- if (this.variable) {
8897
- this.scope.context.includeVariableInModule(this.variable, EMPTY_PATH, context);
8898
- }
8899
- else if (!this.isUndefined) {
8900
- this.object.includePath([this.propertyKey], context);
8901
- }
8902
- }
8903
- includePath(path, context) {
8904
- if (!this.included)
8905
- this.includeNode(context);
8906
- if (this.variable) {
8907
- this.variable?.includePath(path, context);
8908
- }
8909
- else if (!this.isUndefined) {
8910
- this.object.includePath([
8911
- this.propertyKey,
8912
- ...(path.length < MAX_PATH_DEPTH
8913
- ? path
8914
- : [...path.slice(0, MAX_PATH_DEPTH), UnknownKey])
8915
- ], context);
8916
- }
8579
+ this.includeProperties(context, includeChildrenRecursively);
8917
8580
  }
8918
8581
  includeAsAssignmentTarget(context, includeChildrenRecursively, deoptimizeAccess) {
8919
8582
  if (!this.assignmentDeoptimized)
@@ -8922,34 +8585,20 @@ class MemberExpression extends NodeBase {
8922
8585
  this.include(context, includeChildrenRecursively);
8923
8586
  }
8924
8587
  else {
8925
- if (!this.included)
8926
- this.includeNode(context);
8927
- this.object.include(context, includeChildrenRecursively);
8928
- this.property.include(context, includeChildrenRecursively);
8588
+ this.includeProperties(context, includeChildrenRecursively);
8929
8589
  }
8930
8590
  }
8931
- includeCallArguments(context, interaction) {
8591
+ includeCallArguments(context, parameters) {
8932
8592
  if (this.variable) {
8933
- this.variable.includeCallArguments(context, interaction);
8593
+ this.variable.includeCallArguments(context, parameters);
8934
8594
  }
8935
8595
  else {
8936
- super.includeCallArguments(context, interaction);
8596
+ super.includeCallArguments(context, parameters);
8937
8597
  }
8938
8598
  }
8939
- includeDestructuredIfNecessary(context, destructuredInitPath, init) {
8940
- if ((this.included ||=
8941
- destructuredInitPath.length > 0 &&
8942
- !context.brokenFlow &&
8943
- init.hasEffectsOnInteractionAtPath(destructuredInitPath, NODE_INTERACTION_UNKNOWN_ACCESS, createHasEffectsContext()))) {
8944
- init.include(context, false);
8945
- return true;
8946
- }
8947
- return false;
8948
- }
8949
8599
  initialise() {
8950
8600
  super.initialise();
8951
- this.dynamicPropertyKey = getResolvablePropertyKey(this);
8952
- this.propertyKey = this.dynamicPropertyKey === null ? UnknownKey : this.dynamicPropertyKey;
8601
+ this.propertyKey = getResolvablePropertyKey(this);
8953
8602
  this.accessInteraction = { args: [this.object], type: INTERACTION_ACCESSED };
8954
8603
  }
8955
8604
  render(code, options, { renderedParentType, isCalleeOfRenderedParent, renderedSurroundingElement } = parseAst_js.BLANK) {
@@ -8986,7 +8635,8 @@ class MemberExpression extends NodeBase {
8986
8635
  this.bound &&
8987
8636
  propertyReadSideEffects &&
8988
8637
  !(this.variable || this.isUndefined)) {
8989
- 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);
8990
8640
  this.scope.context.requestTreeshakingPass();
8991
8641
  }
8992
8642
  if (this.variable) {
@@ -9003,7 +8653,7 @@ class MemberExpression extends NodeBase {
9003
8653
  this.bound &&
9004
8654
  propertyReadSideEffects &&
9005
8655
  !(this.variable || this.isUndefined)) {
9006
- this.object.deoptimizeArgumentsOnInteractionAtPath(this.assignmentInteraction, [this.propertyKey], SHARED_RECURSION_TRACKER);
8656
+ this.object.deoptimizeArgumentsOnInteractionAtPath(this.assignmentInteraction, [this.getPropertyKey()], SHARED_RECURSION_TRACKER);
9007
8657
  this.scope.context.requestTreeshakingPass();
9008
8658
  }
9009
8659
  }
@@ -9012,24 +8662,24 @@ class MemberExpression extends NodeBase {
9012
8662
  const variable = this.scope.findVariable(this.object.name);
9013
8663
  if (variable.isNamespace) {
9014
8664
  if (this.variable) {
9015
- this.scope.context.includeVariableInModule(this.variable, UNKNOWN_PATH, createInclusionContext());
8665
+ this.scope.context.includeVariableInModule(this.variable);
9016
8666
  }
9017
8667
  this.scope.context.log(parseAst_js.LOGLEVEL_WARN, parseAst_js.logIllegalImportReassignment(this.object.name, this.scope.context.module.id), this.start);
9018
8668
  }
9019
8669
  }
9020
8670
  }
9021
- getDynamicPropertyKey() {
9022
- if (this.dynamicPropertyKey === null) {
9023
- this.dynamicPropertyKey = this.propertyKey;
8671
+ getPropertyKey() {
8672
+ if (this.propertyKey === null) {
8673
+ this.propertyKey = UnknownKey;
9024
8674
  const value = this.property.getLiteralValueAtPath(EMPTY_PATH, SHARED_RECURSION_TRACKER, this);
9025
- return (this.dynamicPropertyKey =
8675
+ return (this.propertyKey =
9026
8676
  value === SymbolToStringTag
9027
8677
  ? value
9028
8678
  : typeof value === 'symbol'
9029
8679
  ? UnknownKey
9030
8680
  : String(value));
9031
8681
  }
9032
- return this.dynamicPropertyKey;
8682
+ return this.propertyKey;
9033
8683
  }
9034
8684
  hasAccessEffect(context) {
9035
8685
  const { propertyReadSideEffects } = this.scope.context.options
@@ -9037,7 +8687,17 @@ class MemberExpression extends NodeBase {
9037
8687
  return (!(this.variable || this.isUndefined) &&
9038
8688
  propertyReadSideEffects &&
9039
8689
  (propertyReadSideEffects === 'always' ||
9040
- 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);
9041
8701
  }
9042
8702
  }
9043
8703
  function resolveNamespaceVariables(baseVariable, path, astContext) {
@@ -9081,20 +8741,18 @@ class MetaProperty extends NodeBase {
9081
8741
  return path.length > 1 || type !== INTERACTION_ACCESSED;
9082
8742
  }
9083
8743
  include() {
9084
- if (!this.included)
9085
- this.includeNode();
9086
- }
9087
- includeNode() {
9088
- this.included = true;
9089
- if (this.meta.name === IMPORT) {
9090
- this.scope.context.addImportMeta(this);
9091
- const parent = this.parent;
9092
- const metaProperty = (this.metaProperty =
9093
- parent instanceof MemberExpression && typeof parent.propertyKey === 'string'
9094
- ? parent.propertyKey
9095
- : null);
9096
- if (metaProperty?.startsWith(FILE_PREFIX)) {
9097
- 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
+ }
9098
8756
  }
9099
8757
  }
9100
8758
  }
@@ -9201,7 +8859,7 @@ class UndefinedVariable extends Variable {
9201
8859
 
9202
8860
  class ExportDefaultVariable extends LocalVariable {
9203
8861
  constructor(name, exportDefaultDeclaration, context) {
9204
- super(name, exportDefaultDeclaration, exportDefaultDeclaration.declaration, EMPTY_PATH, context, 'other');
8862
+ super(name, exportDefaultDeclaration, exportDefaultDeclaration.declaration, context, 'other');
9205
8863
  this.hasId = false;
9206
8864
  this.originalId = null;
9207
8865
  this.originalVariable = null;
@@ -9350,8 +9008,8 @@ class NamespaceVariable extends Variable {
9350
9008
  return (!memberVariable ||
9351
9009
  memberVariable.hasEffectsOnInteractionAtPath(path.slice(1), interaction, context));
9352
9010
  }
9353
- includePath(path, context) {
9354
- super.includePath(path, context);
9011
+ include() {
9012
+ super.include();
9355
9013
  this.context.includeAllExports();
9356
9014
  }
9357
9015
  prepare(accessedGlobalsByScope) {
@@ -9444,9 +9102,9 @@ class SyntheticNamedExportVariable extends Variable {
9444
9102
  getName(getPropertyAccess) {
9445
9103
  return `${this.syntheticNamespace.getName(getPropertyAccess)}${getPropertyAccess(this.name)}`;
9446
9104
  }
9447
- includePath(path, context) {
9448
- super.includePath(path, context);
9449
- this.context.includeVariableInModule(this.syntheticNamespace, path, context);
9105
+ include() {
9106
+ super.include();
9107
+ this.context.includeVariableInModule(this.syntheticNamespace);
9450
9108
  }
9451
9109
  setRenderNames(baseName, name) {
9452
9110
  super.setRenderNames(baseName, name);
@@ -9477,7 +9135,7 @@ class ExternalChunk {
9477
9135
  (this.renormalizeRenderPath ? parseAst_js.normalize(path.relative(this.inputBase, this.id)) : this.id));
9478
9136
  }
9479
9137
  getImportAttributes(snippets) {
9480
- return (this.importAttributes ||= formatAttributes(this.options.format === 'es' &&
9138
+ return (this.importAttributes ||= formatAttributes(['es', 'cjs'].includes(this.options.format) &&
9481
9139
  this.options.externalImportAttributes &&
9482
9140
  this.moduleInfo.attributes, snippets));
9483
9141
  }
@@ -10369,35 +10027,6 @@ function umd(magicString, { accessedGlobals, dependencies, exports, hasDefaultEx
10369
10027
 
10370
10028
  const finalisers = { amd, cjs, es, iife, system, umd };
10371
10029
 
10372
- function getDefaultExportFromCjs (x) {
10373
- return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
10374
- }
10375
-
10376
- function getAugmentedNamespace(n) {
10377
- if (n.__esModule) return n;
10378
- var f = n.default;
10379
- if (typeof f == "function") {
10380
- var a = function a () {
10381
- if (this instanceof a) {
10382
- return Reflect.construct(f, arguments, this.constructor);
10383
- }
10384
- return f.apply(this, arguments);
10385
- };
10386
- a.prototype = f.prototype;
10387
- } else a = {};
10388
- Object.defineProperty(a, '__esModule', {value: true});
10389
- Object.keys(n).forEach(function (k) {
10390
- var d = Object.getOwnPropertyDescriptor(n, k);
10391
- Object.defineProperty(a, k, d.get ? d : {
10392
- enumerable: true,
10393
- get: function () {
10394
- return n[k];
10395
- }
10396
- });
10397
- });
10398
- return a;
10399
- }
10400
-
10401
10030
  var utils = {};
10402
10031
 
10403
10032
  var constants;
@@ -11936,7 +11565,7 @@ function requireParse () {
11936
11565
  }
11937
11566
 
11938
11567
  if (prior.type === 'slash' && prior.prev.type !== 'bos' && rest[0] === '/') {
11939
- const end = rest[1] !== void 0 ? '|$' : '';
11568
+ const end = rest[1] !== undefined ? '|$' : '';
11940
11569
 
11941
11570
  state.output = state.output.slice(0, -(prior.output + prev.output).length);
11942
11571
  prior.output = `(?:${prior.output}`;
@@ -12651,37 +12280,21 @@ class ArrayPattern extends NodeBase {
12651
12280
  element?.addExportedVariables(variables, exportNamesByVariable);
12652
12281
  }
12653
12282
  }
12654
- declare(kind, destructuredInitPath, init) {
12283
+ declare(kind) {
12655
12284
  const variables = [];
12656
- const includedPatternPath = getIncludedPatternPath(destructuredInitPath);
12657
12285
  for (const element of this.elements) {
12658
12286
  if (element !== null) {
12659
- variables.push(...element.declare(kind, includedPatternPath, init));
12287
+ variables.push(...element.declare(kind, UNKNOWN_EXPRESSION));
12660
12288
  }
12661
12289
  }
12662
12290
  return variables;
12663
12291
  }
12664
- deoptimizeAssignment(destructuredInitPath, init) {
12665
- const includedPatternPath = getIncludedPatternPath(destructuredInitPath);
12666
- for (const element of this.elements) {
12667
- element?.deoptimizeAssignment(includedPatternPath, init);
12668
- }
12669
- }
12670
12292
  // Patterns can only be deoptimized at the empty path at the moment
12671
12293
  deoptimizePath() {
12672
12294
  for (const element of this.elements) {
12673
12295
  element?.deoptimizePath(EMPTY_PATH);
12674
12296
  }
12675
12297
  }
12676
- hasEffectsWhenDestructuring(context, destructuredInitPath, init) {
12677
- const includedPatternPath = getIncludedPatternPath(destructuredInitPath);
12678
- for (const element of this.elements) {
12679
- if (element?.hasEffectsWhenDestructuring(context, includedPatternPath, init)) {
12680
- return true;
12681
- }
12682
- }
12683
- return false;
12684
- }
12685
12298
  // Patterns are only checked at the empty path at the moment
12686
12299
  hasEffectsOnInteractionAtPath(_path, interaction, context) {
12687
12300
  for (const element of this.elements) {
@@ -12690,38 +12303,12 @@ class ArrayPattern extends NodeBase {
12690
12303
  }
12691
12304
  return false;
12692
12305
  }
12693
- includeDestructuredIfNecessary(context, destructuredInitPath, init) {
12694
- let included = false;
12695
- const includedPatternPath = getIncludedPatternPath(destructuredInitPath);
12696
- for (const element of this.elements) {
12697
- if (element) {
12698
- element.included ||= included;
12699
- included =
12700
- element.includeDestructuredIfNecessary(context, includedPatternPath, init) || included;
12701
- }
12702
- }
12703
- if (included) {
12704
- // This is necessary so that if any pattern element is included, all are
12705
- // included for proper deconflicting
12706
- for (const element of this.elements) {
12707
- if (element && !element.included) {
12708
- element.included = true;
12709
- element.includeDestructuredIfNecessary(context, includedPatternPath, init);
12710
- }
12711
- }
12712
- }
12713
- return (this.included ||= included);
12714
- }
12715
12306
  markDeclarationReached() {
12716
12307
  for (const element of this.elements) {
12717
12308
  element?.markDeclarationReached();
12718
12309
  }
12719
12310
  }
12720
12311
  }
12721
- ArrayPattern.prototype.includeNode = onlyIncludeSelf;
12722
- const getIncludedPatternPath = (destructuredInitPath) => destructuredInitPath.at(-1) === UnknownKey
12723
- ? destructuredInitPath
12724
- : [...destructuredInitPath, UnknownInteger];
12725
12312
 
12726
12313
  class ArrowFunctionExpression extends FunctionBase {
12727
12314
  constructor() {
@@ -12738,6 +12325,8 @@ class ArrowFunctionExpression extends FunctionBase {
12738
12325
  this.scope = new ReturnValueScope(parentScope, false);
12739
12326
  }
12740
12327
  hasEffects() {
12328
+ if (!this.deoptimized)
12329
+ this.applyDeoptimizations();
12741
12330
  return false;
12742
12331
  }
12743
12332
  hasEffectsOnInteractionAtPath(path, interaction, context) {
@@ -12776,15 +12365,6 @@ class ArrowFunctionExpression extends FunctionBase {
12776
12365
  }
12777
12366
  }
12778
12367
  }
12779
- includeNode(context) {
12780
- this.included = true;
12781
- this.body.includePath(UNKNOWN_PATH, context);
12782
- for (const parameter of this.params) {
12783
- if (!(parameter instanceof Identifier)) {
12784
- parameter.includePath(UNKNOWN_PATH, context);
12785
- }
12786
- }
12787
- }
12788
12368
  getObjectEntity() {
12789
12369
  if (this.objectEntity !== null) {
12790
12370
  return this.objectEntity;
@@ -12804,18 +12384,13 @@ class ObjectPattern extends NodeBase {
12804
12384
  }
12805
12385
  }
12806
12386
  }
12807
- declare(kind, destructuredInitPath, init) {
12387
+ declare(kind, init) {
12808
12388
  const variables = [];
12809
12389
  for (const property of this.properties) {
12810
- variables.push(...property.declare(kind, destructuredInitPath, init));
12390
+ variables.push(...property.declare(kind, init));
12811
12391
  }
12812
12392
  return variables;
12813
12393
  }
12814
- deoptimizeAssignment(destructuredInitPath, init) {
12815
- for (const property of this.properties) {
12816
- property.deoptimizeAssignment(destructuredInitPath, init);
12817
- }
12818
- }
12819
12394
  deoptimizePath(path) {
12820
12395
  if (path.length === 0) {
12821
12396
  for (const property of this.properties) {
@@ -12833,46 +12408,12 @@ class ObjectPattern extends NodeBase {
12833
12408
  }
12834
12409
  return false;
12835
12410
  }
12836
- hasEffectsWhenDestructuring(context, destructuredInitPath, init) {
12837
- for (const property of this.properties) {
12838
- if (property.hasEffectsWhenDestructuring(context, destructuredInitPath, init))
12839
- return true;
12840
- }
12841
- return false;
12842
- }
12843
- includeDestructuredIfNecessary(context, destructuredInitPath, init) {
12844
- let included = false;
12845
- for (const property of this.properties) {
12846
- included =
12847
- property.includeDestructuredIfNecessary(context, destructuredInitPath, init) || included;
12848
- }
12849
- return (this.included ||= included);
12850
- }
12851
12411
  markDeclarationReached() {
12852
12412
  for (const property of this.properties) {
12853
12413
  property.markDeclarationReached();
12854
12414
  }
12855
12415
  }
12856
- render(code, options) {
12857
- if (this.properties.length > 0) {
12858
- const separatedNodes = getCommaSeparatedNodesWithBoundaries(this.properties, code, this.start + 1, this.end - 1);
12859
- let lastSeparatorPos = null;
12860
- for (const { node, separator, start, end } of separatedNodes) {
12861
- if (!node.included) {
12862
- treeshakeNode(node, code, start, end);
12863
- continue;
12864
- }
12865
- lastSeparatorPos = separator;
12866
- node.render(code, options);
12867
- }
12868
- if (lastSeparatorPos) {
12869
- code.remove(lastSeparatorPos, this.end - 1);
12870
- }
12871
- }
12872
- }
12873
12416
  }
12874
- ObjectPattern.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
12875
- ObjectPattern.prototype.applyDeoptimizations = doNotDeoptimize;
12876
12417
 
12877
12418
  class AssignmentExpression extends NodeBase {
12878
12419
  hasEffects(context) {
@@ -12881,9 +12422,7 @@ class AssignmentExpression extends NodeBase {
12881
12422
  this.applyDeoptimizations();
12882
12423
  // MemberExpressions do not access the property before assignments if the
12883
12424
  // operator is '='.
12884
- return (right.hasEffects(context) ||
12885
- left.hasEffectsAsAssignmentTarget(context, operator !== '=') ||
12886
- this.left.hasEffectsWhenDestructuring?.(context, EMPTY_PATH, right));
12425
+ return (right.hasEffects(context) || left.hasEffectsAsAssignmentTarget(context, operator !== '='));
12887
12426
  }
12888
12427
  hasEffectsOnInteractionAtPath(path, interaction, context) {
12889
12428
  return this.right.hasEffectsOnInteractionAtPath(path, interaction, context);
@@ -12892,24 +12431,15 @@ class AssignmentExpression extends NodeBase {
12892
12431
  const { deoptimized, left, right, operator } = this;
12893
12432
  if (!deoptimized)
12894
12433
  this.applyDeoptimizations();
12895
- if (!this.included)
12896
- this.includeNode(context);
12897
- const hasEffectsContext = createHasEffectsContext();
12434
+ this.included = true;
12898
12435
  if (includeChildrenRecursively ||
12899
12436
  operator !== '=' ||
12900
12437
  left.included ||
12901
- left.hasEffectsAsAssignmentTarget(hasEffectsContext, false) ||
12902
- left.hasEffectsWhenDestructuring?.(hasEffectsContext, EMPTY_PATH, right)) {
12438
+ left.hasEffectsAsAssignmentTarget(createHasEffectsContext(), false)) {
12903
12439
  left.includeAsAssignmentTarget(context, includeChildrenRecursively, operator !== '=');
12904
12440
  }
12905
12441
  right.include(context, includeChildrenRecursively);
12906
12442
  }
12907
- includeNode(context) {
12908
- this.included = true;
12909
- if (!this.deoptimized)
12910
- this.applyDeoptimizations();
12911
- this.right.includePath(UNKNOWN_PATH, context);
12912
- }
12913
12443
  initialise() {
12914
12444
  super.initialise();
12915
12445
  if (this.left instanceof Identifier) {
@@ -12970,7 +12500,8 @@ class AssignmentExpression extends NodeBase {
12970
12500
  }
12971
12501
  applyDeoptimizations() {
12972
12502
  this.deoptimized = true;
12973
- this.left.deoptimizeAssignment(EMPTY_PATH, this.right);
12503
+ this.left.deoptimizePath(EMPTY_PATH);
12504
+ this.right.deoptimizePath(UNKNOWN_PATH);
12974
12505
  this.scope.context.requestTreeshakingPass();
12975
12506
  }
12976
12507
  }
@@ -12979,11 +12510,8 @@ class AssignmentPattern extends NodeBase {
12979
12510
  addExportedVariables(variables, exportNamesByVariable) {
12980
12511
  this.left.addExportedVariables(variables, exportNamesByVariable);
12981
12512
  }
12982
- declare(kind, destructuredInitPath, init) {
12983
- return this.left.declare(kind, destructuredInitPath, init);
12984
- }
12985
- deoptimizeAssignment(destructuredInitPath, init) {
12986
- this.left.deoptimizeAssignment(destructuredInitPath, init);
12513
+ declare(kind, init) {
12514
+ return this.left.declare(kind, init);
12987
12515
  }
12988
12516
  deoptimizePath(path) {
12989
12517
  if (path.length === 0) {
@@ -12993,29 +12521,6 @@ class AssignmentPattern extends NodeBase {
12993
12521
  hasEffectsOnInteractionAtPath(path, interaction, context) {
12994
12522
  return (path.length > 0 || this.left.hasEffectsOnInteractionAtPath(EMPTY_PATH, interaction, context));
12995
12523
  }
12996
- hasEffectsWhenDestructuring(context, destructuredInitPath, init) {
12997
- return this.left.hasEffectsWhenDestructuring(context, destructuredInitPath, init);
12998
- }
12999
- includeDestructuredIfNecessary(context, destructuredInitPath, init) {
13000
- let included = this.left.includeDestructuredIfNecessary(context, destructuredInitPath, init) ||
13001
- this.included;
13002
- if ((included ||= this.right.shouldBeIncluded(context))) {
13003
- this.right.include(context, false);
13004
- if (!this.left.included) {
13005
- this.left.included = true;
13006
- // Unfortunately, we need to include the left side again now, so that
13007
- // any declared variables are properly included.
13008
- this.left.includeDestructuredIfNecessary(context, destructuredInitPath, init);
13009
- }
13010
- }
13011
- return (this.included = included);
13012
- }
13013
- includeNode(context) {
13014
- this.included = true;
13015
- if (!this.deoptimized)
13016
- this.applyDeoptimizations();
13017
- this.right.includePath(UNKNOWN_PATH, context);
13018
- }
13019
12524
  markDeclarationReached() {
13020
12525
  this.left.markDeclarationReached();
13021
12526
  }
@@ -13038,34 +12543,22 @@ class AwaitExpression extends NodeBase {
13038
12543
  return true;
13039
12544
  }
13040
12545
  include(context, includeChildrenRecursively) {
13041
- if (!this.included)
13042
- this.includeNode(context);
13043
- this.argument.include(context, includeChildrenRecursively);
13044
- }
13045
- includeNode(context) {
13046
- this.included = true;
13047
12546
  if (!this.deoptimized)
13048
12547
  this.applyDeoptimizations();
13049
- checkTopLevelAwait: if (!this.scope.context.usesTopLevelAwait) {
13050
- let parent = this.parent;
13051
- do {
13052
- if (parent instanceof FunctionNode || parent instanceof ArrowFunctionExpression)
13053
- break checkTopLevelAwait;
13054
- } while ((parent = parent.parent));
13055
- 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
+ }
13056
12558
  }
13057
- // Thenables need to be included
13058
- this.argument.includePath(THEN_PATH, context);
13059
- }
13060
- includePath(path, context) {
13061
- if (!this.deoptimized)
13062
- this.applyDeoptimizations();
13063
- if (!this.included)
13064
- this.includeNode(context);
13065
- this.argument.includePath(path, context);
12559
+ this.argument.include(context, includeChildrenRecursively);
13066
12560
  }
13067
12561
  }
13068
- const THEN_PATH = ['then'];
13069
12562
 
13070
12563
  const binaryOperators = {
13071
12564
  '!=': (left, right) => left != right,
@@ -13119,13 +12612,7 @@ class BinaryExpression extends NodeBase {
13119
12612
  return super.hasEffects(context);
13120
12613
  }
13121
12614
  hasEffectsOnInteractionAtPath(path, { type }) {
13122
- return type !== INTERACTION_ACCESSED || path.length > 1;
13123
- }
13124
- includeNode(context) {
13125
- this.included = true;
13126
- if (this.operator === 'in') {
13127
- this.right.includePath(UNKNOWN_PATH, context);
13128
- }
12615
+ return type !== INTERACTION_ACCESSED || path.length > 1;
13129
12616
  }
13130
12617
  removeAnnotations(code) {
13131
12618
  this.left.removeAnnotations(code);
@@ -13135,7 +12622,6 @@ class BinaryExpression extends NodeBase {
13135
12622
  this.right.render(code, options);
13136
12623
  }
13137
12624
  }
13138
- BinaryExpression.prototype.applyDeoptimizations = doNotDeoptimize;
13139
12625
 
13140
12626
  class BreakStatement extends NodeBase {
13141
12627
  hasEffects(context) {
@@ -13155,7 +12641,7 @@ class BreakStatement extends NodeBase {
13155
12641
  include(context) {
13156
12642
  this.included = true;
13157
12643
  if (this.label) {
13158
- this.label.include(context);
12644
+ this.label.include();
13159
12645
  context.includedLabels.add(this.label.name);
13160
12646
  }
13161
12647
  else {
@@ -13164,8 +12650,6 @@ class BreakStatement extends NodeBase {
13164
12650
  context.brokenFlow = true;
13165
12651
  }
13166
12652
  }
13167
- BreakStatement.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
13168
- BreakStatement.prototype.applyDeoptimizations = doNotDeoptimize;
13169
12653
 
13170
12654
  function renderCallArguments(code, options, node) {
13171
12655
  if (node.arguments.length > 0) {
@@ -13352,14 +12836,10 @@ class CallExpression extends CallExpressionBase {
13352
12836
  this.callee.hasEffectsOnInteractionAtPath(EMPTY_PATH, this.interaction, context)));
13353
12837
  }
13354
12838
  include(context, includeChildrenRecursively) {
13355
- if (!this.included)
13356
- this.includeNode(context);
12839
+ if (!this.deoptimized)
12840
+ this.applyDeoptimizations();
13357
12841
  if (includeChildrenRecursively) {
13358
- this.callee.include(context, true);
13359
- for (const argument of this.arguments) {
13360
- argument.includePath(UNKNOWN_PATH, context);
13361
- argument.include(context, true);
13362
- }
12842
+ super.include(context, includeChildrenRecursively);
13363
12843
  if (includeChildrenRecursively === INCLUDE_PARAMETERS &&
13364
12844
  this.callee instanceof Identifier &&
13365
12845
  this.callee.variable) {
@@ -13367,24 +12847,10 @@ class CallExpression extends CallExpressionBase {
13367
12847
  }
13368
12848
  }
13369
12849
  else {
13370
- // If the callee is a member expression and does not have a variable, its
13371
- // object will already be included via the first argument of the
13372
- // interaction in includeCallArguments. Including it again can lead to
13373
- // severe performance problems.
13374
- if (this.callee instanceof MemberExpression && !this.callee.variable) {
13375
- this.callee.property.include(context, false);
13376
- }
13377
- else {
13378
- this.callee.include(context, false);
13379
- }
13380
- this.callee.includeCallArguments(context, this.interaction);
12850
+ this.included = true;
12851
+ this.callee.include(context, false);
13381
12852
  }
13382
- }
13383
- includeNode(context) {
13384
- this.included = true;
13385
- if (!this.deoptimized)
13386
- this.applyDeoptimizations();
13387
- this.callee.includePath(UNKNOWN_PATH, context);
12853
+ this.callee.includeCallArguments(context, this.arguments);
13388
12854
  }
13389
12855
  initialise() {
13390
12856
  super.initialise();
@@ -13423,14 +12889,13 @@ class CatchClause extends NodeBase {
13423
12889
  this.type = type;
13424
12890
  if (param) {
13425
12891
  this.param = new (this.scope.context.getNodeConstructor(param.type))(this, this.scope).parseNode(param);
13426
- this.param.declare('parameter', EMPTY_PATH, UNKNOWN_EXPRESSION);
12892
+ this.param.declare('parameter', UNKNOWN_EXPRESSION);
13427
12893
  }
13428
12894
  this.body = new BlockStatement(this, this.scope.bodyScope).parseNode(body);
13429
12895
  return super.parseNode(esTreeNode);
13430
12896
  }
13431
12897
  }
13432
12898
  CatchClause.prototype.preventChildBlockScope = true;
13433
- CatchClause.prototype.includeNode = onlyIncludeSelf;
13434
12899
 
13435
12900
  class ChainExpression extends NodeBase {
13436
12901
  // deoptimizations are not relevant as we are not caching values
@@ -13442,22 +12907,17 @@ class ChainExpression extends NodeBase {
13442
12907
  hasEffects(context) {
13443
12908
  return this.expression.hasEffectsAsChainElement(context) === true;
13444
12909
  }
13445
- includePath(path, context) {
13446
- this.included = true;
13447
- this.expression.includePath(path, context);
13448
- }
13449
12910
  removeAnnotations(code) {
13450
12911
  this.expression.removeAnnotations(code);
13451
12912
  }
12913
+ applyDeoptimizations() { }
13452
12914
  }
13453
- ChainExpression.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
13454
- ChainExpression.prototype.applyDeoptimizations = doNotDeoptimize;
13455
12915
 
13456
12916
  class ClassBodyScope extends ChildScope {
13457
12917
  constructor(parent, classNode) {
13458
12918
  const { context } = parent;
13459
12919
  super(parent, context);
13460
- 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')));
13461
12921
  this.instanceScope = new ChildScope(this, context);
13462
12922
  this.instanceScope.variables.set('this', new ThisVariable(context));
13463
12923
  }
@@ -13472,7 +12932,7 @@ class ClassBody extends NodeBase {
13472
12932
  }
13473
12933
  include(context, includeChildrenRecursively) {
13474
12934
  this.included = true;
13475
- this.scope.context.includeVariableInModule(this.scope.thisVariable, UNKNOWN_PATH, context);
12935
+ this.scope.context.includeVariableInModule(this.scope.thisVariable);
13476
12936
  for (const definition of this.body) {
13477
12937
  definition.include(context, includeChildrenRecursively);
13478
12938
  }
@@ -13485,9 +12945,8 @@ class ClassBody extends NodeBase {
13485
12945
  }
13486
12946
  return super.parseNode(esTreeNode);
13487
12947
  }
12948
+ applyDeoptimizations() { }
13488
12949
  }
13489
- ClassBody.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
13490
- ClassBody.prototype.applyDeoptimizations = doNotDeoptimize;
13491
12950
 
13492
12951
  class ClassExpression extends ClassNode {
13493
12952
  render(code, options, { renderedSurroundingElement } = parseAst_js.BLANK) {
@@ -13558,9 +13017,6 @@ class ConditionalExpression extends NodeBase {
13558
13017
  const unusedBranch = this.usedBranch === this.consequent ? this.alternate : this.consequent;
13559
13018
  this.usedBranch = null;
13560
13019
  unusedBranch.deoptimizePath(UNKNOWN_PATH);
13561
- if (this.included) {
13562
- unusedBranch.includePath(UNKNOWN_PATH, createInclusionContext());
13563
- }
13564
13020
  const { expressionsToBeDeoptimized } = this;
13565
13021
  this.expressionsToBeDeoptimized = parseAst_js.EMPTY_ARRAY;
13566
13022
  for (const expression of expressionsToBeDeoptimized) {
@@ -13618,7 +13074,7 @@ class ConditionalExpression extends NodeBase {
13618
13074
  include(context, includeChildrenRecursively) {
13619
13075
  this.included = true;
13620
13076
  const usedBranch = this.getUsedBranch();
13621
- if (usedBranch === null || includeChildrenRecursively || this.test.shouldBeIncluded(context)) {
13077
+ if (includeChildrenRecursively || this.test.shouldBeIncluded(context) || usedBranch === null) {
13622
13078
  this.test.include(context, includeChildrenRecursively);
13623
13079
  this.consequent.include(context, includeChildrenRecursively);
13624
13080
  this.alternate.include(context, includeChildrenRecursively);
@@ -13627,38 +13083,27 @@ class ConditionalExpression extends NodeBase {
13627
13083
  usedBranch.include(context, includeChildrenRecursively);
13628
13084
  }
13629
13085
  }
13630
- includePath(path, context) {
13631
- this.included = true;
13632
- const usedBranch = this.getUsedBranch();
13633
- if (usedBranch === null || this.test.shouldBeIncluded(context)) {
13634
- this.consequent.includePath(path, context);
13635
- this.alternate.includePath(path, context);
13636
- }
13637
- else {
13638
- usedBranch.includePath(path, context);
13639
- }
13640
- }
13641
- includeCallArguments(context, interaction) {
13086
+ includeCallArguments(context, parameters) {
13642
13087
  const usedBranch = this.getUsedBranch();
13643
13088
  if (usedBranch) {
13644
- usedBranch.includeCallArguments(context, interaction);
13089
+ usedBranch.includeCallArguments(context, parameters);
13645
13090
  }
13646
13091
  else {
13647
- this.consequent.includeCallArguments(context, interaction);
13648
- this.alternate.includeCallArguments(context, interaction);
13092
+ this.consequent.includeCallArguments(context, parameters);
13093
+ this.alternate.includeCallArguments(context, parameters);
13649
13094
  }
13650
13095
  }
13651
13096
  removeAnnotations(code) {
13652
13097
  this.test.removeAnnotations(code);
13653
13098
  }
13654
13099
  render(code, options, { isCalleeOfRenderedParent, preventASI, renderedParentType, renderedSurroundingElement } = parseAst_js.BLANK) {
13100
+ const usedBranch = this.getUsedBranch();
13655
13101
  if (this.test.included) {
13656
13102
  this.test.render(code, options, { renderedSurroundingElement });
13657
13103
  this.consequent.render(code, options);
13658
13104
  this.alternate.render(code, options);
13659
13105
  }
13660
13106
  else {
13661
- const usedBranch = this.getUsedBranch();
13662
13107
  const colonPos = findFirstOccurrenceOutsideComment(code.original, ':', this.consequent.end);
13663
13108
  const inclusionStart = findNonWhiteSpace(code.original, (this.consequent.included
13664
13109
  ? findFirstOccurrenceOutsideComment(code.original, '?', this.test.end)
@@ -13690,8 +13135,6 @@ class ConditionalExpression extends NodeBase {
13690
13135
  : (this.usedBranch = testValue ? this.consequent : this.alternate);
13691
13136
  }
13692
13137
  }
13693
- ConditionalExpression.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
13694
- ConditionalExpression.prototype.applyDeoptimizations = doNotDeoptimize;
13695
13138
 
13696
13139
  class ContinueStatement extends NodeBase {
13697
13140
  hasEffects(context) {
@@ -13711,7 +13154,7 @@ class ContinueStatement extends NodeBase {
13711
13154
  include(context) {
13712
13155
  this.included = true;
13713
13156
  if (this.label) {
13714
- this.label.include(context);
13157
+ this.label.include();
13715
13158
  context.includedLabels.add(this.label.name);
13716
13159
  }
13717
13160
  else {
@@ -13720,15 +13163,12 @@ class ContinueStatement extends NodeBase {
13720
13163
  context.brokenFlow = true;
13721
13164
  }
13722
13165
  }
13723
- ContinueStatement.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
13724
- ContinueStatement.prototype.applyDeoptimizations = doNotDeoptimize;
13725
13166
 
13726
13167
  class DebuggerStatement extends NodeBase {
13727
13168
  hasEffects() {
13728
13169
  return true;
13729
13170
  }
13730
13171
  }
13731
- DebuggerStatement.prototype.includeNode = onlyIncludeSelf;
13732
13172
 
13733
13173
  class Decorator extends NodeBase {
13734
13174
  hasEffects(context) {
@@ -13736,7 +13176,6 @@ class Decorator extends NodeBase {
13736
13176
  this.expression.hasEffectsOnInteractionAtPath(EMPTY_PATH, NODE_INTERACTION_UNKNOWN_CALL, context));
13737
13177
  }
13738
13178
  }
13739
- Decorator.prototype.includeNode = onlyIncludeSelf;
13740
13179
 
13741
13180
  function hasLoopBodyEffects(context, body) {
13742
13181
  const { brokenFlow, hasBreak, hasContinue, ignore } = context;
@@ -13776,15 +13215,12 @@ class DoWhileStatement extends NodeBase {
13776
13215
  includeLoopBody(context, this.body, includeChildrenRecursively);
13777
13216
  }
13778
13217
  }
13779
- DoWhileStatement.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
13780
- DoWhileStatement.prototype.applyDeoptimizations = doNotDeoptimize;
13781
13218
 
13782
13219
  class EmptyStatement extends NodeBase {
13783
13220
  hasEffects() {
13784
13221
  return false;
13785
13222
  }
13786
13223
  }
13787
- EmptyStatement.prototype.includeNode = onlyIncludeSelf;
13788
13224
 
13789
13225
  class ExportAllDeclaration extends NodeBase {
13790
13226
  hasEffects() {
@@ -13797,10 +13233,9 @@ class ExportAllDeclaration extends NodeBase {
13797
13233
  render(code, _options, nodeRenderOptions) {
13798
13234
  code.remove(nodeRenderOptions.start, nodeRenderOptions.end);
13799
13235
  }
13236
+ applyDeoptimizations() { }
13800
13237
  }
13801
13238
  ExportAllDeclaration.prototype.needsBoundaries = true;
13802
- ExportAllDeclaration.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
13803
- ExportAllDeclaration.prototype.applyDeoptimizations = doNotDeoptimize;
13804
13239
 
13805
13240
  class ExportNamedDeclaration extends NodeBase {
13806
13241
  bind() {
@@ -13827,15 +13262,13 @@ class ExportNamedDeclaration extends NodeBase {
13827
13262
  this.declaration.render(code, options, { end, start });
13828
13263
  }
13829
13264
  }
13265
+ applyDeoptimizations() { }
13830
13266
  }
13831
13267
  ExportNamedDeclaration.prototype.needsBoundaries = true;
13832
- ExportNamedDeclaration.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
13833
- ExportNamedDeclaration.prototype.applyDeoptimizations = doNotDeoptimize;
13834
13268
 
13835
13269
  class ExportSpecifier extends NodeBase {
13270
+ applyDeoptimizations() { }
13836
13271
  }
13837
- ExportSpecifier.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
13838
- ExportSpecifier.prototype.applyDeoptimizations = doNotDeoptimize;
13839
13272
 
13840
13273
  class ForInStatement extends NodeBase {
13841
13274
  createScope(parentScope) {
@@ -13853,18 +13286,11 @@ class ForInStatement extends NodeBase {
13853
13286
  const { body, deoptimized, left, right } = this;
13854
13287
  if (!deoptimized)
13855
13288
  this.applyDeoptimizations();
13856
- if (!this.included)
13857
- this.includeNode(context);
13289
+ this.included = true;
13858
13290
  left.includeAsAssignmentTarget(context, includeChildrenRecursively || true, false);
13859
13291
  right.include(context, includeChildrenRecursively);
13860
13292
  includeLoopBody(context, body, includeChildrenRecursively);
13861
13293
  }
13862
- includeNode(context) {
13863
- this.included = true;
13864
- if (!this.deoptimized)
13865
- this.applyDeoptimizations();
13866
- this.right.includePath(UNKNOWN_PATH, context);
13867
- }
13868
13294
  initialise() {
13869
13295
  super.initialise();
13870
13296
  this.left.setAssignedValue(UNKNOWN_EXPRESSION);
@@ -13905,18 +13331,11 @@ class ForOfStatement extends NodeBase {
13905
13331
  const { body, deoptimized, left, right } = this;
13906
13332
  if (!deoptimized)
13907
13333
  this.applyDeoptimizations();
13908
- if (!this.included)
13909
- this.includeNode(context);
13334
+ this.included = true;
13910
13335
  left.includeAsAssignmentTarget(context, includeChildrenRecursively || true, false);
13911
13336
  right.include(context, includeChildrenRecursively);
13912
13337
  includeLoopBody(context, body, includeChildrenRecursively);
13913
13338
  }
13914
- includeNode(context) {
13915
- this.included = true;
13916
- if (!this.deoptimized)
13917
- this.applyDeoptimizations();
13918
- this.right.includePath(UNKNOWN_PATH, context);
13919
- }
13920
13339
  initialise() {
13921
13340
  super.initialise();
13922
13341
  this.left.setAssignedValue(UNKNOWN_EXPRESSION);
@@ -13952,9 +13371,7 @@ class ForStatement extends NodeBase {
13952
13371
  }
13953
13372
  include(context, includeChildrenRecursively) {
13954
13373
  this.included = true;
13955
- this.init?.include(context, includeChildrenRecursively, {
13956
- asSingleStatement: true
13957
- });
13374
+ this.init?.include(context, includeChildrenRecursively, { asSingleStatement: true });
13958
13375
  this.test?.include(context, includeChildrenRecursively);
13959
13376
  this.update?.include(context, includeChildrenRecursively);
13960
13377
  includeLoopBody(context, this.body, includeChildrenRecursively);
@@ -13966,8 +13383,6 @@ class ForStatement extends NodeBase {
13966
13383
  this.body.render(code, options);
13967
13384
  }
13968
13385
  }
13969
- ForStatement.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
13970
- ForStatement.prototype.applyDeoptimizations = doNotDeoptimize;
13971
13386
 
13972
13387
  class FunctionExpression extends FunctionNode {
13973
13388
  createScope(parentScope) {
@@ -13999,9 +13414,9 @@ class TrackingScope extends BlockScope {
13999
13414
  super(...arguments);
14000
13415
  this.hoistedDeclarations = [];
14001
13416
  }
14002
- addDeclaration(identifier, context, init, destructuredInitPath, kind) {
13417
+ addDeclaration(identifier, context, init, kind) {
14003
13418
  this.hoistedDeclarations.push(identifier);
14004
- return super.addDeclaration(identifier, context, init, destructuredInitPath, kind);
13419
+ return super.addDeclaration(identifier, context, init, kind);
14005
13420
  }
14006
13421
  }
14007
13422
 
@@ -14100,6 +13515,7 @@ class IfStatement extends NodeBase {
14100
13515
  }
14101
13516
  this.renderHoistedDeclarations(hoistedDeclarations, code, getPropertyAccess);
14102
13517
  }
13518
+ applyDeoptimizations() { }
14103
13519
  getTestValue() {
14104
13520
  if (this.testValue === unset) {
14105
13521
  return (this.testValue = tryCastLiteralValueToBoolean(this.test.getLiteralValueAtPath(EMPTY_PATH, SHARED_RECURSION_TRACKER, this)));
@@ -14168,8 +13584,6 @@ class IfStatement extends NodeBase {
14168
13584
  return false;
14169
13585
  }
14170
13586
  }
14171
- IfStatement.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
14172
- IfStatement.prototype.applyDeoptimizations = doNotDeoptimize;
14173
13587
 
14174
13588
  class ImportAttribute extends NodeBase {
14175
13589
  }
@@ -14187,15 +13601,13 @@ class ImportDeclaration extends NodeBase {
14187
13601
  render(code, _options, nodeRenderOptions) {
14188
13602
  code.remove(nodeRenderOptions.start, nodeRenderOptions.end);
14189
13603
  }
13604
+ applyDeoptimizations() { }
14190
13605
  }
14191
13606
  ImportDeclaration.prototype.needsBoundaries = true;
14192
- ImportDeclaration.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
14193
- ImportDeclaration.prototype.applyDeoptimizations = doNotDeoptimize;
14194
13607
 
14195
13608
  class ImportDefaultSpecifier extends NodeBase {
13609
+ applyDeoptimizations() { }
14196
13610
  }
14197
- ImportDefaultSpecifier.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
14198
- ImportDefaultSpecifier.prototype.applyDeoptimizations = doNotDeoptimize;
14199
13611
 
14200
13612
  function isReassignedExportsMember(variable, exportNamesByVariable) {
14201
13613
  return (variable.renderBaseName !== null && exportNamesByVariable.has(variable) && variable.isReassigned);
@@ -14204,33 +13616,28 @@ function isReassignedExportsMember(variable, exportNamesByVariable) {
14204
13616
  class VariableDeclarator extends NodeBase {
14205
13617
  declareDeclarator(kind, isUsingDeclaration) {
14206
13618
  this.isUsingDeclaration = isUsingDeclaration;
14207
- this.id.declare(kind, EMPTY_PATH, this.init || UNDEFINED_EXPRESSION);
13619
+ this.id.declare(kind, this.init || UNDEFINED_EXPRESSION);
14208
13620
  }
14209
13621
  deoptimizePath(path) {
14210
13622
  this.id.deoptimizePath(path);
14211
13623
  }
14212
13624
  hasEffects(context) {
13625
+ if (!this.deoptimized)
13626
+ this.applyDeoptimizations();
14213
13627
  const initEffect = this.init?.hasEffects(context);
14214
13628
  this.id.markDeclarationReached();
14215
- return (initEffect ||
14216
- this.isUsingDeclaration ||
14217
- this.id.hasEffects(context) ||
14218
- (this.scope.context.options.treeshake
14219
- .propertyReadSideEffects &&
14220
- this.id.hasEffectsWhenDestructuring(context, EMPTY_PATH, this.init || UNDEFINED_EXPRESSION)));
13629
+ return initEffect || this.id.hasEffects(context) || this.isUsingDeclaration;
14221
13630
  }
14222
13631
  include(context, includeChildrenRecursively) {
14223
- const { id, init } = this;
14224
- if (!this.included)
14225
- this.includeNode();
13632
+ const { deoptimized, id, init } = this;
13633
+ if (!deoptimized)
13634
+ this.applyDeoptimizations();
13635
+ this.included = true;
14226
13636
  init?.include(context, includeChildrenRecursively);
14227
13637
  id.markDeclarationReached();
14228
- if (includeChildrenRecursively) {
13638
+ if (includeChildrenRecursively || id.shouldBeIncluded(context)) {
14229
13639
  id.include(context, includeChildrenRecursively);
14230
13640
  }
14231
- else {
14232
- id.includeDestructuredIfNecessary(context, EMPTY_PATH, init || UNDEFINED_EXPRESSION);
14233
- }
14234
13641
  }
14235
13642
  removeAnnotations(code) {
14236
13643
  this.init?.removeAnnotations(code);
@@ -14260,8 +13667,8 @@ class VariableDeclarator extends NodeBase {
14260
13667
  code.appendLeft(end, `${_}=${_}void 0`);
14261
13668
  }
14262
13669
  }
14263
- includeNode() {
14264
- this.included = true;
13670
+ applyDeoptimizations() {
13671
+ this.deoptimized = true;
14265
13672
  const { id, init } = this;
14266
13673
  if (init && id instanceof Identifier && init instanceof ClassExpression && !init.id) {
14267
13674
  const { name, variable } = id;
@@ -14273,14 +13680,11 @@ class VariableDeclarator extends NodeBase {
14273
13680
  }
14274
13681
  }
14275
13682
  }
14276
- VariableDeclarator.prototype.applyDeoptimizations = doNotDeoptimize;
14277
13683
 
14278
13684
  class ImportExpression extends NodeBase {
14279
13685
  constructor() {
14280
13686
  super(...arguments);
14281
13687
  this.inlineNamespace = null;
14282
- this.hasUnknownAccessedKey = false;
14283
- this.accessedPropKey = new Set();
14284
13688
  this.attributes = null;
14285
13689
  this.mechanism = null;
14286
13690
  this.namespaceExportName = undefined;
@@ -14313,15 +13717,12 @@ class ImportExpression extends NodeBase {
14313
13717
  if (parent2 instanceof ExpressionStatement) {
14314
13718
  return parseAst_js.EMPTY_ARRAY;
14315
13719
  }
14316
- // Case 1: const { foo } / module = await import('bar')
13720
+ // Case 1: const { foo } = await import('bar')
14317
13721
  if (parent2 instanceof VariableDeclarator) {
14318
13722
  const declaration = parent2.id;
14319
- if (declaration instanceof Identifier) {
14320
- return this.hasUnknownAccessedKey ? undefined : [...this.accessedPropKey];
14321
- }
14322
- if (declaration instanceof ObjectPattern) {
14323
- return getDeterministicObjectDestructure(declaration);
14324
- }
13723
+ return declaration instanceof ObjectPattern
13724
+ ? getDeterministicObjectDestructure(declaration)
13725
+ : undefined;
14325
13726
  }
14326
13727
  // Case 2: (await import('bar')).foo
14327
13728
  if (parent2 instanceof MemberExpression) {
@@ -14371,29 +13772,12 @@ class ImportExpression extends NodeBase {
14371
13772
  return true;
14372
13773
  }
14373
13774
  include(context, includeChildrenRecursively) {
14374
- if (!this.included)
14375
- this.includeNode();
14376
- this.source.include(context, includeChildrenRecursively);
14377
- }
14378
- includeNode() {
14379
- this.included = true;
14380
- this.scope.context.includeDynamicImport(this);
14381
- this.scope.addAccessedDynamicImport(this);
14382
- }
14383
- includePath(path) {
14384
- if (!this.included)
14385
- this.includeNode();
14386
- // Technically, this is not correct as dynamic imports return a Promise.
14387
- if (this.hasUnknownAccessedKey)
14388
- return;
14389
- if (path[0] === UnknownKey) {
14390
- this.hasUnknownAccessedKey = true;
14391
- }
14392
- else if (typeof path[0] === 'string') {
14393
- this.accessedPropKey.add(path[0]);
13775
+ if (!this.included) {
13776
+ this.included = true;
13777
+ this.scope.context.includeDynamicImport(this);
13778
+ this.scope.addAccessedDynamicImport(this);
14394
13779
  }
14395
- // Update included paths
14396
- this.scope.context.includeDynamicImport(this);
13780
+ this.source.include(context, includeChildrenRecursively);
14397
13781
  }
14398
13782
  initialise() {
14399
13783
  super.initialise();
@@ -14463,6 +13847,7 @@ class ImportExpression extends NodeBase {
14463
13847
  setInternalResolution(inlineNamespace) {
14464
13848
  this.inlineNamespace = inlineNamespace;
14465
13849
  }
13850
+ applyDeoptimizations() { }
14466
13851
  getDynamicImportMechanismAndHelper(resolution, exportMode, { compact, dynamicImportInCjs, format, generatedCode: { arrowFunctions }, interop }, { _, getDirectReturnFunction, getDirectReturnIifeLeft }, pluginDriver) {
14467
13852
  const mechanism = pluginDriver.hookFirstSync('renderDynamicImport', [
14468
13853
  {
@@ -14552,7 +13937,6 @@ class ImportExpression extends NodeBase {
14552
13937
  return { helper: null, mechanism: null };
14553
13938
  }
14554
13939
  }
14555
- ImportExpression.prototype.applyDeoptimizations = doNotDeoptimize;
14556
13940
  function getInteropHelper(resolution, exportMode, interop) {
14557
13941
  return exportMode === 'external'
14558
13942
  ? namespaceInteropHelpersByInteropType[interop(resolution instanceof ExternalModule ? resolution.id : null)]
@@ -14576,14 +13960,12 @@ function getDeterministicObjectDestructure(objectPattern) {
14576
13960
  }
14577
13961
 
14578
13962
  class ImportNamespaceSpecifier extends NodeBase {
13963
+ applyDeoptimizations() { }
14579
13964
  }
14580
- ImportNamespaceSpecifier.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
14581
- ImportNamespaceSpecifier.prototype.applyDeoptimizations = doNotDeoptimize;
14582
13965
 
14583
13966
  class ImportSpecifier extends NodeBase {
13967
+ applyDeoptimizations() { }
14584
13968
  }
14585
- ImportSpecifier.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
14586
- ImportSpecifier.prototype.applyDeoptimizations = doNotDeoptimize;
14587
13969
 
14588
13970
  class JSXIdentifier extends IdentifierBase {
14589
13971
  constructor() {
@@ -14600,29 +13982,6 @@ class JSXIdentifier extends IdentifierBase {
14600
13982
  this.isNativeElement = true;
14601
13983
  }
14602
13984
  }
14603
- include(context) {
14604
- if (!this.included)
14605
- this.includeNode(context);
14606
- }
14607
- includeNode(context) {
14608
- this.included = true;
14609
- if (!this.deoptimized)
14610
- this.applyDeoptimizations();
14611
- if (this.variable !== null) {
14612
- this.scope.context.includeVariableInModule(this.variable, EMPTY_PATH, context);
14613
- }
14614
- }
14615
- includePath(path, context) {
14616
- if (!this.included) {
14617
- this.included = true;
14618
- if (this.variable !== null) {
14619
- this.scope.context.includeVariableInModule(this.variable, path, context);
14620
- }
14621
- }
14622
- else if (path.length > 0) {
14623
- this.variable?.includePath(path, context);
14624
- }
14625
- }
14626
13985
  render(code, { snippets: { getPropertyAccess }, useOriginalName }) {
14627
13986
  if (this.variable) {
14628
13987
  const name = this.variable.getName(getPropertyAccess, useOriginalName);
@@ -14684,7 +14043,6 @@ class JSXAttribute extends NodeBase {
14684
14043
  }
14685
14044
  }
14686
14045
  }
14687
- JSXAttribute.prototype.includeNode = onlyIncludeSelf;
14688
14046
 
14689
14047
  class JSXClosingBase extends NodeBase {
14690
14048
  render(code, options) {
@@ -14697,7 +14055,6 @@ class JSXClosingBase extends NodeBase {
14697
14055
  }
14698
14056
  }
14699
14057
  }
14700
- JSXClosingBase.prototype.includeNode = onlyIncludeSelf;
14701
14058
 
14702
14059
  class JSXClosingElement extends JSXClosingBase {
14703
14060
  }
@@ -14718,15 +14075,8 @@ class JSXSpreadAttribute extends NodeBase {
14718
14075
 
14719
14076
  class JSXEmptyExpression extends NodeBase {
14720
14077
  }
14721
- JSXEmptyExpression.prototype.includeNode = onlyIncludeSelf;
14722
14078
 
14723
14079
  class JSXExpressionContainer extends NodeBase {
14724
- includeNode(context) {
14725
- this.included = true;
14726
- if (!this.deoptimized)
14727
- this.applyDeoptimizations();
14728
- this.expression.includePath(UNKNOWN_PATH, context);
14729
- }
14730
14080
  render(code, options) {
14731
14081
  const { mode } = this.scope.context.options.jsx;
14732
14082
  if (mode !== 'preserve') {
@@ -14747,7 +14097,7 @@ function getRenderedJsxChildren(children) {
14747
14097
  return renderedChildren;
14748
14098
  }
14749
14099
 
14750
- function getAndIncludeFactoryVariable(factory, preserve, importSource, node, context) {
14100
+ function getAndIncludeFactoryVariable(factory, preserve, importSource, node) {
14751
14101
  const [baseName, nestedName] = factory.split('.');
14752
14102
  let factoryVariable;
14753
14103
  if (importSource) {
@@ -14755,7 +14105,7 @@ function getAndIncludeFactoryVariable(factory, preserve, importSource, node, con
14755
14105
  if (preserve) {
14756
14106
  // This pretends we are accessing an included global variable of the same name
14757
14107
  const globalVariable = node.scope.findGlobal(baseName);
14758
- globalVariable.includePath(UNKNOWN_PATH, context);
14108
+ globalVariable.include();
14759
14109
  // This excludes this variable from renaming
14760
14110
  factoryVariable.globalName = baseName;
14761
14111
  }
@@ -14763,7 +14113,7 @@ function getAndIncludeFactoryVariable(factory, preserve, importSource, node, con
14763
14113
  else {
14764
14114
  factoryVariable = node.scope.findGlobal(baseName);
14765
14115
  }
14766
- node.scope.context.includeVariableInModule(factoryVariable, UNKNOWN_PATH, context);
14116
+ node.scope.context.includeVariableInModule(factoryVariable);
14767
14117
  if (factoryVariable instanceof LocalVariable) {
14768
14118
  factoryVariable.consolidateInitializers();
14769
14119
  factoryVariable.addUsedPlace(node);
@@ -14786,20 +14136,16 @@ class JSXElementBase extends NodeBase {
14786
14136
  }
14787
14137
  }
14788
14138
  include(context, includeChildrenRecursively) {
14789
- if (!this.included)
14790
- this.includeNode(context);
14791
- for (const child of this.children) {
14792
- child.include(context, includeChildrenRecursively);
14793
- }
14794
- }
14795
- includeNode(context) {
14796
- this.included = true;
14797
- const { factory, importSource, mode } = this.jsxMode;
14798
- if (factory) {
14799
- this.factory = factory;
14800
- 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
+ }
14801
14145
  }
14146
+ super.include(context, includeChildrenRecursively);
14802
14147
  }
14148
+ applyDeoptimizations() { }
14803
14149
  getRenderingMode() {
14804
14150
  const jsx = this.scope.context.options.jsx;
14805
14151
  const { mode, factory, importSource } = jsx;
@@ -14837,14 +14183,8 @@ class JSXElementBase extends NodeBase {
14837
14183
  return { childrenEnd, firstChild, hasMultipleChildren };
14838
14184
  }
14839
14185
  }
14840
- JSXElementBase.prototype.applyDeoptimizations = doNotDeoptimize;
14841
14186
 
14842
14187
  class JSXElement extends JSXElementBase {
14843
- include(context, includeChildrenRecursively) {
14844
- super.include(context, includeChildrenRecursively);
14845
- this.openingElement.include(context, includeChildrenRecursively);
14846
- this.closingElement?.include(context, includeChildrenRecursively);
14847
- }
14848
14188
  render(code, options) {
14849
14189
  switch (this.jsxMode.mode) {
14850
14190
  case 'classic': {
@@ -14996,11 +14336,6 @@ class JSXElement extends JSXElementBase {
14996
14336
  }
14997
14337
 
14998
14338
  class JSXFragment extends JSXElementBase {
14999
- include(context, includeChildrenRecursively) {
15000
- super.include(context, includeChildrenRecursively);
15001
- this.openingFragment.include(context, includeChildrenRecursively);
15002
- this.closingFragment.include(context, includeChildrenRecursively);
15003
- }
15004
14339
  render(code, options) {
15005
14340
  switch (this.jsxMode.mode) {
15006
14341
  case 'classic': {
@@ -15050,22 +14385,10 @@ class JSXFragment extends JSXElementBase {
15050
14385
  }
15051
14386
 
15052
14387
  class JSXMemberExpression extends NodeBase {
15053
- includeNode(context) {
15054
- this.included = true;
15055
- if (!this.deoptimized)
15056
- this.applyDeoptimizations();
15057
- this.object.includePath([this.property.name], context);
15058
- }
15059
- includePath(path, context) {
15060
- if (!this.included)
15061
- this.includeNode(context);
15062
- this.object.includePath([this.property.name, ...path], context);
15063
- }
15064
14388
  }
15065
14389
 
15066
14390
  class JSXNamespacedName extends NodeBase {
15067
14391
  }
15068
- JSXNamespacedName.prototype.includeNode = onlyIncludeSelf;
15069
14392
 
15070
14393
  class JSXOpeningElement extends NodeBase {
15071
14394
  render(code, options, { jsxMode = this.scope.context.options.jsx.mode } = {}) {
@@ -15075,7 +14398,6 @@ class JSXOpeningElement extends NodeBase {
15075
14398
  }
15076
14399
  }
15077
14400
  }
15078
- JSXOpeningElement.prototype.includeNode = onlyIncludeSelf;
15079
14401
 
15080
14402
  class JSXOpeningFragment extends NodeBase {
15081
14403
  constructor() {
@@ -15083,22 +14405,22 @@ class JSXOpeningFragment extends NodeBase {
15083
14405
  this.fragment = null;
15084
14406
  this.fragmentVariable = null;
15085
14407
  }
15086
- includeNode(context) {
15087
- this.included = true;
15088
- if (!this.deoptimized)
15089
- this.applyDeoptimizations();
15090
- const jsx = this.scope.context.options.jsx;
15091
- if (jsx.mode === 'automatic') {
15092
- this.fragment = 'Fragment';
15093
- this.fragmentVariable = getAndIncludeFactoryVariable('Fragment', false, jsx.jsxImportSource, this, context);
15094
- }
15095
- else {
15096
- const { fragment, importSource, mode } = jsx;
15097
- if (fragment != null) {
15098
- this.fragment = fragment;
15099
- 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
+ }
15100
14421
  }
15101
14422
  }
14423
+ super.include(context, includeChildrenRecursively);
15102
14424
  }
15103
14425
  render(code, options) {
15104
14426
  const { mode } = this.scope.context.options.jsx;
@@ -15135,7 +14457,6 @@ class JSXText extends NodeBase {
15135
14457
  }
15136
14458
  }
15137
14459
  }
15138
- JSXText.prototype.includeNode = onlyIncludeSelf;
15139
14460
 
15140
14461
  class LabeledStatement extends NodeBase {
15141
14462
  hasEffects(context) {
@@ -15157,22 +14478,17 @@ class LabeledStatement extends NodeBase {
15157
14478
  return bodyHasEffects;
15158
14479
  }
15159
14480
  include(context, includeChildrenRecursively) {
15160
- if (!this.included)
15161
- this.includeNode(context);
14481
+ this.included = true;
15162
14482
  const { brokenFlow, includedLabels } = context;
15163
14483
  context.includedLabels = new Set();
15164
14484
  this.body.include(context, includeChildrenRecursively);
15165
14485
  if (includeChildrenRecursively || context.includedLabels.has(this.label.name)) {
15166
- this.label.include(context);
14486
+ this.label.include();
15167
14487
  context.includedLabels.delete(this.label.name);
15168
14488
  context.brokenFlow = brokenFlow;
15169
14489
  }
15170
14490
  context.includedLabels = new Set([...includedLabels, ...context.includedLabels]);
15171
14491
  }
15172
- includeNode(context) {
15173
- this.included = true;
15174
- this.body.includePath(UNKNOWN_PATH, context);
15175
- }
15176
14492
  render(code, options) {
15177
14493
  if (this.label.included) {
15178
14494
  this.label.render(code, options);
@@ -15183,7 +14499,6 @@ class LabeledStatement extends NodeBase {
15183
14499
  this.body.render(code, options);
15184
14500
  }
15185
14501
  }
15186
- LabeledStatement.prototype.applyDeoptimizations = doNotDeoptimize;
15187
14502
 
15188
14503
  class LogicalExpression extends NodeBase {
15189
14504
  constructor() {
@@ -15200,10 +14515,10 @@ class LogicalExpression extends NodeBase {
15200
14515
  this.flags = setFlag(this.flags, 65536 /* Flag.isBranchResolutionAnalysed */, value);
15201
14516
  }
15202
14517
  get hasDeoptimizedCache() {
15203
- return isFlagSet(this.flags, 33554432 /* Flag.hasDeoptimizedCache */);
14518
+ return isFlagSet(this.flags, 16777216 /* Flag.hasDeoptimizedCache */);
15204
14519
  }
15205
14520
  set hasDeoptimizedCache(value) {
15206
- this.flags = setFlag(this.flags, 33554432 /* Flag.hasDeoptimizedCache */, value);
14521
+ this.flags = setFlag(this.flags, 16777216 /* Flag.hasDeoptimizedCache */, value);
15207
14522
  }
15208
14523
  deoptimizeArgumentsOnInteractionAtPath(interaction, path, recursionTracker) {
15209
14524
  this.left.deoptimizeArgumentsOnInteractionAtPath(interaction, path, recursionTracker);
@@ -15216,10 +14531,6 @@ class LogicalExpression extends NodeBase {
15216
14531
  const unusedBranch = this.usedBranch === this.left ? this.right : this.left;
15217
14532
  this.usedBranch = null;
15218
14533
  unusedBranch.deoptimizePath(UNKNOWN_PATH);
15219
- if (this.included) {
15220
- // As we are not tracking inclusions, we just include everything
15221
- unusedBranch.includePath(UNKNOWN_PATH, createInclusionContext());
15222
- }
15223
14534
  }
15224
14535
  const { scope: { context }, expressionsToBeDeoptimized } = this;
15225
14536
  this.expressionsToBeDeoptimized = parseAst_js.EMPTY_ARRAY;
@@ -15265,17 +14576,16 @@ class LogicalExpression extends NodeBase {
15265
14576
  }
15266
14577
  getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin) {
15267
14578
  const usedBranch = this.getUsedBranch();
15268
- if (usedBranch) {
15269
- this.expressionsToBeDeoptimized.push(origin);
15270
- return usedBranch.getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin);
15271
- }
15272
- return [
15273
- new MultiExpression([
15274
- this.left.getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin)[0],
15275
- this.right.getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin)[0]
15276
- ]),
15277
- false
15278
- ];
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);
15279
14589
  }
15280
14590
  hasEffects(context) {
15281
14591
  if (this.left.hasEffects(context)) {
@@ -15288,18 +14598,18 @@ class LogicalExpression extends NodeBase {
15288
14598
  }
15289
14599
  hasEffectsOnInteractionAtPath(path, interaction, context) {
15290
14600
  const usedBranch = this.getUsedBranch();
15291
- if (usedBranch) {
15292
- return usedBranch.hasEffectsOnInteractionAtPath(path, interaction, context);
14601
+ if (!usedBranch) {
14602
+ return (this.left.hasEffectsOnInteractionAtPath(path, interaction, context) ||
14603
+ this.right.hasEffectsOnInteractionAtPath(path, interaction, context));
15293
14604
  }
15294
- return (this.left.hasEffectsOnInteractionAtPath(path, interaction, context) ||
15295
- this.right.hasEffectsOnInteractionAtPath(path, interaction, context));
14605
+ return usedBranch.hasEffectsOnInteractionAtPath(path, interaction, context);
15296
14606
  }
15297
14607
  include(context, includeChildrenRecursively) {
15298
14608
  this.included = true;
15299
14609
  const usedBranch = this.getUsedBranch();
15300
14610
  if (includeChildrenRecursively ||
15301
- !usedBranch ||
15302
- (usedBranch === this.right && this.left.shouldBeIncluded(context))) {
14611
+ (usedBranch === this.right && this.left.shouldBeIncluded(context)) ||
14612
+ !usedBranch) {
15303
14613
  this.left.include(context, includeChildrenRecursively);
15304
14614
  this.right.include(context, includeChildrenRecursively);
15305
14615
  }
@@ -15307,17 +14617,6 @@ class LogicalExpression extends NodeBase {
15307
14617
  usedBranch.include(context, includeChildrenRecursively);
15308
14618
  }
15309
14619
  }
15310
- includePath(path, context) {
15311
- this.included = true;
15312
- const usedBranch = this.getUsedBranch();
15313
- if (!usedBranch || (usedBranch === this.right && this.left.shouldBeIncluded(context))) {
15314
- this.left.includePath(path, context);
15315
- this.right.includePath(path, context);
15316
- }
15317
- else {
15318
- usedBranch.includePath(path, context);
15319
- }
15320
- }
15321
14620
  removeAnnotations(code) {
15322
14621
  this.left.removeAnnotations(code);
15323
14622
  }
@@ -15370,8 +14669,6 @@ class LogicalExpression extends NodeBase {
15370
14669
  return this.usedBranch;
15371
14670
  }
15372
14671
  }
15373
- LogicalExpression.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
15374
- LogicalExpression.prototype.applyDeoptimizations = doNotDeoptimize;
15375
14672
 
15376
14673
  class NewExpression extends NodeBase {
15377
14674
  hasEffects(context) {
@@ -15391,21 +14688,16 @@ class NewExpression extends NodeBase {
15391
14688
  return path.length > 0 || type !== INTERACTION_ACCESSED;
15392
14689
  }
15393
14690
  include(context, includeChildrenRecursively) {
14691
+ if (!this.deoptimized)
14692
+ this.applyDeoptimizations();
15394
14693
  if (includeChildrenRecursively) {
15395
14694
  super.include(context, includeChildrenRecursively);
15396
14695
  }
15397
14696
  else {
15398
- if (!this.included)
15399
- this.includeNode(context);
14697
+ this.included = true;
15400
14698
  this.callee.include(context, false);
15401
14699
  }
15402
- this.callee.includeCallArguments(context, this.interaction);
15403
- }
15404
- includeNode(context) {
15405
- this.included = true;
15406
- if (!this.deoptimized)
15407
- this.applyDeoptimizations();
15408
- this.callee.includePath(UNKNOWN_PATH, context);
14700
+ this.callee.includeCallArguments(context, this.arguments);
15409
14701
  }
15410
14702
  initialise() {
15411
14703
  super.initialise();
@@ -15434,7 +14726,6 @@ class ObjectExpression extends NodeBase {
15434
14726
  constructor() {
15435
14727
  super(...arguments);
15436
14728
  this.objectEntity = null;
15437
- this.protoProp = null;
15438
14729
  }
15439
14730
  deoptimizeArgumentsOnInteractionAtPath(interaction, path, recursionTracker) {
15440
14731
  this.getObjectEntity().deoptimizeArgumentsOnInteractionAtPath(interaction, path, recursionTracker);
@@ -15454,43 +14745,15 @@ class ObjectExpression extends NodeBase {
15454
14745
  hasEffectsOnInteractionAtPath(path, interaction, context) {
15455
14746
  return this.getObjectEntity().hasEffectsOnInteractionAtPath(path, interaction, context);
15456
14747
  }
15457
- include(context, includeChildrenRecursively) {
15458
- if (!this.included)
15459
- this.includeNode(context);
15460
- this.getObjectEntity().include(context, includeChildrenRecursively);
15461
- this.protoProp?.include(context, includeChildrenRecursively);
15462
- }
15463
- includeNode(context) {
15464
- this.included = true;
15465
- this.protoProp?.includePath(UNKNOWN_PATH, context);
15466
- }
15467
- includePath(path, context) {
15468
- if (!this.included)
15469
- this.includeNode(context);
15470
- this.getObjectEntity().includePath(path, context);
15471
- }
15472
14748
  render(code, options, { renderedSurroundingElement } = parseAst_js.BLANK) {
14749
+ super.render(code, options);
15473
14750
  if (renderedSurroundingElement === parseAst_js.ExpressionStatement ||
15474
14751
  renderedSurroundingElement === parseAst_js.ArrowFunctionExpression) {
15475
14752
  code.appendRight(this.start, '(');
15476
14753
  code.prependLeft(this.end, ')');
15477
14754
  }
15478
- if (this.properties.length > 0) {
15479
- const separatedNodes = getCommaSeparatedNodesWithBoundaries(this.properties, code, this.start + 1, this.end - 1);
15480
- let lastSeparatorPos = null;
15481
- for (const { node, separator, start, end } of separatedNodes) {
15482
- if (!node.included) {
15483
- treeshakeNode(node, code, start, end);
15484
- continue;
15485
- }
15486
- lastSeparatorPos = separator;
15487
- node.render(code, options);
15488
- }
15489
- if (lastSeparatorPos) {
15490
- code.remove(lastSeparatorPos, this.end - 1);
15491
- }
15492
- }
15493
14755
  }
14756
+ applyDeoptimizations() { }
15494
14757
  getObjectEntity() {
15495
14758
  if (this.objectEntity !== null) {
15496
14759
  return this.objectEntity;
@@ -15519,7 +14782,6 @@ class ObjectExpression extends NodeBase {
15519
14782
  ? property.key.name
15520
14783
  : String(property.key.value);
15521
14784
  if (key === '__proto__' && property.kind === 'init') {
15522
- this.protoProp = property;
15523
14785
  prototype =
15524
14786
  property.value instanceof Literal && property.value.value === null
15525
14787
  ? null
@@ -15532,7 +14794,6 @@ class ObjectExpression extends NodeBase {
15532
14794
  return (this.objectEntity = new ObjectEntity(properties, prototype));
15533
14795
  }
15534
14796
  }
15535
- ObjectExpression.prototype.applyDeoptimizations = doNotDeoptimize;
15536
14797
 
15537
14798
  class PanicError extends NodeBase {
15538
14799
  initialise() {
@@ -15559,7 +14820,6 @@ class ParseError extends NodeBase {
15559
14820
 
15560
14821
  class PrivateIdentifier extends NodeBase {
15561
14822
  }
15562
- PrivateIdentifier.prototype.includeNode = onlyIncludeSelf;
15563
14823
 
15564
14824
  class Program extends NodeBase {
15565
14825
  constructor() {
@@ -15627,11 +14887,14 @@ class Program extends NodeBase {
15627
14887
  super.render(code, options);
15628
14888
  }
15629
14889
  }
14890
+ applyDeoptimizations() { }
15630
14891
  }
15631
- Program.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
15632
- Program.prototype.applyDeoptimizations = doNotDeoptimize;
15633
14892
 
15634
14893
  class Property extends MethodBase {
14894
+ constructor() {
14895
+ super(...arguments);
14896
+ this.declarationInit = null;
14897
+ }
15635
14898
  //declare method: boolean;
15636
14899
  get method() {
15637
14900
  return isFlagSet(this.flags, 262144 /* Flag.method */);
@@ -15646,41 +14909,17 @@ class Property extends MethodBase {
15646
14909
  set shorthand(value) {
15647
14910
  this.flags = setFlag(this.flags, 524288 /* Flag.shorthand */, value);
15648
14911
  }
15649
- declare(kind, destructuredInitPath, init) {
15650
- return this.value.declare(kind, this.getPathInProperty(destructuredInitPath), init);
15651
- }
15652
- deoptimizeAssignment(destructuredInitPath, init) {
15653
- this.value.deoptimizeAssignment?.(this.getPathInProperty(destructuredInitPath), init);
14912
+ declare(kind, init) {
14913
+ this.declarationInit = init;
14914
+ return this.value.declare(kind, UNKNOWN_EXPRESSION);
15654
14915
  }
15655
14916
  hasEffects(context) {
15656
- return this.key.hasEffects(context) || this.value.hasEffects(context);
15657
- }
15658
- hasEffectsWhenDestructuring(context, destructuredInitPath, init) {
15659
- return this.value.hasEffectsWhenDestructuring?.(context, this.getPathInProperty(destructuredInitPath), init);
15660
- }
15661
- includeDestructuredIfNecessary(context, destructuredInitPath, init) {
15662
- const path = this.getPathInProperty(destructuredInitPath);
15663
- let included = this.value.includeDestructuredIfNecessary(context, path, init) ||
15664
- this.included;
15665
- if ((included ||= this.key.hasEffects(createHasEffectsContext()))) {
15666
- this.key.include(context, false);
15667
- if (!this.value.included) {
15668
- this.value.included = true;
15669
- // Unfortunately, we need to include the value again now, so that any
15670
- // declared variables are properly included.
15671
- this.value.includeDestructuredIfNecessary(context, path, init);
15672
- }
15673
- }
15674
- return (this.included = included);
15675
- }
15676
- include(context, includeChildrenRecursively) {
15677
- this.included = true;
15678
- this.key.include(context, includeChildrenRecursively);
15679
- this.value.include(context, includeChildrenRecursively);
15680
- }
15681
- includePath(path, context) {
15682
- this.included = true;
15683
- 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));
15684
14923
  }
15685
14924
  markDeclarationReached() {
15686
14925
  this.value.markDeclarationReached();
@@ -15691,20 +14930,14 @@ class Property extends MethodBase {
15691
14930
  }
15692
14931
  this.value.render(code, options, { isShorthandProperty: this.shorthand });
15693
14932
  }
15694
- getPathInProperty(destructuredInitPath) {
15695
- return destructuredInitPath.at(-1) === UnknownKey
15696
- ? destructuredInitPath
15697
- : // For now, we only consider static paths as we do not know how to
15698
- // deoptimize the path in the dynamic case.
15699
- this.computed
15700
- ? [...destructuredInitPath, UnknownKey]
15701
- : this.key instanceof Identifier
15702
- ? [...destructuredInitPath, this.key.name]
15703
- : [...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
+ }
15704
14939
  }
15705
14940
  }
15706
- Property.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
15707
- Property.prototype.applyDeoptimizations = doNotDeoptimize;
15708
14941
 
15709
14942
  class PropertyDefinition extends NodeBase {
15710
14943
  get computed() {
@@ -15737,15 +14970,8 @@ class PropertyDefinition extends NodeBase {
15737
14970
  hasEffectsOnInteractionAtPath(path, interaction, context) {
15738
14971
  return !this.value || this.value.hasEffectsOnInteractionAtPath(path, interaction, context);
15739
14972
  }
15740
- includeNode(context) {
15741
- this.included = true;
15742
- this.value?.includePath(UNKNOWN_PATH, context);
15743
- for (const decorator of this.decorators) {
15744
- decorator.includePath(UNKNOWN_PATH, context);
15745
- }
15746
- }
14973
+ applyDeoptimizations() { }
15747
14974
  }
15748
- PropertyDefinition.prototype.applyDeoptimizations = doNotDeoptimize;
15749
14975
 
15750
14976
  class ReturnStatement extends NodeBase {
15751
14977
  hasEffects(context) {
@@ -15755,15 +14981,10 @@ class ReturnStatement extends NodeBase {
15755
14981
  return false;
15756
14982
  }
15757
14983
  include(context, includeChildrenRecursively) {
15758
- if (!this.included)
15759
- this.includeNode(context);
14984
+ this.included = true;
15760
14985
  this.argument?.include(context, includeChildrenRecursively);
15761
14986
  context.brokenFlow = true;
15762
14987
  }
15763
- includeNode(context) {
15764
- this.included = true;
15765
- this.argument?.includePath(UNKNOWN_PATH, context);
15766
- }
15767
14988
  initialise() {
15768
14989
  super.initialise();
15769
14990
  this.scope.addReturnExpression(this.argument || UNKNOWN_EXPRESSION);
@@ -15777,7 +14998,6 @@ class ReturnStatement extends NodeBase {
15777
14998
  }
15778
14999
  }
15779
15000
  }
15780
- ReturnStatement.prototype.applyDeoptimizations = doNotDeoptimize;
15781
15001
 
15782
15002
  class SequenceExpression extends NodeBase {
15783
15003
  deoptimizeArgumentsOnInteractionAtPath(interaction, path, recursionTracker) {
@@ -15805,15 +15025,10 @@ class SequenceExpression extends NodeBase {
15805
15025
  for (const expression of this.expressions) {
15806
15026
  if (includeChildrenRecursively ||
15807
15027
  (expression === lastExpression && !(this.parent instanceof ExpressionStatement)) ||
15808
- expression.shouldBeIncluded(context)) {
15028
+ expression.shouldBeIncluded(context))
15809
15029
  expression.include(context, includeChildrenRecursively);
15810
- }
15811
15030
  }
15812
15031
  }
15813
- includePath(path, context) {
15814
- this.included = true;
15815
- this.expressions[this.expressions.length - 1].includePath(path, context);
15816
- }
15817
15032
  removeAnnotations(code) {
15818
15033
  this.expressions[0].removeAnnotations(code);
15819
15034
  }
@@ -15848,8 +15063,6 @@ class SequenceExpression extends NodeBase {
15848
15063
  }
15849
15064
  }
15850
15065
  }
15851
- SequenceExpression.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
15852
- SequenceExpression.prototype.applyDeoptimizations = doNotDeoptimize;
15853
15066
 
15854
15067
  class Super extends NodeBase {
15855
15068
  bind() {
@@ -15861,15 +15074,11 @@ class Super extends NodeBase {
15861
15074
  deoptimizePath(path) {
15862
15075
  this.variable.deoptimizePath(path);
15863
15076
  }
15864
- include(context) {
15865
- if (!this.included)
15866
- this.includeNode(context);
15867
- }
15868
- includeNode(context) {
15869
- this.included = true;
15870
- if (!this.deoptimized)
15871
- this.applyDeoptimizations();
15872
- 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
+ }
15873
15082
  }
15874
15083
  }
15875
15084
 
@@ -15910,8 +15119,6 @@ class SwitchCase extends NodeBase {
15910
15119
  }
15911
15120
  }
15912
15121
  SwitchCase.prototype.needsBoundaries = true;
15913
- SwitchCase.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
15914
- SwitchCase.prototype.applyDeoptimizations = doNotDeoptimize;
15915
15122
 
15916
15123
  class SwitchStatement extends NodeBase {
15917
15124
  createScope(parentScope) {
@@ -15994,8 +15201,6 @@ class SwitchStatement extends NodeBase {
15994
15201
  }
15995
15202
  }
15996
15203
  }
15997
- SwitchStatement.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
15998
- SwitchStatement.prototype.applyDeoptimizations = doNotDeoptimize;
15999
15204
 
16000
15205
  class TaggedTemplateExpression extends CallExpressionBase {
16001
15206
  bind() {
@@ -16019,8 +15224,8 @@ class TaggedTemplateExpression extends CallExpressionBase {
16019
15224
  this.tag.hasEffectsOnInteractionAtPath(EMPTY_PATH, this.interaction, context));
16020
15225
  }
16021
15226
  include(context, includeChildrenRecursively) {
16022
- if (!this.included)
16023
- this.includeNode(context);
15227
+ if (!this.deoptimized)
15228
+ this.applyDeoptimizations();
16024
15229
  if (includeChildrenRecursively) {
16025
15230
  super.include(context, includeChildrenRecursively);
16026
15231
  }
@@ -16029,7 +15234,7 @@ class TaggedTemplateExpression extends CallExpressionBase {
16029
15234
  this.tag.include(context, includeChildrenRecursively);
16030
15235
  this.quasi.include(context, includeChildrenRecursively);
16031
15236
  }
16032
- this.tag.includeCallArguments(context, this.interaction);
15237
+ this.tag.includeCallArguments(context, this.args);
16033
15238
  const [returnExpression] = this.getReturnExpression();
16034
15239
  if (!returnExpression.included) {
16035
15240
  returnExpression.include(context, false);
@@ -16064,7 +15269,6 @@ class TaggedTemplateExpression extends CallExpressionBase {
16064
15269
  return this.returnExpression;
16065
15270
  }
16066
15271
  }
16067
- TaggedTemplateExpression.prototype.includeNode = onlyIncludeSelf;
16068
15272
 
16069
15273
  class TemplateElement extends NodeBase {
16070
15274
  get tail() {
@@ -16078,13 +15282,15 @@ class TemplateElement extends NodeBase {
16078
15282
  hasEffects() {
16079
15283
  return false;
16080
15284
  }
15285
+ include() {
15286
+ this.included = true;
15287
+ }
16081
15288
  parseNode(esTreeNode) {
16082
15289
  this.value = esTreeNode.value;
16083
15290
  return super.parseNode(esTreeNode);
16084
15291
  }
16085
15292
  render() { }
16086
15293
  }
16087
- TemplateElement.prototype.includeNode = onlyIncludeSelf;
16088
15294
 
16089
15295
  class TemplateLiteral extends NodeBase {
16090
15296
  deoptimizeArgumentsOnInteractionAtPath() { }
@@ -16109,14 +15315,6 @@ class TemplateLiteral extends NodeBase {
16109
15315
  }
16110
15316
  return true;
16111
15317
  }
16112
- includeNode(context) {
16113
- this.included = true;
16114
- if (!this.deoptimized)
16115
- this.applyDeoptimizations();
16116
- for (const node of this.expressions) {
16117
- node.includePath(UNKNOWN_PATH, context);
16118
- }
16119
- }
16120
15318
  render(code, options) {
16121
15319
  code.indentExclusionRanges.push([this.start, this.end]);
16122
15320
  super.render(code, options);
@@ -16126,13 +15324,13 @@ class TemplateLiteral extends NodeBase {
16126
15324
  class ModuleScope extends ChildScope {
16127
15325
  constructor(parent, context) {
16128
15326
  super(parent, context);
16129
- 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'));
16130
15328
  }
16131
- addDeclaration(identifier, context, init, destructuredInitPath, kind) {
15329
+ addDeclaration(identifier, context, init, kind) {
16132
15330
  if (this.context.module.importDescriptions.has(identifier.name)) {
16133
15331
  context.error(parseAst_js.logRedeclarationError(identifier.name), identifier.start);
16134
15332
  }
16135
- return super.addDeclaration(identifier, context, init, destructuredInitPath, kind);
15333
+ return super.addDeclaration(identifier, context, init, kind);
16136
15334
  }
16137
15335
  addExportDefaultDeclaration(name, exportDefaultDeclaration, context) {
16138
15336
  const variable = new ExportDefaultVariable(name, exportDefaultDeclaration, context);
@@ -16177,23 +15375,10 @@ class ThisExpression extends NodeBase {
16177
15375
  }
16178
15376
  return this.variable.hasEffectsOnInteractionAtPath(path, interaction, context);
16179
15377
  }
16180
- include(context) {
16181
- if (!this.included)
16182
- this.includeNode(context);
16183
- }
16184
- includeNode(context) {
16185
- this.included = true;
16186
- if (!this.deoptimized)
16187
- this.applyDeoptimizations();
16188
- this.scope.context.includeVariableInModule(this.variable, EMPTY_PATH, context);
16189
- }
16190
- includePath(path, context) {
15378
+ include() {
16191
15379
  if (!this.included) {
16192
15380
  this.included = true;
16193
- this.scope.context.includeVariableInModule(this.variable, path, context);
16194
- }
16195
- else if (path.length > 0) {
16196
- this.variable.includePath(path, context);
15381
+ this.scope.context.includeVariableInModule(this.variable);
16197
15382
  }
16198
15383
  }
16199
15384
  initialise() {
@@ -16221,8 +15406,7 @@ class ThrowStatement extends NodeBase {
16221
15406
  return true;
16222
15407
  }
16223
15408
  include(context, includeChildrenRecursively) {
16224
- if (!this.included)
16225
- this.includeNode(context);
15409
+ this.included = true;
16226
15410
  this.argument.include(context, includeChildrenRecursively);
16227
15411
  context.brokenFlow = true;
16228
15412
  }
@@ -16233,7 +15417,6 @@ class ThrowStatement extends NodeBase {
16233
15417
  }
16234
15418
  }
16235
15419
  }
16236
- ThrowStatement.prototype.includeNode = onlyIncludeSelf;
16237
15420
 
16238
15421
  class TryStatement extends NodeBase {
16239
15422
  constructor() {
@@ -16270,8 +15453,6 @@ class TryStatement extends NodeBase {
16270
15453
  this.finalizer?.include(context, includeChildrenRecursively);
16271
15454
  }
16272
15455
  }
16273
- TryStatement.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
16274
- TryStatement.prototype.applyDeoptimizations = doNotDeoptimize;
16275
15456
 
16276
15457
  const unaryOperators = {
16277
15458
  '!': value => !value,
@@ -16282,13 +15463,21 @@ const unaryOperators = {
16282
15463
  void: () => undefined,
16283
15464
  '~': value => ~value
16284
15465
  };
15466
+ const UNASSIGNED = Symbol('Unassigned');
16285
15467
  class UnaryExpression extends NodeBase {
15468
+ constructor() {
15469
+ super(...arguments);
15470
+ this.renderedLiteralValue = UNASSIGNED;
15471
+ }
16286
15472
  get prefix() {
16287
15473
  return isFlagSet(this.flags, 2097152 /* Flag.prefix */);
16288
15474
  }
16289
15475
  set prefix(value) {
16290
15476
  this.flags = setFlag(this.flags, 2097152 /* Flag.prefix */, value);
16291
15477
  }
15478
+ deoptimizeCache() {
15479
+ this.renderedLiteralValue = UnknownValue;
15480
+ }
16292
15481
  getLiteralValueAtPath(path, recursionTracker, origin) {
16293
15482
  if (path.length > 0)
16294
15483
  return UnknownValue;
@@ -16316,8 +15505,55 @@ class UnaryExpression extends NodeBase {
16316
15505
  this.scope.context.requestTreeshakingPass();
16317
15506
  }
16318
15507
  }
15508
+ getRenderedLiteralValue(includeChildrenRecursively) {
15509
+ if (this.renderedLiteralValue !== UNASSIGNED)
15510
+ return this.renderedLiteralValue;
15511
+ return (this.renderedLiteralValue = includeChildrenRecursively
15512
+ ? UnknownValue
15513
+ : getSimplifiedLiterals(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
+ code.overwrite(this.start, this.end, this.renderedLiteralValue);
15531
+ }
15532
+ }
15533
+ }
15534
+ function getSimplifiedLiterals(value) {
15535
+ if (value === undefined || typeof value === 'boolean') {
15536
+ return String(value);
15537
+ }
15538
+ if (typeof value === 'string') {
15539
+ return JSON.stringify(value);
15540
+ }
15541
+ if (typeof value === 'number') {
15542
+ return getSimplifiedNumber(value);
15543
+ }
15544
+ return UnknownValue;
15545
+ }
15546
+ function getSimplifiedNumber(value) {
15547
+ if (Object.is(-0, value)) {
15548
+ return '-0';
15549
+ }
15550
+ const exp = value.toExponential();
15551
+ const [base, exponent] = exp.split('e');
15552
+ const floatLength = base.split('.')[1]?.length || 0;
15553
+ const finalizedExp = `${base.replace('.', '')}e${parseInt(exponent) - floatLength}`;
15554
+ const stringifiedValue = String(value).replace('+', '');
15555
+ return finalizedExp.length < stringifiedValue.length ? finalizedExp : stringifiedValue;
16319
15556
  }
16320
- UnaryExpression.prototype.includeNode = onlyIncludeSelf;
16321
15557
 
16322
15558
  class UpdateExpression extends NodeBase {
16323
15559
  hasEffects(context) {
@@ -16329,8 +15565,9 @@ class UpdateExpression extends NodeBase {
16329
15565
  return path.length > 1 || type !== INTERACTION_ACCESSED;
16330
15566
  }
16331
15567
  include(context, includeChildrenRecursively) {
16332
- if (!this.included)
16333
- this.includeNode(context);
15568
+ if (!this.deoptimized)
15569
+ this.applyDeoptimizations();
15570
+ this.included = true;
16334
15571
  this.argument.includeAsAssignmentTarget(context, includeChildrenRecursively, true);
16335
15572
  }
16336
15573
  initialise() {
@@ -16369,7 +15606,6 @@ class UpdateExpression extends NodeBase {
16369
15606
  this.scope.context.requestTreeshakingPass();
16370
15607
  }
16371
15608
  }
16372
- UpdateExpression.prototype.includeNode = onlyIncludeSelf;
16373
15609
 
16374
15610
  function areAllDeclarationsIncludedAndNotExported(declarations, exportNamesByVariable) {
16375
15611
  for (const declarator of declarations) {
@@ -16400,9 +15636,8 @@ class VariableDeclaration extends NodeBase {
16400
15636
  include(context, includeChildrenRecursively, { asSingleStatement } = parseAst_js.BLANK) {
16401
15637
  this.included = true;
16402
15638
  for (const declarator of this.declarations) {
16403
- if (includeChildrenRecursively || declarator.shouldBeIncluded(context)) {
15639
+ if (includeChildrenRecursively || declarator.shouldBeIncluded(context))
16404
15640
  declarator.include(context, includeChildrenRecursively);
16405
- }
16406
15641
  const { id, init } = declarator;
16407
15642
  if (asSingleStatement) {
16408
15643
  id.include(context, includeChildrenRecursively);
@@ -16440,6 +15675,7 @@ class VariableDeclaration extends NodeBase {
16440
15675
  this.renderReplacedDeclarations(code, options);
16441
15676
  }
16442
15677
  }
15678
+ applyDeoptimizations() { }
16443
15679
  renderDeclarationEnd(code, separatorString, lastSeparatorPos, actualContentEnd, renderedContentEnd, systemPatternExports, options) {
16444
15680
  if (code.original.charCodeAt(this.end - 1) === 59 /*";"*/) {
16445
15681
  code.remove(this.end - 1, this.end);
@@ -16482,7 +15718,8 @@ class VariableDeclaration extends NodeBase {
16482
15718
  const singleSystemExport = gatherSystemExportsAndGetSingleExport(separatedNodes, options, aggregatedSystemExports);
16483
15719
  for (const { node, start, separator, contentEnd, end } of separatedNodes) {
16484
15720
  if (!node.included) {
16485
- treeshakeNode(node, code, start, end);
15721
+ code.remove(start, end);
15722
+ node.removeAnnotations(code);
16486
15723
  continue;
16487
15724
  }
16488
15725
  node.render(code, options);
@@ -16552,8 +15789,6 @@ function gatherSystemExportsAndGetSingleExport(separatedNodes, options, aggregat
16552
15789
  }
16553
15790
  return singleSystemExport;
16554
15791
  }
16555
- VariableDeclaration.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
16556
- VariableDeclaration.prototype.applyDeoptimizations = doNotDeoptimize;
16557
15792
 
16558
15793
  class WhileStatement extends NodeBase {
16559
15794
  hasEffects(context) {
@@ -16567,25 +15802,13 @@ class WhileStatement extends NodeBase {
16567
15802
  includeLoopBody(context, this.body, includeChildrenRecursively);
16568
15803
  }
16569
15804
  }
16570
- WhileStatement.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
16571
- WhileStatement.prototype.applyDeoptimizations = doNotDeoptimize;
16572
15805
 
16573
15806
  class YieldExpression extends NodeBase {
16574
- applyDeoptimizations() {
16575
- this.deoptimized = true;
16576
- this.argument?.deoptimizePath(UNKNOWN_PATH);
16577
- }
16578
15807
  hasEffects(context) {
16579
15808
  if (!this.deoptimized)
16580
15809
  this.applyDeoptimizations();
16581
15810
  return !(context.ignore.returnYield && !this.argument?.hasEffects(context));
16582
15811
  }
16583
- includeNode(context) {
16584
- this.included = true;
16585
- if (!this.deoptimized)
16586
- this.applyDeoptimizations();
16587
- this.argument?.includePath(UNKNOWN_PATH, context);
16588
- }
16589
15812
  render(code, options) {
16590
15813
  if (this.argument) {
16591
15814
  this.argument.render(code, options, { preventASI: true });
@@ -16819,7 +16042,7 @@ const bufferParsers = [
16819
16042
  const annotations = (node.annotations = parseAst_js.convertAnnotations(buffer[position + 1], buffer));
16820
16043
  node.annotationNoSideEffects = annotations.some(comment => comment.type === 'noSideEffects');
16821
16044
  const parameters = (node.params = convertNodeList(node, scope, buffer[position + 2], buffer));
16822
- scope.addParameterVariables(parameters.map(parameter => parameter.declare('parameter', EMPTY_PATH, UNKNOWN_EXPRESSION)), parameters[parameters.length - 1] instanceof RestElement);
16045
+ scope.addParameterVariables(parameters.map(parameter => parameter.declare('parameter', UNKNOWN_EXPRESSION)), parameters[parameters.length - 1] instanceof RestElement);
16823
16046
  node.body = convertNode(node, scope.bodyScope, buffer[position + 3], buffer);
16824
16047
  },
16825
16048
  function assignmentExpression(node, position, buffer) {
@@ -16865,7 +16088,7 @@ const bufferParsers = [
16865
16088
  const parameterPosition = buffer[position];
16866
16089
  const parameter = (node.param =
16867
16090
  parameterPosition === 0 ? null : convertNode(node, scope, parameterPosition, buffer));
16868
- parameter?.declare('parameter', EMPTY_PATH, UNKNOWN_EXPRESSION);
16091
+ parameter?.declare('parameter', UNKNOWN_EXPRESSION);
16869
16092
  node.body = convertNode(node, scope.bodyScope, buffer[position + 1], buffer);
16870
16093
  },
16871
16094
  function chainExpression(node, position, buffer) {
@@ -17003,7 +16226,7 @@ const bufferParsers = [
17003
16226
  node.id =
17004
16227
  idPosition === 0 ? null : convertNode(node, scope.parent, idPosition, buffer);
17005
16228
  const parameters = (node.params = convertNodeList(node, scope, buffer[position + 3], buffer));
17006
- scope.addParameterVariables(parameters.map(parameter => parameter.declare('parameter', EMPTY_PATH, UNKNOWN_EXPRESSION)), parameters[parameters.length - 1] instanceof RestElement);
16229
+ scope.addParameterVariables(parameters.map(parameter => parameter.declare('parameter', UNKNOWN_EXPRESSION)), parameters[parameters.length - 1] instanceof RestElement);
17007
16230
  node.body = convertNode(node, scope.bodyScope, buffer[position + 4], buffer);
17008
16231
  },
17009
16232
  function functionExpression(node, position, buffer) {
@@ -17016,7 +16239,7 @@ const bufferParsers = [
17016
16239
  const idPosition = buffer[position + 2];
17017
16240
  node.id = idPosition === 0 ? null : convertNode(node, node.idScope, idPosition, buffer);
17018
16241
  const parameters = (node.params = convertNodeList(node, scope, buffer[position + 3], buffer));
17019
- scope.addParameterVariables(parameters.map(parameter => parameter.declare('parameter', EMPTY_PATH, UNKNOWN_EXPRESSION)), parameters[parameters.length - 1] instanceof RestElement);
16242
+ scope.addParameterVariables(parameters.map(parameter => parameter.declare('parameter', UNKNOWN_EXPRESSION)), parameters[parameters.length - 1] instanceof RestElement);
17020
16243
  node.body = convertNode(node, scope.bodyScope, buffer[position + 4], buffer);
17021
16244
  },
17022
16245
  function identifier(node, position, buffer) {
@@ -17480,8 +16703,8 @@ class ExportShimVariable extends Variable {
17480
16703
  super(MISSING_EXPORT_SHIM_VARIABLE);
17481
16704
  this.module = module;
17482
16705
  }
17483
- includePath(path, context) {
17484
- super.includePath(path, context);
16706
+ include() {
16707
+ super.include();
17485
16708
  this.module.needsExportShim = true;
17486
16709
  }
17487
16710
  }
@@ -18172,15 +17395,16 @@ class Module {
18172
17395
  markModuleAndImpureDependenciesAsExecuted(this);
18173
17396
  this.graph.needsTreeshakingPass = true;
18174
17397
  }
18175
- const inclusionContext = createInclusionContext();
18176
17398
  for (const exportName of this.exports.keys()) {
18177
17399
  if (includeNamespaceMembers || exportName !== this.info.syntheticNamedExports) {
18178
17400
  const variable = this.getVariableForExportName(exportName)[0];
18179
17401
  if (!variable) {
18180
17402
  return parseAst_js.error(parseAst_js.logMissingEntryExport(exportName, this.id));
18181
17403
  }
18182
- this.includeVariable(variable, UNKNOWN_PATH, inclusionContext);
18183
17404
  variable.deoptimizePath(UNKNOWN_PATH);
17405
+ if (!variable.included) {
17406
+ this.includeVariable(variable);
17407
+ }
18184
17408
  }
18185
17409
  }
18186
17410
  for (const name of this.getReexports()) {
@@ -18188,7 +17412,7 @@ class Module {
18188
17412
  if (variable) {
18189
17413
  variable.deoptimizePath(UNKNOWN_PATH);
18190
17414
  if (!variable.included) {
18191
- this.includeVariable(variable, UNKNOWN_PATH, inclusionContext);
17415
+ this.includeVariable(variable);
18192
17416
  }
18193
17417
  if (variable instanceof ExternalVariable) {
18194
17418
  variable.module.reexported = true;
@@ -18209,12 +17433,13 @@ class Module {
18209
17433
  this.graph.needsTreeshakingPass = true;
18210
17434
  }
18211
17435
  let includeNamespaceMembers = false;
18212
- const inclusionContext = createInclusionContext();
18213
17436
  for (const name of names) {
18214
17437
  const variable = this.getVariableForExportName(name)[0];
18215
17438
  if (variable) {
18216
17439
  variable.deoptimizePath(UNKNOWN_PATH);
18217
- this.includeVariable(variable, UNKNOWN_PATH, inclusionContext);
17440
+ if (!variable.included) {
17441
+ this.includeVariable(variable);
17442
+ }
18218
17443
  }
18219
17444
  if (!this.exports.has(name) && !this.reexportDescriptions.has(name)) {
18220
17445
  includeNamespaceMembers = true;
@@ -18315,7 +17540,6 @@ class Module {
18315
17540
  manualPureFunctions: this.graph.pureFunctions,
18316
17541
  module: this,
18317
17542
  moduleContext: this.context,
18318
- newlyIncludedVariableInits: this.graph.newlyIncludedVariableInits,
18319
17543
  options: this.options,
18320
17544
  requestTreeshakingPass: () => (this.graph.needsTreeshakingPass = true),
18321
17545
  traceExport: (name) => this.getVariableForExportName(name)[0],
@@ -18656,13 +17880,13 @@ class Module {
18656
17880
  for (const module of [this, ...this.exportAllModules]) {
18657
17881
  if (module instanceof ExternalModule) {
18658
17882
  const [externalVariable] = module.getVariableForExportName('*');
18659
- externalVariable.includePath(UNKNOWN_PATH, createInclusionContext());
17883
+ externalVariable.include();
18660
17884
  this.includedImports.add(externalVariable);
18661
17885
  externalNamespaces.add(externalVariable);
18662
17886
  }
18663
17887
  else if (module.info.syntheticNamedExports) {
18664
17888
  const syntheticNamespace = module.getSyntheticNamespace();
18665
- syntheticNamespace.includePath(UNKNOWN_PATH, createInclusionContext());
17889
+ syntheticNamespace.include();
18666
17890
  this.includedImports.add(syntheticNamespace);
18667
17891
  syntheticNamespaces.add(syntheticNamespace);
18668
17892
  }
@@ -18672,9 +17896,7 @@ class Module {
18672
17896
  includeDynamicImport(node) {
18673
17897
  const resolution = this.dynamicImports.find(dynamicImport => dynamicImport.node === node).resolution;
18674
17898
  if (resolution instanceof Module) {
18675
- if (!resolution.includedDynamicImporters.includes(this)) {
18676
- resolution.includedDynamicImporters.push(this);
18677
- }
17899
+ resolution.includedDynamicImporters.push(this);
18678
17900
  const importedNames = this.options.treeshake
18679
17901
  ? node.getDeterministicImportedNames()
18680
17902
  : undefined;
@@ -18686,15 +17908,15 @@ class Module {
18686
17908
  }
18687
17909
  }
18688
17910
  }
18689
- includeVariable(variable, path, context) {
18690
- const { included, module: variableModule } = variable;
18691
- variable.includePath(path, context);
18692
- if (included) {
17911
+ includeVariable(variable) {
17912
+ const variableModule = variable.module;
17913
+ if (variable.included) {
18693
17914
  if (variableModule instanceof Module && variableModule !== this) {
18694
17915
  getAndExtendSideEffectModules(variable, this);
18695
17916
  }
18696
17917
  }
18697
17918
  else {
17919
+ variable.include();
18698
17920
  this.graph.needsTreeshakingPass = true;
18699
17921
  if (variableModule instanceof Module) {
18700
17922
  if (!variableModule.isExecuted) {
@@ -18711,8 +17933,8 @@ class Module {
18711
17933
  }
18712
17934
  }
18713
17935
  }
18714
- includeVariableInModule(variable, path, context) {
18715
- this.includeVariable(variable, path, context);
17936
+ includeVariableInModule(variable) {
17937
+ this.includeVariable(variable);
18716
17938
  const variableModule = variable.module;
18717
17939
  if (variableModule && variableModule !== this) {
18718
17940
  this.includedImports.add(variable);
@@ -19649,7 +18871,9 @@ class Chunk {
19649
18871
  }
19650
18872
  return [
19651
18873
  resolution || '',
19652
- (this.outputOptions.format === 'es' && this.outputOptions.externalImportAttributes) || null
18874
+ (['es', 'cjs'].includes(this.outputOptions.format) &&
18875
+ this.outputOptions.externalImportAttributes) ||
18876
+ null
19653
18877
  ];
19654
18878
  }
19655
18879
  getFallbackChunkName() {
@@ -21482,18 +20706,18 @@ function flru (max) {
21482
20706
  return {
21483
20707
  clear: reset,
21484
20708
  has: function (key) {
21485
- return curr[key] !== void 0 || prev[key] !== void 0;
20709
+ return curr[key] !== undefined || prev[key] !== undefined;
21486
20710
  },
21487
20711
  get: function (key) {
21488
20712
  var val = curr[key];
21489
- if (val !== void 0) return val;
21490
- if ((val=prev[key]) !== void 0) {
20713
+ if (val !== undefined) return val;
20714
+ if ((val=prev[key]) !== undefined) {
21491
20715
  keep(key, val);
21492
20716
  return val;
21493
20717
  }
21494
20718
  },
21495
20719
  set: function (key, value) {
21496
- if (curr[key] !== void 0) {
20720
+ if (curr[key] !== undefined) {
21497
20721
  curr[key] = value;
21498
20722
  } else {
21499
20723
  keep(key, value);
@@ -22215,11 +21439,10 @@ class Graph {
22215
21439
  this.options = options;
22216
21440
  this.astLru = flru(5);
22217
21441
  this.cachedModules = new Map();
22218
- this.deoptimizationTracker = new EntityPathTracker();
21442
+ this.deoptimizationTracker = new PathTracker();
22219
21443
  this.entryModules = [];
22220
21444
  this.modulesById = new Map();
22221
21445
  this.needsTreeshakingPass = false;
22222
- this.newlyIncludedVariableInits = new Set();
22223
21446
  this.phase = BuildPhase.LOAD_AND_PARSE;
22224
21447
  this.scope = new GlobalScope();
22225
21448
  this.watchFiles = Object.create(null);
@@ -22313,7 +21536,6 @@ class Graph {
22313
21536
  }
22314
21537
  if (this.options.treeshake) {
22315
21538
  let treeshakingPass = 1;
22316
- this.newlyIncludedVariableInits.clear();
22317
21539
  do {
22318
21540
  timeStart(`treeshaking pass ${treeshakingPass}`, 3);
22319
21541
  this.needsTreeshakingPass = false;
@@ -22338,10 +21560,6 @@ class Graph {
22338
21560
  }
22339
21561
  }
22340
21562
  }
22341
- for (const entity of this.newlyIncludedVariableInits) {
22342
- this.newlyIncludedVariableInits.delete(entity);
22343
- entity.include(createInclusionContext(), false);
22344
- }
22345
21563
  timeEnd(`treeshaking pass ${treeshakingPass++}`, 3);
22346
21564
  } while (this.needsTreeshakingPass);
22347
21565
  }
@@ -23067,12 +22285,10 @@ function defineConfig(options) {
23067
22285
  return options;
23068
22286
  }
23069
22287
 
23070
- exports.blue = blue;
23071
22288
  exports.bold = bold;
23072
22289
  exports.commandAliases = commandAliases;
23073
22290
  exports.createFilter = createFilter;
23074
- exports.cyan = cyan$1;
23075
- exports.cyan$1 = cyan;
22291
+ exports.cyan = cyan;
23076
22292
  exports.defineConfig = defineConfig;
23077
22293
  exports.ensureArray = ensureArray$1;
23078
22294
  exports.getAugmentedNamespace = getAugmentedNamespace;
@@ -23085,6 +22301,7 @@ exports.handleError = handleError;
23085
22301
  exports.isWatchEnabled = isWatchEnabled;
23086
22302
  exports.mergeOptions = mergeOptions;
23087
22303
  exports.normalizePluginOption = normalizePluginOption;
22304
+ exports.pc = pc;
23088
22305
  exports.rollup = rollup;
23089
22306
  exports.rollupInternal = rollupInternal;
23090
22307
  exports.stderr = stderr;