@rollup/wasm-node 4.33.0-0 → 4.33.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,21 +1,21 @@
1
1
  /*
2
2
  @license
3
- Rollup.js v4.33.0-0
4
- Tue, 28 Jan 2025 08:29:38 GMT - commit f854e1988542d09f9691923eddd80888e92240d3
3
+ Rollup.js v4.33.0
4
+ Sat, 01 Feb 2025 07:11:29 GMT - commit 494483e8df7b5d04796b30e37f54d7e96fa91a97
5
5
 
6
6
  https://github.com/rollup/rollup
7
7
 
8
8
  Released under the MIT License.
9
9
  */
10
- import { EMPTY_OBJECT, ExportDefaultDeclaration as ExportDefaultDeclaration$1, CallExpression as CallExpression$1, EMPTY_ARRAY, LOGLEVEL_WARN, logUnusedExternalImports, ANNOTATION_KEY, INVALID_ANNOTATION_KEY, ObjectExpression as ObjectExpression$1, Property as Property$1, Program as Program$1, logIllegalImportReassignment, BLANK, logRedeclarationError, StaticBlock as StaticBlock$1, CatchClause as CatchClause$1, logDuplicateArgumentNameError, logModuleLevelDirective, ReturnStatement as ReturnStatement$1, VariableDeclarator as VariableDeclarator$1, ExpressionStatement as ExpressionStatement$1, logMissingExport, normalize, getImportPath, logMissingNodeBuiltins, logReservedNamespace, error, logIllegalIdentifierAsName, logMissingNameOptionForIifeExport, logMissingNameOptionForUmdExport, logConstVariableReassignError, ArrowFunctionExpression as ArrowFunctionExpression$1, EMPTY_SET, logCannotCallNamespace, logEval, BlockStatement as BlockStatement$1, getRollupError, logModuleParseError, logParseError, LOGLEVEL_INFO, logFirstSideEffect, locate, logInvalidAnnotation, Identifier as Identifier$1, logThisIsUndefined, getAstBuffer, convertAnnotations, FIXED_STRINGS, convertNode as convertNode$1, logImportAttributeIsInvalid, logImportOptionsAreInvalid, logSyntheticNamedExportsNeedNamespaceExport, logMissingEntryExport, logDuplicateExportError, logInvalidSourcemapForError, augmentCodeLocation, logInconsistentImportAttributes, logMissingJsxExport, logNamespaceConflict, logAmbiguousExternalNamespaces, logShimmedExport, parseAst, logInvalidFormatForTopLevelAwait, TemplateLiteral as TemplateLiteral$1, Literal as Literal$1, logCircularReexport, logAddonNotGenerated, logIncompatibleExportOptionValue, logMixedExport, logFailedValidation, isPathFragment, logCyclicCrossChunkReexport, getAliasName, logUnexpectedNamedImport, isAbsolute as isAbsolute$1, relative as relative$1, logUnexpectedNamespaceReexport, logEmptyChunk, logMissingGlobalName, logOptimizeChunkStatus, logSourcemapBroken, logConflictingSourcemapSources, logChunkInvalid, logInvalidOption, logCannotAssignModuleToChunk, URL_OUTPUT_FORMAT, URL_OUTPUT_DIR, URL_OUTPUT_SOURCEMAPFILE, URL_OUTPUT_AMD_ID, logAnonymousPluginCache, logDuplicatePluginName, logUnknownOption, LOGLEVEL_ERROR, logLevelPriority, LOGLEVEL_DEBUG, printQuotedStringList, logInvalidSetAssetSourceCall, logPluginError, logNoTransformMapOrAstWithoutCode, relativeId, logBadLoader, logExternalModulesCannotBeTransformedToModules, logInternalIdCannotBeExternal, isRelative, logUnresolvedImport, logUnresolvedImportTreatedAsExternal, logExternalSyntheticExports, logUnresolvedEntry, logUnresolvedImplicitDependant, logExternalModulesCannotBeIncludedInManualChunks, logEntryCannotBeExternal, logImplicitDependantCannotBeExternal, logNoAssetSourceSet, logFileReferenceIdNotFoundForFilename, logAssetReferenceIdNotFoundForSetSource, logAssetSourceAlreadySet, logInvalidRollupPhaseForChunkEmission, warnDeprecation, logChunkNotGeneratedForFileName, logAssetNotFinalisedForFileName, logFileNameConflict, URL_GENERATEBUNDLE, logInvalidLogPosition, logInputHookInOutputPlugin, logInvalidAddonPluginHook, logInvalidFunctionPluginHook, logImplicitDependantIsNotIncluded, logCircularDependency, augmentLogMessage, URL_TREESHAKE, URL_JSX, URL_TREESHAKE_MODULESIDEEFFECTS, URL_OUTPUT_INLINEDYNAMICIMPORTS, URL_PRESERVEENTRYSIGNATURES, URL_OUTPUT_GENERATEDCODE, isValidUrl, addTrailingSlashIfMissed, URL_OUTPUT_SOURCEMAPBASEURL, URL_OUTPUT_MANUALCHUNKS, logInvalidExportOptionValue, URL_OUTPUT_AMD_BASEPATH, URL_OUTPUT_INTEROP, URL_OUTPUT_EXTERNALIMPORTATTRIBUTES, logAlreadyClosed, logMissingFileOrDirOption, logCannotEmitFromOptionsHook, URL_WATCH } from './parseAst.js';
10
+ import { ExportDefaultDeclaration as ExportDefaultDeclaration$1, CallExpression as CallExpression$1, EMPTY_ARRAY, LOGLEVEL_WARN, logUnusedExternalImports, ANNOTATION_KEY, INVALID_ANNOTATION_KEY, ObjectExpression as ObjectExpression$1, Property as Property$1, Program as Program$1, logIllegalImportReassignment, BLANK, logRedeclarationError, StaticBlock as StaticBlock$1, CatchClause as CatchClause$1, logDuplicateArgumentNameError, logModuleLevelDirective, ReturnStatement as ReturnStatement$1, VariableDeclarator as VariableDeclarator$1, ExpressionStatement as ExpressionStatement$1, logMissingExport, normalize, getImportPath, logMissingNodeBuiltins, logReservedNamespace, error, logIllegalIdentifierAsName, logMissingNameOptionForIifeExport, logMissingNameOptionForUmdExport, logConstVariableReassignError, ArrowFunctionExpression as ArrowFunctionExpression$1, EMPTY_SET, logCannotCallNamespace, logEval, BlockStatement as BlockStatement$1, getRollupError, logParseError, logModuleParseError, LOGLEVEL_INFO, logFirstSideEffect, locate, logInvalidAnnotation, Identifier as Identifier$1, logThisIsUndefined, getAstBuffer, convertAnnotations, FIXED_STRINGS, convertNode as convertNode$1, EMPTY_OBJECT, logImportAttributeIsInvalid, logImportOptionsAreInvalid, logSyntheticNamedExportsNeedNamespaceExport, logMissingEntryExport, logDuplicateExportError, logInvalidSourcemapForError, augmentCodeLocation, logInconsistentImportAttributes, logMissingJsxExport, logNamespaceConflict, logAmbiguousExternalNamespaces, logShimmedExport, parseAst, logCircularReexport, logInvalidFormatForTopLevelAwait, TemplateLiteral as TemplateLiteral$1, Literal as Literal$1, logAddonNotGenerated, logIncompatibleExportOptionValue, logMixedExport, logFailedValidation, isPathFragment, logCyclicCrossChunkReexport, getAliasName, logUnexpectedNamedImport, isAbsolute as isAbsolute$1, relative as relative$1, logUnexpectedNamespaceReexport, logEmptyChunk, logMissingGlobalName, logOptimizeChunkStatus, logSourcemapBroken, logConflictingSourcemapSources, logChunkInvalid, logInvalidOption, URL_OUTPUT_FORMAT, URL_OUTPUT_DIR, URL_OUTPUT_SOURCEMAPFILE, URL_OUTPUT_AMD_ID, logCannotAssignModuleToChunk, logAnonymousPluginCache, logDuplicatePluginName, logUnknownOption, printQuotedStringList, LOGLEVEL_ERROR, logLevelPriority, LOGLEVEL_DEBUG, logInvalidSetAssetSourceCall, logPluginError, logNoTransformMapOrAstWithoutCode, relativeId, logBadLoader, logExternalModulesCannotBeTransformedToModules, logInternalIdCannotBeExternal, isRelative, logUnresolvedImport, logUnresolvedImportTreatedAsExternal, logExternalSyntheticExports, logUnresolvedEntry, logUnresolvedImplicitDependant, logExternalModulesCannotBeIncludedInManualChunks, logEntryCannotBeExternal, logImplicitDependantCannotBeExternal, logNoAssetSourceSet, logFileReferenceIdNotFoundForFilename, logAssetReferenceIdNotFoundForSetSource, logAssetSourceAlreadySet, logInvalidRollupPhaseForChunkEmission, warnDeprecation, URL_GENERATEBUNDLE, logFileNameConflict, logAssetNotFinalisedForFileName, logChunkNotGeneratedForFileName, logInvalidLogPosition, logInputHookInOutputPlugin, logInvalidFunctionPluginHook, logInvalidAddonPluginHook, logImplicitDependantIsNotIncluded, logCircularDependency, augmentLogMessage, URL_JSX, URL_TREESHAKE, URL_TREESHAKE_MODULESIDEEFFECTS, logInvalidExportOptionValue, URL_OUTPUT_INTEROP, isValidUrl, addTrailingSlashIfMissed, URL_OUTPUT_SOURCEMAPBASEURL, URL_OUTPUT_INLINEDYNAMICIMPORTS, URL_PRESERVEENTRYSIGNATURES, URL_OUTPUT_AMD_BASEPATH, URL_OUTPUT_GENERATEDCODE, URL_OUTPUT_MANUALCHUNKS, URL_OUTPUT_EXTERNALIMPORTATTRIBUTES, logAlreadyClosed, logMissingFileOrDirOption, logCannotEmitFromOptionsHook, URL_WATCH } from './parseAst.js';
11
11
  import { relative, dirname, basename, extname, resolve as resolve$1 } from 'node:path';
12
- import { posix, isAbsolute, resolve, win32 } from 'path';
13
- import { parseAsync, xxhashBase16, xxhashBase64Url, xxhashBase36 } from '../../native.js';
12
+ import { posix, win32, isAbsolute, resolve } from 'path';
13
+ import { parseAsync, xxhashBase64Url, xxhashBase36, xxhashBase16 } from '../../native.js';
14
14
  import process$1, { env } 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
 
18
- var version = "4.33.0-0";
18
+ var version = "4.33.0";
19
19
 
20
20
  const comma = ','.charCodeAt(0);
21
21
  const semicolon = ';'.charCodeAt(0);
@@ -1964,6 +1964,71 @@ function renderSystemExportSequenceBeforeExpression(exportedVariable, expression
1964
1964
  }
1965
1965
  }
1966
1966
 
1967
+ /** @import { Node } from 'estree' */
1968
+
1969
+ /**
1970
+ * @param {Node} node
1971
+ * @param {Node} parent
1972
+ * @returns {boolean}
1973
+ */
1974
+ function is_reference(node, parent) {
1975
+ if (node.type === 'MemberExpression') {
1976
+ return !node.computed && is_reference(node.object, node);
1977
+ }
1978
+
1979
+ if (node.type !== 'Identifier') return false;
1980
+
1981
+ switch (parent?.type) {
1982
+ // disregard `bar` in `foo.bar`
1983
+ case 'MemberExpression':
1984
+ return parent.computed || node === parent.object;
1985
+
1986
+ // disregard the `foo` in `class {foo(){}}` but keep it in `class {[foo](){}}`
1987
+ case 'MethodDefinition':
1988
+ return parent.computed;
1989
+
1990
+ // disregard the `meta` in `import.meta`
1991
+ case 'MetaProperty':
1992
+ return parent.meta === node;
1993
+
1994
+ // disregard the `foo` in `class {foo=bar}` but keep it in `class {[foo]=bar}` and `class {bar=foo}`
1995
+ case 'PropertyDefinition':
1996
+ return parent.computed || node === parent.value;
1997
+
1998
+ // disregard the `bar` in `{ bar: foo }`, but keep it in `{ [bar]: foo }`
1999
+ case 'Property':
2000
+ return parent.computed || node === parent.value;
2001
+
2002
+ // disregard the `bar` in `export { foo as bar }` or
2003
+ // the foo in `import { foo as bar }`
2004
+ case 'ExportSpecifier':
2005
+ case 'ImportSpecifier':
2006
+ return node === parent.local;
2007
+
2008
+ // disregard the `foo` in `foo: while (...) { ... break foo; ... continue foo;}`
2009
+ case 'LabeledStatement':
2010
+ case 'BreakStatement':
2011
+ case 'ContinueStatement':
2012
+ return false;
2013
+
2014
+ default:
2015
+ return true;
2016
+ }
2017
+ }
2018
+
2019
+ const PureFunctionKey = Symbol('PureFunction');
2020
+ const getPureFunctions = ({ treeshake }) => {
2021
+ const pureFunctions = Object.create(null);
2022
+ for (const functionName of treeshake ? treeshake.manualPureFunctions : []) {
2023
+ let currentFunctions = pureFunctions;
2024
+ for (const pathSegment of functionName.split('.')) {
2025
+ currentFunctions = currentFunctions[pathSegment] ||= Object.create(null);
2026
+ }
2027
+ currentFunctions[PureFunctionKey] = true;
2028
+ }
2029
+ return pureFunctions;
2030
+ };
2031
+
1967
2032
  function getOrCreate(map, key, init) {
1968
2033
  const existing = map.get(key);
1969
2034
  if (existing !== undefined) {
@@ -1994,7 +2059,7 @@ const UNKNOWN_PATH = [UnknownKey];
1994
2059
  const UNKNOWN_NON_ACCESSOR_PATH = [UnknownNonAccessorKey];
1995
2060
  const UNKNOWN_INTEGER_PATH = [UnknownInteger];
1996
2061
  const EntitiesKey = Symbol('Entities');
1997
- class EntityPathTracker {
2062
+ class PathTracker {
1998
2063
  constructor() {
1999
2064
  this.entityPaths = Object.create(null, {
2000
2065
  [EntitiesKey]: { value: new Set() }
@@ -2019,14 +2084,14 @@ class EntityPathTracker {
2019
2084
  getEntities(path) {
2020
2085
  let currentPaths = this.entityPaths;
2021
2086
  for (const pathSegment of path) {
2022
- currentPaths = currentPaths[pathSegment] ||= Object.create(null, {
2023
- [EntitiesKey]: { value: new Set() }
2024
- });
2087
+ currentPaths = currentPaths[pathSegment] =
2088
+ currentPaths[pathSegment] ||
2089
+ Object.create(null, { [EntitiesKey]: { value: new Set() } });
2025
2090
  }
2026
2091
  return currentPaths[EntitiesKey];
2027
2092
  }
2028
2093
  }
2029
- const SHARED_RECURSION_TRACKER = new EntityPathTracker();
2094
+ const SHARED_RECURSION_TRACKER = new PathTracker();
2030
2095
  class DiscriminatedPathTracker {
2031
2096
  constructor() {
2032
2097
  this.entityPaths = Object.create(null, {
@@ -2036,9 +2101,9 @@ class DiscriminatedPathTracker {
2036
2101
  trackEntityAtPathAndGetIfTracked(path, discriminator, entity) {
2037
2102
  let currentPaths = this.entityPaths;
2038
2103
  for (const pathSegment of path) {
2039
- currentPaths = currentPaths[pathSegment] ||= Object.create(null, {
2040
- [EntitiesKey]: { value: new Map() }
2041
- });
2104
+ currentPaths = currentPaths[pathSegment] =
2105
+ currentPaths[pathSegment] ||
2106
+ Object.create(null, { [EntitiesKey]: { value: new Map() } });
2042
2107
  }
2043
2108
  const trackedEntities = getOrCreate(currentPaths[EntitiesKey], discriminator, (getNewSet));
2044
2109
  if (trackedEntities.has(entity))
@@ -2047,174 +2112,6 @@ class DiscriminatedPathTracker {
2047
2112
  return false;
2048
2113
  }
2049
2114
  }
2050
- const UNKNOWN_INCLUDED_PATH = Object.freeze({ [UnknownKey]: EMPTY_OBJECT });
2051
- class IncludedFullPathTracker {
2052
- constructor() {
2053
- this.includedPaths = null;
2054
- }
2055
- includePathAndGetIfIncluded(path) {
2056
- let included = true;
2057
- let parent = this;
2058
- let parentSegment = 'includedPaths';
2059
- let currentPaths = (this.includedPaths ||=
2060
- ((included = false), Object.create(null)));
2061
- for (const pathSegment of path) {
2062
- // This means from here, all paths are included
2063
- if (currentPaths[UnknownKey]) {
2064
- return true;
2065
- }
2066
- // Including UnknownKey automatically includes all nested paths.
2067
- // From above, we know that UnknownKey is not included yet.
2068
- if (typeof pathSegment === 'symbol') {
2069
- // Hopefully, this saves some memory over just setting
2070
- // currentPaths[UnknownKey] = EMPTY_OBJECT
2071
- parent[parentSegment] = UNKNOWN_INCLUDED_PATH;
2072
- return false;
2073
- }
2074
- parent = currentPaths;
2075
- parentSegment = pathSegment;
2076
- currentPaths = currentPaths[pathSegment] ||= ((included = false), Object.create(null));
2077
- }
2078
- return included;
2079
- }
2080
- }
2081
- const UNKNOWN_INCLUDED_TOP_LEVEL_PATH = Object.freeze({
2082
- [UnknownKey]: true
2083
- });
2084
- class IncludedTopLevelPathTracker {
2085
- constructor() {
2086
- this.includedPaths = null;
2087
- }
2088
- includePathAndGetIfIncluded(path) {
2089
- let included = true;
2090
- const includedPaths = (this.includedPaths ||=
2091
- ((included = false), Object.create(null)));
2092
- if (includedPaths[UnknownKey]) {
2093
- return true;
2094
- }
2095
- const [firstPathSegment, secondPathSegment] = path;
2096
- if (!firstPathSegment) {
2097
- return included;
2098
- }
2099
- if (typeof firstPathSegment === 'symbol') {
2100
- this.includedPaths = UNKNOWN_INCLUDED_TOP_LEVEL_PATH;
2101
- return false;
2102
- }
2103
- if (secondPathSegment) {
2104
- if (includedPaths[firstPathSegment] === UnknownKey) {
2105
- return true;
2106
- }
2107
- includedPaths[firstPathSegment] = UnknownKey;
2108
- return false;
2109
- }
2110
- if (includedPaths[firstPathSegment]) {
2111
- return true;
2112
- }
2113
- includedPaths[firstPathSegment] = true;
2114
- return false;
2115
- }
2116
- includeAllPaths(entity, context, basePath) {
2117
- const { includedPaths } = this;
2118
- if (includedPaths) {
2119
- if (includedPaths[UnknownKey]) {
2120
- entity.includePath([...basePath, UnknownKey], context);
2121
- }
2122
- else {
2123
- const inclusionEntries = Object.entries(includedPaths);
2124
- if (inclusionEntries.length === 0) {
2125
- entity.includePath(basePath, context);
2126
- }
2127
- else {
2128
- for (const [key, value] of inclusionEntries) {
2129
- entity.includePath(value === UnknownKey ? [...basePath, key, UnknownKey] : [...basePath, key], context);
2130
- }
2131
- }
2132
- }
2133
- }
2134
- }
2135
- }
2136
-
2137
- /** @import { Node } from 'estree' */
2138
-
2139
- /**
2140
- * @param {Node} node
2141
- * @param {Node} parent
2142
- * @returns {boolean}
2143
- */
2144
- function is_reference(node, parent) {
2145
- if (node.type === 'MemberExpression') {
2146
- return !node.computed && is_reference(node.object, node);
2147
- }
2148
-
2149
- if (node.type !== 'Identifier') return false;
2150
-
2151
- switch (parent?.type) {
2152
- // disregard `bar` in `foo.bar`
2153
- case 'MemberExpression':
2154
- return parent.computed || node === parent.object;
2155
-
2156
- // disregard the `foo` in `class {foo(){}}` but keep it in `class {[foo](){}}`
2157
- case 'MethodDefinition':
2158
- return parent.computed;
2159
-
2160
- // disregard the `meta` in `import.meta`
2161
- case 'MetaProperty':
2162
- return parent.meta === node;
2163
-
2164
- // disregard the `foo` in `class {foo=bar}` but keep it in `class {[foo]=bar}` and `class {bar=foo}`
2165
- case 'PropertyDefinition':
2166
- return parent.computed || node === parent.value;
2167
-
2168
- // disregard the `bar` in `{ bar: foo }`, but keep it in `{ [bar]: foo }`
2169
- case 'Property':
2170
- return parent.computed || node === parent.value;
2171
-
2172
- // disregard the `bar` in `export { foo as bar }` or
2173
- // the foo in `import { foo as bar }`
2174
- case 'ExportSpecifier':
2175
- case 'ImportSpecifier':
2176
- return node === parent.local;
2177
-
2178
- // disregard the `foo` in `foo: while (...) { ... break foo; ... continue foo;}`
2179
- case 'LabeledStatement':
2180
- case 'BreakStatement':
2181
- case 'ContinueStatement':
2182
- return false;
2183
-
2184
- default:
2185
- return true;
2186
- }
2187
- }
2188
-
2189
- function createInclusionContext() {
2190
- return {
2191
- brokenFlow: false,
2192
- hasBreak: false,
2193
- hasContinue: false,
2194
- includedCallArguments: new Set(),
2195
- includedLabels: new Set()
2196
- };
2197
- }
2198
- function createHasEffectsContext() {
2199
- return {
2200
- accessed: new EntityPathTracker(),
2201
- assigned: new EntityPathTracker(),
2202
- brokenFlow: false,
2203
- called: new DiscriminatedPathTracker(),
2204
- hasBreak: false,
2205
- hasContinue: false,
2206
- ignore: {
2207
- breaks: false,
2208
- continues: false,
2209
- labels: new Set(),
2210
- returnYield: false,
2211
- this: false
2212
- },
2213
- includedLabels: new Set(),
2214
- instantiated: new DiscriminatedPathTracker(),
2215
- replacedVariableInits: new Map()
2216
- };
2217
- }
2218
2115
 
2219
2116
  function isFlagSet(flags, flag) {
2220
2117
  return (flags & flag) !== 0;
@@ -2254,25 +2151,12 @@ class ExpressionEntity {
2254
2151
  hasEffectsOnInteractionAtPath(_path, _interaction, _context) {
2255
2152
  return true;
2256
2153
  }
2257
- include(context, _includeChildrenRecursively, _options) {
2258
- if (!this.included)
2259
- this.includeNode(context);
2260
- }
2261
- includeNode(_context) {
2154
+ include(_context, _includeChildrenRecursively, _options) {
2262
2155
  this.included = true;
2263
2156
  }
2264
- includePath(_path, context) {
2265
- if (!this.included)
2266
- this.includeNode(context);
2267
- }
2268
- /* We are both including and including an unknown path here as the former
2269
- * ensures that nested nodes are included while the latter ensures that all
2270
- * paths of the expression are included.
2271
- * */
2272
- includeCallArguments(context, interaction) {
2273
- for (const argument of interaction.args) {
2274
- argument?.includePath(UNKNOWN_PATH, context);
2275
- argument?.include(context, false);
2157
+ includeCallArguments(context, parameters) {
2158
+ for (const argument of parameters) {
2159
+ argument.include(context, false);
2276
2160
  }
2277
2161
  }
2278
2162
  shouldBeIncluded(_context) {
@@ -2311,19 +2195,6 @@ const NODE_INTERACTION_UNKNOWN_CALL = {
2311
2195
  withNew: false
2312
2196
  };
2313
2197
 
2314
- const PureFunctionKey = Symbol('PureFunction');
2315
- const getPureFunctions = ({ treeshake }) => {
2316
- const pureFunctions = Object.create(null);
2317
- for (const functionName of treeshake ? treeshake.manualPureFunctions : []) {
2318
- let currentFunctions = pureFunctions;
2319
- for (const pathSegment of functionName.split('.')) {
2320
- currentFunctions = currentFunctions[pathSegment] ||= Object.create(null);
2321
- }
2322
- currentFunctions[PureFunctionKey] = true;
2323
- }
2324
- return pureFunctions;
2325
- };
2326
-
2327
2198
  class Variable extends ExpressionEntity {
2328
2199
  markReassigned() {
2329
2200
  this.isReassigned = true;
@@ -2400,9 +2271,9 @@ class Variable extends ExpressionEntity {
2400
2271
  * has not been included previously. Once a variable is included, it should
2401
2272
  * take care all its declarations are included.
2402
2273
  */
2403
- includePath(path, context) {
2274
+ include() {
2404
2275
  this.included = true;
2405
- this.renderedLikeHoisted?.includePath(path, context);
2276
+ this.renderedLikeHoisted?.include();
2406
2277
  }
2407
2278
  /**
2408
2279
  * Links the rendered name of this variable to another variable and includes
@@ -2434,8 +2305,8 @@ class ExternalVariable extends Variable {
2434
2305
  hasEffectsOnInteractionAtPath(path, { type }) {
2435
2306
  return type !== INTERACTION_ACCESSED || path.length > (this.isNamespace ? 1 : 0);
2436
2307
  }
2437
- includePath(path, context) {
2438
- super.includePath(path, context);
2308
+ include() {
2309
+ super.include();
2439
2310
  this.module.used = true;
2440
2311
  }
2441
2312
  }
@@ -2736,6 +2607,36 @@ const childNodeKeys = {
2736
2607
  YieldExpression: ['argument']
2737
2608
  };
2738
2609
 
2610
+ function createInclusionContext() {
2611
+ return {
2612
+ brokenFlow: false,
2613
+ hasBreak: false,
2614
+ hasContinue: false,
2615
+ includedCallArguments: new Set(),
2616
+ includedLabels: new Set()
2617
+ };
2618
+ }
2619
+ function createHasEffectsContext() {
2620
+ return {
2621
+ accessed: new PathTracker(),
2622
+ assigned: new PathTracker(),
2623
+ brokenFlow: false,
2624
+ called: new DiscriminatedPathTracker(),
2625
+ hasBreak: false,
2626
+ hasContinue: false,
2627
+ ignore: {
2628
+ breaks: false,
2629
+ continues: false,
2630
+ labels: new Set(),
2631
+ returnYield: false,
2632
+ this: false
2633
+ },
2634
+ includedLabels: new Set(),
2635
+ instantiated: new DiscriminatedPathTracker(),
2636
+ replacedVariableInits: new Map()
2637
+ };
2638
+ }
2639
+
2739
2640
  const INCLUDE_PARAMETERS = 'variables';
2740
2641
  const IS_SKIPPED_CHAIN = Symbol('IS_SKIPPED_CHAIN');
2741
2642
  class NodeBase extends ExpressionEntity {
@@ -2805,37 +2706,20 @@ class NodeBase extends ExpressionEntity {
2805
2706
  this.hasEffectsOnInteractionAtPath(EMPTY_PATH, this.assignmentInteraction, context));
2806
2707
  }
2807
2708
  include(context, includeChildrenRecursively, _options) {
2808
- if (!this.included)
2809
- this.includeNode(context);
2810
- for (const key of childNodeKeys[this.type]) {
2811
- const value = this[key];
2812
- if (value === null)
2813
- continue;
2814
- if (Array.isArray(value)) {
2815
- for (const child of value) {
2816
- child?.include(context, includeChildrenRecursively);
2817
- }
2818
- }
2819
- else {
2820
- value.include(context, includeChildrenRecursively);
2821
- }
2822
- }
2823
- }
2824
- includeNode(context) {
2825
- this.included = true;
2826
2709
  if (!this.deoptimized)
2827
2710
  this.applyDeoptimizations();
2711
+ this.included = true;
2828
2712
  for (const key of childNodeKeys[this.type]) {
2829
2713
  const value = this[key];
2830
2714
  if (value === null)
2831
2715
  continue;
2832
2716
  if (Array.isArray(value)) {
2833
2717
  for (const child of value) {
2834
- child?.includePath(UNKNOWN_PATH, context);
2718
+ child?.include(context, includeChildrenRecursively);
2835
2719
  }
2836
2720
  }
2837
2721
  else {
2838
- value.includePath(UNKNOWN_PATH, context);
2722
+ value.include(context, includeChildrenRecursively);
2839
2723
  }
2840
2724
  }
2841
2725
  }
@@ -2942,17 +2826,6 @@ class NodeBase extends ExpressionEntity {
2942
2826
  function createChildNodeKeysForNode(esTreeNode) {
2943
2827
  return Object.keys(esTreeNode).filter(key => typeof esTreeNode[key] === 'object' && key.charCodeAt(0) !== 95 /* _ */);
2944
2828
  }
2945
- function onlyIncludeSelf() {
2946
- this.included = true;
2947
- if (!this.deoptimized)
2948
- this.applyDeoptimizations();
2949
- }
2950
- function onlyIncludeSelfNoDeoptimize() {
2951
- this.included = true;
2952
- }
2953
- function doNotDeoptimize() {
2954
- this.deoptimized = true;
2955
- }
2956
2829
 
2957
2830
  function isObjectExpressionNode(node) {
2958
2831
  return node instanceof NodeBase && node.type === ObjectExpression$1;
@@ -2965,8 +2838,8 @@ function assembleMemberDescriptions(memberDescriptions, inheritedDescriptions =
2965
2838
  return Object.create(inheritedDescriptions, memberDescriptions);
2966
2839
  }
2967
2840
  const UNDEFINED_EXPRESSION = new (class UndefinedExpression extends ExpressionEntity {
2968
- getLiteralValueAtPath(path) {
2969
- return path.length > 0 ? UnknownValue : undefined;
2841
+ getLiteralValueAtPath() {
2842
+ return undefined;
2970
2843
  }
2971
2844
  })();
2972
2845
  const returnsUnknown = {
@@ -3163,6 +3036,31 @@ function getMemberReturnExpressionWhenCalled(members, memberName) {
3163
3036
  return [members[memberName].returns, false];
3164
3037
  }
3165
3038
 
3039
+ class SpreadElement extends NodeBase {
3040
+ deoptimizeArgumentsOnInteractionAtPath(interaction, path, recursionTracker) {
3041
+ if (path.length > 0) {
3042
+ this.argument.deoptimizeArgumentsOnInteractionAtPath(interaction, UNKNOWN_PATH, recursionTracker);
3043
+ }
3044
+ }
3045
+ hasEffects(context) {
3046
+ if (!this.deoptimized)
3047
+ this.applyDeoptimizations();
3048
+ const { propertyReadSideEffects } = this.scope.context.options
3049
+ .treeshake;
3050
+ return (this.argument.hasEffects(context) ||
3051
+ (propertyReadSideEffects &&
3052
+ (propertyReadSideEffects === 'always' ||
3053
+ this.argument.hasEffectsOnInteractionAtPath(UNKNOWN_PATH, NODE_INTERACTION_UNKNOWN_ACCESS, context))));
3054
+ }
3055
+ applyDeoptimizations() {
3056
+ this.deoptimized = true;
3057
+ // Only properties of properties of the argument could become subject to reassignment
3058
+ // This will also reassign the return values of iterators
3059
+ this.argument.deoptimizePath([UnknownKey, UnknownKey]);
3060
+ this.scope.context.requestTreeshakingPass();
3061
+ }
3062
+ }
3063
+
3166
3064
  class Method extends ExpressionEntity {
3167
3065
  constructor(description) {
3168
3066
  super();
@@ -3288,7 +3186,6 @@ class ObjectEntity extends ExpressionEntity {
3288
3186
  this.unknownIntegerProps = [];
3289
3187
  this.unmatchableGetters = [];
3290
3188
  this.unmatchablePropertiesAndGetters = [];
3291
- this.unmatchablePropertiesAndSetters = [];
3292
3189
  this.unmatchableSetters = [];
3293
3190
  if (Array.isArray(properties)) {
3294
3191
  this.buildPropertyMaps(properties);
@@ -3445,12 +3342,7 @@ class ObjectEntity extends ExpressionEntity {
3445
3342
  }
3446
3343
  getLiteralValueAtPath(path, recursionTracker, origin) {
3447
3344
  if (path.length === 0) {
3448
- // This should actually be "UnknownTruthyValue". However, this currently
3449
- // causes an issue with TypeScript enums in files with moduleSideEffects:
3450
- // false because we cannot properly track whether a "var" has been
3451
- // initialized. This should be reverted once we can properly track this.
3452
- // return UnknownTruthyValue;
3453
- return UnknownValue;
3345
+ return UnknownTruthyValue;
3454
3346
  }
3455
3347
  const key = path[0];
3456
3348
  const expressionAtPath = this.getMemberExpressionAndTrackDeopt(key, origin);
@@ -3528,36 +3420,9 @@ class ObjectEntity extends ExpressionEntity {
3528
3420
  }
3529
3421
  return false;
3530
3422
  }
3531
- include(context, includeChildrenRecursively) {
3532
- this.included = true;
3533
- for (const property of this.allProperties) {
3534
- if (includeChildrenRecursively || property.shouldBeIncluded(context)) {
3535
- property.include(context, includeChildrenRecursively);
3536
- }
3537
- }
3538
- this.prototypeExpression?.include(context, includeChildrenRecursively);
3539
- }
3540
- includePath(path, context) {
3541
- this.included = true;
3542
- if (path.length === 0)
3543
- return;
3544
- const [key, ...subPath] = path;
3545
- const [includedMembers, includedPath] = typeof key === 'string'
3546
- ? [
3547
- new Set([
3548
- ...(this.propertiesAndGettersByKey[key] || this.unmatchablePropertiesAndGetters),
3549
- ...(this.propertiesAndSettersByKey[key] || this.unmatchablePropertiesAndSetters)
3550
- ]),
3551
- subPath
3552
- ]
3553
- : [this.allProperties, UNKNOWN_PATH];
3554
- for (const property of includedMembers) {
3555
- property.includePath(includedPath, context);
3556
- }
3557
- this.prototypeExpression?.includePath(path, context);
3558
- }
3559
3423
  buildPropertyMaps(properties) {
3560
- const { allProperties, propertiesAndGettersByKey, propertiesAndSettersByKey, settersByKey, gettersByKey, unknownIntegerProps, unmatchablePropertiesAndGetters, unmatchablePropertiesAndSetters, unmatchableGetters, unmatchableSetters } = this;
3424
+ const { allProperties, propertiesAndGettersByKey, propertiesAndSettersByKey, settersByKey, gettersByKey, unknownIntegerProps, unmatchablePropertiesAndGetters, unmatchableGetters, unmatchableSetters } = this;
3425
+ const unmatchablePropertiesAndSetters = [];
3561
3426
  for (let index = properties.length - 1; index >= 0; index--) {
3562
3427
  const { key, kind, property } = properties[index];
3563
3428
  allProperties.push(property);
@@ -3827,37 +3692,6 @@ const ARRAY_PROTOTYPE = new ObjectEntity({
3827
3692
  values: METHOD_DEOPTS_SELF_RETURNS_UNKNOWN
3828
3693
  }, OBJECT_PROTOTYPE, true);
3829
3694
 
3830
- class SpreadElement extends NodeBase {
3831
- deoptimizeArgumentsOnInteractionAtPath(interaction, path, recursionTracker) {
3832
- if (path.length > 0) {
3833
- this.argument.deoptimizeArgumentsOnInteractionAtPath(interaction, UNKNOWN_PATH, recursionTracker);
3834
- }
3835
- }
3836
- hasEffects(context) {
3837
- if (!this.deoptimized)
3838
- this.applyDeoptimizations();
3839
- const { propertyReadSideEffects } = this.scope.context.options
3840
- .treeshake;
3841
- return (this.argument.hasEffects(context) ||
3842
- (propertyReadSideEffects &&
3843
- (propertyReadSideEffects === 'always' ||
3844
- this.argument.hasEffectsOnInteractionAtPath(UNKNOWN_PATH, NODE_INTERACTION_UNKNOWN_ACCESS, context))));
3845
- }
3846
- includeNode(context) {
3847
- this.included = true;
3848
- if (!this.deoptimized)
3849
- this.applyDeoptimizations();
3850
- this.argument.includePath(UNKNOWN_PATH, context);
3851
- }
3852
- applyDeoptimizations() {
3853
- this.deoptimized = true;
3854
- // Only properties of properties of the argument could become subject to reassignment
3855
- // This will also reassign the return values of iterators
3856
- this.argument.deoptimizePath([UnknownKey, UnknownKey]);
3857
- this.scope.context.requestTreeshakingPass();
3858
- }
3859
- }
3860
-
3861
3695
  class ArrayExpression extends NodeBase {
3862
3696
  constructor() {
3863
3697
  super(...arguments);
@@ -3878,16 +3712,6 @@ class ArrayExpression extends NodeBase {
3878
3712
  hasEffectsOnInteractionAtPath(path, interaction, context) {
3879
3713
  return this.getObjectEntity().hasEffectsOnInteractionAtPath(path, interaction, context);
3880
3714
  }
3881
- includeNode(context) {
3882
- this.included = true;
3883
- if (!this.deoptimized)
3884
- this.applyDeoptimizations();
3885
- for (const element of this.elements) {
3886
- if (element) {
3887
- element?.includePath(UNKNOWN_PATH, context);
3888
- }
3889
- }
3890
- }
3891
3715
  applyDeoptimizations() {
3892
3716
  this.deoptimized = true;
3893
3717
  let hasSpread = false;
@@ -4955,37 +4779,17 @@ class GlobalVariable extends Variable {
4955
4779
  }
4956
4780
  }
4957
4781
 
4958
- // To avoid infinite recursions
4959
- const MAX_PATH_DEPTH = 6;
4960
- // If a path is longer than MAX_PATH_DEPTH, it is truncated so that it is at
4961
- // most MAX_PATH_DEPTH long. The last element is always UnknownKey
4962
- const limitConcatenatedPathDepth = (path1, path2) => {
4963
- const { length: length1 } = path1;
4964
- const { length: length2 } = path2;
4965
- return length1 === 0
4966
- ? path2
4967
- : length2 === 0
4968
- ? path1
4969
- : length1 + length2 > MAX_PATH_DEPTH
4970
- ? [...path1, ...path2.slice(0, MAX_PATH_DEPTH - 1 - path1.length), 'UnknownKey']
4971
- : [...path1, ...path2];
4972
- };
4973
-
4974
4782
  class LocalVariable extends Variable {
4975
- constructor(name, declarator, init,
4976
- /** if this is non-empty, the actual init is this path of this.init */
4977
- initPath, context, kind) {
4783
+ constructor(name, declarator, init, context, kind) {
4978
4784
  super(name);
4979
4785
  this.init = init;
4980
- this.initPath = initPath;
4981
- this.kind = kind;
4982
4786
  this.calledFromTryStatement = false;
4983
4787
  this.additionalInitializers = null;
4984
- this.includedPathTracker = new IncludedFullPathTracker();
4985
4788
  this.expressionsToBeDeoptimized = [];
4986
4789
  this.declarations = declarator ? [declarator] : [];
4987
4790
  this.deoptimizationTracker = context.deoptimizationTracker;
4988
4791
  this.module = context.module;
4792
+ this.kind = kind;
4989
4793
  }
4990
4794
  addDeclaration(identifier, init) {
4991
4795
  this.declarations.push(identifier);
@@ -4996,16 +4800,15 @@ class LocalVariable extends Variable {
4996
4800
  for (const initializer of this.additionalInitializers) {
4997
4801
  initializer.deoptimizePath(UNKNOWN_PATH);
4998
4802
  }
4803
+ this.additionalInitializers = null;
4999
4804
  }
5000
4805
  }
5001
4806
  deoptimizeArgumentsOnInteractionAtPath(interaction, path, recursionTracker) {
5002
- if (this.isReassigned || path.length + this.initPath.length > MAX_PATH_DEPTH) {
4807
+ if (this.isReassigned) {
5003
4808
  deoptimizeInteraction(interaction);
5004
4809
  return;
5005
4810
  }
5006
- recursionTracker.withTrackedEntityAtPath(path, this.init, () => {
5007
- this.init.deoptimizeArgumentsOnInteractionAtPath(interaction, [...this.initPath, ...path], recursionTracker);
5008
- }, undefined);
4811
+ recursionTracker.withTrackedEntityAtPath(path, this.init, () => this.init.deoptimizeArgumentsOnInteractionAtPath(interaction, path, recursionTracker), undefined);
5009
4812
  }
5010
4813
  deoptimizePath(path) {
5011
4814
  if (this.isReassigned ||
@@ -5019,40 +4822,37 @@ class LocalVariable extends Variable {
5019
4822
  for (const expression of expressionsToBeDeoptimized) {
5020
4823
  expression.deoptimizeCache();
5021
4824
  }
5022
- this.init.deoptimizePath([...this.initPath, UnknownKey]);
4825
+ this.init.deoptimizePath(UNKNOWN_PATH);
5023
4826
  }
5024
4827
  else {
5025
- this.init.deoptimizePath(limitConcatenatedPathDepth(this.initPath, path));
4828
+ this.init.deoptimizePath(path);
5026
4829
  }
5027
4830
  }
5028
4831
  getLiteralValueAtPath(path, recursionTracker, origin) {
5029
- if (this.isReassigned || path.length + this.initPath.length > MAX_PATH_DEPTH) {
4832
+ if (this.isReassigned) {
5030
4833
  return UnknownValue;
5031
4834
  }
5032
4835
  return recursionTracker.withTrackedEntityAtPath(path, this.init, () => {
5033
4836
  this.expressionsToBeDeoptimized.push(origin);
5034
- return this.init.getLiteralValueAtPath([...this.initPath, ...path], recursionTracker, origin);
4837
+ return this.init.getLiteralValueAtPath(path, recursionTracker, origin);
5035
4838
  }, UnknownValue);
5036
4839
  }
5037
4840
  getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin) {
5038
- if (this.isReassigned || path.length + this.initPath.length > MAX_PATH_DEPTH) {
4841
+ if (this.isReassigned) {
5039
4842
  return UNKNOWN_RETURN_EXPRESSION;
5040
4843
  }
5041
4844
  return recursionTracker.withTrackedEntityAtPath(path, this.init, () => {
5042
4845
  this.expressionsToBeDeoptimized.push(origin);
5043
- return this.init.getReturnExpressionWhenCalledAtPath([...this.initPath, ...path], interaction, recursionTracker, origin);
4846
+ return this.init.getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin);
5044
4847
  }, UNKNOWN_RETURN_EXPRESSION);
5045
4848
  }
5046
4849
  hasEffectsOnInteractionAtPath(path, interaction, context) {
5047
- if (path.length + this.initPath.length > MAX_PATH_DEPTH) {
5048
- return true;
5049
- }
5050
4850
  switch (interaction.type) {
5051
4851
  case INTERACTION_ACCESSED: {
5052
4852
  if (this.isReassigned)
5053
4853
  return true;
5054
4854
  return (!context.accessed.trackEntityAtPathAndGetIfTracked(path, this) &&
5055
- this.init.hasEffectsOnInteractionAtPath([...this.initPath, ...path], interaction, context));
4855
+ this.init.hasEffectsOnInteractionAtPath(path, interaction, context));
5056
4856
  }
5057
4857
  case INTERACTION_ASSIGNED: {
5058
4858
  if (this.included)
@@ -5062,63 +4862,44 @@ class LocalVariable extends Variable {
5062
4862
  if (this.isReassigned)
5063
4863
  return true;
5064
4864
  return (!context.assigned.trackEntityAtPathAndGetIfTracked(path, this) &&
5065
- this.init.hasEffectsOnInteractionAtPath([...this.initPath, ...path], interaction, context));
4865
+ this.init.hasEffectsOnInteractionAtPath(path, interaction, context));
5066
4866
  }
5067
4867
  case INTERACTION_CALLED: {
5068
4868
  if (this.isReassigned)
5069
4869
  return true;
5070
4870
  return (!(interaction.withNew ? context.instantiated : context.called).trackEntityAtPathAndGetIfTracked(path, interaction.args, this) &&
5071
- this.init.hasEffectsOnInteractionAtPath([...this.initPath, ...path], interaction, context));
4871
+ this.init.hasEffectsOnInteractionAtPath(path, interaction, context));
5072
4872
  }
5073
4873
  }
5074
4874
  }
5075
- includePath(path, context) {
5076
- if (!this.includedPathTracker.includePathAndGetIfIncluded(path)) {
5077
- this.module.scope.context.requestTreeshakingPass();
5078
- if (!this.included) {
5079
- // This will reduce the number of tree-shaking passes by eagerly
5080
- // including inits. By pushing this here instead of directly including
5081
- // we avoid deep call stacks.
5082
- this.module.scope.context.newlyIncludedVariableInits.add(this.init);
5083
- }
5084
- super.includePath(path, context);
4875
+ include() {
4876
+ if (!this.included) {
4877
+ super.include();
5085
4878
  for (const declaration of this.declarations) {
5086
4879
  // If node is a default export, it can save a tree-shaking run to include the full declaration now
5087
4880
  if (!declaration.included)
5088
- declaration.include(context, false);
4881
+ declaration.include(createInclusionContext(), false);
5089
4882
  let node = declaration.parent;
5090
4883
  while (!node.included) {
5091
4884
  // We do not want to properly include parents in case they are part of a dead branch
5092
4885
  // in which case .include() might pull in more dead code
5093
- node.includeNode(context);
4886
+ node.included = true;
5094
4887
  if (node.type === Program$1)
5095
4888
  break;
5096
4889
  node = node.parent;
5097
4890
  }
5098
4891
  }
5099
- // We need to make sure we include the correct path of the init
5100
- if (path.length > 0) {
5101
- this.init.includePath(limitConcatenatedPathDepth(this.initPath, path), context);
5102
- this.additionalInitializers?.forEach(initializer => initializer.includePath(UNKNOWN_PATH, context));
5103
- }
5104
4892
  }
5105
4893
  }
5106
- includeCallArguments(context, interaction) {
5107
- if (this.isReassigned ||
5108
- context.includedCallArguments.has(this.init) ||
5109
- // This can be removed again once we can include arguments when called at
5110
- // a specific path
5111
- this.initPath.length > 0) {
5112
- for (const argument of interaction.args) {
5113
- if (argument) {
5114
- argument.includePath(UNKNOWN_PATH, context);
5115
- argument.include(context, false);
5116
- }
4894
+ includeCallArguments(context, parameters) {
4895
+ if (this.isReassigned || context.includedCallArguments.has(this.init)) {
4896
+ for (const argument of parameters) {
4897
+ argument.include(context, false);
5117
4898
  }
5118
4899
  }
5119
4900
  else {
5120
4901
  context.includedCallArguments.add(this.init);
5121
- this.init.includeCallArguments(context, interaction);
4902
+ this.init.includeCallArguments(context, parameters);
5122
4903
  context.includedCallArguments.delete(this.init);
5123
4904
  }
5124
4905
  }
@@ -5198,31 +4979,18 @@ class IdentifierBase extends NodeBase {
5198
4979
  }
5199
4980
  }
5200
4981
  }
5201
- include(context) {
5202
- if (!this.included)
5203
- this.includeNode(context);
5204
- }
5205
- includeNode(context) {
5206
- this.included = true;
4982
+ include() {
5207
4983
  if (!this.deoptimized)
5208
4984
  this.applyDeoptimizations();
5209
- if (this.variable !== null) {
5210
- this.scope.context.includeVariableInModule(this.variable, EMPTY_PATH, context);
5211
- }
5212
- }
5213
- includePath(path, context) {
5214
4985
  if (!this.included) {
5215
4986
  this.included = true;
5216
4987
  if (this.variable !== null) {
5217
- this.scope.context.includeVariableInModule(this.variable, path, context);
4988
+ this.scope.context.includeVariableInModule(this.variable);
5218
4989
  }
5219
4990
  }
5220
- else if (path.length > 0) {
5221
- this.variable?.includePath(path, context);
5222
- }
5223
4991
  }
5224
- includeCallArguments(context, interaction) {
5225
- this.variable.includeCallArguments(context, interaction);
4992
+ includeCallArguments(context, parameters) {
4993
+ this.variable.includeCallArguments(context, parameters);
5226
4994
  }
5227
4995
  isPossibleTDZ() {
5228
4996
  // return cached value to avoid issues with the next tree-shaking pass
@@ -5305,40 +5073,11 @@ function closestParentFunctionOrProgram(node) {
5305
5073
  return node;
5306
5074
  }
5307
5075
 
5308
- class ObjectMember extends ExpressionEntity {
5309
- constructor(object, path) {
5310
- super();
5311
- this.object = object;
5312
- this.path = path;
5313
- }
5314
- deoptimizeArgumentsOnInteractionAtPath(interaction, path, recursionTracker) {
5315
- this.object.deoptimizeArgumentsOnInteractionAtPath(interaction, [...this.path, ...path], recursionTracker);
5316
- }
5317
- deoptimizePath(path) {
5318
- this.object.deoptimizePath([...this.path, ...path]);
5319
- }
5320
- getLiteralValueAtPath(path, recursionTracker, origin) {
5321
- return this.object.getLiteralValueAtPath([...this.path, ...path], recursionTracker, origin);
5322
- }
5323
- getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin) {
5324
- return this.object.getReturnExpressionWhenCalledAtPath([...this.path, ...path], interaction, recursionTracker, origin);
5325
- }
5326
- hasEffectsOnInteractionAtPath(path, interaction, context) {
5327
- return this.object.hasEffectsOnInteractionAtPath([...this.path, ...path], interaction, context);
5328
- }
5329
- }
5330
-
5331
5076
  class Identifier extends IdentifierBase {
5332
5077
  constructor() {
5333
5078
  super(...arguments);
5334
5079
  this.variable = null;
5335
5080
  }
5336
- get isDestructuringDeoptimized() {
5337
- return isFlagSet(this.flags, 16777216 /* Flag.destructuringDeoptimized */);
5338
- }
5339
- set isDestructuringDeoptimized(value) {
5340
- this.flags = setFlag(this.flags, 16777216 /* Flag.destructuringDeoptimized */, value);
5341
- }
5342
5081
  addExportedVariables(variables, exportNamesByVariable) {
5343
5082
  if (exportNamesByVariable.has(this.variable)) {
5344
5083
  variables.push(this.variable);
@@ -5351,52 +5090,42 @@ class Identifier extends IdentifierBase {
5351
5090
  this.isVariableReference = true;
5352
5091
  }
5353
5092
  }
5354
- declare(kind, destructuredInitPath, init) {
5093
+ declare(kind, init) {
5355
5094
  let variable;
5356
5095
  const { treeshake } = this.scope.context.options;
5357
- if (kind === 'parameter') {
5358
- variable = this.scope.addParameterDeclaration(this, destructuredInitPath);
5359
- }
5360
- else {
5361
- variable = this.scope.addDeclaration(this, this.scope.context, init, destructuredInitPath, kind);
5362
- if (kind === 'var' && treeshake && treeshake.correctVarValueBeforeDeclaration) {
5363
- // Necessary to make sure the init is deoptimized. We cannot call deoptimizePath here.
5364
- variable.markInitializersForDeoptimization();
5096
+ switch (kind) {
5097
+ case 'var': {
5098
+ variable = this.scope.addDeclaration(this, this.scope.context, init, kind);
5099
+ if (treeshake && treeshake.correctVarValueBeforeDeclaration) {
5100
+ // Necessary to make sure the init is deoptimized. We cannot call deoptimizePath here.
5101
+ variable.markInitializersForDeoptimization();
5102
+ }
5103
+ break;
5365
5104
  }
5366
- }
5367
- return [(this.variable = variable)];
5368
- }
5369
- deoptimizeAssignment(destructuredInitPath, init) {
5370
- this.deoptimizePath(EMPTY_PATH);
5371
- init.deoptimizePath([...destructuredInitPath, UnknownKey]);
5372
- }
5373
- hasEffectsWhenDestructuring(context, destructuredInitPath, init) {
5374
- return (destructuredInitPath.length > 0 &&
5375
- init.hasEffectsOnInteractionAtPath(destructuredInitPath, NODE_INTERACTION_UNKNOWN_ACCESS, context));
5376
- }
5377
- includeDestructuredIfNecessary(context, destructuredInitPath, init) {
5378
- if (destructuredInitPath.length > 0 && !this.isDestructuringDeoptimized) {
5379
- this.isDestructuringDeoptimized = true;
5380
- init.deoptimizeArgumentsOnInteractionAtPath({
5381
- args: [new ObjectMember(init, destructuredInitPath.slice(0, -1))],
5382
- type: INTERACTION_ACCESSED
5383
- }, destructuredInitPath, SHARED_RECURSION_TRACKER);
5384
- }
5385
- const { propertyReadSideEffects } = this.scope.context.options
5386
- .treeshake;
5387
- if ((this.included ||=
5388
- destructuredInitPath.length > 0 &&
5389
- !context.brokenFlow &&
5390
- propertyReadSideEffects &&
5391
- (propertyReadSideEffects === 'always' ||
5392
- init.hasEffectsOnInteractionAtPath(destructuredInitPath, NODE_INTERACTION_UNKNOWN_ACCESS, createHasEffectsContext())))) {
5393
- if (this.variable && !this.variable.included) {
5394
- this.scope.context.includeVariableInModule(this.variable, EMPTY_PATH, context);
5105
+ case 'function': {
5106
+ // in strict mode, functions are only hoisted within a scope but not across block scopes
5107
+ variable = this.scope.addDeclaration(this, this.scope.context, init, kind);
5108
+ break;
5109
+ }
5110
+ case 'let':
5111
+ case 'const':
5112
+ case 'using':
5113
+ case 'await using':
5114
+ case 'class': {
5115
+ variable = this.scope.addDeclaration(this, this.scope.context, init, kind);
5116
+ break;
5117
+ }
5118
+ case 'parameter': {
5119
+ variable = this.scope.addParameterDeclaration(this);
5120
+ break;
5121
+ }
5122
+ /* istanbul ignore next */
5123
+ default: {
5124
+ /* istanbul ignore next */
5125
+ throw new Error(`Internal Error: Unexpected identifier kind ${kind}.`);
5395
5126
  }
5396
- init.includePath(destructuredInitPath, context);
5397
- return true;
5398
5127
  }
5399
- return false;
5128
+ return [(this.variable = variable)];
5400
5129
  }
5401
5130
  markDeclarationReached() {
5402
5131
  this.variable.initReached = true;
@@ -5462,17 +5191,18 @@ class Scope {
5462
5191
  - then the variable is still declared in the hoisted outer scope, but the initializer is assigned to the parameter
5463
5192
  - const, let, class, and function except in the cases above cannot redeclare anything
5464
5193
  */
5465
- addDeclaration(identifier, context, init, destructuredInitPath, kind) {
5194
+ addDeclaration(identifier, context, init, kind) {
5466
5195
  const name = identifier.name;
5467
5196
  const existingVariable = this.hoistedVariables?.get(name) || this.variables.get(name);
5468
5197
  if (existingVariable) {
5469
- if (kind === 'var' && existingVariable.kind === 'var') {
5198
+ const existingKind = existingVariable.kind;
5199
+ if (kind === 'var' && existingKind === 'var') {
5470
5200
  existingVariable.addDeclaration(identifier, init);
5471
5201
  return existingVariable;
5472
5202
  }
5473
5203
  context.error(logRedeclarationError(name), identifier.start);
5474
5204
  }
5475
- const newVariable = new LocalVariable(identifier.name, identifier, init, destructuredInitPath, context, kind);
5205
+ const newVariable = new LocalVariable(identifier.name, identifier, init, context, kind);
5476
5206
  this.variables.set(name, newVariable);
5477
5207
  return newVariable;
5478
5208
  }
@@ -5648,6 +5378,7 @@ class MethodBase extends NodeBase {
5648
5378
  }
5649
5379
  return this.getAccessedValue()[0].hasEffectsOnInteractionAtPath(path, interaction, context);
5650
5380
  }
5381
+ applyDeoptimizations() { }
5651
5382
  getAccessedValue() {
5652
5383
  if (this.accessedValue === null) {
5653
5384
  if (this.kind === 'get') {
@@ -5661,20 +5392,19 @@ class MethodBase extends NodeBase {
5661
5392
  return this.accessedValue;
5662
5393
  }
5663
5394
  }
5664
- MethodBase.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
5665
- MethodBase.prototype.applyDeoptimizations = doNotDeoptimize;
5666
5395
 
5667
5396
  class MethodDefinition extends MethodBase {
5668
5397
  hasEffects(context) {
5669
5398
  return super.hasEffects(context) || checkEffectForNodes(this.decorators, context);
5670
5399
  }
5400
+ applyDeoptimizations() { }
5671
5401
  }
5672
5402
 
5673
5403
  class BlockScope extends ChildScope {
5674
5404
  constructor(parent) {
5675
5405
  super(parent, parent.context);
5676
5406
  }
5677
- addDeclaration(identifier, context, init, destructuredInitPath, kind) {
5407
+ addDeclaration(identifier, context, init, kind) {
5678
5408
  if (kind === 'var') {
5679
5409
  const name = identifier.name;
5680
5410
  const existingVariable = this.hoistedVariables?.get(name) || this.variables.get(name);
@@ -5686,7 +5416,7 @@ class BlockScope extends ChildScope {
5686
5416
  }
5687
5417
  return context.error(logRedeclarationError(name), identifier.start);
5688
5418
  }
5689
- const declaredVariable = this.parent.addDeclaration(identifier, context, init, destructuredInitPath, kind);
5419
+ const declaredVariable = this.parent.addDeclaration(identifier, context, init, kind);
5690
5420
  // Necessary to make sure the init is deoptimized for conditional declarations.
5691
5421
  // We cannot call deoptimizePath here.
5692
5422
  declaredVariable.markInitializersForDeoptimization();
@@ -5694,7 +5424,7 @@ class BlockScope extends ChildScope {
5694
5424
  this.addHoistedVariable(name, declaredVariable);
5695
5425
  return declaredVariable;
5696
5426
  }
5697
- return super.addDeclaration(identifier, context, init, destructuredInitPath, kind);
5427
+ return super.addDeclaration(identifier, context, init, kind);
5698
5428
  }
5699
5429
  }
5700
5430
 
@@ -5726,12 +5456,33 @@ class StaticBlock extends NodeBase {
5726
5456
  }
5727
5457
  }
5728
5458
  }
5729
- StaticBlock.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
5730
- StaticBlock.prototype.applyDeoptimizations = doNotDeoptimize;
5731
5459
  function isStaticBlock(statement) {
5732
5460
  return statement.type === StaticBlock$1;
5733
5461
  }
5734
5462
 
5463
+ class ObjectMember extends ExpressionEntity {
5464
+ constructor(object, key) {
5465
+ super();
5466
+ this.object = object;
5467
+ this.key = key;
5468
+ }
5469
+ deoptimizeArgumentsOnInteractionAtPath(interaction, path, recursionTracker) {
5470
+ this.object.deoptimizeArgumentsOnInteractionAtPath(interaction, [this.key, ...path], recursionTracker);
5471
+ }
5472
+ deoptimizePath(path) {
5473
+ this.object.deoptimizePath([this.key, ...path]);
5474
+ }
5475
+ getLiteralValueAtPath(path, recursionTracker, origin) {
5476
+ return this.object.getLiteralValueAtPath([this.key, ...path], recursionTracker, origin);
5477
+ }
5478
+ getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin) {
5479
+ return this.object.getReturnExpressionWhenCalledAtPath([this.key, ...path], interaction, recursionTracker, origin);
5480
+ }
5481
+ hasEffectsOnInteractionAtPath(path, interaction, context) {
5482
+ return this.object.hasEffectsOnInteractionAtPath([this.key, ...path], interaction, context);
5483
+ }
5484
+ }
5485
+
5735
5486
  class ClassNode extends NodeBase {
5736
5487
  constructor() {
5737
5488
  super(...arguments);
@@ -5772,20 +5523,21 @@ class ClassNode extends NodeBase {
5772
5523
  : this.getObjectEntity().hasEffectsOnInteractionAtPath(path, interaction, context);
5773
5524
  }
5774
5525
  include(context, includeChildrenRecursively) {
5775
- if (!this.included)
5776
- this.includeNode(context);
5526
+ if (!this.deoptimized)
5527
+ this.applyDeoptimizations();
5528
+ this.included = true;
5777
5529
  this.superClass?.include(context, includeChildrenRecursively);
5778
5530
  this.body.include(context, includeChildrenRecursively);
5779
5531
  for (const decorator of this.decorators)
5780
5532
  decorator.include(context, includeChildrenRecursively);
5781
5533
  if (this.id) {
5782
5534
  this.id.markDeclarationReached();
5783
- this.id.include(context);
5535
+ this.id.include();
5784
5536
  }
5785
5537
  }
5786
5538
  initialise() {
5787
5539
  super.initialise();
5788
- this.id?.declare('class', EMPTY_PATH, this);
5540
+ this.id?.declare('class', this);
5789
5541
  for (const method of this.body.body) {
5790
5542
  if (method instanceof MethodDefinition && method.kind === 'constructor') {
5791
5543
  this.classConstructor = method;
@@ -5843,12 +5595,11 @@ class ClassNode extends NodeBase {
5843
5595
  staticProperties.unshift({
5844
5596
  key: 'prototype',
5845
5597
  kind: 'init',
5846
- property: new ObjectEntity(dynamicMethods, this.superClass ? new ObjectMember(this.superClass, ['prototype']) : OBJECT_PROTOTYPE)
5598
+ property: new ObjectEntity(dynamicMethods, this.superClass ? new ObjectMember(this.superClass, 'prototype') : OBJECT_PROTOTYPE)
5847
5599
  });
5848
5600
  return (this.objectEntity = new ObjectEntity(staticProperties, this.superClass || OBJECT_PROTOTYPE));
5849
5601
  }
5850
5602
  }
5851
- ClassNode.prototype.includeNode = onlyIncludeSelf;
5852
5603
 
5853
5604
  class ClassDeclaration extends ClassNode {
5854
5605
  initialise() {
@@ -5901,60 +5652,53 @@ class ClassDeclaration extends ClassNode {
5901
5652
 
5902
5653
  class ArgumentsVariable extends LocalVariable {
5903
5654
  constructor(context) {
5904
- super('arguments', null, UNKNOWN_EXPRESSION, EMPTY_PATH, context, 'other');
5905
- }
5906
- addArgumentToBeDeoptimized(_argument) { }
5907
- // Only If there is at least one reference, then we need to track all
5908
- // arguments in order to be able to deoptimize them.
5909
- addReference() {
5655
+ super('arguments', null, UNKNOWN_EXPRESSION, context, 'other');
5910
5656
  this.deoptimizedArguments = [];
5911
- this.addArgumentToBeDeoptimized = addArgumentToBeDeoptimized;
5657
+ }
5658
+ addArgumentToBeDeoptimized(argument) {
5659
+ if (this.included) {
5660
+ argument.deoptimizePath(UNKNOWN_PATH);
5661
+ }
5662
+ else {
5663
+ this.deoptimizedArguments.push(argument);
5664
+ }
5912
5665
  }
5913
5666
  hasEffectsOnInteractionAtPath(path, { type }) {
5914
5667
  return type !== INTERACTION_ACCESSED || path.length > 1;
5915
5668
  }
5916
- includePath(path, context) {
5917
- super.includePath(path, context);
5669
+ include() {
5670
+ super.include();
5918
5671
  for (const argument of this.deoptimizedArguments) {
5919
5672
  argument.deoptimizePath(UNKNOWN_PATH);
5920
5673
  }
5921
5674
  this.deoptimizedArguments.length = 0;
5922
5675
  }
5923
5676
  }
5924
- function addArgumentToBeDeoptimized(argument) {
5925
- if (this.included) {
5926
- argument.deoptimizePath(UNKNOWN_PATH);
5927
- }
5928
- else {
5929
- this.deoptimizedArguments?.push(argument);
5930
- }
5931
- }
5932
5677
 
5933
5678
  const MAX_TRACKED_INTERACTIONS = 20;
5934
5679
  const NO_INTERACTIONS = EMPTY_ARRAY;
5935
5680
  const UNKNOWN_DEOPTIMIZED_FIELD = new Set([UnknownKey]);
5936
- const EMPTY_PATH_TRACKER = new EntityPathTracker();
5681
+ const EMPTY_PATH_TRACKER = new PathTracker();
5937
5682
  const UNKNOWN_DEOPTIMIZED_ENTITY = new Set([UNKNOWN_EXPRESSION]);
5938
5683
  class ParameterVariable extends LocalVariable {
5939
- constructor(name, declarator, argumentPath, context) {
5940
- super(name, declarator, UNKNOWN_EXPRESSION, argumentPath, context, 'parameter');
5941
- this.includedPathTracker = new IncludedTopLevelPathTracker();
5942
- this.argumentsToBeDeoptimized = new Set();
5684
+ constructor(name, declarator, context) {
5685
+ super(name, declarator, UNKNOWN_EXPRESSION, context, 'parameter');
5943
5686
  this.deoptimizationInteractions = [];
5944
- this.deoptimizations = new EntityPathTracker();
5687
+ this.deoptimizations = new PathTracker();
5945
5688
  this.deoptimizedFields = new Set();
5946
- this.expressionsDependingOnKnownValue = [];
5689
+ this.entitiesToBeDeoptimized = new Set();
5690
+ this.expressionsUseTheKnownValue = [];
5947
5691
  this.knownValue = null;
5948
5692
  this.knownValueLiteral = UnknownValue;
5693
+ this.frozenValue = null;
5949
5694
  }
5950
- addArgumentValue(entity) {
5951
- this.updateKnownValue(entity);
5695
+ addEntityToBeDeoptimized(entity) {
5952
5696
  if (entity === UNKNOWN_EXPRESSION) {
5953
5697
  // As unknown expressions fully deoptimize all interactions, we can clear
5954
5698
  // the interaction cache at this point provided we keep this optimization
5955
5699
  // in mind when adding new interactions
5956
- if (!this.argumentsToBeDeoptimized.has(UNKNOWN_EXPRESSION)) {
5957
- this.argumentsToBeDeoptimized.add(UNKNOWN_EXPRESSION);
5700
+ if (!this.entitiesToBeDeoptimized.has(UNKNOWN_EXPRESSION)) {
5701
+ this.entitiesToBeDeoptimized.add(UNKNOWN_EXPRESSION);
5958
5702
  for (const { interaction } of this.deoptimizationInteractions) {
5959
5703
  deoptimizeInteraction(interaction);
5960
5704
  }
@@ -5964,30 +5708,27 @@ class ParameterVariable extends LocalVariable {
5964
5708
  else if (this.deoptimizedFields.has(UnknownKey)) {
5965
5709
  // This means that we already deoptimized all interactions and no longer
5966
5710
  // track them
5967
- entity.deoptimizePath([...this.initPath, UnknownKey]);
5711
+ entity.deoptimizePath(UNKNOWN_PATH);
5968
5712
  }
5969
- else if (!this.argumentsToBeDeoptimized.has(entity)) {
5970
- this.argumentsToBeDeoptimized.add(entity);
5713
+ else if (!this.entitiesToBeDeoptimized.has(entity)) {
5714
+ this.entitiesToBeDeoptimized.add(entity);
5971
5715
  for (const field of this.deoptimizedFields) {
5972
- entity.deoptimizePath([...this.initPath, field]);
5716
+ entity.deoptimizePath([field]);
5973
5717
  }
5974
5718
  for (const { interaction, path } of this.deoptimizationInteractions) {
5975
- entity.deoptimizeArgumentsOnInteractionAtPath(interaction, [...this.initPath, ...path], SHARED_RECURSION_TRACKER);
5719
+ entity.deoptimizeArgumentsOnInteractionAtPath(interaction, path, SHARED_RECURSION_TRACKER);
5976
5720
  }
5977
5721
  }
5978
5722
  }
5979
- /** This says we should not make assumptions about the value of the parameter.
5980
- * This is different from deoptimization that will also cause argument values
5981
- * to be deoptimized. */
5982
5723
  markReassigned() {
5983
5724
  if (this.isReassigned) {
5984
5725
  return;
5985
5726
  }
5986
5727
  super.markReassigned();
5987
- for (const expression of this.expressionsDependingOnKnownValue) {
5728
+ for (const expression of this.expressionsUseTheKnownValue) {
5988
5729
  expression.deoptimizeCache();
5989
5730
  }
5990
- this.expressionsDependingOnKnownValue = EMPTY_ARRAY;
5731
+ this.expressionsUseTheKnownValue = EMPTY_ARRAY;
5991
5732
  }
5992
5733
  deoptimizeCache() {
5993
5734
  this.markReassigned();
@@ -6004,7 +5745,7 @@ class ParameterVariable extends LocalVariable {
6004
5745
  }
6005
5746
  if (this.knownValue === null) {
6006
5747
  this.knownValue = argument;
6007
- this.knownValueLiteral = argument.getLiteralValueAtPath(this.initPath, SHARED_RECURSION_TRACKER, this);
5748
+ this.knownValueLiteral = argument.getLiteralValueAtPath(EMPTY_PATH, SHARED_RECURSION_TRACKER, this);
6008
5749
  return;
6009
5750
  }
6010
5751
  // the same literal or identifier, do nothing
@@ -6014,10 +5755,14 @@ class ParameterVariable extends LocalVariable {
6014
5755
  this.knownValue.variable === argument.variable)) {
6015
5756
  return;
6016
5757
  }
6017
- const { knownValueLiteral } = this;
6018
- if (typeof knownValueLiteral === 'symbol' ||
6019
- argument.getLiteralValueAtPath(this.initPath, SHARED_RECURSION_TRACKER, this) !==
6020
- knownValueLiteral) {
5758
+ const oldValue = this.knownValueLiteral;
5759
+ if (typeof oldValue === 'symbol') {
5760
+ this.markReassigned();
5761
+ return;
5762
+ }
5763
+ // add tracking for the new argument
5764
+ const newValue = argument.getLiteralValueAtPath(EMPTY_PATH, SHARED_RECURSION_TRACKER, this);
5765
+ if (newValue !== oldValue) {
6021
5766
  this.markReassigned();
6022
5767
  }
6023
5768
  }
@@ -6028,47 +5773,42 @@ class ParameterVariable extends LocalVariable {
6028
5773
  * @returns the frozen value
6029
5774
  */
6030
5775
  getKnownValue() {
6031
- return this.knownValue || UNKNOWN_EXPRESSION;
5776
+ if (this.frozenValue === null) {
5777
+ this.frozenValue = this.knownValue || UNKNOWN_EXPRESSION;
5778
+ }
5779
+ return this.frozenValue;
6032
5780
  }
6033
5781
  getLiteralValueAtPath(path, recursionTracker, origin) {
6034
- if (this.isReassigned || path.length + this.initPath.length > MAX_PATH_DEPTH) {
5782
+ if (this.isReassigned) {
6035
5783
  return UnknownValue;
6036
5784
  }
6037
5785
  const knownValue = this.getKnownValue();
6038
- this.expressionsDependingOnKnownValue.push(origin);
6039
- return recursionTracker.withTrackedEntityAtPath(path, knownValue, () => knownValue.getLiteralValueAtPath([...this.initPath, ...path], recursionTracker, origin), UnknownValue);
5786
+ this.expressionsUseTheKnownValue.push(origin);
5787
+ return recursionTracker.withTrackedEntityAtPath(path, knownValue, () => knownValue.getLiteralValueAtPath(path, recursionTracker, origin), UnknownValue);
6040
5788
  }
6041
5789
  hasEffectsOnInteractionAtPath(path, interaction, context) {
6042
- const { type } = interaction;
6043
- if (this.isReassigned ||
6044
- type === INTERACTION_ASSIGNED ||
6045
- path.length + this.initPath.length > MAX_PATH_DEPTH) {
5790
+ if (this.isReassigned || interaction.type === INTERACTION_ASSIGNED) {
6046
5791
  return super.hasEffectsOnInteractionAtPath(path, interaction, context);
6047
5792
  }
6048
- return (!(type === INTERACTION_CALLED
6049
- ? (interaction.withNew
6050
- ? context.instantiated
6051
- : context.called).trackEntityAtPathAndGetIfTracked(path, interaction.args, this)
6052
- : context.accessed.trackEntityAtPathAndGetIfTracked(path, this)) &&
6053
- this.getKnownValue().hasEffectsOnInteractionAtPath([...this.initPath, ...path], interaction, context));
5793
+ const knownValue = this.getKnownValue();
5794
+ return knownValue.hasEffectsOnInteractionAtPath(path, interaction, context);
6054
5795
  }
6055
5796
  deoptimizeArgumentsOnInteractionAtPath(interaction, path) {
6056
5797
  // For performance reasons, we fully deoptimize all deeper interactions
6057
5798
  if (path.length >= 2 ||
6058
- this.argumentsToBeDeoptimized.has(UNKNOWN_EXPRESSION) ||
5799
+ this.entitiesToBeDeoptimized.has(UNKNOWN_EXPRESSION) ||
6059
5800
  this.deoptimizationInteractions.length >= MAX_TRACKED_INTERACTIONS ||
6060
5801
  (path.length === 1 &&
6061
5802
  (this.deoptimizedFields.has(UnknownKey) ||
6062
- (interaction.type === INTERACTION_CALLED && this.deoptimizedFields.has(path[0])))) ||
6063
- this.initPath.length + path.length > MAX_PATH_DEPTH) {
5803
+ (interaction.type === INTERACTION_CALLED && this.deoptimizedFields.has(path[0]))))) {
6064
5804
  deoptimizeInteraction(interaction);
6065
5805
  return;
6066
5806
  }
6067
5807
  if (!this.deoptimizations.trackEntityAtPathAndGetIfTracked(path, interaction.args)) {
6068
- for (const entity of this.argumentsToBeDeoptimized) {
6069
- entity.deoptimizeArgumentsOnInteractionAtPath(interaction, [...this.initPath, ...path], SHARED_RECURSION_TRACKER);
5808
+ for (const entity of this.entitiesToBeDeoptimized) {
5809
+ entity.deoptimizeArgumentsOnInteractionAtPath(interaction, path, SHARED_RECURSION_TRACKER);
6070
5810
  }
6071
- if (!this.argumentsToBeDeoptimized.has(UNKNOWN_EXPRESSION)) {
5811
+ if (!this.entitiesToBeDeoptimized.has(UNKNOWN_EXPRESSION)) {
6072
5812
  this.deoptimizationInteractions.push({
6073
5813
  interaction,
6074
5814
  path
@@ -6089,17 +5829,17 @@ class ParameterVariable extends LocalVariable {
6089
5829
  return;
6090
5830
  }
6091
5831
  this.deoptimizedFields.add(key);
6092
- for (const entity of this.argumentsToBeDeoptimized) {
5832
+ for (const entity of this.entitiesToBeDeoptimized) {
6093
5833
  // We do not need a recursion tracker here as we already track whether
6094
5834
  // this field is deoptimized
6095
- entity.deoptimizePath([...this.initPath, key]);
5835
+ entity.deoptimizePath([key]);
6096
5836
  }
6097
5837
  if (key === UnknownKey) {
6098
5838
  // save some memory
6099
5839
  this.deoptimizationInteractions = NO_INTERACTIONS;
6100
5840
  this.deoptimizations = EMPTY_PATH_TRACKER;
6101
5841
  this.deoptimizedFields = UNKNOWN_DEOPTIMIZED_FIELD;
6102
- this.argumentsToBeDeoptimized = UNKNOWN_DEOPTIMIZED_ENTITY;
5842
+ this.entitiesToBeDeoptimized = UNKNOWN_DEOPTIMIZED_ENTITY;
6103
5843
  }
6104
5844
  }
6105
5845
  getReturnExpressionWhenCalledAtPath(path) {
@@ -6114,14 +5854,11 @@ class ParameterVariable extends LocalVariable {
6114
5854
  }
6115
5855
  return UNKNOWN_RETURN_EXPRESSION;
6116
5856
  }
6117
- includeArgumentPaths(entity, context) {
6118
- this.includedPathTracker.includeAllPaths(entity, context, this.initPath);
6119
- }
6120
5857
  }
6121
5858
 
6122
5859
  class ThisVariable extends ParameterVariable {
6123
5860
  constructor(context) {
6124
- super('this', null, EMPTY_PATH, context);
5861
+ super('this', null, context);
6125
5862
  }
6126
5863
  hasEffectsOnInteractionAtPath(path, interaction, context) {
6127
5864
  return (context.replacedVariableInits.get(this) || UNKNOWN_EXPRESSION).hasEffectsOnInteractionAtPath(path, interaction, context);
@@ -6133,7 +5870,7 @@ class CatchBodyScope extends ChildScope {
6133
5870
  super(parent, parent.context);
6134
5871
  this.parent = parent;
6135
5872
  }
6136
- addDeclaration(identifier, context, init, destructuredInitPath, kind) {
5873
+ addDeclaration(identifier, context, init, kind) {
6137
5874
  if (kind === 'var') {
6138
5875
  const name = identifier.name;
6139
5876
  const existingVariable = this.hoistedVariables?.get(name) || this.variables.get(name);
@@ -6146,7 +5883,7 @@ class CatchBodyScope extends ChildScope {
6146
5883
  // the assignment actually goes to the parameter and the var is
6147
5884
  // hoisted without assignment. Locally, it is shadowed by the
6148
5885
  // parameter
6149
- const declaredVariable = this.parent.parent.addDeclaration(identifier, context, UNDEFINED_EXPRESSION, destructuredInitPath, kind);
5886
+ const declaredVariable = this.parent.parent.addDeclaration(identifier, context, UNDEFINED_EXPRESSION, kind);
6150
5887
  // To avoid the need to rewrite the declaration, we link the variable
6151
5888
  // names. If we ever implement a logic that splits initialization and
6152
5889
  // assignment for hoisted vars, the "renderLikeHoisted" logic can be
@@ -6165,7 +5902,7 @@ class CatchBodyScope extends ChildScope {
6165
5902
  return context.error(logRedeclarationError(name), identifier.start);
6166
5903
  }
6167
5904
  // We only add parameters to parameter scopes
6168
- const declaredVariable = this.parent.parent.addDeclaration(identifier, context, init, destructuredInitPath, kind);
5905
+ const declaredVariable = this.parent.parent.addDeclaration(identifier, context, init, kind);
6169
5906
  // Necessary to make sure the init is deoptimized for conditional declarations.
6170
5907
  // We cannot call deoptimizePath here.
6171
5908
  declaredVariable.markInitializersForDeoptimization();
@@ -6173,7 +5910,7 @@ class CatchBodyScope extends ChildScope {
6173
5910
  this.addHoistedVariable(name, declaredVariable);
6174
5911
  return declaredVariable;
6175
5912
  }
6176
- return super.addDeclaration(identifier, context, init, destructuredInitPath, kind);
5913
+ return super.addDeclaration(identifier, context, init, kind);
6177
5914
  }
6178
5915
  }
6179
5916
 
@@ -6183,7 +5920,7 @@ class FunctionBodyScope extends ChildScope {
6183
5920
  }
6184
5921
  // There is stuff that is only allowed in function scopes, i.e. functions can
6185
5922
  // be redeclared, functions and var can redeclare each other
6186
- addDeclaration(identifier, context, init, destructuredInitPath, kind) {
5923
+ addDeclaration(identifier, context, init, kind) {
6187
5924
  const name = identifier.name;
6188
5925
  const existingVariable = this.hoistedVariables?.get(name) || this.variables.get(name);
6189
5926
  if (existingVariable) {
@@ -6195,7 +5932,7 @@ class FunctionBodyScope extends ChildScope {
6195
5932
  }
6196
5933
  context.error(logRedeclarationError(name), identifier.start);
6197
5934
  }
6198
- const newVariable = new LocalVariable(identifier.name, identifier, init, destructuredInitPath, context, kind);
5935
+ const newVariable = new LocalVariable(identifier.name, identifier, init, context, kind);
6199
5936
  this.variables.set(name, newVariable);
6200
5937
  return newVariable;
6201
5938
  }
@@ -6204,21 +5941,21 @@ class FunctionBodyScope extends ChildScope {
6204
5941
  class ParameterScope extends ChildScope {
6205
5942
  constructor(parent, isCatchScope) {
6206
5943
  super(parent, parent.context);
6207
- this.hasRest = false;
6208
5944
  this.parameters = [];
5945
+ this.hasRest = false;
6209
5946
  this.bodyScope = isCatchScope ? new CatchBodyScope(this) : new FunctionBodyScope(this);
6210
5947
  }
6211
5948
  /**
6212
5949
  * Adds a parameter to this scope. Parameters must be added in the correct
6213
5950
  * order, i.e. from left to right.
6214
5951
  */
6215
- addParameterDeclaration(identifier, argumentPath) {
5952
+ addParameterDeclaration(identifier) {
6216
5953
  const { name, start } = identifier;
6217
5954
  const existingParameter = this.variables.get(name);
6218
5955
  if (existingParameter) {
6219
5956
  return this.context.error(logDuplicateArgumentNameError(name), start);
6220
5957
  }
6221
- const variable = new ParameterVariable(name, identifier, argumentPath, this.context);
5958
+ const variable = new ParameterVariable(name, identifier, this.context);
6222
5959
  this.variables.set(name, variable);
6223
5960
  // We also add it to the body scope to detect name conflicts with local
6224
5961
  // variables. We still need the intermediate scope, though, as parameter
@@ -6236,56 +5973,42 @@ class ParameterScope extends ChildScope {
6236
5973
  }
6237
5974
  this.hasRest = hasRest;
6238
5975
  }
6239
- includeCallArguments(context, interaction) {
5976
+ includeCallArguments(context, parameters) {
6240
5977
  let calledFromTryStatement = false;
6241
5978
  let argumentIncluded = false;
6242
5979
  const restParameter = this.hasRest && this.parameters[this.parameters.length - 1];
6243
- const { args } = interaction;
6244
- let lastExplicitlyIncludedIndex = args.length - 1;
6245
- // If there is a SpreadElement, we need to include all arguments after it
6246
- // because we no longer know which argument corresponds to which parameter.
6247
- for (let argumentIndex = 1; argumentIndex < args.length; argumentIndex++) {
6248
- const argument = args[argumentIndex];
6249
- if (argument instanceof SpreadElement && !argumentIncluded) {
6250
- argumentIncluded = true;
6251
- lastExplicitlyIncludedIndex = argumentIndex - 1;
6252
- }
6253
- if (argumentIncluded) {
6254
- argument.includePath(UNKNOWN_PATH, context);
6255
- argument.include(context, false);
5980
+ for (const checkedArgument of parameters) {
5981
+ if (checkedArgument instanceof SpreadElement) {
5982
+ for (const argument of parameters) {
5983
+ argument.include(context, false);
5984
+ }
5985
+ break;
6256
5986
  }
6257
5987
  }
6258
- // Now we go backwards either starting from the last argument or before the
6259
- // first SpreadElement to ensure all arguments before are included as needed
6260
- for (let index = lastExplicitlyIncludedIndex; index >= 1; index--) {
6261
- const parameterVariables = this.parameters[index - 1] || restParameter;
6262
- const argument = args[index];
5988
+ for (let index = parameters.length - 1; index >= 0; index--) {
5989
+ const parameterVariables = this.parameters[index] || restParameter;
5990
+ const argument = parameters[index];
6263
5991
  if (parameterVariables) {
6264
5992
  calledFromTryStatement = false;
6265
5993
  if (parameterVariables.length === 0) {
6266
- // handle empty destructuring to avoid destructuring undefined
5994
+ // handle empty destructuring
6267
5995
  argumentIncluded = true;
6268
5996
  }
6269
5997
  else {
6270
- for (const parameterVariable of parameterVariables) {
6271
- if (parameterVariable.calledFromTryStatement) {
6272
- calledFromTryStatement = true;
6273
- }
6274
- if (parameterVariable.included) {
5998
+ for (const variable of parameterVariables) {
5999
+ if (variable.included) {
6275
6000
  argumentIncluded = true;
6276
- if (calledFromTryStatement) {
6277
- argument.include(context, true);
6278
- }
6279
- else {
6280
- parameterVariable.includeArgumentPaths(argument, context);
6281
- argument.include(context, false);
6282
- }
6001
+ }
6002
+ if (variable.calledFromTryStatement) {
6003
+ calledFromTryStatement = true;
6283
6004
  }
6284
6005
  }
6285
6006
  }
6286
6007
  }
6287
- if (!argument.included && (argumentIncluded || argument.shouldBeIncluded(context))) {
6008
+ if (!argumentIncluded && argument.shouldBeIncluded(context)) {
6288
6009
  argumentIncluded = true;
6010
+ }
6011
+ if (argumentIncluded) {
6289
6012
  argument.include(context, calledFromTryStatement);
6290
6013
  }
6291
6014
  }
@@ -6301,62 +6024,11 @@ class ReturnValueScope extends ParameterScope {
6301
6024
  addReturnExpression(expression) {
6302
6025
  this.returnExpressions.push(expression);
6303
6026
  }
6304
- deoptimizeArgumentsOnCall(interaction) {
6305
- const { parameters } = this;
6306
- const { args } = interaction;
6307
- let position = 0;
6308
- for (; position < args.length - 1; position++) {
6309
- // Only the "this" argument arg[0] can be null
6310
- const argument = args[position + 1];
6311
- if (argument instanceof SpreadElement) {
6312
- // This deoptimizes the current and remaining parameters and arguments
6313
- for (; position < parameters.length; position++) {
6314
- args[position + 1]?.deoptimizePath(UNKNOWN_PATH);
6315
- parameters[position].forEach(variable => variable.markReassigned());
6316
- }
6317
- break;
6318
- }
6319
- if (this.hasRest && position >= parameters.length - 1) {
6320
- argument.deoptimizePath(UNKNOWN_PATH);
6321
- }
6322
- else {
6323
- const variables = parameters[position];
6324
- if (variables) {
6325
- for (const variable of variables) {
6326
- variable.addArgumentValue(argument);
6327
- }
6328
- }
6329
- this.addArgumentToBeDeoptimized(argument);
6330
- }
6331
- }
6332
- const nonRestParameterLength = this.hasRest ? parameters.length - 1 : parameters.length;
6333
- for (; position < nonRestParameterLength; position++) {
6334
- for (const variable of parameters[position]) {
6335
- variable.addArgumentValue(UNDEFINED_EXPRESSION);
6336
- }
6337
- }
6338
- }
6339
6027
  getReturnExpression() {
6340
6028
  if (this.returnExpression === null)
6341
6029
  this.updateReturnExpression();
6342
6030
  return this.returnExpression;
6343
6031
  }
6344
- deoptimizeAllParameters() {
6345
- for (const parameter of this.parameters) {
6346
- for (const variable of parameter) {
6347
- variable.deoptimizePath(UNKNOWN_PATH);
6348
- variable.markReassigned();
6349
- }
6350
- }
6351
- }
6352
- reassignAllParameters() {
6353
- for (const parameter of this.parameters) {
6354
- for (const variable of parameter) {
6355
- variable.markReassigned();
6356
- }
6357
- }
6358
- }
6359
- addArgumentToBeDeoptimized(_argument) { }
6360
6032
  updateReturnExpression() {
6361
6033
  if (this.returnExpressions.length === 1) {
6362
6034
  this.returnExpression = this.returnExpressions[0];
@@ -6372,30 +6044,24 @@ class ReturnValueScope extends ParameterScope {
6372
6044
 
6373
6045
  class FunctionScope extends ReturnValueScope {
6374
6046
  constructor(parent) {
6375
- super(parent, false);
6376
6047
  const { context } = parent;
6048
+ super(parent, false);
6377
6049
  this.variables.set('arguments', (this.argumentsVariable = new ArgumentsVariable(context)));
6378
6050
  this.variables.set('this', (this.thisVariable = new ThisVariable(context)));
6379
6051
  }
6380
6052
  findLexicalBoundary() {
6381
6053
  return this;
6382
6054
  }
6383
- includeCallArguments(context, interaction) {
6384
- super.includeCallArguments(context, interaction);
6055
+ includeCallArguments(context, parameters) {
6056
+ super.includeCallArguments(context, parameters);
6385
6057
  if (this.argumentsVariable.included) {
6386
- const { args } = interaction;
6387
- for (let argumentIndex = 1; argumentIndex < args.length; argumentIndex++) {
6388
- const argument = args[argumentIndex];
6389
- if (argument) {
6390
- argument.includePath(UNKNOWN_PATH, context);
6058
+ for (const argument of parameters) {
6059
+ if (!argument.included) {
6391
6060
  argument.include(context, false);
6392
6061
  }
6393
6062
  }
6394
6063
  }
6395
6064
  }
6396
- addArgumentToBeDeoptimized(argument) {
6397
- this.argumentsVariable.addArgumentToBeDeoptimized(argument);
6398
- }
6399
6065
  }
6400
6066
 
6401
6067
  class ExpressionStatement extends NodeBase {
@@ -6423,9 +6089,8 @@ class ExpressionStatement extends NodeBase {
6423
6089
  return this.parent.type !== Program$1;
6424
6090
  return super.shouldBeIncluded(context);
6425
6091
  }
6092
+ applyDeoptimizations() { }
6426
6093
  }
6427
- ExpressionStatement.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
6428
- ExpressionStatement.prototype.applyDeoptimizations = doNotDeoptimize;
6429
6094
 
6430
6095
  class BlockStatement extends NodeBase {
6431
6096
  get deoptimizeBody() {
@@ -6490,8 +6155,6 @@ class BlockStatement extends NodeBase {
6490
6155
  }
6491
6156
  }
6492
6157
  }
6493
- BlockStatement.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
6494
- BlockStatement.prototype.applyDeoptimizations = doNotDeoptimize;
6495
6158
 
6496
6159
  class RestElement extends NodeBase {
6497
6160
  constructor() {
@@ -6501,12 +6164,9 @@ class RestElement extends NodeBase {
6501
6164
  addExportedVariables(variables, exportNamesByVariable) {
6502
6165
  this.argument.addExportedVariables(variables, exportNamesByVariable);
6503
6166
  }
6504
- declare(kind, destructuredInitPath, init) {
6167
+ declare(kind, init) {
6505
6168
  this.declarationInit = init;
6506
- return this.argument.declare(kind, getIncludedPatternPath$1(destructuredInitPath), init);
6507
- }
6508
- deoptimizeAssignment(destructuredInitPath, init) {
6509
- this.argument.deoptimizeAssignment(getIncludedPatternPath$1(destructuredInitPath), init);
6169
+ return this.argument.declare(kind, UNKNOWN_EXPRESSION);
6510
6170
  }
6511
6171
  deoptimizePath(path) {
6512
6172
  if (path.length === 0) {
@@ -6517,20 +6177,6 @@ class RestElement extends NodeBase {
6517
6177
  return (path.length > 0 ||
6518
6178
  this.argument.hasEffectsOnInteractionAtPath(EMPTY_PATH, interaction, context));
6519
6179
  }
6520
- hasEffectsWhenDestructuring(context, destructuredInitPath, init) {
6521
- return this.argument.hasEffectsWhenDestructuring(context, getIncludedPatternPath$1(destructuredInitPath), init);
6522
- }
6523
- includeDestructuredIfNecessary(context, destructuredInitPath, init) {
6524
- return (this.included =
6525
- this.argument.includeDestructuredIfNecessary(context, getIncludedPatternPath$1(destructuredInitPath), init) || this.included);
6526
- }
6527
- include(context, includeChildrenRecursively) {
6528
- if (!this.included)
6529
- this.includeNode(context);
6530
- // This should just include the identifier, its properties should be
6531
- // included where the variable is used.
6532
- this.argument.include(context, includeChildrenRecursively);
6533
- }
6534
6180
  markDeclarationReached() {
6535
6181
  this.argument.markDeclarationReached();
6536
6182
  }
@@ -6542,16 +6188,12 @@ class RestElement extends NodeBase {
6542
6188
  }
6543
6189
  }
6544
6190
  }
6545
- RestElement.prototype.includeNode = onlyIncludeSelf;
6546
- const getIncludedPatternPath$1 = (destructuredInitPath) => destructuredInitPath.at(-1) === UnknownKey
6547
- ? destructuredInitPath
6548
- : [...destructuredInitPath, UnknownKey];
6549
6191
 
6550
6192
  class FunctionBase extends NodeBase {
6551
6193
  constructor() {
6552
6194
  super(...arguments);
6195
+ this.objectEntity = null;
6553
6196
  this.parameterVariableValuesDeoptimized = false;
6554
- this.includeCallArguments = this.scope.includeCallArguments.bind(this.scope);
6555
6197
  }
6556
6198
  get async() {
6557
6199
  return isFlagSet(this.flags, 256 /* Flag.async */);
@@ -6571,15 +6213,53 @@ class FunctionBase extends NodeBase {
6571
6213
  set generator(value) {
6572
6214
  this.flags = setFlag(this.flags, 4194304 /* Flag.generator */, value);
6573
6215
  }
6574
- get hasCachedEffects() {
6575
- return isFlagSet(this.flags, 67108864 /* Flag.hasEffects */);
6216
+ updateParameterVariableValues(_arguments) {
6217
+ for (let position = 0; position < this.params.length; position++) {
6218
+ const parameter = this.params[position];
6219
+ if (!(parameter instanceof Identifier)) {
6220
+ continue;
6221
+ }
6222
+ const parameterVariable = parameter.variable;
6223
+ const argument = _arguments[position + 1] ?? UNDEFINED_EXPRESSION;
6224
+ parameterVariable.updateKnownValue(argument);
6225
+ }
6576
6226
  }
6577
- set hasCachedEffects(value) {
6578
- this.flags = setFlag(this.flags, 67108864 /* Flag.hasEffects */, value);
6227
+ deoptimizeParameterVariableValues() {
6228
+ for (const parameter of this.params) {
6229
+ if (parameter instanceof Identifier) {
6230
+ const parameterVariable = parameter.variable;
6231
+ parameterVariable.markReassigned();
6232
+ }
6233
+ }
6579
6234
  }
6580
6235
  deoptimizeArgumentsOnInteractionAtPath(interaction, path, recursionTracker) {
6581
- if (interaction.type === INTERACTION_CALLED && path.length === 0) {
6582
- this.scope.deoptimizeArgumentsOnCall(interaction);
6236
+ if (interaction.type === INTERACTION_CALLED) {
6237
+ const { parameters } = this.scope;
6238
+ const { args } = interaction;
6239
+ let hasRest = false;
6240
+ for (let position = 0; position < args.length - 1; position++) {
6241
+ const parameter = this.params[position];
6242
+ // Only the "this" argument arg[0] can be null
6243
+ const argument = args[position + 1];
6244
+ if (argument instanceof SpreadElement) {
6245
+ this.deoptimizeParameterVariableValues();
6246
+ }
6247
+ if (hasRest || parameter instanceof RestElement) {
6248
+ hasRest = true;
6249
+ argument.deoptimizePath(UNKNOWN_PATH);
6250
+ }
6251
+ else if (parameter instanceof Identifier) {
6252
+ parameters[position][0].addEntityToBeDeoptimized(argument);
6253
+ this.addArgumentToBeDeoptimized(argument);
6254
+ }
6255
+ else if (parameter) {
6256
+ argument.deoptimizePath(UNKNOWN_PATH);
6257
+ }
6258
+ else {
6259
+ this.addArgumentToBeDeoptimized(argument);
6260
+ }
6261
+ }
6262
+ this.updateParameterVariableValues(args);
6583
6263
  }
6584
6264
  else {
6585
6265
  this.getObjectEntity().deoptimizeArgumentsOnInteractionAtPath(interaction, path, recursionTracker);
@@ -6591,7 +6271,12 @@ class FunctionBase extends NodeBase {
6591
6271
  // A reassignment of UNKNOWN_PATH is considered equivalent to having lost track
6592
6272
  // which means the return expression and parameters need to be reassigned
6593
6273
  this.scope.getReturnExpression().deoptimizePath(UNKNOWN_PATH);
6594
- this.scope.deoptimizeAllParameters();
6274
+ for (const parameterList of this.scope.parameters) {
6275
+ for (const parameter of parameterList) {
6276
+ parameter.deoptimizePath(UNKNOWN_PATH);
6277
+ parameter.markReassigned();
6278
+ }
6279
+ }
6595
6280
  }
6596
6281
  }
6597
6282
  getLiteralValueAtPath(path, recursionTracker, origin) {
@@ -6615,8 +6300,8 @@ class FunctionBase extends NodeBase {
6615
6300
  if (path.length > 0 || interaction.type !== INTERACTION_CALLED) {
6616
6301
  return this.getObjectEntity().hasEffectsOnInteractionAtPath(path, interaction, context);
6617
6302
  }
6618
- if (this.hasCachedEffects) {
6619
- return true;
6303
+ if (this.annotationNoSideEffects) {
6304
+ return false;
6620
6305
  }
6621
6306
  if (this.async) {
6622
6307
  const { propertyReadSideEffects } = this.scope.context.options
@@ -6626,20 +6311,12 @@ class FunctionBase extends NodeBase {
6626
6311
  (propertyReadSideEffects &&
6627
6312
  (propertyReadSideEffects === 'always' ||
6628
6313
  returnExpression.hasEffectsOnInteractionAtPath(['then'], NODE_INTERACTION_UNKNOWN_ACCESS, context)))) {
6629
- this.hasCachedEffects = true;
6630
6314
  return true;
6631
6315
  }
6632
6316
  }
6633
- const { propertyReadSideEffects } = this.scope.context.options
6634
- .treeshake;
6635
- for (let index = 0; index < this.params.length; index++) {
6636
- const parameter = this.params[index];
6637
- if (parameter.hasEffects(context) ||
6638
- (propertyReadSideEffects &&
6639
- parameter.hasEffectsWhenDestructuring(context, EMPTY_PATH, interaction.args[index + 1] || UNDEFINED_EXPRESSION))) {
6640
- this.hasCachedEffects = true;
6317
+ for (const parameter of this.params) {
6318
+ if (parameter.hasEffects(context))
6641
6319
  return true;
6642
- }
6643
6320
  }
6644
6321
  return false;
6645
6322
  }
@@ -6657,17 +6334,21 @@ class FunctionBase extends NodeBase {
6657
6334
  return variable?.getOnlyFunctionCallUsed() ?? false;
6658
6335
  }
6659
6336
  include(context, includeChildrenRecursively) {
6660
- if (!this.included)
6661
- this.includeNode(context);
6662
- if (!(this.parameterVariableValuesDeoptimized || this.onlyFunctionCallUsed())) {
6337
+ if (!this.parameterVariableValuesDeoptimized && !this.onlyFunctionCallUsed()) {
6663
6338
  this.parameterVariableValuesDeoptimized = true;
6664
- this.scope.reassignAllParameters();
6339
+ this.deoptimizeParameterVariableValues();
6665
6340
  }
6341
+ if (!this.deoptimized)
6342
+ this.applyDeoptimizations();
6343
+ this.included = true;
6666
6344
  const { brokenFlow } = context;
6667
6345
  context.brokenFlow = false;
6668
6346
  this.body.include(context, includeChildrenRecursively);
6669
6347
  context.brokenFlow = brokenFlow;
6670
6348
  }
6349
+ includeCallArguments(context, parameters) {
6350
+ this.scope.includeCallArguments(context, parameters);
6351
+ }
6671
6352
  initialise() {
6672
6353
  super.initialise();
6673
6354
  if (this.body instanceof BlockStatement) {
@@ -6689,14 +6370,14 @@ class FunctionBase extends NodeBase {
6689
6370
  // so that the scope already knows all parameters and can detect conflicts
6690
6371
  // when parsing the body.
6691
6372
  const parameters = (this.params = params.map((parameter) => new (context.getNodeConstructor(parameter.type))(this, scope).parseNode(parameter)));
6692
- scope.addParameterVariables(parameters.map(parameter => parameter.declare('parameter', EMPTY_PATH, UNKNOWN_EXPRESSION)), parameters[parameters.length - 1] instanceof RestElement);
6373
+ scope.addParameterVariables(parameters.map(parameter => parameter.declare('parameter', UNKNOWN_EXPRESSION)), parameters[parameters.length - 1] instanceof RestElement);
6693
6374
  this.body = new (context.getNodeConstructor(body.type))(this, bodyScope).parseNode(body);
6694
6375
  return super.parseNode(esTreeNode);
6695
6376
  }
6377
+ addArgumentToBeDeoptimized(_argument) { }
6378
+ applyDeoptimizations() { }
6696
6379
  }
6697
6380
  FunctionBase.prototype.preventChildBlockScope = true;
6698
- FunctionBase.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
6699
- FunctionBase.prototype.applyDeoptimizations = doNotDeoptimize;
6700
6381
 
6701
6382
  class FunctionNode extends FunctionBase {
6702
6383
  constructor() {
@@ -6708,31 +6389,30 @@ class FunctionNode extends FunctionBase {
6708
6389
  this.constructedEntity = new ObjectEntity(Object.create(null), OBJECT_PROTOTYPE);
6709
6390
  // This makes sure that all deoptimizations of "this" are applied to the
6710
6391
  // constructed entity.
6711
- this.scope.thisVariable.addArgumentValue(this.constructedEntity);
6392
+ this.scope.thisVariable.addEntityToBeDeoptimized(this.constructedEntity);
6712
6393
  }
6713
6394
  deoptimizeArgumentsOnInteractionAtPath(interaction, path, recursionTracker) {
6714
6395
  super.deoptimizeArgumentsOnInteractionAtPath(interaction, path, recursionTracker);
6715
6396
  if (interaction.type === INTERACTION_CALLED && path.length === 0 && interaction.args[0]) {
6716
6397
  // args[0] is the "this" argument
6717
- this.scope.thisVariable.addArgumentValue(interaction.args[0]);
6398
+ this.scope.thisVariable.addEntityToBeDeoptimized(interaction.args[0]);
6718
6399
  }
6719
6400
  }
6720
6401
  hasEffects(context) {
6402
+ if (!this.deoptimized)
6403
+ this.applyDeoptimizations();
6721
6404
  if (this.annotationNoSideEffects) {
6722
6405
  return false;
6723
6406
  }
6724
6407
  return !!this.id?.hasEffects(context);
6725
6408
  }
6726
6409
  hasEffectsOnInteractionAtPath(path, interaction, context) {
6727
- if (this.annotationNoSideEffects &&
6728
- path.length === 0 &&
6729
- interaction.type === INTERACTION_CALLED) {
6730
- return false;
6731
- }
6732
- if (super.hasEffectsOnInteractionAtPath(path, interaction, context)) {
6410
+ if (super.hasEffectsOnInteractionAtPath(path, interaction, context))
6733
6411
  return true;
6412
+ if (this.annotationNoSideEffects) {
6413
+ return false;
6734
6414
  }
6735
- if (path.length === 0 && interaction.type === INTERACTION_CALLED) {
6415
+ if (interaction.type === INTERACTION_CALLED) {
6736
6416
  const thisInit = context.replacedVariableInits.get(this.scope.thisVariable);
6737
6417
  context.replacedVariableInits.set(this.scope.thisVariable, interaction.withNew ? this.constructedEntity : UNKNOWN_EXPRESSION);
6738
6418
  const { brokenFlow, ignore, replacedVariableInits } = context;
@@ -6743,10 +6423,8 @@ class FunctionNode extends FunctionBase {
6743
6423
  returnYield: true,
6744
6424
  this: interaction.withNew
6745
6425
  };
6746
- if (this.body.hasEffects(context)) {
6747
- this.hasCachedEffects = true;
6426
+ if (this.body.hasEffects(context))
6748
6427
  return true;
6749
- }
6750
6428
  context.brokenFlow = brokenFlow;
6751
6429
  if (thisInit) {
6752
6430
  replacedVariableInits.set(this.scope.thisVariable, thisInit);
@@ -6760,7 +6438,7 @@ class FunctionNode extends FunctionBase {
6760
6438
  }
6761
6439
  include(context, includeChildrenRecursively) {
6762
6440
  super.include(context, includeChildrenRecursively);
6763
- this.id?.include(context);
6441
+ this.id?.include();
6764
6442
  const hasArguments = this.scope.argumentsVariable.included;
6765
6443
  for (const parameter of this.params) {
6766
6444
  if (!(parameter instanceof Identifier) || hasArguments) {
@@ -6768,18 +6446,12 @@ class FunctionNode extends FunctionBase {
6768
6446
  }
6769
6447
  }
6770
6448
  }
6771
- includeNode(context) {
6772
- this.included = true;
6773
- const hasArguments = this.scope.argumentsVariable.included;
6774
- for (const parameter of this.params) {
6775
- if (!(parameter instanceof Identifier) || hasArguments) {
6776
- parameter.includePath(UNKNOWN_PATH, context);
6777
- }
6778
- }
6779
- }
6780
6449
  initialise() {
6781
6450
  super.initialise();
6782
- this.id?.declare('function', EMPTY_PATH, this);
6451
+ this.id?.declare('function', this);
6452
+ }
6453
+ addArgumentToBeDeoptimized(argument) {
6454
+ this.scope.argumentsVariable.addArgumentToBeDeoptimized(argument);
6783
6455
  }
6784
6456
  getObjectEntity() {
6785
6457
  if (this.objectEntity !== null) {
@@ -6829,16 +6501,11 @@ function getFunctionIdInsertPosition(code, start) {
6829
6501
  }
6830
6502
  class ExportDefaultDeclaration extends NodeBase {
6831
6503
  include(context, includeChildrenRecursively) {
6832
- this.included = true;
6833
- this.declaration.include(context, includeChildrenRecursively);
6504
+ super.include(context, includeChildrenRecursively);
6834
6505
  if (includeChildrenRecursively) {
6835
- this.scope.context.includeVariableInModule(this.variable, UNKNOWN_PATH, context);
6506
+ this.scope.context.includeVariableInModule(this.variable);
6836
6507
  }
6837
6508
  }
6838
- includePath(path, context) {
6839
- this.included = true;
6840
- this.declaration.includePath(path, context);
6841
- }
6842
6509
  initialise() {
6843
6510
  super.initialise();
6844
6511
  const declaration = this.declaration;
@@ -6883,6 +6550,7 @@ class ExportDefaultDeclaration extends NodeBase {
6883
6550
  }
6884
6551
  this.declaration.render(code, options);
6885
6552
  }
6553
+ applyDeoptimizations() { }
6886
6554
  renderNamedDeclaration(code, declarationStart, idInsertPosition, options) {
6887
6555
  const { exportNamesByVariable, format, snippets: { getPropertyAccess } } = options;
6888
6556
  const name = this.variable.getName(getPropertyAccess);
@@ -6913,8 +6581,6 @@ class ExportDefaultDeclaration extends NodeBase {
6913
6581
  }
6914
6582
  }
6915
6583
  ExportDefaultDeclaration.prototype.needsBoundaries = true;
6916
- ExportDefaultDeclaration.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
6917
- ExportDefaultDeclaration.prototype.applyDeoptimizations = doNotDeoptimize;
6918
6584
 
6919
6585
  const needsEscapeRegEx = /[\n\r'\\\u2028\u2029]/;
6920
6586
  const quoteNewlineRegEx = /([\n\r'\u2028\u2029])/g;
@@ -7184,7 +6850,6 @@ class Literal extends NodeBase {
7184
6850
  }
7185
6851
  }
7186
6852
  }
7187
- Literal.prototype.includeNode = onlyIncludeSelf;
7188
6853
 
7189
6854
  function getChainElementLiteralValueAtPath(element, object, path, recursionTracker, origin) {
7190
6855
  if ('getLiteralValueAtPathAsChainElement' in object) {
@@ -7200,6 +6865,8 @@ function getChainElementLiteralValueAtPath(element, object, path, recursionTrack
7200
6865
  return element.getLiteralValueAtPath(path, recursionTracker, origin);
7201
6866
  }
7202
6867
 
6868
+ // To avoid infinite recursions
6869
+ const MAX_PATH_DEPTH = 7;
7203
6870
  function getResolvablePropertyKey(memberExpression) {
7204
6871
  return memberExpression.computed
7205
6872
  ? getResolvableComputedPropertyKey(memberExpression.property)
@@ -7298,27 +6965,18 @@ class MemberExpression extends NodeBase {
7298
6965
  }
7299
6966
  else if (!this.isUndefined) {
7300
6967
  if (path.length < MAX_PATH_DEPTH) {
7301
- this.object.deoptimizeArgumentsOnInteractionAtPath(interaction, this.propertyKey === UnknownKey ? UNKNOWN_PATH : [this.propertyKey, ...path], recursionTracker);
6968
+ this.object.deoptimizeArgumentsOnInteractionAtPath(interaction, [this.getPropertyKey(), ...path], recursionTracker);
7302
6969
  }
7303
6970
  else {
7304
6971
  deoptimizeInteraction(interaction);
7305
6972
  }
7306
6973
  }
7307
6974
  }
7308
- deoptimizeAssignment(destructuredInitPath, init) {
7309
- this.deoptimizePath(EMPTY_PATH);
7310
- init.deoptimizePath([...destructuredInitPath, UnknownKey]);
7311
- }
7312
6975
  deoptimizeCache() {
7313
- if (this.propertyKey === this.dynamicPropertyKey)
7314
- return;
7315
6976
  const { expressionsToBeDeoptimized, object } = this;
7316
6977
  this.expressionsToBeDeoptimized = EMPTY_ARRAY;
7317
- this.dynamicPropertyKey = this.propertyKey;
6978
+ this.propertyKey = UnknownKey;
7318
6979
  object.deoptimizePath(UNKNOWN_PATH);
7319
- if (this.included) {
7320
- object.includePath(UNKNOWN_PATH, createInclusionContext());
7321
- }
7322
6980
  for (const expression of expressionsToBeDeoptimized) {
7323
6981
  expression.deoptimizeCache();
7324
6982
  }
@@ -7329,13 +6987,11 @@ class MemberExpression extends NodeBase {
7329
6987
  if (this.variable) {
7330
6988
  this.variable.deoptimizePath(path);
7331
6989
  }
7332
- else if (!this.isUndefined) {
7333
- const { propertyKey } = this;
6990
+ else if (!this.isUndefined && path.length < MAX_PATH_DEPTH) {
6991
+ const propertyKey = this.getPropertyKey();
7334
6992
  this.object.deoptimizePath([
7335
6993
  propertyKey === UnknownKey ? UnknownNonAccessorKey : propertyKey,
7336
- ...(path.length < MAX_PATH_DEPTH
7337
- ? path
7338
- : [...path.slice(0, MAX_PATH_DEPTH), UnknownKey])
6994
+ ...path
7339
6995
  ]);
7340
6996
  }
7341
6997
  }
@@ -7346,11 +7002,9 @@ class MemberExpression extends NodeBase {
7346
7002
  if (this.isUndefined) {
7347
7003
  return undefined;
7348
7004
  }
7349
- const propertyKey = this.getDynamicPropertyKey();
7350
- if (propertyKey !== UnknownKey && path.length < MAX_PATH_DEPTH) {
7351
- if (propertyKey !== this.propertyKey)
7352
- this.expressionsToBeDeoptimized.push(origin);
7353
- return this.object.getLiteralValueAtPath([propertyKey, ...path], recursionTracker, origin);
7005
+ if (this.propertyKey !== UnknownKey && path.length < MAX_PATH_DEPTH) {
7006
+ this.expressionsToBeDeoptimized.push(origin);
7007
+ return this.object.getLiteralValueAtPath([this.getPropertyKey(), ...path], recursionTracker, origin);
7354
7008
  }
7355
7009
  return UnknownValue;
7356
7010
  }
@@ -7370,11 +7024,9 @@ class MemberExpression extends NodeBase {
7370
7024
  if (this.isUndefined) {
7371
7025
  return [UNDEFINED_EXPRESSION, false];
7372
7026
  }
7373
- const propertyKey = this.getDynamicPropertyKey();
7374
- if (propertyKey !== UnknownKey && path.length < MAX_PATH_DEPTH) {
7375
- if (propertyKey !== this.propertyKey)
7376
- this.expressionsToBeDeoptimized.push(origin);
7377
- return this.object.getReturnExpressionWhenCalledAtPath([propertyKey, ...path], interaction, recursionTracker, origin);
7027
+ if (this.propertyKey !== UnknownKey && path.length < MAX_PATH_DEPTH) {
7028
+ this.expressionsToBeDeoptimized.push(origin);
7029
+ return this.object.getReturnExpressionWhenCalledAtPath([this.getPropertyKey(), ...path], interaction, recursionTracker, origin);
7378
7030
  }
7379
7031
  return UNKNOWN_RETURN_EXPRESSION;
7380
7032
  }
@@ -7420,45 +7072,14 @@ class MemberExpression extends NodeBase {
7420
7072
  return true;
7421
7073
  }
7422
7074
  if (path.length < MAX_PATH_DEPTH) {
7423
- return this.object.hasEffectsOnInteractionAtPath([this.getDynamicPropertyKey(), ...path], interaction, context);
7075
+ return this.object.hasEffectsOnInteractionAtPath([this.getPropertyKey(), ...path], interaction, context);
7424
7076
  }
7425
7077
  return true;
7426
7078
  }
7427
- hasEffectsWhenDestructuring(context, destructuredInitPath, init) {
7428
- return (destructuredInitPath.length > 0 &&
7429
- init.hasEffectsOnInteractionAtPath(destructuredInitPath, NODE_INTERACTION_UNKNOWN_ACCESS, context));
7430
- }
7431
7079
  include(context, includeChildrenRecursively) {
7432
- if (!this.included)
7433
- this.includeNode(context);
7434
- this.object.include(context, includeChildrenRecursively);
7435
- this.property.include(context, includeChildrenRecursively);
7436
- }
7437
- includeNode(context) {
7438
- this.included = true;
7439
7080
  if (!this.deoptimized)
7440
7081
  this.applyDeoptimizations();
7441
- if (this.variable) {
7442
- this.scope.context.includeVariableInModule(this.variable, EMPTY_PATH, context);
7443
- }
7444
- else if (!this.isUndefined) {
7445
- this.object.includePath([this.propertyKey], context);
7446
- }
7447
- }
7448
- includePath(path, context) {
7449
- if (!this.included)
7450
- this.includeNode(context);
7451
- if (this.variable) {
7452
- this.variable?.includePath(path, context);
7453
- }
7454
- else if (!this.isUndefined) {
7455
- this.object.includePath([
7456
- this.propertyKey,
7457
- ...(path.length < MAX_PATH_DEPTH
7458
- ? path
7459
- : [...path.slice(0, MAX_PATH_DEPTH), UnknownKey])
7460
- ], context);
7461
- }
7082
+ this.includeProperties(context, includeChildrenRecursively);
7462
7083
  }
7463
7084
  includeAsAssignmentTarget(context, includeChildrenRecursively, deoptimizeAccess) {
7464
7085
  if (!this.assignmentDeoptimized)
@@ -7467,34 +7088,20 @@ class MemberExpression extends NodeBase {
7467
7088
  this.include(context, includeChildrenRecursively);
7468
7089
  }
7469
7090
  else {
7470
- if (!this.included)
7471
- this.includeNode(context);
7472
- this.object.include(context, includeChildrenRecursively);
7473
- this.property.include(context, includeChildrenRecursively);
7091
+ this.includeProperties(context, includeChildrenRecursively);
7474
7092
  }
7475
7093
  }
7476
- includeCallArguments(context, interaction) {
7094
+ includeCallArguments(context, parameters) {
7477
7095
  if (this.variable) {
7478
- this.variable.includeCallArguments(context, interaction);
7096
+ this.variable.includeCallArguments(context, parameters);
7479
7097
  }
7480
7098
  else {
7481
- super.includeCallArguments(context, interaction);
7482
- }
7483
- }
7484
- includeDestructuredIfNecessary(context, destructuredInitPath, init) {
7485
- if ((this.included ||=
7486
- destructuredInitPath.length > 0 &&
7487
- !context.brokenFlow &&
7488
- init.hasEffectsOnInteractionAtPath(destructuredInitPath, NODE_INTERACTION_UNKNOWN_ACCESS, createHasEffectsContext()))) {
7489
- init.include(context, false);
7490
- return true;
7099
+ super.includeCallArguments(context, parameters);
7491
7100
  }
7492
- return false;
7493
7101
  }
7494
7102
  initialise() {
7495
7103
  super.initialise();
7496
- this.dynamicPropertyKey = getResolvablePropertyKey(this);
7497
- this.propertyKey = this.dynamicPropertyKey === null ? UnknownKey : this.dynamicPropertyKey;
7104
+ this.propertyKey = getResolvablePropertyKey(this);
7498
7105
  this.accessInteraction = { args: [this.object], type: INTERACTION_ACCESSED };
7499
7106
  }
7500
7107
  render(code, options, { renderedParentType, isCalleeOfRenderedParent, renderedSurroundingElement } = BLANK) {
@@ -7531,7 +7138,8 @@ class MemberExpression extends NodeBase {
7531
7138
  this.bound &&
7532
7139
  propertyReadSideEffects &&
7533
7140
  !(this.variable || this.isUndefined)) {
7534
- this.object.deoptimizeArgumentsOnInteractionAtPath(this.accessInteraction, [this.propertyKey], SHARED_RECURSION_TRACKER);
7141
+ const propertyKey = this.getPropertyKey();
7142
+ this.object.deoptimizeArgumentsOnInteractionAtPath(this.accessInteraction, [propertyKey], SHARED_RECURSION_TRACKER);
7535
7143
  this.scope.context.requestTreeshakingPass();
7536
7144
  }
7537
7145
  if (this.variable) {
@@ -7548,7 +7156,7 @@ class MemberExpression extends NodeBase {
7548
7156
  this.bound &&
7549
7157
  propertyReadSideEffects &&
7550
7158
  !(this.variable || this.isUndefined)) {
7551
- this.object.deoptimizeArgumentsOnInteractionAtPath(this.assignmentInteraction, [this.propertyKey], SHARED_RECURSION_TRACKER);
7159
+ this.object.deoptimizeArgumentsOnInteractionAtPath(this.assignmentInteraction, [this.getPropertyKey()], SHARED_RECURSION_TRACKER);
7552
7160
  this.scope.context.requestTreeshakingPass();
7553
7161
  }
7554
7162
  }
@@ -7557,24 +7165,24 @@ class MemberExpression extends NodeBase {
7557
7165
  const variable = this.scope.findVariable(this.object.name);
7558
7166
  if (variable.isNamespace) {
7559
7167
  if (this.variable) {
7560
- this.scope.context.includeVariableInModule(this.variable, UNKNOWN_PATH, createInclusionContext());
7168
+ this.scope.context.includeVariableInModule(this.variable);
7561
7169
  }
7562
7170
  this.scope.context.log(LOGLEVEL_WARN, logIllegalImportReassignment(this.object.name, this.scope.context.module.id), this.start);
7563
7171
  }
7564
7172
  }
7565
7173
  }
7566
- getDynamicPropertyKey() {
7567
- if (this.dynamicPropertyKey === null) {
7568
- this.dynamicPropertyKey = this.propertyKey;
7174
+ getPropertyKey() {
7175
+ if (this.propertyKey === null) {
7176
+ this.propertyKey = UnknownKey;
7569
7177
  const value = this.property.getLiteralValueAtPath(EMPTY_PATH, SHARED_RECURSION_TRACKER, this);
7570
- return (this.dynamicPropertyKey =
7178
+ return (this.propertyKey =
7571
7179
  value === SymbolToStringTag
7572
7180
  ? value
7573
7181
  : typeof value === 'symbol'
7574
7182
  ? UnknownKey
7575
7183
  : String(value));
7576
7184
  }
7577
- return this.dynamicPropertyKey;
7185
+ return this.propertyKey;
7578
7186
  }
7579
7187
  hasAccessEffect(context) {
7580
7188
  const { propertyReadSideEffects } = this.scope.context.options
@@ -7582,7 +7190,17 @@ class MemberExpression extends NodeBase {
7582
7190
  return (!(this.variable || this.isUndefined) &&
7583
7191
  propertyReadSideEffects &&
7584
7192
  (propertyReadSideEffects === 'always' ||
7585
- this.object.hasEffectsOnInteractionAtPath([this.getDynamicPropertyKey()], this.accessInteraction, context)));
7193
+ this.object.hasEffectsOnInteractionAtPath([this.getPropertyKey()], this.accessInteraction, context)));
7194
+ }
7195
+ includeProperties(context, includeChildrenRecursively) {
7196
+ if (!this.included) {
7197
+ this.included = true;
7198
+ if (this.variable) {
7199
+ this.scope.context.includeVariableInModule(this.variable);
7200
+ }
7201
+ }
7202
+ this.object.include(context, includeChildrenRecursively);
7203
+ this.property.include(context, includeChildrenRecursively);
7586
7204
  }
7587
7205
  }
7588
7206
  function resolveNamespaceVariables(baseVariable, path, astContext) {
@@ -7626,20 +7244,18 @@ class MetaProperty extends NodeBase {
7626
7244
  return path.length > 1 || type !== INTERACTION_ACCESSED;
7627
7245
  }
7628
7246
  include() {
7629
- if (!this.included)
7630
- this.includeNode();
7631
- }
7632
- includeNode() {
7633
- this.included = true;
7634
- if (this.meta.name === IMPORT) {
7635
- this.scope.context.addImportMeta(this);
7636
- const parent = this.parent;
7637
- const metaProperty = (this.metaProperty =
7638
- parent instanceof MemberExpression && typeof parent.propertyKey === 'string'
7639
- ? parent.propertyKey
7640
- : null);
7641
- if (metaProperty?.startsWith(FILE_PREFIX)) {
7642
- this.referenceId = metaProperty.slice(FILE_PREFIX.length);
7247
+ if (!this.included) {
7248
+ this.included = true;
7249
+ if (this.meta.name === IMPORT) {
7250
+ this.scope.context.addImportMeta(this);
7251
+ const parent = this.parent;
7252
+ const metaProperty = (this.metaProperty =
7253
+ parent instanceof MemberExpression && typeof parent.propertyKey === 'string'
7254
+ ? parent.propertyKey
7255
+ : null);
7256
+ if (metaProperty?.startsWith(FILE_PREFIX)) {
7257
+ this.referenceId = metaProperty.slice(FILE_PREFIX.length);
7258
+ }
7643
7259
  }
7644
7260
  }
7645
7261
  }
@@ -7746,7 +7362,7 @@ class UndefinedVariable extends Variable {
7746
7362
 
7747
7363
  class ExportDefaultVariable extends LocalVariable {
7748
7364
  constructor(name, exportDefaultDeclaration, context) {
7749
- super(name, exportDefaultDeclaration, exportDefaultDeclaration.declaration, EMPTY_PATH, context, 'other');
7365
+ super(name, exportDefaultDeclaration, exportDefaultDeclaration.declaration, context, 'other');
7750
7366
  this.hasId = false;
7751
7367
  this.originalId = null;
7752
7368
  this.originalVariable = null;
@@ -7895,8 +7511,8 @@ class NamespaceVariable extends Variable {
7895
7511
  return (!memberVariable ||
7896
7512
  memberVariable.hasEffectsOnInteractionAtPath(path.slice(1), interaction, context));
7897
7513
  }
7898
- includePath(path, context) {
7899
- super.includePath(path, context);
7514
+ include() {
7515
+ super.include();
7900
7516
  this.context.includeAllExports();
7901
7517
  }
7902
7518
  prepare(accessedGlobalsByScope) {
@@ -7989,9 +7605,9 @@ class SyntheticNamedExportVariable extends Variable {
7989
7605
  getName(getPropertyAccess) {
7990
7606
  return `${this.syntheticNamespace.getName(getPropertyAccess)}${getPropertyAccess(this.name)}`;
7991
7607
  }
7992
- includePath(path, context) {
7993
- super.includePath(path, context);
7994
- this.context.includeVariableInModule(this.syntheticNamespace, path, context);
7608
+ include() {
7609
+ super.include();
7610
+ this.context.includeVariableInModule(this.syntheticNamespace);
7995
7611
  }
7996
7612
  setRenderNames(baseName, name) {
7997
7613
  super.setRenderNames(baseName, name);
@@ -11196,37 +10812,21 @@ class ArrayPattern extends NodeBase {
11196
10812
  element?.addExportedVariables(variables, exportNamesByVariable);
11197
10813
  }
11198
10814
  }
11199
- declare(kind, destructuredInitPath, init) {
10815
+ declare(kind) {
11200
10816
  const variables = [];
11201
- const includedPatternPath = getIncludedPatternPath(destructuredInitPath);
11202
10817
  for (const element of this.elements) {
11203
10818
  if (element !== null) {
11204
- variables.push(...element.declare(kind, includedPatternPath, init));
10819
+ variables.push(...element.declare(kind, UNKNOWN_EXPRESSION));
11205
10820
  }
11206
10821
  }
11207
10822
  return variables;
11208
10823
  }
11209
- deoptimizeAssignment(destructuredInitPath, init) {
11210
- const includedPatternPath = getIncludedPatternPath(destructuredInitPath);
11211
- for (const element of this.elements) {
11212
- element?.deoptimizeAssignment(includedPatternPath, init);
11213
- }
11214
- }
11215
10824
  // Patterns can only be deoptimized at the empty path at the moment
11216
10825
  deoptimizePath() {
11217
10826
  for (const element of this.elements) {
11218
10827
  element?.deoptimizePath(EMPTY_PATH);
11219
10828
  }
11220
10829
  }
11221
- hasEffectsWhenDestructuring(context, destructuredInitPath, init) {
11222
- const includedPatternPath = getIncludedPatternPath(destructuredInitPath);
11223
- for (const element of this.elements) {
11224
- if (element?.hasEffectsWhenDestructuring(context, includedPatternPath, init)) {
11225
- return true;
11226
- }
11227
- }
11228
- return false;
11229
- }
11230
10830
  // Patterns are only checked at the empty path at the moment
11231
10831
  hasEffectsOnInteractionAtPath(_path, interaction, context) {
11232
10832
  for (const element of this.elements) {
@@ -11235,38 +10835,12 @@ class ArrayPattern extends NodeBase {
11235
10835
  }
11236
10836
  return false;
11237
10837
  }
11238
- includeDestructuredIfNecessary(context, destructuredInitPath, init) {
11239
- let included = false;
11240
- const includedPatternPath = getIncludedPatternPath(destructuredInitPath);
11241
- for (const element of this.elements) {
11242
- if (element) {
11243
- element.included ||= included;
11244
- included =
11245
- element.includeDestructuredIfNecessary(context, includedPatternPath, init) || included;
11246
- }
11247
- }
11248
- if (included) {
11249
- // This is necessary so that if any pattern element is included, all are
11250
- // included for proper deconflicting
11251
- for (const element of this.elements) {
11252
- if (element && !element.included) {
11253
- element.included = true;
11254
- element.includeDestructuredIfNecessary(context, includedPatternPath, init);
11255
- }
11256
- }
11257
- }
11258
- return (this.included ||= included);
11259
- }
11260
10838
  markDeclarationReached() {
11261
10839
  for (const element of this.elements) {
11262
10840
  element?.markDeclarationReached();
11263
10841
  }
11264
10842
  }
11265
10843
  }
11266
- ArrayPattern.prototype.includeNode = onlyIncludeSelf;
11267
- const getIncludedPatternPath = (destructuredInitPath) => destructuredInitPath.at(-1) === UnknownKey
11268
- ? destructuredInitPath
11269
- : [...destructuredInitPath, UnknownInteger];
11270
10844
 
11271
10845
  class ArrowFunctionExpression extends FunctionBase {
11272
10846
  constructor() {
@@ -11283,17 +10857,17 @@ class ArrowFunctionExpression extends FunctionBase {
11283
10857
  this.scope = new ReturnValueScope(parentScope, false);
11284
10858
  }
11285
10859
  hasEffects() {
10860
+ if (!this.deoptimized)
10861
+ this.applyDeoptimizations();
11286
10862
  return false;
11287
10863
  }
11288
10864
  hasEffectsOnInteractionAtPath(path, interaction, context) {
11289
- if (this.annotationNoSideEffects &&
11290
- path.length === 0 &&
11291
- interaction.type === INTERACTION_CALLED) {
11292
- return false;
11293
- }
11294
10865
  if (super.hasEffectsOnInteractionAtPath(path, interaction, context)) {
11295
10866
  return true;
11296
10867
  }
10868
+ if (this.annotationNoSideEffects) {
10869
+ return false;
10870
+ }
11297
10871
  if (interaction.type === INTERACTION_CALLED) {
11298
10872
  const { ignore, brokenFlow } = context;
11299
10873
  context.ignore = {
@@ -11323,15 +10897,6 @@ class ArrowFunctionExpression extends FunctionBase {
11323
10897
  }
11324
10898
  }
11325
10899
  }
11326
- includeNode(context) {
11327
- this.included = true;
11328
- this.body.includePath(UNKNOWN_PATH, context);
11329
- for (const parameter of this.params) {
11330
- if (!(parameter instanceof Identifier)) {
11331
- parameter.includePath(UNKNOWN_PATH, context);
11332
- }
11333
- }
11334
- }
11335
10900
  getObjectEntity() {
11336
10901
  if (this.objectEntity !== null) {
11337
10902
  return this.objectEntity;
@@ -11351,18 +10916,13 @@ class ObjectPattern extends NodeBase {
11351
10916
  }
11352
10917
  }
11353
10918
  }
11354
- declare(kind, destructuredInitPath, init) {
10919
+ declare(kind, init) {
11355
10920
  const variables = [];
11356
10921
  for (const property of this.properties) {
11357
- variables.push(...property.declare(kind, destructuredInitPath, init));
10922
+ variables.push(...property.declare(kind, init));
11358
10923
  }
11359
10924
  return variables;
11360
10925
  }
11361
- deoptimizeAssignment(destructuredInitPath, init) {
11362
- for (const property of this.properties) {
11363
- property.deoptimizeAssignment(destructuredInitPath, init);
11364
- }
11365
- }
11366
10926
  deoptimizePath(path) {
11367
10927
  if (path.length === 0) {
11368
10928
  for (const property of this.properties) {
@@ -11380,46 +10940,12 @@ class ObjectPattern extends NodeBase {
11380
10940
  }
11381
10941
  return false;
11382
10942
  }
11383
- hasEffectsWhenDestructuring(context, destructuredInitPath, init) {
11384
- for (const property of this.properties) {
11385
- if (property.hasEffectsWhenDestructuring(context, destructuredInitPath, init))
11386
- return true;
11387
- }
11388
- return false;
11389
- }
11390
- includeDestructuredIfNecessary(context, destructuredInitPath, init) {
11391
- let included = false;
11392
- for (const property of this.properties) {
11393
- included =
11394
- property.includeDestructuredIfNecessary(context, destructuredInitPath, init) || included;
11395
- }
11396
- return (this.included ||= included);
11397
- }
11398
10943
  markDeclarationReached() {
11399
10944
  for (const property of this.properties) {
11400
10945
  property.markDeclarationReached();
11401
10946
  }
11402
10947
  }
11403
- render(code, options) {
11404
- if (this.properties.length > 0) {
11405
- const separatedNodes = getCommaSeparatedNodesWithBoundaries(this.properties, code, this.start + 1, this.end - 1);
11406
- let lastSeparatorPos = null;
11407
- for (const { node, separator, start, end } of separatedNodes) {
11408
- if (!node.included) {
11409
- treeshakeNode(node, code, start, end);
11410
- continue;
11411
- }
11412
- lastSeparatorPos = separator;
11413
- node.render(code, options);
11414
- }
11415
- if (lastSeparatorPos) {
11416
- code.remove(lastSeparatorPos, this.end - 1);
11417
- }
11418
- }
11419
- }
11420
10948
  }
11421
- ObjectPattern.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
11422
- ObjectPattern.prototype.applyDeoptimizations = doNotDeoptimize;
11423
10949
 
11424
10950
  class AssignmentExpression extends NodeBase {
11425
10951
  hasEffects(context) {
@@ -11428,9 +10954,7 @@ class AssignmentExpression extends NodeBase {
11428
10954
  this.applyDeoptimizations();
11429
10955
  // MemberExpressions do not access the property before assignments if the
11430
10956
  // operator is '='.
11431
- return (right.hasEffects(context) ||
11432
- left.hasEffectsAsAssignmentTarget(context, operator !== '=') ||
11433
- this.left.hasEffectsWhenDestructuring?.(context, EMPTY_PATH, right));
10957
+ return (right.hasEffects(context) || left.hasEffectsAsAssignmentTarget(context, operator !== '='));
11434
10958
  }
11435
10959
  hasEffectsOnInteractionAtPath(path, interaction, context) {
11436
10960
  return this.right.hasEffectsOnInteractionAtPath(path, interaction, context);
@@ -11439,24 +10963,15 @@ class AssignmentExpression extends NodeBase {
11439
10963
  const { deoptimized, left, right, operator } = this;
11440
10964
  if (!deoptimized)
11441
10965
  this.applyDeoptimizations();
11442
- if (!this.included)
11443
- this.includeNode(context);
11444
- const hasEffectsContext = createHasEffectsContext();
10966
+ this.included = true;
11445
10967
  if (includeChildrenRecursively ||
11446
10968
  operator !== '=' ||
11447
10969
  left.included ||
11448
- left.hasEffectsAsAssignmentTarget(hasEffectsContext, false) ||
11449
- left.hasEffectsWhenDestructuring?.(hasEffectsContext, EMPTY_PATH, right)) {
10970
+ left.hasEffectsAsAssignmentTarget(createHasEffectsContext(), false)) {
11450
10971
  left.includeAsAssignmentTarget(context, includeChildrenRecursively, operator !== '=');
11451
10972
  }
11452
10973
  right.include(context, includeChildrenRecursively);
11453
10974
  }
11454
- includeNode(context) {
11455
- this.included = true;
11456
- if (!this.deoptimized)
11457
- this.applyDeoptimizations();
11458
- this.right.includePath(UNKNOWN_PATH, context);
11459
- }
11460
10975
  initialise() {
11461
10976
  super.initialise();
11462
10977
  if (this.left instanceof Identifier) {
@@ -11517,7 +11032,8 @@ class AssignmentExpression extends NodeBase {
11517
11032
  }
11518
11033
  applyDeoptimizations() {
11519
11034
  this.deoptimized = true;
11520
- this.left.deoptimizeAssignment(EMPTY_PATH, this.right);
11035
+ this.left.deoptimizePath(EMPTY_PATH);
11036
+ this.right.deoptimizePath(UNKNOWN_PATH);
11521
11037
  this.scope.context.requestTreeshakingPass();
11522
11038
  }
11523
11039
  }
@@ -11526,42 +11042,16 @@ class AssignmentPattern extends NodeBase {
11526
11042
  addExportedVariables(variables, exportNamesByVariable) {
11527
11043
  this.left.addExportedVariables(variables, exportNamesByVariable);
11528
11044
  }
11529
- declare(kind, destructuredInitPath, init) {
11530
- return this.left.declare(kind, destructuredInitPath, init);
11531
- }
11532
- deoptimizeAssignment(destructuredInitPath, init) {
11533
- this.left.deoptimizeAssignment(destructuredInitPath, init);
11045
+ declare(kind, init) {
11046
+ return this.left.declare(kind, init);
11534
11047
  }
11535
11048
  deoptimizePath(path) {
11536
11049
  if (path.length === 0) {
11537
11050
  this.left.deoptimizePath(path);
11538
- }
11539
- }
11540
- hasEffectsOnInteractionAtPath(path, interaction, context) {
11541
- return (path.length > 0 || this.left.hasEffectsOnInteractionAtPath(EMPTY_PATH, interaction, context));
11542
- }
11543
- hasEffectsWhenDestructuring(context, destructuredInitPath, init) {
11544
- return this.left.hasEffectsWhenDestructuring(context, destructuredInitPath, init);
11545
- }
11546
- includeDestructuredIfNecessary(context, destructuredInitPath, init) {
11547
- let included = this.left.includeDestructuredIfNecessary(context, destructuredInitPath, init) ||
11548
- this.included;
11549
- if ((included ||= this.right.shouldBeIncluded(context))) {
11550
- this.right.include(context, false);
11551
- if (!this.left.included) {
11552
- this.left.included = true;
11553
- // Unfortunately, we need to include the left side again now, so that
11554
- // any declared variables are properly included.
11555
- this.left.includeDestructuredIfNecessary(context, destructuredInitPath, init);
11556
- }
11557
- }
11558
- return (this.included = included);
11559
- }
11560
- includeNode(context) {
11561
- this.included = true;
11562
- if (!this.deoptimized)
11563
- this.applyDeoptimizations();
11564
- this.right.includePath(UNKNOWN_PATH, context);
11051
+ }
11052
+ }
11053
+ hasEffectsOnInteractionAtPath(path, interaction, context) {
11054
+ return (path.length > 0 || this.left.hasEffectsOnInteractionAtPath(EMPTY_PATH, interaction, context));
11565
11055
  }
11566
11056
  markDeclarationReached() {
11567
11057
  this.left.markDeclarationReached();
@@ -11585,34 +11075,22 @@ class AwaitExpression extends NodeBase {
11585
11075
  return true;
11586
11076
  }
11587
11077
  include(context, includeChildrenRecursively) {
11588
- if (!this.included)
11589
- this.includeNode(context);
11590
- this.argument.include(context, includeChildrenRecursively);
11591
- }
11592
- includeNode(context) {
11593
- this.included = true;
11594
11078
  if (!this.deoptimized)
11595
11079
  this.applyDeoptimizations();
11596
- checkTopLevelAwait: if (!this.scope.context.usesTopLevelAwait) {
11597
- let parent = this.parent;
11598
- do {
11599
- if (parent instanceof FunctionNode || parent instanceof ArrowFunctionExpression)
11600
- break checkTopLevelAwait;
11601
- } while ((parent = parent.parent));
11602
- this.scope.context.usesTopLevelAwait = true;
11080
+ if (!this.included) {
11081
+ this.included = true;
11082
+ checkTopLevelAwait: if (!this.scope.context.usesTopLevelAwait) {
11083
+ let parent = this.parent;
11084
+ do {
11085
+ if (parent instanceof FunctionNode || parent instanceof ArrowFunctionExpression)
11086
+ break checkTopLevelAwait;
11087
+ } while ((parent = parent.parent));
11088
+ this.scope.context.usesTopLevelAwait = true;
11089
+ }
11603
11090
  }
11604
- // Thenables need to be included
11605
- this.argument.includePath(THEN_PATH, context);
11606
- }
11607
- includePath(path, context) {
11608
- if (!this.deoptimized)
11609
- this.applyDeoptimizations();
11610
- if (!this.included)
11611
- this.includeNode(context);
11612
- this.argument.includePath(path, context);
11091
+ this.argument.include(context, includeChildrenRecursively);
11613
11092
  }
11614
11093
  }
11615
- const THEN_PATH = ['then'];
11616
11094
 
11617
11095
  const binaryOperators = {
11618
11096
  '!=': (left, right) => left != right,
@@ -11668,12 +11146,6 @@ class BinaryExpression extends NodeBase {
11668
11146
  hasEffectsOnInteractionAtPath(path, { type }) {
11669
11147
  return type !== INTERACTION_ACCESSED || path.length > 1;
11670
11148
  }
11671
- includeNode(context) {
11672
- this.included = true;
11673
- if (this.operator === 'in') {
11674
- this.right.includePath(UNKNOWN_PATH, context);
11675
- }
11676
- }
11677
11149
  removeAnnotations(code) {
11678
11150
  this.left.removeAnnotations(code);
11679
11151
  }
@@ -11682,7 +11154,6 @@ class BinaryExpression extends NodeBase {
11682
11154
  this.right.render(code, options);
11683
11155
  }
11684
11156
  }
11685
- BinaryExpression.prototype.applyDeoptimizations = doNotDeoptimize;
11686
11157
 
11687
11158
  class BreakStatement extends NodeBase {
11688
11159
  hasEffects(context) {
@@ -11702,7 +11173,7 @@ class BreakStatement extends NodeBase {
11702
11173
  include(context) {
11703
11174
  this.included = true;
11704
11175
  if (this.label) {
11705
- this.label.include(context);
11176
+ this.label.include();
11706
11177
  context.includedLabels.add(this.label.name);
11707
11178
  }
11708
11179
  else {
@@ -11711,8 +11182,6 @@ class BreakStatement extends NodeBase {
11711
11182
  context.brokenFlow = true;
11712
11183
  }
11713
11184
  }
11714
- BreakStatement.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
11715
- BreakStatement.prototype.applyDeoptimizations = doNotDeoptimize;
11716
11185
 
11717
11186
  function renderCallArguments(code, options, node) {
11718
11187
  if (node.arguments.length > 0) {
@@ -11899,14 +11368,10 @@ class CallExpression extends CallExpressionBase {
11899
11368
  this.callee.hasEffectsOnInteractionAtPath(EMPTY_PATH, this.interaction, context)));
11900
11369
  }
11901
11370
  include(context, includeChildrenRecursively) {
11902
- if (!this.included)
11903
- this.includeNode(context);
11371
+ if (!this.deoptimized)
11372
+ this.applyDeoptimizations();
11904
11373
  if (includeChildrenRecursively) {
11905
- this.callee.include(context, true);
11906
- for (const argument of this.arguments) {
11907
- argument.includePath(UNKNOWN_PATH, context);
11908
- argument.include(context, true);
11909
- }
11374
+ super.include(context, includeChildrenRecursively);
11910
11375
  if (includeChildrenRecursively === INCLUDE_PARAMETERS &&
11911
11376
  this.callee instanceof Identifier &&
11912
11377
  this.callee.variable) {
@@ -11914,24 +11379,10 @@ class CallExpression extends CallExpressionBase {
11914
11379
  }
11915
11380
  }
11916
11381
  else {
11917
- // If the callee is a member expression and does not have a variable, its
11918
- // object will already be included via the first argument of the
11919
- // interaction in includeCallArguments. Including it again can lead to
11920
- // severe performance problems.
11921
- if (this.callee instanceof MemberExpression && !this.callee.variable) {
11922
- this.callee.property.include(context, false);
11923
- }
11924
- else {
11925
- this.callee.include(context, false);
11926
- }
11927
- this.callee.includeCallArguments(context, this.interaction);
11382
+ this.included = true;
11383
+ this.callee.include(context, false);
11928
11384
  }
11929
- }
11930
- includeNode(context) {
11931
- this.included = true;
11932
- if (!this.deoptimized)
11933
- this.applyDeoptimizations();
11934
- this.callee.includePath(UNKNOWN_PATH, context);
11385
+ this.callee.includeCallArguments(context, this.arguments);
11935
11386
  }
11936
11387
  initialise() {
11937
11388
  super.initialise();
@@ -11970,14 +11421,13 @@ class CatchClause extends NodeBase {
11970
11421
  this.type = type;
11971
11422
  if (param) {
11972
11423
  this.param = new (this.scope.context.getNodeConstructor(param.type))(this, this.scope).parseNode(param);
11973
- this.param.declare('parameter', EMPTY_PATH, UNKNOWN_EXPRESSION);
11424
+ this.param.declare('parameter', UNKNOWN_EXPRESSION);
11974
11425
  }
11975
11426
  this.body = new BlockStatement(this, this.scope.bodyScope).parseNode(body);
11976
11427
  return super.parseNode(esTreeNode);
11977
11428
  }
11978
11429
  }
11979
11430
  CatchClause.prototype.preventChildBlockScope = true;
11980
- CatchClause.prototype.includeNode = onlyIncludeSelf;
11981
11431
 
11982
11432
  class ChainExpression extends NodeBase {
11983
11433
  // deoptimizations are not relevant as we are not caching values
@@ -11989,22 +11439,17 @@ class ChainExpression extends NodeBase {
11989
11439
  hasEffects(context) {
11990
11440
  return this.expression.hasEffectsAsChainElement(context) === true;
11991
11441
  }
11992
- includePath(path, context) {
11993
- this.included = true;
11994
- this.expression.includePath(path, context);
11995
- }
11996
11442
  removeAnnotations(code) {
11997
11443
  this.expression.removeAnnotations(code);
11998
11444
  }
11445
+ applyDeoptimizations() { }
11999
11446
  }
12000
- ChainExpression.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
12001
- ChainExpression.prototype.applyDeoptimizations = doNotDeoptimize;
12002
11447
 
12003
11448
  class ClassBodyScope extends ChildScope {
12004
11449
  constructor(parent, classNode) {
12005
11450
  const { context } = parent;
12006
11451
  super(parent, context);
12007
- this.variables.set('this', (this.thisVariable = new LocalVariable('this', null, classNode, EMPTY_PATH, context, 'other')));
11452
+ this.variables.set('this', (this.thisVariable = new LocalVariable('this', null, classNode, context, 'other')));
12008
11453
  this.instanceScope = new ChildScope(this, context);
12009
11454
  this.instanceScope.variables.set('this', new ThisVariable(context));
12010
11455
  }
@@ -12019,7 +11464,7 @@ class ClassBody extends NodeBase {
12019
11464
  }
12020
11465
  include(context, includeChildrenRecursively) {
12021
11466
  this.included = true;
12022
- this.scope.context.includeVariableInModule(this.scope.thisVariable, UNKNOWN_PATH, context);
11467
+ this.scope.context.includeVariableInModule(this.scope.thisVariable);
12023
11468
  for (const definition of this.body) {
12024
11469
  definition.include(context, includeChildrenRecursively);
12025
11470
  }
@@ -12032,9 +11477,8 @@ class ClassBody extends NodeBase {
12032
11477
  }
12033
11478
  return super.parseNode(esTreeNode);
12034
11479
  }
11480
+ applyDeoptimizations() { }
12035
11481
  }
12036
- ClassBody.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
12037
- ClassBody.prototype.applyDeoptimizations = doNotDeoptimize;
12038
11482
 
12039
11483
  class ClassExpression extends ClassNode {
12040
11484
  render(code, options, { renderedSurroundingElement } = BLANK) {
@@ -12105,9 +11549,6 @@ class ConditionalExpression extends NodeBase {
12105
11549
  const unusedBranch = this.usedBranch === this.consequent ? this.alternate : this.consequent;
12106
11550
  this.usedBranch = null;
12107
11551
  unusedBranch.deoptimizePath(UNKNOWN_PATH);
12108
- if (this.included) {
12109
- unusedBranch.includePath(UNKNOWN_PATH, createInclusionContext());
12110
- }
12111
11552
  const { expressionsToBeDeoptimized } = this;
12112
11553
  this.expressionsToBeDeoptimized = EMPTY_ARRAY;
12113
11554
  for (const expression of expressionsToBeDeoptimized) {
@@ -12165,7 +11606,7 @@ class ConditionalExpression extends NodeBase {
12165
11606
  include(context, includeChildrenRecursively) {
12166
11607
  this.included = true;
12167
11608
  const usedBranch = this.getUsedBranch();
12168
- if (usedBranch === null || includeChildrenRecursively || this.test.shouldBeIncluded(context)) {
11609
+ if (includeChildrenRecursively || this.test.shouldBeIncluded(context) || usedBranch === null) {
12169
11610
  this.test.include(context, includeChildrenRecursively);
12170
11611
  this.consequent.include(context, includeChildrenRecursively);
12171
11612
  this.alternate.include(context, includeChildrenRecursively);
@@ -12174,38 +11615,27 @@ class ConditionalExpression extends NodeBase {
12174
11615
  usedBranch.include(context, includeChildrenRecursively);
12175
11616
  }
12176
11617
  }
12177
- includePath(path, context) {
12178
- this.included = true;
12179
- const usedBranch = this.getUsedBranch();
12180
- if (usedBranch === null || this.test.shouldBeIncluded(context)) {
12181
- this.consequent.includePath(path, context);
12182
- this.alternate.includePath(path, context);
12183
- }
12184
- else {
12185
- usedBranch.includePath(path, context);
12186
- }
12187
- }
12188
- includeCallArguments(context, interaction) {
11618
+ includeCallArguments(context, parameters) {
12189
11619
  const usedBranch = this.getUsedBranch();
12190
11620
  if (usedBranch) {
12191
- usedBranch.includeCallArguments(context, interaction);
11621
+ usedBranch.includeCallArguments(context, parameters);
12192
11622
  }
12193
11623
  else {
12194
- this.consequent.includeCallArguments(context, interaction);
12195
- this.alternate.includeCallArguments(context, interaction);
11624
+ this.consequent.includeCallArguments(context, parameters);
11625
+ this.alternate.includeCallArguments(context, parameters);
12196
11626
  }
12197
11627
  }
12198
11628
  removeAnnotations(code) {
12199
11629
  this.test.removeAnnotations(code);
12200
11630
  }
12201
11631
  render(code, options, { isCalleeOfRenderedParent, preventASI, renderedParentType, renderedSurroundingElement } = BLANK) {
11632
+ const usedBranch = this.getUsedBranch();
12202
11633
  if (this.test.included) {
12203
11634
  this.test.render(code, options, { renderedSurroundingElement });
12204
11635
  this.consequent.render(code, options);
12205
11636
  this.alternate.render(code, options);
12206
11637
  }
12207
11638
  else {
12208
- const usedBranch = this.getUsedBranch();
12209
11639
  const colonPos = findFirstOccurrenceOutsideComment(code.original, ':', this.consequent.end);
12210
11640
  const inclusionStart = findNonWhiteSpace(code.original, (this.consequent.included
12211
11641
  ? findFirstOccurrenceOutsideComment(code.original, '?', this.test.end)
@@ -12237,8 +11667,6 @@ class ConditionalExpression extends NodeBase {
12237
11667
  : (this.usedBranch = testValue ? this.consequent : this.alternate);
12238
11668
  }
12239
11669
  }
12240
- ConditionalExpression.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
12241
- ConditionalExpression.prototype.applyDeoptimizations = doNotDeoptimize;
12242
11670
 
12243
11671
  class ContinueStatement extends NodeBase {
12244
11672
  hasEffects(context) {
@@ -12258,7 +11686,7 @@ class ContinueStatement extends NodeBase {
12258
11686
  include(context) {
12259
11687
  this.included = true;
12260
11688
  if (this.label) {
12261
- this.label.include(context);
11689
+ this.label.include();
12262
11690
  context.includedLabels.add(this.label.name);
12263
11691
  }
12264
11692
  else {
@@ -12267,15 +11695,12 @@ class ContinueStatement extends NodeBase {
12267
11695
  context.brokenFlow = true;
12268
11696
  }
12269
11697
  }
12270
- ContinueStatement.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
12271
- ContinueStatement.prototype.applyDeoptimizations = doNotDeoptimize;
12272
11698
 
12273
11699
  class DebuggerStatement extends NodeBase {
12274
11700
  hasEffects() {
12275
11701
  return true;
12276
11702
  }
12277
11703
  }
12278
- DebuggerStatement.prototype.includeNode = onlyIncludeSelf;
12279
11704
 
12280
11705
  class Decorator extends NodeBase {
12281
11706
  hasEffects(context) {
@@ -12283,7 +11708,6 @@ class Decorator extends NodeBase {
12283
11708
  this.expression.hasEffectsOnInteractionAtPath(EMPTY_PATH, NODE_INTERACTION_UNKNOWN_CALL, context));
12284
11709
  }
12285
11710
  }
12286
- Decorator.prototype.includeNode = onlyIncludeSelf;
12287
11711
 
12288
11712
  function hasLoopBodyEffects(context, body) {
12289
11713
  const { brokenFlow, hasBreak, hasContinue, ignore } = context;
@@ -12323,15 +11747,12 @@ class DoWhileStatement extends NodeBase {
12323
11747
  includeLoopBody(context, this.body, includeChildrenRecursively);
12324
11748
  }
12325
11749
  }
12326
- DoWhileStatement.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
12327
- DoWhileStatement.prototype.applyDeoptimizations = doNotDeoptimize;
12328
11750
 
12329
11751
  class EmptyStatement extends NodeBase {
12330
11752
  hasEffects() {
12331
11753
  return false;
12332
11754
  }
12333
11755
  }
12334
- EmptyStatement.prototype.includeNode = onlyIncludeSelf;
12335
11756
 
12336
11757
  class ExportAllDeclaration extends NodeBase {
12337
11758
  hasEffects() {
@@ -12344,10 +11765,9 @@ class ExportAllDeclaration extends NodeBase {
12344
11765
  render(code, _options, nodeRenderOptions) {
12345
11766
  code.remove(nodeRenderOptions.start, nodeRenderOptions.end);
12346
11767
  }
11768
+ applyDeoptimizations() { }
12347
11769
  }
12348
11770
  ExportAllDeclaration.prototype.needsBoundaries = true;
12349
- ExportAllDeclaration.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
12350
- ExportAllDeclaration.prototype.applyDeoptimizations = doNotDeoptimize;
12351
11771
 
12352
11772
  class ExportNamedDeclaration extends NodeBase {
12353
11773
  bind() {
@@ -12374,15 +11794,13 @@ class ExportNamedDeclaration extends NodeBase {
12374
11794
  this.declaration.render(code, options, { end, start });
12375
11795
  }
12376
11796
  }
11797
+ applyDeoptimizations() { }
12377
11798
  }
12378
11799
  ExportNamedDeclaration.prototype.needsBoundaries = true;
12379
- ExportNamedDeclaration.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
12380
- ExportNamedDeclaration.prototype.applyDeoptimizations = doNotDeoptimize;
12381
11800
 
12382
11801
  class ExportSpecifier extends NodeBase {
11802
+ applyDeoptimizations() { }
12383
11803
  }
12384
- ExportSpecifier.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
12385
- ExportSpecifier.prototype.applyDeoptimizations = doNotDeoptimize;
12386
11804
 
12387
11805
  class ForInStatement extends NodeBase {
12388
11806
  createScope(parentScope) {
@@ -12400,18 +11818,11 @@ class ForInStatement extends NodeBase {
12400
11818
  const { body, deoptimized, left, right } = this;
12401
11819
  if (!deoptimized)
12402
11820
  this.applyDeoptimizations();
12403
- if (!this.included)
12404
- this.includeNode(context);
11821
+ this.included = true;
12405
11822
  left.includeAsAssignmentTarget(context, includeChildrenRecursively || true, false);
12406
11823
  right.include(context, includeChildrenRecursively);
12407
11824
  includeLoopBody(context, body, includeChildrenRecursively);
12408
11825
  }
12409
- includeNode(context) {
12410
- this.included = true;
12411
- if (!this.deoptimized)
12412
- this.applyDeoptimizations();
12413
- this.right.includePath(UNKNOWN_PATH, context);
12414
- }
12415
11826
  initialise() {
12416
11827
  super.initialise();
12417
11828
  this.left.setAssignedValue(UNKNOWN_EXPRESSION);
@@ -12452,18 +11863,11 @@ class ForOfStatement extends NodeBase {
12452
11863
  const { body, deoptimized, left, right } = this;
12453
11864
  if (!deoptimized)
12454
11865
  this.applyDeoptimizations();
12455
- if (!this.included)
12456
- this.includeNode(context);
11866
+ this.included = true;
12457
11867
  left.includeAsAssignmentTarget(context, includeChildrenRecursively || true, false);
12458
11868
  right.include(context, includeChildrenRecursively);
12459
11869
  includeLoopBody(context, body, includeChildrenRecursively);
12460
11870
  }
12461
- includeNode(context) {
12462
- this.included = true;
12463
- if (!this.deoptimized)
12464
- this.applyDeoptimizations();
12465
- this.right.includePath(UNKNOWN_PATH, context);
12466
- }
12467
11871
  initialise() {
12468
11872
  super.initialise();
12469
11873
  this.left.setAssignedValue(UNKNOWN_EXPRESSION);
@@ -12499,9 +11903,7 @@ class ForStatement extends NodeBase {
12499
11903
  }
12500
11904
  include(context, includeChildrenRecursively) {
12501
11905
  this.included = true;
12502
- this.init?.include(context, includeChildrenRecursively, {
12503
- asSingleStatement: true
12504
- });
11906
+ this.init?.include(context, includeChildrenRecursively, { asSingleStatement: true });
12505
11907
  this.test?.include(context, includeChildrenRecursively);
12506
11908
  this.update?.include(context, includeChildrenRecursively);
12507
11909
  includeLoopBody(context, this.body, includeChildrenRecursively);
@@ -12513,8 +11915,6 @@ class ForStatement extends NodeBase {
12513
11915
  this.body.render(code, options);
12514
11916
  }
12515
11917
  }
12516
- ForStatement.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
12517
- ForStatement.prototype.applyDeoptimizations = doNotDeoptimize;
12518
11918
 
12519
11919
  class FunctionExpression extends FunctionNode {
12520
11920
  createScope(parentScope) {
@@ -12546,9 +11946,9 @@ class TrackingScope extends BlockScope {
12546
11946
  super(...arguments);
12547
11947
  this.hoistedDeclarations = [];
12548
11948
  }
12549
- addDeclaration(identifier, context, init, destructuredInitPath, kind) {
11949
+ addDeclaration(identifier, context, init, kind) {
12550
11950
  this.hoistedDeclarations.push(identifier);
12551
- return super.addDeclaration(identifier, context, init, destructuredInitPath, kind);
11951
+ return super.addDeclaration(identifier, context, init, kind);
12552
11952
  }
12553
11953
  }
12554
11954
 
@@ -12647,6 +12047,7 @@ class IfStatement extends NodeBase {
12647
12047
  }
12648
12048
  this.renderHoistedDeclarations(hoistedDeclarations, code, getPropertyAccess);
12649
12049
  }
12050
+ applyDeoptimizations() { }
12650
12051
  getTestValue() {
12651
12052
  if (this.testValue === unset) {
12652
12053
  return (this.testValue = tryCastLiteralValueToBoolean(this.test.getLiteralValueAtPath(EMPTY_PATH, SHARED_RECURSION_TRACKER, this)));
@@ -12715,8 +12116,6 @@ class IfStatement extends NodeBase {
12715
12116
  return false;
12716
12117
  }
12717
12118
  }
12718
- IfStatement.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
12719
- IfStatement.prototype.applyDeoptimizations = doNotDeoptimize;
12720
12119
 
12721
12120
  class ImportAttribute extends NodeBase {
12722
12121
  }
@@ -12734,15 +12133,13 @@ class ImportDeclaration extends NodeBase {
12734
12133
  render(code, _options, nodeRenderOptions) {
12735
12134
  code.remove(nodeRenderOptions.start, nodeRenderOptions.end);
12736
12135
  }
12136
+ applyDeoptimizations() { }
12737
12137
  }
12738
12138
  ImportDeclaration.prototype.needsBoundaries = true;
12739
- ImportDeclaration.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
12740
- ImportDeclaration.prototype.applyDeoptimizations = doNotDeoptimize;
12741
12139
 
12742
12140
  class ImportDefaultSpecifier extends NodeBase {
12141
+ applyDeoptimizations() { }
12743
12142
  }
12744
- ImportDefaultSpecifier.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
12745
- ImportDefaultSpecifier.prototype.applyDeoptimizations = doNotDeoptimize;
12746
12143
 
12747
12144
  function isReassignedExportsMember(variable, exportNamesByVariable) {
12748
12145
  return (variable.renderBaseName !== null && exportNamesByVariable.has(variable) && variable.isReassigned);
@@ -12751,33 +12148,28 @@ function isReassignedExportsMember(variable, exportNamesByVariable) {
12751
12148
  class VariableDeclarator extends NodeBase {
12752
12149
  declareDeclarator(kind, isUsingDeclaration) {
12753
12150
  this.isUsingDeclaration = isUsingDeclaration;
12754
- this.id.declare(kind, EMPTY_PATH, this.init || UNDEFINED_EXPRESSION);
12151
+ this.id.declare(kind, this.init || UNDEFINED_EXPRESSION);
12755
12152
  }
12756
12153
  deoptimizePath(path) {
12757
12154
  this.id.deoptimizePath(path);
12758
12155
  }
12759
12156
  hasEffects(context) {
12157
+ if (!this.deoptimized)
12158
+ this.applyDeoptimizations();
12760
12159
  const initEffect = this.init?.hasEffects(context);
12761
12160
  this.id.markDeclarationReached();
12762
- return (initEffect ||
12763
- this.isUsingDeclaration ||
12764
- this.id.hasEffects(context) ||
12765
- (this.scope.context.options.treeshake
12766
- .propertyReadSideEffects &&
12767
- this.id.hasEffectsWhenDestructuring(context, EMPTY_PATH, this.init || UNDEFINED_EXPRESSION)));
12161
+ return initEffect || this.id.hasEffects(context) || this.isUsingDeclaration;
12768
12162
  }
12769
12163
  include(context, includeChildrenRecursively) {
12770
- const { id, init } = this;
12771
- if (!this.included)
12772
- this.includeNode();
12164
+ const { deoptimized, id, init } = this;
12165
+ if (!deoptimized)
12166
+ this.applyDeoptimizations();
12167
+ this.included = true;
12773
12168
  init?.include(context, includeChildrenRecursively);
12774
12169
  id.markDeclarationReached();
12775
- if (includeChildrenRecursively) {
12170
+ if (includeChildrenRecursively || id.shouldBeIncluded(context)) {
12776
12171
  id.include(context, includeChildrenRecursively);
12777
12172
  }
12778
- else {
12779
- id.includeDestructuredIfNecessary(context, EMPTY_PATH, init || UNDEFINED_EXPRESSION);
12780
- }
12781
12173
  }
12782
12174
  removeAnnotations(code) {
12783
12175
  this.init?.removeAnnotations(code);
@@ -12807,8 +12199,8 @@ class VariableDeclarator extends NodeBase {
12807
12199
  code.appendLeft(end, `${_}=${_}void 0`);
12808
12200
  }
12809
12201
  }
12810
- includeNode() {
12811
- this.included = true;
12202
+ applyDeoptimizations() {
12203
+ this.deoptimized = true;
12812
12204
  const { id, init } = this;
12813
12205
  if (init && id instanceof Identifier && init instanceof ClassExpression && !init.id) {
12814
12206
  const { name, variable } = id;
@@ -12820,14 +12212,11 @@ class VariableDeclarator extends NodeBase {
12820
12212
  }
12821
12213
  }
12822
12214
  }
12823
- VariableDeclarator.prototype.applyDeoptimizations = doNotDeoptimize;
12824
12215
 
12825
12216
  class ImportExpression extends NodeBase {
12826
12217
  constructor() {
12827
12218
  super(...arguments);
12828
12219
  this.inlineNamespace = null;
12829
- this.hasUnknownAccessedKey = false;
12830
- this.accessedPropKey = new Set();
12831
12220
  this.attributes = null;
12832
12221
  this.mechanism = null;
12833
12222
  this.namespaceExportName = undefined;
@@ -12860,15 +12249,12 @@ class ImportExpression extends NodeBase {
12860
12249
  if (parent2 instanceof ExpressionStatement) {
12861
12250
  return EMPTY_ARRAY;
12862
12251
  }
12863
- // Case 1: const { foo } / module = await import('bar')
12252
+ // Case 1: const { foo } = await import('bar')
12864
12253
  if (parent2 instanceof VariableDeclarator) {
12865
12254
  const declaration = parent2.id;
12866
- if (declaration instanceof Identifier) {
12867
- return this.hasUnknownAccessedKey ? undefined : [...this.accessedPropKey];
12868
- }
12869
- if (declaration instanceof ObjectPattern) {
12870
- return getDeterministicObjectDestructure(declaration);
12871
- }
12255
+ return declaration instanceof ObjectPattern
12256
+ ? getDeterministicObjectDestructure(declaration)
12257
+ : undefined;
12872
12258
  }
12873
12259
  // Case 2: (await import('bar')).foo
12874
12260
  if (parent2 instanceof MemberExpression) {
@@ -12918,29 +12304,12 @@ class ImportExpression extends NodeBase {
12918
12304
  return true;
12919
12305
  }
12920
12306
  include(context, includeChildrenRecursively) {
12921
- if (!this.included)
12922
- this.includeNode();
12923
- this.source.include(context, includeChildrenRecursively);
12924
- }
12925
- includeNode() {
12926
- this.included = true;
12927
- this.scope.context.includeDynamicImport(this);
12928
- this.scope.addAccessedDynamicImport(this);
12929
- }
12930
- includePath(path) {
12931
- if (!this.included)
12932
- this.includeNode();
12933
- // Technically, this is not correct as dynamic imports return a Promise.
12934
- if (this.hasUnknownAccessedKey)
12935
- return;
12936
- if (path[0] === UnknownKey) {
12937
- this.hasUnknownAccessedKey = true;
12938
- }
12939
- else if (typeof path[0] === 'string') {
12940
- this.accessedPropKey.add(path[0]);
12307
+ if (!this.included) {
12308
+ this.included = true;
12309
+ this.scope.context.includeDynamicImport(this);
12310
+ this.scope.addAccessedDynamicImport(this);
12941
12311
  }
12942
- // Update included paths
12943
- this.scope.context.includeDynamicImport(this);
12312
+ this.source.include(context, includeChildrenRecursively);
12944
12313
  }
12945
12314
  initialise() {
12946
12315
  super.initialise();
@@ -12951,7 +12320,7 @@ class ImportExpression extends NodeBase {
12951
12320
  return super.parseNode(esTreeNode);
12952
12321
  }
12953
12322
  render(code, options) {
12954
- const { snippets: { _, getDirectReturnFunction, getObject, getPropertyAccess } } = options;
12323
+ const { snippets: { _, getDirectReturnFunction, getObject, getPropertyAccess }, importAttributesKey } = options;
12955
12324
  if (this.inlineNamespace) {
12956
12325
  const [left, right] = getDirectReturnFunction([], {
12957
12326
  functionReturn: true,
@@ -12984,7 +12353,7 @@ class ImportExpression extends NodeBase {
12984
12353
  code.overwrite(this.source.end, this.end - 1, '', { contentOnly: true });
12985
12354
  }
12986
12355
  if (this.attributes) {
12987
- code.appendLeft(this.end - 1, `,${_}${getObject([['assert', this.attributes]], {
12356
+ code.appendLeft(this.end - 1, `,${_}${getObject([[importAttributesKey, this.attributes]], {
12988
12357
  lineBreakIndent: null
12989
12358
  })}`);
12990
12359
  }
@@ -13010,6 +12379,7 @@ class ImportExpression extends NodeBase {
13010
12379
  setInternalResolution(inlineNamespace) {
13011
12380
  this.inlineNamespace = inlineNamespace;
13012
12381
  }
12382
+ applyDeoptimizations() { }
13013
12383
  getDynamicImportMechanismAndHelper(resolution, exportMode, { compact, dynamicImportInCjs, format, generatedCode: { arrowFunctions }, interop }, { _, getDirectReturnFunction, getDirectReturnIifeLeft }, pluginDriver) {
13014
12384
  const mechanism = pluginDriver.hookFirstSync('renderDynamicImport', [
13015
12385
  {
@@ -13099,7 +12469,6 @@ class ImportExpression extends NodeBase {
13099
12469
  return { helper: null, mechanism: null };
13100
12470
  }
13101
12471
  }
13102
- ImportExpression.prototype.applyDeoptimizations = doNotDeoptimize;
13103
12472
  function getInteropHelper(resolution, exportMode, interop) {
13104
12473
  return exportMode === 'external'
13105
12474
  ? namespaceInteropHelpersByInteropType[interop(resolution instanceof ExternalModule ? resolution.id : null)]
@@ -13123,14 +12492,12 @@ function getDeterministicObjectDestructure(objectPattern) {
13123
12492
  }
13124
12493
 
13125
12494
  class ImportNamespaceSpecifier extends NodeBase {
12495
+ applyDeoptimizations() { }
13126
12496
  }
13127
- ImportNamespaceSpecifier.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
13128
- ImportNamespaceSpecifier.prototype.applyDeoptimizations = doNotDeoptimize;
13129
12497
 
13130
12498
  class ImportSpecifier extends NodeBase {
12499
+ applyDeoptimizations() { }
13131
12500
  }
13132
- ImportSpecifier.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
13133
- ImportSpecifier.prototype.applyDeoptimizations = doNotDeoptimize;
13134
12501
 
13135
12502
  class JSXIdentifier extends IdentifierBase {
13136
12503
  constructor() {
@@ -13147,29 +12514,6 @@ class JSXIdentifier extends IdentifierBase {
13147
12514
  this.isNativeElement = true;
13148
12515
  }
13149
12516
  }
13150
- include(context) {
13151
- if (!this.included)
13152
- this.includeNode(context);
13153
- }
13154
- includeNode(context) {
13155
- this.included = true;
13156
- if (!this.deoptimized)
13157
- this.applyDeoptimizations();
13158
- if (this.variable !== null) {
13159
- this.scope.context.includeVariableInModule(this.variable, EMPTY_PATH, context);
13160
- }
13161
- }
13162
- includePath(path, context) {
13163
- if (!this.included) {
13164
- this.included = true;
13165
- if (this.variable !== null) {
13166
- this.scope.context.includeVariableInModule(this.variable, path, context);
13167
- }
13168
- }
13169
- else if (path.length > 0) {
13170
- this.variable?.includePath(path, context);
13171
- }
13172
- }
13173
12517
  render(code, { snippets: { getPropertyAccess }, useOriginalName }) {
13174
12518
  if (this.variable) {
13175
12519
  const name = this.variable.getName(getPropertyAccess, useOriginalName);
@@ -13231,7 +12575,6 @@ class JSXAttribute extends NodeBase {
13231
12575
  }
13232
12576
  }
13233
12577
  }
13234
- JSXAttribute.prototype.includeNode = onlyIncludeSelf;
13235
12578
 
13236
12579
  class JSXClosingBase extends NodeBase {
13237
12580
  render(code, options) {
@@ -13244,7 +12587,6 @@ class JSXClosingBase extends NodeBase {
13244
12587
  }
13245
12588
  }
13246
12589
  }
13247
- JSXClosingBase.prototype.includeNode = onlyIncludeSelf;
13248
12590
 
13249
12591
  class JSXClosingElement extends JSXClosingBase {
13250
12592
  }
@@ -13265,15 +12607,8 @@ class JSXSpreadAttribute extends NodeBase {
13265
12607
 
13266
12608
  class JSXEmptyExpression extends NodeBase {
13267
12609
  }
13268
- JSXEmptyExpression.prototype.includeNode = onlyIncludeSelf;
13269
12610
 
13270
12611
  class JSXExpressionContainer extends NodeBase {
13271
- includeNode(context) {
13272
- this.included = true;
13273
- if (!this.deoptimized)
13274
- this.applyDeoptimizations();
13275
- this.expression.includePath(UNKNOWN_PATH, context);
13276
- }
13277
12612
  render(code, options) {
13278
12613
  const { mode } = this.scope.context.options.jsx;
13279
12614
  if (mode !== 'preserve') {
@@ -13294,7 +12629,7 @@ function getRenderedJsxChildren(children) {
13294
12629
  return renderedChildren;
13295
12630
  }
13296
12631
 
13297
- function getAndIncludeFactoryVariable(factory, preserve, importSource, node, context) {
12632
+ function getAndIncludeFactoryVariable(factory, preserve, importSource, node) {
13298
12633
  const [baseName, nestedName] = factory.split('.');
13299
12634
  let factoryVariable;
13300
12635
  if (importSource) {
@@ -13302,7 +12637,7 @@ function getAndIncludeFactoryVariable(factory, preserve, importSource, node, con
13302
12637
  if (preserve) {
13303
12638
  // This pretends we are accessing an included global variable of the same name
13304
12639
  const globalVariable = node.scope.findGlobal(baseName);
13305
- globalVariable.includePath(UNKNOWN_PATH, context);
12640
+ globalVariable.include();
13306
12641
  // This excludes this variable from renaming
13307
12642
  factoryVariable.globalName = baseName;
13308
12643
  }
@@ -13310,7 +12645,7 @@ function getAndIncludeFactoryVariable(factory, preserve, importSource, node, con
13310
12645
  else {
13311
12646
  factoryVariable = node.scope.findGlobal(baseName);
13312
12647
  }
13313
- node.scope.context.includeVariableInModule(factoryVariable, UNKNOWN_PATH, context);
12648
+ node.scope.context.includeVariableInModule(factoryVariable);
13314
12649
  if (factoryVariable instanceof LocalVariable) {
13315
12650
  factoryVariable.consolidateInitializers();
13316
12651
  factoryVariable.addUsedPlace(node);
@@ -13333,20 +12668,16 @@ class JSXElementBase extends NodeBase {
13333
12668
  }
13334
12669
  }
13335
12670
  include(context, includeChildrenRecursively) {
13336
- if (!this.included)
13337
- this.includeNode(context);
13338
- for (const child of this.children) {
13339
- child.include(context, includeChildrenRecursively);
13340
- }
13341
- }
13342
- includeNode(context) {
13343
- this.included = true;
13344
- const { factory, importSource, mode } = this.jsxMode;
13345
- if (factory) {
13346
- this.factory = factory;
13347
- this.factoryVariable = getAndIncludeFactoryVariable(factory, mode === 'preserve', importSource, this, context);
12671
+ if (!this.included) {
12672
+ const { factory, importSource, mode } = this.jsxMode;
12673
+ if (factory) {
12674
+ this.factory = factory;
12675
+ this.factoryVariable = getAndIncludeFactoryVariable(factory, mode === 'preserve', importSource, this);
12676
+ }
13348
12677
  }
12678
+ super.include(context, includeChildrenRecursively);
13349
12679
  }
12680
+ applyDeoptimizations() { }
13350
12681
  getRenderingMode() {
13351
12682
  const jsx = this.scope.context.options.jsx;
13352
12683
  const { mode, factory, importSource } = jsx;
@@ -13384,14 +12715,8 @@ class JSXElementBase extends NodeBase {
13384
12715
  return { childrenEnd, firstChild, hasMultipleChildren };
13385
12716
  }
13386
12717
  }
13387
- JSXElementBase.prototype.applyDeoptimizations = doNotDeoptimize;
13388
12718
 
13389
12719
  class JSXElement extends JSXElementBase {
13390
- include(context, includeChildrenRecursively) {
13391
- super.include(context, includeChildrenRecursively);
13392
- this.openingElement.include(context, includeChildrenRecursively);
13393
- this.closingElement?.include(context, includeChildrenRecursively);
13394
- }
13395
12720
  render(code, options) {
13396
12721
  switch (this.jsxMode.mode) {
13397
12722
  case 'classic': {
@@ -13543,11 +12868,6 @@ class JSXElement extends JSXElementBase {
13543
12868
  }
13544
12869
 
13545
12870
  class JSXFragment extends JSXElementBase {
13546
- include(context, includeChildrenRecursively) {
13547
- super.include(context, includeChildrenRecursively);
13548
- this.openingFragment.include(context, includeChildrenRecursively);
13549
- this.closingFragment.include(context, includeChildrenRecursively);
13550
- }
13551
12871
  render(code, options) {
13552
12872
  switch (this.jsxMode.mode) {
13553
12873
  case 'classic': {
@@ -13597,22 +12917,10 @@ class JSXFragment extends JSXElementBase {
13597
12917
  }
13598
12918
 
13599
12919
  class JSXMemberExpression extends NodeBase {
13600
- includeNode(context) {
13601
- this.included = true;
13602
- if (!this.deoptimized)
13603
- this.applyDeoptimizations();
13604
- this.object.includePath([this.property.name], context);
13605
- }
13606
- includePath(path, context) {
13607
- if (!this.included)
13608
- this.includeNode(context);
13609
- this.object.includePath([this.property.name, ...path], context);
13610
- }
13611
12920
  }
13612
12921
 
13613
12922
  class JSXNamespacedName extends NodeBase {
13614
12923
  }
13615
- JSXNamespacedName.prototype.includeNode = onlyIncludeSelf;
13616
12924
 
13617
12925
  class JSXOpeningElement extends NodeBase {
13618
12926
  render(code, options, { jsxMode = this.scope.context.options.jsx.mode } = {}) {
@@ -13622,7 +12930,6 @@ class JSXOpeningElement extends NodeBase {
13622
12930
  }
13623
12931
  }
13624
12932
  }
13625
- JSXOpeningElement.prototype.includeNode = onlyIncludeSelf;
13626
12933
 
13627
12934
  class JSXOpeningFragment extends NodeBase {
13628
12935
  constructor() {
@@ -13630,22 +12937,22 @@ class JSXOpeningFragment extends NodeBase {
13630
12937
  this.fragment = null;
13631
12938
  this.fragmentVariable = null;
13632
12939
  }
13633
- includeNode(context) {
13634
- this.included = true;
13635
- if (!this.deoptimized)
13636
- this.applyDeoptimizations();
13637
- const jsx = this.scope.context.options.jsx;
13638
- if (jsx.mode === 'automatic') {
13639
- this.fragment = 'Fragment';
13640
- this.fragmentVariable = getAndIncludeFactoryVariable('Fragment', false, jsx.jsxImportSource, this, context);
13641
- }
13642
- else {
13643
- const { fragment, importSource, mode } = jsx;
13644
- if (fragment != null) {
13645
- this.fragment = fragment;
13646
- this.fragmentVariable = getAndIncludeFactoryVariable(fragment, mode === 'preserve', importSource, this, context);
12940
+ include(context, includeChildrenRecursively) {
12941
+ if (!this.included) {
12942
+ const jsx = this.scope.context.options.jsx;
12943
+ if (jsx.mode === 'automatic') {
12944
+ this.fragment = 'Fragment';
12945
+ this.fragmentVariable = getAndIncludeFactoryVariable('Fragment', false, jsx.jsxImportSource, this);
12946
+ }
12947
+ else {
12948
+ const { fragment, importSource, mode } = jsx;
12949
+ if (fragment != null) {
12950
+ this.fragment = fragment;
12951
+ this.fragmentVariable = getAndIncludeFactoryVariable(fragment, mode === 'preserve', importSource, this);
12952
+ }
13647
12953
  }
13648
12954
  }
12955
+ super.include(context, includeChildrenRecursively);
13649
12956
  }
13650
12957
  render(code, options) {
13651
12958
  const { mode } = this.scope.context.options.jsx;
@@ -13682,7 +12989,6 @@ class JSXText extends NodeBase {
13682
12989
  }
13683
12990
  }
13684
12991
  }
13685
- JSXText.prototype.includeNode = onlyIncludeSelf;
13686
12992
 
13687
12993
  class LabeledStatement extends NodeBase {
13688
12994
  hasEffects(context) {
@@ -13704,22 +13010,17 @@ class LabeledStatement extends NodeBase {
13704
13010
  return bodyHasEffects;
13705
13011
  }
13706
13012
  include(context, includeChildrenRecursively) {
13707
- if (!this.included)
13708
- this.includeNode(context);
13013
+ this.included = true;
13709
13014
  const { brokenFlow, includedLabels } = context;
13710
13015
  context.includedLabels = new Set();
13711
13016
  this.body.include(context, includeChildrenRecursively);
13712
13017
  if (includeChildrenRecursively || context.includedLabels.has(this.label.name)) {
13713
- this.label.include(context);
13018
+ this.label.include();
13714
13019
  context.includedLabels.delete(this.label.name);
13715
13020
  context.brokenFlow = brokenFlow;
13716
13021
  }
13717
13022
  context.includedLabels = new Set([...includedLabels, ...context.includedLabels]);
13718
13023
  }
13719
- includeNode(context) {
13720
- this.included = true;
13721
- this.body.includePath(UNKNOWN_PATH, context);
13722
- }
13723
13024
  render(code, options) {
13724
13025
  if (this.label.included) {
13725
13026
  this.label.render(code, options);
@@ -13730,7 +13031,6 @@ class LabeledStatement extends NodeBase {
13730
13031
  this.body.render(code, options);
13731
13032
  }
13732
13033
  }
13733
- LabeledStatement.prototype.applyDeoptimizations = doNotDeoptimize;
13734
13034
 
13735
13035
  class LogicalExpression extends NodeBase {
13736
13036
  constructor() {
@@ -13747,10 +13047,10 @@ class LogicalExpression extends NodeBase {
13747
13047
  this.flags = setFlag(this.flags, 65536 /* Flag.isBranchResolutionAnalysed */, value);
13748
13048
  }
13749
13049
  get hasDeoptimizedCache() {
13750
- return isFlagSet(this.flags, 33554432 /* Flag.hasDeoptimizedCache */);
13050
+ return isFlagSet(this.flags, 16777216 /* Flag.hasDeoptimizedCache */);
13751
13051
  }
13752
13052
  set hasDeoptimizedCache(value) {
13753
- this.flags = setFlag(this.flags, 33554432 /* Flag.hasDeoptimizedCache */, value);
13053
+ this.flags = setFlag(this.flags, 16777216 /* Flag.hasDeoptimizedCache */, value);
13754
13054
  }
13755
13055
  deoptimizeArgumentsOnInteractionAtPath(interaction, path, recursionTracker) {
13756
13056
  this.left.deoptimizeArgumentsOnInteractionAtPath(interaction, path, recursionTracker);
@@ -13764,10 +13064,6 @@ class LogicalExpression extends NodeBase {
13764
13064
  const unusedBranch = this.usedBranch === this.left ? this.right : this.left;
13765
13065
  this.usedBranch = null;
13766
13066
  unusedBranch.deoptimizePath(UNKNOWN_PATH);
13767
- if (this.included) {
13768
- // As we are not tracking inclusions, we just include everything
13769
- unusedBranch.includePath(UNKNOWN_PATH, createInclusionContext());
13770
- }
13771
13067
  }
13772
13068
  const { scope: { context }, expressionsToBeDeoptimized } = this;
13773
13069
  this.expressionsToBeDeoptimized = EMPTY_ARRAY;
@@ -13789,6 +13085,8 @@ class LogicalExpression extends NodeBase {
13789
13085
  }
13790
13086
  }
13791
13087
  getLiteralValueAtPath(path, recursionTracker, origin) {
13088
+ if (origin === this)
13089
+ return UnknownValue;
13792
13090
  const usedBranch = this.getUsedBranch();
13793
13091
  if (usedBranch) {
13794
13092
  this.expressionsToBeDeoptimized.push(origin);
@@ -13812,17 +13110,16 @@ class LogicalExpression extends NodeBase {
13812
13110
  }
13813
13111
  getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin) {
13814
13112
  const usedBranch = this.getUsedBranch();
13815
- if (usedBranch) {
13816
- this.expressionsToBeDeoptimized.push(origin);
13817
- return usedBranch.getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin);
13818
- }
13819
- return [
13820
- new MultiExpression([
13821
- this.left.getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin)[0],
13822
- this.right.getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin)[0]
13823
- ]),
13824
- false
13825
- ];
13113
+ if (!usedBranch)
13114
+ return [
13115
+ new MultiExpression([
13116
+ this.left.getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin)[0],
13117
+ this.right.getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin)[0]
13118
+ ]),
13119
+ false
13120
+ ];
13121
+ this.expressionsToBeDeoptimized.push(origin);
13122
+ return usedBranch.getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin);
13826
13123
  }
13827
13124
  hasEffects(context) {
13828
13125
  if (this.left.hasEffects(context)) {
@@ -13835,18 +13132,18 @@ class LogicalExpression extends NodeBase {
13835
13132
  }
13836
13133
  hasEffectsOnInteractionAtPath(path, interaction, context) {
13837
13134
  const usedBranch = this.getUsedBranch();
13838
- if (usedBranch) {
13839
- return usedBranch.hasEffectsOnInteractionAtPath(path, interaction, context);
13135
+ if (!usedBranch) {
13136
+ return (this.left.hasEffectsOnInteractionAtPath(path, interaction, context) ||
13137
+ this.right.hasEffectsOnInteractionAtPath(path, interaction, context));
13840
13138
  }
13841
- return (this.left.hasEffectsOnInteractionAtPath(path, interaction, context) ||
13842
- this.right.hasEffectsOnInteractionAtPath(path, interaction, context));
13139
+ return usedBranch.hasEffectsOnInteractionAtPath(path, interaction, context);
13843
13140
  }
13844
13141
  include(context, includeChildrenRecursively) {
13845
13142
  this.included = true;
13846
13143
  const usedBranch = this.getUsedBranch();
13847
13144
  if (includeChildrenRecursively ||
13848
- !usedBranch ||
13849
- (usedBranch === this.right && this.left.shouldBeIncluded(context))) {
13145
+ (usedBranch === this.right && this.left.shouldBeIncluded(context)) ||
13146
+ !usedBranch) {
13850
13147
  this.left.include(context, includeChildrenRecursively);
13851
13148
  this.right.include(context, includeChildrenRecursively);
13852
13149
  }
@@ -13854,17 +13151,6 @@ class LogicalExpression extends NodeBase {
13854
13151
  usedBranch.include(context, includeChildrenRecursively);
13855
13152
  }
13856
13153
  }
13857
- includePath(path, context) {
13858
- this.included = true;
13859
- const usedBranch = this.getUsedBranch();
13860
- if (!usedBranch || (usedBranch === this.right && this.left.shouldBeIncluded(context))) {
13861
- this.left.includePath(path, context);
13862
- this.right.includePath(path, context);
13863
- }
13864
- else {
13865
- usedBranch.includePath(path, context);
13866
- }
13867
- }
13868
13154
  removeAnnotations(code) {
13869
13155
  this.left.removeAnnotations(code);
13870
13156
  }
@@ -13917,8 +13203,6 @@ class LogicalExpression extends NodeBase {
13917
13203
  return this.usedBranch;
13918
13204
  }
13919
13205
  }
13920
- LogicalExpression.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
13921
- LogicalExpression.prototype.applyDeoptimizations = doNotDeoptimize;
13922
13206
 
13923
13207
  class NewExpression extends NodeBase {
13924
13208
  hasEffects(context) {
@@ -13938,21 +13222,16 @@ class NewExpression extends NodeBase {
13938
13222
  return path.length > 0 || type !== INTERACTION_ACCESSED;
13939
13223
  }
13940
13224
  include(context, includeChildrenRecursively) {
13225
+ if (!this.deoptimized)
13226
+ this.applyDeoptimizations();
13941
13227
  if (includeChildrenRecursively) {
13942
13228
  super.include(context, includeChildrenRecursively);
13943
13229
  }
13944
13230
  else {
13945
- if (!this.included)
13946
- this.includeNode(context);
13231
+ this.included = true;
13947
13232
  this.callee.include(context, false);
13948
13233
  }
13949
- this.callee.includeCallArguments(context, this.interaction);
13950
- }
13951
- includeNode(context) {
13952
- this.included = true;
13953
- if (!this.deoptimized)
13954
- this.applyDeoptimizations();
13955
- this.callee.includePath(UNKNOWN_PATH, context);
13234
+ this.callee.includeCallArguments(context, this.arguments);
13956
13235
  }
13957
13236
  initialise() {
13958
13237
  super.initialise();
@@ -13981,7 +13260,6 @@ class ObjectExpression extends NodeBase {
13981
13260
  constructor() {
13982
13261
  super(...arguments);
13983
13262
  this.objectEntity = null;
13984
- this.protoProp = null;
13985
13263
  }
13986
13264
  deoptimizeArgumentsOnInteractionAtPath(interaction, path, recursionTracker) {
13987
13265
  this.getObjectEntity().deoptimizeArgumentsOnInteractionAtPath(interaction, path, recursionTracker);
@@ -14001,43 +13279,15 @@ class ObjectExpression extends NodeBase {
14001
13279
  hasEffectsOnInteractionAtPath(path, interaction, context) {
14002
13280
  return this.getObjectEntity().hasEffectsOnInteractionAtPath(path, interaction, context);
14003
13281
  }
14004
- include(context, includeChildrenRecursively) {
14005
- if (!this.included)
14006
- this.includeNode(context);
14007
- this.getObjectEntity().include(context, includeChildrenRecursively);
14008
- this.protoProp?.include(context, includeChildrenRecursively);
14009
- }
14010
- includeNode(context) {
14011
- this.included = true;
14012
- this.protoProp?.includePath(UNKNOWN_PATH, context);
14013
- }
14014
- includePath(path, context) {
14015
- if (!this.included)
14016
- this.includeNode(context);
14017
- this.getObjectEntity().includePath(path, context);
14018
- }
14019
13282
  render(code, options, { renderedSurroundingElement } = BLANK) {
13283
+ super.render(code, options);
14020
13284
  if (renderedSurroundingElement === ExpressionStatement$1 ||
14021
13285
  renderedSurroundingElement === ArrowFunctionExpression$1) {
14022
13286
  code.appendRight(this.start, '(');
14023
13287
  code.prependLeft(this.end, ')');
14024
13288
  }
14025
- if (this.properties.length > 0) {
14026
- const separatedNodes = getCommaSeparatedNodesWithBoundaries(this.properties, code, this.start + 1, this.end - 1);
14027
- let lastSeparatorPos = null;
14028
- for (const { node, separator, start, end } of separatedNodes) {
14029
- if (!node.included) {
14030
- treeshakeNode(node, code, start, end);
14031
- continue;
14032
- }
14033
- lastSeparatorPos = separator;
14034
- node.render(code, options);
14035
- }
14036
- if (lastSeparatorPos) {
14037
- code.remove(lastSeparatorPos, this.end - 1);
14038
- }
14039
- }
14040
13289
  }
13290
+ applyDeoptimizations() { }
14041
13291
  getObjectEntity() {
14042
13292
  if (this.objectEntity !== null) {
14043
13293
  return this.objectEntity;
@@ -14066,7 +13316,6 @@ class ObjectExpression extends NodeBase {
14066
13316
  ? property.key.name
14067
13317
  : String(property.key.value);
14068
13318
  if (key === '__proto__' && property.kind === 'init') {
14069
- this.protoProp = property;
14070
13319
  prototype =
14071
13320
  property.value instanceof Literal && property.value.value === null
14072
13321
  ? null
@@ -14079,7 +13328,6 @@ class ObjectExpression extends NodeBase {
14079
13328
  return (this.objectEntity = new ObjectEntity(properties, prototype));
14080
13329
  }
14081
13330
  }
14082
- ObjectExpression.prototype.applyDeoptimizations = doNotDeoptimize;
14083
13331
 
14084
13332
  class PanicError extends NodeBase {
14085
13333
  initialise() {
@@ -14106,7 +13354,6 @@ class ParseError extends NodeBase {
14106
13354
 
14107
13355
  class PrivateIdentifier extends NodeBase {
14108
13356
  }
14109
- PrivateIdentifier.prototype.includeNode = onlyIncludeSelf;
14110
13357
 
14111
13358
  class Program extends NodeBase {
14112
13359
  constructor() {
@@ -14174,11 +13421,14 @@ class Program extends NodeBase {
14174
13421
  super.render(code, options);
14175
13422
  }
14176
13423
  }
13424
+ applyDeoptimizations() { }
14177
13425
  }
14178
- Program.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
14179
- Program.prototype.applyDeoptimizations = doNotDeoptimize;
14180
13426
 
14181
13427
  class Property extends MethodBase {
13428
+ constructor() {
13429
+ super(...arguments);
13430
+ this.declarationInit = null;
13431
+ }
14182
13432
  //declare method: boolean;
14183
13433
  get method() {
14184
13434
  return isFlagSet(this.flags, 262144 /* Flag.method */);
@@ -14193,41 +13443,17 @@ class Property extends MethodBase {
14193
13443
  set shorthand(value) {
14194
13444
  this.flags = setFlag(this.flags, 524288 /* Flag.shorthand */, value);
14195
13445
  }
14196
- declare(kind, destructuredInitPath, init) {
14197
- return this.value.declare(kind, this.getPathInProperty(destructuredInitPath), init);
14198
- }
14199
- deoptimizeAssignment(destructuredInitPath, init) {
14200
- this.value.deoptimizeAssignment?.(this.getPathInProperty(destructuredInitPath), init);
13446
+ declare(kind, init) {
13447
+ this.declarationInit = init;
13448
+ return this.value.declare(kind, UNKNOWN_EXPRESSION);
14201
13449
  }
14202
13450
  hasEffects(context) {
14203
- return this.key.hasEffects(context) || this.value.hasEffects(context);
14204
- }
14205
- hasEffectsWhenDestructuring(context, destructuredInitPath, init) {
14206
- return this.value.hasEffectsWhenDestructuring?.(context, this.getPathInProperty(destructuredInitPath), init);
14207
- }
14208
- includeDestructuredIfNecessary(context, destructuredInitPath, init) {
14209
- const path = this.getPathInProperty(destructuredInitPath);
14210
- let included = this.value.includeDestructuredIfNecessary(context, path, init) ||
14211
- this.included;
14212
- if ((included ||= this.key.hasEffects(createHasEffectsContext()))) {
14213
- this.key.include(context, false);
14214
- if (!this.value.included) {
14215
- this.value.included = true;
14216
- // Unfortunately, we need to include the value again now, so that any
14217
- // declared variables are properly included.
14218
- this.value.includeDestructuredIfNecessary(context, path, init);
14219
- }
14220
- }
14221
- return (this.included = included);
14222
- }
14223
- include(context, includeChildrenRecursively) {
14224
- this.included = true;
14225
- this.key.include(context, includeChildrenRecursively);
14226
- this.value.include(context, includeChildrenRecursively);
14227
- }
14228
- includePath(path, context) {
14229
- this.included = true;
14230
- this.value.includePath(path, context);
13451
+ if (!this.deoptimized)
13452
+ this.applyDeoptimizations();
13453
+ const propertyReadSideEffects = this.scope.context.options.treeshake.propertyReadSideEffects;
13454
+ return ((this.parent.type === 'ObjectPattern' && propertyReadSideEffects === 'always') ||
13455
+ this.key.hasEffects(context) ||
13456
+ this.value.hasEffects(context));
14231
13457
  }
14232
13458
  markDeclarationReached() {
14233
13459
  this.value.markDeclarationReached();
@@ -14238,20 +13464,14 @@ class Property extends MethodBase {
14238
13464
  }
14239
13465
  this.value.render(code, options, { isShorthandProperty: this.shorthand });
14240
13466
  }
14241
- getPathInProperty(destructuredInitPath) {
14242
- return destructuredInitPath.at(-1) === UnknownKey
14243
- ? destructuredInitPath
14244
- : // For now, we only consider static paths as we do not know how to
14245
- // deoptimize the path in the dynamic case.
14246
- this.computed
14247
- ? [...destructuredInitPath, UnknownKey]
14248
- : this.key instanceof Identifier
14249
- ? [...destructuredInitPath, this.key.name]
14250
- : [...destructuredInitPath, String(this.key.value)];
13467
+ applyDeoptimizations() {
13468
+ this.deoptimized = true;
13469
+ if (this.declarationInit !== null) {
13470
+ this.declarationInit.deoptimizePath([UnknownKey, UnknownKey]);
13471
+ this.scope.context.requestTreeshakingPass();
13472
+ }
14251
13473
  }
14252
13474
  }
14253
- Property.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
14254
- Property.prototype.applyDeoptimizations = doNotDeoptimize;
14255
13475
 
14256
13476
  class PropertyDefinition extends NodeBase {
14257
13477
  get computed() {
@@ -14284,15 +13504,8 @@ class PropertyDefinition extends NodeBase {
14284
13504
  hasEffectsOnInteractionAtPath(path, interaction, context) {
14285
13505
  return !this.value || this.value.hasEffectsOnInteractionAtPath(path, interaction, context);
14286
13506
  }
14287
- includeNode(context) {
14288
- this.included = true;
14289
- this.value?.includePath(UNKNOWN_PATH, context);
14290
- for (const decorator of this.decorators) {
14291
- decorator.includePath(UNKNOWN_PATH, context);
14292
- }
14293
- }
13507
+ applyDeoptimizations() { }
14294
13508
  }
14295
- PropertyDefinition.prototype.applyDeoptimizations = doNotDeoptimize;
14296
13509
 
14297
13510
  class ReturnStatement extends NodeBase {
14298
13511
  hasEffects(context) {
@@ -14302,15 +13515,10 @@ class ReturnStatement extends NodeBase {
14302
13515
  return false;
14303
13516
  }
14304
13517
  include(context, includeChildrenRecursively) {
14305
- if (!this.included)
14306
- this.includeNode(context);
13518
+ this.included = true;
14307
13519
  this.argument?.include(context, includeChildrenRecursively);
14308
13520
  context.brokenFlow = true;
14309
13521
  }
14310
- includeNode(context) {
14311
- this.included = true;
14312
- this.argument?.includePath(UNKNOWN_PATH, context);
14313
- }
14314
13522
  initialise() {
14315
13523
  super.initialise();
14316
13524
  this.scope.addReturnExpression(this.argument || UNKNOWN_EXPRESSION);
@@ -14324,7 +13532,6 @@ class ReturnStatement extends NodeBase {
14324
13532
  }
14325
13533
  }
14326
13534
  }
14327
- ReturnStatement.prototype.applyDeoptimizations = doNotDeoptimize;
14328
13535
 
14329
13536
  class SequenceExpression extends NodeBase {
14330
13537
  deoptimizeArgumentsOnInteractionAtPath(interaction, path, recursionTracker) {
@@ -14352,15 +13559,10 @@ class SequenceExpression extends NodeBase {
14352
13559
  for (const expression of this.expressions) {
14353
13560
  if (includeChildrenRecursively ||
14354
13561
  (expression === lastExpression && !(this.parent instanceof ExpressionStatement)) ||
14355
- expression.shouldBeIncluded(context)) {
13562
+ expression.shouldBeIncluded(context))
14356
13563
  expression.include(context, includeChildrenRecursively);
14357
- }
14358
13564
  }
14359
13565
  }
14360
- includePath(path, context) {
14361
- this.included = true;
14362
- this.expressions[this.expressions.length - 1].includePath(path, context);
14363
- }
14364
13566
  removeAnnotations(code) {
14365
13567
  this.expressions[0].removeAnnotations(code);
14366
13568
  }
@@ -14395,8 +13597,6 @@ class SequenceExpression extends NodeBase {
14395
13597
  }
14396
13598
  }
14397
13599
  }
14398
- SequenceExpression.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
14399
- SequenceExpression.prototype.applyDeoptimizations = doNotDeoptimize;
14400
13600
 
14401
13601
  class Super extends NodeBase {
14402
13602
  bind() {
@@ -14408,15 +13608,11 @@ class Super extends NodeBase {
14408
13608
  deoptimizePath(path) {
14409
13609
  this.variable.deoptimizePath(path);
14410
13610
  }
14411
- include(context) {
14412
- if (!this.included)
14413
- this.includeNode(context);
14414
- }
14415
- includeNode(context) {
14416
- this.included = true;
14417
- if (!this.deoptimized)
14418
- this.applyDeoptimizations();
14419
- this.scope.context.includeVariableInModule(this.variable, EMPTY_PATH, context);
13611
+ include() {
13612
+ if (!this.included) {
13613
+ this.included = true;
13614
+ this.scope.context.includeVariableInModule(this.variable);
13615
+ }
14420
13616
  }
14421
13617
  }
14422
13618
 
@@ -14457,8 +13653,6 @@ class SwitchCase extends NodeBase {
14457
13653
  }
14458
13654
  }
14459
13655
  SwitchCase.prototype.needsBoundaries = true;
14460
- SwitchCase.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
14461
- SwitchCase.prototype.applyDeoptimizations = doNotDeoptimize;
14462
13656
 
14463
13657
  class SwitchStatement extends NodeBase {
14464
13658
  createScope(parentScope) {
@@ -14541,8 +13735,6 @@ class SwitchStatement extends NodeBase {
14541
13735
  }
14542
13736
  }
14543
13737
  }
14544
- SwitchStatement.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
14545
- SwitchStatement.prototype.applyDeoptimizations = doNotDeoptimize;
14546
13738
 
14547
13739
  class TaggedTemplateExpression extends CallExpressionBase {
14548
13740
  bind() {
@@ -14566,8 +13758,8 @@ class TaggedTemplateExpression extends CallExpressionBase {
14566
13758
  this.tag.hasEffectsOnInteractionAtPath(EMPTY_PATH, this.interaction, context));
14567
13759
  }
14568
13760
  include(context, includeChildrenRecursively) {
14569
- if (!this.included)
14570
- this.includeNode(context);
13761
+ if (!this.deoptimized)
13762
+ this.applyDeoptimizations();
14571
13763
  if (includeChildrenRecursively) {
14572
13764
  super.include(context, includeChildrenRecursively);
14573
13765
  }
@@ -14576,7 +13768,7 @@ class TaggedTemplateExpression extends CallExpressionBase {
14576
13768
  this.tag.include(context, includeChildrenRecursively);
14577
13769
  this.quasi.include(context, includeChildrenRecursively);
14578
13770
  }
14579
- this.tag.includeCallArguments(context, this.interaction);
13771
+ this.tag.includeCallArguments(context, this.args);
14580
13772
  const [returnExpression] = this.getReturnExpression();
14581
13773
  if (!returnExpression.included) {
14582
13774
  returnExpression.include(context, false);
@@ -14611,7 +13803,6 @@ class TaggedTemplateExpression extends CallExpressionBase {
14611
13803
  return this.returnExpression;
14612
13804
  }
14613
13805
  }
14614
- TaggedTemplateExpression.prototype.includeNode = onlyIncludeSelf;
14615
13806
 
14616
13807
  class TemplateElement extends NodeBase {
14617
13808
  get tail() {
@@ -14625,13 +13816,15 @@ class TemplateElement extends NodeBase {
14625
13816
  hasEffects() {
14626
13817
  return false;
14627
13818
  }
13819
+ include() {
13820
+ this.included = true;
13821
+ }
14628
13822
  parseNode(esTreeNode) {
14629
13823
  this.value = esTreeNode.value;
14630
13824
  return super.parseNode(esTreeNode);
14631
13825
  }
14632
13826
  render() { }
14633
13827
  }
14634
- TemplateElement.prototype.includeNode = onlyIncludeSelf;
14635
13828
 
14636
13829
  class TemplateLiteral extends NodeBase {
14637
13830
  deoptimizeArgumentsOnInteractionAtPath() { }
@@ -14656,14 +13849,6 @@ class TemplateLiteral extends NodeBase {
14656
13849
  }
14657
13850
  return true;
14658
13851
  }
14659
- includeNode(context) {
14660
- this.included = true;
14661
- if (!this.deoptimized)
14662
- this.applyDeoptimizations();
14663
- for (const node of this.expressions) {
14664
- node.includePath(UNKNOWN_PATH, context);
14665
- }
14666
- }
14667
13852
  render(code, options) {
14668
13853
  code.indentExclusionRanges.push([this.start, this.end]);
14669
13854
  super.render(code, options);
@@ -14673,13 +13858,13 @@ class TemplateLiteral extends NodeBase {
14673
13858
  class ModuleScope extends ChildScope {
14674
13859
  constructor(parent, context) {
14675
13860
  super(parent, context);
14676
- this.variables.set('this', new LocalVariable('this', null, UNDEFINED_EXPRESSION, EMPTY_PATH, context, 'other'));
13861
+ this.variables.set('this', new LocalVariable('this', null, UNDEFINED_EXPRESSION, context, 'other'));
14677
13862
  }
14678
- addDeclaration(identifier, context, init, destructuredInitPath, kind) {
13863
+ addDeclaration(identifier, context, init, kind) {
14679
13864
  if (this.context.module.importDescriptions.has(identifier.name)) {
14680
13865
  context.error(logRedeclarationError(identifier.name), identifier.start);
14681
13866
  }
14682
- return super.addDeclaration(identifier, context, init, destructuredInitPath, kind);
13867
+ return super.addDeclaration(identifier, context, init, kind);
14683
13868
  }
14684
13869
  addExportDefaultDeclaration(name, exportDefaultDeclaration, context) {
14685
13870
  const variable = new ExportDefaultVariable(name, exportDefaultDeclaration, context);
@@ -14724,23 +13909,10 @@ class ThisExpression extends NodeBase {
14724
13909
  }
14725
13910
  return this.variable.hasEffectsOnInteractionAtPath(path, interaction, context);
14726
13911
  }
14727
- include(context) {
14728
- if (!this.included)
14729
- this.includeNode(context);
14730
- }
14731
- includeNode(context) {
14732
- this.included = true;
14733
- if (!this.deoptimized)
14734
- this.applyDeoptimizations();
14735
- this.scope.context.includeVariableInModule(this.variable, EMPTY_PATH, context);
14736
- }
14737
- includePath(path, context) {
13912
+ include() {
14738
13913
  if (!this.included) {
14739
13914
  this.included = true;
14740
- this.scope.context.includeVariableInModule(this.variable, path, context);
14741
- }
14742
- else if (path.length > 0) {
14743
- this.variable.includePath(path, context);
13915
+ this.scope.context.includeVariableInModule(this.variable);
14744
13916
  }
14745
13917
  }
14746
13918
  initialise() {
@@ -14768,8 +13940,7 @@ class ThrowStatement extends NodeBase {
14768
13940
  return true;
14769
13941
  }
14770
13942
  include(context, includeChildrenRecursively) {
14771
- if (!this.included)
14772
- this.includeNode(context);
13943
+ this.included = true;
14773
13944
  this.argument.include(context, includeChildrenRecursively);
14774
13945
  context.brokenFlow = true;
14775
13946
  }
@@ -14780,7 +13951,6 @@ class ThrowStatement extends NodeBase {
14780
13951
  }
14781
13952
  }
14782
13953
  }
14783
- ThrowStatement.prototype.includeNode = onlyIncludeSelf;
14784
13954
 
14785
13955
  class TryStatement extends NodeBase {
14786
13956
  constructor() {
@@ -14817,8 +13987,6 @@ class TryStatement extends NodeBase {
14817
13987
  this.finalizer?.include(context, includeChildrenRecursively);
14818
13988
  }
14819
13989
  }
14820
- TryStatement.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
14821
- TryStatement.prototype.applyDeoptimizations = doNotDeoptimize;
14822
13990
 
14823
13991
  const unaryOperators = {
14824
13992
  '!': value => !value,
@@ -14848,8 +14016,17 @@ class UnaryExpression extends NodeBase {
14848
14016
  if (path.length > 0)
14849
14017
  return UnknownValue;
14850
14018
  const argumentValue = this.argument.getLiteralValueAtPath(EMPTY_PATH, recursionTracker, origin);
14851
- if (typeof argumentValue === 'symbol')
14019
+ if (typeof argumentValue === 'symbol') {
14020
+ if (this.operator === 'void')
14021
+ return undefined;
14022
+ if (this.operator === '!') {
14023
+ if (argumentValue === UnknownFalsyValue)
14024
+ return true;
14025
+ if (argumentValue === UnknownTruthyValue)
14026
+ return false;
14027
+ }
14852
14028
  return UnknownValue;
14029
+ }
14853
14030
  return unaryOperators[this.operator](argumentValue);
14854
14031
  }
14855
14032
  hasEffects(context) {
@@ -14925,7 +14102,6 @@ function getSimplifiedNumber(value) {
14925
14102
  const stringifiedValue = String(value).replace('+', '');
14926
14103
  return finalizedExp.length < stringifiedValue.length ? finalizedExp : stringifiedValue;
14927
14104
  }
14928
- UnaryExpression.prototype.includeNode = onlyIncludeSelf;
14929
14105
 
14930
14106
  class UpdateExpression extends NodeBase {
14931
14107
  hasEffects(context) {
@@ -14937,8 +14113,9 @@ class UpdateExpression extends NodeBase {
14937
14113
  return path.length > 1 || type !== INTERACTION_ACCESSED;
14938
14114
  }
14939
14115
  include(context, includeChildrenRecursively) {
14940
- if (!this.included)
14941
- this.includeNode(context);
14116
+ if (!this.deoptimized)
14117
+ this.applyDeoptimizations();
14118
+ this.included = true;
14942
14119
  this.argument.includeAsAssignmentTarget(context, includeChildrenRecursively, true);
14943
14120
  }
14944
14121
  initialise() {
@@ -14977,7 +14154,6 @@ class UpdateExpression extends NodeBase {
14977
14154
  this.scope.context.requestTreeshakingPass();
14978
14155
  }
14979
14156
  }
14980
- UpdateExpression.prototype.includeNode = onlyIncludeSelf;
14981
14157
 
14982
14158
  function areAllDeclarationsIncludedAndNotExported(declarations, exportNamesByVariable) {
14983
14159
  for (const declarator of declarations) {
@@ -15008,9 +14184,8 @@ class VariableDeclaration extends NodeBase {
15008
14184
  include(context, includeChildrenRecursively, { asSingleStatement } = BLANK) {
15009
14185
  this.included = true;
15010
14186
  for (const declarator of this.declarations) {
15011
- if (includeChildrenRecursively || declarator.shouldBeIncluded(context)) {
14187
+ if (includeChildrenRecursively || declarator.shouldBeIncluded(context))
15012
14188
  declarator.include(context, includeChildrenRecursively);
15013
- }
15014
14189
  const { id, init } = declarator;
15015
14190
  if (asSingleStatement) {
15016
14191
  id.include(context, includeChildrenRecursively);
@@ -15048,6 +14223,7 @@ class VariableDeclaration extends NodeBase {
15048
14223
  this.renderReplacedDeclarations(code, options);
15049
14224
  }
15050
14225
  }
14226
+ applyDeoptimizations() { }
15051
14227
  renderDeclarationEnd(code, separatorString, lastSeparatorPos, actualContentEnd, renderedContentEnd, systemPatternExports, options) {
15052
14228
  if (code.original.charCodeAt(this.end - 1) === 59 /*";"*/) {
15053
14229
  code.remove(this.end - 1, this.end);
@@ -15090,7 +14266,8 @@ class VariableDeclaration extends NodeBase {
15090
14266
  const singleSystemExport = gatherSystemExportsAndGetSingleExport(separatedNodes, options, aggregatedSystemExports);
15091
14267
  for (const { node, start, separator, contentEnd, end } of separatedNodes) {
15092
14268
  if (!node.included) {
15093
- treeshakeNode(node, code, start, end);
14269
+ code.remove(start, end);
14270
+ node.removeAnnotations(code);
15094
14271
  continue;
15095
14272
  }
15096
14273
  node.render(code, options);
@@ -15160,8 +14337,6 @@ function gatherSystemExportsAndGetSingleExport(separatedNodes, options, aggregat
15160
14337
  }
15161
14338
  return singleSystemExport;
15162
14339
  }
15163
- VariableDeclaration.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
15164
- VariableDeclaration.prototype.applyDeoptimizations = doNotDeoptimize;
15165
14340
 
15166
14341
  class WhileStatement extends NodeBase {
15167
14342
  hasEffects(context) {
@@ -15175,25 +14350,13 @@ class WhileStatement extends NodeBase {
15175
14350
  includeLoopBody(context, this.body, includeChildrenRecursively);
15176
14351
  }
15177
14352
  }
15178
- WhileStatement.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
15179
- WhileStatement.prototype.applyDeoptimizations = doNotDeoptimize;
15180
14353
 
15181
14354
  class YieldExpression extends NodeBase {
15182
- applyDeoptimizations() {
15183
- this.deoptimized = true;
15184
- this.argument?.deoptimizePath(UNKNOWN_PATH);
15185
- }
15186
14355
  hasEffects(context) {
15187
14356
  if (!this.deoptimized)
15188
14357
  this.applyDeoptimizations();
15189
14358
  return !(context.ignore.returnYield && !this.argument?.hasEffects(context));
15190
14359
  }
15191
- includeNode(context) {
15192
- this.included = true;
15193
- if (!this.deoptimized)
15194
- this.applyDeoptimizations();
15195
- this.argument?.includePath(UNKNOWN_PATH, context);
15196
- }
15197
14360
  render(code, options) {
15198
14361
  if (this.argument) {
15199
14362
  this.argument.render(code, options, { preventASI: true });
@@ -15427,7 +14590,7 @@ const bufferParsers = [
15427
14590
  const annotations = (node.annotations = convertAnnotations(buffer[position + 1], buffer));
15428
14591
  node.annotationNoSideEffects = annotations.some(comment => comment.type === 'noSideEffects');
15429
14592
  const parameters = (node.params = convertNodeList(node, scope, buffer[position + 2], buffer));
15430
- scope.addParameterVariables(parameters.map(parameter => parameter.declare('parameter', EMPTY_PATH, UNKNOWN_EXPRESSION)), parameters[parameters.length - 1] instanceof RestElement);
14593
+ scope.addParameterVariables(parameters.map(parameter => parameter.declare('parameter', UNKNOWN_EXPRESSION)), parameters[parameters.length - 1] instanceof RestElement);
15431
14594
  node.body = convertNode(node, scope.bodyScope, buffer[position + 3], buffer);
15432
14595
  },
15433
14596
  function assignmentExpression(node, position, buffer) {
@@ -15473,7 +14636,7 @@ const bufferParsers = [
15473
14636
  const parameterPosition = buffer[position];
15474
14637
  const parameter = (node.param =
15475
14638
  parameterPosition === 0 ? null : convertNode(node, scope, parameterPosition, buffer));
15476
- parameter?.declare('parameter', EMPTY_PATH, UNKNOWN_EXPRESSION);
14639
+ parameter?.declare('parameter', UNKNOWN_EXPRESSION);
15477
14640
  node.body = convertNode(node, scope.bodyScope, buffer[position + 1], buffer);
15478
14641
  },
15479
14642
  function chainExpression(node, position, buffer) {
@@ -15611,7 +14774,7 @@ const bufferParsers = [
15611
14774
  node.id =
15612
14775
  idPosition === 0 ? null : convertNode(node, scope.parent, idPosition, buffer);
15613
14776
  const parameters = (node.params = convertNodeList(node, scope, buffer[position + 3], buffer));
15614
- scope.addParameterVariables(parameters.map(parameter => parameter.declare('parameter', EMPTY_PATH, UNKNOWN_EXPRESSION)), parameters[parameters.length - 1] instanceof RestElement);
14777
+ scope.addParameterVariables(parameters.map(parameter => parameter.declare('parameter', UNKNOWN_EXPRESSION)), parameters[parameters.length - 1] instanceof RestElement);
15615
14778
  node.body = convertNode(node, scope.bodyScope, buffer[position + 4], buffer);
15616
14779
  },
15617
14780
  function functionExpression(node, position, buffer) {
@@ -15624,7 +14787,7 @@ const bufferParsers = [
15624
14787
  const idPosition = buffer[position + 2];
15625
14788
  node.id = idPosition === 0 ? null : convertNode(node, node.idScope, idPosition, buffer);
15626
14789
  const parameters = (node.params = convertNodeList(node, scope, buffer[position + 3], buffer));
15627
- scope.addParameterVariables(parameters.map(parameter => parameter.declare('parameter', EMPTY_PATH, UNKNOWN_EXPRESSION)), parameters[parameters.length - 1] instanceof RestElement);
14790
+ scope.addParameterVariables(parameters.map(parameter => parameter.declare('parameter', UNKNOWN_EXPRESSION)), parameters[parameters.length - 1] instanceof RestElement);
15628
14791
  node.body = convertNode(node, scope.bodyScope, buffer[position + 4], buffer);
15629
14792
  },
15630
14793
  function identifier(node, position, buffer) {
@@ -16088,8 +15251,8 @@ class ExportShimVariable extends Variable {
16088
15251
  super(MISSING_EXPORT_SHIM_VARIABLE);
16089
15252
  this.module = module;
16090
15253
  }
16091
- includePath(path, context) {
16092
- super.includePath(path, context);
15254
+ include() {
15255
+ super.include();
16093
15256
  this.module.needsExportShim = true;
16094
15257
  }
16095
15258
  }
@@ -16787,15 +15950,16 @@ class Module {
16787
15950
  markModuleAndImpureDependenciesAsExecuted(this);
16788
15951
  this.graph.needsTreeshakingPass = true;
16789
15952
  }
16790
- const inclusionContext = createInclusionContext();
16791
15953
  for (const exportName of this.exports.keys()) {
16792
15954
  if (includeNamespaceMembers || exportName !== this.info.syntheticNamedExports) {
16793
15955
  const variable = this.getVariableForExportName(exportName)[0];
16794
15956
  if (!variable) {
16795
15957
  return error(logMissingEntryExport(exportName, this.id));
16796
15958
  }
16797
- this.includeVariable(variable, UNKNOWN_PATH, inclusionContext);
16798
15959
  variable.deoptimizePath(UNKNOWN_PATH);
15960
+ if (!variable.included) {
15961
+ this.includeVariable(variable);
15962
+ }
16799
15963
  }
16800
15964
  }
16801
15965
  for (const name of this.getReexports()) {
@@ -16803,7 +15967,7 @@ class Module {
16803
15967
  if (variable) {
16804
15968
  variable.deoptimizePath(UNKNOWN_PATH);
16805
15969
  if (!variable.included) {
16806
- this.includeVariable(variable, UNKNOWN_PATH, inclusionContext);
15970
+ this.includeVariable(variable);
16807
15971
  }
16808
15972
  if (variable instanceof ExternalVariable) {
16809
15973
  variable.module.reexported = true;
@@ -16824,12 +15988,13 @@ class Module {
16824
15988
  this.graph.needsTreeshakingPass = true;
16825
15989
  }
16826
15990
  let includeNamespaceMembers = false;
16827
- const inclusionContext = createInclusionContext();
16828
15991
  for (const name of names) {
16829
15992
  const variable = this.getVariableForExportName(name)[0];
16830
15993
  if (variable) {
16831
15994
  variable.deoptimizePath(UNKNOWN_PATH);
16832
- this.includeVariable(variable, UNKNOWN_PATH, inclusionContext);
15995
+ if (!variable.included) {
15996
+ this.includeVariable(variable);
15997
+ }
16833
15998
  }
16834
15999
  if (!this.exports.has(name) && !this.reexportDescriptions.has(name)) {
16835
16000
  includeNamespaceMembers = true;
@@ -16930,7 +16095,6 @@ class Module {
16930
16095
  manualPureFunctions: this.graph.pureFunctions,
16931
16096
  module: this,
16932
16097
  moduleContext: this.context,
16933
- newlyIncludedVariableInits: this.graph.newlyIncludedVariableInits,
16934
16098
  options: this.options,
16935
16099
  requestTreeshakingPass: () => (this.graph.needsTreeshakingPass = true),
16936
16100
  traceExport: (name) => this.getVariableForExportName(name)[0],
@@ -17271,13 +16435,13 @@ class Module {
17271
16435
  for (const module of [this, ...this.exportAllModules]) {
17272
16436
  if (module instanceof ExternalModule) {
17273
16437
  const [externalVariable] = module.getVariableForExportName('*');
17274
- externalVariable.includePath(UNKNOWN_PATH, createInclusionContext());
16438
+ externalVariable.include();
17275
16439
  this.includedImports.add(externalVariable);
17276
16440
  externalNamespaces.add(externalVariable);
17277
16441
  }
17278
16442
  else if (module.info.syntheticNamedExports) {
17279
16443
  const syntheticNamespace = module.getSyntheticNamespace();
17280
- syntheticNamespace.includePath(UNKNOWN_PATH, createInclusionContext());
16444
+ syntheticNamespace.include();
17281
16445
  this.includedImports.add(syntheticNamespace);
17282
16446
  syntheticNamespaces.add(syntheticNamespace);
17283
16447
  }
@@ -17287,9 +16451,7 @@ class Module {
17287
16451
  includeDynamicImport(node) {
17288
16452
  const resolution = this.dynamicImports.find(dynamicImport => dynamicImport.node === node).resolution;
17289
16453
  if (resolution instanceof Module) {
17290
- if (!resolution.includedDynamicImporters.includes(this)) {
17291
- resolution.includedDynamicImporters.push(this);
17292
- }
16454
+ resolution.includedDynamicImporters.push(this);
17293
16455
  const importedNames = this.options.treeshake
17294
16456
  ? node.getDeterministicImportedNames()
17295
16457
  : undefined;
@@ -17301,15 +16463,15 @@ class Module {
17301
16463
  }
17302
16464
  }
17303
16465
  }
17304
- includeVariable(variable, path, context) {
17305
- const { included, module: variableModule } = variable;
17306
- variable.includePath(path, context);
17307
- if (included) {
16466
+ includeVariable(variable) {
16467
+ const variableModule = variable.module;
16468
+ if (variable.included) {
17308
16469
  if (variableModule instanceof Module && variableModule !== this) {
17309
16470
  getAndExtendSideEffectModules(variable, this);
17310
16471
  }
17311
16472
  }
17312
16473
  else {
16474
+ variable.include();
17313
16475
  this.graph.needsTreeshakingPass = true;
17314
16476
  if (variableModule instanceof Module) {
17315
16477
  if (!variableModule.isExecuted) {
@@ -17326,8 +16488,8 @@ class Module {
17326
16488
  }
17327
16489
  }
17328
16490
  }
17329
- includeVariableInModule(variable, path, context) {
17330
- this.includeVariable(variable, path, context);
16491
+ includeVariableInModule(variable) {
16492
+ this.includeVariable(variable);
17331
16493
  const variableModule = variable.module;
17332
16494
  if (variableModule && variableModule !== this) {
17333
16495
  this.includedImports.add(variable);
@@ -18366,17 +17528,21 @@ class Chunk {
18366
17528
  .filter((resolution) => resolution !== this &&
18367
17529
  (resolution instanceof Chunk || resolution instanceof ExternalChunk));
18368
17530
  }
18369
- getDynamicImportStringAndAttributes(resolution, fileName) {
17531
+ getDynamicImportStringAndAttributes(resolution, fileName, node) {
18370
17532
  if (resolution instanceof ExternalModule) {
18371
17533
  const chunk = this.externalChunkByModule.get(resolution);
18372
17534
  return [`'${chunk.getImportPath(fileName)}'`, chunk.getImportAttributes(this.snippets)];
18373
17535
  }
18374
- return [
18375
- resolution || '',
18376
- (['es', 'cjs'].includes(this.outputOptions.format) &&
18377
- this.outputOptions.externalImportAttributes) ||
18378
- null
18379
- ];
17536
+ let attributes = null;
17537
+ if (['es', 'cjs'].includes(this.outputOptions.format) &&
17538
+ this.outputOptions.externalImportAttributes) {
17539
+ const attributesFromImportAttributes = getAttributesFromImportExpression(node);
17540
+ attributes =
17541
+ attributesFromImportAttributes === EMPTY_OBJECT
17542
+ ? true
17543
+ : formatAttributes(attributesFromImportAttributes, this.snippets);
17544
+ }
17545
+ return [resolution || '', attributes];
18380
17546
  }
18381
17547
  getFallbackChunkName() {
18382
17548
  if (this.manualChunkAlias) {
@@ -18592,7 +17758,7 @@ class Chunk {
18592
17758
  // This method changes properties on the AST before rendering and must not be async
18593
17759
  renderModules(fileName) {
18594
17760
  const { accessedGlobalsByScope, dependencies, exportNamesByVariable, includedNamespaces, inputOptions: { onLog }, isEmpty, orderedModules, outputOptions, pluginDriver, renderedModules, snippets } = this;
18595
- const { compact, format, freeze, generatedCode: { symbols } } = outputOptions;
17761
+ const { compact, format, freeze, generatedCode: { symbols }, importAttributesKey } = outputOptions;
18596
17762
  const { _, cnst, n } = snippets;
18597
17763
  this.setDynamicImportResolutions(fileName);
18598
17764
  this.setImportMetaResolutions(fileName);
@@ -18608,6 +17774,7 @@ class Chunk {
18608
17774
  exportNamesByVariable,
18609
17775
  format,
18610
17776
  freeze,
17777
+ importAttributesKey,
18611
17778
  indent,
18612
17779
  pluginDriver,
18613
17780
  snippets,
@@ -18686,7 +17853,7 @@ class Chunk {
18686
17853
  }
18687
17854
  else {
18688
17855
  const { node, resolution } = resolvedDynamicImport;
18689
- const [resolutionString, attributes] = this.getDynamicImportStringAndAttributes(resolution, fileName);
17856
+ const [resolutionString, attributes] = this.getDynamicImportStringAndAttributes(resolution, fileName, node);
18690
17857
  node.setExternalResolution('external', resolution, outputOptions, snippets, pluginDriver, accessedGlobalsByScope, resolutionString, false, attributes);
18691
17858
  }
18692
17859
  }
@@ -21930,11 +21097,10 @@ class Graph {
21930
21097
  this.options = options;
21931
21098
  this.astLru = flru(5);
21932
21099
  this.cachedModules = new Map();
21933
- this.deoptimizationTracker = new EntityPathTracker();
21100
+ this.deoptimizationTracker = new PathTracker();
21934
21101
  this.entryModules = [];
21935
21102
  this.modulesById = new Map();
21936
21103
  this.needsTreeshakingPass = false;
21937
- this.newlyIncludedVariableInits = new Set();
21938
21104
  this.phase = BuildPhase.LOAD_AND_PARSE;
21939
21105
  this.scope = new GlobalScope();
21940
21106
  this.watchFiles = Object.create(null);
@@ -22028,7 +21194,6 @@ class Graph {
22028
21194
  }
22029
21195
  if (this.options.treeshake) {
22030
21196
  let treeshakingPass = 1;
22031
- this.newlyIncludedVariableInits.clear();
22032
21197
  do {
22033
21198
  timeStart(`treeshaking pass ${treeshakingPass}`, 3);
22034
21199
  this.needsTreeshakingPass = false;
@@ -22041,10 +21206,6 @@ class Graph {
22041
21206
  else {
22042
21207
  module.include();
22043
21208
  }
22044
- for (const entity of this.newlyIncludedVariableInits) {
22045
- this.newlyIncludedVariableInits.delete(entity);
22046
- entity.include(createInclusionContext(), false);
22047
- }
22048
21209
  }
22049
21210
  }
22050
21211
  if (treeshakingPass === 1) {
@@ -22917,7 +22078,7 @@ const pc = /*@__PURE__*/getDefaultExportFromCjs(picocolorsExports);
22917
22078
 
22918
22079
  // @see https://no-color.org
22919
22080
  // @see https://www.npmjs.com/package/chalk
22920
- const { bold, cyan, dim, red} = pc.createColors(env.FORCE_COLOR !== '0' && !env.NO_COLOR);
22081
+ const { bold, cyan, dim, gray, green, red, underline, yellow } = pc.createColors(env.FORCE_COLOR !== '0' && !env.NO_COLOR);
22921
22082
 
22922
22083
  // log to stderr to keep `rollup main.js > bundle.js` from breaking
22923
22084
  const stderr = (...parameters) => process$1.stderr.write(`${parameters.join('')}\n`);