diff --git a/es2panda/parser/expressionParser.cpp b/es2panda/parser/expressionParser.cpp index 56bbe33c8d7ca8acb512965934f4df6a38621cf4..92a0998bb37677f96451389a38690d25bde4177c 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 0000000000000000000000000000000000000000..fe32fc10ff8c6859cf47a4d450f96269bae0bbc7 --- /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 0000000000000000000000000000000000000000..ea715d756294e8226df2fd1072517689ec5d02f3 --- /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 716ca0e026f689dcceeda7c22a77f185ffb6a9b7..9f0858d10a36c8078b5ea404d28b698a9947018c 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