t2ym / i18n-element

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

[runtime preprocess][rare use case] Syntax errors with apostrophe ' in id #79

Open t2ym opened 5 years ago

t2ym commented 5 years ago

[runtime preprocess][rare use case] Syntax errors with apostrophe ' in id

Root Cause

Reproducible Code

  html`${bind(this)}<span id="id-with-apostrophie'">hello</span>`

Workaround

Notes

Fix

diff --git a/i18n.js b/i18n.js
index 2c17905..3a00222 100644
--- a/i18n.js
+++ b/i18n.js
@@ -527,7 +527,7 @@ export const html = (strings, ...parts) => {
             }
             while (partPath.length) {
               tmpPart = partPath.shift();
-              valueExpression += `['${tmpPart}']`;
+              valueExpression += `["${tmpPart}"]`;
             }
             if (isJSON) {
               valueExpression = `JSON.stringify(${valueExpression}, null, 2)`;