From 3114674b00908f8588e18c1a5b326ba479d5e2cb Mon Sep 17 00:00:00 2001 From: iLTeoooD Date: Mon, 15 Mar 2021 23:12:01 +0100 Subject: [PATCH] Template scope refactor --- src/compiler/compile/nodes/shared/TemplateScope.ts | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/compiler/compile/nodes/shared/TemplateScope.ts b/src/compiler/compile/nodes/shared/TemplateScope.ts index df694ed45e..f3c5298732 100644 --- a/src/compiler/compile/nodes/shared/TemplateScope.ts +++ b/src/compiler/compile/nodes/shared/TemplateScope.ts @@ -12,11 +12,13 @@ export default class TemplateScope { dependencies_for_name: Map>; owners: Map = new Map(); parent?: TemplateScope; + private static readonly LET_TYPES: string[] = ['Element', 'InlineComponent', 'SlotTemplate']; + private static readonly AWAIT_TYPES: string[] = ['ThenBlock', 'CatchBlock']; constructor(parent?: TemplateScope) { this.parent = parent; - this.names = new Set(parent ? parent.names : []); - this.dependencies_for_name = new Map(parent ? parent.dependencies_for_name : []); + this.names = new Set(parent?.names || []); + this.dependencies_for_name = new Map(parent?.dependencies_for_name || []); } add(name, dependencies: Set, owner) { @@ -36,16 +38,16 @@ export default class TemplateScope { } get_owner(name: string): NodeWithScope { - return this.owners.get(name) || (this.parent && this.parent.get_owner(name)); + return this.owners.get(name) || this.parent?.get_owner(name); } is_let(name: string) { const owner = this.get_owner(name); - return owner && (owner.type === 'Element' || owner.type === 'InlineComponent' || owner.type === 'SlotTemplate'); + return TemplateScope.LET_TYPES.includes(owner?.type); } is_await(name: string) { const owner = this.get_owner(name); - return owner && (owner.type === 'ThenBlock' || owner.type === 'CatchBlock'); + return TemplateScope.AWAIT_TYPES.includes(owner?.type); } }