rollup 3.20.7 → 3.21.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.
package/dist/bin/rollup CHANGED
@@ -2,8 +2,8 @@
2
2
 
3
3
  /*
4
4
  @license
5
- Rollup.js v3.20.7
6
- Fri, 21 Apr 2023 04:31:37 GMT - commit 2820962446b40b7dfab9bdd936be1e230d8b944c
5
+ Rollup.js v3.21.0
6
+ Sun, 23 Apr 2023 19:43:51 GMT - commit b79b73cd8bb98c10ab7eedae154bb5c1e03ced7d
7
7
 
8
8
  https://github.com/rollup/rollup
9
9
 
package/dist/es/rollup.js CHANGED
@@ -1,7 +1,7 @@
1
1
  /*
2
2
  @license
3
- Rollup.js v3.20.7
4
- Fri, 21 Apr 2023 04:31:37 GMT - commit 2820962446b40b7dfab9bdd936be1e230d8b944c
3
+ Rollup.js v3.21.0
4
+ Sun, 23 Apr 2023 19:43:51 GMT - commit b79b73cd8bb98c10ab7eedae154bb5c1e03ced7d
5
5
 
6
6
  https://github.com/rollup/rollup
7
7
 
@@ -1,7 +1,7 @@
1
1
  /*
2
2
  @license
3
- Rollup.js v3.20.7
4
- Fri, 21 Apr 2023 04:31:37 GMT - commit 2820962446b40b7dfab9bdd936be1e230d8b944c
3
+ Rollup.js v3.21.0
4
+ Sun, 23 Apr 2023 19:43:51 GMT - commit b79b73cd8bb98c10ab7eedae154bb5c1e03ced7d
5
5
 
6
6
  https://github.com/rollup/rollup
7
7
 
@@ -16,7 +16,7 @@ import { lstat, realpath, readdir, readFile, mkdir, writeFile } from 'node:fs/pr
16
16
  import { EventEmitter } from 'node:events';
17
17
  import * as tty from 'tty';
18
18
 
19
- var version$1 = "3.20.7";
19
+ var version$1 = "3.21.0";
20
20
 
21
21
  const comma = ','.charCodeAt(0);
22
22
  const semicolon = ';'.charCodeAt(0);
@@ -10985,6 +10985,74 @@ function getToStringTagValue(getObject) {
10985
10985
  });
10986
10986
  }
10987
10987
 
10988
+ function isReassignedExportsMember(variable, exportNamesByVariable) {
10989
+ return (variable.renderBaseName !== null && exportNamesByVariable.has(variable) && variable.isReassigned);
10990
+ }
10991
+
10992
+ class VariableDeclarator extends NodeBase {
10993
+ declareDeclarator(kind) {
10994
+ this.id.declare(kind, this.init || UNDEFINED_EXPRESSION);
10995
+ }
10996
+ deoptimizePath(path) {
10997
+ this.id.deoptimizePath(path);
10998
+ }
10999
+ hasEffects(context) {
11000
+ if (!this.deoptimized)
11001
+ this.applyDeoptimizations();
11002
+ const initEffect = this.init?.hasEffects(context);
11003
+ this.id.markDeclarationReached();
11004
+ return initEffect || this.id.hasEffects(context);
11005
+ }
11006
+ include(context, includeChildrenRecursively) {
11007
+ const { deoptimized, id, init } = this;
11008
+ if (!deoptimized)
11009
+ this.applyDeoptimizations();
11010
+ this.included = true;
11011
+ init?.include(context, includeChildrenRecursively);
11012
+ id.markDeclarationReached();
11013
+ if (includeChildrenRecursively || id.shouldBeIncluded(context)) {
11014
+ id.include(context, includeChildrenRecursively);
11015
+ }
11016
+ }
11017
+ render(code, options) {
11018
+ const { exportNamesByVariable, snippets: { _, getPropertyAccess } } = options;
11019
+ const { end, id, init, start } = this;
11020
+ const renderId = id.included;
11021
+ if (renderId) {
11022
+ id.render(code, options);
11023
+ }
11024
+ else {
11025
+ const operatorPos = findFirstOccurrenceOutsideComment(code.original, '=', id.end);
11026
+ code.remove(start, findNonWhiteSpace(code.original, operatorPos + 1));
11027
+ }
11028
+ if (init) {
11029
+ if (id instanceof Identifier && init instanceof ClassExpression && !init.id) {
11030
+ const renderedVariable = id.variable.getName(getPropertyAccess);
11031
+ if (renderedVariable !== id.name) {
11032
+ code.appendLeft(init.start + 5, ` ${id.name}`);
11033
+ }
11034
+ }
11035
+ init.render(code, options, renderId ? BLANK : { renderedSurroundingElement: ExpressionStatement$1 });
11036
+ }
11037
+ else if (id instanceof Identifier &&
11038
+ isReassignedExportsMember(id.variable, exportNamesByVariable)) {
11039
+ code.appendLeft(end, `${_}=${_}void 0`);
11040
+ }
11041
+ }
11042
+ applyDeoptimizations() {
11043
+ this.deoptimized = true;
11044
+ const { id, init } = this;
11045
+ if (init && id instanceof Identifier && init instanceof ClassExpression && !init.id) {
11046
+ const { name, variable } = id;
11047
+ for (const accessedVariable of init.scope.accessedOutsideVariables.values()) {
11048
+ if (accessedVariable !== variable) {
11049
+ accessedVariable.forbidName(name);
11050
+ }
11051
+ }
11052
+ }
11053
+ }
11054
+ }
11055
+
10988
11056
  // TODO once ImportExpression follows official ESTree specs with "null" as
10989
11057
  // default, keys.ts should be updated
10990
11058
  class ImportExpression extends NodeBase {
@@ -11001,6 +11069,79 @@ class ImportExpression extends NodeBase {
11001
11069
  bind() {
11002
11070
  this.source.bind();
11003
11071
  }
11072
+ /**
11073
+ * Get imported variables for deterministic usage, valid cases are:
11074
+ *
11075
+ * - `const { foo } = await import('bar')`.
11076
+ * - `(await import('bar')).foo`
11077
+ * - `import('bar').then(({ foo }) => {})`
11078
+ *
11079
+ * Returns empty array if it's side-effect only import.
11080
+ * Returns undefined if it's not fully deterministic.
11081
+ */
11082
+ getDeterministicImportedNames() {
11083
+ const parent1 = this.parent;
11084
+ // Side-effect only: import('bar')
11085
+ if (parent1 instanceof ExpressionStatement) {
11086
+ return EMPTY_ARRAY;
11087
+ }
11088
+ if (parent1 instanceof AwaitExpression) {
11089
+ const parent2 = parent1.parent;
11090
+ // Side-effect only: await import('bar')
11091
+ if (parent2 instanceof ExpressionStatement) {
11092
+ return EMPTY_ARRAY;
11093
+ }
11094
+ // Case 1: const { foo } = await import('bar')
11095
+ if (parent2 instanceof VariableDeclarator) {
11096
+ const declaration = parent2.id;
11097
+ return declaration instanceof ObjectPattern
11098
+ ? getDeterministicObjectDestructure(declaration)
11099
+ : undefined;
11100
+ }
11101
+ // Case 2: (await import('bar')).foo
11102
+ if (parent2 instanceof MemberExpression) {
11103
+ const id = parent2.property;
11104
+ if (!parent2.computed && id instanceof Identifier) {
11105
+ return [id.name];
11106
+ }
11107
+ }
11108
+ return;
11109
+ }
11110
+ // Case 3: import('bar').then(({ foo }) => {})
11111
+ if (parent1 instanceof MemberExpression) {
11112
+ const callExpression = parent1.parent;
11113
+ const property = parent1.property;
11114
+ if (!(callExpression instanceof CallExpression) || !(property instanceof Identifier)) {
11115
+ return;
11116
+ }
11117
+ const memberName = property.name;
11118
+ // side-effect only, when only chaining .catch or .finally
11119
+ if (callExpression.parent instanceof ExpressionStatement &&
11120
+ ['catch', 'finally'].includes(memberName)) {
11121
+ return EMPTY_ARRAY;
11122
+ }
11123
+ if (memberName !== 'then')
11124
+ return;
11125
+ // Side-effect only: import('bar').then()
11126
+ if (callExpression.arguments.length === 0) {
11127
+ return EMPTY_ARRAY;
11128
+ }
11129
+ const argument = callExpression.arguments[0];
11130
+ if (callExpression.arguments.length !== 1 ||
11131
+ !(argument instanceof ArrowFunctionExpression || argument instanceof FunctionExpression)) {
11132
+ return;
11133
+ }
11134
+ // Side-effect only: import('bar').then(() => {})
11135
+ if (argument.params.length === 0) {
11136
+ return EMPTY_ARRAY;
11137
+ }
11138
+ const declaration = argument.params[0];
11139
+ if (argument.params.length === 1 && declaration instanceof ObjectPattern) {
11140
+ return getDeterministicObjectDestructure(declaration);
11141
+ }
11142
+ return;
11143
+ }
11144
+ }
11004
11145
  hasEffects() {
11005
11146
  return true;
11006
11147
  }
@@ -11192,6 +11333,15 @@ const accessedImportGlobals = {
11192
11333
  cjs: ['require'],
11193
11334
  system: ['module']
11194
11335
  };
11336
+ function getDeterministicObjectDestructure(objectPattern) {
11337
+ const variables = [];
11338
+ for (const property of objectPattern.properties) {
11339
+ if (property.type === 'RestElement' || property.computed || property.key.type !== 'Identifier')
11340
+ return;
11341
+ variables.push(property.key.name);
11342
+ }
11343
+ return variables;
11344
+ }
11195
11345
 
11196
11346
  class ImportNamespaceSpecifier extends NodeBase {
11197
11347
  applyDeoptimizations() { }
@@ -12436,10 +12586,6 @@ class UpdateExpression extends NodeBase {
12436
12586
  }
12437
12587
  }
12438
12588
 
12439
- function isReassignedExportsMember(variable, exportNamesByVariable) {
12440
- return (variable.renderBaseName !== null && exportNamesByVariable.has(variable) && variable.isReassigned);
12441
- }
12442
-
12443
12589
  function areAllDeclarationsIncludedAndNotExported(declarations, exportNamesByVariable) {
12444
12590
  for (const declarator of declarations) {
12445
12591
  if (!declarator.id.included)
@@ -12616,70 +12762,6 @@ function gatherSystemExportsAndGetSingleExport(separatedNodes, options, aggregat
12616
12762
  return singleSystemExport;
12617
12763
  }
12618
12764
 
12619
- class VariableDeclarator extends NodeBase {
12620
- declareDeclarator(kind) {
12621
- this.id.declare(kind, this.init || UNDEFINED_EXPRESSION);
12622
- }
12623
- deoptimizePath(path) {
12624
- this.id.deoptimizePath(path);
12625
- }
12626
- hasEffects(context) {
12627
- if (!this.deoptimized)
12628
- this.applyDeoptimizations();
12629
- const initEffect = this.init?.hasEffects(context);
12630
- this.id.markDeclarationReached();
12631
- return initEffect || this.id.hasEffects(context);
12632
- }
12633
- include(context, includeChildrenRecursively) {
12634
- const { deoptimized, id, init } = this;
12635
- if (!deoptimized)
12636
- this.applyDeoptimizations();
12637
- this.included = true;
12638
- init?.include(context, includeChildrenRecursively);
12639
- id.markDeclarationReached();
12640
- if (includeChildrenRecursively || id.shouldBeIncluded(context)) {
12641
- id.include(context, includeChildrenRecursively);
12642
- }
12643
- }
12644
- render(code, options) {
12645
- const { exportNamesByVariable, snippets: { _, getPropertyAccess } } = options;
12646
- const { end, id, init, start } = this;
12647
- const renderId = id.included;
12648
- if (renderId) {
12649
- id.render(code, options);
12650
- }
12651
- else {
12652
- const operatorPos = findFirstOccurrenceOutsideComment(code.original, '=', id.end);
12653
- code.remove(start, findNonWhiteSpace(code.original, operatorPos + 1));
12654
- }
12655
- if (init) {
12656
- if (id instanceof Identifier && init instanceof ClassExpression && !init.id) {
12657
- const renderedVariable = id.variable.getName(getPropertyAccess);
12658
- if (renderedVariable !== id.name) {
12659
- code.appendLeft(init.start + 5, ` ${id.name}`);
12660
- }
12661
- }
12662
- init.render(code, options, renderId ? BLANK : { renderedSurroundingElement: ExpressionStatement$1 });
12663
- }
12664
- else if (id instanceof Identifier &&
12665
- isReassignedExportsMember(id.variable, exportNamesByVariable)) {
12666
- code.appendLeft(end, `${_}=${_}void 0`);
12667
- }
12668
- }
12669
- applyDeoptimizations() {
12670
- this.deoptimized = true;
12671
- const { id, init } = this;
12672
- if (init && id instanceof Identifier && init instanceof ClassExpression && !init.id) {
12673
- const { name, variable } = id;
12674
- for (const accessedVariable of init.scope.accessedOutsideVariables.values()) {
12675
- if (accessedVariable !== variable) {
12676
- accessedVariable.forbidName(name);
12677
- }
12678
- }
12679
- }
12680
- }
12681
- }
12682
-
12683
12765
  class WhileStatement extends NodeBase {
12684
12766
  hasEffects(context) {
12685
12767
  if (this.test.hasEffects(context))
@@ -12880,7 +12962,9 @@ class NamespaceVariable extends Variable {
12880
12962
  renderBlock(options) {
12881
12963
  const { exportNamesByVariable, format, freeze, indent: t, namespaceToStringTag, snippets: { _, cnst, getObject, getPropertyAccess, n, s } } = options;
12882
12964
  const memberVariables = this.getMemberVariables();
12883
- const members = Object.entries(memberVariables).map(([name, original]) => {
12965
+ const members = Object.entries(memberVariables)
12966
+ .filter(([_, variable]) => variable.included)
12967
+ .map(([name, original]) => {
12884
12968
  if (this.referencedEarly || original.isReassigned) {
12885
12969
  return [
12886
12970
  null,
@@ -13582,6 +13666,28 @@ class Module {
13582
13666
  this.ast.include(createInclusionContext(), true);
13583
13667
  this.includeAllExports(false);
13584
13668
  }
13669
+ includeExportsByNames(names) {
13670
+ if (!this.isExecuted) {
13671
+ markModuleAndImpureDependenciesAsExecuted(this);
13672
+ this.graph.needsTreeshakingPass = true;
13673
+ }
13674
+ let includeNamespaceMembers = false;
13675
+ for (const name of names) {
13676
+ const variable = this.getVariableForExportName(name)[0];
13677
+ if (variable) {
13678
+ variable.deoptimizePath(UNKNOWN_PATH);
13679
+ if (!variable.included) {
13680
+ this.includeVariable(variable);
13681
+ }
13682
+ }
13683
+ if (!this.exports.has(name) && !this.reexportDescriptions.has(name)) {
13684
+ includeNamespaceMembers = true;
13685
+ }
13686
+ }
13687
+ if (includeNamespaceMembers) {
13688
+ this.namespace.setMergedNamespaces(this.includeAndGetAdditionalMergedNamespaces());
13689
+ }
13690
+ }
13585
13691
  isIncluded() {
13586
13692
  // Modules where this.ast is missing have been loaded via this.load and are
13587
13693
  // not yet fully processed, hence they cannot be included.
@@ -13974,7 +14080,15 @@ class Module {
13974
14080
  const resolution = this.dynamicImports.find(dynamicImport => dynamicImport.node === node).resolution;
13975
14081
  if (resolution instanceof Module) {
13976
14082
  resolution.includedDynamicImporters.push(this);
13977
- resolution.includeAllExports(true);
14083
+ const importedNames = this.options.treeshake
14084
+ ? node.getDeterministicImportedNames()
14085
+ : undefined;
14086
+ if (importedNames) {
14087
+ resolution.includeExportsByNames(importedNames);
14088
+ }
14089
+ else {
14090
+ resolution.includeAllExports(true);
14091
+ }
13978
14092
  }
13979
14093
  }
13980
14094
  includeVariable(variable) {
@@ -1,7 +1,7 @@
1
1
  /*
2
2
  @license
3
- Rollup.js v3.20.7
4
- Fri, 21 Apr 2023 04:31:37 GMT - commit 2820962446b40b7dfab9bdd936be1e230d8b944c
3
+ Rollup.js v3.21.0
4
+ Sun, 23 Apr 2023 19:43:51 GMT - commit b79b73cd8bb98c10ab7eedae154bb5c1e03ced7d
5
5
 
6
6
  https://github.com/rollup/rollup
7
7
 
@@ -1,7 +1,7 @@
1
1
  /*
2
2
  @license
3
- Rollup.js v3.20.7
4
- Fri, 21 Apr 2023 04:31:37 GMT - commit 2820962446b40b7dfab9bdd936be1e230d8b944c
3
+ Rollup.js v3.21.0
4
+ Sun, 23 Apr 2023 19:43:51 GMT - commit b79b73cd8bb98c10ab7eedae154bb5c1e03ced7d
5
5
 
6
6
  https://github.com/rollup/rollup
7
7
 
package/dist/rollup.js CHANGED
@@ -1,7 +1,7 @@
1
1
  /*
2
2
  @license
3
- Rollup.js v3.20.7
4
- Fri, 21 Apr 2023 04:31:37 GMT - commit 2820962446b40b7dfab9bdd936be1e230d8b944c
3
+ Rollup.js v3.21.0
4
+ Sun, 23 Apr 2023 19:43:51 GMT - commit b79b73cd8bb98c10ab7eedae154bb5c1e03ced7d
5
5
 
6
6
  https://github.com/rollup/rollup
7
7
 
@@ -1,7 +1,7 @@
1
1
  /*
2
2
  @license
3
- Rollup.js v3.20.7
4
- Fri, 21 Apr 2023 04:31:37 GMT - commit 2820962446b40b7dfab9bdd936be1e230d8b944c
3
+ Rollup.js v3.21.0
4
+ Sun, 23 Apr 2023 19:43:51 GMT - commit b79b73cd8bb98c10ab7eedae154bb5c1e03ced7d
5
5
 
6
6
  https://github.com/rollup/rollup
7
7
 
@@ -1,7 +1,7 @@
1
1
  /*
2
2
  @license
3
- Rollup.js v3.20.7
4
- Fri, 21 Apr 2023 04:31:37 GMT - commit 2820962446b40b7dfab9bdd936be1e230d8b944c
3
+ Rollup.js v3.21.0
4
+ Sun, 23 Apr 2023 19:43:51 GMT - commit b79b73cd8bb98c10ab7eedae154bb5c1e03ced7d
5
5
 
6
6
  https://github.com/rollup/rollup
7
7
 
@@ -1,7 +1,7 @@
1
1
  /*
2
2
  @license
3
- Rollup.js v3.20.7
4
- Fri, 21 Apr 2023 04:31:37 GMT - commit 2820962446b40b7dfab9bdd936be1e230d8b944c
3
+ Rollup.js v3.21.0
4
+ Sun, 23 Apr 2023 19:43:51 GMT - commit b79b73cd8bb98c10ab7eedae154bb5c1e03ced7d
5
5
 
6
6
  https://github.com/rollup/rollup
7
7
 
@@ -1,7 +1,7 @@
1
1
  /*
2
2
  @license
3
- Rollup.js v3.20.7
4
- Fri, 21 Apr 2023 04:31:37 GMT - commit 2820962446b40b7dfab9bdd936be1e230d8b944c
3
+ Rollup.js v3.21.0
4
+ Sun, 23 Apr 2023 19:43:51 GMT - commit b79b73cd8bb98c10ab7eedae154bb5c1e03ced7d
5
5
 
6
6
  https://github.com/rollup/rollup
7
7
 
@@ -31,7 +31,7 @@ function _interopNamespaceDefault(e) {
31
31
 
32
32
  const tty__namespace = /*#__PURE__*/_interopNamespaceDefault(tty);
33
33
 
34
- var version$1 = "3.20.7";
34
+ var version$1 = "3.21.0";
35
35
 
36
36
  function ensureArray$1(items) {
37
37
  if (Array.isArray(items)) {
@@ -11483,6 +11483,74 @@ function getToStringTagValue(getObject) {
11483
11483
  });
11484
11484
  }
11485
11485
 
11486
+ function isReassignedExportsMember(variable, exportNamesByVariable) {
11487
+ return (variable.renderBaseName !== null && exportNamesByVariable.has(variable) && variable.isReassigned);
11488
+ }
11489
+
11490
+ class VariableDeclarator extends NodeBase {
11491
+ declareDeclarator(kind) {
11492
+ this.id.declare(kind, this.init || UNDEFINED_EXPRESSION);
11493
+ }
11494
+ deoptimizePath(path) {
11495
+ this.id.deoptimizePath(path);
11496
+ }
11497
+ hasEffects(context) {
11498
+ if (!this.deoptimized)
11499
+ this.applyDeoptimizations();
11500
+ const initEffect = this.init?.hasEffects(context);
11501
+ this.id.markDeclarationReached();
11502
+ return initEffect || this.id.hasEffects(context);
11503
+ }
11504
+ include(context, includeChildrenRecursively) {
11505
+ const { deoptimized, id, init } = this;
11506
+ if (!deoptimized)
11507
+ this.applyDeoptimizations();
11508
+ this.included = true;
11509
+ init?.include(context, includeChildrenRecursively);
11510
+ id.markDeclarationReached();
11511
+ if (includeChildrenRecursively || id.shouldBeIncluded(context)) {
11512
+ id.include(context, includeChildrenRecursively);
11513
+ }
11514
+ }
11515
+ render(code, options) {
11516
+ const { exportNamesByVariable, snippets: { _, getPropertyAccess } } = options;
11517
+ const { end, id, init, start } = this;
11518
+ const renderId = id.included;
11519
+ if (renderId) {
11520
+ id.render(code, options);
11521
+ }
11522
+ else {
11523
+ const operatorPos = findFirstOccurrenceOutsideComment(code.original, '=', id.end);
11524
+ code.remove(start, findNonWhiteSpace(code.original, operatorPos + 1));
11525
+ }
11526
+ if (init) {
11527
+ if (id instanceof Identifier && init instanceof ClassExpression && !init.id) {
11528
+ const renderedVariable = id.variable.getName(getPropertyAccess);
11529
+ if (renderedVariable !== id.name) {
11530
+ code.appendLeft(init.start + 5, ` ${id.name}`);
11531
+ }
11532
+ }
11533
+ init.render(code, options, renderId ? BLANK : { renderedSurroundingElement: ExpressionStatement$1 });
11534
+ }
11535
+ else if (id instanceof Identifier &&
11536
+ isReassignedExportsMember(id.variable, exportNamesByVariable)) {
11537
+ code.appendLeft(end, `${_}=${_}void 0`);
11538
+ }
11539
+ }
11540
+ applyDeoptimizations() {
11541
+ this.deoptimized = true;
11542
+ const { id, init } = this;
11543
+ if (init && id instanceof Identifier && init instanceof ClassExpression && !init.id) {
11544
+ const { name, variable } = id;
11545
+ for (const accessedVariable of init.scope.accessedOutsideVariables.values()) {
11546
+ if (accessedVariable !== variable) {
11547
+ accessedVariable.forbidName(name);
11548
+ }
11549
+ }
11550
+ }
11551
+ }
11552
+ }
11553
+
11486
11554
  // TODO once ImportExpression follows official ESTree specs with "null" as
11487
11555
  // default, keys.ts should be updated
11488
11556
  class ImportExpression extends NodeBase {
@@ -11499,6 +11567,79 @@ class ImportExpression extends NodeBase {
11499
11567
  bind() {
11500
11568
  this.source.bind();
11501
11569
  }
11570
+ /**
11571
+ * Get imported variables for deterministic usage, valid cases are:
11572
+ *
11573
+ * - `const { foo } = await import('bar')`.
11574
+ * - `(await import('bar')).foo`
11575
+ * - `import('bar').then(({ foo }) => {})`
11576
+ *
11577
+ * Returns empty array if it's side-effect only import.
11578
+ * Returns undefined if it's not fully deterministic.
11579
+ */
11580
+ getDeterministicImportedNames() {
11581
+ const parent1 = this.parent;
11582
+ // Side-effect only: import('bar')
11583
+ if (parent1 instanceof ExpressionStatement) {
11584
+ return EMPTY_ARRAY;
11585
+ }
11586
+ if (parent1 instanceof AwaitExpression) {
11587
+ const parent2 = parent1.parent;
11588
+ // Side-effect only: await import('bar')
11589
+ if (parent2 instanceof ExpressionStatement) {
11590
+ return EMPTY_ARRAY;
11591
+ }
11592
+ // Case 1: const { foo } = await import('bar')
11593
+ if (parent2 instanceof VariableDeclarator) {
11594
+ const declaration = parent2.id;
11595
+ return declaration instanceof ObjectPattern
11596
+ ? getDeterministicObjectDestructure(declaration)
11597
+ : undefined;
11598
+ }
11599
+ // Case 2: (await import('bar')).foo
11600
+ if (parent2 instanceof MemberExpression) {
11601
+ const id = parent2.property;
11602
+ if (!parent2.computed && id instanceof Identifier) {
11603
+ return [id.name];
11604
+ }
11605
+ }
11606
+ return;
11607
+ }
11608
+ // Case 3: import('bar').then(({ foo }) => {})
11609
+ if (parent1 instanceof MemberExpression) {
11610
+ const callExpression = parent1.parent;
11611
+ const property = parent1.property;
11612
+ if (!(callExpression instanceof CallExpression) || !(property instanceof Identifier)) {
11613
+ return;
11614
+ }
11615
+ const memberName = property.name;
11616
+ // side-effect only, when only chaining .catch or .finally
11617
+ if (callExpression.parent instanceof ExpressionStatement &&
11618
+ ['catch', 'finally'].includes(memberName)) {
11619
+ return EMPTY_ARRAY;
11620
+ }
11621
+ if (memberName !== 'then')
11622
+ return;
11623
+ // Side-effect only: import('bar').then()
11624
+ if (callExpression.arguments.length === 0) {
11625
+ return EMPTY_ARRAY;
11626
+ }
11627
+ const argument = callExpression.arguments[0];
11628
+ if (callExpression.arguments.length !== 1 ||
11629
+ !(argument instanceof ArrowFunctionExpression || argument instanceof FunctionExpression)) {
11630
+ return;
11631
+ }
11632
+ // Side-effect only: import('bar').then(() => {})
11633
+ if (argument.params.length === 0) {
11634
+ return EMPTY_ARRAY;
11635
+ }
11636
+ const declaration = argument.params[0];
11637
+ if (argument.params.length === 1 && declaration instanceof ObjectPattern) {
11638
+ return getDeterministicObjectDestructure(declaration);
11639
+ }
11640
+ return;
11641
+ }
11642
+ }
11502
11643
  hasEffects() {
11503
11644
  return true;
11504
11645
  }
@@ -11690,6 +11831,15 @@ const accessedImportGlobals = {
11690
11831
  cjs: ['require'],
11691
11832
  system: ['module']
11692
11833
  };
11834
+ function getDeterministicObjectDestructure(objectPattern) {
11835
+ const variables = [];
11836
+ for (const property of objectPattern.properties) {
11837
+ if (property.type === 'RestElement' || property.computed || property.key.type !== 'Identifier')
11838
+ return;
11839
+ variables.push(property.key.name);
11840
+ }
11841
+ return variables;
11842
+ }
11693
11843
 
11694
11844
  class ImportNamespaceSpecifier extends NodeBase {
11695
11845
  applyDeoptimizations() { }
@@ -12934,10 +13084,6 @@ class UpdateExpression extends NodeBase {
12934
13084
  }
12935
13085
  }
12936
13086
 
12937
- function isReassignedExportsMember(variable, exportNamesByVariable) {
12938
- return (variable.renderBaseName !== null && exportNamesByVariable.has(variable) && variable.isReassigned);
12939
- }
12940
-
12941
13087
  function areAllDeclarationsIncludedAndNotExported(declarations, exportNamesByVariable) {
12942
13088
  for (const declarator of declarations) {
12943
13089
  if (!declarator.id.included)
@@ -13114,70 +13260,6 @@ function gatherSystemExportsAndGetSingleExport(separatedNodes, options, aggregat
13114
13260
  return singleSystemExport;
13115
13261
  }
13116
13262
 
13117
- class VariableDeclarator extends NodeBase {
13118
- declareDeclarator(kind) {
13119
- this.id.declare(kind, this.init || UNDEFINED_EXPRESSION);
13120
- }
13121
- deoptimizePath(path) {
13122
- this.id.deoptimizePath(path);
13123
- }
13124
- hasEffects(context) {
13125
- if (!this.deoptimized)
13126
- this.applyDeoptimizations();
13127
- const initEffect = this.init?.hasEffects(context);
13128
- this.id.markDeclarationReached();
13129
- return initEffect || this.id.hasEffects(context);
13130
- }
13131
- include(context, includeChildrenRecursively) {
13132
- const { deoptimized, id, init } = this;
13133
- if (!deoptimized)
13134
- this.applyDeoptimizations();
13135
- this.included = true;
13136
- init?.include(context, includeChildrenRecursively);
13137
- id.markDeclarationReached();
13138
- if (includeChildrenRecursively || id.shouldBeIncluded(context)) {
13139
- id.include(context, includeChildrenRecursively);
13140
- }
13141
- }
13142
- render(code, options) {
13143
- const { exportNamesByVariable, snippets: { _, getPropertyAccess } } = options;
13144
- const { end, id, init, start } = this;
13145
- const renderId = id.included;
13146
- if (renderId) {
13147
- id.render(code, options);
13148
- }
13149
- else {
13150
- const operatorPos = findFirstOccurrenceOutsideComment(code.original, '=', id.end);
13151
- code.remove(start, findNonWhiteSpace(code.original, operatorPos + 1));
13152
- }
13153
- if (init) {
13154
- if (id instanceof Identifier && init instanceof ClassExpression && !init.id) {
13155
- const renderedVariable = id.variable.getName(getPropertyAccess);
13156
- if (renderedVariable !== id.name) {
13157
- code.appendLeft(init.start + 5, ` ${id.name}`);
13158
- }
13159
- }
13160
- init.render(code, options, renderId ? BLANK : { renderedSurroundingElement: ExpressionStatement$1 });
13161
- }
13162
- else if (id instanceof Identifier &&
13163
- isReassignedExportsMember(id.variable, exportNamesByVariable)) {
13164
- code.appendLeft(end, `${_}=${_}void 0`);
13165
- }
13166
- }
13167
- applyDeoptimizations() {
13168
- this.deoptimized = true;
13169
- const { id, init } = this;
13170
- if (init && id instanceof Identifier && init instanceof ClassExpression && !init.id) {
13171
- const { name, variable } = id;
13172
- for (const accessedVariable of init.scope.accessedOutsideVariables.values()) {
13173
- if (accessedVariable !== variable) {
13174
- accessedVariable.forbidName(name);
13175
- }
13176
- }
13177
- }
13178
- }
13179
- }
13180
-
13181
13263
  class WhileStatement extends NodeBase {
13182
13264
  hasEffects(context) {
13183
13265
  if (this.test.hasEffects(context))
@@ -13378,7 +13460,9 @@ class NamespaceVariable extends Variable {
13378
13460
  renderBlock(options) {
13379
13461
  const { exportNamesByVariable, format, freeze, indent: t, namespaceToStringTag, snippets: { _, cnst, getObject, getPropertyAccess, n, s } } = options;
13380
13462
  const memberVariables = this.getMemberVariables();
13381
- const members = Object.entries(memberVariables).map(([name, original]) => {
13463
+ const members = Object.entries(memberVariables)
13464
+ .filter(([_, variable]) => variable.included)
13465
+ .map(([name, original]) => {
13382
13466
  if (this.referencedEarly || original.isReassigned) {
13383
13467
  return [
13384
13468
  null,
@@ -14080,6 +14164,28 @@ class Module {
14080
14164
  this.ast.include(createInclusionContext(), true);
14081
14165
  this.includeAllExports(false);
14082
14166
  }
14167
+ includeExportsByNames(names) {
14168
+ if (!this.isExecuted) {
14169
+ markModuleAndImpureDependenciesAsExecuted(this);
14170
+ this.graph.needsTreeshakingPass = true;
14171
+ }
14172
+ let includeNamespaceMembers = false;
14173
+ for (const name of names) {
14174
+ const variable = this.getVariableForExportName(name)[0];
14175
+ if (variable) {
14176
+ variable.deoptimizePath(UNKNOWN_PATH);
14177
+ if (!variable.included) {
14178
+ this.includeVariable(variable);
14179
+ }
14180
+ }
14181
+ if (!this.exports.has(name) && !this.reexportDescriptions.has(name)) {
14182
+ includeNamespaceMembers = true;
14183
+ }
14184
+ }
14185
+ if (includeNamespaceMembers) {
14186
+ this.namespace.setMergedNamespaces(this.includeAndGetAdditionalMergedNamespaces());
14187
+ }
14188
+ }
14083
14189
  isIncluded() {
14084
14190
  // Modules where this.ast is missing have been loaded via this.load and are
14085
14191
  // not yet fully processed, hence they cannot be included.
@@ -14472,7 +14578,15 @@ class Module {
14472
14578
  const resolution = this.dynamicImports.find(dynamicImport => dynamicImport.node === node).resolution;
14473
14579
  if (resolution instanceof Module) {
14474
14580
  resolution.includedDynamicImporters.push(this);
14475
- resolution.includeAllExports(true);
14581
+ const importedNames = this.options.treeshake
14582
+ ? node.getDeterministicImportedNames()
14583
+ : undefined;
14584
+ if (importedNames) {
14585
+ resolution.includeExportsByNames(importedNames);
14586
+ }
14587
+ else {
14588
+ resolution.includeAllExports(true);
14589
+ }
14476
14590
  }
14477
14591
  }
14478
14592
  includeVariable(variable) {
@@ -1,7 +1,7 @@
1
1
  /*
2
2
  @license
3
- Rollup.js v3.20.7
4
- Fri, 21 Apr 2023 04:31:37 GMT - commit 2820962446b40b7dfab9bdd936be1e230d8b944c
3
+ Rollup.js v3.21.0
4
+ Sun, 23 Apr 2023 19:43:51 GMT - commit b79b73cd8bb98c10ab7eedae154bb5c1e03ced7d
5
5
 
6
6
  https://github.com/rollup/rollup
7
7
 
@@ -1,7 +1,7 @@
1
1
  /*
2
2
  @license
3
- Rollup.js v3.20.7
4
- Fri, 21 Apr 2023 04:31:37 GMT - commit 2820962446b40b7dfab9bdd936be1e230d8b944c
3
+ Rollup.js v3.21.0
4
+ Sun, 23 Apr 2023 19:43:51 GMT - commit b79b73cd8bb98c10ab7eedae154bb5c1e03ced7d
5
5
 
6
6
  https://github.com/rollup/rollup
7
7
 
@@ -1,7 +1,7 @@
1
1
  /*
2
2
  @license
3
- Rollup.js v3.20.7
4
- Fri, 21 Apr 2023 04:31:37 GMT - commit 2820962446b40b7dfab9bdd936be1e230d8b944c
3
+ Rollup.js v3.21.0
4
+ Sun, 23 Apr 2023 19:43:51 GMT - commit b79b73cd8bb98c10ab7eedae154bb5c1e03ced7d
5
5
 
6
6
  https://github.com/rollup/rollup
7
7
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rollup",
3
- "version": "3.20.7",
3
+ "version": "3.21.0",
4
4
  "description": "Next-generation ES module bundler",
5
5
  "main": "dist/rollup.js",
6
6
  "module": "dist/es/rollup.js",