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

sparse array patterns

This commit is contained in:
Rich Harris 2018-04-29 17:08:24 -04:00
parent ffe91846f0
commit 9607593705
4 changed files with 32 additions and 2 deletions

View File

@ -46,8 +46,13 @@ export default function readContext(parser: Parser) {
do {
parser.allowWhitespace();
context.elements.push(readContext(parser));
parser.allowWhitespace();
if (parser.template[parser.index] === ',') {
context.elements.push(null);
} else {
context.elements.push(readContext(parser));
parser.allowWhitespace();
}
} while (parser.eat(','));
errorOnAssignmentPattern(parser);

View File

@ -3,6 +3,8 @@ export default function unpackDestructuring(
node: Node,
tail: string
) {
if (!node) return;
if (node.type === 'Identifier') {
contexts.push({
key: node,

View File

@ -0,0 +1,20 @@
export default {
data: {
animalPawsEntries: [
['raccoon', 'hands'],
['eagle', 'wings']
]
},
html: `
<p>hands</p>
<p>wings</p>
`,
test ( assert, component, target ) {
component.set({ animalPawsEntries: [['foo', 'bar']] });
assert.htmlEqual( target.innerHTML, `
<p>bar</p>
`);
},
};

View File

@ -0,0 +1,3 @@
{#each animalPawsEntries as [, pawType]}
<p>{pawType}</p>
{/each}