diff --git a/es2panda/ir/ts/tsMethodSignature.cpp b/es2panda/ir/ts/tsMethodSignature.cpp index c83c09581b3e609ab7383c9c078f11dd188b6137..afe26da5c1ccf2643a4e2b952902ffe646ace084 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 b10488351664e4673e263b27cc3bf4368f0f8926..61e07dee51bedb1b87ad516a910a1a656e8730c9 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 1a8d74c040eeb44028943c823b8864468a8fefb7..44349922fe128fd6966619d7cb472397ca9cc18a 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 7b026849e8e48ab9a200b8dba2148098ee853754..7c43a9f8fed9dd1b27ef088b037e204c8db32bb8 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 37c1fd7f709809cd417749c18796b1fcd5fb2188..977a45f2ead515a00f5f33dcd2ce9d6b5702fe88 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 15e28df1ac944e24c9083e46b325828f5b4dfd54..7a013c213a8d61e4310a7648e89ad22944a729c4 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 474d4ddeb2f48feefd0d7bb2751b94c52e2b7f96..2854b5dddc41d5544098ff93c598cfd296b037c6 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 369ecc781201d78294b52fcc8f2febd3a169fb8f..dd292dbaedebb77c049dad1cbb8022afdfc4bb07 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 0000000000000000000000000000000000000000..4ebbc89b19b72e14044c8caf6923831d623a911a --- /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 0000000000000000000000000000000000000000..3bc0ca9739fa2cbb3671f1272d86a12af8ead136 --- /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 0000000000000000000000000000000000000000..b664927506351ddd0c1fb31ca5cc6efe9c756358 --- /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 0000000000000000000000000000000000000000..1edea87b58617f78b5fb56d670c2ab4d84ef184a --- /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 0000000000000000000000000000000000000000..c8e2a92971b0b21cfe6a2a4231b13c25f930c66c --- /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 0000000000000000000000000000000000000000..e325874fe3ca72869406f8a887a3c77d4818c633 --- /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 0000000000000000000000000000000000000000..21945d7778089454b6b4981df2ca6fa0bb1e547a --- /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 0000000000000000000000000000000000000000..8b14d550292431425b7d4785f061075ddd45aa31 --- /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 0000000000000000000000000000000000000000..1cf534ae47a58f49d4a797ed4a3eed970ed51a93 --- /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 0000000000000000000000000000000000000000..1445cb902ea16d343a7e1575ea07117f7413bfcb --- /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 0000000000000000000000000000000000000000..ab6802971d010615b9074d95b8a260fe5acb34c6 --- /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 0000000000000000000000000000000000000000..8f2658c0c85d05c4e47afb63c74c5c95ca6cc755 --- /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 4c9760fb9f828a7e82e21c3904821f818bf3af0f..97aa20ffb4925938747f329741db5b0f02c9c007 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 02b373b7db7de40ef61fc36fdaa41bb48e9b1a84..def786ea3a4a973c1daadec9455731a1db22d310 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 2c43ab6bbddfb62657eda833b6c9fa710f698faf..17d1cf9dffa9a82f839f62346eca0ab0bb2d5afc 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 d0f0d375fae2562655f7137a8fbdc583a0441707..a7951ac347d946dbc8a0abbd4d919b40fa2ec80d 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 3e80c055909d4b57853cd9d8ae783e626a2725e6..4558c9869aef91dfa44b71aef26d730fd45e2ee0 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 7c0e62e65ae61c791acb78f761931fd53d7c17e4..9ea2dc758f5b8aa3db19f4eee8ebe639d37f3c73 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 95a5adcb63d5e8f9e21d8b507bf0bc4f8d14df20..3da9318650c5618d607ff407db1aa5c5893790e3 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 72a6ce88c2af9ca28234ce50b9dfb52f3a295fbc..059b4a6129ef97afd4892904e5c27f18b3d63cb5 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 6fd777a27acb578b3d44bbcca1509886bc749e36..6877eb13c7a13113998a5ee4a3982b60de640c28 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 b1757fae5d95da3bfb9d766ec8eebbb79ef175af..18d5c1c308369b38b7c7f369ad9f3ebc0d1bf32e 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 2325c2066dd48ddf21166951eb2761120ccc16ea..5d850402f35ed341e7783ad73d7b57246cc03856 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 cc4b7531074d94a102f80b365385a436d140728d..66476afe71c566fddd7b2f77b36abf5519a397be 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",