|
|
@ -34,67 +34,57 @@ export default class EachBlock extends Node {
|
|
|
|
const { dependencies } = this.metadata;
|
|
|
|
const { dependencies } = this.metadata;
|
|
|
|
block.addDependencies(dependencies);
|
|
|
|
block.addDependencies(dependencies);
|
|
|
|
|
|
|
|
|
|
|
|
const indexNames = new Map(block.indexNames);
|
|
|
|
|
|
|
|
const indexName = this.index || `${this.context}_index`;
|
|
|
|
|
|
|
|
indexNames.set(this.context, indexName);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const listNames = new Map(block.listNames);
|
|
|
|
|
|
|
|
const listName = (
|
|
|
|
|
|
|
|
(this.expression.type === 'MemberExpression' && !this.expression.computed) ? this.expression.property.name :
|
|
|
|
|
|
|
|
this.expression.type === 'Identifier' ? this.expression.name :
|
|
|
|
|
|
|
|
`each_value`
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
listNames.set(this.context, listName);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const contextTypes = new Map(block.contextTypes);
|
|
|
|
|
|
|
|
contextTypes.set(this.context, 'each');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const context = this.context;
|
|
|
|
|
|
|
|
const contexts = new Map(block.contexts);
|
|
|
|
|
|
|
|
contexts.set(this.context, context); // TODO this is now redundant
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const indexes = new Map(block.indexes);
|
|
|
|
|
|
|
|
if (this.index) indexes.set(this.index, this.context);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const changeableIndexes = new Map(block.changeableIndexes);
|
|
|
|
|
|
|
|
if (this.index) changeableIndexes.set(this.index, this.key);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (this.destructuredContexts) {
|
|
|
|
|
|
|
|
for (let i = 0; i < this.destructuredContexts.length; i += 1) {
|
|
|
|
|
|
|
|
contexts.set(this.destructuredContexts[i], `${context}[${i}]`);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.block = block.child({
|
|
|
|
this.block = block.child({
|
|
|
|
comment: createDebuggingComment(this, this.generator),
|
|
|
|
comment: createDebuggingComment(this, this.generator),
|
|
|
|
name: this.generator.getUniqueName('create_each_block'),
|
|
|
|
name: this.generator.getUniqueName('create_each_block'),
|
|
|
|
context: this.context,
|
|
|
|
context: this.context,
|
|
|
|
key: this.key,
|
|
|
|
key: this.key,
|
|
|
|
|
|
|
|
|
|
|
|
contexts,
|
|
|
|
contexts: new Map(block.contexts),
|
|
|
|
contextTypes,
|
|
|
|
contextTypes: new Map(block.contextTypes),
|
|
|
|
indexes,
|
|
|
|
indexes: new Map(block.indexes),
|
|
|
|
changeableIndexes,
|
|
|
|
changeableIndexes: new Map(block.changeableIndexes),
|
|
|
|
|
|
|
|
|
|
|
|
listName,
|
|
|
|
listName: (
|
|
|
|
indexName,
|
|
|
|
(this.expression.type === 'MemberExpression' && !this.expression.computed) ? this.expression.property.name :
|
|
|
|
|
|
|
|
this.expression.type === 'Identifier' ? this.expression.name :
|
|
|
|
|
|
|
|
`each_value`
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
indexName: this.index || `${this.context}_index`,
|
|
|
|
|
|
|
|
|
|
|
|
indexNames,
|
|
|
|
indexNames: new Map(block.indexNames),
|
|
|
|
listNames
|
|
|
|
listNames: new Map(block.listNames)
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
this.contextProps = [
|
|
|
|
this.block.contextTypes.set(this.context, 'each');
|
|
|
|
`${context}: ${listName}[#i]`,
|
|
|
|
this.block.indexNames.set(this.context, this.block.indexName);
|
|
|
|
`${indexName}: #i`
|
|
|
|
this.block.listNames.set(this.context, this.block.listName);
|
|
|
|
];
|
|
|
|
if (this.index) {
|
|
|
|
|
|
|
|
this.block.indexes.set(this.index, this.context);
|
|
|
|
|
|
|
|
this.block.changeableIndexes.set(this.index, this.key)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const context = this.block.getUniqueName(this.context);
|
|
|
|
|
|
|
|
this.block.contexts.set(this.context, context); // TODO this is now redundant?
|
|
|
|
|
|
|
|
|
|
|
|
if (this.destructuredContexts) {
|
|
|
|
if (this.destructuredContexts) {
|
|
|
|
for (let i = 0; i < this.destructuredContexts.length; i += 1) {
|
|
|
|
for (let i = 0; i < this.destructuredContexts.length; i += 1) {
|
|
|
|
contexts.set(this.destructuredContexts[i], `${context}[${i}]`);
|
|
|
|
this.block.contexts.set(this.destructuredContexts[i], `${context}[${i}]`);
|
|
|
|
this.contextProps.push(`${this.destructuredContexts[i]}: ${listName}[#i][${i}]`);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.contextProps = [
|
|
|
|
|
|
|
|
`${this.context}: ${this.block.listName}[#i]`,
|
|
|
|
|
|
|
|
`${this.block.indexName}: #i`
|
|
|
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// if (this.destructuredContexts) {
|
|
|
|
|
|
|
|
// for (let i = 0; i < this.destructuredContexts.length; i += 1) {
|
|
|
|
|
|
|
|
// contexts.set(this.destructuredContexts[i], `${context}[${i}]`);
|
|
|
|
|
|
|
|
// this.contextProps.push(`${this.destructuredContexts[i]}: ${this.block.listName}[#i][${i}]`);
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
this.generator.blocks.push(this.block);
|
|
|
|
this.generator.blocks.push(this.block);
|
|
|
|
this.initChildren(this.block, stripWhitespace, nextSibling);
|
|
|
|
this.initChildren(this.block, stripWhitespace, nextSibling);
|
|
|
|
block.addDependencies(this.block.dependencies);
|
|
|
|
block.addDependencies(this.block.dependencies);
|
|
|
|