Skip to content

Fix babel-plugin-htm's escaping - #35

Closed
jviide wants to merge 1 commit into
developit:masterfrom
jviide:patch-04
Closed

jviide wants to merge 1 commit into
developit:masterfrom
jviide:patch-04

Conversation

@jviide

@jviide jviide commented Dec 4, 2018

Copy link
Copy Markdown
Collaborator

The Babel plugin can, in some cases, return unexpected values due to how it temporarily replaces variables with placeholders of form $$$_h_[<number>]. An example of a problematic input is <div>$$$_h_[1]</div> that gets transformed to h("div",{},[]); when the expected result is h("div",{},["$$$_h_[1]"]);.

This pull request fixes this behavior by partially reusing the same trick as in #21, namely escaping all underscores in statics to $__ and all variables to $_[<number>] and unescaping in the end accordingly.

It should be noted that the prefix $_ doesn't have to unique, and $_ can appear in the original template. In the escaped text the variable placeholders will be the only appearances of $_ that are immediately followed some other character than an underscore. This also allows us unescape things prefixed with $_ back unambiguously. The added test demonstrates such a case.

The changes in this pull request were originally a part of #21, but separated for better reviewability.

@jviide

jviide commented Dec 18, 2018

Copy link
Copy Markdown
Collaborator Author

Closing in favor of #43.

@jviide jviide closed this Dec 18, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant