rollup 2.58.3 → 2.60.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,7 +1,7 @@
1
1
  /*
2
2
  @license
3
- Rollup.js v2.58.3
4
- Mon, 25 Oct 2021 13:49:07 GMT - commit 0b8d4c668683c7702f20fcf480db077dbe2be774
3
+ Rollup.js v2.60.0
4
+ Fri, 12 Nov 2021 05:12:41 GMT - commit 8d98341bf746d4baa57bbd730b1fa6449555cfca
5
5
 
6
6
 
7
7
  https://github.com/rollup/rollup
@@ -13,7 +13,7 @@ import { createHash as createHash$1 } from 'crypto';
13
13
  import fs, { lstatSync, realpathSync, readdirSync } from 'fs';
14
14
  import { EventEmitter } from 'events';
15
15
 
16
- var version$1 = "2.58.3";
16
+ var version$1 = "2.60.0";
17
17
 
18
18
  var charToInteger = {};
19
19
  var chars$1 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
@@ -4592,13 +4592,11 @@ class NodeBase extends ExpressionEntity {
4592
4592
  for (const child of value) {
4593
4593
  this[key].push(child === null
4594
4594
  ? null
4595
- : new (this.context.nodeConstructors[child.type] ||
4596
- this.context.nodeConstructors.UnknownNode)(child, this, this.scope));
4595
+ : new (this.context.getNodeConstructor(child.type))(child, this, this.scope));
4597
4596
  }
4598
4597
  }
4599
4598
  else {
4600
- this[key] = new (this.context.nodeConstructors[value.type] ||
4601
- this.context.nodeConstructors.UnknownNode)(value, this, this.scope);
4599
+ this[key] = new (this.context.getNodeConstructor(value.type))(value, this, this.scope);
4602
4600
  }
4603
4601
  }
4604
4602
  }
@@ -4836,576 +4834,83 @@ function renderSystemExportSequenceBeforeExpression(exportedVariable, expression
4836
4834
  }
4837
4835
  }
4838
4836
 
4839
- const chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_$';
4840
- const base = 64;
4841
- function toBase64(num) {
4842
- let outStr = '';
4843
- do {
4844
- const curDigit = num % base;
4845
- num = Math.floor(num / base);
4846
- outStr = chars[curDigit] + outStr;
4847
- } while (num !== 0);
4848
- return outStr;
4849
- }
4837
+ //@ts-check
4838
+ /** @typedef { import('estree').Node} Node */
4839
+ /** @typedef {Node | {
4840
+ * type: 'PropertyDefinition';
4841
+ * computed: boolean;
4842
+ * value: Node
4843
+ * }} NodeWithPropertyDefinition */
4850
4844
 
4851
- const RESERVED_NAMES = {
4852
- __proto__: null,
4853
- await: true,
4854
- break: true,
4855
- case: true,
4856
- catch: true,
4857
- class: true,
4858
- const: true,
4859
- continue: true,
4860
- debugger: true,
4861
- default: true,
4862
- delete: true,
4863
- do: true,
4864
- else: true,
4865
- enum: true,
4866
- eval: true,
4867
- export: true,
4868
- extends: true,
4869
- false: true,
4870
- finally: true,
4871
- for: true,
4872
- function: true,
4873
- if: true,
4874
- implements: true,
4875
- import: true,
4876
- in: true,
4877
- instanceof: true,
4878
- interface: true,
4879
- let: true,
4880
- new: true,
4881
- null: true,
4882
- package: true,
4883
- private: true,
4884
- protected: true,
4885
- public: true,
4886
- return: true,
4887
- static: true,
4888
- super: true,
4889
- switch: true,
4890
- this: true,
4891
- throw: true,
4892
- true: true,
4893
- try: true,
4894
- typeof: true,
4895
- undefined: true,
4896
- var: true,
4897
- void: true,
4898
- while: true,
4899
- with: true,
4900
- yield: true
4901
- };
4845
+ /**
4846
+ *
4847
+ * @param {NodeWithPropertyDefinition} node
4848
+ * @param {NodeWithPropertyDefinition} parent
4849
+ * @returns boolean
4850
+ */
4851
+ function is_reference (node, parent) {
4852
+ if (node.type === 'MemberExpression') {
4853
+ return !node.computed && is_reference(node.object, node);
4854
+ }
4902
4855
 
4903
- function getSafeName(baseName, usedNames) {
4904
- let safeName = baseName;
4905
- let count = 1;
4906
- while (usedNames.has(safeName) || RESERVED_NAMES[safeName]) {
4907
- safeName = `${baseName}$${toBase64(count++)}`;
4908
- }
4909
- usedNames.add(safeName);
4910
- return safeName;
4911
- }
4856
+ if (node.type === 'Identifier') {
4857
+ if (!parent) return true;
4912
4858
 
4913
- const NO_ARGS = [];
4859
+ switch (parent.type) {
4860
+ // disregard `bar` in `foo.bar`
4861
+ case 'MemberExpression': return parent.computed || node === parent.object;
4914
4862
 
4915
- function assembleMemberDescriptions(memberDescriptions, inheritedDescriptions = null) {
4916
- return Object.create(inheritedDescriptions, memberDescriptions);
4863
+ // disregard the `foo` in `class {foo(){}}` but keep it in `class {[foo](){}}`
4864
+ case 'MethodDefinition': return parent.computed;
4865
+
4866
+ // disregard the `foo` in `class {foo=bar}` but keep it in `class {[foo]=bar}` and `class {bar=foo}`
4867
+ case 'PropertyDefinition': return parent.computed || node === parent.value;
4868
+
4869
+ // disregard the `bar` in `{ bar: foo }`, but keep it in `{ [bar]: foo }`
4870
+ case 'Property': return parent.computed || node === parent.value;
4871
+
4872
+ // disregard the `bar` in `export { foo as bar }` or
4873
+ // the foo in `import { foo as bar }`
4874
+ case 'ExportSpecifier':
4875
+ case 'ImportSpecifier': return node === parent.local;
4876
+
4877
+ // disregard the `foo` in `foo: while (...) { ... break foo; ... continue foo;}`
4878
+ case 'LabeledStatement':
4879
+ case 'BreakStatement':
4880
+ case 'ContinueStatement': return false;
4881
+ default: return true;
4882
+ }
4883
+ }
4884
+
4885
+ return false;
4917
4886
  }
4918
- const UNDEFINED_EXPRESSION = new (class UndefinedExpression extends ExpressionEntity {
4919
- getLiteralValueAtPath() {
4920
- return undefined;
4921
- }
4922
- })();
4923
- const returnsUnknown = {
4924
- value: {
4925
- callsArgs: null,
4926
- returns: UNKNOWN_EXPRESSION
4927
- }
4887
+
4888
+ /* eslint sort-keys: "off" */
4889
+ const ValueProperties = Symbol('Value Properties');
4890
+ const PURE = { pure: true };
4891
+ const IMPURE = { pure: false };
4892
+ // We use shortened variables to reduce file size here
4893
+ /* OBJECT */
4894
+ const O = {
4895
+ __proto__: null,
4896
+ [ValueProperties]: IMPURE
4928
4897
  };
4929
- const UNKNOWN_LITERAL_BOOLEAN = new (class UnknownBoolean extends ExpressionEntity {
4930
- getReturnExpressionWhenCalledAtPath(path) {
4931
- if (path.length === 1) {
4932
- return getMemberReturnExpressionWhenCalled(literalBooleanMembers, path[0]);
4933
- }
4934
- return UNKNOWN_EXPRESSION;
4935
- }
4936
- hasEffectsWhenAccessedAtPath(path) {
4937
- return path.length > 1;
4938
- }
4939
- hasEffectsWhenCalledAtPath(path, callOptions, context) {
4940
- if (path.length === 1) {
4941
- return hasMemberEffectWhenCalled(literalBooleanMembers, path[0], callOptions, context);
4942
- }
4943
- return true;
4944
- }
4945
- })();
4946
- const returnsBoolean = {
4947
- value: {
4948
- callsArgs: null,
4949
- returns: UNKNOWN_LITERAL_BOOLEAN
4950
- }
4898
+ /* PURE FUNCTION */
4899
+ const PF = {
4900
+ __proto__: null,
4901
+ [ValueProperties]: PURE
4951
4902
  };
4952
- const UNKNOWN_LITERAL_NUMBER = new (class UnknownNumber extends ExpressionEntity {
4953
- getReturnExpressionWhenCalledAtPath(path) {
4954
- if (path.length === 1) {
4955
- return getMemberReturnExpressionWhenCalled(literalNumberMembers, path[0]);
4956
- }
4957
- return UNKNOWN_EXPRESSION;
4958
- }
4959
- hasEffectsWhenAccessedAtPath(path) {
4960
- return path.length > 1;
4961
- }
4962
- hasEffectsWhenCalledAtPath(path, callOptions, context) {
4963
- if (path.length === 1) {
4964
- return hasMemberEffectWhenCalled(literalNumberMembers, path[0], callOptions, context);
4965
- }
4966
- return true;
4967
- }
4968
- })();
4969
- const returnsNumber = {
4970
- value: {
4971
- callsArgs: null,
4972
- returns: UNKNOWN_LITERAL_NUMBER
4973
- }
4903
+ /* CONSTRUCTOR */
4904
+ const C = {
4905
+ __proto__: null,
4906
+ [ValueProperties]: IMPURE,
4907
+ prototype: O
4974
4908
  };
4975
- const UNKNOWN_LITERAL_STRING = new (class UnknownString extends ExpressionEntity {
4976
- getReturnExpressionWhenCalledAtPath(path) {
4977
- if (path.length === 1) {
4978
- return getMemberReturnExpressionWhenCalled(literalStringMembers, path[0]);
4979
- }
4980
- return UNKNOWN_EXPRESSION;
4981
- }
4982
- hasEffectsWhenAccessedAtPath(path) {
4983
- return path.length > 1;
4984
- }
4985
- hasEffectsWhenCalledAtPath(path, callOptions, context) {
4986
- if (path.length === 1) {
4987
- return hasMemberEffectWhenCalled(literalStringMembers, path[0], callOptions, context);
4988
- }
4989
- return true;
4990
- }
4991
- })();
4992
- const returnsString = {
4993
- value: {
4994
- callsArgs: null,
4995
- returns: UNKNOWN_LITERAL_STRING
4996
- }
4997
- };
4998
- const objectMembers = assembleMemberDescriptions({
4999
- hasOwnProperty: returnsBoolean,
5000
- isPrototypeOf: returnsBoolean,
5001
- propertyIsEnumerable: returnsBoolean,
5002
- toLocaleString: returnsString,
5003
- toString: returnsString,
5004
- valueOf: returnsUnknown
5005
- });
5006
- const literalBooleanMembers = assembleMemberDescriptions({
5007
- valueOf: returnsBoolean
5008
- }, objectMembers);
5009
- const literalNumberMembers = assembleMemberDescriptions({
5010
- toExponential: returnsString,
5011
- toFixed: returnsString,
5012
- toLocaleString: returnsString,
5013
- toPrecision: returnsString,
5014
- valueOf: returnsNumber
5015
- }, objectMembers);
5016
- const literalStringMembers = assembleMemberDescriptions({
5017
- charAt: returnsString,
5018
- charCodeAt: returnsNumber,
5019
- codePointAt: returnsNumber,
5020
- concat: returnsString,
5021
- endsWith: returnsBoolean,
5022
- includes: returnsBoolean,
5023
- indexOf: returnsNumber,
5024
- lastIndexOf: returnsNumber,
5025
- localeCompare: returnsNumber,
5026
- match: returnsBoolean,
5027
- normalize: returnsString,
5028
- padEnd: returnsString,
5029
- padStart: returnsString,
5030
- repeat: returnsString,
5031
- replace: {
5032
- value: {
5033
- callsArgs: [1],
5034
- returns: UNKNOWN_LITERAL_STRING
5035
- }
5036
- },
5037
- search: returnsNumber,
5038
- slice: returnsString,
5039
- split: returnsUnknown,
5040
- startsWith: returnsBoolean,
5041
- substr: returnsString,
5042
- substring: returnsString,
5043
- toLocaleLowerCase: returnsString,
5044
- toLocaleUpperCase: returnsString,
5045
- toLowerCase: returnsString,
5046
- toUpperCase: returnsString,
5047
- trim: returnsString,
5048
- valueOf: returnsString
5049
- }, objectMembers);
5050
- function getLiteralMembersForValue(value) {
5051
- switch (typeof value) {
5052
- case 'boolean':
5053
- return literalBooleanMembers;
5054
- case 'number':
5055
- return literalNumberMembers;
5056
- case 'string':
5057
- return literalStringMembers;
5058
- default:
5059
- return Object.create(null);
5060
- }
5061
- }
5062
- function hasMemberEffectWhenCalled(members, memberName, callOptions, context) {
5063
- if (typeof memberName !== 'string' || !members[memberName]) {
5064
- return true;
5065
- }
5066
- if (!members[memberName].callsArgs)
5067
- return false;
5068
- for (const argIndex of members[memberName].callsArgs) {
5069
- if (callOptions.args[argIndex] &&
5070
- callOptions.args[argIndex].hasEffectsWhenCalledAtPath(EMPTY_PATH, {
5071
- args: NO_ARGS,
5072
- thisParam: null,
5073
- withNew: false
5074
- }, context))
5075
- return true;
5076
- }
5077
- return false;
5078
- }
5079
- function getMemberReturnExpressionWhenCalled(members, memberName) {
5080
- if (typeof memberName !== 'string' || !members[memberName])
5081
- return UNKNOWN_EXPRESSION;
5082
- return members[memberName].returns;
5083
- }
5084
-
5085
- class LocalVariable extends Variable {
5086
- constructor(name, declarator, init, context) {
5087
- super(name);
5088
- this.calledFromTryStatement = false;
5089
- this.additionalInitializers = null;
5090
- this.expressionsToBeDeoptimized = [];
5091
- this.declarations = declarator ? [declarator] : [];
5092
- this.init = init;
5093
- this.deoptimizationTracker = context.deoptimizationTracker;
5094
- this.module = context.module;
5095
- }
5096
- addDeclaration(identifier, init) {
5097
- this.declarations.push(identifier);
5098
- const additionalInitializers = this.markInitializersForDeoptimization();
5099
- if (init !== null) {
5100
- additionalInitializers.push(init);
5101
- }
5102
- }
5103
- consolidateInitializers() {
5104
- if (this.additionalInitializers !== null) {
5105
- for (const initializer of this.additionalInitializers) {
5106
- initializer.deoptimizePath(UNKNOWN_PATH);
5107
- }
5108
- this.additionalInitializers = null;
5109
- }
5110
- }
5111
- deoptimizePath(path) {
5112
- var _a, _b;
5113
- if (this.isReassigned ||
5114
- this.deoptimizationTracker.trackEntityAtPathAndGetIfTracked(path, this)) {
5115
- return;
5116
- }
5117
- if (path.length === 0) {
5118
- if (!this.isReassigned) {
5119
- this.isReassigned = true;
5120
- const expressionsToBeDeoptimized = this.expressionsToBeDeoptimized;
5121
- this.expressionsToBeDeoptimized = [];
5122
- for (const expression of expressionsToBeDeoptimized) {
5123
- expression.deoptimizeCache();
5124
- }
5125
- (_a = this.init) === null || _a === void 0 ? void 0 : _a.deoptimizePath(UNKNOWN_PATH);
5126
- }
5127
- }
5128
- else {
5129
- (_b = this.init) === null || _b === void 0 ? void 0 : _b.deoptimizePath(path);
5130
- }
5131
- }
5132
- deoptimizeThisOnEventAtPath(event, path, thisParameter, recursionTracker) {
5133
- if (this.isReassigned || !this.init) {
5134
- return thisParameter.deoptimizePath(UNKNOWN_PATH);
5135
- }
5136
- recursionTracker.withTrackedEntityAtPath(path, this.init, () => this.init.deoptimizeThisOnEventAtPath(event, path, thisParameter, recursionTracker), undefined);
5137
- }
5138
- getLiteralValueAtPath(path, recursionTracker, origin) {
5139
- if (this.isReassigned || !this.init) {
5140
- return UnknownValue;
5141
- }
5142
- return recursionTracker.withTrackedEntityAtPath(path, this.init, () => {
5143
- this.expressionsToBeDeoptimized.push(origin);
5144
- return this.init.getLiteralValueAtPath(path, recursionTracker, origin);
5145
- }, UnknownValue);
5146
- }
5147
- getReturnExpressionWhenCalledAtPath(path, callOptions, recursionTracker, origin) {
5148
- if (this.isReassigned || !this.init) {
5149
- return UNKNOWN_EXPRESSION;
5150
- }
5151
- return recursionTracker.withTrackedEntityAtPath(path, this.init, () => {
5152
- this.expressionsToBeDeoptimized.push(origin);
5153
- return this.init.getReturnExpressionWhenCalledAtPath(path, callOptions, recursionTracker, origin);
5154
- }, UNKNOWN_EXPRESSION);
5155
- }
5156
- hasEffectsWhenAccessedAtPath(path, context) {
5157
- if (this.isReassigned)
5158
- return true;
5159
- return (this.init &&
5160
- !context.accessed.trackEntityAtPathAndGetIfTracked(path, this) &&
5161
- this.init.hasEffectsWhenAccessedAtPath(path, context));
5162
- }
5163
- hasEffectsWhenAssignedAtPath(path, context) {
5164
- if (this.included)
5165
- return true;
5166
- if (path.length === 0)
5167
- return false;
5168
- if (this.isReassigned)
5169
- return true;
5170
- return (this.init &&
5171
- !context.accessed.trackEntityAtPathAndGetIfTracked(path, this) &&
5172
- this.init.hasEffectsWhenAssignedAtPath(path, context));
5173
- }
5174
- hasEffectsWhenCalledAtPath(path, callOptions, context) {
5175
- if (this.isReassigned)
5176
- return true;
5177
- return (this.init &&
5178
- !(callOptions.withNew ? context.instantiated : context.called).trackEntityAtPathAndGetIfTracked(path, callOptions, this) &&
5179
- this.init.hasEffectsWhenCalledAtPath(path, callOptions, context));
5180
- }
5181
- include() {
5182
- if (!this.included) {
5183
- this.included = true;
5184
- for (const declaration of this.declarations) {
5185
- // If node is a default export, it can save a tree-shaking run to include the full declaration now
5186
- if (!declaration.included)
5187
- declaration.include(createInclusionContext(), false);
5188
- let node = declaration.parent;
5189
- while (!node.included) {
5190
- // We do not want to properly include parents in case they are part of a dead branch
5191
- // in which case .include() might pull in more dead code
5192
- node.included = true;
5193
- if (node.type === Program$1)
5194
- break;
5195
- node = node.parent;
5196
- }
5197
- }
5198
- }
5199
- }
5200
- includeCallArguments(context, args) {
5201
- if (this.isReassigned || (this.init && context.includedCallArguments.has(this.init))) {
5202
- for (const arg of args) {
5203
- arg.include(context, false);
5204
- }
5205
- }
5206
- else if (this.init) {
5207
- context.includedCallArguments.add(this.init);
5208
- this.init.includeCallArguments(context, args);
5209
- context.includedCallArguments.delete(this.init);
5210
- }
5211
- }
5212
- markCalledFromTryStatement() {
5213
- this.calledFromTryStatement = true;
5214
- }
5215
- markInitializersForDeoptimization() {
5216
- if (this.additionalInitializers === null) {
5217
- this.additionalInitializers = this.init === null ? [] : [this.init];
5218
- this.init = UNKNOWN_EXPRESSION;
5219
- this.isReassigned = true;
5220
- }
5221
- return this.additionalInitializers;
5222
- }
5223
- }
5224
-
5225
- class Scope$1 {
5226
- constructor() {
5227
- this.children = [];
5228
- this.variables = new Map();
5229
- }
5230
- addDeclaration(identifier, context, init, _isHoisted) {
5231
- const name = identifier.name;
5232
- let variable = this.variables.get(name);
5233
- if (variable) {
5234
- variable.addDeclaration(identifier, init);
5235
- }
5236
- else {
5237
- variable = new LocalVariable(identifier.name, identifier, init || UNDEFINED_EXPRESSION, context);
5238
- this.variables.set(name, variable);
5239
- }
5240
- return variable;
5241
- }
5242
- contains(name) {
5243
- return this.variables.has(name);
5244
- }
5245
- findVariable(_name) {
5246
- throw new Error('Internal Error: findVariable needs to be implemented by a subclass');
5247
- }
5248
- }
5249
-
5250
- class ChildScope extends Scope$1 {
5251
- constructor(parent) {
5252
- super();
5253
- this.accessedOutsideVariables = new Map();
5254
- this.parent = parent;
5255
- parent.children.push(this);
5256
- }
5257
- addAccessedDynamicImport(importExpression) {
5258
- (this.accessedDynamicImports || (this.accessedDynamicImports = new Set())).add(importExpression);
5259
- if (this.parent instanceof ChildScope) {
5260
- this.parent.addAccessedDynamicImport(importExpression);
5261
- }
5262
- }
5263
- addAccessedGlobals(globals, accessedGlobalsByScope) {
5264
- const accessedGlobals = accessedGlobalsByScope.get(this) || new Set();
5265
- for (const name of globals) {
5266
- accessedGlobals.add(name);
5267
- }
5268
- accessedGlobalsByScope.set(this, accessedGlobals);
5269
- if (this.parent instanceof ChildScope) {
5270
- this.parent.addAccessedGlobals(globals, accessedGlobalsByScope);
5271
- }
5272
- }
5273
- addNamespaceMemberAccess(name, variable) {
5274
- this.accessedOutsideVariables.set(name, variable);
5275
- this.parent.addNamespaceMemberAccess(name, variable);
5276
- }
5277
- addReturnExpression(expression) {
5278
- this.parent instanceof ChildScope && this.parent.addReturnExpression(expression);
5279
- }
5280
- addUsedOutsideNames(usedNames, format, exportNamesByVariable, accessedGlobalsByScope) {
5281
- for (const variable of this.accessedOutsideVariables.values()) {
5282
- if (variable.included) {
5283
- usedNames.add(variable.getBaseVariableName());
5284
- if (format === 'system' && exportNamesByVariable.has(variable)) {
5285
- usedNames.add('exports');
5286
- }
5287
- }
5288
- }
5289
- const accessedGlobals = accessedGlobalsByScope.get(this);
5290
- if (accessedGlobals) {
5291
- for (const name of accessedGlobals) {
5292
- usedNames.add(name);
5293
- }
5294
- }
5295
- }
5296
- contains(name) {
5297
- return this.variables.has(name) || this.parent.contains(name);
5298
- }
5299
- deconflict(format, exportNamesByVariable, accessedGlobalsByScope) {
5300
- const usedNames = new Set();
5301
- this.addUsedOutsideNames(usedNames, format, exportNamesByVariable, accessedGlobalsByScope);
5302
- if (this.accessedDynamicImports) {
5303
- for (const importExpression of this.accessedDynamicImports) {
5304
- if (importExpression.inlineNamespace) {
5305
- usedNames.add(importExpression.inlineNamespace.getBaseVariableName());
5306
- }
5307
- }
5308
- }
5309
- for (const [name, variable] of this.variables) {
5310
- if (variable.included || variable.alwaysRendered) {
5311
- variable.setRenderNames(null, getSafeName(name, usedNames));
5312
- }
5313
- }
5314
- for (const scope of this.children) {
5315
- scope.deconflict(format, exportNamesByVariable, accessedGlobalsByScope);
5316
- }
5317
- }
5318
- findLexicalBoundary() {
5319
- return this.parent.findLexicalBoundary();
5320
- }
5321
- findVariable(name) {
5322
- const knownVariable = this.variables.get(name) || this.accessedOutsideVariables.get(name);
5323
- if (knownVariable) {
5324
- return knownVariable;
5325
- }
5326
- const variable = this.parent.findVariable(name);
5327
- this.accessedOutsideVariables.set(name, variable);
5328
- return variable;
5329
- }
5330
- }
5331
-
5332
- //@ts-check
5333
- /** @typedef { import('estree').Node} Node */
5334
- /** @typedef {Node | {
5335
- * type: 'PropertyDefinition';
5336
- * computed: boolean;
5337
- * value: Node
5338
- * }} NodeWithPropertyDefinition */
5339
-
5340
- /**
5341
- *
5342
- * @param {NodeWithPropertyDefinition} node
5343
- * @param {NodeWithPropertyDefinition} parent
5344
- * @returns boolean
5345
- */
5346
- function is_reference (node, parent) {
5347
- if (node.type === 'MemberExpression') {
5348
- return !node.computed && is_reference(node.object, node);
5349
- }
5350
-
5351
- if (node.type === 'Identifier') {
5352
- if (!parent) return true;
5353
-
5354
- switch (parent.type) {
5355
- // disregard `bar` in `foo.bar`
5356
- case 'MemberExpression': return parent.computed || node === parent.object;
5357
-
5358
- // disregard the `foo` in `class {foo(){}}` but keep it in `class {[foo](){}}`
5359
- case 'MethodDefinition': return parent.computed;
5360
-
5361
- // disregard the `foo` in `class {foo=bar}` but keep it in `class {[foo]=bar}` and `class {bar=foo}`
5362
- case 'PropertyDefinition': return parent.computed || node === parent.value;
5363
-
5364
- // disregard the `bar` in `{ bar: foo }`, but keep it in `{ [bar]: foo }`
5365
- case 'Property': return parent.computed || node === parent.value;
5366
-
5367
- // disregard the `bar` in `export { foo as bar }` or
5368
- // the foo in `import { foo as bar }`
5369
- case 'ExportSpecifier':
5370
- case 'ImportSpecifier': return node === parent.local;
5371
-
5372
- // disregard the `foo` in `foo: while (...) { ... break foo; ... continue foo;}`
5373
- case 'LabeledStatement':
5374
- case 'BreakStatement':
5375
- case 'ContinueStatement': return false;
5376
- default: return true;
5377
- }
5378
- }
5379
-
5380
- return false;
5381
- }
5382
-
5383
- /* eslint sort-keys: "off" */
5384
- const ValueProperties = Symbol('Value Properties');
5385
- const PURE = { pure: true };
5386
- const IMPURE = { pure: false };
5387
- // We use shortened variables to reduce file size here
5388
- /* OBJECT */
5389
- const O = {
5390
- __proto__: null,
5391
- [ValueProperties]: IMPURE
5392
- };
5393
- /* PURE FUNCTION */
5394
- const PF = {
5395
- __proto__: null,
5396
- [ValueProperties]: PURE
5397
- };
5398
- /* CONSTRUCTOR */
5399
- const C = {
5400
- __proto__: null,
5401
- [ValueProperties]: IMPURE,
5402
- prototype: O
5403
- };
5404
- /* PURE CONSTRUCTOR */
5405
- const PC = {
5406
- __proto__: null,
5407
- [ValueProperties]: PURE,
5408
- prototype: O
4909
+ /* PURE CONSTRUCTOR */
4910
+ const PC = {
4911
+ __proto__: null,
4912
+ [ValueProperties]: PURE,
4913
+ prototype: O
5409
4914
  };
5410
4915
  const ARRAY_TYPE = {
5411
4916
  __proto__: null,
@@ -6202,226 +5707,719 @@ const knownGlobals = {
6202
5707
  for (const global of ['window', 'global', 'self', 'globalThis']) {
6203
5708
  knownGlobals[global] = knownGlobals;
6204
5709
  }
6205
- function getGlobalAtPath(path) {
6206
- let currentGlobal = knownGlobals;
6207
- for (const pathSegment of path) {
6208
- if (typeof pathSegment !== 'string') {
6209
- return null;
5710
+ function getGlobalAtPath(path) {
5711
+ let currentGlobal = knownGlobals;
5712
+ for (const pathSegment of path) {
5713
+ if (typeof pathSegment !== 'string') {
5714
+ return null;
5715
+ }
5716
+ currentGlobal = currentGlobal[pathSegment];
5717
+ if (!currentGlobal) {
5718
+ return null;
5719
+ }
5720
+ }
5721
+ return currentGlobal[ValueProperties];
5722
+ }
5723
+ function isPureGlobal(path) {
5724
+ const globalAtPath = getGlobalAtPath(path);
5725
+ return globalAtPath !== null && globalAtPath.pure;
5726
+ }
5727
+ function isGlobalMember(path) {
5728
+ if (path.length === 1) {
5729
+ return path[0] === 'undefined' || getGlobalAtPath(path) !== null;
5730
+ }
5731
+ return getGlobalAtPath(path.slice(0, -1)) !== null;
5732
+ }
5733
+
5734
+ class GlobalVariable extends Variable {
5735
+ constructor() {
5736
+ super(...arguments);
5737
+ this.isReassigned = true;
5738
+ }
5739
+ hasEffectsWhenAccessedAtPath(path) {
5740
+ return !isGlobalMember([this.name, ...path]);
5741
+ }
5742
+ hasEffectsWhenCalledAtPath(path) {
5743
+ return !isPureGlobal([this.name, ...path]);
5744
+ }
5745
+ }
5746
+
5747
+ class LocalVariable extends Variable {
5748
+ constructor(name, declarator, init, context) {
5749
+ super(name);
5750
+ this.calledFromTryStatement = false;
5751
+ this.additionalInitializers = null;
5752
+ this.expressionsToBeDeoptimized = [];
5753
+ this.declarations = declarator ? [declarator] : [];
5754
+ this.init = init;
5755
+ this.deoptimizationTracker = context.deoptimizationTracker;
5756
+ this.module = context.module;
5757
+ }
5758
+ addDeclaration(identifier, init) {
5759
+ this.declarations.push(identifier);
5760
+ const additionalInitializers = this.markInitializersForDeoptimization();
5761
+ if (init !== null) {
5762
+ additionalInitializers.push(init);
5763
+ }
5764
+ }
5765
+ consolidateInitializers() {
5766
+ if (this.additionalInitializers !== null) {
5767
+ for (const initializer of this.additionalInitializers) {
5768
+ initializer.deoptimizePath(UNKNOWN_PATH);
5769
+ }
5770
+ this.additionalInitializers = null;
5771
+ }
5772
+ }
5773
+ deoptimizePath(path) {
5774
+ var _a, _b;
5775
+ if (this.isReassigned ||
5776
+ this.deoptimizationTracker.trackEntityAtPathAndGetIfTracked(path, this)) {
5777
+ return;
5778
+ }
5779
+ if (path.length === 0) {
5780
+ if (!this.isReassigned) {
5781
+ this.isReassigned = true;
5782
+ const expressionsToBeDeoptimized = this.expressionsToBeDeoptimized;
5783
+ this.expressionsToBeDeoptimized = [];
5784
+ for (const expression of expressionsToBeDeoptimized) {
5785
+ expression.deoptimizeCache();
5786
+ }
5787
+ (_a = this.init) === null || _a === void 0 ? void 0 : _a.deoptimizePath(UNKNOWN_PATH);
5788
+ }
5789
+ }
5790
+ else {
5791
+ (_b = this.init) === null || _b === void 0 ? void 0 : _b.deoptimizePath(path);
5792
+ }
5793
+ }
5794
+ deoptimizeThisOnEventAtPath(event, path, thisParameter, recursionTracker) {
5795
+ if (this.isReassigned || !this.init) {
5796
+ return thisParameter.deoptimizePath(UNKNOWN_PATH);
5797
+ }
5798
+ recursionTracker.withTrackedEntityAtPath(path, this.init, () => this.init.deoptimizeThisOnEventAtPath(event, path, thisParameter, recursionTracker), undefined);
5799
+ }
5800
+ getLiteralValueAtPath(path, recursionTracker, origin) {
5801
+ if (this.isReassigned || !this.init) {
5802
+ return UnknownValue;
5803
+ }
5804
+ return recursionTracker.withTrackedEntityAtPath(path, this.init, () => {
5805
+ this.expressionsToBeDeoptimized.push(origin);
5806
+ return this.init.getLiteralValueAtPath(path, recursionTracker, origin);
5807
+ }, UnknownValue);
5808
+ }
5809
+ getReturnExpressionWhenCalledAtPath(path, callOptions, recursionTracker, origin) {
5810
+ if (this.isReassigned || !this.init) {
5811
+ return UNKNOWN_EXPRESSION;
5812
+ }
5813
+ return recursionTracker.withTrackedEntityAtPath(path, this.init, () => {
5814
+ this.expressionsToBeDeoptimized.push(origin);
5815
+ return this.init.getReturnExpressionWhenCalledAtPath(path, callOptions, recursionTracker, origin);
5816
+ }, UNKNOWN_EXPRESSION);
5817
+ }
5818
+ hasEffectsWhenAccessedAtPath(path, context) {
5819
+ if (this.isReassigned)
5820
+ return true;
5821
+ return (this.init &&
5822
+ !context.accessed.trackEntityAtPathAndGetIfTracked(path, this) &&
5823
+ this.init.hasEffectsWhenAccessedAtPath(path, context));
5824
+ }
5825
+ hasEffectsWhenAssignedAtPath(path, context) {
5826
+ if (this.included)
5827
+ return true;
5828
+ if (path.length === 0)
5829
+ return false;
5830
+ if (this.isReassigned)
5831
+ return true;
5832
+ return (this.init &&
5833
+ !context.accessed.trackEntityAtPathAndGetIfTracked(path, this) &&
5834
+ this.init.hasEffectsWhenAssignedAtPath(path, context));
5835
+ }
5836
+ hasEffectsWhenCalledAtPath(path, callOptions, context) {
5837
+ if (this.isReassigned)
5838
+ return true;
5839
+ return (this.init &&
5840
+ !(callOptions.withNew ? context.instantiated : context.called).trackEntityAtPathAndGetIfTracked(path, callOptions, this) &&
5841
+ this.init.hasEffectsWhenCalledAtPath(path, callOptions, context));
5842
+ }
5843
+ include() {
5844
+ if (!this.included) {
5845
+ this.included = true;
5846
+ for (const declaration of this.declarations) {
5847
+ // If node is a default export, it can save a tree-shaking run to include the full declaration now
5848
+ if (!declaration.included)
5849
+ declaration.include(createInclusionContext(), false);
5850
+ let node = declaration.parent;
5851
+ while (!node.included) {
5852
+ // We do not want to properly include parents in case they are part of a dead branch
5853
+ // in which case .include() might pull in more dead code
5854
+ node.included = true;
5855
+ if (node.type === Program$1)
5856
+ break;
5857
+ node = node.parent;
5858
+ }
5859
+ }
5860
+ }
5861
+ }
5862
+ includeCallArguments(context, args) {
5863
+ if (this.isReassigned || (this.init && context.includedCallArguments.has(this.init))) {
5864
+ for (const arg of args) {
5865
+ arg.include(context, false);
5866
+ }
5867
+ }
5868
+ else if (this.init) {
5869
+ context.includedCallArguments.add(this.init);
5870
+ this.init.includeCallArguments(context, args);
5871
+ context.includedCallArguments.delete(this.init);
5872
+ }
5873
+ }
5874
+ markCalledFromTryStatement() {
5875
+ this.calledFromTryStatement = true;
5876
+ }
5877
+ markInitializersForDeoptimization() {
5878
+ if (this.additionalInitializers === null) {
5879
+ this.additionalInitializers = this.init === null ? [] : [this.init];
5880
+ this.init = UNKNOWN_EXPRESSION;
5881
+ this.isReassigned = true;
5882
+ }
5883
+ return this.additionalInitializers;
5884
+ }
5885
+ }
5886
+
5887
+ const tdzVariableKinds = {
5888
+ __proto__: null,
5889
+ class: true,
5890
+ const: true,
5891
+ let: true,
5892
+ var: true
5893
+ };
5894
+ class Identifier extends NodeBase {
5895
+ constructor() {
5896
+ super(...arguments);
5897
+ this.variable = null;
5898
+ this.deoptimized = false;
5899
+ this.isTDZAccess = null;
5900
+ }
5901
+ addExportedVariables(variables, exportNamesByVariable) {
5902
+ if (this.variable !== null && exportNamesByVariable.has(this.variable)) {
5903
+ variables.push(this.variable);
5904
+ }
5905
+ }
5906
+ bind() {
5907
+ if (this.variable === null && is_reference(this, this.parent)) {
5908
+ this.variable = this.scope.findVariable(this.name);
5909
+ this.variable.addReference(this);
5910
+ }
5911
+ }
5912
+ declare(kind, init) {
5913
+ let variable;
5914
+ const { treeshake } = this.context.options;
5915
+ switch (kind) {
5916
+ case 'var':
5917
+ variable = this.scope.addDeclaration(this, this.context, init, true);
5918
+ if (treeshake && treeshake.correctVarValueBeforeDeclaration) {
5919
+ // Necessary to make sure the init is deoptimized. We cannot call deoptimizePath here.
5920
+ variable.markInitializersForDeoptimization();
5921
+ }
5922
+ break;
5923
+ case 'function':
5924
+ // in strict mode, functions are only hoisted within a scope but not across block scopes
5925
+ variable = this.scope.addDeclaration(this, this.context, init, false);
5926
+ break;
5927
+ case 'let':
5928
+ case 'const':
5929
+ case 'class':
5930
+ variable = this.scope.addDeclaration(this, this.context, init, false);
5931
+ break;
5932
+ case 'parameter':
5933
+ variable = this.scope.addParameterDeclaration(this);
5934
+ break;
5935
+ /* istanbul ignore next */
5936
+ default:
5937
+ /* istanbul ignore next */
5938
+ throw new Error(`Internal Error: Unexpected identifier kind ${kind}.`);
5939
+ }
5940
+ variable.kind = kind;
5941
+ return [(this.variable = variable)];
5942
+ }
5943
+ deoptimizePath(path) {
5944
+ if (path.length === 0 && !this.scope.contains(this.name)) {
5945
+ this.disallowImportReassignment();
5946
+ }
5947
+ this.variable.deoptimizePath(path);
5948
+ }
5949
+ deoptimizeThisOnEventAtPath(event, path, thisParameter, recursionTracker) {
5950
+ this.variable.deoptimizeThisOnEventAtPath(event, path, thisParameter, recursionTracker);
5951
+ }
5952
+ getLiteralValueAtPath(path, recursionTracker, origin) {
5953
+ return this.getVariableRespectingTDZ().getLiteralValueAtPath(path, recursionTracker, origin);
5954
+ }
5955
+ getReturnExpressionWhenCalledAtPath(path, callOptions, recursionTracker, origin) {
5956
+ return this.getVariableRespectingTDZ().getReturnExpressionWhenCalledAtPath(path, callOptions, recursionTracker, origin);
5957
+ }
5958
+ hasEffects() {
5959
+ if (!this.deoptimized)
5960
+ this.applyDeoptimizations();
5961
+ if (this.isPossibleTDZ() && this.variable.kind !== 'var') {
5962
+ return true;
5963
+ }
5964
+ return (this.context.options.treeshake.unknownGlobalSideEffects &&
5965
+ this.variable instanceof GlobalVariable &&
5966
+ this.variable.hasEffectsWhenAccessedAtPath(EMPTY_PATH));
5967
+ }
5968
+ hasEffectsWhenAccessedAtPath(path, context) {
5969
+ return (this.variable !== null &&
5970
+ this.getVariableRespectingTDZ().hasEffectsWhenAccessedAtPath(path, context));
5971
+ }
5972
+ hasEffectsWhenAssignedAtPath(path, context) {
5973
+ return (!this.variable ||
5974
+ (path.length > 0
5975
+ ? this.getVariableRespectingTDZ()
5976
+ : this.variable).hasEffectsWhenAssignedAtPath(path, context));
5977
+ }
5978
+ hasEffectsWhenCalledAtPath(path, callOptions, context) {
5979
+ return (!this.variable ||
5980
+ this.getVariableRespectingTDZ().hasEffectsWhenCalledAtPath(path, callOptions, context));
5981
+ }
5982
+ include() {
5983
+ if (!this.deoptimized)
5984
+ this.applyDeoptimizations();
5985
+ if (!this.included) {
5986
+ this.included = true;
5987
+ if (this.variable !== null) {
5988
+ this.context.includeVariableInModule(this.variable);
5989
+ }
5990
+ }
5991
+ }
5992
+ includeCallArguments(context, args) {
5993
+ this.getVariableRespectingTDZ().includeCallArguments(context, args);
5994
+ }
5995
+ isPossibleTDZ() {
5996
+ // return cached value to avoid issues with the next tree-shaking pass
5997
+ if (this.isTDZAccess !== null)
5998
+ return this.isTDZAccess;
5999
+ if (!(this.variable instanceof LocalVariable) ||
6000
+ !this.variable.kind ||
6001
+ !(this.variable.kind in tdzVariableKinds)) {
6002
+ return (this.isTDZAccess = false);
6003
+ }
6004
+ let decl_id;
6005
+ if (this.variable.declarations &&
6006
+ this.variable.declarations.length === 1 &&
6007
+ (decl_id = this.variable.declarations[0]) &&
6008
+ this.start < decl_id.start &&
6009
+ closestParentFunctionOrProgram(this) === closestParentFunctionOrProgram(decl_id)) {
6010
+ // a variable accessed before its declaration
6011
+ // in the same function or at top level of module
6012
+ return (this.isTDZAccess = true);
6013
+ }
6014
+ if (!this.variable.initReached) {
6015
+ // Either a const/let TDZ violation or
6016
+ // var use before declaration was encountered.
6017
+ return (this.isTDZAccess = true);
6018
+ }
6019
+ return (this.isTDZAccess = false);
6020
+ }
6021
+ markDeclarationReached() {
6022
+ this.variable.initReached = true;
6023
+ }
6024
+ render(code, { snippets: { getPropertyAccess } }, { renderedParentType, isCalleeOfRenderedParent, isShorthandProperty } = BLANK) {
6025
+ if (this.variable) {
6026
+ const name = this.variable.getName(getPropertyAccess);
6027
+ if (name !== this.name) {
6028
+ code.overwrite(this.start, this.end, name, {
6029
+ contentOnly: true,
6030
+ storeName: true
6031
+ });
6032
+ if (isShorthandProperty) {
6033
+ code.prependRight(this.start, `${this.name}: `);
6034
+ }
6035
+ }
6036
+ // In strict mode, any variable named "eval" must be the actual "eval" function
6037
+ if (name === 'eval' &&
6038
+ renderedParentType === CallExpression$1 &&
6039
+ isCalleeOfRenderedParent) {
6040
+ code.appendRight(this.start, '0, ');
6041
+ }
6042
+ }
6043
+ }
6044
+ applyDeoptimizations() {
6045
+ this.deoptimized = true;
6046
+ if (this.variable !== null && this.variable instanceof LocalVariable) {
6047
+ this.variable.consolidateInitializers();
6048
+ this.context.requestTreeshakingPass();
6210
6049
  }
6211
- currentGlobal = currentGlobal[pathSegment];
6212
- if (!currentGlobal) {
6213
- return null;
6050
+ }
6051
+ disallowImportReassignment() {
6052
+ return this.context.error({
6053
+ code: 'ILLEGAL_REASSIGNMENT',
6054
+ message: `Illegal reassignment to import '${this.name}'`
6055
+ }, this.start);
6056
+ }
6057
+ getVariableRespectingTDZ() {
6058
+ if (this.isPossibleTDZ()) {
6059
+ return UNKNOWN_EXPRESSION;
6214
6060
  }
6061
+ return this.variable;
6215
6062
  }
6216
- return currentGlobal[ValueProperties];
6217
6063
  }
6218
- function isPureGlobal(path) {
6219
- const globalAtPath = getGlobalAtPath(path);
6220
- return globalAtPath !== null && globalAtPath.pure;
6064
+ function closestParentFunctionOrProgram(node) {
6065
+ while (node && !/^Program|Function/.test(node.type)) {
6066
+ node = node.parent;
6067
+ }
6068
+ // one of: ArrowFunctionExpression, FunctionDeclaration, FunctionExpression or Program
6069
+ return node;
6221
6070
  }
6222
- function isGlobalMember(path) {
6223
- if (path.length === 1) {
6224
- return path[0] === 'undefined' || getGlobalAtPath(path) !== null;
6071
+
6072
+ const chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_$';
6073
+ const base = 64;
6074
+ function toBase64(num) {
6075
+ let outStr = '';
6076
+ do {
6077
+ const curDigit = num % base;
6078
+ num = Math.floor(num / base);
6079
+ outStr = chars[curDigit] + outStr;
6080
+ } while (num !== 0);
6081
+ return outStr;
6082
+ }
6083
+
6084
+ const RESERVED_NAMES = {
6085
+ __proto__: null,
6086
+ await: true,
6087
+ break: true,
6088
+ case: true,
6089
+ catch: true,
6090
+ class: true,
6091
+ const: true,
6092
+ continue: true,
6093
+ debugger: true,
6094
+ default: true,
6095
+ delete: true,
6096
+ do: true,
6097
+ else: true,
6098
+ enum: true,
6099
+ eval: true,
6100
+ export: true,
6101
+ extends: true,
6102
+ false: true,
6103
+ finally: true,
6104
+ for: true,
6105
+ function: true,
6106
+ if: true,
6107
+ implements: true,
6108
+ import: true,
6109
+ in: true,
6110
+ instanceof: true,
6111
+ interface: true,
6112
+ let: true,
6113
+ new: true,
6114
+ null: true,
6115
+ package: true,
6116
+ private: true,
6117
+ protected: true,
6118
+ public: true,
6119
+ return: true,
6120
+ static: true,
6121
+ super: true,
6122
+ switch: true,
6123
+ this: true,
6124
+ throw: true,
6125
+ true: true,
6126
+ try: true,
6127
+ typeof: true,
6128
+ undefined: true,
6129
+ var: true,
6130
+ void: true,
6131
+ while: true,
6132
+ with: true,
6133
+ yield: true
6134
+ };
6135
+
6136
+ function getSafeName(baseName, usedNames) {
6137
+ let safeName = baseName;
6138
+ let count = 1;
6139
+ while (usedNames.has(safeName) || RESERVED_NAMES[safeName]) {
6140
+ safeName = `${baseName}$${toBase64(count++)}`;
6225
6141
  }
6226
- return getGlobalAtPath(path.slice(0, -1)) !== null;
6142
+ usedNames.add(safeName);
6143
+ return safeName;
6227
6144
  }
6228
6145
 
6229
- class GlobalVariable extends Variable {
6230
- constructor() {
6231
- super(...arguments);
6232
- this.isReassigned = true;
6146
+ const NO_ARGS = [];
6147
+
6148
+ function assembleMemberDescriptions(memberDescriptions, inheritedDescriptions = null) {
6149
+ return Object.create(inheritedDescriptions, memberDescriptions);
6150
+ }
6151
+ const UNDEFINED_EXPRESSION = new (class UndefinedExpression extends ExpressionEntity {
6152
+ getLiteralValueAtPath() {
6153
+ return undefined;
6154
+ }
6155
+ })();
6156
+ const returnsUnknown = {
6157
+ value: {
6158
+ callsArgs: null,
6159
+ returns: UNKNOWN_EXPRESSION
6160
+ }
6161
+ };
6162
+ const UNKNOWN_LITERAL_BOOLEAN = new (class UnknownBoolean extends ExpressionEntity {
6163
+ getReturnExpressionWhenCalledAtPath(path) {
6164
+ if (path.length === 1) {
6165
+ return getMemberReturnExpressionWhenCalled(literalBooleanMembers, path[0]);
6166
+ }
6167
+ return UNKNOWN_EXPRESSION;
6233
6168
  }
6234
6169
  hasEffectsWhenAccessedAtPath(path) {
6235
- return !isGlobalMember([this.name, ...path]);
6170
+ return path.length > 1;
6171
+ }
6172
+ hasEffectsWhenCalledAtPath(path, callOptions, context) {
6173
+ if (path.length === 1) {
6174
+ return hasMemberEffectWhenCalled(literalBooleanMembers, path[0], callOptions, context);
6175
+ }
6176
+ return true;
6177
+ }
6178
+ })();
6179
+ const returnsBoolean = {
6180
+ value: {
6181
+ callsArgs: null,
6182
+ returns: UNKNOWN_LITERAL_BOOLEAN
6183
+ }
6184
+ };
6185
+ const UNKNOWN_LITERAL_NUMBER = new (class UnknownNumber extends ExpressionEntity {
6186
+ getReturnExpressionWhenCalledAtPath(path) {
6187
+ if (path.length === 1) {
6188
+ return getMemberReturnExpressionWhenCalled(literalNumberMembers, path[0]);
6189
+ }
6190
+ return UNKNOWN_EXPRESSION;
6191
+ }
6192
+ hasEffectsWhenAccessedAtPath(path) {
6193
+ return path.length > 1;
6194
+ }
6195
+ hasEffectsWhenCalledAtPath(path, callOptions, context) {
6196
+ if (path.length === 1) {
6197
+ return hasMemberEffectWhenCalled(literalNumberMembers, path[0], callOptions, context);
6198
+ }
6199
+ return true;
6200
+ }
6201
+ })();
6202
+ const returnsNumber = {
6203
+ value: {
6204
+ callsArgs: null,
6205
+ returns: UNKNOWN_LITERAL_NUMBER
6206
+ }
6207
+ };
6208
+ const UNKNOWN_LITERAL_STRING = new (class UnknownString extends ExpressionEntity {
6209
+ getReturnExpressionWhenCalledAtPath(path) {
6210
+ if (path.length === 1) {
6211
+ return getMemberReturnExpressionWhenCalled(literalStringMembers, path[0]);
6212
+ }
6213
+ return UNKNOWN_EXPRESSION;
6214
+ }
6215
+ hasEffectsWhenAccessedAtPath(path) {
6216
+ return path.length > 1;
6217
+ }
6218
+ hasEffectsWhenCalledAtPath(path, callOptions, context) {
6219
+ if (path.length === 1) {
6220
+ return hasMemberEffectWhenCalled(literalStringMembers, path[0], callOptions, context);
6221
+ }
6222
+ return true;
6223
+ }
6224
+ })();
6225
+ const returnsString = {
6226
+ value: {
6227
+ callsArgs: null,
6228
+ returns: UNKNOWN_LITERAL_STRING
6229
+ }
6230
+ };
6231
+ const objectMembers = assembleMemberDescriptions({
6232
+ hasOwnProperty: returnsBoolean,
6233
+ isPrototypeOf: returnsBoolean,
6234
+ propertyIsEnumerable: returnsBoolean,
6235
+ toLocaleString: returnsString,
6236
+ toString: returnsString,
6237
+ valueOf: returnsUnknown
6238
+ });
6239
+ const literalBooleanMembers = assembleMemberDescriptions({
6240
+ valueOf: returnsBoolean
6241
+ }, objectMembers);
6242
+ const literalNumberMembers = assembleMemberDescriptions({
6243
+ toExponential: returnsString,
6244
+ toFixed: returnsString,
6245
+ toLocaleString: returnsString,
6246
+ toPrecision: returnsString,
6247
+ valueOf: returnsNumber
6248
+ }, objectMembers);
6249
+ const literalStringMembers = assembleMemberDescriptions({
6250
+ charAt: returnsString,
6251
+ charCodeAt: returnsNumber,
6252
+ codePointAt: returnsNumber,
6253
+ concat: returnsString,
6254
+ endsWith: returnsBoolean,
6255
+ includes: returnsBoolean,
6256
+ indexOf: returnsNumber,
6257
+ lastIndexOf: returnsNumber,
6258
+ localeCompare: returnsNumber,
6259
+ match: returnsBoolean,
6260
+ normalize: returnsString,
6261
+ padEnd: returnsString,
6262
+ padStart: returnsString,
6263
+ repeat: returnsString,
6264
+ replace: {
6265
+ value: {
6266
+ callsArgs: [1],
6267
+ returns: UNKNOWN_LITERAL_STRING
6268
+ }
6269
+ },
6270
+ search: returnsNumber,
6271
+ slice: returnsString,
6272
+ split: returnsUnknown,
6273
+ startsWith: returnsBoolean,
6274
+ substr: returnsString,
6275
+ substring: returnsString,
6276
+ toLocaleLowerCase: returnsString,
6277
+ toLocaleUpperCase: returnsString,
6278
+ toLowerCase: returnsString,
6279
+ toUpperCase: returnsString,
6280
+ trim: returnsString,
6281
+ valueOf: returnsString
6282
+ }, objectMembers);
6283
+ function getLiteralMembersForValue(value) {
6284
+ switch (typeof value) {
6285
+ case 'boolean':
6286
+ return literalBooleanMembers;
6287
+ case 'number':
6288
+ return literalNumberMembers;
6289
+ case 'string':
6290
+ return literalStringMembers;
6291
+ default:
6292
+ return Object.create(null);
6293
+ }
6294
+ }
6295
+ function hasMemberEffectWhenCalled(members, memberName, callOptions, context) {
6296
+ if (typeof memberName !== 'string' || !members[memberName]) {
6297
+ return true;
6236
6298
  }
6237
- hasEffectsWhenCalledAtPath(path) {
6238
- return !isPureGlobal([this.name, ...path]);
6299
+ if (!members[memberName].callsArgs)
6300
+ return false;
6301
+ for (const argIndex of members[memberName].callsArgs) {
6302
+ if (callOptions.args[argIndex] &&
6303
+ callOptions.args[argIndex].hasEffectsWhenCalledAtPath(EMPTY_PATH, {
6304
+ args: NO_ARGS,
6305
+ thisParam: null,
6306
+ withNew: false
6307
+ }, context))
6308
+ return true;
6239
6309
  }
6310
+ return false;
6311
+ }
6312
+ function getMemberReturnExpressionWhenCalled(members, memberName) {
6313
+ if (typeof memberName !== 'string' || !members[memberName])
6314
+ return UNKNOWN_EXPRESSION;
6315
+ return members[memberName].returns;
6240
6316
  }
6241
6317
 
6242
- const tdzVariableKinds = {
6243
- __proto__: null,
6244
- class: true,
6245
- const: true,
6246
- let: true,
6247
- var: true
6248
- };
6249
- class Identifier extends NodeBase {
6318
+ class Scope$1 {
6250
6319
  constructor() {
6251
- super(...arguments);
6252
- this.variable = null;
6253
- this.deoptimized = false;
6254
- this.isTDZAccess = null;
6255
- }
6256
- addExportedVariables(variables, exportNamesByVariable) {
6257
- if (this.variable !== null && exportNamesByVariable.has(this.variable)) {
6258
- variables.push(this.variable);
6259
- }
6260
- }
6261
- bind() {
6262
- if (this.variable === null && is_reference(this, this.parent)) {
6263
- this.variable = this.scope.findVariable(this.name);
6264
- this.variable.addReference(this);
6265
- }
6320
+ this.children = [];
6321
+ this.variables = new Map();
6266
6322
  }
6267
- declare(kind, init) {
6268
- let variable;
6269
- const { treeshake } = this.context.options;
6270
- switch (kind) {
6271
- case 'var':
6272
- variable = this.scope.addDeclaration(this, this.context, init, true);
6273
- if (treeshake && treeshake.correctVarValueBeforeDeclaration) {
6274
- // Necessary to make sure the init is deoptimized. We cannot call deoptimizePath here.
6275
- variable.markInitializersForDeoptimization();
6276
- }
6277
- break;
6278
- case 'function':
6279
- // in strict mode, functions are only hoisted within a scope but not across block scopes
6280
- variable = this.scope.addDeclaration(this, this.context, init, false);
6281
- break;
6282
- case 'let':
6283
- case 'const':
6284
- case 'class':
6285
- variable = this.scope.addDeclaration(this, this.context, init, false);
6286
- break;
6287
- case 'parameter':
6288
- variable = this.scope.addParameterDeclaration(this);
6289
- break;
6290
- /* istanbul ignore next */
6291
- default:
6292
- /* istanbul ignore next */
6293
- throw new Error(`Internal Error: Unexpected identifier kind ${kind}.`);
6323
+ addDeclaration(identifier, context, init, _isHoisted) {
6324
+ const name = identifier.name;
6325
+ let variable = this.variables.get(name);
6326
+ if (variable) {
6327
+ variable.addDeclaration(identifier, init);
6294
6328
  }
6295
- variable.kind = kind;
6296
- return [(this.variable = variable)];
6297
- }
6298
- deoptimizePath(path) {
6299
- if (path.length === 0 && !this.scope.contains(this.name)) {
6300
- this.disallowImportReassignment();
6329
+ else {
6330
+ variable = new LocalVariable(identifier.name, identifier, init || UNDEFINED_EXPRESSION, context);
6331
+ this.variables.set(name, variable);
6301
6332
  }
6302
- this.variable.deoptimizePath(path);
6333
+ return variable;
6303
6334
  }
6304
- deoptimizeThisOnEventAtPath(event, path, thisParameter, recursionTracker) {
6305
- this.variable.deoptimizeThisOnEventAtPath(event, path, thisParameter, recursionTracker);
6335
+ contains(name) {
6336
+ return this.variables.has(name);
6306
6337
  }
6307
- getLiteralValueAtPath(path, recursionTracker, origin) {
6308
- return this.getVariableRespectingTDZ().getLiteralValueAtPath(path, recursionTracker, origin);
6338
+ findVariable(_name) {
6339
+ throw new Error('Internal Error: findVariable needs to be implemented by a subclass');
6309
6340
  }
6310
- getReturnExpressionWhenCalledAtPath(path, callOptions, recursionTracker, origin) {
6311
- return this.getVariableRespectingTDZ().getReturnExpressionWhenCalledAtPath(path, callOptions, recursionTracker, origin);
6341
+ }
6342
+
6343
+ class ChildScope extends Scope$1 {
6344
+ constructor(parent) {
6345
+ super();
6346
+ this.accessedOutsideVariables = new Map();
6347
+ this.parent = parent;
6348
+ parent.children.push(this);
6312
6349
  }
6313
- hasEffects() {
6314
- if (!this.deoptimized)
6315
- this.applyDeoptimizations();
6316
- if (this.isPossibleTDZ() && this.variable.kind !== 'var') {
6317
- return true;
6350
+ addAccessedDynamicImport(importExpression) {
6351
+ (this.accessedDynamicImports || (this.accessedDynamicImports = new Set())).add(importExpression);
6352
+ if (this.parent instanceof ChildScope) {
6353
+ this.parent.addAccessedDynamicImport(importExpression);
6318
6354
  }
6319
- return (this.context.options.treeshake.unknownGlobalSideEffects &&
6320
- this.variable instanceof GlobalVariable &&
6321
- this.variable.hasEffectsWhenAccessedAtPath(EMPTY_PATH));
6322
6355
  }
6323
- hasEffectsWhenAccessedAtPath(path, context) {
6324
- return (this.variable !== null &&
6325
- this.getVariableRespectingTDZ().hasEffectsWhenAccessedAtPath(path, context));
6356
+ addAccessedGlobals(globals, accessedGlobalsByScope) {
6357
+ const accessedGlobals = accessedGlobalsByScope.get(this) || new Set();
6358
+ for (const name of globals) {
6359
+ accessedGlobals.add(name);
6360
+ }
6361
+ accessedGlobalsByScope.set(this, accessedGlobals);
6362
+ if (this.parent instanceof ChildScope) {
6363
+ this.parent.addAccessedGlobals(globals, accessedGlobalsByScope);
6364
+ }
6326
6365
  }
6327
- hasEffectsWhenAssignedAtPath(path, context) {
6328
- return (!this.variable ||
6329
- (path.length > 0
6330
- ? this.getVariableRespectingTDZ()
6331
- : this.variable).hasEffectsWhenAssignedAtPath(path, context));
6366
+ addNamespaceMemberAccess(name, variable) {
6367
+ this.accessedOutsideVariables.set(name, variable);
6368
+ this.parent.addNamespaceMemberAccess(name, variable);
6332
6369
  }
6333
- hasEffectsWhenCalledAtPath(path, callOptions, context) {
6334
- return (!this.variable ||
6335
- this.getVariableRespectingTDZ().hasEffectsWhenCalledAtPath(path, callOptions, context));
6370
+ addReturnExpression(expression) {
6371
+ this.parent instanceof ChildScope && this.parent.addReturnExpression(expression);
6336
6372
  }
6337
- include() {
6338
- if (!this.deoptimized)
6339
- this.applyDeoptimizations();
6340
- if (!this.included) {
6341
- this.included = true;
6342
- if (this.variable !== null) {
6343
- this.context.includeVariableInModule(this.variable);
6373
+ addUsedOutsideNames(usedNames, format, exportNamesByVariable, accessedGlobalsByScope) {
6374
+ for (const variable of this.accessedOutsideVariables.values()) {
6375
+ if (variable.included) {
6376
+ usedNames.add(variable.getBaseVariableName());
6377
+ if (format === 'system' && exportNamesByVariable.has(variable)) {
6378
+ usedNames.add('exports');
6379
+ }
6344
6380
  }
6345
6381
  }
6346
- }
6347
- includeCallArguments(context, args) {
6348
- this.getVariableRespectingTDZ().includeCallArguments(context, args);
6349
- }
6350
- isPossibleTDZ() {
6351
- // return cached value to avoid issues with the next tree-shaking pass
6352
- if (this.isTDZAccess !== null)
6353
- return this.isTDZAccess;
6354
- if (!(this.variable instanceof LocalVariable) ||
6355
- !this.variable.kind ||
6356
- !(this.variable.kind in tdzVariableKinds)) {
6357
- return (this.isTDZAccess = false);
6358
- }
6359
- let decl_id;
6360
- if (this.variable.declarations &&
6361
- this.variable.declarations.length === 1 &&
6362
- (decl_id = this.variable.declarations[0]) &&
6363
- this.start < decl_id.start &&
6364
- closestParentFunctionOrProgram(this) === closestParentFunctionOrProgram(decl_id)) {
6365
- // a variable accessed before its declaration
6366
- // in the same function or at top level of module
6367
- return (this.isTDZAccess = true);
6368
- }
6369
- if (!this.variable.initReached) {
6370
- // Either a const/let TDZ violation or
6371
- // var use before declaration was encountered.
6372
- return (this.isTDZAccess = true);
6382
+ const accessedGlobals = accessedGlobalsByScope.get(this);
6383
+ if (accessedGlobals) {
6384
+ for (const name of accessedGlobals) {
6385
+ usedNames.add(name);
6386
+ }
6373
6387
  }
6374
- return (this.isTDZAccess = false);
6375
6388
  }
6376
- markDeclarationReached() {
6377
- this.variable.initReached = true;
6389
+ contains(name) {
6390
+ return this.variables.has(name) || this.parent.contains(name);
6378
6391
  }
6379
- render(code, { snippets: { getPropertyAccess } }, { renderedParentType, isCalleeOfRenderedParent, isShorthandProperty } = BLANK) {
6380
- if (this.variable) {
6381
- const name = this.variable.getName(getPropertyAccess);
6382
- if (name !== this.name) {
6383
- code.overwrite(this.start, this.end, name, {
6384
- contentOnly: true,
6385
- storeName: true
6386
- });
6387
- if (isShorthandProperty) {
6388
- code.prependRight(this.start, `${this.name}: `);
6392
+ deconflict(format, exportNamesByVariable, accessedGlobalsByScope) {
6393
+ const usedNames = new Set();
6394
+ this.addUsedOutsideNames(usedNames, format, exportNamesByVariable, accessedGlobalsByScope);
6395
+ if (this.accessedDynamicImports) {
6396
+ for (const importExpression of this.accessedDynamicImports) {
6397
+ if (importExpression.inlineNamespace) {
6398
+ usedNames.add(importExpression.inlineNamespace.getBaseVariableName());
6389
6399
  }
6390
6400
  }
6391
- // In strict mode, any variable named "eval" must be the actual "eval" function
6392
- if (name === 'eval' &&
6393
- renderedParentType === CallExpression$1 &&
6394
- isCalleeOfRenderedParent) {
6395
- code.appendRight(this.start, '0, ');
6401
+ }
6402
+ for (const [name, variable] of this.variables) {
6403
+ if (variable.included || variable.alwaysRendered) {
6404
+ variable.setRenderNames(null, getSafeName(name, usedNames));
6396
6405
  }
6397
6406
  }
6398
- }
6399
- applyDeoptimizations() {
6400
- this.deoptimized = true;
6401
- if (this.variable !== null && this.variable instanceof LocalVariable) {
6402
- this.variable.consolidateInitializers();
6403
- this.context.requestTreeshakingPass();
6407
+ for (const scope of this.children) {
6408
+ scope.deconflict(format, exportNamesByVariable, accessedGlobalsByScope);
6404
6409
  }
6405
6410
  }
6406
- disallowImportReassignment() {
6407
- return this.context.error({
6408
- code: 'ILLEGAL_REASSIGNMENT',
6409
- message: `Illegal reassignment to import '${this.name}'`
6410
- }, this.start);
6411
+ findLexicalBoundary() {
6412
+ return this.parent.findLexicalBoundary();
6411
6413
  }
6412
- getVariableRespectingTDZ() {
6413
- if (this.isPossibleTDZ()) {
6414
- return UNKNOWN_EXPRESSION;
6414
+ findVariable(name) {
6415
+ const knownVariable = this.variables.get(name) || this.accessedOutsideVariables.get(name);
6416
+ if (knownVariable) {
6417
+ return knownVariable;
6415
6418
  }
6416
- return this.variable;
6417
- }
6418
- }
6419
- function closestParentFunctionOrProgram(node) {
6420
- while (node && !/^Program|Function/.test(node.type)) {
6421
- node = node.parent;
6422
- }
6423
- // one of: ArrowFunctionExpression, FunctionDeclaration, FunctionExpression or Program
6424
- return node;
6419
+ const variable = this.parent.findVariable(name);
6420
+ this.accessedOutsideVariables.set(name, variable);
6421
+ return variable;
6422
+ }
6425
6423
  }
6426
6424
 
6427
6425
  const EVENT_ACCESSED = 0;
@@ -7117,7 +7115,7 @@ class ClassDeclaration extends ClassNode {
7117
7115
  }
7118
7116
  parseNode(esTreeNode) {
7119
7117
  if (esTreeNode.id !== null) {
7120
- this.id = new this.context.nodeConstructors.Identifier(esTreeNode.id, this, this.scope.parent);
7118
+ this.id = new Identifier(esTreeNode.id, this, this.scope.parent);
7121
7119
  }
7122
7120
  super.parseNode(esTreeNode);
7123
7121
  }
@@ -7353,6 +7351,101 @@ class FunctionScope extends ReturnValueScope {
7353
7351
  }
7354
7352
  }
7355
7353
 
7354
+ class BlockScope extends ChildScope {
7355
+ addDeclaration(identifier, context, init, isHoisted) {
7356
+ if (isHoisted) {
7357
+ const variable = this.parent.addDeclaration(identifier, context, init, isHoisted);
7358
+ // Necessary to make sure the init is deoptimized for conditional declarations.
7359
+ // We cannot call deoptimizePath here.
7360
+ variable.markInitializersForDeoptimization();
7361
+ return variable;
7362
+ }
7363
+ else {
7364
+ return super.addDeclaration(identifier, context, init, false);
7365
+ }
7366
+ }
7367
+ }
7368
+
7369
+ class ExpressionStatement extends NodeBase {
7370
+ initialise() {
7371
+ if (this.directive &&
7372
+ this.directive !== 'use strict' &&
7373
+ this.parent.type === Program$1) {
7374
+ this.context.warn(
7375
+ // This is necessary, because either way (deleting or not) can lead to errors.
7376
+ {
7377
+ code: 'MODULE_LEVEL_DIRECTIVE',
7378
+ message: `Module level directives cause errors when bundled, '${this.directive}' was ignored.`
7379
+ }, this.start);
7380
+ }
7381
+ }
7382
+ render(code, options) {
7383
+ super.render(code, options);
7384
+ if (this.included)
7385
+ this.insertSemicolon(code);
7386
+ }
7387
+ shouldBeIncluded(context) {
7388
+ if (this.directive && this.directive !== 'use strict')
7389
+ return this.parent.type !== Program$1;
7390
+ return super.shouldBeIncluded(context);
7391
+ }
7392
+ }
7393
+
7394
+ class BlockStatement extends NodeBase {
7395
+ constructor() {
7396
+ super(...arguments);
7397
+ this.directlyIncluded = false;
7398
+ }
7399
+ addImplicitReturnExpressionToScope() {
7400
+ const lastStatement = this.body[this.body.length - 1];
7401
+ if (!lastStatement || lastStatement.type !== ReturnStatement$1) {
7402
+ this.scope.addReturnExpression(UNKNOWN_EXPRESSION);
7403
+ }
7404
+ }
7405
+ createScope(parentScope) {
7406
+ this.scope = this.parent.preventChildBlockScope
7407
+ ? parentScope
7408
+ : new BlockScope(parentScope);
7409
+ }
7410
+ hasEffects(context) {
7411
+ if (this.deoptimizeBody)
7412
+ return true;
7413
+ for (const node of this.body) {
7414
+ if (context.brokenFlow)
7415
+ break;
7416
+ if (node.hasEffects(context))
7417
+ return true;
7418
+ }
7419
+ return false;
7420
+ }
7421
+ include(context, includeChildrenRecursively) {
7422
+ if (!(this.deoptimizeBody && this.directlyIncluded)) {
7423
+ this.included = true;
7424
+ this.directlyIncluded = true;
7425
+ if (this.deoptimizeBody)
7426
+ includeChildrenRecursively = true;
7427
+ for (const node of this.body) {
7428
+ if (includeChildrenRecursively || node.shouldBeIncluded(context))
7429
+ node.include(context, includeChildrenRecursively);
7430
+ }
7431
+ }
7432
+ }
7433
+ initialise() {
7434
+ const firstBodyStatement = this.body[0];
7435
+ this.deoptimizeBody =
7436
+ firstBodyStatement instanceof ExpressionStatement &&
7437
+ firstBodyStatement.directive === 'use asm';
7438
+ }
7439
+ render(code, options) {
7440
+ if (this.body.length) {
7441
+ renderStatementList(this.body, code, this.start + 1, this.end - 1, options);
7442
+ }
7443
+ else {
7444
+ super.render(code, options);
7445
+ }
7446
+ }
7447
+ }
7448
+
7356
7449
  class RestElement extends NodeBase {
7357
7450
  constructor() {
7358
7451
  super(...arguments);
@@ -7512,7 +7605,7 @@ class FunctionNode extends NodeBase {
7512
7605
  this.body.addImplicitReturnExpressionToScope();
7513
7606
  }
7514
7607
  parseNode(esTreeNode) {
7515
- this.body = new this.context.nodeConstructors.BlockStatement(esTreeNode.body, this, this.scope.hoistedBodyVarScope);
7608
+ this.body = new BlockStatement(esTreeNode.body, this, this.scope.hoistedBodyVarScope);
7516
7609
  super.parseNode(esTreeNode);
7517
7610
  }
7518
7611
  }
@@ -7527,7 +7620,7 @@ class FunctionDeclaration extends FunctionNode {
7527
7620
  }
7528
7621
  parseNode(esTreeNode) {
7529
7622
  if (esTreeNode.id !== null) {
7530
- this.id = new this.context.nodeConstructors.Identifier(esTreeNode.id, this, this.scope.parent);
7623
+ this.id = new Identifier(esTreeNode.id, this, this.scope.parent);
7531
7624
  }
7532
7625
  super.parseNode(esTreeNode);
7533
7626
  }
@@ -8118,101 +8211,6 @@ class ArrayPattern extends NodeBase {
8118
8211
  }
8119
8212
  }
8120
8213
 
8121
- class BlockScope extends ChildScope {
8122
- addDeclaration(identifier, context, init, isHoisted) {
8123
- if (isHoisted) {
8124
- const variable = this.parent.addDeclaration(identifier, context, init, isHoisted);
8125
- // Necessary to make sure the init is deoptimized for conditional declarations.
8126
- // We cannot call deoptimizePath here.
8127
- variable.markInitializersForDeoptimization();
8128
- return variable;
8129
- }
8130
- else {
8131
- return super.addDeclaration(identifier, context, init, false);
8132
- }
8133
- }
8134
- }
8135
-
8136
- class ExpressionStatement extends NodeBase {
8137
- initialise() {
8138
- if (this.directive &&
8139
- this.directive !== 'use strict' &&
8140
- this.parent.type === Program$1) {
8141
- this.context.warn(
8142
- // This is necessary, because either way (deleting or not) can lead to errors.
8143
- {
8144
- code: 'MODULE_LEVEL_DIRECTIVE',
8145
- message: `Module level directives cause errors when bundled, '${this.directive}' was ignored.`
8146
- }, this.start);
8147
- }
8148
- }
8149
- render(code, options) {
8150
- super.render(code, options);
8151
- if (this.included)
8152
- this.insertSemicolon(code);
8153
- }
8154
- shouldBeIncluded(context) {
8155
- if (this.directive && this.directive !== 'use strict')
8156
- return this.parent.type !== Program$1;
8157
- return super.shouldBeIncluded(context);
8158
- }
8159
- }
8160
-
8161
- class BlockStatement extends NodeBase {
8162
- constructor() {
8163
- super(...arguments);
8164
- this.directlyIncluded = false;
8165
- }
8166
- addImplicitReturnExpressionToScope() {
8167
- const lastStatement = this.body[this.body.length - 1];
8168
- if (!lastStatement || lastStatement.type !== ReturnStatement$1) {
8169
- this.scope.addReturnExpression(UNKNOWN_EXPRESSION);
8170
- }
8171
- }
8172
- createScope(parentScope) {
8173
- this.scope = this.parent.preventChildBlockScope
8174
- ? parentScope
8175
- : new BlockScope(parentScope);
8176
- }
8177
- hasEffects(context) {
8178
- if (this.deoptimizeBody)
8179
- return true;
8180
- for (const node of this.body) {
8181
- if (node.hasEffects(context))
8182
- return true;
8183
- if (context.brokenFlow)
8184
- break;
8185
- }
8186
- return false;
8187
- }
8188
- include(context, includeChildrenRecursively) {
8189
- if (!this.deoptimizeBody || !this.directlyIncluded) {
8190
- this.included = true;
8191
- this.directlyIncluded = true;
8192
- if (this.deoptimizeBody)
8193
- includeChildrenRecursively = true;
8194
- for (const node of this.body) {
8195
- if (includeChildrenRecursively || node.shouldBeIncluded(context))
8196
- node.include(context, includeChildrenRecursively);
8197
- }
8198
- }
8199
- }
8200
- initialise() {
8201
- const firstBodyStatement = this.body[0];
8202
- this.deoptimizeBody =
8203
- firstBodyStatement instanceof ExpressionStatement &&
8204
- firstBodyStatement.directive === 'use asm';
8205
- }
8206
- render(code, options) {
8207
- if (this.body.length) {
8208
- renderStatementList(this.body, code, this.start + 1, this.end - 1, options);
8209
- }
8210
- else {
8211
- super.render(code, options);
8212
- }
8213
- }
8214
- }
8215
-
8216
8214
  class ArrowFunctionExpression extends NodeBase {
8217
8215
  constructor() {
8218
8216
  super(...arguments);
@@ -8310,7 +8308,7 @@ class ArrowFunctionExpression extends NodeBase {
8310
8308
  }
8311
8309
  parseNode(esTreeNode) {
8312
8310
  if (esTreeNode.body.type === BlockStatement$1) {
8313
- this.body = new this.context.nodeConstructors.BlockStatement(esTreeNode.body, this, this.scope.hoistedBodyVarScope);
8311
+ this.body = new BlockStatement(esTreeNode.body, this, this.scope.hoistedBodyVarScope);
8314
8312
  }
8315
8313
  super.parseNode(esTreeNode);
8316
8314
  }
@@ -9086,8 +9084,7 @@ class CatchClause extends NodeBase {
9086
9084
  // name instead of the variable
9087
9085
  const { param } = esTreeNode;
9088
9086
  if (param) {
9089
- this.param = new (this.context.nodeConstructors[param.type] ||
9090
- this.context.nodeConstructors.UnknownNode)(param, this, this.scope);
9087
+ this.param = new (this.context.getNodeConstructor(param.type))(param, this, this.scope);
9091
9088
  this.param.declare('parameter', UNKNOWN_EXPRESSION);
9092
9089
  }
9093
9090
  super.parseNode(esTreeNode);
@@ -9123,7 +9120,7 @@ class ClassBody extends NodeBase {
9123
9120
  parseNode(esTreeNode) {
9124
9121
  const body = (this.body = []);
9125
9122
  for (const definition of esTreeNode.body) {
9126
- body.push(new this.context.nodeConstructors[definition.type](definition, this, definition.static ? this.scope : this.scope.instanceScope));
9123
+ body.push(new (this.context.getNodeConstructor(definition.type))(definition, this, definition.static ? this.scope : this.scope.instanceScope));
9127
9124
  }
9128
9125
  super.parseNode(esTreeNode);
9129
9126
  }
@@ -9614,12 +9611,10 @@ class IfStatement extends NodeBase {
9614
9611
  }
9615
9612
  parseNode(esTreeNode) {
9616
9613
  this.consequentScope = new TrackingScope(this.scope);
9617
- this.consequent = new (this.context.nodeConstructors[esTreeNode.consequent.type] ||
9618
- this.context.nodeConstructors.UnknownNode)(esTreeNode.consequent, this, this.consequentScope);
9614
+ this.consequent = new (this.context.getNodeConstructor(esTreeNode.consequent.type))(esTreeNode.consequent, this, this.consequentScope);
9619
9615
  if (esTreeNode.alternate) {
9620
9616
  this.alternateScope = new TrackingScope(this.scope);
9621
- this.alternate = new (this.context.nodeConstructors[esTreeNode.alternate.type] ||
9622
- this.context.nodeConstructors.UnknownNode)(esTreeNode.alternate, this, this.alternateScope);
9617
+ this.alternate = new (this.context.getNodeConstructor(esTreeNode.alternate.type))(esTreeNode.alternate, this, this.alternateScope);
9623
9618
  }
9624
9619
  super.parseNode(esTreeNode);
9625
9620
  }
@@ -9851,13 +9846,18 @@ const HELPER_GENERATORS = {
9851
9846
  `}${n}${n}`);
9852
9847
  },
9853
9848
  [MERGE_NAMESPACES_VARIABLE](t, snippets, liveBindings, freeze) {
9854
- const { _, n } = snippets;
9849
+ const { _, cnst, n } = snippets;
9850
+ const useForEach = cnst === 'var' && liveBindings;
9855
9851
  return (`function ${MERGE_NAMESPACES_VARIABLE}(n, m)${_}{${n}` +
9856
9852
  `${t}${loopOverNamespaces(`{${n}` +
9857
9853
  `${t}${t}${t}if${_}(k${_}!==${_}'default'${_}&&${_}!(k in n))${_}{${n}` +
9858
- (liveBindings ? copyPropertyLiveBinding : copyPropertyStatic)(t, t + t + t + t, snippets) +
9854
+ (liveBindings
9855
+ ? useForEach
9856
+ ? copyOwnPropertyLiveBinding
9857
+ : copyPropertyLiveBinding
9858
+ : copyPropertyStatic)(t, t + t + t + t, snippets) +
9859
9859
  `${t}${t}${t}}${n}` +
9860
- `${t}${t}}`, !liveBindings, t, snippets)}${n}` +
9860
+ `${t}${t}}`, useForEach, t, snippets)}${n}` +
9861
9861
  `${t}return ${getFrozen('n', freeze)};${n}` +
9862
9862
  `}${n}${n}`);
9863
9863
  }
@@ -9867,7 +9867,7 @@ const getDefaultStatic = ({ _, getPropertyAccess }) => `e${getPropertyAccess('de
9867
9867
  const createNamespaceObject = (t, i, snippets, liveBindings, freeze, namespaceToStringTag) => {
9868
9868
  const { _, cnst, getPropertyAccess, n, s } = snippets;
9869
9869
  const copyProperty = `{${n}` +
9870
- (liveBindings ? copyNonDefaultPropertyLiveBinding : copyPropertyStatic)(t, i + t + t, snippets) +
9870
+ (liveBindings ? copyNonDefaultOwnPropertyLiveBinding : copyPropertyStatic)(t, i + t + t, snippets) +
9871
9871
  `${i}${t}}`;
9872
9872
  return (`${i}${cnst} n${_}=${_}${namespaceToStringTag
9873
9873
  ? `{__proto__:${_}null,${_}[Symbol.toStringTag]:${_}'Module'}`
@@ -9884,30 +9884,30 @@ const loopOverKeys = (body, allowVarLoopVariable, { _, cnst, getFunctionIntro, s
9884
9884
  isAsync: false,
9885
9885
  name: null
9886
9886
  })}${body})${s}`;
9887
- const loopOverNamespaces = (body, allowVarLoopVariable, t, { _, cnst, getDirectReturnFunction, getFunctionIntro, n }) => {
9888
- if (cnst !== 'var' || allowVarLoopVariable) {
9889
- return (`for${_}(var i${_}=${_}0;${_}i${_}<${_}m.length;${_}i++)${_}{${n}` +
9890
- `${t}${t}${cnst} e${_}=${_}m[i];${n}` +
9891
- `${t}${t}if${_}(typeof e${_}!==${_}'string'${_}&&${_}!Array.isArray(e))${_}{${_}for${_}(${cnst} k in e)${_}${body}${_}}${n}${t}}`);
9892
- }
9893
- const [left, right] = getDirectReturnFunction(['e'], {
9894
- functionReturn: false,
9895
- lineBreakIndent: { base: t, t },
9896
- name: null
9897
- });
9898
- return (`m.forEach(${left}` +
9899
- `e${_}&&${_}typeof e${_}!==${_}'string'${_}&&${_}!Array.isArray(e)${_}&&${_}Object.keys(e).forEach(${getFunctionIntro(['k'], {
9900
- isAsync: false,
9887
+ const loopOverNamespaces = (body, useForEach, t, { _, cnst, getDirectReturnFunction, getFunctionIntro, n }) => {
9888
+ if (useForEach) {
9889
+ const [left, right] = getDirectReturnFunction(['e'], {
9890
+ functionReturn: false,
9891
+ lineBreakIndent: { base: t, t },
9901
9892
  name: null
9902
- })}${body})${right});`);
9893
+ });
9894
+ return (`m.forEach(${left}` +
9895
+ `e${_}&&${_}typeof e${_}!==${_}'string'${_}&&${_}!Array.isArray(e)${_}&&${_}Object.keys(e).forEach(${getFunctionIntro(['k'], {
9896
+ isAsync: false,
9897
+ name: null
9898
+ })}${body})${right});`);
9899
+ }
9900
+ return (`for${_}(var i${_}=${_}0;${_}i${_}<${_}m.length;${_}i++)${_}{${n}` +
9901
+ `${t}${t}${cnst} e${_}=${_}m[i];${n}` +
9902
+ `${t}${t}if${_}(typeof e${_}!==${_}'string'${_}&&${_}!Array.isArray(e))${_}{${_}for${_}(${cnst} k in e)${_}${body}${_}}${n}${t}}`);
9903
9903
  };
9904
- const copyNonDefaultPropertyLiveBinding = (t, i, snippets) => {
9904
+ const copyNonDefaultOwnPropertyLiveBinding = (t, i, snippets) => {
9905
9905
  const { _, n } = snippets;
9906
9906
  return (`${i}if${_}(k${_}!==${_}'default')${_}{${n}` +
9907
- copyPropertyLiveBinding(t, i + t, snippets) +
9907
+ copyOwnPropertyLiveBinding(t, i + t, snippets) +
9908
9908
  `${i}}${n}`);
9909
9909
  };
9910
- const copyPropertyLiveBinding = (t, i, { _, cnst, getDirectReturnFunction, n }) => {
9910
+ const copyOwnPropertyLiveBinding = (t, i, { _, cnst, getDirectReturnFunction, n }) => {
9911
9911
  const [left, right] = getDirectReturnFunction([], {
9912
9912
  functionReturn: true,
9913
9913
  lineBreakIndent: null,
@@ -9919,6 +9919,20 @@ const copyPropertyLiveBinding = (t, i, { _, cnst, getDirectReturnFunction, n })
9919
9919
  `${i}${t}get:${_}${left}e[k]${right}${n}` +
9920
9920
  `${i}});${n}`);
9921
9921
  };
9922
+ const copyPropertyLiveBinding = (t, i, { _, cnst, getDirectReturnFunction, n }) => {
9923
+ const [left, right] = getDirectReturnFunction([], {
9924
+ functionReturn: true,
9925
+ lineBreakIndent: null,
9926
+ name: null
9927
+ });
9928
+ return (`${i}${cnst} d${_}=${_}Object.getOwnPropertyDescriptor(e,${_}k);${n}` +
9929
+ `${i}if${_}(d)${_}{${n}` +
9930
+ `${i}${t}Object.defineProperty(n,${_}k,${_}d.get${_}?${_}d${_}:${_}{${n}` +
9931
+ `${i}${t}${t}enumerable:${_}true,${n}` +
9932
+ `${i}${t}${t}get:${_}${left}e[k]${right}${n}` +
9933
+ `${i}${t}});${n}` +
9934
+ `${i}}${n}`);
9935
+ };
9922
9936
  const copyPropertyStatic = (_t, i, { _, n }) => `${i}n[k]${_}=${_}e[k];${n}`;
9923
9937
  const getFrozen = (fragment, freeze) => freeze ? `Object.freeze(${fragment})` : fragment;
9924
9938
  const HELPER_NAMES = Object.keys(HELPER_GENERATORS);
@@ -11110,6 +11124,34 @@ class SequenceExpression extends NodeBase {
11110
11124
  }
11111
11125
  }
11112
11126
 
11127
+ class StaticBlock extends NodeBase {
11128
+ createScope(parentScope) {
11129
+ this.scope = new BlockScope(parentScope);
11130
+ }
11131
+ hasEffects(context) {
11132
+ for (const node of this.body) {
11133
+ if (node.hasEffects(context))
11134
+ return true;
11135
+ }
11136
+ return false;
11137
+ }
11138
+ include(context, includeChildrenRecursively) {
11139
+ this.included = true;
11140
+ for (const node of this.body) {
11141
+ if (includeChildrenRecursively || node.shouldBeIncluded(context))
11142
+ node.include(context, includeChildrenRecursively);
11143
+ }
11144
+ }
11145
+ render(code, options) {
11146
+ if (this.body.length) {
11147
+ renderStatementList(this.body, code, this.start + 1, this.end - 1, options);
11148
+ }
11149
+ else {
11150
+ super.render(code, options);
11151
+ }
11152
+ }
11153
+ }
11154
+
11113
11155
  class Super extends NodeBase {
11114
11156
  bind() {
11115
11157
  this.variable = this.scope.findVariable('this');
@@ -11742,6 +11784,7 @@ const nodeConstructors = {
11742
11784
  ReturnStatement,
11743
11785
  SequenceExpression,
11744
11786
  SpreadElement,
11787
+ StaticBlock,
11745
11788
  Super,
11746
11789
  SwitchCase,
11747
11790
  SwitchStatement,
@@ -12140,7 +12183,6 @@ class Module {
12140
12183
  this.isExecuted = false;
12141
12184
  this.isUserDefinedEntryPoint = false;
12142
12185
  this.needsExportShim = false;
12143
- this.preserveSignature = this.options.preserveEntrySignatures;
12144
12186
  this.reexportDescriptions = Object.create(null);
12145
12187
  this.sideEffectDependenciesByVariable = new Map();
12146
12188
  this.sources = new Set();
@@ -12158,6 +12200,7 @@ class Module {
12158
12200
  this.transitiveReexports = null;
12159
12201
  this.excludeFromSourcemap = /\0/.test(id);
12160
12202
  this.context = options.moduleContext(id);
12203
+ this.preserveSignature = this.options.preserveEntrySignatures;
12161
12204
  // eslint-disable-next-line @typescript-eslint/no-this-alias
12162
12205
  const module = this;
12163
12206
  this.info = {
@@ -12184,7 +12227,7 @@ class Module {
12184
12227
  return Array.from(module.implicitlyLoadedBefore, getId);
12185
12228
  },
12186
12229
  get importedIds() {
12187
- return Array.from(module.sources, source => module.resolvedIds[source].id);
12230
+ return Array.from(module.sources, source => { var _a; return (_a = module.resolvedIds[source]) === null || _a === void 0 ? void 0 : _a.id; }).filter(Boolean);
12188
12231
  },
12189
12232
  get importers() {
12190
12233
  return module.importers.sort();
@@ -12535,6 +12578,7 @@ class Module {
12535
12578
  getExports: this.getExports.bind(this),
12536
12579
  getModuleExecIndex: () => this.execIndex,
12537
12580
  getModuleName: this.basename.bind(this),
12581
+ getNodeConstructor: (name) => nodeConstructors[name] || nodeConstructors.UnknownNode,
12538
12582
  getReexports: this.getReexports.bind(this),
12539
12583
  importDescriptions: this.importDescriptions,
12540
12584
  includeAllExports: () => this.includeAllExports(true),
@@ -12543,7 +12587,6 @@ class Module {
12543
12587
  magicString: this.magicString,
12544
12588
  module: this,
12545
12589
  moduleContext: this.context,
12546
- nodeConstructors,
12547
12590
  options: this.options,
12548
12591
  requestTreeshakingPass: () => (this.graph.needsTreeshakingPass = true),
12549
12592
  traceExport: this.getVariableForExportName.bind(this),
@@ -21847,6 +21890,7 @@ class ModuleLoader {
21847
21890
  this.implicitEntryModules = new Set();
21848
21891
  this.indexedEntryModules = [];
21849
21892
  this.latestLoadModulesPromise = Promise.resolve();
21893
+ this.moduleLoadPromises = new Map();
21850
21894
  this.nextEntryModuleIndex = 0;
21851
21895
  this.readQueue = new Queue();
21852
21896
  this.resolveId = async (source, importer, customOptions, isEntry, skip = null) => {
@@ -21908,6 +21952,9 @@ class ModuleLoader {
21908
21952
  }
21909
21953
  return module;
21910
21954
  }
21955
+ preloadModule(resolvedId) {
21956
+ return this.fetchModule(this.addDefaultsToResolvedId(resolvedId), undefined, false, true).then(module => module.info);
21957
+ }
21911
21958
  addDefaultsToResolvedId(resolvedId) {
21912
21959
  var _a, _b;
21913
21960
  if (!resolvedId) {
@@ -22008,39 +22055,45 @@ class ModuleLoader {
22008
22055
  }
22009
22056
  }
22010
22057
  }
22011
- async fetchModule({ id, meta, moduleSideEffects, syntheticNamedExports }, importer, isEntry) {
22058
+ // If this is a preload, then this method always waits for the dependencies of the module to be resolved.
22059
+ // Otherwise if the module does not exist, it waits for the module and all its dependencies to be loaded.
22060
+ // Otherwise it returns immediately.
22061
+ async fetchModule({ id, meta, moduleSideEffects, syntheticNamedExports }, importer, isEntry, isPreload) {
22012
22062
  const existingModule = this.modulesById.get(id);
22013
22063
  if (existingModule instanceof Module) {
22014
- if (isEntry) {
22015
- existingModule.info.isEntry = true;
22016
- this.implicitEntryModules.delete(existingModule);
22017
- for (const dependant of existingModule.implicitlyLoadedAfter) {
22018
- dependant.implicitlyLoadedBefore.delete(existingModule);
22019
- }
22020
- existingModule.implicitlyLoadedAfter.clear();
22021
- }
22064
+ await this.handleExistingModule(existingModule, isEntry, isPreload);
22022
22065
  return existingModule;
22023
22066
  }
22024
22067
  const module = new Module(this.graph, id, this.options, isEntry, moduleSideEffects, syntheticNamedExports, meta);
22025
22068
  this.modulesById.set(id, module);
22026
22069
  this.graph.watchFiles[id] = true;
22027
- await this.addModuleSource(id, importer, module);
22028
- const resolveStaticDependencyPromises = this.getResolveStaticDependencyPromises(module);
22029
- const resolveDynamicImportPromises = this.getResolveDynamicImportPromises(module);
22030
- Promise.all([
22031
- ...resolveStaticDependencyPromises,
22032
- ...resolveDynamicImportPromises
22033
- ])
22034
- .then(() => this.pluginDriver.hookParallel('moduleParsed', [module.info]))
22035
- .catch(() => {
22036
- /* rejections thrown here are also handled within PluginDriver - they are safe to ignore */
22070
+ const loadPromise = this.addModuleSource(id, importer, module).then(() => [
22071
+ this.getResolveStaticDependencyPromises(module),
22072
+ this.getResolveDynamicImportPromises(module)
22073
+ ]);
22074
+ const loadAndResolveDependenciesPromise = loadPromise
22075
+ .then(([resolveStaticDependencyPromises, resolveDynamicImportPromises]) => Promise.all([...resolveStaticDependencyPromises, ...resolveDynamicImportPromises]))
22076
+ .then(() => this.pluginDriver.hookParallel('moduleParsed', [module.info]));
22077
+ loadAndResolveDependenciesPromise.catch(() => {
22078
+ /* avoid unhandled promise rejections */
22037
22079
  });
22080
+ if (isPreload) {
22081
+ this.moduleLoadPromises.set(module, loadPromise);
22082
+ await loadPromise;
22083
+ }
22084
+ else {
22085
+ await this.fetchModuleDependencies(module, ...(await loadPromise));
22086
+ // To handle errors when resolving dependencies or in moduleParsed
22087
+ await loadAndResolveDependenciesPromise;
22088
+ }
22089
+ return module;
22090
+ }
22091
+ async fetchModuleDependencies(module, resolveStaticDependencyPromises, resolveDynamicDependencyPromises) {
22038
22092
  await Promise.all([
22039
22093
  this.fetchStaticDependencies(module, resolveStaticDependencyPromises),
22040
- this.fetchDynamicDependencies(module, resolveDynamicImportPromises)
22094
+ this.fetchDynamicDependencies(module, resolveDynamicDependencyPromises)
22041
22095
  ]);
22042
22096
  module.linkImports();
22043
- return module;
22044
22097
  }
22045
22098
  fetchResolvedDependency(source, importer, resolvedId) {
22046
22099
  if (resolvedId.external) {
@@ -22055,7 +22108,7 @@ class ModuleLoader {
22055
22108
  return Promise.resolve(externalModule);
22056
22109
  }
22057
22110
  else {
22058
- return this.fetchModule(resolvedId, importer, false);
22111
+ return this.fetchModule(resolvedId, importer, false, false);
22059
22112
  }
22060
22113
  }
22061
22114
  async fetchStaticDependencies(module, resolveStaticDependencyPromises) {
@@ -22126,6 +22179,26 @@ class ModuleLoader {
22126
22179
  this.handleResolveId(await this.resolveId(source, module.id, EMPTY_OBJECT, false), source, module.id))
22127
22180
  ]);
22128
22181
  }
22182
+ async handleExistingModule(module, isEntry, isPreload) {
22183
+ const loadPromise = this.moduleLoadPromises.get(module);
22184
+ if (isPreload) {
22185
+ await loadPromise;
22186
+ return;
22187
+ }
22188
+ if (isEntry) {
22189
+ module.info.isEntry = true;
22190
+ this.implicitEntryModules.delete(module);
22191
+ for (const dependant of module.implicitlyLoadedAfter) {
22192
+ dependant.implicitlyLoadedBefore.delete(module);
22193
+ }
22194
+ module.implicitlyLoadedAfter.clear();
22195
+ }
22196
+ if (loadPromise) {
22197
+ this.moduleLoadPromises.delete(module);
22198
+ await this.fetchModuleDependencies(module, ...(await loadPromise));
22199
+ }
22200
+ return;
22201
+ }
22129
22202
  handleResolveId(resolvedId, source, importer) {
22130
22203
  if (resolvedId === null) {
22131
22204
  if (isRelative(source)) {
@@ -22162,7 +22235,7 @@ class ModuleLoader {
22162
22235
  }
22163
22236
  return this.fetchModule(this.addDefaultsToResolvedId(typeof resolveIdResult === 'object'
22164
22237
  ? resolveIdResult
22165
- : { id: resolveIdResult }), undefined, isEntry);
22238
+ : { id: resolveIdResult }), undefined, isEntry, false);
22166
22239
  }
22167
22240
  async resolveDynamicImport(module, specifier, importer) {
22168
22241
  const resolution = await this.pluginDriver.hookFirst('resolveDynamicImport', [
@@ -22290,12 +22363,16 @@ function getPluginContext(plugin, pluginCache, graph, options, fileEmitter, exis
22290
22363
  getModuleInfo: graph.getModuleInfo,
22291
22364
  getWatchFiles: () => Object.keys(graph.watchFiles),
22292
22365
  isExternal: getDeprecatedContextHandler((id, parentId, isResolved = false) => options.external(id, parentId, isResolved), 'isExternal', 'resolve', plugin.name, true, options),
22366
+ load(resolvedId) {
22367
+ return graph.moduleLoader.preloadModule(resolvedId);
22368
+ },
22293
22369
  meta: {
22294
22370
  rollupVersion: version$1,
22295
22371
  watchMode: graph.watchMode
22296
22372
  },
22297
22373
  get moduleIds() {
22298
22374
  function* wrappedModuleIds() {
22375
+ // We are wrapping this in a generator to only show the message once we are actually iterating
22299
22376
  warnDeprecation({
22300
22377
  message: `Accessing "this.moduleIds" on the plugin context by plugin ${plugin.name} is deprecated. The "this.getModuleIds" plugin context function should be used instead.`,
22301
22378
  plugin: plugin.name
@@ -23007,12 +23084,15 @@ const getHasModuleSideEffects = (moduleSideEffectsOption, pureExternalModules) =
23007
23084
  return (id, external) => !(external && isPureExternalModule(id));
23008
23085
  };
23009
23086
 
23087
+ // https://datatracker.ietf.org/doc/html/rfc2396
23088
+ // eslint-disable-next-line no-control-regex
23089
+ const INVALID_CHAR_RE = /[\x00-\x1F\x7F<>*#"{}|^[\]`;?:&=+$,]/g;
23010
23090
  function sanitizeFileName(name) {
23011
23091
  const match = /^[a-z]:/i.exec(name);
23012
23092
  const driveLetter = match ? match[0] : '';
23013
23093
  // A `:` is only allowed as part of a windows drive letter (ex: C:\foo)
23014
23094
  // Otherwise, avoid them because they can refer to NTFS alternate data streams.
23015
- return driveLetter + name.substr(driveLetter.length).replace(/[\0?*:]/g, '_');
23095
+ return driveLetter + name.substr(driveLetter.length).replace(INVALID_CHAR_RE, '_');
23016
23096
  }
23017
23097
 
23018
23098
  function normalizeOutputOptions(config, inputOptions, unsetInputOptions) {