This repository was archived by the owner on Aug 4, 2021. It is now read-only.
Make transform stateless#71
Merged
Rich-Harris merged 6 commits intomasterfrom Jun 7, 2016
Merged
Conversation
| } | ||
|
|
||
| const HELPERS_ID = '\0commonjsHelpers'; | ||
| const HELPERS_NAME = '__commonjsHelpers'; |
Contributor
There was a problem hiding this comment.
I realize this is no worse than it was, but this should be generated so as not to conflict with anything in the file. Could do a simple indexOf with an incrementing suffix rather than trying to be clever with scopes.
Contributor
Author
There was a problem hiding this comment.
good point – fixed
Contributor
|
Neat! Prepending a module name with |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This follows up on @tivac's suggestion in rollup/rollup#658 – rather than tracking which CommonJS features are used and injecting them haphazardly using the
introhook, modules importcommonjsHelpers. This is cleaner, and will allow the results of the transformation to be cached.There is a wrinkle however: the synthetic ID used for the helpers goes through the same resolution process as any other ID. Since in this case that frequently means rollup-plugin-node-resolve, we end up passing trying to resolve whatever ID we use with the Node resolution algorithm, which will obviously fail.
So I'm proposing we adopt the following convention: plugins that generate synthetic helper modules, like this one, should use the null character (
\0) in the ID. Plugins that implementresolveIdshould ignore IDs with the null character. (The reason I'm suggesting NUL is that it's invalid in filenames on both *nix and Windows.)I've already taken the liberty of updating
createFilterand node-resolve.Any thoughts @rollup/collaborators?
Apologies for the bad git discipline, I managed to roll some extra stuff in here 😕