diff --git a/es2panda/BUILD.gn b/es2panda/BUILD.gn index 184bfa3f28bb458f8691d8527bedec572b791cc2..788719bab92903858e9bd5f066d73e8555b7b304 100644 --- a/es2panda/BUILD.gn +++ b/es2panda/BUILD.gn @@ -92,6 +92,7 @@ es2panda_src = [ "ir/expressions/taggedTemplateExpression.cpp", "ir/expressions/templateLiteral.cpp", "ir/expressions/thisExpression.cpp", + "ir/expressions/typeArgumentsExpression.cpp", "ir/expressions/unaryExpression.cpp", "ir/expressions/updateExpression.cpp", "ir/expressions/yieldExpression.cpp", diff --git a/es2panda/ir/astNodeMapping.h b/es2panda/ir/astNodeMapping.h index 5ca835452b834aaab2899f87c61daf03134f924b..fb75caa922cf8fac1a9479f8b16815570fbb9260 100644 --- a/es2panda/ir/astNodeMapping.h +++ b/es2panda/ir/astNodeMapping.h @@ -136,6 +136,7 @@ _(TEMPLATE_ELEMENT, TemplateElement) \ _(TEMPLATE_LITERAL, TemplateLiteral) \ _(THIS_EXPRESSION, ThisExpression) \ + _(TYPE_ARGUMENTS_EXPRESSION, TypeArgumentsExpression) \ _(THROW_STATEMENT, ThrowStatement) \ _(TRY_STATEMENT, TryStatement) \ _(UNARY_EXPRESSION, UnaryExpression) \ diff --git a/es2panda/ir/expressions/typeArgumentsExpression.cpp b/es2panda/ir/expressions/typeArgumentsExpression.cpp new file mode 100644 index 0000000000000000000000000000000000000000..dc737a4ea54d2e3b356a0b1028f564c8ef7f4c41 --- /dev/null +++ b/es2panda/ir/expressions/typeArgumentsExpression.cpp @@ -0,0 +1,52 @@ +/** + * Copyright (c) 2023 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. + */ + +#include "typeArgumentsExpression.h" + +#include +#include +#include + +namespace panda::es2panda::ir { + +void TypeArgumentsExpression::Iterate([[maybe_unused]] const NodeTraverser &cb) const +{ + cb(leftHandExpression_); + cb(typeArguments_); +} + +void TypeArgumentsExpression::Dump(ir::AstDumper *dumper) const +{ + dumper->Add({{"type", "TypeArgumentsExpression"}, {"leftHandExpression", leftHandExpression_}, + {"typeArguments", typeArguments_}}); +} + +void TypeArgumentsExpression::Compile(compiler::PandaGen *pg) const +{ + leftHandExpression_->Compile(pg); +} + +checker::Type *TypeArgumentsExpression::Check(checker::Checker *checker) const +{ + return nullptr; +} + +void TypeArgumentsExpression::UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) +{ + leftHandExpression_ = std::get(cb(leftHandExpression_))->AsExpression(); + typeArguments_ = std::get(cb(typeArguments_))->AsTSTypeParameterInstantiation(); +} + +} // namespace panda::es2panda::ir diff --git a/es2panda/ir/expressions/typeArgumentsExpression.h b/es2panda/ir/expressions/typeArgumentsExpression.h new file mode 100644 index 0000000000000000000000000000000000000000..dac49cf72cbd9b51de2187d6a76f538d46d11553 --- /dev/null +++ b/es2panda/ir/expressions/typeArgumentsExpression.h @@ -0,0 +1,67 @@ +/** + * Copyright (c) 2023 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. + */ + +#ifndef ES2PANDA_IR_EXPRESSION_TYPE_ARGUMENTS_EXPRESSION_H +#define ES2PANDA_IR_EXPRESSION_TYPE_ARGUMENTS_EXPRESSION_H + +#include + +namespace panda::es2panda::compiler { +class PandaGen; +} // namespace panda::es2panda::compiler + +namespace panda::es2panda::checker { +class Checker; +class Type; +} // namespace panda::es2panda::checker + +namespace panda::es2panda::ir { + +class TSTypeParameterInstantiation; + +class TypeArgumentsExpression : public Expression { +public: + explicit TypeArgumentsExpression(Expression *leftHandExpression, + TSTypeParameterInstantiation *typeArguments) + : Expression(AstNodeType::TYPE_ARGUMENTS_EXPRESSION), + leftHandExpression_(leftHandExpression), + typeArguments_(typeArguments) + { + } + + const Expression *LeftHandExpression() const + { + return leftHandExpression_; + } + + const TSTypeParameterInstantiation *TypeArguments() const + { + return typeArguments_; + } + + void Iterate(const NodeTraverser &cb) const override; + void Dump(ir::AstDumper *dumper) const override; + void Compile(compiler::PandaGen *pg) const override; + checker::Type *Check(checker::Checker *checker) const override; + void UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; + +private: + Expression *leftHandExpression_; + TSTypeParameterInstantiation *typeArguments_; +}; + +} // namespace panda::es2panda::ir + +#endif diff --git a/es2panda/parser/expressionParser.cpp b/es2panda/parser/expressionParser.cpp index ba53678f8b76fa36461af3ca3dfcfba6d715776f..d63a59dd7bad0108709e899b5df29bbd5a9a6907 100644 --- a/es2panda/parser/expressionParser.cpp +++ b/es2panda/parser/expressionParser.cpp @@ -50,6 +50,7 @@ #include #include #include +#include #include #include #include @@ -1473,6 +1474,35 @@ ir::ArrowFunctionExpression *ParserImpl::ParsePotentialArrowExpression(ir::Expre return nullptr; } +bool ParserImpl::IsGenericInstantiation() +{ + switch (lexer_->GetToken().Type()) { + case lexer::TokenType::EOS: + case lexer::TokenType::PUNCTUATOR_SEMI_COLON: + case lexer::TokenType::PUNCTUATOR_RIGHT_PARENTHESIS: + case lexer::TokenType::PUNCTUATOR_RIGHT_BRACE: + case lexer::TokenType::PUNCTUATOR_RIGHT_SQUARE_BRACKET: + case lexer::TokenType::PUNCTUATOR_EQUAL: + case lexer::TokenType::PUNCTUATOR_LESS_THAN_EQUAL: + case lexer::TokenType::PUNCTUATOR_NOT_EQUAL: + case lexer::TokenType::PUNCTUATOR_QUESTION_MARK: + case lexer::TokenType::PUNCTUATOR_STRICT_EQUAL: + case lexer::TokenType::PUNCTUATOR_NOT_STRICT_EQUAL: + case lexer::TokenType::PUNCTUATOR_LOGICAL_AND: + case lexer::TokenType::PUNCTUATOR_SUBSTITUTION: + case lexer::TokenType::PUNCTUATOR_LOGICAL_OR: + case lexer::TokenType::PUNCTUATOR_COMMA: + case lexer::TokenType::PUNCTUATOR_NULLISH_COALESCING: + case lexer::TokenType::PUNCTUATOR_LOGICAL_AND_EQUAL: + case lexer::TokenType::PUNCTUATOR_LOGICAL_OR_EQUAL: { + return true; + } + default: { + return false; + } + } +} + bool ParserImpl::ParsePotentialTsGenericFunctionCall(ir::Expression **returnExpression, const lexer::SourcePosition &startLoc, bool ignoreCallExpression) { @@ -1503,8 +1533,11 @@ bool ParserImpl::ParsePotentialTsGenericFunctionCall(ir::Expression **returnExpr return true; } - if (lexer_->GetToken().Type() == lexer::TokenType::EOS) { - ThrowSyntaxError("'(' or '`' expected"); + if (IsGenericInstantiation() || lexer_->GetToken().NewLine()) { + *returnExpression = AllocNode(*returnExpression, typeParams); + lexer::SourcePosition endLoc = typeParams->End(); + (*returnExpression)->SetRange({startLoc, endLoc}); + return false; } if (lexer_->GetToken().Type() == lexer::TokenType::PUNCTUATOR_LEFT_PARENTHESIS) { diff --git a/es2panda/parser/parserImpl.cpp b/es2panda/parser/parserImpl.cpp index 7ae00cb6c9085de2abc17c73942b81e6ed87ecbc..3efaad027a83a8dbfbd2be2c7e7bcd263b5cf574 100644 --- a/es2panda/parser/parserImpl.cpp +++ b/es2panda/parser/parserImpl.cpp @@ -41,6 +41,7 @@ #include #include #include +#include #include #include #include @@ -1085,11 +1086,12 @@ ir::Expression *ParserImpl::ParseTsTypeReferenceOrQuery(TypeAnnotationParsingOpt ir::TSTypeParameterInstantiation *typeParamInst = nullptr; if (lexer_->GetToken().Type() == lexer::TokenType::PUNCTUATOR_LESS_THAN) { + typeParamInst = ParseTsTypeParameterInstantiation(options & TypeAnnotationParsingOptions::THROW_ERROR); if (parseQuery) { - ThrowSyntaxError("Unexpected token."); + typeName = AllocNode(typeName, typeParamInst); + lexer::SourcePosition endLoc = typeParamInst->End(); + typeName->SetRange({referenceStartLoc, endLoc}); } - - typeParamInst = ParseTsTypeParameterInstantiation(options & TypeAnnotationParsingOptions::THROW_ERROR); } if (lexer_->GetToken().Type() == lexer::TokenType::PUNCTUATOR_LEFT_SQUARE_BRACKET && diff --git a/es2panda/parser/parserImpl.h b/es2panda/parser/parserImpl.h index 92d663f62bb41b4e00fc4957564a1fbcea826788..7350735c29b980fb97de59a8b9a957fd90db2dfb 100644 --- a/es2panda/parser/parserImpl.h +++ b/es2panda/parser/parserImpl.h @@ -387,6 +387,7 @@ private: bool ignoreCallExpression); void ValidateUpdateExpression(ir::Expression *returnExpression, bool isChainExpression); + bool IsGenericInstantiation(); bool ParsePotentialTsGenericFunctionCall(ir::Expression **returnExpression, const lexer::SourcePosition &startLoc, bool ignoreCallExpression); ir::Expression *ParsePostPrimaryExpression(ir::Expression *primaryExpr, lexer::SourcePosition startLoc, diff --git a/es2panda/test/compiler/ts/cases/conformance/expressions/ts-test-instantiation-expressions-1-expected.txt b/es2panda/test/compiler/ts/cases/conformance/expressions/ts-test-instantiation-expressions-1-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..0a3538aed4eb6d3277a29bd398b4d36a9262deb8 --- /dev/null +++ b/es2panda/test/compiler/ts/cases/conformance/expressions/ts-test-instantiation-expressions-1-expected.txt @@ -0,0 +1,3 @@ +abc +function +function diff --git a/es2panda/test/compiler/ts/cases/conformance/expressions/ts-test-instantiation-expressions-1.ts b/es2panda/test/compiler/ts/cases/conformance/expressions/ts-test-instantiation-expressions-1.ts new file mode 100644 index 0000000000000000000000000000000000000000..c829c9fbfc77418d9a3a71f3b0d68b9159c8789d --- /dev/null +++ b/es2panda/test/compiler/ts/cases/conformance/expressions/ts-test-instantiation-expressions-1.ts @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2023 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. + */ + +function makeBox(value: T) { + print(value) +}; + +const makeStringBox = makeBox; // (value: string) => { value: string } +const stringBox = makeStringBox('abc'); // { value: string } + +print(typeof makeBox) +print(typeof makeBox) diff --git a/es2panda/test/compiler/ts/cases/conformance/expressions/ts-test-instantiation-expressions-2-expected.txt b/es2panda/test/compiler/ts/cases/conformance/expressions/ts-test-instantiation-expressions-2-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..56221beeaeb3a0d060436485a4c517c3a92fcc09 --- /dev/null +++ b/es2panda/test/compiler/ts/cases/conformance/expressions/ts-test-instantiation-expressions-2-expected.txt @@ -0,0 +1,3 @@ +function +function +function diff --git a/es2panda/test/compiler/ts/cases/conformance/expressions/ts-test-instantiation-expressions-2.ts b/es2panda/test/compiler/ts/cases/conformance/expressions/ts-test-instantiation-expressions-2.ts new file mode 100644 index 0000000000000000000000000000000000000000..9ace8e599c428c4338e977068e2fd12225ae2a34 --- /dev/null +++ b/es2panda/test/compiler/ts/cases/conformance/expressions/ts-test-instantiation-expressions-2.ts @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2023 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. + */ + +const ErrorMap = Map; // new () => Map +const test1 = new ErrorMap(); // Map + +print(typeof Map) + +const myArray = Array +const test2 = new myArray() +print(typeof Array) + +const mySet = Set +const test3 = new mySet() +print(typeof Set) \ No newline at end of file diff --git a/es2panda/test/compiler/ts/cases/conformance/expressions/ts-test-instantiation-expressions-3-expected.txt b/es2panda/test/compiler/ts/cases/conformance/expressions/ts-test-instantiation-expressions-3-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..190a18037c64c43e6b11489df4bf0b9eb6d2c9bf --- /dev/null +++ b/es2panda/test/compiler/ts/cases/conformance/expressions/ts-test-instantiation-expressions-3-expected.txt @@ -0,0 +1 @@ +123 diff --git a/es2panda/test/compiler/ts/cases/conformance/expressions/ts-test-instantiation-expressions-3.ts b/es2panda/test/compiler/ts/cases/conformance/expressions/ts-test-instantiation-expressions-3.ts new file mode 100644 index 0000000000000000000000000000000000000000..bd7bea02cc2acb477163051cdd89308d5721d6b7 --- /dev/null +++ b/es2panda/test/compiler/ts/cases/conformance/expressions/ts-test-instantiation-expressions-3.ts @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2023 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. + */ + +class Container { + value: T; + + constructor(value: T) { + this.value = value; + } + + test() { + print(this.value); + } +} + +const a = Container; +const b = new a(123); +b.test() \ No newline at end of file diff --git a/es2panda/test/compiler/ts/cases/conformance/expressions/ts-test-instantiation-expressions-4-expected.txt b/es2panda/test/compiler/ts/cases/conformance/expressions/ts-test-instantiation-expressions-4-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..274f08967d27120b5adc7ab12c16c65191c68bbc --- /dev/null +++ b/es2panda/test/compiler/ts/cases/conformance/expressions/ts-test-instantiation-expressions-4-expected.txt @@ -0,0 +1,7 @@ +123 +true +false +true +123 +true +false diff --git a/es2panda/test/compiler/ts/cases/conformance/expressions/ts-test-instantiation-expressions-4.ts b/es2panda/test/compiler/ts/cases/conformance/expressions/ts-test-instantiation-expressions-4.ts new file mode 100644 index 0000000000000000000000000000000000000000..c5435720668f9334f781e3166d046a2e32323e7d --- /dev/null +++ b/es2panda/test/compiler/ts/cases/conformance/expressions/ts-test-instantiation-expressions-4.ts @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2023 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. + */ + +function A(value: T) { + print(value) +} + +// "}" after "<***>" +{var c = A} +c("123") + +// "==" after "<***>" +print(A == A) + +// "!=" after "<***>" +print(A != A) + +// "<=" after "<***>" +print(A <= A) + +// "? :" after "<***>" +A ? print(123) : print(456) + +// "===" after "<***>" +print(A === A) + +// "!==" after "<***>" +print(A !== A) diff --git a/es2panda/test/parser/ts/test_instantiation_expressions1-expected.txt b/es2panda/test/parser/ts/test_instantiation_expressions1-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..c46aa0876442beda6aee87a33c434c9b741008d1 --- /dev/null +++ b/es2panda/test/parser/ts/test_instantiation_expressions1-expected.txt @@ -0,0 +1,950 @@ +{ + "type": "Program", + "statements": [ + { + "type": "FunctionDeclaration", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "makeBox", + "loc": { + "start": { + "line": 17, + "column": 10 + }, + "end": { + "line": 17, + "column": 17 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [ + { + "type": "Identifier", + "name": "value", + "typeAnnotation": { + "type": "TSTypeReference", + "typeName": { + "type": "Identifier", + "name": "T", + "loc": { + "start": { + "line": 17, + "column": 28 + }, + "end": { + "line": 17, + "column": 29 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 28 + }, + "end": { + "line": 17, + "column": 29 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 21 + }, + "end": { + "line": 17, + "column": 26 + } + } + } + ], + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "params": [ + { + "type": "TSTypeParameter", + "name": { + "type": "Identifier", + "name": "T", + "loc": { + "start": { + "line": 17, + "column": 18 + }, + "end": { + "line": 17, + "column": 19 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 18 + }, + "end": { + "line": 17, + "column": 20 + } + } + } + ], + "loc": { + "start": { + "line": 17, + "column": 17 + }, + "end": { + "line": 17, + "column": 20 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ReturnStatement", + "argument": { + "type": "ObjectExpression", + "properties": [ + { + "type": "Property", + "method": false, + "shorthand": true, + "computed": false, + "key": { + "type": "Identifier", + "name": "value", + "loc": { + "start": { + "line": 18, + "column": 14 + }, + "end": { + "line": 18, + "column": 19 + } + } + }, + "value": { + "type": "Identifier", + "name": "value", + "loc": { + "start": { + "line": 18, + "column": 14 + }, + "end": { + "line": 18, + "column": 19 + } + } + }, + "kind": "init", + "loc": { + "start": { + "line": 18, + "column": 14 + }, + "end": { + "line": 18, + "column": 19 + } + } + } + ], + "loc": { + "start": { + "line": 18, + "column": 12 + }, + "end": { + "line": 18, + "column": 21 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 5 + }, + "end": { + "line": 18, + "column": 22 + } + } + } + ], + "loc": { + "start": { + "line": 17, + "column": 31 + }, + "end": { + "line": 19, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 1 + }, + "end": { + "line": 19, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 1 + }, + "end": { + "line": 19, + "column": 2 + } + } + }, + { + "type": "EmptyStatement", + "loc": { + "start": { + "line": 19, + "column": 2 + }, + "end": { + "line": 19, + "column": 3 + } + } + }, + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "makeStringBox", + "loc": { + "start": { + "line": 21, + "column": 7 + }, + "end": { + "line": 21, + "column": 20 + } + } + }, + "init": { + "type": "TypeArgumentsExpression", + "leftHandExpression": { + "type": "Identifier", + "name": "makeBox", + "loc": { + "start": { + "line": 21, + "column": 23 + }, + "end": { + "line": 21, + "column": 30 + } + } + }, + "typeArguments": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "TSStringKeyword", + "loc": { + "start": { + "line": 21, + "column": 31 + }, + "end": { + "line": 21, + "column": 37 + } + } + } + ], + "loc": { + "start": { + "line": 21, + "column": 30 + }, + "end": { + "line": 21, + "column": 38 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 23 + }, + "end": { + "line": 21, + "column": 38 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 7 + }, + "end": { + "line": 21, + "column": 38 + } + } + } + ], + "kind": "const", + "loc": { + "start": { + "line": 21, + "column": 1 + }, + "end": { + "line": 21, + "column": 39 + } + } + }, + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "stringBox", + "loc": { + "start": { + "line": 22, + "column": 7 + }, + "end": { + "line": 22, + "column": 16 + } + } + }, + "init": { + "type": "CallExpression", + "callee": { + "type": "Identifier", + "name": "makeStringBox", + "loc": { + "start": { + "line": 22, + "column": 19 + }, + "end": { + "line": 22, + "column": 32 + } + } + }, + "arguments": [ + { + "type": "StringLiteral", + "value": "abc", + "loc": { + "start": { + "line": 22, + "column": 33 + }, + "end": { + "line": 22, + "column": 38 + } + } + } + ], + "optional": false, + "loc": { + "start": { + "line": 22, + "column": 19 + }, + "end": { + "line": 22, + "column": 39 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 7 + }, + "end": { + "line": 22, + "column": 39 + } + } + } + ], + "kind": "const", + "loc": { + "start": { + "line": 22, + "column": 1 + }, + "end": { + "line": 22, + "column": 40 + } + } + }, + { + "type": "TSTypeAliasDeclaration", + "id": { + "type": "Identifier", + "name": "StringBoxMaker", + "loc": { + "start": { + "line": 24, + "column": 6 + }, + "end": { + "line": 24, + "column": 20 + } + } + }, + "typeAnnotation": { + "type": "TSTypeQuery", + "exprName": { + "type": "TypeArgumentsExpression", + "leftHandExpression": { + "type": "Identifier", + "name": "makeBox", + "loc": { + "start": { + "line": 24, + "column": 30 + }, + "end": { + "line": 24, + "column": 37 + } + } + }, + "typeArguments": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "TSStringKeyword", + "loc": { + "start": { + "line": 24, + "column": 38 + }, + "end": { + "line": 24, + "column": 44 + } + } + } + ], + "loc": { + "start": { + "line": 24, + "column": 30 + }, + "end": { + "line": 24, + "column": 45 + } + } + }, + "loc": { + "start": { + "line": 24, + "column": 23 + }, + "end": { + "line": 24, + "column": 45 + } + } + }, + "loc": { + "start": { + "line": 24, + "column": 23 + }, + "end": { + "line": 24, + "column": 45 + } + } + }, + "loc": { + "start": { + "line": 24, + "column": 1 + }, + "end": { + "line": 24, + "column": 46 + } + } + }, + { + "type": "TSTypeAliasDeclaration", + "id": { + "type": "Identifier", + "name": "BoxFunc", + "loc": { + "start": { + "line": 25, + "column": 6 + }, + "end": { + "line": 25, + "column": 13 + } + } + }, + "typeAnnotation": { + "type": "TSTypeQuery", + "exprName": { + "type": "TypeArgumentsExpression", + "leftHandExpression": { + "type": "Identifier", + "name": "makeBox", + "loc": { + "start": { + "line": 25, + "column": 26 + }, + "end": { + "line": 25, + "column": 33 + } + } + }, + "typeArguments": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "TSTypeReference", + "typeName": { + "type": "Identifier", + "name": "T", + "loc": { + "start": { + "line": 25, + "column": 34 + }, + "end": { + "line": 25, + "column": 35 + } + } + }, + "loc": { + "start": { + "line": 25, + "column": 34 + }, + "end": { + "line": 25, + "column": 35 + } + } + } + ], + "loc": { + "start": { + "line": 25, + "column": 26 + }, + "end": { + "line": 25, + "column": 36 + } + } + }, + "loc": { + "start": { + "line": 25, + "column": 19 + }, + "end": { + "line": 25, + "column": 36 + } + } + }, + "loc": { + "start": { + "line": 25, + "column": 19 + }, + "end": { + "line": 25, + "column": 36 + } + } + }, + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "params": [ + { + "type": "TSTypeParameter", + "name": { + "type": "Identifier", + "name": "T", + "loc": { + "start": { + "line": 25, + "column": 14 + }, + "end": { + "line": 25, + "column": 15 + } + } + }, + "loc": { + "start": { + "line": 25, + "column": 14 + }, + "end": { + "line": 25, + "column": 16 + } + } + } + ], + "loc": { + "start": { + "line": 25, + "column": 13 + }, + "end": { + "line": 25, + "column": 16 + } + } + }, + "loc": { + "start": { + "line": 25, + "column": 1 + }, + "end": { + "line": 25, + "column": 37 + } + } + }, + { + "type": "TSTypeAliasDeclaration", + "id": { + "type": "Identifier", + "name": "Box", + "loc": { + "start": { + "line": 26, + "column": 6 + }, + "end": { + "line": 26, + "column": 9 + } + } + }, + "typeAnnotation": { + "type": "TSTypeReference", + "typeName": { + "type": "Identifier", + "name": "ReturnType", + "loc": { + "start": { + "line": 26, + "column": 15 + }, + "end": { + "line": 26, + "column": 25 + } + } + }, + "typeParameters": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "TSTypeQuery", + "exprName": { + "type": "TypeArgumentsExpression", + "leftHandExpression": { + "type": "Identifier", + "name": "makeBox", + "loc": { + "start": { + "line": 26, + "column": 33 + }, + "end": { + "line": 26, + "column": 40 + } + } + }, + "typeArguments": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "TSTypeReference", + "typeName": { + "type": "Identifier", + "name": "T", + "loc": { + "start": { + "line": 26, + "column": 41 + }, + "end": { + "line": 26, + "column": 42 + } + } + }, + "loc": { + "start": { + "line": 26, + "column": 41 + }, + "end": { + "line": 26, + "column": 42 + } + } + } + ], + "loc": { + "start": { + "line": 26, + "column": 33 + }, + "end": { + "line": 26, + "column": 44 + } + } + }, + "loc": { + "start": { + "line": 26, + "column": 26 + }, + "end": { + "line": 26, + "column": 44 + } + } + }, + "loc": { + "start": { + "line": 26, + "column": 26 + }, + "end": { + "line": 26, + "column": 44 + } + } + } + ], + "loc": { + "start": { + "line": 26, + "column": 15 + }, + "end": { + "line": 26, + "column": 44 + } + } + }, + "loc": { + "start": { + "line": 26, + "column": 15 + }, + "end": { + "line": 26, + "column": 25 + } + } + }, + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "params": [ + { + "type": "TSTypeParameter", + "name": { + "type": "Identifier", + "name": "T", + "loc": { + "start": { + "line": 26, + "column": 10 + }, + "end": { + "line": 26, + "column": 11 + } + } + }, + "loc": { + "start": { + "line": 26, + "column": 10 + }, + "end": { + "line": 26, + "column": 12 + } + } + } + ], + "loc": { + "start": { + "line": 26, + "column": 9 + }, + "end": { + "line": 26, + "column": 12 + } + } + }, + "loc": { + "start": { + "line": 26, + "column": 1 + }, + "end": { + "line": 26, + "column": 45 + } + } + }, + { + "type": "TSTypeAliasDeclaration", + "id": { + "type": "Identifier", + "name": "StringBox", + "loc": { + "start": { + "line": 27, + "column": 6 + }, + "end": { + "line": 27, + "column": 15 + } + } + }, + "typeAnnotation": { + "type": "TSTypeReference", + "typeName": { + "type": "Identifier", + "name": "Box", + "loc": { + "start": { + "line": 27, + "column": 18 + }, + "end": { + "line": 27, + "column": 21 + } + } + }, + "typeParameters": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "TSStringKeyword", + "loc": { + "start": { + "line": 27, + "column": 22 + }, + "end": { + "line": 27, + "column": 28 + } + } + } + ], + "loc": { + "start": { + "line": 27, + "column": 18 + }, + "end": { + "line": 27, + "column": 29 + } + } + }, + "loc": { + "start": { + "line": 27, + "column": 18 + }, + "end": { + "line": 27, + "column": 21 + } + } + }, + "loc": { + "start": { + "line": 27, + "column": 1 + }, + "end": { + "line": 27, + "column": 30 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 28, + "column": 1 + } + } +} diff --git a/es2panda/test/parser/ts/test_instantiation_expressions1.ts b/es2panda/test/parser/ts/test_instantiation_expressions1.ts new file mode 100644 index 0000000000000000000000000000000000000000..d8c0f06373b8f5708cf327d97e496d897654aa91 --- /dev/null +++ b/es2panda/test/parser/ts/test_instantiation_expressions1.ts @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2023 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. + */ + + +function makeBox(value: T) { + return { value }; +}; + +const makeStringBox = makeBox; // (value: string) => { value: string } +const stringBox = makeStringBox('abc'); // { value: string } + +type StringBoxMaker = typeof makeBox; // (value: string) => { value: string } +type BoxFunc = typeof makeBox; // (value: T) => { value: T } +type Box = ReturnType>; // { value: T } +type StringBox = Box; // { value: string } \ No newline at end of file diff --git a/es2panda/test/parser/ts/test_instantiation_expressions2-expected.txt b/es2panda/test/parser/ts/test_instantiation_expressions2-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..812b9eb60789d12ac28833f2c12414eb6b0e0f99 --- /dev/null +++ b/es2panda/test/parser/ts/test_instantiation_expressions2-expected.txt @@ -0,0 +1,333 @@ +{ + "type": "Program", + "statements": [ + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "ErrorMap", + "loc": { + "start": { + "line": 17, + "column": 7 + }, + "end": { + "line": 17, + "column": 15 + } + } + }, + "init": { + "type": "TypeArgumentsExpression", + "leftHandExpression": { + "type": "Identifier", + "name": "Map", + "loc": { + "start": { + "line": 17, + "column": 18 + }, + "end": { + "line": 17, + "column": 21 + } + } + }, + "typeArguments": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "TSStringKeyword", + "loc": { + "start": { + "line": 17, + "column": 22 + }, + "end": { + "line": 17, + "column": 28 + } + } + }, + { + "type": "TSTypeReference", + "typeName": { + "type": "Identifier", + "name": "Error", + "loc": { + "start": { + "line": 17, + "column": 30 + }, + "end": { + "line": 17, + "column": 35 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 30 + }, + "end": { + "line": 17, + "column": 35 + } + } + } + ], + "loc": { + "start": { + "line": 17, + "column": 21 + }, + "end": { + "line": 17, + "column": 36 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 18 + }, + "end": { + "line": 17, + "column": 36 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 7 + }, + "end": { + "line": 17, + "column": 36 + } + } + } + ], + "kind": "const", + "loc": { + "start": { + "line": 17, + "column": 1 + }, + "end": { + "line": 17, + "column": 37 + } + } + }, + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "errorMap", + "loc": { + "start": { + "line": 18, + "column": 7 + }, + "end": { + "line": 18, + "column": 15 + } + } + }, + "init": { + "type": "NewExpression", + "callee": { + "type": "Identifier", + "name": "ErrorMap", + "loc": { + "start": { + "line": 18, + "column": 22 + }, + "end": { + "line": 18, + "column": 30 + } + } + }, + "arguments": [], + "loc": { + "start": { + "line": 18, + "column": 18 + }, + "end": { + "line": 18, + "column": 32 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 7 + }, + "end": { + "line": 18, + "column": 32 + } + } + } + ], + "kind": "const", + "loc": { + "start": { + "line": 18, + "column": 1 + }, + "end": { + "line": 18, + "column": 33 + } + } + }, + { + "type": "TSTypeAliasDeclaration", + "id": { + "type": "Identifier", + "name": "ErrorMapConstructor", + "loc": { + "start": { + "line": 20, + "column": 6 + }, + "end": { + "line": 20, + "column": 25 + } + } + }, + "typeAnnotation": { + "type": "TSTypeQuery", + "exprName": { + "type": "TypeArgumentsExpression", + "leftHandExpression": { + "type": "Identifier", + "name": "Map", + "loc": { + "start": { + "line": 20, + "column": 35 + }, + "end": { + "line": 20, + "column": 38 + } + } + }, + "typeArguments": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "TSStringKeyword", + "loc": { + "start": { + "line": 20, + "column": 39 + }, + "end": { + "line": 20, + "column": 45 + } + } + }, + { + "type": "TSTypeReference", + "typeName": { + "type": "Identifier", + "name": "Error", + "loc": { + "start": { + "line": 20, + "column": 47 + }, + "end": { + "line": 20, + "column": 52 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 47 + }, + "end": { + "line": 20, + "column": 52 + } + } + } + ], + "loc": { + "start": { + "line": 20, + "column": 35 + }, + "end": { + "line": 20, + "column": 53 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 28 + }, + "end": { + "line": 20, + "column": 53 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 28 + }, + "end": { + "line": 20, + "column": 53 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 1 + }, + "end": { + "line": 20, + "column": 54 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 21, + "column": 1 + } + } +} diff --git a/es2panda/test/parser/ts/test_instantiation_expressions2.ts b/es2panda/test/parser/ts/test_instantiation_expressions2.ts new file mode 100644 index 0000000000000000000000000000000000000000..1fcafc7e2401e6eba21e3b0a22df1972ea2cbfdd --- /dev/null +++ b/es2panda/test/parser/ts/test_instantiation_expressions2.ts @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2023 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. + */ + + +const ErrorMap = Map; // new () => Map +const errorMap = new ErrorMap(); // Map + +type ErrorMapConstructor = typeof Map; // new () => Map \ No newline at end of file diff --git a/es2panda/test/parser/ts/test_instantiation_expressions3-expected.txt b/es2panda/test/parser/ts/test_instantiation_expressions3-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..b29e3e88f50cf3df5cd78d0c0bf3e22fe140e3a5 --- /dev/null +++ b/es2panda/test/parser/ts/test_instantiation_expressions3-expected.txt @@ -0,0 +1,806 @@ +{ + "type": "Program", + "statements": [ + { + "type": "FunctionDeclaration", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "A", + "loc": { + "start": { + "line": 17, + "column": 10 + }, + "end": { + "line": 17, + "column": 11 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [ + { + "type": "Identifier", + "name": "value", + "typeAnnotation": { + "type": "TSTypeReference", + "typeName": { + "type": "Identifier", + "name": "T", + "loc": { + "start": { + "line": 17, + "column": 22 + }, + "end": { + "line": 17, + "column": 23 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 22 + }, + "end": { + "line": 17, + "column": 23 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 15 + }, + "end": { + "line": 17, + "column": 20 + } + } + } + ], + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "params": [ + { + "type": "TSTypeParameter", + "name": { + "type": "Identifier", + "name": "T", + "loc": { + "start": { + "line": 17, + "column": 12 + }, + "end": { + "line": 17, + "column": 13 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 12 + }, + "end": { + "line": 17, + "column": 14 + } + } + } + ], + "loc": { + "start": { + "line": 17, + "column": 11 + }, + "end": { + "line": 17, + "column": 14 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ExpressionStatement", + "expression": { + "type": "CallExpression", + "callee": { + "type": "Identifier", + "name": "print", + "loc": { + "start": { + "line": 18, + "column": 5 + }, + "end": { + "line": 18, + "column": 10 + } + } + }, + "arguments": [ + { + "type": "Identifier", + "name": "value", + "loc": { + "start": { + "line": 18, + "column": 11 + }, + "end": { + "line": 18, + "column": 16 + } + } + } + ], + "optional": false, + "loc": { + "start": { + "line": 18, + "column": 5 + }, + "end": { + "line": 18, + "column": 17 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 5 + }, + "end": { + "line": 18, + "column": 17 + } + } + } + ], + "loc": { + "start": { + "line": 17, + "column": 25 + }, + "end": { + "line": 19, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 1 + }, + "end": { + "line": 19, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 1 + }, + "end": { + "line": 19, + "column": 2 + } + } + }, + { + "type": "ExpressionStatement", + "expression": { + "type": "LogicalExpression", + "operator": "&&", + "left": { + "type": "TypeArgumentsExpression", + "leftHandExpression": { + "type": "Identifier", + "name": "A", + "loc": { + "start": { + "line": 22, + "column": 1 + }, + "end": { + "line": 22, + "column": 2 + } + } + }, + "typeArguments": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "TSStringKeyword", + "loc": { + "start": { + "line": 22, + "column": 3 + }, + "end": { + "line": 22, + "column": 9 + } + } + } + ], + "loc": { + "start": { + "line": 22, + "column": 2 + }, + "end": { + "line": 22, + "column": 10 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 1 + }, + "end": { + "line": 22, + "column": 10 + } + } + }, + "right": { + "type": "TypeArgumentsExpression", + "leftHandExpression": { + "type": "Identifier", + "name": "A", + "loc": { + "start": { + "line": 22, + "column": 14 + }, + "end": { + "line": 22, + "column": 15 + } + } + }, + "typeArguments": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "TSNumberKeyword", + "loc": { + "start": { + "line": 22, + "column": 16 + }, + "end": { + "line": 22, + "column": 22 + } + } + } + ], + "loc": { + "start": { + "line": 22, + "column": 15 + }, + "end": { + "line": 22, + "column": 23 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 14 + }, + "end": { + "line": 22, + "column": 23 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 1 + }, + "end": { + "line": 22, + "column": 23 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 1 + }, + "end": { + "line": 22, + "column": 23 + } + } + }, + { + "type": "ExpressionStatement", + "expression": { + "type": "LogicalExpression", + "operator": "||", + "left": { + "type": "TypeArgumentsExpression", + "leftHandExpression": { + "type": "Identifier", + "name": "A", + "loc": { + "start": { + "line": 25, + "column": 1 + }, + "end": { + "line": 25, + "column": 2 + } + } + }, + "typeArguments": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "TSStringKeyword", + "loc": { + "start": { + "line": 25, + "column": 3 + }, + "end": { + "line": 25, + "column": 9 + } + } + } + ], + "loc": { + "start": { + "line": 25, + "column": 2 + }, + "end": { + "line": 25, + "column": 10 + } + } + }, + "loc": { + "start": { + "line": 25, + "column": 1 + }, + "end": { + "line": 25, + "column": 10 + } + } + }, + "right": { + "type": "TypeArgumentsExpression", + "leftHandExpression": { + "type": "Identifier", + "name": "A", + "loc": { + "start": { + "line": 25, + "column": 14 + }, + "end": { + "line": 25, + "column": 15 + } + } + }, + "typeArguments": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "TSNumberKeyword", + "loc": { + "start": { + "line": 25, + "column": 16 + }, + "end": { + "line": 25, + "column": 22 + } + } + } + ], + "loc": { + "start": { + "line": 25, + "column": 15 + }, + "end": { + "line": 25, + "column": 23 + } + } + }, + "loc": { + "start": { + "line": 25, + "column": 14 + }, + "end": { + "line": 25, + "column": 23 + } + } + }, + "loc": { + "start": { + "line": 25, + "column": 1 + }, + "end": { + "line": 25, + "column": 23 + } + } + }, + "loc": { + "start": { + "line": 25, + "column": 1 + }, + "end": { + "line": 25, + "column": 23 + } + } + }, + { + "type": "ExpressionStatement", + "expression": { + "type": "LogicalExpression", + "operator": "??", + "left": { + "type": "TypeArgumentsExpression", + "leftHandExpression": { + "type": "Identifier", + "name": "A", + "loc": { + "start": { + "line": 28, + "column": 1 + }, + "end": { + "line": 28, + "column": 2 + } + } + }, + "typeArguments": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "TSStringKeyword", + "loc": { + "start": { + "line": 28, + "column": 3 + }, + "end": { + "line": 28, + "column": 9 + } + } + } + ], + "loc": { + "start": { + "line": 28, + "column": 2 + }, + "end": { + "line": 28, + "column": 10 + } + } + }, + "loc": { + "start": { + "line": 28, + "column": 1 + }, + "end": { + "line": 28, + "column": 10 + } + } + }, + "right": { + "type": "TypeArgumentsExpression", + "leftHandExpression": { + "type": "Identifier", + "name": "A", + "loc": { + "start": { + "line": 28, + "column": 14 + }, + "end": { + "line": 28, + "column": 15 + } + } + }, + "typeArguments": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "TSNumberKeyword", + "loc": { + "start": { + "line": 28, + "column": 16 + }, + "end": { + "line": 28, + "column": 22 + } + } + } + ], + "loc": { + "start": { + "line": 28, + "column": 15 + }, + "end": { + "line": 28, + "column": 23 + } + } + }, + "loc": { + "start": { + "line": 28, + "column": 14 + }, + "end": { + "line": 28, + "column": 23 + } + } + }, + "loc": { + "start": { + "line": 28, + "column": 1 + }, + "end": { + "line": 28, + "column": 23 + } + } + }, + "loc": { + "start": { + "line": 28, + "column": 1 + }, + "end": { + "line": 28, + "column": 23 + } + } + }, + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "d", + "loc": { + "start": { + "line": 31, + "column": 5 + }, + "end": { + "line": 31, + "column": 6 + } + } + }, + "init": { + "type": "TypeArgumentsExpression", + "leftHandExpression": { + "type": "Identifier", + "name": "A", + "loc": { + "start": { + "line": 31, + "column": 9 + }, + "end": { + "line": 31, + "column": 10 + } + } + }, + "typeArguments": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "TSStringKeyword", + "loc": { + "start": { + "line": 31, + "column": 11 + }, + "end": { + "line": 31, + "column": 17 + } + } + } + ], + "loc": { + "start": { + "line": 31, + "column": 10 + }, + "end": { + "line": 31, + "column": 18 + } + } + }, + "loc": { + "start": { + "line": 31, + "column": 9 + }, + "end": { + "line": 31, + "column": 18 + } + } + }, + "loc": { + "start": { + "line": 31, + "column": 5 + }, + "end": { + "line": 31, + "column": 18 + } + } + }, + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "e", + "loc": { + "start": { + "line": 31, + "column": 20 + }, + "end": { + "line": 31, + "column": 21 + } + } + }, + "init": { + "type": "TypeArgumentsExpression", + "leftHandExpression": { + "type": "Identifier", + "name": "A", + "loc": { + "start": { + "line": 31, + "column": 24 + }, + "end": { + "line": 31, + "column": 25 + } + } + }, + "typeArguments": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "TSNumberKeyword", + "loc": { + "start": { + "line": 31, + "column": 26 + }, + "end": { + "line": 31, + "column": 32 + } + } + } + ], + "loc": { + "start": { + "line": 31, + "column": 25 + }, + "end": { + "line": 31, + "column": 33 + } + } + }, + "loc": { + "start": { + "line": 31, + "column": 24 + }, + "end": { + "line": 31, + "column": 33 + } + } + }, + "loc": { + "start": { + "line": 31, + "column": 20 + }, + "end": { + "line": 31, + "column": 33 + } + } + } + ], + "kind": "var", + "loc": { + "start": { + "line": 31, + "column": 1 + }, + "end": { + "line": 31, + "column": 33 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 31, + "column": 33 + } + } +} diff --git a/es2panda/test/parser/ts/test_instantiation_expressions3.ts b/es2panda/test/parser/ts/test_instantiation_expressions3.ts new file mode 100644 index 0000000000000000000000000000000000000000..46f5cd2023de1677d5113e0084484518b27c63a3 --- /dev/null +++ b/es2panda/test/parser/ts/test_instantiation_expressions3.ts @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2023 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. + */ + + +function A(value: T) { + print(value) +} + +// "&&" after "<***>" +A && A + +// "||" after "<***>" +A || A + +// "??" after "<***>" +A ?? A + +// "," after "<***>" +var d = A, e = A \ No newline at end of file diff --git a/es2panda/test/parser/ts/test_instantiation_expressions4-expected.txt b/es2panda/test/parser/ts/test_instantiation_expressions4-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..bf67950a4517921df9f37306f2c11c32946e2e55 --- /dev/null +++ b/es2panda/test/parser/ts/test_instantiation_expressions4-expected.txt @@ -0,0 +1 @@ +SyntaxError: Invalid left-hand side in assignment expression [test_instantiation_expressions4.ts:22:11] diff --git a/es2panda/test/parser/ts/test_instantiation_expressions4.ts b/es2panda/test/parser/ts/test_instantiation_expressions4.ts new file mode 100644 index 0000000000000000000000000000000000000000..c66ff906c1c82dfbc05e1fa909e0696572b2c176 --- /dev/null +++ b/es2panda/test/parser/ts/test_instantiation_expressions4.ts @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2023 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. + */ + + +function A(value: T) { + print(value) +} + +// "&&=" after "<***>" +A &&= A \ No newline at end of file diff --git a/es2panda/test/parser/ts/test_instantiation_expressions5-expected.txt b/es2panda/test/parser/ts/test_instantiation_expressions5-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..e1ea674986b0e7e462dbadf6f29d77a9ea8759bc --- /dev/null +++ b/es2panda/test/parser/ts/test_instantiation_expressions5-expected.txt @@ -0,0 +1 @@ +SyntaxError: Invalid left-hand side in assignment expression [test_instantiation_expressions5.ts:22:11] diff --git a/es2panda/test/parser/ts/test_instantiation_expressions5.ts b/es2panda/test/parser/ts/test_instantiation_expressions5.ts new file mode 100644 index 0000000000000000000000000000000000000000..652c47e02e50eff4255d39f537456be21168fe8a --- /dev/null +++ b/es2panda/test/parser/ts/test_instantiation_expressions5.ts @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2023 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. + */ + + +function A(value: T) { + print(value) +} + +// "||=" after "<***>" +A ||= A \ No newline at end of file diff --git a/es2panda/test/parser/ts/test_instantiation_expressions6-expected.txt b/es2panda/test/parser/ts/test_instantiation_expressions6-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..c008d35b9d3f2b3de51f8f461c1f623e9b84af46 --- /dev/null +++ b/es2panda/test/parser/ts/test_instantiation_expressions6-expected.txt @@ -0,0 +1 @@ +SyntaxError: Invalid left-hand side in assignment expression [test_instantiation_expressions6.ts:22:11] diff --git a/es2panda/test/parser/ts/test_instantiation_expressions6.ts b/es2panda/test/parser/ts/test_instantiation_expressions6.ts new file mode 100644 index 0000000000000000000000000000000000000000..c04ddf8965b4a02803a30082e956c4df32b72026 --- /dev/null +++ b/es2panda/test/parser/ts/test_instantiation_expressions6.ts @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2023 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. + */ + + +function A(value: T) { + print(value) +} + +// "=" after "<***>" +A = A \ No newline at end of file