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

Only add export setter for non-esm exports #8910

Merged
merged 4 commits into from Mar 27, 2023
Merged

Conversation

mattcompiles
Copy link
Contributor

↪️ Pull Request

This PR resolves an issue where Parcel would generate code that could potentially re-assign a const export. When running this code through the SWC optimizer it would throw the following error: cannot reassign to a variable declared with const. The runtime code that allows reassignment of exports is only needed for CJS exports, however Parcel currently adds it for all exports in the case it detects any CJS usage in the file (e.g. when using mixed files with both CJS and ESM 🤢).

This PR makes the scope hoisting packager aware which exports were declared with ESM syntax and avoids adding the reassignment code for those exports.

Note: I've just added isEsm to the asset symbol metadata for now which means it's untyped and kind of hidden. Might be good to make it a first class property at some point?

💻 Examples

🚨 Test instructions

✔️ PR Todo

  • Added/updated unit tests for this change
  • Included links to related issues/PRs

@parcel-benchmark
Copy link

parcel-benchmark commented Mar 24, 2023

Benchmark Results

Kitchen Sink ✅

Timings

Description Time Difference
Cold 1.86s +58.00ms
Cached 410.00ms +21.00ms ⚠️

Cold Bundles

No bundle changes detected.

Cached Bundles

No bundle changes detected.

React HackerNews ✅

Timings

Description Time Difference
Cold 8.29s -133.00ms
Cached 522.00ms +22.00ms

Cold Bundles

Bundle Size Difference Time Difference
dist/PermalinkedComment.60e78a07.js 4.18kb +0.00b 517.00ms -68.00ms 🚀
dist/UserProfile.c18819ee.js 1.57kb +0.00b 517.00ms -68.00ms 🚀
dist/NotFound.cfeedbab.js 427.00b +0.00b 517.00ms -68.00ms 🚀
dist/logo.c5bb83f1.png 246.00b +0.00b 372.00ms -125.00ms 🚀

Cached Bundles

No bundle changes detected.

AtlasKit Editor ✅

Timings

Description Time Difference
Cold 1.22m -1.24s
Cached 2.46s -14.00ms

Cold Bundles

Bundle Size Difference Time Difference
dist/index.0976f9cb.js 3.83mb -16.00b 🚀 19.14s -32.00ms
dist/refractor.c460668c.js 601.81kb +0.00b 13.13s +2.72s ⚠️
dist/media-viewer.bd165005.js 542.15kb +0.00b 13.10s +2.69s ⚠️
dist/popup.2cbde099.js 329.78kb -7.00b 🚀 13.13s +76.00ms
dist/ConfigPanelFieldsLoader.f06a6b36.js 312.08kb +0.00b 9.48s -939.00ms 🚀
dist/card.501ecffa.js 143.52kb +0.00b 9.47s -938.00ms 🚀
dist/ConfigPanelFieldsLoader.e1ae433f.js 83.45kb +0.00b 9.48s -939.00ms 🚀
dist/ElementBrowser.3bcad544.js 65.85kb +0.00b 9.48s -939.00ms 🚀
dist/archive.503fa405.js 61.48kb -15.00b 🚀 13.13s +2.72s ⚠️
dist/esm.945b66be.js 60.94kb +0.00b 9.47s -938.00ms 🚀
dist/component-lazy.60375b05.js 60.45kb +0.00b 7.05s +627.00ms ⚠️
dist/ConfigPanelFieldsLoader.ef739802.js 16.14kb +0.00b 9.47s -940.00ms 🚀
dist/ui.2de0ef21.js 14.88kb +0.00b 9.47s -940.00ms 🚀
dist/ConfigPanelFieldsLoader.c68d84ab.js 14.25kb +0.00b 9.47s -940.00ms 🚀
dist/pdfRenderer.187ba54d.js 12.21kb +0.00b 13.10s +2.69s ⚠️
dist/mobile-upload.136dd5cb.js 8.08kb +0.00b 9.48s -938.00ms 🚀
dist/mobile-upload.0bdb676c.js 8.08kb +0.00b 9.47s -938.00ms 🚀
dist/media-viewer-analytics-error-boundary.e6109a6a.js 3.46kb +0.00b 13.13s +2.72s ⚠️
dist/ru.896915b9.js 2.94kb +0.00b 9.47s +2.35s ⚠️
dist/uk.48c97550.js 2.89kb +0.00b 9.47s -940.00ms 🚀
dist/codeViewerRenderer.915ef6b3.js 2.84kb +0.00b 13.10s +2.69s ⚠️
dist/th.31044730.js 2.73kb +0.00b 9.47s -940.00ms 🚀
dist/vi.d8dcb67a.js 2.22kb +0.00b 9.47s -939.00ms 🚀
dist/pt_BR.eccfad73.js 2.19kb +0.00b 9.11s +1.99s ⚠️
dist/tr.46f26598.js 2.16kb +0.00b 9.47s -939.00ms 🚀
dist/sv.13d93533.js 2.10kb +0.00b 9.47s -940.00ms 🚀
dist/zh_TW.afaf6222.js 1.98kb +0.00b 9.47s -939.00ms 🚀
dist/zh.fcdc32bb.js 1.96kb +0.00b 9.47s -939.00ms 🚀
dist/workerHasher.ef49a7fc.js 1.72kb +0.00b 9.48s -938.00ms 🚀
dist/workerHasher.9d5fe27b.js 1.72kb +0.00b 9.48s -936.00ms 🚀
dist/heading5.023a8f1f.js 1.36kb +0.00b 7.06s +636.00ms ⚠️
dist/sk.101f1705.js 786.00b +0.00b 9.47s +2.35s ⚠️
dist/simpleHasher.f1f58b0a.js 687.00b +0.00b 9.48s -938.00ms 🚀
dist/simpleHasher.09f4d713.js 687.00b +0.00b 9.48s -936.00ms 🚀
dist/ro.a6eff34a.js 612.00b +0.00b 9.15s +2.03s ⚠️
dist/index.html 240.00b +0.00b 13.23s +7.22s ⚠️

Cached Bundles

Bundle Size Difference Time Difference
dist/index.0976f9cb.js 3.83mb -16.00b 🚀 19.53s +232.00ms
dist/popup.2cbde099.js 329.78kb -7.00b 🚀 12.97s +130.00ms
dist/archive.503fa405.js 61.48kb -15.00b 🚀 12.97s +129.00ms

Three.js ✅

Timings

Description Time Difference
Cold 5.68s -39.00ms
Cached 314.00ms -8.00ms

Cold Bundles

No bundle changes detected.

Cached Bundles

Bundle Size Difference Time Difference
dist/Three.js 572.22kb +0.00b 1.17s -59.00ms 🚀

Click here to view a detailed benchmark overview.

@mischnic
Copy link
Member

We should add an integration test

@mattcompiles
Copy link
Contributor Author

@mischnic Integration test added 👍

@mattcompiles mattcompiles merged commit ce4a38b into v2 Mar 27, 2023
9 of 16 checks passed
@mattcompiles mattcompiles deleted the mutable-export-fix branch March 27, 2023 22:01
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

4 participants