Ensure that template literals generated by JSX-to-HTM transform has a balanced amount of quasis and expressions #199
Conversation
JSX expressions such as <><Foo />{Bar}</> get parsed into unbalanced TemplateLiteral expressions where there are less quasis than there should be when compared to the number of expressions.
Always keep a quasi - even one with no text - after an expression in generated template literals.
|
yay! |
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.
This pull request fixes the babel-plugin-transform-jsx-to-htm plugin output for JSX inputs like this:
Before the fix the plugin crashes with the following error message:
The fix is to always ensure that a template literal expression ends with a quasi, even when the quasi is an empty string. New static string content is then always applied to the (currently) last quasi in the template. When an expression is added a new empty quasi is immediately appended after that.
Kudos to @cristianbote for noticing a problem on wmr output that was caused by this issue. It appears that this fix also fixes the wmr problem.
This pull request also adds a test illustrating the problem.