0
0
mirror of https://github.com/sveltejs/svelte.git synced 2024-12-01 17:30:59 +01:00

Merge pull request #1905 from sveltejs/hash-in-dynamic-attribute

only apply aliasing logic once
This commit is contained in:
Rich Harris 2018-12-23 10:49:41 -05:00 committed by GitHub
commit 6def7ca69b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 32 additions and 5 deletions

View File

@ -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;
});
`;
}
}

View File

@ -0,0 +1,26 @@
export default {
preserveIdentifiers: true,
props: {
links: ['a', 'b', 'c']
},
html: `
<a href="x#a">x#a</a>
<a href="x#b">x#b</a>
<a href="x#c">x#c</a>
`,
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, `
<a href="x#d">x#d</a>
<a href="x#e">x#e</a>
<a href="x#f">x#f</a>
`);
}
};

View File

@ -0,0 +1,3 @@
{#each links as link}
<a href="x#{link}">x#{link}</a>
{/each}