dont create context for pending block

pull/1173/head
Rich Harris 7 years ago
parent 27f6d560b5
commit ec488fe347

@ -246,7 +246,6 @@ export default class Generator {
if (contextName !== name) { if (contextName !== name) {
// this is true for 'reserved' names like `state` and `component`, // this is true for 'reserved' names like `state` and `component`,
// also destructured contexts // also destructured contexts
code.overwrite( code.overwrite(
node.start, node.start,
node.start + name.length, node.start + name.length,

@ -35,21 +35,19 @@ export default class AwaitBlock extends Node {
].forEach(([status, arg]) => { ].forEach(([status, arg]) => {
const child = this[status]; const child = this[status];
const context = arg || '_';
const contexts = new Map(block.contexts);
contexts.set(arg, context);
const contextTypes = new Map(block.contextTypes);
contextTypes.set(arg, status);
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`),
context, contexts: new Map(block.contexts),
contexts, contextTypes: new Map(block.contextTypes)
contextTypes
}); });
if (arg) {
child.block.context = arg;
child.block.contexts.set(arg, arg); // TODO should be using getUniqueName
child.block.contextTypes.set(arg, status);
}
child.initChildren(child.block, stripWhitespace, nextSibling); child.initChildren(child.block, stripWhitespace, nextSibling);
this.generator.blocks.push(child.block); this.generator.blocks.push(child.block);
@ -107,7 +105,7 @@ export default class AwaitBlock extends Node {
if (${token} !== ${await_token}) return; if (${token} !== ${await_token}) return;
var ${old_block} = ${await_block}; var ${old_block} = ${await_block};
${await_block} = (${await_block_type} = type)(#component, state); ${await_block} = type && (${await_block_type} = type)(#component, state);
if (${old_block}) { if (${old_block}) {
${old_block}.u(); ${old_block}.u();
@ -124,13 +122,21 @@ export default class AwaitBlock extends Node {
if (@isPromise(${promise})) { if (@isPromise(${promise})) {
${promise}.then(function(${value}) { ${promise}.then(function(${value}) {
var state = #component.get(); ${this.then.block.context ? deindent`
${resolved} = { ${this.then.block.context}: ${value} }; var state = #component.get();
${replace_await_block}(${token}, ${create_then_block}, @assign({}, state, ${resolved})); ${resolved} = { ${this.then.block.context}: ${value} };
${replace_await_block}(${token}, ${create_then_block}, @assign({}, state, ${resolved}));
` : deindent`
${replace_await_block}(${token}, null, null);
`}
}, function (${error}) { }, function (${error}) {
var state = #component.get(); ${this.catch.block.context ? deindent`
${resolved} = { ${this.catch.block.context}: ${error} }; var state = #component.get();
${replace_await_block}(${token}, ${create_catch_block}, @assign({}, state, ${resolved})); ${resolved} = { ${this.catch.block.context}: ${error} };
${replace_await_block}(${token}, ${create_catch_block}, @assign({}, state, ${resolved}));
` : deindent`
${replace_await_block}(${token}, null, null);
`}
}); });
// if we previously had a then/catch block, destroy it // if we previously had a then/catch block, destroy it

Loading…
Cancel
Save