From 098e3db683eaf354609d577a5496ed71262528f3 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Mon, 24 Jul 2017 19:16:47 -0400 Subject: [PATCH] correctly unescape @ symbols (#712) --- src/generators/dom/Block.ts | 4 ++-- src/generators/dom/index.ts | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/generators/dom/Block.ts b/src/generators/dom/Block.ts index ff58a4e947..70323ae5cf 100644 --- a/src/generators/dom/Block.ts +++ b/src/generators/dom/Block.ts @@ -355,8 +355,8 @@ export default class Block { ${properties} }; } - `.replace(/(\\)?#(\w*)/g, (match, escaped, name) => { - return escaped ? match.slice(1) : this.alias(name); + `.replace(/(\\\\)?#(\w*)/g, (match, escaped, name) => { + return escaped ? match.slice(2) : this.alias(name); }); } } diff --git a/src/generators/dom/index.ts b/src/generators/dom/index.ts index 55c6599cd7..17f2c8b482 100644 --- a/src/generators/dom/index.ts +++ b/src/generators/dom/index.ts @@ -137,15 +137,15 @@ export default function dom( if (generator.stylesheet.hasStyles && options.css !== false) { const { css, cssMap } = generator.stylesheet.render(options.filename); - const textContent = options.dev ? + const textContent = stringify(options.dev ? `${css}\n/*# sourceMappingURL=${cssMap.toUrl()} */` : - css; + css); builder.addBlock(deindent` function @add_css () { var style = @createElement( 'style' ); style.id = '${generator.stylesheet.id}-style'; - style.textContent = ${JSON.stringify(textContent)}; + style.textContent = ${textContent}; @appendNode( style, document.head ); } `); @@ -263,8 +263,8 @@ export default function dom( let result = builder .toString() - .replace(/(\\)?@(\w*)/g, (match: string, escaped: string, name: string) => { - if (escaped) return match.slice(1); + .replace(/(\\\\)?@(\w*)/g, (match: string, escaped: string, name: string) => { + if (escaped) return match.slice(2); if (name in shared) { if (options.dev && `${name}Dev` in shared) name = `${name}Dev`;