don't over-escape '#' in sharedPath

pull/750/head
Conduitry 8 years ago
parent b869e48bff
commit 0e9f16b589

@ -145,12 +145,9 @@ export default function dom(
if (generator.stylesheet.hasStyles && options.css !== false) { if (generator.stylesheet.hasStyles && options.css !== false) {
const { css, cssMap } = generator.stylesheet.render(options.filename); const { css, cssMap } = generator.stylesheet.render(options.filename);
// special case: we only want to escape '@' and not '#', because at this point all we'll be unescaping is '@' const textContent = stringify(options.dev ?
const textContent = JSON.stringify((options.dev ?
`${css}\n/*# sourceMappingURL=${cssMap.toUrl()} */` : `${css}\n/*# sourceMappingURL=${cssMap.toUrl()} */` :
css).replace(/(@+)/g, (match: string) => { css, { onlyEscapeAtSymbol: true });
return match + match[0];
}));
builder.addBlock(deindent` builder.addBlock(deindent`
function @add_css () { function @add_css () {
@ -304,13 +301,13 @@ export default function dom(
}); });
result = result =
`import { ${names.join(', ')} } from ${stringify(sharedPath)};\n\n` + `import { ${names.join(', ')} } from ${stringify(sharedPath, { onlyEscapeAtSymbol: true })};\n\n` +
result; result;
} }
else if (format === 'cjs') { else if (format === 'cjs') {
const SHARED = '__shared'; const SHARED = '__shared';
let requires = `var ${SHARED} = require( ${stringify(sharedPath)} );`; let requires = `var ${SHARED} = require( ${stringify(sharedPath, { onlyEscapeAtSymbol: true })} );`;
used.forEach(name => { used.forEach(name => {
const alias = generator.alias(name); const alias = generator.alias(name);
requires += `\nvar ${alias} = ${SHARED}.${name};`; requires += `\nvar ${alias} = ${SHARED}.${name};`;

@ -1,9 +1,9 @@
export function stringify(data: string) { export function stringify(data: string, options = {}) {
return JSON.stringify(escape(data)); return JSON.stringify(escape(data, options));
} }
export function escape(data: string) { export function escape(data: string, { onlyEscapeAtSymbol = false } = {}) {
return data.replace(/(@+|#+)/g, (match: string) => { return data.replace(onlyEscapeAtSymbol ? /(@+)/g : /(@+|#+)/g, (match: string) => {
return match + match[0]; return match + match[0];
}); });
} }

Loading…
Cancel
Save