diff --git a/es2panda/parser/parserImpl.cpp b/es2panda/parser/parserImpl.cpp index 47ddccec25dc907a14b0bb87caef709f6fc5cac5..06be5356190ca62e676ea454d39ba071fff4e39f 100644 --- a/es2panda/parser/parserImpl.cpp +++ b/es2panda/parser/parserImpl.cpp @@ -548,7 +548,8 @@ ir::Expression *ParserImpl::ParseTsTypeAnnotationElement(ir::Expression *typeAnn break; } - return ParseTsUnionType(typeAnnotation, *options & TypeAnnotationParsingOptions::RESTRICT_EXTENDS); + return ParseTsUnionType(typeAnnotation, *options & TypeAnnotationParsingOptions::RESTRICT_EXTENDS, + *options & TypeAnnotationParsingOptions::THROW_ERROR); } case lexer::TokenType::PUNCTUATOR_BITWISE_AND: { if (*options & (TypeAnnotationParsingOptions::IN_MODIFIER | @@ -557,7 +558,8 @@ ir::Expression *ParserImpl::ParseTsTypeAnnotationElement(ir::Expression *typeAnn } return ParseTsIntersectionType(typeAnnotation, *options & TypeAnnotationParsingOptions::IN_UNION, - *options & TypeAnnotationParsingOptions::RESTRICT_EXTENDS); + *options & TypeAnnotationParsingOptions::RESTRICT_EXTENDS, + *options & TypeAnnotationParsingOptions::THROW_ERROR); } case lexer::TokenType::PUNCTUATOR_MINUS: case lexer::TokenType::LITERAL_NUMBER: @@ -1703,13 +1705,15 @@ ir::TSArrayType *ParserImpl::ParseTsArrayType(ir::Expression *elementType) return arrayType; } -ir::TSUnionType *ParserImpl::ParseTsUnionType(ir::Expression *type, bool restrictExtends) +ir::TSUnionType *ParserImpl::ParseTsUnionType(ir::Expression *type, bool restrictExtends, bool throwError) { ArenaVector types(Allocator()->Adapter()); lexer::SourcePosition startLoc; - TypeAnnotationParsingOptions options = - TypeAnnotationParsingOptions::THROW_ERROR | TypeAnnotationParsingOptions::IN_UNION; + TypeAnnotationParsingOptions options = TypeAnnotationParsingOptions::IN_UNION; + if (throwError) { + options |= TypeAnnotationParsingOptions::THROW_ERROR; + } if (restrictExtends) { options |= TypeAnnotationParsingOptions::RESTRICT_EXTENDS; @@ -1729,7 +1733,12 @@ ir::TSUnionType *ParserImpl::ParseTsUnionType(ir::Expression *type, bool restric lexer_->NextToken(); // eat '|' - types.push_back(ParseTsTypeAnnotation(&options)); + ir::Expression* union_suffix_type = ParseTsTypeAnnotation(&options); + if (union_suffix_type == nullptr) { + return nullptr; + } + + types.push_back(union_suffix_type); } lexer::SourcePosition endLoc = types.back()->End(); @@ -1742,13 +1751,16 @@ ir::TSUnionType *ParserImpl::ParseTsUnionType(ir::Expression *type, bool restric return unionType; } -ir::TSIntersectionType *ParserImpl::ParseTsIntersectionType(ir::Expression *type, bool inUnion, bool restrictExtends) +ir::TSIntersectionType *ParserImpl::ParseTsIntersectionType(ir::Expression *type, bool inUnion, bool restrictExtends, + bool throwError) { ArenaVector types(Allocator()->Adapter()); lexer::SourcePosition startLoc; - TypeAnnotationParsingOptions options = - TypeAnnotationParsingOptions::THROW_ERROR | TypeAnnotationParsingOptions::IN_INTERSECTION; + TypeAnnotationParsingOptions options = TypeAnnotationParsingOptions::IN_INTERSECTION; + if (throwError) { + options |= TypeAnnotationParsingOptions::THROW_ERROR; + } if (restrictExtends) { options |= TypeAnnotationParsingOptions::RESTRICT_EXTENDS; @@ -1772,7 +1784,11 @@ ir::TSIntersectionType *ParserImpl::ParseTsIntersectionType(ir::Expression *type lexer_->NextToken(); // eat '&' - types.push_back(ParseTsTypeAnnotation(&options)); + ir::Expression* suffix_type = ParseTsTypeAnnotation(&options); + if (suffix_type == nullptr) { + return nullptr; + } + types.push_back(suffix_type); } lexer::SourcePosition endLoc = types.back()->End(); diff --git a/es2panda/parser/parserImpl.h b/es2panda/parser/parserImpl.h index dc3330e1af3246bff2595d8e7411a2e9746e7e53..dc23e59aa152ec6e7356a0c873ab065cf265c004 100644 --- a/es2panda/parser/parserImpl.h +++ b/es2panda/parser/parserImpl.h @@ -253,8 +253,9 @@ private: 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::TSIntersectionType *ParseTsIntersectionType(ir::Expression *type, bool inUnion, bool restrictExtends, + bool throwError); + ir::TSUnionType *ParseTsUnionType(ir::Expression *type, bool restrictExtends, bool throwError); ir::Expression *ParseTsParenthesizedOrFunctionType(ir::Expression *typeAnnotation, bool throwError); ir::TSArrayType *ParseTsArrayType(ir::Expression *elementType); bool IsTsFunctionType(); diff --git a/es2panda/test/parser/ts/test_for_statement_condition_with_expression1-expected.txt b/es2panda/test/parser/ts/test_for_statement_condition_with_expression1-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..7fa98efef2ecdba6c77a60c64463ccbaae48d48b --- /dev/null +++ b/es2panda/test/parser/ts/test_for_statement_condition_with_expression1-expected.txt @@ -0,0 +1,394 @@ +{ + "type": "Program", + "statements": [ + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "x", + "typeAnnotation": { + "type": "TSNumberKeyword", + "loc": { + "start": { + "line": 17, + "column": 8 + }, + "end": { + "line": 17, + "column": 14 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 5 + }, + "end": { + "line": 17, + "column": 6 + } + } + }, + "init": { + "type": "NumberLiteral", + "value": 10, + "loc": { + "start": { + "line": 17, + "column": 17 + }, + "end": { + "line": 17, + "column": 19 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 5 + }, + "end": { + "line": 17, + "column": 19 + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 17, + "column": 1 + }, + "end": { + "line": 17, + "column": 20 + } + } + }, + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "y", + "typeAnnotation": { + "type": "TSNumberKeyword", + "loc": { + "start": { + "line": 18, + "column": 8 + }, + "end": { + "line": 18, + "column": 14 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 5 + }, + "end": { + "line": 18, + "column": 6 + } + } + }, + "init": { + "type": "NumberLiteral", + "value": 12, + "loc": { + "start": { + "line": 18, + "column": 17 + }, + "end": { + "line": 18, + "column": 19 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 5 + }, + "end": { + "line": 18, + "column": 19 + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 18, + "column": 1 + }, + "end": { + "line": 18, + "column": 20 + } + } + }, + { + "type": "ForUpdateStatement", + "init": { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "i", + "loc": { + "start": { + "line": 19, + "column": 10 + }, + "end": { + "line": 19, + "column": 11 + } + } + }, + "init": { + "type": "NumberLiteral", + "value": 0, + "loc": { + "start": { + "line": 19, + "column": 14 + }, + "end": { + "line": 19, + "column": 15 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 10 + }, + "end": { + "line": 19, + "column": 15 + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 19, + "column": 6 + }, + "end": { + "line": 19, + "column": 15 + } + } + }, + "test": { + "type": "BinaryExpression", + "operator": "<", + "left": { + "type": "Identifier", + "name": "i", + "loc": { + "start": { + "line": 19, + "column": 17 + }, + "end": { + "line": 19, + "column": 18 + } + } + }, + "right": { + "type": "BinaryExpression", + "operator": "|", + "left": { + "type": "BinaryExpression", + "operator": "&", + "left": { + "type": "Identifier", + "name": "x", + "loc": { + "start": { + "line": 19, + "column": 23 + }, + "end": { + "line": 19, + "column": 24 + } + } + }, + "right": { + "type": "Identifier", + "name": "y", + "loc": { + "start": { + "line": 19, + "column": 27 + }, + "end": { + "line": 19, + "column": 28 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 22 + }, + "end": { + "line": 19, + "column": 29 + } + } + }, + "right": { + "type": "BinaryExpression", + "operator": "^", + "left": { + "type": "Identifier", + "name": "x", + "loc": { + "start": { + "line": 19, + "column": 31 + }, + "end": { + "line": 19, + "column": 32 + } + } + }, + "right": { + "type": "Identifier", + "name": "y", + "loc": { + "start": { + "line": 19, + "column": 35 + }, + "end": { + "line": 19, + "column": 36 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 30 + }, + "end": { + "line": 19, + "column": 37 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 21 + }, + "end": { + "line": 19, + "column": 38 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 17 + }, + "end": { + "line": 19, + "column": 38 + } + } + }, + "update": { + "type": "UpdateExpression", + "operator": "++", + "prefix": false, + "argument": { + "type": "Identifier", + "name": "i", + "loc": { + "start": { + "line": 19, + "column": 40 + }, + "end": { + "line": 19, + "column": 41 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 40 + }, + "end": { + "line": 19, + "column": 43 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 19, + "column": 44 + }, + "end": { + "line": 20, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 1 + }, + "end": { + "line": 20, + "column": 2 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 20, + "column": 2 + } + } +} diff --git a/es2panda/test/parser/ts/test_for_statement_condition_with_expression1.ts b/es2panda/test/parser/ts/test_for_statement_condition_with_expression1.ts new file mode 100644 index 0000000000000000000000000000000000000000..b9a336ea6dbef49544529d354666e5c72dfee216 --- /dev/null +++ b/es2panda/test/parser/ts/test_for_statement_condition_with_expression1.ts @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2024 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. + */ + + +let x: number = 10; +let y: number = 12; +for (let i = 0; i < ((x & y)|(x ^ y)); i++){ +} \ No newline at end of file diff --git a/es2panda/test/parser/ts/test_for_statement_condition_with_expression2-expected.txt b/es2panda/test/parser/ts/test_for_statement_condition_with_expression2-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..89c17f5dc45d84cb26a40b1b4c57fc48990942ca --- /dev/null +++ b/es2panda/test/parser/ts/test_for_statement_condition_with_expression2-expected.txt @@ -0,0 +1,940 @@ +{ + "type": "Program", + "statements": [ + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "x", + "typeAnnotation": { + "type": "TSNumberKeyword", + "loc": { + "start": { + "line": 17, + "column": 8 + }, + "end": { + "line": 17, + "column": 14 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 5 + }, + "end": { + "line": 17, + "column": 6 + } + } + }, + "init": { + "type": "NumberLiteral", + "value": 10, + "loc": { + "start": { + "line": 17, + "column": 17 + }, + "end": { + "line": 17, + "column": 19 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 5 + }, + "end": { + "line": 17, + "column": 19 + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 17, + "column": 1 + }, + "end": { + "line": 17, + "column": 20 + } + } + }, + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "y", + "typeAnnotation": { + "type": "TSNumberKeyword", + "loc": { + "start": { + "line": 18, + "column": 8 + }, + "end": { + "line": 18, + "column": 14 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 5 + }, + "end": { + "line": 18, + "column": 6 + } + } + }, + "init": { + "type": "NumberLiteral", + "value": 12, + "loc": { + "start": { + "line": 18, + "column": 17 + }, + "end": { + "line": 18, + "column": 19 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 5 + }, + "end": { + "line": 18, + "column": 19 + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 18, + "column": 1 + }, + "end": { + "line": 18, + "column": 20 + } + } + }, + { + "type": "ForUpdateStatement", + "init": { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "i", + "loc": { + "start": { + "line": 19, + "column": 10 + }, + "end": { + "line": 19, + "column": 11 + } + } + }, + "init": { + "type": "NumberLiteral", + "value": 0, + "loc": { + "start": { + "line": 19, + "column": 14 + }, + "end": { + "line": 19, + "column": 15 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 10 + }, + "end": { + "line": 19, + "column": 15 + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 19, + "column": 6 + }, + "end": { + "line": 19, + "column": 15 + } + } + }, + "test": { + "type": "BinaryExpression", + "operator": "<", + "left": { + "type": "Identifier", + "name": "i", + "loc": { + "start": { + "line": 19, + "column": 17 + }, + "end": { + "line": 19, + "column": 18 + } + } + }, + "right": { + "type": "BinaryExpression", + "operator": "+", + "left": { + "type": "BinaryExpression", + "operator": "+", + "left": { + "type": "BinaryExpression", + "operator": "-", + "left": { + "type": "BinaryExpression", + "operator": "&", + "left": { + "type": "Identifier", + "name": "x", + "loc": { + "start": { + "line": 19, + "column": 23 + }, + "end": { + "line": 19, + "column": 24 + } + } + }, + "right": { + "type": "UnaryExpression", + "operator": "~", + "prefix": true, + "argument": { + "type": "Identifier", + "name": "y", + "loc": { + "start": { + "line": 19, + "column": 26 + }, + "end": { + "line": 19, + "column": 27 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 25 + }, + "end": { + "line": 19, + "column": 27 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 22 + }, + "end": { + "line": 19, + "column": 28 + } + } + }, + "right": { + "type": "BinaryExpression", + "operator": "&", + "left": { + "type": "UnaryExpression", + "operator": "~", + "prefix": true, + "argument": { + "type": "Identifier", + "name": "x", + "loc": { + "start": { + "line": 19, + "column": 33 + }, + "end": { + "line": 19, + "column": 34 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 32 + }, + "end": { + "line": 19, + "column": 34 + } + } + }, + "right": { + "type": "Identifier", + "name": "y", + "loc": { + "start": { + "line": 19, + "column": 35 + }, + "end": { + "line": 19, + "column": 36 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 31 + }, + "end": { + "line": 19, + "column": 37 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 22 + }, + "end": { + "line": 19, + "column": 37 + } + } + }, + "right": { + "type": "BinaryExpression", + "operator": "+", + "left": { + "type": "BinaryExpression", + "operator": "-", + "left": { + "type": "BinaryExpression", + "operator": "-", + "left": { + "type": "CallExpression", + "callee": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "Math", + "loc": { + "start": { + "line": 19, + "column": 41 + }, + "end": { + "line": 19, + "column": 45 + } + } + }, + "property": { + "type": "Identifier", + "name": "trunc", + "loc": { + "start": { + "line": 19, + "column": 46 + }, + "end": { + "line": 19, + "column": 51 + } + } + }, + "computed": false, + "optional": false, + "loc": { + "start": { + "line": 19, + "column": 41 + }, + "end": { + "line": 19, + "column": 51 + } + } + }, + "arguments": [ + { + "type": "Identifier", + "name": "x", + "loc": { + "start": { + "line": 19, + "column": 52 + }, + "end": { + "line": 19, + "column": 53 + } + } + } + ], + "optional": false, + "loc": { + "start": { + "line": 19, + "column": 41 + }, + "end": { + "line": 19, + "column": 54 + } + } + }, + "right": { + "type": "BinaryExpression", + "operator": "|", + "left": { + "type": "Identifier", + "name": "x", + "loc": { + "start": { + "line": 19, + "column": 58 + }, + "end": { + "line": 19, + "column": 59 + } + } + }, + "right": { + "type": "NumberLiteral", + "value": 0, + "loc": { + "start": { + "line": 19, + "column": 60 + }, + "end": { + "line": 19, + "column": 61 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 57 + }, + "end": { + "line": 19, + "column": 62 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 41 + }, + "end": { + "line": 19, + "column": 62 + } + } + }, + "right": { + "type": "CallExpression", + "callee": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "Math", + "loc": { + "start": { + "line": 19, + "column": 65 + }, + "end": { + "line": 19, + "column": 69 + } + } + }, + "property": { + "type": "Identifier", + "name": "trunc", + "loc": { + "start": { + "line": 19, + "column": 70 + }, + "end": { + "line": 19, + "column": 75 + } + } + }, + "computed": false, + "optional": false, + "loc": { + "start": { + "line": 19, + "column": 65 + }, + "end": { + "line": 19, + "column": 75 + } + } + }, + "arguments": [ + { + "type": "Identifier", + "name": "y", + "loc": { + "start": { + "line": 19, + "column": 76 + }, + "end": { + "line": 19, + "column": 77 + } + } + } + ], + "optional": false, + "loc": { + "start": { + "line": 19, + "column": 65 + }, + "end": { + "line": 19, + "column": 78 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 41 + }, + "end": { + "line": 19, + "column": 78 + } + } + }, + "right": { + "type": "BinaryExpression", + "operator": "|", + "left": { + "type": "Identifier", + "name": "y", + "loc": { + "start": { + "line": 19, + "column": 82 + }, + "end": { + "line": 19, + "column": 83 + } + } + }, + "right": { + "type": "NumberLiteral", + "value": 0, + "loc": { + "start": { + "line": 19, + "column": 84 + }, + "end": { + "line": 19, + "column": 85 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 81 + }, + "end": { + "line": 19, + "column": 86 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 40 + }, + "end": { + "line": 19, + "column": 87 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 22 + }, + "end": { + "line": 19, + "column": 87 + } + } + }, + "right": { + "type": "BinaryExpression", + "operator": "-", + "left": { + "type": "BinaryExpression", + "operator": "+", + "left": { + "type": "BinaryExpression", + "operator": "-", + "left": { + "type": "Identifier", + "name": "x", + "loc": { + "start": { + "line": 19, + "column": 91 + }, + "end": { + "line": 19, + "column": 92 + } + } + }, + "right": { + "type": "Identifier", + "name": "y", + "loc": { + "start": { + "line": 19, + "column": 93 + }, + "end": { + "line": 19, + "column": 94 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 91 + }, + "end": { + "line": 19, + "column": 94 + } + } + }, + "right": { + "type": "CallExpression", + "callee": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "Math", + "loc": { + "start": { + "line": 19, + "column": 95 + }, + "end": { + "line": 19, + "column": 99 + } + } + }, + "property": { + "type": "Identifier", + "name": "trunc", + "loc": { + "start": { + "line": 19, + "column": 100 + }, + "end": { + "line": 19, + "column": 105 + } + } + }, + "computed": false, + "optional": false, + "loc": { + "start": { + "line": 19, + "column": 95 + }, + "end": { + "line": 19, + "column": 105 + } + } + }, + "arguments": [ + { + "type": "Identifier", + "name": "y", + "loc": { + "start": { + "line": 19, + "column": 106 + }, + "end": { + "line": 19, + "column": 107 + } + } + } + ], + "optional": false, + "loc": { + "start": { + "line": 19, + "column": 95 + }, + "end": { + "line": 19, + "column": 108 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 91 + }, + "end": { + "line": 19, + "column": 108 + } + } + }, + "right": { + "type": "CallExpression", + "callee": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "Math", + "loc": { + "start": { + "line": 19, + "column": 111 + }, + "end": { + "line": 19, + "column": 115 + } + } + }, + "property": { + "type": "Identifier", + "name": "trunc", + "loc": { + "start": { + "line": 19, + "column": 116 + }, + "end": { + "line": 19, + "column": 121 + } + } + }, + "computed": false, + "optional": false, + "loc": { + "start": { + "line": 19, + "column": 111 + }, + "end": { + "line": 19, + "column": 121 + } + } + }, + "arguments": [ + { + "type": "Identifier", + "name": "x", + "loc": { + "start": { + "line": 19, + "column": 122 + }, + "end": { + "line": 19, + "column": 123 + } + } + } + ], + "optional": false, + "loc": { + "start": { + "line": 19, + "column": 111 + }, + "end": { + "line": 19, + "column": 124 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 90 + }, + "end": { + "line": 19, + "column": 125 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 21 + }, + "end": { + "line": 19, + "column": 126 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 17 + }, + "end": { + "line": 19, + "column": 126 + } + } + }, + "update": { + "type": "UpdateExpression", + "operator": "++", + "prefix": false, + "argument": { + "type": "Identifier", + "name": "i", + "loc": { + "start": { + "line": 19, + "column": 128 + }, + "end": { + "line": 19, + "column": 129 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 128 + }, + "end": { + "line": 19, + "column": 131 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 19, + "column": 133 + }, + "end": { + "line": 20, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 1 + }, + "end": { + "line": 20, + "column": 2 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 20, + "column": 2 + } + } +} diff --git a/es2panda/test/parser/ts/test_for_statement_condition_with_expression2.ts b/es2panda/test/parser/ts/test_for_statement_condition_with_expression2.ts new file mode 100644 index 0000000000000000000000000000000000000000..8909251be6d88d26b89199e1d73a8b9d1dd6f5ab --- /dev/null +++ b/es2panda/test/parser/ts/test_for_statement_condition_with_expression2.ts @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2024 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. + */ + + +let x: number = 10; +let y: number = 12; +for (let i = 0; i < ((x&~y) - (~x&y) + (Math.trunc(x) - (x|0) - Math.trunc(y) + (y|0)) + (x-y+Math.trunc(y) - Math.trunc(x))); i++) { +} \ No newline at end of file