From 392fec9238f00320f18b710d26a1386c1dea8dd2 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Sun, 23 Dec 2018 10:38:25 -0500 Subject: [PATCH] only apply aliasing logic once --- src/compile/render-dom/Block.ts | 8 +++--- .../samples/hash-in-attribute/_config.js | 26 +++++++++++++++++++ .../samples/hash-in-attribute/main.html | 3 +++ 3 files changed, 32 insertions(+), 5 deletions(-) create mode 100644 test/runtime/samples/hash-in-attribute/_config.js create mode 100644 test/runtime/samples/hash-in-attribute/main.html diff --git a/src/compile/render-dom/Block.ts b/src/compile/render-dom/Block.ts index 8a205e25fd..573a9863d8 100644 --- a/src/compile/render-dom/Block.ts +++ b/src/compile/render-dom/Block.ts @@ -409,12 +409,10 @@ export default class Block { const localKey = this.key && this.getUniqueName('key'); return deindent` - ${this.comment && `// ${escape(this.comment)}`} - function ${this.name}(#component, ${this.key ? `${localKey}, ` : ''}ctx) { + ${this.comment && `// ${this.comment}`} + function ${this.name}(${this.alias('component')}, ${this.key ? `${localKey}, ` : ''}ctx) { ${this.getContents(localKey)} } - `.replace(/(#+)(\w*)/g, (match: string, sigil: string, name: string) => { - return sigil === '#' ? this.alias(name) : sigil.slice(1) + name; - }); + `; } } diff --git a/test/runtime/samples/hash-in-attribute/_config.js b/test/runtime/samples/hash-in-attribute/_config.js new file mode 100644 index 0000000000..5e5726c48f --- /dev/null +++ b/test/runtime/samples/hash-in-attribute/_config.js @@ -0,0 +1,26 @@ +export default { + preserveIdentifiers: true, + + props: { + links: ['a', 'b', 'c'] + }, + + html: ` + x#a + x#b + x#c + `, + + test({ assert, component, target }) { + component.links = ['d', 'e', 'f']; + + const links = [...target.querySelectorAll('a')]; + assert.deepEqual(links.map(l => l.href), ['x#d', 'x#e', 'x#f']); + + assert.htmlEqual(target.innerHTML, ` + x#d + x#e + x#f + `); + } +}; \ No newline at end of file diff --git a/test/runtime/samples/hash-in-attribute/main.html b/test/runtime/samples/hash-in-attribute/main.html new file mode 100644 index 0000000000..0d1455b066 --- /dev/null +++ b/test/runtime/samples/hash-in-attribute/main.html @@ -0,0 +1,3 @@ +{#each links as link} + x#{link} +{/each} \ No newline at end of file