From 3fa83e332fc75b5d55e5da6ddc5fe951e4b43e71 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Sat, 9 Dec 2017 17:32:02 -0500 Subject: [PATCH] rename _block to block --- src/generators/nodes/AwaitBlock.ts | 26 +++++------ src/generators/nodes/CatchBlock.ts | 3 +- src/generators/nodes/EachBlock.ts | 64 ++++++++++++++-------------- src/generators/nodes/ElseBlock.ts | 2 +- src/generators/nodes/IfBlock.ts | 44 +++++++++---------- src/generators/nodes/PendingBlock.ts | 2 +- src/generators/nodes/ThenBlock.ts | 3 +- 7 files changed, 71 insertions(+), 73 deletions(-) diff --git a/src/generators/nodes/AwaitBlock.ts b/src/generators/nodes/AwaitBlock.ts index 561dd2cbc4..61fa2f053e 100644 --- a/src/generators/nodes/AwaitBlock.ts +++ b/src/generators/nodes/AwaitBlock.ts @@ -39,7 +39,7 @@ export default class AwaitBlock extends Node { const contexts = new Map(block.contexts); contexts.set(arg, context); - child._block = block.child({ + child.block = block.child({ comment: createDebuggingComment(child, this.generator), name: this.generator.getUniqueName(`create_${status}_block`), params: block.params.concat(context), @@ -47,18 +47,18 @@ export default class AwaitBlock extends Node { contexts }); - child.initChildren(child._block, stripWhitespace, nextSibling); - this.generator.blocks.push(child._block); + child.initChildren(child.block, stripWhitespace, nextSibling); + this.generator.blocks.push(child.block); - if (child._block.dependencies.size > 0) { + if (child.block.dependencies.size > 0) { dynamic = true; - block.addDependencies(child._block.dependencies); + block.addDependencies(child.block.dependencies); } }); - this.pending._block.hasUpdateMethod = dynamic; - this.then._block.hasUpdateMethod = dynamic; - this.catch._block.hasUpdateMethod = dynamic; + this.pending.block.hasUpdateMethod = dynamic; + this.then.block.hasUpdateMethod = dynamic; + this.catch.block.hasUpdateMethod = dynamic; } build( @@ -86,9 +86,9 @@ export default class AwaitBlock extends Node { const old_block = block.getUniqueName(`old_block`); const value = block.getUniqueName(`value`); const error = block.getUniqueName(`error`); - const create_pending_block = this.pending._block.name; - const create_then_block = this.then._block.name; - const create_catch_block = this.catch._block.name; + const create_pending_block = this.pending.block.name; + const create_then_block = this.then.block.name; + const create_catch_block = this.catch.block.name; block.addVariable(await_block); block.addVariable(await_block_type); @@ -165,7 +165,7 @@ export default class AwaitBlock extends Node { `${handle_promise}(${promise}, ${params})` ); - if (this.pending._block.hasUpdateMethod) { + if (this.pending.block.hasUpdateMethod) { block.builders.update.addBlock(deindent` if (${conditions.join(' && ')}) { // nothing @@ -193,7 +193,7 @@ export default class AwaitBlock extends Node { [this.pending, this.then, this.catch].forEach(status => { status.children.forEach(child => { - child.build(status._block, null,'nodes'); + child.build(status.block, null,'nodes'); }); }); } diff --git a/src/generators/nodes/CatchBlock.ts b/src/generators/nodes/CatchBlock.ts index 4d1f270ea4..2ba5709eeb 100644 --- a/src/generators/nodes/CatchBlock.ts +++ b/src/generators/nodes/CatchBlock.ts @@ -2,7 +2,6 @@ import Node from './shared/Node'; import Block from '../dom/Block'; export default class CatchBlock extends Node { - _block: Block; - _state: State; + block: Block; children: Node[]; } \ No newline at end of file diff --git a/src/generators/nodes/EachBlock.ts b/src/generators/nodes/EachBlock.ts index 2782972ab8..574c9bb9cf 100644 --- a/src/generators/nodes/EachBlock.ts +++ b/src/generators/nodes/EachBlock.ts @@ -8,7 +8,7 @@ import createDebuggingComment from '../../utils/createDebuggingComment'; export default class EachBlock extends Node { type: 'EachBlock'; - _block: Block; + block: Block; expression: Node; iterations: string; @@ -62,7 +62,7 @@ export default class EachBlock extends Node { } } - this._block = block.child({ + this.block = block.child({ comment: createDebuggingComment(this, this.generator), name: this.generator.getUniqueName('create_each_block'), context: this.context, @@ -80,24 +80,24 @@ export default class EachBlock extends Node { params: block.params.concat(listName, context, indexName), }); - this.generator.blocks.push(this._block); - this.initChildren(this._block, stripWhitespace, nextSibling); - block.addDependencies(this._block.dependencies); - this._block.hasUpdateMethod = this._block.dependencies.size > 0; + this.generator.blocks.push(this.block); + this.initChildren(this.block, stripWhitespace, nextSibling); + block.addDependencies(this.block.dependencies); + this.block.hasUpdateMethod = this.block.dependencies.size > 0; if (this.else) { - this.else._block = block.child({ + this.else.block = block.child({ comment: '// TODO', // createDebuggingComment(this.else, generator), - name: this.generator.getUniqueName(`${this._block.name}_else`), + name: this.generator.getUniqueName(`${this.block.name}_else`), }); - this.generator.blocks.push(this.else._block); + this.generator.blocks.push(this.else.block); this.else.initChildren( - this.else._block, + this.else.block, stripWhitespace, nextSibling ); - this.else._block.hasUpdateMethod = this.else._block.dependencies.size > 0; + this.else.block.hasUpdateMethod = this.else.block.dependencies.size > 0; } } @@ -110,8 +110,8 @@ export default class EachBlock extends Node { const each = this.var; - const create_each_block = this._block.name; - const each_block_value = this._block.listName; + const create_each_block = this.block.name; + const each_block_value = this.block.listName; const iterations = this.iterations; const params = block.params.join(', '); @@ -127,7 +127,7 @@ export default class EachBlock extends Node { generator.code.overwrite(c, c + 4, 'length'); const length = `[✂${c}-${c+4}✂]`; - const mountOrIntro = this._block.hasIntroMethod ? 'i' : 'm'; + const mountOrIntro = this.block.hasIntroMethod ? 'i' : 'm'; const vars = { each, create_each_block, @@ -167,7 +167,7 @@ export default class EachBlock extends Node { // TODO neaten this up... will end up with an empty line in the block block.builders.init.addBlock(deindent` if (!${each_block_value}.${length}) { - ${each_block_else} = ${this.else._block.name}(${params}, #component); + ${each_block_else} = ${this.else.block.name}(${params}, #component); ${each_block_else}.c(); } `); @@ -180,12 +180,12 @@ export default class EachBlock extends Node { const initialMountNode = parentNode || `${anchor}.parentNode`; - if (this.else._block.hasUpdateMethod) { + if (this.else.block.hasUpdateMethod) { block.builders.update.addBlock(deindent` if (!${each_block_value}.${length} && ${each_block_else}) { ${each_block_else}.p( changed, ${params} ); } else if (!${each_block_value}.${length}) { - ${each_block_else} = ${this.else._block.name}(${params}, #component); + ${each_block_else} = ${this.else.block.name}(${params}, #component); ${each_block_else}.c(); ${each_block_else}.${mountOrIntro}(${initialMountNode}, ${anchor}); } else if (${each_block_else}) { @@ -203,7 +203,7 @@ export default class EachBlock extends Node { ${each_block_else} = null; } } else if (!${each_block_else}) { - ${each_block_else} = ${this.else._block.name}(${params}, #component); + ${each_block_else} = ${this.else.block.name}(${params}, #component); ${each_block_else}.c(); ${each_block_else}.${mountOrIntro}(${initialMountNode}, ${anchor}); } @@ -220,12 +220,12 @@ export default class EachBlock extends Node { } this.children.forEach((child: Node) => { - child.build(this._block, null, 'nodes'); + child.build(this.block, null, 'nodes'); }); if (this.else) { this.else.children.forEach((child: Node) => { - child.build(this.else._block, null, 'nodes'); + child.build(this.else.block, null, 'nodes'); }); } } @@ -258,11 +258,11 @@ export default class EachBlock extends Node { if (this.children[0] && this.children[0].type === 'Element') { // TODO or text/tag/raw - this._block.first = this.children[0].var; // TODO this is highly confusing + this.block.first = this.children[0].var; // TODO this is highly confusing } else { - this._block.first = this._block.getUniqueName('first'); - this._block.addElement( - this._block.first, + this.block.first = this.block.getUniqueName('first'); + this.block.addElement( + this.block.first, `@createComment()`, `@createComment()`, null @@ -310,10 +310,10 @@ export default class EachBlock extends Node { } `); - const dynamic = this._block.hasUpdateMethod; + const dynamic = this.block.hasUpdateMethod; let destroy; - if (this._block.hasOutroMethod) { + if (this.block.hasOutroMethod) { const fn = block.getUniqueName(`${each}_outro`); block.builders.init.addBlock(deindent` function ${fn}(iteration) { @@ -419,7 +419,7 @@ export default class EachBlock extends Node { if (${last}) ${last}.next = ${iteration}; ${iteration}.last = ${last}; - ${this._block.hasIntroMethod && `${iteration}.i(${updateMountNode}, ${anchor});`} + ${this.block.hasIntroMethod && `${iteration}.i(${updateMountNode}, ${anchor});`} ${last} = ${iteration}; } @@ -494,7 +494,7 @@ export default class EachBlock extends Node { } `); - const allDependencies = new Set(this._block.dependencies); + const allDependencies = new Set(this.block.dependencies); const { dependencies } = this.metadata; dependencies.forEach((dependency: string) => { allDependencies.add(dependency); @@ -506,8 +506,8 @@ export default class EachBlock extends Node { .join(' || '); if (condition !== '') { - const forLoopBody = this._block.hasUpdateMethod - ? this._block.hasIntroMethod + const forLoopBody = this.block.hasUpdateMethod + ? this.block.hasIntroMethod ? deindent` if (${iterations}[#i]) { ${iterations}[#i].p(changed, ${params}, ${each_block_value}, ${each_block_value}[#i], #i); @@ -532,10 +532,10 @@ export default class EachBlock extends Node { ${iterations}[#i].${mountOrIntro}(${updateMountNode}, ${anchor}); `; - const start = this._block.hasUpdateMethod ? '0' : `${iterations}.length`; + const start = this.block.hasUpdateMethod ? '0' : `${iterations}.length`; const outro = block.getUniqueName('outro'); - const destroy = this._block.hasOutroMethod + const destroy = this.block.hasOutroMethod ? deindent` function ${outro}(i) { if (${iterations}[i]) { diff --git a/src/generators/nodes/ElseBlock.ts b/src/generators/nodes/ElseBlock.ts index 3d5a125770..0a48881fbb 100644 --- a/src/generators/nodes/ElseBlock.ts +++ b/src/generators/nodes/ElseBlock.ts @@ -4,5 +4,5 @@ import Block from '../dom/Block'; export default class ElseBlock extends Node { type: 'ElseBlock'; children: Node[]; - _block: Block; + block: Block; } \ No newline at end of file diff --git a/src/generators/nodes/IfBlock.ts b/src/generators/nodes/IfBlock.ts index 2f06440b47..b3978e5356 100644 --- a/src/generators/nodes/IfBlock.ts +++ b/src/generators/nodes/IfBlock.ts @@ -19,7 +19,7 @@ export default class IfBlock extends Node { type: 'IfBlock'; else: ElseBlock; - _block: Block; + block: Block; init( block: Block, @@ -40,40 +40,40 @@ export default class IfBlock extends Node { block.addDependencies(node.metadata.dependencies); - node._block = block.child({ + node.block = block.child({ comment: createDebuggingComment(node, generator), name: generator.getUniqueName(`create_if_block`), }); - blocks.push(node._block); - node.initChildren(node._block, stripWhitespace, nextSibling); + blocks.push(node.block); + node.initChildren(node.block, stripWhitespace, nextSibling); - if (node._block.dependencies.size > 0) { + if (node.block.dependencies.size > 0) { dynamic = true; - block.addDependencies(node._block.dependencies); + block.addDependencies(node.block.dependencies); } - if (node._block.hasIntroMethod) hasIntros = true; - if (node._block.hasOutroMethod) hasOutros = true; + if (node.block.hasIntroMethod) hasIntros = true; + if (node.block.hasOutroMethod) hasOutros = true; if (isElseIf(node.else)) { attachBlocks(node.else.children[0]); } else if (node.else) { - node.else._block = block.child({ + node.else.block = block.child({ comment: createDebuggingComment(node.else, generator), name: generator.getUniqueName(`create_if_block`), }); - blocks.push(node.else._block); + blocks.push(node.else.block); node.else.initChildren( - node.else._block, + node.else.block, stripWhitespace, nextSibling ); - if (node.else._block.dependencies.size > 0) { + if (node.else.block.dependencies.size > 0) { dynamic = true; - block.addDependencies(node.else._block.dependencies); + block.addDependencies(node.else.block.dependencies); } } } @@ -166,10 +166,10 @@ function getBranches( const branches = [ { condition: node.metadata.snippet, - block: node._block.name, - hasUpdateMethod: node._block.hasUpdateMethod, - hasIntroMethod: node._block.hasIntroMethod, - hasOutroMethod: node._block.hasOutroMethod, + block: node.block.name, + hasUpdateMethod: node.block.hasUpdateMethod, + hasIntroMethod: node.block.hasIntroMethod, + hasOutroMethod: node.block.hasOutroMethod, }, ]; @@ -182,10 +182,10 @@ function getBranches( } else { branches.push({ condition: null, - block: node.else ? node.else._block.name : null, - hasUpdateMethod: node.else ? node.else._block.hasUpdateMethod : false, - hasIntroMethod: node.else ? node.else._block.hasIntroMethod : false, - hasOutroMethod: node.else ? node.else._block.hasOutroMethod : false, + block: node.else ? node.else.block.name : null, + hasUpdateMethod: node.else ? node.else.block.hasUpdateMethod : false, + hasIntroMethod: node.else ? node.else.block.hasIntroMethod : false, + hasOutroMethod: node.else ? node.else.block.hasOutroMethod : false, }); if (node.else) { @@ -202,7 +202,7 @@ function visitChildren( node: Node ) { node.children.forEach((child: Node) => { - child.build(node._block, null, 'nodes'); + child.build(node.block, null, 'nodes'); }); } diff --git a/src/generators/nodes/PendingBlock.ts b/src/generators/nodes/PendingBlock.ts index ddb8ba5260..fc7a3dd1c0 100644 --- a/src/generators/nodes/PendingBlock.ts +++ b/src/generators/nodes/PendingBlock.ts @@ -2,6 +2,6 @@ import Node from './shared/Node'; import Block from '../dom/Block'; export default class PendingBlock extends Node { - _block: Block; + block: Block; children: Node[]; } \ No newline at end of file diff --git a/src/generators/nodes/ThenBlock.ts b/src/generators/nodes/ThenBlock.ts index f1c529c5f5..d7d8cedc03 100644 --- a/src/generators/nodes/ThenBlock.ts +++ b/src/generators/nodes/ThenBlock.ts @@ -2,7 +2,6 @@ import Node from './shared/Node'; import Block from '../dom/Block'; export default class ThenBlock extends Node { - _block: Block; - _state: State; + block: Block; children: Node[]; } \ No newline at end of file