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

Conversation

mischnic
Copy link
Member

@mischnic mischnic commented Mar 6, 2019

↪️ Pull Request

The treeshake function tried to remove the right side of assignment if expression was of this form (when nested in a sequence expression):

var $TJPF$export$default = ($TJPF$export$THING = ($TJPF$export$SOME = undefined, $TJPF$exports.SOME = $TJPF$export$SOME), $TJPF$exports.THING = $TJPF$export$THING);

(Don't think "multiassignments" are the official name)

Bug was introduced by myself in #2418 🙈
Part of #1984

💻 Examples

from react-transition-group:

exports.default = exports.EXITING = exports.ENTERED = exports.ENTERING = exports.EXITED = exports.UNMOUNTED = void 0;

var UNMOUNTED = 'unmounted';
exports.UNMOUNTED = UNMOUNTED;
var EXITED = 'exited';
exports.EXITED = EXITED;
var ENTERING = 'entering';
exports.ENTERING = ENTERING;
var ENTERED = 'entered';
exports.ENTERED = ENTERED;
var EXITING = 'exiting';
exports.EXITING = EXITING;
🚨  Property right of AssignmentExpression expected node to be of a type ["Expression"] but instead got null
    at Object.validate (.../parcel/node_modules/@babel/types/lib/definitions/utils.js:128:13)
    at Object.validate (.../parcel/node_modules/@babel/types/lib/validators/validate.js:17:9)
    at NodePath._replaceWith (.../parcel/node_modules/@babel/traverse/lib/path/replacement.js:194:9)
    at NodePath._remove (.../parcel/node_modules/@babel/traverse/lib/path/removal.js:51:10)
    at NodePath.remove (.../parcel/node_modules/@babel/traverse/lib/path/removal.js:30:8)
    at remove (.../parcel/packages/core/parcel-bundler/src/scope-hoisting/shake.js:109:25)
    at Array.forEach (<anonymous>)
    at Object.keys.forEach.name (.../parcel/packages/core/parcel-bundler/src/scope-hoisting/shake.js:30:65)
    at Array.forEach (<anonymous>)
    at treeShake (.../parcel/packages/core/parcel-bundler/src/scope-hoisting/shake.js:20:33)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

after hoisting:

var $TJPF$export$default = ($TJPF$export$THING = ($TJPF$export$SOME = undefined, $TJPF$exports.SOME = $TJPF$export$SOME), $TJPF$exports.THING = $TJPF$export$THING);

✔️ PR Todo

  • Added/updated unit tests for this change
  • Filled out test instructions (In case there aren't any unit tests)
  • Included links to related issues/PRs

@DeMoorJasper DeMoorJasper merged commit 6ecb65c into master Mar 7, 2019
@DeMoorJasper DeMoorJasper deleted the treeshaking-multiassign branch March 7, 2019 12:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants