rollup 4.27.2 → 4.27.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,22 +1,22 @@
1
1
  /*
2
2
  @license
3
- Rollup.js v4.27.2
4
- Fri, 15 Nov 2024 17:19:22 GMT - commit a503a4dd9982bf20fd38aeb171882a27828906ae
3
+ Rollup.js v4.27.4
4
+ Sat, 23 Nov 2024 06:59:50 GMT - commit e805b546405a4e6cfccd3fe73e9f4df770023824
5
5
 
6
6
  https://github.com/rollup/rollup
7
7
 
8
8
  Released under the MIT License.
9
9
  */
10
- import { EMPTY_OBJECT, CallExpression as CallExpression$1, ExportDefaultDeclaration as ExportDefaultDeclaration$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, convertAnnotations, FIXED_STRINGS, convertNode as convertNode$1, getAstBuffer, logImportAttributeIsInvalid, logImportOptionsAreInvalid, logSyntheticNamedExportsNeedNamespaceExport, logCircularReexport, logMissingEntryExport, logInvalidFormatForTopLevelAwait, logDuplicateExportError, logInvalidSourcemapForError, augmentCodeLocation, logInconsistentImportAttributes, logMissingJsxExport, logNamespaceConflict, logAmbiguousExternalNamespaces, logShimmedExport, parseAst, TemplateLiteral as TemplateLiteral$1, Literal as Literal$1, logAddonNotGenerated, logIncompatibleExportOptionValue, logMixedExport, logFailedValidation, isPathFragment, getAliasName, logCyclicCrossChunkReexport, logUnexpectedNamedImport, isAbsolute as isAbsolute$1, relative as relative$1, logUnexpectedNamespaceReexport, logMissingGlobalName, logEmptyChunk, logOptimizeChunkStatus, logConflictingSourcemapSources, logSourcemapBroken, logInvalidOption, URL_OUTPUT_FORMAT, URL_OUTPUT_DIR, URL_OUTPUT_SOURCEMAPFILE, URL_OUTPUT_AMD_ID, logCannotAssignModuleToChunk, logChunkInvalid, logAnonymousPluginCache, logDuplicatePluginName, LOGLEVEL_ERROR, logLevelPriority, LOGLEVEL_DEBUG, printQuotedStringList, logUnknownOption, logNoTransformMapOrAstWithoutCode, logInvalidSetAssetSourceCall, logPluginError, relativeId, logBadLoader, logExternalModulesCannotBeTransformedToModules, logInternalIdCannotBeExternal, isRelative, logUnresolvedImport, logUnresolvedImportTreatedAsExternal, logExternalSyntheticExports, logUnresolvedEntry, logUnresolvedImplicitDependant, logExternalModulesCannotBeIncludedInManualChunks, logEntryCannotBeExternal, logImplicitDependantCannotBeExternal, logNoAssetSourceSet, logFileReferenceIdNotFoundForFilename, logChunkNotGeneratedForFileName, logAssetNotFinalisedForFileName, logAssetReferenceIdNotFoundForSetSource, logAssetSourceAlreadySet, logFileNameConflict, logInvalidRollupPhaseForChunkEmission, warnDeprecation, URL_GENERATEBUNDLE, logInvalidLogPosition, logInvalidFunctionPluginHook, logInputHookInOutputPlugin, logInvalidAddonPluginHook, logImplicitDependantIsNotIncluded, logCircularDependency, augmentLogMessage, URL_TREESHAKE, URL_TREESHAKE_MODULESIDEEFFECTS, URL_JSX, URL_OUTPUT_INLINEDYNAMICIMPORTS, URL_PRESERVEENTRYSIGNATURES, URL_OUTPUT_GENERATEDCODE, URL_OUTPUT_EXTERNALIMPORTATTRIBUTES, isValidUrl, addTrailingSlashIfMissed, URL_OUTPUT_SOURCEMAPBASEURL, URL_OUTPUT_MANUALCHUNKS, logInvalidExportOptionValue, URL_OUTPUT_AMD_BASEPATH, URL_OUTPUT_INTEROP, logAlreadyClosed, logCannotEmitFromOptionsHook, logMissingFileOrDirOption, 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 { isAbsolute, win32, posix, resolve } 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.27.2";
19
+ var version = "4.27.4";
20
20
 
21
21
  const comma = ','.charCodeAt(0);
22
22
  const semicolon = ';'.charCodeAt(0);
@@ -421,6 +421,9 @@ class SourceMap {
421
421
  if (typeof properties.x_google_ignoreList !== 'undefined') {
422
422
  this.x_google_ignoreList = properties.x_google_ignoreList;
423
423
  }
424
+ if (typeof properties.debugId !== 'undefined') {
425
+ this.debugId = properties.debugId;
426
+ }
424
427
  }
425
428
 
426
429
  toString() {
@@ -1997,6 +2000,19 @@ function is_reference(node, parent) {
1997
2000
  }
1998
2001
  }
1999
2002
 
2003
+ const PureFunctionKey = Symbol('PureFunction');
2004
+ const getPureFunctions = ({ treeshake }) => {
2005
+ const pureFunctions = Object.create(null);
2006
+ for (const functionName of treeshake ? treeshake.manualPureFunctions : []) {
2007
+ let currentFunctions = pureFunctions;
2008
+ for (const pathSegment of functionName.split('.')) {
2009
+ currentFunctions = currentFunctions[pathSegment] ||= Object.create(null);
2010
+ }
2011
+ currentFunctions[PureFunctionKey] = true;
2012
+ }
2013
+ return pureFunctions;
2014
+ };
2015
+
2000
2016
  function getOrCreate(map, key, init) {
2001
2017
  const existing = map.get(key);
2002
2018
  if (existing !== undefined) {
@@ -2027,7 +2043,7 @@ const UNKNOWN_PATH = [UnknownKey];
2027
2043
  const UNKNOWN_NON_ACCESSOR_PATH = [UnknownNonAccessorKey];
2028
2044
  const UNKNOWN_INTEGER_PATH = [UnknownInteger];
2029
2045
  const EntitiesKey = Symbol('Entities');
2030
- class EntityPathTracker {
2046
+ class PathTracker {
2031
2047
  constructor() {
2032
2048
  this.entityPaths = Object.create(null, {
2033
2049
  [EntitiesKey]: { value: new Set() }
@@ -2052,14 +2068,14 @@ class EntityPathTracker {
2052
2068
  getEntities(path) {
2053
2069
  let currentPaths = this.entityPaths;
2054
2070
  for (const pathSegment of path) {
2055
- currentPaths = currentPaths[pathSegment] ||= Object.create(null, {
2056
- [EntitiesKey]: { value: new Set() }
2057
- });
2071
+ currentPaths = currentPaths[pathSegment] =
2072
+ currentPaths[pathSegment] ||
2073
+ Object.create(null, { [EntitiesKey]: { value: new Set() } });
2058
2074
  }
2059
2075
  return currentPaths[EntitiesKey];
2060
2076
  }
2061
2077
  }
2062
- const SHARED_RECURSION_TRACKER = new EntityPathTracker();
2078
+ const SHARED_RECURSION_TRACKER = new PathTracker();
2063
2079
  class DiscriminatedPathTracker {
2064
2080
  constructor() {
2065
2081
  this.entityPaths = Object.create(null, {
@@ -2069,9 +2085,9 @@ class DiscriminatedPathTracker {
2069
2085
  trackEntityAtPathAndGetIfTracked(path, discriminator, entity) {
2070
2086
  let currentPaths = this.entityPaths;
2071
2087
  for (const pathSegment of path) {
2072
- currentPaths = currentPaths[pathSegment] ||= Object.create(null, {
2073
- [EntitiesKey]: { value: new Map() }
2074
- });
2088
+ currentPaths = currentPaths[pathSegment] =
2089
+ currentPaths[pathSegment] ||
2090
+ Object.create(null, { [EntitiesKey]: { value: new Map() } });
2075
2091
  }
2076
2092
  const trackedEntities = getOrCreate(currentPaths[EntitiesKey], discriminator, (getNewSet));
2077
2093
  if (trackedEntities.has(entity))
@@ -2080,85 +2096,6 @@ class DiscriminatedPathTracker {
2080
2096
  return false;
2081
2097
  }
2082
2098
  }
2083
- const UNKNOWN_INCLUDED_PATH = Object.freeze({ [UnknownKey]: EMPTY_OBJECT });
2084
- class IncludedPathTracker {
2085
- constructor() {
2086
- this.includedPaths = null;
2087
- }
2088
- includePathAndGetIfIncluded(path) {
2089
- let included = true;
2090
- let parent = this;
2091
- let parentSegment = 'includedPaths';
2092
- let currentPaths = (this.includedPaths ||=
2093
- ((included = false), Object.create(null)));
2094
- for (const pathSegment of path) {
2095
- // This means from here, all paths are included
2096
- if (currentPaths[UnknownKey]) {
2097
- return true;
2098
- }
2099
- // Including UnknownKey automatically includes all nested paths.
2100
- // From above, we know that UnknownKey is not included yet.
2101
- if (typeof pathSegment === 'symbol') {
2102
- // Hopefully, this saves some memory over just setting
2103
- // currentPaths[UnknownKey] = EMPTY_OBJECT
2104
- parent[parentSegment] = UNKNOWN_INCLUDED_PATH;
2105
- return false;
2106
- }
2107
- parent = currentPaths;
2108
- parentSegment = pathSegment;
2109
- currentPaths = currentPaths[pathSegment] ||= ((included = false), Object.create(null));
2110
- }
2111
- return included;
2112
- }
2113
- includeAllPaths(entity, context, basePath) {
2114
- const { includedPaths } = this;
2115
- if (includedPaths) {
2116
- includeAllPaths(entity, context, basePath, includedPaths);
2117
- }
2118
- }
2119
- }
2120
- function includeAllPaths(entity, context, basePath, currentPaths) {
2121
- if (currentPaths[UnknownKey]) {
2122
- return entity.includePath([...basePath, UnknownKey], context, false);
2123
- }
2124
- const keys = Object.keys(currentPaths);
2125
- if (keys.length === 0) {
2126
- return entity.includePath(basePath, context, false);
2127
- }
2128
- for (const key of keys) {
2129
- includeAllPaths(entity, context, [...basePath, key], currentPaths[key]);
2130
- }
2131
- }
2132
-
2133
- function createInclusionContext() {
2134
- return {
2135
- brokenFlow: false,
2136
- hasBreak: false,
2137
- hasContinue: false,
2138
- includedCallArguments: new Set(),
2139
- includedLabels: new Set()
2140
- };
2141
- }
2142
- function createHasEffectsContext() {
2143
- return {
2144
- accessed: new EntityPathTracker(),
2145
- assigned: new EntityPathTracker(),
2146
- brokenFlow: false,
2147
- called: new DiscriminatedPathTracker(),
2148
- hasBreak: false,
2149
- hasContinue: false,
2150
- ignore: {
2151
- breaks: false,
2152
- continues: false,
2153
- labels: new Set(),
2154
- returnYield: false,
2155
- this: false
2156
- },
2157
- includedLabels: new Set(),
2158
- instantiated: new DiscriminatedPathTracker(),
2159
- replacedVariableInits: new Map()
2160
- };
2161
- }
2162
2099
 
2163
2100
  function isFlagSet(flags, flag) {
2164
2101
  return (flags & flag) !== 0;
@@ -2197,12 +2134,12 @@ class ExpressionEntity {
2197
2134
  hasEffectsOnInteractionAtPath(_path, _interaction, _context) {
2198
2135
  return true;
2199
2136
  }
2200
- includePath(_path, _context, _includeChildrenRecursively, _options) {
2137
+ include(_context, _includeChildrenRecursively, _options) {
2201
2138
  this.included = true;
2202
2139
  }
2203
- includeCallArguments(context, interaction) {
2204
- for (const argument of interaction.args) {
2205
- argument?.includePath(UNKNOWN_PATH, context, false);
2140
+ includeCallArguments(context, parameters) {
2141
+ for (const argument of parameters) {
2142
+ argument.include(context, false);
2206
2143
  }
2207
2144
  }
2208
2145
  shouldBeIncluded(_context) {
@@ -2241,19 +2178,6 @@ const NODE_INTERACTION_UNKNOWN_CALL = {
2241
2178
  withNew: false
2242
2179
  };
2243
2180
 
2244
- const PureFunctionKey = Symbol('PureFunction');
2245
- const getPureFunctions = ({ treeshake }) => {
2246
- const pureFunctions = Object.create(null);
2247
- for (const functionName of treeshake ? treeshake.manualPureFunctions : []) {
2248
- let currentFunctions = pureFunctions;
2249
- for (const pathSegment of functionName.split('.')) {
2250
- currentFunctions = currentFunctions[pathSegment] ||= Object.create(null);
2251
- }
2252
- currentFunctions[PureFunctionKey] = true;
2253
- }
2254
- return pureFunctions;
2255
- };
2256
-
2257
2181
  class Variable extends ExpressionEntity {
2258
2182
  markReassigned() {
2259
2183
  this.isReassigned = true;
@@ -2330,9 +2254,9 @@ class Variable extends ExpressionEntity {
2330
2254
  * has not been included previously. Once a variable is included, it should
2331
2255
  * take care all its declarations are included.
2332
2256
  */
2333
- includePath(path, context) {
2257
+ include() {
2334
2258
  this.included = true;
2335
- this.renderedLikeHoisted?.includePath(path, context);
2259
+ this.renderedLikeHoisted?.include();
2336
2260
  }
2337
2261
  /**
2338
2262
  * Links the rendered name of this variable to another variable and includes
@@ -2364,8 +2288,8 @@ class ExternalVariable extends Variable {
2364
2288
  hasEffectsOnInteractionAtPath(path, { type }) {
2365
2289
  return type !== INTERACTION_ACCESSED || path.length > (this.isNamespace ? 1 : 0);
2366
2290
  }
2367
- includePath(path, context) {
2368
- super.includePath(path, context);
2291
+ include() {
2292
+ super.include();
2369
2293
  this.module.used = true;
2370
2294
  }
2371
2295
  }
@@ -2666,6 +2590,36 @@ const childNodeKeys = {
2666
2590
  YieldExpression: ['argument']
2667
2591
  };
2668
2592
 
2593
+ function createInclusionContext() {
2594
+ return {
2595
+ brokenFlow: false,
2596
+ hasBreak: false,
2597
+ hasContinue: false,
2598
+ includedCallArguments: new Set(),
2599
+ includedLabels: new Set()
2600
+ };
2601
+ }
2602
+ function createHasEffectsContext() {
2603
+ return {
2604
+ accessed: new PathTracker(),
2605
+ assigned: new PathTracker(),
2606
+ brokenFlow: false,
2607
+ called: new DiscriminatedPathTracker(),
2608
+ hasBreak: false,
2609
+ hasContinue: false,
2610
+ ignore: {
2611
+ breaks: false,
2612
+ continues: false,
2613
+ labels: new Set(),
2614
+ returnYield: false,
2615
+ this: false
2616
+ },
2617
+ includedLabels: new Set(),
2618
+ instantiated: new DiscriminatedPathTracker(),
2619
+ replacedVariableInits: new Map()
2620
+ };
2621
+ }
2622
+
2669
2623
  const INCLUDE_PARAMETERS = 'variables';
2670
2624
  const IS_SKIPPED_CHAIN = Symbol('IS_SKIPPED_CHAIN');
2671
2625
  class NodeBase extends ExpressionEntity {
@@ -2734,7 +2688,7 @@ class NodeBase extends ExpressionEntity {
2734
2688
  return (this.hasEffects(context) ||
2735
2689
  this.hasEffectsOnInteractionAtPath(EMPTY_PATH, this.assignmentInteraction, context));
2736
2690
  }
2737
- includePath(_path, context, includeChildrenRecursively, _options) {
2691
+ include(context, includeChildrenRecursively, _options) {
2738
2692
  if (!this.deoptimized)
2739
2693
  this.applyDeoptimizations();
2740
2694
  this.included = true;
@@ -2744,16 +2698,16 @@ class NodeBase extends ExpressionEntity {
2744
2698
  continue;
2745
2699
  if (Array.isArray(value)) {
2746
2700
  for (const child of value) {
2747
- child?.includePath(UNKNOWN_PATH, context, includeChildrenRecursively);
2701
+ child?.include(context, includeChildrenRecursively);
2748
2702
  }
2749
2703
  }
2750
2704
  else {
2751
- value.includePath(UNKNOWN_PATH, context, includeChildrenRecursively);
2705
+ value.include(context, includeChildrenRecursively);
2752
2706
  }
2753
2707
  }
2754
2708
  }
2755
2709
  includeAsAssignmentTarget(context, includeChildrenRecursively, _deoptimizeAccess) {
2756
- this.includePath(UNKNOWN_PATH, context, includeChildrenRecursively);
2710
+ this.include(context, includeChildrenRecursively);
2757
2711
  }
2758
2712
  /**
2759
2713
  * Override to perform special initialisation steps after the scope is
@@ -3215,7 +3169,6 @@ class ObjectEntity extends ExpressionEntity {
3215
3169
  this.unknownIntegerProps = [];
3216
3170
  this.unmatchableGetters = [];
3217
3171
  this.unmatchablePropertiesAndGetters = [];
3218
- this.unmatchablePropertiesAndSetters = [];
3219
3172
  this.unmatchableSetters = [];
3220
3173
  if (Array.isArray(properties)) {
3221
3174
  this.buildPropertyMaps(properties);
@@ -3450,37 +3403,9 @@ class ObjectEntity extends ExpressionEntity {
3450
3403
  }
3451
3404
  return false;
3452
3405
  }
3453
- includePath(path, context, includeChildrenRecursively) {
3454
- this.included = true;
3455
- const [key, ...subPath] = path;
3456
- if (key == null || includeChildrenRecursively) {
3457
- for (const property of this.allProperties) {
3458
- if (includeChildrenRecursively || property.shouldBeIncluded(context)) {
3459
- property.includePath(EMPTY_PATH, context, includeChildrenRecursively);
3460
- }
3461
- }
3462
- this.prototypeExpression?.includePath(EMPTY_PATH, context, includeChildrenRecursively);
3463
- }
3464
- else {
3465
- const [includedMembers, includedPath] = typeof key === 'string'
3466
- ? [
3467
- [
3468
- ...new Set([
3469
- ...(this.propertiesAndGettersByKey[key] || this.unmatchablePropertiesAndGetters),
3470
- ...(this.propertiesAndSettersByKey[key] || this.unmatchablePropertiesAndSetters)
3471
- ])
3472
- ],
3473
- subPath
3474
- ]
3475
- : [this.allProperties, UNKNOWN_PATH];
3476
- for (const property of includedMembers) {
3477
- property.includePath(includedPath, context, includeChildrenRecursively);
3478
- }
3479
- this.prototypeExpression?.includePath(path, context, includeChildrenRecursively);
3480
- }
3481
- }
3482
3406
  buildPropertyMaps(properties) {
3483
- const { allProperties, propertiesAndGettersByKey, propertiesAndSettersByKey, settersByKey, gettersByKey, unknownIntegerProps, unmatchablePropertiesAndGetters, unmatchablePropertiesAndSetters, unmatchableGetters, unmatchableSetters } = this;
3407
+ const { allProperties, propertiesAndGettersByKey, propertiesAndSettersByKey, settersByKey, gettersByKey, unknownIntegerProps, unmatchablePropertiesAndGetters, unmatchableGetters, unmatchableSetters } = this;
3408
+ const unmatchablePropertiesAndSetters = [];
3484
3409
  for (let index = properties.length - 1; index >= 0; index--) {
3485
3410
  const { key, kind, property } = properties[index];
3486
3411
  allProperties.push(property);
@@ -4837,37 +4762,17 @@ class GlobalVariable extends Variable {
4837
4762
  }
4838
4763
  }
4839
4764
 
4840
- // To avoid infinite recursions
4841
- const MAX_PATH_DEPTH = 6;
4842
- // If a path is longer than MAX_PATH_DEPTH, it is truncated so that it is at
4843
- // most MAX_PATH_DEPTH long. The last element is always UnknownKey
4844
- const limitConcatenatedPathDepth = (path1, path2) => {
4845
- const { length: length1 } = path1;
4846
- const { length: length2 } = path2;
4847
- return length1 === 0
4848
- ? path2
4849
- : length2 === 0
4850
- ? path1
4851
- : length1 + length2 > MAX_PATH_DEPTH
4852
- ? [...path1, ...path2.slice(0, MAX_PATH_DEPTH - 1 - path1.length), 'UnknownKey']
4853
- : [...path1, ...path2];
4854
- };
4855
-
4856
4765
  class LocalVariable extends Variable {
4857
- constructor(name, declarator, init,
4858
- /** if this is non-empty, the actual init is this path of this.init */
4859
- initPath, context, kind) {
4766
+ constructor(name, declarator, init, context, kind) {
4860
4767
  super(name);
4861
4768
  this.init = init;
4862
- this.initPath = initPath;
4863
- this.kind = kind;
4864
4769
  this.calledFromTryStatement = false;
4865
4770
  this.additionalInitializers = null;
4866
- this.includedPathTracker = new IncludedPathTracker();
4867
4771
  this.expressionsToBeDeoptimized = [];
4868
4772
  this.declarations = declarator ? [declarator] : [];
4869
4773
  this.deoptimizationTracker = context.deoptimizationTracker;
4870
4774
  this.module = context.module;
4775
+ this.kind = kind;
4871
4776
  }
4872
4777
  addDeclaration(identifier, init) {
4873
4778
  this.declarations.push(identifier);
@@ -4878,16 +4783,15 @@ class LocalVariable extends Variable {
4878
4783
  for (const initializer of this.additionalInitializers) {
4879
4784
  initializer.deoptimizePath(UNKNOWN_PATH);
4880
4785
  }
4786
+ this.additionalInitializers = null;
4881
4787
  }
4882
4788
  }
4883
4789
  deoptimizeArgumentsOnInteractionAtPath(interaction, path, recursionTracker) {
4884
- if (this.isReassigned || path.length + this.initPath.length > MAX_PATH_DEPTH) {
4790
+ if (this.isReassigned) {
4885
4791
  deoptimizeInteraction(interaction);
4886
4792
  return;
4887
4793
  }
4888
- recursionTracker.withTrackedEntityAtPath(path, this.init, () => {
4889
- this.init.deoptimizeArgumentsOnInteractionAtPath(interaction, [...this.initPath, ...path], recursionTracker);
4890
- }, undefined);
4794
+ recursionTracker.withTrackedEntityAtPath(path, this.init, () => this.init.deoptimizeArgumentsOnInteractionAtPath(interaction, path, recursionTracker), undefined);
4891
4795
  }
4892
4796
  deoptimizePath(path) {
4893
4797
  if (this.isReassigned ||
@@ -4901,40 +4805,37 @@ class LocalVariable extends Variable {
4901
4805
  for (const expression of expressionsToBeDeoptimized) {
4902
4806
  expression.deoptimizeCache();
4903
4807
  }
4904
- this.init.deoptimizePath([...this.initPath, UnknownKey]);
4808
+ this.init.deoptimizePath(UNKNOWN_PATH);
4905
4809
  }
4906
4810
  else {
4907
- this.init.deoptimizePath(limitConcatenatedPathDepth(this.initPath, path));
4811
+ this.init.deoptimizePath(path);
4908
4812
  }
4909
4813
  }
4910
4814
  getLiteralValueAtPath(path, recursionTracker, origin) {
4911
- if (this.isReassigned || path.length + this.initPath.length > MAX_PATH_DEPTH) {
4815
+ if (this.isReassigned) {
4912
4816
  return UnknownValue;
4913
4817
  }
4914
4818
  return recursionTracker.withTrackedEntityAtPath(path, this.init, () => {
4915
4819
  this.expressionsToBeDeoptimized.push(origin);
4916
- return this.init.getLiteralValueAtPath([...this.initPath, ...path], recursionTracker, origin);
4820
+ return this.init.getLiteralValueAtPath(path, recursionTracker, origin);
4917
4821
  }, UnknownValue);
4918
4822
  }
4919
4823
  getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin) {
4920
- if (this.isReassigned || path.length + this.initPath.length > MAX_PATH_DEPTH) {
4824
+ if (this.isReassigned) {
4921
4825
  return UNKNOWN_RETURN_EXPRESSION;
4922
4826
  }
4923
4827
  return recursionTracker.withTrackedEntityAtPath(path, this.init, () => {
4924
4828
  this.expressionsToBeDeoptimized.push(origin);
4925
- return this.init.getReturnExpressionWhenCalledAtPath([...this.initPath, ...path], interaction, recursionTracker, origin);
4829
+ return this.init.getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin);
4926
4830
  }, UNKNOWN_RETURN_EXPRESSION);
4927
4831
  }
4928
4832
  hasEffectsOnInteractionAtPath(path, interaction, context) {
4929
- if (path.length + this.initPath.length > MAX_PATH_DEPTH) {
4930
- return true;
4931
- }
4932
4833
  switch (interaction.type) {
4933
4834
  case INTERACTION_ACCESSED: {
4934
4835
  if (this.isReassigned)
4935
4836
  return true;
4936
4837
  return (!context.accessed.trackEntityAtPathAndGetIfTracked(path, this) &&
4937
- this.init.hasEffectsOnInteractionAtPath([...this.initPath, ...path], interaction, context));
4838
+ this.init.hasEffectsOnInteractionAtPath(path, interaction, context));
4938
4839
  }
4939
4840
  case INTERACTION_ASSIGNED: {
4940
4841
  if (this.included)
@@ -4944,23 +4845,23 @@ class LocalVariable extends Variable {
4944
4845
  if (this.isReassigned)
4945
4846
  return true;
4946
4847
  return (!context.assigned.trackEntityAtPathAndGetIfTracked(path, this) &&
4947
- this.init.hasEffectsOnInteractionAtPath([...this.initPath, ...path], interaction, context));
4848
+ this.init.hasEffectsOnInteractionAtPath(path, interaction, context));
4948
4849
  }
4949
4850
  case INTERACTION_CALLED: {
4950
4851
  if (this.isReassigned)
4951
4852
  return true;
4952
4853
  return (!(interaction.withNew ? context.instantiated : context.called).trackEntityAtPathAndGetIfTracked(path, interaction.args, this) &&
4953
- this.init.hasEffectsOnInteractionAtPath([...this.initPath, ...path], interaction, context));
4854
+ this.init.hasEffectsOnInteractionAtPath(path, interaction, context));
4954
4855
  }
4955
4856
  }
4956
4857
  }
4957
- includePath(path, context) {
4958
- if (!this.includedPathTracker.includePathAndGetIfIncluded(path)) {
4959
- super.includePath(path, context);
4858
+ include() {
4859
+ if (!this.included) {
4860
+ super.include();
4960
4861
  for (const declaration of this.declarations) {
4961
4862
  // If node is a default export, it can save a tree-shaking run to include the full declaration now
4962
4863
  if (!declaration.included)
4963
- declaration.includePath(EMPTY_PATH, context, false);
4864
+ declaration.include(createInclusionContext(), false);
4964
4865
  let node = declaration.parent;
4965
4866
  while (!node.included) {
4966
4867
  // We do not want to properly include parents in case they are part of a dead branch
@@ -4971,26 +4872,17 @@ class LocalVariable extends Variable {
4971
4872
  node = node.parent;
4972
4873
  }
4973
4874
  }
4974
- // We need to make sure we include the correct path of the init
4975
- if (path.length > 0) {
4976
- this.init.includePath(limitConcatenatedPathDepth(this.initPath, path), context, false);
4977
- this.additionalInitializers?.forEach(initializer => initializer.includePath(UNKNOWN_PATH, context, false));
4978
- }
4979
4875
  }
4980
4876
  }
4981
- includeCallArguments(context, interaction) {
4982
- if (this.isReassigned ||
4983
- context.includedCallArguments.has(this.init) ||
4984
- // This can be removed again once we can include arguments when called at
4985
- // a specific path
4986
- this.initPath.length > 0) {
4987
- for (const argument of interaction.args) {
4988
- argument?.includePath(UNKNOWN_PATH, context, false);
4877
+ includeCallArguments(context, parameters) {
4878
+ if (this.isReassigned || context.includedCallArguments.has(this.init)) {
4879
+ for (const argument of parameters) {
4880
+ argument.include(context, false);
4989
4881
  }
4990
4882
  }
4991
4883
  else {
4992
4884
  context.includedCallArguments.add(this.init);
4993
- this.init.includeCallArguments(context, interaction);
4885
+ this.init.includeCallArguments(context, parameters);
4994
4886
  context.includedCallArguments.delete(this.init);
4995
4887
  }
4996
4888
  }
@@ -5070,21 +4962,18 @@ class IdentifierBase extends NodeBase {
5070
4962
  }
5071
4963
  }
5072
4964
  }
5073
- includePath(path, context) {
4965
+ include() {
5074
4966
  if (!this.deoptimized)
5075
4967
  this.applyDeoptimizations();
5076
4968
  if (!this.included) {
5077
4969
  this.included = true;
5078
4970
  if (this.variable !== null) {
5079
- this.scope.context.includeVariableInModule(this.variable, path);
4971
+ this.scope.context.includeVariableInModule(this.variable);
5080
4972
  }
5081
4973
  }
5082
- else if (path.length > 0) {
5083
- this.variable?.includePath(path, context);
5084
- }
5085
4974
  }
5086
- includeCallArguments(context, interaction) {
5087
- this.variable.includeCallArguments(context, interaction);
4975
+ includeCallArguments(context, parameters) {
4976
+ this.variable.includeCallArguments(context, parameters);
5088
4977
  }
5089
4978
  isPossibleTDZ() {
5090
4979
  // return cached value to avoid issues with the next tree-shaking pass
@@ -5167,40 +5056,11 @@ function closestParentFunctionOrProgram(node) {
5167
5056
  return node;
5168
5057
  }
5169
5058
 
5170
- class ObjectMember extends ExpressionEntity {
5171
- constructor(object, path) {
5172
- super();
5173
- this.object = object;
5174
- this.path = path;
5175
- }
5176
- deoptimizeArgumentsOnInteractionAtPath(interaction, path, recursionTracker) {
5177
- this.object.deoptimizeArgumentsOnInteractionAtPath(interaction, [...this.path, ...path], recursionTracker);
5178
- }
5179
- deoptimizePath(path) {
5180
- this.object.deoptimizePath([...this.path, ...path]);
5181
- }
5182
- getLiteralValueAtPath(path, recursionTracker, origin) {
5183
- return this.object.getLiteralValueAtPath([...this.path, ...path], recursionTracker, origin);
5184
- }
5185
- getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin) {
5186
- return this.object.getReturnExpressionWhenCalledAtPath([...this.path, ...path], interaction, recursionTracker, origin);
5187
- }
5188
- hasEffectsOnInteractionAtPath(path, interaction, context) {
5189
- return this.object.hasEffectsOnInteractionAtPath([...this.path, ...path], interaction, context);
5190
- }
5191
- }
5192
-
5193
5059
  class Identifier extends IdentifierBase {
5194
5060
  constructor() {
5195
5061
  super(...arguments);
5196
5062
  this.variable = null;
5197
5063
  }
5198
- get isDestructuringDeoptimized() {
5199
- return isFlagSet(this.flags, 8388608 /* Flag.destructuringDeoptimized */);
5200
- }
5201
- set isDestructuringDeoptimized(value) {
5202
- this.flags = setFlag(this.flags, 8388608 /* Flag.destructuringDeoptimized */, value);
5203
- }
5204
5064
  addExportedVariables(variables, exportNamesByVariable) {
5205
5065
  if (exportNamesByVariable.has(this.variable)) {
5206
5066
  variables.push(this.variable);
@@ -5213,52 +5073,42 @@ class Identifier extends IdentifierBase {
5213
5073
  this.isVariableReference = true;
5214
5074
  }
5215
5075
  }
5216
- declare(kind, destructuredInitPath, init) {
5076
+ declare(kind, init) {
5217
5077
  let variable;
5218
5078
  const { treeshake } = this.scope.context.options;
5219
- if (kind === 'parameter') {
5220
- variable = this.scope.addParameterDeclaration(this, destructuredInitPath);
5221
- }
5222
- else {
5223
- variable = this.scope.addDeclaration(this, this.scope.context, init, destructuredInitPath, kind);
5224
- if (kind === 'var' && treeshake && treeshake.correctVarValueBeforeDeclaration) {
5225
- // Necessary to make sure the init is deoptimized. We cannot call deoptimizePath here.
5226
- variable.markInitializersForDeoptimization();
5079
+ switch (kind) {
5080
+ case 'var': {
5081
+ variable = this.scope.addDeclaration(this, this.scope.context, init, kind);
5082
+ if (treeshake && treeshake.correctVarValueBeforeDeclaration) {
5083
+ // Necessary to make sure the init is deoptimized. We cannot call deoptimizePath here.
5084
+ variable.markInitializersForDeoptimization();
5085
+ }
5086
+ break;
5227
5087
  }
5228
- }
5229
- return [(this.variable = variable)];
5230
- }
5231
- deoptimizeAssignment(destructuredInitPath, init) {
5232
- this.deoptimizePath(EMPTY_PATH);
5233
- init.deoptimizePath([...destructuredInitPath, UnknownKey]);
5234
- }
5235
- hasEffectsWhenDestructuring(context, destructuredInitPath, init) {
5236
- return (destructuredInitPath.length > 0 &&
5237
- init.hasEffectsOnInteractionAtPath(destructuredInitPath, NODE_INTERACTION_UNKNOWN_ACCESS, context));
5238
- }
5239
- includeDestructuredIfNecessary(context, destructuredInitPath, init) {
5240
- if (destructuredInitPath.length > 0 && !this.isDestructuringDeoptimized) {
5241
- this.isDestructuringDeoptimized = true;
5242
- init.deoptimizeArgumentsOnInteractionAtPath({
5243
- args: [new ObjectMember(init, destructuredInitPath.slice(0, -1))],
5244
- type: INTERACTION_ACCESSED
5245
- }, destructuredInitPath, SHARED_RECURSION_TRACKER);
5246
- }
5247
- const { propertyReadSideEffects } = this.scope.context.options
5248
- .treeshake;
5249
- if ((this.included ||=
5250
- destructuredInitPath.length > 0 &&
5251
- !context.brokenFlow &&
5252
- propertyReadSideEffects &&
5253
- (propertyReadSideEffects === 'always' ||
5254
- init.hasEffectsOnInteractionAtPath(destructuredInitPath, NODE_INTERACTION_UNKNOWN_ACCESS, createHasEffectsContext())))) {
5255
- if (this.variable && !this.variable.included) {
5256
- this.scope.context.includeVariableInModule(this.variable, EMPTY_PATH);
5088
+ case 'function': {
5089
+ // in strict mode, functions are only hoisted within a scope but not across block scopes
5090
+ variable = this.scope.addDeclaration(this, this.scope.context, init, kind);
5091
+ break;
5092
+ }
5093
+ case 'let':
5094
+ case 'const':
5095
+ case 'using':
5096
+ case 'await using':
5097
+ case 'class': {
5098
+ variable = this.scope.addDeclaration(this, this.scope.context, init, kind);
5099
+ break;
5100
+ }
5101
+ case 'parameter': {
5102
+ variable = this.scope.addParameterDeclaration(this);
5103
+ break;
5104
+ }
5105
+ /* istanbul ignore next */
5106
+ default: {
5107
+ /* istanbul ignore next */
5108
+ throw new Error(`Internal Error: Unexpected identifier kind ${kind}.`);
5257
5109
  }
5258
- init.includePath(destructuredInitPath, context, false);
5259
- return true;
5260
5110
  }
5261
- return false;
5111
+ return [(this.variable = variable)];
5262
5112
  }
5263
5113
  markDeclarationReached() {
5264
5114
  this.variable.initReached = true;
@@ -5324,17 +5174,18 @@ class Scope {
5324
5174
  - then the variable is still declared in the hoisted outer scope, but the initializer is assigned to the parameter
5325
5175
  - const, let, class, and function except in the cases above cannot redeclare anything
5326
5176
  */
5327
- addDeclaration(identifier, context, init, destructuredInitPath, kind) {
5177
+ addDeclaration(identifier, context, init, kind) {
5328
5178
  const name = identifier.name;
5329
5179
  const existingVariable = this.hoistedVariables?.get(name) || this.variables.get(name);
5330
5180
  if (existingVariable) {
5331
- if (kind === 'var' && existingVariable.kind === 'var') {
5181
+ const existingKind = existingVariable.kind;
5182
+ if (kind === 'var' && existingKind === 'var') {
5332
5183
  existingVariable.addDeclaration(identifier, init);
5333
5184
  return existingVariable;
5334
5185
  }
5335
5186
  context.error(logRedeclarationError(name), identifier.start);
5336
5187
  }
5337
- const newVariable = new LocalVariable(identifier.name, identifier, init, destructuredInitPath, context, kind);
5188
+ const newVariable = new LocalVariable(identifier.name, identifier, init, context, kind);
5338
5189
  this.variables.set(name, newVariable);
5339
5190
  return newVariable;
5340
5191
  }
@@ -5536,7 +5387,7 @@ class BlockScope extends ChildScope {
5536
5387
  constructor(parent) {
5537
5388
  super(parent, parent.context);
5538
5389
  }
5539
- addDeclaration(identifier, context, init, destructuredInitPath, kind) {
5390
+ addDeclaration(identifier, context, init, kind) {
5540
5391
  if (kind === 'var') {
5541
5392
  const name = identifier.name;
5542
5393
  const existingVariable = this.hoistedVariables?.get(name) || this.variables.get(name);
@@ -5548,7 +5399,7 @@ class BlockScope extends ChildScope {
5548
5399
  }
5549
5400
  return context.error(logRedeclarationError(name), identifier.start);
5550
5401
  }
5551
- const declaredVariable = this.parent.addDeclaration(identifier, context, init, destructuredInitPath, kind);
5402
+ const declaredVariable = this.parent.addDeclaration(identifier, context, init, kind);
5552
5403
  // Necessary to make sure the init is deoptimized for conditional declarations.
5553
5404
  // We cannot call deoptimizePath here.
5554
5405
  declaredVariable.markInitializersForDeoptimization();
@@ -5556,7 +5407,7 @@ class BlockScope extends ChildScope {
5556
5407
  this.addHoistedVariable(name, declaredVariable);
5557
5408
  return declaredVariable;
5558
5409
  }
5559
- return super.addDeclaration(identifier, context, init, destructuredInitPath, kind);
5410
+ return super.addDeclaration(identifier, context, init, kind);
5560
5411
  }
5561
5412
  }
5562
5413
 
@@ -5571,11 +5422,11 @@ class StaticBlock extends NodeBase {
5571
5422
  }
5572
5423
  return false;
5573
5424
  }
5574
- includePath(_path, context, includeChildrenRecursively) {
5425
+ include(context, includeChildrenRecursively) {
5575
5426
  this.included = true;
5576
5427
  for (const node of this.body) {
5577
5428
  if (includeChildrenRecursively || node.shouldBeIncluded(context))
5578
- node.includePath(UNKNOWN_PATH, context, includeChildrenRecursively);
5429
+ node.include(context, includeChildrenRecursively);
5579
5430
  }
5580
5431
  }
5581
5432
  render(code, options) {
@@ -5592,6 +5443,29 @@ function isStaticBlock(statement) {
5592
5443
  return statement.type === StaticBlock$1;
5593
5444
  }
5594
5445
 
5446
+ class ObjectMember extends ExpressionEntity {
5447
+ constructor(object, key) {
5448
+ super();
5449
+ this.object = object;
5450
+ this.key = key;
5451
+ }
5452
+ deoptimizeArgumentsOnInteractionAtPath(interaction, path, recursionTracker) {
5453
+ this.object.deoptimizeArgumentsOnInteractionAtPath(interaction, [this.key, ...path], recursionTracker);
5454
+ }
5455
+ deoptimizePath(path) {
5456
+ this.object.deoptimizePath([this.key, ...path]);
5457
+ }
5458
+ getLiteralValueAtPath(path, recursionTracker, origin) {
5459
+ return this.object.getLiteralValueAtPath([this.key, ...path], recursionTracker, origin);
5460
+ }
5461
+ getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin) {
5462
+ return this.object.getReturnExpressionWhenCalledAtPath([this.key, ...path], interaction, recursionTracker, origin);
5463
+ }
5464
+ hasEffectsOnInteractionAtPath(path, interaction, context) {
5465
+ return this.object.hasEffectsOnInteractionAtPath([this.key, ...path], interaction, context);
5466
+ }
5467
+ }
5468
+
5595
5469
  class ClassNode extends NodeBase {
5596
5470
  constructor() {
5597
5471
  super(...arguments);
@@ -5631,22 +5505,22 @@ class ClassNode extends NodeBase {
5631
5505
  false
5632
5506
  : this.getObjectEntity().hasEffectsOnInteractionAtPath(path, interaction, context);
5633
5507
  }
5634
- includePath(_path, context, includeChildrenRecursively) {
5508
+ include(context, includeChildrenRecursively) {
5635
5509
  if (!this.deoptimized)
5636
5510
  this.applyDeoptimizations();
5637
5511
  this.included = true;
5638
- this.superClass?.includePath(UNKNOWN_PATH, context, includeChildrenRecursively);
5639
- this.body.includePath(UNKNOWN_PATH, context, includeChildrenRecursively);
5512
+ this.superClass?.include(context, includeChildrenRecursively);
5513
+ this.body.include(context, includeChildrenRecursively);
5640
5514
  for (const decorator of this.decorators)
5641
- decorator.includePath(UNKNOWN_PATH, context, includeChildrenRecursively);
5515
+ decorator.include(context, includeChildrenRecursively);
5642
5516
  if (this.id) {
5643
5517
  this.id.markDeclarationReached();
5644
- this.id.includePath(UNKNOWN_PATH, createInclusionContext());
5518
+ this.id.include();
5645
5519
  }
5646
5520
  }
5647
5521
  initialise() {
5648
5522
  super.initialise();
5649
- this.id?.declare('class', EMPTY_PATH, this);
5523
+ this.id?.declare('class', this);
5650
5524
  for (const method of this.body.body) {
5651
5525
  if (method instanceof MethodDefinition && method.kind === 'constructor') {
5652
5526
  this.classConstructor = method;
@@ -5704,7 +5578,7 @@ class ClassNode extends NodeBase {
5704
5578
  staticProperties.unshift({
5705
5579
  key: 'prototype',
5706
5580
  kind: 'init',
5707
- property: new ObjectEntity(dynamicMethods, this.superClass ? new ObjectMember(this.superClass, ['prototype']) : OBJECT_PROTOTYPE)
5581
+ property: new ObjectEntity(dynamicMethods, this.superClass ? new ObjectMember(this.superClass, 'prototype') : OBJECT_PROTOTYPE)
5708
5582
  });
5709
5583
  return (this.objectEntity = new ObjectEntity(staticProperties, this.superClass || OBJECT_PROTOTYPE));
5710
5584
  }
@@ -5761,7 +5635,7 @@ class ClassDeclaration extends ClassNode {
5761
5635
 
5762
5636
  class ArgumentsVariable extends LocalVariable {
5763
5637
  constructor(context) {
5764
- super('arguments', null, UNKNOWN_EXPRESSION, EMPTY_PATH, context, 'other');
5638
+ super('arguments', null, UNKNOWN_EXPRESSION, context, 'other');
5765
5639
  this.deoptimizedArguments = [];
5766
5640
  }
5767
5641
  addArgumentToBeDeoptimized(argument) {
@@ -5775,8 +5649,8 @@ class ArgumentsVariable extends LocalVariable {
5775
5649
  hasEffectsOnInteractionAtPath(path, { type }) {
5776
5650
  return type !== INTERACTION_ACCESSED || path.length > 1;
5777
5651
  }
5778
- includePath(path, context) {
5779
- super.includePath(path, context);
5652
+ include() {
5653
+ super.include();
5780
5654
  for (const argument of this.deoptimizedArguments) {
5781
5655
  argument.deoptimizePath(UNKNOWN_PATH);
5782
5656
  }
@@ -5787,28 +5661,27 @@ class ArgumentsVariable extends LocalVariable {
5787
5661
  const MAX_TRACKED_INTERACTIONS = 20;
5788
5662
  const NO_INTERACTIONS = EMPTY_ARRAY;
5789
5663
  const UNKNOWN_DEOPTIMIZED_FIELD = new Set([UnknownKey]);
5790
- const EMPTY_PATH_TRACKER = new EntityPathTracker();
5664
+ const EMPTY_PATH_TRACKER = new PathTracker();
5791
5665
  const UNKNOWN_DEOPTIMIZED_ENTITY = new Set([UNKNOWN_EXPRESSION]);
5792
5666
  class ParameterVariable extends LocalVariable {
5793
- constructor(name, declarator, argumentPath, context) {
5794
- super(name, declarator, UNKNOWN_EXPRESSION, argumentPath, context, 'parameter');
5667
+ constructor(name, declarator, context) {
5668
+ super(name, declarator, UNKNOWN_EXPRESSION, context, 'parameter');
5795
5669
  this.deoptimizationInteractions = [];
5796
- this.deoptimizations = new EntityPathTracker();
5670
+ this.deoptimizations = new PathTracker();
5797
5671
  this.deoptimizedFields = new Set();
5798
- this.argumentsToBeDeoptimized = new Set();
5799
- this.expressionsDependingOnKnownValue = [];
5672
+ this.entitiesToBeDeoptimized = new Set();
5673
+ this.expressionsUseTheKnownValue = [];
5800
5674
  this.knownValue = null;
5801
5675
  this.knownValueLiteral = UnknownValue;
5802
5676
  this.frozenValue = null;
5803
5677
  }
5804
- addArgumentValue(entity) {
5805
- this.updateKnownValue(entity);
5678
+ addEntityToBeDeoptimized(entity) {
5806
5679
  if (entity === UNKNOWN_EXPRESSION) {
5807
5680
  // As unknown expressions fully deoptimize all interactions, we can clear
5808
5681
  // the interaction cache at this point provided we keep this optimization
5809
5682
  // in mind when adding new interactions
5810
- if (!this.argumentsToBeDeoptimized.has(UNKNOWN_EXPRESSION)) {
5811
- this.argumentsToBeDeoptimized.add(UNKNOWN_EXPRESSION);
5683
+ if (!this.entitiesToBeDeoptimized.has(UNKNOWN_EXPRESSION)) {
5684
+ this.entitiesToBeDeoptimized.add(UNKNOWN_EXPRESSION);
5812
5685
  for (const { interaction } of this.deoptimizationInteractions) {
5813
5686
  deoptimizeInteraction(interaction);
5814
5687
  }
@@ -5818,34 +5691,27 @@ class ParameterVariable extends LocalVariable {
5818
5691
  else if (this.deoptimizedFields.has(UnknownKey)) {
5819
5692
  // This means that we already deoptimized all interactions and no longer
5820
5693
  // track them
5821
- entity.deoptimizePath([...this.initPath, UnknownKey]);
5694
+ entity.deoptimizePath(UNKNOWN_PATH);
5822
5695
  }
5823
- else if (!this.argumentsToBeDeoptimized.has(entity)) {
5824
- this.argumentsToBeDeoptimized.add(entity);
5696
+ else if (!this.entitiesToBeDeoptimized.has(entity)) {
5697
+ this.entitiesToBeDeoptimized.add(entity);
5825
5698
  for (const field of this.deoptimizedFields) {
5826
- entity.deoptimizePath([...this.initPath, field]);
5699
+ entity.deoptimizePath([field]);
5827
5700
  }
5828
5701
  for (const { interaction, path } of this.deoptimizationInteractions) {
5829
- if (this.initPath.length + path.length > MAX_PATH_DEPTH) {
5830
- deoptimizeInteraction(interaction);
5831
- continue;
5832
- }
5833
- entity.deoptimizeArgumentsOnInteractionAtPath(interaction, [...this.initPath, ...path], SHARED_RECURSION_TRACKER);
5702
+ entity.deoptimizeArgumentsOnInteractionAtPath(interaction, path, SHARED_RECURSION_TRACKER);
5834
5703
  }
5835
5704
  }
5836
5705
  }
5837
- /** This says we should not make assumptions about the value of the parameter.
5838
- * This is different from deoptimization that will also cause argument values
5839
- * to be deoptimized. */
5840
5706
  markReassigned() {
5841
5707
  if (this.isReassigned) {
5842
5708
  return;
5843
5709
  }
5844
5710
  super.markReassigned();
5845
- for (const expression of this.expressionsDependingOnKnownValue) {
5711
+ for (const expression of this.expressionsUseTheKnownValue) {
5846
5712
  expression.deoptimizeCache();
5847
5713
  }
5848
- this.expressionsDependingOnKnownValue = EMPTY_ARRAY;
5714
+ this.expressionsUseTheKnownValue = EMPTY_ARRAY;
5849
5715
  }
5850
5716
  deoptimizeCache() {
5851
5717
  this.markReassigned();
@@ -5862,7 +5728,7 @@ class ParameterVariable extends LocalVariable {
5862
5728
  }
5863
5729
  if (this.knownValue === null) {
5864
5730
  this.knownValue = argument;
5865
- this.knownValueLiteral = argument.getLiteralValueAtPath(this.initPath, SHARED_RECURSION_TRACKER, this);
5731
+ this.knownValueLiteral = argument.getLiteralValueAtPath(EMPTY_PATH, SHARED_RECURSION_TRACKER, this);
5866
5732
  return;
5867
5733
  }
5868
5734
  // the same literal or identifier, do nothing
@@ -5878,7 +5744,7 @@ class ParameterVariable extends LocalVariable {
5878
5744
  return;
5879
5745
  }
5880
5746
  // add tracking for the new argument
5881
- const newValue = argument.getLiteralValueAtPath(this.initPath, SHARED_RECURSION_TRACKER, this);
5747
+ const newValue = argument.getLiteralValueAtPath(EMPTY_PATH, SHARED_RECURSION_TRACKER, this);
5882
5748
  if (newValue !== oldValue) {
5883
5749
  this.markReassigned();
5884
5750
  }
@@ -5896,31 +5762,24 @@ class ParameterVariable extends LocalVariable {
5896
5762
  return this.frozenValue;
5897
5763
  }
5898
5764
  getLiteralValueAtPath(path, recursionTracker, origin) {
5899
- if (this.isReassigned || path.length + this.initPath.length > MAX_PATH_DEPTH) {
5765
+ if (this.isReassigned) {
5900
5766
  return UnknownValue;
5901
5767
  }
5902
5768
  const knownValue = this.getKnownValue();
5903
- this.expressionsDependingOnKnownValue.push(origin);
5904
- return recursionTracker.withTrackedEntityAtPath(path, knownValue, () => knownValue.getLiteralValueAtPath([...this.initPath, ...path], recursionTracker, origin), UnknownValue);
5769
+ this.expressionsUseTheKnownValue.push(origin);
5770
+ return recursionTracker.withTrackedEntityAtPath(path, knownValue, () => knownValue.getLiteralValueAtPath(path, recursionTracker, origin), UnknownValue);
5905
5771
  }
5906
5772
  hasEffectsOnInteractionAtPath(path, interaction, context) {
5907
- const { type } = interaction;
5908
- if (this.isReassigned ||
5909
- type === INTERACTION_ASSIGNED ||
5910
- path.length + this.initPath.length > MAX_PATH_DEPTH) {
5773
+ if (this.isReassigned || interaction.type === INTERACTION_ASSIGNED) {
5911
5774
  return super.hasEffectsOnInteractionAtPath(path, interaction, context);
5912
5775
  }
5913
- return (!(type === INTERACTION_CALLED
5914
- ? (interaction.withNew
5915
- ? context.instantiated
5916
- : context.called).trackEntityAtPathAndGetIfTracked(path, interaction.args, this)
5917
- : context.accessed.trackEntityAtPathAndGetIfTracked(path, this)) &&
5918
- this.getKnownValue().hasEffectsOnInteractionAtPath([...this.initPath, ...path], interaction, context));
5776
+ const knownValue = this.getKnownValue();
5777
+ return knownValue.hasEffectsOnInteractionAtPath(path, interaction, context);
5919
5778
  }
5920
5779
  deoptimizeArgumentsOnInteractionAtPath(interaction, path) {
5921
5780
  // For performance reasons, we fully deoptimize all deeper interactions
5922
5781
  if (path.length >= 2 ||
5923
- this.argumentsToBeDeoptimized.has(UNKNOWN_EXPRESSION) ||
5782
+ this.entitiesToBeDeoptimized.has(UNKNOWN_EXPRESSION) ||
5924
5783
  this.deoptimizationInteractions.length >= MAX_TRACKED_INTERACTIONS ||
5925
5784
  (path.length === 1 &&
5926
5785
  (this.deoptimizedFields.has(UnknownKey) ||
@@ -5929,10 +5788,10 @@ class ParameterVariable extends LocalVariable {
5929
5788
  return;
5930
5789
  }
5931
5790
  if (!this.deoptimizations.trackEntityAtPathAndGetIfTracked(path, interaction.args)) {
5932
- for (const entity of this.argumentsToBeDeoptimized) {
5933
- entity.deoptimizeArgumentsOnInteractionAtPath(interaction, [...this.initPath, ...path], SHARED_RECURSION_TRACKER);
5791
+ for (const entity of this.entitiesToBeDeoptimized) {
5792
+ entity.deoptimizeArgumentsOnInteractionAtPath(interaction, path, SHARED_RECURSION_TRACKER);
5934
5793
  }
5935
- if (!this.argumentsToBeDeoptimized.has(UNKNOWN_EXPRESSION)) {
5794
+ if (!this.entitiesToBeDeoptimized.has(UNKNOWN_EXPRESSION)) {
5936
5795
  this.deoptimizationInteractions.push({
5937
5796
  interaction,
5938
5797
  path
@@ -5953,17 +5812,17 @@ class ParameterVariable extends LocalVariable {
5953
5812
  return;
5954
5813
  }
5955
5814
  this.deoptimizedFields.add(key);
5956
- for (const entity of this.argumentsToBeDeoptimized) {
5815
+ for (const entity of this.entitiesToBeDeoptimized) {
5957
5816
  // We do not need a recursion tracker here as we already track whether
5958
5817
  // this field is deoptimized
5959
- entity.deoptimizePath([...this.initPath, key]);
5818
+ entity.deoptimizePath([key]);
5960
5819
  }
5961
5820
  if (key === UnknownKey) {
5962
5821
  // save some memory
5963
5822
  this.deoptimizationInteractions = NO_INTERACTIONS;
5964
5823
  this.deoptimizations = EMPTY_PATH_TRACKER;
5965
5824
  this.deoptimizedFields = UNKNOWN_DEOPTIMIZED_FIELD;
5966
- this.argumentsToBeDeoptimized = UNKNOWN_DEOPTIMIZED_ENTITY;
5825
+ this.entitiesToBeDeoptimized = UNKNOWN_DEOPTIMIZED_ENTITY;
5967
5826
  }
5968
5827
  }
5969
5828
  getReturnExpressionWhenCalledAtPath(path) {
@@ -5978,14 +5837,11 @@ class ParameterVariable extends LocalVariable {
5978
5837
  }
5979
5838
  return UNKNOWN_RETURN_EXPRESSION;
5980
5839
  }
5981
- includeArgumentPaths(entity, context) {
5982
- this.includedPathTracker.includeAllPaths(entity, context, this.initPath);
5983
- }
5984
5840
  }
5985
5841
 
5986
5842
  class ThisVariable extends ParameterVariable {
5987
5843
  constructor(context) {
5988
- super('this', null, EMPTY_PATH, context);
5844
+ super('this', null, context);
5989
5845
  }
5990
5846
  hasEffectsOnInteractionAtPath(path, interaction, context) {
5991
5847
  return (context.replacedVariableInits.get(this) || UNKNOWN_EXPRESSION).hasEffectsOnInteractionAtPath(path, interaction, context);
@@ -5997,7 +5853,7 @@ class CatchBodyScope extends ChildScope {
5997
5853
  super(parent, parent.context);
5998
5854
  this.parent = parent;
5999
5855
  }
6000
- addDeclaration(identifier, context, init, destructuredInitPath, kind) {
5856
+ addDeclaration(identifier, context, init, kind) {
6001
5857
  if (kind === 'var') {
6002
5858
  const name = identifier.name;
6003
5859
  const existingVariable = this.hoistedVariables?.get(name) || this.variables.get(name);
@@ -6010,7 +5866,7 @@ class CatchBodyScope extends ChildScope {
6010
5866
  // the assignment actually goes to the parameter and the var is
6011
5867
  // hoisted without assignment. Locally, it is shadowed by the
6012
5868
  // parameter
6013
- const declaredVariable = this.parent.parent.addDeclaration(identifier, context, UNDEFINED_EXPRESSION, destructuredInitPath, kind);
5869
+ const declaredVariable = this.parent.parent.addDeclaration(identifier, context, UNDEFINED_EXPRESSION, kind);
6014
5870
  // To avoid the need to rewrite the declaration, we link the variable
6015
5871
  // names. If we ever implement a logic that splits initialization and
6016
5872
  // assignment for hoisted vars, the "renderLikeHoisted" logic can be
@@ -6029,7 +5885,7 @@ class CatchBodyScope extends ChildScope {
6029
5885
  return context.error(logRedeclarationError(name), identifier.start);
6030
5886
  }
6031
5887
  // We only add parameters to parameter scopes
6032
- const declaredVariable = this.parent.parent.addDeclaration(identifier, context, init, destructuredInitPath, kind);
5888
+ const declaredVariable = this.parent.parent.addDeclaration(identifier, context, init, kind);
6033
5889
  // Necessary to make sure the init is deoptimized for conditional declarations.
6034
5890
  // We cannot call deoptimizePath here.
6035
5891
  declaredVariable.markInitializersForDeoptimization();
@@ -6037,7 +5893,7 @@ class CatchBodyScope extends ChildScope {
6037
5893
  this.addHoistedVariable(name, declaredVariable);
6038
5894
  return declaredVariable;
6039
5895
  }
6040
- return super.addDeclaration(identifier, context, init, destructuredInitPath, kind);
5896
+ return super.addDeclaration(identifier, context, init, kind);
6041
5897
  }
6042
5898
  }
6043
5899
 
@@ -6047,7 +5903,7 @@ class FunctionBodyScope extends ChildScope {
6047
5903
  }
6048
5904
  // There is stuff that is only allowed in function scopes, i.e. functions can
6049
5905
  // be redeclared, functions and var can redeclare each other
6050
- addDeclaration(identifier, context, init, destructuredInitPath, kind) {
5906
+ addDeclaration(identifier, context, init, kind) {
6051
5907
  const name = identifier.name;
6052
5908
  const existingVariable = this.hoistedVariables?.get(name) || this.variables.get(name);
6053
5909
  if (existingVariable) {
@@ -6059,7 +5915,7 @@ class FunctionBodyScope extends ChildScope {
6059
5915
  }
6060
5916
  context.error(logRedeclarationError(name), identifier.start);
6061
5917
  }
6062
- const newVariable = new LocalVariable(identifier.name, identifier, init, destructuredInitPath, context, kind);
5918
+ const newVariable = new LocalVariable(identifier.name, identifier, init, context, kind);
6063
5919
  this.variables.set(name, newVariable);
6064
5920
  return newVariable;
6065
5921
  }
@@ -6068,21 +5924,21 @@ class FunctionBodyScope extends ChildScope {
6068
5924
  class ParameterScope extends ChildScope {
6069
5925
  constructor(parent, isCatchScope) {
6070
5926
  super(parent, parent.context);
6071
- this.hasRest = false;
6072
5927
  this.parameters = [];
5928
+ this.hasRest = false;
6073
5929
  this.bodyScope = isCatchScope ? new CatchBodyScope(this) : new FunctionBodyScope(this);
6074
5930
  }
6075
5931
  /**
6076
5932
  * Adds a parameter to this scope. Parameters must be added in the correct
6077
5933
  * order, i.e. from left to right.
6078
5934
  */
6079
- addParameterDeclaration(identifier, argumentPath) {
5935
+ addParameterDeclaration(identifier) {
6080
5936
  const { name, start } = identifier;
6081
5937
  const existingParameter = this.variables.get(name);
6082
5938
  if (existingParameter) {
6083
5939
  return this.context.error(logDuplicateArgumentNameError(name), start);
6084
5940
  }
6085
- const variable = new ParameterVariable(name, identifier, argumentPath, this.context);
5941
+ const variable = new ParameterVariable(name, identifier, this.context);
6086
5942
  this.variables.set(name, variable);
6087
5943
  // We also add it to the body scope to detect name conflicts with local
6088
5944
  // variables. We still need the intermediate scope, though, as parameter
@@ -6100,54 +5956,43 @@ class ParameterScope extends ChildScope {
6100
5956
  }
6101
5957
  this.hasRest = hasRest;
6102
5958
  }
6103
- includeCallArguments(context, interaction) {
5959
+ includeCallArguments(context, parameters) {
6104
5960
  let calledFromTryStatement = false;
6105
5961
  let argumentIncluded = false;
6106
5962
  const restParameter = this.hasRest && this.parameters[this.parameters.length - 1];
6107
- const { args } = interaction;
6108
- let lastExplicitlyIncludedIndex = args.length - 1;
6109
- // If there is a SpreadElement, we need to include all arguments after it
6110
- // because we no longer know which argument corresponds to which parameter.
6111
- for (let argumentIndex = 1; argumentIndex < args.length; argumentIndex++) {
6112
- if (args[argumentIndex] instanceof SpreadElement && !argumentIncluded) {
6113
- argumentIncluded = true;
6114
- lastExplicitlyIncludedIndex = argumentIndex - 1;
6115
- }
6116
- if (argumentIncluded) {
6117
- args[argumentIndex].includePath(UNKNOWN_PATH, context, false);
5963
+ for (const checkedArgument of parameters) {
5964
+ if (checkedArgument instanceof SpreadElement) {
5965
+ for (const argument of parameters) {
5966
+ argument.include(context, false);
5967
+ }
5968
+ break;
6118
5969
  }
6119
5970
  }
6120
- // Now we go backwards either starting from the last argument or before the
6121
- // first SpreadElement to ensure all arguments before are included as needed
6122
- for (let index = lastExplicitlyIncludedIndex; index >= 1; index--) {
6123
- const parameterVariables = this.parameters[index - 1] || restParameter;
6124
- const argument = args[index];
5971
+ for (let index = parameters.length - 1; index >= 0; index--) {
5972
+ const parameterVariables = this.parameters[index] || restParameter;
5973
+ const argument = parameters[index];
6125
5974
  if (parameterVariables) {
6126
5975
  calledFromTryStatement = false;
6127
5976
  if (parameterVariables.length === 0) {
6128
- // handle empty destructuring to avoid destructuring undefined
5977
+ // handle empty destructuring
6129
5978
  argumentIncluded = true;
6130
5979
  }
6131
5980
  else {
6132
5981
  for (const variable of parameterVariables) {
6133
- if (variable.calledFromTryStatement) {
6134
- calledFromTryStatement = true;
6135
- }
6136
5982
  if (variable.included) {
6137
5983
  argumentIncluded = true;
6138
- if (calledFromTryStatement) {
6139
- argument.includePath(UNKNOWN_PATH, context, true);
6140
- }
6141
- else {
6142
- variable.includeArgumentPaths(argument, context);
6143
- }
5984
+ }
5985
+ if (variable.calledFromTryStatement) {
5986
+ calledFromTryStatement = true;
6144
5987
  }
6145
5988
  }
6146
5989
  }
6147
5990
  }
6148
- if (!argument.included && (argumentIncluded || argument.shouldBeIncluded(context))) {
5991
+ if (!argumentIncluded && argument.shouldBeIncluded(context)) {
6149
5992
  argumentIncluded = true;
6150
- argument.includePath(EMPTY_PATH, context, calledFromTryStatement);
5993
+ }
5994
+ if (argumentIncluded) {
5995
+ argument.include(context, calledFromTryStatement);
6151
5996
  }
6152
5997
  }
6153
5998
  }
@@ -6162,61 +6007,11 @@ class ReturnValueScope extends ParameterScope {
6162
6007
  addReturnExpression(expression) {
6163
6008
  this.returnExpressions.push(expression);
6164
6009
  }
6165
- deoptimizeArgumentsOnCall(interaction) {
6166
- const { parameters } = this;
6167
- const { args } = interaction;
6168
- let position = 0;
6169
- for (; position < args.length - 1; position++) {
6170
- // Only the "this" argument arg[0] can be null
6171
- const argument = args[position + 1];
6172
- if (argument instanceof SpreadElement) {
6173
- // This deoptimizes the current and remaining parameters and arguments
6174
- for (; position < parameters.length; position++) {
6175
- args[position + 1]?.deoptimizePath(UNKNOWN_PATH);
6176
- parameters[position].forEach(variable => variable.markReassigned());
6177
- }
6178
- break;
6179
- }
6180
- if (this.hasRest && position >= parameters.length - 1) {
6181
- argument.deoptimizePath(UNKNOWN_PATH);
6182
- }
6183
- else {
6184
- const variables = parameters[position];
6185
- if (variables) {
6186
- for (const variable of variables) {
6187
- variable.addArgumentValue(argument);
6188
- }
6189
- }
6190
- this.addArgumentToBeDeoptimized(argument);
6191
- }
6192
- }
6193
- for (; position < parameters.length; position++) {
6194
- for (const variable of parameters[position]) {
6195
- variable.addArgumentValue(UNDEFINED_EXPRESSION);
6196
- }
6197
- }
6198
- }
6199
6010
  getReturnExpression() {
6200
6011
  if (this.returnExpression === null)
6201
6012
  this.updateReturnExpression();
6202
6013
  return this.returnExpression;
6203
6014
  }
6204
- deoptimizeAllParameters() {
6205
- for (const parameter of this.parameters) {
6206
- for (const variable of parameter) {
6207
- variable.deoptimizePath(UNKNOWN_PATH);
6208
- variable.markReassigned();
6209
- }
6210
- }
6211
- }
6212
- reassignAllParameters() {
6213
- for (const parameter of this.parameters) {
6214
- for (const variable of parameter) {
6215
- variable.markReassigned();
6216
- }
6217
- }
6218
- }
6219
- addArgumentToBeDeoptimized(_argument) { }
6220
6015
  updateReturnExpression() {
6221
6016
  if (this.returnExpressions.length === 1) {
6222
6017
  this.returnExpression = this.returnExpressions[0];
@@ -6232,26 +6027,24 @@ class ReturnValueScope extends ParameterScope {
6232
6027
 
6233
6028
  class FunctionScope extends ReturnValueScope {
6234
6029
  constructor(parent) {
6235
- super(parent, false);
6236
6030
  const { context } = parent;
6031
+ super(parent, false);
6237
6032
  this.variables.set('arguments', (this.argumentsVariable = new ArgumentsVariable(context)));
6238
6033
  this.variables.set('this', (this.thisVariable = new ThisVariable(context)));
6239
6034
  }
6240
6035
  findLexicalBoundary() {
6241
6036
  return this;
6242
6037
  }
6243
- includeCallArguments(context, interaction) {
6244
- super.includeCallArguments(context, interaction);
6038
+ includeCallArguments(context, parameters) {
6039
+ super.includeCallArguments(context, parameters);
6245
6040
  if (this.argumentsVariable.included) {
6246
- const { args } = interaction;
6247
- for (let argumentIndex = 1; argumentIndex < args.length; argumentIndex++) {
6248
- args[argumentIndex]?.includePath(UNKNOWN_PATH, context, false);
6041
+ for (const argument of parameters) {
6042
+ if (!argument.included) {
6043
+ argument.include(context, false);
6044
+ }
6249
6045
  }
6250
6046
  }
6251
6047
  }
6252
- addArgumentToBeDeoptimized(argument) {
6253
- this.argumentsVariable.addArgumentToBeDeoptimized(argument);
6254
- }
6255
6048
  }
6256
6049
 
6257
6050
  class ExpressionStatement extends NodeBase {
@@ -6317,7 +6110,7 @@ class BlockStatement extends NodeBase {
6317
6110
  }
6318
6111
  return false;
6319
6112
  }
6320
- includePath(_path, context, includeChildrenRecursively) {
6113
+ include(context, includeChildrenRecursively) {
6321
6114
  if (!(this.deoptimizeBody && this.directlyIncluded)) {
6322
6115
  this.included = true;
6323
6116
  this.directlyIncluded = true;
@@ -6325,7 +6118,7 @@ class BlockStatement extends NodeBase {
6325
6118
  includeChildrenRecursively = true;
6326
6119
  for (const node of this.body) {
6327
6120
  if (includeChildrenRecursively || node.shouldBeIncluded(context))
6328
- node.includePath(UNKNOWN_PATH, context, includeChildrenRecursively);
6121
+ node.include(context, includeChildrenRecursively);
6329
6122
  }
6330
6123
  }
6331
6124
  }
@@ -6354,12 +6147,9 @@ class RestElement extends NodeBase {
6354
6147
  addExportedVariables(variables, exportNamesByVariable) {
6355
6148
  this.argument.addExportedVariables(variables, exportNamesByVariable);
6356
6149
  }
6357
- declare(kind, destructuredInitPath, init) {
6150
+ declare(kind, init) {
6358
6151
  this.declarationInit = init;
6359
- return this.argument.declare(kind, getIncludedPatternPath$1(destructuredInitPath), init);
6360
- }
6361
- deoptimizeAssignment(destructuredInitPath, init) {
6362
- this.argument.deoptimizeAssignment(getIncludedPatternPath$1(destructuredInitPath), init);
6152
+ return this.argument.declare(kind, UNKNOWN_EXPRESSION);
6363
6153
  }
6364
6154
  deoptimizePath(path) {
6365
6155
  if (path.length === 0) {
@@ -6370,19 +6160,6 @@ class RestElement extends NodeBase {
6370
6160
  return (path.length > 0 ||
6371
6161
  this.argument.hasEffectsOnInteractionAtPath(EMPTY_PATH, interaction, context));
6372
6162
  }
6373
- hasEffectsWhenDestructuring(context, destructuredInitPath, init) {
6374
- return this.argument.hasEffectsWhenDestructuring(context, getIncludedPatternPath$1(destructuredInitPath), init);
6375
- }
6376
- includeDestructuredIfNecessary(context, destructuredInitPath, init) {
6377
- return (this.included =
6378
- this.argument.includeDestructuredIfNecessary(context, getIncludedPatternPath$1(destructuredInitPath), init) || this.included);
6379
- }
6380
- includePath(_path, context, includeChildrenRecursively) {
6381
- this.included = true;
6382
- // This should just include the identifier, its properties should be
6383
- // included where the variable is used.
6384
- this.argument.includePath(EMPTY_PATH, context, includeChildrenRecursively);
6385
- }
6386
6163
  markDeclarationReached() {
6387
6164
  this.argument.markDeclarationReached();
6388
6165
  }
@@ -6394,15 +6171,12 @@ class RestElement extends NodeBase {
6394
6171
  }
6395
6172
  }
6396
6173
  }
6397
- const getIncludedPatternPath$1 = (destructuredInitPath) => destructuredInitPath.at(-1) === UnknownKey
6398
- ? destructuredInitPath
6399
- : [...destructuredInitPath, UnknownKey];
6400
6174
 
6401
6175
  class FunctionBase extends NodeBase {
6402
6176
  constructor() {
6403
6177
  super(...arguments);
6178
+ this.objectEntity = null;
6404
6179
  this.parameterVariableValuesDeoptimized = false;
6405
- this.includeCallArguments = this.scope.includeCallArguments.bind(this.scope);
6406
6180
  }
6407
6181
  get async() {
6408
6182
  return isFlagSet(this.flags, 256 /* Flag.async */);
@@ -6422,9 +6196,53 @@ class FunctionBase extends NodeBase {
6422
6196
  set generator(value) {
6423
6197
  this.flags = setFlag(this.flags, 4194304 /* Flag.generator */, value);
6424
6198
  }
6199
+ updateParameterVariableValues(_arguments) {
6200
+ for (let position = 0; position < this.params.length; position++) {
6201
+ const parameter = this.params[position];
6202
+ if (!(parameter instanceof Identifier)) {
6203
+ continue;
6204
+ }
6205
+ const parameterVariable = parameter.variable;
6206
+ const argument = _arguments[position + 1] ?? UNDEFINED_EXPRESSION;
6207
+ parameterVariable.updateKnownValue(argument);
6208
+ }
6209
+ }
6210
+ deoptimizeParameterVariableValues() {
6211
+ for (const parameter of this.params) {
6212
+ if (parameter instanceof Identifier) {
6213
+ const parameterVariable = parameter.variable;
6214
+ parameterVariable.markReassigned();
6215
+ }
6216
+ }
6217
+ }
6425
6218
  deoptimizeArgumentsOnInteractionAtPath(interaction, path, recursionTracker) {
6426
- if (interaction.type === INTERACTION_CALLED && path.length === 0) {
6427
- this.scope.deoptimizeArgumentsOnCall(interaction);
6219
+ if (interaction.type === INTERACTION_CALLED) {
6220
+ const { parameters } = this.scope;
6221
+ const { args } = interaction;
6222
+ let hasRest = false;
6223
+ for (let position = 0; position < args.length - 1; position++) {
6224
+ const parameter = this.params[position];
6225
+ // Only the "this" argument arg[0] can be null
6226
+ const argument = args[position + 1];
6227
+ if (argument instanceof SpreadElement) {
6228
+ this.deoptimizeParameterVariableValues();
6229
+ }
6230
+ if (hasRest || parameter instanceof RestElement) {
6231
+ hasRest = true;
6232
+ argument.deoptimizePath(UNKNOWN_PATH);
6233
+ }
6234
+ else if (parameter instanceof Identifier) {
6235
+ parameters[position][0].addEntityToBeDeoptimized(argument);
6236
+ this.addArgumentToBeDeoptimized(argument);
6237
+ }
6238
+ else if (parameter) {
6239
+ argument.deoptimizePath(UNKNOWN_PATH);
6240
+ }
6241
+ else {
6242
+ this.addArgumentToBeDeoptimized(argument);
6243
+ }
6244
+ }
6245
+ this.updateParameterVariableValues(args);
6428
6246
  }
6429
6247
  else {
6430
6248
  this.getObjectEntity().deoptimizeArgumentsOnInteractionAtPath(interaction, path, recursionTracker);
@@ -6436,7 +6254,12 @@ class FunctionBase extends NodeBase {
6436
6254
  // A reassignment of UNKNOWN_PATH is considered equivalent to having lost track
6437
6255
  // which means the return expression and parameters need to be reassigned
6438
6256
  this.scope.getReturnExpression().deoptimizePath(UNKNOWN_PATH);
6439
- this.scope.deoptimizeAllParameters();
6257
+ for (const parameterList of this.scope.parameters) {
6258
+ for (const parameter of parameterList) {
6259
+ parameter.deoptimizePath(UNKNOWN_PATH);
6260
+ parameter.markReassigned();
6261
+ }
6262
+ }
6440
6263
  }
6441
6264
  }
6442
6265
  getLiteralValueAtPath(path, recursionTracker, origin) {
@@ -6474,13 +6297,8 @@ class FunctionBase extends NodeBase {
6474
6297
  return true;
6475
6298
  }
6476
6299
  }
6477
- const { propertyReadSideEffects } = this.scope.context.options
6478
- .treeshake;
6479
- for (let index = 0; index < this.params.length; index++) {
6480
- const parameter = this.params[index];
6481
- if (parameter.hasEffects(context) ||
6482
- (propertyReadSideEffects &&
6483
- parameter.hasEffectsWhenDestructuring(context, EMPTY_PATH, interaction.args[index + 1] || UNDEFINED_EXPRESSION)))
6300
+ for (const parameter of this.params) {
6301
+ if (parameter.hasEffects(context))
6484
6302
  return true;
6485
6303
  }
6486
6304
  return false;
@@ -6498,19 +6316,22 @@ class FunctionBase extends NodeBase {
6498
6316
  }
6499
6317
  return variable?.getOnlyFunctionCallUsed() ?? false;
6500
6318
  }
6501
- includePath(_path, context, includeChildrenRecursively) {
6502
- if (!(this.parameterVariableValuesDeoptimized || this.onlyFunctionCallUsed())) {
6319
+ include(context, includeChildrenRecursively) {
6320
+ if (!this.parameterVariableValuesDeoptimized && !this.onlyFunctionCallUsed()) {
6503
6321
  this.parameterVariableValuesDeoptimized = true;
6504
- this.scope.reassignAllParameters();
6322
+ this.deoptimizeParameterVariableValues();
6505
6323
  }
6506
6324
  if (!this.deoptimized)
6507
6325
  this.applyDeoptimizations();
6508
6326
  this.included = true;
6509
6327
  const { brokenFlow } = context;
6510
6328
  context.brokenFlow = false;
6511
- this.body.includePath(UNKNOWN_PATH, context, includeChildrenRecursively);
6329
+ this.body.include(context, includeChildrenRecursively);
6512
6330
  context.brokenFlow = brokenFlow;
6513
6331
  }
6332
+ includeCallArguments(context, parameters) {
6333
+ this.scope.includeCallArguments(context, parameters);
6334
+ }
6514
6335
  initialise() {
6515
6336
  super.initialise();
6516
6337
  if (this.body instanceof BlockStatement) {
@@ -6532,10 +6353,11 @@ class FunctionBase extends NodeBase {
6532
6353
  // so that the scope already knows all parameters and can detect conflicts
6533
6354
  // when parsing the body.
6534
6355
  const parameters = (this.params = params.map((parameter) => new (context.getNodeConstructor(parameter.type))(this, scope).parseNode(parameter)));
6535
- scope.addParameterVariables(parameters.map(parameter => parameter.declare('parameter', EMPTY_PATH, UNKNOWN_EXPRESSION)), parameters[parameters.length - 1] instanceof RestElement);
6356
+ scope.addParameterVariables(parameters.map(parameter => parameter.declare('parameter', UNKNOWN_EXPRESSION)), parameters[parameters.length - 1] instanceof RestElement);
6536
6357
  this.body = new (context.getNodeConstructor(body.type))(this, bodyScope).parseNode(body);
6537
6358
  return super.parseNode(esTreeNode);
6538
6359
  }
6360
+ addArgumentToBeDeoptimized(_argument) { }
6539
6361
  applyDeoptimizations() { }
6540
6362
  }
6541
6363
  FunctionBase.prototype.preventChildBlockScope = true;
@@ -6550,13 +6372,13 @@ class FunctionNode extends FunctionBase {
6550
6372
  this.constructedEntity = new ObjectEntity(Object.create(null), OBJECT_PROTOTYPE);
6551
6373
  // This makes sure that all deoptimizations of "this" are applied to the
6552
6374
  // constructed entity.
6553
- this.scope.thisVariable.addArgumentValue(this.constructedEntity);
6375
+ this.scope.thisVariable.addEntityToBeDeoptimized(this.constructedEntity);
6554
6376
  }
6555
6377
  deoptimizeArgumentsOnInteractionAtPath(interaction, path, recursionTracker) {
6556
6378
  super.deoptimizeArgumentsOnInteractionAtPath(interaction, path, recursionTracker);
6557
6379
  if (interaction.type === INTERACTION_CALLED && path.length === 0 && interaction.args[0]) {
6558
6380
  // args[0] is the "this" argument
6559
- this.scope.thisVariable.addArgumentValue(interaction.args[0]);
6381
+ this.scope.thisVariable.addEntityToBeDeoptimized(interaction.args[0]);
6560
6382
  }
6561
6383
  }
6562
6384
  hasEffects(context) {
@@ -6597,19 +6419,22 @@ class FunctionNode extends FunctionBase {
6597
6419
  }
6598
6420
  return false;
6599
6421
  }
6600
- includePath(path, context, includeChildrenRecursively) {
6601
- super.includePath(path, context, includeChildrenRecursively);
6602
- this.id?.includePath(UNKNOWN_PATH, createInclusionContext());
6422
+ include(context, includeChildrenRecursively) {
6423
+ super.include(context, includeChildrenRecursively);
6424
+ this.id?.include();
6603
6425
  const hasArguments = this.scope.argumentsVariable.included;
6604
6426
  for (const parameter of this.params) {
6605
6427
  if (!(parameter instanceof Identifier) || hasArguments) {
6606
- parameter.includePath(UNKNOWN_PATH, context, includeChildrenRecursively);
6428
+ parameter.include(context, includeChildrenRecursively);
6607
6429
  }
6608
6430
  }
6609
6431
  }
6610
6432
  initialise() {
6611
6433
  super.initialise();
6612
- this.id?.declare('function', EMPTY_PATH, this);
6434
+ this.id?.declare('function', this);
6435
+ }
6436
+ addArgumentToBeDeoptimized(argument) {
6437
+ this.scope.argumentsVariable.addArgumentToBeDeoptimized(argument);
6613
6438
  }
6614
6439
  getObjectEntity() {
6615
6440
  if (this.objectEntity !== null) {
@@ -6658,11 +6483,10 @@ function getFunctionIdInsertPosition(code, start) {
6658
6483
  return declarationEnd + generatorStarPos + 1;
6659
6484
  }
6660
6485
  class ExportDefaultDeclaration extends NodeBase {
6661
- includePath(path, context, includeChildrenRecursively) {
6662
- this.included = true;
6663
- this.declaration.includePath(path, context, includeChildrenRecursively);
6486
+ include(context, includeChildrenRecursively) {
6487
+ super.include(context, includeChildrenRecursively);
6664
6488
  if (includeChildrenRecursively) {
6665
- this.scope.context.includeVariableInModule(this.variable, path);
6489
+ this.scope.context.includeVariableInModule(this.variable);
6666
6490
  }
6667
6491
  }
6668
6492
  initialise() {
@@ -7024,6 +6848,8 @@ function getChainElementLiteralValueAtPath(element, object, path, recursionTrack
7024
6848
  return element.getLiteralValueAtPath(path, recursionTracker, origin);
7025
6849
  }
7026
6850
 
6851
+ // To avoid infinite recursions
6852
+ const MAX_PATH_DEPTH = 7;
7027
6853
  function getResolvablePropertyKey(memberExpression) {
7028
6854
  return memberExpression.computed
7029
6855
  ? getResolvableComputedPropertyKey(memberExpression.property)
@@ -7129,10 +6955,6 @@ class MemberExpression extends NodeBase {
7129
6955
  }
7130
6956
  }
7131
6957
  }
7132
- deoptimizeAssignment(destructuredInitPath, init) {
7133
- this.deoptimizePath(EMPTY_PATH);
7134
- init.deoptimizePath([...destructuredInitPath, UnknownKey]);
7135
- }
7136
6958
  deoptimizeCache() {
7137
6959
  const { expressionsToBeDeoptimized, object } = this;
7138
6960
  this.expressionsToBeDeoptimized = EMPTY_ARRAY;
@@ -7148,13 +6970,11 @@ class MemberExpression extends NodeBase {
7148
6970
  if (this.variable) {
7149
6971
  this.variable.deoptimizePath(path);
7150
6972
  }
7151
- else if (!this.isUndefined) {
6973
+ else if (!this.isUndefined && path.length < MAX_PATH_DEPTH) {
7152
6974
  const propertyKey = this.getPropertyKey();
7153
6975
  this.object.deoptimizePath([
7154
6976
  propertyKey === UnknownKey ? UnknownNonAccessorKey : propertyKey,
7155
- ...(path.length < MAX_PATH_DEPTH
7156
- ? path
7157
- : [...path.slice(0, MAX_PATH_DEPTH), UnknownKey])
6977
+ ...path
7158
6978
  ]);
7159
6979
  }
7160
6980
  }
@@ -7239,47 +7059,28 @@ class MemberExpression extends NodeBase {
7239
7059
  }
7240
7060
  return true;
7241
7061
  }
7242
- hasEffectsWhenDestructuring(context, destructuredInitPath, init) {
7243
- return (destructuredInitPath.length > 0 &&
7244
- init.hasEffectsOnInteractionAtPath(destructuredInitPath, NODE_INTERACTION_UNKNOWN_ACCESS, context));
7245
- }
7246
- includePath(path, context, includeChildrenRecursively) {
7062
+ include(context, includeChildrenRecursively) {
7247
7063
  if (!this.deoptimized)
7248
7064
  this.applyDeoptimizations();
7249
- this.includeProperties(path, [
7250
- this.getPropertyKey(),
7251
- ...(path.length < MAX_PATH_DEPTH
7252
- ? path
7253
- : [...path.slice(0, MAX_PATH_DEPTH), UnknownKey])
7254
- ], context, includeChildrenRecursively);
7065
+ this.includeProperties(context, includeChildrenRecursively);
7255
7066
  }
7256
7067
  includeAsAssignmentTarget(context, includeChildrenRecursively, deoptimizeAccess) {
7257
7068
  if (!this.assignmentDeoptimized)
7258
7069
  this.applyAssignmentDeoptimization();
7259
7070
  if (deoptimizeAccess) {
7260
- this.includePath([this.getPropertyKey()], context, includeChildrenRecursively);
7071
+ this.include(context, includeChildrenRecursively);
7261
7072
  }
7262
7073
  else {
7263
- this.includeProperties(EMPTY_PATH, [this.getPropertyKey()], context, includeChildrenRecursively);
7074
+ this.includeProperties(context, includeChildrenRecursively);
7264
7075
  }
7265
7076
  }
7266
- includeCallArguments(context, interaction) {
7077
+ includeCallArguments(context, parameters) {
7267
7078
  if (this.variable) {
7268
- this.variable.includeCallArguments(context, interaction);
7079
+ this.variable.includeCallArguments(context, parameters);
7269
7080
  }
7270
7081
  else {
7271
- super.includeCallArguments(context, interaction);
7272
- }
7273
- }
7274
- includeDestructuredIfNecessary(context, destructuredInitPath, init) {
7275
- if ((this.included ||=
7276
- destructuredInitPath.length > 0 &&
7277
- !context.brokenFlow &&
7278
- init.hasEffectsOnInteractionAtPath(destructuredInitPath, NODE_INTERACTION_UNKNOWN_ACCESS, createHasEffectsContext()))) {
7279
- init.includePath(destructuredInitPath, context, false);
7280
- return true;
7082
+ super.includeCallArguments(context, parameters);
7281
7083
  }
7282
- return false;
7283
7084
  }
7284
7085
  initialise() {
7285
7086
  super.initialise();
@@ -7347,7 +7148,7 @@ class MemberExpression extends NodeBase {
7347
7148
  const variable = this.scope.findVariable(this.object.name);
7348
7149
  if (variable.isNamespace) {
7349
7150
  if (this.variable) {
7350
- this.scope.context.includeVariableInModule(this.variable, UNKNOWN_PATH);
7151
+ this.scope.context.includeVariableInModule(this.variable);
7351
7152
  }
7352
7153
  this.scope.context.log(LOGLEVEL_WARN, logIllegalImportReassignment(this.object.name, this.scope.context.module.id), this.start);
7353
7154
  }
@@ -7374,18 +7175,15 @@ class MemberExpression extends NodeBase {
7374
7175
  (propertyReadSideEffects === 'always' ||
7375
7176
  this.object.hasEffectsOnInteractionAtPath([this.getPropertyKey()], this.accessInteraction, context)));
7376
7177
  }
7377
- includeProperties(includedPath, objectPath, context, includeChildrenRecursively) {
7178
+ includeProperties(context, includeChildrenRecursively) {
7378
7179
  if (!this.included) {
7379
7180
  this.included = true;
7380
7181
  if (this.variable) {
7381
- this.scope.context.includeVariableInModule(this.variable, includedPath);
7182
+ this.scope.context.includeVariableInModule(this.variable);
7382
7183
  }
7383
7184
  }
7384
- else if (includedPath.length > 0) {
7385
- this.variable?.includePath(includedPath, context);
7386
- }
7387
- this.object.includePath(objectPath, context, includeChildrenRecursively);
7388
- this.property.includePath(UNKNOWN_PATH, context, includeChildrenRecursively);
7185
+ this.object.include(context, includeChildrenRecursively);
7186
+ this.property.include(context, includeChildrenRecursively);
7389
7187
  }
7390
7188
  }
7391
7189
  function resolveNamespaceVariables(baseVariable, path, astContext) {
@@ -7428,7 +7226,7 @@ class MetaProperty extends NodeBase {
7428
7226
  hasEffectsOnInteractionAtPath(path, { type }) {
7429
7227
  return path.length > 1 || type !== INTERACTION_ACCESSED;
7430
7228
  }
7431
- includePath() {
7229
+ include() {
7432
7230
  if (!this.included) {
7433
7231
  this.included = true;
7434
7232
  if (this.meta.name === IMPORT) {
@@ -7547,7 +7345,7 @@ class UndefinedVariable extends Variable {
7547
7345
 
7548
7346
  class ExportDefaultVariable extends LocalVariable {
7549
7347
  constructor(name, exportDefaultDeclaration, context) {
7550
- super(name, exportDefaultDeclaration, exportDefaultDeclaration.declaration, EMPTY_PATH, context, 'other');
7348
+ super(name, exportDefaultDeclaration, exportDefaultDeclaration.declaration, context, 'other');
7551
7349
  this.hasId = false;
7552
7350
  this.originalId = null;
7553
7351
  this.originalVariable = null;
@@ -7696,8 +7494,8 @@ class NamespaceVariable extends Variable {
7696
7494
  return (!memberVariable ||
7697
7495
  memberVariable.hasEffectsOnInteractionAtPath(path.slice(1), interaction, context));
7698
7496
  }
7699
- includePath(path, context) {
7700
- super.includePath(path, context);
7497
+ include() {
7498
+ super.include();
7701
7499
  this.context.includeAllExports();
7702
7500
  }
7703
7501
  prepare(accessedGlobalsByScope) {
@@ -7790,9 +7588,9 @@ class SyntheticNamedExportVariable extends Variable {
7790
7588
  getName(getPropertyAccess) {
7791
7589
  return `${this.syntheticNamespace.getName(getPropertyAccess)}${getPropertyAccess(this.name)}`;
7792
7590
  }
7793
- includePath(path, context) {
7794
- super.includePath(path, context);
7795
- this.context.includeVariableInModule(this.syntheticNamespace, path);
7591
+ include() {
7592
+ super.include();
7593
+ this.context.includeVariableInModule(this.syntheticNamespace);
7796
7594
  }
7797
7595
  setRenderNames(baseName, name) {
7798
7596
  super.setRenderNames(baseName, name);
@@ -10991,37 +10789,21 @@ class ArrayPattern extends NodeBase {
10991
10789
  element?.addExportedVariables(variables, exportNamesByVariable);
10992
10790
  }
10993
10791
  }
10994
- declare(kind, destructuredInitPath, init) {
10792
+ declare(kind) {
10995
10793
  const variables = [];
10996
- const includedPatternPath = getIncludedPatternPath(destructuredInitPath);
10997
10794
  for (const element of this.elements) {
10998
10795
  if (element !== null) {
10999
- variables.push(...element.declare(kind, includedPatternPath, init));
10796
+ variables.push(...element.declare(kind, UNKNOWN_EXPRESSION));
11000
10797
  }
11001
10798
  }
11002
10799
  return variables;
11003
10800
  }
11004
- deoptimizeAssignment(destructuredInitPath, init) {
11005
- const includedPatternPath = getIncludedPatternPath(destructuredInitPath);
11006
- for (const element of this.elements) {
11007
- element?.deoptimizeAssignment(includedPatternPath, init);
11008
- }
11009
- }
11010
10801
  // Patterns can only be deoptimized at the empty path at the moment
11011
10802
  deoptimizePath() {
11012
10803
  for (const element of this.elements) {
11013
10804
  element?.deoptimizePath(EMPTY_PATH);
11014
10805
  }
11015
10806
  }
11016
- hasEffectsWhenDestructuring(context, destructuredInitPath, init) {
11017
- const includedPatternPath = getIncludedPatternPath(destructuredInitPath);
11018
- for (const element of this.elements) {
11019
- if (element?.hasEffectsWhenDestructuring(context, includedPatternPath, init)) {
11020
- return true;
11021
- }
11022
- }
11023
- return false;
11024
- }
11025
10807
  // Patterns are only checked at the empty path at the moment
11026
10808
  hasEffectsOnInteractionAtPath(_path, interaction, context) {
11027
10809
  for (const element of this.elements) {
@@ -11030,37 +10812,12 @@ class ArrayPattern extends NodeBase {
11030
10812
  }
11031
10813
  return false;
11032
10814
  }
11033
- includeDestructuredIfNecessary(context, destructuredInitPath, init) {
11034
- let included = false;
11035
- const includedPatternPath = getIncludedPatternPath(destructuredInitPath);
11036
- for (const element of this.elements) {
11037
- if (element) {
11038
- element.included ||= included;
11039
- included =
11040
- element.includeDestructuredIfNecessary(context, includedPatternPath, init) || included;
11041
- }
11042
- }
11043
- if (included) {
11044
- // This is necessary so that if any pattern element is included, all are
11045
- // included for proper deconflicting
11046
- for (const element of this.elements) {
11047
- if (element && !element.included) {
11048
- element.included = true;
11049
- element.includeDestructuredIfNecessary(context, includedPatternPath, init);
11050
- }
11051
- }
11052
- }
11053
- return (this.included ||= included);
11054
- }
11055
10815
  markDeclarationReached() {
11056
10816
  for (const element of this.elements) {
11057
10817
  element?.markDeclarationReached();
11058
10818
  }
11059
10819
  }
11060
10820
  }
11061
- const getIncludedPatternPath = (destructuredInitPath) => destructuredInitPath.at(-1) === UnknownKey
11062
- ? destructuredInitPath
11063
- : [...destructuredInitPath, UnknownInteger];
11064
10821
 
11065
10822
  class ArrowFunctionExpression extends FunctionBase {
11066
10823
  constructor() {
@@ -11109,11 +10866,11 @@ class ArrowFunctionExpression extends FunctionBase {
11109
10866
  this.parent.callee === this;
11110
10867
  return isIIFE || super.onlyFunctionCallUsed();
11111
10868
  }
11112
- includePath(_path, context, includeChildrenRecursively) {
11113
- super.includePath(UNKNOWN_PATH, context, includeChildrenRecursively);
10869
+ include(context, includeChildrenRecursively) {
10870
+ super.include(context, includeChildrenRecursively);
11114
10871
  for (const parameter of this.params) {
11115
10872
  if (!(parameter instanceof Identifier)) {
11116
- parameter.includePath(UNKNOWN_PATH, context, includeChildrenRecursively);
10873
+ parameter.include(context, includeChildrenRecursively);
11117
10874
  }
11118
10875
  }
11119
10876
  }
@@ -11136,18 +10893,13 @@ class ObjectPattern extends NodeBase {
11136
10893
  }
11137
10894
  }
11138
10895
  }
11139
- declare(kind, destructuredInitPath, init) {
10896
+ declare(kind, init) {
11140
10897
  const variables = [];
11141
10898
  for (const property of this.properties) {
11142
- variables.push(...property.declare(kind, destructuredInitPath, init));
10899
+ variables.push(...property.declare(kind, init));
11143
10900
  }
11144
10901
  return variables;
11145
10902
  }
11146
- deoptimizeAssignment(destructuredInitPath, init) {
11147
- for (const property of this.properties) {
11148
- property.deoptimizeAssignment(destructuredInitPath, init);
11149
- }
11150
- }
11151
10903
  deoptimizePath(path) {
11152
10904
  if (path.length === 0) {
11153
10905
  for (const property of this.properties) {
@@ -11165,44 +10917,11 @@ class ObjectPattern extends NodeBase {
11165
10917
  }
11166
10918
  return false;
11167
10919
  }
11168
- hasEffectsWhenDestructuring(context, destructuredInitPath, init) {
11169
- for (const property of this.properties) {
11170
- if (property.hasEffectsWhenDestructuring(context, destructuredInitPath, init))
11171
- return true;
11172
- }
11173
- return false;
11174
- }
11175
- includeDestructuredIfNecessary(context, destructuredInitPath, init) {
11176
- let included = false;
11177
- for (const property of this.properties) {
11178
- included =
11179
- property.includeDestructuredIfNecessary(context, destructuredInitPath, init) || included;
11180
- }
11181
- return (this.included ||= included);
11182
- }
11183
10920
  markDeclarationReached() {
11184
10921
  for (const property of this.properties) {
11185
10922
  property.markDeclarationReached();
11186
10923
  }
11187
10924
  }
11188
- render(code, options) {
11189
- if (this.properties.length > 0) {
11190
- const separatedNodes = getCommaSeparatedNodesWithBoundaries(this.properties, code, this.start + 1, this.end - 1);
11191
- let lastSeparatorPos = null;
11192
- for (const { node, separator, start, end } of separatedNodes) {
11193
- if (!node.included) {
11194
- treeshakeNode(node, code, start, end);
11195
- continue;
11196
- }
11197
- lastSeparatorPos = separator;
11198
- node.render(code, options);
11199
- }
11200
- if (lastSeparatorPos) {
11201
- code.remove(lastSeparatorPos, this.end - 1);
11202
- }
11203
- }
11204
- }
11205
- applyDeoptimizations() { }
11206
10925
  }
11207
10926
 
11208
10927
  class AssignmentExpression extends NodeBase {
@@ -11212,27 +10931,23 @@ class AssignmentExpression extends NodeBase {
11212
10931
  this.applyDeoptimizations();
11213
10932
  // MemberExpressions do not access the property before assignments if the
11214
10933
  // operator is '='.
11215
- return (right.hasEffects(context) ||
11216
- left.hasEffectsAsAssignmentTarget(context, operator !== '=') ||
11217
- this.left.hasEffectsWhenDestructuring?.(context, EMPTY_PATH, right));
10934
+ return (right.hasEffects(context) || left.hasEffectsAsAssignmentTarget(context, operator !== '='));
11218
10935
  }
11219
10936
  hasEffectsOnInteractionAtPath(path, interaction, context) {
11220
10937
  return this.right.hasEffectsOnInteractionAtPath(path, interaction, context);
11221
10938
  }
11222
- includePath(_path, context, includeChildrenRecursively) {
10939
+ include(context, includeChildrenRecursively) {
11223
10940
  const { deoptimized, left, right, operator } = this;
11224
10941
  if (!deoptimized)
11225
10942
  this.applyDeoptimizations();
11226
10943
  this.included = true;
11227
- const hasEffectsContext = createHasEffectsContext();
11228
10944
  if (includeChildrenRecursively ||
11229
10945
  operator !== '=' ||
11230
10946
  left.included ||
11231
- left.hasEffectsAsAssignmentTarget(hasEffectsContext, false) ||
11232
- left.hasEffectsWhenDestructuring?.(hasEffectsContext, EMPTY_PATH, right)) {
10947
+ left.hasEffectsAsAssignmentTarget(createHasEffectsContext(), false)) {
11233
10948
  left.includeAsAssignmentTarget(context, includeChildrenRecursively, operator !== '=');
11234
10949
  }
11235
- right.includePath(UNKNOWN_PATH, context, includeChildrenRecursively);
10950
+ right.include(context, includeChildrenRecursively);
11236
10951
  }
11237
10952
  initialise() {
11238
10953
  super.initialise();
@@ -11294,7 +11009,8 @@ class AssignmentExpression extends NodeBase {
11294
11009
  }
11295
11010
  applyDeoptimizations() {
11296
11011
  this.deoptimized = true;
11297
- this.left.deoptimizeAssignment(EMPTY_PATH, this.right);
11012
+ this.left.deoptimizePath(EMPTY_PATH);
11013
+ this.right.deoptimizePath(UNKNOWN_PATH);
11298
11014
  this.scope.context.requestTreeshakingPass();
11299
11015
  }
11300
11016
  }
@@ -11303,11 +11019,8 @@ class AssignmentPattern extends NodeBase {
11303
11019
  addExportedVariables(variables, exportNamesByVariable) {
11304
11020
  this.left.addExportedVariables(variables, exportNamesByVariable);
11305
11021
  }
11306
- declare(kind, destructuredInitPath, init) {
11307
- return this.left.declare(kind, destructuredInitPath, init);
11308
- }
11309
- deoptimizeAssignment(destructuredInitPath, init) {
11310
- this.left.deoptimizeAssignment(destructuredInitPath, init);
11022
+ declare(kind, init) {
11023
+ return this.left.declare(kind, init);
11311
11024
  }
11312
11025
  deoptimizePath(path) {
11313
11026
  if (path.length === 0) {
@@ -11317,23 +11030,6 @@ class AssignmentPattern extends NodeBase {
11317
11030
  hasEffectsOnInteractionAtPath(path, interaction, context) {
11318
11031
  return (path.length > 0 || this.left.hasEffectsOnInteractionAtPath(EMPTY_PATH, interaction, context));
11319
11032
  }
11320
- hasEffectsWhenDestructuring(context, destructuredInitPath, init) {
11321
- return this.left.hasEffectsWhenDestructuring(context, destructuredInitPath, init);
11322
- }
11323
- includeDestructuredIfNecessary(context, destructuredInitPath, init) {
11324
- let included = this.left.includeDestructuredIfNecessary(context, destructuredInitPath, init) ||
11325
- this.included;
11326
- if ((included ||= this.right.shouldBeIncluded(context))) {
11327
- this.right.includePath(UNKNOWN_PATH, context, false);
11328
- if (!this.left.included) {
11329
- this.left.included = true;
11330
- // Unfortunately, we need to include the left side again now, so that
11331
- // any declared variables are properly included.
11332
- this.left.includeDestructuredIfNecessary(context, destructuredInitPath, init);
11333
- }
11334
- }
11335
- return (this.included = included);
11336
- }
11337
11033
  markDeclarationReached() {
11338
11034
  this.left.markDeclarationReached();
11339
11035
  }
@@ -11355,7 +11051,7 @@ class AwaitExpression extends NodeBase {
11355
11051
  this.applyDeoptimizations();
11356
11052
  return true;
11357
11053
  }
11358
- includePath(path, context, includeChildrenRecursively) {
11054
+ include(context, includeChildrenRecursively) {
11359
11055
  if (!this.deoptimized)
11360
11056
  this.applyDeoptimizations();
11361
11057
  if (!this.included) {
@@ -11369,7 +11065,7 @@ class AwaitExpression extends NodeBase {
11369
11065
  this.scope.context.usesTopLevelAwait = true;
11370
11066
  }
11371
11067
  }
11372
- this.argument.includePath(path, context, includeChildrenRecursively);
11068
+ this.argument.include(context, includeChildrenRecursively);
11373
11069
  }
11374
11070
  }
11375
11071
 
@@ -11451,10 +11147,10 @@ class BreakStatement extends NodeBase {
11451
11147
  context.brokenFlow = true;
11452
11148
  return false;
11453
11149
  }
11454
- includePath(_, context) {
11150
+ include(context) {
11455
11151
  this.included = true;
11456
11152
  if (this.label) {
11457
- this.label.includePath(UNKNOWN_PATH, createInclusionContext());
11153
+ this.label.include();
11458
11154
  context.includedLabels.add(this.label.name);
11459
11155
  }
11460
11156
  else {
@@ -11648,11 +11344,11 @@ class CallExpression extends CallExpressionBase {
11648
11344
  (calleeHasEffects ||
11649
11345
  this.callee.hasEffectsOnInteractionAtPath(EMPTY_PATH, this.interaction, context)));
11650
11346
  }
11651
- includePath(path, context, includeChildrenRecursively) {
11347
+ include(context, includeChildrenRecursively) {
11652
11348
  if (!this.deoptimized)
11653
11349
  this.applyDeoptimizations();
11654
11350
  if (includeChildrenRecursively) {
11655
- super.includePath(path, context, includeChildrenRecursively);
11351
+ super.include(context, includeChildrenRecursively);
11656
11352
  if (includeChildrenRecursively === INCLUDE_PARAMETERS &&
11657
11353
  this.callee instanceof Identifier &&
11658
11354
  this.callee.variable) {
@@ -11661,18 +11357,9 @@ class CallExpression extends CallExpressionBase {
11661
11357
  }
11662
11358
  else {
11663
11359
  this.included = true;
11664
- // If the callee is a member expression and does not have a variable, its
11665
- // object will already be included via the first argument of the
11666
- // interaction in includeCallArguments. Including it again can lead to
11667
- // severe performance problems.
11668
- if (this.callee instanceof MemberExpression && !this.callee.variable) {
11669
- this.callee.property.includePath(UNKNOWN_PATH, context, false);
11670
- }
11671
- else {
11672
- this.callee.includePath(UNKNOWN_PATH, context, false);
11673
- }
11674
- this.callee.includeCallArguments(context, this.interaction);
11360
+ this.callee.include(context, false);
11675
11361
  }
11362
+ this.callee.includeCallArguments(context, this.arguments);
11676
11363
  }
11677
11364
  initialise() {
11678
11365
  super.initialise();
@@ -11711,7 +11398,7 @@ class CatchClause extends NodeBase {
11711
11398
  this.type = type;
11712
11399
  if (param) {
11713
11400
  this.param = new (this.scope.context.getNodeConstructor(param.type))(this, this.scope).parseNode(param);
11714
- this.param.declare('parameter', EMPTY_PATH, UNKNOWN_EXPRESSION);
11401
+ this.param.declare('parameter', UNKNOWN_EXPRESSION);
11715
11402
  }
11716
11403
  this.body = new BlockStatement(this, this.scope.bodyScope).parseNode(body);
11717
11404
  return super.parseNode(esTreeNode);
@@ -11739,7 +11426,7 @@ class ClassBodyScope extends ChildScope {
11739
11426
  constructor(parent, classNode) {
11740
11427
  const { context } = parent;
11741
11428
  super(parent, context);
11742
- this.variables.set('this', (this.thisVariable = new LocalVariable('this', null, classNode, EMPTY_PATH, context, 'other')));
11429
+ this.variables.set('this', (this.thisVariable = new LocalVariable('this', null, classNode, context, 'other')));
11743
11430
  this.instanceScope = new ChildScope(this, context);
11744
11431
  this.instanceScope.variables.set('this', new ThisVariable(context));
11745
11432
  }
@@ -11752,11 +11439,11 @@ class ClassBody extends NodeBase {
11752
11439
  createScope(parentScope) {
11753
11440
  this.scope = new ClassBodyScope(parentScope, this.parent);
11754
11441
  }
11755
- includePath(_path, context, includeChildrenRecursively) {
11442
+ include(context, includeChildrenRecursively) {
11756
11443
  this.included = true;
11757
- this.scope.context.includeVariableInModule(this.scope.thisVariable, UNKNOWN_PATH);
11444
+ this.scope.context.includeVariableInModule(this.scope.thisVariable);
11758
11445
  for (const definition of this.body) {
11759
- definition.includePath(UNKNOWN_PATH, context, includeChildrenRecursively);
11446
+ definition.include(context, includeChildrenRecursively);
11760
11447
  }
11761
11448
  }
11762
11449
  parseNode(esTreeNode) {
@@ -11880,26 +11567,26 @@ class ConditionalExpression extends NodeBase {
11880
11567
  }
11881
11568
  return usedBranch.hasEffectsOnInteractionAtPath(path, interaction, context);
11882
11569
  }
11883
- includePath(path, context, includeChildrenRecursively) {
11570
+ include(context, includeChildrenRecursively) {
11884
11571
  this.included = true;
11885
11572
  const usedBranch = this.getUsedBranch();
11886
11573
  if (includeChildrenRecursively || this.test.shouldBeIncluded(context) || usedBranch === null) {
11887
- this.test.includePath(UNKNOWN_PATH, context, includeChildrenRecursively);
11888
- this.consequent.includePath(path, context, includeChildrenRecursively);
11889
- this.alternate.includePath(path, context, includeChildrenRecursively);
11574
+ this.test.include(context, includeChildrenRecursively);
11575
+ this.consequent.include(context, includeChildrenRecursively);
11576
+ this.alternate.include(context, includeChildrenRecursively);
11890
11577
  }
11891
11578
  else {
11892
- usedBranch.includePath(path, context, includeChildrenRecursively);
11579
+ usedBranch.include(context, includeChildrenRecursively);
11893
11580
  }
11894
11581
  }
11895
- includeCallArguments(context, interaction) {
11582
+ includeCallArguments(context, parameters) {
11896
11583
  const usedBranch = this.getUsedBranch();
11897
11584
  if (usedBranch) {
11898
- usedBranch.includeCallArguments(context, interaction);
11585
+ usedBranch.includeCallArguments(context, parameters);
11899
11586
  }
11900
11587
  else {
11901
- this.consequent.includeCallArguments(context, interaction);
11902
- this.alternate.includeCallArguments(context, interaction);
11588
+ this.consequent.includeCallArguments(context, parameters);
11589
+ this.alternate.includeCallArguments(context, parameters);
11903
11590
  }
11904
11591
  }
11905
11592
  removeAnnotations(code) {
@@ -11960,10 +11647,10 @@ class ContinueStatement extends NodeBase {
11960
11647
  context.brokenFlow = true;
11961
11648
  return false;
11962
11649
  }
11963
- includePath(_, context) {
11650
+ include(context) {
11964
11651
  this.included = true;
11965
11652
  if (this.label) {
11966
- this.label.includePath(UNKNOWN_PATH, createInclusionContext());
11653
+ this.label.include();
11967
11654
  context.includedLabels.add(this.label.name);
11968
11655
  }
11969
11656
  else {
@@ -12006,7 +11693,7 @@ function includeLoopBody(context, body, includeChildrenRecursively) {
12006
11693
  const { brokenFlow, hasBreak, hasContinue } = context;
12007
11694
  context.hasBreak = false;
12008
11695
  context.hasContinue = false;
12009
- body.includePath(UNKNOWN_PATH, context, includeChildrenRecursively, { asSingleStatement: true });
11696
+ body.include(context, includeChildrenRecursively, { asSingleStatement: true });
12010
11697
  context.hasBreak = hasBreak;
12011
11698
  context.hasContinue = hasContinue;
12012
11699
  context.brokenFlow = brokenFlow;
@@ -12018,9 +11705,9 @@ class DoWhileStatement extends NodeBase {
12018
11705
  return true;
12019
11706
  return hasLoopBodyEffects(context, this.body);
12020
11707
  }
12021
- includePath(_path, context, includeChildrenRecursively) {
11708
+ include(context, includeChildrenRecursively) {
12022
11709
  this.included = true;
12023
- this.test.includePath(UNKNOWN_PATH, context, includeChildrenRecursively);
11710
+ this.test.include(context, includeChildrenRecursively);
12024
11711
  includeLoopBody(context, this.body, includeChildrenRecursively);
12025
11712
  }
12026
11713
  }
@@ -12091,13 +11778,13 @@ class ForInStatement extends NodeBase {
12091
11778
  return true;
12092
11779
  return hasLoopBodyEffects(context, body);
12093
11780
  }
12094
- includePath(_path, context, includeChildrenRecursively) {
11781
+ include(context, includeChildrenRecursively) {
12095
11782
  const { body, deoptimized, left, right } = this;
12096
11783
  if (!deoptimized)
12097
11784
  this.applyDeoptimizations();
12098
11785
  this.included = true;
12099
11786
  left.includeAsAssignmentTarget(context, includeChildrenRecursively || true, false);
12100
- right.includePath(UNKNOWN_PATH, context, includeChildrenRecursively);
11787
+ right.include(context, includeChildrenRecursively);
12101
11788
  includeLoopBody(context, body, includeChildrenRecursively);
12102
11789
  }
12103
11790
  initialise() {
@@ -12136,13 +11823,13 @@ class ForOfStatement extends NodeBase {
12136
11823
  // Placeholder until proper Symbol.Iterator support
12137
11824
  return true;
12138
11825
  }
12139
- includePath(_path, context, includeChildrenRecursively) {
11826
+ include(context, includeChildrenRecursively) {
12140
11827
  const { body, deoptimized, left, right } = this;
12141
11828
  if (!deoptimized)
12142
11829
  this.applyDeoptimizations();
12143
11830
  this.included = true;
12144
11831
  left.includeAsAssignmentTarget(context, includeChildrenRecursively || true, false);
12145
- right.includePath(UNKNOWN_PATH, context, includeChildrenRecursively);
11832
+ right.include(context, includeChildrenRecursively);
12146
11833
  includeLoopBody(context, body, includeChildrenRecursively);
12147
11834
  }
12148
11835
  initialise() {
@@ -12178,13 +11865,11 @@ class ForStatement extends NodeBase {
12178
11865
  }
12179
11866
  return hasLoopBodyEffects(context, this.body);
12180
11867
  }
12181
- includePath(_path, context, includeChildrenRecursively) {
11868
+ include(context, includeChildrenRecursively) {
12182
11869
  this.included = true;
12183
- this.init?.includePath(UNKNOWN_PATH, context, includeChildrenRecursively, {
12184
- asSingleStatement: true
12185
- });
12186
- this.test?.includePath(UNKNOWN_PATH, context, includeChildrenRecursively);
12187
- this.update?.includePath(UNKNOWN_PATH, context, includeChildrenRecursively);
11870
+ this.init?.include(context, includeChildrenRecursively, { asSingleStatement: true });
11871
+ this.test?.include(context, includeChildrenRecursively);
11872
+ this.update?.include(context, includeChildrenRecursively);
12188
11873
  includeLoopBody(context, this.body, includeChildrenRecursively);
12189
11874
  }
12190
11875
  render(code, options) {
@@ -12225,9 +11910,9 @@ class TrackingScope extends BlockScope {
12225
11910
  super(...arguments);
12226
11911
  this.hoistedDeclarations = [];
12227
11912
  }
12228
- addDeclaration(identifier, context, init, destructuredInitPath, kind) {
11913
+ addDeclaration(identifier, context, init, kind) {
12229
11914
  this.hoistedDeclarations.push(identifier);
12230
- return super.addDeclaration(identifier, context, init, destructuredInitPath, kind);
11915
+ return super.addDeclaration(identifier, context, init, kind);
12231
11916
  }
12232
11917
  }
12233
11918
 
@@ -12260,7 +11945,7 @@ class IfStatement extends NodeBase {
12260
11945
  }
12261
11946
  return testValue ? this.consequent.hasEffects(context) : !!this.alternate?.hasEffects(context);
12262
11947
  }
12263
- includePath(_, context, includeChildrenRecursively) {
11948
+ include(context, includeChildrenRecursively) {
12264
11949
  this.included = true;
12265
11950
  if (includeChildrenRecursively) {
12266
11951
  this.includeRecursively(includeChildrenRecursively, context);
@@ -12335,31 +12020,31 @@ class IfStatement extends NodeBase {
12335
12020
  }
12336
12021
  includeKnownTest(context, testValue) {
12337
12022
  if (this.test.shouldBeIncluded(context)) {
12338
- this.test.includePath(UNKNOWN_PATH, context, false);
12023
+ this.test.include(context, false);
12339
12024
  }
12340
12025
  if (testValue && this.consequent.shouldBeIncluded(context)) {
12341
- this.consequent.includePath(UNKNOWN_PATH, context, false, { asSingleStatement: true });
12026
+ this.consequent.include(context, false, { asSingleStatement: true });
12342
12027
  }
12343
12028
  if (!testValue && this.alternate?.shouldBeIncluded(context)) {
12344
- this.alternate.includePath(UNKNOWN_PATH, context, false, { asSingleStatement: true });
12029
+ this.alternate.include(context, false, { asSingleStatement: true });
12345
12030
  }
12346
12031
  }
12347
12032
  includeRecursively(includeChildrenRecursively, context) {
12348
- this.test.includePath(UNKNOWN_PATH, context, includeChildrenRecursively);
12349
- this.consequent.includePath(UNKNOWN_PATH, context, includeChildrenRecursively);
12350
- this.alternate?.includePath(UNKNOWN_PATH, context, includeChildrenRecursively);
12033
+ this.test.include(context, includeChildrenRecursively);
12034
+ this.consequent.include(context, includeChildrenRecursively);
12035
+ this.alternate?.include(context, includeChildrenRecursively);
12351
12036
  }
12352
12037
  includeUnknownTest(context) {
12353
- this.test.includePath(UNKNOWN_PATH, context, false);
12038
+ this.test.include(context, false);
12354
12039
  const { brokenFlow } = context;
12355
12040
  let consequentBrokenFlow = false;
12356
12041
  if (this.consequent.shouldBeIncluded(context)) {
12357
- this.consequent.includePath(UNKNOWN_PATH, context, false, { asSingleStatement: true });
12042
+ this.consequent.include(context, false, { asSingleStatement: true });
12358
12043
  consequentBrokenFlow = context.brokenFlow;
12359
12044
  context.brokenFlow = brokenFlow;
12360
12045
  }
12361
12046
  if (this.alternate?.shouldBeIncluded(context)) {
12362
- this.alternate.includePath(UNKNOWN_PATH, context, false, { asSingleStatement: true });
12047
+ this.alternate.include(context, false, { asSingleStatement: true });
12363
12048
  context.brokenFlow = context.brokenFlow && consequentBrokenFlow;
12364
12049
  }
12365
12050
  }
@@ -12427,7 +12112,7 @@ function isReassignedExportsMember(variable, exportNamesByVariable) {
12427
12112
  class VariableDeclarator extends NodeBase {
12428
12113
  declareDeclarator(kind, isUsingDeclaration) {
12429
12114
  this.isUsingDeclaration = isUsingDeclaration;
12430
- this.id.declare(kind, EMPTY_PATH, this.init || UNDEFINED_EXPRESSION);
12115
+ this.id.declare(kind, this.init || UNDEFINED_EXPRESSION);
12431
12116
  }
12432
12117
  deoptimizePath(path) {
12433
12118
  this.id.deoptimizePath(path);
@@ -12437,25 +12122,17 @@ class VariableDeclarator extends NodeBase {
12437
12122
  this.applyDeoptimizations();
12438
12123
  const initEffect = this.init?.hasEffects(context);
12439
12124
  this.id.markDeclarationReached();
12440
- return (initEffect ||
12441
- this.isUsingDeclaration ||
12442
- this.id.hasEffects(context) ||
12443
- (this.scope.context.options.treeshake
12444
- .propertyReadSideEffects &&
12445
- this.id.hasEffectsWhenDestructuring(context, EMPTY_PATH, this.init || UNDEFINED_EXPRESSION)));
12446
- }
12447
- includePath(_path, context, includeChildrenRecursively) {
12125
+ return initEffect || this.id.hasEffects(context) || this.isUsingDeclaration;
12126
+ }
12127
+ include(context, includeChildrenRecursively) {
12448
12128
  const { deoptimized, id, init } = this;
12449
12129
  if (!deoptimized)
12450
12130
  this.applyDeoptimizations();
12451
12131
  this.included = true;
12452
- init?.includePath(EMPTY_PATH, context, includeChildrenRecursively);
12132
+ init?.include(context, includeChildrenRecursively);
12453
12133
  id.markDeclarationReached();
12454
- if (includeChildrenRecursively) {
12455
- id.includePath(EMPTY_PATH, context, includeChildrenRecursively);
12456
- }
12457
- else {
12458
- id.includeDestructuredIfNecessary(context, EMPTY_PATH, init || UNDEFINED_EXPRESSION);
12134
+ if (includeChildrenRecursively || id.shouldBeIncluded(context)) {
12135
+ id.include(context, includeChildrenRecursively);
12459
12136
  }
12460
12137
  }
12461
12138
  removeAnnotations(code) {
@@ -12504,8 +12181,6 @@ class ImportExpression extends NodeBase {
12504
12181
  constructor() {
12505
12182
  super(...arguments);
12506
12183
  this.inlineNamespace = null;
12507
- this.hasUnknownAccessedKey = false;
12508
- this.accessedPropKey = new Set();
12509
12184
  this.attributes = null;
12510
12185
  this.mechanism = null;
12511
12186
  this.namespaceExportName = undefined;
@@ -12538,15 +12213,12 @@ class ImportExpression extends NodeBase {
12538
12213
  if (parent2 instanceof ExpressionStatement) {
12539
12214
  return EMPTY_ARRAY;
12540
12215
  }
12541
- // Case 1: const { foo } / module = await import('bar')
12216
+ // Case 1: const { foo } = await import('bar')
12542
12217
  if (parent2 instanceof VariableDeclarator) {
12543
12218
  const declaration = parent2.id;
12544
- if (declaration instanceof Identifier) {
12545
- return this.hasUnknownAccessedKey ? undefined : [...this.accessedPropKey];
12546
- }
12547
- if (declaration instanceof ObjectPattern) {
12548
- return getDeterministicObjectDestructure(declaration);
12549
- }
12219
+ return declaration instanceof ObjectPattern
12220
+ ? getDeterministicObjectDestructure(declaration)
12221
+ : undefined;
12550
12222
  }
12551
12223
  // Case 2: (await import('bar')).foo
12552
12224
  if (parent2 instanceof MemberExpression) {
@@ -12595,23 +12267,13 @@ class ImportExpression extends NodeBase {
12595
12267
  hasEffects() {
12596
12268
  return true;
12597
12269
  }
12598
- includePath(path, context, includeChildrenRecursively) {
12270
+ include(context, includeChildrenRecursively) {
12599
12271
  if (!this.included) {
12600
12272
  this.included = true;
12601
12273
  this.scope.context.includeDynamicImport(this);
12602
12274
  this.scope.addAccessedDynamicImport(this);
12603
- this.source.includePath(path, context, includeChildrenRecursively);
12604
- }
12605
- if (this.hasUnknownAccessedKey)
12606
- return;
12607
- if (path[0] === UnknownKey) {
12608
- this.hasUnknownAccessedKey = true;
12609
- this.scope.context.includeDynamicImport(this);
12610
- }
12611
- else if (typeof path[0] === 'string') {
12612
- this.accessedPropKey.add(path[0]);
12613
- this.scope.context.includeDynamicImport(this);
12614
12275
  }
12276
+ this.source.include(context, includeChildrenRecursively);
12615
12277
  }
12616
12278
  initialise() {
12617
12279
  super.initialise();
@@ -12939,7 +12601,7 @@ function getAndIncludeFactoryVariable(factory, preserve, importSource, node) {
12939
12601
  if (preserve) {
12940
12602
  // This pretends we are accessing an included global variable of the same name
12941
12603
  const globalVariable = node.scope.findGlobal(baseName);
12942
- globalVariable.includePath(UNKNOWN_PATH, createInclusionContext());
12604
+ globalVariable.include();
12943
12605
  // This excludes this variable from renaming
12944
12606
  factoryVariable.globalName = baseName;
12945
12607
  }
@@ -12947,7 +12609,7 @@ function getAndIncludeFactoryVariable(factory, preserve, importSource, node) {
12947
12609
  else {
12948
12610
  factoryVariable = node.scope.findGlobal(baseName);
12949
12611
  }
12950
- node.scope.context.includeVariableInModule(factoryVariable, UNKNOWN_PATH);
12612
+ node.scope.context.includeVariableInModule(factoryVariable);
12951
12613
  if (factoryVariable instanceof LocalVariable) {
12952
12614
  factoryVariable.consolidateInitializers();
12953
12615
  factoryVariable.addUsedPlace(node);
@@ -12969,7 +12631,7 @@ class JSXElementBase extends NodeBase {
12969
12631
  this.scope.context.addImportSource(importSource);
12970
12632
  }
12971
12633
  }
12972
- includePath(path, context, includeChildrenRecursively) {
12634
+ include(context, includeChildrenRecursively) {
12973
12635
  if (!this.included) {
12974
12636
  const { factory, importSource, mode } = this.jsxMode;
12975
12637
  if (factory) {
@@ -12977,7 +12639,7 @@ class JSXElementBase extends NodeBase {
12977
12639
  this.factoryVariable = getAndIncludeFactoryVariable(factory, mode === 'preserve', importSource, this);
12978
12640
  }
12979
12641
  }
12980
- super.includePath(path, context, includeChildrenRecursively);
12642
+ super.include(context, includeChildrenRecursively);
12981
12643
  }
12982
12644
  applyDeoptimizations() { }
12983
12645
  getRenderingMode() {
@@ -13239,7 +12901,7 @@ class JSXOpeningFragment extends NodeBase {
13239
12901
  this.fragment = null;
13240
12902
  this.fragmentVariable = null;
13241
12903
  }
13242
- includePath(path, context, includeChildrenRecursively) {
12904
+ include(context, includeChildrenRecursively) {
13243
12905
  if (!this.included) {
13244
12906
  const jsx = this.scope.context.options.jsx;
13245
12907
  if (jsx.mode === 'automatic') {
@@ -13254,7 +12916,7 @@ class JSXOpeningFragment extends NodeBase {
13254
12916
  }
13255
12917
  }
13256
12918
  }
13257
- super.includePath(path, context, includeChildrenRecursively);
12919
+ super.include(context, includeChildrenRecursively);
13258
12920
  }
13259
12921
  render(code, options) {
13260
12922
  const { mode } = this.scope.context.options.jsx;
@@ -13311,13 +12973,13 @@ class LabeledStatement extends NodeBase {
13311
12973
  context.includedLabels = new Set([...includedLabels, ...context.includedLabels]);
13312
12974
  return bodyHasEffects;
13313
12975
  }
13314
- includePath(_path, context, includeChildrenRecursively) {
12976
+ include(context, includeChildrenRecursively) {
13315
12977
  this.included = true;
13316
12978
  const { brokenFlow, includedLabels } = context;
13317
12979
  context.includedLabels = new Set();
13318
- this.body.includePath(UNKNOWN_PATH, context, includeChildrenRecursively);
12980
+ this.body.include(context, includeChildrenRecursively);
13319
12981
  if (includeChildrenRecursively || context.includedLabels.has(this.label.name)) {
13320
- this.label.includePath(UNKNOWN_PATH, createInclusionContext());
12982
+ this.label.include();
13321
12983
  context.includedLabels.delete(this.label.name);
13322
12984
  context.brokenFlow = brokenFlow;
13323
12985
  }
@@ -13414,17 +13076,17 @@ class LogicalExpression extends NodeBase {
13414
13076
  }
13415
13077
  return usedBranch.hasEffectsOnInteractionAtPath(path, interaction, context);
13416
13078
  }
13417
- includePath(path, context, includeChildrenRecursively) {
13079
+ include(context, includeChildrenRecursively) {
13418
13080
  this.included = true;
13419
13081
  const usedBranch = this.getUsedBranch();
13420
13082
  if (includeChildrenRecursively ||
13421
13083
  (usedBranch === this.right && this.left.shouldBeIncluded(context)) ||
13422
13084
  !usedBranch) {
13423
- this.left.includePath(path, context, includeChildrenRecursively);
13424
- this.right.includePath(path, context, includeChildrenRecursively);
13085
+ this.left.include(context, includeChildrenRecursively);
13086
+ this.right.include(context, includeChildrenRecursively);
13425
13087
  }
13426
13088
  else {
13427
- usedBranch.includePath(path, context, includeChildrenRecursively);
13089
+ usedBranch.include(context, includeChildrenRecursively);
13428
13090
  }
13429
13091
  }
13430
13092
  removeAnnotations(code) {
@@ -13496,17 +13158,17 @@ class NewExpression extends NodeBase {
13496
13158
  hasEffectsOnInteractionAtPath(path, { type }) {
13497
13159
  return path.length > 0 || type !== INTERACTION_ACCESSED;
13498
13160
  }
13499
- includePath(path, context, includeChildrenRecursively) {
13161
+ include(context, includeChildrenRecursively) {
13500
13162
  if (!this.deoptimized)
13501
13163
  this.applyDeoptimizations();
13502
13164
  if (includeChildrenRecursively) {
13503
- super.includePath(path, context, includeChildrenRecursively);
13165
+ super.include(context, includeChildrenRecursively);
13504
13166
  }
13505
13167
  else {
13506
13168
  this.included = true;
13507
- this.callee.includePath(UNKNOWN_PATH, context, false);
13169
+ this.callee.include(context, false);
13508
13170
  }
13509
- this.callee.includeCallArguments(context, this.interaction);
13171
+ this.callee.includeCallArguments(context, this.arguments);
13510
13172
  }
13511
13173
  initialise() {
13512
13174
  super.initialise();
@@ -13535,7 +13197,6 @@ class ObjectExpression extends NodeBase {
13535
13197
  constructor() {
13536
13198
  super(...arguments);
13537
13199
  this.objectEntity = null;
13538
- this.protoProp = null;
13539
13200
  }
13540
13201
  deoptimizeArgumentsOnInteractionAtPath(interaction, path, recursionTracker) {
13541
13202
  this.getObjectEntity().deoptimizeArgumentsOnInteractionAtPath(interaction, path, recursionTracker);
@@ -13555,32 +13216,13 @@ class ObjectExpression extends NodeBase {
13555
13216
  hasEffectsOnInteractionAtPath(path, interaction, context) {
13556
13217
  return this.getObjectEntity().hasEffectsOnInteractionAtPath(path, interaction, context);
13557
13218
  }
13558
- includePath(path, context, includeChildrenRecursively) {
13559
- this.included = true;
13560
- this.getObjectEntity().includePath(path, context, includeChildrenRecursively);
13561
- this.protoProp?.includePath(UNKNOWN_PATH, context, includeChildrenRecursively);
13562
- }
13563
13219
  render(code, options, { renderedSurroundingElement } = BLANK) {
13220
+ super.render(code, options);
13564
13221
  if (renderedSurroundingElement === ExpressionStatement$1 ||
13565
13222
  renderedSurroundingElement === ArrowFunctionExpression$1) {
13566
13223
  code.appendRight(this.start, '(');
13567
13224
  code.prependLeft(this.end, ')');
13568
13225
  }
13569
- if (this.properties.length > 0) {
13570
- const separatedNodes = getCommaSeparatedNodesWithBoundaries(this.properties, code, this.start + 1, this.end - 1);
13571
- let lastSeparatorPos = null;
13572
- for (const { node, separator, start, end } of separatedNodes) {
13573
- if (!node.included) {
13574
- treeshakeNode(node, code, start, end);
13575
- continue;
13576
- }
13577
- lastSeparatorPos = separator;
13578
- node.render(code, options);
13579
- }
13580
- if (lastSeparatorPos) {
13581
- code.remove(lastSeparatorPos, this.end - 1);
13582
- }
13583
- }
13584
13226
  }
13585
13227
  applyDeoptimizations() { }
13586
13228
  getObjectEntity() {
@@ -13611,7 +13253,6 @@ class ObjectExpression extends NodeBase {
13611
13253
  ? property.key.name
13612
13254
  : String(property.key.value);
13613
13255
  if (key === '__proto__' && property.kind === 'init') {
13614
- this.protoProp = property;
13615
13256
  prototype =
13616
13257
  property.value instanceof Literal && property.value.value === null
13617
13258
  ? null
@@ -13678,11 +13319,11 @@ class Program extends NodeBase {
13678
13319
  }
13679
13320
  return false;
13680
13321
  }
13681
- includePath(_path, context, includeChildrenRecursively) {
13322
+ include(context, includeChildrenRecursively) {
13682
13323
  this.included = true;
13683
13324
  for (const node of this.body) {
13684
13325
  if (includeChildrenRecursively || node.shouldBeIncluded(context)) {
13685
- node.includePath(UNKNOWN_PATH, context, includeChildrenRecursively);
13326
+ node.include(context, includeChildrenRecursively);
13686
13327
  }
13687
13328
  }
13688
13329
  }
@@ -13721,6 +13362,10 @@ class Program extends NodeBase {
13721
13362
  }
13722
13363
 
13723
13364
  class Property extends MethodBase {
13365
+ constructor() {
13366
+ super(...arguments);
13367
+ this.declarationInit = null;
13368
+ }
13724
13369
  //declare method: boolean;
13725
13370
  get method() {
13726
13371
  return isFlagSet(this.flags, 262144 /* Flag.method */);
@@ -13735,39 +13380,17 @@ class Property extends MethodBase {
13735
13380
  set shorthand(value) {
13736
13381
  this.flags = setFlag(this.flags, 524288 /* Flag.shorthand */, value);
13737
13382
  }
13738
- declare(kind, destructuredInitPath, init) {
13739
- return this.value.declare(kind, this.getPathInProperty(destructuredInitPath), init);
13740
- }
13741
- deoptimizeAssignment(destructuredInitPath, init) {
13742
- this.value.deoptimizeAssignment?.(this.getPathInProperty(destructuredInitPath), init);
13383
+ declare(kind, init) {
13384
+ this.declarationInit = init;
13385
+ return this.value.declare(kind, UNKNOWN_EXPRESSION);
13743
13386
  }
13744
13387
  hasEffects(context) {
13745
13388
  if (!this.deoptimized)
13746
13389
  this.applyDeoptimizations();
13747
- return this.key.hasEffects(context) || this.value.hasEffects(context);
13748
- }
13749
- hasEffectsWhenDestructuring(context, destructuredInitPath, init) {
13750
- return this.value.hasEffectsWhenDestructuring?.(context, this.getPathInProperty(destructuredInitPath), init);
13751
- }
13752
- includeDestructuredIfNecessary(context, destructuredInitPath, init) {
13753
- const path = this.getPathInProperty(destructuredInitPath);
13754
- let included = this.value.includeDestructuredIfNecessary(context, path, init) ||
13755
- this.included;
13756
- if ((included ||= this.key.hasEffects(createHasEffectsContext()))) {
13757
- this.key.includePath(EMPTY_PATH, context, false);
13758
- if (!this.value.included) {
13759
- this.value.included = true;
13760
- // Unfortunately, we need to include the value again now, so that any
13761
- // declared variables are properly included.
13762
- this.value.includeDestructuredIfNecessary(context, path, init);
13763
- }
13764
- }
13765
- return (this.included = included);
13766
- }
13767
- includePath(path, context, includeChildrenRecursively) {
13768
- this.included = true;
13769
- this.key.includePath(EMPTY_PATH, context, includeChildrenRecursively);
13770
- this.value.includePath(path, context, includeChildrenRecursively);
13390
+ const propertyReadSideEffects = this.scope.context.options.treeshake.propertyReadSideEffects;
13391
+ return ((this.parent.type === 'ObjectPattern' && propertyReadSideEffects === 'always') ||
13392
+ this.key.hasEffects(context) ||
13393
+ this.value.hasEffects(context));
13771
13394
  }
13772
13395
  markDeclarationReached() {
13773
13396
  this.value.markDeclarationReached();
@@ -13778,17 +13401,12 @@ class Property extends MethodBase {
13778
13401
  }
13779
13402
  this.value.render(code, options, { isShorthandProperty: this.shorthand });
13780
13403
  }
13781
- applyDeoptimizations() { }
13782
- getPathInProperty(destructuredInitPath) {
13783
- return destructuredInitPath.at(-1) === UnknownKey
13784
- ? destructuredInitPath
13785
- : // For now, we only consider static paths as we do not know how to
13786
- // deoptimize the path in the dynamic case.
13787
- this.computed
13788
- ? [...destructuredInitPath, UnknownKey]
13789
- : this.key instanceof Identifier
13790
- ? [...destructuredInitPath, this.key.name]
13791
- : [...destructuredInitPath, String(this.key.value)];
13404
+ applyDeoptimizations() {
13405
+ this.deoptimized = true;
13406
+ if (this.declarationInit !== null) {
13407
+ this.declarationInit.deoptimizePath([UnknownKey, UnknownKey]);
13408
+ this.scope.context.requestTreeshakingPass();
13409
+ }
13792
13410
  }
13793
13411
  }
13794
13412
 
@@ -13833,9 +13451,9 @@ class ReturnStatement extends NodeBase {
13833
13451
  context.brokenFlow = true;
13834
13452
  return false;
13835
13453
  }
13836
- includePath(_path, context, includeChildrenRecursively) {
13454
+ include(context, includeChildrenRecursively) {
13837
13455
  this.included = true;
13838
- this.argument?.includePath(UNKNOWN_PATH, context, includeChildrenRecursively);
13456
+ this.argument?.include(context, includeChildrenRecursively);
13839
13457
  context.brokenFlow = true;
13840
13458
  }
13841
13459
  initialise() {
@@ -13872,14 +13490,14 @@ class SequenceExpression extends NodeBase {
13872
13490
  hasEffectsOnInteractionAtPath(path, interaction, context) {
13873
13491
  return this.expressions[this.expressions.length - 1].hasEffectsOnInteractionAtPath(path, interaction, context);
13874
13492
  }
13875
- includePath(path, context, includeChildrenRecursively) {
13493
+ include(context, includeChildrenRecursively) {
13876
13494
  this.included = true;
13877
13495
  const lastExpression = this.expressions[this.expressions.length - 1];
13878
13496
  for (const expression of this.expressions) {
13879
13497
  if (includeChildrenRecursively ||
13880
13498
  (expression === lastExpression && !(this.parent instanceof ExpressionStatement)) ||
13881
13499
  expression.shouldBeIncluded(context))
13882
- expression.includePath(path, context, includeChildrenRecursively);
13500
+ expression.include(context, includeChildrenRecursively);
13883
13501
  }
13884
13502
  }
13885
13503
  removeAnnotations(code) {
@@ -13927,13 +13545,10 @@ class Super extends NodeBase {
13927
13545
  deoptimizePath(path) {
13928
13546
  this.variable.deoptimizePath(path);
13929
13547
  }
13930
- includePath(path, context) {
13548
+ include() {
13931
13549
  if (!this.included) {
13932
13550
  this.included = true;
13933
- this.scope.context.includeVariableInModule(this.variable, path);
13934
- }
13935
- else if (path.length > 0) {
13936
- this.variable.includePath(path, context);
13551
+ this.scope.context.includeVariableInModule(this.variable);
13937
13552
  }
13938
13553
  }
13939
13554
  }
@@ -13950,12 +13565,12 @@ class SwitchCase extends NodeBase {
13950
13565
  }
13951
13566
  return false;
13952
13567
  }
13953
- includePath(_path, context, includeChildrenRecursively) {
13568
+ include(context, includeChildrenRecursively) {
13954
13569
  this.included = true;
13955
- this.test?.includePath(UNKNOWN_PATH, context, includeChildrenRecursively);
13570
+ this.test?.include(context, includeChildrenRecursively);
13956
13571
  for (const node of this.consequent) {
13957
13572
  if (includeChildrenRecursively || node.shouldBeIncluded(context))
13958
- node.includePath(UNKNOWN_PATH, context, includeChildrenRecursively);
13573
+ node.include(context, includeChildrenRecursively);
13959
13574
  }
13960
13575
  }
13961
13576
  render(code, options, nodeRenderOptions) {
@@ -14003,9 +13618,9 @@ class SwitchStatement extends NodeBase {
14003
13618
  context.hasBreak = hasBreak;
14004
13619
  return false;
14005
13620
  }
14006
- includePath(_path, context, includeChildrenRecursively) {
13621
+ include(context, includeChildrenRecursively) {
14007
13622
  this.included = true;
14008
- this.discriminant.includePath(UNKNOWN_PATH, context, includeChildrenRecursively);
13623
+ this.discriminant.include(context, includeChildrenRecursively);
14009
13624
  const { brokenFlow, hasBreak } = context;
14010
13625
  context.hasBreak = false;
14011
13626
  let onlyHasBrokenFlow = true;
@@ -14022,7 +13637,7 @@ class SwitchStatement extends NodeBase {
14022
13637
  isCaseIncluded = switchCase.hasEffects(hasEffectsContext);
14023
13638
  }
14024
13639
  if (isCaseIncluded) {
14025
- switchCase.includePath(UNKNOWN_PATH, context, includeChildrenRecursively);
13640
+ switchCase.include(context, includeChildrenRecursively);
14026
13641
  onlyHasBrokenFlow &&= context.brokenFlow && !context.hasBreak;
14027
13642
  context.hasBreak = false;
14028
13643
  context.brokenFlow = brokenFlow;
@@ -14079,21 +13694,21 @@ class TaggedTemplateExpression extends CallExpressionBase {
14079
13694
  return (this.tag.hasEffects(context) ||
14080
13695
  this.tag.hasEffectsOnInteractionAtPath(EMPTY_PATH, this.interaction, context));
14081
13696
  }
14082
- includePath(path, context, includeChildrenRecursively) {
13697
+ include(context, includeChildrenRecursively) {
14083
13698
  if (!this.deoptimized)
14084
13699
  this.applyDeoptimizations();
14085
13700
  if (includeChildrenRecursively) {
14086
- super.includePath(path, context, includeChildrenRecursively);
13701
+ super.include(context, includeChildrenRecursively);
14087
13702
  }
14088
13703
  else {
14089
13704
  this.included = true;
14090
- this.tag.includePath(UNKNOWN_PATH, context, includeChildrenRecursively);
14091
- this.quasi.includePath(UNKNOWN_PATH, context, includeChildrenRecursively);
13705
+ this.tag.include(context, includeChildrenRecursively);
13706
+ this.quasi.include(context, includeChildrenRecursively);
14092
13707
  }
14093
- this.tag.includeCallArguments(context, this.interaction);
13708
+ this.tag.includeCallArguments(context, this.args);
14094
13709
  const [returnExpression] = this.getReturnExpression();
14095
13710
  if (!returnExpression.included) {
14096
- returnExpression.includePath(UNKNOWN_PATH, context, false);
13711
+ returnExpression.include(context, false);
14097
13712
  }
14098
13713
  }
14099
13714
  initialise() {
@@ -14138,7 +13753,7 @@ class TemplateElement extends NodeBase {
14138
13753
  hasEffects() {
14139
13754
  return false;
14140
13755
  }
14141
- includePath() {
13756
+ include() {
14142
13757
  this.included = true;
14143
13758
  }
14144
13759
  parseNode(esTreeNode) {
@@ -14180,13 +13795,13 @@ class TemplateLiteral extends NodeBase {
14180
13795
  class ModuleScope extends ChildScope {
14181
13796
  constructor(parent, context) {
14182
13797
  super(parent, context);
14183
- this.variables.set('this', new LocalVariable('this', null, UNDEFINED_EXPRESSION, EMPTY_PATH, context, 'other'));
13798
+ this.variables.set('this', new LocalVariable('this', null, UNDEFINED_EXPRESSION, context, 'other'));
14184
13799
  }
14185
- addDeclaration(identifier, context, init, destructuredInitPath, kind) {
13800
+ addDeclaration(identifier, context, init, kind) {
14186
13801
  if (this.context.module.importDescriptions.has(identifier.name)) {
14187
13802
  context.error(logRedeclarationError(identifier.name), identifier.start);
14188
13803
  }
14189
- return super.addDeclaration(identifier, context, init, destructuredInitPath, kind);
13804
+ return super.addDeclaration(identifier, context, init, kind);
14190
13805
  }
14191
13806
  addExportDefaultDeclaration(name, exportDefaultDeclaration, context) {
14192
13807
  const variable = new ExportDefaultVariable(name, exportDefaultDeclaration, context);
@@ -14231,13 +13846,10 @@ class ThisExpression extends NodeBase {
14231
13846
  }
14232
13847
  return this.variable.hasEffectsOnInteractionAtPath(path, interaction, context);
14233
13848
  }
14234
- includePath(path, context) {
13849
+ include() {
14235
13850
  if (!this.included) {
14236
13851
  this.included = true;
14237
- this.scope.context.includeVariableInModule(this.variable, path);
14238
- }
14239
- else if (path.length > 0) {
14240
- this.variable.includePath(path, context);
13852
+ this.scope.context.includeVariableInModule(this.variable);
14241
13853
  }
14242
13854
  }
14243
13855
  initialise() {
@@ -14264,9 +13876,9 @@ class ThrowStatement extends NodeBase {
14264
13876
  hasEffects() {
14265
13877
  return true;
14266
13878
  }
14267
- includePath(_path, context, includeChildrenRecursively) {
13879
+ include(context, includeChildrenRecursively) {
14268
13880
  this.included = true;
14269
- this.argument.includePath(UNKNOWN_PATH, context, includeChildrenRecursively);
13881
+ this.argument.include(context, includeChildrenRecursively);
14270
13882
  context.brokenFlow = true;
14271
13883
  }
14272
13884
  render(code, options) {
@@ -14288,13 +13900,13 @@ class TryStatement extends NodeBase {
14288
13900
  ? this.block.body.length > 0
14289
13901
  : this.block.hasEffects(context)) || !!this.finalizer?.hasEffects(context));
14290
13902
  }
14291
- includePath(_path, context, includeChildrenRecursively) {
13903
+ include(context, includeChildrenRecursively) {
14292
13904
  const tryCatchDeoptimization = this.scope.context.options.treeshake?.tryCatchDeoptimization;
14293
13905
  const { brokenFlow, includedLabels } = context;
14294
13906
  if (!this.directlyIncluded || !tryCatchDeoptimization) {
14295
13907
  this.included = true;
14296
13908
  this.directlyIncluded = true;
14297
- this.block.includePath(UNKNOWN_PATH, context, tryCatchDeoptimization ? INCLUDE_PARAMETERS : includeChildrenRecursively);
13909
+ this.block.include(context, tryCatchDeoptimization ? INCLUDE_PARAMETERS : includeChildrenRecursively);
14298
13910
  if (includedLabels.size > 0) {
14299
13911
  this.includedLabelsAfterBlock = [...includedLabels];
14300
13912
  }
@@ -14306,10 +13918,10 @@ class TryStatement extends NodeBase {
14306
13918
  }
14307
13919
  }
14308
13920
  if (this.handler !== null) {
14309
- this.handler.includePath(UNKNOWN_PATH, context, includeChildrenRecursively);
13921
+ this.handler.include(context, includeChildrenRecursively);
14310
13922
  context.brokenFlow = brokenFlow;
14311
13923
  }
14312
- this.finalizer?.includePath(UNKNOWN_PATH, context, includeChildrenRecursively);
13924
+ this.finalizer?.include(context, includeChildrenRecursively);
14313
13925
  }
14314
13926
  }
14315
13927
 
@@ -14367,7 +13979,7 @@ class UpdateExpression extends NodeBase {
14367
13979
  hasEffectsOnInteractionAtPath(path, { type }) {
14368
13980
  return path.length > 1 || type !== INTERACTION_ACCESSED;
14369
13981
  }
14370
- includePath(_, context, includeChildrenRecursively) {
13982
+ include(context, includeChildrenRecursively) {
14371
13983
  if (!this.deoptimized)
14372
13984
  this.applyDeoptimizations();
14373
13985
  this.included = true;
@@ -14436,20 +14048,20 @@ class VariableDeclaration extends NodeBase {
14436
14048
  hasEffectsOnInteractionAtPath() {
14437
14049
  return false;
14438
14050
  }
14439
- includePath(_path, context, includeChildrenRecursively, { asSingleStatement } = BLANK) {
14051
+ include(context, includeChildrenRecursively, { asSingleStatement } = BLANK) {
14440
14052
  this.included = true;
14441
14053
  for (const declarator of this.declarations) {
14442
14054
  if (includeChildrenRecursively || declarator.shouldBeIncluded(context))
14443
- declarator.includePath(UNKNOWN_PATH, context, includeChildrenRecursively);
14055
+ declarator.include(context, includeChildrenRecursively);
14444
14056
  const { id, init } = declarator;
14445
14057
  if (asSingleStatement) {
14446
- id.includePath(EMPTY_PATH, context, includeChildrenRecursively);
14058
+ id.include(context, includeChildrenRecursively);
14447
14059
  }
14448
14060
  if (init &&
14449
14061
  id.included &&
14450
14062
  !init.included &&
14451
14063
  (id instanceof ObjectPattern || id instanceof ArrayPattern)) {
14452
- init.includePath(EMPTY_PATH, context, includeChildrenRecursively);
14064
+ init.include(context, includeChildrenRecursively);
14453
14065
  }
14454
14066
  }
14455
14067
  }
@@ -14521,7 +14133,8 @@ class VariableDeclaration extends NodeBase {
14521
14133
  const singleSystemExport = gatherSystemExportsAndGetSingleExport(separatedNodes, options, aggregatedSystemExports);
14522
14134
  for (const { node, start, separator, contentEnd, end } of separatedNodes) {
14523
14135
  if (!node.included) {
14524
- treeshakeNode(node, code, start, end);
14136
+ code.remove(start, end);
14137
+ node.removeAnnotations(code);
14525
14138
  continue;
14526
14139
  }
14527
14140
  node.render(code, options);
@@ -14598,9 +14211,9 @@ class WhileStatement extends NodeBase {
14598
14211
  return true;
14599
14212
  return hasLoopBodyEffects(context, this.body);
14600
14213
  }
14601
- includePath(_path, context, includeChildrenRecursively) {
14214
+ include(context, includeChildrenRecursively) {
14602
14215
  this.included = true;
14603
- this.test.includePath(UNKNOWN_PATH, context, includeChildrenRecursively);
14216
+ this.test.include(context, includeChildrenRecursively);
14604
14217
  includeLoopBody(context, this.body, includeChildrenRecursively);
14605
14218
  }
14606
14219
  }
@@ -14844,7 +14457,7 @@ const bufferParsers = [
14844
14457
  const annotations = (node.annotations = convertAnnotations(buffer[position + 1], buffer));
14845
14458
  node.annotationNoSideEffects = annotations.some(comment => comment.type === 'noSideEffects');
14846
14459
  const parameters = (node.params = convertNodeList(node, scope, buffer[position + 2], buffer));
14847
- scope.addParameterVariables(parameters.map(parameter => parameter.declare('parameter', EMPTY_PATH, UNKNOWN_EXPRESSION)), parameters[parameters.length - 1] instanceof RestElement);
14460
+ scope.addParameterVariables(parameters.map(parameter => parameter.declare('parameter', UNKNOWN_EXPRESSION)), parameters[parameters.length - 1] instanceof RestElement);
14848
14461
  node.body = convertNode(node, scope.bodyScope, buffer[position + 3], buffer);
14849
14462
  },
14850
14463
  function assignmentExpression(node, position, buffer) {
@@ -14890,7 +14503,7 @@ const bufferParsers = [
14890
14503
  const parameterPosition = buffer[position];
14891
14504
  const parameter = (node.param =
14892
14505
  parameterPosition === 0 ? null : convertNode(node, scope, parameterPosition, buffer));
14893
- parameter?.declare('parameter', EMPTY_PATH, UNKNOWN_EXPRESSION);
14506
+ parameter?.declare('parameter', UNKNOWN_EXPRESSION);
14894
14507
  node.body = convertNode(node, scope.bodyScope, buffer[position + 1], buffer);
14895
14508
  },
14896
14509
  function chainExpression(node, position, buffer) {
@@ -15028,7 +14641,7 @@ const bufferParsers = [
15028
14641
  node.id =
15029
14642
  idPosition === 0 ? null : convertNode(node, scope.parent, idPosition, buffer);
15030
14643
  const parameters = (node.params = convertNodeList(node, scope, buffer[position + 3], buffer));
15031
- scope.addParameterVariables(parameters.map(parameter => parameter.declare('parameter', EMPTY_PATH, UNKNOWN_EXPRESSION)), parameters[parameters.length - 1] instanceof RestElement);
14644
+ scope.addParameterVariables(parameters.map(parameter => parameter.declare('parameter', UNKNOWN_EXPRESSION)), parameters[parameters.length - 1] instanceof RestElement);
15032
14645
  node.body = convertNode(node, scope.bodyScope, buffer[position + 4], buffer);
15033
14646
  },
15034
14647
  function functionExpression(node, position, buffer) {
@@ -15041,7 +14654,7 @@ const bufferParsers = [
15041
14654
  const idPosition = buffer[position + 2];
15042
14655
  node.id = idPosition === 0 ? null : convertNode(node, node.idScope, idPosition, buffer);
15043
14656
  const parameters = (node.params = convertNodeList(node, scope, buffer[position + 3], buffer));
15044
- scope.addParameterVariables(parameters.map(parameter => parameter.declare('parameter', EMPTY_PATH, UNKNOWN_EXPRESSION)), parameters[parameters.length - 1] instanceof RestElement);
14657
+ scope.addParameterVariables(parameters.map(parameter => parameter.declare('parameter', UNKNOWN_EXPRESSION)), parameters[parameters.length - 1] instanceof RestElement);
15045
14658
  node.body = convertNode(node, scope.bodyScope, buffer[position + 4], buffer);
15046
14659
  },
15047
14660
  function identifier(node, position, buffer) {
@@ -15400,8 +15013,8 @@ class UnknownNode extends NodeBase {
15400
15013
  hasEffects() {
15401
15014
  return true;
15402
15015
  }
15403
- includePath(path, context) {
15404
- super.includePath(path, context, true);
15016
+ include(context) {
15017
+ super.include(context, true);
15405
15018
  }
15406
15019
  }
15407
15020
 
@@ -15505,8 +15118,8 @@ class ExportShimVariable extends Variable {
15505
15118
  super(MISSING_EXPORT_SHIM_VARIABLE);
15506
15119
  this.module = module;
15507
15120
  }
15508
- includePath(path, context) {
15509
- super.includePath(path, context);
15121
+ include() {
15122
+ super.include();
15510
15123
  this.module.needsExportShim = true;
15511
15124
  }
15512
15125
  }
@@ -16197,7 +15810,7 @@ class Module {
16197
15810
  include() {
16198
15811
  const context = createInclusionContext();
16199
15812
  if (this.ast.shouldBeIncluded(context))
16200
- this.ast.includePath(EMPTY_PATH, context, false);
15813
+ this.ast.include(context, false);
16201
15814
  }
16202
15815
  includeAllExports(includeNamespaceMembers) {
16203
15816
  if (!this.isExecuted) {
@@ -16211,7 +15824,9 @@ class Module {
16211
15824
  return error(logMissingEntryExport(exportName, this.id));
16212
15825
  }
16213
15826
  variable.deoptimizePath(UNKNOWN_PATH);
16214
- this.includeVariable(variable, UNKNOWN_PATH);
15827
+ if (!variable.included) {
15828
+ this.includeVariable(variable);
15829
+ }
16215
15830
  }
16216
15831
  }
16217
15832
  for (const name of this.getReexports()) {
@@ -16219,7 +15834,7 @@ class Module {
16219
15834
  if (variable) {
16220
15835
  variable.deoptimizePath(UNKNOWN_PATH);
16221
15836
  if (!variable.included) {
16222
- this.includeVariable(variable, UNKNOWN_PATH);
15837
+ this.includeVariable(variable);
16223
15838
  }
16224
15839
  if (variable instanceof ExternalVariable) {
16225
15840
  variable.module.reexported = true;
@@ -16231,7 +15846,7 @@ class Module {
16231
15846
  }
16232
15847
  }
16233
15848
  includeAllInBundle() {
16234
- this.ast.includePath(UNKNOWN_PATH, createInclusionContext(), true);
15849
+ this.ast.include(createInclusionContext(), true);
16235
15850
  this.includeAllExports(false);
16236
15851
  }
16237
15852
  includeExportsByNames(names) {
@@ -16245,7 +15860,7 @@ class Module {
16245
15860
  if (variable) {
16246
15861
  variable.deoptimizePath(UNKNOWN_PATH);
16247
15862
  if (!variable.included) {
16248
- this.includeVariable(variable, UNKNOWN_PATH);
15863
+ this.includeVariable(variable);
16249
15864
  }
16250
15865
  }
16251
15866
  if (!this.exports.has(name) && !this.reexportDescriptions.has(name)) {
@@ -16687,13 +16302,13 @@ class Module {
16687
16302
  for (const module of [this, ...this.exportAllModules]) {
16688
16303
  if (module instanceof ExternalModule) {
16689
16304
  const [externalVariable] = module.getVariableForExportName('*');
16690
- externalVariable.includePath(UNKNOWN_PATH, createInclusionContext());
16305
+ externalVariable.include();
16691
16306
  this.includedImports.add(externalVariable);
16692
16307
  externalNamespaces.add(externalVariable);
16693
16308
  }
16694
16309
  else if (module.info.syntheticNamedExports) {
16695
16310
  const syntheticNamespace = module.getSyntheticNamespace();
16696
- syntheticNamespace.includePath(UNKNOWN_PATH, createInclusionContext());
16311
+ syntheticNamespace.include();
16697
16312
  this.includedImports.add(syntheticNamespace);
16698
16313
  syntheticNamespaces.add(syntheticNamespace);
16699
16314
  }
@@ -16703,9 +16318,7 @@ class Module {
16703
16318
  includeDynamicImport(node) {
16704
16319
  const resolution = this.dynamicImports.find(dynamicImport => dynamicImport.node === node).resolution;
16705
16320
  if (resolution instanceof Module) {
16706
- if (!resolution.includedDynamicImporters.includes(this)) {
16707
- resolution.includedDynamicImporters.push(this);
16708
- }
16321
+ resolution.includedDynamicImporters.push(this);
16709
16322
  const importedNames = this.options.treeshake
16710
16323
  ? node.getDeterministicImportedNames()
16711
16324
  : undefined;
@@ -16717,7 +16330,7 @@ class Module {
16717
16330
  }
16718
16331
  }
16719
16332
  }
16720
- includeVariable(variable, path) {
16333
+ includeVariable(variable) {
16721
16334
  const variableModule = variable.module;
16722
16335
  if (variable.included) {
16723
16336
  if (variableModule instanceof Module && variableModule !== this) {
@@ -16725,6 +16338,7 @@ class Module {
16725
16338
  }
16726
16339
  }
16727
16340
  else {
16341
+ variable.include();
16728
16342
  this.graph.needsTreeshakingPass = true;
16729
16343
  if (variableModule instanceof Module) {
16730
16344
  if (!variableModule.isExecuted) {
@@ -16740,10 +16354,9 @@ class Module {
16740
16354
  }
16741
16355
  }
16742
16356
  }
16743
- variable.includePath(path, createInclusionContext());
16744
16357
  }
16745
- includeVariableInModule(variable, path) {
16746
- this.includeVariable(variable, path);
16358
+ includeVariableInModule(variable) {
16359
+ this.includeVariable(variable);
16747
16360
  const variableModule = variable.module;
16748
16361
  if (variableModule && variableModule !== this) {
16749
16362
  this.includedImports.add(variable);
@@ -21340,7 +20953,7 @@ class Graph {
21340
20953
  this.options = options;
21341
20954
  this.astLru = flru(5);
21342
20955
  this.cachedModules = new Map();
21343
- this.deoptimizationTracker = new EntityPathTracker();
20956
+ this.deoptimizationTracker = new PathTracker();
21344
20957
  this.entryModules = [];
21345
20958
  this.modulesById = new Map();
21346
20959
  this.needsTreeshakingPass = false;
@@ -22340,7 +21953,7 @@ createColors();
22340
21953
 
22341
21954
  // @see https://no-color.org
22342
21955
  // @see https://www.npmjs.com/package/chalk
22343
- const { bold, cyan, dim, red} = createColors({
21956
+ const { bold, cyan, dim, gray, green, red, underline, yellow } = createColors({
22344
21957
  useColor: env$1.FORCE_COLOR !== '0' && !env$1.NO_COLOR
22345
21958
  });
22346
21959