mirror of https://github.com/sveltejs/svelte
deconflict names. fixes #88
parent
0e64f26712
commit
659eb32bc5
@ -1,12 +1,14 @@
|
||||
export default function counter () {
|
||||
export default function counter ( used ) {
|
||||
const counts = {};
|
||||
|
||||
return function ( label ) {
|
||||
if ( label in counts ) {
|
||||
return `${label}${counts[ label ]++}`;
|
||||
used.forEach( name => counts[ name ] = 1 );
|
||||
|
||||
return function ( name ) {
|
||||
if ( name in counts ) {
|
||||
return `${name}${counts[ name ]++}`;
|
||||
}
|
||||
|
||||
counts[ label ] = 1;
|
||||
return label;
|
||||
counts[ name ] = 1;
|
||||
return name;
|
||||
};
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
export default {
|
||||
enter ( generator, node ) {
|
||||
const name = generator.current.counter( `text` );
|
||||
const name = generator.current.getUniqueName( `text` );
|
||||
generator.addElement( name, `document.createTextNode( ${JSON.stringify( node.data )} )` );
|
||||
}
|
||||
};
|
||||
|
@ -0,0 +1 @@
|
||||
<p>{{index + 1}}: {{widget.name}}</p>
|
@ -0,0 +1,14 @@
|
||||
export default {
|
||||
html: `<p>1: foo</p><p>2: bar</p><p>3: baz</p>`,
|
||||
|
||||
test ( assert, component, target ) {
|
||||
component.set({
|
||||
widgets: [
|
||||
{ name: 'bish' },
|
||||
{ name: 'bosh' }
|
||||
]
|
||||
});
|
||||
|
||||
assert.htmlEqual( target.innerHTML, `<p>1: bish</p><p>2: bosh</p>` );
|
||||
}
|
||||
};
|
@ -0,0 +1,21 @@
|
||||
{{#each widgets as widget, i}}
|
||||
<Widget widget='{{widget}}' index='{{i}}'/>
|
||||
{{/each}}
|
||||
|
||||
<script>
|
||||
import Widget from './Widget.html';
|
||||
|
||||
export default {
|
||||
data () {
|
||||
return {
|
||||
widgets: [
|
||||
{ name: 'foo' },
|
||||
{ name: 'bar' },
|
||||
{ name: 'baz' }
|
||||
]
|
||||
};
|
||||
},
|
||||
|
||||
components: { Widget }
|
||||
};
|
||||
</script>
|
Loading…
Reference in new issue