From f854e15bedd88fedcd73c21f2ab951de38ca6434 Mon Sep 17 00:00:00 2001 From: openharmony_ci <120357966@qq.com> Date: Mon, 16 May 2022 13:24:57 +0000 Subject: [PATCH] !228 fix new_target syntax error Merge pull request !228 from zrg/fix_new_target --- ts2panda/src/syntaxChecker.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/ts2panda/src/syntaxChecker.ts b/ts2panda/src/syntaxChecker.ts index 0d179e1f96..6dd3df639f 100644 --- a/ts2panda/src/syntaxChecker.ts +++ b/ts2panda/src/syntaxChecker.ts @@ -355,14 +355,14 @@ function checkMetaProperty(node: ts.MetaProperty) { throw new DiagnosticError(node, DiagnosticCode._0_is_not_a_valid_meta_property_for_keyword_1_Did_you_mean_2, file, args); } - if (!getContainingFunction(node)) { + let func = getContainingFunctionDeclaration(node); + if (!func) { throw new DiagnosticError(node, DiagnosticCode.Meta_property_0_is_only_allowed_in_the_body_of_a_function_declaration_function_expression_or_constructor, file, args); } else { - let func = getContainingFunctionDeclaration(node); - while (getContainingFunctionDeclaration(func!)) { - func = getContainingFunctionDeclaration(func!); + if (ts.isMethodDeclaration(func)) { + throw new DiagnosticError(node, DiagnosticCode.Meta_property_0_is_only_allowed_in_the_body_of_a_function_declaration_function_expression_or_constructor, file, args); } - if (func && ts.isArrowFunction(func)) { + if (ts.isArrowFunction(func) && !jshelpers.getNewTargetContainer(node)) { throw new DiagnosticError(node, DiagnosticCode.Meta_property_0_is_only_allowed_in_the_body_of_a_function_declaration_function_expression_or_constructor, file, args); } } -- Gitee