-
Notifications
You must be signed in to change notification settings - Fork 637
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
feat: skip extraneously duplicating AST during transformation #854
Conversation
Digging into the failures. Looks like the Looks like simply running ast through Upgrading fixes the issue: - "@babel/traverse": "^7.14.0",
+ "@babel/traverse": "^7.14.9", |
@motiz88 has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
Quick update - we hoped to get this in for last week's release but that wasn't possible. Updating Babel internally is causing a bit of a cascade headache.
There's probably a combination of versions that works with a bit of lockfile hacking, but I'd rather fix the issues and make a clean upgrade to latest (7.20). Working on it.. |
@robhogan any update on this? |
We've just come out of a holiday infra code freeze, landing those Babel updates now. |
…ges) Summary: Update `babel/generator` to the latest, which is a semver-minor update within the pre-existing range. I'm separating this out for ease of review because it brings some noisy snapshot changes, including more granular source maps and fewer empty lines in generated output. The majority of this is a result of babel/babel#14980 (`>=7.19.4`). This and the previous diff clear the way for a general Babel update, which is currently blocking a perf-boosting Metro PR #854. Changelog: [Internal] Bump `babel/generator dependency` to `^7.20.0` Reviewed By: motiz88 Differential Revision: D41438635 fbshipit-source-id: d56853169be22a2197ad53d6320ec6c1faf6b2a7
…ges) Summary: Update `babel/generator` to the latest, which is a semver-minor update within the pre-existing range. I'm separating this out for ease of review because it brings some noisy snapshot changes, including more granular source maps and fewer empty lines in generated output. The majority of this is a result of babel/babel#14980 (`>=7.19.4`). This and the previous diff clear the way for a general Babel update, which is currently blocking a perf-boosting Metro PR facebook/metro#854. Changelog: [Internal] Bump `babel/generator dependency` to `^7.20.0` Reviewed By: motiz88 Differential Revision: D41438635 fbshipit-source-id: d56853169be22a2197ad53d6320ec6c1faf6b2a7
The Babel ^7.20 updates have landed, but this PR is now showing failures on public CI - I'm AFK but looks like the same Babel bug that necessitated the patch update is back in the latest version. Will try to have a look next week but just FYI in case you get chance in the meantime. Related (?): |
Follow-up: Looks like the problem is not that the AST is mutated, but that I can't find where this was ever fixed - I suspect it might not have been, but "updating" resulted in multiple This looks like exactly the problem described by @loganfsmyth in the (still open) issue above. A few options come to mind:
|
Ah, Babel path caching hell, my old nemesis. Thanks for taking a look @robhogan! This is also a prime example of why replacing the transformer with something like SWC would be helpful from a correctness standpoint as well as (likely) performance. |
@robhogan has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
I've gone with option 3 - the If there are no objections (@motiz88, @EvanBacon) I'll merge this in time for tomorrow's scheduled Metro release. Edit: This broke |
@robhogan has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
For visibility, I think #906 (option 2, effectively) is now the least-worst prerequisite. (Clearing the node was no good either, because it wipes metadata that may be needed upstream - in particular it broke a bunch of our Jest tests because we use this transformer in Jest setup, and Jest relies on path properties.) |
….0 (#264) [![Mend Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com) This PR contains the following updates: | Package | Change | Age | Adoption | Passing | Confidence | |---|---|---|---|---|---| | [metro-react-native-babel-preset](https://togithub.com/facebook/metro) | [`^0.72.0` -> `^0.76.0`](https://renovatebot.com/diffs/npm/metro-react-native-babel-preset/0.72.3/0.76.0) | [![age](https://badges.renovateapi.com/packages/npm/metro-react-native-babel-preset/0.76.0/age-slim)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://badges.renovateapi.com/packages/npm/metro-react-native-babel-preset/0.76.0/adoption-slim)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://badges.renovateapi.com/packages/npm/metro-react-native-babel-preset/0.76.0/compatibility-slim/0.72.3)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://badges.renovateapi.com/packages/npm/metro-react-native-babel-preset/0.76.0/confidence-slim/0.72.3)](https://docs.renovatebot.com/merge-confidence/) | --- ### Release Notes <details> <summary>facebook/metro</summary> ### [`v0.76.0`](https://togithub.com/facebook/metro/releases/tag/v0.76.0) [Compare Source](https://togithub.com/facebook/metro/compare/v0.75.1...v0.76.0) - **\[Breaking]**: Increase minimum Node version from 14 to 16. (facebook/metro@e5950ae by [@​huntie](https://togithub.com/huntie)) - **\[Breaking]**: Remove `isAssetFile` from custom resolver context, add `assetExts`. (facebook/metro@c6548f7 by [@​huntie](https://togithub.com/huntie)) - **\[Feature]**: Support [`require.resolveWeak()`](https://facebook.github.io/metro/docs/module-api#requireresolveweak). (facebook/metro@354d6e4 by [@​motiz88](https://togithub.com/motiz88)) - **\[Fix]**: Don't over-invalidate on symlink changes if resolution through symlinks is not enabled. (facebook/metro@2303c10 by [@​robhogan](https://togithub.com/robhogan)) - **\[Fix]**: Returning `false` from [`context.redirectModulePath`](https://facebook.github.io/metro/docs/resolution#redirectmodulepath-string--string--false) will resolve to empty module in all cases. (facebook/metro@0f1846a by [@​huntie](https://togithub.com/huntie)) - **\[Fix]**: Respect extensionless entries in `browser`, `react-native` etc when resolving subpath package specifiers. (facebook/metro@7e92227 by [@​huntie](https://togithub.com/huntie)) - **\[Fix]**: Remove undocumented Meta-only `__jsResource` and `__conditionallySplitJsResource` functions from module API. (facebook/metro@f1d905b and facebook/metro@69c8fc7 by [@​motiz88](https://togithub.com/motiz88)) > NOTE: Experimental features are not covered by semver and can change at any time. - **\[Experimental]**: Fixes and improvements for symlink support. (facebook/metro@0e2a70a, facebook/metro@3bef954, and facebook/metro@eeb211f by [@​robhogan](https://togithub.com/robhogan)) - **\[Experimental]**: Fix bug where `"exports"` field would be used on relative imports within a package. (facebook/metro@cd25c2b by [@​huntie](https://togithub.com/huntie)) ### [`v0.75.1`](https://togithub.com/facebook/metro/releases/tag/v0.75.1) [Compare Source](https://togithub.com/facebook/metro/compare/v0.75.0...v0.75.1) - **\[Feature]**: `metro-inspector-proxy`: Add a human-readable reference to each inspector entries/pages.([https://github.com/facebook/metro/pull/921](https://togithub.com/facebook/metro/pull/921) by [@​byCedric](https://togithub.com/byCedric)) - **\[Feature]**: `metro-inspector-proxy`: Report errors in the console. (facebook/metro@da8b41b by [@​mattbfb](https://togithub.com/mattbfb)) - **\[Fix]**: Race condition where a very recently modified file might have missing metadata.(facebook/metro@baf28ab by [@​robhogan](https://togithub.com/robhogan)) - **\[Fix]**: Source maps may have invalid entries when using Terser minification. ([https://github.com/facebook/metro/pull/928](https://togithub.com/facebook/metro/pull/928) by [@​robhogan](https://togithub.com/robhogan)) - **\[Fix]**: `metro-inspector-proxy`: Fetch source maps from Metro. (facebook/metro@6690b39 by [@​mattbfb](https://togithub.com/mattbfb)) - **\[Fix]**: Mitigate potential source map mismatches with concurrent transformations due to [terser#​1341](https://togithub.com/terser/terser/issues/1341). ([https://github.com/facebook/metro/pull/929](https://togithub.com/facebook/metro/pull/929) by [@​robhogan](https://togithub.com/robhogan)) > NOTE: Experimental features are not covered by semver and can change at any time. - **\[Experimental]**: Add initial_build annotation to Resolving and Transforming Dependencies (facebook/metro@fc83b52 by [@​blakef](https://togithub.com/blakef)) - **\[Experimental]**: Implement support for Package Exports (enabled via `resolver.unstable_enablePackageExports`) (facebook/metro@4d7ab38, facebook/metro@38b96f8, facebook/metro@216d3e2, facebook/metro@6e6f36f by [@​huntie](https://togithub.com/huntie)) - **\[Experimental]**: Implement support for symlinks (enabled via `resolver.unstable_enableSymlinks`) ([https://github.com/facebook/metro/pull/925](https://togithub.com/facebook/metro/pull/925), [https://github.com/facebook/metro/pull/926](https://togithub.com/facebook/metro/pull/926), etc. by [@​robhogan](https://togithub.com/robhogan)) **Full Changelog:** facebook/metro@v0.75.0...v0.75.1 ### [`v0.75.0`](https://togithub.com/facebook/metro/releases/tag/v0.75.0) [Compare Source](https://togithub.com/facebook/metro/compare/v0.74.1...v0.75.0) - **\[Breaking]**: Formalise minimum Node JS requirement at 14.17.0 via `package.json#engines`. (facebook/metro@c3e453e) - **\[Breaking]**: Filter untyped context properties passed to custom resolvers. (facebook/metro@cb01ec0) - **\[Breaking]**: Change default `context.redirectModulePath` implementation to return absolute path in all cases. (facebook/metro@acbfe63) - **\[Feature]**: Add `mainFields`, `getPackage`, and `getPackageForModule` to custom resolver context. (facebook/metro@adfb593) **Full Changelog**: facebook/metro@v0.74.1...v0.75.0 ### [`v0.74.1`](https://togithub.com/facebook/metro/releases/tag/v0.74.1) [Compare Source](https://togithub.com/facebook/metro/compare/v0.74.0...v0.74.1) - **\[Feature]**: Add `@babel/plugin-proposal-numeric-separator` to `metro-react-native-babel-preset` ([https://github.com/facebook/metro/pull/681](https://togithub.com/facebook/metro/pull/681) by [@​SConaway](https://togithub.com/SConaway)) **Full Changelog**: facebook/metro@v0.74.0...v0.74.1 ### [`v0.74.0`](https://togithub.com/facebook/metro/releases/tag/v0.74.0) [Compare Source](https://togithub.com/facebook/metro/compare/v0.73.8...v0.74.0) - **\[Breaking]** Remove [@​babel/plugin-transform-template-literals](https://togithub.com/babel/plugin-transform-template-literals) from metro-react-native-babel-preset (facebook/metro@322dea8) - **\[Breaking]** Remove `postProcessBundleSourcemap` from config (facebook/metro@339794e) - **\[Fix]** Don't log ENOENT errors to console for expected URL stack frames (facebook/metro@1031ae6) - **\[Fix]** Don't attempt to use the `find` crawler on Windows (facebook/metro@735aa9f) - **\[Performance]** Improve AST processing during transformation ([https://github.com/facebook/metro/pull/854](https://togithub.com/facebook/metro/pull/854) by [@​EvanBacon](https://togithub.com/EvanBacon)) - **\[Performance]** Improve Fast Refresh responsiveness when watching a large number of files (facebook/metro@b942eca) **Full Changelog:** facebook/metro@v0.73.6...v0.74.0 ### [`v0.73.8`](https://togithub.com/facebook/metro/releases/tag/v0.73.8) [Compare Source](https://togithub.com/facebook/metro/compare/v0.73.7...v0.73.8) *This is a hotfix on the `0.73.x` branch.* - **\[Fix]**: Source maps may have invalid entries when using Terser minification. ([https://github.com/facebook/metro/pull/928](https://togithub.com/facebook/metro/pull/928)) - **\[Fix]**: Mitigate potential source map mismatches with concurrent transformations due to [terser#​1341](https://togithub.com/terser/terser/issues/1341). ([https://github.com/facebook/metro/pull/929](https://togithub.com/facebook/metro/pull/929)) **Full Changelog**: facebook/metro@v0.73.7...v0.73.8 ### [`v0.73.7`](https://togithub.com/facebook/metro/releases/tag/v0.73.7) [Compare Source](https://togithub.com/facebook/metro/compare/v0.73.6...v0.73.7) *This is a hotfix on the `0.73.x` branch.* - **\[Fix]** Don't attempt to use the `find` crawler on Windows (facebook/metro@3703019) ### [`v0.73.6`](https://togithub.com/facebook/metro/releases/tag/v0.73.6) [Compare Source](https://togithub.com/facebook/metro/compare/v0.73.5...v0.73.6) - **\[Fix]** Fix duplicate 'add' events, reduce dropped events on new subtrees in `NodeWatcher` (non-Watchman, non-macOS).(facebook/metro@51fb7e3) > NOTE: Experimental features are not covered by semver and can change at any time. - **\[Experimental]** `experimentalImportBundleSupport`: Move bundle path hints into serialised dependency map([https://github.com/facebook/metro/pull/901](https://togithub.com/facebook/metro/pull/901)) **Full Changelog:** facebook/metro@v0.73.5...v0.73.6 ### [`v0.73.5`](https://togithub.com/facebook/metro/releases/tag/v0.73.5) [Compare Source](https://togithub.com/facebook/metro/compare/v0.73.4...v0.73.5) - **\[Fix]**: Make all `getTransformOptions` result properties optional. (facebook/metro@a07c823) - **\[Fix]**: Bug that can lead to "unknown module" errors at runtime after an incremental build. (facebook/metro@b1be263) - **\[Fix]**: `metro-runtime`: Re-throw cached module errors without wrapping. (facebook/metro@032c4a1) - **\[Fix]** Bump `babel/types` dependency to `^7.20.0` for more consistent exposed AST Bump `babel/types` dependency to `^7.20.0` for more consistent exposed AST **Full Changelog**: facebook/metro@v0.73.4...v0.73.5 ### [`v0.73.4`](https://togithub.com/facebook/metro/releases/tag/v0.73.4) [Compare Source](https://togithub.com/facebook/metro/compare/v0.73.3...v0.73.4) - **\[Feature]:** Expose `watch` option in `RunServerOptions` ([https://github.com/facebook/metro/pull/889](https://togithub.com/facebook/metro/pull/889) by [@​EvanBacon](https://togithub.com/EvanBacon)) - **\[Feature]:** `metro-runtime`: Emit additional context on WebSocket `'close'` events (facebook/metro@d54986c) > NOTE: Experimental features are not covered by semver and can change at any time. - **\[Experimental]**: `experimentalImportBundleSupport`: Retraverse parents of deleted async dependencies (facebook/metro@cb806d1) **Full Changelog:** facebook/metro@v0.73.3...v0.73.4 ### [`v0.73.3`](https://togithub.com/facebook/metro/releases/tag/v0.73.3) [Compare Source](https://togithub.com/facebook/metro/compare/v0.73.2...v0.73.3) - **\[Feature]**: Add configurable watcher health check that is off by default (facebook/metro@7adf468, facebook/metro@39f6e50) > NOTE: Experimental features are not covered by semver and can change at any time. - **\[Experimental]**: Move `experimentalImportBundleSupport` option from transformer to server (facebook/metro@3c0e1f7) **Full Changelog:** facebook/metro@v0.73.2...v0.73.3 ### [`v0.73.2`](https://togithub.com/facebook/metro/releases/tag/v0.73.2) [Compare Source](https://togithub.com/facebook/metro/compare/v0.73.1...v0.73.2) Maintenance release with purely internal changes. **Full Changelog:** facebook/metro@v0.73.1...v0.73.2 ### [`v0.73.1`](https://togithub.com/facebook/metro/releases/tag/v0.73.1) [Compare Source](https://togithub.com/facebook/metro/compare/v0.73.0...v0.73.1) - **\[Fix]**: Generate a unique name for each Watchman subscription. ([`3b0e78a`](https://togithub.com/facebook/metro/commit/3b0e78a76f4eea9f02e8b8464cf5b5e4549d6ac7)) > NOTE: Experimental features are not covered by semver and can change at any time. - **\[Experimental]\[Fix]**: Normalize file paths for `require.context` on Windows ([https://github.com/facebook/metro/pull/876](https://togithub.com/facebook/metro/pull/876) by [@​byCedric](https://togithub.com/byCedric)) **Full Changelog:** facebook/metro@v0.73.0...v0.73.1 ### [`v0.73.0`](https://togithub.com/facebook/metro/releases/tag/v0.73.0) [Compare Source](https://togithub.com/facebook/metro/compare/v0.72.3...v0.73.0) - **\[Breaking]** Switch default minifier from `uglify-es` to `terser`. ([#​871](https://togithub.com/facebook/metro/issues/871)) - **\[Breaking]**: Increase minimum supported Node.js version to ^14.17.0. ([#​872](https://togithub.com/facebook/metro/issues/872)) - **\[Breaking]**: Drop support for old (pre-CalVer) Watchman versions. ([`422055a`](https://togithub.com/facebook/metro/commit/422055a5ccaca41edb1864ca07d4f810b3e03791)) - **\[Feature]**: Support `fsevents` watcher on Apple Silicon. ([#​875](https://togithub.com/facebook/metro/issues/875)) - **\[Feature]**: Support loading source URLs in inspector-proxy. ([`db19b06`](https://togithub.com/facebook/metro/commit/db19b06bdd6d2fbbe109e4f3be4b3af3489c1f1c)) - **\[Fix]**: Log warning on unexpected error during `metro-file-map` cache read. ([`7028b7f`](https://togithub.com/facebook/metro/commit/7028b7f51074f9ceef22258a8643d0f90de2388b)) - **\[Fix]**: Remove exponentiation operator transform from `metro-react-native-babel-preset`. ([`c2365bb`](https://togithub.com/facebook/metro/commit/c2365bb1d72a3773b31c05feab13a96afac484df)) - **\[Fix]**: Don’t check `watchman --version` if `useWatchman` is false. ([`76c9307`](https://togithub.com/facebook/metro/commit/76c9307ed61efa7794b30b4e585cc5941ed73e16)) **Full Changelog:** facebook/metro@v0.72.3...v0.73.0 </details> --- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Mend Renovate](https://www.mend.io/free-developer-tools/renovate/). View repository job log [here](https://app.renovatebot.com/dashboard#github/dooboolab/dooboo-ui). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNC4xNjAuMCIsInVwZGF0ZWRJblZlciI6IjM0LjE2MC4wIn0=--> Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
…ges) Summary: Update `babel/generator` to the latest, which is a semver-minor update within the pre-existing range. I'm separating this out for ease of review because it brings some noisy snapshot changes, including more granular source maps and fewer empty lines in generated output. The majority of this is a result of babel/babel#14980 (`>=7.19.4`). This and the previous diff clear the way for a general Babel update, which is currently blocking a perf-boosting Metro PR facebook/metro#854. Changelog: [Internal] Bump `babel/generator dependency` to `^7.20.0` Reviewed By: motiz88 Differential Revision: D41438635 fbshipit-source-id: d56853169be22a2197ad53d6320ec6c1faf6b2a7
# Why Most of the [Exotic mode](https://blog.expo.dev/drastically-faster-bundling-in-react-native-a54f268e0ed1) performance benefits have been integrated in the default Expo CLI bundling pipeline (e.g. [less AST cloning](facebook/metro#854), [faster worker creation](facebook/metro#856)), and as such, the feature no longer needs to be enabled/disabled. Setting `mode: "exotic"` will no longer have any additional effects over the default. # Checklist <!-- Please check the appropriate items below if they apply to your diff. This is required for changes to Expo modules. --> - [ ] Documentation is up to date to reflect these changes (eg: https://docs.expo.dev and README.md). - [ ] Conforms with the [Documentation Writing Style Guide](https://github.com/expo/expo/blob/main/guides/Expo%20Documentation%20Writing%20Style%20Guide.md) - [ ] This diff will work correctly for `npx expo prebuild` & EAS Build (eg: updated a module plugin). --------- Co-authored-by: Expo Bot <[email protected]>
# Why Most of the [Exotic mode](https://blog.expo.dev/drastically-faster-bundling-in-react-native-a54f268e0ed1) performance benefits have been integrated in the default Expo CLI bundling pipeline (e.g. [less AST cloning](facebook/metro#854), [faster worker creation](facebook/metro#856)), and as such, the feature no longer needs to be enabled/disabled. Setting `mode: "exotic"` will no longer have any additional effects over the default. # Checklist <!-- Please check the appropriate items below if they apply to your diff. This is required for changes to Expo modules. --> - [ ] Documentation is up to date to reflect these changes (eg: https://docs.expo.dev and README.md). - [ ] Conforms with the [Documentation Writing Style Guide](https://github.com/expo/expo/blob/main/guides/Expo%20Documentation%20Writing%20Style%20Guide.md) - [ ] This diff will work correctly for `npx expo prebuild` & EAS Build (eg: updated a module plugin). --------- Co-authored-by: Expo Bot <[email protected]>
Summary: * deleted `yarn.lock` and reinstalled all packages re-creating it. * deleted the not needed node-fetch as it was bugging and fixed the test `js/tools/metro/packages/metro/src/integration_tests/__tests__/server-test.js` that is caused by it. * updated babel types * fixed the traverse bug #854 (comment) in file `js/tools/metro/packages/metro-source-map/src/generateFunctionMap.js` in a new way Differential Revision: D61204726
Summary: Pull Request resolved: #1321 * deleted `yarn.lock` and reinstalled all packages re-creating it. * deleted the not needed node-fetch as it was bugging and fixed the test `js/tools/metro/packages/metro/src/integration_tests/__tests__/server-test.js` that is caused by it. * updated babel types * fixed the traverse bug #854 (comment) in file `js/tools/metro/packages/metro-source-map/src/generateFunctionMap.js` in a new way Differential Revision: D61204726
Summary: Pull Request resolved: #1321 * deleted `yarn.lock` and reinstalled all packages re-creating it. * deleted the not needed node-fetch as it was bugging and fixed the test `js/tools/metro/packages/metro/src/integration_tests/__tests__/server-test.js` that is caused by it. * updated babel types * fixed the traverse bug #854 (comment) in file `js/tools/metro/packages/metro-source-map/src/generateFunctionMap.js` in a new way Differential Revision: D61204726
Summary: Pull Request resolved: #1321 * deleted `yarn.lock` and reinstalled all packages re-creating it. * deleted the not needed node-fetch as it was bugging and fixed the test `js/tools/metro/packages/metro/src/integration_tests/__tests__/server-test.js` that is caused by it. * updated babel types * fixed the traverse bug #854 (comment) in file `js/tools/metro/packages/metro-source-map/src/generateFunctionMap.js` in a new way Differential Revision: D61204726
…cond copy of babel traverse Summary: ### The issue Traverse in babel 7 is currently polluting the cache with nodes that have no `hub` entry (see babel/babel#6437). Since the traverse cache is used by other babel operations that expect `hub` to be present, this breaks the code in all kind of unexpected scenarios. While this issue is fixed in babel 8 (not released at this moment), it's still an issue in the latest version of babel 7. ### The previous workaround We implemented a workaround for it in #854 (comment) however in the latest version of `babel/traverse`, that workaround cannot be used anymore (more about that below). ### The new workaround Instead, we are implementing a different workaround that installs traverse twice, including installing it's cache file twice. We use the second copy of traverse `babel/traverse--for-generate-function-map` only in `forEachMapping`, allowing the rest of the system to use the traverse caching without the pollution issue mentioned above. ### Why the previous workaround stopped working Due to the use of a `let export` in the latest version of traverse cache, and how it's used in the latest version, we can't re-write `traverse.cache.path` anymore. This cache is exported with a `let export`: https://github.com/babel/babel/blob/5ebab544af2f1c6fc6abdaae6f4e5426975c9a16/packages/babel-traverse/src/cache.ts#L6-L20 And it compiles to: ``` let pathsCache = exports.path = new WeakMap(); function clearPath() { exports.path = pathsCache = new WeakMap(); } ``` and then used like this: ``` function getCachedPaths(hub, parent) { // ... pathsCache.get(hub); // ... } ``` Which means that re-writing the export like we used to do breaks the traverse cache because `exports.path` is re-written, but not `pathsCache` while the latter is used inside the file: ``` const previousCache = traverse.cache.path; traverse.cache.clearPath(); traverse(ast, { /* settings */ }); // this line is breaking the traverse cache traverse.cache.path = previousCache; ``` Differential Revision: D61917782
For visibility, the new workaround for that is implemented here: #1340 |
…cond copy of babel traverse (#1340) Summary: Pull Request resolved: #1340 ### The issue Traverse in babel 7 is currently polluting the cache with BabelNode that has no `hub` entry (see babel/babel#6437). Since the traverse cache is used by other babel operations (mostly transform) which might expect `hub` to be present, this breaks the code in all kind of unexpected scenarios. While this issue has been fixed in babel 8 (not released at this moment), it is still an issue in the latest version of babel 7. ### The previous workaround We've implemented a workaround for that issue in #854 (comment) however updating to the latest version of `babel/traverse`, that workaround is not working anymore (more about that below). ### The new workaround Instead, we are implementing a different workaround that installs traverse twice, including installing it's cache file twice. We use the second copy of traverse `babel/traverse--for-generate-function-map` only in `forEachMapping`, allowing the rest of the system to use the traverse caching from the main copy of traverse (`babel/traverse`) without the pollution issue mentioned above. ### Why the previous workaround stopped working Due to the use of a `let export` in the latest version of traverse cache, and how it's used in the latest version, we can't re-write `traverse.cache.path` anymore. This cache is exported with a `let export`: https://github.com/babel/babel/blob/5ebab544af2f1c6fc6abdaae6f4e5426975c9a16/packages/babel-traverse/src/cache.ts#L6-L20 And it compiles to: ``` let pathsCache = exports.path = new WeakMap(); function clearPath() { exports.path = pathsCache = new WeakMap(); } ``` and then used like this: ``` function getCachedPaths(hub, parent) { // ... pathsCache.get(hub); // ... } ``` Which means that re-writing the export like we used to do breaks the traverse cache because `exports.path` is re-written, but not `pathsCache` while the latter is used inside the file: ``` const previousCache = traverse.cache.path; traverse.cache.clearPath(); traverse(ast, { /* settings */ }); // this line is breaking the traverse cache traverse.cache.path = previousCache; ``` Reviewed By: robhogan Differential Revision: D61917782 fbshipit-source-id: 2ecc3133c1f9ecfe4912cb1fe2bf6151127e8e28
Summary
We split the parse/transform steps up to accommodate Hermes parsing, but this
defaults to cloning the AST which increases the transformation time by a fair amount.
You get this behavior by default when using Babel's
transform
method directly, which is what other bundlers do.Test plan
Bundling
three.js
in production mode:$ metro build ./example/index.js --out dist/index.js --platform ios --reset-cache --max-workers 0
Before:
After: