diff --git a/src/compiler/code_generator.ts b/src/compiler/code_generator.ts index db7918da..f8000c35 100644 --- a/src/compiler/code_generator.ts +++ b/src/compiler/code_generator.ts @@ -282,6 +282,7 @@ export class CodeGenerator { for (let block of this.blocks) { if (block.dom) { let xmlString = block.asXmlString(); + xmlString = xmlString.replace(/`/g, "\\`"); if (block.dynamicTagName) { xmlString = xmlString.replace(/^<\w+/, `<\${tag || '${block.dom.nodeName}'}`); xmlString = xmlString.replace(/\w+>$/, `\${tag || '${block.dom.nodeName}'}>`); diff --git a/tests/compiler/__snapshots__/attributes.test.ts.snap b/tests/compiler/__snapshots__/attributes.test.ts.snap index b5afa9b8..60cc10cb 100644 --- a/tests/compiler/__snapshots__/attributes.test.ts.snap +++ b/tests/compiler/__snapshots__/attributes.test.ts.snap @@ -126,6 +126,20 @@ exports[`attributes dynamic attributes 1`] = ` }" `; +exports[`attributes dynamic attributes with backticks 1`] = ` +"function anonymous(app, bdom, helpers +) { + let { text, createBlock, list, multi, html, toggler, comment } = bdom; + + let block1 = createBlock(\`
\`); + + return function template(ctx, node, key = \\"\\") { + let attr1 = \`bar\`; + return block1([attr1]); + } +}" +`; + exports[`attributes dynamic class attribute 1`] = ` "function anonymous(app, bdom, helpers ) { @@ -374,6 +388,19 @@ exports[`attributes static attributes on void elements 1`] = ` }" `; +exports[`attributes static attributes with backticks 1`] = ` +"function anonymous(app, bdom, helpers +) { + let { text, createBlock, list, multi, html, toggler, comment } = bdom; + + let block1 = createBlock(\`
\`); + + return function template(ctx, node, key = \\"\\") { + return block1(); + } +}" +`; + exports[`attributes static attributes with dashes 1`] = ` "function anonymous(app, bdom, helpers ) { diff --git a/tests/compiler/attributes.test.ts b/tests/compiler/attributes.test.ts index 72c01869..616e7d1e 100644 --- a/tests/compiler/attributes.test.ts +++ b/tests/compiler/attributes.test.ts @@ -22,6 +22,12 @@ describe("attributes", () => { expect(renderToString(template)).toBe(`
`); }); + test("static attributes with backticks", () => { + const template = '
'; + const result = renderToString(template); + expect(result).toBe('
'); + }); + test("static attributes on void elements", () => { const template = `Test`; expect(renderToString(template)).toBe(`Test`); @@ -33,6 +39,12 @@ describe("attributes", () => { expect(result).toBe(`
`); }); + test("dynamic attributes with backticks", () => { + const template = '
'; + const result = renderToString(template); + expect(result).toBe(`
`); + }); + test("two dynamic attributes", () => { const template = `
`; const result = renderToString(template);