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

Hoist function exports to top of module body in CJS/AMD/UMD #57669

Merged
merged 2 commits into from
Mar 6, 2024
Merged

Conversation

rbuckton
Copy link
Member

@rbuckton rbuckton commented Mar 6, 2024

This changes our emit for CommonJS, AMD, and UMD so that exports for exported function declarations are hoisted to the top of the transformed module body. There is a minor impact on the order of keys in the exportedNames_1 map synthesized for SystemJS modules as a consequence of this change, but it has no impact to runtime behavior.

Fixes #39853

@typescript-bot typescript-bot added Author: Team For Milestone Bug PRs that fix a bug with a specific milestone labels Mar 6, 2024
@jakebailey
Copy link
Member

I just merge conflicted this via #57668; you'll have to merge main to delete some of these baselines. (sorry!)

@tjzel
Copy link

tjzel commented Jul 23, 2024

@rbuckton Is there an option to disable this behavior while generating CommonJS?

github-merge-queue bot pushed a commit to software-mansion/react-native-reanimated that referenced this pull request Jul 23, 2024
## Summary

Since Reanimated Babel Plugin breaks hoisting and [newer Typescript
hoists CommonJS exports by
default](microsoft/TypeScript#57669) we
sometimes need to dehoist those exports.

## Test plan

- [x] Add unit test suite.
- [x] Runtime tests pass.
@rbuckton
Copy link
Member Author

@rbuckton Is there an option to disable this behavior while generating CommonJS?

No, there is not. It's there a reason you would need to disable it?

@tjzel
Copy link

tjzel commented Jul 24, 2024

Reanimated Babel plugin does code transformations that break hoisting - function declarations become variable declarations with assignments. Therefore with this change we also have to move the exports to the bottom of file so the values are not exported as undefined. It's not really a blocker, but an inconvenience nevertheless.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Author: Team For Milestone Bug PRs that fix a bug with a specific milestone
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Hoisted function declarations should be assigned to exports before any require calls
5 participants