Skip to content

Commit

Permalink
Make treeshaking handle "multiassignments" (#2729)
Browse files Browse the repository at this point in the history
  • Loading branch information
mischnic authored and DeMoorJasper committed Mar 7, 2019
1 parent ee78fa7 commit 6ecb65c
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import x, {y} from "./b";
export default [x, y];
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
exports.default = exports.y = exports.z = undefined;
var y = 'y';
exports.y = y;
var z = 'z';
exports.z = z;

Object.defineProperty(exports, "__esModule", {
value: true
});
19 changes: 19 additions & 0 deletions packages/core/integration-tests/test/scope-hoisting.js
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,25 @@ describe('scope hoisting', function() {
assert(!/.-./.test(contents));
});

it('handle export multi-assignment', async function() {
let b = await bundle(
path.join(
__dirname,
'/integration/scope-hoisting/es6/tree-shaking-multiassignment/a.js'
),
{minify: true}
);

let output = await run(b);
assert.deepEqual(output.default, [undefined, 'y']);

// let contents = await fs.readFile(
// path.join(__dirname, '/dist/a.js'),
// 'utf8'
// );
// assert(!/["']z["']/.test(contents));
});

it('support exporting a ES6 module exported as CommonJS', async function() {
let b = await bundle(
path.join(
Expand Down
4 changes: 3 additions & 1 deletion packages/core/parcel-bundler/src/scope-hoisting/shake.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,9 @@ function remove(path) {
if (path.isAssignmentExpression()) {
if (path.parentPath.isSequenceExpression()) {
if (path.parent.expressions.length == 1) {
path.parentPath.remove();
// replace sequence expression with it's sole child
path.parentPath.replaceWith(path);
remove(path.parentPath);
} else {
path.remove();
}
Expand Down

0 comments on commit 6ecb65c

Please sign in to comment.