adobe / htlengine

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

Generated JS code from Calendar WCM Core Components has duplicate constants names #286

Closed benoit-adobe closed 3 years ago

benoit-adobe commented 3 years ago

When compiling the content fragment with the Structured Content Fragment default data from the AEM component site it throws an error:

SyntaxError: Identifier 'format' has already been declared
    at new Function (<anonymous>)
    at Compiler.compileToFunction (/Users/benoit/Desktop/projects/practice/aem-styleguide/tests/htl-engine-latest/node_modules/@adobe/htlengine/src/compiler/Compiler.js:280:22)

After checking the code, the error is coming from the calendar.html file when transformed in JS, as the result is:

(function _template_src_content_jcr_root_apps_core_wcm_components_contentfragment_v1_contentfragment_calendar_html(){
    let element;
    element = function* _template_src_content_jcr_root_apps_core_wcm_components_contentfragment_v1_contentfragment_calendar_html_element(args) {
        const date = args[1]['date'] || '';
        const format = args[1]['format'] || '';
        let $t, $n = args[0];
        $.dom.text($n,"\n    \n    ");
        const format = format ? format : "YYYY-MM-dd HH:mm";
        if (format) {
        }
        $.dom.text($n,"\n    \n    ");
        const var_0 = yield $.xss($.exec("format", format, {"format": date, }), "html");
        $.dom.append($n, var_0);
        $.dom.text($n,"\n");
    };
    $.template('src/content/jcr_root/apps/core/wcm/components/contentfragment/v1/contentfragment/calendar.html', 'element', element);
})();

The error is coming from the duplicated format constants from the JS snippet. A couple of questions:

tripodsan commented 3 years ago

The error is coming from the duplicated format constants from the JS snippet. A couple of questions:

  • Is this issue coming from the fact that there's multiple format variables in the HTML?

probably. but this shouldn't cause any errors.

  • Is there some protected key words in the htlengine?

no.

  • Can it happen in other components?

should not.

github-actions[bot] commented 3 years ago

:tada: This issue has been resolved in version 6.2.14 :tada:

The release is available on:

Your semantic-release bot :package::rocket: