From 97a507bcaa7bcfa1ef560a04b9fdf06ce2b0138b Mon Sep 17 00:00:00 2001 From: zhangrengao Date: Tue, 10 May 2022 11:04:15 +0800 Subject: [PATCH] fix new.target syntax error Signed-off-by: zhangrengao Change-Id: Ia526b5b5f9695f9f9723d1f8dfb63aa4156b081c --- 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 cf62d1ebfb..d4cf3d170b 100644 --- a/ts2panda/src/syntaxChecker.ts +++ b/ts2panda/src/syntaxChecker.ts @@ -357,14 +357,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