Expand debug statements in place to permit subsequent Babel plugin translation#103
Merged
ef4 merged 3 commits intoember-cli:mainfrom Jun 24, 2025
Merged
Conversation
…e.g. from @embroider/macros) to perform further translation
Contributor
|
Thanks, this seems good to me. Out of an abundance of caution I'm going to label it at breaking so we release this as a major, so that it doesn't destabilize any of the much older apps that could be depending on the 1.x of this package. Embroider can use the 2.x directly. |
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 join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Problem
Whenever this plugin encounters a debug function call statement, its builder performs a partial translation that gets fully resolved and substituted only once
expandMacrosis called at the exit of the file.While this behavior works fine for standalone translation, the deferred substitution fails to permit other registered Babel plugins the opportunity to translate the replacement expression, due to the nature of Babel's one-shot AST traversal.
In particular, this poses a problem when using the
'@embroider/macros'condition, since the resultingisDevelopingApp()call expression is not seen by the later Babel plugin from @embroider/macros.Solution
Rather than collecting all expressions for later expansion, this change expands the debug statements in-place, and in doing so, Babel passes the replacement expression to all registered plugins. (This includes the current plugin, but the replacement expression statement is always a logical expression rather than a direct call statement, so it is not subject to re-processing by this plugin.)
Concern: Chesterton's Fence
It is unclear to me why the plugin was originally written in the manner where it collects expressions for later substitution, and whether modifying this behavior will lead to other problems. It appears that this was the behavior from the initial commit 99c4e6b, and the purpose in that code seems to have been that logic for calculating the debug flag was implemented in the Program.exit hook, so the final expression was only known at that point. It's unclear to me why exactly this approach was taken and has been preserved through a variety of refactors, but I suspect it is related in some way to the need to determine whether/how to adjust module imports, which is no longer a necessity. My hope therefore is that the effect of this change will not have adverse effects on existing usages.