From 6e9f9633b0ecd0477fa8909a826a77e161586086 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Wed, 30 Aug 2017 11:31:58 -0400 Subject: [PATCH] set all node.var names in preprocess --- src/generators/dom/interfaces.ts | 3 --- src/generators/dom/preprocess.ts | 14 +++++++++----- src/generators/dom/visitors/EachBlock.ts | 3 ++- src/generators/dom/visitors/IfBlock.ts | 2 +- 4 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/generators/dom/interfaces.ts b/src/generators/dom/interfaces.ts index 37dc449d1d..a925fb1b91 100644 --- a/src/generators/dom/interfaces.ts +++ b/src/generators/dom/interfaces.ts @@ -3,13 +3,10 @@ import Block from './Block'; import { Node } from '../../interfaces'; export interface State { - name?: string; namespace: string; parentNode: string; parentNodes: string; - isTopLevel: boolean; parentNodeName?: string; - basename?: string; inEachBlock?: boolean; allUsedContexts?: string[]; usesComponent?: boolean; diff --git a/src/generators/dom/preprocess.ts b/src/generators/dom/preprocess.ts index 0ac58adfa8..3aa78249c3 100644 --- a/src/generators/dom/preprocess.ts +++ b/src/generators/dom/preprocess.ts @@ -16,7 +16,7 @@ function getChildState(parent: State, child = {}) { return assign( {}, parent, - { name: null, parentNode: null, parentNodes: 'nodes' }, + { parentNode: null, parentNodes: 'nodes' }, child || {} ); } @@ -45,10 +45,10 @@ const preprocessors = { componentStack: Node[], stripWhitespace: boolean ) => { + node.var = block.getUniqueName('text'); + const dependencies = block.findDependencies(node.expression); block.addDependencies(dependencies); - - node.var = block.getUniqueName('text'); }, RawMustacheTag: ( @@ -60,10 +60,10 @@ const preprocessors = { componentStack: Node[], stripWhitespace: boolean ) => { + node.var = block.getUniqueName('raw'); + const dependencies = block.findDependencies(node.expression); block.addDependencies(dependencies); - - node.var = block.getUniqueName('raw'); }, Text: ( @@ -100,6 +100,8 @@ const preprocessors = { let hasOutros = false; function attachBlocks(node: Node) { + node.var = block.getUniqueName(`if_block`); + const dependencies = block.findDependencies(node.expression); block.addDependencies(dependencies); @@ -171,6 +173,8 @@ const preprocessors = { stripWhitespace: boolean, nextSibling: Node ) => { + node.var = block.getUniqueName(`each_block`); + const dependencies = block.findDependencies(node.expression); block.addDependencies(dependencies); diff --git a/src/generators/dom/visitors/EachBlock.ts b/src/generators/dom/visitors/EachBlock.ts index 7796f2414c..0c769f2e78 100644 --- a/src/generators/dom/visitors/EachBlock.ts +++ b/src/generators/dom/visitors/EachBlock.ts @@ -14,7 +14,8 @@ export default function visitEachBlock( elementStack: Node[], componentStack: Node[] ) { - const each_block = generator.getUniqueName(`each_block`); + const each_block = node.var; + const create_each_block = node._block.name; const each_block_value = node._block.listName; const iterations = block.getUniqueName(`${each_block}_iterations`); diff --git a/src/generators/dom/visitors/IfBlock.ts b/src/generators/dom/visitors/IfBlock.ts index 3ce27599ff..97747b0083 100644 --- a/src/generators/dom/visitors/IfBlock.ts +++ b/src/generators/dom/visitors/IfBlock.ts @@ -78,7 +78,7 @@ export default function visitIfBlock( elementStack: Node[], componentStack: Node[] ) { - const name = generator.getUniqueName(`if_block`); + const name = node.var; const needsAnchor = node.next ? !isDomNode(node.next) : !state.parentNode; const anchor = needsAnchor