sweet-js / sweet-core

Sweeten your JavaScript.
https://www.sweetjs.org
BSD 2-Clause "Simplified" License
4.58k stars 208 forks source link

Hygiene broken in template literals that use interpolation #744

Open kevin-dp opened 6 years ago

kevin-dp commented 6 years ago

Assume a regular JS file with no macros involved at all:

var test = { someField: 10 };
console.log(`test.someField = ${test.someField}`);

One would expect that the compilation of regular JS code containing no macros yields equivalent code. However, this is the resulting code after compilation:

var test_0 = { someField: 10 };
console.log(`test.someField = ${test.someField}`);

Notice how the variable test has been renamed to test_0 for hygiene, but test in the interpolation within the template literal is unchanged.

This bug does not occur when avoiding template literals and writing it as console.log('test.someField = ' + test.someField);

shaunlebron commented 5 years ago

this bit me today. is it possible to disable hygiene to prevent renaming? this would be useful for simple cases where we are not inserting any new variables.