sweet-js/sweet-core

Hygiene broken in template literals that use interpolation

kevin-dp opened this issue · 1 comments

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);

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.