From 4249266eb8c9727fab1273a9b1d3ade681df1f79 Mon Sep 17 00:00:00 2001 From: songqi Date: Wed, 4 Jan 2023 14:49:10 +0800 Subject: [PATCH] Fix parser of lessThan Token Issue: I6IYK3 Tests: test262/parser/compiler/tsc Signed-off-by: songqi Change-Id: Ic6754395eae385caa268055a18264828460566e8 --- es2panda/parser/parserImpl.cpp | 54 +-- es2panda/parser/parserImpl.h | 13 +- .../ts-test-if-statement-2-expected.txt | 1 + .../statements/ts-test-if-statement-2.ts | 21 ++ .../ts/test-function-generic-expected.txt | 1 + .../test/parser/ts/test-function-generic.ts | 21 ++ .../ts/test-lessThan-expression1-expected.txt | 314 ++++++++++++++++++ .../parser/ts/test-lessThan-expression1.ts | 21 ++ .../ts/test-lessThan-expression2-expected.txt | 271 +++++++++++++++ .../parser/ts/test-lessThan-expression2.ts | 19 ++ 10 files changed, 709 insertions(+), 27 deletions(-) create mode 100644 es2panda/test/compiler/ts/cases/conformance/statements/ts-test-if-statement-2-expected.txt create mode 100644 es2panda/test/compiler/ts/cases/conformance/statements/ts-test-if-statement-2.ts create mode 100644 es2panda/test/parser/ts/test-function-generic-expected.txt create mode 100644 es2panda/test/parser/ts/test-function-generic.ts create mode 100644 es2panda/test/parser/ts/test-lessThan-expression1-expected.txt create mode 100644 es2panda/test/parser/ts/test-lessThan-expression1.ts create mode 100644 es2panda/test/parser/ts/test-lessThan-expression2-expected.txt create mode 100644 es2panda/test/parser/ts/test-lessThan-expression2.ts diff --git a/es2panda/parser/parserImpl.cpp b/es2panda/parser/parserImpl.cpp index a245d55f623..6b06f8820f0 100644 --- a/es2panda/parser/parserImpl.cpp +++ b/es2panda/parser/parserImpl.cpp @@ -312,13 +312,13 @@ ir::TSTypeReference *ParserImpl::ParseTsConstExpression() return typeReference; } -ir::Expression *ParserImpl::ParseTsIdentifierReference() +ir::Expression *ParserImpl::ParseTsIdentifierReference(TypeAnnotationParsingOptions options) { if (CurrentLiteralIsBasicType() && lexer_->Lookahead() != LEX_CHAR_DOT) { - return ParseTsBasicType(); + return ParseTsBasicType(options); } - return ParseTsTypeReferenceOrQuery(); + return ParseTsTypeReferenceOrQuery(options, false); } bool ParserImpl::IsStartOfMappedType() const @@ -426,7 +426,7 @@ ir::Expression *ParserImpl::ParseTsTypeLiteralOrTsMappedType(ir::Expression *typ } ir::Expression *ParserImpl::ParseTsTypeReferenceOrTsTypePredicate(ir::Expression *typeAnnotation, - bool canBeTsTypePredicate) + bool canBeTsTypePredicate, bool throwError) { if (typeAnnotation) { return nullptr; @@ -436,7 +436,7 @@ ir::Expression *ParserImpl::ParseTsTypeReferenceOrTsTypePredicate(ir::Expression return ParseTsTypePredicate(); } - return ParseTsTypeOperatorOrTypeReference(); + return ParseTsTypeOperatorOrTypeReference(throwError); } ir::Expression *ParserImpl::ParseTsThisTypeOrTsTypePredicate(ir::Expression *typeAnnotation, bool canBeTsTypePredicate, @@ -542,7 +542,7 @@ ir::Expression *ParserImpl::ParseTsTypeAnnotationElement(ir::Expression *typeAnn return ParseTsArrayType(typeAnnotation); } - return ParseTsIndexAccessType(typeAnnotation); + return ParseTsIndexAccessType(typeAnnotation, *options & TypeAnnotationParsingOptions::THROW_ERROR); } return ParseTsTupleType(); @@ -561,14 +561,14 @@ ir::Expression *ParserImpl::ParseTsTypeAnnotationElement(ir::Expression *typeAnn break; } - return ParseTsBasicType(); + return ParseTsBasicType(*options); } case lexer::TokenType::KEYW_TYPEOF: { if (typeAnnotation) { break; } - return ParseTsTypeReferenceOrQuery(true); + return ParseTsTypeReferenceOrQuery(*options, true); } case lexer::TokenType::KEYW_IMPORT: { if (typeAnnotation) { @@ -593,7 +593,8 @@ ir::Expression *ParserImpl::ParseTsTypeAnnotationElement(ir::Expression *typeAnn } return ParseTsTypeReferenceOrTsTypePredicate( - typeAnnotation, *options & TypeAnnotationParsingOptions::CAN_BE_TS_TYPE_PREDICATE); + typeAnnotation, *options & TypeAnnotationParsingOptions::CAN_BE_TS_TYPE_PREDICATE, + *options & TypeAnnotationParsingOptions::THROW_ERROR); } case lexer::TokenType::KEYW_EXTENDS: { if (*options & (TypeAnnotationParsingOptions::IN_UNION | TypeAnnotationParsingOptions::IN_INTERSECTION)) { @@ -601,7 +602,7 @@ ir::Expression *ParserImpl::ParseTsTypeAnnotationElement(ir::Expression *typeAnn } if (!typeAnnotation) { - return ParseTsIdentifierReference(); + return ParseTsIdentifierReference(*options); } return ParseTsConditionalType(typeAnnotation, *options & TypeAnnotationParsingOptions::RESTRICT_EXTENDS); @@ -773,9 +774,10 @@ ir::Expression *ParserImpl::ParseTsTypeAnnotation(TypeAnnotationParsingOptions * return typeAnnotation; } -ir::Expression *ParserImpl::ParseTsTypeOperatorOrTypeReference() +ir::Expression *ParserImpl::ParseTsTypeOperatorOrTypeReference(bool throwError) { - TypeAnnotationParsingOptions options = TypeAnnotationParsingOptions::THROW_ERROR; + TypeAnnotationParsingOptions options = throwError ? + TypeAnnotationParsingOptions::THROW_ERROR : TypeAnnotationParsingOptions::NO_OPTS; if (lexer_->GetToken().KeywordType() == lexer::TokenType::KEYW_READONLY) { lexer::SourcePosition typeOperatorStart = lexer_->GetToken().Start(); @@ -846,7 +848,7 @@ ir::Expression *ParserImpl::ParseTsTypeOperatorOrTypeReference() return inferType; } - return ParseTsIdentifierReference(); + return ParseTsIdentifierReference(options); } bool ParserImpl::IsTSNamedTupleMember() @@ -1007,7 +1009,7 @@ ir::Expression *ParserImpl::ParseTsQualifiedReference(ir::Expression *typeName) return typeName; } -ir::Expression *ParserImpl::ParseTsIndexAccessType(ir::Expression *typeName) +ir::Expression *ParserImpl::ParseTsIndexAccessType(ir::Expression *typeName, bool throwError) { TypeAnnotationParsingOptions options = TypeAnnotationParsingOptions::THROW_ERROR; @@ -1017,7 +1019,10 @@ ir::Expression *ParserImpl::ParseTsIndexAccessType(ir::Expression *typeName) ir::Expression *indexType = ParseTsTypeAnnotation(&options); if (lexer_->GetToken().Type() != lexer::TokenType::PUNCTUATOR_RIGHT_SQUARE_BRACKET) { - ThrowSyntaxError("']' exprected"); + if (!throwError) { + return nullptr; + } + ThrowSyntaxError("']' expected"); } lexer_->NextToken(); // eat ']' @@ -1030,7 +1035,7 @@ ir::Expression *ParserImpl::ParseTsIndexAccessType(ir::Expression *typeName) return typeName; } -ir::Expression *ParserImpl::ParseTsTypeReferenceOrQuery(bool parseQuery) +ir::Expression *ParserImpl::ParseTsTypeReferenceOrQuery(TypeAnnotationParsingOptions options, bool parseQuery) { lexer::SourcePosition referenceStartLoc = lexer_->GetToken().Start(); @@ -1084,7 +1089,7 @@ ir::Expression *ParserImpl::ParseTsTypeReferenceOrQuery(bool parseQuery) typeName->SetRange({referenceStartLoc, lexer_->GetToken().End()}); - return ParseTsIndexAccessType(typeName); + return ParseTsIndexAccessType(typeName, options & TypeAnnotationParsingOptions::THROW_ERROR); } ir::Expression *returnNode = nullptr; @@ -1746,6 +1751,9 @@ ir::Expression *ParserImpl::ParseTsParenthesizedOrFunctionType(ir::Expression *t if (lexer_->GetToken().Type() != lexer::TokenType::PUNCTUATOR_LEFT_PARENTHESIS && lexer_->GetToken().Type() != lexer::TokenType::PUNCTUATOR_LESS_THAN) { + if (!throwError) { + return nullptr; + } ThrowSyntaxError("'(' expected"); } } @@ -1823,7 +1831,7 @@ ir::Expression *ParserImpl::ParseTsFunctionType(lexer::SourcePosition startLoc, return funcType; } -ir::Expression *ParserImpl::ParseTsBasicType() +ir::Expression *ParserImpl::ParseTsBasicType(TypeAnnotationParsingOptions options) { ir::Expression *typeAnnotation = nullptr; @@ -1831,7 +1839,11 @@ ir::Expression *ParserImpl::ParseTsBasicType() lexer_->NextToken(); if (lexer_->GetToken().Type() != lexer::TokenType::LITERAL_NUMBER) { - ThrowSyntaxError("Type expected"); + if (options & TypeAnnotationParsingOptions::THROW_ERROR) { + ThrowSyntaxError("Type expected"); + } else { + return nullptr; + } } } if (lexer_->GetToken().Type() == lexer::TokenType::LITERAL_NUMBER) { @@ -2895,7 +2907,7 @@ ir::ClassDefinition *ParserImpl::ParseClassDefinition(bool isDeclaration, bool i if (!isDeclare && !isCtorContinuousDefined) { ThrowSyntaxError("Constructor implementation is missing.", property->Start()); } - + if (hasConstructorFuncBody) { ThrowSyntaxError("Multiple constructor implementations are not allowed.", property->Start()); } @@ -3030,7 +3042,7 @@ ir::TSEnumDeclaration *ParserImpl::ParseEnumDeclaration(bool isExport, bool isDe auto enumCtx = binder::LexicalScope(Binder(), enumMemberBindings); auto *enumDeclaration = ParseEnumMembers(key, enumStart, isExport, isDeclare, isConst); res->Declaration()->AsEnumLiteralDecl()->Add(enumDeclaration); - + return enumDeclaration; } diff --git a/es2panda/parser/parserImpl.h b/es2panda/parser/parserImpl.h index cd12f818eb0..b8d0fa10971 100644 --- a/es2panda/parser/parserImpl.h +++ b/es2panda/parser/parserImpl.h @@ -238,9 +238,9 @@ private: static bool IsMemberExpressionsAreSame(const ir::MemberExpression *mExp1, const ir::MemberExpression *mExp2); static bool IsMethodDefinitionsAreSame(const ir::MethodDefinition *property, ir::MethodDefinition *overload); ir::TSTypeReference *ParseTsConstExpression(); - ir::Expression *ParseTsTypeOperatorOrTypeReference(); - ir::Expression *ParseTsIdentifierReference(); - ir::Expression *ParseTsBasicType(); + ir::Expression *ParseTsTypeOperatorOrTypeReference(bool throwError); + ir::Expression *ParseTsIdentifierReference(TypeAnnotationParsingOptions options); + ir::Expression *ParseTsBasicType(TypeAnnotationParsingOptions options); ir::TSIntersectionType *ParseTsIntersectionType(ir::Expression *type, bool inUnion, bool restrictExtends); ir::TSUnionType *ParseTsUnionType(ir::Expression *type, bool restrictExtends); ir::Expression *ParseTsParenthesizedOrFunctionType(ir::Expression *typeAnnotation, bool throwError); @@ -257,9 +257,9 @@ private: ir::Expression *ParseTsTypeLiteralOrInterfaceMember(); ArenaVector ParseTsTypeLiteralOrInterface(); ir::Expression *ParseTsThisType(bool throwError); - ir::Expression *ParseTsIndexAccessType(ir::Expression *typeName); + ir::Expression *ParseTsIndexAccessType(ir::Expression *typeName, bool throwError); ir::Expression *ParseTsQualifiedReference(ir::Expression *typeName); - ir::Expression *ParseTsTypeReferenceOrQuery(bool parseQuery = false); + ir::Expression *ParseTsTypeReferenceOrQuery(TypeAnnotationParsingOptions options, bool parseQuery = false); bool IsTSNamedTupleMember(); void HandleRestType(ir::AstNodeType elementType, bool *hasRestType) const; ir::Expression *ParseTsTupleElement(ir::TSTupleKind *kind, bool *seenOptional, bool *hasRestType); @@ -267,7 +267,8 @@ private: ir::TSImportType *ParseTsImportType(const lexer::SourcePosition &startLoc, bool isTypeof = false); ir::Expression *ParseTsTypeAnnotation(TypeAnnotationParsingOptions *options); ir::Expression *ParseTsTypeLiteralOrTsMappedType(ir::Expression *typeAnnotation); - ir::Expression *ParseTsTypeReferenceOrTsTypePredicate(ir::Expression *typeAnnotation, bool canBeTsTypePredicate); + ir::Expression *ParseTsTypeReferenceOrTsTypePredicate(ir::Expression *typeAnnotation, bool canBeTsTypePredicate, + bool throwError); ir::Expression *ParseTsThisTypeOrTsTypePredicate(ir::Expression *typeAnnotation, bool canBeTsTypePredicate, bool throwError); ir::Expression *ParseTsTemplateLiteralType(); diff --git a/es2panda/test/compiler/ts/cases/conformance/statements/ts-test-if-statement-2-expected.txt b/es2panda/test/compiler/ts/cases/conformance/statements/ts-test-if-statement-2-expected.txt new file mode 100644 index 00000000000..ce013625030 --- /dev/null +++ b/es2panda/test/compiler/ts/cases/conformance/statements/ts-test-if-statement-2-expected.txt @@ -0,0 +1 @@ +hello diff --git a/es2panda/test/compiler/ts/cases/conformance/statements/ts-test-if-statement-2.ts b/es2panda/test/compiler/ts/cases/conformance/statements/ts-test-if-statement-2.ts new file mode 100644 index 00000000000..e0946153eff --- /dev/null +++ b/es2panda/test/compiler/ts/cases/conformance/statements/ts-test-if-statement-2.ts @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +var a = 1; +if (-2 < -a) { + print("hello"); +} + diff --git a/es2panda/test/parser/ts/test-function-generic-expected.txt b/es2panda/test/parser/ts/test-function-generic-expected.txt new file mode 100644 index 00000000000..9be1f6f7670 --- /dev/null +++ b/es2panda/test/parser/ts/test-function-generic-expected.txt @@ -0,0 +1 @@ +SyntaxError: Identifier expected. [test-function-generic.ts:21:13] diff --git a/es2panda/test/parser/ts/test-function-generic.ts b/es2panda/test/parser/ts/test-function-generic.ts new file mode 100644 index 00000000000..b327e9e1ebe --- /dev/null +++ b/es2panda/test/parser/ts/test-function-generic.ts @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +function func (a : T) { + console.log(a); +} + +func(10); diff --git a/es2panda/test/parser/ts/test-lessThan-expression1-expected.txt b/es2panda/test/parser/ts/test-lessThan-expression1-expected.txt new file mode 100644 index 00000000000..0ec43a4e323 --- /dev/null +++ b/es2panda/test/parser/ts/test-lessThan-expression1-expected.txt @@ -0,0 +1,314 @@ +{ + "type": "Program", + "statements": [ + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "arr", + "loc": { + "start": { + "line": 17, + "column": 7 + }, + "end": { + "line": 17, + "column": 10 + } + } + }, + "init": { + "type": "ArrayExpression", + "elements": [ + { + "type": "NumberLiteral", + "value": 1, + "loc": { + "start": { + "line": 17, + "column": 14 + }, + "end": { + "line": 17, + "column": 15 + } + } + }, + { + "type": "NumberLiteral", + "value": 2, + "loc": { + "start": { + "line": 17, + "column": 16 + }, + "end": { + "line": 17, + "column": 17 + } + } + }, + { + "type": "NumberLiteral", + "value": 3, + "loc": { + "start": { + "line": 17, + "column": 18 + }, + "end": { + "line": 17, + "column": 19 + } + } + }, + { + "type": "NumberLiteral", + "value": 4, + "loc": { + "start": { + "line": 17, + "column": 20 + }, + "end": { + "line": 17, + "column": 21 + } + } + } + ], + "loc": { + "start": { + "line": 17, + "column": 13 + }, + "end": { + "line": 17, + "column": 22 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 7 + }, + "end": { + "line": 17, + "column": 22 + } + } + } + ], + "kind": "const", + "loc": { + "start": { + "line": 17, + "column": 1 + }, + "end": { + "line": 17, + "column": 23 + } + } + }, + { + "type": "IfStatement", + "test": { + "type": "BinaryExpression", + "operator": "<", + "left": { + "type": "NumberLiteral", + "value": 0, + "loc": { + "start": { + "line": 19, + "column": 5 + }, + "end": { + "line": 19, + "column": 6 + } + } + }, + "right": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "arr", + "loc": { + "start": { + "line": 19, + "column": 9 + }, + "end": { + "line": 19, + "column": 12 + } + } + }, + "property": { + "type": "BinaryExpression", + "operator": "+", + "left": { + "type": "NumberLiteral", + "value": 1, + "loc": { + "start": { + "line": 19, + "column": 13 + }, + "end": { + "line": 19, + "column": 14 + } + } + }, + "right": { + "type": "NumberLiteral", + "value": 2, + "loc": { + "start": { + "line": 19, + "column": 17 + }, + "end": { + "line": 19, + "column": 18 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 13 + }, + "end": { + "line": 19, + "column": 18 + } + } + }, + "computed": true, + "optional": false, + "loc": { + "start": { + "line": 19, + "column": 9 + }, + "end": { + "line": 19, + "column": 19 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 5 + }, + "end": { + "line": 19, + "column": 19 + } + } + }, + "consequent": { + "type": "BlockStatement", + "statements": [ + { + "type": "ExpressionStatement", + "expression": { + "type": "CallExpression", + "callee": { + "type": "Identifier", + "name": "print", + "loc": { + "start": { + "line": 20, + "column": 5 + }, + "end": { + "line": 20, + "column": 10 + } + } + }, + "arguments": [ + { + "type": "StringLiteral", + "value": "helloWorld", + "loc": { + "start": { + "line": 20, + "column": 11 + }, + "end": { + "line": 20, + "column": 23 + } + } + } + ], + "optional": false, + "loc": { + "start": { + "line": 20, + "column": 5 + }, + "end": { + "line": 20, + "column": 24 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 5 + }, + "end": { + "line": 20, + "column": 25 + } + } + } + ], + "loc": { + "start": { + "line": 19, + "column": 21 + }, + "end": { + "line": 21, + "column": 2 + } + } + }, + "alternate": null, + "loc": { + "start": { + "line": 19, + "column": 1 + }, + "end": { + "line": 21, + "column": 2 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 22, + "column": 1 + } + } +} diff --git a/es2panda/test/parser/ts/test-lessThan-expression1.ts b/es2panda/test/parser/ts/test-lessThan-expression1.ts new file mode 100644 index 00000000000..610a0f18a5a --- /dev/null +++ b/es2panda/test/parser/ts/test-lessThan-expression1.ts @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +const arr = [1,2,3,4]; + +if (0 < arr[1 + 2]) { + print("helloWorld"); +} diff --git a/es2panda/test/parser/ts/test-lessThan-expression2-expected.txt b/es2panda/test/parser/ts/test-lessThan-expression2-expected.txt new file mode 100644 index 00000000000..4ecc06eb255 --- /dev/null +++ b/es2panda/test/parser/ts/test-lessThan-expression2-expected.txt @@ -0,0 +1,271 @@ +{ + "type": "Program", + "statements": [ + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "A", + "loc": { + "start": { + "line": 17, + "column": 7 + }, + "end": { + "line": 17, + "column": 8 + } + } + }, + "superClass": null, + "implements": [], + "constructor": { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "constructor", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "constructor", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": null, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 1 + }, + "end": { + "line": 19, + "column": 2 + } + } + }, + "body": [ + { + "type": "ClassProperty", + "key": { + "type": "Identifier", + "name": "a", + "loc": { + "start": { + "line": 18, + "column": 5 + }, + "end": { + "line": 18, + "column": 6 + } + } + }, + "value": { + "type": "BinaryExpression", + "operator": "<", + "left": { + "type": "NumberLiteral", + "value": 1, + "loc": { + "start": { + "line": 18, + "column": 9 + }, + "end": { + "line": 18, + "column": 10 + } + } + }, + "right": { + "type": "CallExpression", + "callee": { + "type": "MemberExpression", + "object": { + "type": "NewExpression", + "callee": { + "type": "Identifier", + "name": "Date", + "loc": { + "start": { + "line": 18, + "column": 18 + }, + "end": { + "line": 18, + "column": 22 + } + } + }, + "arguments": [], + "loc": { + "start": { + "line": 18, + "column": 14 + }, + "end": { + "line": 18, + "column": 24 + } + } + }, + "property": { + "type": "Identifier", + "name": "getTime", + "loc": { + "start": { + "line": 18, + "column": 25 + }, + "end": { + "line": 18, + "column": 32 + } + } + }, + "computed": false, + "optional": false, + "loc": { + "start": { + "line": 18, + "column": 14 + }, + "end": { + "line": 18, + "column": 32 + } + } + }, + "arguments": [], + "optional": false, + "loc": { + "start": { + "line": 18, + "column": 13 + }, + "end": { + "line": 18, + "column": 35 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 9 + }, + "end": { + "line": 18, + "column": 35 + } + } + }, + "static": false, + "readonly": false, + "declare": false, + "optional": false, + "computed": false, + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 5 + }, + "end": { + "line": 18, + "column": 35 + } + } + } + ], + "indexSignatures": [], + "loc": { + "start": { + "line": 17, + "column": 9 + }, + "end": { + "line": 19, + "column": 2 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 1 + }, + "end": { + "line": 19, + "column": 2 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 20, + "column": 1 + } + } +} diff --git a/es2panda/test/parser/ts/test-lessThan-expression2.ts b/es2panda/test/parser/ts/test-lessThan-expression2.ts new file mode 100644 index 00000000000..d5f203287e8 --- /dev/null +++ b/es2panda/test/parser/ts/test-lessThan-expression2.ts @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +class A { + a = 1 < (new Date().getTime()); +} -- Gitee