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

Shake exports with pure property assignments #2979

Merged
merged 2 commits into from May 7, 2019
Merged

Conversation

devongovett
Copy link
Member

Fixes #2909.

For example, assigning a displayName to a function is pretty common in react code, and does not cause side effects.

mischnic
mischnic previously approved these changes May 6, 2019
@@ -85,7 +76,8 @@ function isExportAssignment(path) {
// match "path.any = any;"
path.parentPath.isMemberExpression() &&
path.parentPath.parentPath.isAssignmentExpression() &&
path.parentPath.parentPath.node.left === path.parentPath.node
path.parentPath.parentPath.node.left === path.parentPath.node &&
path.parentPath.parentPath.get('right').isPure()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should rather be called isExportAssignmentPure now?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually... I think this check is unnecessary now

@@ -122,6 +114,15 @@ function remove(path) {
} else if (isUnusedWildcard(path)) {
remove(path.parentPath);
} else if (!path.removed) {
path.remove();
if (
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code duplication isn't ideal but I don't see a cleaner way without doing some extra if checks

@devongovett devongovett merged commit 4100b9e into master May 7, 2019
@devongovett devongovett deleted the tree-shaking-fix branch May 7, 2019 04:41
twome added a commit to twome/parcel that referenced this pull request May 12, 2019
…e/strip-type-module-attr

* 'master' of github.com:parcel-bundler/parcel:
  Update deps & gitattributes (parcel-bundler#3006)
  Fix assigning to exports from inside a function in scope hoisting (parcel-bundler#2994)
  Define __esModule interop flag when requiring ES module from CommonJS (parcel-bundler#2993)
  Replace module.require in scope hoisting (parcel-bundler#2875)
  Clear scope cache before crawling (parcel-bundler#2986)
  Fix CI (parcel-bundler#2990)
  Shake exports with pure property assignments (parcel-bundler#2979)
  Update postcss.js (parcel-bundler#2922)
  Fail immediately if yarn.lock updates are needed (parcel-bundler#2945)

# Conflicts:
#	packages/core/parcel-bundler/package.json
#	yarn.lock
twome added a commit to twome/parcel that referenced this pull request Sep 10, 2019
…e/strip-type-module-attr

* 'master' of github.com:parcel-bundler/parcel:
  fix source maps on coffeescript assets (parcel-bundler#3423)
  Fixes parcel-bundler#3133 by upgrading serialize-to-js from 1.1.1 to 3.0.0  (parcel-bundler#3451)
  Fix up misleading usage information (parcel-bundler#3158)
  bump chokidar to get a reload fix for linux (parcel-bundler#2878)
  Use uppercase for the first letter of the issue template (parcel-bundler#3192)
  Update dotenv-expand to allow overriding of falsy values (parcel-bundler#2971)
  Fixes 3076: HMR update breaks in webworker due to window (and location.reload) not existing in web worker context. (parcel-bundler#3078)
  Scope hoisting destructuring (parcel-bundler#2742)
  Create FUNDING.yml (parcel-bundler#3074)
  Added new info command  (parcel-bundler#3068)
  Fix typo (parcel-bundler#3043)
  Update deps & gitattributes (parcel-bundler#3006)
  Fix assigning to exports from inside a function in scope hoisting (parcel-bundler#2994)
  Define __esModule interop flag when requiring ES module from CommonJS (parcel-bundler#2993)
  Replace module.require in scope hoisting (parcel-bundler#2875)
  Clear scope cache before crawling (parcel-bundler#2986)
  Fix CI (parcel-bundler#2990)
  Shake exports with pure property assignments (parcel-bundler#2979)
  Update postcss.js (parcel-bundler#2922)
  Fail immediately if yarn.lock updates are needed (parcel-bundler#2945)
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.

Why the production bundle size is significantly larger that create-react-app
2 participants