tntim96/JSCover

Instruments in lit-html template

Closed this issue · 6 comments

I am extending JSCover usage on all of my projects and run into this error
Uncaught SyntaxError: Missing } in template expression

Minimum reproduction is

+++++src/hello.js+++++
import {LitElement, html} from 'https://unpkg.com/@polymer/lit-element@latest/lit-element.js?module';

class MyElement extends LitElement {
    render() {
        return html`
          <div
		@mouseenter="${(evt) => alert('hovered')}">
		hello, hover me
          </div>
	`;
    }  
}
customElements.define('my-element', MyElement);

+++++src/index.html+++++
<!DOCTYPE html>
<html>
  <head>
    <script type="module" src="hello.js"></script>
  </head>
  <body>
    <my-element></my-element>
  </body>
</html>
  1. instrument the JavaScript source using file mode: java -jar JSCover-all.jar src/ target/
  2. Load the target/index.html from Chrome could see console error.
    Uncaught SyntaxError: Missing } in template expression

Usually I saw JSCover skips embedded code but somehow take the lit-html template. I was using custom element framework from lit-element: https://lit.dev/docs/v1/lit-html/introduction/.

Thanks for JSCover support!

Hi, just checking if the posted reproduction is good to spot the issue? Any suggestion to fix or workaround is appreciated.

Hi @guoruizo , sorry for taking so long on this. It looks like a genuine bug and it looks fixable, although I'll have to think about how to instrument in template strings. First thought is there shouldn't be any instrumentation. 🤔

Also, are you on Java 8? I think I should create a branch that still supports Java 8, but that will require a slightly older version of the closure-compiler which is OK.

I've released it in the 2.0.16 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.

Hi @guoruizo , sorry for taking so long on this. It looks like a genuine bug and it looks fixable, although I'll have to think about how to instrument in template strings. First thought is there shouldn't be any instrumentation. thinking

Also, are you on Java 8? I think I should create a branch that still supports Java 8, but that will require a slightly older version of the closure-compiler which is OK.

I had the same question when I ran into this and thought probably okay not to instrument the html' template code. I think as long as it does not error, no instrumentation in that code block is explainable. Yes, that was java8 when I reproduced it. Thanks for considering it!

I've released it in the 2.0.16 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.

Works fine using the latest JAR!

Great! Thanks for the feedback. I think I'll release in a week or so.