From 2e17e5f22e4c293c454f24ce71cca22ff517839b Mon Sep 17 00:00:00 2001 From: xucheng46 Date: Wed, 12 Oct 2022 17:53:39 +0800 Subject: [PATCH] Fix parse of type assersion expression in await Issue: https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/I5VD3W Test: parse tests, compiler tests, test262 Signed-off-by: xucheng46 Change-Id: I4a7c145dbf2f275f02c51faa421db99b4b4b61e7 --- es2panda/parser/expressionParser.cpp | 3 + .../test/parser/ts/test-await-expected.txt | 752 ++++++++++++++++++ es2panda/test/parser/ts/test-await.ts | 27 + es2panda/test/test_tsc_ignore_list.txt | 1 - 4 files changed, 782 insertions(+), 1 deletion(-) create mode 100644 es2panda/test/parser/ts/test-await-expected.txt create mode 100644 es2panda/test/parser/ts/test-await.ts diff --git a/es2panda/parser/expressionParser.cpp b/es2panda/parser/expressionParser.cpp index 56bbe33c8d..92a0998bb3 100644 --- a/es2panda/parser/expressionParser.cpp +++ b/es2panda/parser/expressionParser.cpp @@ -1108,6 +1108,9 @@ ir::Expression *ParserImpl::ParsePrimaryExpression(ExpressionParseFlags flags) case lexer::TokenType::PUNCTUATOR_BACK_TICK: { return ParseTemplateLiteral(); } + case lexer::TokenType::PUNCTUATOR_LESS_THAN: { + return ParseTsTypeAssertion(); + } default: { break; } diff --git a/es2panda/test/parser/ts/test-await-expected.txt b/es2panda/test/parser/ts/test-await-expected.txt new file mode 100644 index 0000000000..fe32fc10ff --- /dev/null +++ b/es2panda/test/parser/ts/test-await-expected.txt @@ -0,0 +1,752 @@ +{ + "type": "Program", + "statements": [ + { + "type": "FunctionDeclaration", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "f", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 16 + }, + "end": { + "line": 17, + "column": 17 + } + } + }, + "generator": false, + "async": true, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ExpressionStatement", + "expression": { + "type": "AwaitExpression", + "argument": { + "type": "NumberLiteral", + "value": 0, + "loc": { + "start": { + "line": 18, + "column": 11 + }, + "end": { + "line": 18, + "column": 12 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 5 + }, + "end": { + "line": 18, + "column": 12 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 5 + }, + "end": { + "line": 18, + "column": 13 + } + } + }, + { + "type": "ExpressionStatement", + "expression": { + "type": "UnaryExpression", + "operator": "void", + "prefix": true, + "argument": { + "type": "AwaitExpression", + "argument": { + "type": "NumberLiteral", + "value": 0, + "loc": { + "start": { + "line": 19, + "column": 16 + }, + "end": { + "line": 19, + "column": 17 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 10 + }, + "end": { + "line": 19, + "column": 17 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 5 + }, + "end": { + "line": 19, + "column": 17 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 5 + }, + "end": { + "line": 19, + "column": 18 + } + } + }, + { + "type": "ExpressionStatement", + "expression": { + "type": "AwaitExpression", + "argument": { + "type": "AwaitExpression", + "argument": { + "type": "NumberLiteral", + "value": 0, + "loc": { + "start": { + "line": 20, + "column": 17 + }, + "end": { + "line": 20, + "column": 18 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 11 + }, + "end": { + "line": 20, + "column": 18 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 5 + }, + "end": { + "line": 20, + "column": 18 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 5 + }, + "end": { + "line": 20, + "column": 19 + } + } + }, + { + "type": "ExpressionStatement", + "expression": { + "type": "TSTypeAssertion", + "typeAnnotation": { + "type": "TSNumberKeyword", + "loc": { + "start": { + "line": 21, + "column": 6 + }, + "end": { + "line": 21, + "column": 12 + } + } + }, + "expression": { + "type": "AwaitExpression", + "argument": { + "type": "NumberLiteral", + "value": 0, + "loc": { + "start": { + "line": 21, + "column": 20 + }, + "end": { + "line": 21, + "column": 21 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 14 + }, + "end": { + "line": 21, + "column": 21 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 5 + }, + "end": { + "line": 21, + "column": 22 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 5 + }, + "end": { + "line": 21, + "column": 22 + } + } + }, + { + "type": "ExpressionStatement", + "expression": { + "type": "TSTypeAssertion", + "typeAnnotation": { + "type": "TSNumberKeyword", + "loc": { + "start": { + "line": 22, + "column": 6 + }, + "end": { + "line": 22, + "column": 12 + } + } + }, + "expression": { + "type": "UnaryExpression", + "operator": "void", + "prefix": true, + "argument": { + "type": "AwaitExpression", + "argument": { + "type": "NumberLiteral", + "value": 0, + "loc": { + "start": { + "line": 22, + "column": 25 + }, + "end": { + "line": 22, + "column": 26 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 19 + }, + "end": { + "line": 22, + "column": 26 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 14 + }, + "end": { + "line": 22, + "column": 26 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 5 + }, + "end": { + "line": 22, + "column": 27 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 5 + }, + "end": { + "line": 22, + "column": 27 + } + } + }, + { + "type": "ExpressionStatement", + "expression": { + "type": "UnaryExpression", + "operator": "typeof", + "prefix": true, + "argument": { + "type": "AwaitExpression", + "argument": { + "type": "NumberLiteral", + "value": 0, + "loc": { + "start": { + "line": 23, + "column": 18 + }, + "end": { + "line": 23, + "column": 19 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 12 + }, + "end": { + "line": 23, + "column": 19 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 5 + }, + "end": { + "line": 23, + "column": 19 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 5 + }, + "end": { + "line": 23, + "column": 20 + } + } + }, + { + "type": "ExpressionStatement", + "expression": { + "type": "UnaryExpression", + "operator": "typeof", + "prefix": true, + "argument": { + "type": "UnaryExpression", + "operator": "void", + "prefix": true, + "argument": { + "type": "AwaitExpression", + "argument": { + "type": "NumberLiteral", + "value": 0, + "loc": { + "start": { + "line": 24, + "column": 23 + }, + "end": { + "line": 24, + "column": 24 + } + } + }, + "loc": { + "start": { + "line": 24, + "column": 17 + }, + "end": { + "line": 24, + "column": 24 + } + } + }, + "loc": { + "start": { + "line": 24, + "column": 12 + }, + "end": { + "line": 24, + "column": 24 + } + } + }, + "loc": { + "start": { + "line": 24, + "column": 5 + }, + "end": { + "line": 24, + "column": 24 + } + } + }, + "loc": { + "start": { + "line": 24, + "column": 5 + }, + "end": { + "line": 24, + "column": 25 + } + } + }, + { + "type": "ExpressionStatement", + "expression": { + "type": "TSTypeAssertion", + "typeAnnotation": { + "type": "TSStringKeyword", + "loc": { + "start": { + "line": 25, + "column": 6 + }, + "end": { + "line": 25, + "column": 12 + } + } + }, + "expression": { + "type": "UnaryExpression", + "operator": "typeof", + "prefix": true, + "argument": { + "type": "TSTypeAssertion", + "typeAnnotation": { + "type": "TSNumberKeyword", + "loc": { + "start": { + "line": 25, + "column": 22 + }, + "end": { + "line": 25, + "column": 28 + } + } + }, + "expression": { + "type": "UnaryExpression", + "operator": "void", + "prefix": true, + "argument": { + "type": "AwaitExpression", + "argument": { + "type": "NumberLiteral", + "value": 0, + "loc": { + "start": { + "line": 25, + "column": 41 + }, + "end": { + "line": 25, + "column": 42 + } + } + }, + "loc": { + "start": { + "line": 25, + "column": 35 + }, + "end": { + "line": 25, + "column": 42 + } + } + }, + "loc": { + "start": { + "line": 25, + "column": 30 + }, + "end": { + "line": 25, + "column": 42 + } + } + }, + "loc": { + "start": { + "line": 25, + "column": 21 + }, + "end": { + "line": 25, + "column": 43 + } + } + }, + "loc": { + "start": { + "line": 25, + "column": 14 + }, + "end": { + "line": 25, + "column": 43 + } + } + }, + "loc": { + "start": { + "line": 25, + "column": 5 + }, + "end": { + "line": 25, + "column": 43 + } + } + }, + "loc": { + "start": { + "line": 25, + "column": 5 + }, + "end": { + "line": 25, + "column": 43 + } + } + }, + { + "type": "ExpressionStatement", + "expression": { + "type": "AwaitExpression", + "argument": { + "type": "TSTypeAssertion", + "typeAnnotation": { + "type": "TSStringKeyword", + "loc": { + "start": { + "line": 26, + "column": 12 + }, + "end": { + "line": 26, + "column": 18 + } + } + }, + "expression": { + "type": "UnaryExpression", + "operator": "typeof", + "prefix": true, + "argument": { + "type": "TSTypeAssertion", + "typeAnnotation": { + "type": "TSNumberKeyword", + "loc": { + "start": { + "line": 26, + "column": 28 + }, + "end": { + "line": 26, + "column": 34 + } + } + }, + "expression": { + "type": "UnaryExpression", + "operator": "void", + "prefix": true, + "argument": { + "type": "AwaitExpression", + "argument": { + "type": "NumberLiteral", + "value": 0, + "loc": { + "start": { + "line": 26, + "column": 47 + }, + "end": { + "line": 26, + "column": 48 + } + } + }, + "loc": { + "start": { + "line": 26, + "column": 41 + }, + "end": { + "line": 26, + "column": 48 + } + } + }, + "loc": { + "start": { + "line": 26, + "column": 36 + }, + "end": { + "line": 26, + "column": 48 + } + } + }, + "loc": { + "start": { + "line": 26, + "column": 27 + }, + "end": { + "line": 26, + "column": 49 + } + } + }, + "loc": { + "start": { + "line": 26, + "column": 20 + }, + "end": { + "line": 26, + "column": 49 + } + } + }, + "loc": { + "start": { + "line": 26, + "column": 11 + }, + "end": { + "line": 26, + "column": 49 + } + } + }, + "loc": { + "start": { + "line": 26, + "column": 5 + }, + "end": { + "line": 26, + "column": 49 + } + } + }, + "loc": { + "start": { + "line": 26, + "column": 5 + }, + "end": { + "line": 26, + "column": 49 + } + } + } + ], + "loc": { + "start": { + "line": 17, + "column": 20 + }, + "end": { + "line": 27, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 7 + }, + "end": { + "line": 27, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 1 + }, + "end": { + "line": 27, + "column": 2 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 28, + "column": 1 + } + } +} diff --git a/es2panda/test/parser/ts/test-await.ts b/es2panda/test/parser/ts/test-await.ts new file mode 100644 index 0000000000..ea715d7562 --- /dev/null +++ b/es2panda/test/parser/ts/test-await.ts @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2022 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. + */ + + +async function f() { + await 0; + void await 0; + await await 0; + await 0; + void await 0; + typeof await 0; + typeof void await 0; + typeof void await 0; + await typeof void await 0; +} diff --git a/es2panda/test/test_tsc_ignore_list.txt b/es2panda/test/test_tsc_ignore_list.txt index 716ca0e026..9f0858d10a 100644 --- a/es2panda/test/test_tsc_ignore_list.txt +++ b/es2panda/test/test_tsc_ignore_list.txt @@ -3,7 +3,6 @@ es2panda/test/TypeScript/tests/cases/compiler/arrowFunctionWithObjectLiteralBody es2panda/test/TypeScript/tests/cases/compiler/arrowFunctionWithObjectLiteralBody6.ts es2panda/test/TypeScript/tests/cases/compiler/assertionFunctionsCanNarrowByDiscriminant.ts es2panda/test/TypeScript/tests/cases/compiler/bom-utf16be.ts -es2panda/test/TypeScript/tests/cases/compiler/castOfAwait.ts es2panda/test/TypeScript/tests/cases/compiler/castTest.ts es2panda/test/TypeScript/tests/cases/compiler/classFunctionMerging.ts es2panda/test/TypeScript/tests/cases/compiler/collisionArgumentsInType.ts -- Gitee