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 });
this.contexts.forEach(context => {
if (context.type === 'DestructuredVariable') {
this.scope.add(context.key.name, this.expression.dependencies, this);
}
if (context.type !== 'DestructuredVariable') return;
this.scope.add(context.key.name, this.expression.dependencies, this);
});
if (this.index) {

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

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

Loading…
Cancel
Save