From 5d5f5dea8059c506c56915292d0f575fc98134e2 Mon Sep 17 00:00:00 2001 From: lwx1285216 Date: Thu, 2 Nov 2023 04:24:01 +0000 Subject: [PATCH] Increase recognition of memory set and get methods in the interface Change-Id: I47372efbfef547df26d879ee84e11b8f6ed7d1bc Signed-off-by: lwx1285216 --- es2panda/ir/ts/tsMethodSignature.cpp | 2 + es2panda/ir/ts/tsMethodSignature.h | 17 +- es2panda/parser/parserImpl.cpp | 37 ++- es2panda/parser/parserImpl.h | 3 +- .../parser/ts/test-interface-expected.txt | 4 + ...-interface-method-identifier1-expected.txt | 4 + .../parser/ts/test-interface4-expected.txt | 4 + .../parser/ts/test-type-literal-expected.txt | 6 + .../ts/test_GetOrSetAccessor1-expected.txt | 249 ++++++++++++++++++ .../test/parser/ts/test_GetOrSetAccessor1.ts | 23 ++ .../ts/test_GetOrSetAccessor2-expected.txt | 234 ++++++++++++++++ .../test/parser/ts/test_GetOrSetAccessor2.ts | 24 ++ .../ts/test_GetOrSetAccessor3-expected.txt | 192 ++++++++++++++ .../test/parser/ts/test_GetOrSetAccessor3.ts | 20 ++ .../ts/test_GetOrSetAccessor4-expected.txt | 192 ++++++++++++++ .../test/parser/ts/test_GetOrSetAccessor4.ts | 20 ++ .../ts/test_GetOrSetAccessor5-expected.txt | 192 ++++++++++++++ .../test/parser/ts/test_GetOrSetAccessor5.ts | 20 ++ .../ts/test_GetOrSetAccessor6-expected.txt | 163 ++++++++++++ .../test/parser/ts/test_GetOrSetAccessor6.ts | 20 ++ .../test/parser/ts/test_generic-expected.txt | 2 + .../parser/ts/test_import_type-expected.txt | 2 + .../test/parser/ts/test_module-expected.txt | 2 + .../parser/ts/test_satisfies3-expected.txt | 6 + .../parser/ts/test_satisfies4-expected.txt | 2 + .../interfaceAssignment-expected.txt | 2 + .../interfaceUsedAsValue-expected.txt | 2 + .../type_checker/memberExpTests-expected.txt | 2 + .../objectDestructuring-expected.txt | 2 + .../objectLiteralAssignability-expected.txt | 6 + .../type_checker/test-interface-expected.txt | 6 + .../test-type-literal-expected.txt | 8 + 32 files changed, 1460 insertions(+), 8 deletions(-) create mode 100644 es2panda/test/parser/ts/test_GetOrSetAccessor1-expected.txt create mode 100644 es2panda/test/parser/ts/test_GetOrSetAccessor1.ts create mode 100644 es2panda/test/parser/ts/test_GetOrSetAccessor2-expected.txt create mode 100644 es2panda/test/parser/ts/test_GetOrSetAccessor2.ts create mode 100644 es2panda/test/parser/ts/test_GetOrSetAccessor3-expected.txt create mode 100644 es2panda/test/parser/ts/test_GetOrSetAccessor3.ts create mode 100644 es2panda/test/parser/ts/test_GetOrSetAccessor4-expected.txt create mode 100644 es2panda/test/parser/ts/test_GetOrSetAccessor4.ts create mode 100644 es2panda/test/parser/ts/test_GetOrSetAccessor5-expected.txt create mode 100644 es2panda/test/parser/ts/test_GetOrSetAccessor5.ts create mode 100644 es2panda/test/parser/ts/test_GetOrSetAccessor6-expected.txt create mode 100644 es2panda/test/parser/ts/test_GetOrSetAccessor6.ts diff --git a/es2panda/ir/ts/tsMethodSignature.cpp b/es2panda/ir/ts/tsMethodSignature.cpp index c83c09581b..afe26da5c1 100644 --- a/es2panda/ir/ts/tsMethodSignature.cpp +++ b/es2panda/ir/ts/tsMethodSignature.cpp @@ -48,6 +48,8 @@ void TSMethodSignature::Dump(ir::AstDumper *dumper) const dumper->Add({{"type", "TSMethodSignature"}, {"computed", computed_}, {"optional", optional_}, + {"isGetAccessor",isGetAccessor_}, + {"isSetAccessor",isSetAccessor_}, {"key", key_}, {"params", params_}, {"typeParameters", AstDumper::Optional(typeParams_)}, diff --git a/es2panda/ir/ts/tsMethodSignature.h b/es2panda/ir/ts/tsMethodSignature.h index b104883516..61e07dee51 100644 --- a/es2panda/ir/ts/tsMethodSignature.h +++ b/es2panda/ir/ts/tsMethodSignature.h @@ -39,7 +39,7 @@ class TSMethodSignature : public Expression { public: explicit TSMethodSignature(binder::Scope *scope, Expression *key, TSTypeParameterDeclaration *typeParams, ArenaVector &¶ms, Expression *returnTypeAnnotation, bool computed, - bool optional) + bool optional, bool isGetAccessor, bool isSetAccessor) : Expression(AstNodeType::TS_METHOD_SIGNATURE), scope_(scope), key_(key), @@ -47,7 +47,10 @@ public: params_(std::move(params)), returnTypeAnnotation_(returnTypeAnnotation), computed_(computed), - optional_(optional) + optional_(optional), + isGetAccessor_(isGetAccessor), + isSetAccessor_(isSetAccessor) + { } @@ -90,6 +93,14 @@ public: { return optional_; } + bool IsGetAccessor() const + { + return isGetAccessor_; + } + bool IsSetAccessor() const + { + return isSetAccessor_; + } void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; @@ -105,6 +116,8 @@ private: Expression *returnTypeAnnotation_; bool computed_; bool optional_; + bool isGetAccessor_; + bool isSetAccessor_; }; } // namespace panda::es2panda::ir diff --git a/es2panda/parser/parserImpl.cpp b/es2panda/parser/parserImpl.cpp index 1a8d74c040..44349922fe 100644 --- a/es2panda/parser/parserImpl.cpp +++ b/es2panda/parser/parserImpl.cpp @@ -1277,16 +1277,43 @@ ir::TSTypePredicate *ParserImpl::ParseTsTypePredicate() return result; } -ir::Expression *ParserImpl::ParseTsTypeLiteralOrInterfaceKey(bool *computed, bool *signature, bool *isIndexSignature) +ir::Expression *ParserImpl::ParseTsTypeLiteralOrInterfaceKey(bool *computed, bool *signature, bool *isGetAccessor, bool *isSetAccessor, bool *isIndexSignature) { ir::Expression *key = nullptr; if (lexer_->GetToken().Type() == lexer::TokenType::LITERAL_IDENT && (lexer_->GetToken().KeywordType() != lexer::TokenType::KEYW_NEW || - (lexer_->Lookahead() != LEX_CHAR_LEFT_PAREN && lexer_->Lookahead() != LEX_CHAR_LESS_THAN))) { + (lexer_->Lookahead() != LEX_CHAR_LEFT_PAREN && lexer_->Lookahead() != LEX_CHAR_LESS_THAN)) && + (lexer_->GetToken().KeywordType() != lexer::TokenType::KEYW_GET) && + (lexer_->GetToken().KeywordType() != lexer::TokenType::KEYW_SET)) { key = AllocNode(lexer_->GetToken().Ident()); key->SetRange(lexer_->GetToken().Loc()); lexer_->NextToken(); + } else if (lexer_->GetToken().Type() == lexer::TokenType::LITERAL_IDENT && + (lexer_->GetToken().KeywordType() == lexer::TokenType::KEYW_GET || + lexer_->GetToken().KeywordType() == lexer::TokenType::KEYW_SET)) { + auto pos = lexer_->Save(); + lexer_->NextToken(); + if (lexer_->GetToken().Type() != lexer::TokenType::KEYW_VOID && + lexer_->GetToken().Type() != lexer::TokenType::LITERAL_IDENT) { + lexer_->Rewind(pos); + key = AllocNode(lexer_->GetToken().Ident()); + key->SetRange(lexer_->GetToken().Loc()); + lexer_->NextToken(); + } else { + lexer_->Rewind(pos); + if (lexer_->GetToken().KeywordType() == lexer::TokenType::KEYW_GET) { + *isGetAccessor = true; + } else { + *isSetAccessor = true; + } + lexer_->NextToken(); + key = AllocNode(lexer_->GetToken().Ident()); + key->SetRange(lexer_->GetToken().Loc()); + lexer_->NextToken(); + + } + } else if (lexer_->GetToken().Type() == lexer::TokenType::LITERAL_NUMBER) { if (lexer_->GetToken().Flags() & lexer::TokenFlags::NUMBER_BIGINT) { key = AllocNode(lexer_->GetToken().BigInt()); @@ -1385,6 +1412,8 @@ ir::Expression *ParserImpl::ParseTsTypeLiteralOrInterfaceMember() bool optional = false; bool signature = false; bool readonly = false; + bool isGetAccessor = false; + bool isSetAccessor = false; bool isConstructSignature = false; bool isIndexSignature = false; lexer::SourcePosition memberStartLoc = lexer_->GetToken().Start(); @@ -1396,7 +1425,7 @@ ir::Expression *ParserImpl::ParseTsTypeLiteralOrInterfaceMember() lexer_->NextToken(); } - ir::Expression *key = ParseTsTypeLiteralOrInterfaceKey(&computed, &signature, &isIndexSignature); + ir::Expression *key = ParseTsTypeLiteralOrInterfaceKey(&computed, &signature, &isGetAccessor, &isSetAccessor, &isIndexSignature); if (lexer_->GetToken().Type() == lexer::TokenType::PUNCTUATOR_QUESTION_MARK) { if (isIndexSignature) { @@ -1464,7 +1493,7 @@ ir::Expression *ParserImpl::ParseTsTypeLiteralOrInterfaceMember() funcParamScope->BindNode(member); } else { member = AllocNode(funcParamScope, key, typeParamDecl, std::move(params), - typeAnnotation, computed, optional); + typeAnnotation, computed, optional, isGetAccessor, isSetAccessor);//改动 funcParamScope->BindNode(member); CreateTSVariableForProperty(member, key, flags | binder::VariableFlags::METHOD); } diff --git a/es2panda/parser/parserImpl.h b/es2panda/parser/parserImpl.h index 7b026849e8..7c43a9f8fe 100644 --- a/es2panda/parser/parserImpl.h +++ b/es2panda/parser/parserImpl.h @@ -261,8 +261,7 @@ private: ir::MappedOption ParseMappedOption(lexer::TokenType tokenType); ir::TSMappedType *ParseTsMappedType(); ir::TSTypePredicate *ParseTsTypePredicate(); - ir::Expression *ParseTsTypeLiteralOrInterfaceKey(bool *computed, bool *signature, bool *isIndexSignature); - ir::Expression *ParseTsConditionalType(ir::Expression *checkType, bool restrictExtends); + ir::Expression *ParseTsTypeLiteralOrInterfaceKey(bool *computed, bool *signature, bool *isGetAccessor, bool *isSetAccessor, bool *isIndexSignature); ir::Expression *ParseTsTypeLiteralOrInterfaceMember(); ArenaVector ParseTsTypeLiteralOrInterface(); ir::Expression *ParseTsThisType(bool throwError); diff --git a/es2panda/test/parser/ts/test-interface-expected.txt b/es2panda/test/parser/ts/test-interface-expected.txt index 37c1fd7f70..977a45f2ea 100644 --- a/es2panda/test/parser/ts/test-interface-expected.txt +++ b/es2panda/test/parser/ts/test-interface-expected.txt @@ -124,6 +124,8 @@ "type": "TSMethodSignature", "computed": false, "optional": false, + "isGetAccessor": false, + "isSetAccessor": false, "key": { "type": "Identifier", "name": "c", @@ -563,6 +565,8 @@ "type": "TSMethodSignature", "computed": false, "optional": true, + "isGetAccessor": false, + "isSetAccessor": false, "key": { "type": "Identifier", "name": "c", diff --git a/es2panda/test/parser/ts/test-interface-method-identifier1-expected.txt b/es2panda/test/parser/ts/test-interface-method-identifier1-expected.txt index 15e28df1ac..7a013c213a 100644 --- a/es2panda/test/parser/ts/test-interface-method-identifier1-expected.txt +++ b/es2panda/test/parser/ts/test-interface-method-identifier1-expected.txt @@ -10,6 +10,8 @@ "type": "TSMethodSignature", "computed": false, "optional": false, + "isGetAccessor": false, + "isSetAccessor": false, "key": { "type": "Identifier", "name": "then", @@ -252,6 +254,8 @@ "type": "TSMethodSignature", "computed": false, "optional": false, + "isGetAccessor": false, + "isSetAccessor": false, "key": { "type": "Identifier", "name": "then", diff --git a/es2panda/test/parser/ts/test-interface4-expected.txt b/es2panda/test/parser/ts/test-interface4-expected.txt index 474d4ddeb2..2854b5dddc 100644 --- a/es2panda/test/parser/ts/test-interface4-expected.txt +++ b/es2panda/test/parser/ts/test-interface4-expected.txt @@ -10,6 +10,8 @@ "type": "TSMethodSignature", "computed": false, "optional": false, + "isGetAccessor": false, + "isSetAccessor": false, "key": { "type": "Identifier", "name": "func", @@ -108,6 +110,8 @@ "type": "TSMethodSignature", "computed": false, "optional": false, + "isGetAccessor": false, + "isSetAccessor": false, "key": { "type": "Identifier", "name": "is", diff --git a/es2panda/test/parser/ts/test-type-literal-expected.txt b/es2panda/test/parser/ts/test-type-literal-expected.txt index 369ecc7812..dd292dbaed 100644 --- a/es2panda/test/parser/ts/test-type-literal-expected.txt +++ b/es2panda/test/parser/ts/test-type-literal-expected.txt @@ -141,6 +141,8 @@ "type": "TSMethodSignature", "computed": false, "optional": true, + "isGetAccessor": false, + "isSetAccessor": false, "key": { "type": "Identifier", "name": "b", @@ -491,6 +493,8 @@ "type": "TSMethodSignature", "computed": false, "optional": false, + "isGetAccessor": false, + "isSetAccessor": false, "key": { "type": "Identifier", "name": "a", @@ -829,6 +833,8 @@ "type": "TSMethodSignature", "computed": true, "optional": false, + "isGetAccessor": false, + "isSetAccessor": false, "key": { "type": "NumberLiteral", "value": 5, diff --git a/es2panda/test/parser/ts/test_GetOrSetAccessor1-expected.txt b/es2panda/test/parser/ts/test_GetOrSetAccessor1-expected.txt new file mode 100644 index 0000000000..4ebbc89b19 --- /dev/null +++ b/es2panda/test/parser/ts/test_GetOrSetAccessor1-expected.txt @@ -0,0 +1,249 @@ +{ + "type": "Program", + "statements": [ + { + "type": "TSInterfaceDeclaration", + "body": { + "type": "TSInterfaceBody", + "body": [ + { + "type": "TSPropertySignature", + "computed": false, + "optional": false, + "readonly": false, + "key": { + "type": "Identifier", + "name": "id", + "loc": { + "start": { + "line": 18, + "column": 5 + }, + "end": { + "line": 18, + "column": 7 + } + } + }, + "typeAnnotation": { + "type": "TSNumberKeyword", + "loc": { + "start": { + "line": 18, + "column": 9 + }, + "end": { + "line": 18, + "column": 15 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 5 + }, + "end": { + "line": 18, + "column": 16 + } + } + }, + { + "type": "TSPropertySignature", + "computed": false, + "optional": false, + "readonly": false, + "key": { + "type": "Identifier", + "name": "name", + "loc": { + "start": { + "line": 19, + "column": 5 + }, + "end": { + "line": 19, + "column": 9 + } + } + }, + "typeAnnotation": { + "type": "TSStringKeyword", + "loc": { + "start": { + "line": 19, + "column": 11 + }, + "end": { + "line": 19, + "column": 17 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 5 + }, + "end": { + "line": 19, + "column": 18 + } + } + }, + { + "type": "TSMethodSignature", + "computed": false, + "optional": false, + "isGetAccessor": true, + "isSetAccessor": false, + "key": { + "type": "Identifier", + "name": "gid", + "loc": { + "start": { + "line": 20, + "column": 9 + }, + "end": { + "line": 20, + "column": 12 + } + } + }, + "params": [], + "typeAnnotation": { + "type": "TSNumberKeyword", + "loc": { + "start": { + "line": 20, + "column": 16 + }, + "end": { + "line": 20, + "column": 22 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 5 + }, + "end": { + "line": 20, + "column": 23 + } + } + }, + { + "type": "TSMethodSignature", + "computed": false, + "optional": false, + "isGetAccessor": false, + "isSetAccessor": true, + "key": { + "type": "Identifier", + "name": "sid", + "loc": { + "start": { + "line": 21, + "column": 9 + }, + "end": { + "line": 21, + "column": 12 + } + } + }, + "params": [ + { + "type": "Identifier", + "name": "id", + "typeAnnotation": { + "type": "TSNumberKeyword", + "loc": { + "start": { + "line": 21, + "column": 17 + }, + "end": { + "line": 21, + "column": 23 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 13 + }, + "end": { + "line": 21, + "column": 15 + } + } + } + ], + "loc": { + "start": { + "line": 21, + "column": 5 + }, + "end": { + "line": 21, + "column": 25 + } + } + } + ], + "loc": { + "start": { + "line": 17, + "column": 15 + }, + "end": { + "line": 22, + "column": 4 + } + } + }, + "id": { + "type": "Identifier", + "name": "Obj", + "loc": { + "start": { + "line": 17, + "column": 11 + }, + "end": { + "line": 17, + "column": 14 + } + } + }, + "extends": [], + "loc": { + "start": { + "line": 17, + "column": 1 + }, + "end": { + "line": 22, + "column": 4 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 24, + "column": 1 + } + } +} diff --git a/es2panda/test/parser/ts/test_GetOrSetAccessor1.ts b/es2panda/test/parser/ts/test_GetOrSetAccessor1.ts new file mode 100644 index 0000000000..3bc0ca9739 --- /dev/null +++ b/es2panda/test/parser/ts/test_GetOrSetAccessor1.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. + */ + + +interface Obj { + id: number; + name: string; + get gid(): number; + set sid(id: number); + } + diff --git a/es2panda/test/parser/ts/test_GetOrSetAccessor2-expected.txt b/es2panda/test/parser/ts/test_GetOrSetAccessor2-expected.txt new file mode 100644 index 0000000000..b664927506 --- /dev/null +++ b/es2panda/test/parser/ts/test_GetOrSetAccessor2-expected.txt @@ -0,0 +1,234 @@ +{ + "type": "Program", + "statements": [ + { + "type": "TSInterfaceDeclaration", + "body": { + "type": "TSInterfaceBody", + "body": [ + { + "type": "TSPropertySignature", + "computed": false, + "optional": false, + "readonly": false, + "key": { + "type": "Identifier", + "name": "id", + "loc": { + "start": { + "line": 18, + "column": 5 + }, + "end": { + "line": 18, + "column": 7 + } + } + }, + "typeAnnotation": { + "type": "TSNumberKeyword", + "loc": { + "start": { + "line": 18, + "column": 9 + }, + "end": { + "line": 18, + "column": 15 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 5 + }, + "end": { + "line": 18, + "column": 16 + } + } + }, + { + "type": "TSPropertySignature", + "computed": false, + "optional": false, + "readonly": false, + "key": { + "type": "Identifier", + "name": "name1", + "loc": { + "start": { + "line": 19, + "column": 5 + }, + "end": { + "line": 19, + "column": 10 + } + } + }, + "typeAnnotation": { + "type": "TSStringKeyword", + "loc": { + "start": { + "line": 19, + "column": 12 + }, + "end": { + "line": 19, + "column": 18 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 5 + }, + "end": { + "line": 19, + "column": 19 + } + } + }, + { + "type": "TSMethodSignature", + "computed": false, + "optional": true, + "isGetAccessor": false, + "isSetAccessor": false, + "key": { + "type": "Identifier", + "name": "get", + "loc": { + "start": { + "line": 20, + "column": 5 + }, + "end": { + "line": 20, + "column": 8 + } + } + }, + "params": [], + "typeAnnotation": { + "type": "TSNumberKeyword", + "loc": { + "start": { + "line": 20, + "column": 13 + }, + "end": { + "line": 20, + "column": 19 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 5 + }, + "end": { + "line": 20, + "column": 20 + } + } + }, + { + "type": "TSMethodSignature", + "computed": false, + "optional": false, + "isGetAccessor": true, + "isSetAccessor": false, + "key": { + "type": "Identifier", + "name": "getname1", + "loc": { + "start": { + "line": 21, + "column": 9 + }, + "end": { + "line": 21, + "column": 17 + } + } + }, + "params": [], + "typeAnnotation": { + "type": "TSNumberKeyword", + "loc": { + "start": { + "line": 21, + "column": 20 + }, + "end": { + "line": 21, + "column": 26 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 5 + }, + "end": { + "line": 21, + "column": 27 + } + } + } + ], + "loc": { + "start": { + "line": 17, + "column": 15 + }, + "end": { + "line": 23, + "column": 4 + } + } + }, + "id": { + "type": "Identifier", + "name": "Obj", + "loc": { + "start": { + "line": 17, + "column": 11 + }, + "end": { + "line": 17, + "column": 14 + } + } + }, + "extends": [], + "loc": { + "start": { + "line": 17, + "column": 1 + }, + "end": { + "line": 23, + "column": 4 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 25, + "column": 1 + } + } +} diff --git a/es2panda/test/parser/ts/test_GetOrSetAccessor2.ts b/es2panda/test/parser/ts/test_GetOrSetAccessor2.ts new file mode 100644 index 0000000000..1edea87b58 --- /dev/null +++ b/es2panda/test/parser/ts/test_GetOrSetAccessor2.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. + */ + + +interface Obj { + id: number; + name1: string; + get?(): number; + get getname1():number; + + } + diff --git a/es2panda/test/parser/ts/test_GetOrSetAccessor3-expected.txt b/es2panda/test/parser/ts/test_GetOrSetAccessor3-expected.txt new file mode 100644 index 0000000000..c8e2a92971 --- /dev/null +++ b/es2panda/test/parser/ts/test_GetOrSetAccessor3-expected.txt @@ -0,0 +1,192 @@ +{ + "type": "Program", + "statements": [ + { + "type": "TSInterfaceDeclaration", + "body": { + "type": "TSInterfaceBody", + "body": [ + { + "type": "TSMethodSignature", + "computed": false, + "optional": false, + "isGetAccessor": false, + "isSetAccessor": false, + "key": { + "type": "Identifier", + "name": "get1", + "loc": { + "start": { + "line": 18, + "column": 5 + }, + "end": { + "line": 18, + "column": 9 + } + } + }, + "params": [], + "typeAnnotation": { + "type": "TSVoidKeyword", + "loc": { + "start": { + "line": 18, + "column": 12 + }, + "end": { + "line": 18, + "column": 16 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 5 + }, + "end": { + "line": 18, + "column": 17 + } + } + }, + { + "type": "TSMethodSignature", + "computed": false, + "optional": false, + "isGetAccessor": false, + "isSetAccessor": false, + "key": { + "type": "Identifier", + "name": "get2", + "loc": { + "start": { + "line": 19, + "column": 5 + }, + "end": { + "line": 19, + "column": 9 + } + } + }, + "params": [], + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "params": [ + { + "type": "TSTypeParameter", + "name": { + "type": "Identifier", + "name": "T", + "loc": { + "start": { + "line": 19, + "column": 10 + }, + "end": { + "line": 19, + "column": 11 + } + } + }, + "in": false, + "out": false, + "loc": { + "start": { + "line": 19, + "column": 10 + }, + "end": { + "line": 19, + "column": 12 + } + } + } + ], + "loc": { + "start": { + "line": 19, + "column": 9 + }, + "end": { + "line": 19, + "column": 12 + } + } + }, + "typeAnnotation": { + "type": "TSVoidKeyword", + "loc": { + "start": { + "line": 19, + "column": 15 + }, + "end": { + "line": 19, + "column": 19 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 5 + }, + "end": { + "line": 19, + "column": 20 + } + } + } + ], + "loc": { + "start": { + "line": 17, + "column": 15 + }, + "end": { + "line": 20, + "column": 2 + } + } + }, + "id": { + "type": "Identifier", + "name": "Obj", + "loc": { + "start": { + "line": 17, + "column": 11 + }, + "end": { + "line": 17, + "column": 14 + } + } + }, + "extends": [], + "loc": { + "start": { + "line": 17, + "column": 1 + }, + "end": { + "line": 20, + "column": 2 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 20, + "column": 2 + } + } +} diff --git a/es2panda/test/parser/ts/test_GetOrSetAccessor3.ts b/es2panda/test/parser/ts/test_GetOrSetAccessor3.ts new file mode 100644 index 0000000000..e325874fe3 --- /dev/null +++ b/es2panda/test/parser/ts/test_GetOrSetAccessor3.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. + */ + + +interface Obj { + get1():void; + get2():void; +} \ No newline at end of file diff --git a/es2panda/test/parser/ts/test_GetOrSetAccessor4-expected.txt b/es2panda/test/parser/ts/test_GetOrSetAccessor4-expected.txt new file mode 100644 index 0000000000..21945d7778 --- /dev/null +++ b/es2panda/test/parser/ts/test_GetOrSetAccessor4-expected.txt @@ -0,0 +1,192 @@ +{ + "type": "Program", + "statements": [ + { + "type": "TSInterfaceDeclaration", + "body": { + "type": "TSInterfaceBody", + "body": [ + { + "type": "TSMethodSignature", + "computed": false, + "optional": false, + "isGetAccessor": false, + "isSetAccessor": false, + "key": { + "type": "Identifier", + "name": "set1", + "loc": { + "start": { + "line": 18, + "column": 5 + }, + "end": { + "line": 18, + "column": 9 + } + } + }, + "params": [], + "typeAnnotation": { + "type": "TSVoidKeyword", + "loc": { + "start": { + "line": 18, + "column": 12 + }, + "end": { + "line": 18, + "column": 16 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 5 + }, + "end": { + "line": 18, + "column": 17 + } + } + }, + { + "type": "TSMethodSignature", + "computed": false, + "optional": false, + "isGetAccessor": false, + "isSetAccessor": false, + "key": { + "type": "Identifier", + "name": "set2", + "loc": { + "start": { + "line": 19, + "column": 5 + }, + "end": { + "line": 19, + "column": 9 + } + } + }, + "params": [], + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "params": [ + { + "type": "TSTypeParameter", + "name": { + "type": "Identifier", + "name": "T", + "loc": { + "start": { + "line": 19, + "column": 10 + }, + "end": { + "line": 19, + "column": 11 + } + } + }, + "in": false, + "out": false, + "loc": { + "start": { + "line": 19, + "column": 10 + }, + "end": { + "line": 19, + "column": 12 + } + } + } + ], + "loc": { + "start": { + "line": 19, + "column": 9 + }, + "end": { + "line": 19, + "column": 12 + } + } + }, + "typeAnnotation": { + "type": "TSVoidKeyword", + "loc": { + "start": { + "line": 19, + "column": 15 + }, + "end": { + "line": 19, + "column": 19 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 5 + }, + "end": { + "line": 19, + "column": 20 + } + } + } + ], + "loc": { + "start": { + "line": 17, + "column": 15 + }, + "end": { + "line": 20, + "column": 4 + } + } + }, + "id": { + "type": "Identifier", + "name": "Obj", + "loc": { + "start": { + "line": 17, + "column": 11 + }, + "end": { + "line": 17, + "column": 14 + } + } + }, + "extends": [], + "loc": { + "start": { + "line": 17, + "column": 1 + }, + "end": { + "line": 20, + "column": 4 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 20, + "column": 4 + } + } +} diff --git a/es2panda/test/parser/ts/test_GetOrSetAccessor4.ts b/es2panda/test/parser/ts/test_GetOrSetAccessor4.ts new file mode 100644 index 0000000000..8b14d55029 --- /dev/null +++ b/es2panda/test/parser/ts/test_GetOrSetAccessor4.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. + */ + + +interface Obj { + set1():void; + set2():void; + } \ No newline at end of file diff --git a/es2panda/test/parser/ts/test_GetOrSetAccessor5-expected.txt b/es2panda/test/parser/ts/test_GetOrSetAccessor5-expected.txt new file mode 100644 index 0000000000..1cf534ae47 --- /dev/null +++ b/es2panda/test/parser/ts/test_GetOrSetAccessor5-expected.txt @@ -0,0 +1,192 @@ +{ + "type": "Program", + "statements": [ + { + "type": "TSInterfaceDeclaration", + "body": { + "type": "TSInterfaceBody", + "body": [ + { + "type": "TSMethodSignature", + "computed": false, + "optional": true, + "isGetAccessor": false, + "isSetAccessor": false, + "key": { + "type": "Identifier", + "name": "setid", + "loc": { + "start": { + "line": 18, + "column": 5 + }, + "end": { + "line": 18, + "column": 10 + } + } + }, + "params": [], + "typeAnnotation": { + "type": "TSVoidKeyword", + "loc": { + "start": { + "line": 18, + "column": 14 + }, + "end": { + "line": 18, + "column": 18 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 5 + }, + "end": { + "line": 18, + "column": 19 + } + } + }, + { + "type": "TSMethodSignature", + "computed": false, + "optional": false, + "isGetAccessor": false, + "isSetAccessor": false, + "key": { + "type": "Identifier", + "name": "set", + "loc": { + "start": { + "line": 19, + "column": 5 + }, + "end": { + "line": 19, + "column": 8 + } + } + }, + "params": [], + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "params": [ + { + "type": "TSTypeParameter", + "name": { + "type": "Identifier", + "name": "T", + "loc": { + "start": { + "line": 19, + "column": 9 + }, + "end": { + "line": 19, + "column": 10 + } + } + }, + "in": false, + "out": false, + "loc": { + "start": { + "line": 19, + "column": 9 + }, + "end": { + "line": 19, + "column": 11 + } + } + } + ], + "loc": { + "start": { + "line": 19, + "column": 8 + }, + "end": { + "line": 19, + "column": 11 + } + } + }, + "typeAnnotation": { + "type": "TSVoidKeyword", + "loc": { + "start": { + "line": 19, + "column": 14 + }, + "end": { + "line": 19, + "column": 18 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 5 + }, + "end": { + "line": 19, + "column": 19 + } + } + } + ], + "loc": { + "start": { + "line": 17, + "column": 15 + }, + "end": { + "line": 20, + "column": 4 + } + } + }, + "id": { + "type": "Identifier", + "name": "Obj", + "loc": { + "start": { + "line": 17, + "column": 11 + }, + "end": { + "line": 17, + "column": 14 + } + } + }, + "extends": [], + "loc": { + "start": { + "line": 17, + "column": 1 + }, + "end": { + "line": 20, + "column": 4 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 20, + "column": 4 + } + } +} diff --git a/es2panda/test/parser/ts/test_GetOrSetAccessor5.ts b/es2panda/test/parser/ts/test_GetOrSetAccessor5.ts new file mode 100644 index 0000000000..1445cb902e --- /dev/null +++ b/es2panda/test/parser/ts/test_GetOrSetAccessor5.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. + */ + + +interface Obj { + setid?():void; + set():void; + } \ No newline at end of file diff --git a/es2panda/test/parser/ts/test_GetOrSetAccessor6-expected.txt b/es2panda/test/parser/ts/test_GetOrSetAccessor6-expected.txt new file mode 100644 index 0000000000..ab6802971d --- /dev/null +++ b/es2panda/test/parser/ts/test_GetOrSetAccessor6-expected.txt @@ -0,0 +1,163 @@ +{ + "type": "Program", + "statements": [ + { + "type": "TSInterfaceDeclaration", + "body": { + "type": "TSInterfaceBody", + "body": [ + { + "type": "TSMethodSignature", + "computed": false, + "optional": false, + "isGetAccessor": false, + "isSetAccessor": true, + "key": { + "type": "Identifier", + "name": "set", + "loc": { + "start": { + "line": 18, + "column": 9 + }, + "end": { + "line": 18, + "column": 12 + } + } + }, + "params": [ + { + "type": "Identifier", + "name": "p", + "typeAnnotation": { + "type": "TSStringKeyword", + "loc": { + "start": { + "line": 18, + "column": 15 + }, + "end": { + "line": 18, + "column": 21 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 13 + }, + "end": { + "line": 18, + "column": 14 + } + } + } + ], + "loc": { + "start": { + "line": 18, + "column": 5 + }, + "end": { + "line": 18, + "column": 23 + } + } + }, + { + "type": "TSMethodSignature", + "computed": false, + "optional": false, + "isGetAccessor": true, + "isSetAccessor": false, + "key": { + "type": "Identifier", + "name": "get", + "loc": { + "start": { + "line": 19, + "column": 9 + }, + "end": { + "line": 19, + "column": 12 + } + } + }, + "params": [], + "typeAnnotation": { + "type": "TSNumberKeyword", + "loc": { + "start": { + "line": 19, + "column": 15 + }, + "end": { + "line": 19, + "column": 21 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 5 + }, + "end": { + "line": 19, + "column": 22 + } + } + } + ], + "loc": { + "start": { + "line": 17, + "column": 14 + }, + "end": { + "line": 20, + "column": 2 + } + } + }, + "id": { + "type": "Identifier", + "name": "I1", + "loc": { + "start": { + "line": 17, + "column": 11 + }, + "end": { + "line": 17, + "column": 13 + } + } + }, + "extends": [], + "loc": { + "start": { + "line": 17, + "column": 1 + }, + "end": { + "line": 20, + "column": 2 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 20, + "column": 2 + } + } +} diff --git a/es2panda/test/parser/ts/test_GetOrSetAccessor6.ts b/es2panda/test/parser/ts/test_GetOrSetAccessor6.ts new file mode 100644 index 0000000000..8f2658c0c8 --- /dev/null +++ b/es2panda/test/parser/ts/test_GetOrSetAccessor6.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. + */ + + +interface I1 { + set set(p:string); + get get():number; +} \ No newline at end of file diff --git a/es2panda/test/parser/ts/test_generic-expected.txt b/es2panda/test/parser/ts/test_generic-expected.txt index 4c9760fb9f..97aa20ffb4 100644 --- a/es2panda/test/parser/ts/test_generic-expected.txt +++ b/es2panda/test/parser/ts/test_generic-expected.txt @@ -1783,6 +1783,8 @@ "type": "TSMethodSignature", "computed": false, "optional": false, + "isGetAccessor": false, + "isSetAccessor": false, "key": { "type": "Identifier", "name": "readonly", diff --git a/es2panda/test/parser/ts/test_import_type-expected.txt b/es2panda/test/parser/ts/test_import_type-expected.txt index 02b373b7db..def786ea3a 100644 --- a/es2panda/test/parser/ts/test_import_type-expected.txt +++ b/es2panda/test/parser/ts/test_import_type-expected.txt @@ -95,6 +95,8 @@ "type": "TSMethodSignature", "computed": false, "optional": false, + "isGetAccessor": false, + "isSetAccessor": false, "key": { "type": "Identifier", "name": "k", diff --git a/es2panda/test/parser/ts/test_module-expected.txt b/es2panda/test/parser/ts/test_module-expected.txt index 2c43ab6bbd..17d1cf9dff 100644 --- a/es2panda/test/parser/ts/test_module-expected.txt +++ b/es2panda/test/parser/ts/test_module-expected.txt @@ -185,6 +185,8 @@ "type": "TSMethodSignature", "computed": false, "optional": false, + "isGetAccessor": false, + "isSetAccessor": false, "key": { "type": "Identifier", "name": "b", diff --git a/es2panda/test/parser/ts/test_satisfies3-expected.txt b/es2panda/test/parser/ts/test_satisfies3-expected.txt index d0f0d375fa..a7951ac347 100644 --- a/es2panda/test/parser/ts/test_satisfies3-expected.txt +++ b/es2panda/test/parser/ts/test_satisfies3-expected.txt @@ -19,6 +19,8 @@ "type": "TSMethodSignature", "computed": false, "optional": false, + "isGetAccessor": false, + "isSetAccessor": false, "key": { "type": "Identifier", "name": "f", @@ -398,6 +400,8 @@ "type": "TSMethodSignature", "computed": false, "optional": false, + "isGetAccessor": false, + "isSetAccessor": false, "key": { "type": "Identifier", "name": "g", @@ -709,6 +713,8 @@ "type": "TSMethodSignature", "computed": false, "optional": false, + "isGetAccessor": false, + "isSetAccessor": false, "key": { "type": "Identifier", "name": "f", diff --git a/es2panda/test/parser/ts/test_satisfies4-expected.txt b/es2panda/test/parser/ts/test_satisfies4-expected.txt index 3e80c05590..4558c9869a 100644 --- a/es2panda/test/parser/ts/test_satisfies4-expected.txt +++ b/es2panda/test/parser/ts/test_satisfies4-expected.txt @@ -24,6 +24,8 @@ "type": "TSMethodSignature", "computed": false, "optional": false, + "isGetAccessor": false, + "isSetAccessor": false, "key": { "type": "Identifier", "name": "move", diff --git a/es2panda/test/parser/ts/type_checker/interfaceAssignment-expected.txt b/es2panda/test/parser/ts/type_checker/interfaceAssignment-expected.txt index 7c0e62e65a..9ea2dc758f 100644 --- a/es2panda/test/parser/ts/type_checker/interfaceAssignment-expected.txt +++ b/es2panda/test/parser/ts/type_checker/interfaceAssignment-expected.txt @@ -402,6 +402,8 @@ "type": "TSMethodSignature", "computed": false, "optional": false, + "isGetAccessor": false, + "isSetAccessor": false, "key": { "type": "Identifier", "name": "d", diff --git a/es2panda/test/parser/ts/type_checker/interfaceUsedAsValue-expected.txt b/es2panda/test/parser/ts/type_checker/interfaceUsedAsValue-expected.txt index 95a5adcb63..3da9318650 100644 --- a/es2panda/test/parser/ts/type_checker/interfaceUsedAsValue-expected.txt +++ b/es2panda/test/parser/ts/type_checker/interfaceUsedAsValue-expected.txt @@ -53,6 +53,8 @@ "type": "TSMethodSignature", "computed": false, "optional": false, + "isGetAccessor": false, + "isSetAccessor": false, "key": { "type": "Identifier", "name": "b", diff --git a/es2panda/test/parser/ts/type_checker/memberExpTests-expected.txt b/es2panda/test/parser/ts/type_checker/memberExpTests-expected.txt index 72a6ce88c2..059b4a6129 100644 --- a/es2panda/test/parser/ts/type_checker/memberExpTests-expected.txt +++ b/es2panda/test/parser/ts/type_checker/memberExpTests-expected.txt @@ -4633,6 +4633,8 @@ "type": "TSMethodSignature", "computed": false, "optional": false, + "isGetAccessor": false, + "isSetAccessor": false, "key": { "type": "Identifier", "name": "b", diff --git a/es2panda/test/parser/ts/type_checker/objectDestructuring-expected.txt b/es2panda/test/parser/ts/type_checker/objectDestructuring-expected.txt index 6fd777a27a..6877eb13c7 100644 --- a/es2panda/test/parser/ts/type_checker/objectDestructuring-expected.txt +++ b/es2panda/test/parser/ts/type_checker/objectDestructuring-expected.txt @@ -3771,6 +3771,8 @@ "type": "TSMethodSignature", "computed": false, "optional": false, + "isGetAccessor": false, + "isSetAccessor": false, "key": { "type": "Identifier", "name": "b", diff --git a/es2panda/test/parser/ts/type_checker/objectLiteralAssignability-expected.txt b/es2panda/test/parser/ts/type_checker/objectLiteralAssignability-expected.txt index b1757fae5d..18d5c1c308 100644 --- a/es2panda/test/parser/ts/type_checker/objectLiteralAssignability-expected.txt +++ b/es2panda/test/parser/ts/type_checker/objectLiteralAssignability-expected.txt @@ -2069,6 +2069,8 @@ "type": "TSMethodSignature", "computed": false, "optional": false, + "isGetAccessor": false, + "isSetAccessor": false, "key": { "type": "Identifier", "name": "a", @@ -2167,6 +2169,8 @@ "type": "TSMethodSignature", "computed": false, "optional": false, + "isGetAccessor": false, + "isSetAccessor": false, "key": { "type": "Identifier", "name": "b", @@ -6620,6 +6624,8 @@ "type": "TSMethodSignature", "computed": false, "optional": true, + "isGetAccessor": false, + "isSetAccessor": false, "key": { "type": "Identifier", "name": "b", diff --git a/es2panda/test/parser/ts/type_checker/test-interface-expected.txt b/es2panda/test/parser/ts/type_checker/test-interface-expected.txt index 2325c2066d..5d850402f3 100644 --- a/es2panda/test/parser/ts/type_checker/test-interface-expected.txt +++ b/es2panda/test/parser/ts/type_checker/test-interface-expected.txt @@ -124,6 +124,8 @@ "type": "TSMethodSignature", "computed": false, "optional": false, + "isGetAccessor": false, + "isSetAccessor": false, "key": { "type": "Identifier", "name": "c", @@ -415,6 +417,8 @@ "type": "TSMethodSignature", "computed": false, "optional": false, + "isGetAccessor": false, + "isSetAccessor": false, "key": { "type": "Identifier", "name": "readonly", @@ -689,6 +693,8 @@ "type": "TSMethodSignature", "computed": false, "optional": true, + "isGetAccessor": false, + "isSetAccessor": false, "key": { "type": "Identifier", "name": "c", diff --git a/es2panda/test/parser/ts/type_checker/test-type-literal-expected.txt b/es2panda/test/parser/ts/type_checker/test-type-literal-expected.txt index cc4b753107..66476afe71 100644 --- a/es2panda/test/parser/ts/type_checker/test-type-literal-expected.txt +++ b/es2panda/test/parser/ts/type_checker/test-type-literal-expected.txt @@ -141,6 +141,8 @@ "type": "TSMethodSignature", "computed": false, "optional": true, + "isGetAccessor": false, + "isSetAccessor": false, "key": { "type": "Identifier", "name": "b", @@ -530,6 +532,8 @@ "type": "TSMethodSignature", "computed": false, "optional": false, + "isGetAccessor": false, + "isSetAccessor": false, "key": { "type": "Identifier", "name": "a", @@ -909,6 +913,8 @@ "type": "TSMethodSignature", "computed": true, "optional": false, + "isGetAccessor": false, + "isSetAccessor": false, "key": { "type": "NumberLiteral", "value": 5, @@ -1525,6 +1531,8 @@ "type": "TSMethodSignature", "computed": false, "optional": false, + "isGetAccessor": false, + "isSetAccessor": false, "key": { "type": "Identifier", "name": "readonly", -- Gitee