diff --git a/src/parse/read/context.ts b/src/parse/read/context.ts index feb31d150e..3ab18695bd 100644 --- a/src/parse/read/context.ts +++ b/src/parse/read/context.ts @@ -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); diff --git a/src/utils/unpackDestructuring.ts b/src/utils/unpackDestructuring.ts index 2c48d5c762..749d26b34b 100644 --- a/src/utils/unpackDestructuring.ts +++ b/src/utils/unpackDestructuring.ts @@ -3,6 +3,8 @@ export default function unpackDestructuring( node: Node, tail: string ) { + if (!node) return; + if (node.type === 'Identifier') { contexts.push({ key: node, diff --git a/test/runtime/samples/each-block-destructured-array-sparse/_config.js b/test/runtime/samples/each-block-destructured-array-sparse/_config.js new file mode 100644 index 0000000000..f504cfe377 --- /dev/null +++ b/test/runtime/samples/each-block-destructured-array-sparse/_config.js @@ -0,0 +1,20 @@ +export default { + data: { + animalPawsEntries: [ + ['raccoon', 'hands'], + ['eagle', 'wings'] + ] + }, + + html: ` +
hands
+wings
+ `, + + test ( assert, component, target ) { + component.set({ animalPawsEntries: [['foo', 'bar']] }); + assert.htmlEqual( target.innerHTML, ` +bar
+ `); + }, +}; diff --git a/test/runtime/samples/each-block-destructured-array-sparse/main.html b/test/runtime/samples/each-block-destructured-array-sparse/main.html new file mode 100644 index 0000000000..7ca8e403d8 --- /dev/null +++ b/test/runtime/samples/each-block-destructured-array-sparse/main.html @@ -0,0 +1,3 @@ +{#each animalPawsEntries as [, pawType]} +{pawType}
+{/each}