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

Fix issues when using colocated component's with decorators. #340

Merged

Conversation

rwjblue
Copy link
Member

@rwjblue rwjblue commented Oct 19, 2019

The changes made in f9053bc added the ability to detect export { Foo as default } along side the ability to detect export default Foo. When ran in isolation (or with the @babel/plugin-transform-typescript) this works fine, but in common scenarios without typescript support it failed.

The cause of the failure is a bit difficult to grok, but basically it is because when our ExportDefaultDeclaration hook is hit, we add the setComponentTemplate invocation. Then subsequently another plugin changes from export default Foo to export { Foo as default } (the combination of @babel/plugin-proposal-decorators and @babel/plugin-proposal-class-fields does this), and we run the new ExportNamedDeclaration which causes us to add setComponentTemplate invocation again.

The fix added here ensures that only one setComponentTemplate invocation will be added (even if we see both export default Foo and export { Foo as default } during traversal).

Fixes #339.

The changes made in f9053bc added the ability to detect `export { Foo
as default }` along side the ability to detect `export default Foo`.
When ran in isolation (or with the `@babel/plugin-transform-typescript`)
this works fine, but in common scenarios without typescript support it
failed.

The cause of the failure is a bit difficult to grok, but _basically_ it
is because when our `ExportDefaultDeclaration` hook is hit, we add the
`setComponentTemplate` invocation. Then **subsequently** another plugin
changes from `export default Foo` to `export { Foo as default }` (the
combination of `@babel/plugin-proposal-decorators` and
`@babel/plugin-proposal-class-fields` does this), and we run the new
`ExportNamedDeclaration` which causes us to add `setComponentTemplate`
invocation **_again_**.

The fix added here ensures that _only **one**_ `setComponentTemplate`
invocation will be added (even if we see both `export default Foo` and
`export { Foo as default }` during traversal).
@rwjblue
Copy link
Member Author

rwjblue commented Oct 19, 2019

/cc @dfreeman (if you have time for a review)

@rwjblue rwjblue added the bug label Oct 19, 2019
@rwjblue rwjblue merged commit 4ce280b into ember-cli:master Oct 19, 2019
@rwjblue rwjblue deleted the fix-decorator-non-typescript-usage branch October 19, 2019 17:07
@dfreeman
Copy link
Contributor

🤦‍♂ Sorry about that @rwjblue! Fix looks good to me.

Copy link
Member Author

rwjblue commented Oct 21, 2019

No worries at all!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG 4.0.7] Using tracked with co-location results in double setting of template
2 participants