rename _block to block

pull/992/head
Rich Harris 8 years ago
parent ea418cd306
commit 3fa83e332f

@ -39,7 +39,7 @@ export default class AwaitBlock extends Node {
const contexts = new Map(block.contexts); const contexts = new Map(block.contexts);
contexts.set(arg, context); contexts.set(arg, context);
child._block = block.child({ child.block = block.child({
comment: createDebuggingComment(child, this.generator), comment: createDebuggingComment(child, this.generator),
name: this.generator.getUniqueName(`create_${status}_block`), name: this.generator.getUniqueName(`create_${status}_block`),
params: block.params.concat(context), params: block.params.concat(context),
@ -47,18 +47,18 @@ export default class AwaitBlock extends Node {
contexts contexts
}); });
child.initChildren(child._block, stripWhitespace, nextSibling); child.initChildren(child.block, stripWhitespace, nextSibling);
this.generator.blocks.push(child._block); this.generator.blocks.push(child.block);
if (child._block.dependencies.size > 0) { if (child.block.dependencies.size > 0) {
dynamic = true; dynamic = true;
block.addDependencies(child._block.dependencies); block.addDependencies(child.block.dependencies);
} }
}); });
this.pending._block.hasUpdateMethod = dynamic; this.pending.block.hasUpdateMethod = dynamic;
this.then._block.hasUpdateMethod = dynamic; this.then.block.hasUpdateMethod = dynamic;
this.catch._block.hasUpdateMethod = dynamic; this.catch.block.hasUpdateMethod = dynamic;
} }
build( build(
@ -86,9 +86,9 @@ export default class AwaitBlock extends Node {
const old_block = block.getUniqueName(`old_block`); const old_block = block.getUniqueName(`old_block`);
const value = block.getUniqueName(`value`); const value = block.getUniqueName(`value`);
const error = block.getUniqueName(`error`); const error = block.getUniqueName(`error`);
const create_pending_block = this.pending._block.name; const create_pending_block = this.pending.block.name;
const create_then_block = this.then._block.name; const create_then_block = this.then.block.name;
const create_catch_block = this.catch._block.name; const create_catch_block = this.catch.block.name;
block.addVariable(await_block); block.addVariable(await_block);
block.addVariable(await_block_type); block.addVariable(await_block_type);
@ -165,7 +165,7 @@ export default class AwaitBlock extends Node {
`${handle_promise}(${promise}, ${params})` `${handle_promise}(${promise}, ${params})`
); );
if (this.pending._block.hasUpdateMethod) { if (this.pending.block.hasUpdateMethod) {
block.builders.update.addBlock(deindent` block.builders.update.addBlock(deindent`
if (${conditions.join(' && ')}) { if (${conditions.join(' && ')}) {
// nothing // nothing
@ -193,7 +193,7 @@ export default class AwaitBlock extends Node {
[this.pending, this.then, this.catch].forEach(status => { [this.pending, this.then, this.catch].forEach(status => {
status.children.forEach(child => { status.children.forEach(child => {
child.build(status._block, null,'nodes'); child.build(status.block, null,'nodes');
}); });
}); });
} }

@ -2,7 +2,6 @@ import Node from './shared/Node';
import Block from '../dom/Block'; import Block from '../dom/Block';
export default class CatchBlock extends Node { export default class CatchBlock extends Node {
_block: Block; block: Block;
_state: State;
children: Node[]; children: Node[];
} }

@ -8,7 +8,7 @@ import createDebuggingComment from '../../utils/createDebuggingComment';
export default class EachBlock extends Node { export default class EachBlock extends Node {
type: 'EachBlock'; type: 'EachBlock';
_block: Block; block: Block;
expression: Node; expression: Node;
iterations: string; 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), 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,
@ -80,24 +80,24 @@ export default class EachBlock extends Node {
params: block.params.concat(listName, context, indexName), params: block.params.concat(listName, context, indexName),
}); });
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);
this._block.hasUpdateMethod = this._block.dependencies.size > 0; this.block.hasUpdateMethod = this.block.dependencies.size > 0;
if (this.else) { if (this.else) {
this.else._block = block.child({ this.else.block = block.child({
comment: '// TODO', // createDebuggingComment(this.else, generator), 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.initChildren(
this.else._block, this.else.block,
stripWhitespace, stripWhitespace,
nextSibling 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 each = this.var;
const create_each_block = this._block.name; const create_each_block = this.block.name;
const each_block_value = this._block.listName; const each_block_value = this.block.listName;
const iterations = this.iterations; const iterations = this.iterations;
const params = block.params.join(', '); const params = block.params.join(', ');
@ -127,7 +127,7 @@ export default class EachBlock extends Node {
generator.code.overwrite(c, c + 4, 'length'); generator.code.overwrite(c, c + 4, 'length');
const length = `[✂${c}-${c+4}✂]`; const length = `[✂${c}-${c+4}✂]`;
const mountOrIntro = this._block.hasIntroMethod ? 'i' : 'm'; const mountOrIntro = this.block.hasIntroMethod ? 'i' : 'm';
const vars = { const vars = {
each, each,
create_each_block, 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 // TODO neaten this up... will end up with an empty line in the block
block.builders.init.addBlock(deindent` block.builders.init.addBlock(deindent`
if (!${each_block_value}.${length}) { 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}.c();
} }
`); `);
@ -180,12 +180,12 @@ export default class EachBlock extends Node {
const initialMountNode = parentNode || `${anchor}.parentNode`; const initialMountNode = parentNode || `${anchor}.parentNode`;
if (this.else._block.hasUpdateMethod) { if (this.else.block.hasUpdateMethod) {
block.builders.update.addBlock(deindent` block.builders.update.addBlock(deindent`
if (!${each_block_value}.${length} && ${each_block_else}) { if (!${each_block_value}.${length} && ${each_block_else}) {
${each_block_else}.p( changed, ${params} ); ${each_block_else}.p( changed, ${params} );
} else if (!${each_block_value}.${length}) { } 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}.c();
${each_block_else}.${mountOrIntro}(${initialMountNode}, ${anchor}); ${each_block_else}.${mountOrIntro}(${initialMountNode}, ${anchor});
} else if (${each_block_else}) { } else if (${each_block_else}) {
@ -203,7 +203,7 @@ export default class EachBlock extends Node {
${each_block_else} = null; ${each_block_else} = null;
} }
} else if (!${each_block_else}) { } 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}.c();
${each_block_else}.${mountOrIntro}(${initialMountNode}, ${anchor}); ${each_block_else}.${mountOrIntro}(${initialMountNode}, ${anchor});
} }
@ -220,12 +220,12 @@ export default class EachBlock extends Node {
} }
this.children.forEach((child: Node) => { this.children.forEach((child: Node) => {
child.build(this._block, null, 'nodes'); child.build(this.block, null, 'nodes');
}); });
if (this.else) { if (this.else) {
this.else.children.forEach((child: Node) => { 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') { if (this.children[0] && this.children[0].type === 'Element') {
// TODO or text/tag/raw // 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 { } else {
this._block.first = this._block.getUniqueName('first'); this.block.first = this.block.getUniqueName('first');
this._block.addElement( this.block.addElement(
this._block.first, this.block.first,
`@createComment()`, `@createComment()`,
`@createComment()`, `@createComment()`,
null null
@ -310,10 +310,10 @@ export default class EachBlock extends Node {
} }
`); `);
const dynamic = this._block.hasUpdateMethod; const dynamic = this.block.hasUpdateMethod;
let destroy; let destroy;
if (this._block.hasOutroMethod) { if (this.block.hasOutroMethod) {
const fn = block.getUniqueName(`${each}_outro`); const fn = block.getUniqueName(`${each}_outro`);
block.builders.init.addBlock(deindent` block.builders.init.addBlock(deindent`
function ${fn}(iteration) { function ${fn}(iteration) {
@ -419,7 +419,7 @@ export default class EachBlock extends Node {
if (${last}) ${last}.next = ${iteration}; if (${last}) ${last}.next = ${iteration};
${iteration}.last = ${last}; ${iteration}.last = ${last};
${this._block.hasIntroMethod && `${iteration}.i(${updateMountNode}, ${anchor});`} ${this.block.hasIntroMethod && `${iteration}.i(${updateMountNode}, ${anchor});`}
${last} = ${iteration}; ${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; const { dependencies } = this.metadata;
dependencies.forEach((dependency: string) => { dependencies.forEach((dependency: string) => {
allDependencies.add(dependency); allDependencies.add(dependency);
@ -506,8 +506,8 @@ export default class EachBlock extends Node {
.join(' || '); .join(' || ');
if (condition !== '') { if (condition !== '') {
const forLoopBody = this._block.hasUpdateMethod const forLoopBody = this.block.hasUpdateMethod
? this._block.hasIntroMethod ? this.block.hasIntroMethod
? deindent` ? deindent`
if (${iterations}[#i]) { if (${iterations}[#i]) {
${iterations}[#i].p(changed, ${params}, ${each_block_value}, ${each_block_value}[#i], #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}); ${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 outro = block.getUniqueName('outro');
const destroy = this._block.hasOutroMethod const destroy = this.block.hasOutroMethod
? deindent` ? deindent`
function ${outro}(i) { function ${outro}(i) {
if (${iterations}[i]) { if (${iterations}[i]) {

@ -4,5 +4,5 @@ import Block from '../dom/Block';
export default class ElseBlock extends Node { export default class ElseBlock extends Node {
type: 'ElseBlock'; type: 'ElseBlock';
children: Node[]; children: Node[];
_block: Block; block: Block;
} }

@ -19,7 +19,7 @@ export default class IfBlock extends Node {
type: 'IfBlock'; type: 'IfBlock';
else: ElseBlock; else: ElseBlock;
_block: Block; block: Block;
init( init(
block: Block, block: Block,
@ -40,40 +40,40 @@ export default class IfBlock extends Node {
block.addDependencies(node.metadata.dependencies); block.addDependencies(node.metadata.dependencies);
node._block = block.child({ node.block = block.child({
comment: createDebuggingComment(node, generator), comment: createDebuggingComment(node, generator),
name: generator.getUniqueName(`create_if_block`), name: generator.getUniqueName(`create_if_block`),
}); });
blocks.push(node._block); blocks.push(node.block);
node.initChildren(node._block, stripWhitespace, nextSibling); node.initChildren(node.block, stripWhitespace, nextSibling);
if (node._block.dependencies.size > 0) { if (node.block.dependencies.size > 0) {
dynamic = true; dynamic = true;
block.addDependencies(node._block.dependencies); block.addDependencies(node.block.dependencies);
} }
if (node._block.hasIntroMethod) hasIntros = true; if (node.block.hasIntroMethod) hasIntros = true;
if (node._block.hasOutroMethod) hasOutros = true; if (node.block.hasOutroMethod) hasOutros = true;
if (isElseIf(node.else)) { if (isElseIf(node.else)) {
attachBlocks(node.else.children[0]); attachBlocks(node.else.children[0]);
} else if (node.else) { } else if (node.else) {
node.else._block = block.child({ node.else.block = block.child({
comment: createDebuggingComment(node.else, generator), comment: createDebuggingComment(node.else, generator),
name: generator.getUniqueName(`create_if_block`), name: generator.getUniqueName(`create_if_block`),
}); });
blocks.push(node.else._block); blocks.push(node.else.block);
node.else.initChildren( node.else.initChildren(
node.else._block, node.else.block,
stripWhitespace, stripWhitespace,
nextSibling nextSibling
); );
if (node.else._block.dependencies.size > 0) { if (node.else.block.dependencies.size > 0) {
dynamic = true; dynamic = true;
block.addDependencies(node.else._block.dependencies); block.addDependencies(node.else.block.dependencies);
} }
} }
} }
@ -166,10 +166,10 @@ function getBranches(
const branches = [ const branches = [
{ {
condition: node.metadata.snippet, condition: node.metadata.snippet,
block: node._block.name, block: node.block.name,
hasUpdateMethod: node._block.hasUpdateMethod, hasUpdateMethod: node.block.hasUpdateMethod,
hasIntroMethod: node._block.hasIntroMethod, hasIntroMethod: node.block.hasIntroMethod,
hasOutroMethod: node._block.hasOutroMethod, hasOutroMethod: node.block.hasOutroMethod,
}, },
]; ];
@ -182,10 +182,10 @@ function getBranches(
} else { } else {
branches.push({ branches.push({
condition: null, condition: null,
block: node.else ? node.else._block.name : null, block: node.else ? node.else.block.name : null,
hasUpdateMethod: node.else ? node.else._block.hasUpdateMethod : false, hasUpdateMethod: node.else ? node.else.block.hasUpdateMethod : false,
hasIntroMethod: node.else ? node.else._block.hasIntroMethod : false, hasIntroMethod: node.else ? node.else.block.hasIntroMethod : false,
hasOutroMethod: node.else ? node.else._block.hasOutroMethod : false, hasOutroMethod: node.else ? node.else.block.hasOutroMethod : false,
}); });
if (node.else) { if (node.else) {
@ -202,7 +202,7 @@ function visitChildren(
node: Node node: Node
) { ) {
node.children.forEach((child: Node) => { node.children.forEach((child: Node) => {
child.build(node._block, null, 'nodes'); child.build(node.block, null, 'nodes');
}); });
} }

@ -2,6 +2,6 @@ import Node from './shared/Node';
import Block from '../dom/Block'; import Block from '../dom/Block';
export default class PendingBlock extends Node { export default class PendingBlock extends Node {
_block: Block; block: Block;
children: Node[]; children: Node[];
} }

@ -2,7 +2,6 @@ import Node from './shared/Node';
import Block from '../dom/Block'; import Block from '../dom/Block';
export default class ThenBlock extends Node { export default class ThenBlock extends Node {
_block: Block; block: Block;
_state: State;
children: Node[]; children: Node[];
} }
Loading…
Cancel
Save