Make checking for DestructuedVariable a one-liner

pull/8386/head
Nguyen Tran 4 years ago
parent 404893d33a
commit 4fc2e3960e

@ -45,9 +45,8 @@ export default class EachBlock extends AbstractBlock {
unpack_destructuring({ contexts: this.contexts, node: info.context, scope, component, owner: this, context_rest_properties: this.context_rest_properties }); unpack_destructuring({ contexts: this.contexts, node: info.context, scope, component, owner: this, context_rest_properties: this.context_rest_properties });
this.contexts.forEach(context => { this.contexts.forEach(context => {
if (context.type === 'DestructuredVariable') { if (context.type !== 'DestructuredVariable') return;
this.scope.add(context.key.name, this.expression.dependencies, this); this.scope.add(context.key.name, this.expression.dependencies, this);
}
}); });
if (this.index) { if (this.index) {

@ -214,11 +214,10 @@ function update_reference(
const find_from_context = (node: Identifier) => { const find_from_context = (node: Identifier) => {
for (let i = n; i < contexts.length; i++) { for (let i = n; i < contexts.length; i++) {
const cur_context = contexts[i]; const cur_context = contexts[i];
if (cur_context.type === 'DestructuredVariable') { if (cur_context.type !== 'DestructuredVariable') continue;
const { key } = cur_context; const { key } = cur_context;
if (node.name === key.name) { if (node.name === key.name) {
throw new Error(`Cannot access '${node.name}' before initialization`); throw new Error(`Cannot access '${node.name}' before initialization`);
}
} }
} }
return to_ctx(node.name); return to_ctx(node.name);

@ -70,9 +70,8 @@ class AwaitBlockBranch extends Wrapper {
this.renderer.add_to_context(this.value, true); this.renderer.add_to_context(this.value, true);
} else { } else {
contexts.forEach(context => { contexts.forEach(context => {
if (context.type === 'DestructuredVariable') { if (context.type !== 'DestructuredVariable') return;
this.renderer.add_to_context(context.key.name, true); this.renderer.add_to_context(context.key.name, true);
}
}); });
this.value = this.block.parent.get_unique_name('value').name; this.value = this.block.parent.get_unique_name('value').name;
this.value_contexts = contexts; this.value_contexts = contexts;

Loading…
Cancel
Save