Skip to content

Commit

Permalink
Merge pull request #897 from jacobmischka/destructure-each-updates
Browse files Browse the repository at this point in the history
Destructure each updates
  • Loading branch information
Rich-Harris authored Oct 20, 2017
2 parents bc88471 + f0aea9b commit b1e1c5c
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 13 deletions.
13 changes: 7 additions & 6 deletions src/generators/dom/preprocess.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,12 +229,6 @@ const preprocessors = {
const contexts = new Map(block.contexts);
contexts.set(node.context, context);

if (node.destructuredContexts) {
for (const i = 0; i < node.destructuredContexts.length; i++) {
contexts.set(node.destructuredContexts[i], `${context}[${i}]`);
}
}

const indexes = new Map(block.indexes);
if (node.index) indexes.set(node.index, node.context);

Expand All @@ -244,6 +238,13 @@ const preprocessors = {
const contextDependencies = new Map(block.contextDependencies);
contextDependencies.set(node.context, dependencies);

if (node.destructuredContexts) {
for (const i = 0; i < node.destructuredContexts.length; i++) {
contexts.set(node.destructuredContexts[i], `${context}[${i}]`);
contextDependencies.set(node.destructuredContexts[i], dependencies);
}
}

node._block = block.child({
comment: createDebuggingComment(node, generator),
name: generator.getUniqueName('create_each_block'),
Expand Down
13 changes: 7 additions & 6 deletions src/generators/server-side-rendering/visitors/EachBlock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,19 @@ export default function visitEachBlock(
const contexts = new Map(block.contexts);
contexts.set(node.context, node.context);

if (node.destructuredContexts) {
for (const i = 0; i < node.destructuredContexts.length; i++) {
contexts.set(node.destructuredContexts[i], `${node.context}[${i}]`);
}
}

const indexes = new Map(block.indexes);
if (node.index) indexes.set(node.index, node.context);

const contextDependencies = new Map(block.contextDependencies);
contextDependencies.set(node.context, dependencies);

if (node.destructuredContexts) {
for (const i = 0; i < node.destructuredContexts.length; i++) {
contexts.set(node.destructuredContexts[i], `${node.context}[${i}]`);
contextDependencies.set(node.destructuredContexts[i], dependencies);
}
}

const childBlock = block.child({
contexts,
indexes,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,12 @@ export default {
html: `
<p>raccoon: hands</p>
<p>eagle: wings</p>
`
`,

test ( assert, component, target ) {
component.set({ animalPawsEntries: [['foo', 'bar']] });
assert.htmlEqual( target.innerHTML, `
<p>foo: bar</p>
`);
},
};

0 comments on commit b1e1c5c

Please sign in to comment.