Mutate existing default export declarations for improved compatibility #18
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.
Calling
t.exportDefaultDeclaration
triggers theExportDefaultDeclaration
in other babel transforms. In some cases triggering that hook multiple times can lead to unexpected behavior.For example, in the the template-colocation-plugin at https://github.com/embroider-build/embroider/blob/289f83d80d/packages/shared-internals/src/template-colocation-plugin.ts), the first call of the hook will see a class declaration and set
state.associate
1 (which later causessetComponentTemplate
to be appended after theexport
2). The second call of the hook sees a non-class expression and wraps it insetComponentTemplate
within the export 3. In the end, that leaves us with twosetComponentTemplate
calls.Resolves #16
This issue could alternatively be fixed with a change to the template-colocation-plugin itself (e.g. have it unset
state.associate
on the second invocation ofExportDefaultDeclaration
.I'm unsure how to go about adding a test for this. Do we want to try and pull the template-colocation-plugin into the decorator-transforms test suite somehow? 🤔
Footnotes
https://github.com/embroider-build/embroider/blob/289f83d80d/packages/shared-internals/src/template-colocation-plugin.ts#L103-L111 ↩
https://github.com/embroider-build/embroider/blob/289f83d80d/packages/shared-internals/src/template-colocation-plugin.ts#L82-L91 ↩
https://github.com/embroider-build/embroider/blob/289f83d80d/packages/shared-internals/src/template-colocation-plugin.ts#L129-L131 ↩