From b74b445373a194b26eaae6d12d4e92084546e5ca Mon Sep 17 00:00:00 2001 From: Tan Li Hau Date: Sat, 2 Jan 2021 10:39:46 +0800 Subject: [PATCH] fix template_scope of undefined --- src/compiler/compile/nodes/Action.ts | 7 +++++-- .../compile/render_dom/wrappers/shared/add_actions.ts | 4 ++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/compiler/compile/nodes/Action.ts b/src/compiler/compile/nodes/Action.ts index 3cd6ed8b6704..347ea2fb3081 100644 --- a/src/compiler/compile/nodes/Action.ts +++ b/src/compiler/compile/nodes/Action.ts @@ -2,15 +2,16 @@ import Node from './shared/Node'; import Expression from './shared/Expression'; import Component from '../Component'; import TemplateScope from './shared/TemplateScope'; -import { TemplateNode } from '../../interfaces'; +import { Directive } from '../../interfaces'; export default class Action extends Node { type: 'Action'; name: string; expression: Expression; uses_context: boolean; + template_scope: TemplateScope; - constructor(component: Component, parent: Node, scope: TemplateScope, info: TemplateNode) { + constructor(component: Component, parent: Node, scope: TemplateScope, info: Directive) { super(component, parent, scope, info); const object = info.name.split('.')[0]; @@ -23,6 +24,8 @@ export default class Action extends Node { ? new Expression(component, this, scope, info.expression) : null; + this.template_scope = scope; + this.uses_context = this.expression && this.expression.uses_context; } } diff --git a/src/compiler/compile/render_dom/wrappers/shared/add_actions.ts b/src/compiler/compile/render_dom/wrappers/shared/add_actions.ts index 485c9eff3203..b57820beb3ed 100644 --- a/src/compiler/compile/render_dom/wrappers/shared/add_actions.ts +++ b/src/compiler/compile/render_dom/wrappers/shared/add_actions.ts @@ -12,7 +12,7 @@ export default function add_actions( } export function add_action(block: Block, target: string, action: Action) { - const { expression } = action; + const { expression, template_scope } = action; let snippet; let dependencies; @@ -29,7 +29,7 @@ export function add_action(block: Block, target: string, action: Action) { const [obj, ...properties] = action.name.split('.'); - const fn = is_contextual(action.component, action.expression.template_scope, obj) + const fn = is_contextual(action.component, template_scope, obj) ? block.renderer.reference(obj) : obj;