@rollup/wasm-node 4.30.0-1 → 4.30.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,22 +1,21 @@
1
1
  /*
2
2
  @license
3
- Rollup.js v4.30.0-1
4
- Mon, 30 Dec 2024 06:51:45 GMT - commit 41ab39a6e4a5181e9be21e816dd6f11c57e1c52a
3
+ Rollup.js v4.30.0
4
+ Mon, 06 Jan 2025 06:36:11 GMT - commit 958d5ebabd49297e9a4b78ad34ac0a0132305dea
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';
14
- import process$1, { env as env$1 } from 'node:process';
12
+ import { posix, win32, isAbsolute, resolve } from 'path';
13
+ import { parseAsync, xxhashBase64Url, xxhashBase36, xxhashBase16 } from '../../native.js';
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
- import * as tty from 'tty';
18
17
 
19
- var version = "4.30.0-1";
18
+ var version = "4.30.0";
20
19
 
21
20
  const comma = ','.charCodeAt(0);
22
21
  const semicolon = ';'.charCodeAt(0);
@@ -41,7 +40,7 @@ function decodeInteger(reader, relative) {
41
40
  const shouldNegate = value & 1;
42
41
  value >>>= 1;
43
42
  if (shouldNegate) {
44
- value = -0x80000000 | -value;
43
+ value = -2147483648 | -value;
45
44
  }
46
45
  return relative + value;
47
46
  }
@@ -1965,6 +1964,71 @@ function renderSystemExportSequenceBeforeExpression(exportedVariable, expression
1965
1964
  }
1966
1965
  }
1967
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
+
1968
2032
  function getOrCreate(map, key, init) {
1969
2033
  const existing = map.get(key);
1970
2034
  if (existing !== undefined) {
@@ -1995,7 +2059,7 @@ const UNKNOWN_PATH = [UnknownKey];
1995
2059
  const UNKNOWN_NON_ACCESSOR_PATH = [UnknownNonAccessorKey];
1996
2060
  const UNKNOWN_INTEGER_PATH = [UnknownInteger];
1997
2061
  const EntitiesKey = Symbol('Entities');
1998
- class EntityPathTracker {
2062
+ class PathTracker {
1999
2063
  constructor() {
2000
2064
  this.entityPaths = Object.create(null, {
2001
2065
  [EntitiesKey]: { value: new Set() }
@@ -2020,14 +2084,14 @@ class EntityPathTracker {
2020
2084
  getEntities(path) {
2021
2085
  let currentPaths = this.entityPaths;
2022
2086
  for (const pathSegment of path) {
2023
- currentPaths = currentPaths[pathSegment] ||= Object.create(null, {
2024
- [EntitiesKey]: { value: new Set() }
2025
- });
2087
+ currentPaths = currentPaths[pathSegment] =
2088
+ currentPaths[pathSegment] ||
2089
+ Object.create(null, { [EntitiesKey]: { value: new Set() } });
2026
2090
  }
2027
2091
  return currentPaths[EntitiesKey];
2028
2092
  }
2029
2093
  }
2030
- const SHARED_RECURSION_TRACKER = new EntityPathTracker();
2094
+ const SHARED_RECURSION_TRACKER = new PathTracker();
2031
2095
  class DiscriminatedPathTracker {
2032
2096
  constructor() {
2033
2097
  this.entityPaths = Object.create(null, {
@@ -2037,9 +2101,9 @@ class DiscriminatedPathTracker {
2037
2101
  trackEntityAtPathAndGetIfTracked(path, discriminator, entity) {
2038
2102
  let currentPaths = this.entityPaths;
2039
2103
  for (const pathSegment of path) {
2040
- currentPaths = currentPaths[pathSegment] ||= Object.create(null, {
2041
- [EntitiesKey]: { value: new Map() }
2042
- });
2104
+ currentPaths = currentPaths[pathSegment] =
2105
+ currentPaths[pathSegment] ||
2106
+ Object.create(null, { [EntitiesKey]: { value: new Map() } });
2043
2107
  }
2044
2108
  const trackedEntities = getOrCreate(currentPaths[EntitiesKey], discriminator, (getNewSet));
2045
2109
  if (trackedEntities.has(entity))
@@ -2048,137 +2112,6 @@ class DiscriminatedPathTracker {
2048
2112
  return false;
2049
2113
  }
2050
2114
  }
2051
- const UNKNOWN_INCLUDED_PATH = Object.freeze({ [UnknownKey]: EMPTY_OBJECT });
2052
- class IncludedPathTracker {
2053
- constructor() {
2054
- this.includedPaths = null;
2055
- }
2056
- includePathAndGetIfIncluded(path) {
2057
- let included = true;
2058
- let parent = this;
2059
- let parentSegment = 'includedPaths';
2060
- let currentPaths = (this.includedPaths ||=
2061
- ((included = false), Object.create(null)));
2062
- for (const pathSegment of path) {
2063
- // This means from here, all paths are included
2064
- if (currentPaths[UnknownKey]) {
2065
- return true;
2066
- }
2067
- // Including UnknownKey automatically includes all nested paths.
2068
- // From above, we know that UnknownKey is not included yet.
2069
- if (typeof pathSegment === 'symbol') {
2070
- // Hopefully, this saves some memory over just setting
2071
- // currentPaths[UnknownKey] = EMPTY_OBJECT
2072
- parent[parentSegment] = UNKNOWN_INCLUDED_PATH;
2073
- return false;
2074
- }
2075
- parent = currentPaths;
2076
- parentSegment = pathSegment;
2077
- currentPaths = currentPaths[pathSegment] ||= ((included = false), Object.create(null));
2078
- }
2079
- return included;
2080
- }
2081
- includeAllPaths(entity, context, basePath) {
2082
- const { includedPaths } = this;
2083
- if (includedPaths) {
2084
- includeAllPaths(entity, context, basePath, includedPaths);
2085
- }
2086
- }
2087
- }
2088
- function includeAllPaths(entity, context, basePath, currentPaths) {
2089
- if (currentPaths[UnknownKey]) {
2090
- return entity.includePath([...basePath, UnknownKey], context);
2091
- }
2092
- const keys = Object.keys(currentPaths);
2093
- if (keys.length === 0) {
2094
- return entity.includePath(basePath, context);
2095
- }
2096
- for (const key of keys) {
2097
- includeAllPaths(entity, context, [...basePath, key], currentPaths[key]);
2098
- }
2099
- }
2100
-
2101
- /** @import { Node } from 'estree' */
2102
-
2103
- /**
2104
- * @param {Node} node
2105
- * @param {Node} parent
2106
- * @returns {boolean}
2107
- */
2108
- function is_reference(node, parent) {
2109
- if (node.type === 'MemberExpression') {
2110
- return !node.computed && is_reference(node.object, node);
2111
- }
2112
-
2113
- if (node.type !== 'Identifier') return false;
2114
-
2115
- switch (parent?.type) {
2116
- // disregard `bar` in `foo.bar`
2117
- case 'MemberExpression':
2118
- return parent.computed || node === parent.object;
2119
-
2120
- // disregard the `foo` in `class {foo(){}}` but keep it in `class {[foo](){}}`
2121
- case 'MethodDefinition':
2122
- return parent.computed;
2123
-
2124
- // disregard the `meta` in `import.meta`
2125
- case 'MetaProperty':
2126
- return parent.meta === node;
2127
-
2128
- // disregard the `foo` in `class {foo=bar}` but keep it in `class {[foo]=bar}` and `class {bar=foo}`
2129
- case 'PropertyDefinition':
2130
- return parent.computed || node === parent.value;
2131
-
2132
- // disregard the `bar` in `{ bar: foo }`, but keep it in `{ [bar]: foo }`
2133
- case 'Property':
2134
- return parent.computed || node === parent.value;
2135
-
2136
- // disregard the `bar` in `export { foo as bar }` or
2137
- // the foo in `import { foo as bar }`
2138
- case 'ExportSpecifier':
2139
- case 'ImportSpecifier':
2140
- return node === parent.local;
2141
-
2142
- // disregard the `foo` in `foo: while (...) { ... break foo; ... continue foo;}`
2143
- case 'LabeledStatement':
2144
- case 'BreakStatement':
2145
- case 'ContinueStatement':
2146
- return false;
2147
-
2148
- default:
2149
- return true;
2150
- }
2151
- }
2152
-
2153
- function createInclusionContext() {
2154
- return {
2155
- brokenFlow: false,
2156
- hasBreak: false,
2157
- hasContinue: false,
2158
- includedCallArguments: new Set(),
2159
- includedLabels: new Set()
2160
- };
2161
- }
2162
- function createHasEffectsContext() {
2163
- return {
2164
- accessed: new EntityPathTracker(),
2165
- assigned: new EntityPathTracker(),
2166
- brokenFlow: false,
2167
- called: new DiscriminatedPathTracker(),
2168
- hasBreak: false,
2169
- hasContinue: false,
2170
- ignore: {
2171
- breaks: false,
2172
- continues: false,
2173
- labels: new Set(),
2174
- returnYield: false,
2175
- this: false
2176
- },
2177
- includedLabels: new Set(),
2178
- instantiated: new DiscriminatedPathTracker(),
2179
- replacedVariableInits: new Map()
2180
- };
2181
- }
2182
2115
 
2183
2116
  function isFlagSet(flags, flag) {
2184
2117
  return (flags & flag) !== 0;
@@ -2218,25 +2151,12 @@ class ExpressionEntity {
2218
2151
  hasEffectsOnInteractionAtPath(_path, _interaction, _context) {
2219
2152
  return true;
2220
2153
  }
2221
- include(context, _includeChildrenRecursively, _options) {
2222
- if (!this.included)
2223
- this.includeNode(context);
2224
- }
2225
- includeNode(_context) {
2154
+ include(_context, _includeChildrenRecursively, _options) {
2226
2155
  this.included = true;
2227
2156
  }
2228
- includePath(_path, context) {
2229
- if (!this.included)
2230
- this.includeNode(context);
2231
- }
2232
- /* We are both including and including an unknown path here as the former
2233
- * ensures that nested nodes are included while the latter ensures that all
2234
- * paths of the expression are included.
2235
- * */
2236
- includeCallArguments(context, interaction) {
2237
- for (const argument of interaction.args) {
2238
- argument?.includePath(UNKNOWN_PATH, context);
2239
- argument?.include(context, false);
2157
+ includeCallArguments(context, parameters) {
2158
+ for (const argument of parameters) {
2159
+ argument.include(context, false);
2240
2160
  }
2241
2161
  }
2242
2162
  shouldBeIncluded(_context) {
@@ -2275,19 +2195,6 @@ const NODE_INTERACTION_UNKNOWN_CALL = {
2275
2195
  withNew: false
2276
2196
  };
2277
2197
 
2278
- const PureFunctionKey = Symbol('PureFunction');
2279
- const getPureFunctions = ({ treeshake }) => {
2280
- const pureFunctions = Object.create(null);
2281
- for (const functionName of treeshake ? treeshake.manualPureFunctions : []) {
2282
- let currentFunctions = pureFunctions;
2283
- for (const pathSegment of functionName.split('.')) {
2284
- currentFunctions = currentFunctions[pathSegment] ||= Object.create(null);
2285
- }
2286
- currentFunctions[PureFunctionKey] = true;
2287
- }
2288
- return pureFunctions;
2289
- };
2290
-
2291
2198
  class Variable extends ExpressionEntity {
2292
2199
  markReassigned() {
2293
2200
  this.isReassigned = true;
@@ -2364,9 +2271,9 @@ class Variable extends ExpressionEntity {
2364
2271
  * has not been included previously. Once a variable is included, it should
2365
2272
  * take care all its declarations are included.
2366
2273
  */
2367
- includePath(path, context) {
2274
+ include() {
2368
2275
  this.included = true;
2369
- this.renderedLikeHoisted?.includePath(path, context);
2276
+ this.renderedLikeHoisted?.include();
2370
2277
  }
2371
2278
  /**
2372
2279
  * Links the rendered name of this variable to another variable and includes
@@ -2398,8 +2305,8 @@ class ExternalVariable extends Variable {
2398
2305
  hasEffectsOnInteractionAtPath(path, { type }) {
2399
2306
  return type !== INTERACTION_ACCESSED || path.length > (this.isNamespace ? 1 : 0);
2400
2307
  }
2401
- includePath(path, context) {
2402
- super.includePath(path, context);
2308
+ include() {
2309
+ super.include();
2403
2310
  this.module.used = true;
2404
2311
  }
2405
2312
  }
@@ -2700,6 +2607,36 @@ const childNodeKeys = {
2700
2607
  YieldExpression: ['argument']
2701
2608
  };
2702
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
+
2703
2640
  const INCLUDE_PARAMETERS = 'variables';
2704
2641
  const IS_SKIPPED_CHAIN = Symbol('IS_SKIPPED_CHAIN');
2705
2642
  class NodeBase extends ExpressionEntity {
@@ -2769,37 +2706,20 @@ class NodeBase extends ExpressionEntity {
2769
2706
  this.hasEffectsOnInteractionAtPath(EMPTY_PATH, this.assignmentInteraction, context));
2770
2707
  }
2771
2708
  include(context, includeChildrenRecursively, _options) {
2772
- if (!this.included)
2773
- this.includeNode(context);
2774
- for (const key of childNodeKeys[this.type]) {
2775
- const value = this[key];
2776
- if (value === null)
2777
- continue;
2778
- if (Array.isArray(value)) {
2779
- for (const child of value) {
2780
- child?.include(context, includeChildrenRecursively);
2781
- }
2782
- }
2783
- else {
2784
- value.include(context, includeChildrenRecursively);
2785
- }
2786
- }
2787
- }
2788
- includeNode(context) {
2789
- this.included = true;
2790
2709
  if (!this.deoptimized)
2791
2710
  this.applyDeoptimizations();
2711
+ this.included = true;
2792
2712
  for (const key of childNodeKeys[this.type]) {
2793
2713
  const value = this[key];
2794
2714
  if (value === null)
2795
2715
  continue;
2796
2716
  if (Array.isArray(value)) {
2797
2717
  for (const child of value) {
2798
- child?.includePath(UNKNOWN_PATH, context);
2718
+ child?.include(context, includeChildrenRecursively);
2799
2719
  }
2800
2720
  }
2801
2721
  else {
2802
- value.includePath(UNKNOWN_PATH, context);
2722
+ value.include(context, includeChildrenRecursively);
2803
2723
  }
2804
2724
  }
2805
2725
  }
@@ -2906,17 +2826,6 @@ class NodeBase extends ExpressionEntity {
2906
2826
  function createChildNodeKeysForNode(esTreeNode) {
2907
2827
  return Object.keys(esTreeNode).filter(key => typeof esTreeNode[key] === 'object' && key.charCodeAt(0) !== 95 /* _ */);
2908
2828
  }
2909
- function onlyIncludeSelf() {
2910
- this.included = true;
2911
- if (!this.deoptimized)
2912
- this.applyDeoptimizations();
2913
- }
2914
- function onlyIncludeSelfNoDeoptimize() {
2915
- this.included = true;
2916
- }
2917
- function doNotDeoptimize() {
2918
- this.deoptimized = true;
2919
- }
2920
2829
 
2921
2830
  function isObjectExpressionNode(node) {
2922
2831
  return node instanceof NodeBase && node.type === ObjectExpression$1;
@@ -2929,8 +2838,8 @@ function assembleMemberDescriptions(memberDescriptions, inheritedDescriptions =
2929
2838
  return Object.create(inheritedDescriptions, memberDescriptions);
2930
2839
  }
2931
2840
  const UNDEFINED_EXPRESSION = new (class UndefinedExpression extends ExpressionEntity {
2932
- getLiteralValueAtPath(path) {
2933
- return path.length > 0 ? UnknownValue : undefined;
2841
+ getLiteralValueAtPath() {
2842
+ return undefined;
2934
2843
  }
2935
2844
  })();
2936
2845
  const returnsUnknown = {
@@ -3127,6 +3036,31 @@ function getMemberReturnExpressionWhenCalled(members, memberName) {
3127
3036
  return [members[memberName].returns, false];
3128
3037
  }
3129
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
+
3130
3064
  class Method extends ExpressionEntity {
3131
3065
  constructor(description) {
3132
3066
  super();
@@ -3252,7 +3186,6 @@ class ObjectEntity extends ExpressionEntity {
3252
3186
  this.unknownIntegerProps = [];
3253
3187
  this.unmatchableGetters = [];
3254
3188
  this.unmatchablePropertiesAndGetters = [];
3255
- this.unmatchablePropertiesAndSetters = [];
3256
3189
  this.unmatchableSetters = [];
3257
3190
  if (Array.isArray(properties)) {
3258
3191
  this.buildPropertyMaps(properties);
@@ -3409,12 +3342,7 @@ class ObjectEntity extends ExpressionEntity {
3409
3342
  }
3410
3343
  getLiteralValueAtPath(path, recursionTracker, origin) {
3411
3344
  if (path.length === 0) {
3412
- // This should actually be "UnknownTruthyValue". However, this currently
3413
- // causes an issue with TypeScript enums in files with moduleSideEffects:
3414
- // false because we cannot properly track whether a "var" has been
3415
- // initialized. This should be reverted once we can properly track this.
3416
- // return UnknownTruthyValue;
3417
- return UnknownValue;
3345
+ return UnknownTruthyValue;
3418
3346
  }
3419
3347
  const key = path[0];
3420
3348
  const expressionAtPath = this.getMemberExpressionAndTrackDeopt(key, origin);
@@ -3492,38 +3420,9 @@ class ObjectEntity extends ExpressionEntity {
3492
3420
  }
3493
3421
  return false;
3494
3422
  }
3495
- include(context, includeChildrenRecursively) {
3496
- this.included = true;
3497
- for (const property of this.allProperties) {
3498
- if (includeChildrenRecursively || property.shouldBeIncluded(context)) {
3499
- property.include(context, includeChildrenRecursively);
3500
- }
3501
- }
3502
- this.prototypeExpression?.include(context, includeChildrenRecursively);
3503
- }
3504
- includePath(path, context) {
3505
- this.included = true;
3506
- if (path.length === 0)
3507
- return;
3508
- const [key, ...subPath] = path;
3509
- const [includedMembers, includedPath] = typeof key === 'string'
3510
- ? [
3511
- [
3512
- ...new Set([
3513
- ...(this.propertiesAndGettersByKey[key] || this.unmatchablePropertiesAndGetters),
3514
- ...(this.propertiesAndSettersByKey[key] || this.unmatchablePropertiesAndSetters)
3515
- ])
3516
- ],
3517
- subPath
3518
- ]
3519
- : [this.allProperties, UNKNOWN_PATH];
3520
- for (const property of includedMembers) {
3521
- property.includePath(includedPath, context);
3522
- }
3523
- this.prototypeExpression?.includePath(path, context);
3524
- }
3525
3423
  buildPropertyMaps(properties) {
3526
- 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 = [];
3527
3426
  for (let index = properties.length - 1; index >= 0; index--) {
3528
3427
  const { key, kind, property } = properties[index];
3529
3428
  allProperties.push(property);
@@ -3793,37 +3692,6 @@ const ARRAY_PROTOTYPE = new ObjectEntity({
3793
3692
  values: METHOD_DEOPTS_SELF_RETURNS_UNKNOWN
3794
3693
  }, OBJECT_PROTOTYPE, true);
3795
3694
 
3796
- class SpreadElement extends NodeBase {
3797
- deoptimizeArgumentsOnInteractionAtPath(interaction, path, recursionTracker) {
3798
- if (path.length > 0) {
3799
- this.argument.deoptimizeArgumentsOnInteractionAtPath(interaction, UNKNOWN_PATH, recursionTracker);
3800
- }
3801
- }
3802
- hasEffects(context) {
3803
- if (!this.deoptimized)
3804
- this.applyDeoptimizations();
3805
- const { propertyReadSideEffects } = this.scope.context.options
3806
- .treeshake;
3807
- return (this.argument.hasEffects(context) ||
3808
- (propertyReadSideEffects &&
3809
- (propertyReadSideEffects === 'always' ||
3810
- this.argument.hasEffectsOnInteractionAtPath(UNKNOWN_PATH, NODE_INTERACTION_UNKNOWN_ACCESS, context))));
3811
- }
3812
- includeNode(context) {
3813
- this.included = true;
3814
- if (!this.deoptimized)
3815
- this.applyDeoptimizations();
3816
- this.argument.includePath(UNKNOWN_PATH, context);
3817
- }
3818
- applyDeoptimizations() {
3819
- this.deoptimized = true;
3820
- // Only properties of properties of the argument could become subject to reassignment
3821
- // This will also reassign the return values of iterators
3822
- this.argument.deoptimizePath([UnknownKey, UnknownKey]);
3823
- this.scope.context.requestTreeshakingPass();
3824
- }
3825
- }
3826
-
3827
3695
  class ArrayExpression extends NodeBase {
3828
3696
  constructor() {
3829
3697
  super(...arguments);
@@ -3844,16 +3712,6 @@ class ArrayExpression extends NodeBase {
3844
3712
  hasEffectsOnInteractionAtPath(path, interaction, context) {
3845
3713
  return this.getObjectEntity().hasEffectsOnInteractionAtPath(path, interaction, context);
3846
3714
  }
3847
- includeNode(context) {
3848
- this.included = true;
3849
- if (!this.deoptimized)
3850
- this.applyDeoptimizations();
3851
- for (const element of this.elements) {
3852
- if (element) {
3853
- element?.includePath(UNKNOWN_PATH, context);
3854
- }
3855
- }
3856
- }
3857
3715
  applyDeoptimizations() {
3858
3716
  this.deoptimized = true;
3859
3717
  let hasSpread = false;
@@ -4921,37 +4779,17 @@ class GlobalVariable extends Variable {
4921
4779
  }
4922
4780
  }
4923
4781
 
4924
- // To avoid infinite recursions
4925
- const MAX_PATH_DEPTH = 6;
4926
- // If a path is longer than MAX_PATH_DEPTH, it is truncated so that it is at
4927
- // most MAX_PATH_DEPTH long. The last element is always UnknownKey
4928
- const limitConcatenatedPathDepth = (path1, path2) => {
4929
- const { length: length1 } = path1;
4930
- const { length: length2 } = path2;
4931
- return length1 === 0
4932
- ? path2
4933
- : length2 === 0
4934
- ? path1
4935
- : length1 + length2 > MAX_PATH_DEPTH
4936
- ? [...path1, ...path2.slice(0, MAX_PATH_DEPTH - 1 - path1.length), 'UnknownKey']
4937
- : [...path1, ...path2];
4938
- };
4939
-
4940
4782
  class LocalVariable extends Variable {
4941
- constructor(name, declarator, init,
4942
- /** if this is non-empty, the actual init is this path of this.init */
4943
- initPath, context, kind) {
4783
+ constructor(name, declarator, init, context, kind) {
4944
4784
  super(name);
4945
4785
  this.init = init;
4946
- this.initPath = initPath;
4947
- this.kind = kind;
4948
4786
  this.calledFromTryStatement = false;
4949
4787
  this.additionalInitializers = null;
4950
- this.includedPathTracker = new IncludedPathTracker();
4951
4788
  this.expressionsToBeDeoptimized = [];
4952
4789
  this.declarations = declarator ? [declarator] : [];
4953
4790
  this.deoptimizationTracker = context.deoptimizationTracker;
4954
4791
  this.module = context.module;
4792
+ this.kind = kind;
4955
4793
  }
4956
4794
  addDeclaration(identifier, init) {
4957
4795
  this.declarations.push(identifier);
@@ -4962,16 +4800,15 @@ class LocalVariable extends Variable {
4962
4800
  for (const initializer of this.additionalInitializers) {
4963
4801
  initializer.deoptimizePath(UNKNOWN_PATH);
4964
4802
  }
4803
+ this.additionalInitializers = null;
4965
4804
  }
4966
4805
  }
4967
4806
  deoptimizeArgumentsOnInteractionAtPath(interaction, path, recursionTracker) {
4968
- if (this.isReassigned || path.length + this.initPath.length > MAX_PATH_DEPTH) {
4807
+ if (this.isReassigned) {
4969
4808
  deoptimizeInteraction(interaction);
4970
4809
  return;
4971
4810
  }
4972
- recursionTracker.withTrackedEntityAtPath(path, this.init, () => {
4973
- this.init.deoptimizeArgumentsOnInteractionAtPath(interaction, [...this.initPath, ...path], recursionTracker);
4974
- }, undefined);
4811
+ recursionTracker.withTrackedEntityAtPath(path, this.init, () => this.init.deoptimizeArgumentsOnInteractionAtPath(interaction, path, recursionTracker), undefined);
4975
4812
  }
4976
4813
  deoptimizePath(path) {
4977
4814
  if (this.isReassigned ||
@@ -4985,40 +4822,37 @@ class LocalVariable extends Variable {
4985
4822
  for (const expression of expressionsToBeDeoptimized) {
4986
4823
  expression.deoptimizeCache();
4987
4824
  }
4988
- this.init.deoptimizePath([...this.initPath, UnknownKey]);
4825
+ this.init.deoptimizePath(UNKNOWN_PATH);
4989
4826
  }
4990
4827
  else {
4991
- this.init.deoptimizePath(limitConcatenatedPathDepth(this.initPath, path));
4828
+ this.init.deoptimizePath(path);
4992
4829
  }
4993
4830
  }
4994
4831
  getLiteralValueAtPath(path, recursionTracker, origin) {
4995
- if (this.isReassigned || path.length + this.initPath.length > MAX_PATH_DEPTH) {
4832
+ if (this.isReassigned) {
4996
4833
  return UnknownValue;
4997
4834
  }
4998
4835
  return recursionTracker.withTrackedEntityAtPath(path, this.init, () => {
4999
4836
  this.expressionsToBeDeoptimized.push(origin);
5000
- return this.init.getLiteralValueAtPath([...this.initPath, ...path], recursionTracker, origin);
4837
+ return this.init.getLiteralValueAtPath(path, recursionTracker, origin);
5001
4838
  }, UnknownValue);
5002
4839
  }
5003
4840
  getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin) {
5004
- if (this.isReassigned || path.length + this.initPath.length > MAX_PATH_DEPTH) {
4841
+ if (this.isReassigned) {
5005
4842
  return UNKNOWN_RETURN_EXPRESSION;
5006
4843
  }
5007
4844
  return recursionTracker.withTrackedEntityAtPath(path, this.init, () => {
5008
4845
  this.expressionsToBeDeoptimized.push(origin);
5009
- return this.init.getReturnExpressionWhenCalledAtPath([...this.initPath, ...path], interaction, recursionTracker, origin);
4846
+ return this.init.getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin);
5010
4847
  }, UNKNOWN_RETURN_EXPRESSION);
5011
4848
  }
5012
4849
  hasEffectsOnInteractionAtPath(path, interaction, context) {
5013
- if (path.length + this.initPath.length > MAX_PATH_DEPTH) {
5014
- return true;
5015
- }
5016
4850
  switch (interaction.type) {
5017
4851
  case INTERACTION_ACCESSED: {
5018
4852
  if (this.isReassigned)
5019
4853
  return true;
5020
4854
  return (!context.accessed.trackEntityAtPathAndGetIfTracked(path, this) &&
5021
- this.init.hasEffectsOnInteractionAtPath([...this.initPath, ...path], interaction, context));
4855
+ this.init.hasEffectsOnInteractionAtPath(path, interaction, context));
5022
4856
  }
5023
4857
  case INTERACTION_ASSIGNED: {
5024
4858
  if (this.included)
@@ -5028,63 +4862,44 @@ class LocalVariable extends Variable {
5028
4862
  if (this.isReassigned)
5029
4863
  return true;
5030
4864
  return (!context.assigned.trackEntityAtPathAndGetIfTracked(path, this) &&
5031
- this.init.hasEffectsOnInteractionAtPath([...this.initPath, ...path], interaction, context));
4865
+ this.init.hasEffectsOnInteractionAtPath(path, interaction, context));
5032
4866
  }
5033
4867
  case INTERACTION_CALLED: {
5034
4868
  if (this.isReassigned)
5035
4869
  return true;
5036
4870
  return (!(interaction.withNew ? context.instantiated : context.called).trackEntityAtPathAndGetIfTracked(path, interaction.args, this) &&
5037
- this.init.hasEffectsOnInteractionAtPath([...this.initPath, ...path], interaction, context));
4871
+ this.init.hasEffectsOnInteractionAtPath(path, interaction, context));
5038
4872
  }
5039
4873
  }
5040
4874
  }
5041
- includePath(path, context) {
5042
- if (!this.includedPathTracker.includePathAndGetIfIncluded(path)) {
5043
- this.module.scope.context.requestTreeshakingPass();
5044
- if (!this.included) {
5045
- // This will reduce the number of tree-shaking passes by eagerly
5046
- // including inits. By pushing this here instead of directly including
5047
- // we avoid deep call stacks.
5048
- this.module.scope.context.newlyIncludedVariableInits.add(this.init);
5049
- }
5050
- super.includePath(path, context);
4875
+ include() {
4876
+ if (!this.included) {
4877
+ super.include();
5051
4878
  for (const declaration of this.declarations) {
5052
4879
  // If node is a default export, it can save a tree-shaking run to include the full declaration now
5053
4880
  if (!declaration.included)
5054
- declaration.include(context, false);
4881
+ declaration.include(createInclusionContext(), false);
5055
4882
  let node = declaration.parent;
5056
4883
  while (!node.included) {
5057
4884
  // We do not want to properly include parents in case they are part of a dead branch
5058
4885
  // in which case .include() might pull in more dead code
5059
- node.includeNode(context);
4886
+ node.included = true;
5060
4887
  if (node.type === Program$1)
5061
4888
  break;
5062
4889
  node = node.parent;
5063
4890
  }
5064
4891
  }
5065
- // We need to make sure we include the correct path of the init
5066
- if (path.length > 0) {
5067
- this.init.includePath(limitConcatenatedPathDepth(this.initPath, path), context);
5068
- this.additionalInitializers?.forEach(initializer => initializer.includePath(UNKNOWN_PATH, context));
5069
- }
5070
4892
  }
5071
4893
  }
5072
- includeCallArguments(context, interaction) {
5073
- if (this.isReassigned ||
5074
- context.includedCallArguments.has(this.init) ||
5075
- // This can be removed again once we can include arguments when called at
5076
- // a specific path
5077
- this.initPath.length > 0) {
5078
- for (const argument of interaction.args) {
5079
- if (argument) {
5080
- argument.includePath(UNKNOWN_PATH, context);
5081
- argument.include(context, false);
5082
- }
4894
+ includeCallArguments(context, parameters) {
4895
+ if (this.isReassigned || context.includedCallArguments.has(this.init)) {
4896
+ for (const argument of parameters) {
4897
+ argument.include(context, false);
5083
4898
  }
5084
4899
  }
5085
4900
  else {
5086
4901
  context.includedCallArguments.add(this.init);
5087
- this.init.includeCallArguments(context, interaction);
4902
+ this.init.includeCallArguments(context, parameters);
5088
4903
  context.includedCallArguments.delete(this.init);
5089
4904
  }
5090
4905
  }
@@ -5164,31 +4979,18 @@ class IdentifierBase extends NodeBase {
5164
4979
  }
5165
4980
  }
5166
4981
  }
5167
- include(context) {
5168
- if (!this.included)
5169
- this.includeNode(context);
5170
- }
5171
- includeNode(context) {
5172
- this.included = true;
4982
+ include() {
5173
4983
  if (!this.deoptimized)
5174
4984
  this.applyDeoptimizations();
5175
- if (this.variable !== null) {
5176
- this.scope.context.includeVariableInModule(this.variable, EMPTY_PATH, context);
5177
- }
5178
- }
5179
- includePath(path, context) {
5180
4985
  if (!this.included) {
5181
4986
  this.included = true;
5182
4987
  if (this.variable !== null) {
5183
- this.scope.context.includeVariableInModule(this.variable, path, context);
4988
+ this.scope.context.includeVariableInModule(this.variable);
5184
4989
  }
5185
4990
  }
5186
- else if (path.length > 0) {
5187
- this.variable?.includePath(path, context);
5188
- }
5189
4991
  }
5190
- includeCallArguments(context, interaction) {
5191
- this.variable.includeCallArguments(context, interaction);
4992
+ includeCallArguments(context, parameters) {
4993
+ this.variable.includeCallArguments(context, parameters);
5192
4994
  }
5193
4995
  isPossibleTDZ() {
5194
4996
  // return cached value to avoid issues with the next tree-shaking pass
@@ -5271,40 +5073,11 @@ function closestParentFunctionOrProgram(node) {
5271
5073
  return node;
5272
5074
  }
5273
5075
 
5274
- class ObjectMember extends ExpressionEntity {
5275
- constructor(object, path) {
5276
- super();
5277
- this.object = object;
5278
- this.path = path;
5279
- }
5280
- deoptimizeArgumentsOnInteractionAtPath(interaction, path, recursionTracker) {
5281
- this.object.deoptimizeArgumentsOnInteractionAtPath(interaction, [...this.path, ...path], recursionTracker);
5282
- }
5283
- deoptimizePath(path) {
5284
- this.object.deoptimizePath([...this.path, ...path]);
5285
- }
5286
- getLiteralValueAtPath(path, recursionTracker, origin) {
5287
- return this.object.getLiteralValueAtPath([...this.path, ...path], recursionTracker, origin);
5288
- }
5289
- getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin) {
5290
- return this.object.getReturnExpressionWhenCalledAtPath([...this.path, ...path], interaction, recursionTracker, origin);
5291
- }
5292
- hasEffectsOnInteractionAtPath(path, interaction, context) {
5293
- return this.object.hasEffectsOnInteractionAtPath([...this.path, ...path], interaction, context);
5294
- }
5295
- }
5296
-
5297
5076
  class Identifier extends IdentifierBase {
5298
5077
  constructor() {
5299
5078
  super(...arguments);
5300
5079
  this.variable = null;
5301
5080
  }
5302
- get isDestructuringDeoptimized() {
5303
- return isFlagSet(this.flags, 16777216 /* Flag.destructuringDeoptimized */);
5304
- }
5305
- set isDestructuringDeoptimized(value) {
5306
- this.flags = setFlag(this.flags, 16777216 /* Flag.destructuringDeoptimized */, value);
5307
- }
5308
5081
  addExportedVariables(variables, exportNamesByVariable) {
5309
5082
  if (exportNamesByVariable.has(this.variable)) {
5310
5083
  variables.push(this.variable);
@@ -5317,52 +5090,42 @@ class Identifier extends IdentifierBase {
5317
5090
  this.isVariableReference = true;
5318
5091
  }
5319
5092
  }
5320
- declare(kind, destructuredInitPath, init) {
5093
+ declare(kind, init) {
5321
5094
  let variable;
5322
5095
  const { treeshake } = this.scope.context.options;
5323
- if (kind === 'parameter') {
5324
- variable = this.scope.addParameterDeclaration(this, destructuredInitPath);
5325
- }
5326
- else {
5327
- variable = this.scope.addDeclaration(this, this.scope.context, init, destructuredInitPath, kind);
5328
- if (kind === 'var' && treeshake && treeshake.correctVarValueBeforeDeclaration) {
5329
- // Necessary to make sure the init is deoptimized. We cannot call deoptimizePath here.
5330
- 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;
5331
5104
  }
5332
- }
5333
- return [(this.variable = variable)];
5334
- }
5335
- deoptimizeAssignment(destructuredInitPath, init) {
5336
- this.deoptimizePath(EMPTY_PATH);
5337
- init.deoptimizePath([...destructuredInitPath, UnknownKey]);
5338
- }
5339
- hasEffectsWhenDestructuring(context, destructuredInitPath, init) {
5340
- return (destructuredInitPath.length > 0 &&
5341
- init.hasEffectsOnInteractionAtPath(destructuredInitPath, NODE_INTERACTION_UNKNOWN_ACCESS, context));
5342
- }
5343
- includeDestructuredIfNecessary(context, destructuredInitPath, init) {
5344
- if (destructuredInitPath.length > 0 && !this.isDestructuringDeoptimized) {
5345
- this.isDestructuringDeoptimized = true;
5346
- init.deoptimizeArgumentsOnInteractionAtPath({
5347
- args: [new ObjectMember(init, destructuredInitPath.slice(0, -1))],
5348
- type: INTERACTION_ACCESSED
5349
- }, destructuredInitPath, SHARED_RECURSION_TRACKER);
5350
- }
5351
- const { propertyReadSideEffects } = this.scope.context.options
5352
- .treeshake;
5353
- if ((this.included ||=
5354
- destructuredInitPath.length > 0 &&
5355
- !context.brokenFlow &&
5356
- propertyReadSideEffects &&
5357
- (propertyReadSideEffects === 'always' ||
5358
- init.hasEffectsOnInteractionAtPath(destructuredInitPath, NODE_INTERACTION_UNKNOWN_ACCESS, createHasEffectsContext())))) {
5359
- if (this.variable && !this.variable.included) {
5360
- 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}.`);
5361
5126
  }
5362
- init.includePath(destructuredInitPath, context);
5363
- return true;
5364
5127
  }
5365
- return false;
5128
+ return [(this.variable = variable)];
5366
5129
  }
5367
5130
  markDeclarationReached() {
5368
5131
  this.variable.initReached = true;
@@ -5428,17 +5191,18 @@ class Scope {
5428
5191
  - then the variable is still declared in the hoisted outer scope, but the initializer is assigned to the parameter
5429
5192
  - const, let, class, and function except in the cases above cannot redeclare anything
5430
5193
  */
5431
- addDeclaration(identifier, context, init, destructuredInitPath, kind) {
5194
+ addDeclaration(identifier, context, init, kind) {
5432
5195
  const name = identifier.name;
5433
5196
  const existingVariable = this.hoistedVariables?.get(name) || this.variables.get(name);
5434
5197
  if (existingVariable) {
5435
- if (kind === 'var' && existingVariable.kind === 'var') {
5198
+ const existingKind = existingVariable.kind;
5199
+ if (kind === 'var' && existingKind === 'var') {
5436
5200
  existingVariable.addDeclaration(identifier, init);
5437
5201
  return existingVariable;
5438
5202
  }
5439
5203
  context.error(logRedeclarationError(name), identifier.start);
5440
5204
  }
5441
- const newVariable = new LocalVariable(identifier.name, identifier, init, destructuredInitPath, context, kind);
5205
+ const newVariable = new LocalVariable(identifier.name, identifier, init, context, kind);
5442
5206
  this.variables.set(name, newVariable);
5443
5207
  return newVariable;
5444
5208
  }
@@ -5614,6 +5378,7 @@ class MethodBase extends NodeBase {
5614
5378
  }
5615
5379
  return this.getAccessedValue()[0].hasEffectsOnInteractionAtPath(path, interaction, context);
5616
5380
  }
5381
+ applyDeoptimizations() { }
5617
5382
  getAccessedValue() {
5618
5383
  if (this.accessedValue === null) {
5619
5384
  if (this.kind === 'get') {
@@ -5627,20 +5392,19 @@ class MethodBase extends NodeBase {
5627
5392
  return this.accessedValue;
5628
5393
  }
5629
5394
  }
5630
- MethodBase.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
5631
- MethodBase.prototype.applyDeoptimizations = doNotDeoptimize;
5632
5395
 
5633
5396
  class MethodDefinition extends MethodBase {
5634
5397
  hasEffects(context) {
5635
5398
  return super.hasEffects(context) || checkEffectForNodes(this.decorators, context);
5636
5399
  }
5400
+ applyDeoptimizations() { }
5637
5401
  }
5638
5402
 
5639
5403
  class BlockScope extends ChildScope {
5640
5404
  constructor(parent) {
5641
5405
  super(parent, parent.context);
5642
5406
  }
5643
- addDeclaration(identifier, context, init, destructuredInitPath, kind) {
5407
+ addDeclaration(identifier, context, init, kind) {
5644
5408
  if (kind === 'var') {
5645
5409
  const name = identifier.name;
5646
5410
  const existingVariable = this.hoistedVariables?.get(name) || this.variables.get(name);
@@ -5652,7 +5416,7 @@ class BlockScope extends ChildScope {
5652
5416
  }
5653
5417
  return context.error(logRedeclarationError(name), identifier.start);
5654
5418
  }
5655
- const declaredVariable = this.parent.addDeclaration(identifier, context, init, destructuredInitPath, kind);
5419
+ const declaredVariable = this.parent.addDeclaration(identifier, context, init, kind);
5656
5420
  // Necessary to make sure the init is deoptimized for conditional declarations.
5657
5421
  // We cannot call deoptimizePath here.
5658
5422
  declaredVariable.markInitializersForDeoptimization();
@@ -5660,7 +5424,7 @@ class BlockScope extends ChildScope {
5660
5424
  this.addHoistedVariable(name, declaredVariable);
5661
5425
  return declaredVariable;
5662
5426
  }
5663
- return super.addDeclaration(identifier, context, init, destructuredInitPath, kind);
5427
+ return super.addDeclaration(identifier, context, init, kind);
5664
5428
  }
5665
5429
  }
5666
5430
 
@@ -5692,12 +5456,33 @@ class StaticBlock extends NodeBase {
5692
5456
  }
5693
5457
  }
5694
5458
  }
5695
- StaticBlock.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
5696
- StaticBlock.prototype.applyDeoptimizations = doNotDeoptimize;
5697
5459
  function isStaticBlock(statement) {
5698
5460
  return statement.type === StaticBlock$1;
5699
5461
  }
5700
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
+
5701
5486
  class ClassNode extends NodeBase {
5702
5487
  constructor() {
5703
5488
  super(...arguments);
@@ -5738,20 +5523,21 @@ class ClassNode extends NodeBase {
5738
5523
  : this.getObjectEntity().hasEffectsOnInteractionAtPath(path, interaction, context);
5739
5524
  }
5740
5525
  include(context, includeChildrenRecursively) {
5741
- if (!this.included)
5742
- this.includeNode(context);
5526
+ if (!this.deoptimized)
5527
+ this.applyDeoptimizations();
5528
+ this.included = true;
5743
5529
  this.superClass?.include(context, includeChildrenRecursively);
5744
5530
  this.body.include(context, includeChildrenRecursively);
5745
5531
  for (const decorator of this.decorators)
5746
5532
  decorator.include(context, includeChildrenRecursively);
5747
5533
  if (this.id) {
5748
5534
  this.id.markDeclarationReached();
5749
- this.id.include(context);
5535
+ this.id.include();
5750
5536
  }
5751
5537
  }
5752
5538
  initialise() {
5753
5539
  super.initialise();
5754
- this.id?.declare('class', EMPTY_PATH, this);
5540
+ this.id?.declare('class', this);
5755
5541
  for (const method of this.body.body) {
5756
5542
  if (method instanceof MethodDefinition && method.kind === 'constructor') {
5757
5543
  this.classConstructor = method;
@@ -5809,12 +5595,11 @@ class ClassNode extends NodeBase {
5809
5595
  staticProperties.unshift({
5810
5596
  key: 'prototype',
5811
5597
  kind: 'init',
5812
- 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)
5813
5599
  });
5814
5600
  return (this.objectEntity = new ObjectEntity(staticProperties, this.superClass || OBJECT_PROTOTYPE));
5815
5601
  }
5816
5602
  }
5817
- ClassNode.prototype.includeNode = onlyIncludeSelf;
5818
5603
 
5819
5604
  class ClassDeclaration extends ClassNode {
5820
5605
  initialise() {
@@ -5867,7 +5652,7 @@ class ClassDeclaration extends ClassNode {
5867
5652
 
5868
5653
  class ArgumentsVariable extends LocalVariable {
5869
5654
  constructor(context) {
5870
- super('arguments', null, UNKNOWN_EXPRESSION, EMPTY_PATH, context, 'other');
5655
+ super('arguments', null, UNKNOWN_EXPRESSION, context, 'other');
5871
5656
  this.deoptimizedArguments = [];
5872
5657
  }
5873
5658
  addArgumentToBeDeoptimized(argument) {
@@ -5881,8 +5666,8 @@ class ArgumentsVariable extends LocalVariable {
5881
5666
  hasEffectsOnInteractionAtPath(path, { type }) {
5882
5667
  return type !== INTERACTION_ACCESSED || path.length > 1;
5883
5668
  }
5884
- includePath(path, context) {
5885
- super.includePath(path, context);
5669
+ include() {
5670
+ super.include();
5886
5671
  for (const argument of this.deoptimizedArguments) {
5887
5672
  argument.deoptimizePath(UNKNOWN_PATH);
5888
5673
  }
@@ -5893,28 +5678,27 @@ class ArgumentsVariable extends LocalVariable {
5893
5678
  const MAX_TRACKED_INTERACTIONS = 20;
5894
5679
  const NO_INTERACTIONS = EMPTY_ARRAY;
5895
5680
  const UNKNOWN_DEOPTIMIZED_FIELD = new Set([UnknownKey]);
5896
- const EMPTY_PATH_TRACKER = new EntityPathTracker();
5681
+ const EMPTY_PATH_TRACKER = new PathTracker();
5897
5682
  const UNKNOWN_DEOPTIMIZED_ENTITY = new Set([UNKNOWN_EXPRESSION]);
5898
5683
  class ParameterVariable extends LocalVariable {
5899
- constructor(name, declarator, argumentPath, context) {
5900
- super(name, declarator, UNKNOWN_EXPRESSION, argumentPath, context, 'parameter');
5684
+ constructor(name, declarator, context) {
5685
+ super(name, declarator, UNKNOWN_EXPRESSION, context, 'parameter');
5901
5686
  this.deoptimizationInteractions = [];
5902
- this.deoptimizations = new EntityPathTracker();
5687
+ this.deoptimizations = new PathTracker();
5903
5688
  this.deoptimizedFields = new Set();
5904
- this.argumentsToBeDeoptimized = new Set();
5905
- this.expressionsDependingOnKnownValue = [];
5689
+ this.entitiesToBeDeoptimized = new Set();
5690
+ this.expressionsUseTheKnownValue = [];
5906
5691
  this.knownValue = null;
5907
5692
  this.knownValueLiteral = UnknownValue;
5908
5693
  this.frozenValue = null;
5909
5694
  }
5910
- addArgumentValue(entity) {
5911
- this.updateKnownValue(entity);
5695
+ addEntityToBeDeoptimized(entity) {
5912
5696
  if (entity === UNKNOWN_EXPRESSION) {
5913
5697
  // As unknown expressions fully deoptimize all interactions, we can clear
5914
5698
  // the interaction cache at this point provided we keep this optimization
5915
5699
  // in mind when adding new interactions
5916
- if (!this.argumentsToBeDeoptimized.has(UNKNOWN_EXPRESSION)) {
5917
- this.argumentsToBeDeoptimized.add(UNKNOWN_EXPRESSION);
5700
+ if (!this.entitiesToBeDeoptimized.has(UNKNOWN_EXPRESSION)) {
5701
+ this.entitiesToBeDeoptimized.add(UNKNOWN_EXPRESSION);
5918
5702
  for (const { interaction } of this.deoptimizationInteractions) {
5919
5703
  deoptimizeInteraction(interaction);
5920
5704
  }
@@ -5924,34 +5708,27 @@ class ParameterVariable extends LocalVariable {
5924
5708
  else if (this.deoptimizedFields.has(UnknownKey)) {
5925
5709
  // This means that we already deoptimized all interactions and no longer
5926
5710
  // track them
5927
- entity.deoptimizePath([...this.initPath, UnknownKey]);
5711
+ entity.deoptimizePath(UNKNOWN_PATH);
5928
5712
  }
5929
- else if (!this.argumentsToBeDeoptimized.has(entity)) {
5930
- this.argumentsToBeDeoptimized.add(entity);
5713
+ else if (!this.entitiesToBeDeoptimized.has(entity)) {
5714
+ this.entitiesToBeDeoptimized.add(entity);
5931
5715
  for (const field of this.deoptimizedFields) {
5932
- entity.deoptimizePath([...this.initPath, field]);
5716
+ entity.deoptimizePath([field]);
5933
5717
  }
5934
5718
  for (const { interaction, path } of this.deoptimizationInteractions) {
5935
- if (this.initPath.length + path.length > MAX_PATH_DEPTH) {
5936
- deoptimizeInteraction(interaction);
5937
- continue;
5938
- }
5939
- entity.deoptimizeArgumentsOnInteractionAtPath(interaction, [...this.initPath, ...path], SHARED_RECURSION_TRACKER);
5719
+ entity.deoptimizeArgumentsOnInteractionAtPath(interaction, path, SHARED_RECURSION_TRACKER);
5940
5720
  }
5941
5721
  }
5942
5722
  }
5943
- /** This says we should not make assumptions about the value of the parameter.
5944
- * This is different from deoptimization that will also cause argument values
5945
- * to be deoptimized. */
5946
5723
  markReassigned() {
5947
5724
  if (this.isReassigned) {
5948
5725
  return;
5949
5726
  }
5950
5727
  super.markReassigned();
5951
- for (const expression of this.expressionsDependingOnKnownValue) {
5728
+ for (const expression of this.expressionsUseTheKnownValue) {
5952
5729
  expression.deoptimizeCache();
5953
5730
  }
5954
- this.expressionsDependingOnKnownValue = EMPTY_ARRAY;
5731
+ this.expressionsUseTheKnownValue = EMPTY_ARRAY;
5955
5732
  }
5956
5733
  deoptimizeCache() {
5957
5734
  this.markReassigned();
@@ -5968,7 +5745,7 @@ class ParameterVariable extends LocalVariable {
5968
5745
  }
5969
5746
  if (this.knownValue === null) {
5970
5747
  this.knownValue = argument;
5971
- this.knownValueLiteral = argument.getLiteralValueAtPath(this.initPath, SHARED_RECURSION_TRACKER, this);
5748
+ this.knownValueLiteral = argument.getLiteralValueAtPath(EMPTY_PATH, SHARED_RECURSION_TRACKER, this);
5972
5749
  return;
5973
5750
  }
5974
5751
  // the same literal or identifier, do nothing
@@ -5984,7 +5761,7 @@ class ParameterVariable extends LocalVariable {
5984
5761
  return;
5985
5762
  }
5986
5763
  // add tracking for the new argument
5987
- const newValue = argument.getLiteralValueAtPath(this.initPath, SHARED_RECURSION_TRACKER, this);
5764
+ const newValue = argument.getLiteralValueAtPath(EMPTY_PATH, SHARED_RECURSION_TRACKER, this);
5988
5765
  if (newValue !== oldValue) {
5989
5766
  this.markReassigned();
5990
5767
  }
@@ -6002,31 +5779,24 @@ class ParameterVariable extends LocalVariable {
6002
5779
  return this.frozenValue;
6003
5780
  }
6004
5781
  getLiteralValueAtPath(path, recursionTracker, origin) {
6005
- if (this.isReassigned || path.length + this.initPath.length > MAX_PATH_DEPTH) {
5782
+ if (this.isReassigned) {
6006
5783
  return UnknownValue;
6007
5784
  }
6008
5785
  const knownValue = this.getKnownValue();
6009
- this.expressionsDependingOnKnownValue.push(origin);
6010
- 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);
6011
5788
  }
6012
5789
  hasEffectsOnInteractionAtPath(path, interaction, context) {
6013
- const { type } = interaction;
6014
- if (this.isReassigned ||
6015
- type === INTERACTION_ASSIGNED ||
6016
- path.length + this.initPath.length > MAX_PATH_DEPTH) {
5790
+ if (this.isReassigned || interaction.type === INTERACTION_ASSIGNED) {
6017
5791
  return super.hasEffectsOnInteractionAtPath(path, interaction, context);
6018
5792
  }
6019
- return (!(type === INTERACTION_CALLED
6020
- ? (interaction.withNew
6021
- ? context.instantiated
6022
- : context.called).trackEntityAtPathAndGetIfTracked(path, interaction.args, this)
6023
- : context.accessed.trackEntityAtPathAndGetIfTracked(path, this)) &&
6024
- this.getKnownValue().hasEffectsOnInteractionAtPath([...this.initPath, ...path], interaction, context));
5793
+ const knownValue = this.getKnownValue();
5794
+ return knownValue.hasEffectsOnInteractionAtPath(path, interaction, context);
6025
5795
  }
6026
5796
  deoptimizeArgumentsOnInteractionAtPath(interaction, path) {
6027
5797
  // For performance reasons, we fully deoptimize all deeper interactions
6028
5798
  if (path.length >= 2 ||
6029
- this.argumentsToBeDeoptimized.has(UNKNOWN_EXPRESSION) ||
5799
+ this.entitiesToBeDeoptimized.has(UNKNOWN_EXPRESSION) ||
6030
5800
  this.deoptimizationInteractions.length >= MAX_TRACKED_INTERACTIONS ||
6031
5801
  (path.length === 1 &&
6032
5802
  (this.deoptimizedFields.has(UnknownKey) ||
@@ -6035,10 +5805,10 @@ class ParameterVariable extends LocalVariable {
6035
5805
  return;
6036
5806
  }
6037
5807
  if (!this.deoptimizations.trackEntityAtPathAndGetIfTracked(path, interaction.args)) {
6038
- for (const entity of this.argumentsToBeDeoptimized) {
6039
- entity.deoptimizeArgumentsOnInteractionAtPath(interaction, [...this.initPath, ...path], SHARED_RECURSION_TRACKER);
5808
+ for (const entity of this.entitiesToBeDeoptimized) {
5809
+ entity.deoptimizeArgumentsOnInteractionAtPath(interaction, path, SHARED_RECURSION_TRACKER);
6040
5810
  }
6041
- if (!this.argumentsToBeDeoptimized.has(UNKNOWN_EXPRESSION)) {
5811
+ if (!this.entitiesToBeDeoptimized.has(UNKNOWN_EXPRESSION)) {
6042
5812
  this.deoptimizationInteractions.push({
6043
5813
  interaction,
6044
5814
  path
@@ -6059,17 +5829,17 @@ class ParameterVariable extends LocalVariable {
6059
5829
  return;
6060
5830
  }
6061
5831
  this.deoptimizedFields.add(key);
6062
- for (const entity of this.argumentsToBeDeoptimized) {
5832
+ for (const entity of this.entitiesToBeDeoptimized) {
6063
5833
  // We do not need a recursion tracker here as we already track whether
6064
5834
  // this field is deoptimized
6065
- entity.deoptimizePath([...this.initPath, key]);
5835
+ entity.deoptimizePath([key]);
6066
5836
  }
6067
5837
  if (key === UnknownKey) {
6068
5838
  // save some memory
6069
5839
  this.deoptimizationInteractions = NO_INTERACTIONS;
6070
5840
  this.deoptimizations = EMPTY_PATH_TRACKER;
6071
5841
  this.deoptimizedFields = UNKNOWN_DEOPTIMIZED_FIELD;
6072
- this.argumentsToBeDeoptimized = UNKNOWN_DEOPTIMIZED_ENTITY;
5842
+ this.entitiesToBeDeoptimized = UNKNOWN_DEOPTIMIZED_ENTITY;
6073
5843
  }
6074
5844
  }
6075
5845
  getReturnExpressionWhenCalledAtPath(path) {
@@ -6084,14 +5854,11 @@ class ParameterVariable extends LocalVariable {
6084
5854
  }
6085
5855
  return UNKNOWN_RETURN_EXPRESSION;
6086
5856
  }
6087
- includeArgumentPaths(entity, context) {
6088
- this.includedPathTracker.includeAllPaths(entity, context, this.initPath);
6089
- }
6090
5857
  }
6091
5858
 
6092
5859
  class ThisVariable extends ParameterVariable {
6093
5860
  constructor(context) {
6094
- super('this', null, EMPTY_PATH, context);
5861
+ super('this', null, context);
6095
5862
  }
6096
5863
  hasEffectsOnInteractionAtPath(path, interaction, context) {
6097
5864
  return (context.replacedVariableInits.get(this) || UNKNOWN_EXPRESSION).hasEffectsOnInteractionAtPath(path, interaction, context);
@@ -6103,7 +5870,7 @@ class CatchBodyScope extends ChildScope {
6103
5870
  super(parent, parent.context);
6104
5871
  this.parent = parent;
6105
5872
  }
6106
- addDeclaration(identifier, context, init, destructuredInitPath, kind) {
5873
+ addDeclaration(identifier, context, init, kind) {
6107
5874
  if (kind === 'var') {
6108
5875
  const name = identifier.name;
6109
5876
  const existingVariable = this.hoistedVariables?.get(name) || this.variables.get(name);
@@ -6116,7 +5883,7 @@ class CatchBodyScope extends ChildScope {
6116
5883
  // the assignment actually goes to the parameter and the var is
6117
5884
  // hoisted without assignment. Locally, it is shadowed by the
6118
5885
  // parameter
6119
- const declaredVariable = this.parent.parent.addDeclaration(identifier, context, UNDEFINED_EXPRESSION, destructuredInitPath, kind);
5886
+ const declaredVariable = this.parent.parent.addDeclaration(identifier, context, UNDEFINED_EXPRESSION, kind);
6120
5887
  // To avoid the need to rewrite the declaration, we link the variable
6121
5888
  // names. If we ever implement a logic that splits initialization and
6122
5889
  // assignment for hoisted vars, the "renderLikeHoisted" logic can be
@@ -6135,7 +5902,7 @@ class CatchBodyScope extends ChildScope {
6135
5902
  return context.error(logRedeclarationError(name), identifier.start);
6136
5903
  }
6137
5904
  // We only add parameters to parameter scopes
6138
- const declaredVariable = this.parent.parent.addDeclaration(identifier, context, init, destructuredInitPath, kind);
5905
+ const declaredVariable = this.parent.parent.addDeclaration(identifier, context, init, kind);
6139
5906
  // Necessary to make sure the init is deoptimized for conditional declarations.
6140
5907
  // We cannot call deoptimizePath here.
6141
5908
  declaredVariable.markInitializersForDeoptimization();
@@ -6143,7 +5910,7 @@ class CatchBodyScope extends ChildScope {
6143
5910
  this.addHoistedVariable(name, declaredVariable);
6144
5911
  return declaredVariable;
6145
5912
  }
6146
- return super.addDeclaration(identifier, context, init, destructuredInitPath, kind);
5913
+ return super.addDeclaration(identifier, context, init, kind);
6147
5914
  }
6148
5915
  }
6149
5916
 
@@ -6153,7 +5920,7 @@ class FunctionBodyScope extends ChildScope {
6153
5920
  }
6154
5921
  // There is stuff that is only allowed in function scopes, i.e. functions can
6155
5922
  // be redeclared, functions and var can redeclare each other
6156
- addDeclaration(identifier, context, init, destructuredInitPath, kind) {
5923
+ addDeclaration(identifier, context, init, kind) {
6157
5924
  const name = identifier.name;
6158
5925
  const existingVariable = this.hoistedVariables?.get(name) || this.variables.get(name);
6159
5926
  if (existingVariable) {
@@ -6165,7 +5932,7 @@ class FunctionBodyScope extends ChildScope {
6165
5932
  }
6166
5933
  context.error(logRedeclarationError(name), identifier.start);
6167
5934
  }
6168
- const newVariable = new LocalVariable(identifier.name, identifier, init, destructuredInitPath, context, kind);
5935
+ const newVariable = new LocalVariable(identifier.name, identifier, init, context, kind);
6169
5936
  this.variables.set(name, newVariable);
6170
5937
  return newVariable;
6171
5938
  }
@@ -6174,21 +5941,21 @@ class FunctionBodyScope extends ChildScope {
6174
5941
  class ParameterScope extends ChildScope {
6175
5942
  constructor(parent, isCatchScope) {
6176
5943
  super(parent, parent.context);
6177
- this.hasRest = false;
6178
5944
  this.parameters = [];
5945
+ this.hasRest = false;
6179
5946
  this.bodyScope = isCatchScope ? new CatchBodyScope(this) : new FunctionBodyScope(this);
6180
5947
  }
6181
5948
  /**
6182
5949
  * Adds a parameter to this scope. Parameters must be added in the correct
6183
5950
  * order, i.e. from left to right.
6184
5951
  */
6185
- addParameterDeclaration(identifier, argumentPath) {
5952
+ addParameterDeclaration(identifier) {
6186
5953
  const { name, start } = identifier;
6187
5954
  const existingParameter = this.variables.get(name);
6188
5955
  if (existingParameter) {
6189
5956
  return this.context.error(logDuplicateArgumentNameError(name), start);
6190
5957
  }
6191
- const variable = new ParameterVariable(name, identifier, argumentPath, this.context);
5958
+ const variable = new ParameterVariable(name, identifier, this.context);
6192
5959
  this.variables.set(name, variable);
6193
5960
  // We also add it to the body scope to detect name conflicts with local
6194
5961
  // variables. We still need the intermediate scope, though, as parameter
@@ -6206,56 +5973,42 @@ class ParameterScope extends ChildScope {
6206
5973
  }
6207
5974
  this.hasRest = hasRest;
6208
5975
  }
6209
- includeCallArguments(context, interaction) {
5976
+ includeCallArguments(context, parameters) {
6210
5977
  let calledFromTryStatement = false;
6211
5978
  let argumentIncluded = false;
6212
5979
  const restParameter = this.hasRest && this.parameters[this.parameters.length - 1];
6213
- const { args } = interaction;
6214
- let lastExplicitlyIncludedIndex = args.length - 1;
6215
- // If there is a SpreadElement, we need to include all arguments after it
6216
- // because we no longer know which argument corresponds to which parameter.
6217
- for (let argumentIndex = 1; argumentIndex < args.length; argumentIndex++) {
6218
- const argument = args[argumentIndex];
6219
- if (argument instanceof SpreadElement && !argumentIncluded) {
6220
- argumentIncluded = true;
6221
- lastExplicitlyIncludedIndex = argumentIndex - 1;
6222
- }
6223
- if (argumentIncluded) {
6224
- argument.includePath(UNKNOWN_PATH, context);
6225
- 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;
6226
5986
  }
6227
5987
  }
6228
- // Now we go backwards either starting from the last argument or before the
6229
- // first SpreadElement to ensure all arguments before are included as needed
6230
- for (let index = lastExplicitlyIncludedIndex; index >= 1; index--) {
6231
- const parameterVariables = this.parameters[index - 1] || restParameter;
6232
- 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];
6233
5991
  if (parameterVariables) {
6234
5992
  calledFromTryStatement = false;
6235
5993
  if (parameterVariables.length === 0) {
6236
- // handle empty destructuring to avoid destructuring undefined
5994
+ // handle empty destructuring
6237
5995
  argumentIncluded = true;
6238
5996
  }
6239
5997
  else {
6240
5998
  for (const variable of parameterVariables) {
6241
- if (variable.calledFromTryStatement) {
6242
- calledFromTryStatement = true;
6243
- }
6244
5999
  if (variable.included) {
6245
6000
  argumentIncluded = true;
6246
- if (calledFromTryStatement) {
6247
- argument.include(context, true);
6248
- }
6249
- else {
6250
- variable.includeArgumentPaths(argument, context);
6251
- argument.include(context, false);
6252
- }
6001
+ }
6002
+ if (variable.calledFromTryStatement) {
6003
+ calledFromTryStatement = true;
6253
6004
  }
6254
6005
  }
6255
6006
  }
6256
6007
  }
6257
- if (!argument.included && (argumentIncluded || argument.shouldBeIncluded(context))) {
6008
+ if (!argumentIncluded && argument.shouldBeIncluded(context)) {
6258
6009
  argumentIncluded = true;
6010
+ }
6011
+ if (argumentIncluded) {
6259
6012
  argument.include(context, calledFromTryStatement);
6260
6013
  }
6261
6014
  }
@@ -6271,62 +6024,11 @@ class ReturnValueScope extends ParameterScope {
6271
6024
  addReturnExpression(expression) {
6272
6025
  this.returnExpressions.push(expression);
6273
6026
  }
6274
- deoptimizeArgumentsOnCall(interaction) {
6275
- const { parameters } = this;
6276
- const { args } = interaction;
6277
- let position = 0;
6278
- for (; position < args.length - 1; position++) {
6279
- // Only the "this" argument arg[0] can be null
6280
- const argument = args[position + 1];
6281
- if (argument instanceof SpreadElement) {
6282
- // This deoptimizes the current and remaining parameters and arguments
6283
- for (; position < parameters.length; position++) {
6284
- args[position + 1]?.deoptimizePath(UNKNOWN_PATH);
6285
- parameters[position].forEach(variable => variable.markReassigned());
6286
- }
6287
- break;
6288
- }
6289
- if (this.hasRest && position >= parameters.length - 1) {
6290
- argument.deoptimizePath(UNKNOWN_PATH);
6291
- }
6292
- else {
6293
- const variables = parameters[position];
6294
- if (variables) {
6295
- for (const variable of variables) {
6296
- variable.addArgumentValue(argument);
6297
- }
6298
- }
6299
- this.addArgumentToBeDeoptimized(argument);
6300
- }
6301
- }
6302
- const nonRestParameterLength = this.hasRest ? parameters.length - 1 : parameters.length;
6303
- for (; position < nonRestParameterLength; position++) {
6304
- for (const variable of parameters[position]) {
6305
- variable.addArgumentValue(UNDEFINED_EXPRESSION);
6306
- }
6307
- }
6308
- }
6309
6027
  getReturnExpression() {
6310
6028
  if (this.returnExpression === null)
6311
6029
  this.updateReturnExpression();
6312
6030
  return this.returnExpression;
6313
6031
  }
6314
- deoptimizeAllParameters() {
6315
- for (const parameter of this.parameters) {
6316
- for (const variable of parameter) {
6317
- variable.deoptimizePath(UNKNOWN_PATH);
6318
- variable.markReassigned();
6319
- }
6320
- }
6321
- }
6322
- reassignAllParameters() {
6323
- for (const parameter of this.parameters) {
6324
- for (const variable of parameter) {
6325
- variable.markReassigned();
6326
- }
6327
- }
6328
- }
6329
- addArgumentToBeDeoptimized(_argument) { }
6330
6032
  updateReturnExpression() {
6331
6033
  if (this.returnExpressions.length === 1) {
6332
6034
  this.returnExpression = this.returnExpressions[0];
@@ -6342,30 +6044,24 @@ class ReturnValueScope extends ParameterScope {
6342
6044
 
6343
6045
  class FunctionScope extends ReturnValueScope {
6344
6046
  constructor(parent) {
6345
- super(parent, false);
6346
6047
  const { context } = parent;
6048
+ super(parent, false);
6347
6049
  this.variables.set('arguments', (this.argumentsVariable = new ArgumentsVariable(context)));
6348
6050
  this.variables.set('this', (this.thisVariable = new ThisVariable(context)));
6349
6051
  }
6350
6052
  findLexicalBoundary() {
6351
6053
  return this;
6352
6054
  }
6353
- includeCallArguments(context, interaction) {
6354
- super.includeCallArguments(context, interaction);
6055
+ includeCallArguments(context, parameters) {
6056
+ super.includeCallArguments(context, parameters);
6355
6057
  if (this.argumentsVariable.included) {
6356
- const { args } = interaction;
6357
- for (let argumentIndex = 1; argumentIndex < args.length; argumentIndex++) {
6358
- const argument = args[argumentIndex];
6359
- if (argument) {
6360
- argument.includePath(UNKNOWN_PATH, context);
6058
+ for (const argument of parameters) {
6059
+ if (!argument.included) {
6361
6060
  argument.include(context, false);
6362
6061
  }
6363
6062
  }
6364
6063
  }
6365
6064
  }
6366
- addArgumentToBeDeoptimized(argument) {
6367
- this.argumentsVariable.addArgumentToBeDeoptimized(argument);
6368
- }
6369
6065
  }
6370
6066
 
6371
6067
  class ExpressionStatement extends NodeBase {
@@ -6393,9 +6089,8 @@ class ExpressionStatement extends NodeBase {
6393
6089
  return this.parent.type !== Program$1;
6394
6090
  return super.shouldBeIncluded(context);
6395
6091
  }
6092
+ applyDeoptimizations() { }
6396
6093
  }
6397
- ExpressionStatement.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
6398
- ExpressionStatement.prototype.applyDeoptimizations = doNotDeoptimize;
6399
6094
 
6400
6095
  class BlockStatement extends NodeBase {
6401
6096
  get deoptimizeBody() {
@@ -6460,8 +6155,6 @@ class BlockStatement extends NodeBase {
6460
6155
  }
6461
6156
  }
6462
6157
  }
6463
- BlockStatement.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
6464
- BlockStatement.prototype.applyDeoptimizations = doNotDeoptimize;
6465
6158
 
6466
6159
  class RestElement extends NodeBase {
6467
6160
  constructor() {
@@ -6471,12 +6164,9 @@ class RestElement extends NodeBase {
6471
6164
  addExportedVariables(variables, exportNamesByVariable) {
6472
6165
  this.argument.addExportedVariables(variables, exportNamesByVariable);
6473
6166
  }
6474
- declare(kind, destructuredInitPath, init) {
6167
+ declare(kind, init) {
6475
6168
  this.declarationInit = init;
6476
- return this.argument.declare(kind, getIncludedPatternPath$1(destructuredInitPath), init);
6477
- }
6478
- deoptimizeAssignment(destructuredInitPath, init) {
6479
- this.argument.deoptimizeAssignment(getIncludedPatternPath$1(destructuredInitPath), init);
6169
+ return this.argument.declare(kind, UNKNOWN_EXPRESSION);
6480
6170
  }
6481
6171
  deoptimizePath(path) {
6482
6172
  if (path.length === 0) {
@@ -6487,20 +6177,6 @@ class RestElement extends NodeBase {
6487
6177
  return (path.length > 0 ||
6488
6178
  this.argument.hasEffectsOnInteractionAtPath(EMPTY_PATH, interaction, context));
6489
6179
  }
6490
- hasEffectsWhenDestructuring(context, destructuredInitPath, init) {
6491
- return this.argument.hasEffectsWhenDestructuring(context, getIncludedPatternPath$1(destructuredInitPath), init);
6492
- }
6493
- includeDestructuredIfNecessary(context, destructuredInitPath, init) {
6494
- return (this.included =
6495
- this.argument.includeDestructuredIfNecessary(context, getIncludedPatternPath$1(destructuredInitPath), init) || this.included);
6496
- }
6497
- include(context, includeChildrenRecursively) {
6498
- if (!this.included)
6499
- this.includeNode(context);
6500
- // This should just include the identifier, its properties should be
6501
- // included where the variable is used.
6502
- this.argument.include(context, includeChildrenRecursively);
6503
- }
6504
6180
  markDeclarationReached() {
6505
6181
  this.argument.markDeclarationReached();
6506
6182
  }
@@ -6512,16 +6188,12 @@ class RestElement extends NodeBase {
6512
6188
  }
6513
6189
  }
6514
6190
  }
6515
- RestElement.prototype.includeNode = onlyIncludeSelf;
6516
- const getIncludedPatternPath$1 = (destructuredInitPath) => destructuredInitPath.at(-1) === UnknownKey
6517
- ? destructuredInitPath
6518
- : [...destructuredInitPath, UnknownKey];
6519
6191
 
6520
6192
  class FunctionBase extends NodeBase {
6521
6193
  constructor() {
6522
6194
  super(...arguments);
6195
+ this.objectEntity = null;
6523
6196
  this.parameterVariableValuesDeoptimized = false;
6524
- this.includeCallArguments = this.scope.includeCallArguments.bind(this.scope);
6525
6197
  }
6526
6198
  get async() {
6527
6199
  return isFlagSet(this.flags, 256 /* Flag.async */);
@@ -6541,9 +6213,53 @@ class FunctionBase extends NodeBase {
6541
6213
  set generator(value) {
6542
6214
  this.flags = setFlag(this.flags, 4194304 /* Flag.generator */, value);
6543
6215
  }
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
+ }
6226
+ }
6227
+ deoptimizeParameterVariableValues() {
6228
+ for (const parameter of this.params) {
6229
+ if (parameter instanceof Identifier) {
6230
+ const parameterVariable = parameter.variable;
6231
+ parameterVariable.markReassigned();
6232
+ }
6233
+ }
6234
+ }
6544
6235
  deoptimizeArgumentsOnInteractionAtPath(interaction, path, recursionTracker) {
6545
- if (interaction.type === INTERACTION_CALLED && path.length === 0) {
6546
- 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);
6547
6263
  }
6548
6264
  else {
6549
6265
  this.getObjectEntity().deoptimizeArgumentsOnInteractionAtPath(interaction, path, recursionTracker);
@@ -6555,7 +6271,12 @@ class FunctionBase extends NodeBase {
6555
6271
  // A reassignment of UNKNOWN_PATH is considered equivalent to having lost track
6556
6272
  // which means the return expression and parameters need to be reassigned
6557
6273
  this.scope.getReturnExpression().deoptimizePath(UNKNOWN_PATH);
6558
- 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
+ }
6559
6280
  }
6560
6281
  }
6561
6282
  getLiteralValueAtPath(path, recursionTracker, origin) {
@@ -6593,13 +6314,8 @@ class FunctionBase extends NodeBase {
6593
6314
  return true;
6594
6315
  }
6595
6316
  }
6596
- const { propertyReadSideEffects } = this.scope.context.options
6597
- .treeshake;
6598
- for (let index = 0; index < this.params.length; index++) {
6599
- const parameter = this.params[index];
6600
- if (parameter.hasEffects(context) ||
6601
- (propertyReadSideEffects &&
6602
- parameter.hasEffectsWhenDestructuring(context, EMPTY_PATH, interaction.args[index + 1] || UNDEFINED_EXPRESSION)))
6317
+ for (const parameter of this.params) {
6318
+ if (parameter.hasEffects(context))
6603
6319
  return true;
6604
6320
  }
6605
6321
  return false;
@@ -6618,17 +6334,21 @@ class FunctionBase extends NodeBase {
6618
6334
  return variable?.getOnlyFunctionCallUsed() ?? false;
6619
6335
  }
6620
6336
  include(context, includeChildrenRecursively) {
6621
- if (!this.included)
6622
- this.includeNode(context);
6623
- if (!(this.parameterVariableValuesDeoptimized || this.onlyFunctionCallUsed())) {
6337
+ if (!this.parameterVariableValuesDeoptimized && !this.onlyFunctionCallUsed()) {
6624
6338
  this.parameterVariableValuesDeoptimized = true;
6625
- this.scope.reassignAllParameters();
6339
+ this.deoptimizeParameterVariableValues();
6626
6340
  }
6341
+ if (!this.deoptimized)
6342
+ this.applyDeoptimizations();
6343
+ this.included = true;
6627
6344
  const { brokenFlow } = context;
6628
6345
  context.brokenFlow = false;
6629
6346
  this.body.include(context, includeChildrenRecursively);
6630
6347
  context.brokenFlow = brokenFlow;
6631
6348
  }
6349
+ includeCallArguments(context, parameters) {
6350
+ this.scope.includeCallArguments(context, parameters);
6351
+ }
6632
6352
  initialise() {
6633
6353
  super.initialise();
6634
6354
  if (this.body instanceof BlockStatement) {
@@ -6650,14 +6370,14 @@ class FunctionBase extends NodeBase {
6650
6370
  // so that the scope already knows all parameters and can detect conflicts
6651
6371
  // when parsing the body.
6652
6372
  const parameters = (this.params = params.map((parameter) => new (context.getNodeConstructor(parameter.type))(this, scope).parseNode(parameter)));
6653
- 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);
6654
6374
  this.body = new (context.getNodeConstructor(body.type))(this, bodyScope).parseNode(body);
6655
6375
  return super.parseNode(esTreeNode);
6656
6376
  }
6377
+ addArgumentToBeDeoptimized(_argument) { }
6378
+ applyDeoptimizations() { }
6657
6379
  }
6658
6380
  FunctionBase.prototype.preventChildBlockScope = true;
6659
- FunctionBase.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
6660
- FunctionBase.prototype.applyDeoptimizations = doNotDeoptimize;
6661
6381
 
6662
6382
  class FunctionNode extends FunctionBase {
6663
6383
  constructor() {
@@ -6669,16 +6389,18 @@ class FunctionNode extends FunctionBase {
6669
6389
  this.constructedEntity = new ObjectEntity(Object.create(null), OBJECT_PROTOTYPE);
6670
6390
  // This makes sure that all deoptimizations of "this" are applied to the
6671
6391
  // constructed entity.
6672
- this.scope.thisVariable.addArgumentValue(this.constructedEntity);
6392
+ this.scope.thisVariable.addEntityToBeDeoptimized(this.constructedEntity);
6673
6393
  }
6674
6394
  deoptimizeArgumentsOnInteractionAtPath(interaction, path, recursionTracker) {
6675
6395
  super.deoptimizeArgumentsOnInteractionAtPath(interaction, path, recursionTracker);
6676
6396
  if (interaction.type === INTERACTION_CALLED && path.length === 0 && interaction.args[0]) {
6677
6397
  // args[0] is the "this" argument
6678
- this.scope.thisVariable.addArgumentValue(interaction.args[0]);
6398
+ this.scope.thisVariable.addEntityToBeDeoptimized(interaction.args[0]);
6679
6399
  }
6680
6400
  }
6681
6401
  hasEffects(context) {
6402
+ if (!this.deoptimized)
6403
+ this.applyDeoptimizations();
6682
6404
  if (this.annotationNoSideEffects) {
6683
6405
  return false;
6684
6406
  }
@@ -6716,7 +6438,7 @@ class FunctionNode extends FunctionBase {
6716
6438
  }
6717
6439
  include(context, includeChildrenRecursively) {
6718
6440
  super.include(context, includeChildrenRecursively);
6719
- this.id?.include(context);
6441
+ this.id?.include();
6720
6442
  const hasArguments = this.scope.argumentsVariable.included;
6721
6443
  for (const parameter of this.params) {
6722
6444
  if (!(parameter instanceof Identifier) || hasArguments) {
@@ -6724,18 +6446,12 @@ class FunctionNode extends FunctionBase {
6724
6446
  }
6725
6447
  }
6726
6448
  }
6727
- includeNode(context) {
6728
- this.included = true;
6729
- const hasArguments = this.scope.argumentsVariable.included;
6730
- for (const parameter of this.params) {
6731
- if (!(parameter instanceof Identifier) || hasArguments) {
6732
- parameter.includePath(UNKNOWN_PATH, context);
6733
- }
6734
- }
6735
- }
6736
6449
  initialise() {
6737
6450
  super.initialise();
6738
- this.id?.declare('function', EMPTY_PATH, this);
6451
+ this.id?.declare('function', this);
6452
+ }
6453
+ addArgumentToBeDeoptimized(argument) {
6454
+ this.scope.argumentsVariable.addArgumentToBeDeoptimized(argument);
6739
6455
  }
6740
6456
  getObjectEntity() {
6741
6457
  if (this.objectEntity !== null) {
@@ -6785,16 +6501,11 @@ function getFunctionIdInsertPosition(code, start) {
6785
6501
  }
6786
6502
  class ExportDefaultDeclaration extends NodeBase {
6787
6503
  include(context, includeChildrenRecursively) {
6788
- this.included = true;
6789
- this.declaration.include(context, includeChildrenRecursively);
6504
+ super.include(context, includeChildrenRecursively);
6790
6505
  if (includeChildrenRecursively) {
6791
- this.scope.context.includeVariableInModule(this.variable, UNKNOWN_PATH, context);
6506
+ this.scope.context.includeVariableInModule(this.variable);
6792
6507
  }
6793
6508
  }
6794
- includePath(path, context) {
6795
- this.included = true;
6796
- this.declaration.includePath(path, context);
6797
- }
6798
6509
  initialise() {
6799
6510
  super.initialise();
6800
6511
  const declaration = this.declaration;
@@ -6839,6 +6550,7 @@ class ExportDefaultDeclaration extends NodeBase {
6839
6550
  }
6840
6551
  this.declaration.render(code, options);
6841
6552
  }
6553
+ applyDeoptimizations() { }
6842
6554
  renderNamedDeclaration(code, declarationStart, idInsertPosition, options) {
6843
6555
  const { exportNamesByVariable, format, snippets: { getPropertyAccess } } = options;
6844
6556
  const name = this.variable.getName(getPropertyAccess);
@@ -6869,8 +6581,6 @@ class ExportDefaultDeclaration extends NodeBase {
6869
6581
  }
6870
6582
  }
6871
6583
  ExportDefaultDeclaration.prototype.needsBoundaries = true;
6872
- ExportDefaultDeclaration.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
6873
- ExportDefaultDeclaration.prototype.applyDeoptimizations = doNotDeoptimize;
6874
6584
 
6875
6585
  const needsEscapeRegEx = /[\n\r'\\\u2028\u2029]/;
6876
6586
  const quoteNewlineRegEx = /([\n\r'\u2028\u2029])/g;
@@ -7140,7 +6850,6 @@ class Literal extends NodeBase {
7140
6850
  }
7141
6851
  }
7142
6852
  }
7143
- Literal.prototype.includeNode = onlyIncludeSelf;
7144
6853
 
7145
6854
  function getChainElementLiteralValueAtPath(element, object, path, recursionTracker, origin) {
7146
6855
  if ('getLiteralValueAtPathAsChainElement' in object) {
@@ -7156,6 +6865,8 @@ function getChainElementLiteralValueAtPath(element, object, path, recursionTrack
7156
6865
  return element.getLiteralValueAtPath(path, recursionTracker, origin);
7157
6866
  }
7158
6867
 
6868
+ // To avoid infinite recursions
6869
+ const MAX_PATH_DEPTH = 7;
7159
6870
  function getResolvablePropertyKey(memberExpression) {
7160
6871
  return memberExpression.computed
7161
6872
  ? getResolvableComputedPropertyKey(memberExpression.property)
@@ -7254,27 +6965,18 @@ class MemberExpression extends NodeBase {
7254
6965
  }
7255
6966
  else if (!this.isUndefined) {
7256
6967
  if (path.length < MAX_PATH_DEPTH) {
7257
- this.object.deoptimizeArgumentsOnInteractionAtPath(interaction, this.propertyKey === UnknownKey ? UNKNOWN_PATH : [this.propertyKey, ...path], recursionTracker);
6968
+ this.object.deoptimizeArgumentsOnInteractionAtPath(interaction, [this.getPropertyKey(), ...path], recursionTracker);
7258
6969
  }
7259
6970
  else {
7260
6971
  deoptimizeInteraction(interaction);
7261
6972
  }
7262
6973
  }
7263
6974
  }
7264
- deoptimizeAssignment(destructuredInitPath, init) {
7265
- this.deoptimizePath(EMPTY_PATH);
7266
- init.deoptimizePath([...destructuredInitPath, UnknownKey]);
7267
- }
7268
6975
  deoptimizeCache() {
7269
- if (this.propertyKey === this.dynamicPropertyKey)
7270
- return;
7271
6976
  const { expressionsToBeDeoptimized, object } = this;
7272
6977
  this.expressionsToBeDeoptimized = EMPTY_ARRAY;
7273
- this.dynamicPropertyKey = this.propertyKey;
6978
+ this.propertyKey = UnknownKey;
7274
6979
  object.deoptimizePath(UNKNOWN_PATH);
7275
- if (this.included) {
7276
- object.includePath(UNKNOWN_PATH, createInclusionContext());
7277
- }
7278
6980
  for (const expression of expressionsToBeDeoptimized) {
7279
6981
  expression.deoptimizeCache();
7280
6982
  }
@@ -7285,13 +6987,11 @@ class MemberExpression extends NodeBase {
7285
6987
  if (this.variable) {
7286
6988
  this.variable.deoptimizePath(path);
7287
6989
  }
7288
- else if (!this.isUndefined) {
7289
- const { propertyKey } = this;
6990
+ else if (!this.isUndefined && path.length < MAX_PATH_DEPTH) {
6991
+ const propertyKey = this.getPropertyKey();
7290
6992
  this.object.deoptimizePath([
7291
6993
  propertyKey === UnknownKey ? UnknownNonAccessorKey : propertyKey,
7292
- ...(path.length < MAX_PATH_DEPTH
7293
- ? path
7294
- : [...path.slice(0, MAX_PATH_DEPTH), UnknownKey])
6994
+ ...path
7295
6995
  ]);
7296
6996
  }
7297
6997
  }
@@ -7302,11 +7002,9 @@ class MemberExpression extends NodeBase {
7302
7002
  if (this.isUndefined) {
7303
7003
  return undefined;
7304
7004
  }
7305
- const propertyKey = this.getDynamicPropertyKey();
7306
- if (propertyKey !== UnknownKey && path.length < MAX_PATH_DEPTH) {
7307
- if (propertyKey !== this.propertyKey)
7308
- this.expressionsToBeDeoptimized.push(origin);
7309
- 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);
7310
7008
  }
7311
7009
  return UnknownValue;
7312
7010
  }
@@ -7326,11 +7024,9 @@ class MemberExpression extends NodeBase {
7326
7024
  if (this.isUndefined) {
7327
7025
  return [UNDEFINED_EXPRESSION, false];
7328
7026
  }
7329
- const propertyKey = this.getDynamicPropertyKey();
7330
- if (propertyKey !== UnknownKey && path.length < MAX_PATH_DEPTH) {
7331
- if (propertyKey !== this.propertyKey)
7332
- this.expressionsToBeDeoptimized.push(origin);
7333
- 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);
7334
7030
  }
7335
7031
  return UNKNOWN_RETURN_EXPRESSION;
7336
7032
  }
@@ -7376,45 +7072,14 @@ class MemberExpression extends NodeBase {
7376
7072
  return true;
7377
7073
  }
7378
7074
  if (path.length < MAX_PATH_DEPTH) {
7379
- return this.object.hasEffectsOnInteractionAtPath([this.getDynamicPropertyKey(), ...path], interaction, context);
7075
+ return this.object.hasEffectsOnInteractionAtPath([this.getPropertyKey(), ...path], interaction, context);
7380
7076
  }
7381
7077
  return true;
7382
7078
  }
7383
- hasEffectsWhenDestructuring(context, destructuredInitPath, init) {
7384
- return (destructuredInitPath.length > 0 &&
7385
- init.hasEffectsOnInteractionAtPath(destructuredInitPath, NODE_INTERACTION_UNKNOWN_ACCESS, context));
7386
- }
7387
7079
  include(context, includeChildrenRecursively) {
7388
- if (!this.included)
7389
- this.includeNode(context);
7390
- this.object.include(context, includeChildrenRecursively);
7391
- this.property.include(context, includeChildrenRecursively);
7392
- }
7393
- includeNode(context) {
7394
- this.included = true;
7395
7080
  if (!this.deoptimized)
7396
7081
  this.applyDeoptimizations();
7397
- if (this.variable) {
7398
- this.scope.context.includeVariableInModule(this.variable, EMPTY_PATH, context);
7399
- }
7400
- else if (!this.isUndefined) {
7401
- this.object.includePath([this.propertyKey], context);
7402
- }
7403
- }
7404
- includePath(path, context) {
7405
- if (!this.included)
7406
- this.includeNode(context);
7407
- if (this.variable) {
7408
- this.variable?.includePath(path, context);
7409
- }
7410
- else if (!this.isUndefined) {
7411
- this.object.includePath([
7412
- this.propertyKey,
7413
- ...(path.length < MAX_PATH_DEPTH
7414
- ? path
7415
- : [...path.slice(0, MAX_PATH_DEPTH), UnknownKey])
7416
- ], context);
7417
- }
7082
+ this.includeProperties(context, includeChildrenRecursively);
7418
7083
  }
7419
7084
  includeAsAssignmentTarget(context, includeChildrenRecursively, deoptimizeAccess) {
7420
7085
  if (!this.assignmentDeoptimized)
@@ -7423,34 +7088,20 @@ class MemberExpression extends NodeBase {
7423
7088
  this.include(context, includeChildrenRecursively);
7424
7089
  }
7425
7090
  else {
7426
- if (!this.included)
7427
- this.includeNode(context);
7428
- this.object.include(context, includeChildrenRecursively);
7429
- this.property.include(context, includeChildrenRecursively);
7091
+ this.includeProperties(context, includeChildrenRecursively);
7430
7092
  }
7431
7093
  }
7432
- includeCallArguments(context, interaction) {
7094
+ includeCallArguments(context, parameters) {
7433
7095
  if (this.variable) {
7434
- this.variable.includeCallArguments(context, interaction);
7096
+ this.variable.includeCallArguments(context, parameters);
7435
7097
  }
7436
7098
  else {
7437
- super.includeCallArguments(context, interaction);
7438
- }
7439
- }
7440
- includeDestructuredIfNecessary(context, destructuredInitPath, init) {
7441
- if ((this.included ||=
7442
- destructuredInitPath.length > 0 &&
7443
- !context.brokenFlow &&
7444
- init.hasEffectsOnInteractionAtPath(destructuredInitPath, NODE_INTERACTION_UNKNOWN_ACCESS, createHasEffectsContext()))) {
7445
- init.include(context, false);
7446
- return true;
7099
+ super.includeCallArguments(context, parameters);
7447
7100
  }
7448
- return false;
7449
7101
  }
7450
7102
  initialise() {
7451
7103
  super.initialise();
7452
- this.dynamicPropertyKey = getResolvablePropertyKey(this);
7453
- this.propertyKey = this.dynamicPropertyKey === null ? UnknownKey : this.dynamicPropertyKey;
7104
+ this.propertyKey = getResolvablePropertyKey(this);
7454
7105
  this.accessInteraction = { args: [this.object], type: INTERACTION_ACCESSED };
7455
7106
  }
7456
7107
  render(code, options, { renderedParentType, isCalleeOfRenderedParent, renderedSurroundingElement } = BLANK) {
@@ -7487,7 +7138,8 @@ class MemberExpression extends NodeBase {
7487
7138
  this.bound &&
7488
7139
  propertyReadSideEffects &&
7489
7140
  !(this.variable || this.isUndefined)) {
7490
- 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);
7491
7143
  this.scope.context.requestTreeshakingPass();
7492
7144
  }
7493
7145
  if (this.variable) {
@@ -7504,7 +7156,7 @@ class MemberExpression extends NodeBase {
7504
7156
  this.bound &&
7505
7157
  propertyReadSideEffects &&
7506
7158
  !(this.variable || this.isUndefined)) {
7507
- this.object.deoptimizeArgumentsOnInteractionAtPath(this.assignmentInteraction, [this.propertyKey], SHARED_RECURSION_TRACKER);
7159
+ this.object.deoptimizeArgumentsOnInteractionAtPath(this.assignmentInteraction, [this.getPropertyKey()], SHARED_RECURSION_TRACKER);
7508
7160
  this.scope.context.requestTreeshakingPass();
7509
7161
  }
7510
7162
  }
@@ -7513,24 +7165,24 @@ class MemberExpression extends NodeBase {
7513
7165
  const variable = this.scope.findVariable(this.object.name);
7514
7166
  if (variable.isNamespace) {
7515
7167
  if (this.variable) {
7516
- this.scope.context.includeVariableInModule(this.variable, UNKNOWN_PATH, createInclusionContext());
7168
+ this.scope.context.includeVariableInModule(this.variable);
7517
7169
  }
7518
7170
  this.scope.context.log(LOGLEVEL_WARN, logIllegalImportReassignment(this.object.name, this.scope.context.module.id), this.start);
7519
7171
  }
7520
7172
  }
7521
7173
  }
7522
- getDynamicPropertyKey() {
7523
- if (this.dynamicPropertyKey === null) {
7524
- this.dynamicPropertyKey = this.propertyKey;
7174
+ getPropertyKey() {
7175
+ if (this.propertyKey === null) {
7176
+ this.propertyKey = UnknownKey;
7525
7177
  const value = this.property.getLiteralValueAtPath(EMPTY_PATH, SHARED_RECURSION_TRACKER, this);
7526
- return (this.dynamicPropertyKey =
7178
+ return (this.propertyKey =
7527
7179
  value === SymbolToStringTag
7528
7180
  ? value
7529
7181
  : typeof value === 'symbol'
7530
7182
  ? UnknownKey
7531
7183
  : String(value));
7532
7184
  }
7533
- return this.dynamicPropertyKey;
7185
+ return this.propertyKey;
7534
7186
  }
7535
7187
  hasAccessEffect(context) {
7536
7188
  const { propertyReadSideEffects } = this.scope.context.options
@@ -7538,7 +7190,17 @@ class MemberExpression extends NodeBase {
7538
7190
  return (!(this.variable || this.isUndefined) &&
7539
7191
  propertyReadSideEffects &&
7540
7192
  (propertyReadSideEffects === 'always' ||
7541
- 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);
7542
7204
  }
7543
7205
  }
7544
7206
  function resolveNamespaceVariables(baseVariable, path, astContext) {
@@ -7582,20 +7244,18 @@ class MetaProperty extends NodeBase {
7582
7244
  return path.length > 1 || type !== INTERACTION_ACCESSED;
7583
7245
  }
7584
7246
  include() {
7585
- if (!this.included)
7586
- this.includeNode();
7587
- }
7588
- includeNode() {
7589
- this.included = true;
7590
- if (this.meta.name === IMPORT) {
7591
- this.scope.context.addImportMeta(this);
7592
- const parent = this.parent;
7593
- const metaProperty = (this.metaProperty =
7594
- parent instanceof MemberExpression && typeof parent.propertyKey === 'string'
7595
- ? parent.propertyKey
7596
- : null);
7597
- if (metaProperty?.startsWith(FILE_PREFIX)) {
7598
- 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
+ }
7599
7259
  }
7600
7260
  }
7601
7261
  }
@@ -7702,7 +7362,7 @@ class UndefinedVariable extends Variable {
7702
7362
 
7703
7363
  class ExportDefaultVariable extends LocalVariable {
7704
7364
  constructor(name, exportDefaultDeclaration, context) {
7705
- super(name, exportDefaultDeclaration, exportDefaultDeclaration.declaration, EMPTY_PATH, context, 'other');
7365
+ super(name, exportDefaultDeclaration, exportDefaultDeclaration.declaration, context, 'other');
7706
7366
  this.hasId = false;
7707
7367
  this.originalId = null;
7708
7368
  this.originalVariable = null;
@@ -7851,8 +7511,8 @@ class NamespaceVariable extends Variable {
7851
7511
  return (!memberVariable ||
7852
7512
  memberVariable.hasEffectsOnInteractionAtPath(path.slice(1), interaction, context));
7853
7513
  }
7854
- includePath(path, context) {
7855
- super.includePath(path, context);
7514
+ include() {
7515
+ super.include();
7856
7516
  this.context.includeAllExports();
7857
7517
  }
7858
7518
  prepare(accessedGlobalsByScope) {
@@ -7945,9 +7605,9 @@ class SyntheticNamedExportVariable extends Variable {
7945
7605
  getName(getPropertyAccess) {
7946
7606
  return `${this.syntheticNamespace.getName(getPropertyAccess)}${getPropertyAccess(this.name)}`;
7947
7607
  }
7948
- includePath(path, context) {
7949
- super.includePath(path, context);
7950
- this.context.includeVariableInModule(this.syntheticNamespace, path, context);
7608
+ include() {
7609
+ super.include();
7610
+ this.context.includeVariableInModule(this.syntheticNamespace);
7951
7611
  }
7952
7612
  setRenderNames(baseName, name) {
7953
7613
  super.setRenderNames(baseName, name);
@@ -7978,7 +7638,7 @@ class ExternalChunk {
7978
7638
  (this.renormalizeRenderPath ? normalize(relative(this.inputBase, this.id)) : this.id));
7979
7639
  }
7980
7640
  getImportAttributes(snippets) {
7981
- return (this.importAttributes ||= formatAttributes(this.options.format === 'es' &&
7641
+ return (this.importAttributes ||= formatAttributes(['es', 'cjs'].includes(this.options.format) &&
7982
7642
  this.options.externalImportAttributes &&
7983
7643
  this.moduleInfo.attributes, snippets));
7984
7644
  }
@@ -10437,7 +10097,7 @@ function requireParse () {
10437
10097
  }
10438
10098
 
10439
10099
  if (prior.type === 'slash' && prior.prev.type !== 'bos' && rest[0] === '/') {
10440
- const end = rest[1] !== void 0 ? '|$' : '';
10100
+ const end = rest[1] !== undefined ? '|$' : '';
10441
10101
 
10442
10102
  state.output = state.output.slice(0, -(prior.output + prev.output).length);
10443
10103
  prior.output = `(?:${prior.output}`;
@@ -11152,37 +10812,21 @@ class ArrayPattern extends NodeBase {
11152
10812
  element?.addExportedVariables(variables, exportNamesByVariable);
11153
10813
  }
11154
10814
  }
11155
- declare(kind, destructuredInitPath, init) {
10815
+ declare(kind) {
11156
10816
  const variables = [];
11157
- const includedPatternPath = getIncludedPatternPath(destructuredInitPath);
11158
10817
  for (const element of this.elements) {
11159
10818
  if (element !== null) {
11160
- variables.push(...element.declare(kind, includedPatternPath, init));
10819
+ variables.push(...element.declare(kind, UNKNOWN_EXPRESSION));
11161
10820
  }
11162
10821
  }
11163
10822
  return variables;
11164
10823
  }
11165
- deoptimizeAssignment(destructuredInitPath, init) {
11166
- const includedPatternPath = getIncludedPatternPath(destructuredInitPath);
11167
- for (const element of this.elements) {
11168
- element?.deoptimizeAssignment(includedPatternPath, init);
11169
- }
11170
- }
11171
10824
  // Patterns can only be deoptimized at the empty path at the moment
11172
10825
  deoptimizePath() {
11173
10826
  for (const element of this.elements) {
11174
10827
  element?.deoptimizePath(EMPTY_PATH);
11175
10828
  }
11176
10829
  }
11177
- hasEffectsWhenDestructuring(context, destructuredInitPath, init) {
11178
- const includedPatternPath = getIncludedPatternPath(destructuredInitPath);
11179
- for (const element of this.elements) {
11180
- if (element?.hasEffectsWhenDestructuring(context, includedPatternPath, init)) {
11181
- return true;
11182
- }
11183
- }
11184
- return false;
11185
- }
11186
10830
  // Patterns are only checked at the empty path at the moment
11187
10831
  hasEffectsOnInteractionAtPath(_path, interaction, context) {
11188
10832
  for (const element of this.elements) {
@@ -11191,38 +10835,12 @@ class ArrayPattern extends NodeBase {
11191
10835
  }
11192
10836
  return false;
11193
10837
  }
11194
- includeDestructuredIfNecessary(context, destructuredInitPath, init) {
11195
- let included = false;
11196
- const includedPatternPath = getIncludedPatternPath(destructuredInitPath);
11197
- for (const element of this.elements) {
11198
- if (element) {
11199
- element.included ||= included;
11200
- included =
11201
- element.includeDestructuredIfNecessary(context, includedPatternPath, init) || included;
11202
- }
11203
- }
11204
- if (included) {
11205
- // This is necessary so that if any pattern element is included, all are
11206
- // included for proper deconflicting
11207
- for (const element of this.elements) {
11208
- if (element && !element.included) {
11209
- element.included = true;
11210
- element.includeDestructuredIfNecessary(context, includedPatternPath, init);
11211
- }
11212
- }
11213
- }
11214
- return (this.included ||= included);
11215
- }
11216
10838
  markDeclarationReached() {
11217
10839
  for (const element of this.elements) {
11218
10840
  element?.markDeclarationReached();
11219
10841
  }
11220
10842
  }
11221
10843
  }
11222
- ArrayPattern.prototype.includeNode = onlyIncludeSelf;
11223
- const getIncludedPatternPath = (destructuredInitPath) => destructuredInitPath.at(-1) === UnknownKey
11224
- ? destructuredInitPath
11225
- : [...destructuredInitPath, UnknownInteger];
11226
10844
 
11227
10845
  class ArrowFunctionExpression extends FunctionBase {
11228
10846
  constructor() {
@@ -11239,6 +10857,8 @@ class ArrowFunctionExpression extends FunctionBase {
11239
10857
  this.scope = new ReturnValueScope(parentScope, false);
11240
10858
  }
11241
10859
  hasEffects() {
10860
+ if (!this.deoptimized)
10861
+ this.applyDeoptimizations();
11242
10862
  return false;
11243
10863
  }
11244
10864
  hasEffectsOnInteractionAtPath(path, interaction, context) {
@@ -11277,15 +10897,6 @@ class ArrowFunctionExpression extends FunctionBase {
11277
10897
  }
11278
10898
  }
11279
10899
  }
11280
- includeNode(context) {
11281
- this.included = true;
11282
- this.body.includePath(UNKNOWN_PATH, context);
11283
- for (const parameter of this.params) {
11284
- if (!(parameter instanceof Identifier)) {
11285
- parameter.includePath(UNKNOWN_PATH, context);
11286
- }
11287
- }
11288
- }
11289
10900
  getObjectEntity() {
11290
10901
  if (this.objectEntity !== null) {
11291
10902
  return this.objectEntity;
@@ -11305,18 +10916,13 @@ class ObjectPattern extends NodeBase {
11305
10916
  }
11306
10917
  }
11307
10918
  }
11308
- declare(kind, destructuredInitPath, init) {
10919
+ declare(kind, init) {
11309
10920
  const variables = [];
11310
10921
  for (const property of this.properties) {
11311
- variables.push(...property.declare(kind, destructuredInitPath, init));
10922
+ variables.push(...property.declare(kind, init));
11312
10923
  }
11313
10924
  return variables;
11314
10925
  }
11315
- deoptimizeAssignment(destructuredInitPath, init) {
11316
- for (const property of this.properties) {
11317
- property.deoptimizeAssignment(destructuredInitPath, init);
11318
- }
11319
- }
11320
10926
  deoptimizePath(path) {
11321
10927
  if (path.length === 0) {
11322
10928
  for (const property of this.properties) {
@@ -11334,46 +10940,12 @@ class ObjectPattern extends NodeBase {
11334
10940
  }
11335
10941
  return false;
11336
10942
  }
11337
- hasEffectsWhenDestructuring(context, destructuredInitPath, init) {
11338
- for (const property of this.properties) {
11339
- if (property.hasEffectsWhenDestructuring(context, destructuredInitPath, init))
11340
- return true;
11341
- }
11342
- return false;
11343
- }
11344
- includeDestructuredIfNecessary(context, destructuredInitPath, init) {
11345
- let included = false;
11346
- for (const property of this.properties) {
11347
- included =
11348
- property.includeDestructuredIfNecessary(context, destructuredInitPath, init) || included;
11349
- }
11350
- return (this.included ||= included);
11351
- }
11352
10943
  markDeclarationReached() {
11353
10944
  for (const property of this.properties) {
11354
10945
  property.markDeclarationReached();
11355
10946
  }
11356
10947
  }
11357
- render(code, options) {
11358
- if (this.properties.length > 0) {
11359
- const separatedNodes = getCommaSeparatedNodesWithBoundaries(this.properties, code, this.start + 1, this.end - 1);
11360
- let lastSeparatorPos = null;
11361
- for (const { node, separator, start, end } of separatedNodes) {
11362
- if (!node.included) {
11363
- treeshakeNode(node, code, start, end);
11364
- continue;
11365
- }
11366
- lastSeparatorPos = separator;
11367
- node.render(code, options);
11368
- }
11369
- if (lastSeparatorPos) {
11370
- code.remove(lastSeparatorPos, this.end - 1);
11371
- }
11372
- }
11373
- }
11374
10948
  }
11375
- ObjectPattern.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
11376
- ObjectPattern.prototype.applyDeoptimizations = doNotDeoptimize;
11377
10949
 
11378
10950
  class AssignmentExpression extends NodeBase {
11379
10951
  hasEffects(context) {
@@ -11382,9 +10954,7 @@ class AssignmentExpression extends NodeBase {
11382
10954
  this.applyDeoptimizations();
11383
10955
  // MemberExpressions do not access the property before assignments if the
11384
10956
  // operator is '='.
11385
- return (right.hasEffects(context) ||
11386
- left.hasEffectsAsAssignmentTarget(context, operator !== '=') ||
11387
- this.left.hasEffectsWhenDestructuring?.(context, EMPTY_PATH, right));
10957
+ return (right.hasEffects(context) || left.hasEffectsAsAssignmentTarget(context, operator !== '='));
11388
10958
  }
11389
10959
  hasEffectsOnInteractionAtPath(path, interaction, context) {
11390
10960
  return this.right.hasEffectsOnInteractionAtPath(path, interaction, context);
@@ -11393,24 +10963,15 @@ class AssignmentExpression extends NodeBase {
11393
10963
  const { deoptimized, left, right, operator } = this;
11394
10964
  if (!deoptimized)
11395
10965
  this.applyDeoptimizations();
11396
- if (!this.included)
11397
- this.includeNode(context);
11398
- const hasEffectsContext = createHasEffectsContext();
10966
+ this.included = true;
11399
10967
  if (includeChildrenRecursively ||
11400
10968
  operator !== '=' ||
11401
10969
  left.included ||
11402
- left.hasEffectsAsAssignmentTarget(hasEffectsContext, false) ||
11403
- left.hasEffectsWhenDestructuring?.(hasEffectsContext, EMPTY_PATH, right)) {
10970
+ left.hasEffectsAsAssignmentTarget(createHasEffectsContext(), false)) {
11404
10971
  left.includeAsAssignmentTarget(context, includeChildrenRecursively, operator !== '=');
11405
10972
  }
11406
10973
  right.include(context, includeChildrenRecursively);
11407
10974
  }
11408
- includeNode(context) {
11409
- this.included = true;
11410
- if (!this.deoptimized)
11411
- this.applyDeoptimizations();
11412
- this.right.includePath(UNKNOWN_PATH, context);
11413
- }
11414
10975
  initialise() {
11415
10976
  super.initialise();
11416
10977
  if (this.left instanceof Identifier) {
@@ -11471,7 +11032,8 @@ class AssignmentExpression extends NodeBase {
11471
11032
  }
11472
11033
  applyDeoptimizations() {
11473
11034
  this.deoptimized = true;
11474
- this.left.deoptimizeAssignment(EMPTY_PATH, this.right);
11035
+ this.left.deoptimizePath(EMPTY_PATH);
11036
+ this.right.deoptimizePath(UNKNOWN_PATH);
11475
11037
  this.scope.context.requestTreeshakingPass();
11476
11038
  }
11477
11039
  }
@@ -11480,11 +11042,8 @@ class AssignmentPattern extends NodeBase {
11480
11042
  addExportedVariables(variables, exportNamesByVariable) {
11481
11043
  this.left.addExportedVariables(variables, exportNamesByVariable);
11482
11044
  }
11483
- declare(kind, destructuredInitPath, init) {
11484
- return this.left.declare(kind, destructuredInitPath, init);
11485
- }
11486
- deoptimizeAssignment(destructuredInitPath, init) {
11487
- this.left.deoptimizeAssignment(destructuredInitPath, init);
11045
+ declare(kind, init) {
11046
+ return this.left.declare(kind, init);
11488
11047
  }
11489
11048
  deoptimizePath(path) {
11490
11049
  if (path.length === 0) {
@@ -11494,29 +11053,6 @@ class AssignmentPattern extends NodeBase {
11494
11053
  hasEffectsOnInteractionAtPath(path, interaction, context) {
11495
11054
  return (path.length > 0 || this.left.hasEffectsOnInteractionAtPath(EMPTY_PATH, interaction, context));
11496
11055
  }
11497
- hasEffectsWhenDestructuring(context, destructuredInitPath, init) {
11498
- return this.left.hasEffectsWhenDestructuring(context, destructuredInitPath, init);
11499
- }
11500
- includeDestructuredIfNecessary(context, destructuredInitPath, init) {
11501
- let included = this.left.includeDestructuredIfNecessary(context, destructuredInitPath, init) ||
11502
- this.included;
11503
- if ((included ||= this.right.shouldBeIncluded(context))) {
11504
- this.right.include(context, false);
11505
- if (!this.left.included) {
11506
- this.left.included = true;
11507
- // Unfortunately, we need to include the left side again now, so that
11508
- // any declared variables are properly included.
11509
- this.left.includeDestructuredIfNecessary(context, destructuredInitPath, init);
11510
- }
11511
- }
11512
- return (this.included = included);
11513
- }
11514
- includeNode(context) {
11515
- this.included = true;
11516
- if (!this.deoptimized)
11517
- this.applyDeoptimizations();
11518
- this.right.includePath(UNKNOWN_PATH, context);
11519
- }
11520
11056
  markDeclarationReached() {
11521
11057
  this.left.markDeclarationReached();
11522
11058
  }
@@ -11539,34 +11075,22 @@ class AwaitExpression extends NodeBase {
11539
11075
  return true;
11540
11076
  }
11541
11077
  include(context, includeChildrenRecursively) {
11542
- if (!this.included)
11543
- this.includeNode(context);
11544
- this.argument.include(context, includeChildrenRecursively);
11545
- }
11546
- includeNode(context) {
11547
- this.included = true;
11548
11078
  if (!this.deoptimized)
11549
11079
  this.applyDeoptimizations();
11550
- checkTopLevelAwait: if (!this.scope.context.usesTopLevelAwait) {
11551
- let parent = this.parent;
11552
- do {
11553
- if (parent instanceof FunctionNode || parent instanceof ArrowFunctionExpression)
11554
- break checkTopLevelAwait;
11555
- } while ((parent = parent.parent));
11556
- 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
+ }
11557
11090
  }
11558
- // Thenables need to be included
11559
- this.argument.includePath(THEN_PATH, context);
11560
- }
11561
- includePath(path, context) {
11562
- if (!this.deoptimized)
11563
- this.applyDeoptimizations();
11564
- if (!this.included)
11565
- this.includeNode(context);
11566
- this.argument.includePath(path, context);
11091
+ this.argument.include(context, includeChildrenRecursively);
11567
11092
  }
11568
11093
  }
11569
- const THEN_PATH = ['then'];
11570
11094
 
11571
11095
  const binaryOperators = {
11572
11096
  '!=': (left, right) => left != right,
@@ -11622,12 +11146,6 @@ class BinaryExpression extends NodeBase {
11622
11146
  hasEffectsOnInteractionAtPath(path, { type }) {
11623
11147
  return type !== INTERACTION_ACCESSED || path.length > 1;
11624
11148
  }
11625
- includeNode(context) {
11626
- this.included = true;
11627
- if (this.operator === 'in') {
11628
- this.right.includePath(UNKNOWN_PATH, context);
11629
- }
11630
- }
11631
11149
  removeAnnotations(code) {
11632
11150
  this.left.removeAnnotations(code);
11633
11151
  }
@@ -11636,7 +11154,6 @@ class BinaryExpression extends NodeBase {
11636
11154
  this.right.render(code, options);
11637
11155
  }
11638
11156
  }
11639
- BinaryExpression.prototype.applyDeoptimizations = doNotDeoptimize;
11640
11157
 
11641
11158
  class BreakStatement extends NodeBase {
11642
11159
  hasEffects(context) {
@@ -11656,7 +11173,7 @@ class BreakStatement extends NodeBase {
11656
11173
  include(context) {
11657
11174
  this.included = true;
11658
11175
  if (this.label) {
11659
- this.label.include(context);
11176
+ this.label.include();
11660
11177
  context.includedLabels.add(this.label.name);
11661
11178
  }
11662
11179
  else {
@@ -11665,8 +11182,6 @@ class BreakStatement extends NodeBase {
11665
11182
  context.brokenFlow = true;
11666
11183
  }
11667
11184
  }
11668
- BreakStatement.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
11669
- BreakStatement.prototype.applyDeoptimizations = doNotDeoptimize;
11670
11185
 
11671
11186
  function renderCallArguments(code, options, node) {
11672
11187
  if (node.arguments.length > 0) {
@@ -11853,14 +11368,10 @@ class CallExpression extends CallExpressionBase {
11853
11368
  this.callee.hasEffectsOnInteractionAtPath(EMPTY_PATH, this.interaction, context)));
11854
11369
  }
11855
11370
  include(context, includeChildrenRecursively) {
11856
- if (!this.included)
11857
- this.includeNode(context);
11371
+ if (!this.deoptimized)
11372
+ this.applyDeoptimizations();
11858
11373
  if (includeChildrenRecursively) {
11859
- this.callee.include(context, true);
11860
- for (const argument of this.arguments) {
11861
- argument.includePath(UNKNOWN_PATH, context);
11862
- argument.include(context, true);
11863
- }
11374
+ super.include(context, includeChildrenRecursively);
11864
11375
  if (includeChildrenRecursively === INCLUDE_PARAMETERS &&
11865
11376
  this.callee instanceof Identifier &&
11866
11377
  this.callee.variable) {
@@ -11868,24 +11379,10 @@ class CallExpression extends CallExpressionBase {
11868
11379
  }
11869
11380
  }
11870
11381
  else {
11871
- // If the callee is a member expression and does not have a variable, its
11872
- // object will already be included via the first argument of the
11873
- // interaction in includeCallArguments. Including it again can lead to
11874
- // severe performance problems.
11875
- if (this.callee instanceof MemberExpression && !this.callee.variable) {
11876
- this.callee.property.include(context, false);
11877
- }
11878
- else {
11879
- this.callee.include(context, false);
11880
- }
11881
- this.callee.includeCallArguments(context, this.interaction);
11382
+ this.included = true;
11383
+ this.callee.include(context, false);
11882
11384
  }
11883
- }
11884
- includeNode(context) {
11885
- this.included = true;
11886
- if (!this.deoptimized)
11887
- this.applyDeoptimizations();
11888
- this.callee.includePath(UNKNOWN_PATH, context);
11385
+ this.callee.includeCallArguments(context, this.arguments);
11889
11386
  }
11890
11387
  initialise() {
11891
11388
  super.initialise();
@@ -11924,14 +11421,13 @@ class CatchClause extends NodeBase {
11924
11421
  this.type = type;
11925
11422
  if (param) {
11926
11423
  this.param = new (this.scope.context.getNodeConstructor(param.type))(this, this.scope).parseNode(param);
11927
- this.param.declare('parameter', EMPTY_PATH, UNKNOWN_EXPRESSION);
11424
+ this.param.declare('parameter', UNKNOWN_EXPRESSION);
11928
11425
  }
11929
11426
  this.body = new BlockStatement(this, this.scope.bodyScope).parseNode(body);
11930
11427
  return super.parseNode(esTreeNode);
11931
11428
  }
11932
11429
  }
11933
11430
  CatchClause.prototype.preventChildBlockScope = true;
11934
- CatchClause.prototype.includeNode = onlyIncludeSelf;
11935
11431
 
11936
11432
  class ChainExpression extends NodeBase {
11937
11433
  // deoptimizations are not relevant as we are not caching values
@@ -11943,22 +11439,17 @@ class ChainExpression extends NodeBase {
11943
11439
  hasEffects(context) {
11944
11440
  return this.expression.hasEffectsAsChainElement(context) === true;
11945
11441
  }
11946
- includePath(path, context) {
11947
- this.included = true;
11948
- this.expression.includePath(path, context);
11949
- }
11950
11442
  removeAnnotations(code) {
11951
11443
  this.expression.removeAnnotations(code);
11952
11444
  }
11445
+ applyDeoptimizations() { }
11953
11446
  }
11954
- ChainExpression.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
11955
- ChainExpression.prototype.applyDeoptimizations = doNotDeoptimize;
11956
11447
 
11957
11448
  class ClassBodyScope extends ChildScope {
11958
11449
  constructor(parent, classNode) {
11959
11450
  const { context } = parent;
11960
11451
  super(parent, context);
11961
- 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')));
11962
11453
  this.instanceScope = new ChildScope(this, context);
11963
11454
  this.instanceScope.variables.set('this', new ThisVariable(context));
11964
11455
  }
@@ -11973,7 +11464,7 @@ class ClassBody extends NodeBase {
11973
11464
  }
11974
11465
  include(context, includeChildrenRecursively) {
11975
11466
  this.included = true;
11976
- this.scope.context.includeVariableInModule(this.scope.thisVariable, UNKNOWN_PATH, context);
11467
+ this.scope.context.includeVariableInModule(this.scope.thisVariable);
11977
11468
  for (const definition of this.body) {
11978
11469
  definition.include(context, includeChildrenRecursively);
11979
11470
  }
@@ -11986,9 +11477,8 @@ class ClassBody extends NodeBase {
11986
11477
  }
11987
11478
  return super.parseNode(esTreeNode);
11988
11479
  }
11480
+ applyDeoptimizations() { }
11989
11481
  }
11990
- ClassBody.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
11991
- ClassBody.prototype.applyDeoptimizations = doNotDeoptimize;
11992
11482
 
11993
11483
  class ClassExpression extends ClassNode {
11994
11484
  render(code, options, { renderedSurroundingElement } = BLANK) {
@@ -12059,9 +11549,6 @@ class ConditionalExpression extends NodeBase {
12059
11549
  const unusedBranch = this.usedBranch === this.consequent ? this.alternate : this.consequent;
12060
11550
  this.usedBranch = null;
12061
11551
  unusedBranch.deoptimizePath(UNKNOWN_PATH);
12062
- if (this.included) {
12063
- unusedBranch.includePath(UNKNOWN_PATH, createInclusionContext());
12064
- }
12065
11552
  const { expressionsToBeDeoptimized } = this;
12066
11553
  this.expressionsToBeDeoptimized = EMPTY_ARRAY;
12067
11554
  for (const expression of expressionsToBeDeoptimized) {
@@ -12119,7 +11606,7 @@ class ConditionalExpression extends NodeBase {
12119
11606
  include(context, includeChildrenRecursively) {
12120
11607
  this.included = true;
12121
11608
  const usedBranch = this.getUsedBranch();
12122
- if (usedBranch === null || includeChildrenRecursively || this.test.shouldBeIncluded(context)) {
11609
+ if (includeChildrenRecursively || this.test.shouldBeIncluded(context) || usedBranch === null) {
12123
11610
  this.test.include(context, includeChildrenRecursively);
12124
11611
  this.consequent.include(context, includeChildrenRecursively);
12125
11612
  this.alternate.include(context, includeChildrenRecursively);
@@ -12128,38 +11615,27 @@ class ConditionalExpression extends NodeBase {
12128
11615
  usedBranch.include(context, includeChildrenRecursively);
12129
11616
  }
12130
11617
  }
12131
- includePath(path, context) {
12132
- this.included = true;
12133
- const usedBranch = this.getUsedBranch();
12134
- if (usedBranch === null || this.test.shouldBeIncluded(context)) {
12135
- this.consequent.includePath(path, context);
12136
- this.alternate.includePath(path, context);
12137
- }
12138
- else {
12139
- usedBranch.includePath(path, context);
12140
- }
12141
- }
12142
- includeCallArguments(context, interaction) {
11618
+ includeCallArguments(context, parameters) {
12143
11619
  const usedBranch = this.getUsedBranch();
12144
11620
  if (usedBranch) {
12145
- usedBranch.includeCallArguments(context, interaction);
11621
+ usedBranch.includeCallArguments(context, parameters);
12146
11622
  }
12147
11623
  else {
12148
- this.consequent.includeCallArguments(context, interaction);
12149
- this.alternate.includeCallArguments(context, interaction);
11624
+ this.consequent.includeCallArguments(context, parameters);
11625
+ this.alternate.includeCallArguments(context, parameters);
12150
11626
  }
12151
11627
  }
12152
11628
  removeAnnotations(code) {
12153
11629
  this.test.removeAnnotations(code);
12154
11630
  }
12155
11631
  render(code, options, { isCalleeOfRenderedParent, preventASI, renderedParentType, renderedSurroundingElement } = BLANK) {
11632
+ const usedBranch = this.getUsedBranch();
12156
11633
  if (this.test.included) {
12157
11634
  this.test.render(code, options, { renderedSurroundingElement });
12158
11635
  this.consequent.render(code, options);
12159
11636
  this.alternate.render(code, options);
12160
11637
  }
12161
11638
  else {
12162
- const usedBranch = this.getUsedBranch();
12163
11639
  const colonPos = findFirstOccurrenceOutsideComment(code.original, ':', this.consequent.end);
12164
11640
  const inclusionStart = findNonWhiteSpace(code.original, (this.consequent.included
12165
11641
  ? findFirstOccurrenceOutsideComment(code.original, '?', this.test.end)
@@ -12191,8 +11667,6 @@ class ConditionalExpression extends NodeBase {
12191
11667
  : (this.usedBranch = testValue ? this.consequent : this.alternate);
12192
11668
  }
12193
11669
  }
12194
- ConditionalExpression.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
12195
- ConditionalExpression.prototype.applyDeoptimizations = doNotDeoptimize;
12196
11670
 
12197
11671
  class ContinueStatement extends NodeBase {
12198
11672
  hasEffects(context) {
@@ -12212,7 +11686,7 @@ class ContinueStatement extends NodeBase {
12212
11686
  include(context) {
12213
11687
  this.included = true;
12214
11688
  if (this.label) {
12215
- this.label.include(context);
11689
+ this.label.include();
12216
11690
  context.includedLabels.add(this.label.name);
12217
11691
  }
12218
11692
  else {
@@ -12221,15 +11695,12 @@ class ContinueStatement extends NodeBase {
12221
11695
  context.brokenFlow = true;
12222
11696
  }
12223
11697
  }
12224
- ContinueStatement.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
12225
- ContinueStatement.prototype.applyDeoptimizations = doNotDeoptimize;
12226
11698
 
12227
11699
  class DebuggerStatement extends NodeBase {
12228
11700
  hasEffects() {
12229
11701
  return true;
12230
11702
  }
12231
11703
  }
12232
- DebuggerStatement.prototype.includeNode = onlyIncludeSelf;
12233
11704
 
12234
11705
  class Decorator extends NodeBase {
12235
11706
  hasEffects(context) {
@@ -12237,7 +11708,6 @@ class Decorator extends NodeBase {
12237
11708
  this.expression.hasEffectsOnInteractionAtPath(EMPTY_PATH, NODE_INTERACTION_UNKNOWN_CALL, context));
12238
11709
  }
12239
11710
  }
12240
- Decorator.prototype.includeNode = onlyIncludeSelf;
12241
11711
 
12242
11712
  function hasLoopBodyEffects(context, body) {
12243
11713
  const { brokenFlow, hasBreak, hasContinue, ignore } = context;
@@ -12277,15 +11747,12 @@ class DoWhileStatement extends NodeBase {
12277
11747
  includeLoopBody(context, this.body, includeChildrenRecursively);
12278
11748
  }
12279
11749
  }
12280
- DoWhileStatement.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
12281
- DoWhileStatement.prototype.applyDeoptimizations = doNotDeoptimize;
12282
11750
 
12283
11751
  class EmptyStatement extends NodeBase {
12284
11752
  hasEffects() {
12285
11753
  return false;
12286
11754
  }
12287
11755
  }
12288
- EmptyStatement.prototype.includeNode = onlyIncludeSelf;
12289
11756
 
12290
11757
  class ExportAllDeclaration extends NodeBase {
12291
11758
  hasEffects() {
@@ -12298,10 +11765,9 @@ class ExportAllDeclaration extends NodeBase {
12298
11765
  render(code, _options, nodeRenderOptions) {
12299
11766
  code.remove(nodeRenderOptions.start, nodeRenderOptions.end);
12300
11767
  }
11768
+ applyDeoptimizations() { }
12301
11769
  }
12302
11770
  ExportAllDeclaration.prototype.needsBoundaries = true;
12303
- ExportAllDeclaration.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
12304
- ExportAllDeclaration.prototype.applyDeoptimizations = doNotDeoptimize;
12305
11771
 
12306
11772
  class ExportNamedDeclaration extends NodeBase {
12307
11773
  bind() {
@@ -12328,15 +11794,13 @@ class ExportNamedDeclaration extends NodeBase {
12328
11794
  this.declaration.render(code, options, { end, start });
12329
11795
  }
12330
11796
  }
11797
+ applyDeoptimizations() { }
12331
11798
  }
12332
11799
  ExportNamedDeclaration.prototype.needsBoundaries = true;
12333
- ExportNamedDeclaration.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
12334
- ExportNamedDeclaration.prototype.applyDeoptimizations = doNotDeoptimize;
12335
11800
 
12336
11801
  class ExportSpecifier extends NodeBase {
11802
+ applyDeoptimizations() { }
12337
11803
  }
12338
- ExportSpecifier.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
12339
- ExportSpecifier.prototype.applyDeoptimizations = doNotDeoptimize;
12340
11804
 
12341
11805
  class ForInStatement extends NodeBase {
12342
11806
  createScope(parentScope) {
@@ -12354,18 +11818,11 @@ class ForInStatement extends NodeBase {
12354
11818
  const { body, deoptimized, left, right } = this;
12355
11819
  if (!deoptimized)
12356
11820
  this.applyDeoptimizations();
12357
- if (!this.included)
12358
- this.includeNode(context);
11821
+ this.included = true;
12359
11822
  left.includeAsAssignmentTarget(context, includeChildrenRecursively || true, false);
12360
11823
  right.include(context, includeChildrenRecursively);
12361
11824
  includeLoopBody(context, body, includeChildrenRecursively);
12362
11825
  }
12363
- includeNode(context) {
12364
- this.included = true;
12365
- if (!this.deoptimized)
12366
- this.applyDeoptimizations();
12367
- this.right.includePath(UNKNOWN_PATH, context);
12368
- }
12369
11826
  initialise() {
12370
11827
  super.initialise();
12371
11828
  this.left.setAssignedValue(UNKNOWN_EXPRESSION);
@@ -12406,18 +11863,11 @@ class ForOfStatement extends NodeBase {
12406
11863
  const { body, deoptimized, left, right } = this;
12407
11864
  if (!deoptimized)
12408
11865
  this.applyDeoptimizations();
12409
- if (!this.included)
12410
- this.includeNode(context);
11866
+ this.included = true;
12411
11867
  left.includeAsAssignmentTarget(context, includeChildrenRecursively || true, false);
12412
11868
  right.include(context, includeChildrenRecursively);
12413
11869
  includeLoopBody(context, body, includeChildrenRecursively);
12414
11870
  }
12415
- includeNode(context) {
12416
- this.included = true;
12417
- if (!this.deoptimized)
12418
- this.applyDeoptimizations();
12419
- this.right.includePath(UNKNOWN_PATH, context);
12420
- }
12421
11871
  initialise() {
12422
11872
  super.initialise();
12423
11873
  this.left.setAssignedValue(UNKNOWN_EXPRESSION);
@@ -12453,9 +11903,7 @@ class ForStatement extends NodeBase {
12453
11903
  }
12454
11904
  include(context, includeChildrenRecursively) {
12455
11905
  this.included = true;
12456
- this.init?.include(context, includeChildrenRecursively, {
12457
- asSingleStatement: true
12458
- });
11906
+ this.init?.include(context, includeChildrenRecursively, { asSingleStatement: true });
12459
11907
  this.test?.include(context, includeChildrenRecursively);
12460
11908
  this.update?.include(context, includeChildrenRecursively);
12461
11909
  includeLoopBody(context, this.body, includeChildrenRecursively);
@@ -12467,8 +11915,6 @@ class ForStatement extends NodeBase {
12467
11915
  this.body.render(code, options);
12468
11916
  }
12469
11917
  }
12470
- ForStatement.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
12471
- ForStatement.prototype.applyDeoptimizations = doNotDeoptimize;
12472
11918
 
12473
11919
  class FunctionExpression extends FunctionNode {
12474
11920
  createScope(parentScope) {
@@ -12500,9 +11946,9 @@ class TrackingScope extends BlockScope {
12500
11946
  super(...arguments);
12501
11947
  this.hoistedDeclarations = [];
12502
11948
  }
12503
- addDeclaration(identifier, context, init, destructuredInitPath, kind) {
11949
+ addDeclaration(identifier, context, init, kind) {
12504
11950
  this.hoistedDeclarations.push(identifier);
12505
- return super.addDeclaration(identifier, context, init, destructuredInitPath, kind);
11951
+ return super.addDeclaration(identifier, context, init, kind);
12506
11952
  }
12507
11953
  }
12508
11954
 
@@ -12601,6 +12047,7 @@ class IfStatement extends NodeBase {
12601
12047
  }
12602
12048
  this.renderHoistedDeclarations(hoistedDeclarations, code, getPropertyAccess);
12603
12049
  }
12050
+ applyDeoptimizations() { }
12604
12051
  getTestValue() {
12605
12052
  if (this.testValue === unset) {
12606
12053
  return (this.testValue = tryCastLiteralValueToBoolean(this.test.getLiteralValueAtPath(EMPTY_PATH, SHARED_RECURSION_TRACKER, this)));
@@ -12669,8 +12116,6 @@ class IfStatement extends NodeBase {
12669
12116
  return false;
12670
12117
  }
12671
12118
  }
12672
- IfStatement.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
12673
- IfStatement.prototype.applyDeoptimizations = doNotDeoptimize;
12674
12119
 
12675
12120
  class ImportAttribute extends NodeBase {
12676
12121
  }
@@ -12688,15 +12133,13 @@ class ImportDeclaration extends NodeBase {
12688
12133
  render(code, _options, nodeRenderOptions) {
12689
12134
  code.remove(nodeRenderOptions.start, nodeRenderOptions.end);
12690
12135
  }
12136
+ applyDeoptimizations() { }
12691
12137
  }
12692
12138
  ImportDeclaration.prototype.needsBoundaries = true;
12693
- ImportDeclaration.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
12694
- ImportDeclaration.prototype.applyDeoptimizations = doNotDeoptimize;
12695
12139
 
12696
12140
  class ImportDefaultSpecifier extends NodeBase {
12141
+ applyDeoptimizations() { }
12697
12142
  }
12698
- ImportDefaultSpecifier.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
12699
- ImportDefaultSpecifier.prototype.applyDeoptimizations = doNotDeoptimize;
12700
12143
 
12701
12144
  function isReassignedExportsMember(variable, exportNamesByVariable) {
12702
12145
  return (variable.renderBaseName !== null && exportNamesByVariable.has(variable) && variable.isReassigned);
@@ -12705,33 +12148,28 @@ function isReassignedExportsMember(variable, exportNamesByVariable) {
12705
12148
  class VariableDeclarator extends NodeBase {
12706
12149
  declareDeclarator(kind, isUsingDeclaration) {
12707
12150
  this.isUsingDeclaration = isUsingDeclaration;
12708
- this.id.declare(kind, EMPTY_PATH, this.init || UNDEFINED_EXPRESSION);
12151
+ this.id.declare(kind, this.init || UNDEFINED_EXPRESSION);
12709
12152
  }
12710
12153
  deoptimizePath(path) {
12711
12154
  this.id.deoptimizePath(path);
12712
12155
  }
12713
12156
  hasEffects(context) {
12157
+ if (!this.deoptimized)
12158
+ this.applyDeoptimizations();
12714
12159
  const initEffect = this.init?.hasEffects(context);
12715
12160
  this.id.markDeclarationReached();
12716
- return (initEffect ||
12717
- this.isUsingDeclaration ||
12718
- this.id.hasEffects(context) ||
12719
- (this.scope.context.options.treeshake
12720
- .propertyReadSideEffects &&
12721
- this.id.hasEffectsWhenDestructuring(context, EMPTY_PATH, this.init || UNDEFINED_EXPRESSION)));
12161
+ return initEffect || this.id.hasEffects(context) || this.isUsingDeclaration;
12722
12162
  }
12723
12163
  include(context, includeChildrenRecursively) {
12724
- const { id, init } = this;
12725
- if (!this.included)
12726
- this.includeNode();
12164
+ const { deoptimized, id, init } = this;
12165
+ if (!deoptimized)
12166
+ this.applyDeoptimizations();
12167
+ this.included = true;
12727
12168
  init?.include(context, includeChildrenRecursively);
12728
12169
  id.markDeclarationReached();
12729
- if (includeChildrenRecursively) {
12170
+ if (includeChildrenRecursively || id.shouldBeIncluded(context)) {
12730
12171
  id.include(context, includeChildrenRecursively);
12731
12172
  }
12732
- else {
12733
- id.includeDestructuredIfNecessary(context, EMPTY_PATH, init || UNDEFINED_EXPRESSION);
12734
- }
12735
12173
  }
12736
12174
  removeAnnotations(code) {
12737
12175
  this.init?.removeAnnotations(code);
@@ -12761,8 +12199,8 @@ class VariableDeclarator extends NodeBase {
12761
12199
  code.appendLeft(end, `${_}=${_}void 0`);
12762
12200
  }
12763
12201
  }
12764
- includeNode() {
12765
- this.included = true;
12202
+ applyDeoptimizations() {
12203
+ this.deoptimized = true;
12766
12204
  const { id, init } = this;
12767
12205
  if (init && id instanceof Identifier && init instanceof ClassExpression && !init.id) {
12768
12206
  const { name, variable } = id;
@@ -12774,14 +12212,11 @@ class VariableDeclarator extends NodeBase {
12774
12212
  }
12775
12213
  }
12776
12214
  }
12777
- VariableDeclarator.prototype.applyDeoptimizations = doNotDeoptimize;
12778
12215
 
12779
12216
  class ImportExpression extends NodeBase {
12780
12217
  constructor() {
12781
12218
  super(...arguments);
12782
12219
  this.inlineNamespace = null;
12783
- this.hasUnknownAccessedKey = false;
12784
- this.accessedPropKey = new Set();
12785
12220
  this.attributes = null;
12786
12221
  this.mechanism = null;
12787
12222
  this.namespaceExportName = undefined;
@@ -12814,15 +12249,12 @@ class ImportExpression extends NodeBase {
12814
12249
  if (parent2 instanceof ExpressionStatement) {
12815
12250
  return EMPTY_ARRAY;
12816
12251
  }
12817
- // Case 1: const { foo } / module = await import('bar')
12252
+ // Case 1: const { foo } = await import('bar')
12818
12253
  if (parent2 instanceof VariableDeclarator) {
12819
12254
  const declaration = parent2.id;
12820
- if (declaration instanceof Identifier) {
12821
- return this.hasUnknownAccessedKey ? undefined : [...this.accessedPropKey];
12822
- }
12823
- if (declaration instanceof ObjectPattern) {
12824
- return getDeterministicObjectDestructure(declaration);
12825
- }
12255
+ return declaration instanceof ObjectPattern
12256
+ ? getDeterministicObjectDestructure(declaration)
12257
+ : undefined;
12826
12258
  }
12827
12259
  // Case 2: (await import('bar')).foo
12828
12260
  if (parent2 instanceof MemberExpression) {
@@ -12872,29 +12304,12 @@ class ImportExpression extends NodeBase {
12872
12304
  return true;
12873
12305
  }
12874
12306
  include(context, includeChildrenRecursively) {
12875
- if (!this.included)
12876
- this.includeNode();
12877
- this.source.include(context, includeChildrenRecursively);
12878
- }
12879
- includeNode() {
12880
- this.included = true;
12881
- this.scope.context.includeDynamicImport(this);
12882
- this.scope.addAccessedDynamicImport(this);
12883
- }
12884
- includePath(path) {
12885
- if (!this.included)
12886
- this.includeNode();
12887
- // Technically, this is not correct as dynamic imports return a Promise.
12888
- if (this.hasUnknownAccessedKey)
12889
- return;
12890
- if (path[0] === UnknownKey) {
12891
- this.hasUnknownAccessedKey = true;
12892
- }
12893
- else if (typeof path[0] === 'string') {
12894
- this.accessedPropKey.add(path[0]);
12307
+ if (!this.included) {
12308
+ this.included = true;
12309
+ this.scope.context.includeDynamicImport(this);
12310
+ this.scope.addAccessedDynamicImport(this);
12895
12311
  }
12896
- // Update included paths
12897
- this.scope.context.includeDynamicImport(this);
12312
+ this.source.include(context, includeChildrenRecursively);
12898
12313
  }
12899
12314
  initialise() {
12900
12315
  super.initialise();
@@ -12964,6 +12379,7 @@ class ImportExpression extends NodeBase {
12964
12379
  setInternalResolution(inlineNamespace) {
12965
12380
  this.inlineNamespace = inlineNamespace;
12966
12381
  }
12382
+ applyDeoptimizations() { }
12967
12383
  getDynamicImportMechanismAndHelper(resolution, exportMode, { compact, dynamicImportInCjs, format, generatedCode: { arrowFunctions }, interop }, { _, getDirectReturnFunction, getDirectReturnIifeLeft }, pluginDriver) {
12968
12384
  const mechanism = pluginDriver.hookFirstSync('renderDynamicImport', [
12969
12385
  {
@@ -13053,7 +12469,6 @@ class ImportExpression extends NodeBase {
13053
12469
  return { helper: null, mechanism: null };
13054
12470
  }
13055
12471
  }
13056
- ImportExpression.prototype.applyDeoptimizations = doNotDeoptimize;
13057
12472
  function getInteropHelper(resolution, exportMode, interop) {
13058
12473
  return exportMode === 'external'
13059
12474
  ? namespaceInteropHelpersByInteropType[interop(resolution instanceof ExternalModule ? resolution.id : null)]
@@ -13077,14 +12492,12 @@ function getDeterministicObjectDestructure(objectPattern) {
13077
12492
  }
13078
12493
 
13079
12494
  class ImportNamespaceSpecifier extends NodeBase {
12495
+ applyDeoptimizations() { }
13080
12496
  }
13081
- ImportNamespaceSpecifier.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
13082
- ImportNamespaceSpecifier.prototype.applyDeoptimizations = doNotDeoptimize;
13083
12497
 
13084
12498
  class ImportSpecifier extends NodeBase {
12499
+ applyDeoptimizations() { }
13085
12500
  }
13086
- ImportSpecifier.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
13087
- ImportSpecifier.prototype.applyDeoptimizations = doNotDeoptimize;
13088
12501
 
13089
12502
  class JSXIdentifier extends IdentifierBase {
13090
12503
  constructor() {
@@ -13101,29 +12514,6 @@ class JSXIdentifier extends IdentifierBase {
13101
12514
  this.isNativeElement = true;
13102
12515
  }
13103
12516
  }
13104
- include(context) {
13105
- if (!this.included)
13106
- this.includeNode(context);
13107
- }
13108
- includeNode(context) {
13109
- this.included = true;
13110
- if (!this.deoptimized)
13111
- this.applyDeoptimizations();
13112
- if (this.variable !== null) {
13113
- this.scope.context.includeVariableInModule(this.variable, EMPTY_PATH, context);
13114
- }
13115
- }
13116
- includePath(path, context) {
13117
- if (!this.included) {
13118
- this.included = true;
13119
- if (this.variable !== null) {
13120
- this.scope.context.includeVariableInModule(this.variable, path, context);
13121
- }
13122
- }
13123
- else if (path.length > 0) {
13124
- this.variable?.includePath(path, context);
13125
- }
13126
- }
13127
12517
  render(code, { snippets: { getPropertyAccess }, useOriginalName }) {
13128
12518
  if (this.variable) {
13129
12519
  const name = this.variable.getName(getPropertyAccess, useOriginalName);
@@ -13185,7 +12575,6 @@ class JSXAttribute extends NodeBase {
13185
12575
  }
13186
12576
  }
13187
12577
  }
13188
- JSXAttribute.prototype.includeNode = onlyIncludeSelf;
13189
12578
 
13190
12579
  class JSXClosingBase extends NodeBase {
13191
12580
  render(code, options) {
@@ -13198,7 +12587,6 @@ class JSXClosingBase extends NodeBase {
13198
12587
  }
13199
12588
  }
13200
12589
  }
13201
- JSXClosingBase.prototype.includeNode = onlyIncludeSelf;
13202
12590
 
13203
12591
  class JSXClosingElement extends JSXClosingBase {
13204
12592
  }
@@ -13219,15 +12607,8 @@ class JSXSpreadAttribute extends NodeBase {
13219
12607
 
13220
12608
  class JSXEmptyExpression extends NodeBase {
13221
12609
  }
13222
- JSXEmptyExpression.prototype.includeNode = onlyIncludeSelf;
13223
12610
 
13224
12611
  class JSXExpressionContainer extends NodeBase {
13225
- includeNode(context) {
13226
- this.included = true;
13227
- if (!this.deoptimized)
13228
- this.applyDeoptimizations();
13229
- this.expression.includePath(UNKNOWN_PATH, context);
13230
- }
13231
12612
  render(code, options) {
13232
12613
  const { mode } = this.scope.context.options.jsx;
13233
12614
  if (mode !== 'preserve') {
@@ -13248,7 +12629,7 @@ function getRenderedJsxChildren(children) {
13248
12629
  return renderedChildren;
13249
12630
  }
13250
12631
 
13251
- function getAndIncludeFactoryVariable(factory, preserve, importSource, node, context) {
12632
+ function getAndIncludeFactoryVariable(factory, preserve, importSource, node) {
13252
12633
  const [baseName, nestedName] = factory.split('.');
13253
12634
  let factoryVariable;
13254
12635
  if (importSource) {
@@ -13256,7 +12637,7 @@ function getAndIncludeFactoryVariable(factory, preserve, importSource, node, con
13256
12637
  if (preserve) {
13257
12638
  // This pretends we are accessing an included global variable of the same name
13258
12639
  const globalVariable = node.scope.findGlobal(baseName);
13259
- globalVariable.includePath(UNKNOWN_PATH, context);
12640
+ globalVariable.include();
13260
12641
  // This excludes this variable from renaming
13261
12642
  factoryVariable.globalName = baseName;
13262
12643
  }
@@ -13264,7 +12645,7 @@ function getAndIncludeFactoryVariable(factory, preserve, importSource, node, con
13264
12645
  else {
13265
12646
  factoryVariable = node.scope.findGlobal(baseName);
13266
12647
  }
13267
- node.scope.context.includeVariableInModule(factoryVariable, UNKNOWN_PATH, context);
12648
+ node.scope.context.includeVariableInModule(factoryVariable);
13268
12649
  if (factoryVariable instanceof LocalVariable) {
13269
12650
  factoryVariable.consolidateInitializers();
13270
12651
  factoryVariable.addUsedPlace(node);
@@ -13287,20 +12668,16 @@ class JSXElementBase extends NodeBase {
13287
12668
  }
13288
12669
  }
13289
12670
  include(context, includeChildrenRecursively) {
13290
- if (!this.included)
13291
- this.includeNode(context);
13292
- for (const child of this.children) {
13293
- child.include(context, includeChildrenRecursively);
13294
- }
13295
- }
13296
- includeNode(context) {
13297
- this.included = true;
13298
- const { factory, importSource, mode } = this.jsxMode;
13299
- if (factory) {
13300
- this.factory = factory;
13301
- 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
+ }
13302
12677
  }
12678
+ super.include(context, includeChildrenRecursively);
13303
12679
  }
12680
+ applyDeoptimizations() { }
13304
12681
  getRenderingMode() {
13305
12682
  const jsx = this.scope.context.options.jsx;
13306
12683
  const { mode, factory, importSource } = jsx;
@@ -13338,14 +12715,8 @@ class JSXElementBase extends NodeBase {
13338
12715
  return { childrenEnd, firstChild, hasMultipleChildren };
13339
12716
  }
13340
12717
  }
13341
- JSXElementBase.prototype.applyDeoptimizations = doNotDeoptimize;
13342
12718
 
13343
12719
  class JSXElement extends JSXElementBase {
13344
- include(context, includeChildrenRecursively) {
13345
- super.include(context, includeChildrenRecursively);
13346
- this.openingElement.include(context, includeChildrenRecursively);
13347
- this.closingElement?.include(context, includeChildrenRecursively);
13348
- }
13349
12720
  render(code, options) {
13350
12721
  switch (this.jsxMode.mode) {
13351
12722
  case 'classic': {
@@ -13497,11 +12868,6 @@ class JSXElement extends JSXElementBase {
13497
12868
  }
13498
12869
 
13499
12870
  class JSXFragment extends JSXElementBase {
13500
- include(context, includeChildrenRecursively) {
13501
- super.include(context, includeChildrenRecursively);
13502
- this.openingFragment.include(context, includeChildrenRecursively);
13503
- this.closingFragment.include(context, includeChildrenRecursively);
13504
- }
13505
12871
  render(code, options) {
13506
12872
  switch (this.jsxMode.mode) {
13507
12873
  case 'classic': {
@@ -13551,22 +12917,10 @@ class JSXFragment extends JSXElementBase {
13551
12917
  }
13552
12918
 
13553
12919
  class JSXMemberExpression extends NodeBase {
13554
- includeNode(context) {
13555
- this.included = true;
13556
- if (!this.deoptimized)
13557
- this.applyDeoptimizations();
13558
- this.object.includePath([this.property.name], context);
13559
- }
13560
- includePath(path, context) {
13561
- if (!this.included)
13562
- this.includeNode(context);
13563
- this.object.includePath([this.property.name, ...path], context);
13564
- }
13565
12920
  }
13566
12921
 
13567
12922
  class JSXNamespacedName extends NodeBase {
13568
12923
  }
13569
- JSXNamespacedName.prototype.includeNode = onlyIncludeSelf;
13570
12924
 
13571
12925
  class JSXOpeningElement extends NodeBase {
13572
12926
  render(code, options, { jsxMode = this.scope.context.options.jsx.mode } = {}) {
@@ -13576,7 +12930,6 @@ class JSXOpeningElement extends NodeBase {
13576
12930
  }
13577
12931
  }
13578
12932
  }
13579
- JSXOpeningElement.prototype.includeNode = onlyIncludeSelf;
13580
12933
 
13581
12934
  class JSXOpeningFragment extends NodeBase {
13582
12935
  constructor() {
@@ -13584,22 +12937,22 @@ class JSXOpeningFragment extends NodeBase {
13584
12937
  this.fragment = null;
13585
12938
  this.fragmentVariable = null;
13586
12939
  }
13587
- includeNode(context) {
13588
- this.included = true;
13589
- if (!this.deoptimized)
13590
- this.applyDeoptimizations();
13591
- const jsx = this.scope.context.options.jsx;
13592
- if (jsx.mode === 'automatic') {
13593
- this.fragment = 'Fragment';
13594
- this.fragmentVariable = getAndIncludeFactoryVariable('Fragment', false, jsx.jsxImportSource, this, context);
13595
- }
13596
- else {
13597
- const { fragment, importSource, mode } = jsx;
13598
- if (fragment != null) {
13599
- this.fragment = fragment;
13600
- 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
+ }
13601
12953
  }
13602
12954
  }
12955
+ super.include(context, includeChildrenRecursively);
13603
12956
  }
13604
12957
  render(code, options) {
13605
12958
  const { mode } = this.scope.context.options.jsx;
@@ -13636,7 +12989,6 @@ class JSXText extends NodeBase {
13636
12989
  }
13637
12990
  }
13638
12991
  }
13639
- JSXText.prototype.includeNode = onlyIncludeSelf;
13640
12992
 
13641
12993
  class LabeledStatement extends NodeBase {
13642
12994
  hasEffects(context) {
@@ -13658,22 +13010,17 @@ class LabeledStatement extends NodeBase {
13658
13010
  return bodyHasEffects;
13659
13011
  }
13660
13012
  include(context, includeChildrenRecursively) {
13661
- if (!this.included)
13662
- this.includeNode(context);
13013
+ this.included = true;
13663
13014
  const { brokenFlow, includedLabels } = context;
13664
13015
  context.includedLabels = new Set();
13665
13016
  this.body.include(context, includeChildrenRecursively);
13666
13017
  if (includeChildrenRecursively || context.includedLabels.has(this.label.name)) {
13667
- this.label.include(context);
13018
+ this.label.include();
13668
13019
  context.includedLabels.delete(this.label.name);
13669
13020
  context.brokenFlow = brokenFlow;
13670
13021
  }
13671
13022
  context.includedLabels = new Set([...includedLabels, ...context.includedLabels]);
13672
13023
  }
13673
- includeNode(context) {
13674
- this.included = true;
13675
- this.body.includePath(UNKNOWN_PATH, context);
13676
- }
13677
13024
  render(code, options) {
13678
13025
  if (this.label.included) {
13679
13026
  this.label.render(code, options);
@@ -13684,7 +13031,6 @@ class LabeledStatement extends NodeBase {
13684
13031
  this.body.render(code, options);
13685
13032
  }
13686
13033
  }
13687
- LabeledStatement.prototype.applyDeoptimizations = doNotDeoptimize;
13688
13034
 
13689
13035
  class LogicalExpression extends NodeBase {
13690
13036
  constructor() {
@@ -13701,10 +13047,10 @@ class LogicalExpression extends NodeBase {
13701
13047
  this.flags = setFlag(this.flags, 65536 /* Flag.isBranchResolutionAnalysed */, value);
13702
13048
  }
13703
13049
  get hasDeoptimizedCache() {
13704
- return isFlagSet(this.flags, 33554432 /* Flag.hasDeoptimizedCache */);
13050
+ return isFlagSet(this.flags, 16777216 /* Flag.hasDeoptimizedCache */);
13705
13051
  }
13706
13052
  set hasDeoptimizedCache(value) {
13707
- this.flags = setFlag(this.flags, 33554432 /* Flag.hasDeoptimizedCache */, value);
13053
+ this.flags = setFlag(this.flags, 16777216 /* Flag.hasDeoptimizedCache */, value);
13708
13054
  }
13709
13055
  deoptimizeArgumentsOnInteractionAtPath(interaction, path, recursionTracker) {
13710
13056
  this.left.deoptimizeArgumentsOnInteractionAtPath(interaction, path, recursionTracker);
@@ -13717,10 +13063,6 @@ class LogicalExpression extends NodeBase {
13717
13063
  const unusedBranch = this.usedBranch === this.left ? this.right : this.left;
13718
13064
  this.usedBranch = null;
13719
13065
  unusedBranch.deoptimizePath(UNKNOWN_PATH);
13720
- if (this.included) {
13721
- // As we are not tracking inclusions, we just include everything
13722
- unusedBranch.includePath(UNKNOWN_PATH, createInclusionContext());
13723
- }
13724
13066
  }
13725
13067
  const { scope: { context }, expressionsToBeDeoptimized } = this;
13726
13068
  this.expressionsToBeDeoptimized = EMPTY_ARRAY;
@@ -13766,17 +13108,16 @@ class LogicalExpression extends NodeBase {
13766
13108
  }
13767
13109
  getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin) {
13768
13110
  const usedBranch = this.getUsedBranch();
13769
- if (usedBranch) {
13770
- this.expressionsToBeDeoptimized.push(origin);
13771
- return usedBranch.getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin);
13772
- }
13773
- return [
13774
- new MultiExpression([
13775
- this.left.getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin)[0],
13776
- this.right.getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin)[0]
13777
- ]),
13778
- false
13779
- ];
13111
+ if (!usedBranch)
13112
+ return [
13113
+ new MultiExpression([
13114
+ this.left.getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin)[0],
13115
+ this.right.getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin)[0]
13116
+ ]),
13117
+ false
13118
+ ];
13119
+ this.expressionsToBeDeoptimized.push(origin);
13120
+ return usedBranch.getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin);
13780
13121
  }
13781
13122
  hasEffects(context) {
13782
13123
  if (this.left.hasEffects(context)) {
@@ -13789,18 +13130,18 @@ class LogicalExpression extends NodeBase {
13789
13130
  }
13790
13131
  hasEffectsOnInteractionAtPath(path, interaction, context) {
13791
13132
  const usedBranch = this.getUsedBranch();
13792
- if (usedBranch) {
13793
- return usedBranch.hasEffectsOnInteractionAtPath(path, interaction, context);
13133
+ if (!usedBranch) {
13134
+ return (this.left.hasEffectsOnInteractionAtPath(path, interaction, context) ||
13135
+ this.right.hasEffectsOnInteractionAtPath(path, interaction, context));
13794
13136
  }
13795
- return (this.left.hasEffectsOnInteractionAtPath(path, interaction, context) ||
13796
- this.right.hasEffectsOnInteractionAtPath(path, interaction, context));
13137
+ return usedBranch.hasEffectsOnInteractionAtPath(path, interaction, context);
13797
13138
  }
13798
13139
  include(context, includeChildrenRecursively) {
13799
13140
  this.included = true;
13800
13141
  const usedBranch = this.getUsedBranch();
13801
13142
  if (includeChildrenRecursively ||
13802
- !usedBranch ||
13803
- (usedBranch === this.right && this.left.shouldBeIncluded(context))) {
13143
+ (usedBranch === this.right && this.left.shouldBeIncluded(context)) ||
13144
+ !usedBranch) {
13804
13145
  this.left.include(context, includeChildrenRecursively);
13805
13146
  this.right.include(context, includeChildrenRecursively);
13806
13147
  }
@@ -13808,17 +13149,6 @@ class LogicalExpression extends NodeBase {
13808
13149
  usedBranch.include(context, includeChildrenRecursively);
13809
13150
  }
13810
13151
  }
13811
- includePath(path, context) {
13812
- this.included = true;
13813
- const usedBranch = this.getUsedBranch();
13814
- if (!usedBranch || (usedBranch === this.right && this.left.shouldBeIncluded(context))) {
13815
- this.left.includePath(path, context);
13816
- this.right.includePath(path, context);
13817
- }
13818
- else {
13819
- usedBranch.includePath(path, context);
13820
- }
13821
- }
13822
13152
  removeAnnotations(code) {
13823
13153
  this.left.removeAnnotations(code);
13824
13154
  }
@@ -13871,8 +13201,6 @@ class LogicalExpression extends NodeBase {
13871
13201
  return this.usedBranch;
13872
13202
  }
13873
13203
  }
13874
- LogicalExpression.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
13875
- LogicalExpression.prototype.applyDeoptimizations = doNotDeoptimize;
13876
13204
 
13877
13205
  class NewExpression extends NodeBase {
13878
13206
  hasEffects(context) {
@@ -13892,21 +13220,16 @@ class NewExpression extends NodeBase {
13892
13220
  return path.length > 0 || type !== INTERACTION_ACCESSED;
13893
13221
  }
13894
13222
  include(context, includeChildrenRecursively) {
13223
+ if (!this.deoptimized)
13224
+ this.applyDeoptimizations();
13895
13225
  if (includeChildrenRecursively) {
13896
13226
  super.include(context, includeChildrenRecursively);
13897
13227
  }
13898
13228
  else {
13899
- if (!this.included)
13900
- this.includeNode(context);
13229
+ this.included = true;
13901
13230
  this.callee.include(context, false);
13902
13231
  }
13903
- this.callee.includeCallArguments(context, this.interaction);
13904
- }
13905
- includeNode(context) {
13906
- this.included = true;
13907
- if (!this.deoptimized)
13908
- this.applyDeoptimizations();
13909
- this.callee.includePath(UNKNOWN_PATH, context);
13232
+ this.callee.includeCallArguments(context, this.arguments);
13910
13233
  }
13911
13234
  initialise() {
13912
13235
  super.initialise();
@@ -13935,7 +13258,6 @@ class ObjectExpression extends NodeBase {
13935
13258
  constructor() {
13936
13259
  super(...arguments);
13937
13260
  this.objectEntity = null;
13938
- this.protoProp = null;
13939
13261
  }
13940
13262
  deoptimizeArgumentsOnInteractionAtPath(interaction, path, recursionTracker) {
13941
13263
  this.getObjectEntity().deoptimizeArgumentsOnInteractionAtPath(interaction, path, recursionTracker);
@@ -13955,43 +13277,15 @@ class ObjectExpression extends NodeBase {
13955
13277
  hasEffectsOnInteractionAtPath(path, interaction, context) {
13956
13278
  return this.getObjectEntity().hasEffectsOnInteractionAtPath(path, interaction, context);
13957
13279
  }
13958
- include(context, includeChildrenRecursively) {
13959
- if (!this.included)
13960
- this.includeNode(context);
13961
- this.getObjectEntity().include(context, includeChildrenRecursively);
13962
- this.protoProp?.include(context, includeChildrenRecursively);
13963
- }
13964
- includeNode(context) {
13965
- this.included = true;
13966
- this.protoProp?.includePath(UNKNOWN_PATH, context);
13967
- }
13968
- includePath(path, context) {
13969
- if (!this.included)
13970
- this.includeNode(context);
13971
- this.getObjectEntity().includePath(path, context);
13972
- }
13973
13280
  render(code, options, { renderedSurroundingElement } = BLANK) {
13281
+ super.render(code, options);
13974
13282
  if (renderedSurroundingElement === ExpressionStatement$1 ||
13975
13283
  renderedSurroundingElement === ArrowFunctionExpression$1) {
13976
13284
  code.appendRight(this.start, '(');
13977
13285
  code.prependLeft(this.end, ')');
13978
13286
  }
13979
- if (this.properties.length > 0) {
13980
- const separatedNodes = getCommaSeparatedNodesWithBoundaries(this.properties, code, this.start + 1, this.end - 1);
13981
- let lastSeparatorPos = null;
13982
- for (const { node, separator, start, end } of separatedNodes) {
13983
- if (!node.included) {
13984
- treeshakeNode(node, code, start, end);
13985
- continue;
13986
- }
13987
- lastSeparatorPos = separator;
13988
- node.render(code, options);
13989
- }
13990
- if (lastSeparatorPos) {
13991
- code.remove(lastSeparatorPos, this.end - 1);
13992
- }
13993
- }
13994
13287
  }
13288
+ applyDeoptimizations() { }
13995
13289
  getObjectEntity() {
13996
13290
  if (this.objectEntity !== null) {
13997
13291
  return this.objectEntity;
@@ -14020,7 +13314,6 @@ class ObjectExpression extends NodeBase {
14020
13314
  ? property.key.name
14021
13315
  : String(property.key.value);
14022
13316
  if (key === '__proto__' && property.kind === 'init') {
14023
- this.protoProp = property;
14024
13317
  prototype =
14025
13318
  property.value instanceof Literal && property.value.value === null
14026
13319
  ? null
@@ -14033,7 +13326,6 @@ class ObjectExpression extends NodeBase {
14033
13326
  return (this.objectEntity = new ObjectEntity(properties, prototype));
14034
13327
  }
14035
13328
  }
14036
- ObjectExpression.prototype.applyDeoptimizations = doNotDeoptimize;
14037
13329
 
14038
13330
  class PanicError extends NodeBase {
14039
13331
  initialise() {
@@ -14060,7 +13352,6 @@ class ParseError extends NodeBase {
14060
13352
 
14061
13353
  class PrivateIdentifier extends NodeBase {
14062
13354
  }
14063
- PrivateIdentifier.prototype.includeNode = onlyIncludeSelf;
14064
13355
 
14065
13356
  class Program extends NodeBase {
14066
13357
  constructor() {
@@ -14128,11 +13419,14 @@ class Program extends NodeBase {
14128
13419
  super.render(code, options);
14129
13420
  }
14130
13421
  }
13422
+ applyDeoptimizations() { }
14131
13423
  }
14132
- Program.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
14133
- Program.prototype.applyDeoptimizations = doNotDeoptimize;
14134
13424
 
14135
13425
  class Property extends MethodBase {
13426
+ constructor() {
13427
+ super(...arguments);
13428
+ this.declarationInit = null;
13429
+ }
14136
13430
  //declare method: boolean;
14137
13431
  get method() {
14138
13432
  return isFlagSet(this.flags, 262144 /* Flag.method */);
@@ -14147,41 +13441,17 @@ class Property extends MethodBase {
14147
13441
  set shorthand(value) {
14148
13442
  this.flags = setFlag(this.flags, 524288 /* Flag.shorthand */, value);
14149
13443
  }
14150
- declare(kind, destructuredInitPath, init) {
14151
- return this.value.declare(kind, this.getPathInProperty(destructuredInitPath), init);
14152
- }
14153
- deoptimizeAssignment(destructuredInitPath, init) {
14154
- this.value.deoptimizeAssignment?.(this.getPathInProperty(destructuredInitPath), init);
13444
+ declare(kind, init) {
13445
+ this.declarationInit = init;
13446
+ return this.value.declare(kind, UNKNOWN_EXPRESSION);
14155
13447
  }
14156
13448
  hasEffects(context) {
14157
- return this.key.hasEffects(context) || this.value.hasEffects(context);
14158
- }
14159
- hasEffectsWhenDestructuring(context, destructuredInitPath, init) {
14160
- return this.value.hasEffectsWhenDestructuring?.(context, this.getPathInProperty(destructuredInitPath), init);
14161
- }
14162
- includeDestructuredIfNecessary(context, destructuredInitPath, init) {
14163
- const path = this.getPathInProperty(destructuredInitPath);
14164
- let included = this.value.includeDestructuredIfNecessary(context, path, init) ||
14165
- this.included;
14166
- if ((included ||= this.key.hasEffects(createHasEffectsContext()))) {
14167
- this.key.include(context, false);
14168
- if (!this.value.included) {
14169
- this.value.included = true;
14170
- // Unfortunately, we need to include the value again now, so that any
14171
- // declared variables are properly included.
14172
- this.value.includeDestructuredIfNecessary(context, path, init);
14173
- }
14174
- }
14175
- return (this.included = included);
14176
- }
14177
- include(context, includeChildrenRecursively) {
14178
- this.included = true;
14179
- this.key.include(context, includeChildrenRecursively);
14180
- this.value.include(context, includeChildrenRecursively);
14181
- }
14182
- includePath(path, context) {
14183
- this.included = true;
14184
- this.value.includePath(path, context);
13449
+ if (!this.deoptimized)
13450
+ this.applyDeoptimizations();
13451
+ const propertyReadSideEffects = this.scope.context.options.treeshake.propertyReadSideEffects;
13452
+ return ((this.parent.type === 'ObjectPattern' && propertyReadSideEffects === 'always') ||
13453
+ this.key.hasEffects(context) ||
13454
+ this.value.hasEffects(context));
14185
13455
  }
14186
13456
  markDeclarationReached() {
14187
13457
  this.value.markDeclarationReached();
@@ -14192,20 +13462,14 @@ class Property extends MethodBase {
14192
13462
  }
14193
13463
  this.value.render(code, options, { isShorthandProperty: this.shorthand });
14194
13464
  }
14195
- getPathInProperty(destructuredInitPath) {
14196
- return destructuredInitPath.at(-1) === UnknownKey
14197
- ? destructuredInitPath
14198
- : // For now, we only consider static paths as we do not know how to
14199
- // deoptimize the path in the dynamic case.
14200
- this.computed
14201
- ? [...destructuredInitPath, UnknownKey]
14202
- : this.key instanceof Identifier
14203
- ? [...destructuredInitPath, this.key.name]
14204
- : [...destructuredInitPath, String(this.key.value)];
13465
+ applyDeoptimizations() {
13466
+ this.deoptimized = true;
13467
+ if (this.declarationInit !== null) {
13468
+ this.declarationInit.deoptimizePath([UnknownKey, UnknownKey]);
13469
+ this.scope.context.requestTreeshakingPass();
13470
+ }
14205
13471
  }
14206
13472
  }
14207
- Property.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
14208
- Property.prototype.applyDeoptimizations = doNotDeoptimize;
14209
13473
 
14210
13474
  class PropertyDefinition extends NodeBase {
14211
13475
  get computed() {
@@ -14238,15 +13502,8 @@ class PropertyDefinition extends NodeBase {
14238
13502
  hasEffectsOnInteractionAtPath(path, interaction, context) {
14239
13503
  return !this.value || this.value.hasEffectsOnInteractionAtPath(path, interaction, context);
14240
13504
  }
14241
- includeNode(context) {
14242
- this.included = true;
14243
- this.value?.includePath(UNKNOWN_PATH, context);
14244
- for (const decorator of this.decorators) {
14245
- decorator.includePath(UNKNOWN_PATH, context);
14246
- }
14247
- }
13505
+ applyDeoptimizations() { }
14248
13506
  }
14249
- PropertyDefinition.prototype.applyDeoptimizations = doNotDeoptimize;
14250
13507
 
14251
13508
  class ReturnStatement extends NodeBase {
14252
13509
  hasEffects(context) {
@@ -14256,15 +13513,10 @@ class ReturnStatement extends NodeBase {
14256
13513
  return false;
14257
13514
  }
14258
13515
  include(context, includeChildrenRecursively) {
14259
- if (!this.included)
14260
- this.includeNode(context);
13516
+ this.included = true;
14261
13517
  this.argument?.include(context, includeChildrenRecursively);
14262
13518
  context.brokenFlow = true;
14263
13519
  }
14264
- includeNode(context) {
14265
- this.included = true;
14266
- this.argument?.includePath(UNKNOWN_PATH, context);
14267
- }
14268
13520
  initialise() {
14269
13521
  super.initialise();
14270
13522
  this.scope.addReturnExpression(this.argument || UNKNOWN_EXPRESSION);
@@ -14278,7 +13530,6 @@ class ReturnStatement extends NodeBase {
14278
13530
  }
14279
13531
  }
14280
13532
  }
14281
- ReturnStatement.prototype.applyDeoptimizations = doNotDeoptimize;
14282
13533
 
14283
13534
  class SequenceExpression extends NodeBase {
14284
13535
  deoptimizeArgumentsOnInteractionAtPath(interaction, path, recursionTracker) {
@@ -14306,15 +13557,10 @@ class SequenceExpression extends NodeBase {
14306
13557
  for (const expression of this.expressions) {
14307
13558
  if (includeChildrenRecursively ||
14308
13559
  (expression === lastExpression && !(this.parent instanceof ExpressionStatement)) ||
14309
- expression.shouldBeIncluded(context)) {
13560
+ expression.shouldBeIncluded(context))
14310
13561
  expression.include(context, includeChildrenRecursively);
14311
- }
14312
13562
  }
14313
13563
  }
14314
- includePath(path, context) {
14315
- this.included = true;
14316
- this.expressions[this.expressions.length - 1].includePath(path, context);
14317
- }
14318
13564
  removeAnnotations(code) {
14319
13565
  this.expressions[0].removeAnnotations(code);
14320
13566
  }
@@ -14349,8 +13595,6 @@ class SequenceExpression extends NodeBase {
14349
13595
  }
14350
13596
  }
14351
13597
  }
14352
- SequenceExpression.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
14353
- SequenceExpression.prototype.applyDeoptimizations = doNotDeoptimize;
14354
13598
 
14355
13599
  class Super extends NodeBase {
14356
13600
  bind() {
@@ -14362,15 +13606,11 @@ class Super extends NodeBase {
14362
13606
  deoptimizePath(path) {
14363
13607
  this.variable.deoptimizePath(path);
14364
13608
  }
14365
- include(context) {
14366
- if (!this.included)
14367
- this.includeNode(context);
14368
- }
14369
- includeNode(context) {
14370
- this.included = true;
14371
- if (!this.deoptimized)
14372
- this.applyDeoptimizations();
14373
- this.scope.context.includeVariableInModule(this.variable, EMPTY_PATH, context);
13609
+ include() {
13610
+ if (!this.included) {
13611
+ this.included = true;
13612
+ this.scope.context.includeVariableInModule(this.variable);
13613
+ }
14374
13614
  }
14375
13615
  }
14376
13616
 
@@ -14411,8 +13651,6 @@ class SwitchCase extends NodeBase {
14411
13651
  }
14412
13652
  }
14413
13653
  SwitchCase.prototype.needsBoundaries = true;
14414
- SwitchCase.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
14415
- SwitchCase.prototype.applyDeoptimizations = doNotDeoptimize;
14416
13654
 
14417
13655
  class SwitchStatement extends NodeBase {
14418
13656
  createScope(parentScope) {
@@ -14495,8 +13733,6 @@ class SwitchStatement extends NodeBase {
14495
13733
  }
14496
13734
  }
14497
13735
  }
14498
- SwitchStatement.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
14499
- SwitchStatement.prototype.applyDeoptimizations = doNotDeoptimize;
14500
13736
 
14501
13737
  class TaggedTemplateExpression extends CallExpressionBase {
14502
13738
  bind() {
@@ -14520,8 +13756,8 @@ class TaggedTemplateExpression extends CallExpressionBase {
14520
13756
  this.tag.hasEffectsOnInteractionAtPath(EMPTY_PATH, this.interaction, context));
14521
13757
  }
14522
13758
  include(context, includeChildrenRecursively) {
14523
- if (!this.included)
14524
- this.includeNode(context);
13759
+ if (!this.deoptimized)
13760
+ this.applyDeoptimizations();
14525
13761
  if (includeChildrenRecursively) {
14526
13762
  super.include(context, includeChildrenRecursively);
14527
13763
  }
@@ -14530,7 +13766,7 @@ class TaggedTemplateExpression extends CallExpressionBase {
14530
13766
  this.tag.include(context, includeChildrenRecursively);
14531
13767
  this.quasi.include(context, includeChildrenRecursively);
14532
13768
  }
14533
- this.tag.includeCallArguments(context, this.interaction);
13769
+ this.tag.includeCallArguments(context, this.args);
14534
13770
  const [returnExpression] = this.getReturnExpression();
14535
13771
  if (!returnExpression.included) {
14536
13772
  returnExpression.include(context, false);
@@ -14565,7 +13801,6 @@ class TaggedTemplateExpression extends CallExpressionBase {
14565
13801
  return this.returnExpression;
14566
13802
  }
14567
13803
  }
14568
- TaggedTemplateExpression.prototype.includeNode = onlyIncludeSelf;
14569
13804
 
14570
13805
  class TemplateElement extends NodeBase {
14571
13806
  get tail() {
@@ -14579,13 +13814,15 @@ class TemplateElement extends NodeBase {
14579
13814
  hasEffects() {
14580
13815
  return false;
14581
13816
  }
13817
+ include() {
13818
+ this.included = true;
13819
+ }
14582
13820
  parseNode(esTreeNode) {
14583
13821
  this.value = esTreeNode.value;
14584
13822
  return super.parseNode(esTreeNode);
14585
13823
  }
14586
13824
  render() { }
14587
13825
  }
14588
- TemplateElement.prototype.includeNode = onlyIncludeSelf;
14589
13826
 
14590
13827
  class TemplateLiteral extends NodeBase {
14591
13828
  deoptimizeArgumentsOnInteractionAtPath() { }
@@ -14610,14 +13847,6 @@ class TemplateLiteral extends NodeBase {
14610
13847
  }
14611
13848
  return true;
14612
13849
  }
14613
- includeNode(context) {
14614
- this.included = true;
14615
- if (!this.deoptimized)
14616
- this.applyDeoptimizations();
14617
- for (const node of this.expressions) {
14618
- node.includePath(UNKNOWN_PATH, context);
14619
- }
14620
- }
14621
13850
  render(code, options) {
14622
13851
  code.indentExclusionRanges.push([this.start, this.end]);
14623
13852
  super.render(code, options);
@@ -14627,13 +13856,13 @@ class TemplateLiteral extends NodeBase {
14627
13856
  class ModuleScope extends ChildScope {
14628
13857
  constructor(parent, context) {
14629
13858
  super(parent, context);
14630
- this.variables.set('this', new LocalVariable('this', null, UNDEFINED_EXPRESSION, EMPTY_PATH, context, 'other'));
13859
+ this.variables.set('this', new LocalVariable('this', null, UNDEFINED_EXPRESSION, context, 'other'));
14631
13860
  }
14632
- addDeclaration(identifier, context, init, destructuredInitPath, kind) {
13861
+ addDeclaration(identifier, context, init, kind) {
14633
13862
  if (this.context.module.importDescriptions.has(identifier.name)) {
14634
13863
  context.error(logRedeclarationError(identifier.name), identifier.start);
14635
13864
  }
14636
- return super.addDeclaration(identifier, context, init, destructuredInitPath, kind);
13865
+ return super.addDeclaration(identifier, context, init, kind);
14637
13866
  }
14638
13867
  addExportDefaultDeclaration(name, exportDefaultDeclaration, context) {
14639
13868
  const variable = new ExportDefaultVariable(name, exportDefaultDeclaration, context);
@@ -14678,23 +13907,10 @@ class ThisExpression extends NodeBase {
14678
13907
  }
14679
13908
  return this.variable.hasEffectsOnInteractionAtPath(path, interaction, context);
14680
13909
  }
14681
- include(context) {
14682
- if (!this.included)
14683
- this.includeNode(context);
14684
- }
14685
- includeNode(context) {
14686
- this.included = true;
14687
- if (!this.deoptimized)
14688
- this.applyDeoptimizations();
14689
- this.scope.context.includeVariableInModule(this.variable, EMPTY_PATH, context);
14690
- }
14691
- includePath(path, context) {
13910
+ include() {
14692
13911
  if (!this.included) {
14693
13912
  this.included = true;
14694
- this.scope.context.includeVariableInModule(this.variable, path, context);
14695
- }
14696
- else if (path.length > 0) {
14697
- this.variable.includePath(path, context);
13913
+ this.scope.context.includeVariableInModule(this.variable);
14698
13914
  }
14699
13915
  }
14700
13916
  initialise() {
@@ -14722,8 +13938,7 @@ class ThrowStatement extends NodeBase {
14722
13938
  return true;
14723
13939
  }
14724
13940
  include(context, includeChildrenRecursively) {
14725
- if (!this.included)
14726
- this.includeNode(context);
13941
+ this.included = true;
14727
13942
  this.argument.include(context, includeChildrenRecursively);
14728
13943
  context.brokenFlow = true;
14729
13944
  }
@@ -14734,7 +13949,6 @@ class ThrowStatement extends NodeBase {
14734
13949
  }
14735
13950
  }
14736
13951
  }
14737
- ThrowStatement.prototype.includeNode = onlyIncludeSelf;
14738
13952
 
14739
13953
  class TryStatement extends NodeBase {
14740
13954
  constructor() {
@@ -14771,8 +13985,6 @@ class TryStatement extends NodeBase {
14771
13985
  this.finalizer?.include(context, includeChildrenRecursively);
14772
13986
  }
14773
13987
  }
14774
- TryStatement.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
14775
- TryStatement.prototype.applyDeoptimizations = doNotDeoptimize;
14776
13988
 
14777
13989
  const unaryOperators = {
14778
13990
  '!': value => !value,
@@ -14783,13 +13995,21 @@ const unaryOperators = {
14783
13995
  void: () => undefined,
14784
13996
  '~': value => ~value
14785
13997
  };
13998
+ const UNASSIGNED = Symbol('Unassigned');
14786
13999
  class UnaryExpression extends NodeBase {
14000
+ constructor() {
14001
+ super(...arguments);
14002
+ this.renderedLiteralValue = UNASSIGNED;
14003
+ }
14787
14004
  get prefix() {
14788
14005
  return isFlagSet(this.flags, 2097152 /* Flag.prefix */);
14789
14006
  }
14790
14007
  set prefix(value) {
14791
14008
  this.flags = setFlag(this.flags, 2097152 /* Flag.prefix */, value);
14792
14009
  }
14010
+ deoptimizeCache() {
14011
+ this.renderedLiteralValue = UnknownValue;
14012
+ }
14793
14013
  getLiteralValueAtPath(path, recursionTracker, origin) {
14794
14014
  if (path.length > 0)
14795
14015
  return UnknownValue;
@@ -14817,8 +14037,55 @@ class UnaryExpression extends NodeBase {
14817
14037
  this.scope.context.requestTreeshakingPass();
14818
14038
  }
14819
14039
  }
14040
+ getRenderedLiteralValue(includeChildrenRecursively) {
14041
+ if (this.renderedLiteralValue !== UNASSIGNED)
14042
+ return this.renderedLiteralValue;
14043
+ return (this.renderedLiteralValue = includeChildrenRecursively
14044
+ ? UnknownValue
14045
+ : getSimplifiedLiterals(this.getLiteralValueAtPath(EMPTY_PATH, SHARED_RECURSION_TRACKER, this)));
14046
+ }
14047
+ include(context, includeChildrenRecursively, _options) {
14048
+ if (!this.deoptimized)
14049
+ this.applyDeoptimizations();
14050
+ this.included = true;
14051
+ if (typeof this.getRenderedLiteralValue(includeChildrenRecursively) === 'symbol' ||
14052
+ this.argument.shouldBeIncluded(context)) {
14053
+ this.argument.include(context, includeChildrenRecursively);
14054
+ this.renderedLiteralValue = UnknownValue;
14055
+ }
14056
+ }
14057
+ render(code, options) {
14058
+ if (typeof this.renderedLiteralValue === 'symbol') {
14059
+ super.render(code, options);
14060
+ }
14061
+ else {
14062
+ code.overwrite(this.start, this.end, this.renderedLiteralValue);
14063
+ }
14064
+ }
14065
+ }
14066
+ function getSimplifiedLiterals(value) {
14067
+ if (value === undefined || typeof value === 'boolean') {
14068
+ return String(value);
14069
+ }
14070
+ if (typeof value === 'string') {
14071
+ return JSON.stringify(value);
14072
+ }
14073
+ if (typeof value === 'number') {
14074
+ return getSimplifiedNumber(value);
14075
+ }
14076
+ return UnknownValue;
14077
+ }
14078
+ function getSimplifiedNumber(value) {
14079
+ if (Object.is(-0, value)) {
14080
+ return '-0';
14081
+ }
14082
+ const exp = value.toExponential();
14083
+ const [base, exponent] = exp.split('e');
14084
+ const floatLength = base.split('.')[1]?.length || 0;
14085
+ const finalizedExp = `${base.replace('.', '')}e${parseInt(exponent) - floatLength}`;
14086
+ const stringifiedValue = String(value).replace('+', '');
14087
+ return finalizedExp.length < stringifiedValue.length ? finalizedExp : stringifiedValue;
14820
14088
  }
14821
- UnaryExpression.prototype.includeNode = onlyIncludeSelf;
14822
14089
 
14823
14090
  class UpdateExpression extends NodeBase {
14824
14091
  hasEffects(context) {
@@ -14830,8 +14097,9 @@ class UpdateExpression extends NodeBase {
14830
14097
  return path.length > 1 || type !== INTERACTION_ACCESSED;
14831
14098
  }
14832
14099
  include(context, includeChildrenRecursively) {
14833
- if (!this.included)
14834
- this.includeNode(context);
14100
+ if (!this.deoptimized)
14101
+ this.applyDeoptimizations();
14102
+ this.included = true;
14835
14103
  this.argument.includeAsAssignmentTarget(context, includeChildrenRecursively, true);
14836
14104
  }
14837
14105
  initialise() {
@@ -14870,7 +14138,6 @@ class UpdateExpression extends NodeBase {
14870
14138
  this.scope.context.requestTreeshakingPass();
14871
14139
  }
14872
14140
  }
14873
- UpdateExpression.prototype.includeNode = onlyIncludeSelf;
14874
14141
 
14875
14142
  function areAllDeclarationsIncludedAndNotExported(declarations, exportNamesByVariable) {
14876
14143
  for (const declarator of declarations) {
@@ -14901,9 +14168,8 @@ class VariableDeclaration extends NodeBase {
14901
14168
  include(context, includeChildrenRecursively, { asSingleStatement } = BLANK) {
14902
14169
  this.included = true;
14903
14170
  for (const declarator of this.declarations) {
14904
- if (includeChildrenRecursively || declarator.shouldBeIncluded(context)) {
14171
+ if (includeChildrenRecursively || declarator.shouldBeIncluded(context))
14905
14172
  declarator.include(context, includeChildrenRecursively);
14906
- }
14907
14173
  const { id, init } = declarator;
14908
14174
  if (asSingleStatement) {
14909
14175
  id.include(context, includeChildrenRecursively);
@@ -14941,6 +14207,7 @@ class VariableDeclaration extends NodeBase {
14941
14207
  this.renderReplacedDeclarations(code, options);
14942
14208
  }
14943
14209
  }
14210
+ applyDeoptimizations() { }
14944
14211
  renderDeclarationEnd(code, separatorString, lastSeparatorPos, actualContentEnd, renderedContentEnd, systemPatternExports, options) {
14945
14212
  if (code.original.charCodeAt(this.end - 1) === 59 /*";"*/) {
14946
14213
  code.remove(this.end - 1, this.end);
@@ -14983,7 +14250,8 @@ class VariableDeclaration extends NodeBase {
14983
14250
  const singleSystemExport = gatherSystemExportsAndGetSingleExport(separatedNodes, options, aggregatedSystemExports);
14984
14251
  for (const { node, start, separator, contentEnd, end } of separatedNodes) {
14985
14252
  if (!node.included) {
14986
- treeshakeNode(node, code, start, end);
14253
+ code.remove(start, end);
14254
+ node.removeAnnotations(code);
14987
14255
  continue;
14988
14256
  }
14989
14257
  node.render(code, options);
@@ -15053,8 +14321,6 @@ function gatherSystemExportsAndGetSingleExport(separatedNodes, options, aggregat
15053
14321
  }
15054
14322
  return singleSystemExport;
15055
14323
  }
15056
- VariableDeclaration.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
15057
- VariableDeclaration.prototype.applyDeoptimizations = doNotDeoptimize;
15058
14324
 
15059
14325
  class WhileStatement extends NodeBase {
15060
14326
  hasEffects(context) {
@@ -15068,25 +14334,13 @@ class WhileStatement extends NodeBase {
15068
14334
  includeLoopBody(context, this.body, includeChildrenRecursively);
15069
14335
  }
15070
14336
  }
15071
- WhileStatement.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
15072
- WhileStatement.prototype.applyDeoptimizations = doNotDeoptimize;
15073
14337
 
15074
14338
  class YieldExpression extends NodeBase {
15075
- applyDeoptimizations() {
15076
- this.deoptimized = true;
15077
- this.argument?.deoptimizePath(UNKNOWN_PATH);
15078
- }
15079
14339
  hasEffects(context) {
15080
14340
  if (!this.deoptimized)
15081
14341
  this.applyDeoptimizations();
15082
14342
  return !(context.ignore.returnYield && !this.argument?.hasEffects(context));
15083
14343
  }
15084
- includeNode(context) {
15085
- this.included = true;
15086
- if (!this.deoptimized)
15087
- this.applyDeoptimizations();
15088
- this.argument?.includePath(UNKNOWN_PATH, context);
15089
- }
15090
14344
  render(code, options) {
15091
14345
  if (this.argument) {
15092
14346
  this.argument.render(code, options, { preventASI: true });
@@ -15320,7 +14574,7 @@ const bufferParsers = [
15320
14574
  const annotations = (node.annotations = convertAnnotations(buffer[position + 1], buffer));
15321
14575
  node.annotationNoSideEffects = annotations.some(comment => comment.type === 'noSideEffects');
15322
14576
  const parameters = (node.params = convertNodeList(node, scope, buffer[position + 2], buffer));
15323
- scope.addParameterVariables(parameters.map(parameter => parameter.declare('parameter', EMPTY_PATH, UNKNOWN_EXPRESSION)), parameters[parameters.length - 1] instanceof RestElement);
14577
+ scope.addParameterVariables(parameters.map(parameter => parameter.declare('parameter', UNKNOWN_EXPRESSION)), parameters[parameters.length - 1] instanceof RestElement);
15324
14578
  node.body = convertNode(node, scope.bodyScope, buffer[position + 3], buffer);
15325
14579
  },
15326
14580
  function assignmentExpression(node, position, buffer) {
@@ -15366,7 +14620,7 @@ const bufferParsers = [
15366
14620
  const parameterPosition = buffer[position];
15367
14621
  const parameter = (node.param =
15368
14622
  parameterPosition === 0 ? null : convertNode(node, scope, parameterPosition, buffer));
15369
- parameter?.declare('parameter', EMPTY_PATH, UNKNOWN_EXPRESSION);
14623
+ parameter?.declare('parameter', UNKNOWN_EXPRESSION);
15370
14624
  node.body = convertNode(node, scope.bodyScope, buffer[position + 1], buffer);
15371
14625
  },
15372
14626
  function chainExpression(node, position, buffer) {
@@ -15504,7 +14758,7 @@ const bufferParsers = [
15504
14758
  node.id =
15505
14759
  idPosition === 0 ? null : convertNode(node, scope.parent, idPosition, buffer);
15506
14760
  const parameters = (node.params = convertNodeList(node, scope, buffer[position + 3], buffer));
15507
- scope.addParameterVariables(parameters.map(parameter => parameter.declare('parameter', EMPTY_PATH, UNKNOWN_EXPRESSION)), parameters[parameters.length - 1] instanceof RestElement);
14761
+ scope.addParameterVariables(parameters.map(parameter => parameter.declare('parameter', UNKNOWN_EXPRESSION)), parameters[parameters.length - 1] instanceof RestElement);
15508
14762
  node.body = convertNode(node, scope.bodyScope, buffer[position + 4], buffer);
15509
14763
  },
15510
14764
  function functionExpression(node, position, buffer) {
@@ -15517,7 +14771,7 @@ const bufferParsers = [
15517
14771
  const idPosition = buffer[position + 2];
15518
14772
  node.id = idPosition === 0 ? null : convertNode(node, node.idScope, idPosition, buffer);
15519
14773
  const parameters = (node.params = convertNodeList(node, scope, buffer[position + 3], buffer));
15520
- scope.addParameterVariables(parameters.map(parameter => parameter.declare('parameter', EMPTY_PATH, UNKNOWN_EXPRESSION)), parameters[parameters.length - 1] instanceof RestElement);
14774
+ scope.addParameterVariables(parameters.map(parameter => parameter.declare('parameter', UNKNOWN_EXPRESSION)), parameters[parameters.length - 1] instanceof RestElement);
15521
14775
  node.body = convertNode(node, scope.bodyScope, buffer[position + 4], buffer);
15522
14776
  },
15523
14777
  function identifier(node, position, buffer) {
@@ -15981,8 +15235,8 @@ class ExportShimVariable extends Variable {
15981
15235
  super(MISSING_EXPORT_SHIM_VARIABLE);
15982
15236
  this.module = module;
15983
15237
  }
15984
- includePath(path, context) {
15985
- super.includePath(path, context);
15238
+ include() {
15239
+ super.include();
15986
15240
  this.module.needsExportShim = true;
15987
15241
  }
15988
15242
  }
@@ -16680,15 +15934,16 @@ class Module {
16680
15934
  markModuleAndImpureDependenciesAsExecuted(this);
16681
15935
  this.graph.needsTreeshakingPass = true;
16682
15936
  }
16683
- const inclusionContext = createInclusionContext();
16684
15937
  for (const exportName of this.exports.keys()) {
16685
15938
  if (includeNamespaceMembers || exportName !== this.info.syntheticNamedExports) {
16686
15939
  const variable = this.getVariableForExportName(exportName)[0];
16687
15940
  if (!variable) {
16688
15941
  return error(logMissingEntryExport(exportName, this.id));
16689
15942
  }
16690
- this.includeVariable(variable, UNKNOWN_PATH, inclusionContext);
16691
15943
  variable.deoptimizePath(UNKNOWN_PATH);
15944
+ if (!variable.included) {
15945
+ this.includeVariable(variable);
15946
+ }
16692
15947
  }
16693
15948
  }
16694
15949
  for (const name of this.getReexports()) {
@@ -16696,7 +15951,7 @@ class Module {
16696
15951
  if (variable) {
16697
15952
  variable.deoptimizePath(UNKNOWN_PATH);
16698
15953
  if (!variable.included) {
16699
- this.includeVariable(variable, UNKNOWN_PATH, inclusionContext);
15954
+ this.includeVariable(variable);
16700
15955
  }
16701
15956
  if (variable instanceof ExternalVariable) {
16702
15957
  variable.module.reexported = true;
@@ -16717,12 +15972,13 @@ class Module {
16717
15972
  this.graph.needsTreeshakingPass = true;
16718
15973
  }
16719
15974
  let includeNamespaceMembers = false;
16720
- const inclusionContext = createInclusionContext();
16721
15975
  for (const name of names) {
16722
15976
  const variable = this.getVariableForExportName(name)[0];
16723
15977
  if (variable) {
16724
15978
  variable.deoptimizePath(UNKNOWN_PATH);
16725
- this.includeVariable(variable, UNKNOWN_PATH, inclusionContext);
15979
+ if (!variable.included) {
15980
+ this.includeVariable(variable);
15981
+ }
16726
15982
  }
16727
15983
  if (!this.exports.has(name) && !this.reexportDescriptions.has(name)) {
16728
15984
  includeNamespaceMembers = true;
@@ -16823,7 +16079,6 @@ class Module {
16823
16079
  manualPureFunctions: this.graph.pureFunctions,
16824
16080
  module: this,
16825
16081
  moduleContext: this.context,
16826
- newlyIncludedVariableInits: this.graph.newlyIncludedVariableInits,
16827
16082
  options: this.options,
16828
16083
  requestTreeshakingPass: () => (this.graph.needsTreeshakingPass = true),
16829
16084
  traceExport: (name) => this.getVariableForExportName(name)[0],
@@ -17164,13 +16419,13 @@ class Module {
17164
16419
  for (const module of [this, ...this.exportAllModules]) {
17165
16420
  if (module instanceof ExternalModule) {
17166
16421
  const [externalVariable] = module.getVariableForExportName('*');
17167
- externalVariable.includePath(UNKNOWN_PATH, createInclusionContext());
16422
+ externalVariable.include();
17168
16423
  this.includedImports.add(externalVariable);
17169
16424
  externalNamespaces.add(externalVariable);
17170
16425
  }
17171
16426
  else if (module.info.syntheticNamedExports) {
17172
16427
  const syntheticNamespace = module.getSyntheticNamespace();
17173
- syntheticNamespace.includePath(UNKNOWN_PATH, createInclusionContext());
16428
+ syntheticNamespace.include();
17174
16429
  this.includedImports.add(syntheticNamespace);
17175
16430
  syntheticNamespaces.add(syntheticNamespace);
17176
16431
  }
@@ -17180,9 +16435,7 @@ class Module {
17180
16435
  includeDynamicImport(node) {
17181
16436
  const resolution = this.dynamicImports.find(dynamicImport => dynamicImport.node === node).resolution;
17182
16437
  if (resolution instanceof Module) {
17183
- if (!resolution.includedDynamicImporters.includes(this)) {
17184
- resolution.includedDynamicImporters.push(this);
17185
- }
16438
+ resolution.includedDynamicImporters.push(this);
17186
16439
  const importedNames = this.options.treeshake
17187
16440
  ? node.getDeterministicImportedNames()
17188
16441
  : undefined;
@@ -17194,15 +16447,15 @@ class Module {
17194
16447
  }
17195
16448
  }
17196
16449
  }
17197
- includeVariable(variable, path, context) {
17198
- const { included, module: variableModule } = variable;
17199
- variable.includePath(path, context);
17200
- if (included) {
16450
+ includeVariable(variable) {
16451
+ const variableModule = variable.module;
16452
+ if (variable.included) {
17201
16453
  if (variableModule instanceof Module && variableModule !== this) {
17202
16454
  getAndExtendSideEffectModules(variable, this);
17203
16455
  }
17204
16456
  }
17205
16457
  else {
16458
+ variable.include();
17206
16459
  this.graph.needsTreeshakingPass = true;
17207
16460
  if (variableModule instanceof Module) {
17208
16461
  if (!variableModule.isExecuted) {
@@ -17219,8 +16472,8 @@ class Module {
17219
16472
  }
17220
16473
  }
17221
16474
  }
17222
- includeVariableInModule(variable, path, context) {
17223
- this.includeVariable(variable, path, context);
16475
+ includeVariableInModule(variable) {
16476
+ this.includeVariable(variable);
17224
16477
  const variableModule = variable.module;
17225
16478
  if (variableModule && variableModule !== this) {
17226
16479
  this.includedImports.add(variable);
@@ -18266,7 +17519,9 @@ class Chunk {
18266
17519
  }
18267
17520
  return [
18268
17521
  resolution || '',
18269
- (this.outputOptions.format === 'es' && this.outputOptions.externalImportAttributes) || null
17522
+ (['es', 'cjs'].includes(this.outputOptions.format) &&
17523
+ this.outputOptions.externalImportAttributes) ||
17524
+ null
18270
17525
  ];
18271
17526
  }
18272
17527
  getFallbackChunkName() {
@@ -20119,18 +19374,18 @@ function flru (max) {
20119
19374
  return {
20120
19375
  clear: reset,
20121
19376
  has: function (key) {
20122
- return curr[key] !== void 0 || prev[key] !== void 0;
19377
+ return curr[key] !== undefined || prev[key] !== undefined;
20123
19378
  },
20124
19379
  get: function (key) {
20125
19380
  var val = curr[key];
20126
- if (val !== void 0) return val;
20127
- if ((val=prev[key]) !== void 0) {
19381
+ if (val !== undefined) return val;
19382
+ if ((val=prev[key]) !== undefined) {
20128
19383
  keep(key, val);
20129
19384
  return val;
20130
19385
  }
20131
19386
  },
20132
19387
  set: function (key, value) {
20133
- if (curr[key] !== void 0) {
19388
+ if (curr[key] !== undefined) {
20134
19389
  curr[key] = value;
20135
19390
  } else {
20136
19391
  keep(key, value);
@@ -21817,11 +21072,10 @@ class Graph {
21817
21072
  this.options = options;
21818
21073
  this.astLru = flru(5);
21819
21074
  this.cachedModules = new Map();
21820
- this.deoptimizationTracker = new EntityPathTracker();
21075
+ this.deoptimizationTracker = new PathTracker();
21821
21076
  this.entryModules = [];
21822
21077
  this.modulesById = new Map();
21823
21078
  this.needsTreeshakingPass = false;
21824
- this.newlyIncludedVariableInits = new Set();
21825
21079
  this.phase = BuildPhase.LOAD_AND_PARSE;
21826
21080
  this.scope = new GlobalScope();
21827
21081
  this.watchFiles = Object.create(null);
@@ -21915,7 +21169,6 @@ class Graph {
21915
21169
  }
21916
21170
  if (this.options.treeshake) {
21917
21171
  let treeshakingPass = 1;
21918
- this.newlyIncludedVariableInits.clear();
21919
21172
  do {
21920
21173
  timeStart(`treeshaking pass ${treeshakingPass}`, 3);
21921
21174
  this.needsTreeshakingPass = false;
@@ -21940,10 +21193,6 @@ class Graph {
21940
21193
  }
21941
21194
  }
21942
21195
  }
21943
- for (const entity of this.newlyIncludedVariableInits) {
21944
- this.newlyIncludedVariableInits.delete(entity);
21945
- entity.include(createInclusionContext(), false);
21946
- }
21947
21196
  timeEnd(`treeshaking pass ${treeshakingPass++}`, 3);
21948
21197
  } while (this.needsTreeshakingPass);
21949
21198
  }
@@ -22714,118 +21963,97 @@ function defineConfig(options) {
22714
21963
  return options;
22715
21964
  }
22716
21965
 
22717
- const {
22718
- env = {},
22719
- argv = [],
22720
- platform = "",
22721
- } = typeof process === "undefined" ? {} : process;
22722
-
22723
- const isDisabled = "NO_COLOR" in env || argv.includes("--no-color");
22724
- const isForced = "FORCE_COLOR" in env || argv.includes("--color");
22725
- const isWindows = platform === "win32";
22726
- const isDumbTerminal = env.TERM === "dumb";
22727
-
22728
- const isCompatibleTerminal =
22729
- tty && tty.isatty && tty.isatty(1) && env.TERM && !isDumbTerminal;
22730
-
22731
- const isCI =
22732
- "CI" in env &&
22733
- ("GITHUB_ACTIONS" in env || "GITLAB_CI" in env || "CIRCLECI" in env);
22734
-
22735
- const isColorSupported =
22736
- !isDisabled &&
22737
- (isForced || (isWindows && !isDumbTerminal) || isCompatibleTerminal || isCI);
22738
-
22739
- const replaceClose = (
22740
- index,
22741
- string,
22742
- close,
22743
- replace,
22744
- head = string.substring(0, index) + replace,
22745
- tail = string.substring(index + close.length),
22746
- next = tail.indexOf(close)
22747
- ) => head + (next < 0 ? tail : replaceClose(next, tail, close, replace));
22748
-
22749
- const clearBleed = (index, string, open, close, replace) =>
22750
- index < 0
22751
- ? open + string + close
22752
- : open + replaceClose(index, string, close, replace) + close;
22753
-
22754
- const filterEmpty =
22755
- (open, close, replace = open, at = open.length + 1) =>
22756
- (string) =>
22757
- string || !(string === "" || string === undefined)
22758
- ? clearBleed(
22759
- ("" + string).indexOf(close, at),
22760
- string,
22761
- open,
22762
- close,
22763
- replace
22764
- )
22765
- : "";
22766
-
22767
- const init = (open, close, replace) =>
22768
- filterEmpty(`\x1b[${open}m`, `\x1b[${close}m`, replace);
22769
-
22770
- const colors = {
22771
- reset: init(0, 0),
22772
- bold: init(1, 22, "\x1b[22m\x1b[1m"),
22773
- dim: init(2, 22, "\x1b[22m\x1b[2m"),
22774
- italic: init(3, 23),
22775
- underline: init(4, 24),
22776
- inverse: init(7, 27),
22777
- hidden: init(8, 28),
22778
- strikethrough: init(9, 29),
22779
- black: init(30, 39),
22780
- red: init(31, 39),
22781
- green: init(32, 39),
22782
- yellow: init(33, 39),
22783
- blue: init(34, 39),
22784
- magenta: init(35, 39),
22785
- cyan: init(36, 39),
22786
- white: init(37, 39),
22787
- gray: init(90, 39),
22788
- bgBlack: init(40, 49),
22789
- bgRed: init(41, 49),
22790
- bgGreen: init(42, 49),
22791
- bgYellow: init(43, 49),
22792
- bgBlue: init(44, 49),
22793
- bgMagenta: init(45, 49),
22794
- bgCyan: init(46, 49),
22795
- bgWhite: init(47, 49),
22796
- blackBright: init(90, 39),
22797
- redBright: init(91, 39),
22798
- greenBright: init(92, 39),
22799
- yellowBright: init(93, 39),
22800
- blueBright: init(94, 39),
22801
- magentaBright: init(95, 39),
22802
- cyanBright: init(96, 39),
22803
- whiteBright: init(97, 39),
22804
- bgBlackBright: init(100, 49),
22805
- bgRedBright: init(101, 49),
22806
- bgGreenBright: init(102, 49),
22807
- bgYellowBright: init(103, 49),
22808
- bgBlueBright: init(104, 49),
22809
- bgMagentaBright: init(105, 49),
22810
- bgCyanBright: init(106, 49),
22811
- bgWhiteBright: init(107, 49),
22812
- };
21966
+ var picocolors = {exports: {}};
21967
+
21968
+ var hasRequiredPicocolors;
21969
+
21970
+ function requirePicocolors () {
21971
+ if (hasRequiredPicocolors) return picocolors.exports;
21972
+ hasRequiredPicocolors = 1;
21973
+ let p = process || {}, argv = p.argv || [], env = p.env || {};
21974
+ let isColorSupported =
21975
+ !(!!env.NO_COLOR || argv.includes("--no-color")) &&
21976
+ (!!env.FORCE_COLOR || argv.includes("--color") || p.platform === "win32" || ((p.stdout || {}).isTTY && env.TERM !== "dumb") || !!env.CI);
21977
+
21978
+ let formatter = (open, close, replace = open) =>
21979
+ input => {
21980
+ let string = "" + input, index = string.indexOf(close, open.length);
21981
+ return ~index ? open + replaceClose(string, close, replace, index) + close : open + string + close
21982
+ };
21983
+
21984
+ let replaceClose = (string, close, replace, index) => {
21985
+ let result = "", cursor = 0;
21986
+ do {
21987
+ result += string.substring(cursor, index) + replace;
21988
+ cursor = index + close.length;
21989
+ index = string.indexOf(close, cursor);
21990
+ } while (~index)
21991
+ return result + string.substring(cursor)
21992
+ };
21993
+
21994
+ let createColors = (enabled = isColorSupported) => {
21995
+ let f = enabled ? formatter : () => String;
21996
+ return {
21997
+ isColorSupported: enabled,
21998
+ reset: f("\x1b[0m", "\x1b[0m"),
21999
+ bold: f("\x1b[1m", "\x1b[22m", "\x1b[22m\x1b[1m"),
22000
+ dim: f("\x1b[2m", "\x1b[22m", "\x1b[22m\x1b[2m"),
22001
+ italic: f("\x1b[3m", "\x1b[23m"),
22002
+ underline: f("\x1b[4m", "\x1b[24m"),
22003
+ inverse: f("\x1b[7m", "\x1b[27m"),
22004
+ hidden: f("\x1b[8m", "\x1b[28m"),
22005
+ strikethrough: f("\x1b[9m", "\x1b[29m"),
22006
+
22007
+ black: f("\x1b[30m", "\x1b[39m"),
22008
+ red: f("\x1b[31m", "\x1b[39m"),
22009
+ green: f("\x1b[32m", "\x1b[39m"),
22010
+ yellow: f("\x1b[33m", "\x1b[39m"),
22011
+ blue: f("\x1b[34m", "\x1b[39m"),
22012
+ magenta: f("\x1b[35m", "\x1b[39m"),
22013
+ cyan: f("\x1b[36m", "\x1b[39m"),
22014
+ white: f("\x1b[37m", "\x1b[39m"),
22015
+ gray: f("\x1b[90m", "\x1b[39m"),
22016
+
22017
+ bgBlack: f("\x1b[40m", "\x1b[49m"),
22018
+ bgRed: f("\x1b[41m", "\x1b[49m"),
22019
+ bgGreen: f("\x1b[42m", "\x1b[49m"),
22020
+ bgYellow: f("\x1b[43m", "\x1b[49m"),
22021
+ bgBlue: f("\x1b[44m", "\x1b[49m"),
22022
+ bgMagenta: f("\x1b[45m", "\x1b[49m"),
22023
+ bgCyan: f("\x1b[46m", "\x1b[49m"),
22024
+ bgWhite: f("\x1b[47m", "\x1b[49m"),
22025
+
22026
+ blackBright: f("\x1b[90m", "\x1b[39m"),
22027
+ redBright: f("\x1b[91m", "\x1b[39m"),
22028
+ greenBright: f("\x1b[92m", "\x1b[39m"),
22029
+ yellowBright: f("\x1b[93m", "\x1b[39m"),
22030
+ blueBright: f("\x1b[94m", "\x1b[39m"),
22031
+ magentaBright: f("\x1b[95m", "\x1b[39m"),
22032
+ cyanBright: f("\x1b[96m", "\x1b[39m"),
22033
+ whiteBright: f("\x1b[97m", "\x1b[39m"),
22034
+
22035
+ bgBlackBright: f("\x1b[100m", "\x1b[49m"),
22036
+ bgRedBright: f("\x1b[101m", "\x1b[49m"),
22037
+ bgGreenBright: f("\x1b[102m", "\x1b[49m"),
22038
+ bgYellowBright: f("\x1b[103m", "\x1b[49m"),
22039
+ bgBlueBright: f("\x1b[104m", "\x1b[49m"),
22040
+ bgMagentaBright: f("\x1b[105m", "\x1b[49m"),
22041
+ bgCyanBright: f("\x1b[106m", "\x1b[49m"),
22042
+ bgWhiteBright: f("\x1b[107m", "\x1b[49m"),
22043
+ }
22044
+ };
22813
22045
 
22814
- const createColors = ({ useColor = isColorSupported } = {}) =>
22815
- useColor
22816
- ? colors
22817
- : Object.keys(colors).reduce(
22818
- (colors, key) => ({ ...colors, [key]: String }),
22819
- {}
22820
- );
22046
+ picocolors.exports = createColors();
22047
+ picocolors.exports.createColors = createColors;
22048
+ return picocolors.exports;
22049
+ }
22821
22050
 
22822
- createColors();
22051
+ var picocolorsExports = /*@__PURE__*/ requirePicocolors();
22052
+ const pc = /*@__PURE__*/getDefaultExportFromCjs(picocolorsExports);
22823
22053
 
22824
22054
  // @see https://no-color.org
22825
22055
  // @see https://www.npmjs.com/package/chalk
22826
- const { bold, cyan, dim, red} = createColors({
22827
- useColor: env$1.FORCE_COLOR !== '0' && !env$1.NO_COLOR
22828
- });
22056
+ const { bold, cyan, dim, gray, green, red, underline, yellow } = pc.createColors(env.FORCE_COLOR !== '0' && !env.NO_COLOR);
22829
22057
 
22830
22058
  // log to stderr to keep `rollup main.js > bundle.js` from breaking
22831
22059
  const stderr = (...parameters) => process$1.stderr.write(`${parameters.join('')}\n`);