From 591785a2cc75f6e8c15c152b503859594b764414 Mon Sep 17 00:00:00 2001 From: songqi Date: Mon, 31 Jul 2023 12:05:45 +0800 Subject: [PATCH] Fix parser of ParseTsIndexAccessType Issue: I7P8LQ Tests: test_es2abc Signed-off-by: songqi Change-Id: Ie8199a0f713197092a1c1729ca5de5afaafc6729 --- es2panda/parser/parserImpl.cpp | 3 +- .../ts/test-lessThan-expression3-expected.txt | 215 ++++++++++++++++++ .../parser/ts/test-lessThan-expression3.ts | 17 ++ 3 files changed, 234 insertions(+), 1 deletion(-) create mode 100644 es2panda/test/parser/ts/test-lessThan-expression3-expected.txt create mode 100644 es2panda/test/parser/ts/test-lessThan-expression3.ts diff --git a/es2panda/parser/parserImpl.cpp b/es2panda/parser/parserImpl.cpp index 5adcebbc4b..7d6653311c 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 0000000000..4808ad75e7 --- /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 0000000000..1c4088d28e --- /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]]; -- Gitee