google / closure-compiler

A JavaScript checker and optimizer.
https://developers.google.com/closure/compiler/
Apache License 2.0
7.37k stars 1.15k forks source link

Parse error, when ccjs compiles its own previous output #2477

Closed Mikolaj closed 7 years ago

Mikolaj commented 7 years ago

The file for which the error manifests is this https://github.com/LambdaHack/lambdahack.github.io/releases/download/newestJS/all.ccbug.js

Commandline and log:

~/r/LambdaHack$ ccjs ~/Downloads/all.js --compilation_level=ADVANCED_OPTIMIZATIONS --isolation_mode=IIFE --assume_function_wrapper --jscomp_off="*" --externs=node > /tmp/ff.js
/home/mikolaj/Downloads/all.js:11256: ERROR - Parse error. ')' expected
Vdt=S1(xr,Nv),Wdt=a2(Vdt),Xdt=b2(Wdt,Nv),Ydt=c2(Xdt),Zdt=e0(ak,J8l),$dt=g4(MC),aet=b5($dt),bet=n3(aet),cet=i2(L8l),det=l2(wIl),eet=B3(det),fet=gX(yO,C8l),get=oX(fet),het=oW(get,y8l),iet=R1(het),jet=pW(iet,wi,x8l),ket=R1(jet),let=J1(ket,jQ,kQ),met=a2(let),oet=RAi(met,v7l,kQ),pet=oX(oet),qet=oW(pet,s8l),ret=R1(qet),set=i2(F8l),tet=WS(iHl,e6),uet=l2(O8l),vet=B3(uet),wet=J1(xr,Z5,kQ),xet=a2(wet),yet=M1(xet,ict,Hv),zet=c2(yet),Aet=e0(ak,u8l),Bet=i2(B8l),Cet=i2(y8l),Det=g3k(ret,HCs,r8l),Eet=a2(Det),Fet=
                                                                                                                                                                                                                                                          ^

1 error(s), 0 warning(s)

Compiler version is latest from yesterday.

The original file, before the first application of ccjs, is the output of ghcjs --- a compiler of Haskell to JS and the Haskell project is https://github.com/LambdaHack/LambdaHack/commit/4d84a69e1e734ce00bd3cff64cb889d1f9160e2a

ChadKillingsworth commented 7 years ago

let is a reserved word in strict mode: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Lexical_grammar

The error is correct (though not the most helpful).

Mikolaj commented 7 years ago

@ChadKillingsworth: either I don't understand or you don't. If let is a reserved word, then why ccjs used it in its output? Remember, I'm compiling ccjs's output with ccjs.

ChadKillingsworth commented 7 years ago

This depends on input/output language levels. You'd also need to dig through and find out what the original input looked like. If the compiler is renaming to a reserved keyword, that would be a bug. If the original input uses a function parameter named let that's a very different issue.

It's entirely possible for a previous compilation to be invalid input for a subsequent one depending on flags and language levels.

Mikolaj commented 7 years ago

OK, I see. Both compilations were with exactly the same parameters --- as shown above. So the original files could not contain the same kind of error, or it would be caught already in the first compilation. But if an error of one kind, more benign (so benign that --jscomp_off="*" supresses it successfully and also the code runs fine), may be transformed to a parsing error in the resulting JS, then indeed, that would explain the issue and I would be to blame for compiling an erroneous code to being with. But can a non-parsing error be transformed to a parsing error? And even if it is, is that a sensible behaviour?

ChadKillingsworth commented 7 years ago

But can a non-parsing error be transformed to a parsing error? And even if it is, is that a sensible behaviour?

Yes is the answer to both questions. Optimizations can transform code in non-trivial ways. So definitely suppressing an error could cause this.

Mikolaj commented 7 years ago

OK, I trust you. Thank you.