rollup 2.51.2 → 2.52.3

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.
package/dist/es/rollup.js CHANGED
@@ -1,7 +1,7 @@
1
1
  /*
2
2
  @license
3
- Rollup.js v2.51.2
4
- Fri, 11 Jun 2021 05:35:15 GMT - commit bfae7910ea7553d56782cb5ee0c8581e2b451729
3
+ Rollup.js v2.52.3
4
+ Fri, 25 Jun 2021 13:12:43 GMT - commit 9c436a7c7c368f2ff840735a30119899513ff4bd
5
5
 
6
6
 
7
7
  https://github.com/rollup/rollup
@@ -1,7 +1,7 @@
1
1
  /*
2
2
  @license
3
- Rollup.js v2.51.2
4
- Fri, 11 Jun 2021 05:35:15 GMT - commit bfae7910ea7553d56782cb5ee0c8581e2b451729
3
+ Rollup.js v2.52.3
4
+ Fri, 25 Jun 2021 13:12:43 GMT - commit 9c436a7c7c368f2ff840735a30119899513ff4bd
5
5
 
6
6
 
7
7
  https://github.com/rollup/rollup
@@ -14,7 +14,7 @@ import * as fs from 'fs';
14
14
  import { lstatSync, realpathSync, readdirSync } from 'fs';
15
15
  import { EventEmitter } from 'events';
16
16
 
17
- var version$1 = "2.51.2";
17
+ var version$1 = "2.52.3";
18
18
 
19
19
  var charToInteger = {};
20
20
  var chars$1 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
@@ -3027,9 +3027,7 @@ class LocalVariable extends Variable {
3027
3027
  if (path.length > MAX_PATH_DEPTH || this.isReassigned)
3028
3028
  return true;
3029
3029
  return (this.init &&
3030
- !(callOptions.withNew
3031
- ? context.instantiated
3032
- : context.called).trackEntityAtPathAndGetIfTracked(path, callOptions, this) &&
3030
+ !(callOptions.withNew ? context.instantiated : context.called).trackEntityAtPathAndGetIfTracked(path, callOptions, this) &&
3033
3031
  this.init.hasEffectsWhenCalledAtPath(path, callOptions, context));
3034
3032
  }
3035
3033
  include() {
@@ -4104,9 +4102,14 @@ class Identifier extends NodeBase {
4104
4102
  }
4105
4103
  declare(kind, init) {
4106
4104
  let variable;
4105
+ const { treeshake } = this.context.options;
4107
4106
  switch (kind) {
4108
4107
  case 'var':
4109
4108
  variable = this.scope.addDeclaration(this, this.context, init, true);
4109
+ if (treeshake && treeshake.correctVarValueBeforeDeclaration) {
4110
+ // Necessary to make sure the init is deoptimized. We cannot call deoptimizePath here.
4111
+ this.scope.addDeclaration(this, this.context, UNDEFINED_EXPRESSION, true);
4112
+ }
4110
4113
  break;
4111
4114
  case 'function':
4112
4115
  // in strict mode, functions are only hoisted within a scope but not across block scopes
@@ -4280,9 +4283,10 @@ const INTEGER_REG_EXP = /^\d+$/;
4280
4283
  class ObjectEntity extends ExpressionEntity {
4281
4284
  // If a PropertyMap is used, this will be taken as propertiesAndGettersByKey
4282
4285
  // and we assume there are no setters or getters
4283
- constructor(properties, prototypeExpression) {
4286
+ constructor(properties, prototypeExpression, immutable = false) {
4284
4287
  super();
4285
4288
  this.prototypeExpression = prototypeExpression;
4289
+ this.immutable = immutable;
4286
4290
  this.allProperties = [];
4287
4291
  this.deoptimizedPaths = Object.create(null);
4288
4292
  this.expressionsToBeDeoptimizedByKey = Object.create(null);
@@ -4338,7 +4342,7 @@ class ObjectEntity extends ExpressionEntity {
4338
4342
  }
4339
4343
  deoptimizePath(path) {
4340
4344
  var _a;
4341
- if (this.hasUnknownDeoptimizedProperty)
4345
+ if (this.hasUnknownDeoptimizedProperty || this.immutable)
4342
4346
  return;
4343
4347
  const key = path[0];
4344
4348
  if (path.length === 1) {
@@ -4370,9 +4374,6 @@ class ObjectEntity extends ExpressionEntity {
4370
4374
  }
4371
4375
  deoptimizeThisOnEventAtPath(event, path, thisParameter, recursionTracker) {
4372
4376
  var _a;
4373
- if (path.length === 0) {
4374
- return;
4375
- }
4376
4377
  const [key, ...subPath] = path;
4377
4378
  if (this.hasUnknownDeoptimizedProperty ||
4378
4379
  // single paths that are deoptimized will not become getters or setters
@@ -4399,7 +4400,9 @@ class ObjectEntity extends ExpressionEntity {
4399
4400
  property.deoptimizeThisOnEventAtPath(event, subPath, thisParameter, recursionTracker);
4400
4401
  }
4401
4402
  }
4402
- this.thisParametersToBeDeoptimized.add(thisParameter);
4403
+ if (!this.immutable) {
4404
+ this.thisParametersToBeDeoptimized.add(thisParameter);
4405
+ }
4403
4406
  return;
4404
4407
  }
4405
4408
  for (const property of relevantUnmatchableProperties) {
@@ -4423,7 +4426,9 @@ class ObjectEntity extends ExpressionEntity {
4423
4426
  property.deoptimizeThisOnEventAtPath(event, subPath, thisParameter, recursionTracker);
4424
4427
  }
4425
4428
  }
4426
- this.thisParametersToBeDeoptimized.add(thisParameter);
4429
+ if (!this.immutable) {
4430
+ this.thisParametersToBeDeoptimized.add(thisParameter);
4431
+ }
4427
4432
  (_a = this.prototypeExpression) === null || _a === void 0 ? void 0 : _a.deoptimizeThisOnEventAtPath(event, path, thisParameter, recursionTracker);
4428
4433
  }
4429
4434
  getLiteralValueAtPath(path, recursionTracker, origin) {
@@ -4486,8 +4491,9 @@ class ObjectEntity extends ExpressionEntity {
4486
4491
  return false;
4487
4492
  }
4488
4493
  for (const getter of this.unmatchableGetters) {
4489
- if (getter.hasEffectsWhenAccessedAtPath(subPath, context))
4494
+ if (getter.hasEffectsWhenAccessedAtPath(subPath, context)) {
4490
4495
  return true;
4496
+ }
4491
4497
  }
4492
4498
  }
4493
4499
  else {
@@ -4520,6 +4526,7 @@ class ObjectEntity extends ExpressionEntity {
4520
4526
  }
4521
4527
  if (this.hasUnknownDeoptimizedProperty)
4522
4528
  return true;
4529
+ // We do not need to test for unknown properties as in that case, hasUnknownDeoptimizedProperty is true
4523
4530
  if (typeof key === 'string') {
4524
4531
  if (this.propertiesAndSettersByKey[key]) {
4525
4532
  const setters = this.settersByKey[key];
@@ -4532,15 +4539,8 @@ class ObjectEntity extends ExpressionEntity {
4532
4539
  return false;
4533
4540
  }
4534
4541
  for (const property of this.unmatchableSetters) {
4535
- if (property.hasEffectsWhenAssignedAtPath(subPath, context))
4542
+ if (property.hasEffectsWhenAssignedAtPath(subPath, context)) {
4536
4543
  return true;
4537
- }
4538
- }
4539
- else {
4540
- for (const setters of Object.values(this.settersByKey).concat([this.unmatchableSetters])) {
4541
- for (const setter of setters) {
4542
- if (setter.hasEffectsWhenAssignedAtPath(subPath, context))
4543
- return true;
4544
4544
  }
4545
4545
  }
4546
4546
  }
@@ -4599,11 +4599,6 @@ class ObjectEntity extends ExpressionEntity {
4599
4599
  }
4600
4600
  if (!propertiesAndGettersByKey[key]) {
4601
4601
  propertiesAndGettersByKey[key] = [property, ...unmatchablePropertiesAndGetters];
4602
- if (INTEGER_REG_EXP.test(key)) {
4603
- for (const integerProperty of unknownIntegerProps) {
4604
- propertiesAndGettersByKey[key].push(integerProperty);
4605
- }
4606
- }
4607
4602
  }
4608
4603
  }
4609
4604
  }
@@ -4654,7 +4649,7 @@ class ObjectEntity extends ExpressionEntity {
4654
4649
  return UNKNOWN_EXPRESSION;
4655
4650
  }
4656
4651
  const expression = this.getMemberExpression(key);
4657
- if (expression !== UNKNOWN_EXPRESSION) {
4652
+ if (!(expression === UNKNOWN_EXPRESSION || this.immutable)) {
4658
4653
  const expressionsToBeDeoptimized = (this.expressionsToBeDeoptimizedByKey[key] =
4659
4654
  this.expressionsToBeDeoptimizedByKey[key] || []);
4660
4655
  expressionsToBeDeoptimized.push(origin);
@@ -4787,7 +4782,7 @@ const OBJECT_PROTOTYPE = new ObjectEntity({
4787
4782
  toLocaleString: METHOD_RETURNS_STRING,
4788
4783
  toString: METHOD_RETURNS_STRING,
4789
4784
  valueOf: METHOD_RETURNS_UNKNOWN
4790
- }, null);
4785
+ }, null, true);
4791
4786
 
4792
4787
  class ClassNode extends NodeBase {
4793
4788
  constructor() {
@@ -5766,7 +5761,7 @@ const ARRAY_PROTOTYPE = new ObjectEntity({
5766
5761
  splice: METHOD_MUTATES_SELF_RETURNS_NEW_ARRAY,
5767
5762
  unshift: METHOD_MUTATES_SELF_RETURNS_NUMBER,
5768
5763
  values: METHOD_DEOPTS_SELF_RETURNS_UNKNOWN
5769
- }, OBJECT_PROTOTYPE);
5764
+ }, OBJECT_PROTOTYPE, true);
5770
5765
 
5771
5766
  class ArrayExpression extends NodeBase {
5772
5767
  constructor() {
@@ -5801,10 +5796,14 @@ class ArrayExpression extends NodeBase {
5801
5796
  const properties = [
5802
5797
  { key: 'length', kind: 'init', property: UNKNOWN_LITERAL_NUMBER }
5803
5798
  ];
5799
+ let hasSpread = false;
5804
5800
  for (let index = 0; index < this.elements.length; index++) {
5805
5801
  const element = this.elements[index];
5806
- if (element instanceof SpreadElement) {
5807
- properties.unshift({ key: UnknownInteger, kind: 'init', property: element });
5802
+ if (element instanceof SpreadElement || hasSpread) {
5803
+ if (element) {
5804
+ hasSpread = true;
5805
+ properties.unshift({ key: UnknownInteger, kind: 'init', property: element });
5806
+ }
5808
5807
  }
5809
5808
  else if (!element) {
5810
5809
  properties.push({ key: String(index), kind: 'init', property: UNDEFINED_EXPRESSION });
@@ -5857,7 +5856,9 @@ class ArrayPattern extends NodeBase {
5857
5856
  class BlockScope extends ChildScope {
5858
5857
  addDeclaration(identifier, context, init, isHoisted) {
5859
5858
  if (isHoisted) {
5860
- return this.parent.addDeclaration(identifier, context, UNKNOWN_EXPRESSION, isHoisted);
5859
+ this.parent.addDeclaration(identifier, context, init, isHoisted);
5860
+ // Necessary to make sure the init is deoptimized. We cannot call deoptimizePath here.
5861
+ return this.parent.addDeclaration(identifier, context, UNDEFINED_EXPRESSION, isHoisted);
5861
5862
  }
5862
5863
  else {
5863
5864
  return super.addDeclaration(identifier, context, init, false);
@@ -6618,9 +6619,7 @@ class CallExpression extends NodeBase {
6618
6619
  this.getReturnExpression().hasEffectsWhenAssignedAtPath(path, context));
6619
6620
  }
6620
6621
  hasEffectsWhenCalledAtPath(path, callOptions, context) {
6621
- return (!(callOptions.withNew
6622
- ? context.instantiated
6623
- : context.called).trackEntityAtPathAndGetIfTracked(path, callOptions, this) &&
6622
+ return (!(callOptions.withNew ? context.instantiated : context.called).trackEntityAtPathAndGetIfTracked(path, callOptions, this) &&
6624
6623
  this.getReturnExpression().hasEffectsWhenCalledAtPath(path, callOptions, context));
6625
6624
  }
6626
6625
  include(context, includeChildrenRecursively) {
@@ -6701,8 +6700,7 @@ class CatchScope extends ParameterScope {
6701
6700
  existingParameter.addDeclaration(identifier, init);
6702
6701
  return existingParameter;
6703
6702
  }
6704
- // as parameters are handled differently, all remaining declarations are
6705
- // hoisted
6703
+ // as parameters are handled differently, all remaining declarations are hoisted
6706
6704
  return this.parent.addDeclaration(identifier, context, init, isHoisted);
6707
6705
  }
6708
6706
  }
@@ -8326,7 +8324,11 @@ const getResolveUrl = (path, URL = 'URL') => `new ${URL}(${path}).href`;
8326
8324
  const getRelativeUrlFromDocument = (relativePath) => getResolveUrl(`'${relativePath}', document.currentScript && document.currentScript.src || document.baseURI`);
8327
8325
  const getGenericImportMetaMechanism = (getUrl) => (prop, chunkId) => {
8328
8326
  const urlMechanism = getUrl(chunkId);
8329
- return prop === null ? `({ url: ${urlMechanism} })` : prop === 'url' ? urlMechanism : 'undefined';
8327
+ return prop === null
8328
+ ? `({ url: ${urlMechanism} })`
8329
+ : prop === 'url'
8330
+ ? urlMechanism
8331
+ : 'undefined';
8330
8332
  };
8331
8333
  const getUrlFromDocument = (chunkId) => `(document.currentScript && document.currentScript.src || new URL('${chunkId}', document.baseURI).href)`;
8332
8334
  const relativeUrlMechanisms = {
@@ -13788,9 +13790,10 @@ function getLineInfo(input, offset) {
13788
13790
  var defaultOptions = {
13789
13791
  // `ecmaVersion` indicates the ECMAScript version to parse. Must be
13790
13792
  // either 3, 5, 6 (or 2015), 7 (2016), 8 (2017), 9 (2018), 10
13791
- // (2019), 11 (2020), 12 (2021), or `"latest"` (the latest version
13792
- // the library supports). This influences support for strict mode,
13793
- // the set of reserved words, and support for new syntax features.
13793
+ // (2019), 11 (2020), 12 (2021), 13 (2022), or `"latest"` (the
13794
+ // latest version the library supports). This influences support
13795
+ // for strict mode, the set of reserved words, and support for
13796
+ // new syntax features.
13794
13797
  ecmaVersion: null,
13795
13798
  // `sourceType` indicates the mode the code should be parsed in.
13796
13799
  // Can be either `"script"` or `"module"`. This influences global
@@ -13817,9 +13820,13 @@ var defaultOptions = {
13817
13820
  // appearing at the top of the program, and an import.meta expression
13818
13821
  // in a script isn't considered an error.
13819
13822
  allowImportExportEverywhere: false,
13823
+ // By default, await identifiers are allowed to appear at the top-level scope only if ecmaVersion >= 2022.
13820
13824
  // When enabled, await identifiers are allowed to appear at the top-level scope,
13821
13825
  // but they are still not allowed in non-async functions.
13822
- allowAwaitOutsideFunction: false,
13826
+ allowAwaitOutsideFunction: null,
13827
+ // When enabled, super identifiers are not constrained to
13828
+ // appearing in methods and do not raise an error when they appear elsewhere.
13829
+ allowSuperOutsideMethod: null,
13823
13830
  // When enabled, hashbang directive in the beginning of file
13824
13831
  // is allowed and treated as a line comment.
13825
13832
  allowHashBang: false,
@@ -13895,6 +13902,8 @@ function getOptions(opts) {
13895
13902
 
13896
13903
  if (options.allowReserved == null)
13897
13904
  { options.allowReserved = options.ecmaVersion < 5; }
13905
+ if (options.allowAwaitOutsideFunction == null)
13906
+ { options.allowAwaitOutsideFunction = options.ecmaVersion >= 13; }
13898
13907
 
13899
13908
  if (isArray(options.onToken)) {
13900
13909
  var tokens = options.onToken;
@@ -14047,7 +14056,7 @@ prototypeAccessors.allowSuper.get = function () {
14047
14056
  var ref = this.currentThisScope();
14048
14057
  var flags = ref.flags;
14049
14058
  var inClassFieldInit = ref.inClassFieldInit;
14050
- return (flags & SCOPE_SUPER) > 0 || inClassFieldInit
14059
+ return (flags & SCOPE_SUPER) > 0 || inClassFieldInit || this.options.allowSuperOutsideMethod
14051
14060
  };
14052
14061
  prototypeAccessors.allowDirectSuper.get = function () { return (this.currentThisScope().flags & SCOPE_DIRECT_SUPER) > 0 };
14053
14062
  prototypeAccessors.treatFunctionsAsVar.get = function () { return this.treatFunctionsAsVarInScope(this.currentScope()) };
@@ -14272,13 +14281,14 @@ pp$1.isLet = function(context) {
14272
14281
  // Statement) is allowed here. If context is not empty then only a Statement
14273
14282
  // is allowed. However, `let [` is an explicit negative lookahead for
14274
14283
  // ExpressionStatement, so special-case it first.
14275
- if (nextCh === 91) { return true } // '['
14284
+ if (nextCh === 91 || nextCh === 92 || nextCh > 0xd7ff && nextCh < 0xdc00) { return true } // '[', '/', astral
14276
14285
  if (context) { return false }
14277
14286
 
14278
14287
  if (nextCh === 123) { return true } // '{'
14279
14288
  if (isIdentifierStart(nextCh, true)) {
14280
14289
  var pos = next + 1;
14281
- while (isIdentifierChar(this.input.charCodeAt(pos), true)) { ++pos; }
14290
+ while (isIdentifierChar(nextCh = this.input.charCodeAt(pos), true)) { ++pos; }
14291
+ if (nextCh === 92 || nextCh > 0xd7ff && nextCh < 0xdc00) { return true }
14282
14292
  var ident = this.input.slice(next, pos);
14283
14293
  if (!keywordRelationalOperator.test(ident)) { return true }
14284
14294
  }
@@ -14294,10 +14304,11 @@ pp$1.isAsyncFunction = function() {
14294
14304
 
14295
14305
  skipWhiteSpace.lastIndex = this.pos;
14296
14306
  var skip = skipWhiteSpace.exec(this.input);
14297
- var next = this.pos + skip[0].length;
14307
+ var next = this.pos + skip[0].length, after;
14298
14308
  return !lineBreak.test(this.input.slice(this.pos, next)) &&
14299
14309
  this.input.slice(next, next + 8) === "function" &&
14300
- (next + 8 === this.input.length || !isIdentifierChar(this.input.charAt(next + 8)))
14310
+ (next + 8 === this.input.length ||
14311
+ !(isIdentifierChar(after = this.input.charCodeAt(next + 8)) || after > 0xd7ff && after < 0xdc00))
14301
14312
  };
14302
14313
 
14303
14314
  // Parse a single statement.
@@ -17034,7 +17045,7 @@ var pp$8 = Parser.prototype;
17034
17045
 
17035
17046
  var RegExpValidationState = function RegExpValidationState(parser) {
17036
17047
  this.parser = parser;
17037
- this.validFlags = "gim" + (parser.options.ecmaVersion >= 6 ? "uy" : "") + (parser.options.ecmaVersion >= 9 ? "s" : "");
17048
+ this.validFlags = "gim" + (parser.options.ecmaVersion >= 6 ? "uy" : "") + (parser.options.ecmaVersion >= 9 ? "s" : "") + (parser.options.ecmaVersion >= 13 ? "d" : "");
17038
17049
  this.unicodeProperties = data[parser.options.ecmaVersion >= 12 ? 12 : parser.options.ecmaVersion];
17039
17050
  this.source = "";
17040
17051
  this.flags = "";
@@ -18899,7 +18910,7 @@ pp$9.readWord = function() {
18899
18910
 
18900
18911
  // Acorn is a tiny, fast JavaScript parser written in JavaScript.
18901
18912
 
18902
- var version = "8.2.4";
18913
+ var version = "8.4.0";
18903
18914
 
18904
18915
  Parser.acorn = {
18905
18916
  Parser: Parser,
@@ -20044,10 +20055,8 @@ class Graph {
20044
20055
  };
20045
20056
  }
20046
20057
  async generateModuleGraph() {
20047
- ({
20048
- entryModules: this.entryModules,
20049
- implicitEntryModules: this.implicitEntryModules
20050
- } = await this.moduleLoader.addEntryModules(normalizeEntryModules(this.options.input), true));
20058
+ ({ entryModules: this.entryModules, implicitEntryModules: this.implicitEntryModules } =
20059
+ await this.moduleLoader.addEntryModules(normalizeEntryModules(this.options.input), true));
20051
20060
  if (this.entryModules.length === 0) {
20052
20061
  throw new Error('You must supply options.input to rollup');
20053
20062
  }
@@ -20159,6 +20168,32 @@ function warnUnknownOptions(passedOptions, validOptions, optionType, warn, ignor
20159
20168
  });
20160
20169
  }
20161
20170
  }
20171
+ const treeshakePresets = {
20172
+ recommended: {
20173
+ annotations: true,
20174
+ correctVarValueBeforeDeclaration: false,
20175
+ moduleSideEffects: () => true,
20176
+ propertyReadSideEffects: true,
20177
+ tryCatchDeoptimization: true,
20178
+ unknownGlobalSideEffects: false
20179
+ },
20180
+ safest: {
20181
+ annotations: true,
20182
+ correctVarValueBeforeDeclaration: true,
20183
+ moduleSideEffects: () => true,
20184
+ propertyReadSideEffects: true,
20185
+ tryCatchDeoptimization: true,
20186
+ unknownGlobalSideEffects: true
20187
+ },
20188
+ smallest: {
20189
+ annotations: true,
20190
+ correctVarValueBeforeDeclaration: false,
20191
+ moduleSideEffects: () => false,
20192
+ propertyReadSideEffects: false,
20193
+ tryCatchDeoptimization: false,
20194
+ unknownGlobalSideEffects: false
20195
+ }
20196
+ };
20162
20197
 
20163
20198
  function normalizeInputOptions(config) {
20164
20199
  var _a, _b, _c;
@@ -20194,7 +20229,8 @@ function normalizeInputOptions(config) {
20194
20229
  return { options, unsetOptions };
20195
20230
  }
20196
20231
  const getOnwarn = (config) => {
20197
- return config.onwarn
20232
+ const { onwarn } = config;
20233
+ return onwarn
20198
20234
  ? warning => {
20199
20235
  warning.toString = () => {
20200
20236
  let str = '';
@@ -20205,7 +20241,7 @@ const getOnwarn = (config) => {
20205
20241
  str += warning.message;
20206
20242
  return str;
20207
20243
  };
20208
- config.onwarn(warning, defaultOnWarn);
20244
+ onwarn(warning, defaultOnWarn);
20209
20245
  }
20210
20246
  : defaultOnWarn;
20211
20247
  };
@@ -20217,10 +20253,7 @@ const getAcorn = (config) => ({
20217
20253
  ...config.acorn
20218
20254
  });
20219
20255
  const getAcornInjectPlugins = (config) => ensureArray(config.acornInjectPlugins);
20220
- const getCache = (config) => {
20221
- var _a;
20222
- return ((_a = config.cache) === null || _a === void 0 ? void 0 : _a.cache) || config.cache;
20223
- };
20256
+ const getCache = (config) => { var _a; return ((_a = config.cache) === null || _a === void 0 ? void 0 : _a.cache) || config.cache; };
20224
20257
  const getIdMatcher = (option) => {
20225
20258
  if (option === true) {
20226
20259
  return () => true;
@@ -20294,28 +20327,44 @@ const getTreeshake = (config, warn, strictDeprecations) => {
20294
20327
  if (configTreeshake === false) {
20295
20328
  return false;
20296
20329
  }
20297
- if (configTreeshake && configTreeshake !== true) {
20330
+ if (typeof configTreeshake === 'string') {
20331
+ const preset = treeshakePresets[configTreeshake];
20332
+ if (preset) {
20333
+ return preset;
20334
+ }
20335
+ error(errInvalidOption('treeshake', `valid values are false, true, ${printQuotedStringList(Object.keys(treeshakePresets))}. You can also supply an object for more fine-grained control`));
20336
+ }
20337
+ let configWithPreset = {};
20338
+ if (typeof configTreeshake === 'object') {
20298
20339
  if (typeof configTreeshake.pureExternalModules !== 'undefined') {
20299
20340
  warnDeprecationWithOptions(`The "treeshake.pureExternalModules" option is deprecated. The "treeshake.moduleSideEffects" option should be used instead. "treeshake.pureExternalModules: true" is equivalent to "treeshake.moduleSideEffects: 'no-external'"`, true, warn, strictDeprecations);
20300
20341
  }
20301
- return {
20302
- annotations: configTreeshake.annotations !== false,
20303
- moduleSideEffects: getHasModuleSideEffects(configTreeshake.moduleSideEffects, configTreeshake.pureExternalModules, warn),
20304
- propertyReadSideEffects: (configTreeshake.propertyReadSideEffects === 'always' && 'always') ||
20305
- configTreeshake.propertyReadSideEffects !== false,
20306
- tryCatchDeoptimization: configTreeshake.tryCatchDeoptimization !== false,
20307
- unknownGlobalSideEffects: configTreeshake.unknownGlobalSideEffects !== false
20308
- };
20342
+ configWithPreset = configTreeshake;
20343
+ const presetName = configTreeshake.preset;
20344
+ if (presetName) {
20345
+ const preset = treeshakePresets[presetName];
20346
+ if (preset) {
20347
+ configWithPreset = { ...preset, ...configTreeshake };
20348
+ }
20349
+ else {
20350
+ error(errInvalidOption('treeshake.preset', `valid values are ${printQuotedStringList(Object.keys(treeshakePresets))}`));
20351
+ }
20352
+ }
20309
20353
  }
20310
20354
  return {
20311
- annotations: true,
20312
- moduleSideEffects: () => true,
20313
- propertyReadSideEffects: true,
20314
- tryCatchDeoptimization: true,
20315
- unknownGlobalSideEffects: true
20355
+ annotations: configWithPreset.annotations !== false,
20356
+ correctVarValueBeforeDeclaration: configWithPreset.correctVarValueBeforeDeclaration === true,
20357
+ moduleSideEffects: typeof configTreeshake === 'object' && configTreeshake.pureExternalModules
20358
+ ? getHasModuleSideEffects(configTreeshake.moduleSideEffects, configTreeshake.pureExternalModules)
20359
+ : getHasModuleSideEffects(configWithPreset.moduleSideEffects, undefined),
20360
+ propertyReadSideEffects: configWithPreset.propertyReadSideEffects === 'always'
20361
+ ? 'always'
20362
+ : configWithPreset.propertyReadSideEffects !== false,
20363
+ tryCatchDeoptimization: configWithPreset.tryCatchDeoptimization !== false,
20364
+ unknownGlobalSideEffects: configWithPreset.unknownGlobalSideEffects !== false
20316
20365
  };
20317
20366
  };
20318
- const getHasModuleSideEffects = (moduleSideEffectsOption, pureExternalModules, warn) => {
20367
+ const getHasModuleSideEffects = (moduleSideEffectsOption, pureExternalModules) => {
20319
20368
  if (typeof moduleSideEffectsOption === 'boolean') {
20320
20369
  return () => moduleSideEffectsOption;
20321
20370
  }
@@ -20330,7 +20379,7 @@ const getHasModuleSideEffects = (moduleSideEffectsOption, pureExternalModules, w
20330
20379
  return id => ids.has(id);
20331
20380
  }
20332
20381
  if (moduleSideEffectsOption) {
20333
- warn(errInvalidOption('treeshake.moduleSideEffects', 'please use one of false, "no-external", a function or an array'));
20382
+ error(errInvalidOption('treeshake.moduleSideEffects', 'please use one of false, "no-external", a function or an array'));
20334
20383
  }
20335
20384
  const isPureExternalModule = getIdMatcher(pureExternalModules);
20336
20385
  return (id, external) => !(external && isPureExternalModule(id));
@@ -20388,11 +20437,11 @@ function normalizeOutputOptions(config, inputOptions, unsetInputOptions) {
20388
20437
  preferConst: config.preferConst || false,
20389
20438
  preserveModules,
20390
20439
  preserveModulesRoot: getPreserveModulesRoot(config),
20391
- sanitizeFileName: (typeof config.sanitizeFileName === 'function'
20440
+ sanitizeFileName: typeof config.sanitizeFileName === 'function'
20392
20441
  ? config.sanitizeFileName
20393
20442
  : config.sanitizeFileName === false
20394
20443
  ? id => id
20395
- : sanitizeFileName),
20444
+ : sanitizeFileName,
20396
20445
  sourcemap: config.sourcemap || false,
20397
20446
  sourcemapExcludeSources: config.sourcemapExcludeSources || false,
20398
20447
  sourcemapFile: config.sourcemapFile,
@@ -20405,7 +20454,7 @@ function normalizeOutputOptions(config, inputOptions, unsetInputOptions) {
20405
20454
  return { options: outputOptions, unsetOptions };
20406
20455
  }
20407
20456
  const getFile = (config, preserveModules, inputOptions) => {
20408
- const file = config.file;
20457
+ const { file } = config;
20409
20458
  if (typeof file === 'string') {
20410
20459
  if (preserveModules) {
20411
20460
  return error({
@@ -20448,8 +20497,7 @@ const getFormat = (config) => {
20448
20497
  };
20449
20498
  const getInlineDynamicImports = (config, inputOptions) => {
20450
20499
  var _a;
20451
- const inlineDynamicImports = ((_a = config.inlineDynamicImports) !== null && _a !== void 0 ? _a : inputOptions.inlineDynamicImports) ||
20452
- false;
20500
+ const inlineDynamicImports = ((_a = config.inlineDynamicImports) !== null && _a !== void 0 ? _a : inputOptions.inlineDynamicImports) || false;
20453
20501
  const { input } = inputOptions;
20454
20502
  if (inlineDynamicImports && (Array.isArray(input) ? input : Object.keys(input)).length > 1) {
20455
20503
  return error({
@@ -20479,7 +20527,7 @@ const getPreserveModules = (config, inlineDynamicImports, inputOptions) => {
20479
20527
  return preserveModules;
20480
20528
  };
20481
20529
  const getPreserveModulesRoot = (config) => {
20482
- const preserveModulesRoot = config.preserveModulesRoot;
20530
+ const { preserveModulesRoot } = config;
20483
20531
  if (preserveModulesRoot === null || preserveModulesRoot === undefined) {
20484
20532
  return undefined;
20485
20533
  }
@@ -20529,7 +20577,7 @@ const getAddon = (config, name) => {
20529
20577
  return () => configAddon || '';
20530
20578
  };
20531
20579
  const getDir = (config, file) => {
20532
- const dir = config.dir;
20580
+ const { dir } = config;
20533
20581
  if (typeof dir === 'string' && typeof file === 'string') {
20534
20582
  return error({
20535
20583
  code: 'INVALID_OPTION',
@@ -20621,10 +20669,7 @@ const getManualChunks = (config, inlineDynamicImports, preserveModules, inputOpt
20621
20669
  }
20622
20670
  return configManualChunks || {};
20623
20671
  };
20624
- const getMinifyInternalExports = (config, format, compact) => {
20625
- var _a;
20626
- return (_a = config.minifyInternalExports) !== null && _a !== void 0 ? _a : (compact || format === 'es' || format === 'system');
20627
- };
20672
+ const getMinifyInternalExports = (config, format, compact) => { var _a; return (_a = config.minifyInternalExports) !== null && _a !== void 0 ? _a : (compact || format === 'es' || format === 'system'); };
20628
20673
 
20629
20674
  function rollup(rawInputOptions) {
20630
20675
  return rollupInternal(rawInputOptions, null);
@@ -20847,4 +20892,4 @@ function watch(configs) {
20847
20892
  return emitter;
20848
20893
  }
20849
20894
 
20850
- export { defaultOnWarn, defineConfig, ensureArray, fseventsImporter, rollup, rollupInternal, version$1 as version, warnUnknownOptions, watch };
20895
+ export { defaultOnWarn, defineConfig, ensureArray, errInvalidOption, error, fseventsImporter, printQuotedStringList, rollup, rollupInternal, treeshakePresets, version$1 as version, warnUnknownOptions, watch };