Skip to content

Commit 066620e

Browse files
authored
Also remove export-all declarations when not tree-shaking (#3209)
1 parent 38c3171 commit 066620e

7 files changed

Lines changed: 19 additions & 1 deletion

File tree

src/ast/nodes/ExportAllDeclaration.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1+
import MagicString from 'magic-string';
2+
import { NodeRenderOptions, RenderOptions } from '../../utils/renderHelpers';
13
import Literal from './Literal';
24
import * as NodeType from './NodeType';
35
import { NodeBase } from './shared/Node';
46

57
export default class ExportAllDeclaration extends NodeBase {
8+
needsBoundaries!: true;
69
source!: Literal<string>;
710
type!: NodeType.tExportAllDeclaration;
811

@@ -13,4 +16,13 @@ export default class ExportAllDeclaration extends NodeBase {
1316
initialise() {
1417
this.context.addExport(this);
1518
}
19+
20+
render(code: MagicString, _options: RenderOptions, nodeRenderOptions?: NodeRenderOptions) {
21+
code.remove(
22+
(nodeRenderOptions as NodeRenderOptions).start as number,
23+
(nodeRenderOptions as NodeRenderOptions).end as number
24+
);
25+
}
1626
}
27+
28+
ExportAllDeclaration.prototype.needsBoundaries = true;

test/form/samples/no-treeshake/_expected/amd.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ define(['exports', 'external'], function (exports, external) { 'use strict';
4747

4848
exports.create = create;
4949
exports.getPrototypeOf = getPrototypeOf;
50+
exports.quux = quux;
5051
exports.strange = quux;
5152

5253
Object.defineProperty(exports, '__esModule', { value: true });

test/form/samples/no-treeshake/_expected/cjs.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,5 @@ test({
5151

5252
exports.create = create;
5353
exports.getPrototypeOf = getPrototypeOf;
54+
exports.quux = quux;
5455
exports.strange = quux;

test/form/samples/no-treeshake/_expected/es.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,4 @@ test({
4545
}
4646
});
4747

48-
export { create, getPrototypeOf, quux as strange };
48+
export { create, getPrototypeOf, quux, quux as strange };

test/form/samples/no-treeshake/_expected/iife.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ var stirred = (function (exports, external) {
4848

4949
exports.create = create;
5050
exports.getPrototypeOf = getPrototypeOf;
51+
exports.quux = quux;
5152
exports.strange = quux;
5253

5354
return exports;

test/form/samples/no-treeshake/_expected/umd.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151

5252
exports.create = create;
5353
exports.getPrototypeOf = getPrototypeOf;
54+
exports.quux = quux;
5455
exports.strange = quux;
5556

5657
Object.defineProperty(exports, '__esModule', { value: true });

test/form/samples/no-treeshake/main.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import * as external from 'external';
22
import foo from './foo.js';
3+
34
export { quux as strange } from './quux.js';
5+
export * from './quux.js';
46

57
function baz() {
68
return foo + external.value;

0 commit comments

Comments
 (0)