tntim96 / JSCover

JSCover is a JavaScript Code Coverage Tool that measures line, branch and function coverage
GNU General Public License v2.0
399 stars 84 forks source link

IllegalStateException: FUNCTION when arrow function is used #310

Closed guoruizo closed 2 years ago

guoruizo commented 2 years ago

Hi I am using JSCover 2.0.13 file mode to instrument the the following code. The code is saved to a js file under 'source_sample' folder: java -jar target/dist/JSCover-all.jar -fs source_sample/ dest/

I got the following closure-compiler error: Exception in thread "pool-2-thread-1" java.lang.IllegalStateException: FUNCTION 1:18 [length: 133] [source_file: /PersonMixin.js] [arrow_fn: 1] at com.google.javascript.jscomp.jarjar.com.google.common.base.Preconditions.checkState(Preconditions.java:502) at com.google.javascript.jscomp.CodeGenerator.add(CodeGenerator.java:398) at com.google.javascript.jscomp.CodeGenerator.addExpr(CodeGenerator.java:1771) at com.google.javascript.jscomp.CodeGenerator.add(CodeGenerator.java:296) at com.google.javascript.jscomp.CodeGenerator.addExpr(CodeGenerator.java:1771) at com.google.javascript.jscomp.CodeGenerator.addList(CodeGenerator.java:1829) at com.google.javascript.jscomp.CodeGenerator.add(CodeGenerator.java:256) at com.google.javascript.jscomp.CodeGenerator.add(CodeGenerator.java:699) at com.google.javascript.jscomp.CodeGenerator.add(CodeGenerator.java:105) at com.google.javascript.jscomp.CodePrinter.toSource(CodePrinter.java:874) at com.google.javascript.jscomp.CodePrinter.access$300(CodePrinter.java:42) at com.google.javascript.jscomp.CodePrinter$Builder.build(CodePrinter.java:809) at jscover.instrument.SourceProcessor.instrumentSource(SourceProcessor.java:481) at jscover.instrument.SourceProcessor.processSourceWithoutHeader(SourceProcessor.java:438) at jscover.instrument.SourceProcessor.processSource(SourceProcessor.java:426) at jscover.instrument.SourceProcessor.processSourceForFileSystem(SourceProcessor.java:418) at jscover.instrument.InstrumenterService.instrumentJSForFileSystem(InstrumenterService.java:381) at jscover.filesystem.FileSystemInstrumenter.lambda$copyFolder$2(FileSystemInstrumenter.java:417) at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) at java.base/java.lang.Thread.run(Thread.java:829)

reproduction code: const FoodMixin = superclass => class extends superclass { eat(food) { console.log("Eating ${food}"); } };

class Animal { constructor(name) { this.name = name } }

class Dog extends FoodMixin(Animal) { constructor(...args) { super(...args) }

bark() { console.log("Woff woff!") }

haveLunch(food) { this.eat(food); } }

I thought it maybe the issue of closure-compiler used by the version so I pasted it to closure-compiler online, which seems compiling fine: https://closure-compiler.appspot.com/home

It turns out if I change this line of code to (without newline before the class) const FoodMixin = superclass => class extends superclass { It passes.

Do you know what might the issue here?

tntim96 commented 2 years ago

I've released it in the 2.0.14 SNAPSHOT if you'd like to test.

<repositories>
    <repository>
        <id>sonatype-nexus-snapshots</id>
        <name>Sonatype Nexus Snapshots</name>
        <url>https://oss.sonatype.org/content/repositories/snapshots</url>
        <snapshots>
            <enabled>true</enabled>
        </snapshots>
    </repository>
</repositories>

Or build the latest JAR yourself or download from here.

Let me know if that fixes your issue and I'll build a release.

guoruizo commented 2 years ago

Instrumentation passes now! Thanks and looking forward to 2.0.14!

guoruizo commented 2 years ago

Is it possible v2.0.14 could be released next week so I could use the new version in my Maven project? Thanks

tntim96 commented 2 years ago

Should be doable

tntim96 commented 2 years ago

Done