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

$ in template literals #57

Closed
subzey opened this issue Oct 31, 2016 · 2 comments
Closed

$ in template literals #57

subzey opened this issue Oct 31, 2016 · 2 comments
Assignees
Labels
Milestone

Comments

@subzey
Copy link

subzey commented Oct 31, 2016

Currently renaming routine incorrectly treats $ in template literals as a variable. As a result, it is renamed.

There's an example: after passing alert(`${i}`) into RegPack, the resulting string becomes alert(`a{e}`).

That's not a big issue as the $ may be manually excluded, but this behavior can be surprising.

@Siorki Siorki added the bug label Nov 1, 2016
@Siorki Siorki added this to the 5.0 milestone Nov 1, 2016
@Siorki
Copy link
Owner

Siorki commented Nov 1, 2016

So far RegPack performs renaming inside strings, however I am still not convinced that it should be done that way, the only reason for it is if the string is run through eval() (or any equivalent). This is an open topic.

RegPack v5.0 will identify strings within the code (for #55). This issue can easily be solved by checking for ${ in template literals.
Avoiding replacement for template literals should be as easy as ckeching for ${

@Siorki
Copy link
Owner

Siorki commented Jan 30, 2017

I went for the following strategy : the replacement is performed :

  • outside strings
  • inside a substitution pattern ${...} of a template string, as it is likely that variables will be mentioned there

Every other occurrence (in a string) is not replaced. I assumed that eval()'ing a string is an uncommon occurrence.

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

No branches or pull requests

2 participants