diff --git a/es2panda/parser/parserImpl.cpp b/es2panda/parser/parserImpl.cpp index 5adcebbc4b7a6940fa234595ae8ac24bdc352309..7d6653311c9a2979aa61753ee82351ccb26dfc59 100644 --- a/es2panda/parser/parserImpl.cpp +++ b/es2panda/parser/parserImpl.cpp @@ -1016,7 +1016,8 @@ ir::Expression *ParserImpl::ParseTsQualifiedReference(ir::Expression *typeName) ir::Expression *ParserImpl::ParseTsIndexAccessType(ir::Expression *typeName, bool throwError) { - TypeAnnotationParsingOptions options = TypeAnnotationParsingOptions::THROW_ERROR; + TypeAnnotationParsingOptions options = throwError ? + TypeAnnotationParsingOptions::THROW_ERROR : TypeAnnotationParsingOptions::NO_OPTS; do { lexer_->NextToken(); // eat '[' diff --git a/es2panda/test/parser/ts/test-lessThan-expression3-expected.txt b/es2panda/test/parser/ts/test-lessThan-expression3-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..4808ad75e77a64bd391a85901ec9d9727cfa495d --- /dev/null +++ b/es2panda/test/parser/ts/test-lessThan-expression3-expected.txt @@ -0,0 +1,215 @@ +{ + "type": "Program", + "statements": [ + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "result", + "loc": { + "start": { + "line": 17, + "column": 5 + }, + "end": { + "line": 17, + "column": 11 + } + } + }, + "init": { + "type": "BinaryExpression", + "operator": "<", + "left": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "x", + "loc": { + "start": { + "line": 17, + "column": 14 + }, + "end": { + "line": 17, + "column": 15 + } + } + }, + "property": { + "type": "NumberLiteral", + "value": 1, + "loc": { + "start": { + "line": 17, + "column": 16 + }, + "end": { + "line": 17, + "column": 17 + } + } + }, + "computed": true, + "optional": false, + "loc": { + "start": { + "line": 17, + "column": 14 + }, + "end": { + "line": 17, + "column": 18 + } + } + }, + "right": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "x", + "loc": { + "start": { + "line": 17, + "column": 21 + }, + "end": { + "line": 17, + "column": 22 + } + } + }, + "property": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "y", + "loc": { + "start": { + "line": 17, + "column": 23 + }, + "end": { + "line": 17, + "column": 24 + } + } + }, + "property": { + "type": "BinaryExpression", + "operator": ">>", + "left": { + "type": "NumberLiteral", + "value": 2, + "loc": { + "start": { + "line": 17, + "column": 25 + }, + "end": { + "line": 17, + "column": 26 + } + } + }, + "right": { + "type": "NumberLiteral", + "value": 1, + "loc": { + "start": { + "line": 17, + "column": 30 + }, + "end": { + "line": 17, + "column": 31 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 25 + }, + "end": { + "line": 17, + "column": 31 + } + } + }, + "computed": true, + "optional": false, + "loc": { + "start": { + "line": 17, + "column": 23 + }, + "end": { + "line": 17, + "column": 32 + } + } + }, + "computed": true, + "optional": false, + "loc": { + "start": { + "line": 17, + "column": 21 + }, + "end": { + "line": 17, + "column": 33 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 14 + }, + "end": { + "line": 17, + "column": 33 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 5 + }, + "end": { + "line": 17, + "column": 33 + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 17, + "column": 1 + }, + "end": { + "line": 17, + "column": 34 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 18, + "column": 1 + } + } +} diff --git a/es2panda/test/parser/ts/test-lessThan-expression3.ts b/es2panda/test/parser/ts/test-lessThan-expression3.ts new file mode 100644 index 0000000000000000000000000000000000000000..1c4088d28ea3fe29995479937ab22ba58a484e50 --- /dev/null +++ b/es2panda/test/parser/ts/test-lessThan-expression3.ts @@ -0,0 +1,17 @@ +/* + * 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. + */ + + +let result = x[1] < x[y[2 >> 1]];