From 1266c50f4520147f83b328fdfaef4545b558bfb7 Mon Sep 17 00:00:00 2001 From: xucheng46 Date: Wed, 19 Oct 2022 11:16:52 +0800 Subject: [PATCH] Fix identifier expected problems Issue: https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/I5WKEQ Test: parser tests, compiler tests, test262 Signed-off-by: xucheng46 Change-Id: I672411e6c6dbaf6872e2997c7e4f04765ed05078 --- es2panda/parser/parserImpl.cpp | 2 +- es2panda/parser/parserImpl.h | 1 + es2panda/parser/statementParser.cpp | 62 ++- .../parser/ts/test-interface2-expected.txt | 2 +- .../ts/test-keyword-identify1-expected.txt | 328 +++++++++++ .../test/parser/ts/test-keyword-identify1.ts | 25 + .../ts/test-keyword-identify2-expected.txt | 398 ++++++++++++++ .../test/parser/ts/test-keyword-identify2.ts | 26 + .../ts/test-keyword-identify3-expected.txt | 380 +++++++++++++ .../test/parser/ts/test-keyword-identify3.ts | 24 + .../ts/test-keyword-identify4-expected.txt | 329 +++++++++++ .../test/parser/ts/test-keyword-identify4.ts | 24 + .../ts/test-keyword-identify5-expected.txt | 510 ++++++++++++++++++ .../test/parser/ts/test-keyword-identify5.ts | 32 ++ .../ts/test-keyword-identify6-expected.txt | 324 +++++++++++ .../test/parser/ts/test-keyword-identify6.ts | 24 + .../ts/test-keyword-identify7-expected.txt | 231 ++++++++ .../test/parser/ts/test-keyword-identify7.ts | 21 + .../parser/ts/test-type-alias1-expected.txt | 2 +- .../ts/test-type-annotation2-expected.txt | 392 ++++++++++++++ .../test/parser/ts/test-type-annotation2.ts | 23 + .../test/parser/ts/test_module10-expected.txt | 160 ++++++ es2panda/test/parser/ts/test_module10.ts | 20 + .../test/parser/ts/test_module7-expected.txt | 444 +++++++++++++++ es2panda/test/parser/ts/test_module7.ts | 24 + .../test/parser/ts/test_module8-expected.txt | 75 +++ es2panda/test/parser/ts/test_module8.ts | 18 + .../test/parser/ts/test_module9-expected.txt | 61 +++ es2panda/test/parser/ts/test_module9.ts | 18 + es2panda/test/test_tsc_ignore_list.txt | 3 - 30 files changed, 3970 insertions(+), 13 deletions(-) create mode 100644 es2panda/test/parser/ts/test-keyword-identify1-expected.txt create mode 100644 es2panda/test/parser/ts/test-keyword-identify1.ts create mode 100644 es2panda/test/parser/ts/test-keyword-identify2-expected.txt create mode 100644 es2panda/test/parser/ts/test-keyword-identify2.ts create mode 100644 es2panda/test/parser/ts/test-keyword-identify3-expected.txt create mode 100644 es2panda/test/parser/ts/test-keyword-identify3.ts create mode 100644 es2panda/test/parser/ts/test-keyword-identify4-expected.txt create mode 100644 es2panda/test/parser/ts/test-keyword-identify4.ts create mode 100644 es2panda/test/parser/ts/test-keyword-identify5-expected.txt create mode 100644 es2panda/test/parser/ts/test-keyword-identify5.ts create mode 100644 es2panda/test/parser/ts/test-keyword-identify6-expected.txt create mode 100644 es2panda/test/parser/ts/test-keyword-identify6.ts create mode 100644 es2panda/test/parser/ts/test-keyword-identify7-expected.txt create mode 100644 es2panda/test/parser/ts/test-keyword-identify7.ts create mode 100644 es2panda/test/parser/ts/test-type-annotation2-expected.txt create mode 100644 es2panda/test/parser/ts/test-type-annotation2.ts create mode 100644 es2panda/test/parser/ts/test_module10-expected.txt create mode 100644 es2panda/test/parser/ts/test_module10.ts create mode 100644 es2panda/test/parser/ts/test_module7-expected.txt create mode 100644 es2panda/test/parser/ts/test_module7.ts create mode 100644 es2panda/test/parser/ts/test_module8-expected.txt create mode 100644 es2panda/test/parser/ts/test_module8.ts create mode 100644 es2panda/test/parser/ts/test_module9-expected.txt create mode 100644 es2panda/test/parser/ts/test_module9.ts diff --git a/es2panda/parser/parserImpl.cpp b/es2panda/parser/parserImpl.cpp index 728a446cf4..5bb2f0ef9b 100644 --- a/es2panda/parser/parserImpl.cpp +++ b/es2panda/parser/parserImpl.cpp @@ -926,7 +926,7 @@ ir::Expression *ParserImpl::ParseTsQualifiedReference(ir::Expression *typeName) lexer::SourcePosition startLoc = typeName->Start(); do { - lexer_->NextToken(); // eat '.' + lexer_->NextToken(lexer::LexerNextTokenFlags::KEYWORD_TO_IDENT); // eat '.' if (lexer_->GetToken().Type() != lexer::TokenType::LITERAL_IDENT) { ThrowSyntaxError("Identifier expected"); diff --git a/es2panda/parser/parserImpl.h b/es2panda/parser/parserImpl.h index ad31d00a8e..5dcd841f30 100644 --- a/es2panda/parser/parserImpl.h +++ b/es2panda/parser/parserImpl.h @@ -437,6 +437,7 @@ private: bool ParseDirective(ArenaVector *statements); void ParseDirectivePrologue(ArenaVector *statements); ArenaVector ParseStatementList(StatementParsingFlags flags = StatementParsingFlags::ALLOW_LEXICAL); + bool IsTsDeclarationStatement() const; ir::Statement *ParseStatement(StatementParsingFlags flags = StatementParsingFlags::NONE); ir::TSModuleDeclaration *ParseTsModuleDeclaration(bool isDeclare, bool isExport = false); ir::TSModuleDeclaration *ParseTsAmbientExternalModuleDeclaration(const lexer::SourcePosition &startLoc, diff --git a/es2panda/parser/statementParser.cpp b/es2panda/parser/statementParser.cpp index ff80d42d1c..8f27503438 100644 --- a/es2panda/parser/statementParser.cpp +++ b/es2panda/parser/statementParser.cpp @@ -89,6 +89,10 @@ bool ParserImpl::CheckDeclare() const auto startPos = lexer_->Save(); lexer_->NextToken(); // eat 'declare' + if (lexer_->GetToken().NewLine()) { + lexer_->Rewind(startPos); + return false; + } switch (lexer_->GetToken().Type()) { case lexer::TokenType::KEYW_VAR: case lexer::TokenType::KEYW_LET: @@ -147,6 +151,47 @@ bool ParserImpl::IsLabelFollowedByIterationStatement() } return false; } + +bool ParserImpl::IsTsDeclarationStatement() const +{ + const auto startPos = lexer_->Save(); + bool isTsDeclarationStatement = false; + + auto keywordType = lexer_->GetToken().KeywordType(); + lexer_->NextToken(); + switch (keywordType) { + case lexer::TokenType::KEYW_MODULE: + case lexer::TokenType::KEYW_NAMESPACE: { + isTsDeclarationStatement = !lexer_->GetToken().NewLine() && + (lexer_->GetToken().Type() == lexer::TokenType::LITERAL_IDENT || + lexer_->GetToken().Type() == lexer::TokenType::LITERAL_STRING); + break; + } + case lexer::TokenType::KEYW_GLOBAL: { + isTsDeclarationStatement = lexer_->GetToken().Type() == lexer::TokenType::LITERAL_IDENT || + lexer_->GetToken().Type() == lexer::TokenType::PUNCTUATOR_LEFT_BRACE || + lexer_->GetToken().Type() == lexer::TokenType::KEYW_EXPORT; + break; + } + case lexer::TokenType::KEYW_INTERFACE: + case lexer::TokenType::KEYW_TYPE: { + isTsDeclarationStatement = !lexer_->GetToken().NewLine() && + lexer_->GetToken().Type() == lexer::TokenType::LITERAL_IDENT; + break; + } + case lexer::TokenType::KEYW_ENUM: { + isTsDeclarationStatement = true; + break; + } + default: { + break; + } + } + + lexer_->Rewind(startPos); + return isTsDeclarationStatement; +} + ir::Statement *ParserImpl::ParseStatement(StatementParsingFlags flags) { bool isDeclare = false; @@ -158,17 +203,20 @@ ir::Statement *ParserImpl::ParseStatement(StatementParsingFlags flags) } if (lexer_->GetToken().KeywordType() == lexer::TokenType::KEYW_ABSTRACT) { + const auto startPos = lexer_->Save(); lexer_->NextToken(); // eat abstract keyword if (lexer_->GetToken().Type() != lexer::TokenType::KEYW_CLASS) { - ThrowSyntaxError("abstract modifier can only appear on a class, method, or property declaration."); + lexer_->Rewind(startPos); + } else { + return ParseClassStatement(flags, isDeclare, std::move(decorators), true); } - return ParseClassStatement(flags, isDeclare, std::move(decorators), true); } - if (lexer_->GetToken().KeywordType() == lexer::TokenType::KEYW_GLOBAL || - lexer_->GetToken().KeywordType() == lexer::TokenType::KEYW_MODULE || - lexer_->GetToken().KeywordType() == lexer::TokenType::KEYW_NAMESPACE) { + if ((lexer_->GetToken().KeywordType() == lexer::TokenType::KEYW_GLOBAL || + lexer_->GetToken().KeywordType() == lexer::TokenType::KEYW_MODULE || + lexer_->GetToken().KeywordType() == lexer::TokenType::KEYW_NAMESPACE) && + IsTsDeclarationStatement()) { auto savedStatus = context_.Status(); if (isDeclare) { context_.Status() |= ParserStatus::IN_AMBIENT_CONTEXT; @@ -304,7 +352,7 @@ ir::TSModuleDeclaration *ParserImpl::ParseTsAmbientExternalModuleDeclaration(con body = ParseTsModuleBlock(); } else if (lexer_->GetToken().Type() == lexer::TokenType::PUNCTUATOR_SEMI_COLON) { lexer_->NextToken(); - } else { + } else if (!lexer_->GetToken().NewLine()) { ThrowSyntaxError("';' expected"); } @@ -572,7 +620,7 @@ ir::Statement *ParserImpl::ParsePotentialExpressionStatement(StatementParsingFla return ParseLabelledStatement(pos); } - if (Extension() == ScriptExtension::TS) { + if (Extension() == ScriptExtension::TS && IsTsDeclarationStatement()) { switch (lexer_->GetToken().KeywordType()) { case lexer::TokenType::KEYW_ENUM: { return ParseEnumDeclaration(false, isDeclare, false); diff --git a/es2panda/test/parser/ts/test-interface2-expected.txt b/es2panda/test/parser/ts/test-interface2-expected.txt index dcdfdaa0b0..45fa92dda5 100644 --- a/es2panda/test/parser/ts/test-interface2-expected.txt +++ b/es2panda/test/parser/ts/test-interface2-expected.txt @@ -1 +1 @@ -SyntaxError: Identifier expected [test-interface2.ts:17:11] +SyntaxError: Unexpected token [test-interface2.ts:17:11] diff --git a/es2panda/test/parser/ts/test-keyword-identify1-expected.txt b/es2panda/test/parser/ts/test-keyword-identify1-expected.txt new file mode 100644 index 0000000000..d549a6d74f --- /dev/null +++ b/es2panda/test/parser/ts/test-keyword-identify1-expected.txt @@ -0,0 +1,328 @@ +{ + "type": "Program", + "statements": [ + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "namespace", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 5 + }, + "end": { + "line": 17, + "column": 14 + } + } + }, + "init": { + "type": "NumberLiteral", + "value": 1, + "loc": { + "start": { + "line": 17, + "column": 17 + }, + "end": { + "line": 17, + "column": 18 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 5 + }, + "end": { + "line": 17, + "column": 18 + } + } + }, + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "ns", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 20 + }, + "end": { + "line": 17, + "column": 22 + } + } + }, + "init": { + "type": "NumberLiteral", + "value": 2, + "loc": { + "start": { + "line": 17, + "column": 25 + }, + "end": { + "line": 17, + "column": 26 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 20 + }, + "end": { + "line": 17, + "column": 26 + } + } + } + ], + "kind": "var", + "loc": { + "start": { + "line": 17, + "column": 1 + }, + "end": { + "line": 17, + "column": 27 + } + } + }, + { + "type": "ExpressionStatement", + "expression": { + "type": "AssignmentExpression", + "operator": "=", + "left": { + "type": "Identifier", + "name": "namespace", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 1 + }, + "end": { + "line": 18, + "column": 10 + } + } + }, + "right": { + "type": "NumberLiteral", + "value": 2, + "loc": { + "start": { + "line": 18, + "column": 13 + }, + "end": { + "line": 18, + "column": 14 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 1 + }, + "end": { + "line": 18, + "column": 14 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 1 + }, + "end": { + "line": 18, + "column": 15 + } + } + }, + { + "type": "ExpressionStatement", + "expression": { + "type": "UpdateExpression", + "operator": "++", + "prefix": false, + "argument": { + "type": "Identifier", + "name": "namespace", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 1 + }, + "end": { + "line": 19, + "column": 10 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 1 + }, + "end": { + "line": 19, + "column": 12 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 1 + }, + "end": { + "line": 19, + "column": 13 + } + } + }, + { + "type": "ExpressionStatement", + "expression": { + "type": "Identifier", + "name": "namespace", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 1 + }, + "end": { + "line": 21, + "column": 10 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 1 + }, + "end": { + "line": 21, + "column": 10 + } + } + }, + { + "type": "ExpressionStatement", + "expression": { + "type": "Identifier", + "name": "ns", + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 1 + }, + "end": { + "line": 22, + "column": 3 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 1 + }, + "end": { + "line": 22, + "column": 3 + } + } + }, + { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 23, + "column": 1 + }, + "end": { + "line": 23, + "column": 3 + } + } + }, + { + "type": "TSModuleDeclaration", + "id": { + "type": "Identifier", + "name": "N", + "decorators": [], + "loc": { + "start": { + "line": 25, + "column": 11 + }, + "end": { + "line": 25, + "column": 12 + } + } + }, + "body": { + "type": "TSModuleBlock", + "body": [], + "loc": { + "start": { + "line": 25, + "column": 13 + }, + "end": { + "line": 25, + "column": 15 + } + } + }, + "declare": false, + "global": false, + "loc": { + "start": { + "line": 25, + "column": 1 + }, + "end": { + "line": 25, + "column": 15 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 25, + "column": 15 + } + } +} diff --git a/es2panda/test/parser/ts/test-keyword-identify1.ts b/es2panda/test/parser/ts/test-keyword-identify1.ts new file mode 100644 index 0000000000..9c48819f23 --- /dev/null +++ b/es2panda/test/parser/ts/test-keyword-identify1.ts @@ -0,0 +1,25 @@ +/* + * 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. + */ + + +var namespace = 1, ns = 2; +namespace = 2; +namespace++; + +namespace +ns +{} + +namespace N {} \ No newline at end of file diff --git a/es2panda/test/parser/ts/test-keyword-identify2-expected.txt b/es2panda/test/parser/ts/test-keyword-identify2-expected.txt new file mode 100644 index 0000000000..956fb3fe17 --- /dev/null +++ b/es2panda/test/parser/ts/test-keyword-identify2-expected.txt @@ -0,0 +1,398 @@ +{ + "type": "Program", + "statements": [ + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "declare", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 5 + }, + "end": { + "line": 17, + "column": 12 + } + } + }, + "init": { + "type": "NumberLiteral", + "value": 0, + "loc": { + "start": { + "line": 17, + "column": 15 + }, + "end": { + "line": 17, + "column": 16 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 5 + }, + "end": { + "line": 17, + "column": 16 + } + } + }, + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "namespace", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 18 + }, + "end": { + "line": 17, + "column": 27 + } + } + }, + "init": { + "type": "NumberLiteral", + "value": 1, + "loc": { + "start": { + "line": 17, + "column": 30 + }, + "end": { + "line": 17, + "column": 31 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 18 + }, + "end": { + "line": 17, + "column": 31 + } + } + }, + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "ns", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 33 + }, + "end": { + "line": 17, + "column": 35 + } + } + }, + "init": { + "type": "NumberLiteral", + "value": 2, + "loc": { + "start": { + "line": 17, + "column": 38 + }, + "end": { + "line": 17, + "column": 39 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 33 + }, + "end": { + "line": 17, + "column": 39 + } + } + } + ], + "kind": "var", + "loc": { + "start": { + "line": 17, + "column": 1 + }, + "end": { + "line": 17, + "column": 40 + } + } + }, + { + "type": "ExpressionStatement", + "expression": { + "type": "AssignmentExpression", + "operator": "=", + "left": { + "type": "Identifier", + "name": "declare", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 1 + }, + "end": { + "line": 18, + "column": 8 + } + } + }, + "right": { + "type": "NumberLiteral", + "value": 2, + "loc": { + "start": { + "line": 18, + "column": 11 + }, + "end": { + "line": 18, + "column": 12 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 1 + }, + "end": { + "line": 18, + "column": 12 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 1 + }, + "end": { + "line": 18, + "column": 13 + } + } + }, + { + "type": "ExpressionStatement", + "expression": { + "type": "UpdateExpression", + "operator": "++", + "prefix": false, + "argument": { + "type": "Identifier", + "name": "declare", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 1 + }, + "end": { + "line": 19, + "column": 8 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 1 + }, + "end": { + "line": 19, + "column": 10 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 1 + }, + "end": { + "line": 19, + "column": 11 + } + } + }, + { + "type": "ExpressionStatement", + "expression": { + "type": "Identifier", + "name": "declare", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 1 + }, + "end": { + "line": 21, + "column": 8 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 1 + }, + "end": { + "line": 21, + "column": 8 + } + } + }, + { + "type": "ExpressionStatement", + "expression": { + "type": "Identifier", + "name": "namespace", + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 1 + }, + "end": { + "line": 22, + "column": 10 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 1 + }, + "end": { + "line": 22, + "column": 10 + } + } + }, + { + "type": "ExpressionStatement", + "expression": { + "type": "Identifier", + "name": "ns", + "decorators": [], + "loc": { + "start": { + "line": 23, + "column": 1 + }, + "end": { + "line": 23, + "column": 3 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 1 + }, + "end": { + "line": 23, + "column": 3 + } + } + }, + { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 24, + "column": 1 + }, + "end": { + "line": 24, + "column": 3 + } + } + }, + { + "type": "TSModuleDeclaration", + "id": { + "type": "Identifier", + "name": "declare", + "decorators": [], + "loc": { + "start": { + "line": 26, + "column": 19 + }, + "end": { + "line": 26, + "column": 26 + } + } + }, + "body": { + "type": "TSModuleBlock", + "body": [], + "loc": { + "start": { + "line": 26, + "column": 27 + }, + "end": { + "line": 26, + "column": 29 + } + } + }, + "declare": true, + "global": false, + "loc": { + "start": { + "line": 26, + "column": 9 + }, + "end": { + "line": 26, + "column": 29 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 26, + "column": 29 + } + } +} diff --git a/es2panda/test/parser/ts/test-keyword-identify2.ts b/es2panda/test/parser/ts/test-keyword-identify2.ts new file mode 100644 index 0000000000..a2c2b9b4f7 --- /dev/null +++ b/es2panda/test/parser/ts/test-keyword-identify2.ts @@ -0,0 +1,26 @@ +/* + * 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. + */ + + +var declare = 0, namespace = 1, ns = 2; +declare = 2; +declare++; + +declare +namespace +ns +{} + +declare namespace declare {} \ No newline at end of file diff --git a/es2panda/test/parser/ts/test-keyword-identify3-expected.txt b/es2panda/test/parser/ts/test-keyword-identify3-expected.txt new file mode 100644 index 0000000000..cd992f311d --- /dev/null +++ b/es2panda/test/parser/ts/test-keyword-identify3-expected.txt @@ -0,0 +1,380 @@ +{ + "type": "Program", + "statements": [ + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "abstract", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 5 + }, + "end": { + "line": 17, + "column": 13 + } + } + }, + "init": { + "type": "NumberLiteral", + "value": 1, + "loc": { + "start": { + "line": 17, + "column": 16 + }, + "end": { + "line": 17, + "column": 17 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 5 + }, + "end": { + "line": 17, + "column": 17 + } + } + } + ], + "kind": "var", + "loc": { + "start": { + "line": 17, + "column": 1 + }, + "end": { + "line": 17, + "column": 18 + } + } + }, + { + "type": "ExpressionStatement", + "expression": { + "type": "AssignmentExpression", + "operator": "=", + "left": { + "type": "Identifier", + "name": "abstract", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 1 + }, + "end": { + "line": 18, + "column": 9 + } + } + }, + "right": { + "type": "NumberLiteral", + "value": 2, + "loc": { + "start": { + "line": 18, + "column": 12 + }, + "end": { + "line": 18, + "column": 13 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 1 + }, + "end": { + "line": 18, + "column": 13 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 1 + }, + "end": { + "line": 18, + "column": 14 + } + } + }, + { + "type": "ExpressionStatement", + "expression": { + "type": "UpdateExpression", + "operator": "++", + "prefix": false, + "argument": { + "type": "Identifier", + "name": "abstract", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 1 + }, + "end": { + "line": 19, + "column": 9 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 1 + }, + "end": { + "line": 19, + "column": 11 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 1 + }, + "end": { + "line": 19, + "column": 12 + } + } + }, + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "C", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 16 + }, + "end": { + "line": 21, + "column": 17 + } + } + }, + "superClass": null, + "implements": [], + "constructor": { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "constructor", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": null, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 10 + }, + "end": { + "line": 24, + "column": 2 + } + } + }, + "body": [ + { + "type": "ClassProperty", + "key": { + "type": "Identifier", + "name": "abstract", + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 3 + }, + "end": { + "line": 22, + "column": 11 + } + } + }, + "value": { + "type": "NumberLiteral", + "value": 1, + "loc": { + "start": { + "line": 22, + "column": 14 + }, + "end": { + "line": 22, + "column": 15 + } + } + }, + "static": false, + "readonly": false, + "declare": false, + "optional": false, + "computed": false, + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 3 + }, + "end": { + "line": 22, + "column": 15 + } + } + }, + { + "type": "ClassProperty", + "key": { + "type": "Identifier", + "name": "a", + "decorators": [], + "loc": { + "start": { + "line": 23, + "column": 12 + }, + "end": { + "line": 23, + "column": 13 + } + } + }, + "abstract": true, + "static": false, + "readonly": false, + "declare": false, + "optional": false, + "computed": false, + "decorators": [], + "loc": { + "start": { + "line": 23, + "column": 3 + }, + "end": { + "line": 23, + "column": 13 + } + } + } + ], + "indexSignatures": [], + "loc": { + "start": { + "line": 21, + "column": 18 + }, + "end": { + "line": 24, + "column": 2 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 10 + }, + "end": { + "line": 24, + "column": 2 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 24, + "column": 2 + } + } +} diff --git a/es2panda/test/parser/ts/test-keyword-identify3.ts b/es2panda/test/parser/ts/test-keyword-identify3.ts new file mode 100644 index 0000000000..f2466db2d8 --- /dev/null +++ b/es2panda/test/parser/ts/test-keyword-identify3.ts @@ -0,0 +1,24 @@ +/* + * 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. + */ + + +var abstract = 1; +abstract = 2; +abstract++; + +abstract class C { + abstract = 1; + abstract a; +} \ No newline at end of file diff --git a/es2panda/test/parser/ts/test-keyword-identify4-expected.txt b/es2panda/test/parser/ts/test-keyword-identify4-expected.txt new file mode 100644 index 0000000000..1ecf8330ab --- /dev/null +++ b/es2panda/test/parser/ts/test-keyword-identify4-expected.txt @@ -0,0 +1,329 @@ +{ + "type": "Program", + "statements": [ + { + "type": "ExportNamedDeclaration", + "declaration": { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "declare", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 12 + }, + "end": { + "line": 17, + "column": 19 + } + } + }, + "init": { + "type": "NumberLiteral", + "value": 0, + "loc": { + "start": { + "line": 17, + "column": 22 + }, + "end": { + "line": 17, + "column": 23 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 12 + }, + "end": { + "line": 17, + "column": 23 + } + } + }, + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "global", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 25 + }, + "end": { + "line": 17, + "column": 31 + } + } + }, + "init": { + "type": "NumberLiteral", + "value": 1, + "loc": { + "start": { + "line": 17, + "column": 34 + }, + "end": { + "line": 17, + "column": 35 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 25 + }, + "end": { + "line": 17, + "column": 35 + } + } + } + ], + "kind": "var", + "loc": { + "start": { + "line": 17, + "column": 8 + }, + "end": { + "line": 17, + "column": 36 + } + } + }, + "source": null, + "specifiers": [], + "loc": { + "start": { + "line": 17, + "column": 1 + }, + "end": { + "line": 17, + "column": 36 + } + } + }, + { + "type": "ExpressionStatement", + "expression": { + "type": "AssignmentExpression", + "operator": "=", + "left": { + "type": "Identifier", + "name": "global", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 1 + }, + "end": { + "line": 18, + "column": 7 + } + } + }, + "right": { + "type": "NumberLiteral", + "value": 2, + "loc": { + "start": { + "line": 18, + "column": 10 + }, + "end": { + "line": 18, + "column": 11 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 1 + }, + "end": { + "line": 18, + "column": 11 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 1 + }, + "end": { + "line": 18, + "column": 12 + } + } + }, + { + "type": "ExpressionStatement", + "expression": { + "type": "UpdateExpression", + "operator": "++", + "prefix": false, + "argument": { + "type": "Identifier", + "name": "global", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 1 + }, + "end": { + "line": 19, + "column": 7 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 1 + }, + "end": { + "line": 19, + "column": 9 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 1 + }, + "end": { + "line": 19, + "column": 10 + } + } + }, + { + "type": "TSModuleDeclaration", + "id": { + "type": "Identifier", + "name": "global", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 9 + }, + "end": { + "line": 21, + "column": 15 + } + } + }, + "body": { + "type": "TSModuleBlock", + "body": [], + "loc": { + "start": { + "line": 21, + "column": 16 + }, + "end": { + "line": 21, + "column": 18 + } + } + }, + "declare": true, + "global": true, + "loc": { + "start": { + "line": 21, + "column": 9 + }, + "end": { + "line": 23, + "column": 8 + } + } + }, + { + "type": "ExpressionStatement", + "expression": { + "type": "Identifier", + "name": "declare", + "decorators": [], + "loc": { + "start": { + "line": 23, + "column": 1 + }, + "end": { + "line": 23, + "column": 8 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 1 + }, + "end": { + "line": 23, + "column": 8 + } + } + }, + { + "type": "ExpressionStatement", + "expression": { + "type": "Identifier", + "name": "global", + "decorators": [], + "loc": { + "start": { + "line": 24, + "column": 1 + }, + "end": { + "line": 24, + "column": 7 + } + } + }, + "loc": { + "start": { + "line": 24, + "column": 1 + }, + "end": { + "line": 24, + "column": 7 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 25, + "column": 1 + } + } +} diff --git a/es2panda/test/parser/ts/test-keyword-identify4.ts b/es2panda/test/parser/ts/test-keyword-identify4.ts new file mode 100644 index 0000000000..f72625740c --- /dev/null +++ b/es2panda/test/parser/ts/test-keyword-identify4.ts @@ -0,0 +1,24 @@ +/* + * 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. + */ + + +export var declare = 0, global = 1; +global = 2; +global++; + +declare global {} + +declare +global diff --git a/es2panda/test/parser/ts/test-keyword-identify5-expected.txt b/es2panda/test/parser/ts/test-keyword-identify5-expected.txt new file mode 100644 index 0000000000..bf5ed3426c --- /dev/null +++ b/es2panda/test/parser/ts/test-keyword-identify5-expected.txt @@ -0,0 +1,510 @@ +{ + "type": "Program", + "statements": [ + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "declare", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 5 + }, + "end": { + "line": 17, + "column": 12 + } + } + }, + "init": { + "type": "NumberLiteral", + "value": 0, + "loc": { + "start": { + "line": 17, + "column": 15 + }, + "end": { + "line": 17, + "column": 16 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 5 + }, + "end": { + "line": 17, + "column": 16 + } + } + }, + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "module", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 18 + }, + "end": { + "line": 17, + "column": 24 + } + } + }, + "init": { + "type": "NumberLiteral", + "value": 1, + "loc": { + "start": { + "line": 17, + "column": 27 + }, + "end": { + "line": 17, + "column": 28 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 18 + }, + "end": { + "line": 17, + "column": 28 + } + } + }, + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "ns", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 30 + }, + "end": { + "line": 17, + "column": 32 + } + } + }, + "init": { + "type": "NumberLiteral", + "value": 2, + "loc": { + "start": { + "line": 17, + "column": 35 + }, + "end": { + "line": 17, + "column": 36 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 30 + }, + "end": { + "line": 17, + "column": 36 + } + } + } + ], + "kind": "var", + "loc": { + "start": { + "line": 17, + "column": 1 + }, + "end": { + "line": 17, + "column": 37 + } + } + }, + { + "type": "ExpressionStatement", + "expression": { + "type": "AssignmentExpression", + "operator": "=", + "left": { + "type": "Identifier", + "name": "module", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 1 + }, + "end": { + "line": 18, + "column": 7 + } + } + }, + "right": { + "type": "NumberLiteral", + "value": 2, + "loc": { + "start": { + "line": 18, + "column": 10 + }, + "end": { + "line": 18, + "column": 11 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 1 + }, + "end": { + "line": 18, + "column": 11 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 1 + }, + "end": { + "line": 18, + "column": 12 + } + } + }, + { + "type": "ExpressionStatement", + "expression": { + "type": "UpdateExpression", + "operator": "++", + "prefix": false, + "argument": { + "type": "Identifier", + "name": "module", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 1 + }, + "end": { + "line": 19, + "column": 7 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 1 + }, + "end": { + "line": 19, + "column": 9 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 1 + }, + "end": { + "line": 19, + "column": 10 + } + } + }, + { + "type": "ExpressionStatement", + "expression": { + "type": "Identifier", + "name": "module", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 1 + }, + "end": { + "line": 21, + "column": 7 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 1 + }, + "end": { + "line": 21, + "column": 7 + } + } + }, + { + "type": "ExpressionStatement", + "expression": { + "type": "Identifier", + "name": "ns", + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 1 + }, + "end": { + "line": 22, + "column": 3 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 1 + }, + "end": { + "line": 22, + "column": 3 + } + } + }, + { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 23, + "column": 1 + }, + "end": { + "line": 23, + "column": 3 + } + } + }, + { + "type": "ExpressionStatement", + "expression": { + "type": "Identifier", + "name": "declare", + "decorators": [], + "loc": { + "start": { + "line": 25, + "column": 1 + }, + "end": { + "line": 25, + "column": 8 + } + } + }, + "loc": { + "start": { + "line": 25, + "column": 1 + }, + "end": { + "line": 25, + "column": 8 + } + } + }, + { + "type": "ExpressionStatement", + "expression": { + "type": "Identifier", + "name": "module", + "decorators": [], + "loc": { + "start": { + "line": 26, + "column": 1 + }, + "end": { + "line": 26, + "column": 7 + } + } + }, + "loc": { + "start": { + "line": 26, + "column": 1 + }, + "end": { + "line": 26, + "column": 7 + } + } + }, + { + "type": "ExpressionStatement", + "expression": { + "type": "StringLiteral", + "value": "a", + "loc": { + "start": { + "line": 27, + "column": 1 + }, + "end": { + "line": 27, + "column": 4 + } + } + }, + "loc": { + "start": { + "line": 27, + "column": 1 + }, + "end": { + "line": 27, + "column": 4 + } + } + }, + { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 28, + "column": 1 + }, + "end": { + "line": 28, + "column": 3 + } + } + }, + { + "type": "TSModuleDeclaration", + "id": { + "type": "Identifier", + "name": "M", + "decorators": [], + "loc": { + "start": { + "line": 30, + "column": 8 + }, + "end": { + "line": 30, + "column": 9 + } + } + }, + "body": { + "type": "TSModuleBlock", + "body": [], + "loc": { + "start": { + "line": 30, + "column": 10 + }, + "end": { + "line": 30, + "column": 12 + } + } + }, + "declare": false, + "global": false, + "loc": { + "start": { + "line": 30, + "column": 1 + }, + "end": { + "line": 32, + "column": 8 + } + } + }, + { + "type": "TSModuleDeclaration", + "id": { + "type": "StringLiteral", + "value": "module", + "loc": { + "start": { + "line": 32, + "column": 16 + }, + "end": { + "line": 32, + "column": 24 + } + } + }, + "body": { + "type": "TSModuleBlock", + "body": [], + "loc": { + "start": { + "line": 32, + "column": 25 + }, + "end": { + "line": 32, + "column": 27 + } + } + }, + "declare": true, + "global": false, + "loc": { + "start": { + "line": 32, + "column": 9 + }, + "end": { + "line": 33, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 33, + "column": 1 + } + } +} diff --git a/es2panda/test/parser/ts/test-keyword-identify5.ts b/es2panda/test/parser/ts/test-keyword-identify5.ts new file mode 100644 index 0000000000..4d704df9af --- /dev/null +++ b/es2panda/test/parser/ts/test-keyword-identify5.ts @@ -0,0 +1,32 @@ +/* + * 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. + */ + + +var declare = 0, module = 1, ns = 2; +module = 2; +module++; + +module +ns +{} + +declare +module +"a" +{} + +module M {} + +declare module "module" {} diff --git a/es2panda/test/parser/ts/test-keyword-identify6-expected.txt b/es2panda/test/parser/ts/test-keyword-identify6-expected.txt new file mode 100644 index 0000000000..ce37339e41 --- /dev/null +++ b/es2panda/test/parser/ts/test-keyword-identify6-expected.txt @@ -0,0 +1,324 @@ +{ + "type": "Program", + "statements": [ + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "type", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 5 + }, + "end": { + "line": 17, + "column": 9 + } + } + }, + "init": { + "type": "NumberLiteral", + "value": 1, + "loc": { + "start": { + "line": 17, + "column": 12 + }, + "end": { + "line": 17, + "column": 13 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 5 + }, + "end": { + "line": 17, + "column": 13 + } + } + }, + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "a", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 15 + }, + "end": { + "line": 17, + "column": 16 + } + } + }, + "init": { + "type": "NumberLiteral", + "value": 0, + "loc": { + "start": { + "line": 17, + "column": 19 + }, + "end": { + "line": 17, + "column": 20 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 15 + }, + "end": { + "line": 17, + "column": 20 + } + } + } + ], + "kind": "var", + "loc": { + "start": { + "line": 17, + "column": 1 + }, + "end": { + "line": 17, + "column": 21 + } + } + }, + { + "type": "ExpressionStatement", + "expression": { + "type": "AssignmentExpression", + "operator": "=", + "left": { + "type": "Identifier", + "name": "type", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 1 + }, + "end": { + "line": 18, + "column": 5 + } + } + }, + "right": { + "type": "NumberLiteral", + "value": 2, + "loc": { + "start": { + "line": 18, + "column": 8 + }, + "end": { + "line": 18, + "column": 9 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 1 + }, + "end": { + "line": 18, + "column": 9 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 1 + }, + "end": { + "line": 18, + "column": 10 + } + } + }, + { + "type": "ExpressionStatement", + "expression": { + "type": "UpdateExpression", + "operator": "++", + "prefix": false, + "argument": { + "type": "Identifier", + "name": "type", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 1 + }, + "end": { + "line": 19, + "column": 5 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 1 + }, + "end": { + "line": 19, + "column": 7 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 1 + }, + "end": { + "line": 19, + "column": 8 + } + } + }, + { + "type": "TSTypeAliasDeclaration", + "id": { + "type": "Identifier", + "name": "a", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 6 + }, + "end": { + "line": 21, + "column": 7 + } + } + }, + "typeAnnotation": { + "type": "TSNumberKeyword", + "loc": { + "start": { + "line": 21, + "column": 10 + }, + "end": { + "line": 21, + "column": 16 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 1 + }, + "end": { + "line": 21, + "column": 17 + } + } + }, + { + "type": "EmptyStatement", + "loc": { + "start": { + "line": 21, + "column": 16 + }, + "end": { + "line": 21, + "column": 17 + } + } + }, + { + "type": "ExpressionStatement", + "expression": { + "type": "Identifier", + "name": "type", + "decorators": [], + "loc": { + "start": { + "line": 23, + "column": 1 + }, + "end": { + "line": 23, + "column": 5 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 1 + }, + "end": { + "line": 23, + "column": 5 + } + } + }, + { + "type": "ExpressionStatement", + "expression": { + "type": "Identifier", + "name": "a", + "decorators": [], + "loc": { + "start": { + "line": 24, + "column": 1 + }, + "end": { + "line": 24, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 24, + "column": 1 + }, + "end": { + "line": 24, + "column": 2 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 25, + "column": 1 + } + } +} diff --git a/es2panda/test/parser/ts/test-keyword-identify6.ts b/es2panda/test/parser/ts/test-keyword-identify6.ts new file mode 100644 index 0000000000..bd0a7d0001 --- /dev/null +++ b/es2panda/test/parser/ts/test-keyword-identify6.ts @@ -0,0 +1,24 @@ +/* + * 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. + */ + + +var type = 1, a = 0; +type = 2; +type++; + +type a = number; + +type +a diff --git a/es2panda/test/parser/ts/test-keyword-identify7-expected.txt b/es2panda/test/parser/ts/test-keyword-identify7-expected.txt new file mode 100644 index 0000000000..71c3972240 --- /dev/null +++ b/es2panda/test/parser/ts/test-keyword-identify7-expected.txt @@ -0,0 +1,231 @@ +{ + "type": "Program", + "statements": [ + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "async", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 5 + }, + "end": { + "line": 17, + "column": 10 + } + } + }, + "init": { + "type": "NumberLiteral", + "value": 1, + "loc": { + "start": { + "line": 17, + "column": 13 + }, + "end": { + "line": 17, + "column": 14 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 5 + }, + "end": { + "line": 17, + "column": 14 + } + } + } + ], + "kind": "var", + "loc": { + "start": { + "line": 17, + "column": 1 + }, + "end": { + "line": 17, + "column": 15 + } + } + }, + { + "type": "ExpressionStatement", + "expression": { + "type": "AssignmentExpression", + "operator": "=", + "left": { + "type": "Identifier", + "name": "async", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 1 + }, + "end": { + "line": 18, + "column": 6 + } + } + }, + "right": { + "type": "NumberLiteral", + "value": 2, + "loc": { + "start": { + "line": 18, + "column": 9 + }, + "end": { + "line": 18, + "column": 10 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 1 + }, + "end": { + "line": 18, + "column": 10 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 1 + }, + "end": { + "line": 18, + "column": 11 + } + } + }, + { + "type": "ExpressionStatement", + "expression": { + "type": "UpdateExpression", + "operator": "++", + "prefix": false, + "argument": { + "type": "Identifier", + "name": "async", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 1 + }, + "end": { + "line": 19, + "column": 6 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 1 + }, + "end": { + "line": 19, + "column": 8 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 1 + }, + "end": { + "line": 19, + "column": 9 + } + } + }, + { + "type": "FunctionDeclaration", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "f", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 16 + }, + "end": { + "line": 21, + "column": 17 + } + } + }, + "generator": false, + "async": true, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 21, + "column": 19 + }, + "end": { + "line": 21, + "column": 21 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 7 + }, + "end": { + "line": 21, + "column": 21 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 1 + }, + "end": { + "line": 21, + "column": 21 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 21, + "column": 21 + } + } +} diff --git a/es2panda/test/parser/ts/test-keyword-identify7.ts b/es2panda/test/parser/ts/test-keyword-identify7.ts new file mode 100644 index 0000000000..40d4f2549c --- /dev/null +++ b/es2panda/test/parser/ts/test-keyword-identify7.ts @@ -0,0 +1,21 @@ +/* + * 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. + */ + + +var async = 1; +async = 2; +async++; + +async function f(){} \ No newline at end of file diff --git a/es2panda/test/parser/ts/test-type-alias1-expected.txt b/es2panda/test/parser/ts/test-type-alias1-expected.txt index 93719ca643..ef3046876d 100644 --- a/es2panda/test/parser/ts/test-type-alias1-expected.txt +++ b/es2panda/test/parser/ts/test-type-alias1-expected.txt @@ -1 +1 @@ -SyntaxError: Identifier expected [test-type-alias1.ts:17:6] +SyntaxError: Unexpected token [test-type-alias1.ts:17:6] diff --git a/es2panda/test/parser/ts/test-type-annotation2-expected.txt b/es2panda/test/parser/ts/test-type-annotation2-expected.txt new file mode 100644 index 0000000000..6aa8faad9a --- /dev/null +++ b/es2panda/test/parser/ts/test-type-annotation2-expected.txt @@ -0,0 +1,392 @@ +{ + "type": "Program", + "statements": [ + { + "type": "TSEnumDeclaration", + "id": { + "type": "Identifier", + "name": "E", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 6 + }, + "end": { + "line": 17, + "column": 7 + } + } + }, + "members": [ + { + "type": "TSEnumMember", + "id": { + "type": "Identifier", + "name": "false", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 5 + }, + "end": { + "line": 18, + "column": 10 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 10 + }, + "end": { + "line": 18, + "column": 11 + } + } + }, + { + "type": "TSEnumMember", + "id": { + "type": "Identifier", + "name": "true", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 5 + }, + "end": { + "line": 19, + "column": 9 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 1 + }, + "end": { + "line": 20, + "column": 2 + } + } + } + ], + "const": false, + "loc": { + "start": { + "line": 17, + "column": 1 + }, + "end": { + "line": 20, + "column": 2 + } + } + }, + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "a", + "typeAnnotation": { + "type": "TSTypeReference", + "typeName": { + "type": "TSQualifiedName", + "left": { + "type": "Identifier", + "name": "E", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 9 + }, + "end": { + "line": 21, + "column": 10 + } + } + }, + "right": { + "type": "Identifier", + "name": "false", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 11 + }, + "end": { + "line": 21, + "column": 16 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 9 + }, + "end": { + "line": 21, + "column": 18 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 9 + }, + "end": { + "line": 21, + "column": 18 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 5 + }, + "end": { + "line": 21, + "column": 6 + } + } + }, + "init": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "E", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 19 + }, + "end": { + "line": 21, + "column": 20 + } + } + }, + "property": { + "type": "Identifier", + "name": "false", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 21 + }, + "end": { + "line": 21, + "column": 26 + } + } + }, + "computed": false, + "optional": false, + "loc": { + "start": { + "line": 21, + "column": 19 + }, + "end": { + "line": 21, + "column": 26 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 5 + }, + "end": { + "line": 21, + "column": 26 + } + } + } + ], + "kind": "var", + "loc": { + "start": { + "line": 21, + "column": 1 + }, + "end": { + "line": 21, + "column": 26 + } + } + }, + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "b", + "typeAnnotation": { + "type": "TSTypeReference", + "typeName": { + "type": "TSQualifiedName", + "left": { + "type": "Identifier", + "name": "E", + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 9 + }, + "end": { + "line": 22, + "column": 10 + } + } + }, + "right": { + "type": "Identifier", + "name": "true", + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 11 + }, + "end": { + "line": 22, + "column": 15 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 9 + }, + "end": { + "line": 22, + "column": 17 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 9 + }, + "end": { + "line": 22, + "column": 17 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 5 + }, + "end": { + "line": 22, + "column": 6 + } + } + }, + "init": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "E", + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 18 + }, + "end": { + "line": 22, + "column": 19 + } + } + }, + "property": { + "type": "Identifier", + "name": "true", + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 20 + }, + "end": { + "line": 22, + "column": 24 + } + } + }, + "computed": false, + "optional": false, + "loc": { + "start": { + "line": 22, + "column": 18 + }, + "end": { + "line": 22, + "column": 24 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 5 + }, + "end": { + "line": 22, + "column": 24 + } + } + } + ], + "kind": "var", + "loc": { + "start": { + "line": 22, + "column": 1 + }, + "end": { + "line": 22, + "column": 24 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 24, + "column": 1 + } + } +} diff --git a/es2panda/test/parser/ts/test-type-annotation2.ts b/es2panda/test/parser/ts/test-type-annotation2.ts new file mode 100644 index 0000000000..a38984061d --- /dev/null +++ b/es2panda/test/parser/ts/test-type-annotation2.ts @@ -0,0 +1,23 @@ +/* + * 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. + */ + + +enum E{ + false, + true +} +var a : E.false = E.false +var b : E.true = E.true + diff --git a/es2panda/test/parser/ts/test_module10-expected.txt b/es2panda/test/parser/ts/test_module10-expected.txt new file mode 100644 index 0000000000..3f24be5f09 --- /dev/null +++ b/es2panda/test/parser/ts/test_module10-expected.txt @@ -0,0 +1,160 @@ +{ + "type": "Program", + "statements": [ + { + "type": "ExportNamedDeclaration", + "declaration": null, + "source": null, + "specifiers": [], + "loc": { + "start": { + "line": 17, + "column": 1 + }, + "end": { + "line": 17, + "column": 9 + } + } + }, + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "a", + "typeAnnotation": { + "type": "TSNumberKeyword", + "loc": { + "start": { + "line": 18, + "column": 9 + }, + "end": { + "line": 18, + "column": 15 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 5 + }, + "end": { + "line": 18, + "column": 6 + } + } + }, + "init": { + "type": "NumberLiteral", + "value": 1, + "loc": { + "start": { + "line": 18, + "column": 18 + }, + "end": { + "line": 18, + "column": 19 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 5 + }, + "end": { + "line": 18, + "column": 19 + } + } + } + ], + "kind": "var", + "loc": { + "start": { + "line": 18, + "column": 1 + }, + "end": { + "line": 18, + "column": 20 + } + } + }, + { + "type": "TSModuleDeclaration", + "id": { + "type": "Identifier", + "name": "global", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 9 + }, + "end": { + "line": 19, + "column": 15 + } + } + }, + "declare": true, + "global": true, + "loc": { + "start": { + "line": 19, + "column": 9 + }, + "end": { + "line": 20, + "column": 2 + } + } + }, + { + "type": "ExpressionStatement", + "expression": { + "type": "Identifier", + "name": "a", + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 1 + }, + "end": { + "line": 20, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 1 + }, + "end": { + "line": 20, + "column": 3 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 21, + "column": 1 + } + } +} diff --git a/es2panda/test/parser/ts/test_module10.ts b/es2panda/test/parser/ts/test_module10.ts new file mode 100644 index 0000000000..ef15a5d7b2 --- /dev/null +++ b/es2panda/test/parser/ts/test_module10.ts @@ -0,0 +1,20 @@ +/* + * 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. + */ + + +export{} +var a : number = 1; +declare global +a; diff --git a/es2panda/test/parser/ts/test_module7-expected.txt b/es2panda/test/parser/ts/test_module7-expected.txt new file mode 100644 index 0000000000..9df4eab8d8 --- /dev/null +++ b/es2panda/test/parser/ts/test_module7-expected.txt @@ -0,0 +1,444 @@ +{ + "type": "Program", + "statements": [ + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "module", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 5 + }, + "end": { + "line": 17, + "column": 11 + } + } + }, + "init": { + "type": "NumberLiteral", + "value": 1, + "loc": { + "start": { + "line": 17, + "column": 14 + }, + "end": { + "line": 17, + "column": 15 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 5 + }, + "end": { + "line": 17, + "column": 15 + } + } + } + ], + "kind": "var", + "loc": { + "start": { + "line": 17, + "column": 1 + }, + "end": { + "line": 17, + "column": 16 + } + } + }, + { + "type": "ExpressionStatement", + "expression": { + "type": "AssignmentExpression", + "operator": "=", + "left": { + "type": "Identifier", + "name": "module", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 1 + }, + "end": { + "line": 18, + "column": 7 + } + } + }, + "right": { + "type": "BinaryExpression", + "operator": "+", + "left": { + "type": "Identifier", + "name": "module", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 10 + }, + "end": { + "line": 18, + "column": 16 + } + } + }, + "right": { + "type": "NumberLiteral", + "value": 1, + "loc": { + "start": { + "line": 18, + "column": 19 + }, + "end": { + "line": 18, + "column": 20 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 10 + }, + "end": { + "line": 18, + "column": 20 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 1 + }, + "end": { + "line": 18, + "column": 20 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 1 + }, + "end": { + "line": 18, + "column": 21 + } + } + }, + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "namespace", + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 5 + }, + "end": { + "line": 20, + "column": 14 + } + } + }, + "init": { + "type": "NumberLiteral", + "value": 1, + "loc": { + "start": { + "line": 20, + "column": 17 + }, + "end": { + "line": 20, + "column": 18 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 5 + }, + "end": { + "line": 20, + "column": 18 + } + } + } + ], + "kind": "var", + "loc": { + "start": { + "line": 20, + "column": 1 + }, + "end": { + "line": 20, + "column": 19 + } + } + }, + { + "type": "ExpressionStatement", + "expression": { + "type": "AssignmentExpression", + "operator": "=", + "left": { + "type": "Identifier", + "name": "namespace", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 1 + }, + "end": { + "line": 21, + "column": 10 + } + } + }, + "right": { + "type": "BinaryExpression", + "operator": "+", + "left": { + "type": "Identifier", + "name": "namespace", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 13 + }, + "end": { + "line": 21, + "column": 22 + } + } + }, + "right": { + "type": "NumberLiteral", + "value": 1, + "loc": { + "start": { + "line": 21, + "column": 25 + }, + "end": { + "line": 21, + "column": 26 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 13 + }, + "end": { + "line": 21, + "column": 26 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 1 + }, + "end": { + "line": 21, + "column": 26 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 1 + }, + "end": { + "line": 21, + "column": 27 + } + } + }, + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "global", + "decorators": [], + "loc": { + "start": { + "line": 23, + "column": 5 + }, + "end": { + "line": 23, + "column": 11 + } + } + }, + "init": { + "type": "NumberLiteral", + "value": 1, + "loc": { + "start": { + "line": 23, + "column": 14 + }, + "end": { + "line": 23, + "column": 15 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 5 + }, + "end": { + "line": 23, + "column": 15 + } + } + } + ], + "kind": "var", + "loc": { + "start": { + "line": 23, + "column": 1 + }, + "end": { + "line": 23, + "column": 16 + } + } + }, + { + "type": "ExpressionStatement", + "expression": { + "type": "AssignmentExpression", + "operator": "=", + "left": { + "type": "Identifier", + "name": "global", + "decorators": [], + "loc": { + "start": { + "line": 24, + "column": 1 + }, + "end": { + "line": 24, + "column": 7 + } + } + }, + "right": { + "type": "BinaryExpression", + "operator": "+", + "left": { + "type": "Identifier", + "name": "global", + "decorators": [], + "loc": { + "start": { + "line": 24, + "column": 10 + }, + "end": { + "line": 24, + "column": 16 + } + } + }, + "right": { + "type": "NumberLiteral", + "value": 1, + "loc": { + "start": { + "line": 24, + "column": 19 + }, + "end": { + "line": 24, + "column": 20 + } + } + }, + "loc": { + "start": { + "line": 24, + "column": 10 + }, + "end": { + "line": 24, + "column": 20 + } + } + }, + "loc": { + "start": { + "line": 24, + "column": 1 + }, + "end": { + "line": 24, + "column": 20 + } + } + }, + "loc": { + "start": { + "line": 24, + "column": 1 + }, + "end": { + "line": 24, + "column": 21 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 25, + "column": 1 + } + } +} diff --git a/es2panda/test/parser/ts/test_module7.ts b/es2panda/test/parser/ts/test_module7.ts new file mode 100644 index 0000000000..754cbd86b6 --- /dev/null +++ b/es2panda/test/parser/ts/test_module7.ts @@ -0,0 +1,24 @@ +/* + * 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. + */ + + +var module = 1; +module = module + 1; + +var namespace = 1; +namespace = namespace + 1; + +var global = 1; +global = global + 1; diff --git a/es2panda/test/parser/ts/test_module8-expected.txt b/es2panda/test/parser/ts/test_module8-expected.txt new file mode 100644 index 0000000000..24fcf88d82 --- /dev/null +++ b/es2panda/test/parser/ts/test_module8-expected.txt @@ -0,0 +1,75 @@ +{ + "type": "Program", + "statements": [ + { + "type": "ExportNamedDeclaration", + "declaration": null, + "source": null, + "specifiers": [], + "loc": { + "start": { + "line": 17, + "column": 1 + }, + "end": { + "line": 17, + "column": 9 + } + } + }, + { + "type": "TSModuleDeclaration", + "id": { + "type": "Identifier", + "name": "global", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 9 + }, + "end": { + "line": 18, + "column": 15 + } + } + }, + "body": { + "type": "TSModuleBlock", + "body": [], + "loc": { + "start": { + "line": 18, + "column": 16 + }, + "end": { + "line": 18, + "column": 18 + } + } + }, + "declare": true, + "global": true, + "loc": { + "start": { + "line": 18, + "column": 9 + }, + "end": { + "line": 19, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 19, + "column": 1 + } + } +} diff --git a/es2panda/test/parser/ts/test_module8.ts b/es2panda/test/parser/ts/test_module8.ts new file mode 100644 index 0000000000..7d3b301655 --- /dev/null +++ b/es2panda/test/parser/ts/test_module8.ts @@ -0,0 +1,18 @@ +/* + * 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. + */ + + +export{} +declare global {} diff --git a/es2panda/test/parser/ts/test_module9-expected.txt b/es2panda/test/parser/ts/test_module9-expected.txt new file mode 100644 index 0000000000..2dea29e46e --- /dev/null +++ b/es2panda/test/parser/ts/test_module9-expected.txt @@ -0,0 +1,61 @@ +{ + "type": "Program", + "statements": [ + { + "type": "TSModuleDeclaration", + "id": { + "type": "Identifier", + "name": "global", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 9 + }, + "end": { + "line": 17, + "column": 15 + } + } + }, + "declare": true, + "global": true, + "loc": { + "start": { + "line": 17, + "column": 9 + }, + "end": { + "line": 18, + "column": 7 + } + } + }, + { + "type": "ExportNamedDeclaration", + "declaration": null, + "source": null, + "specifiers": [], + "loc": { + "start": { + "line": 18, + "column": 1 + }, + "end": { + "line": 18, + "column": 10 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 19, + "column": 1 + } + } +} diff --git a/es2panda/test/parser/ts/test_module9.ts b/es2panda/test/parser/ts/test_module9.ts new file mode 100644 index 0000000000..e6cac24b0a --- /dev/null +++ b/es2panda/test/parser/ts/test_module9.ts @@ -0,0 +1,18 @@ +/* + * 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. + */ + + +declare global +export {} diff --git a/es2panda/test/test_tsc_ignore_list.txt b/es2panda/test/test_tsc_ignore_list.txt index 4aff71e039..4c20b5a3ec 100644 --- a/es2panda/test/test_tsc_ignore_list.txt +++ b/es2panda/test/test_tsc_ignore_list.txt @@ -26,7 +26,6 @@ es2panda/test/TypeScript/tests/cases/compiler/letInVarDeclOfForOf_ES6.ts es2panda/test/TypeScript/tests/cases/compiler/mutuallyRecursiveInterfaceDeclaration.ts es2panda/test/TypeScript/tests/cases/compiler/overloadedConstructorFixesInferencesAppropriately.ts es2panda/test/TypeScript/tests/cases/compiler/parameterInitializerBeforeDestructuringEmit.ts -es2panda/test/TypeScript/tests/cases/compiler/parseEntityNameWithReservedWord.ts es2panda/test/TypeScript/tests/cases/compiler/shebang.ts es2panda/test/TypeScript/tests/cases/compiler/sigantureIsSubTypeIfTheyAreIdentical.ts es2panda/test/TypeScript/tests/cases/compiler/sourceMap-LineBreaks.ts @@ -77,14 +76,12 @@ es2panda/test/TypeScript/tests/cases/conformance/functions/functionWithUseStrict es2panda/test/TypeScript/tests/cases/conformance/interfaces/interfaceDeclarations/asiPreventsParsingAsInterface01.ts es2panda/test/TypeScript/tests/cases/conformance/interfaces/interfaceDeclarations/asiPreventsParsingAsInterface03.ts es2panda/test/TypeScript/tests/cases/conformance/interfaces/interfaceDeclarations/asiPreventsParsingAsInterface04.ts -es2panda/test/TypeScript/tests/cases/conformance/internalModules/moduleDeclarations/asiPreventsParsingAsNamespace04.ts es2panda/test/TypeScript/tests/cases/conformance/parser/ecmascript5/RegressionTests/parser579071.ts es2panda/test/TypeScript/tests/cases/conformance/parser/ecmascript5/Statements/ContinueStatements/parser_continueTarget3.ts es2panda/test/TypeScript/tests/cases/conformance/parser/ecmascript5/parserUnicodeWhitespaceCharacter1.ts es2panda/test/TypeScript/tests/cases/conformance/scanner/ecmascript3/scannerES3NumericLiteral2.ts es2panda/test/TypeScript/tests/cases/conformance/types/keyof/keyofAndIndexedAccess.ts es2panda/test/TypeScript/tests/cases/conformance/types/members/objectTypeWithStringNamedNumericProperty.ts -es2panda/test/TypeScript/tests/cases/conformance/types/specifyingTypes/typeQueries/typeQueryWithReservedWords.ts es2panda/test/TypeScript/tests/cases/conformance/types/typeParameters/typeArgumentLists/constraintSatisfactionWithEmptyObject.ts es2panda/test/TypeScript/tests/cases/conformance/types/uniqueSymbol/uniqueSymbols.ts es2panda/test/TypeScript/tests/cases/conformance/types/uniqueSymbol/uniqueSymbolsDeclarations.ts -- Gitee