google / traceur-compiler

Traceur is a JavaScript.next-to-JavaScript-of-today compiler
Apache License 2.0
8.17k stars 578 forks source link

traceur is breaking my typeof tests #2135

Closed excenter closed 7 years ago

excenter commented 7 years ago

I have a simple line of code } else if ( typeof id == 'object'){ which when run through .pipe(traceur()) twice is mangled into } else if ((typeof id === 'undefined' ? 'undefined' : $traceurRuntime.typeof(id)) == 'object') { which give me $traceurRuntime is not defined whenever it's run in the browser.

excenter commented 7 years ago

it also happens if run through once.

excenter commented 7 years ago

To clarify, we use Traceur as a gulp task before publishing, and including an entire runtime because traceur has different ideas about typeof comparisons is bananas. Are there options/flags we can use so that it doesn't call for the traceurRuntime?

UltCombo commented 7 years ago

Disable the symbols option when compiling. https://github.com/google/traceur-compiler/wiki/Options-for-Compiling

http://google.github.io/traceur-compiler/demo/repl.html#%2F%2F%20Options%3A%20--symbols%3Dfalse%0A%0Atypeof%20foo

arv commented 7 years ago

Thanks @UltCombo

excenter commented 7 years ago

http://google.github.io/traceur-compiler/demo/repl.html#%2F%2F%20Options%3A%20--symbols%3Dfalse%0Aif%20(%20typeof%20id%20%3D%3D%20'object')%7B%0A%0A%7D

it works in that format, but how does one pass that option to traceur in gulp?

var traceurOptions = {
   symbols: false
 };

followed by .pipe(traceur(traceurOptions)) still changes if ( typeof id == 'object'){ to if ((typeof id === 'undefined' ? 'undefined' : $traceurRuntime.typeof(id)) == 'object') {

CORRECTION: Thank you that does fix things, it doesn't if you apply the pipe to the second translation and not the first.