google / closure-compiler

A JavaScript checker and optimizer.

Home Page:https://developers.google.com/closure/compiler/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Regression in 20230802.0.0 related to spread operator

codyebberson opened this issue · comments

Consider this input:

// test.js

function test() {
  console.log(...[,,,,'foo']);
}

test();

That works fine with google-closure-compiler@20230502.0.0:

$ npx google-closure-compiler@20230502.0.0 test.js
function test(){console.log(...[,,,,"foo"])}test();

It results in error with google-closure-compiler@20230802.0.0:

$ npx google-closure-compiler@20230802.0.0 test.js
java.lang.IllegalStateException: Expected expression or [ITER_SPREAD] but was EMPTY. Reference node:
EMPTY 2:18  [source_file: test.js]

 Parent node:
CALL 2:2  [length: 27] [source_file: test.js]
    GETPROP log 2:10  [length: 3] [source_file: test.js]
        NAME console 2:2  [length: 7] [source_file: test.js]
    EMPTY 2:18  [source_file: test.js]
    EMPTY 2:19  [source_file: test.js]
    EMPTY 2:20  [source_file: test.js]
    EMPTY 2:21  [source_file: test.js]
    STRINGLIT foo 2:22  [length: 5] [source_file: test.js]

        at com.google.javascript.jscomp.AstValidator$1.handleViolation(AstValidator.java:87)
        at com.google.javascript.jscomp.AstValidator.violation(AstValidator.java:2135)
        at com.google.javascript.jscomp.AstValidator.validatePseudoExpression(AstValidator.java:498)
        at com.google.javascript.jscomp.AstValidator.validateCall(AstValidator.java:1175)
        at com.google.javascript.jscomp.AstValidator.validateExpression(AstValidator.java:420)
        at com.google.javascript.jscomp.AstValidator.validateExprStmt(AstValidator.java:1561)
        at com.google.javascript.jscomp.AstValidator.validateStatement(AstValidator.java:213)
        at com.google.javascript.jscomp.AstValidator.validateStatement(AstValidator.java:157)
        at com.google.javascript.jscomp.AstValidator.validateBlock(AstValidator.java:985)
        at com.google.javascript.jscomp.AstValidator.validateFunctionBody(AstValidator.java:1133)
        at com.google.javascript.jscomp.AstValidator.validateFunctionStatement(AstValidator.java:1075)
        at com.google.javascript.jscomp.AstValidator.validateStatement(AstValidator.java:177)
        at com.google.javascript.jscomp.AstValidator.validateStatement(AstValidator.java:157)
        at com.google.javascript.jscomp.AstValidator.validateStatements(AstValidator.java:151)
        at com.google.javascript.jscomp.AstValidator.validateScript(AstValidator.java:140)
        at com.google.javascript.jscomp.AstValidator.validateCodeRoot(AstValidator.java:126)
        at com.google.javascript.jscomp.AstValidator.process(AstValidator.java:111)
        at com.google.javascript.jscomp.PhaseOptimizer$NamedPass.process(PhaseOptimizer.java:240)
        at com.google.javascript.jscomp.PhaseOptimizer.process(PhaseOptimizer.java:179)
        at com.google.javascript.jscomp.Compiler.performFinalizations(Compiler.java:2981)
        at com.google.javascript.jscomp.Compiler.lambda$stage3Passes$8(Compiler.java:1054)
        at com.google.javascript.jscomp.CompilerExecutor.lambda$runInCompilerThread$0(CompilerExecutor.java:100)
        at java.base@17.0.7/java.util.concurrent.FutureTask.run(FutureTask.java:264)
        at java.base@17.0.7/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
        at java.base@17.0.7/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
        at java.base@17.0.7/java.lang.Thread.run(Thread.java:833)

Testing on nightly builds, it appears that it works up to google-closure-compiler@20230625.0.0-nightly and starts failing with google-closure-compiler@20230626.0.0-nightly.

Running Microsoft Windows 11

$ node --version
v18.16.1

$ npm --version
9.5.1

$ java --version
openjdk 19.0.1 2022-10-18
OpenJDK Runtime Environment Corretto-19.0.1.10.1 (build 19.0.1+10-FR)
OpenJDK 64-Bit Server VM Corretto-19.0.1.10.1 (build 19.0.1+10-FR, mixed mode, sharing)

@rishipal Is it possible this is related to this commit? 9d71f37

Thanks for the report

This is fixed with 2979771