adobe / htlengine

An HTL (Sightly) Interpreter/Compiler for Node.js
Apache License 2.0
47 stars 20 forks source link

Data attributes not compiling correctly #278

Closed bofoy closed 3 years ago

bofoy commented 3 years ago

We have certain data attributes in our HTL in the form of

<a data-foo-bar=${model.baz}>Link</a>

When compiling the template using compileToFunction I got the error

SyntaxError: Missing initializer in const declaration
    at new Function (<anonymous>)
    at Compiler.compileToFunction

After examining the code generated by compileToString, I see variables created from the data attributes in the form of const var_attrName_data_foo-bar17. This seems to be causing the issues with the compileToFunction. Not sure if I'm missing a config or if there is a workaround for this. Any help would be appreciated!

tripodsan commented 3 years ago

thanks for reporting.... I'll look into it

tripodsan commented 3 years ago

hmm, I tried the following:

<a data-foo-bar=${foobar.id}>Link</a>

with:

{
  foobar: {
    id: 'foo',
  },
}

renders as:

<a data-foo-bar="foo">Link</a>

and is compiled as:

    $t = $.dom.create("a",false,false);
    const var_attrValue0 = foobar["id"];
    if (!$.col.empty(var_attrValue0)) {
      $.dom.attr($t, 'data-foo-bar', var_attrValue0, 'attribute');
    }
    $n = $.dom.push($n,$t);

so I don't really know if you're example is correct....

tripodsan commented 3 years ago

I'm closing this as won't fix. please provide better example.