Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make treeshaking handle "multiassignments" #2729

Merged
merged 2 commits into from Mar 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -0,0 +1,2 @@
import x, {y} from "./b";
export default [x, y];
@@ -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
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
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