diff --git a/ts2panda/src/syntaxChecker.ts b/ts2panda/src/syntaxChecker.ts index cf62d1ebfb82f9687c5247c4972f5ab87d4882d9..d4cf3d170b46383167923a7d768fdd01f4fc64c1 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); } }