Merge pull request #1312 from sveltejs/gh-1275

deconflict against inherited contexts
pull/1332/head
Rich Harris 7 years ago committed by GitHub
commit 4a6807eab1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -398,7 +398,7 @@ export default class Generator {
return alias;
}
getUniqueNameMaker() {
getUniqueNameMaker(names: string[]) {
const localUsedNames = new Set();
function add(name: string) {
@ -407,6 +407,7 @@ export default class Generator {
reservedNames.forEach(add);
this.userVars.forEach(add);
names.forEach(add);
return (name: string) => {
if (test) name = `${name}$`;

@ -105,7 +105,7 @@ export default class Block {
this.hasOutroMethod = false;
this.outros = 0;
this.getUniqueName = this.generator.getUniqueNameMaker();
this.getUniqueName = this.generator.getUniqueNameMaker([...this.contexts.values()]);
this.variables = new Map();
this.aliases = new Map()

@ -48,33 +48,6 @@ export class DomGenerator extends Generator {
// initial values for e.g. window.innerWidth, if there's a <:Window> meta tag
this.metaBindings = [];
}
getUniqueNameMaker() {
const localUsedNames = new Set();
function add(name: string) {
localUsedNames.add(name);
}
reservedNames.forEach(add);
this.userVars.forEach(add);
for (const name in shared) {
localUsedNames.add(test ? `${name}$` : name);
}
return (name: string) => {
if (test) name = `${name}$`;
let alias = name;
for (
let i = 1;
this.usedNames.has(alias) ||
localUsedNames.has(alias);
alias = `${name}_${i++}`
);
localUsedNames.add(alias);
return alias;
};
}
}
export default function dom(

@ -0,0 +1,17 @@
export default {
html: `
<span>1</span>
<span>2</span>
`,
test(assert, component, target) {
component.set({
list: [3, 4]
});
assert.htmlEqual(target.innerHTML, `
<span>3</span>
<span>4</span>
`);
}
};

@ -0,0 +1,18 @@
{{#each list as nested}}
{{#if true}}
<Nested :nested/>
{{/if}}
{{/each}}
<script>
import Nested from './Nested.html';
export default {
data: () => ({
list: [1, 2]
}),
components: {
Nested
}
};
</script>
Loading…
Cancel
Save