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

[BUGFIX] Fix Babel transform interactions with other transforms #53

Merged
merged 1 commit into from
Apr 3, 2020
Merged

[BUGFIX] Fix Babel transform interactions with other transforms #53

merged 1 commit into from
Apr 3, 2020

Conversation

pzuraq
Copy link
Member

@pzuraq pzuraq commented Apr 3, 2020

While working on some quality of life improvements in the repo, I found
some buggy interactions between the Babel transform and other
transforms. Specifically, the @babel/preset-typescript transform and
the @glimmer/babel-plugin-glimmer-env transform.

In the first case, the TypeScript transform removes all imports bindings
that no longer have references once types are removed, and it does this
before our transform has a chance to run. This results in imported
values being removed, even though they are used in templates.

In the case of the @glimmer/babel-plugin-glimmer-env, referencing the
Program path directly causes errors when it goes to replace references
to the DEBUG binding.

This PR updates the logic to create an empty path that is added to the
AST and referenced properly, so TS doesn't remove values and
@glimmer/env can "replace" it correctly. We also avoid adding this
extra reference to any type bindings, because then they won't be
removed.

The alternative would be to skip the queue by using the Program to
iterate the AST, but that seems like it would be more brittle than this.

While working on some quality of life improvements in the repo, I found
some buggy interactions between the Babel transform and other
transforms. Specifically, the `@babel/preset-typescript` transform and
the `@glimmer/babel-plugin-glimmer-env` transform.

In the first case, the TypeScript transform removes all imports bindings
that no longer have references once types are removed, and it does this
_before_ our transform has a chance to run. This results in imported
values being removed, even though they are used in templates.

In the case of the `@glimmer/babel-plugin-glimmer-env`, referencing the
Program path directly causes errors when it goes to _replace_ references
to the `DEBUG` binding.

This PR updates the logic to create an empty path that is added to the
AST and referenced properly, so TS doesn't remove values and
`@glimmer/env` can "replace" it correctly. We also avoid adding this
extra reference to any _type_ bindings, because then they _won't_ be
removed.

The alternative would be to skip the queue by using the `Program` to
iterate the AST, but that seems like it would be more brittle than this.
@chiragpat chiragpat merged commit e24e7b9 into glimmerjs:master Apr 3, 2020
@pzuraq pzuraq added the bug Something isn't working label Apr 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants