@rollup/wasm-node 4.29.0-2 → 4.29.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,22 +1,22 @@
1
1
  /*
2
2
  @license
3
- Rollup.js v4.29.0-2
4
- Fri, 20 Dec 2024 06:55:29 GMT - commit bbb7e7b1d4e208a923b0f18ceb8dd886838e1a01
3
+ Rollup.js v4.29.0
4
+ Fri, 20 Dec 2024 18:36:54 GMT - commit dadd4882c4984d7875af799ad56e506784d50e1c
5
5
 
6
6
  https://github.com/rollup/rollup
7
7
 
8
8
  Released under the MIT License.
9
9
  */
10
- import { EMPTY_OBJECT, ExportDefaultDeclaration as ExportDefaultDeclaration$1, CallExpression as CallExpression$1, EMPTY_ARRAY, LOGLEVEL_WARN, logUnusedExternalImports, ANNOTATION_KEY, INVALID_ANNOTATION_KEY, ObjectExpression as ObjectExpression$1, Property as Property$1, Program as Program$1, logIllegalImportReassignment, BLANK, logRedeclarationError, StaticBlock as StaticBlock$1, CatchClause as CatchClause$1, logDuplicateArgumentNameError, logModuleLevelDirective, ReturnStatement as ReturnStatement$1, VariableDeclarator as VariableDeclarator$1, ExpressionStatement as ExpressionStatement$1, logMissingExport, normalize, getImportPath, logMissingNodeBuiltins, logReservedNamespace, error, logIllegalIdentifierAsName, logMissingNameOptionForIifeExport, logMissingNameOptionForUmdExport, logConstVariableReassignError, ArrowFunctionExpression as ArrowFunctionExpression$1, EMPTY_SET, logCannotCallNamespace, logEval, BlockStatement as BlockStatement$1, getRollupError, logModuleParseError, logParseError, LOGLEVEL_INFO, logFirstSideEffect, locate, logInvalidAnnotation, Identifier as Identifier$1, logThisIsUndefined, getAstBuffer, convertAnnotations, FIXED_STRINGS, convertNode as convertNode$1, logImportAttributeIsInvalid, logImportOptionsAreInvalid, logSyntheticNamedExportsNeedNamespaceExport, logMissingEntryExport, logDuplicateExportError, logInvalidSourcemapForError, augmentCodeLocation, logInconsistentImportAttributes, logMissingJsxExport, logNamespaceConflict, logAmbiguousExternalNamespaces, logShimmedExport, parseAst, logInvalidFormatForTopLevelAwait, TemplateLiteral as TemplateLiteral$1, Literal as Literal$1, logCircularReexport, logAddonNotGenerated, logIncompatibleExportOptionValue, logMixedExport, logFailedValidation, isPathFragment, logCyclicCrossChunkReexport, getAliasName, logUnexpectedNamedImport, isAbsolute as isAbsolute$1, relative as relative$1, logUnexpectedNamespaceReexport, logEmptyChunk, logMissingGlobalName, logOptimizeChunkStatus, logSourcemapBroken, logConflictingSourcemapSources, logChunkInvalid, logInvalidOption, logCannotAssignModuleToChunk, URL_OUTPUT_FORMAT, URL_OUTPUT_DIR, URL_OUTPUT_SOURCEMAPFILE, URL_OUTPUT_AMD_ID, logAnonymousPluginCache, logDuplicatePluginName, logUnknownOption, LOGLEVEL_ERROR, logLevelPriority, LOGLEVEL_DEBUG, printQuotedStringList, logInvalidSetAssetSourceCall, logPluginError, logNoTransformMapOrAstWithoutCode, relativeId, logBadLoader, logExternalModulesCannotBeTransformedToModules, logInternalIdCannotBeExternal, isRelative, logUnresolvedImport, logUnresolvedImportTreatedAsExternal, logExternalSyntheticExports, logUnresolvedEntry, logUnresolvedImplicitDependant, logExternalModulesCannotBeIncludedInManualChunks, logEntryCannotBeExternal, logImplicitDependantCannotBeExternal, logNoAssetSourceSet, logFileReferenceIdNotFoundForFilename, logAssetReferenceIdNotFoundForSetSource, logAssetSourceAlreadySet, logInvalidRollupPhaseForChunkEmission, warnDeprecation, logChunkNotGeneratedForFileName, logAssetNotFinalisedForFileName, logFileNameConflict, URL_GENERATEBUNDLE, logInvalidLogPosition, logInputHookInOutputPlugin, logInvalidAddonPluginHook, logInvalidFunctionPluginHook, logImplicitDependantIsNotIncluded, logCircularDependency, augmentLogMessage, URL_TREESHAKE, URL_JSX, URL_TREESHAKE_MODULESIDEEFFECTS, URL_OUTPUT_INLINEDYNAMICIMPORTS, URL_PRESERVEENTRYSIGNATURES, URL_OUTPUT_GENERATEDCODE, isValidUrl, addTrailingSlashIfMissed, URL_OUTPUT_SOURCEMAPBASEURL, URL_OUTPUT_MANUALCHUNKS, logInvalidExportOptionValue, URL_OUTPUT_AMD_BASEPATH, URL_OUTPUT_INTEROP, URL_OUTPUT_EXTERNALIMPORTATTRIBUTES, logAlreadyClosed, logMissingFileOrDirOption, logCannotEmitFromOptionsHook, URL_WATCH } from './parseAst.js';
10
+ import { ExportDefaultDeclaration as ExportDefaultDeclaration$1, CallExpression as CallExpression$1, EMPTY_ARRAY, LOGLEVEL_WARN, logUnusedExternalImports, ANNOTATION_KEY, INVALID_ANNOTATION_KEY, ObjectExpression as ObjectExpression$1, Property as Property$1, Program as Program$1, logIllegalImportReassignment, BLANK, logRedeclarationError, StaticBlock as StaticBlock$1, CatchClause as CatchClause$1, logDuplicateArgumentNameError, logModuleLevelDirective, ReturnStatement as ReturnStatement$1, VariableDeclarator as VariableDeclarator$1, ExpressionStatement as ExpressionStatement$1, logMissingExport, normalize, getImportPath, logMissingNodeBuiltins, logReservedNamespace, error, logIllegalIdentifierAsName, logMissingNameOptionForIifeExport, logMissingNameOptionForUmdExport, logConstVariableReassignError, ArrowFunctionExpression as ArrowFunctionExpression$1, EMPTY_SET, logCannotCallNamespace, logEval, BlockStatement as BlockStatement$1, getRollupError, logParseError, logModuleParseError, LOGLEVEL_INFO, logFirstSideEffect, locate, logInvalidAnnotation, Identifier as Identifier$1, logThisIsUndefined, getAstBuffer, convertAnnotations, FIXED_STRINGS, convertNode as convertNode$1, EMPTY_OBJECT, logImportAttributeIsInvalid, logImportOptionsAreInvalid, logSyntheticNamedExportsNeedNamespaceExport, logMissingEntryExport, logDuplicateExportError, logInvalidSourcemapForError, augmentCodeLocation, logInconsistentImportAttributes, logMissingJsxExport, logNamespaceConflict, logAmbiguousExternalNamespaces, logShimmedExport, parseAst, logCircularReexport, logInvalidFormatForTopLevelAwait, TemplateLiteral as TemplateLiteral$1, Literal as Literal$1, logAddonNotGenerated, logIncompatibleExportOptionValue, logMixedExport, logFailedValidation, isPathFragment, logCyclicCrossChunkReexport, getAliasName, logUnexpectedNamedImport, isAbsolute as isAbsolute$1, relative as relative$1, logUnexpectedNamespaceReexport, logEmptyChunk, logMissingGlobalName, logOptimizeChunkStatus, logSourcemapBroken, logConflictingSourcemapSources, logChunkInvalid, logInvalidOption, URL_OUTPUT_FORMAT, URL_OUTPUT_DIR, URL_OUTPUT_SOURCEMAPFILE, URL_OUTPUT_AMD_ID, logCannotAssignModuleToChunk, logAnonymousPluginCache, logDuplicatePluginName, logUnknownOption, printQuotedStringList, LOGLEVEL_ERROR, logLevelPriority, LOGLEVEL_DEBUG, logInvalidSetAssetSourceCall, logPluginError, logNoTransformMapOrAstWithoutCode, relativeId, logBadLoader, logExternalModulesCannotBeTransformedToModules, logInternalIdCannotBeExternal, isRelative, logUnresolvedImport, logUnresolvedImportTreatedAsExternal, logExternalSyntheticExports, logUnresolvedEntry, logUnresolvedImplicitDependant, logExternalModulesCannotBeIncludedInManualChunks, logEntryCannotBeExternal, logImplicitDependantCannotBeExternal, logNoAssetSourceSet, logFileReferenceIdNotFoundForFilename, logAssetReferenceIdNotFoundForSetSource, logAssetSourceAlreadySet, logInvalidRollupPhaseForChunkEmission, warnDeprecation, URL_GENERATEBUNDLE, logFileNameConflict, logAssetNotFinalisedForFileName, logChunkNotGeneratedForFileName, logInvalidLogPosition, logInputHookInOutputPlugin, logInvalidFunctionPluginHook, logInvalidAddonPluginHook, logImplicitDependantIsNotIncluded, logCircularDependency, augmentLogMessage, URL_JSX, URL_TREESHAKE, URL_TREESHAKE_MODULESIDEEFFECTS, logInvalidExportOptionValue, URL_OUTPUT_INTEROP, isValidUrl, addTrailingSlashIfMissed, URL_OUTPUT_SOURCEMAPBASEURL, URL_OUTPUT_INLINEDYNAMICIMPORTS, URL_PRESERVEENTRYSIGNATURES, URL_OUTPUT_AMD_BASEPATH, URL_OUTPUT_GENERATEDCODE, URL_OUTPUT_MANUALCHUNKS, URL_OUTPUT_EXTERNALIMPORTATTRIBUTES, logAlreadyClosed, logMissingFileOrDirOption, logCannotEmitFromOptionsHook, URL_WATCH } from './parseAst.js';
11
11
  import { relative, dirname, basename, extname, resolve as resolve$1 } from 'node:path';
12
- import { posix, isAbsolute, resolve, win32 } from 'path';
13
- import { parseAsync, xxhashBase16, xxhashBase64Url, xxhashBase36 } from '../../native.js';
12
+ import { posix, win32, isAbsolute, resolve } from 'path';
13
+ import { parseAsync, xxhashBase64Url, xxhashBase36, xxhashBase16 } from '../../native.js';
14
14
  import process$1, { env as env$1 } from 'node:process';
15
15
  import { performance } from 'node:perf_hooks';
16
16
  import { lstat, realpath, readdir, readFile, mkdir, writeFile } from 'node:fs/promises';
17
17
  import * as tty from 'tty';
18
18
 
19
- var version = "4.29.0-2";
19
+ var version = "4.29.0";
20
20
 
21
21
  const comma = ','.charCodeAt(0);
22
22
  const semicolon = ';'.charCodeAt(0);
@@ -328,7 +328,7 @@ let Chunk$1 = class Chunk {
328
328
  // ' test'.trim()
329
329
  // split -> ' ' + 'test'
330
330
  // ✔️ edit -> '' + 'test'
331
- // ✖️ edit -> 'test' + ''
331
+ // ✖️ edit -> 'test' + ''
332
332
  // TODO is this block necessary?...
333
333
  newChunk.edit('', false);
334
334
  this.content = '';
@@ -575,6 +575,7 @@ class Mappings {
575
575
  this.raw[this.generatedCodeLine] = this.rawSegments = [];
576
576
  this.generatedCodeColumn = 0;
577
577
  first = true;
578
+ charInHiresBoundary = false;
578
579
  } else {
579
580
  if (this.hires || first || sourcemapLocations.has(originalCharIndex)) {
580
581
  const segment = [this.generatedCodeColumn, sourceIndex, loc.line, loc.column];
@@ -652,6 +653,7 @@ class MagicString {
652
653
  storedNames: { writable: true, value: {} },
653
654
  indentStr: { writable: true, value: undefined },
654
655
  ignoreList: { writable: true, value: options.ignoreList },
656
+ offset: { writable: true, value: options.offset || 0 },
655
657
  });
656
658
 
657
659
  this.byStart[0] = chunk;
@@ -670,6 +672,8 @@ class MagicString {
670
672
  }
671
673
 
672
674
  appendLeft(index, content) {
675
+ index = index + this.offset;
676
+
673
677
  if (typeof content !== 'string') throw new TypeError('inserted content must be a string');
674
678
 
675
679
  this._split(index);
@@ -685,6 +689,8 @@ class MagicString {
685
689
  }
686
690
 
687
691
  appendRight(index, content) {
692
+ index = index + this.offset;
693
+
688
694
  if (typeof content !== 'string') throw new TypeError('inserted content must be a string');
689
695
 
690
696
  this._split(index);
@@ -700,7 +706,7 @@ class MagicString {
700
706
  }
701
707
 
702
708
  clone() {
703
- const cloned = new MagicString(this.original, { filename: this.filename });
709
+ const cloned = new MagicString(this.original, { filename: this.filename, offset: this.offset });
704
710
 
705
711
  let originalChunk = this.firstChunk;
706
712
  let clonedChunk = (cloned.firstChunk = cloned.lastSearchedChunk = originalChunk.clone());
@@ -898,7 +904,7 @@ class MagicString {
898
904
  if (!warned.insertLeft) {
899
905
  console.warn(
900
906
  'magicString.insertLeft(...) is deprecated. Use magicString.appendLeft(...) instead',
901
- ); // eslint-disable-line no-console
907
+ );
902
908
  warned.insertLeft = true;
903
909
  }
904
910
 
@@ -909,7 +915,7 @@ class MagicString {
909
915
  if (!warned.insertRight) {
910
916
  console.warn(
911
917
  'magicString.insertRight(...) is deprecated. Use magicString.prependRight(...) instead',
912
- ); // eslint-disable-line no-console
918
+ );
913
919
  warned.insertRight = true;
914
920
  }
915
921
 
@@ -917,6 +923,10 @@ class MagicString {
917
923
  }
918
924
 
919
925
  move(start, end, index) {
926
+ start = start + this.offset;
927
+ end = end + this.offset;
928
+ index = index + this.offset;
929
+
920
930
  if (index >= start && index <= end) throw new Error('Cannot move a selection inside itself');
921
931
 
922
932
  this._split(start);
@@ -959,6 +969,9 @@ class MagicString {
959
969
  }
960
970
 
961
971
  update(start, end, content, options) {
972
+ start = start + this.offset;
973
+ end = end + this.offset;
974
+
962
975
  if (typeof content !== 'string') throw new TypeError('replacement content must be a string');
963
976
 
964
977
  if (this.original.length !== 0) {
@@ -979,7 +992,7 @@ class MagicString {
979
992
  if (!warned.storeName) {
980
993
  console.warn(
981
994
  'The final argument to magicString.overwrite(...) should be an options object. See https://github.com/rich-harris/magic-string',
982
- ); // eslint-disable-line no-console
995
+ );
983
996
  warned.storeName = true;
984
997
  }
985
998
 
@@ -1030,6 +1043,8 @@ class MagicString {
1030
1043
  }
1031
1044
 
1032
1045
  prependLeft(index, content) {
1046
+ index = index + this.offset;
1047
+
1033
1048
  if (typeof content !== 'string') throw new TypeError('inserted content must be a string');
1034
1049
 
1035
1050
  this._split(index);
@@ -1045,6 +1060,8 @@ class MagicString {
1045
1060
  }
1046
1061
 
1047
1062
  prependRight(index, content) {
1063
+ index = index + this.offset;
1064
+
1048
1065
  if (typeof content !== 'string') throw new TypeError('inserted content must be a string');
1049
1066
 
1050
1067
  this._split(index);
@@ -1060,6 +1077,9 @@ class MagicString {
1060
1077
  }
1061
1078
 
1062
1079
  remove(start, end) {
1080
+ start = start + this.offset;
1081
+ end = end + this.offset;
1082
+
1063
1083
  if (this.original.length !== 0) {
1064
1084
  while (start < 0) start += this.original.length;
1065
1085
  while (end < 0) end += this.original.length;
@@ -1086,6 +1106,9 @@ class MagicString {
1086
1106
  }
1087
1107
 
1088
1108
  reset(start, end) {
1109
+ start = start + this.offset;
1110
+ end = end + this.offset;
1111
+
1089
1112
  if (this.original.length !== 0) {
1090
1113
  while (start < 0) start += this.original.length;
1091
1114
  while (end < 0) end += this.original.length;
@@ -1150,7 +1173,10 @@ class MagicString {
1150
1173
  return this.intro + lineStr;
1151
1174
  }
1152
1175
 
1153
- slice(start = 0, end = this.original.length) {
1176
+ slice(start = 0, end = this.original.length - this.offset) {
1177
+ start = start + this.offset;
1178
+ end = end + this.offset;
1179
+
1154
1180
  if (this.original.length !== 0) {
1155
1181
  while (start < 0) start += this.original.length;
1156
1182
  while (end < 0) end += this.original.length;
@@ -1386,11 +1412,7 @@ class MagicString {
1386
1412
  if (match.index != null) {
1387
1413
  const replacement = getReplacement(match, this.original);
1388
1414
  if (replacement !== match[0]) {
1389
- this.overwrite(
1390
- match.index,
1391
- match.index + match[0].length,
1392
- replacement
1393
- );
1415
+ this.overwrite(match.index, match.index + match[0].length, replacement);
1394
1416
  }
1395
1417
  }
1396
1418
  });
@@ -1399,11 +1421,7 @@ class MagicString {
1399
1421
  if (match && match.index != null) {
1400
1422
  const replacement = getReplacement(match, this.original);
1401
1423
  if (replacement !== match[0]) {
1402
- this.overwrite(
1403
- match.index,
1404
- match.index + match[0].length,
1405
- replacement
1406
- );
1424
+ this.overwrite(match.index, match.index + match[0].length, replacement);
1407
1425
  }
1408
1426
  }
1409
1427
  }
@@ -1438,8 +1456,7 @@ class MagicString {
1438
1456
  index = original.indexOf(string, index + stringLength)
1439
1457
  ) {
1440
1458
  const previous = original.slice(index, index + stringLength);
1441
- if (previous !== replacement)
1442
- this.overwrite(index, index + stringLength, replacement);
1459
+ if (previous !== replacement) this.overwrite(index, index + stringLength, replacement);
1443
1460
  }
1444
1461
 
1445
1462
  return this;
@@ -1948,6 +1965,71 @@ function renderSystemExportSequenceBeforeExpression(exportedVariable, expression
1948
1965
  }
1949
1966
  }
1950
1967
 
1968
+ /** @import { Node } from 'estree' */
1969
+
1970
+ /**
1971
+ * @param {Node} node
1972
+ * @param {Node} parent
1973
+ * @returns {boolean}
1974
+ */
1975
+ function is_reference(node, parent) {
1976
+ if (node.type === 'MemberExpression') {
1977
+ return !node.computed && is_reference(node.object, node);
1978
+ }
1979
+
1980
+ if (node.type !== 'Identifier') return false;
1981
+
1982
+ switch (parent?.type) {
1983
+ // disregard `bar` in `foo.bar`
1984
+ case 'MemberExpression':
1985
+ return parent.computed || node === parent.object;
1986
+
1987
+ // disregard the `foo` in `class {foo(){}}` but keep it in `class {[foo](){}}`
1988
+ case 'MethodDefinition':
1989
+ return parent.computed;
1990
+
1991
+ // disregard the `meta` in `import.meta`
1992
+ case 'MetaProperty':
1993
+ return parent.meta === node;
1994
+
1995
+ // disregard the `foo` in `class {foo=bar}` but keep it in `class {[foo]=bar}` and `class {bar=foo}`
1996
+ case 'PropertyDefinition':
1997
+ return parent.computed || node === parent.value;
1998
+
1999
+ // disregard the `bar` in `{ bar: foo }`, but keep it in `{ [bar]: foo }`
2000
+ case 'Property':
2001
+ return parent.computed || node === parent.value;
2002
+
2003
+ // disregard the `bar` in `export { foo as bar }` or
2004
+ // the foo in `import { foo as bar }`
2005
+ case 'ExportSpecifier':
2006
+ case 'ImportSpecifier':
2007
+ return node === parent.local;
2008
+
2009
+ // disregard the `foo` in `foo: while (...) { ... break foo; ... continue foo;}`
2010
+ case 'LabeledStatement':
2011
+ case 'BreakStatement':
2012
+ case 'ContinueStatement':
2013
+ return false;
2014
+
2015
+ default:
2016
+ return true;
2017
+ }
2018
+ }
2019
+
2020
+ const PureFunctionKey = Symbol('PureFunction');
2021
+ const getPureFunctions = ({ treeshake }) => {
2022
+ const pureFunctions = Object.create(null);
2023
+ for (const functionName of treeshake ? treeshake.manualPureFunctions : []) {
2024
+ let currentFunctions = pureFunctions;
2025
+ for (const pathSegment of functionName.split('.')) {
2026
+ currentFunctions = currentFunctions[pathSegment] ||= Object.create(null);
2027
+ }
2028
+ currentFunctions[PureFunctionKey] = true;
2029
+ }
2030
+ return pureFunctions;
2031
+ };
2032
+
1951
2033
  function getOrCreate(map, key, init) {
1952
2034
  const existing = map.get(key);
1953
2035
  if (existing !== undefined) {
@@ -1978,7 +2060,7 @@ const UNKNOWN_PATH = [UnknownKey];
1978
2060
  const UNKNOWN_NON_ACCESSOR_PATH = [UnknownNonAccessorKey];
1979
2061
  const UNKNOWN_INTEGER_PATH = [UnknownInteger];
1980
2062
  const EntitiesKey = Symbol('Entities');
1981
- class EntityPathTracker {
2063
+ class PathTracker {
1982
2064
  constructor() {
1983
2065
  this.entityPaths = Object.create(null, {
1984
2066
  [EntitiesKey]: { value: new Set() }
@@ -2003,14 +2085,14 @@ class EntityPathTracker {
2003
2085
  getEntities(path) {
2004
2086
  let currentPaths = this.entityPaths;
2005
2087
  for (const pathSegment of path) {
2006
- currentPaths = currentPaths[pathSegment] ||= Object.create(null, {
2007
- [EntitiesKey]: { value: new Set() }
2008
- });
2088
+ currentPaths = currentPaths[pathSegment] =
2089
+ currentPaths[pathSegment] ||
2090
+ Object.create(null, { [EntitiesKey]: { value: new Set() } });
2009
2091
  }
2010
2092
  return currentPaths[EntitiesKey];
2011
2093
  }
2012
2094
  }
2013
- const SHARED_RECURSION_TRACKER = new EntityPathTracker();
2095
+ const SHARED_RECURSION_TRACKER = new PathTracker();
2014
2096
  class DiscriminatedPathTracker {
2015
2097
  constructor() {
2016
2098
  this.entityPaths = Object.create(null, {
@@ -2020,9 +2102,9 @@ class DiscriminatedPathTracker {
2020
2102
  trackEntityAtPathAndGetIfTracked(path, discriminator, entity) {
2021
2103
  let currentPaths = this.entityPaths;
2022
2104
  for (const pathSegment of path) {
2023
- currentPaths = currentPaths[pathSegment] ||= Object.create(null, {
2024
- [EntitiesKey]: { value: new Map() }
2025
- });
2105
+ currentPaths = currentPaths[pathSegment] =
2106
+ currentPaths[pathSegment] ||
2107
+ Object.create(null, { [EntitiesKey]: { value: new Map() } });
2026
2108
  }
2027
2109
  const trackedEntities = getOrCreate(currentPaths[EntitiesKey], discriminator, (getNewSet));
2028
2110
  if (trackedEntities.has(entity))
@@ -2031,137 +2113,6 @@ class DiscriminatedPathTracker {
2031
2113
  return false;
2032
2114
  }
2033
2115
  }
2034
- const UNKNOWN_INCLUDED_PATH = Object.freeze({ [UnknownKey]: EMPTY_OBJECT });
2035
- class IncludedPathTracker {
2036
- constructor() {
2037
- this.includedPaths = null;
2038
- }
2039
- includePathAndGetIfIncluded(path) {
2040
- let included = true;
2041
- let parent = this;
2042
- let parentSegment = 'includedPaths';
2043
- let currentPaths = (this.includedPaths ||=
2044
- ((included = false), Object.create(null)));
2045
- for (const pathSegment of path) {
2046
- // This means from here, all paths are included
2047
- if (currentPaths[UnknownKey]) {
2048
- return true;
2049
- }
2050
- // Including UnknownKey automatically includes all nested paths.
2051
- // From above, we know that UnknownKey is not included yet.
2052
- if (typeof pathSegment === 'symbol') {
2053
- // Hopefully, this saves some memory over just setting
2054
- // currentPaths[UnknownKey] = EMPTY_OBJECT
2055
- parent[parentSegment] = UNKNOWN_INCLUDED_PATH;
2056
- return false;
2057
- }
2058
- parent = currentPaths;
2059
- parentSegment = pathSegment;
2060
- currentPaths = currentPaths[pathSegment] ||= ((included = false), Object.create(null));
2061
- }
2062
- return included;
2063
- }
2064
- includeAllPaths(entity, context, basePath) {
2065
- const { includedPaths } = this;
2066
- if (includedPaths) {
2067
- includeAllPaths(entity, context, basePath, includedPaths);
2068
- }
2069
- }
2070
- }
2071
- function includeAllPaths(entity, context, basePath, currentPaths) {
2072
- if (currentPaths[UnknownKey]) {
2073
- return entity.includePath([...basePath, UnknownKey], context);
2074
- }
2075
- const keys = Object.keys(currentPaths);
2076
- if (keys.length === 0) {
2077
- return entity.includePath(basePath, context);
2078
- }
2079
- for (const key of keys) {
2080
- includeAllPaths(entity, context, [...basePath, key], currentPaths[key]);
2081
- }
2082
- }
2083
-
2084
- /** @import { Node } from 'estree' */
2085
-
2086
- /**
2087
- * @param {Node} node
2088
- * @param {Node} parent
2089
- * @returns {boolean}
2090
- */
2091
- function is_reference(node, parent) {
2092
- if (node.type === 'MemberExpression') {
2093
- return !node.computed && is_reference(node.object, node);
2094
- }
2095
-
2096
- if (node.type !== 'Identifier') return false;
2097
-
2098
- switch (parent?.type) {
2099
- // disregard `bar` in `foo.bar`
2100
- case 'MemberExpression':
2101
- return parent.computed || node === parent.object;
2102
-
2103
- // disregard the `foo` in `class {foo(){}}` but keep it in `class {[foo](){}}`
2104
- case 'MethodDefinition':
2105
- return parent.computed;
2106
-
2107
- // disregard the `meta` in `import.meta`
2108
- case 'MetaProperty':
2109
- return parent.meta === node;
2110
-
2111
- // disregard the `foo` in `class {foo=bar}` but keep it in `class {[foo]=bar}` and `class {bar=foo}`
2112
- case 'PropertyDefinition':
2113
- return parent.computed || node === parent.value;
2114
-
2115
- // disregard the `bar` in `{ bar: foo }`, but keep it in `{ [bar]: foo }`
2116
- case 'Property':
2117
- return parent.computed || node === parent.value;
2118
-
2119
- // disregard the `bar` in `export { foo as bar }` or
2120
- // the foo in `import { foo as bar }`
2121
- case 'ExportSpecifier':
2122
- case 'ImportSpecifier':
2123
- return node === parent.local;
2124
-
2125
- // disregard the `foo` in `foo: while (...) { ... break foo; ... continue foo;}`
2126
- case 'LabeledStatement':
2127
- case 'BreakStatement':
2128
- case 'ContinueStatement':
2129
- return false;
2130
-
2131
- default:
2132
- return true;
2133
- }
2134
- }
2135
-
2136
- function createInclusionContext() {
2137
- return {
2138
- brokenFlow: false,
2139
- hasBreak: false,
2140
- hasContinue: false,
2141
- includedCallArguments: new Set(),
2142
- includedLabels: new Set()
2143
- };
2144
- }
2145
- function createHasEffectsContext() {
2146
- return {
2147
- accessed: new EntityPathTracker(),
2148
- assigned: new EntityPathTracker(),
2149
- brokenFlow: false,
2150
- called: new DiscriminatedPathTracker(),
2151
- hasBreak: false,
2152
- hasContinue: false,
2153
- ignore: {
2154
- breaks: false,
2155
- continues: false,
2156
- labels: new Set(),
2157
- returnYield: false,
2158
- this: false
2159
- },
2160
- includedLabels: new Set(),
2161
- instantiated: new DiscriminatedPathTracker(),
2162
- replacedVariableInits: new Map()
2163
- };
2164
- }
2165
2116
 
2166
2117
  function isFlagSet(flags, flag) {
2167
2118
  return (flags & flag) !== 0;
@@ -2172,6 +2123,7 @@ function setFlag(flags, flag, value) {
2172
2123
 
2173
2124
  const UnknownValue = Symbol('Unknown Value');
2174
2125
  const UnknownTruthyValue = Symbol('Unknown Truthy Value');
2126
+ const UnknownFalsyValue = Symbol('Unknown Falsy Value');
2175
2127
  class ExpressionEntity {
2176
2128
  constructor() {
2177
2129
  this.flags = 0;
@@ -2200,25 +2152,12 @@ class ExpressionEntity {
2200
2152
  hasEffectsOnInteractionAtPath(_path, _interaction, _context) {
2201
2153
  return true;
2202
2154
  }
2203
- include(context, _includeChildrenRecursively, _options) {
2204
- if (!this.included)
2205
- this.includeNode(context);
2206
- }
2207
- includeNode(_context) {
2155
+ include(_context, _includeChildrenRecursively, _options) {
2208
2156
  this.included = true;
2209
2157
  }
2210
- includePath(_path, context) {
2211
- if (!this.included)
2212
- this.includeNode(context);
2213
- }
2214
- /* We are both including and including an unknown path here as the former
2215
- * ensures that nested nodes are included while the latter ensures that all
2216
- * paths of the expression are included.
2217
- * */
2218
- includeCallArguments(context, interaction) {
2219
- for (const argument of interaction.args) {
2220
- argument?.includePath(UNKNOWN_PATH, context);
2221
- argument?.include(context, false);
2158
+ includeCallArguments(context, parameters) {
2159
+ for (const argument of parameters) {
2160
+ argument.include(context, false);
2222
2161
  }
2223
2162
  }
2224
2163
  shouldBeIncluded(_context) {
@@ -2257,19 +2196,6 @@ const NODE_INTERACTION_UNKNOWN_CALL = {
2257
2196
  withNew: false
2258
2197
  };
2259
2198
 
2260
- const PureFunctionKey = Symbol('PureFunction');
2261
- const getPureFunctions = ({ treeshake }) => {
2262
- const pureFunctions = Object.create(null);
2263
- for (const functionName of treeshake ? treeshake.manualPureFunctions : []) {
2264
- let currentFunctions = pureFunctions;
2265
- for (const pathSegment of functionName.split('.')) {
2266
- currentFunctions = currentFunctions[pathSegment] ||= Object.create(null);
2267
- }
2268
- currentFunctions[PureFunctionKey] = true;
2269
- }
2270
- return pureFunctions;
2271
- };
2272
-
2273
2199
  class Variable extends ExpressionEntity {
2274
2200
  markReassigned() {
2275
2201
  this.isReassigned = true;
@@ -2346,9 +2272,9 @@ class Variable extends ExpressionEntity {
2346
2272
  * has not been included previously. Once a variable is included, it should
2347
2273
  * take care all its declarations are included.
2348
2274
  */
2349
- includePath(path, context) {
2275
+ include() {
2350
2276
  this.included = true;
2351
- this.renderedLikeHoisted?.includePath(path, context);
2277
+ this.renderedLikeHoisted?.include();
2352
2278
  }
2353
2279
  /**
2354
2280
  * Links the rendered name of this variable to another variable and includes
@@ -2380,8 +2306,8 @@ class ExternalVariable extends Variable {
2380
2306
  hasEffectsOnInteractionAtPath(path, { type }) {
2381
2307
  return type !== INTERACTION_ACCESSED || path.length > (this.isNamespace ? 1 : 0);
2382
2308
  }
2383
- includePath(path, context) {
2384
- super.includePath(path, context);
2309
+ include() {
2310
+ super.include();
2385
2311
  this.module.used = true;
2386
2312
  }
2387
2313
  }
@@ -2682,6 +2608,36 @@ const childNodeKeys = {
2682
2608
  YieldExpression: ['argument']
2683
2609
  };
2684
2610
 
2611
+ function createInclusionContext() {
2612
+ return {
2613
+ brokenFlow: false,
2614
+ hasBreak: false,
2615
+ hasContinue: false,
2616
+ includedCallArguments: new Set(),
2617
+ includedLabels: new Set()
2618
+ };
2619
+ }
2620
+ function createHasEffectsContext() {
2621
+ return {
2622
+ accessed: new PathTracker(),
2623
+ assigned: new PathTracker(),
2624
+ brokenFlow: false,
2625
+ called: new DiscriminatedPathTracker(),
2626
+ hasBreak: false,
2627
+ hasContinue: false,
2628
+ ignore: {
2629
+ breaks: false,
2630
+ continues: false,
2631
+ labels: new Set(),
2632
+ returnYield: false,
2633
+ this: false
2634
+ },
2635
+ includedLabels: new Set(),
2636
+ instantiated: new DiscriminatedPathTracker(),
2637
+ replacedVariableInits: new Map()
2638
+ };
2639
+ }
2640
+
2685
2641
  const INCLUDE_PARAMETERS = 'variables';
2686
2642
  const IS_SKIPPED_CHAIN = Symbol('IS_SKIPPED_CHAIN');
2687
2643
  class NodeBase extends ExpressionEntity {
@@ -2751,37 +2707,20 @@ class NodeBase extends ExpressionEntity {
2751
2707
  this.hasEffectsOnInteractionAtPath(EMPTY_PATH, this.assignmentInteraction, context));
2752
2708
  }
2753
2709
  include(context, includeChildrenRecursively, _options) {
2754
- if (!this.included)
2755
- this.includeNode(context);
2756
- for (const key of childNodeKeys[this.type]) {
2757
- const value = this[key];
2758
- if (value === null)
2759
- continue;
2760
- if (Array.isArray(value)) {
2761
- for (const child of value) {
2762
- child?.include(context, includeChildrenRecursively);
2763
- }
2764
- }
2765
- else {
2766
- value.include(context, includeChildrenRecursively);
2767
- }
2768
- }
2769
- }
2770
- includeNode(context) {
2771
- this.included = true;
2772
2710
  if (!this.deoptimized)
2773
2711
  this.applyDeoptimizations();
2712
+ this.included = true;
2774
2713
  for (const key of childNodeKeys[this.type]) {
2775
2714
  const value = this[key];
2776
2715
  if (value === null)
2777
2716
  continue;
2778
2717
  if (Array.isArray(value)) {
2779
2718
  for (const child of value) {
2780
- child?.includePath(UNKNOWN_PATH, context);
2719
+ child?.include(context, includeChildrenRecursively);
2781
2720
  }
2782
2721
  }
2783
2722
  else {
2784
- value.includePath(UNKNOWN_PATH, context);
2723
+ value.include(context, includeChildrenRecursively);
2785
2724
  }
2786
2725
  }
2787
2726
  }
@@ -2888,17 +2827,6 @@ class NodeBase extends ExpressionEntity {
2888
2827
  function createChildNodeKeysForNode(esTreeNode) {
2889
2828
  return Object.keys(esTreeNode).filter(key => typeof esTreeNode[key] === 'object' && key.charCodeAt(0) !== 95 /* _ */);
2890
2829
  }
2891
- function onlyIncludeSelf() {
2892
- this.included = true;
2893
- if (!this.deoptimized)
2894
- this.applyDeoptimizations();
2895
- }
2896
- function onlyIncludeSelfNoDeoptimize() {
2897
- this.included = true;
2898
- }
2899
- function doNotDeoptimize() {
2900
- this.deoptimized = true;
2901
- }
2902
2830
 
2903
2831
  function isObjectExpressionNode(node) {
2904
2832
  return node instanceof NodeBase && node.type === ObjectExpression$1;
@@ -2911,8 +2839,8 @@ function assembleMemberDescriptions(memberDescriptions, inheritedDescriptions =
2911
2839
  return Object.create(inheritedDescriptions, memberDescriptions);
2912
2840
  }
2913
2841
  const UNDEFINED_EXPRESSION = new (class UndefinedExpression extends ExpressionEntity {
2914
- getLiteralValueAtPath(path) {
2915
- return path.length > 0 ? UnknownValue : undefined;
2842
+ getLiteralValueAtPath() {
2843
+ return undefined;
2916
2844
  }
2917
2845
  })();
2918
2846
  const returnsUnknown = {
@@ -3109,6 +3037,31 @@ function getMemberReturnExpressionWhenCalled(members, memberName) {
3109
3037
  return [members[memberName].returns, false];
3110
3038
  }
3111
3039
 
3040
+ class SpreadElement extends NodeBase {
3041
+ deoptimizeArgumentsOnInteractionAtPath(interaction, path, recursionTracker) {
3042
+ if (path.length > 0) {
3043
+ this.argument.deoptimizeArgumentsOnInteractionAtPath(interaction, UNKNOWN_PATH, recursionTracker);
3044
+ }
3045
+ }
3046
+ hasEffects(context) {
3047
+ if (!this.deoptimized)
3048
+ this.applyDeoptimizations();
3049
+ const { propertyReadSideEffects } = this.scope.context.options
3050
+ .treeshake;
3051
+ return (this.argument.hasEffects(context) ||
3052
+ (propertyReadSideEffects &&
3053
+ (propertyReadSideEffects === 'always' ||
3054
+ this.argument.hasEffectsOnInteractionAtPath(UNKNOWN_PATH, NODE_INTERACTION_UNKNOWN_ACCESS, context))));
3055
+ }
3056
+ applyDeoptimizations() {
3057
+ this.deoptimized = true;
3058
+ // Only properties of properties of the argument could become subject to reassignment
3059
+ // This will also reassign the return values of iterators
3060
+ this.argument.deoptimizePath([UnknownKey, UnknownKey]);
3061
+ this.scope.context.requestTreeshakingPass();
3062
+ }
3063
+ }
3064
+
3112
3065
  class Method extends ExpressionEntity {
3113
3066
  constructor(description) {
3114
3067
  super();
@@ -3234,7 +3187,6 @@ class ObjectEntity extends ExpressionEntity {
3234
3187
  this.unknownIntegerProps = [];
3235
3188
  this.unmatchableGetters = [];
3236
3189
  this.unmatchablePropertiesAndGetters = [];
3237
- this.unmatchablePropertiesAndSetters = [];
3238
3190
  this.unmatchableSetters = [];
3239
3191
  if (Array.isArray(properties)) {
3240
3192
  this.buildPropertyMaps(properties);
@@ -3469,38 +3421,9 @@ class ObjectEntity extends ExpressionEntity {
3469
3421
  }
3470
3422
  return false;
3471
3423
  }
3472
- include(context, includeChildrenRecursively) {
3473
- this.included = true;
3474
- for (const property of this.allProperties) {
3475
- if (includeChildrenRecursively || property.shouldBeIncluded(context)) {
3476
- property.include(context, includeChildrenRecursively);
3477
- }
3478
- }
3479
- this.prototypeExpression?.include(context, includeChildrenRecursively);
3480
- }
3481
- includePath(path, context) {
3482
- this.included = true;
3483
- if (path.length === 0)
3484
- return;
3485
- const [key, ...subPath] = path;
3486
- const [includedMembers, includedPath] = typeof key === 'string'
3487
- ? [
3488
- [
3489
- ...new Set([
3490
- ...(this.propertiesAndGettersByKey[key] || this.unmatchablePropertiesAndGetters),
3491
- ...(this.propertiesAndSettersByKey[key] || this.unmatchablePropertiesAndSetters)
3492
- ])
3493
- ],
3494
- subPath
3495
- ]
3496
- : [this.allProperties, UNKNOWN_PATH];
3497
- for (const property of includedMembers) {
3498
- property.includePath(includedPath, context);
3499
- }
3500
- this.prototypeExpression?.includePath(path, context);
3501
- }
3502
3424
  buildPropertyMaps(properties) {
3503
- const { allProperties, propertiesAndGettersByKey, propertiesAndSettersByKey, settersByKey, gettersByKey, unknownIntegerProps, unmatchablePropertiesAndGetters, unmatchablePropertiesAndSetters, unmatchableGetters, unmatchableSetters } = this;
3425
+ const { allProperties, propertiesAndGettersByKey, propertiesAndSettersByKey, settersByKey, gettersByKey, unknownIntegerProps, unmatchablePropertiesAndGetters, unmatchableGetters, unmatchableSetters } = this;
3426
+ const unmatchablePropertiesAndSetters = [];
3504
3427
  for (let index = properties.length - 1; index >= 0; index--) {
3505
3428
  const { key, kind, property } = properties[index];
3506
3429
  allProperties.push(property);
@@ -3770,37 +3693,6 @@ const ARRAY_PROTOTYPE = new ObjectEntity({
3770
3693
  values: METHOD_DEOPTS_SELF_RETURNS_UNKNOWN
3771
3694
  }, OBJECT_PROTOTYPE, true);
3772
3695
 
3773
- class SpreadElement extends NodeBase {
3774
- deoptimizeArgumentsOnInteractionAtPath(interaction, path, recursionTracker) {
3775
- if (path.length > 0) {
3776
- this.argument.deoptimizeArgumentsOnInteractionAtPath(interaction, UNKNOWN_PATH, recursionTracker);
3777
- }
3778
- }
3779
- hasEffects(context) {
3780
- if (!this.deoptimized)
3781
- this.applyDeoptimizations();
3782
- const { propertyReadSideEffects } = this.scope.context.options
3783
- .treeshake;
3784
- return (this.argument.hasEffects(context) ||
3785
- (propertyReadSideEffects &&
3786
- (propertyReadSideEffects === 'always' ||
3787
- this.argument.hasEffectsOnInteractionAtPath(UNKNOWN_PATH, NODE_INTERACTION_UNKNOWN_ACCESS, context))));
3788
- }
3789
- includeNode(context) {
3790
- this.included = true;
3791
- if (!this.deoptimized)
3792
- this.applyDeoptimizations();
3793
- this.argument.includePath(UNKNOWN_PATH, context);
3794
- }
3795
- applyDeoptimizations() {
3796
- this.deoptimized = true;
3797
- // Only properties of properties of the argument could become subject to reassignment
3798
- // This will also reassign the return values of iterators
3799
- this.argument.deoptimizePath([UnknownKey, UnknownKey]);
3800
- this.scope.context.requestTreeshakingPass();
3801
- }
3802
- }
3803
-
3804
3696
  class ArrayExpression extends NodeBase {
3805
3697
  constructor() {
3806
3698
  super(...arguments);
@@ -3821,16 +3713,6 @@ class ArrayExpression extends NodeBase {
3821
3713
  hasEffectsOnInteractionAtPath(path, interaction, context) {
3822
3714
  return this.getObjectEntity().hasEffectsOnInteractionAtPath(path, interaction, context);
3823
3715
  }
3824
- includeNode(context) {
3825
- this.included = true;
3826
- if (!this.deoptimized)
3827
- this.applyDeoptimizations();
3828
- for (const element of this.elements) {
3829
- if (element) {
3830
- element?.includePath(UNKNOWN_PATH, context);
3831
- }
3832
- }
3833
- }
3834
3716
  applyDeoptimizations() {
3835
3717
  this.deoptimized = true;
3836
3718
  let hasSpread = false;
@@ -3872,29 +3754,29 @@ class ArrayExpression extends NodeBase {
3872
3754
 
3873
3755
  /* eslint sort-keys: "off" */
3874
3756
  const ValueProperties = Symbol('Value Properties');
3875
- const getTruthyLiteralValue = () => UnknownTruthyValue;
3757
+ const getUnknownValue = () => UnknownValue;
3876
3758
  const returnFalse = () => false;
3877
3759
  const returnTrue = () => true;
3878
3760
  const PURE = {
3879
3761
  deoptimizeArgumentsOnCall: doNothing,
3880
- getLiteralValue: getTruthyLiteralValue,
3762
+ getLiteralValue: getUnknownValue,
3881
3763
  hasEffectsWhenCalled: returnFalse
3882
3764
  };
3883
3765
  const IMPURE = {
3884
3766
  deoptimizeArgumentsOnCall: doNothing,
3885
- getLiteralValue: getTruthyLiteralValue,
3767
+ getLiteralValue: getUnknownValue,
3886
3768
  hasEffectsWhenCalled: returnTrue
3887
3769
  };
3888
3770
  const PURE_WITH_ARRAY = {
3889
3771
  deoptimizeArgumentsOnCall: doNothing,
3890
- getLiteralValue: getTruthyLiteralValue,
3772
+ getLiteralValue: getUnknownValue,
3891
3773
  hasEffectsWhenCalled({ args }) {
3892
3774
  return args.length > 1 && !(args[1] instanceof ArrayExpression);
3893
3775
  }
3894
3776
  };
3895
3777
  const GETTER_ACCESS = {
3896
3778
  deoptimizeArgumentsOnCall: doNothing,
3897
- getLiteralValue: getTruthyLiteralValue,
3779
+ getLiteralValue: getUnknownValue,
3898
3780
  hasEffectsWhenCalled({ args }, context) {
3899
3781
  const [_thisArgument, firstArgument] = args;
3900
3782
  return (!(firstArgument instanceof ExpressionEntity) ||
@@ -3924,7 +3806,7 @@ const MUTATES_ARG_WITHOUT_ACCESSOR = {
3924
3806
  deoptimizeArgumentsOnCall({ args: [, firstArgument] }) {
3925
3807
  firstArgument?.deoptimizePath(UNKNOWN_PATH);
3926
3808
  },
3927
- getLiteralValue: getTruthyLiteralValue,
3809
+ getLiteralValue: getUnknownValue,
3928
3810
  hasEffectsWhenCalled({ args }, context) {
3929
3811
  return (args.length <= 1 ||
3930
3812
  args[1].hasEffectsOnInteractionAtPath(UNKNOWN_NON_ACCESSOR_PATH, NODE_INTERACTION_UNKNOWN_ASSIGNMENT, context));
@@ -4131,7 +4013,7 @@ const knownGlobals = {
4131
4013
  }
4132
4014
  target.deoptimizePath(UNKNOWN_PATH);
4133
4015
  },
4134
- getLiteralValue: getTruthyLiteralValue,
4016
+ getLiteralValue: getUnknownValue,
4135
4017
  hasEffectsWhenCalled: returnTrue
4136
4018
  }
4137
4019
  },
@@ -4321,7 +4203,7 @@ const knownGlobals = {
4321
4203
  deoptimizeArgumentsOnCall({ args }) {
4322
4204
  args[2]?.deoptimizePath(['detail']);
4323
4205
  },
4324
- getLiteralValue: getTruthyLiteralValue,
4206
+ getLiteralValue: getUnknownValue,
4325
4207
  hasEffectsWhenCalled: returnFalse
4326
4208
  },
4327
4209
  prototype: O
@@ -4898,37 +4780,17 @@ class GlobalVariable extends Variable {
4898
4780
  }
4899
4781
  }
4900
4782
 
4901
- // To avoid infinite recursions
4902
- const MAX_PATH_DEPTH = 6;
4903
- // If a path is longer than MAX_PATH_DEPTH, it is truncated so that it is at
4904
- // most MAX_PATH_DEPTH long. The last element is always UnknownKey
4905
- const limitConcatenatedPathDepth = (path1, path2) => {
4906
- const { length: length1 } = path1;
4907
- const { length: length2 } = path2;
4908
- return length1 === 0
4909
- ? path2
4910
- : length2 === 0
4911
- ? path1
4912
- : length1 + length2 > MAX_PATH_DEPTH
4913
- ? [...path1, ...path2.slice(0, MAX_PATH_DEPTH - 1 - path1.length), 'UnknownKey']
4914
- : [...path1, ...path2];
4915
- };
4916
-
4917
4783
  class LocalVariable extends Variable {
4918
- constructor(name, declarator, init,
4919
- /** if this is non-empty, the actual init is this path of this.init */
4920
- initPath, context, kind) {
4784
+ constructor(name, declarator, init, context, kind) {
4921
4785
  super(name);
4922
4786
  this.init = init;
4923
- this.initPath = initPath;
4924
- this.kind = kind;
4925
4787
  this.calledFromTryStatement = false;
4926
4788
  this.additionalInitializers = null;
4927
- this.includedPathTracker = new IncludedPathTracker();
4928
4789
  this.expressionsToBeDeoptimized = [];
4929
4790
  this.declarations = declarator ? [declarator] : [];
4930
4791
  this.deoptimizationTracker = context.deoptimizationTracker;
4931
4792
  this.module = context.module;
4793
+ this.kind = kind;
4932
4794
  }
4933
4795
  addDeclaration(identifier, init) {
4934
4796
  this.declarations.push(identifier);
@@ -4939,16 +4801,15 @@ class LocalVariable extends Variable {
4939
4801
  for (const initializer of this.additionalInitializers) {
4940
4802
  initializer.deoptimizePath(UNKNOWN_PATH);
4941
4803
  }
4804
+ this.additionalInitializers = null;
4942
4805
  }
4943
4806
  }
4944
4807
  deoptimizeArgumentsOnInteractionAtPath(interaction, path, recursionTracker) {
4945
- if (this.isReassigned || path.length + this.initPath.length > MAX_PATH_DEPTH) {
4808
+ if (this.isReassigned) {
4946
4809
  deoptimizeInteraction(interaction);
4947
4810
  return;
4948
4811
  }
4949
- recursionTracker.withTrackedEntityAtPath(path, this.init, () => {
4950
- this.init.deoptimizeArgumentsOnInteractionAtPath(interaction, [...this.initPath, ...path], recursionTracker);
4951
- }, undefined);
4812
+ recursionTracker.withTrackedEntityAtPath(path, this.init, () => this.init.deoptimizeArgumentsOnInteractionAtPath(interaction, path, recursionTracker), undefined);
4952
4813
  }
4953
4814
  deoptimizePath(path) {
4954
4815
  if (this.isReassigned ||
@@ -4962,40 +4823,37 @@ class LocalVariable extends Variable {
4962
4823
  for (const expression of expressionsToBeDeoptimized) {
4963
4824
  expression.deoptimizeCache();
4964
4825
  }
4965
- this.init.deoptimizePath([...this.initPath, UnknownKey]);
4826
+ this.init.deoptimizePath(UNKNOWN_PATH);
4966
4827
  }
4967
4828
  else {
4968
- this.init.deoptimizePath(limitConcatenatedPathDepth(this.initPath, path));
4829
+ this.init.deoptimizePath(path);
4969
4830
  }
4970
4831
  }
4971
4832
  getLiteralValueAtPath(path, recursionTracker, origin) {
4972
- if (this.isReassigned || path.length + this.initPath.length > MAX_PATH_DEPTH) {
4833
+ if (this.isReassigned) {
4973
4834
  return UnknownValue;
4974
4835
  }
4975
4836
  return recursionTracker.withTrackedEntityAtPath(path, this.init, () => {
4976
4837
  this.expressionsToBeDeoptimized.push(origin);
4977
- return this.init.getLiteralValueAtPath([...this.initPath, ...path], recursionTracker, origin);
4838
+ return this.init.getLiteralValueAtPath(path, recursionTracker, origin);
4978
4839
  }, UnknownValue);
4979
4840
  }
4980
4841
  getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin) {
4981
- if (this.isReassigned || path.length + this.initPath.length > MAX_PATH_DEPTH) {
4842
+ if (this.isReassigned) {
4982
4843
  return UNKNOWN_RETURN_EXPRESSION;
4983
4844
  }
4984
4845
  return recursionTracker.withTrackedEntityAtPath(path, this.init, () => {
4985
4846
  this.expressionsToBeDeoptimized.push(origin);
4986
- return this.init.getReturnExpressionWhenCalledAtPath([...this.initPath, ...path], interaction, recursionTracker, origin);
4847
+ return this.init.getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin);
4987
4848
  }, UNKNOWN_RETURN_EXPRESSION);
4988
4849
  }
4989
4850
  hasEffectsOnInteractionAtPath(path, interaction, context) {
4990
- if (path.length + this.initPath.length > MAX_PATH_DEPTH) {
4991
- return true;
4992
- }
4993
4851
  switch (interaction.type) {
4994
4852
  case INTERACTION_ACCESSED: {
4995
4853
  if (this.isReassigned)
4996
4854
  return true;
4997
4855
  return (!context.accessed.trackEntityAtPathAndGetIfTracked(path, this) &&
4998
- this.init.hasEffectsOnInteractionAtPath([...this.initPath, ...path], interaction, context));
4856
+ this.init.hasEffectsOnInteractionAtPath(path, interaction, context));
4999
4857
  }
5000
4858
  case INTERACTION_ASSIGNED: {
5001
4859
  if (this.included)
@@ -5005,63 +4863,44 @@ class LocalVariable extends Variable {
5005
4863
  if (this.isReassigned)
5006
4864
  return true;
5007
4865
  return (!context.assigned.trackEntityAtPathAndGetIfTracked(path, this) &&
5008
- this.init.hasEffectsOnInteractionAtPath([...this.initPath, ...path], interaction, context));
4866
+ this.init.hasEffectsOnInteractionAtPath(path, interaction, context));
5009
4867
  }
5010
4868
  case INTERACTION_CALLED: {
5011
4869
  if (this.isReassigned)
5012
4870
  return true;
5013
4871
  return (!(interaction.withNew ? context.instantiated : context.called).trackEntityAtPathAndGetIfTracked(path, interaction.args, this) &&
5014
- this.init.hasEffectsOnInteractionAtPath([...this.initPath, ...path], interaction, context));
4872
+ this.init.hasEffectsOnInteractionAtPath(path, interaction, context));
5015
4873
  }
5016
4874
  }
5017
4875
  }
5018
- includePath(path, context) {
5019
- if (!this.includedPathTracker.includePathAndGetIfIncluded(path)) {
5020
- this.module.scope.context.requestTreeshakingPass();
5021
- if (!this.included) {
5022
- // This will reduce the number of tree-shaking passes by eagerly
5023
- // including inits. By pushing this here instead of directly including
5024
- // we avoid deep call stacks.
5025
- this.module.scope.context.newlyIncludedVariableInits.add(this.init);
5026
- }
5027
- super.includePath(path, context);
4876
+ include() {
4877
+ if (!this.included) {
4878
+ super.include();
5028
4879
  for (const declaration of this.declarations) {
5029
4880
  // If node is a default export, it can save a tree-shaking run to include the full declaration now
5030
4881
  if (!declaration.included)
5031
- declaration.include(context, false);
4882
+ declaration.include(createInclusionContext(), false);
5032
4883
  let node = declaration.parent;
5033
4884
  while (!node.included) {
5034
4885
  // We do not want to properly include parents in case they are part of a dead branch
5035
4886
  // in which case .include() might pull in more dead code
5036
- node.includeNode(context);
4887
+ node.included = true;
5037
4888
  if (node.type === Program$1)
5038
4889
  break;
5039
4890
  node = node.parent;
5040
4891
  }
5041
4892
  }
5042
- // We need to make sure we include the correct path of the init
5043
- if (path.length > 0) {
5044
- this.init.includePath(limitConcatenatedPathDepth(this.initPath, path), context);
5045
- this.additionalInitializers?.forEach(initializer => initializer.includePath(UNKNOWN_PATH, context));
5046
- }
5047
4893
  }
5048
4894
  }
5049
- includeCallArguments(context, interaction) {
5050
- if (this.isReassigned ||
5051
- context.includedCallArguments.has(this.init) ||
5052
- // This can be removed again once we can include arguments when called at
5053
- // a specific path
5054
- this.initPath.length > 0) {
5055
- for (const argument of interaction.args) {
5056
- if (argument) {
5057
- argument.includePath(UNKNOWN_PATH, context);
5058
- argument.include(context, false);
5059
- }
4895
+ includeCallArguments(context, parameters) {
4896
+ if (this.isReassigned || context.includedCallArguments.has(this.init)) {
4897
+ for (const argument of parameters) {
4898
+ argument.include(context, false);
5060
4899
  }
5061
4900
  }
5062
4901
  else {
5063
4902
  context.includedCallArguments.add(this.init);
5064
- this.init.includeCallArguments(context, interaction);
4903
+ this.init.includeCallArguments(context, parameters);
5065
4904
  context.includedCallArguments.delete(this.init);
5066
4905
  }
5067
4906
  }
@@ -5141,31 +4980,18 @@ class IdentifierBase extends NodeBase {
5141
4980
  }
5142
4981
  }
5143
4982
  }
5144
- include(context) {
5145
- if (!this.included)
5146
- this.includeNode(context);
5147
- }
5148
- includeNode(context) {
5149
- this.included = true;
4983
+ include() {
5150
4984
  if (!this.deoptimized)
5151
4985
  this.applyDeoptimizations();
5152
- if (this.variable !== null) {
5153
- this.scope.context.includeVariableInModule(this.variable, EMPTY_PATH, context);
5154
- }
5155
- }
5156
- includePath(path, context) {
5157
4986
  if (!this.included) {
5158
4987
  this.included = true;
5159
4988
  if (this.variable !== null) {
5160
- this.scope.context.includeVariableInModule(this.variable, path, context);
4989
+ this.scope.context.includeVariableInModule(this.variable);
5161
4990
  }
5162
4991
  }
5163
- else if (path.length > 0) {
5164
- this.variable?.includePath(path, context);
5165
- }
5166
4992
  }
5167
- includeCallArguments(context, interaction) {
5168
- this.variable.includeCallArguments(context, interaction);
4993
+ includeCallArguments(context, parameters) {
4994
+ this.variable.includeCallArguments(context, parameters);
5169
4995
  }
5170
4996
  isPossibleTDZ() {
5171
4997
  // return cached value to avoid issues with the next tree-shaking pass
@@ -5248,40 +5074,11 @@ function closestParentFunctionOrProgram(node) {
5248
5074
  return node;
5249
5075
  }
5250
5076
 
5251
- class ObjectMember extends ExpressionEntity {
5252
- constructor(object, path) {
5253
- super();
5254
- this.object = object;
5255
- this.path = path;
5256
- }
5257
- deoptimizeArgumentsOnInteractionAtPath(interaction, path, recursionTracker) {
5258
- this.object.deoptimizeArgumentsOnInteractionAtPath(interaction, [...this.path, ...path], recursionTracker);
5259
- }
5260
- deoptimizePath(path) {
5261
- this.object.deoptimizePath([...this.path, ...path]);
5262
- }
5263
- getLiteralValueAtPath(path, recursionTracker, origin) {
5264
- return this.object.getLiteralValueAtPath([...this.path, ...path], recursionTracker, origin);
5265
- }
5266
- getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin) {
5267
- return this.object.getReturnExpressionWhenCalledAtPath([...this.path, ...path], interaction, recursionTracker, origin);
5268
- }
5269
- hasEffectsOnInteractionAtPath(path, interaction, context) {
5270
- return this.object.hasEffectsOnInteractionAtPath([...this.path, ...path], interaction, context);
5271
- }
5272
- }
5273
-
5274
5077
  class Identifier extends IdentifierBase {
5275
5078
  constructor() {
5276
5079
  super(...arguments);
5277
5080
  this.variable = null;
5278
5081
  }
5279
- get isDestructuringDeoptimized() {
5280
- return isFlagSet(this.flags, 8388608 /* Flag.destructuringDeoptimized */);
5281
- }
5282
- set isDestructuringDeoptimized(value) {
5283
- this.flags = setFlag(this.flags, 8388608 /* Flag.destructuringDeoptimized */, value);
5284
- }
5285
5082
  addExportedVariables(variables, exportNamesByVariable) {
5286
5083
  if (exportNamesByVariable.has(this.variable)) {
5287
5084
  variables.push(this.variable);
@@ -5293,53 +5090,43 @@ class Identifier extends IdentifierBase {
5293
5090
  this.variable.addReference(this);
5294
5091
  this.isVariableReference = true;
5295
5092
  }
5296
- }
5297
- declare(kind, destructuredInitPath, init) {
5298
- let variable;
5299
- const { treeshake } = this.scope.context.options;
5300
- if (kind === 'parameter') {
5301
- variable = this.scope.addParameterDeclaration(this, destructuredInitPath);
5302
- }
5303
- else {
5304
- variable = this.scope.addDeclaration(this, this.scope.context, init, destructuredInitPath, kind);
5305
- if (kind === 'var' && treeshake && treeshake.correctVarValueBeforeDeclaration) {
5306
- // Necessary to make sure the init is deoptimized. We cannot call deoptimizePath here.
5307
- variable.markInitializersForDeoptimization();
5308
- }
5309
- }
5310
- return [(this.variable = variable)];
5311
- }
5312
- deoptimizeAssignment(destructuredInitPath, init) {
5313
- this.deoptimizePath(EMPTY_PATH);
5314
- init.deoptimizePath([...destructuredInitPath, UnknownKey]);
5315
- }
5316
- hasEffectsWhenDestructuring(context, destructuredInitPath, init) {
5317
- return (destructuredInitPath.length > 0 &&
5318
- init.hasEffectsOnInteractionAtPath(destructuredInitPath, NODE_INTERACTION_UNKNOWN_ACCESS, context));
5319
- }
5320
- includeDestructuredIfNecessary(context, destructuredInitPath, init) {
5321
- if (destructuredInitPath.length > 0 && !this.isDestructuringDeoptimized) {
5322
- this.isDestructuringDeoptimized = true;
5323
- init.deoptimizeArgumentsOnInteractionAtPath({
5324
- args: [new ObjectMember(init, destructuredInitPath.slice(0, -1))],
5325
- type: INTERACTION_ACCESSED
5326
- }, destructuredInitPath, SHARED_RECURSION_TRACKER);
5327
- }
5328
- const { propertyReadSideEffects } = this.scope.context.options
5329
- .treeshake;
5330
- if ((this.included ||=
5331
- destructuredInitPath.length > 0 &&
5332
- !context.brokenFlow &&
5333
- propertyReadSideEffects &&
5334
- (propertyReadSideEffects === 'always' ||
5335
- init.hasEffectsOnInteractionAtPath(destructuredInitPath, NODE_INTERACTION_UNKNOWN_ACCESS, createHasEffectsContext())))) {
5336
- if (this.variable && !this.variable.included) {
5337
- this.scope.context.includeVariableInModule(this.variable, EMPTY_PATH, context);
5093
+ }
5094
+ declare(kind, init) {
5095
+ let variable;
5096
+ const { treeshake } = this.scope.context.options;
5097
+ switch (kind) {
5098
+ case 'var': {
5099
+ variable = this.scope.addDeclaration(this, this.scope.context, init, kind);
5100
+ if (treeshake && treeshake.correctVarValueBeforeDeclaration) {
5101
+ // Necessary to make sure the init is deoptimized. We cannot call deoptimizePath here.
5102
+ variable.markInitializersForDeoptimization();
5103
+ }
5104
+ break;
5105
+ }
5106
+ case 'function': {
5107
+ // in strict mode, functions are only hoisted within a scope but not across block scopes
5108
+ variable = this.scope.addDeclaration(this, this.scope.context, init, kind);
5109
+ break;
5110
+ }
5111
+ case 'let':
5112
+ case 'const':
5113
+ case 'using':
5114
+ case 'await using':
5115
+ case 'class': {
5116
+ variable = this.scope.addDeclaration(this, this.scope.context, init, kind);
5117
+ break;
5118
+ }
5119
+ case 'parameter': {
5120
+ variable = this.scope.addParameterDeclaration(this);
5121
+ break;
5122
+ }
5123
+ /* istanbul ignore next */
5124
+ default: {
5125
+ /* istanbul ignore next */
5126
+ throw new Error(`Internal Error: Unexpected identifier kind ${kind}.`);
5338
5127
  }
5339
- init.includePath(destructuredInitPath, context);
5340
- return true;
5341
5128
  }
5342
- return false;
5129
+ return [(this.variable = variable)];
5343
5130
  }
5344
5131
  markDeclarationReached() {
5345
5132
  this.variable.initReached = true;
@@ -5405,17 +5192,18 @@ class Scope {
5405
5192
  - then the variable is still declared in the hoisted outer scope, but the initializer is assigned to the parameter
5406
5193
  - const, let, class, and function except in the cases above cannot redeclare anything
5407
5194
  */
5408
- addDeclaration(identifier, context, init, destructuredInitPath, kind) {
5195
+ addDeclaration(identifier, context, init, kind) {
5409
5196
  const name = identifier.name;
5410
5197
  const existingVariable = this.hoistedVariables?.get(name) || this.variables.get(name);
5411
5198
  if (existingVariable) {
5412
- if (kind === 'var' && existingVariable.kind === 'var') {
5199
+ const existingKind = existingVariable.kind;
5200
+ if (kind === 'var' && existingKind === 'var') {
5413
5201
  existingVariable.addDeclaration(identifier, init);
5414
5202
  return existingVariable;
5415
5203
  }
5416
5204
  context.error(logRedeclarationError(name), identifier.start);
5417
5205
  }
5418
- const newVariable = new LocalVariable(identifier.name, identifier, init, destructuredInitPath, context, kind);
5206
+ const newVariable = new LocalVariable(identifier.name, identifier, init, context, kind);
5419
5207
  this.variables.set(name, newVariable);
5420
5208
  return newVariable;
5421
5209
  }
@@ -5591,6 +5379,7 @@ class MethodBase extends NodeBase {
5591
5379
  }
5592
5380
  return this.getAccessedValue()[0].hasEffectsOnInteractionAtPath(path, interaction, context);
5593
5381
  }
5382
+ applyDeoptimizations() { }
5594
5383
  getAccessedValue() {
5595
5384
  if (this.accessedValue === null) {
5596
5385
  if (this.kind === 'get') {
@@ -5604,20 +5393,19 @@ class MethodBase extends NodeBase {
5604
5393
  return this.accessedValue;
5605
5394
  }
5606
5395
  }
5607
- MethodBase.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
5608
- MethodBase.prototype.applyDeoptimizations = doNotDeoptimize;
5609
5396
 
5610
5397
  class MethodDefinition extends MethodBase {
5611
5398
  hasEffects(context) {
5612
5399
  return super.hasEffects(context) || checkEffectForNodes(this.decorators, context);
5613
5400
  }
5401
+ applyDeoptimizations() { }
5614
5402
  }
5615
5403
 
5616
5404
  class BlockScope extends ChildScope {
5617
5405
  constructor(parent) {
5618
5406
  super(parent, parent.context);
5619
5407
  }
5620
- addDeclaration(identifier, context, init, destructuredInitPath, kind) {
5408
+ addDeclaration(identifier, context, init, kind) {
5621
5409
  if (kind === 'var') {
5622
5410
  const name = identifier.name;
5623
5411
  const existingVariable = this.hoistedVariables?.get(name) || this.variables.get(name);
@@ -5629,7 +5417,7 @@ class BlockScope extends ChildScope {
5629
5417
  }
5630
5418
  return context.error(logRedeclarationError(name), identifier.start);
5631
5419
  }
5632
- const declaredVariable = this.parent.addDeclaration(identifier, context, init, destructuredInitPath, kind);
5420
+ const declaredVariable = this.parent.addDeclaration(identifier, context, init, kind);
5633
5421
  // Necessary to make sure the init is deoptimized for conditional declarations.
5634
5422
  // We cannot call deoptimizePath here.
5635
5423
  declaredVariable.markInitializersForDeoptimization();
@@ -5637,7 +5425,7 @@ class BlockScope extends ChildScope {
5637
5425
  this.addHoistedVariable(name, declaredVariable);
5638
5426
  return declaredVariable;
5639
5427
  }
5640
- return super.addDeclaration(identifier, context, init, destructuredInitPath, kind);
5428
+ return super.addDeclaration(identifier, context, init, kind);
5641
5429
  }
5642
5430
  }
5643
5431
 
@@ -5669,12 +5457,33 @@ class StaticBlock extends NodeBase {
5669
5457
  }
5670
5458
  }
5671
5459
  }
5672
- StaticBlock.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
5673
- StaticBlock.prototype.applyDeoptimizations = doNotDeoptimize;
5674
5460
  function isStaticBlock(statement) {
5675
5461
  return statement.type === StaticBlock$1;
5676
5462
  }
5677
5463
 
5464
+ class ObjectMember extends ExpressionEntity {
5465
+ constructor(object, key) {
5466
+ super();
5467
+ this.object = object;
5468
+ this.key = key;
5469
+ }
5470
+ deoptimizeArgumentsOnInteractionAtPath(interaction, path, recursionTracker) {
5471
+ this.object.deoptimizeArgumentsOnInteractionAtPath(interaction, [this.key, ...path], recursionTracker);
5472
+ }
5473
+ deoptimizePath(path) {
5474
+ this.object.deoptimizePath([this.key, ...path]);
5475
+ }
5476
+ getLiteralValueAtPath(path, recursionTracker, origin) {
5477
+ return this.object.getLiteralValueAtPath([this.key, ...path], recursionTracker, origin);
5478
+ }
5479
+ getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin) {
5480
+ return this.object.getReturnExpressionWhenCalledAtPath([this.key, ...path], interaction, recursionTracker, origin);
5481
+ }
5482
+ hasEffectsOnInteractionAtPath(path, interaction, context) {
5483
+ return this.object.hasEffectsOnInteractionAtPath([this.key, ...path], interaction, context);
5484
+ }
5485
+ }
5486
+
5678
5487
  class ClassNode extends NodeBase {
5679
5488
  constructor() {
5680
5489
  super(...arguments);
@@ -5715,20 +5524,21 @@ class ClassNode extends NodeBase {
5715
5524
  : this.getObjectEntity().hasEffectsOnInteractionAtPath(path, interaction, context);
5716
5525
  }
5717
5526
  include(context, includeChildrenRecursively) {
5718
- if (!this.included)
5719
- this.includeNode(context);
5527
+ if (!this.deoptimized)
5528
+ this.applyDeoptimizations();
5529
+ this.included = true;
5720
5530
  this.superClass?.include(context, includeChildrenRecursively);
5721
5531
  this.body.include(context, includeChildrenRecursively);
5722
5532
  for (const decorator of this.decorators)
5723
5533
  decorator.include(context, includeChildrenRecursively);
5724
5534
  if (this.id) {
5725
5535
  this.id.markDeclarationReached();
5726
- this.id.include(context);
5536
+ this.id.include();
5727
5537
  }
5728
5538
  }
5729
5539
  initialise() {
5730
5540
  super.initialise();
5731
- this.id?.declare('class', EMPTY_PATH, this);
5541
+ this.id?.declare('class', this);
5732
5542
  for (const method of this.body.body) {
5733
5543
  if (method instanceof MethodDefinition && method.kind === 'constructor') {
5734
5544
  this.classConstructor = method;
@@ -5786,12 +5596,11 @@ class ClassNode extends NodeBase {
5786
5596
  staticProperties.unshift({
5787
5597
  key: 'prototype',
5788
5598
  kind: 'init',
5789
- property: new ObjectEntity(dynamicMethods, this.superClass ? new ObjectMember(this.superClass, ['prototype']) : OBJECT_PROTOTYPE)
5599
+ property: new ObjectEntity(dynamicMethods, this.superClass ? new ObjectMember(this.superClass, 'prototype') : OBJECT_PROTOTYPE)
5790
5600
  });
5791
5601
  return (this.objectEntity = new ObjectEntity(staticProperties, this.superClass || OBJECT_PROTOTYPE));
5792
5602
  }
5793
5603
  }
5794
- ClassNode.prototype.includeNode = onlyIncludeSelf;
5795
5604
 
5796
5605
  class ClassDeclaration extends ClassNode {
5797
5606
  initialise() {
@@ -5844,7 +5653,7 @@ class ClassDeclaration extends ClassNode {
5844
5653
 
5845
5654
  class ArgumentsVariable extends LocalVariable {
5846
5655
  constructor(context) {
5847
- super('arguments', null, UNKNOWN_EXPRESSION, EMPTY_PATH, context, 'other');
5656
+ super('arguments', null, UNKNOWN_EXPRESSION, context, 'other');
5848
5657
  this.deoptimizedArguments = [];
5849
5658
  }
5850
5659
  addArgumentToBeDeoptimized(argument) {
@@ -5858,8 +5667,8 @@ class ArgumentsVariable extends LocalVariable {
5858
5667
  hasEffectsOnInteractionAtPath(path, { type }) {
5859
5668
  return type !== INTERACTION_ACCESSED || path.length > 1;
5860
5669
  }
5861
- includePath(path, context) {
5862
- super.includePath(path, context);
5670
+ include() {
5671
+ super.include();
5863
5672
  for (const argument of this.deoptimizedArguments) {
5864
5673
  argument.deoptimizePath(UNKNOWN_PATH);
5865
5674
  }
@@ -5870,28 +5679,27 @@ class ArgumentsVariable extends LocalVariable {
5870
5679
  const MAX_TRACKED_INTERACTIONS = 20;
5871
5680
  const NO_INTERACTIONS = EMPTY_ARRAY;
5872
5681
  const UNKNOWN_DEOPTIMIZED_FIELD = new Set([UnknownKey]);
5873
- const EMPTY_PATH_TRACKER = new EntityPathTracker();
5682
+ const EMPTY_PATH_TRACKER = new PathTracker();
5874
5683
  const UNKNOWN_DEOPTIMIZED_ENTITY = new Set([UNKNOWN_EXPRESSION]);
5875
5684
  class ParameterVariable extends LocalVariable {
5876
- constructor(name, declarator, argumentPath, context) {
5877
- super(name, declarator, UNKNOWN_EXPRESSION, argumentPath, context, 'parameter');
5685
+ constructor(name, declarator, context) {
5686
+ super(name, declarator, UNKNOWN_EXPRESSION, context, 'parameter');
5878
5687
  this.deoptimizationInteractions = [];
5879
- this.deoptimizations = new EntityPathTracker();
5688
+ this.deoptimizations = new PathTracker();
5880
5689
  this.deoptimizedFields = new Set();
5881
- this.argumentsToBeDeoptimized = new Set();
5882
- this.expressionsDependingOnKnownValue = [];
5690
+ this.entitiesToBeDeoptimized = new Set();
5691
+ this.expressionsUseTheKnownValue = [];
5883
5692
  this.knownValue = null;
5884
5693
  this.knownValueLiteral = UnknownValue;
5885
5694
  this.frozenValue = null;
5886
5695
  }
5887
- addArgumentValue(entity) {
5888
- this.updateKnownValue(entity);
5696
+ addEntityToBeDeoptimized(entity) {
5889
5697
  if (entity === UNKNOWN_EXPRESSION) {
5890
5698
  // As unknown expressions fully deoptimize all interactions, we can clear
5891
5699
  // the interaction cache at this point provided we keep this optimization
5892
5700
  // in mind when adding new interactions
5893
- if (!this.argumentsToBeDeoptimized.has(UNKNOWN_EXPRESSION)) {
5894
- this.argumentsToBeDeoptimized.add(UNKNOWN_EXPRESSION);
5701
+ if (!this.entitiesToBeDeoptimized.has(UNKNOWN_EXPRESSION)) {
5702
+ this.entitiesToBeDeoptimized.add(UNKNOWN_EXPRESSION);
5895
5703
  for (const { interaction } of this.deoptimizationInteractions) {
5896
5704
  deoptimizeInteraction(interaction);
5897
5705
  }
@@ -5901,34 +5709,27 @@ class ParameterVariable extends LocalVariable {
5901
5709
  else if (this.deoptimizedFields.has(UnknownKey)) {
5902
5710
  // This means that we already deoptimized all interactions and no longer
5903
5711
  // track them
5904
- entity.deoptimizePath([...this.initPath, UnknownKey]);
5712
+ entity.deoptimizePath(UNKNOWN_PATH);
5905
5713
  }
5906
- else if (!this.argumentsToBeDeoptimized.has(entity)) {
5907
- this.argumentsToBeDeoptimized.add(entity);
5714
+ else if (!this.entitiesToBeDeoptimized.has(entity)) {
5715
+ this.entitiesToBeDeoptimized.add(entity);
5908
5716
  for (const field of this.deoptimizedFields) {
5909
- entity.deoptimizePath([...this.initPath, field]);
5717
+ entity.deoptimizePath([field]);
5910
5718
  }
5911
5719
  for (const { interaction, path } of this.deoptimizationInteractions) {
5912
- if (this.initPath.length + path.length > MAX_PATH_DEPTH) {
5913
- deoptimizeInteraction(interaction);
5914
- continue;
5915
- }
5916
- entity.deoptimizeArgumentsOnInteractionAtPath(interaction, [...this.initPath, ...path], SHARED_RECURSION_TRACKER);
5720
+ entity.deoptimizeArgumentsOnInteractionAtPath(interaction, path, SHARED_RECURSION_TRACKER);
5917
5721
  }
5918
5722
  }
5919
5723
  }
5920
- /** This says we should not make assumptions about the value of the parameter.
5921
- * This is different from deoptimization that will also cause argument values
5922
- * to be deoptimized. */
5923
5724
  markReassigned() {
5924
5725
  if (this.isReassigned) {
5925
5726
  return;
5926
5727
  }
5927
5728
  super.markReassigned();
5928
- for (const expression of this.expressionsDependingOnKnownValue) {
5729
+ for (const expression of this.expressionsUseTheKnownValue) {
5929
5730
  expression.deoptimizeCache();
5930
5731
  }
5931
- this.expressionsDependingOnKnownValue = EMPTY_ARRAY;
5732
+ this.expressionsUseTheKnownValue = EMPTY_ARRAY;
5932
5733
  }
5933
5734
  deoptimizeCache() {
5934
5735
  this.markReassigned();
@@ -5945,7 +5746,7 @@ class ParameterVariable extends LocalVariable {
5945
5746
  }
5946
5747
  if (this.knownValue === null) {
5947
5748
  this.knownValue = argument;
5948
- this.knownValueLiteral = argument.getLiteralValueAtPath(this.initPath, SHARED_RECURSION_TRACKER, this);
5749
+ this.knownValueLiteral = argument.getLiteralValueAtPath(EMPTY_PATH, SHARED_RECURSION_TRACKER, this);
5949
5750
  return;
5950
5751
  }
5951
5752
  // the same literal or identifier, do nothing
@@ -5961,7 +5762,7 @@ class ParameterVariable extends LocalVariable {
5961
5762
  return;
5962
5763
  }
5963
5764
  // add tracking for the new argument
5964
- const newValue = argument.getLiteralValueAtPath(this.initPath, SHARED_RECURSION_TRACKER, this);
5765
+ const newValue = argument.getLiteralValueAtPath(EMPTY_PATH, SHARED_RECURSION_TRACKER, this);
5965
5766
  if (newValue !== oldValue) {
5966
5767
  this.markReassigned();
5967
5768
  }
@@ -5979,31 +5780,24 @@ class ParameterVariable extends LocalVariable {
5979
5780
  return this.frozenValue;
5980
5781
  }
5981
5782
  getLiteralValueAtPath(path, recursionTracker, origin) {
5982
- if (this.isReassigned || path.length + this.initPath.length > MAX_PATH_DEPTH) {
5783
+ if (this.isReassigned) {
5983
5784
  return UnknownValue;
5984
5785
  }
5985
5786
  const knownValue = this.getKnownValue();
5986
- this.expressionsDependingOnKnownValue.push(origin);
5987
- return recursionTracker.withTrackedEntityAtPath(path, knownValue, () => knownValue.getLiteralValueAtPath([...this.initPath, ...path], recursionTracker, origin), UnknownValue);
5787
+ this.expressionsUseTheKnownValue.push(origin);
5788
+ return recursionTracker.withTrackedEntityAtPath(path, knownValue, () => knownValue.getLiteralValueAtPath(path, recursionTracker, origin), UnknownValue);
5988
5789
  }
5989
5790
  hasEffectsOnInteractionAtPath(path, interaction, context) {
5990
- const { type } = interaction;
5991
- if (this.isReassigned ||
5992
- type === INTERACTION_ASSIGNED ||
5993
- path.length + this.initPath.length > MAX_PATH_DEPTH) {
5791
+ if (this.isReassigned || interaction.type === INTERACTION_ASSIGNED) {
5994
5792
  return super.hasEffectsOnInteractionAtPath(path, interaction, context);
5995
5793
  }
5996
- return (!(type === INTERACTION_CALLED
5997
- ? (interaction.withNew
5998
- ? context.instantiated
5999
- : context.called).trackEntityAtPathAndGetIfTracked(path, interaction.args, this)
6000
- : context.accessed.trackEntityAtPathAndGetIfTracked(path, this)) &&
6001
- this.getKnownValue().hasEffectsOnInteractionAtPath([...this.initPath, ...path], interaction, context));
5794
+ const knownValue = this.getKnownValue();
5795
+ return knownValue.hasEffectsOnInteractionAtPath(path, interaction, context);
6002
5796
  }
6003
5797
  deoptimizeArgumentsOnInteractionAtPath(interaction, path) {
6004
5798
  // For performance reasons, we fully deoptimize all deeper interactions
6005
5799
  if (path.length >= 2 ||
6006
- this.argumentsToBeDeoptimized.has(UNKNOWN_EXPRESSION) ||
5800
+ this.entitiesToBeDeoptimized.has(UNKNOWN_EXPRESSION) ||
6007
5801
  this.deoptimizationInteractions.length >= MAX_TRACKED_INTERACTIONS ||
6008
5802
  (path.length === 1 &&
6009
5803
  (this.deoptimizedFields.has(UnknownKey) ||
@@ -6012,10 +5806,10 @@ class ParameterVariable extends LocalVariable {
6012
5806
  return;
6013
5807
  }
6014
5808
  if (!this.deoptimizations.trackEntityAtPathAndGetIfTracked(path, interaction.args)) {
6015
- for (const entity of this.argumentsToBeDeoptimized) {
6016
- entity.deoptimizeArgumentsOnInteractionAtPath(interaction, [...this.initPath, ...path], SHARED_RECURSION_TRACKER);
5809
+ for (const entity of this.entitiesToBeDeoptimized) {
5810
+ entity.deoptimizeArgumentsOnInteractionAtPath(interaction, path, SHARED_RECURSION_TRACKER);
6017
5811
  }
6018
- if (!this.argumentsToBeDeoptimized.has(UNKNOWN_EXPRESSION)) {
5812
+ if (!this.entitiesToBeDeoptimized.has(UNKNOWN_EXPRESSION)) {
6019
5813
  this.deoptimizationInteractions.push({
6020
5814
  interaction,
6021
5815
  path
@@ -6036,17 +5830,17 @@ class ParameterVariable extends LocalVariable {
6036
5830
  return;
6037
5831
  }
6038
5832
  this.deoptimizedFields.add(key);
6039
- for (const entity of this.argumentsToBeDeoptimized) {
5833
+ for (const entity of this.entitiesToBeDeoptimized) {
6040
5834
  // We do not need a recursion tracker here as we already track whether
6041
5835
  // this field is deoptimized
6042
- entity.deoptimizePath([...this.initPath, key]);
5836
+ entity.deoptimizePath([key]);
6043
5837
  }
6044
5838
  if (key === UnknownKey) {
6045
5839
  // save some memory
6046
5840
  this.deoptimizationInteractions = NO_INTERACTIONS;
6047
5841
  this.deoptimizations = EMPTY_PATH_TRACKER;
6048
5842
  this.deoptimizedFields = UNKNOWN_DEOPTIMIZED_FIELD;
6049
- this.argumentsToBeDeoptimized = UNKNOWN_DEOPTIMIZED_ENTITY;
5843
+ this.entitiesToBeDeoptimized = UNKNOWN_DEOPTIMIZED_ENTITY;
6050
5844
  }
6051
5845
  }
6052
5846
  getReturnExpressionWhenCalledAtPath(path) {
@@ -6061,14 +5855,11 @@ class ParameterVariable extends LocalVariable {
6061
5855
  }
6062
5856
  return UNKNOWN_RETURN_EXPRESSION;
6063
5857
  }
6064
- includeArgumentPaths(entity, context) {
6065
- this.includedPathTracker.includeAllPaths(entity, context, this.initPath);
6066
- }
6067
5858
  }
6068
5859
 
6069
5860
  class ThisVariable extends ParameterVariable {
6070
5861
  constructor(context) {
6071
- super('this', null, EMPTY_PATH, context);
5862
+ super('this', null, context);
6072
5863
  }
6073
5864
  hasEffectsOnInteractionAtPath(path, interaction, context) {
6074
5865
  return (context.replacedVariableInits.get(this) || UNKNOWN_EXPRESSION).hasEffectsOnInteractionAtPath(path, interaction, context);
@@ -6080,7 +5871,7 @@ class CatchBodyScope extends ChildScope {
6080
5871
  super(parent, parent.context);
6081
5872
  this.parent = parent;
6082
5873
  }
6083
- addDeclaration(identifier, context, init, destructuredInitPath, kind) {
5874
+ addDeclaration(identifier, context, init, kind) {
6084
5875
  if (kind === 'var') {
6085
5876
  const name = identifier.name;
6086
5877
  const existingVariable = this.hoistedVariables?.get(name) || this.variables.get(name);
@@ -6093,7 +5884,7 @@ class CatchBodyScope extends ChildScope {
6093
5884
  // the assignment actually goes to the parameter and the var is
6094
5885
  // hoisted without assignment. Locally, it is shadowed by the
6095
5886
  // parameter
6096
- const declaredVariable = this.parent.parent.addDeclaration(identifier, context, UNDEFINED_EXPRESSION, destructuredInitPath, kind);
5887
+ const declaredVariable = this.parent.parent.addDeclaration(identifier, context, UNDEFINED_EXPRESSION, kind);
6097
5888
  // To avoid the need to rewrite the declaration, we link the variable
6098
5889
  // names. If we ever implement a logic that splits initialization and
6099
5890
  // assignment for hoisted vars, the "renderLikeHoisted" logic can be
@@ -6112,7 +5903,7 @@ class CatchBodyScope extends ChildScope {
6112
5903
  return context.error(logRedeclarationError(name), identifier.start);
6113
5904
  }
6114
5905
  // We only add parameters to parameter scopes
6115
- const declaredVariable = this.parent.parent.addDeclaration(identifier, context, init, destructuredInitPath, kind);
5906
+ const declaredVariable = this.parent.parent.addDeclaration(identifier, context, init, kind);
6116
5907
  // Necessary to make sure the init is deoptimized for conditional declarations.
6117
5908
  // We cannot call deoptimizePath here.
6118
5909
  declaredVariable.markInitializersForDeoptimization();
@@ -6120,7 +5911,7 @@ class CatchBodyScope extends ChildScope {
6120
5911
  this.addHoistedVariable(name, declaredVariable);
6121
5912
  return declaredVariable;
6122
5913
  }
6123
- return super.addDeclaration(identifier, context, init, destructuredInitPath, kind);
5914
+ return super.addDeclaration(identifier, context, init, kind);
6124
5915
  }
6125
5916
  }
6126
5917
 
@@ -6130,7 +5921,7 @@ class FunctionBodyScope extends ChildScope {
6130
5921
  }
6131
5922
  // There is stuff that is only allowed in function scopes, i.e. functions can
6132
5923
  // be redeclared, functions and var can redeclare each other
6133
- addDeclaration(identifier, context, init, destructuredInitPath, kind) {
5924
+ addDeclaration(identifier, context, init, kind) {
6134
5925
  const name = identifier.name;
6135
5926
  const existingVariable = this.hoistedVariables?.get(name) || this.variables.get(name);
6136
5927
  if (existingVariable) {
@@ -6142,7 +5933,7 @@ class FunctionBodyScope extends ChildScope {
6142
5933
  }
6143
5934
  context.error(logRedeclarationError(name), identifier.start);
6144
5935
  }
6145
- const newVariable = new LocalVariable(identifier.name, identifier, init, destructuredInitPath, context, kind);
5936
+ const newVariable = new LocalVariable(identifier.name, identifier, init, context, kind);
6146
5937
  this.variables.set(name, newVariable);
6147
5938
  return newVariable;
6148
5939
  }
@@ -6151,21 +5942,21 @@ class FunctionBodyScope extends ChildScope {
6151
5942
  class ParameterScope extends ChildScope {
6152
5943
  constructor(parent, isCatchScope) {
6153
5944
  super(parent, parent.context);
6154
- this.hasRest = false;
6155
5945
  this.parameters = [];
5946
+ this.hasRest = false;
6156
5947
  this.bodyScope = isCatchScope ? new CatchBodyScope(this) : new FunctionBodyScope(this);
6157
5948
  }
6158
5949
  /**
6159
5950
  * Adds a parameter to this scope. Parameters must be added in the correct
6160
5951
  * order, i.e. from left to right.
6161
5952
  */
6162
- addParameterDeclaration(identifier, argumentPath) {
5953
+ addParameterDeclaration(identifier) {
6163
5954
  const { name, start } = identifier;
6164
5955
  const existingParameter = this.variables.get(name);
6165
5956
  if (existingParameter) {
6166
5957
  return this.context.error(logDuplicateArgumentNameError(name), start);
6167
5958
  }
6168
- const variable = new ParameterVariable(name, identifier, argumentPath, this.context);
5959
+ const variable = new ParameterVariable(name, identifier, this.context);
6169
5960
  this.variables.set(name, variable);
6170
5961
  // We also add it to the body scope to detect name conflicts with local
6171
5962
  // variables. We still need the intermediate scope, though, as parameter
@@ -6183,56 +5974,42 @@ class ParameterScope extends ChildScope {
6183
5974
  }
6184
5975
  this.hasRest = hasRest;
6185
5976
  }
6186
- includeCallArguments(context, interaction) {
5977
+ includeCallArguments(context, parameters) {
6187
5978
  let calledFromTryStatement = false;
6188
5979
  let argumentIncluded = false;
6189
5980
  const restParameter = this.hasRest && this.parameters[this.parameters.length - 1];
6190
- const { args } = interaction;
6191
- let lastExplicitlyIncludedIndex = args.length - 1;
6192
- // If there is a SpreadElement, we need to include all arguments after it
6193
- // because we no longer know which argument corresponds to which parameter.
6194
- for (let argumentIndex = 1; argumentIndex < args.length; argumentIndex++) {
6195
- const argument = args[argumentIndex];
6196
- if (argument instanceof SpreadElement && !argumentIncluded) {
6197
- argumentIncluded = true;
6198
- lastExplicitlyIncludedIndex = argumentIndex - 1;
6199
- }
6200
- if (argumentIncluded) {
6201
- argument.includePath(UNKNOWN_PATH, context);
6202
- argument.include(context, false);
5981
+ for (const checkedArgument of parameters) {
5982
+ if (checkedArgument instanceof SpreadElement) {
5983
+ for (const argument of parameters) {
5984
+ argument.include(context, false);
5985
+ }
5986
+ break;
6203
5987
  }
6204
5988
  }
6205
- // Now we go backwards either starting from the last argument or before the
6206
- // first SpreadElement to ensure all arguments before are included as needed
6207
- for (let index = lastExplicitlyIncludedIndex; index >= 1; index--) {
6208
- const parameterVariables = this.parameters[index - 1] || restParameter;
6209
- const argument = args[index];
5989
+ for (let index = parameters.length - 1; index >= 0; index--) {
5990
+ const parameterVariables = this.parameters[index] || restParameter;
5991
+ const argument = parameters[index];
6210
5992
  if (parameterVariables) {
6211
5993
  calledFromTryStatement = false;
6212
5994
  if (parameterVariables.length === 0) {
6213
- // handle empty destructuring to avoid destructuring undefined
5995
+ // handle empty destructuring
6214
5996
  argumentIncluded = true;
6215
5997
  }
6216
5998
  else {
6217
5999
  for (const variable of parameterVariables) {
6218
- if (variable.calledFromTryStatement) {
6219
- calledFromTryStatement = true;
6220
- }
6221
6000
  if (variable.included) {
6222
6001
  argumentIncluded = true;
6223
- if (calledFromTryStatement) {
6224
- argument.include(context, true);
6225
- }
6226
- else {
6227
- variable.includeArgumentPaths(argument, context);
6228
- argument.include(context, false);
6229
- }
6002
+ }
6003
+ if (variable.calledFromTryStatement) {
6004
+ calledFromTryStatement = true;
6230
6005
  }
6231
6006
  }
6232
6007
  }
6233
6008
  }
6234
- if (!argument.included && (argumentIncluded || argument.shouldBeIncluded(context))) {
6009
+ if (!argumentIncluded && argument.shouldBeIncluded(context)) {
6235
6010
  argumentIncluded = true;
6011
+ }
6012
+ if (argumentIncluded) {
6236
6013
  argument.include(context, calledFromTryStatement);
6237
6014
  }
6238
6015
  }
@@ -6248,62 +6025,11 @@ class ReturnValueScope extends ParameterScope {
6248
6025
  addReturnExpression(expression) {
6249
6026
  this.returnExpressions.push(expression);
6250
6027
  }
6251
- deoptimizeArgumentsOnCall(interaction) {
6252
- const { parameters } = this;
6253
- const { args } = interaction;
6254
- let position = 0;
6255
- for (; position < args.length - 1; position++) {
6256
- // Only the "this" argument arg[0] can be null
6257
- const argument = args[position + 1];
6258
- if (argument instanceof SpreadElement) {
6259
- // This deoptimizes the current and remaining parameters and arguments
6260
- for (; position < parameters.length; position++) {
6261
- args[position + 1]?.deoptimizePath(UNKNOWN_PATH);
6262
- parameters[position].forEach(variable => variable.markReassigned());
6263
- }
6264
- break;
6265
- }
6266
- if (this.hasRest && position >= parameters.length - 1) {
6267
- argument.deoptimizePath(UNKNOWN_PATH);
6268
- }
6269
- else {
6270
- const variables = parameters[position];
6271
- if (variables) {
6272
- for (const variable of variables) {
6273
- variable.addArgumentValue(argument);
6274
- }
6275
- }
6276
- this.addArgumentToBeDeoptimized(argument);
6277
- }
6278
- }
6279
- const nonRestParameterLength = this.hasRest ? parameters.length - 1 : parameters.length;
6280
- for (; position < nonRestParameterLength; position++) {
6281
- for (const variable of parameters[position]) {
6282
- variable.addArgumentValue(UNDEFINED_EXPRESSION);
6283
- }
6284
- }
6285
- }
6286
6028
  getReturnExpression() {
6287
6029
  if (this.returnExpression === null)
6288
6030
  this.updateReturnExpression();
6289
6031
  return this.returnExpression;
6290
6032
  }
6291
- deoptimizeAllParameters() {
6292
- for (const parameter of this.parameters) {
6293
- for (const variable of parameter) {
6294
- variable.deoptimizePath(UNKNOWN_PATH);
6295
- variable.markReassigned();
6296
- }
6297
- }
6298
- }
6299
- reassignAllParameters() {
6300
- for (const parameter of this.parameters) {
6301
- for (const variable of parameter) {
6302
- variable.markReassigned();
6303
- }
6304
- }
6305
- }
6306
- addArgumentToBeDeoptimized(_argument) { }
6307
6033
  updateReturnExpression() {
6308
6034
  if (this.returnExpressions.length === 1) {
6309
6035
  this.returnExpression = this.returnExpressions[0];
@@ -6319,30 +6045,24 @@ class ReturnValueScope extends ParameterScope {
6319
6045
 
6320
6046
  class FunctionScope extends ReturnValueScope {
6321
6047
  constructor(parent) {
6322
- super(parent, false);
6323
6048
  const { context } = parent;
6049
+ super(parent, false);
6324
6050
  this.variables.set('arguments', (this.argumentsVariable = new ArgumentsVariable(context)));
6325
6051
  this.variables.set('this', (this.thisVariable = new ThisVariable(context)));
6326
6052
  }
6327
6053
  findLexicalBoundary() {
6328
6054
  return this;
6329
6055
  }
6330
- includeCallArguments(context, interaction) {
6331
- super.includeCallArguments(context, interaction);
6056
+ includeCallArguments(context, parameters) {
6057
+ super.includeCallArguments(context, parameters);
6332
6058
  if (this.argumentsVariable.included) {
6333
- const { args } = interaction;
6334
- for (let argumentIndex = 1; argumentIndex < args.length; argumentIndex++) {
6335
- const argument = args[argumentIndex];
6336
- if (argument) {
6337
- argument.includePath(UNKNOWN_PATH, context);
6059
+ for (const argument of parameters) {
6060
+ if (!argument.included) {
6338
6061
  argument.include(context, false);
6339
6062
  }
6340
6063
  }
6341
6064
  }
6342
6065
  }
6343
- addArgumentToBeDeoptimized(argument) {
6344
- this.argumentsVariable.addArgumentToBeDeoptimized(argument);
6345
- }
6346
6066
  }
6347
6067
 
6348
6068
  class ExpressionStatement extends NodeBase {
@@ -6370,9 +6090,8 @@ class ExpressionStatement extends NodeBase {
6370
6090
  return this.parent.type !== Program$1;
6371
6091
  return super.shouldBeIncluded(context);
6372
6092
  }
6093
+ applyDeoptimizations() { }
6373
6094
  }
6374
- ExpressionStatement.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
6375
- ExpressionStatement.prototype.applyDeoptimizations = doNotDeoptimize;
6376
6095
 
6377
6096
  class BlockStatement extends NodeBase {
6378
6097
  get deoptimizeBody() {
@@ -6437,8 +6156,6 @@ class BlockStatement extends NodeBase {
6437
6156
  }
6438
6157
  }
6439
6158
  }
6440
- BlockStatement.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
6441
- BlockStatement.prototype.applyDeoptimizations = doNotDeoptimize;
6442
6159
 
6443
6160
  class RestElement extends NodeBase {
6444
6161
  constructor() {
@@ -6448,12 +6165,9 @@ class RestElement extends NodeBase {
6448
6165
  addExportedVariables(variables, exportNamesByVariable) {
6449
6166
  this.argument.addExportedVariables(variables, exportNamesByVariable);
6450
6167
  }
6451
- declare(kind, destructuredInitPath, init) {
6168
+ declare(kind, init) {
6452
6169
  this.declarationInit = init;
6453
- return this.argument.declare(kind, getIncludedPatternPath$1(destructuredInitPath), init);
6454
- }
6455
- deoptimizeAssignment(destructuredInitPath, init) {
6456
- this.argument.deoptimizeAssignment(getIncludedPatternPath$1(destructuredInitPath), init);
6170
+ return this.argument.declare(kind, UNKNOWN_EXPRESSION);
6457
6171
  }
6458
6172
  deoptimizePath(path) {
6459
6173
  if (path.length === 0) {
@@ -6464,20 +6178,6 @@ class RestElement extends NodeBase {
6464
6178
  return (path.length > 0 ||
6465
6179
  this.argument.hasEffectsOnInteractionAtPath(EMPTY_PATH, interaction, context));
6466
6180
  }
6467
- hasEffectsWhenDestructuring(context, destructuredInitPath, init) {
6468
- return this.argument.hasEffectsWhenDestructuring(context, getIncludedPatternPath$1(destructuredInitPath), init);
6469
- }
6470
- includeDestructuredIfNecessary(context, destructuredInitPath, init) {
6471
- return (this.included =
6472
- this.argument.includeDestructuredIfNecessary(context, getIncludedPatternPath$1(destructuredInitPath), init) || this.included);
6473
- }
6474
- include(context, includeChildrenRecursively) {
6475
- if (!this.included)
6476
- this.includeNode(context);
6477
- // This should just include the identifier, its properties should be
6478
- // included where the variable is used.
6479
- this.argument.include(context, includeChildrenRecursively);
6480
- }
6481
6181
  markDeclarationReached() {
6482
6182
  this.argument.markDeclarationReached();
6483
6183
  }
@@ -6489,16 +6189,12 @@ class RestElement extends NodeBase {
6489
6189
  }
6490
6190
  }
6491
6191
  }
6492
- RestElement.prototype.includeNode = onlyIncludeSelf;
6493
- const getIncludedPatternPath$1 = (destructuredInitPath) => destructuredInitPath.at(-1) === UnknownKey
6494
- ? destructuredInitPath
6495
- : [...destructuredInitPath, UnknownKey];
6496
6192
 
6497
6193
  class FunctionBase extends NodeBase {
6498
6194
  constructor() {
6499
6195
  super(...arguments);
6196
+ this.objectEntity = null;
6500
6197
  this.parameterVariableValuesDeoptimized = false;
6501
- this.includeCallArguments = this.scope.includeCallArguments.bind(this.scope);
6502
6198
  }
6503
6199
  get async() {
6504
6200
  return isFlagSet(this.flags, 256 /* Flag.async */);
@@ -6518,9 +6214,53 @@ class FunctionBase extends NodeBase {
6518
6214
  set generator(value) {
6519
6215
  this.flags = setFlag(this.flags, 4194304 /* Flag.generator */, value);
6520
6216
  }
6217
+ updateParameterVariableValues(_arguments) {
6218
+ for (let position = 0; position < this.params.length; position++) {
6219
+ const parameter = this.params[position];
6220
+ if (!(parameter instanceof Identifier)) {
6221
+ continue;
6222
+ }
6223
+ const parameterVariable = parameter.variable;
6224
+ const argument = _arguments[position + 1] ?? UNDEFINED_EXPRESSION;
6225
+ parameterVariable.updateKnownValue(argument);
6226
+ }
6227
+ }
6228
+ deoptimizeParameterVariableValues() {
6229
+ for (const parameter of this.params) {
6230
+ if (parameter instanceof Identifier) {
6231
+ const parameterVariable = parameter.variable;
6232
+ parameterVariable.markReassigned();
6233
+ }
6234
+ }
6235
+ }
6521
6236
  deoptimizeArgumentsOnInteractionAtPath(interaction, path, recursionTracker) {
6522
- if (interaction.type === INTERACTION_CALLED && path.length === 0) {
6523
- this.scope.deoptimizeArgumentsOnCall(interaction);
6237
+ if (interaction.type === INTERACTION_CALLED) {
6238
+ const { parameters } = this.scope;
6239
+ const { args } = interaction;
6240
+ let hasRest = false;
6241
+ for (let position = 0; position < args.length - 1; position++) {
6242
+ const parameter = this.params[position];
6243
+ // Only the "this" argument arg[0] can be null
6244
+ const argument = args[position + 1];
6245
+ if (argument instanceof SpreadElement) {
6246
+ this.deoptimizeParameterVariableValues();
6247
+ }
6248
+ if (hasRest || parameter instanceof RestElement) {
6249
+ hasRest = true;
6250
+ argument.deoptimizePath(UNKNOWN_PATH);
6251
+ }
6252
+ else if (parameter instanceof Identifier) {
6253
+ parameters[position][0].addEntityToBeDeoptimized(argument);
6254
+ this.addArgumentToBeDeoptimized(argument);
6255
+ }
6256
+ else if (parameter) {
6257
+ argument.deoptimizePath(UNKNOWN_PATH);
6258
+ }
6259
+ else {
6260
+ this.addArgumentToBeDeoptimized(argument);
6261
+ }
6262
+ }
6263
+ this.updateParameterVariableValues(args);
6524
6264
  }
6525
6265
  else {
6526
6266
  this.getObjectEntity().deoptimizeArgumentsOnInteractionAtPath(interaction, path, recursionTracker);
@@ -6532,7 +6272,12 @@ class FunctionBase extends NodeBase {
6532
6272
  // A reassignment of UNKNOWN_PATH is considered equivalent to having lost track
6533
6273
  // which means the return expression and parameters need to be reassigned
6534
6274
  this.scope.getReturnExpression().deoptimizePath(UNKNOWN_PATH);
6535
- this.scope.deoptimizeAllParameters();
6275
+ for (const parameterList of this.scope.parameters) {
6276
+ for (const parameter of parameterList) {
6277
+ parameter.deoptimizePath(UNKNOWN_PATH);
6278
+ parameter.markReassigned();
6279
+ }
6280
+ }
6536
6281
  }
6537
6282
  }
6538
6283
  getLiteralValueAtPath(path, recursionTracker, origin) {
@@ -6570,13 +6315,8 @@ class FunctionBase extends NodeBase {
6570
6315
  return true;
6571
6316
  }
6572
6317
  }
6573
- const { propertyReadSideEffects } = this.scope.context.options
6574
- .treeshake;
6575
- for (let index = 0; index < this.params.length; index++) {
6576
- const parameter = this.params[index];
6577
- if (parameter.hasEffects(context) ||
6578
- (propertyReadSideEffects &&
6579
- parameter.hasEffectsWhenDestructuring(context, EMPTY_PATH, interaction.args[index + 1] || UNDEFINED_EXPRESSION)))
6318
+ for (const parameter of this.params) {
6319
+ if (parameter.hasEffects(context))
6580
6320
  return true;
6581
6321
  }
6582
6322
  return false;
@@ -6595,17 +6335,21 @@ class FunctionBase extends NodeBase {
6595
6335
  return variable?.getOnlyFunctionCallUsed() ?? false;
6596
6336
  }
6597
6337
  include(context, includeChildrenRecursively) {
6598
- if (!this.included)
6599
- this.includeNode(context);
6600
- if (!(this.parameterVariableValuesDeoptimized || this.onlyFunctionCallUsed())) {
6338
+ if (!this.parameterVariableValuesDeoptimized && !this.onlyFunctionCallUsed()) {
6601
6339
  this.parameterVariableValuesDeoptimized = true;
6602
- this.scope.reassignAllParameters();
6340
+ this.deoptimizeParameterVariableValues();
6603
6341
  }
6342
+ if (!this.deoptimized)
6343
+ this.applyDeoptimizations();
6344
+ this.included = true;
6604
6345
  const { brokenFlow } = context;
6605
6346
  context.brokenFlow = false;
6606
6347
  this.body.include(context, includeChildrenRecursively);
6607
6348
  context.brokenFlow = brokenFlow;
6608
6349
  }
6350
+ includeCallArguments(context, parameters) {
6351
+ this.scope.includeCallArguments(context, parameters);
6352
+ }
6609
6353
  initialise() {
6610
6354
  super.initialise();
6611
6355
  if (this.body instanceof BlockStatement) {
@@ -6627,14 +6371,14 @@ class FunctionBase extends NodeBase {
6627
6371
  // so that the scope already knows all parameters and can detect conflicts
6628
6372
  // when parsing the body.
6629
6373
  const parameters = (this.params = params.map((parameter) => new (context.getNodeConstructor(parameter.type))(this, scope).parseNode(parameter)));
6630
- scope.addParameterVariables(parameters.map(parameter => parameter.declare('parameter', EMPTY_PATH, UNKNOWN_EXPRESSION)), parameters[parameters.length - 1] instanceof RestElement);
6374
+ scope.addParameterVariables(parameters.map(parameter => parameter.declare('parameter', UNKNOWN_EXPRESSION)), parameters[parameters.length - 1] instanceof RestElement);
6631
6375
  this.body = new (context.getNodeConstructor(body.type))(this, bodyScope).parseNode(body);
6632
6376
  return super.parseNode(esTreeNode);
6633
6377
  }
6378
+ addArgumentToBeDeoptimized(_argument) { }
6379
+ applyDeoptimizations() { }
6634
6380
  }
6635
6381
  FunctionBase.prototype.preventChildBlockScope = true;
6636
- FunctionBase.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
6637
- FunctionBase.prototype.applyDeoptimizations = doNotDeoptimize;
6638
6382
 
6639
6383
  class FunctionNode extends FunctionBase {
6640
6384
  constructor() {
@@ -6646,16 +6390,18 @@ class FunctionNode extends FunctionBase {
6646
6390
  this.constructedEntity = new ObjectEntity(Object.create(null), OBJECT_PROTOTYPE);
6647
6391
  // This makes sure that all deoptimizations of "this" are applied to the
6648
6392
  // constructed entity.
6649
- this.scope.thisVariable.addArgumentValue(this.constructedEntity);
6393
+ this.scope.thisVariable.addEntityToBeDeoptimized(this.constructedEntity);
6650
6394
  }
6651
6395
  deoptimizeArgumentsOnInteractionAtPath(interaction, path, recursionTracker) {
6652
6396
  super.deoptimizeArgumentsOnInteractionAtPath(interaction, path, recursionTracker);
6653
6397
  if (interaction.type === INTERACTION_CALLED && path.length === 0 && interaction.args[0]) {
6654
6398
  // args[0] is the "this" argument
6655
- this.scope.thisVariable.addArgumentValue(interaction.args[0]);
6399
+ this.scope.thisVariable.addEntityToBeDeoptimized(interaction.args[0]);
6656
6400
  }
6657
6401
  }
6658
6402
  hasEffects(context) {
6403
+ if (!this.deoptimized)
6404
+ this.applyDeoptimizations();
6659
6405
  if (this.annotationNoSideEffects) {
6660
6406
  return false;
6661
6407
  }
@@ -6693,7 +6439,7 @@ class FunctionNode extends FunctionBase {
6693
6439
  }
6694
6440
  include(context, includeChildrenRecursively) {
6695
6441
  super.include(context, includeChildrenRecursively);
6696
- this.id?.include(context);
6442
+ this.id?.include();
6697
6443
  const hasArguments = this.scope.argumentsVariable.included;
6698
6444
  for (const parameter of this.params) {
6699
6445
  if (!(parameter instanceof Identifier) || hasArguments) {
@@ -6701,18 +6447,12 @@ class FunctionNode extends FunctionBase {
6701
6447
  }
6702
6448
  }
6703
6449
  }
6704
- includeNode(context) {
6705
- this.included = true;
6706
- const hasArguments = this.scope.argumentsVariable.included;
6707
- for (const parameter of this.params) {
6708
- if (!(parameter instanceof Identifier) || hasArguments) {
6709
- parameter.includePath(UNKNOWN_PATH, context);
6710
- }
6711
- }
6712
- }
6713
6450
  initialise() {
6714
6451
  super.initialise();
6715
- this.id?.declare('function', EMPTY_PATH, this);
6452
+ this.id?.declare('function', this);
6453
+ }
6454
+ addArgumentToBeDeoptimized(argument) {
6455
+ this.scope.argumentsVariable.addArgumentToBeDeoptimized(argument);
6716
6456
  }
6717
6457
  getObjectEntity() {
6718
6458
  if (this.objectEntity !== null) {
@@ -6762,16 +6502,11 @@ function getFunctionIdInsertPosition(code, start) {
6762
6502
  }
6763
6503
  class ExportDefaultDeclaration extends NodeBase {
6764
6504
  include(context, includeChildrenRecursively) {
6765
- this.included = true;
6766
- this.declaration.include(context, includeChildrenRecursively);
6505
+ super.include(context, includeChildrenRecursively);
6767
6506
  if (includeChildrenRecursively) {
6768
- this.scope.context.includeVariableInModule(this.variable, UNKNOWN_PATH, context);
6507
+ this.scope.context.includeVariableInModule(this.variable);
6769
6508
  }
6770
6509
  }
6771
- includePath(path, context) {
6772
- this.included = true;
6773
- this.declaration.includePath(path, context);
6774
- }
6775
6510
  initialise() {
6776
6511
  super.initialise();
6777
6512
  const declaration = this.declaration;
@@ -6816,6 +6551,7 @@ class ExportDefaultDeclaration extends NodeBase {
6816
6551
  }
6817
6552
  this.declaration.render(code, options);
6818
6553
  }
6554
+ applyDeoptimizations() { }
6819
6555
  renderNamedDeclaration(code, declarationStart, idInsertPosition, options) {
6820
6556
  const { exportNamesByVariable, format, snippets: { getPropertyAccess } } = options;
6821
6557
  const name = this.variable.getName(getPropertyAccess);
@@ -6846,8 +6582,6 @@ class ExportDefaultDeclaration extends NodeBase {
6846
6582
  }
6847
6583
  }
6848
6584
  ExportDefaultDeclaration.prototype.needsBoundaries = true;
6849
- ExportDefaultDeclaration.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
6850
- ExportDefaultDeclaration.prototype.applyDeoptimizations = doNotDeoptimize;
6851
6585
 
6852
6586
  const needsEscapeRegEx = /[\n\r'\\\u2028\u2029]/;
6853
6587
  const quoteNewlineRegEx = /([\n\r'\u2028\u2029])/g;
@@ -7117,7 +6851,6 @@ class Literal extends NodeBase {
7117
6851
  }
7118
6852
  }
7119
6853
  }
7120
- Literal.prototype.includeNode = onlyIncludeSelf;
7121
6854
 
7122
6855
  function getChainElementLiteralValueAtPath(element, object, path, recursionTracker, origin) {
7123
6856
  if ('getLiteralValueAtPathAsChainElement' in object) {
@@ -7133,6 +6866,8 @@ function getChainElementLiteralValueAtPath(element, object, path, recursionTrack
7133
6866
  return element.getLiteralValueAtPath(path, recursionTracker, origin);
7134
6867
  }
7135
6868
 
6869
+ // To avoid infinite recursions
6870
+ const MAX_PATH_DEPTH = 7;
7136
6871
  function getResolvablePropertyKey(memberExpression) {
7137
6872
  return memberExpression.computed
7138
6873
  ? getResolvableComputedPropertyKey(memberExpression.property)
@@ -7231,27 +6966,18 @@ class MemberExpression extends NodeBase {
7231
6966
  }
7232
6967
  else if (!this.isUndefined) {
7233
6968
  if (path.length < MAX_PATH_DEPTH) {
7234
- this.object.deoptimizeArgumentsOnInteractionAtPath(interaction, this.propertyKey === UnknownKey ? UNKNOWN_PATH : [this.propertyKey, ...path], recursionTracker);
6969
+ this.object.deoptimizeArgumentsOnInteractionAtPath(interaction, [this.getPropertyKey(), ...path], recursionTracker);
7235
6970
  }
7236
6971
  else {
7237
6972
  deoptimizeInteraction(interaction);
7238
6973
  }
7239
6974
  }
7240
6975
  }
7241
- deoptimizeAssignment(destructuredInitPath, init) {
7242
- this.deoptimizePath(EMPTY_PATH);
7243
- init.deoptimizePath([...destructuredInitPath, UnknownKey]);
7244
- }
7245
6976
  deoptimizeCache() {
7246
- if (this.propertyKey === this.dynamicPropertyKey)
7247
- return;
7248
6977
  const { expressionsToBeDeoptimized, object } = this;
7249
6978
  this.expressionsToBeDeoptimized = EMPTY_ARRAY;
7250
- this.dynamicPropertyKey = this.propertyKey;
6979
+ this.propertyKey = UnknownKey;
7251
6980
  object.deoptimizePath(UNKNOWN_PATH);
7252
- if (this.included) {
7253
- object.includePath(UNKNOWN_PATH, createInclusionContext());
7254
- }
7255
6981
  for (const expression of expressionsToBeDeoptimized) {
7256
6982
  expression.deoptimizeCache();
7257
6983
  }
@@ -7262,13 +6988,11 @@ class MemberExpression extends NodeBase {
7262
6988
  if (this.variable) {
7263
6989
  this.variable.deoptimizePath(path);
7264
6990
  }
7265
- else if (!this.isUndefined) {
7266
- const { propertyKey } = this;
6991
+ else if (!this.isUndefined && path.length < MAX_PATH_DEPTH) {
6992
+ const propertyKey = this.getPropertyKey();
7267
6993
  this.object.deoptimizePath([
7268
6994
  propertyKey === UnknownKey ? UnknownNonAccessorKey : propertyKey,
7269
- ...(path.length < MAX_PATH_DEPTH
7270
- ? path
7271
- : [...path.slice(0, MAX_PATH_DEPTH), UnknownKey])
6995
+ ...path
7272
6996
  ]);
7273
6997
  }
7274
6998
  }
@@ -7279,11 +7003,9 @@ class MemberExpression extends NodeBase {
7279
7003
  if (this.isUndefined) {
7280
7004
  return undefined;
7281
7005
  }
7282
- const propertyKey = this.getDynamicPropertyKey();
7283
- if (propertyKey !== UnknownKey && path.length < MAX_PATH_DEPTH) {
7284
- if (propertyKey !== this.propertyKey)
7285
- this.expressionsToBeDeoptimized.push(origin);
7286
- return this.object.getLiteralValueAtPath([propertyKey, ...path], recursionTracker, origin);
7006
+ if (this.propertyKey !== UnknownKey && path.length < MAX_PATH_DEPTH) {
7007
+ this.expressionsToBeDeoptimized.push(origin);
7008
+ return this.object.getLiteralValueAtPath([this.getPropertyKey(), ...path], recursionTracker, origin);
7287
7009
  }
7288
7010
  return UnknownValue;
7289
7011
  }
@@ -7303,11 +7025,9 @@ class MemberExpression extends NodeBase {
7303
7025
  if (this.isUndefined) {
7304
7026
  return [UNDEFINED_EXPRESSION, false];
7305
7027
  }
7306
- const propertyKey = this.getDynamicPropertyKey();
7307
- if (propertyKey !== UnknownKey && path.length < MAX_PATH_DEPTH) {
7308
- if (propertyKey !== this.propertyKey)
7309
- this.expressionsToBeDeoptimized.push(origin);
7310
- return this.object.getReturnExpressionWhenCalledAtPath([propertyKey, ...path], interaction, recursionTracker, origin);
7028
+ if (this.propertyKey !== UnknownKey && path.length < MAX_PATH_DEPTH) {
7029
+ this.expressionsToBeDeoptimized.push(origin);
7030
+ return this.object.getReturnExpressionWhenCalledAtPath([this.getPropertyKey(), ...path], interaction, recursionTracker, origin);
7311
7031
  }
7312
7032
  return UNKNOWN_RETURN_EXPRESSION;
7313
7033
  }
@@ -7353,45 +7073,14 @@ class MemberExpression extends NodeBase {
7353
7073
  return true;
7354
7074
  }
7355
7075
  if (path.length < MAX_PATH_DEPTH) {
7356
- return this.object.hasEffectsOnInteractionAtPath([this.getDynamicPropertyKey(), ...path], interaction, context);
7076
+ return this.object.hasEffectsOnInteractionAtPath([this.getPropertyKey(), ...path], interaction, context);
7357
7077
  }
7358
7078
  return true;
7359
7079
  }
7360
- hasEffectsWhenDestructuring(context, destructuredInitPath, init) {
7361
- return (destructuredInitPath.length > 0 &&
7362
- init.hasEffectsOnInteractionAtPath(destructuredInitPath, NODE_INTERACTION_UNKNOWN_ACCESS, context));
7363
- }
7364
7080
  include(context, includeChildrenRecursively) {
7365
- if (!this.included)
7366
- this.includeNode(context);
7367
- this.object.include(context, includeChildrenRecursively);
7368
- this.property.include(context, includeChildrenRecursively);
7369
- }
7370
- includeNode(context) {
7371
- this.included = true;
7372
7081
  if (!this.deoptimized)
7373
7082
  this.applyDeoptimizations();
7374
- if (this.variable) {
7375
- this.scope.context.includeVariableInModule(this.variable, EMPTY_PATH, context);
7376
- }
7377
- else if (!this.isUndefined) {
7378
- this.object.includePath([this.propertyKey], context);
7379
- }
7380
- }
7381
- includePath(path, context) {
7382
- if (!this.included)
7383
- this.includeNode(context);
7384
- if (this.variable) {
7385
- this.variable?.includePath(path, context);
7386
- }
7387
- else if (!this.isUndefined) {
7388
- this.object.includePath([
7389
- this.propertyKey,
7390
- ...(path.length < MAX_PATH_DEPTH
7391
- ? path
7392
- : [...path.slice(0, MAX_PATH_DEPTH), UnknownKey])
7393
- ], context);
7394
- }
7083
+ this.includeProperties(context, includeChildrenRecursively);
7395
7084
  }
7396
7085
  includeAsAssignmentTarget(context, includeChildrenRecursively, deoptimizeAccess) {
7397
7086
  if (!this.assignmentDeoptimized)
@@ -7400,34 +7089,20 @@ class MemberExpression extends NodeBase {
7400
7089
  this.include(context, includeChildrenRecursively);
7401
7090
  }
7402
7091
  else {
7403
- if (!this.included)
7404
- this.includeNode(context);
7405
- this.object.include(context, includeChildrenRecursively);
7406
- this.property.include(context, includeChildrenRecursively);
7092
+ this.includeProperties(context, includeChildrenRecursively);
7407
7093
  }
7408
7094
  }
7409
- includeCallArguments(context, interaction) {
7095
+ includeCallArguments(context, parameters) {
7410
7096
  if (this.variable) {
7411
- this.variable.includeCallArguments(context, interaction);
7097
+ this.variable.includeCallArguments(context, parameters);
7412
7098
  }
7413
7099
  else {
7414
- super.includeCallArguments(context, interaction);
7415
- }
7416
- }
7417
- includeDestructuredIfNecessary(context, destructuredInitPath, init) {
7418
- if ((this.included ||=
7419
- destructuredInitPath.length > 0 &&
7420
- !context.brokenFlow &&
7421
- init.hasEffectsOnInteractionAtPath(destructuredInitPath, NODE_INTERACTION_UNKNOWN_ACCESS, createHasEffectsContext()))) {
7422
- init.include(context, false);
7423
- return true;
7100
+ super.includeCallArguments(context, parameters);
7424
7101
  }
7425
- return false;
7426
7102
  }
7427
7103
  initialise() {
7428
7104
  super.initialise();
7429
- this.dynamicPropertyKey = getResolvablePropertyKey(this);
7430
- this.propertyKey = this.dynamicPropertyKey === null ? UnknownKey : this.dynamicPropertyKey;
7105
+ this.propertyKey = getResolvablePropertyKey(this);
7431
7106
  this.accessInteraction = { args: [this.object], type: INTERACTION_ACCESSED };
7432
7107
  }
7433
7108
  render(code, options, { renderedParentType, isCalleeOfRenderedParent, renderedSurroundingElement } = BLANK) {
@@ -7464,7 +7139,8 @@ class MemberExpression extends NodeBase {
7464
7139
  this.bound &&
7465
7140
  propertyReadSideEffects &&
7466
7141
  !(this.variable || this.isUndefined)) {
7467
- this.object.deoptimizeArgumentsOnInteractionAtPath(this.accessInteraction, [this.propertyKey], SHARED_RECURSION_TRACKER);
7142
+ const propertyKey = this.getPropertyKey();
7143
+ this.object.deoptimizeArgumentsOnInteractionAtPath(this.accessInteraction, [propertyKey], SHARED_RECURSION_TRACKER);
7468
7144
  this.scope.context.requestTreeshakingPass();
7469
7145
  }
7470
7146
  if (this.variable) {
@@ -7481,7 +7157,7 @@ class MemberExpression extends NodeBase {
7481
7157
  this.bound &&
7482
7158
  propertyReadSideEffects &&
7483
7159
  !(this.variable || this.isUndefined)) {
7484
- this.object.deoptimizeArgumentsOnInteractionAtPath(this.assignmentInteraction, [this.propertyKey], SHARED_RECURSION_TRACKER);
7160
+ this.object.deoptimizeArgumentsOnInteractionAtPath(this.assignmentInteraction, [this.getPropertyKey()], SHARED_RECURSION_TRACKER);
7485
7161
  this.scope.context.requestTreeshakingPass();
7486
7162
  }
7487
7163
  }
@@ -7490,24 +7166,24 @@ class MemberExpression extends NodeBase {
7490
7166
  const variable = this.scope.findVariable(this.object.name);
7491
7167
  if (variable.isNamespace) {
7492
7168
  if (this.variable) {
7493
- this.scope.context.includeVariableInModule(this.variable, UNKNOWN_PATH, createInclusionContext());
7169
+ this.scope.context.includeVariableInModule(this.variable);
7494
7170
  }
7495
7171
  this.scope.context.log(LOGLEVEL_WARN, logIllegalImportReassignment(this.object.name, this.scope.context.module.id), this.start);
7496
7172
  }
7497
7173
  }
7498
7174
  }
7499
- getDynamicPropertyKey() {
7500
- if (this.dynamicPropertyKey === null) {
7501
- this.dynamicPropertyKey = this.propertyKey;
7175
+ getPropertyKey() {
7176
+ if (this.propertyKey === null) {
7177
+ this.propertyKey = UnknownKey;
7502
7178
  const value = this.property.getLiteralValueAtPath(EMPTY_PATH, SHARED_RECURSION_TRACKER, this);
7503
- return (this.dynamicPropertyKey =
7179
+ return (this.propertyKey =
7504
7180
  value === SymbolToStringTag
7505
7181
  ? value
7506
7182
  : typeof value === 'symbol'
7507
7183
  ? UnknownKey
7508
7184
  : String(value));
7509
7185
  }
7510
- return this.dynamicPropertyKey;
7186
+ return this.propertyKey;
7511
7187
  }
7512
7188
  hasAccessEffect(context) {
7513
7189
  const { propertyReadSideEffects } = this.scope.context.options
@@ -7515,7 +7191,17 @@ class MemberExpression extends NodeBase {
7515
7191
  return (!(this.variable || this.isUndefined) &&
7516
7192
  propertyReadSideEffects &&
7517
7193
  (propertyReadSideEffects === 'always' ||
7518
- this.object.hasEffectsOnInteractionAtPath([this.getDynamicPropertyKey()], this.accessInteraction, context)));
7194
+ this.object.hasEffectsOnInteractionAtPath([this.getPropertyKey()], this.accessInteraction, context)));
7195
+ }
7196
+ includeProperties(context, includeChildrenRecursively) {
7197
+ if (!this.included) {
7198
+ this.included = true;
7199
+ if (this.variable) {
7200
+ this.scope.context.includeVariableInModule(this.variable);
7201
+ }
7202
+ }
7203
+ this.object.include(context, includeChildrenRecursively);
7204
+ this.property.include(context, includeChildrenRecursively);
7519
7205
  }
7520
7206
  }
7521
7207
  function resolveNamespaceVariables(baseVariable, path, astContext) {
@@ -7559,20 +7245,18 @@ class MetaProperty extends NodeBase {
7559
7245
  return path.length > 1 || type !== INTERACTION_ACCESSED;
7560
7246
  }
7561
7247
  include() {
7562
- if (!this.included)
7563
- this.includeNode();
7564
- }
7565
- includeNode() {
7566
- this.included = true;
7567
- if (this.meta.name === IMPORT) {
7568
- this.scope.context.addImportMeta(this);
7569
- const parent = this.parent;
7570
- const metaProperty = (this.metaProperty =
7571
- parent instanceof MemberExpression && typeof parent.propertyKey === 'string'
7572
- ? parent.propertyKey
7573
- : null);
7574
- if (metaProperty?.startsWith(FILE_PREFIX)) {
7575
- this.referenceId = metaProperty.slice(FILE_PREFIX.length);
7248
+ if (!this.included) {
7249
+ this.included = true;
7250
+ if (this.meta.name === IMPORT) {
7251
+ this.scope.context.addImportMeta(this);
7252
+ const parent = this.parent;
7253
+ const metaProperty = (this.metaProperty =
7254
+ parent instanceof MemberExpression && typeof parent.propertyKey === 'string'
7255
+ ? parent.propertyKey
7256
+ : null);
7257
+ if (metaProperty?.startsWith(FILE_PREFIX)) {
7258
+ this.referenceId = metaProperty.slice(FILE_PREFIX.length);
7259
+ }
7576
7260
  }
7577
7261
  }
7578
7262
  }
@@ -7679,7 +7363,7 @@ class UndefinedVariable extends Variable {
7679
7363
 
7680
7364
  class ExportDefaultVariable extends LocalVariable {
7681
7365
  constructor(name, exportDefaultDeclaration, context) {
7682
- super(name, exportDefaultDeclaration, exportDefaultDeclaration.declaration, EMPTY_PATH, context, 'other');
7366
+ super(name, exportDefaultDeclaration, exportDefaultDeclaration.declaration, context, 'other');
7683
7367
  this.hasId = false;
7684
7368
  this.originalId = null;
7685
7369
  this.originalVariable = null;
@@ -7828,8 +7512,8 @@ class NamespaceVariable extends Variable {
7828
7512
  return (!memberVariable ||
7829
7513
  memberVariable.hasEffectsOnInteractionAtPath(path.slice(1), interaction, context));
7830
7514
  }
7831
- includePath(path, context) {
7832
- super.includePath(path, context);
7515
+ include() {
7516
+ super.include();
7833
7517
  this.context.includeAllExports();
7834
7518
  }
7835
7519
  prepare(accessedGlobalsByScope) {
@@ -7922,9 +7606,9 @@ class SyntheticNamedExportVariable extends Variable {
7922
7606
  getName(getPropertyAccess) {
7923
7607
  return `${this.syntheticNamespace.getName(getPropertyAccess)}${getPropertyAccess(this.name)}`;
7924
7608
  }
7925
- includePath(path, context) {
7926
- super.includePath(path, context);
7927
- this.context.includeVariableInModule(this.syntheticNamespace, path, context);
7609
+ include() {
7610
+ super.include();
7611
+ this.context.includeVariableInModule(this.syntheticNamespace);
7928
7612
  }
7929
7613
  setRenderNames(baseName, name) {
7930
7614
  super.setRenderNames(baseName, name);
@@ -11100,11 +10784,17 @@ const createFilter = function createFilter(include, exclude, options) {
11100
10784
  const pathId = normalizePath(id);
11101
10785
  for (let i = 0; i < excludeMatchers.length; ++i) {
11102
10786
  const matcher = excludeMatchers[i];
10787
+ if (matcher instanceof RegExp) {
10788
+ matcher.lastIndex = 0;
10789
+ }
11103
10790
  if (matcher.test(pathId))
11104
10791
  return false;
11105
10792
  }
11106
10793
  for (let i = 0; i < includeMatchers.length; ++i) {
11107
10794
  const matcher = includeMatchers[i];
10795
+ if (matcher instanceof RegExp) {
10796
+ matcher.lastIndex = 0;
10797
+ }
11108
10798
  if (matcher.test(pathId))
11109
10799
  return true;
11110
10800
  }
@@ -11123,37 +10813,21 @@ class ArrayPattern extends NodeBase {
11123
10813
  element?.addExportedVariables(variables, exportNamesByVariable);
11124
10814
  }
11125
10815
  }
11126
- declare(kind, destructuredInitPath, init) {
10816
+ declare(kind) {
11127
10817
  const variables = [];
11128
- const includedPatternPath = getIncludedPatternPath(destructuredInitPath);
11129
10818
  for (const element of this.elements) {
11130
10819
  if (element !== null) {
11131
- variables.push(...element.declare(kind, includedPatternPath, init));
10820
+ variables.push(...element.declare(kind, UNKNOWN_EXPRESSION));
11132
10821
  }
11133
10822
  }
11134
10823
  return variables;
11135
10824
  }
11136
- deoptimizeAssignment(destructuredInitPath, init) {
11137
- const includedPatternPath = getIncludedPatternPath(destructuredInitPath);
11138
- for (const element of this.elements) {
11139
- element?.deoptimizeAssignment(includedPatternPath, init);
11140
- }
11141
- }
11142
10825
  // Patterns can only be deoptimized at the empty path at the moment
11143
10826
  deoptimizePath() {
11144
10827
  for (const element of this.elements) {
11145
10828
  element?.deoptimizePath(EMPTY_PATH);
11146
10829
  }
11147
10830
  }
11148
- hasEffectsWhenDestructuring(context, destructuredInitPath, init) {
11149
- const includedPatternPath = getIncludedPatternPath(destructuredInitPath);
11150
- for (const element of this.elements) {
11151
- if (element?.hasEffectsWhenDestructuring(context, includedPatternPath, init)) {
11152
- return true;
11153
- }
11154
- }
11155
- return false;
11156
- }
11157
10831
  // Patterns are only checked at the empty path at the moment
11158
10832
  hasEffectsOnInteractionAtPath(_path, interaction, context) {
11159
10833
  for (const element of this.elements) {
@@ -11162,38 +10836,12 @@ class ArrayPattern extends NodeBase {
11162
10836
  }
11163
10837
  return false;
11164
10838
  }
11165
- includeDestructuredIfNecessary(context, destructuredInitPath, init) {
11166
- let included = false;
11167
- const includedPatternPath = getIncludedPatternPath(destructuredInitPath);
11168
- for (const element of this.elements) {
11169
- if (element) {
11170
- element.included ||= included;
11171
- included =
11172
- element.includeDestructuredIfNecessary(context, includedPatternPath, init) || included;
11173
- }
11174
- }
11175
- if (included) {
11176
- // This is necessary so that if any pattern element is included, all are
11177
- // included for proper deconflicting
11178
- for (const element of this.elements) {
11179
- if (element && !element.included) {
11180
- element.included = true;
11181
- element.includeDestructuredIfNecessary(context, includedPatternPath, init);
11182
- }
11183
- }
11184
- }
11185
- return (this.included ||= included);
11186
- }
11187
10839
  markDeclarationReached() {
11188
10840
  for (const element of this.elements) {
11189
10841
  element?.markDeclarationReached();
11190
10842
  }
11191
10843
  }
11192
10844
  }
11193
- ArrayPattern.prototype.includeNode = onlyIncludeSelf;
11194
- const getIncludedPatternPath = (destructuredInitPath) => destructuredInitPath.at(-1) === UnknownKey
11195
- ? destructuredInitPath
11196
- : [...destructuredInitPath, UnknownInteger];
11197
10845
 
11198
10846
  class ArrowFunctionExpression extends FunctionBase {
11199
10847
  constructor() {
@@ -11210,6 +10858,8 @@ class ArrowFunctionExpression extends FunctionBase {
11210
10858
  this.scope = new ReturnValueScope(parentScope, false);
11211
10859
  }
11212
10860
  hasEffects() {
10861
+ if (!this.deoptimized)
10862
+ this.applyDeoptimizations();
11213
10863
  return false;
11214
10864
  }
11215
10865
  hasEffectsOnInteractionAtPath(path, interaction, context) {
@@ -11248,15 +10898,6 @@ class ArrowFunctionExpression extends FunctionBase {
11248
10898
  }
11249
10899
  }
11250
10900
  }
11251
- includeNode(context) {
11252
- this.included = true;
11253
- this.body.includePath(UNKNOWN_PATH, context);
11254
- for (const parameter of this.params) {
11255
- if (!(parameter instanceof Identifier)) {
11256
- parameter.includePath(UNKNOWN_PATH, context);
11257
- }
11258
- }
11259
- }
11260
10901
  getObjectEntity() {
11261
10902
  if (this.objectEntity !== null) {
11262
10903
  return this.objectEntity;
@@ -11276,18 +10917,13 @@ class ObjectPattern extends NodeBase {
11276
10917
  }
11277
10918
  }
11278
10919
  }
11279
- declare(kind, destructuredInitPath, init) {
10920
+ declare(kind, init) {
11280
10921
  const variables = [];
11281
10922
  for (const property of this.properties) {
11282
- variables.push(...property.declare(kind, destructuredInitPath, init));
10923
+ variables.push(...property.declare(kind, init));
11283
10924
  }
11284
10925
  return variables;
11285
10926
  }
11286
- deoptimizeAssignment(destructuredInitPath, init) {
11287
- for (const property of this.properties) {
11288
- property.deoptimizeAssignment(destructuredInitPath, init);
11289
- }
11290
- }
11291
10927
  deoptimizePath(path) {
11292
10928
  if (path.length === 0) {
11293
10929
  for (const property of this.properties) {
@@ -11305,46 +10941,12 @@ class ObjectPattern extends NodeBase {
11305
10941
  }
11306
10942
  return false;
11307
10943
  }
11308
- hasEffectsWhenDestructuring(context, destructuredInitPath, init) {
11309
- for (const property of this.properties) {
11310
- if (property.hasEffectsWhenDestructuring(context, destructuredInitPath, init))
11311
- return true;
11312
- }
11313
- return false;
11314
- }
11315
- includeDestructuredIfNecessary(context, destructuredInitPath, init) {
11316
- let included = false;
11317
- for (const property of this.properties) {
11318
- included =
11319
- property.includeDestructuredIfNecessary(context, destructuredInitPath, init) || included;
11320
- }
11321
- return (this.included ||= included);
11322
- }
11323
10944
  markDeclarationReached() {
11324
10945
  for (const property of this.properties) {
11325
10946
  property.markDeclarationReached();
11326
10947
  }
11327
10948
  }
11328
- render(code, options) {
11329
- if (this.properties.length > 0) {
11330
- const separatedNodes = getCommaSeparatedNodesWithBoundaries(this.properties, code, this.start + 1, this.end - 1);
11331
- let lastSeparatorPos = null;
11332
- for (const { node, separator, start, end } of separatedNodes) {
11333
- if (!node.included) {
11334
- treeshakeNode(node, code, start, end);
11335
- continue;
11336
- }
11337
- lastSeparatorPos = separator;
11338
- node.render(code, options);
11339
- }
11340
- if (lastSeparatorPos) {
11341
- code.remove(lastSeparatorPos, this.end - 1);
11342
- }
11343
- }
11344
- }
11345
10949
  }
11346
- ObjectPattern.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
11347
- ObjectPattern.prototype.applyDeoptimizations = doNotDeoptimize;
11348
10950
 
11349
10951
  class AssignmentExpression extends NodeBase {
11350
10952
  hasEffects(context) {
@@ -11353,9 +10955,7 @@ class AssignmentExpression extends NodeBase {
11353
10955
  this.applyDeoptimizations();
11354
10956
  // MemberExpressions do not access the property before assignments if the
11355
10957
  // operator is '='.
11356
- return (right.hasEffects(context) ||
11357
- left.hasEffectsAsAssignmentTarget(context, operator !== '=') ||
11358
- this.left.hasEffectsWhenDestructuring?.(context, EMPTY_PATH, right));
10958
+ return (right.hasEffects(context) || left.hasEffectsAsAssignmentTarget(context, operator !== '='));
11359
10959
  }
11360
10960
  hasEffectsOnInteractionAtPath(path, interaction, context) {
11361
10961
  return this.right.hasEffectsOnInteractionAtPath(path, interaction, context);
@@ -11364,24 +10964,15 @@ class AssignmentExpression extends NodeBase {
11364
10964
  const { deoptimized, left, right, operator } = this;
11365
10965
  if (!deoptimized)
11366
10966
  this.applyDeoptimizations();
11367
- if (!this.included)
11368
- this.includeNode(context);
11369
- const hasEffectsContext = createHasEffectsContext();
10967
+ this.included = true;
11370
10968
  if (includeChildrenRecursively ||
11371
10969
  operator !== '=' ||
11372
10970
  left.included ||
11373
- left.hasEffectsAsAssignmentTarget(hasEffectsContext, false) ||
11374
- left.hasEffectsWhenDestructuring?.(hasEffectsContext, EMPTY_PATH, right)) {
10971
+ left.hasEffectsAsAssignmentTarget(createHasEffectsContext(), false)) {
11375
10972
  left.includeAsAssignmentTarget(context, includeChildrenRecursively, operator !== '=');
11376
10973
  }
11377
10974
  right.include(context, includeChildrenRecursively);
11378
10975
  }
11379
- includeNode(context) {
11380
- this.included = true;
11381
- if (!this.deoptimized)
11382
- this.applyDeoptimizations();
11383
- this.right.includePath(UNKNOWN_PATH, context);
11384
- }
11385
10976
  initialise() {
11386
10977
  super.initialise();
11387
10978
  if (this.left instanceof Identifier) {
@@ -11442,7 +11033,8 @@ class AssignmentExpression extends NodeBase {
11442
11033
  }
11443
11034
  applyDeoptimizations() {
11444
11035
  this.deoptimized = true;
11445
- this.left.deoptimizeAssignment(EMPTY_PATH, this.right);
11036
+ this.left.deoptimizePath(EMPTY_PATH);
11037
+ this.right.deoptimizePath(UNKNOWN_PATH);
11446
11038
  this.scope.context.requestTreeshakingPass();
11447
11039
  }
11448
11040
  }
@@ -11451,11 +11043,8 @@ class AssignmentPattern extends NodeBase {
11451
11043
  addExportedVariables(variables, exportNamesByVariable) {
11452
11044
  this.left.addExportedVariables(variables, exportNamesByVariable);
11453
11045
  }
11454
- declare(kind, destructuredInitPath, init) {
11455
- return this.left.declare(kind, destructuredInitPath, init);
11456
- }
11457
- deoptimizeAssignment(destructuredInitPath, init) {
11458
- this.left.deoptimizeAssignment(destructuredInitPath, init);
11046
+ declare(kind, init) {
11047
+ return this.left.declare(kind, init);
11459
11048
  }
11460
11049
  deoptimizePath(path) {
11461
11050
  if (path.length === 0) {
@@ -11465,29 +11054,6 @@ class AssignmentPattern extends NodeBase {
11465
11054
  hasEffectsOnInteractionAtPath(path, interaction, context) {
11466
11055
  return (path.length > 0 || this.left.hasEffectsOnInteractionAtPath(EMPTY_PATH, interaction, context));
11467
11056
  }
11468
- hasEffectsWhenDestructuring(context, destructuredInitPath, init) {
11469
- return this.left.hasEffectsWhenDestructuring(context, destructuredInitPath, init);
11470
- }
11471
- includeDestructuredIfNecessary(context, destructuredInitPath, init) {
11472
- let included = this.left.includeDestructuredIfNecessary(context, destructuredInitPath, init) ||
11473
- this.included;
11474
- if ((included ||= this.right.shouldBeIncluded(context))) {
11475
- this.right.include(context, false);
11476
- if (!this.left.included) {
11477
- this.left.included = true;
11478
- // Unfortunately, we need to include the left side again now, so that
11479
- // any declared variables are properly included.
11480
- this.left.includeDestructuredIfNecessary(context, destructuredInitPath, init);
11481
- }
11482
- }
11483
- return (this.included = included);
11484
- }
11485
- includeNode(context) {
11486
- this.included = true;
11487
- if (!this.deoptimized)
11488
- this.applyDeoptimizations();
11489
- this.right.includePath(UNKNOWN_PATH, context);
11490
- }
11491
11057
  markDeclarationReached() {
11492
11058
  this.left.markDeclarationReached();
11493
11059
  }
@@ -11504,40 +11070,28 @@ class AssignmentPattern extends NodeBase {
11504
11070
  }
11505
11071
 
11506
11072
  class AwaitExpression extends NodeBase {
11507
- hasEffects() {
11508
- if (!this.deoptimized)
11509
- this.applyDeoptimizations();
11510
- return true;
11511
- }
11512
- include(context, includeChildrenRecursively) {
11513
- if (!this.included)
11514
- this.includeNode(context);
11515
- this.argument.include(context, includeChildrenRecursively);
11516
- }
11517
- includeNode(context) {
11518
- this.included = true;
11073
+ hasEffects() {
11519
11074
  if (!this.deoptimized)
11520
11075
  this.applyDeoptimizations();
11521
- checkTopLevelAwait: if (!this.scope.context.usesTopLevelAwait) {
11522
- let parent = this.parent;
11523
- do {
11524
- if (parent instanceof FunctionNode || parent instanceof ArrowFunctionExpression)
11525
- break checkTopLevelAwait;
11526
- } while ((parent = parent.parent));
11527
- this.scope.context.usesTopLevelAwait = true;
11528
- }
11529
- // Thenables need to be included
11530
- this.argument.includePath(THEN_PATH, context);
11076
+ return true;
11531
11077
  }
11532
- includePath(path, context) {
11078
+ include(context, includeChildrenRecursively) {
11533
11079
  if (!this.deoptimized)
11534
11080
  this.applyDeoptimizations();
11535
- if (!this.included)
11536
- this.includeNode(context);
11537
- this.argument.includePath(path, context);
11081
+ if (!this.included) {
11082
+ this.included = true;
11083
+ checkTopLevelAwait: if (!this.scope.context.usesTopLevelAwait) {
11084
+ let parent = this.parent;
11085
+ do {
11086
+ if (parent instanceof FunctionNode || parent instanceof ArrowFunctionExpression)
11087
+ break checkTopLevelAwait;
11088
+ } while ((parent = parent.parent));
11089
+ this.scope.context.usesTopLevelAwait = true;
11090
+ }
11091
+ }
11092
+ this.argument.include(context, includeChildrenRecursively);
11538
11093
  }
11539
11094
  }
11540
- const THEN_PATH = ['then'];
11541
11095
 
11542
11096
  const binaryOperators = {
11543
11097
  '!=': (left, right) => left != right,
@@ -11593,12 +11147,6 @@ class BinaryExpression extends NodeBase {
11593
11147
  hasEffectsOnInteractionAtPath(path, { type }) {
11594
11148
  return type !== INTERACTION_ACCESSED || path.length > 1;
11595
11149
  }
11596
- includeNode(context) {
11597
- this.included = true;
11598
- if (this.operator === 'in') {
11599
- this.right.includePath(UNKNOWN_PATH, context);
11600
- }
11601
- }
11602
11150
  removeAnnotations(code) {
11603
11151
  this.left.removeAnnotations(code);
11604
11152
  }
@@ -11607,7 +11155,6 @@ class BinaryExpression extends NodeBase {
11607
11155
  this.right.render(code, options);
11608
11156
  }
11609
11157
  }
11610
- BinaryExpression.prototype.applyDeoptimizations = doNotDeoptimize;
11611
11158
 
11612
11159
  class BreakStatement extends NodeBase {
11613
11160
  hasEffects(context) {
@@ -11627,7 +11174,7 @@ class BreakStatement extends NodeBase {
11627
11174
  include(context) {
11628
11175
  this.included = true;
11629
11176
  if (this.label) {
11630
- this.label.include(context);
11177
+ this.label.include();
11631
11178
  context.includedLabels.add(this.label.name);
11632
11179
  }
11633
11180
  else {
@@ -11636,8 +11183,6 @@ class BreakStatement extends NodeBase {
11636
11183
  context.brokenFlow = true;
11637
11184
  }
11638
11185
  }
11639
- BreakStatement.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
11640
- BreakStatement.prototype.applyDeoptimizations = doNotDeoptimize;
11641
11186
 
11642
11187
  function renderCallArguments(code, options, node) {
11643
11188
  if (node.arguments.length > 0) {
@@ -11824,14 +11369,10 @@ class CallExpression extends CallExpressionBase {
11824
11369
  this.callee.hasEffectsOnInteractionAtPath(EMPTY_PATH, this.interaction, context)));
11825
11370
  }
11826
11371
  include(context, includeChildrenRecursively) {
11827
- if (!this.included)
11828
- this.includeNode(context);
11372
+ if (!this.deoptimized)
11373
+ this.applyDeoptimizations();
11829
11374
  if (includeChildrenRecursively) {
11830
- this.callee.include(context, true);
11831
- for (const argument of this.arguments) {
11832
- argument.includePath(UNKNOWN_PATH, context);
11833
- argument.include(context, true);
11834
- }
11375
+ super.include(context, includeChildrenRecursively);
11835
11376
  if (includeChildrenRecursively === INCLUDE_PARAMETERS &&
11836
11377
  this.callee instanceof Identifier &&
11837
11378
  this.callee.variable) {
@@ -11839,24 +11380,10 @@ class CallExpression extends CallExpressionBase {
11839
11380
  }
11840
11381
  }
11841
11382
  else {
11842
- // If the callee is a member expression and does not have a variable, its
11843
- // object will already be included via the first argument of the
11844
- // interaction in includeCallArguments. Including it again can lead to
11845
- // severe performance problems.
11846
- if (this.callee instanceof MemberExpression && !this.callee.variable) {
11847
- this.callee.property.include(context, false);
11848
- }
11849
- else {
11850
- this.callee.include(context, false);
11851
- }
11852
- this.callee.includeCallArguments(context, this.interaction);
11383
+ this.included = true;
11384
+ this.callee.include(context, false);
11853
11385
  }
11854
- }
11855
- includeNode(context) {
11856
- this.included = true;
11857
- if (!this.deoptimized)
11858
- this.applyDeoptimizations();
11859
- this.callee.includePath(UNKNOWN_PATH, context);
11386
+ this.callee.includeCallArguments(context, this.arguments);
11860
11387
  }
11861
11388
  initialise() {
11862
11389
  super.initialise();
@@ -11895,14 +11422,13 @@ class CatchClause extends NodeBase {
11895
11422
  this.type = type;
11896
11423
  if (param) {
11897
11424
  this.param = new (this.scope.context.getNodeConstructor(param.type))(this, this.scope).parseNode(param);
11898
- this.param.declare('parameter', EMPTY_PATH, UNKNOWN_EXPRESSION);
11425
+ this.param.declare('parameter', UNKNOWN_EXPRESSION);
11899
11426
  }
11900
11427
  this.body = new BlockStatement(this, this.scope.bodyScope).parseNode(body);
11901
11428
  return super.parseNode(esTreeNode);
11902
11429
  }
11903
11430
  }
11904
11431
  CatchClause.prototype.preventChildBlockScope = true;
11905
- CatchClause.prototype.includeNode = onlyIncludeSelf;
11906
11432
 
11907
11433
  class ChainExpression extends NodeBase {
11908
11434
  // deoptimizations are not relevant as we are not caching values
@@ -11914,22 +11440,17 @@ class ChainExpression extends NodeBase {
11914
11440
  hasEffects(context) {
11915
11441
  return this.expression.hasEffectsAsChainElement(context) === true;
11916
11442
  }
11917
- includePath(path, context) {
11918
- this.included = true;
11919
- this.expression.includePath(path, context);
11920
- }
11921
11443
  removeAnnotations(code) {
11922
11444
  this.expression.removeAnnotations(code);
11923
11445
  }
11446
+ applyDeoptimizations() { }
11924
11447
  }
11925
- ChainExpression.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
11926
- ChainExpression.prototype.applyDeoptimizations = doNotDeoptimize;
11927
11448
 
11928
11449
  class ClassBodyScope extends ChildScope {
11929
11450
  constructor(parent, classNode) {
11930
11451
  const { context } = parent;
11931
11452
  super(parent, context);
11932
- this.variables.set('this', (this.thisVariable = new LocalVariable('this', null, classNode, EMPTY_PATH, context, 'other')));
11453
+ this.variables.set('this', (this.thisVariable = new LocalVariable('this', null, classNode, context, 'other')));
11933
11454
  this.instanceScope = new ChildScope(this, context);
11934
11455
  this.instanceScope.variables.set('this', new ThisVariable(context));
11935
11456
  }
@@ -11944,7 +11465,7 @@ class ClassBody extends NodeBase {
11944
11465
  }
11945
11466
  include(context, includeChildrenRecursively) {
11946
11467
  this.included = true;
11947
- this.scope.context.includeVariableInModule(this.scope.thisVariable, UNKNOWN_PATH, context);
11468
+ this.scope.context.includeVariableInModule(this.scope.thisVariable);
11948
11469
  for (const definition of this.body) {
11949
11470
  definition.include(context, includeChildrenRecursively);
11950
11471
  }
@@ -11957,9 +11478,8 @@ class ClassBody extends NodeBase {
11957
11478
  }
11958
11479
  return super.parseNode(esTreeNode);
11959
11480
  }
11481
+ applyDeoptimizations() { }
11960
11482
  }
11961
- ClassBody.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
11962
- ClassBody.prototype.applyDeoptimizations = doNotDeoptimize;
11963
11483
 
11964
11484
  class ClassExpression extends ClassNode {
11965
11485
  render(code, options, { renderedSurroundingElement } = BLANK) {
@@ -11971,6 +11491,19 @@ class ClassExpression extends ClassNode {
11971
11491
  }
11972
11492
  }
11973
11493
 
11494
+ function tryCastLiteralValueToBoolean(literalValue) {
11495
+ if (typeof literalValue === 'symbol') {
11496
+ if (literalValue === UnknownFalsyValue) {
11497
+ return false;
11498
+ }
11499
+ if (literalValue === UnknownTruthyValue) {
11500
+ return true;
11501
+ }
11502
+ return UnknownValue;
11503
+ }
11504
+ return !!literalValue;
11505
+ }
11506
+
11974
11507
  class MultiExpression extends ExpressionEntity {
11975
11508
  constructor(expressions) {
11976
11509
  super();
@@ -12017,9 +11550,6 @@ class ConditionalExpression extends NodeBase {
12017
11550
  const unusedBranch = this.usedBranch === this.consequent ? this.alternate : this.consequent;
12018
11551
  this.usedBranch = null;
12019
11552
  unusedBranch.deoptimizePath(UNKNOWN_PATH);
12020
- if (this.included) {
12021
- unusedBranch.includePath(UNKNOWN_PATH, createInclusionContext());
12022
- }
12023
11553
  const { expressionsToBeDeoptimized } = this;
12024
11554
  this.expressionsToBeDeoptimized = EMPTY_ARRAY;
12025
11555
  for (const expression of expressionsToBeDeoptimized) {
@@ -12077,7 +11607,7 @@ class ConditionalExpression extends NodeBase {
12077
11607
  include(context, includeChildrenRecursively) {
12078
11608
  this.included = true;
12079
11609
  const usedBranch = this.getUsedBranch();
12080
- if (usedBranch === null || includeChildrenRecursively || this.test.shouldBeIncluded(context)) {
11610
+ if (includeChildrenRecursively || this.test.shouldBeIncluded(context) || usedBranch === null) {
12081
11611
  this.test.include(context, includeChildrenRecursively);
12082
11612
  this.consequent.include(context, includeChildrenRecursively);
12083
11613
  this.alternate.include(context, includeChildrenRecursively);
@@ -12086,38 +11616,27 @@ class ConditionalExpression extends NodeBase {
12086
11616
  usedBranch.include(context, includeChildrenRecursively);
12087
11617
  }
12088
11618
  }
12089
- includePath(path, context) {
12090
- this.included = true;
12091
- const usedBranch = this.getUsedBranch();
12092
- if (usedBranch === null || this.test.shouldBeIncluded(context)) {
12093
- this.consequent.includePath(path, context);
12094
- this.alternate.includePath(path, context);
12095
- }
12096
- else {
12097
- usedBranch.includePath(path, context);
12098
- }
12099
- }
12100
- includeCallArguments(context, interaction) {
11619
+ includeCallArguments(context, parameters) {
12101
11620
  const usedBranch = this.getUsedBranch();
12102
11621
  if (usedBranch) {
12103
- usedBranch.includeCallArguments(context, interaction);
11622
+ usedBranch.includeCallArguments(context, parameters);
12104
11623
  }
12105
11624
  else {
12106
- this.consequent.includeCallArguments(context, interaction);
12107
- this.alternate.includeCallArguments(context, interaction);
11625
+ this.consequent.includeCallArguments(context, parameters);
11626
+ this.alternate.includeCallArguments(context, parameters);
12108
11627
  }
12109
11628
  }
12110
11629
  removeAnnotations(code) {
12111
11630
  this.test.removeAnnotations(code);
12112
11631
  }
12113
11632
  render(code, options, { isCalleeOfRenderedParent, preventASI, renderedParentType, renderedSurroundingElement } = BLANK) {
11633
+ const usedBranch = this.getUsedBranch();
12114
11634
  if (this.test.included) {
12115
11635
  this.test.render(code, options, { renderedSurroundingElement });
12116
11636
  this.consequent.render(code, options);
12117
11637
  this.alternate.render(code, options);
12118
11638
  }
12119
11639
  else {
12120
- const usedBranch = this.getUsedBranch();
12121
11640
  const colonPos = findFirstOccurrenceOutsideComment(code.original, ':', this.consequent.end);
12122
11641
  const inclusionStart = findNonWhiteSpace(code.original, (this.consequent.included
12123
11642
  ? findFirstOccurrenceOutsideComment(code.original, '?', this.test.end)
@@ -12143,14 +11662,12 @@ class ConditionalExpression extends NodeBase {
12143
11662
  return this.usedBranch;
12144
11663
  }
12145
11664
  this.isBranchResolutionAnalysed = true;
12146
- const testValue = this.test.getLiteralValueAtPath(EMPTY_PATH, SHARED_RECURSION_TRACKER, this);
11665
+ const testValue = tryCastLiteralValueToBoolean(this.test.getLiteralValueAtPath(EMPTY_PATH, SHARED_RECURSION_TRACKER, this));
12147
11666
  return typeof testValue === 'symbol'
12148
11667
  ? null
12149
11668
  : (this.usedBranch = testValue ? this.consequent : this.alternate);
12150
11669
  }
12151
11670
  }
12152
- ConditionalExpression.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
12153
- ConditionalExpression.prototype.applyDeoptimizations = doNotDeoptimize;
12154
11671
 
12155
11672
  class ContinueStatement extends NodeBase {
12156
11673
  hasEffects(context) {
@@ -12170,7 +11687,7 @@ class ContinueStatement extends NodeBase {
12170
11687
  include(context) {
12171
11688
  this.included = true;
12172
11689
  if (this.label) {
12173
- this.label.include(context);
11690
+ this.label.include();
12174
11691
  context.includedLabels.add(this.label.name);
12175
11692
  }
12176
11693
  else {
@@ -12179,15 +11696,12 @@ class ContinueStatement extends NodeBase {
12179
11696
  context.brokenFlow = true;
12180
11697
  }
12181
11698
  }
12182
- ContinueStatement.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
12183
- ContinueStatement.prototype.applyDeoptimizations = doNotDeoptimize;
12184
11699
 
12185
11700
  class DebuggerStatement extends NodeBase {
12186
11701
  hasEffects() {
12187
11702
  return true;
12188
11703
  }
12189
11704
  }
12190
- DebuggerStatement.prototype.includeNode = onlyIncludeSelf;
12191
11705
 
12192
11706
  class Decorator extends NodeBase {
12193
11707
  hasEffects(context) {
@@ -12195,7 +11709,6 @@ class Decorator extends NodeBase {
12195
11709
  this.expression.hasEffectsOnInteractionAtPath(EMPTY_PATH, NODE_INTERACTION_UNKNOWN_CALL, context));
12196
11710
  }
12197
11711
  }
12198
- Decorator.prototype.includeNode = onlyIncludeSelf;
12199
11712
 
12200
11713
  function hasLoopBodyEffects(context, body) {
12201
11714
  const { brokenFlow, hasBreak, hasContinue, ignore } = context;
@@ -12235,15 +11748,12 @@ class DoWhileStatement extends NodeBase {
12235
11748
  includeLoopBody(context, this.body, includeChildrenRecursively);
12236
11749
  }
12237
11750
  }
12238
- DoWhileStatement.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
12239
- DoWhileStatement.prototype.applyDeoptimizations = doNotDeoptimize;
12240
11751
 
12241
11752
  class EmptyStatement extends NodeBase {
12242
11753
  hasEffects() {
12243
11754
  return false;
12244
11755
  }
12245
11756
  }
12246
- EmptyStatement.prototype.includeNode = onlyIncludeSelf;
12247
11757
 
12248
11758
  class ExportAllDeclaration extends NodeBase {
12249
11759
  hasEffects() {
@@ -12256,10 +11766,9 @@ class ExportAllDeclaration extends NodeBase {
12256
11766
  render(code, _options, nodeRenderOptions) {
12257
11767
  code.remove(nodeRenderOptions.start, nodeRenderOptions.end);
12258
11768
  }
11769
+ applyDeoptimizations() { }
12259
11770
  }
12260
11771
  ExportAllDeclaration.prototype.needsBoundaries = true;
12261
- ExportAllDeclaration.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
12262
- ExportAllDeclaration.prototype.applyDeoptimizations = doNotDeoptimize;
12263
11772
 
12264
11773
  class ExportNamedDeclaration extends NodeBase {
12265
11774
  bind() {
@@ -12286,15 +11795,13 @@ class ExportNamedDeclaration extends NodeBase {
12286
11795
  this.declaration.render(code, options, { end, start });
12287
11796
  }
12288
11797
  }
11798
+ applyDeoptimizations() { }
12289
11799
  }
12290
11800
  ExportNamedDeclaration.prototype.needsBoundaries = true;
12291
- ExportNamedDeclaration.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
12292
- ExportNamedDeclaration.prototype.applyDeoptimizations = doNotDeoptimize;
12293
11801
 
12294
11802
  class ExportSpecifier extends NodeBase {
11803
+ applyDeoptimizations() { }
12295
11804
  }
12296
- ExportSpecifier.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
12297
- ExportSpecifier.prototype.applyDeoptimizations = doNotDeoptimize;
12298
11805
 
12299
11806
  class ForInStatement extends NodeBase {
12300
11807
  createScope(parentScope) {
@@ -12312,18 +11819,11 @@ class ForInStatement extends NodeBase {
12312
11819
  const { body, deoptimized, left, right } = this;
12313
11820
  if (!deoptimized)
12314
11821
  this.applyDeoptimizations();
12315
- if (!this.included)
12316
- this.includeNode(context);
11822
+ this.included = true;
12317
11823
  left.includeAsAssignmentTarget(context, includeChildrenRecursively || true, false);
12318
11824
  right.include(context, includeChildrenRecursively);
12319
11825
  includeLoopBody(context, body, includeChildrenRecursively);
12320
11826
  }
12321
- includeNode(context) {
12322
- this.included = true;
12323
- if (!this.deoptimized)
12324
- this.applyDeoptimizations();
12325
- this.right.includePath(UNKNOWN_PATH, context);
12326
- }
12327
11827
  initialise() {
12328
11828
  super.initialise();
12329
11829
  this.left.setAssignedValue(UNKNOWN_EXPRESSION);
@@ -12364,18 +11864,11 @@ class ForOfStatement extends NodeBase {
12364
11864
  const { body, deoptimized, left, right } = this;
12365
11865
  if (!deoptimized)
12366
11866
  this.applyDeoptimizations();
12367
- if (!this.included)
12368
- this.includeNode(context);
11867
+ this.included = true;
12369
11868
  left.includeAsAssignmentTarget(context, includeChildrenRecursively || true, false);
12370
11869
  right.include(context, includeChildrenRecursively);
12371
11870
  includeLoopBody(context, body, includeChildrenRecursively);
12372
11871
  }
12373
- includeNode(context) {
12374
- this.included = true;
12375
- if (!this.deoptimized)
12376
- this.applyDeoptimizations();
12377
- this.right.includePath(UNKNOWN_PATH, context);
12378
- }
12379
11872
  initialise() {
12380
11873
  super.initialise();
12381
11874
  this.left.setAssignedValue(UNKNOWN_EXPRESSION);
@@ -12411,9 +11904,7 @@ class ForStatement extends NodeBase {
12411
11904
  }
12412
11905
  include(context, includeChildrenRecursively) {
12413
11906
  this.included = true;
12414
- this.init?.include(context, includeChildrenRecursively, {
12415
- asSingleStatement: true
12416
- });
11907
+ this.init?.include(context, includeChildrenRecursively, { asSingleStatement: true });
12417
11908
  this.test?.include(context, includeChildrenRecursively);
12418
11909
  this.update?.include(context, includeChildrenRecursively);
12419
11910
  includeLoopBody(context, this.body, includeChildrenRecursively);
@@ -12425,8 +11916,6 @@ class ForStatement extends NodeBase {
12425
11916
  this.body.render(code, options);
12426
11917
  }
12427
11918
  }
12428
- ForStatement.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
12429
- ForStatement.prototype.applyDeoptimizations = doNotDeoptimize;
12430
11919
 
12431
11920
  class FunctionExpression extends FunctionNode {
12432
11921
  createScope(parentScope) {
@@ -12458,9 +11947,9 @@ class TrackingScope extends BlockScope {
12458
11947
  super(...arguments);
12459
11948
  this.hoistedDeclarations = [];
12460
11949
  }
12461
- addDeclaration(identifier, context, init, destructuredInitPath, kind) {
11950
+ addDeclaration(identifier, context, init, kind) {
12462
11951
  this.hoistedDeclarations.push(identifier);
12463
- return super.addDeclaration(identifier, context, init, destructuredInitPath, kind);
11952
+ return super.addDeclaration(identifier, context, init, kind);
12464
11953
  }
12465
11954
  }
12466
11955
 
@@ -12559,9 +12048,10 @@ class IfStatement extends NodeBase {
12559
12048
  }
12560
12049
  this.renderHoistedDeclarations(hoistedDeclarations, code, getPropertyAccess);
12561
12050
  }
12051
+ applyDeoptimizations() { }
12562
12052
  getTestValue() {
12563
12053
  if (this.testValue === unset) {
12564
- return (this.testValue = this.test.getLiteralValueAtPath(EMPTY_PATH, SHARED_RECURSION_TRACKER, this));
12054
+ return (this.testValue = tryCastLiteralValueToBoolean(this.test.getLiteralValueAtPath(EMPTY_PATH, SHARED_RECURSION_TRACKER, this)));
12565
12055
  }
12566
12056
  return this.testValue;
12567
12057
  }
@@ -12627,8 +12117,6 @@ class IfStatement extends NodeBase {
12627
12117
  return false;
12628
12118
  }
12629
12119
  }
12630
- IfStatement.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
12631
- IfStatement.prototype.applyDeoptimizations = doNotDeoptimize;
12632
12120
 
12633
12121
  class ImportAttribute extends NodeBase {
12634
12122
  }
@@ -12646,15 +12134,13 @@ class ImportDeclaration extends NodeBase {
12646
12134
  render(code, _options, nodeRenderOptions) {
12647
12135
  code.remove(nodeRenderOptions.start, nodeRenderOptions.end);
12648
12136
  }
12137
+ applyDeoptimizations() { }
12649
12138
  }
12650
12139
  ImportDeclaration.prototype.needsBoundaries = true;
12651
- ImportDeclaration.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
12652
- ImportDeclaration.prototype.applyDeoptimizations = doNotDeoptimize;
12653
12140
 
12654
12141
  class ImportDefaultSpecifier extends NodeBase {
12142
+ applyDeoptimizations() { }
12655
12143
  }
12656
- ImportDefaultSpecifier.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
12657
- ImportDefaultSpecifier.prototype.applyDeoptimizations = doNotDeoptimize;
12658
12144
 
12659
12145
  function isReassignedExportsMember(variable, exportNamesByVariable) {
12660
12146
  return (variable.renderBaseName !== null && exportNamesByVariable.has(variable) && variable.isReassigned);
@@ -12663,33 +12149,28 @@ function isReassignedExportsMember(variable, exportNamesByVariable) {
12663
12149
  class VariableDeclarator extends NodeBase {
12664
12150
  declareDeclarator(kind, isUsingDeclaration) {
12665
12151
  this.isUsingDeclaration = isUsingDeclaration;
12666
- this.id.declare(kind, EMPTY_PATH, this.init || UNDEFINED_EXPRESSION);
12152
+ this.id.declare(kind, this.init || UNDEFINED_EXPRESSION);
12667
12153
  }
12668
12154
  deoptimizePath(path) {
12669
12155
  this.id.deoptimizePath(path);
12670
12156
  }
12671
12157
  hasEffects(context) {
12158
+ if (!this.deoptimized)
12159
+ this.applyDeoptimizations();
12672
12160
  const initEffect = this.init?.hasEffects(context);
12673
12161
  this.id.markDeclarationReached();
12674
- return (initEffect ||
12675
- this.isUsingDeclaration ||
12676
- this.id.hasEffects(context) ||
12677
- (this.scope.context.options.treeshake
12678
- .propertyReadSideEffects &&
12679
- this.id.hasEffectsWhenDestructuring(context, EMPTY_PATH, this.init || UNDEFINED_EXPRESSION)));
12162
+ return initEffect || this.id.hasEffects(context) || this.isUsingDeclaration;
12680
12163
  }
12681
12164
  include(context, includeChildrenRecursively) {
12682
- const { id, init } = this;
12683
- if (!this.included)
12684
- this.includeNode();
12165
+ const { deoptimized, id, init } = this;
12166
+ if (!deoptimized)
12167
+ this.applyDeoptimizations();
12168
+ this.included = true;
12685
12169
  init?.include(context, includeChildrenRecursively);
12686
12170
  id.markDeclarationReached();
12687
- if (includeChildrenRecursively) {
12171
+ if (includeChildrenRecursively || id.shouldBeIncluded(context)) {
12688
12172
  id.include(context, includeChildrenRecursively);
12689
12173
  }
12690
- else {
12691
- id.includeDestructuredIfNecessary(context, EMPTY_PATH, init || UNDEFINED_EXPRESSION);
12692
- }
12693
12174
  }
12694
12175
  removeAnnotations(code) {
12695
12176
  this.init?.removeAnnotations(code);
@@ -12719,8 +12200,8 @@ class VariableDeclarator extends NodeBase {
12719
12200
  code.appendLeft(end, `${_}=${_}void 0`);
12720
12201
  }
12721
12202
  }
12722
- includeNode() {
12723
- this.included = true;
12203
+ applyDeoptimizations() {
12204
+ this.deoptimized = true;
12724
12205
  const { id, init } = this;
12725
12206
  if (init && id instanceof Identifier && init instanceof ClassExpression && !init.id) {
12726
12207
  const { name, variable } = id;
@@ -12732,14 +12213,11 @@ class VariableDeclarator extends NodeBase {
12732
12213
  }
12733
12214
  }
12734
12215
  }
12735
- VariableDeclarator.prototype.applyDeoptimizations = doNotDeoptimize;
12736
12216
 
12737
12217
  class ImportExpression extends NodeBase {
12738
12218
  constructor() {
12739
12219
  super(...arguments);
12740
12220
  this.inlineNamespace = null;
12741
- this.hasUnknownAccessedKey = false;
12742
- this.accessedPropKey = new Set();
12743
12221
  this.attributes = null;
12744
12222
  this.mechanism = null;
12745
12223
  this.namespaceExportName = undefined;
@@ -12772,15 +12250,12 @@ class ImportExpression extends NodeBase {
12772
12250
  if (parent2 instanceof ExpressionStatement) {
12773
12251
  return EMPTY_ARRAY;
12774
12252
  }
12775
- // Case 1: const { foo } / module = await import('bar')
12253
+ // Case 1: const { foo } = await import('bar')
12776
12254
  if (parent2 instanceof VariableDeclarator) {
12777
12255
  const declaration = parent2.id;
12778
- if (declaration instanceof Identifier) {
12779
- return this.hasUnknownAccessedKey ? undefined : [...this.accessedPropKey];
12780
- }
12781
- if (declaration instanceof ObjectPattern) {
12782
- return getDeterministicObjectDestructure(declaration);
12783
- }
12256
+ return declaration instanceof ObjectPattern
12257
+ ? getDeterministicObjectDestructure(declaration)
12258
+ : undefined;
12784
12259
  }
12785
12260
  // Case 2: (await import('bar')).foo
12786
12261
  if (parent2 instanceof MemberExpression) {
@@ -12830,29 +12305,12 @@ class ImportExpression extends NodeBase {
12830
12305
  return true;
12831
12306
  }
12832
12307
  include(context, includeChildrenRecursively) {
12833
- if (!this.included)
12834
- this.includeNode();
12835
- this.source.include(context, includeChildrenRecursively);
12836
- }
12837
- includeNode() {
12838
- this.included = true;
12839
- this.scope.context.includeDynamicImport(this);
12840
- this.scope.addAccessedDynamicImport(this);
12841
- }
12842
- includePath(path) {
12843
- if (!this.included)
12844
- this.includeNode();
12845
- // Technically, this is not correct as dynamic imports return a Promise.
12846
- if (this.hasUnknownAccessedKey)
12847
- return;
12848
- if (path[0] === UnknownKey) {
12849
- this.hasUnknownAccessedKey = true;
12850
- }
12851
- else if (typeof path[0] === 'string') {
12852
- this.accessedPropKey.add(path[0]);
12308
+ if (!this.included) {
12309
+ this.included = true;
12310
+ this.scope.context.includeDynamicImport(this);
12311
+ this.scope.addAccessedDynamicImport(this);
12853
12312
  }
12854
- // Update included paths
12855
- this.scope.context.includeDynamicImport(this);
12313
+ this.source.include(context, includeChildrenRecursively);
12856
12314
  }
12857
12315
  initialise() {
12858
12316
  super.initialise();
@@ -12922,6 +12380,7 @@ class ImportExpression extends NodeBase {
12922
12380
  setInternalResolution(inlineNamespace) {
12923
12381
  this.inlineNamespace = inlineNamespace;
12924
12382
  }
12383
+ applyDeoptimizations() { }
12925
12384
  getDynamicImportMechanismAndHelper(resolution, exportMode, { compact, dynamicImportInCjs, format, generatedCode: { arrowFunctions }, interop }, { _, getDirectReturnFunction, getDirectReturnIifeLeft }, pluginDriver) {
12926
12385
  const mechanism = pluginDriver.hookFirstSync('renderDynamicImport', [
12927
12386
  {
@@ -13011,7 +12470,6 @@ class ImportExpression extends NodeBase {
13011
12470
  return { helper: null, mechanism: null };
13012
12471
  }
13013
12472
  }
13014
- ImportExpression.prototype.applyDeoptimizations = doNotDeoptimize;
13015
12473
  function getInteropHelper(resolution, exportMode, interop) {
13016
12474
  return exportMode === 'external'
13017
12475
  ? namespaceInteropHelpersByInteropType[interop(resolution instanceof ExternalModule ? resolution.id : null)]
@@ -13035,14 +12493,12 @@ function getDeterministicObjectDestructure(objectPattern) {
13035
12493
  }
13036
12494
 
13037
12495
  class ImportNamespaceSpecifier extends NodeBase {
12496
+ applyDeoptimizations() { }
13038
12497
  }
13039
- ImportNamespaceSpecifier.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
13040
- ImportNamespaceSpecifier.prototype.applyDeoptimizations = doNotDeoptimize;
13041
12498
 
13042
12499
  class ImportSpecifier extends NodeBase {
12500
+ applyDeoptimizations() { }
13043
12501
  }
13044
- ImportSpecifier.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
13045
- ImportSpecifier.prototype.applyDeoptimizations = doNotDeoptimize;
13046
12502
 
13047
12503
  class JSXIdentifier extends IdentifierBase {
13048
12504
  constructor() {
@@ -13059,29 +12515,6 @@ class JSXIdentifier extends IdentifierBase {
13059
12515
  this.isNativeElement = true;
13060
12516
  }
13061
12517
  }
13062
- include(context) {
13063
- if (!this.included)
13064
- this.includeNode(context);
13065
- }
13066
- includeNode(context) {
13067
- this.included = true;
13068
- if (!this.deoptimized)
13069
- this.applyDeoptimizations();
13070
- if (this.variable !== null) {
13071
- this.scope.context.includeVariableInModule(this.variable, EMPTY_PATH, context);
13072
- }
13073
- }
13074
- includePath(path, context) {
13075
- if (!this.included) {
13076
- this.included = true;
13077
- if (this.variable !== null) {
13078
- this.scope.context.includeVariableInModule(this.variable, path, context);
13079
- }
13080
- }
13081
- else if (path.length > 0) {
13082
- this.variable?.includePath(path, context);
13083
- }
13084
- }
13085
12518
  render(code, { snippets: { getPropertyAccess }, useOriginalName }) {
13086
12519
  if (this.variable) {
13087
12520
  const name = this.variable.getName(getPropertyAccess, useOriginalName);
@@ -13143,7 +12576,6 @@ class JSXAttribute extends NodeBase {
13143
12576
  }
13144
12577
  }
13145
12578
  }
13146
- JSXAttribute.prototype.includeNode = onlyIncludeSelf;
13147
12579
 
13148
12580
  class JSXClosingBase extends NodeBase {
13149
12581
  render(code, options) {
@@ -13156,7 +12588,6 @@ class JSXClosingBase extends NodeBase {
13156
12588
  }
13157
12589
  }
13158
12590
  }
13159
- JSXClosingBase.prototype.includeNode = onlyIncludeSelf;
13160
12591
 
13161
12592
  class JSXClosingElement extends JSXClosingBase {
13162
12593
  }
@@ -13177,15 +12608,8 @@ class JSXSpreadAttribute extends NodeBase {
13177
12608
 
13178
12609
  class JSXEmptyExpression extends NodeBase {
13179
12610
  }
13180
- JSXEmptyExpression.prototype.includeNode = onlyIncludeSelf;
13181
12611
 
13182
12612
  class JSXExpressionContainer extends NodeBase {
13183
- includeNode(context) {
13184
- this.included = true;
13185
- if (!this.deoptimized)
13186
- this.applyDeoptimizations();
13187
- this.expression.includePath(UNKNOWN_PATH, context);
13188
- }
13189
12613
  render(code, options) {
13190
12614
  const { mode } = this.scope.context.options.jsx;
13191
12615
  if (mode !== 'preserve') {
@@ -13206,7 +12630,7 @@ function getRenderedJsxChildren(children) {
13206
12630
  return renderedChildren;
13207
12631
  }
13208
12632
 
13209
- function getAndIncludeFactoryVariable(factory, preserve, importSource, node, context) {
12633
+ function getAndIncludeFactoryVariable(factory, preserve, importSource, node) {
13210
12634
  const [baseName, nestedName] = factory.split('.');
13211
12635
  let factoryVariable;
13212
12636
  if (importSource) {
@@ -13214,7 +12638,7 @@ function getAndIncludeFactoryVariable(factory, preserve, importSource, node, con
13214
12638
  if (preserve) {
13215
12639
  // This pretends we are accessing an included global variable of the same name
13216
12640
  const globalVariable = node.scope.findGlobal(baseName);
13217
- globalVariable.includePath(UNKNOWN_PATH, context);
12641
+ globalVariable.include();
13218
12642
  // This excludes this variable from renaming
13219
12643
  factoryVariable.globalName = baseName;
13220
12644
  }
@@ -13222,7 +12646,7 @@ function getAndIncludeFactoryVariable(factory, preserve, importSource, node, con
13222
12646
  else {
13223
12647
  factoryVariable = node.scope.findGlobal(baseName);
13224
12648
  }
13225
- node.scope.context.includeVariableInModule(factoryVariable, UNKNOWN_PATH, context);
12649
+ node.scope.context.includeVariableInModule(factoryVariable);
13226
12650
  if (factoryVariable instanceof LocalVariable) {
13227
12651
  factoryVariable.consolidateInitializers();
13228
12652
  factoryVariable.addUsedPlace(node);
@@ -13245,20 +12669,16 @@ class JSXElementBase extends NodeBase {
13245
12669
  }
13246
12670
  }
13247
12671
  include(context, includeChildrenRecursively) {
13248
- if (!this.included)
13249
- this.includeNode(context);
13250
- for (const child of this.children) {
13251
- child.include(context, includeChildrenRecursively);
13252
- }
13253
- }
13254
- includeNode(context) {
13255
- this.included = true;
13256
- const { factory, importSource, mode } = this.jsxMode;
13257
- if (factory) {
13258
- this.factory = factory;
13259
- this.factoryVariable = getAndIncludeFactoryVariable(factory, mode === 'preserve', importSource, this, context);
12672
+ if (!this.included) {
12673
+ const { factory, importSource, mode } = this.jsxMode;
12674
+ if (factory) {
12675
+ this.factory = factory;
12676
+ this.factoryVariable = getAndIncludeFactoryVariable(factory, mode === 'preserve', importSource, this);
12677
+ }
13260
12678
  }
12679
+ super.include(context, includeChildrenRecursively);
13261
12680
  }
12681
+ applyDeoptimizations() { }
13262
12682
  getRenderingMode() {
13263
12683
  const jsx = this.scope.context.options.jsx;
13264
12684
  const { mode, factory, importSource } = jsx;
@@ -13296,14 +12716,8 @@ class JSXElementBase extends NodeBase {
13296
12716
  return { childrenEnd, firstChild, hasMultipleChildren };
13297
12717
  }
13298
12718
  }
13299
- JSXElementBase.prototype.applyDeoptimizations = doNotDeoptimize;
13300
12719
 
13301
12720
  class JSXElement extends JSXElementBase {
13302
- include(context, includeChildrenRecursively) {
13303
- super.include(context, includeChildrenRecursively);
13304
- this.openingElement.include(context, includeChildrenRecursively);
13305
- this.closingElement?.include(context, includeChildrenRecursively);
13306
- }
13307
12721
  render(code, options) {
13308
12722
  switch (this.jsxMode.mode) {
13309
12723
  case 'classic': {
@@ -13455,11 +12869,6 @@ class JSXElement extends JSXElementBase {
13455
12869
  }
13456
12870
 
13457
12871
  class JSXFragment extends JSXElementBase {
13458
- include(context, includeChildrenRecursively) {
13459
- super.include(context, includeChildrenRecursively);
13460
- this.openingFragment.include(context, includeChildrenRecursively);
13461
- this.closingFragment.include(context, includeChildrenRecursively);
13462
- }
13463
12872
  render(code, options) {
13464
12873
  switch (this.jsxMode.mode) {
13465
12874
  case 'classic': {
@@ -13509,22 +12918,10 @@ class JSXFragment extends JSXElementBase {
13509
12918
  }
13510
12919
 
13511
12920
  class JSXMemberExpression extends NodeBase {
13512
- includeNode(context) {
13513
- this.included = true;
13514
- if (!this.deoptimized)
13515
- this.applyDeoptimizations();
13516
- this.object.includePath([this.property.name], context);
13517
- }
13518
- includePath(path, context) {
13519
- if (!this.included)
13520
- this.includeNode(context);
13521
- this.object.includePath([this.property.name, ...path], context);
13522
- }
13523
12921
  }
13524
12922
 
13525
12923
  class JSXNamespacedName extends NodeBase {
13526
12924
  }
13527
- JSXNamespacedName.prototype.includeNode = onlyIncludeSelf;
13528
12925
 
13529
12926
  class JSXOpeningElement extends NodeBase {
13530
12927
  render(code, options, { jsxMode = this.scope.context.options.jsx.mode } = {}) {
@@ -13534,7 +12931,6 @@ class JSXOpeningElement extends NodeBase {
13534
12931
  }
13535
12932
  }
13536
12933
  }
13537
- JSXOpeningElement.prototype.includeNode = onlyIncludeSelf;
13538
12934
 
13539
12935
  class JSXOpeningFragment extends NodeBase {
13540
12936
  constructor() {
@@ -13542,22 +12938,22 @@ class JSXOpeningFragment extends NodeBase {
13542
12938
  this.fragment = null;
13543
12939
  this.fragmentVariable = null;
13544
12940
  }
13545
- includeNode(context) {
13546
- this.included = true;
13547
- if (!this.deoptimized)
13548
- this.applyDeoptimizations();
13549
- const jsx = this.scope.context.options.jsx;
13550
- if (jsx.mode === 'automatic') {
13551
- this.fragment = 'Fragment';
13552
- this.fragmentVariable = getAndIncludeFactoryVariable('Fragment', false, jsx.jsxImportSource, this, context);
13553
- }
13554
- else {
13555
- const { fragment, importSource, mode } = jsx;
13556
- if (fragment != null) {
13557
- this.fragment = fragment;
13558
- this.fragmentVariable = getAndIncludeFactoryVariable(fragment, mode === 'preserve', importSource, this, context);
12941
+ include(context, includeChildrenRecursively) {
12942
+ if (!this.included) {
12943
+ const jsx = this.scope.context.options.jsx;
12944
+ if (jsx.mode === 'automatic') {
12945
+ this.fragment = 'Fragment';
12946
+ this.fragmentVariable = getAndIncludeFactoryVariable('Fragment', false, jsx.jsxImportSource, this);
12947
+ }
12948
+ else {
12949
+ const { fragment, importSource, mode } = jsx;
12950
+ if (fragment != null) {
12951
+ this.fragment = fragment;
12952
+ this.fragmentVariable = getAndIncludeFactoryVariable(fragment, mode === 'preserve', importSource, this);
12953
+ }
13559
12954
  }
13560
12955
  }
12956
+ super.include(context, includeChildrenRecursively);
13561
12957
  }
13562
12958
  render(code, options) {
13563
12959
  const { mode } = this.scope.context.options.jsx;
@@ -13594,7 +12990,6 @@ class JSXText extends NodeBase {
13594
12990
  }
13595
12991
  }
13596
12992
  }
13597
- JSXText.prototype.includeNode = onlyIncludeSelf;
13598
12993
 
13599
12994
  class LabeledStatement extends NodeBase {
13600
12995
  hasEffects(context) {
@@ -13616,22 +13011,17 @@ class LabeledStatement extends NodeBase {
13616
13011
  return bodyHasEffects;
13617
13012
  }
13618
13013
  include(context, includeChildrenRecursively) {
13619
- if (!this.included)
13620
- this.includeNode(context);
13014
+ this.included = true;
13621
13015
  const { brokenFlow, includedLabels } = context;
13622
13016
  context.includedLabels = new Set();
13623
13017
  this.body.include(context, includeChildrenRecursively);
13624
13018
  if (includeChildrenRecursively || context.includedLabels.has(this.label.name)) {
13625
- this.label.include(context);
13019
+ this.label.include();
13626
13020
  context.includedLabels.delete(this.label.name);
13627
13021
  context.brokenFlow = brokenFlow;
13628
13022
  }
13629
13023
  context.includedLabels = new Set([...includedLabels, ...context.includedLabels]);
13630
13024
  }
13631
- includeNode(context) {
13632
- this.included = true;
13633
- this.body.includePath(UNKNOWN_PATH, context);
13634
- }
13635
13025
  render(code, options) {
13636
13026
  if (this.label.included) {
13637
13027
  this.label.render(code, options);
@@ -13642,7 +13032,6 @@ class LabeledStatement extends NodeBase {
13642
13032
  this.body.render(code, options);
13643
13033
  }
13644
13034
  }
13645
- LabeledStatement.prototype.applyDeoptimizations = doNotDeoptimize;
13646
13035
 
13647
13036
  class LogicalExpression extends NodeBase {
13648
13037
  constructor() {
@@ -13667,10 +13056,6 @@ class LogicalExpression extends NodeBase {
13667
13056
  const unusedBranch = this.usedBranch === this.left ? this.right : this.left;
13668
13057
  this.usedBranch = null;
13669
13058
  unusedBranch.deoptimizePath(UNKNOWN_PATH);
13670
- if (this.included) {
13671
- // As we are not tracking inclusions, we just include everything
13672
- unusedBranch.includePath(UNKNOWN_PATH, createInclusionContext());
13673
- }
13674
13059
  const { scope: { context }, expressionsToBeDeoptimized } = this;
13675
13060
  this.expressionsToBeDeoptimized = EMPTY_ARRAY;
13676
13061
  for (const expression of expressionsToBeDeoptimized) {
@@ -13697,21 +13082,33 @@ class LogicalExpression extends NodeBase {
13697
13082
  this.expressionsToBeDeoptimized.push(origin);
13698
13083
  return usedBranch.getLiteralValueAtPath(path, recursionTracker, origin);
13699
13084
  }
13085
+ else {
13086
+ const rightValue = this.right.getLiteralValueAtPath(path, recursionTracker, origin);
13087
+ const booleanOrUnknown = tryCastLiteralValueToBoolean(rightValue);
13088
+ if (typeof booleanOrUnknown !== 'symbol') {
13089
+ if (!booleanOrUnknown && this.operator === '&&') {
13090
+ this.expressionsToBeDeoptimized.push(origin);
13091
+ return UnknownFalsyValue;
13092
+ }
13093
+ if (booleanOrUnknown && this.operator === '||') {
13094
+ return UnknownTruthyValue;
13095
+ }
13096
+ }
13097
+ }
13700
13098
  return UnknownValue;
13701
13099
  }
13702
13100
  getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin) {
13703
13101
  const usedBranch = this.getUsedBranch();
13704
- if (usedBranch) {
13705
- this.expressionsToBeDeoptimized.push(origin);
13706
- return usedBranch.getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin);
13707
- }
13708
- return [
13709
- new MultiExpression([
13710
- this.left.getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin)[0],
13711
- this.right.getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin)[0]
13712
- ]),
13713
- false
13714
- ];
13102
+ if (!usedBranch)
13103
+ return [
13104
+ new MultiExpression([
13105
+ this.left.getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin)[0],
13106
+ this.right.getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin)[0]
13107
+ ]),
13108
+ false
13109
+ ];
13110
+ this.expressionsToBeDeoptimized.push(origin);
13111
+ return usedBranch.getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin);
13715
13112
  }
13716
13113
  hasEffects(context) {
13717
13114
  if (this.left.hasEffects(context)) {
@@ -13724,18 +13121,18 @@ class LogicalExpression extends NodeBase {
13724
13121
  }
13725
13122
  hasEffectsOnInteractionAtPath(path, interaction, context) {
13726
13123
  const usedBranch = this.getUsedBranch();
13727
- if (usedBranch) {
13728
- return usedBranch.hasEffectsOnInteractionAtPath(path, interaction, context);
13124
+ if (!usedBranch) {
13125
+ return (this.left.hasEffectsOnInteractionAtPath(path, interaction, context) ||
13126
+ this.right.hasEffectsOnInteractionAtPath(path, interaction, context));
13729
13127
  }
13730
- return (this.left.hasEffectsOnInteractionAtPath(path, interaction, context) ||
13731
- this.right.hasEffectsOnInteractionAtPath(path, interaction, context));
13128
+ return usedBranch.hasEffectsOnInteractionAtPath(path, interaction, context);
13732
13129
  }
13733
13130
  include(context, includeChildrenRecursively) {
13734
13131
  this.included = true;
13735
13132
  const usedBranch = this.getUsedBranch();
13736
13133
  if (includeChildrenRecursively ||
13737
- !usedBranch ||
13738
- (usedBranch === this.right && this.left.shouldBeIncluded(context))) {
13134
+ (usedBranch === this.right && this.left.shouldBeIncluded(context)) ||
13135
+ !usedBranch) {
13739
13136
  this.left.include(context, includeChildrenRecursively);
13740
13137
  this.right.include(context, includeChildrenRecursively);
13741
13138
  }
@@ -13743,17 +13140,6 @@ class LogicalExpression extends NodeBase {
13743
13140
  usedBranch.include(context, includeChildrenRecursively);
13744
13141
  }
13745
13142
  }
13746
- includePath(path, context) {
13747
- this.included = true;
13748
- const usedBranch = this.getUsedBranch();
13749
- if (!usedBranch || (usedBranch === this.right && this.left.shouldBeIncluded(context))) {
13750
- this.left.includePath(path, context);
13751
- this.right.includePath(path, context);
13752
- }
13753
- else {
13754
- usedBranch.includePath(path, context);
13755
- }
13756
- }
13757
13143
  removeAnnotations(code) {
13758
13144
  this.left.removeAnnotations(code);
13759
13145
  }
@@ -13790,13 +13176,14 @@ class LogicalExpression extends NodeBase {
13790
13176
  if (!this.isBranchResolutionAnalysed) {
13791
13177
  this.isBranchResolutionAnalysed = true;
13792
13178
  const leftValue = this.left.getLiteralValueAtPath(EMPTY_PATH, SHARED_RECURSION_TRACKER, this);
13793
- if (typeof leftValue === 'symbol') {
13179
+ const booleanOrUnknown = tryCastLiteralValueToBoolean(leftValue);
13180
+ if (typeof booleanOrUnknown === 'symbol') {
13794
13181
  return null;
13795
13182
  }
13796
13183
  else {
13797
13184
  this.usedBranch =
13798
- (this.operator === '||' && leftValue) ||
13799
- (this.operator === '&&' && !leftValue) ||
13185
+ (this.operator === '||' && booleanOrUnknown) ||
13186
+ (this.operator === '&&' && !booleanOrUnknown) ||
13800
13187
  (this.operator === '??' && leftValue != null)
13801
13188
  ? this.left
13802
13189
  : this.right;
@@ -13805,8 +13192,6 @@ class LogicalExpression extends NodeBase {
13805
13192
  return this.usedBranch;
13806
13193
  }
13807
13194
  }
13808
- LogicalExpression.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
13809
- LogicalExpression.prototype.applyDeoptimizations = doNotDeoptimize;
13810
13195
 
13811
13196
  class NewExpression extends NodeBase {
13812
13197
  hasEffects(context) {
@@ -13826,21 +13211,16 @@ class NewExpression extends NodeBase {
13826
13211
  return path.length > 0 || type !== INTERACTION_ACCESSED;
13827
13212
  }
13828
13213
  include(context, includeChildrenRecursively) {
13214
+ if (!this.deoptimized)
13215
+ this.applyDeoptimizations();
13829
13216
  if (includeChildrenRecursively) {
13830
13217
  super.include(context, includeChildrenRecursively);
13831
13218
  }
13832
13219
  else {
13833
- if (!this.included)
13834
- this.includeNode(context);
13220
+ this.included = true;
13835
13221
  this.callee.include(context, false);
13836
13222
  }
13837
- this.callee.includeCallArguments(context, this.interaction);
13838
- }
13839
- includeNode(context) {
13840
- this.included = true;
13841
- if (!this.deoptimized)
13842
- this.applyDeoptimizations();
13843
- this.callee.includePath(UNKNOWN_PATH, context);
13223
+ this.callee.includeCallArguments(context, this.arguments);
13844
13224
  }
13845
13225
  initialise() {
13846
13226
  super.initialise();
@@ -13869,7 +13249,6 @@ class ObjectExpression extends NodeBase {
13869
13249
  constructor() {
13870
13250
  super(...arguments);
13871
13251
  this.objectEntity = null;
13872
- this.protoProp = null;
13873
13252
  }
13874
13253
  deoptimizeArgumentsOnInteractionAtPath(interaction, path, recursionTracker) {
13875
13254
  this.getObjectEntity().deoptimizeArgumentsOnInteractionAtPath(interaction, path, recursionTracker);
@@ -13889,43 +13268,15 @@ class ObjectExpression extends NodeBase {
13889
13268
  hasEffectsOnInteractionAtPath(path, interaction, context) {
13890
13269
  return this.getObjectEntity().hasEffectsOnInteractionAtPath(path, interaction, context);
13891
13270
  }
13892
- include(context, includeChildrenRecursively) {
13893
- if (!this.included)
13894
- this.includeNode(context);
13895
- this.getObjectEntity().include(context, includeChildrenRecursively);
13896
- this.protoProp?.include(context, includeChildrenRecursively);
13897
- }
13898
- includeNode(context) {
13899
- this.included = true;
13900
- this.protoProp?.includePath(UNKNOWN_PATH, context);
13901
- }
13902
- includePath(path, context) {
13903
- if (!this.included)
13904
- this.includeNode(context);
13905
- this.getObjectEntity().includePath(path, context);
13906
- }
13907
13271
  render(code, options, { renderedSurroundingElement } = BLANK) {
13272
+ super.render(code, options);
13908
13273
  if (renderedSurroundingElement === ExpressionStatement$1 ||
13909
13274
  renderedSurroundingElement === ArrowFunctionExpression$1) {
13910
13275
  code.appendRight(this.start, '(');
13911
13276
  code.prependLeft(this.end, ')');
13912
13277
  }
13913
- if (this.properties.length > 0) {
13914
- const separatedNodes = getCommaSeparatedNodesWithBoundaries(this.properties, code, this.start + 1, this.end - 1);
13915
- let lastSeparatorPos = null;
13916
- for (const { node, separator, start, end } of separatedNodes) {
13917
- if (!node.included) {
13918
- treeshakeNode(node, code, start, end);
13919
- continue;
13920
- }
13921
- lastSeparatorPos = separator;
13922
- node.render(code, options);
13923
- }
13924
- if (lastSeparatorPos) {
13925
- code.remove(lastSeparatorPos, this.end - 1);
13926
- }
13927
- }
13928
13278
  }
13279
+ applyDeoptimizations() { }
13929
13280
  getObjectEntity() {
13930
13281
  if (this.objectEntity !== null) {
13931
13282
  return this.objectEntity;
@@ -13954,7 +13305,6 @@ class ObjectExpression extends NodeBase {
13954
13305
  ? property.key.name
13955
13306
  : String(property.key.value);
13956
13307
  if (key === '__proto__' && property.kind === 'init') {
13957
- this.protoProp = property;
13958
13308
  prototype =
13959
13309
  property.value instanceof Literal && property.value.value === null
13960
13310
  ? null
@@ -13967,7 +13317,6 @@ class ObjectExpression extends NodeBase {
13967
13317
  return (this.objectEntity = new ObjectEntity(properties, prototype));
13968
13318
  }
13969
13319
  }
13970
- ObjectExpression.prototype.applyDeoptimizations = doNotDeoptimize;
13971
13320
 
13972
13321
  class PanicError extends NodeBase {
13973
13322
  initialise() {
@@ -13994,7 +13343,6 @@ class ParseError extends NodeBase {
13994
13343
 
13995
13344
  class PrivateIdentifier extends NodeBase {
13996
13345
  }
13997
- PrivateIdentifier.prototype.includeNode = onlyIncludeSelf;
13998
13346
 
13999
13347
  class Program extends NodeBase {
14000
13348
  constructor() {
@@ -14062,11 +13410,14 @@ class Program extends NodeBase {
14062
13410
  super.render(code, options);
14063
13411
  }
14064
13412
  }
13413
+ applyDeoptimizations() { }
14065
13414
  }
14066
- Program.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
14067
- Program.prototype.applyDeoptimizations = doNotDeoptimize;
14068
13415
 
14069
13416
  class Property extends MethodBase {
13417
+ constructor() {
13418
+ super(...arguments);
13419
+ this.declarationInit = null;
13420
+ }
14070
13421
  //declare method: boolean;
14071
13422
  get method() {
14072
13423
  return isFlagSet(this.flags, 262144 /* Flag.method */);
@@ -14081,41 +13432,17 @@ class Property extends MethodBase {
14081
13432
  set shorthand(value) {
14082
13433
  this.flags = setFlag(this.flags, 524288 /* Flag.shorthand */, value);
14083
13434
  }
14084
- declare(kind, destructuredInitPath, init) {
14085
- return this.value.declare(kind, this.getPathInProperty(destructuredInitPath), init);
14086
- }
14087
- deoptimizeAssignment(destructuredInitPath, init) {
14088
- this.value.deoptimizeAssignment?.(this.getPathInProperty(destructuredInitPath), init);
13435
+ declare(kind, init) {
13436
+ this.declarationInit = init;
13437
+ return this.value.declare(kind, UNKNOWN_EXPRESSION);
14089
13438
  }
14090
13439
  hasEffects(context) {
14091
- return this.key.hasEffects(context) || this.value.hasEffects(context);
14092
- }
14093
- hasEffectsWhenDestructuring(context, destructuredInitPath, init) {
14094
- return this.value.hasEffectsWhenDestructuring?.(context, this.getPathInProperty(destructuredInitPath), init);
14095
- }
14096
- includeDestructuredIfNecessary(context, destructuredInitPath, init) {
14097
- const path = this.getPathInProperty(destructuredInitPath);
14098
- let included = this.value.includeDestructuredIfNecessary(context, path, init) ||
14099
- this.included;
14100
- if ((included ||= this.key.hasEffects(createHasEffectsContext()))) {
14101
- this.key.include(context, false);
14102
- if (!this.value.included) {
14103
- this.value.included = true;
14104
- // Unfortunately, we need to include the value again now, so that any
14105
- // declared variables are properly included.
14106
- this.value.includeDestructuredIfNecessary(context, path, init);
14107
- }
14108
- }
14109
- return (this.included = included);
14110
- }
14111
- include(context, includeChildrenRecursively) {
14112
- this.included = true;
14113
- this.key.include(context, includeChildrenRecursively);
14114
- this.value.include(context, includeChildrenRecursively);
14115
- }
14116
- includePath(path, context) {
14117
- this.included = true;
14118
- this.value.includePath(path, context);
13440
+ if (!this.deoptimized)
13441
+ this.applyDeoptimizations();
13442
+ const propertyReadSideEffects = this.scope.context.options.treeshake.propertyReadSideEffects;
13443
+ return ((this.parent.type === 'ObjectPattern' && propertyReadSideEffects === 'always') ||
13444
+ this.key.hasEffects(context) ||
13445
+ this.value.hasEffects(context));
14119
13446
  }
14120
13447
  markDeclarationReached() {
14121
13448
  this.value.markDeclarationReached();
@@ -14126,20 +13453,14 @@ class Property extends MethodBase {
14126
13453
  }
14127
13454
  this.value.render(code, options, { isShorthandProperty: this.shorthand });
14128
13455
  }
14129
- getPathInProperty(destructuredInitPath) {
14130
- return destructuredInitPath.at(-1) === UnknownKey
14131
- ? destructuredInitPath
14132
- : // For now, we only consider static paths as we do not know how to
14133
- // deoptimize the path in the dynamic case.
14134
- this.computed
14135
- ? [...destructuredInitPath, UnknownKey]
14136
- : this.key instanceof Identifier
14137
- ? [...destructuredInitPath, this.key.name]
14138
- : [...destructuredInitPath, String(this.key.value)];
13456
+ applyDeoptimizations() {
13457
+ this.deoptimized = true;
13458
+ if (this.declarationInit !== null) {
13459
+ this.declarationInit.deoptimizePath([UnknownKey, UnknownKey]);
13460
+ this.scope.context.requestTreeshakingPass();
13461
+ }
14139
13462
  }
14140
13463
  }
14141
- Property.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
14142
- Property.prototype.applyDeoptimizations = doNotDeoptimize;
14143
13464
 
14144
13465
  class PropertyDefinition extends NodeBase {
14145
13466
  get computed() {
@@ -14172,15 +13493,8 @@ class PropertyDefinition extends NodeBase {
14172
13493
  hasEffectsOnInteractionAtPath(path, interaction, context) {
14173
13494
  return !this.value || this.value.hasEffectsOnInteractionAtPath(path, interaction, context);
14174
13495
  }
14175
- includeNode(context) {
14176
- this.included = true;
14177
- this.value?.includePath(UNKNOWN_PATH, context);
14178
- for (const decorator of this.decorators) {
14179
- decorator.includePath(UNKNOWN_PATH, context);
14180
- }
14181
- }
13496
+ applyDeoptimizations() { }
14182
13497
  }
14183
- PropertyDefinition.prototype.applyDeoptimizations = doNotDeoptimize;
14184
13498
 
14185
13499
  class ReturnStatement extends NodeBase {
14186
13500
  hasEffects(context) {
@@ -14190,15 +13504,10 @@ class ReturnStatement extends NodeBase {
14190
13504
  return false;
14191
13505
  }
14192
13506
  include(context, includeChildrenRecursively) {
14193
- if (!this.included)
14194
- this.includeNode(context);
13507
+ this.included = true;
14195
13508
  this.argument?.include(context, includeChildrenRecursively);
14196
13509
  context.brokenFlow = true;
14197
13510
  }
14198
- includeNode(context) {
14199
- this.included = true;
14200
- this.argument?.includePath(UNKNOWN_PATH, context);
14201
- }
14202
13511
  initialise() {
14203
13512
  super.initialise();
14204
13513
  this.scope.addReturnExpression(this.argument || UNKNOWN_EXPRESSION);
@@ -14212,7 +13521,6 @@ class ReturnStatement extends NodeBase {
14212
13521
  }
14213
13522
  }
14214
13523
  }
14215
- ReturnStatement.prototype.applyDeoptimizations = doNotDeoptimize;
14216
13524
 
14217
13525
  class SequenceExpression extends NodeBase {
14218
13526
  deoptimizeArgumentsOnInteractionAtPath(interaction, path, recursionTracker) {
@@ -14240,15 +13548,10 @@ class SequenceExpression extends NodeBase {
14240
13548
  for (const expression of this.expressions) {
14241
13549
  if (includeChildrenRecursively ||
14242
13550
  (expression === lastExpression && !(this.parent instanceof ExpressionStatement)) ||
14243
- expression.shouldBeIncluded(context)) {
13551
+ expression.shouldBeIncluded(context))
14244
13552
  expression.include(context, includeChildrenRecursively);
14245
- }
14246
13553
  }
14247
13554
  }
14248
- includePath(path, context) {
14249
- this.included = true;
14250
- this.expressions[this.expressions.length - 1].includePath(path, context);
14251
- }
14252
13555
  removeAnnotations(code) {
14253
13556
  this.expressions[0].removeAnnotations(code);
14254
13557
  }
@@ -14283,8 +13586,6 @@ class SequenceExpression extends NodeBase {
14283
13586
  }
14284
13587
  }
14285
13588
  }
14286
- SequenceExpression.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
14287
- SequenceExpression.prototype.applyDeoptimizations = doNotDeoptimize;
14288
13589
 
14289
13590
  class Super extends NodeBase {
14290
13591
  bind() {
@@ -14296,15 +13597,11 @@ class Super extends NodeBase {
14296
13597
  deoptimizePath(path) {
14297
13598
  this.variable.deoptimizePath(path);
14298
13599
  }
14299
- include(context) {
14300
- if (!this.included)
14301
- this.includeNode(context);
14302
- }
14303
- includeNode(context) {
14304
- this.included = true;
14305
- if (!this.deoptimized)
14306
- this.applyDeoptimizations();
14307
- this.scope.context.includeVariableInModule(this.variable, EMPTY_PATH, context);
13600
+ include() {
13601
+ if (!this.included) {
13602
+ this.included = true;
13603
+ this.scope.context.includeVariableInModule(this.variable);
13604
+ }
14308
13605
  }
14309
13606
  }
14310
13607
 
@@ -14345,8 +13642,6 @@ class SwitchCase extends NodeBase {
14345
13642
  }
14346
13643
  }
14347
13644
  SwitchCase.prototype.needsBoundaries = true;
14348
- SwitchCase.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
14349
- SwitchCase.prototype.applyDeoptimizations = doNotDeoptimize;
14350
13645
 
14351
13646
  class SwitchStatement extends NodeBase {
14352
13647
  createScope(parentScope) {
@@ -14429,8 +13724,6 @@ class SwitchStatement extends NodeBase {
14429
13724
  }
14430
13725
  }
14431
13726
  }
14432
- SwitchStatement.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
14433
- SwitchStatement.prototype.applyDeoptimizations = doNotDeoptimize;
14434
13727
 
14435
13728
  class TaggedTemplateExpression extends CallExpressionBase {
14436
13729
  bind() {
@@ -14454,8 +13747,8 @@ class TaggedTemplateExpression extends CallExpressionBase {
14454
13747
  this.tag.hasEffectsOnInteractionAtPath(EMPTY_PATH, this.interaction, context));
14455
13748
  }
14456
13749
  include(context, includeChildrenRecursively) {
14457
- if (!this.included)
14458
- this.includeNode(context);
13750
+ if (!this.deoptimized)
13751
+ this.applyDeoptimizations();
14459
13752
  if (includeChildrenRecursively) {
14460
13753
  super.include(context, includeChildrenRecursively);
14461
13754
  }
@@ -14464,7 +13757,7 @@ class TaggedTemplateExpression extends CallExpressionBase {
14464
13757
  this.tag.include(context, includeChildrenRecursively);
14465
13758
  this.quasi.include(context, includeChildrenRecursively);
14466
13759
  }
14467
- this.tag.includeCallArguments(context, this.interaction);
13760
+ this.tag.includeCallArguments(context, this.args);
14468
13761
  const [returnExpression] = this.getReturnExpression();
14469
13762
  if (!returnExpression.included) {
14470
13763
  returnExpression.include(context, false);
@@ -14499,7 +13792,6 @@ class TaggedTemplateExpression extends CallExpressionBase {
14499
13792
  return this.returnExpression;
14500
13793
  }
14501
13794
  }
14502
- TaggedTemplateExpression.prototype.includeNode = onlyIncludeSelf;
14503
13795
 
14504
13796
  class TemplateElement extends NodeBase {
14505
13797
  get tail() {
@@ -14513,13 +13805,15 @@ class TemplateElement extends NodeBase {
14513
13805
  hasEffects() {
14514
13806
  return false;
14515
13807
  }
13808
+ include() {
13809
+ this.included = true;
13810
+ }
14516
13811
  parseNode(esTreeNode) {
14517
13812
  this.value = esTreeNode.value;
14518
13813
  return super.parseNode(esTreeNode);
14519
13814
  }
14520
13815
  render() { }
14521
13816
  }
14522
- TemplateElement.prototype.includeNode = onlyIncludeSelf;
14523
13817
 
14524
13818
  class TemplateLiteral extends NodeBase {
14525
13819
  deoptimizeArgumentsOnInteractionAtPath() { }
@@ -14544,14 +13838,6 @@ class TemplateLiteral extends NodeBase {
14544
13838
  }
14545
13839
  return true;
14546
13840
  }
14547
- includeNode(context) {
14548
- this.included = true;
14549
- if (!this.deoptimized)
14550
- this.applyDeoptimizations();
14551
- for (const node of this.expressions) {
14552
- node.includePath(UNKNOWN_PATH, context);
14553
- }
14554
- }
14555
13841
  render(code, options) {
14556
13842
  code.indentExclusionRanges.push([this.start, this.end]);
14557
13843
  super.render(code, options);
@@ -14561,13 +13847,13 @@ class TemplateLiteral extends NodeBase {
14561
13847
  class ModuleScope extends ChildScope {
14562
13848
  constructor(parent, context) {
14563
13849
  super(parent, context);
14564
- this.variables.set('this', new LocalVariable('this', null, UNDEFINED_EXPRESSION, EMPTY_PATH, context, 'other'));
13850
+ this.variables.set('this', new LocalVariable('this', null, UNDEFINED_EXPRESSION, context, 'other'));
14565
13851
  }
14566
- addDeclaration(identifier, context, init, destructuredInitPath, kind) {
13852
+ addDeclaration(identifier, context, init, kind) {
14567
13853
  if (this.context.module.importDescriptions.has(identifier.name)) {
14568
13854
  context.error(logRedeclarationError(identifier.name), identifier.start);
14569
13855
  }
14570
- return super.addDeclaration(identifier, context, init, destructuredInitPath, kind);
13856
+ return super.addDeclaration(identifier, context, init, kind);
14571
13857
  }
14572
13858
  addExportDefaultDeclaration(name, exportDefaultDeclaration, context) {
14573
13859
  const variable = new ExportDefaultVariable(name, exportDefaultDeclaration, context);
@@ -14612,23 +13898,10 @@ class ThisExpression extends NodeBase {
14612
13898
  }
14613
13899
  return this.variable.hasEffectsOnInteractionAtPath(path, interaction, context);
14614
13900
  }
14615
- include(context) {
14616
- if (!this.included)
14617
- this.includeNode(context);
14618
- }
14619
- includeNode(context) {
14620
- this.included = true;
14621
- if (!this.deoptimized)
14622
- this.applyDeoptimizations();
14623
- this.scope.context.includeVariableInModule(this.variable, EMPTY_PATH, context);
14624
- }
14625
- includePath(path, context) {
13901
+ include() {
14626
13902
  if (!this.included) {
14627
13903
  this.included = true;
14628
- this.scope.context.includeVariableInModule(this.variable, path, context);
14629
- }
14630
- else if (path.length > 0) {
14631
- this.variable.includePath(path, context);
13904
+ this.scope.context.includeVariableInModule(this.variable);
14632
13905
  }
14633
13906
  }
14634
13907
  initialise() {
@@ -14656,8 +13929,7 @@ class ThrowStatement extends NodeBase {
14656
13929
  return true;
14657
13930
  }
14658
13931
  include(context, includeChildrenRecursively) {
14659
- if (!this.included)
14660
- this.includeNode(context);
13932
+ this.included = true;
14661
13933
  this.argument.include(context, includeChildrenRecursively);
14662
13934
  context.brokenFlow = true;
14663
13935
  }
@@ -14668,7 +13940,6 @@ class ThrowStatement extends NodeBase {
14668
13940
  }
14669
13941
  }
14670
13942
  }
14671
- ThrowStatement.prototype.includeNode = onlyIncludeSelf;
14672
13943
 
14673
13944
  class TryStatement extends NodeBase {
14674
13945
  constructor() {
@@ -14705,8 +13976,6 @@ class TryStatement extends NodeBase {
14705
13976
  this.finalizer?.include(context, includeChildrenRecursively);
14706
13977
  }
14707
13978
  }
14708
- TryStatement.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
14709
- TryStatement.prototype.applyDeoptimizations = doNotDeoptimize;
14710
13979
 
14711
13980
  const unaryOperators = {
14712
13981
  '!': value => !value,
@@ -14752,7 +14021,6 @@ class UnaryExpression extends NodeBase {
14752
14021
  }
14753
14022
  }
14754
14023
  }
14755
- UnaryExpression.prototype.includeNode = onlyIncludeSelf;
14756
14024
 
14757
14025
  class UpdateExpression extends NodeBase {
14758
14026
  hasEffects(context) {
@@ -14764,8 +14032,9 @@ class UpdateExpression extends NodeBase {
14764
14032
  return path.length > 1 || type !== INTERACTION_ACCESSED;
14765
14033
  }
14766
14034
  include(context, includeChildrenRecursively) {
14767
- if (!this.included)
14768
- this.includeNode(context);
14035
+ if (!this.deoptimized)
14036
+ this.applyDeoptimizations();
14037
+ this.included = true;
14769
14038
  this.argument.includeAsAssignmentTarget(context, includeChildrenRecursively, true);
14770
14039
  }
14771
14040
  initialise() {
@@ -14804,7 +14073,6 @@ class UpdateExpression extends NodeBase {
14804
14073
  this.scope.context.requestTreeshakingPass();
14805
14074
  }
14806
14075
  }
14807
- UpdateExpression.prototype.includeNode = onlyIncludeSelf;
14808
14076
 
14809
14077
  function areAllDeclarationsIncludedAndNotExported(declarations, exportNamesByVariable) {
14810
14078
  for (const declarator of declarations) {
@@ -14835,9 +14103,8 @@ class VariableDeclaration extends NodeBase {
14835
14103
  include(context, includeChildrenRecursively, { asSingleStatement } = BLANK) {
14836
14104
  this.included = true;
14837
14105
  for (const declarator of this.declarations) {
14838
- if (includeChildrenRecursively || declarator.shouldBeIncluded(context)) {
14106
+ if (includeChildrenRecursively || declarator.shouldBeIncluded(context))
14839
14107
  declarator.include(context, includeChildrenRecursively);
14840
- }
14841
14108
  const { id, init } = declarator;
14842
14109
  if (asSingleStatement) {
14843
14110
  id.include(context, includeChildrenRecursively);
@@ -14875,6 +14142,7 @@ class VariableDeclaration extends NodeBase {
14875
14142
  this.renderReplacedDeclarations(code, options);
14876
14143
  }
14877
14144
  }
14145
+ applyDeoptimizations() { }
14878
14146
  renderDeclarationEnd(code, separatorString, lastSeparatorPos, actualContentEnd, renderedContentEnd, systemPatternExports, options) {
14879
14147
  if (code.original.charCodeAt(this.end - 1) === 59 /*";"*/) {
14880
14148
  code.remove(this.end - 1, this.end);
@@ -14917,7 +14185,8 @@ class VariableDeclaration extends NodeBase {
14917
14185
  const singleSystemExport = gatherSystemExportsAndGetSingleExport(separatedNodes, options, aggregatedSystemExports);
14918
14186
  for (const { node, start, separator, contentEnd, end } of separatedNodes) {
14919
14187
  if (!node.included) {
14920
- treeshakeNode(node, code, start, end);
14188
+ code.remove(start, end);
14189
+ node.removeAnnotations(code);
14921
14190
  continue;
14922
14191
  }
14923
14192
  node.render(code, options);
@@ -14987,8 +14256,6 @@ function gatherSystemExportsAndGetSingleExport(separatedNodes, options, aggregat
14987
14256
  }
14988
14257
  return singleSystemExport;
14989
14258
  }
14990
- VariableDeclaration.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
14991
- VariableDeclaration.prototype.applyDeoptimizations = doNotDeoptimize;
14992
14259
 
14993
14260
  class WhileStatement extends NodeBase {
14994
14261
  hasEffects(context) {
@@ -15002,25 +14269,13 @@ class WhileStatement extends NodeBase {
15002
14269
  includeLoopBody(context, this.body, includeChildrenRecursively);
15003
14270
  }
15004
14271
  }
15005
- WhileStatement.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
15006
- WhileStatement.prototype.applyDeoptimizations = doNotDeoptimize;
15007
14272
 
15008
14273
  class YieldExpression extends NodeBase {
15009
- applyDeoptimizations() {
15010
- this.deoptimized = true;
15011
- this.argument?.deoptimizePath(UNKNOWN_PATH);
15012
- }
15013
14274
  hasEffects(context) {
15014
14275
  if (!this.deoptimized)
15015
14276
  this.applyDeoptimizations();
15016
14277
  return !(context.ignore.returnYield && !this.argument?.hasEffects(context));
15017
14278
  }
15018
- includeNode(context) {
15019
- this.included = true;
15020
- if (!this.deoptimized)
15021
- this.applyDeoptimizations();
15022
- this.argument?.includePath(UNKNOWN_PATH, context);
15023
- }
15024
14279
  render(code, options) {
15025
14280
  if (this.argument) {
15026
14281
  this.argument.render(code, options, { preventASI: true });
@@ -15254,7 +14509,7 @@ const bufferParsers = [
15254
14509
  const annotations = (node.annotations = convertAnnotations(buffer[position + 1], buffer));
15255
14510
  node.annotationNoSideEffects = annotations.some(comment => comment.type === 'noSideEffects');
15256
14511
  const parameters = (node.params = convertNodeList(node, scope, buffer[position + 2], buffer));
15257
- scope.addParameterVariables(parameters.map(parameter => parameter.declare('parameter', EMPTY_PATH, UNKNOWN_EXPRESSION)), parameters[parameters.length - 1] instanceof RestElement);
14512
+ scope.addParameterVariables(parameters.map(parameter => parameter.declare('parameter', UNKNOWN_EXPRESSION)), parameters[parameters.length - 1] instanceof RestElement);
15258
14513
  node.body = convertNode(node, scope.bodyScope, buffer[position + 3], buffer);
15259
14514
  },
15260
14515
  function assignmentExpression(node, position, buffer) {
@@ -15300,7 +14555,7 @@ const bufferParsers = [
15300
14555
  const parameterPosition = buffer[position];
15301
14556
  const parameter = (node.param =
15302
14557
  parameterPosition === 0 ? null : convertNode(node, scope, parameterPosition, buffer));
15303
- parameter?.declare('parameter', EMPTY_PATH, UNKNOWN_EXPRESSION);
14558
+ parameter?.declare('parameter', UNKNOWN_EXPRESSION);
15304
14559
  node.body = convertNode(node, scope.bodyScope, buffer[position + 1], buffer);
15305
14560
  },
15306
14561
  function chainExpression(node, position, buffer) {
@@ -15438,7 +14693,7 @@ const bufferParsers = [
15438
14693
  node.id =
15439
14694
  idPosition === 0 ? null : convertNode(node, scope.parent, idPosition, buffer);
15440
14695
  const parameters = (node.params = convertNodeList(node, scope, buffer[position + 3], buffer));
15441
- scope.addParameterVariables(parameters.map(parameter => parameter.declare('parameter', EMPTY_PATH, UNKNOWN_EXPRESSION)), parameters[parameters.length - 1] instanceof RestElement);
14696
+ scope.addParameterVariables(parameters.map(parameter => parameter.declare('parameter', UNKNOWN_EXPRESSION)), parameters[parameters.length - 1] instanceof RestElement);
15442
14697
  node.body = convertNode(node, scope.bodyScope, buffer[position + 4], buffer);
15443
14698
  },
15444
14699
  function functionExpression(node, position, buffer) {
@@ -15451,7 +14706,7 @@ const bufferParsers = [
15451
14706
  const idPosition = buffer[position + 2];
15452
14707
  node.id = idPosition === 0 ? null : convertNode(node, node.idScope, idPosition, buffer);
15453
14708
  const parameters = (node.params = convertNodeList(node, scope, buffer[position + 3], buffer));
15454
- scope.addParameterVariables(parameters.map(parameter => parameter.declare('parameter', EMPTY_PATH, UNKNOWN_EXPRESSION)), parameters[parameters.length - 1] instanceof RestElement);
14709
+ scope.addParameterVariables(parameters.map(parameter => parameter.declare('parameter', UNKNOWN_EXPRESSION)), parameters[parameters.length - 1] instanceof RestElement);
15455
14710
  node.body = convertNode(node, scope.bodyScope, buffer[position + 4], buffer);
15456
14711
  },
15457
14712
  function identifier(node, position, buffer) {
@@ -15915,8 +15170,8 @@ class ExportShimVariable extends Variable {
15915
15170
  super(MISSING_EXPORT_SHIM_VARIABLE);
15916
15171
  this.module = module;
15917
15172
  }
15918
- includePath(path, context) {
15919
- super.includePath(path, context);
15173
+ include() {
15174
+ super.include();
15920
15175
  this.module.needsExportShim = true;
15921
15176
  }
15922
15177
  }
@@ -16614,15 +15869,16 @@ class Module {
16614
15869
  markModuleAndImpureDependenciesAsExecuted(this);
16615
15870
  this.graph.needsTreeshakingPass = true;
16616
15871
  }
16617
- const inclusionContext = createInclusionContext();
16618
15872
  for (const exportName of this.exports.keys()) {
16619
15873
  if (includeNamespaceMembers || exportName !== this.info.syntheticNamedExports) {
16620
15874
  const variable = this.getVariableForExportName(exportName)[0];
16621
15875
  if (!variable) {
16622
15876
  return error(logMissingEntryExport(exportName, this.id));
16623
15877
  }
16624
- this.includeVariable(variable, UNKNOWN_PATH, inclusionContext);
16625
15878
  variable.deoptimizePath(UNKNOWN_PATH);
15879
+ if (!variable.included) {
15880
+ this.includeVariable(variable);
15881
+ }
16626
15882
  }
16627
15883
  }
16628
15884
  for (const name of this.getReexports()) {
@@ -16630,7 +15886,7 @@ class Module {
16630
15886
  if (variable) {
16631
15887
  variable.deoptimizePath(UNKNOWN_PATH);
16632
15888
  if (!variable.included) {
16633
- this.includeVariable(variable, UNKNOWN_PATH, inclusionContext);
15889
+ this.includeVariable(variable);
16634
15890
  }
16635
15891
  if (variable instanceof ExternalVariable) {
16636
15892
  variable.module.reexported = true;
@@ -16651,12 +15907,13 @@ class Module {
16651
15907
  this.graph.needsTreeshakingPass = true;
16652
15908
  }
16653
15909
  let includeNamespaceMembers = false;
16654
- const inclusionContext = createInclusionContext();
16655
15910
  for (const name of names) {
16656
15911
  const variable = this.getVariableForExportName(name)[0];
16657
15912
  if (variable) {
16658
15913
  variable.deoptimizePath(UNKNOWN_PATH);
16659
- this.includeVariable(variable, UNKNOWN_PATH, inclusionContext);
15914
+ if (!variable.included) {
15915
+ this.includeVariable(variable);
15916
+ }
16660
15917
  }
16661
15918
  if (!this.exports.has(name) && !this.reexportDescriptions.has(name)) {
16662
15919
  includeNamespaceMembers = true;
@@ -16757,7 +16014,6 @@ class Module {
16757
16014
  manualPureFunctions: this.graph.pureFunctions,
16758
16015
  module: this,
16759
16016
  moduleContext: this.context,
16760
- newlyIncludedVariableInits: this.graph.newlyIncludedVariableInits,
16761
16017
  options: this.options,
16762
16018
  requestTreeshakingPass: () => (this.graph.needsTreeshakingPass = true),
16763
16019
  traceExport: (name) => this.getVariableForExportName(name)[0],
@@ -17098,13 +16354,13 @@ class Module {
17098
16354
  for (const module of [this, ...this.exportAllModules]) {
17099
16355
  if (module instanceof ExternalModule) {
17100
16356
  const [externalVariable] = module.getVariableForExportName('*');
17101
- externalVariable.includePath(UNKNOWN_PATH, createInclusionContext());
16357
+ externalVariable.include();
17102
16358
  this.includedImports.add(externalVariable);
17103
16359
  externalNamespaces.add(externalVariable);
17104
16360
  }
17105
16361
  else if (module.info.syntheticNamedExports) {
17106
16362
  const syntheticNamespace = module.getSyntheticNamespace();
17107
- syntheticNamespace.includePath(UNKNOWN_PATH, createInclusionContext());
16363
+ syntheticNamespace.include();
17108
16364
  this.includedImports.add(syntheticNamespace);
17109
16365
  syntheticNamespaces.add(syntheticNamespace);
17110
16366
  }
@@ -17114,9 +16370,7 @@ class Module {
17114
16370
  includeDynamicImport(node) {
17115
16371
  const resolution = this.dynamicImports.find(dynamicImport => dynamicImport.node === node).resolution;
17116
16372
  if (resolution instanceof Module) {
17117
- if (!resolution.includedDynamicImporters.includes(this)) {
17118
- resolution.includedDynamicImporters.push(this);
17119
- }
16373
+ resolution.includedDynamicImporters.push(this);
17120
16374
  const importedNames = this.options.treeshake
17121
16375
  ? node.getDeterministicImportedNames()
17122
16376
  : undefined;
@@ -17128,15 +16382,15 @@ class Module {
17128
16382
  }
17129
16383
  }
17130
16384
  }
17131
- includeVariable(variable, path, context) {
17132
- const { included, module: variableModule } = variable;
17133
- variable.includePath(path, context);
17134
- if (included) {
16385
+ includeVariable(variable) {
16386
+ const variableModule = variable.module;
16387
+ if (variable.included) {
17135
16388
  if (variableModule instanceof Module && variableModule !== this) {
17136
16389
  getAndExtendSideEffectModules(variable, this);
17137
16390
  }
17138
16391
  }
17139
16392
  else {
16393
+ variable.include();
17140
16394
  this.graph.needsTreeshakingPass = true;
17141
16395
  if (variableModule instanceof Module) {
17142
16396
  if (!variableModule.isExecuted) {
@@ -17153,8 +16407,8 @@ class Module {
17153
16407
  }
17154
16408
  }
17155
16409
  }
17156
- includeVariableInModule(variable, path, context) {
17157
- this.includeVariable(variable, path, context);
16410
+ includeVariableInModule(variable) {
16411
+ this.includeVariable(variable);
17158
16412
  const variableModule = variable.module;
17159
16413
  if (variableModule && variableModule !== this) {
17160
16414
  this.includedImports.add(variable);
@@ -21751,11 +21005,10 @@ class Graph {
21751
21005
  this.options = options;
21752
21006
  this.astLru = flru(5);
21753
21007
  this.cachedModules = new Map();
21754
- this.deoptimizationTracker = new EntityPathTracker();
21008
+ this.deoptimizationTracker = new PathTracker();
21755
21009
  this.entryModules = [];
21756
21010
  this.modulesById = new Map();
21757
21011
  this.needsTreeshakingPass = false;
21758
- this.newlyIncludedVariableInits = new Set();
21759
21012
  this.phase = BuildPhase.LOAD_AND_PARSE;
21760
21013
  this.scope = new GlobalScope();
21761
21014
  this.watchFiles = Object.create(null);
@@ -21849,7 +21102,6 @@ class Graph {
21849
21102
  }
21850
21103
  if (this.options.treeshake) {
21851
21104
  let treeshakingPass = 1;
21852
- this.newlyIncludedVariableInits.clear();
21853
21105
  do {
21854
21106
  timeStart(`treeshaking pass ${treeshakingPass}`, 3);
21855
21107
  this.needsTreeshakingPass = false;
@@ -21874,10 +21126,6 @@ class Graph {
21874
21126
  }
21875
21127
  }
21876
21128
  }
21877
- for (const entity of this.newlyIncludedVariableInits) {
21878
- this.newlyIncludedVariableInits.delete(entity);
21879
- entity.include(createInclusionContext(), false);
21880
- }
21881
21129
  timeEnd(`treeshaking pass ${treeshakingPass++}`, 3);
21882
21130
  } while (this.needsTreeshakingPass);
21883
21131
  }
@@ -22757,7 +22005,7 @@ createColors();
22757
22005
 
22758
22006
  // @see https://no-color.org
22759
22007
  // @see https://www.npmjs.com/package/chalk
22760
- const { bold, cyan, dim, red} = createColors({
22008
+ const { bold, cyan, dim, gray, green, red, underline, yellow } = createColors({
22761
22009
  useColor: env$1.FORCE_COLOR !== '0' && !env$1.NO_COLOR
22762
22010
  });
22763
22011