t2ym / i18n-element

I18N Base Element for Lit and Polymer
Other
9 stars 1 forks source link

[buildtime preprocess][rare use case] SyntaxError: Unexpected token "][" with quotation " in id #80

Open t2ym opened 5 years ago

t2ym commented 5 years ago

[buildtime preprocess][rare use case] SyntaxError: Unexpected token "][" with quotation " in id

Root Cause

Reproducible Code

  html`${bind(this)}<span id="id-with-&quot;">hello</span>`

Fix

diff --git a/demo/gulpfile.js b/demo/gulpfile.js
index 9ce403c..eb41561 100644
--- a/demo/gulpfile.js
+++ b/demo/gulpfile.js
@@ -350,7 +350,7 @@ function traverseAst(ast, templates) {
                       valueExpression = 'effectiveLang';
                     }
                     while (tmpPart = partPath.shift()) {
-                      valueExpression += `["${tmpPart}"]`;
+                      valueExpression += `["${tmpPart.replace(/"/g, '\\"')}"]`;
                     }
                     if (isJSON) {
                       if (useI18nFormatDataProperty) {

Workarounds