From 812b381f9cad7ad7426dffb795813d5cdb234b01 Mon Sep 17 00:00:00 2001 From: xucheng46 Date: Tue, 19 Jul 2022 17:41:04 +0800 Subject: [PATCH] Enable symbol and some other ts features in es2abc parser 1. Enable symbol and unique symbol type 2. Enable optional members, rest elements and variadic tuple in tuple type 3. Fix the issue in enum with shifting on enum members 4. Enalbe key remapping via as Issue: https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/I5JXH3 Test: test262, parser tests, compiler tests Signed-off-by: xucheng46 Change-Id: I57d28402151ac40fce7dbe23f0e9782b76eb1e6f --- es2panda/BUILD.gn | 4 + es2panda/CMakeLists.txt | 4 + es2panda/ir/astNodeMapping.h | 3 + es2panda/ir/ts/tsMappedType.cpp | 1 + es2panda/ir/ts/tsMappedType.h | 6 +- es2panda/ir/ts/tsNamedTupleMember.cpp | 3 +- es2panda/ir/ts/tsNamedTupleMember.h | 11 +- es2panda/ir/ts/tsOptionalType.cpp | 53 + es2panda/ir/ts/tsOptionalType.h | 40 + es2panda/ir/ts/tsRestType.cpp | 53 + es2panda/ir/ts/tsRestType.h | 40 + es2panda/ir/ts/tsSymbolKeyword.cpp | 43 + es2panda/ir/ts/tsSymbolKeyword.h | 37 + es2panda/lexer/scripts/keywords.rb | 2 + es2panda/lexer/token/tokenType.h | 2 + es2panda/parser/expressionParser.cpp | 12 +- es2panda/parser/parserImpl.cpp | 131 +- es2panda/parser/parserImpl.h | 1 + .../ts/test-enum-declaration6-expected.txt | 374 ++++ .../test/parser/ts/test-enum-declaration6.ts | 23 + .../parser/ts/test-func-param-expected.txt | 12 +- .../test-ts-key-remapping-via-as-expected.txt | 900 +++++++++ .../parser/ts/test-ts-key-remapping-via-as.ts | 23 + .../ts/test-ts-symbol-type-expected.txt | 268 +++ .../test/parser/ts/test-ts-symbol-type.ts | 21 + .../test-ts-unique-symbol-type-expected.txt | 363 ++++ .../parser/ts/test-ts-unique-symbol-type.ts | 21 + .../parser/ts/test-tuple-type-expected.txt | 42 +- .../parser/ts/test-tuple-type2-expected.txt | 2 +- .../parser/ts/test-tuple-type5-expected.txt | 1691 +++++++++++++++++ es2panda/test/parser/ts/test-tuple-type5.ts | 32 + .../test/parser/ts/test_generic-expected.txt | 46 +- .../parser/ts/test_import_type-expected.txt | 4 +- .../parser/ts/test_this_type-expected.txt | 4 +- .../arrayDestructuring-expected.txt | 40 +- .../arrayDestructuring12-expected.txt | 6 +- .../arrayDestructuring13-expected.txt | 6 +- .../arrayDestructuring15-expected.txt | 2 +- .../arrayDestructuring16-expected.txt | 2 +- .../arrayDestructuring17-expected.txt | 4 +- .../arrayDestructuring18-expected.txt | 10 +- .../arrayDestructuring19-expected.txt | 10 +- .../arrayDestructuring27-expected.txt | 4 +- .../arrayDestructuring4-expected.txt | 4 +- .../arrayDestructuring5-expected.txt | 4 +- .../arrayDestructuring6-expected.txt | 4 +- .../functionOverload2-expected.txt | 16 +- .../interfaceAssignment-expected.txt | 4 +- .../interfaceAssignment3-expected.txt | 4 +- .../type_checker/memberExpTests-expected.txt | 6 +- .../objectDestructuring23-expected.txt | 4 +- .../objectDestructuring24-expected.txt | 4 +- .../objectDestructuring25-expected.txt | 4 +- .../objectLiteralAssignability-expected.txt | 6 +- .../test-type-literal-expected.txt | 2 +- .../tupleAssignability-expected.txt | 156 +- .../tupleAssignability10-expected.txt | 4 +- .../tupleAssignability11-expected.txt | 2 +- .../tupleAssignability12-expected.txt | 14 +- .../tupleAssignability13-expected.txt | 6 +- .../tupleAssignability15-expected.txt | 6 +- .../tupleAssignability16-expected.txt | 4 +- .../tupleAssignability17-expected.txt | 10 +- .../tupleAssignability18-expected.txt | 20 +- .../tupleAssignability19-expected.txt | 4 +- .../tupleAssignability2-expected.txt | 4 +- .../tupleAssignability20-expected.txt | 4 +- .../tupleAssignability21-expected.txt | 10 +- .../tupleAssignability22-expected.txt | 4 +- .../tupleAssignability23-expected.txt | 12 +- .../tupleAssignability24-expected.txt | 14 +- .../tupleAssignability3-expected.txt | 6 +- .../tupleAssignability4-expected.txt | 8 +- .../tupleAssignability5-expected.txt | 4 +- .../tupleAssignability6-expected.txt | 12 +- .../tupleAssignability7-expected.txt | 12 +- .../tupleAssignability8-expected.txt | 10 +- .../tupleAssignability9-expected.txt | 8 +- .../typeAliasUsedAsValue-expected.txt | 6 +- .../varRedeclaration-expected.txt | 24 +- .../varRedeclaration6-expected.txt | 12 +- es2panda/typescript/checker.h | 5 + .../typescript/types/globalTypesHolder.cpp | 9 +- es2panda/typescript/types/globalTypesHolder.h | 2 + es2panda/typescript/types/symbolType.cpp | 50 + es2panda/typescript/types/symbolType.h | 36 + es2panda/typescript/types/typeFacts.h | 7 + es2panda/typescript/types/typeMapping.h | 1 + es2panda/typescript/types/types.h | 1 + 89 files changed, 4545 insertions(+), 360 deletions(-) create mode 100644 es2panda/ir/ts/tsOptionalType.cpp create mode 100644 es2panda/ir/ts/tsOptionalType.h create mode 100644 es2panda/ir/ts/tsRestType.cpp create mode 100644 es2panda/ir/ts/tsRestType.h create mode 100644 es2panda/ir/ts/tsSymbolKeyword.cpp create mode 100644 es2panda/ir/ts/tsSymbolKeyword.h create mode 100644 es2panda/test/parser/ts/test-enum-declaration6-expected.txt create mode 100644 es2panda/test/parser/ts/test-enum-declaration6.ts create mode 100644 es2panda/test/parser/ts/test-ts-key-remapping-via-as-expected.txt create mode 100644 es2panda/test/parser/ts/test-ts-key-remapping-via-as.ts create mode 100644 es2panda/test/parser/ts/test-ts-symbol-type-expected.txt create mode 100644 es2panda/test/parser/ts/test-ts-symbol-type.ts create mode 100644 es2panda/test/parser/ts/test-ts-unique-symbol-type-expected.txt create mode 100644 es2panda/test/parser/ts/test-ts-unique-symbol-type.ts create mode 100644 es2panda/test/parser/ts/test-tuple-type5-expected.txt create mode 100644 es2panda/test/parser/ts/test-tuple-type5.ts create mode 100644 es2panda/typescript/types/symbolType.cpp create mode 100644 es2panda/typescript/types/symbolType.h diff --git a/es2panda/BUILD.gn b/es2panda/BUILD.gn index 17dff9d9cd..847457188e 100644 --- a/es2panda/BUILD.gn +++ b/es2panda/BUILD.gn @@ -157,13 +157,16 @@ es2panda_src = [ "ir/ts/tsNullKeyword.cpp", "ir/ts/tsNumberKeyword.cpp", "ir/ts/tsObjectKeyword.cpp", + "ir/ts/tsOptionalType.cpp", "ir/ts/tsParameterProperty.cpp", "ir/ts/tsParenthesizedType.cpp", "ir/ts/tsPrivateIdentifier.cpp", "ir/ts/tsPropertySignature.cpp", "ir/ts/tsQualifiedName.cpp", + "ir/ts/tsRestType.cpp", "ir/ts/tsSignatureDeclaration.cpp", "ir/ts/tsStringKeyword.cpp", + "ir/ts/tsSymbolKeyword.cpp", "ir/ts/tsTemplateLiteralType.cpp", "ir/ts/tsThisType.cpp", "ir/ts/tsTupleType.cpp", @@ -227,6 +230,7 @@ es2panda_src = [ "typescript/types/signature.cpp", "typescript/types/stringLiteralType.cpp", "typescript/types/stringType.cpp", + "typescript/types/symbolType.cpp", "typescript/types/tupleType.cpp", "typescript/types/type.cpp", "typescript/types/typeParameter.cpp", diff --git a/es2panda/CMakeLists.txt b/es2panda/CMakeLists.txt index 9a213084ed..80e619467f 100644 --- a/es2panda/CMakeLists.txt +++ b/es2panda/CMakeLists.txt @@ -206,13 +206,16 @@ set(ES2PANDA_LIB_SRC ir/ts/tsNullKeyword.cpp ir/ts/tsNumberKeyword.cpp ir/ts/tsObjectKeyword.cpp + ir/ts/tsOptionalType.cpp ir/ts/tsParameterProperty.cpp ir/ts/tsParenthesizedType.cpp ir/ts/tsPrivateIdentifier.cpp ir/ts/tsPropertySignature.cpp ir/ts/tsQualifiedName.cpp + ir/ts/tsRestType.cpp ir/ts/tsSignatureDeclaration.cpp ir/ts/tsStringKeyword.cpp + ir/ts/tsSymbolKeyword.cpp ir/ts/tsTemplateLiteralType.cpp ir/ts/tsThisType.cpp ir/ts/tsTupleType.cpp @@ -274,6 +277,7 @@ set(ES2PANDA_LIB_SRC typescript/types/signature.cpp typescript/types/stringLiteralType.cpp typescript/types/stringType.cpp + typescript/types/symbolType.cpp typescript/types/tupleType.cpp typescript/types/type.cpp typescript/types/typeParameter.cpp diff --git a/es2panda/ir/astNodeMapping.h b/es2panda/ir/astNodeMapping.h index 33c87d44a7..aa260c1c87 100644 --- a/es2panda/ir/astNodeMapping.h +++ b/es2panda/ir/astNodeMapping.h @@ -78,6 +78,7 @@ _(TS_NUMBER_KEYWORD, TSNumberKeyword) \ _(TS_ANY_KEYWORD, TSAnyKeyword) \ _(TS_STRING_KEYWORD, TSStringKeyword) \ + _(TS_SYMBOL_KEYWORD, TSSymbolKeyword) \ _(TS_BOOLEAN_KEYWORD, TSBooleanKeyword) \ _(TS_VOID_KEYWORD, TSVoidKeyword) \ _(TS_UNDEFINED_KEYWORD, TSUndefinedKeyword) \ @@ -87,6 +88,8 @@ _(TS_NEVER_KEYWORD, TSNeverKeyword) \ _(TS_NON_NULL_EXPRESSION, TSNonNullExpression) \ _(TS_NULL_KEYWORD, TSNullKeyword) \ + _(TS_OPTIONAL_TYPE, TSOptionalType) \ + _(TS_REST_TYPE, TSRestType) \ _(TS_ARRAY_TYPE, TSArrayType) \ _(TS_UNION_TYPE, TSUnionType) \ _(TS_TYPE_LITERAL, TSTypeLiteral) \ diff --git a/es2panda/ir/ts/tsMappedType.cpp b/es2panda/ir/ts/tsMappedType.cpp index 4d2a57b135..37178340cf 100644 --- a/es2panda/ir/ts/tsMappedType.cpp +++ b/es2panda/ir/ts/tsMappedType.cpp @@ -33,6 +33,7 @@ void TSMappedType::Dump(ir::AstDumper *dumper) const dumper->Add( {{"type", "TSMappedType"}, {"typeParameter", typeParameter_}, + {"nameKeyType", AstDumper::Optional(nameKeyType_)}, {"typeAnnotation", AstDumper::Optional(typeAnnotation_)}, {"readonly", readonly_ == MappedOption::NO_OPTS ? AstDumper::Optional(false) diff --git a/es2panda/ir/ts/tsMappedType.h b/es2panda/ir/ts/tsMappedType.h index 6e24cb4d3c..f7d32a4574 100644 --- a/es2panda/ir/ts/tsMappedType.h +++ b/es2panda/ir/ts/tsMappedType.h @@ -32,10 +32,11 @@ namespace panda::es2panda::ir { class TSMappedType : public TypeNode { public: - explicit TSMappedType(TSTypeParameter *typeParameter, Expression *typeAnnotation, MappedOption readonly, - MappedOption optional) + explicit TSMappedType(TSTypeParameter *typeParameter, Expression *nameKeyType, Expression *typeAnnotation, + MappedOption readonly, MappedOption optional) : TypeNode(AstNodeType::TS_MAPPED_TYPE), typeParameter_(typeParameter), + nameKeyType_(nameKeyType), typeAnnotation_(typeAnnotation), readonly_(readonly), optional_(optional) @@ -70,6 +71,7 @@ public: private: TSTypeParameter *typeParameter_; + Expression *nameKeyType_; Expression *typeAnnotation_; MappedOption readonly_; MappedOption optional_; diff --git a/es2panda/ir/ts/tsNamedTupleMember.cpp b/es2panda/ir/ts/tsNamedTupleMember.cpp index 1d70a26cac..5c76fbeef4 100644 --- a/es2panda/ir/ts/tsNamedTupleMember.cpp +++ b/es2panda/ir/ts/tsNamedTupleMember.cpp @@ -30,7 +30,8 @@ void TSNamedTupleMember::Dump(ir::AstDumper *dumper) const dumper->Add({{"type", "TSNamedTupleMember"}, {"elementType", elementType_}, {"label", label_}, - {"optional", AstDumper::Optional(optional_)}}); + {"optional", AstDumper::Optional(optional_)}, + {"rest", AstDumper::Optional(rest_)}}); } void TSNamedTupleMember::Compile([[maybe_unused]] compiler::PandaGen *pg) const {} diff --git a/es2panda/ir/ts/tsNamedTupleMember.h b/es2panda/ir/ts/tsNamedTupleMember.h index b4c5703031..135d4ed889 100644 --- a/es2panda/ir/ts/tsNamedTupleMember.h +++ b/es2panda/ir/ts/tsNamedTupleMember.h @@ -31,11 +31,12 @@ namespace panda::es2panda::ir { class TSNamedTupleMember : public Expression { public: - explicit TSNamedTupleMember(Expression *label, Expression *elementType, bool optional) + explicit TSNamedTupleMember(Expression *label, Expression *elementType, bool optional, bool rest) : Expression(AstNodeType::TS_NAMED_TUPLE_MEMBER), label_(label), elementType_(elementType), - optional_(optional) + optional_(optional), + rest_(rest) { } @@ -54,6 +55,11 @@ public: return optional_; } + bool IsRest() const + { + return rest_; + } + void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; @@ -63,6 +69,7 @@ private: Expression *label_; Expression *elementType_; bool optional_; + bool rest_; }; } // namespace panda::es2panda::ir diff --git a/es2panda/ir/ts/tsOptionalType.cpp b/es2panda/ir/ts/tsOptionalType.cpp new file mode 100644 index 0000000000..297e6641ed --- /dev/null +++ b/es2panda/ir/ts/tsOptionalType.cpp @@ -0,0 +1,53 @@ +/* + * 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. + */ + +#include "tsOptionalType.h" + +#include +#include + +namespace panda::es2panda::ir { + +void TSOptionalType::Iterate(const NodeTraverser &cb) const +{ + cb(type_); +} + +void TSOptionalType::Dump(ir::AstDumper *dumper) const +{ + dumper->Add({{"type", "TSOptionalType"}, {"typeAnnotation", type_}}); +} + +void TSOptionalType::Compile([[maybe_unused]] compiler::PandaGen *pg) const {} + +checker::Type *TSOptionalType::Check([[maybe_unused]] checker::Checker *checker) const +{ + // TODO(xucheng): Implement checker for ts optional type + return nullptr; +} + +checker::Type *TSOptionalType::GetType(checker::Checker *checker) const +{ + auto found = checker->NodeCache().find(this); + if (found != checker->NodeCache().end()) { + return found->second; + } + + checker::Type *type = type_->AsTypeNode()->GetType(checker); + checker->NodeCache().insert({this, type}); + return type; +} + +} // namespace panda::es2panda::ir diff --git a/es2panda/ir/ts/tsOptionalType.h b/es2panda/ir/ts/tsOptionalType.h new file mode 100644 index 0000000000..3d9af242b0 --- /dev/null +++ b/es2panda/ir/ts/tsOptionalType.h @@ -0,0 +1,40 @@ +/* + * 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. + */ + +#ifndef ES2PANDA_IR_TS_TSOPTIONAL_TYPE_H +#define ES2PANDA_IR_TS_TSOPTIONAL_TYPE_H + +#include +#include +#include + +namespace panda::es2panda::ir { + +class TSOptionalType : public TypeNode { +public: + explicit TSOptionalType(Expression *type) : TypeNode(AstNodeType::TS_OPTIONAL_TYPE), type_(type) {} + + void Iterate(const NodeTraverser &cb) const override; + void Dump(ir::AstDumper *dumper) const override; + void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; + checker::Type *Check([[maybe_unused]] checker::Checker *checker) const override; + checker::Type *GetType(checker::Checker *checker) const override; + +private: + Expression *type_; +}; +} // namespace panda::es2panda::ir + +#endif diff --git a/es2panda/ir/ts/tsRestType.cpp b/es2panda/ir/ts/tsRestType.cpp new file mode 100644 index 0000000000..a3ec1e049c --- /dev/null +++ b/es2panda/ir/ts/tsRestType.cpp @@ -0,0 +1,53 @@ +/* + * 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. + */ + +#include "tsRestType.h" + +#include +#include + +namespace panda::es2panda::ir { + +void TSRestType::Iterate(const NodeTraverser &cb) const +{ + cb(type_); +} + +void TSRestType::Dump(ir::AstDumper *dumper) const +{ + dumper->Add({{"type", "TSRestType"}, {"typeAnnotation", type_}}); +} + +void TSRestType::Compile([[maybe_unused]] compiler::PandaGen *pg) const {} + +checker::Type *TSRestType::Check([[maybe_unused]] checker::Checker *checker) const +{ + // TODO(xucheng): Implement checker for ts rest type + return nullptr; +} + +checker::Type *TSRestType::GetType(checker::Checker *checker) const +{ + auto found = checker->NodeCache().find(this); + if (found != checker->NodeCache().end()) { + return found->second; + } + + checker::Type *type = type_->AsTypeNode()->GetType(checker); + checker->NodeCache().insert({this, type}); + return type; +} + +} // namespace panda::es2panda::ir diff --git a/es2panda/ir/ts/tsRestType.h b/es2panda/ir/ts/tsRestType.h new file mode 100644 index 0000000000..419333842f --- /dev/null +++ b/es2panda/ir/ts/tsRestType.h @@ -0,0 +1,40 @@ +/* + * 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. + */ + +#ifndef ES2PANDA_IR_TS_TSREST_TYPE_H +#define ES2PANDA_IR_TS_TSREST_TYPE_H + +#include +#include +#include + +namespace panda::es2panda::ir { + +class TSRestType : public TypeNode { +public: + explicit TSRestType(Expression *type) : TypeNode(AstNodeType::TS_REST_TYPE), type_(type) {} + + void Iterate(const NodeTraverser &cb) const override; + void Dump(ir::AstDumper *dumper) const override; + void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; + checker::Type *Check([[maybe_unused]] checker::Checker *checker) const override; + checker::Type *GetType(checker::Checker *checker) const override; + +private: + Expression *type_; +}; +} // namespace panda::es2panda::ir + +#endif diff --git a/es2panda/ir/ts/tsSymbolKeyword.cpp b/es2panda/ir/ts/tsSymbolKeyword.cpp new file mode 100644 index 0000000000..7234176e4f --- /dev/null +++ b/es2panda/ir/ts/tsSymbolKeyword.cpp @@ -0,0 +1,43 @@ +/* + * 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. + */ + +#include "tsSymbolKeyword.h" + +#include +#include + +namespace panda::es2panda::ir { + +void TSSymbolKeyword::Iterate([[maybe_unused]] const NodeTraverser &cb) const {} + +void TSSymbolKeyword::Dump(ir::AstDumper *dumper) const +{ + dumper->Add({{"type", "TSSymbolKeyword"}}); +} + +void TSSymbolKeyword::Compile([[maybe_unused]] compiler::PandaGen *pg) const {} + +checker::Type *TSSymbolKeyword::Check([[maybe_unused]] checker::Checker *checker) const +{ + // TODO(xucheng): Implement checker for ts symbol keyword + return nullptr; +} + +checker::Type *TSSymbolKeyword::GetType(checker::Checker *checker) const +{ + return checker->GlobalSymbolType(); +} + +} // namespace panda::es2panda::ir diff --git a/es2panda/ir/ts/tsSymbolKeyword.h b/es2panda/ir/ts/tsSymbolKeyword.h new file mode 100644 index 0000000000..27e20304e8 --- /dev/null +++ b/es2panda/ir/ts/tsSymbolKeyword.h @@ -0,0 +1,37 @@ +/* + * 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. + */ + +#ifndef ES2PANDA_IR_TS_TSSYMBOL_KEYWORD_H +#define ES2PANDA_IR_TS_TSSYMBOL_KEYWORD_H + +#include +#include +#include + +namespace panda::es2panda::ir { + +class TSSymbolKeyword : public TypeNode { +public: + explicit TSSymbolKeyword() : TypeNode(AstNodeType::TS_SYMBOL_KEYWORD) {} + + void Iterate(const NodeTraverser &cb) const override; + void Dump(ir::AstDumper *dumper) const override; + void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; + checker::Type *Check([[maybe_unused]] checker::Checker *checker) const override; + checker::Type *GetType(checker::Checker *checker) const override; +}; +} // namespace panda::es2panda::ir + +#endif diff --git a/es2panda/lexer/scripts/keywords.rb b/es2panda/lexer/scripts/keywords.rb index d3ae98705f..00183eca59 100644 --- a/es2panda/lexer/scripts/keywords.rb +++ b/es2panda/lexer/scripts/keywords.rb @@ -142,6 +142,7 @@ keywords = [ "string" => ["TokenType::LITERAL_IDENT", "TokenType::KEYW_STRING"], "super" => ["TokenType::KEYW_SUPER", "TokenType::KEYW_SUPER"], "switch" => ["TokenType::KEYW_SWITCH", "TokenType::KEYW_SWITCH"], + "symbol" => ["TokenType::LITERAL_IDENT", "TokenType::KEYW_SYMBOL"], }, # keywords start with 't' @@ -157,6 +158,7 @@ keywords = [ # keywords start with 'u' { "undefined" => ["TokenType::LITERAL_IDENT", "TokenType::KEYW_UNDEFINED"], + "unique" => ["TokenType::LITERAL_IDENT", "TokenType::KEYW_UNIQUE"], "unknown" => ["TokenType::LITERAL_IDENT", "TokenType::KEYW_UNKNOWN"], }, diff --git a/es2panda/lexer/token/tokenType.h b/es2panda/lexer/token/tokenType.h index 48f53a5099..29ddcfe28d 100644 --- a/es2panda/lexer/token/tokenType.h +++ b/es2panda/lexer/token/tokenType.h @@ -140,6 +140,7 @@ enum class TokenType { KEYW_STRING, KEYW_SUPER, KEYW_SWITCH, + KEYW_SYMBOL, KEYW_THIS, KEYW_THROW, KEYW_TYPE, @@ -155,6 +156,7 @@ enum class TokenType { KEYW_ASYNC, KEYW_READONLY, KEYW_KEYOF, + KEYW_UNIQUE, KEYW_MODULE, KEYW_NAMESPACE, KEYW_INFER, diff --git a/es2panda/parser/expressionParser.cpp b/es2panda/parser/expressionParser.cpp index e66239d189..e0d85967de 100644 --- a/es2panda/parser/expressionParser.cpp +++ b/es2panda/parser/expressionParser.cpp @@ -1457,11 +1457,21 @@ bool ParserImpl::ParsePotentialTsGenericFunctionCall(ir::Expression **returnExpr const auto savedPos = lexer_->Save(); + bool isLeftShift = false; if (lexer_->GetToken().Type() == lexer::TokenType::PUNCTUATOR_LEFT_SHIFT) { lexer_->BackwardToken(lexer::TokenType::PUNCTUATOR_LESS_THAN, 1); + isLeftShift = true; } - ir::TSTypeParameterInstantiation *typeParams = ParseTsTypeParameterInstantiation(false); + ir::TSTypeParameterInstantiation *typeParams; + try { + typeParams = ParseTsTypeParameterInstantiation(false); + } catch (const Error &e) { + if (!isLeftShift) { + throw e; + } + typeParams = nullptr; + } if (!typeParams) { lexer_->Rewind(savedPos); diff --git a/es2panda/parser/parserImpl.cpp b/es2panda/parser/parserImpl.cpp index d3039e2a13..b94cd55f1b 100644 --- a/es2panda/parser/parserImpl.cpp +++ b/es2panda/parser/parserImpl.cpp @@ -70,13 +70,16 @@ #include #include #include +#include #include #include #include #include #include +#include #include #include +#include #include #include #include @@ -189,6 +192,7 @@ bool ParserImpl::CurrentLiteralIsBasicType() case lexer::TokenType::KEYW_BOOLEAN: case lexer::TokenType::KEYW_NUMBER: case lexer::TokenType::KEYW_STRING: + case lexer::TokenType::KEYW_SYMBOL: case lexer::TokenType::KEYW_UNKNOWN: case lexer::TokenType::KEYW_UNDEFINED: case lexer::TokenType::KEYW_NEVER: @@ -716,6 +720,7 @@ ir::Expression *ParserImpl::ParseTsTypeOperatorOrTypeReference() options |= TypeAnnotationParsingOptions::IN_MODIFIER; ir::Expression *type = ParseTsTypeAnnotation(&options); + ASSERT(type != nullptr); if (!type->IsTSArrayType() && !type->IsTSTupleType()) { ThrowSyntaxError( @@ -736,6 +741,7 @@ ir::Expression *ParserImpl::ParseTsTypeOperatorOrTypeReference() options |= TypeAnnotationParsingOptions::IN_MODIFIER; ir::Expression *type = ParseTsTypeAnnotation(&options); + ASSERT(type != nullptr); auto *typeOperator = AllocNode(type, ir::TSOperatorType::KEYOF); @@ -744,6 +750,20 @@ ir::Expression *ParserImpl::ParseTsTypeOperatorOrTypeReference() return typeOperator; } + if (lexer_->GetToken().KeywordType() == lexer::TokenType::KEYW_UNIQUE) { + lexer::SourcePosition typeOperatorStart = lexer_->GetToken().Start(); + lexer_->NextToken(); + + ir::Expression *type = ParseTsTypeAnnotation(&options); + ASSERT(type != nullptr); + + auto *typeOperator = AllocNode(type, ir::TSOperatorType::UNIQUE); + + typeOperator->SetRange({typeOperatorStart, type->End()}); + + return typeOperator; + } + if (lexer_->GetToken().KeywordType() == lexer::TokenType::KEYW_INFER) { if (!(context_.Status() & ParserStatus::IN_EXTENDS)) { ThrowSyntaxError( @@ -766,59 +786,84 @@ ir::Expression *ParserImpl::ParseTsTypeOperatorOrTypeReference() return ParseTsIdentifierReference(); } +bool ParserImpl::IsTSNamedTupleMember() +{ + if (lexer_->GetToken().Type() != lexer::TokenType::LITERAL_IDENT) { + return false; + } + const auto savePos = lexer_->Save(); + bool isNamedMember = false; + lexer_->NextToken(); + if (lexer_->GetToken().Type() == lexer::TokenType::PUNCTUATOR_COLON || + (lexer_->GetToken().Type() == lexer::TokenType::PUNCTUATOR_QUESTION_MARK && + lexer_->Lookahead() == LEX_CHAR_COLON)) { + isNamedMember = true; + } + lexer_->Rewind(savePos); + return isNamedMember; +} + ir::Expression *ParserImpl::ParseTsTupleElement(ir::TSTupleKind *kind, bool *seenOptional) { - lexer::SourcePosition elementStart = lexer_->GetToken().Start(); + lexer::SourcePosition startPos = lexer_->GetToken().Start(); ir::Expression *element = nullptr; bool isOptional = false; + bool isRestType = false; TypeAnnotationParsingOptions options = TypeAnnotationParsingOptions::THROW_ERROR; - if (lexer_->GetToken().Type() == lexer::TokenType::LITERAL_IDENT && !CurrentLiteralIsBasicType()) { - auto *elementIdent = AllocNode(lexer_->GetToken().Ident(), Allocator()); - elementIdent->SetRange(lexer_->GetToken().Loc()); + if (lexer_->GetToken().Type() == lexer::TokenType::PUNCTUATOR_PERIOD_PERIOD_PERIOD) { + isRestType = true; + lexer_->NextToken(); // eat '...' + } - if (lexer_->Lookahead() == LEX_CHAR_COLON || lexer_->Lookahead() == LEX_CHAR_QUESTION) { - if (*kind == ir::TSTupleKind::DEFAULT) { - ThrowSyntaxError("Tuple members must all have names or all not have names"); - } + if (IsTSNamedTupleMember()) { + if (*kind == ir::TSTupleKind::DEFAULT) { + ThrowSyntaxError("Tuple members must all have or haven't names"); + } + *kind = ir::TSTupleKind::NAMED; - lexer_->NextToken(); // eat ident + auto *elementIdent = AllocNode(lexer_->GetToken().Ident(), Allocator()); + elementIdent->SetRange(lexer_->GetToken().Loc()); + lexer_->NextToken(); // eat identifier - if (lexer_->GetToken().Type() == lexer::TokenType::PUNCTUATOR_QUESTION_MARK) { - lexer_->NextToken(); // eat '?' - isOptional = true; - *seenOptional = true; - } else if (*seenOptional) { - ThrowSyntaxError("A required element cannot follow an optional element"); - } + if (lexer_->GetToken().Type() == lexer::TokenType::PUNCTUATOR_QUESTION_MARK) { + lexer_->NextToken(); // eat '?' + isOptional = true; + *seenOptional = true; + } else if (*seenOptional) { + ThrowSyntaxError("A required element cannot follow an optional element"); + } - if (lexer_->GetToken().Type() != lexer::TokenType::PUNCTUATOR_COLON) { - ThrowSyntaxError("':' expected"); - } + if (lexer_->GetToken().Type() != lexer::TokenType::PUNCTUATOR_COLON) { + ThrowSyntaxError("':' expected"); + } - lexer_->NextToken(); // eat ':' - auto *elementType = ParseTsTypeAnnotation(&options); - *kind = ir::TSTupleKind::NAMED; + lexer_->NextToken(); // eat ':' + auto *elementType = ParseTsTypeAnnotation(&options); + ASSERT(elementType != nullptr); - element = AllocNode(elementIdent, elementType, isOptional); - } else { - element = ParseTsTypeReferenceOrQuery(); - } - if (lexer_->GetToken().Type() != lexer::TokenType::PUNCTUATOR_COMMA && - lexer_->GetToken().Type() != lexer::TokenType::PUNCTUATOR_RIGHT_SQUARE_BRACKET) { - element = ParseTsTypeAnnotationElement(element, &options); - } + element = AllocNode(elementIdent, elementType, isOptional, isRestType); + element->SetRange({startPos, elementType->End()}); } else { if (*kind == ir::TSTupleKind::NAMED) { - ThrowSyntaxError("Tuple members must all have names or all not have names"); + ThrowSyntaxError("Tuple members must all have or haven't names"); } - *kind = ir::TSTupleKind::DEFAULT; + element = ParseTsTypeAnnotation(&options); - } + ASSERT(element != nullptr); + if (element && isRestType) { + lexer::SourcePosition endPos = element->End(); + element = AllocNode(std::move(element)); + element->SetRange({startPos, endPos}); + } - if (element) { - element->SetRange({elementStart, lexer_->GetToken().End()}); + if (lexer_->GetToken().Type() == lexer::TokenType::PUNCTUATOR_QUESTION_MARK) { + lexer::SourcePosition elementStartPos = element->Start(); + element = AllocNode(std::move(element)); + element->SetRange({elementStartPos, lexer_->GetToken().End()}); + lexer_->NextToken(); // eat '?' + } } return element; } @@ -835,6 +880,7 @@ ir::TSTupleType *ParserImpl::ParseTsTupleType() while (lexer_->GetToken().Type() != lexer::TokenType::PUNCTUATOR_RIGHT_SQUARE_BRACKET) { ir::Expression *element = ParseTsTupleElement(&kind, &seenOptional); + elements.push_back(element); if (lexer_->GetToken().Type() == lexer::TokenType::PUNCTUATOR_RIGHT_SQUARE_BRACKET) { @@ -1037,6 +1083,14 @@ ir::TSMappedType *ParserImpl::ParseTsMappedType() ir::TSTypeParameter *typeParameter = ParseTsMappedTypeParameter(); + ir::Expression *nameKeyType = nullptr; + if (lexer_->GetToken().KeywordType() == lexer::TokenType::KEYW_AS) { + lexer_->NextToken(); // eat 'as' + TypeAnnotationParsingOptions options = TypeAnnotationParsingOptions::THROW_ERROR; + nameKeyType = ParseTsTypeAnnotation(&options); + ASSERT(nameKeyType != nullptr); + } + if (lexer_->GetToken().Type() != lexer::TokenType::PUNCTUATOR_RIGHT_SQUARE_BRACKET) { ThrowSyntaxError("']' expected"); } @@ -1065,7 +1119,7 @@ ir::TSMappedType *ParserImpl::ParseTsMappedType() ThrowSyntaxError("'}' expected"); } - auto *mappedType = AllocNode(typeParameter, typeAnnotation, readonly, optional); + auto *mappedType = AllocNode(typeParameter, nameKeyType, typeAnnotation, readonly, optional); mappedType->SetRange({startLoc, lexer_->GetToken().End()}); @@ -1706,6 +1760,8 @@ ir::Expression *ParserImpl::ParseTsBasicType() typeAnnotation = AllocNode(); } else if (lexer_->GetToken().KeywordType() == lexer::TokenType::KEYW_BIGINT) { typeAnnotation = AllocNode(); + } else if (lexer_->GetToken().KeywordType() == lexer::TokenType::KEYW_SYMBOL) { + typeAnnotation = AllocNode(); } else { ThrowSyntaxError("Unexpected type"); } @@ -2082,7 +2138,8 @@ ir::Expression *ParserImpl::ParseClassKey(ClassElmentDescriptor *desc, bool isDe desc->invalidComputedProperty = !propName->IsNumberLiteral() && !propName->IsStringLiteral() && !(propName->IsMemberExpression() && propName->AsMemberExpression()->Object()->IsIdentifier() && - propName->AsMemberExpression()->Object()->AsIdentifier()->Name().Is("Symbol")); + propName->AsMemberExpression()->Object()->AsIdentifier()->Name().Is("Symbol")) && + !propName->IsIdentifier(); } if (lexer_->GetToken().Type() != lexer::TokenType::PUNCTUATOR_RIGHT_SQUARE_BRACKET) { diff --git a/es2panda/parser/parserImpl.h b/es2panda/parser/parserImpl.h index ed541f881c..3bc4cc2811 100644 --- a/es2panda/parser/parserImpl.h +++ b/es2panda/parser/parserImpl.h @@ -251,6 +251,7 @@ private: ir::Expression *ParseTsIndexAccessType(ir::Expression *typeName); ir::Expression *ParseTsQualifiedReference(ir::Expression *typeName); ir::Expression *ParseTsTypeReferenceOrQuery(bool parseQuery = false); + bool IsTSNamedTupleMember(); ir::Expression *ParseTsTupleElement(ir::TSTupleKind *kind, bool *seenOptional); ir::TSTupleType *ParseTsTupleType(); ir::TSImportType *ParseTsImportType(const lexer::SourcePosition &startLoc, bool isTypeof = false); diff --git a/es2panda/test/parser/ts/test-enum-declaration6-expected.txt b/es2panda/test/parser/ts/test-enum-declaration6-expected.txt new file mode 100644 index 0000000000..a679aa60af --- /dev/null +++ b/es2panda/test/parser/ts/test-enum-declaration6-expected.txt @@ -0,0 +1,374 @@ +{ + "type": "Program", + "statements": [ + { + "type": "TSEnumDeclaration", + "id": { + "type": "Identifier", + "name": "ShiftE", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 6 + }, + "end": { + "line": 17, + "column": 12 + } + } + }, + "members": [ + { + "type": "TSEnumMember", + "id": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 5 + }, + "end": { + "line": 18, + "column": 6 + } + } + }, + "initializer": { + "type": "NumberLiteral", + "value": 1, + "loc": { + "start": { + "line": 18, + "column": 9 + }, + "end": { + "line": 18, + "column": 10 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 9 + }, + "end": { + "line": 18, + "column": 11 + } + } + }, + { + "type": "TSEnumMember", + "id": { + "type": "Identifier", + "name": "B", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 5 + }, + "end": { + "line": 19, + "column": 6 + } + } + }, + "initializer": { + "type": "BinaryExpression", + "operator": "<<", + "left": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 9 + }, + "end": { + "line": 19, + "column": 10 + } + } + }, + "right": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 14 + }, + "end": { + "line": 19, + "column": 15 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 9 + }, + "end": { + "line": 19, + "column": 15 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 9 + }, + "end": { + "line": 19, + "column": 16 + } + } + }, + { + "type": "TSEnumMember", + "id": { + "type": "Identifier", + "name": "C", + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 5 + }, + "end": { + "line": 20, + "column": 6 + } + } + }, + "initializer": { + "type": "BinaryExpression", + "operator": "<<", + "left": { + "type": "Identifier", + "name": "B", + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 9 + }, + "end": { + "line": 20, + "column": 10 + } + } + }, + "right": { + "type": "NumberLiteral", + "value": 1, + "loc": { + "start": { + "line": 20, + "column": 14 + }, + "end": { + "line": 20, + "column": 15 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 9 + }, + "end": { + "line": 20, + "column": 15 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 9 + }, + "end": { + "line": 20, + "column": 16 + } + } + }, + { + "type": "TSEnumMember", + "id": { + "type": "Identifier", + "name": "D", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 5 + }, + "end": { + "line": 21, + "column": 6 + } + } + }, + "initializer": { + "type": "BinaryExpression", + "operator": "<<", + "left": { + "type": "Identifier", + "name": "C", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 9 + }, + "end": { + "line": 21, + "column": 10 + } + } + }, + "right": { + "type": "Identifier", + "name": "B", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 14 + }, + "end": { + "line": 21, + "column": 15 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 9 + }, + "end": { + "line": 21, + "column": 15 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 9 + }, + "end": { + "line": 21, + "column": 16 + } + } + }, + { + "type": "TSEnumMember", + "id": { + "type": "Identifier", + "name": "E", + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 5 + }, + "end": { + "line": 22, + "column": 6 + } + } + }, + "initializer": { + "type": "BinaryExpression", + "operator": "<<", + "left": { + "type": "Identifier", + "name": "D", + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 9 + }, + "end": { + "line": 22, + "column": 10 + } + } + }, + "right": { + "type": "NumberLiteral", + "value": 2, + "loc": { + "start": { + "line": 22, + "column": 14 + }, + "end": { + "line": 22, + "column": 15 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 9 + }, + "end": { + "line": 22, + "column": 15 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 9 + }, + "end": { + "line": 22, + "column": 16 + } + } + } + ], + "const": false, + "loc": { + "start": { + "line": 17, + "column": 1 + }, + "end": { + "line": 23, + "column": 2 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 23, + "column": 2 + } + } +} diff --git a/es2panda/test/parser/ts/test-enum-declaration6.ts b/es2panda/test/parser/ts/test-enum-declaration6.ts new file mode 100644 index 0000000000..3fb14ee994 --- /dev/null +++ b/es2panda/test/parser/ts/test-enum-declaration6.ts @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +enum ShiftE { + A = 1, + B = A << A, + C = B << 1, + D = C << B, + E = D << 2, +} \ No newline at end of file diff --git a/es2panda/test/parser/ts/test-func-param-expected.txt b/es2panda/test/parser/ts/test-func-param-expected.txt index 6a8699ea81..360ebf454c 100644 --- a/es2panda/test/parser/ts/test-func-param-expected.txt +++ b/es2panda/test/parser/ts/test-func-param-expected.txt @@ -678,7 +678,7 @@ }, "end": { "line": 21, - "column": 32 + "column": 31 } } }, @@ -691,7 +691,7 @@ }, "end": { "line": 21, - "column": 40 + "column": 39 } } } @@ -1270,7 +1270,7 @@ }, "end": { "line": 23, - "column": 40 + "column": 39 } } }, @@ -1283,7 +1283,7 @@ }, "end": { "line": 23, - "column": 48 + "column": 47 } } } @@ -1662,7 +1662,7 @@ }, "end": { "line": 25, - "column": 41 + "column": 40 } } }, @@ -1675,7 +1675,7 @@ }, "end": { "line": 25, - "column": 49 + "column": 48 } } } diff --git a/es2panda/test/parser/ts/test-ts-key-remapping-via-as-expected.txt b/es2panda/test/parser/ts/test-ts-key-remapping-via-as-expected.txt new file mode 100644 index 0000000000..d93d9a7321 --- /dev/null +++ b/es2panda/test/parser/ts/test-ts-key-remapping-via-as-expected.txt @@ -0,0 +1,900 @@ +{ + "type": "Program", + "statements": [ + { + "type": "TSTypeAliasDeclaration", + "id": { + "type": "Identifier", + "name": "GetName", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 6 + }, + "end": { + "line": 17, + "column": 13 + } + } + }, + "typeAnnotation": { + "type": "TSMappedType", + "typeParameter": { + "type": "TSTypeParameter", + "name": { + "type": "Identifier", + "name": "p", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 6 + }, + "end": { + "line": 18, + "column": 7 + } + } + }, + "constraint": { + "type": "TSTypeReference", + "typeName": { + "type": "Identifier", + "name": "Type", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 11 + }, + "end": { + "line": 18, + "column": 15 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 11 + }, + "end": { + "line": 18, + "column": 15 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 6 + }, + "end": { + "line": 18, + "column": 15 + } + } + }, + "nameKeyType": { + "type": "TSIndexedAccessType", + "objectType": { + "type": "TSTypeReference", + "typeName": { + "type": "Identifier", + "name": "p", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 19 + }, + "end": { + "line": 18, + "column": 20 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 19 + }, + "end": { + "line": 18, + "column": 21 + } + } + }, + "indexType": { + "type": "TSLiteralType", + "literal": { + "type": "StringLiteral", + "value": "name", + "loc": { + "start": { + "line": 18, + "column": 21 + }, + "end": { + "line": 18, + "column": 27 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 21 + }, + "end": { + "line": 18, + "column": 27 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 19 + }, + "end": { + "line": 18, + "column": 29 + } + } + }, + "typeAnnotation": { + "type": "TSNumberKeyword", + "loc": { + "start": { + "line": 18, + "column": 32 + }, + "end": { + "line": 18, + "column": 38 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 45 + }, + "end": { + "line": 19, + "column": 2 + } + } + }, + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "params": [ + { + "type": "TSTypeParameter", + "name": { + "type": "Identifier", + "name": "Type", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 14 + }, + "end": { + "line": 17, + "column": 18 + } + } + }, + "constraint": { + "type": "TSTypeLiteral", + "members": [ + { + "type": "TSPropertySignature", + "computed": false, + "optional": false, + "readonly": false, + "key": { + "type": "Identifier", + "name": "name", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 28 + }, + "end": { + "line": 17, + "column": 32 + } + } + }, + "typeAnnotation": { + "type": "TSStringKeyword", + "loc": { + "start": { + "line": 17, + "column": 34 + }, + "end": { + "line": 17, + "column": 40 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 28 + }, + "end": { + "line": 17, + "column": 41 + } + } + } + ], + "loc": { + "start": { + "line": 17, + "column": 27 + }, + "end": { + "line": 17, + "column": 41 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 14 + }, + "end": { + "line": 17, + "column": 42 + } + } + } + ], + "loc": { + "start": { + "line": 17, + "column": 13 + }, + "end": { + "line": 17, + "column": 42 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 1 + }, + "end": { + "line": 20, + "column": 5 + } + } + }, + { + "type": "TSTypeAliasDeclaration", + "id": { + "type": "Identifier", + "name": "NameA", + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 6 + }, + "end": { + "line": 20, + "column": 11 + } + } + }, + "typeAnnotation": { + "type": "TSTypeLiteral", + "members": [ + { + "type": "TSPropertySignature", + "computed": false, + "optional": false, + "readonly": false, + "key": { + "type": "Identifier", + "name": "name", + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 15 + }, + "end": { + "line": 20, + "column": 19 + } + } + }, + "typeAnnotation": { + "type": "TSLiteralType", + "literal": { + "type": "StringLiteral", + "value": "A", + "loc": { + "start": { + "line": 20, + "column": 21 + }, + "end": { + "line": 20, + "column": 24 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 21 + }, + "end": { + "line": 20, + "column": 24 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 15 + }, + "end": { + "line": 20, + "column": 25 + } + } + }, + { + "type": "TSPropertySignature", + "computed": false, + "optional": false, + "readonly": false, + "key": { + "type": "Identifier", + "name": "kind", + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 26 + }, + "end": { + "line": 20, + "column": 30 + } + } + }, + "typeAnnotation": { + "type": "TSStringKeyword", + "loc": { + "start": { + "line": 20, + "column": 32 + }, + "end": { + "line": 20, + "column": 38 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 26 + }, + "end": { + "line": 20, + "column": 39 + } + } + } + ], + "loc": { + "start": { + "line": 20, + "column": 14 + }, + "end": { + "line": 20, + "column": 39 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 1 + }, + "end": { + "line": 21, + "column": 5 + } + } + }, + { + "type": "TSTypeAliasDeclaration", + "id": { + "type": "Identifier", + "name": "NameB", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 6 + }, + "end": { + "line": 21, + "column": 11 + } + } + }, + "typeAnnotation": { + "type": "TSTypeLiteral", + "members": [ + { + "type": "TSPropertySignature", + "computed": false, + "optional": false, + "readonly": false, + "key": { + "type": "Identifier", + "name": "name", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 15 + }, + "end": { + "line": 21, + "column": 19 + } + } + }, + "typeAnnotation": { + "type": "TSLiteralType", + "literal": { + "type": "StringLiteral", + "value": "B", + "loc": { + "start": { + "line": 21, + "column": 21 + }, + "end": { + "line": 21, + "column": 24 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 21 + }, + "end": { + "line": 21, + "column": 24 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 15 + }, + "end": { + "line": 21, + "column": 25 + } + } + }, + { + "type": "TSPropertySignature", + "computed": false, + "optional": false, + "readonly": false, + "key": { + "type": "Identifier", + "name": "kind", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 26 + }, + "end": { + "line": 21, + "column": 30 + } + } + }, + "typeAnnotation": { + "type": "TSStringKeyword", + "loc": { + "start": { + "line": 21, + "column": 32 + }, + "end": { + "line": 21, + "column": 38 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 26 + }, + "end": { + "line": 21, + "column": 39 + } + } + } + ], + "loc": { + "start": { + "line": 21, + "column": 14 + }, + "end": { + "line": 21, + "column": 39 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 1 + }, + "end": { + "line": 22, + "column": 5 + } + } + }, + { + "type": "TSTypeAliasDeclaration", + "id": { + "type": "Identifier", + "name": "NameC", + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 6 + }, + "end": { + "line": 22, + "column": 11 + } + } + }, + "typeAnnotation": { + "type": "TSTypeLiteral", + "members": [ + { + "type": "TSPropertySignature", + "computed": false, + "optional": false, + "readonly": false, + "key": { + "type": "Identifier", + "name": "name", + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 15 + }, + "end": { + "line": 22, + "column": 19 + } + } + }, + "typeAnnotation": { + "type": "TSLiteralType", + "literal": { + "type": "StringLiteral", + "value": "C", + "loc": { + "start": { + "line": 22, + "column": 21 + }, + "end": { + "line": 22, + "column": 24 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 21 + }, + "end": { + "line": 22, + "column": 24 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 15 + }, + "end": { + "line": 22, + "column": 25 + } + } + }, + { + "type": "TSPropertySignature", + "computed": false, + "optional": false, + "readonly": false, + "key": { + "type": "Identifier", + "name": "kind", + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 26 + }, + "end": { + "line": 22, + "column": 30 + } + } + }, + "typeAnnotation": { + "type": "TSStringKeyword", + "loc": { + "start": { + "line": 22, + "column": 32 + }, + "end": { + "line": 22, + "column": 38 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 26 + }, + "end": { + "line": 22, + "column": 39 + } + } + } + ], + "loc": { + "start": { + "line": 22, + "column": 14 + }, + "end": { + "line": 22, + "column": 39 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 1 + }, + "end": { + "line": 23, + "column": 5 + } + } + }, + { + "type": "TSTypeAliasDeclaration", + "id": { + "type": "Identifier", + "name": "Name", + "decorators": [], + "loc": { + "start": { + "line": 23, + "column": 6 + }, + "end": { + "line": 23, + "column": 10 + } + } + }, + "typeAnnotation": { + "type": "TSTypeReference", + "typeName": { + "type": "Identifier", + "name": "GetName", + "decorators": [], + "loc": { + "start": { + "line": 23, + "column": 13 + }, + "end": { + "line": 23, + "column": 20 + } + } + }, + "typeParameters": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "TSUnionType", + "types": [ + { + "type": "TSTypeReference", + "typeName": { + "type": "Identifier", + "name": "NameA", + "decorators": [], + "loc": { + "start": { + "line": 23, + "column": 21 + }, + "end": { + "line": 23, + "column": 26 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 21 + }, + "end": { + "line": 23, + "column": 26 + } + } + }, + { + "type": "TSTypeReference", + "typeName": { + "type": "Identifier", + "name": "NameB", + "decorators": [], + "loc": { + "start": { + "line": 23, + "column": 29 + }, + "end": { + "line": 23, + "column": 34 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 29 + }, + "end": { + "line": 23, + "column": 34 + } + } + }, + { + "type": "TSTypeReference", + "typeName": { + "type": "Identifier", + "name": "NameC", + "decorators": [], + "loc": { + "start": { + "line": 23, + "column": 37 + }, + "end": { + "line": 23, + "column": 42 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 37 + }, + "end": { + "line": 23, + "column": 42 + } + } + } + ], + "loc": { + "start": { + "line": 23, + "column": 21 + }, + "end": { + "line": 23, + "column": 42 + } + } + } + ], + "loc": { + "start": { + "line": 23, + "column": 13 + }, + "end": { + "line": 23, + "column": 43 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 13 + }, + "end": { + "line": 23, + "column": 20 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 1 + }, + "end": { + "line": 23, + "column": 43 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 23, + "column": 43 + } + } +} diff --git a/es2panda/test/parser/ts/test-ts-key-remapping-via-as.ts b/es2panda/test/parser/ts/test-ts-key-remapping-via-as.ts new file mode 100644 index 0000000000..432297669c --- /dev/null +++ b/es2panda/test/parser/ts/test-ts-key-remapping-via-as.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. + */ + + +type GetName = { + [p in Type as p["name"]] : number; +} +type NameA = {name: "A", kind: string} +type NameB = {name: "B", kind: string} +type NameC = {name: "C", kind: string} +type Name = GetName \ No newline at end of file diff --git a/es2panda/test/parser/ts/test-ts-symbol-type-expected.txt b/es2panda/test/parser/ts/test-ts-symbol-type-expected.txt new file mode 100644 index 0000000000..500309772e --- /dev/null +++ b/es2panda/test/parser/ts/test-ts-symbol-type-expected.txt @@ -0,0 +1,268 @@ +{ + "type": "Program", + "statements": [ + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "s", + "typeAnnotation": { + "type": "TSSymbolKeyword", + "loc": { + "start": { + "line": 17, + "column": 9 + }, + "end": { + "line": 17, + "column": 15 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 5 + }, + "end": { + "line": 17, + "column": 6 + } + } + }, + "init": { + "type": "CallExpression", + "callee": { + "type": "Identifier", + "name": "Symbol", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 18 + }, + "end": { + "line": 17, + "column": 24 + } + } + }, + "arguments": [ + { + "type": "StringLiteral", + "value": "foo", + "loc": { + "start": { + "line": 17, + "column": 25 + }, + "end": { + "line": 17, + "column": 30 + } + } + } + ], + "optional": false, + "loc": { + "start": { + "line": 17, + "column": 18 + }, + "end": { + "line": 17, + "column": 31 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 5 + }, + "end": { + "line": 17, + "column": 31 + } + } + } + ], + "kind": "var", + "loc": { + "start": { + "line": 17, + "column": 1 + }, + "end": { + "line": 17, + "column": 32 + } + } + }, + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "symbolVar", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 5 + }, + "end": { + "line": 18, + "column": 14 + } + } + }, + "init": { + "type": "ObjectExpression", + "properties": [ + { + "type": "Property", + "method": false, + "shorthand": false, + "computed": false, + "key": { + "type": "Identifier", + "name": "a", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 5 + }, + "end": { + "line": 19, + "column": 6 + } + } + }, + "value": { + "type": "NumberLiteral", + "value": 1, + "loc": { + "start": { + "line": 19, + "column": 9 + }, + "end": { + "line": 19, + "column": 10 + } + } + }, + "kind": "init", + "loc": { + "start": { + "line": 19, + "column": 5 + }, + "end": { + "line": 19, + "column": 10 + } + } + }, + { + "type": "Property", + "method": false, + "shorthand": false, + "computed": true, + "key": { + "type": "Identifier", + "name": "s", + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 6 + }, + "end": { + "line": 20, + "column": 7 + } + } + }, + "value": { + "type": "StringLiteral", + "value": "string", + "loc": { + "start": { + "line": 20, + "column": 11 + }, + "end": { + "line": 20, + "column": 19 + } + } + }, + "kind": "init", + "loc": { + "start": { + "line": 20, + "column": 5 + }, + "end": { + "line": 20, + "column": 19 + } + } + } + ], + "loc": { + "start": { + "line": 18, + "column": 17 + }, + "end": { + "line": 21, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 5 + }, + "end": { + "line": 21, + "column": 2 + } + } + } + ], + "kind": "var", + "loc": { + "start": { + "line": 18, + "column": 1 + }, + "end": { + "line": 21, + "column": 2 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 21, + "column": 2 + } + } +} diff --git a/es2panda/test/parser/ts/test-ts-symbol-type.ts b/es2panda/test/parser/ts/test-ts-symbol-type.ts new file mode 100644 index 0000000000..8b2e79d3b4 --- /dev/null +++ b/es2panda/test/parser/ts/test-ts-symbol-type.ts @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +var s : symbol = Symbol("foo"); +var symbolVar = { + a : 1, + [s] : "string", +} \ No newline at end of file diff --git a/es2panda/test/parser/ts/test-ts-unique-symbol-type-expected.txt b/es2panda/test/parser/ts/test-ts-unique-symbol-type-expected.txt new file mode 100644 index 0000000000..c8f6a920d1 --- /dev/null +++ b/es2panda/test/parser/ts/test-ts-unique-symbol-type-expected.txt @@ -0,0 +1,363 @@ +{ + "type": "Program", + "statements": [ + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "s2", + "typeAnnotation": { + "type": "TSTypeOperator", + "operator": "unique", + "typeAnnotation": { + "type": "TSSymbolKeyword", + "loc": { + "start": { + "line": 17, + "column": 19 + }, + "end": { + "line": 17, + "column": 25 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 12 + }, + "end": { + "line": 17, + "column": 25 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 7 + }, + "end": { + "line": 17, + "column": 9 + } + } + }, + "init": { + "type": "CallExpression", + "callee": { + "type": "Identifier", + "name": "Symbol", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 28 + }, + "end": { + "line": 17, + "column": 34 + } + } + }, + "arguments": [], + "optional": false, + "loc": { + "start": { + "line": 17, + "column": 28 + }, + "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": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "SymbolClass", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 7 + }, + "end": { + "line": 18, + "column": 18 + } + } + }, + "superClass": null, + "implements": [], + "constructor": { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "constructor", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": null, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 1 + }, + "end": { + "line": 21, + "column": 2 + } + } + }, + "body": [ + { + "type": "ClassProperty", + "key": { + "type": "Identifier", + "name": "a", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 5 + }, + "end": { + "line": 19, + "column": 6 + } + } + }, + "value": { + "type": "StringLiteral", + "value": "a", + "loc": { + "start": { + "line": 19, + "column": 18 + }, + "end": { + "line": 19, + "column": 21 + } + } + }, + "static": false, + "readonly": false, + "declare": false, + "optional": false, + "computed": false, + "typeAnnotation": { + "type": "TSStringKeyword", + "loc": { + "start": { + "line": 19, + "column": 9 + }, + "end": { + "line": 19, + "column": 15 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 5 + }, + "end": { + "line": 19, + "column": 21 + } + } + }, + { + "type": "ClassProperty", + "key": { + "type": "Identifier", + "name": "s2", + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 6 + }, + "end": { + "line": 20, + "column": 8 + } + } + }, + "value": { + "type": "NumberLiteral", + "value": 2, + "loc": { + "start": { + "line": 20, + "column": 21 + }, + "end": { + "line": 20, + "column": 22 + } + } + }, + "static": false, + "readonly": false, + "declare": false, + "optional": false, + "computed": true, + "typeAnnotation": { + "type": "TSNumberKeyword", + "loc": { + "start": { + "line": 20, + "column": 12 + }, + "end": { + "line": 20, + "column": 18 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 5 + }, + "end": { + "line": 20, + "column": 22 + } + } + } + ], + "indexSignatures": [], + "loc": { + "start": { + "line": 18, + "column": 18 + }, + "end": { + "line": 21, + "column": 2 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 1 + }, + "end": { + "line": 21, + "column": 2 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 21, + "column": 2 + } + } +} diff --git a/es2panda/test/parser/ts/test-ts-unique-symbol-type.ts b/es2panda/test/parser/ts/test-ts-unique-symbol-type.ts new file mode 100644 index 0000000000..f445074c8f --- /dev/null +++ b/es2panda/test/parser/ts/test-ts-unique-symbol-type.ts @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +const s2 : unique symbol = Symbol(); +class SymbolClass{ + a : string = "a"; + [s2] : number = 2; +} \ No newline at end of file diff --git a/es2panda/test/parser/ts/test-tuple-type-expected.txt b/es2panda/test/parser/ts/test-tuple-type-expected.txt index 8e576727c9..474686f08a 100644 --- a/es2panda/test/parser/ts/test-tuple-type-expected.txt +++ b/es2panda/test/parser/ts/test-tuple-type-expected.txt @@ -49,7 +49,7 @@ }, "end": { "line": 17, - "column": 19 + "column": 18 } } }, @@ -90,7 +90,7 @@ }, "end": { "line": 17, - "column": 30 + "column": 29 } } }, @@ -185,7 +185,7 @@ }, "end": { "line": 17, - "column": 53 + "column": 52 } } } @@ -258,7 +258,7 @@ }, "end": { "line": 18, - "column": 16 + "column": 15 } } }, @@ -271,7 +271,7 @@ }, "end": { "line": 18, - "column": 24 + "column": 23 } } }, @@ -284,7 +284,7 @@ }, "end": { "line": 18, - "column": 32 + "column": 31 } } } @@ -388,7 +388,7 @@ }, "end": { "line": 19, - "column": 20 + "column": 19 } } }, @@ -429,7 +429,7 @@ }, "end": { "line": 19, - "column": 31 + "column": 30 } } } @@ -441,7 +441,7 @@ }, "end": { "line": 19, - "column": 32 + "column": 31 } } }, @@ -491,7 +491,7 @@ }, "end": { "line": 19, - "column": 55 + "column": 54 } } }, @@ -504,7 +504,7 @@ }, "end": { "line": 19, - "column": 64 + "column": 63 } } } @@ -553,7 +553,7 @@ }, "end": { "line": 19, - "column": 79 + "column": 78 } } } @@ -632,7 +632,7 @@ }, "end": { "line": 20, - "column": 18 + "column": 17 } } }, @@ -645,7 +645,7 @@ }, "end": { "line": 20, - "column": 26 + "column": 25 } } } @@ -657,7 +657,7 @@ }, "end": { "line": 20, - "column": 27 + "column": 26 } } }, @@ -670,7 +670,7 @@ }, "end": { "line": 20, - "column": 35 + "column": 34 } } }, @@ -683,7 +683,7 @@ }, "end": { "line": 20, - "column": 43 + "column": 42 } } } @@ -695,7 +695,7 @@ }, "end": { "line": 20, - "column": 44 + "column": 43 } } }, @@ -708,7 +708,7 @@ }, "end": { "line": 20, - "column": 52 + "column": 51 } } }, @@ -721,7 +721,7 @@ }, "end": { "line": 20, - "column": 60 + "column": 59 } } } @@ -852,7 +852,7 @@ }, "end": { "line": 21, - "column": 14 + "column": 10 } } } diff --git a/es2panda/test/parser/ts/test-tuple-type2-expected.txt b/es2panda/test/parser/ts/test-tuple-type2-expected.txt index 7329971951..e2affa9688 100644 --- a/es2panda/test/parser/ts/test-tuple-type2-expected.txt +++ b/es2panda/test/parser/ts/test-tuple-type2-expected.txt @@ -1 +1 @@ -SyntaxError: Tuple members must all have names or all not have names [test-tuple-type2.ts:17:17] +SyntaxError: Tuple members must all have or haven't names [test-tuple-type2.ts:17:17] diff --git a/es2panda/test/parser/ts/test-tuple-type5-expected.txt b/es2panda/test/parser/ts/test-tuple-type5-expected.txt new file mode 100644 index 0000000000..5454b9fc2b --- /dev/null +++ b/es2panda/test/parser/ts/test-tuple-type5-expected.txt @@ -0,0 +1,1691 @@ +{ + "type": "Program", + "statements": [ + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "x1", + "typeAnnotation": { + "type": "TSTupleType", + "elementTypes": [ + { + "type": "TSNumberKeyword", + "loc": { + "start": { + "line": 17, + "column": 11 + }, + "end": { + "line": 17, + "column": 17 + } + } + }, + { + "type": "TSStringKeyword", + "loc": { + "start": { + "line": 17, + "column": 19 + }, + "end": { + "line": 17, + "column": 25 + } + } + } + ], + "loc": { + "start": { + "line": 17, + "column": 10 + }, + "end": { + "line": 17, + "column": 26 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 5 + }, + "end": { + "line": 17, + "column": 7 + } + } + }, + "init": null, + "loc": { + "start": { + "line": 17, + "column": 5 + }, + "end": { + "line": 17, + "column": 7 + } + } + } + ], + "kind": "var", + "loc": { + "start": { + "line": 17, + "column": 1 + }, + "end": { + "line": 17, + "column": 27 + } + } + }, + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "x2", + "typeAnnotation": { + "type": "TSTupleType", + "elementTypes": [ + { + "type": "TSStringKeyword", + "loc": { + "start": { + "line": 18, + "column": 11 + }, + "end": { + "line": 18, + "column": 17 + } + } + }, + { + "type": "TSRestType", + "typeAnnotation": { + "type": "TSArrayType", + "elementType": { + "type": "TSNumberKeyword", + "loc": { + "start": { + "line": 18, + "column": 22 + }, + "end": { + "line": 18, + "column": 28 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 22 + }, + "end": { + "line": 18, + "column": 30 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 19 + }, + "end": { + "line": 18, + "column": 30 + } + } + }, + { + "type": "TSStringKeyword", + "loc": { + "start": { + "line": 18, + "column": 32 + }, + "end": { + "line": 18, + "column": 38 + } + } + } + ], + "loc": { + "start": { + "line": 18, + "column": 10 + }, + "end": { + "line": 18, + "column": 39 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 5 + }, + "end": { + "line": 18, + "column": 7 + } + } + }, + "init": null, + "loc": { + "start": { + "line": 18, + "column": 5 + }, + "end": { + "line": 18, + "column": 7 + } + } + } + ], + "kind": "var", + "loc": { + "start": { + "line": 18, + "column": 1 + }, + "end": { + "line": 18, + "column": 40 + } + } + }, + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "x3", + "typeAnnotation": { + "type": "TSTupleType", + "elementTypes": [ + { + "type": "TSNamedTupleMember", + "elementType": { + "type": "TSBooleanKeyword", + "loc": { + "start": { + "line": 19, + "column": 15 + }, + "end": { + "line": 19, + "column": 22 + } + } + }, + "label": { + "type": "Identifier", + "name": "a", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 11 + }, + "end": { + "line": 19, + "column": 12 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 11 + }, + "end": { + "line": 19, + "column": 22 + } + } + }, + { + "type": "TSNamedTupleMember", + "elementType": { + "type": "TSArrayType", + "elementType": { + "type": "TSStringKeyword", + "loc": { + "start": { + "line": 19, + "column": 30 + }, + "end": { + "line": 19, + "column": 36 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 30 + }, + "end": { + "line": 19, + "column": 38 + } + } + }, + "label": { + "type": "Identifier", + "name": "b", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 27 + }, + "end": { + "line": 19, + "column": 28 + } + } + }, + "rest": true, + "loc": { + "start": { + "line": 19, + "column": 24 + }, + "end": { + "line": 19, + "column": 38 + } + } + }, + { + "type": "TSNamedTupleMember", + "elementType": { + "type": "TSNumberKeyword", + "loc": { + "start": { + "line": 19, + "column": 44 + }, + "end": { + "line": 19, + "column": 50 + } + } + }, + "label": { + "type": "Identifier", + "name": "c", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 40 + }, + "end": { + "line": 19, + "column": 41 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 40 + }, + "end": { + "line": 19, + "column": 50 + } + } + } + ], + "loc": { + "start": { + "line": 19, + "column": 10 + }, + "end": { + "line": 19, + "column": 51 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 5 + }, + "end": { + "line": 19, + "column": 7 + } + } + }, + "init": null, + "loc": { + "start": { + "line": 19, + "column": 5 + }, + "end": { + "line": 19, + "column": 7 + } + } + } + ], + "kind": "var", + "loc": { + "start": { + "line": 19, + "column": 1 + }, + "end": { + "line": 19, + "column": 52 + } + } + }, + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "x4", + "typeAnnotation": { + "type": "TSTupleType", + "elementTypes": [ + { + "type": "TSStringKeyword", + "loc": { + "start": { + "line": 20, + "column": 11 + }, + "end": { + "line": 20, + "column": 17 + } + } + }, + { + "type": "TSOptionalType", + "typeAnnotation": { + "type": "TSNumberKeyword", + "loc": { + "start": { + "line": 20, + "column": 19 + }, + "end": { + "line": 20, + "column": 25 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 19 + }, + "end": { + "line": 20, + "column": 26 + } + } + } + ], + "loc": { + "start": { + "line": 20, + "column": 10 + }, + "end": { + "line": 20, + "column": 27 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 5 + }, + "end": { + "line": 20, + "column": 7 + } + } + }, + "init": null, + "loc": { + "start": { + "line": 20, + "column": 5 + }, + "end": { + "line": 20, + "column": 7 + } + } + } + ], + "kind": "var", + "loc": { + "start": { + "line": 20, + "column": 1 + }, + "end": { + "line": 20, + "column": 28 + } + } + }, + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "x5", + "typeAnnotation": { + "type": "TSTupleType", + "elementTypes": [ + { + "type": "TSNamedTupleMember", + "elementType": { + "type": "TSNumberKeyword", + "loc": { + "start": { + "line": 21, + "column": 15 + }, + "end": { + "line": 21, + "column": 21 + } + } + }, + "label": { + "type": "Identifier", + "name": "a", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 11 + }, + "end": { + "line": 21, + "column": 12 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 11 + }, + "end": { + "line": 21, + "column": 21 + } + } + }, + { + "type": "TSNamedTupleMember", + "elementType": { + "type": "TSStringKeyword", + "loc": { + "start": { + "line": 21, + "column": 28 + }, + "end": { + "line": 21, + "column": 34 + } + } + }, + "label": { + "type": "Identifier", + "name": "b", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 23 + }, + "end": { + "line": 21, + "column": 24 + } + } + }, + "optional": true, + "loc": { + "start": { + "line": 21, + "column": 23 + }, + "end": { + "line": 21, + "column": 34 + } + } + } + ], + "loc": { + "start": { + "line": 21, + "column": 10 + }, + "end": { + "line": 21, + "column": 35 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 5 + }, + "end": { + "line": 21, + "column": 7 + } + } + }, + "init": null, + "loc": { + "start": { + "line": 21, + "column": 5 + }, + "end": { + "line": 21, + "column": 7 + } + } + } + ], + "kind": "var", + "loc": { + "start": { + "line": 21, + "column": 1 + }, + "end": { + "line": 21, + "column": 36 + } + } + }, + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "ForTupleTest", + "decorators": [], + "loc": { + "start": { + "line": 23, + "column": 7 + }, + "end": { + "line": 23, + "column": 19 + } + } + }, + "superClass": null, + "implements": [], + "constructor": { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "constructor", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": null, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 23, + "column": 1 + }, + "end": { + "line": 24, + "column": 2 + } + } + }, + "body": [], + "indexSignatures": [], + "loc": { + "start": { + "line": 23, + "column": 20 + }, + "end": { + "line": 24, + "column": 2 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 23, + "column": 1 + }, + "end": { + "line": 24, + "column": 2 + } + } + }, + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "x6", + "typeAnnotation": { + "type": "TSTupleType", + "elementTypes": [ + { + "type": "TSTypeReference", + "typeName": { + "type": "Identifier", + "name": "ForTupleTest", + "decorators": [], + "loc": { + "start": { + "line": 25, + "column": 11 + }, + "end": { + "line": 25, + "column": 23 + } + } + }, + "loc": { + "start": { + "line": 25, + "column": 11 + }, + "end": { + "line": 25, + "column": 23 + } + } + }, + { + "type": "TSOptionalType", + "typeAnnotation": { + "type": "TSTypeReference", + "typeName": { + "type": "Identifier", + "name": "ForTupleTest", + "decorators": [], + "loc": { + "start": { + "line": 25, + "column": 25 + }, + "end": { + "line": 25, + "column": 37 + } + } + }, + "loc": { + "start": { + "line": 25, + "column": 25 + }, + "end": { + "line": 25, + "column": 37 + } + } + }, + "loc": { + "start": { + "line": 25, + "column": 25 + }, + "end": { + "line": 25, + "column": 38 + } + } + } + ], + "loc": { + "start": { + "line": 25, + "column": 10 + }, + "end": { + "line": 25, + "column": 39 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 25, + "column": 5 + }, + "end": { + "line": 25, + "column": 7 + } + } + }, + "init": null, + "loc": { + "start": { + "line": 25, + "column": 5 + }, + "end": { + "line": 25, + "column": 7 + } + } + } + ], + "kind": "var", + "loc": { + "start": { + "line": 25, + "column": 1 + }, + "end": { + "line": 25, + "column": 40 + } + } + }, + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "x7", + "typeAnnotation": { + "type": "TSTupleType", + "elementTypes": [ + { + "type": "TSNamedTupleMember", + "elementType": { + "type": "TSNumberKeyword", + "loc": { + "start": { + "line": 26, + "column": 15 + }, + "end": { + "line": 26, + "column": 21 + } + } + }, + "label": { + "type": "Identifier", + "name": "a", + "decorators": [], + "loc": { + "start": { + "line": 26, + "column": 11 + }, + "end": { + "line": 26, + "column": 12 + } + } + }, + "loc": { + "start": { + "line": 26, + "column": 11 + }, + "end": { + "line": 26, + "column": 21 + } + } + }, + { + "type": "TSNamedTupleMember", + "elementType": { + "type": "TSTypeReference", + "typeName": { + "type": "Identifier", + "name": "ForTupleTest", + "decorators": [], + "loc": { + "start": { + "line": 26, + "column": 28 + }, + "end": { + "line": 26, + "column": 40 + } + } + }, + "loc": { + "start": { + "line": 26, + "column": 28 + }, + "end": { + "line": 26, + "column": 40 + } + } + }, + "label": { + "type": "Identifier", + "name": "b", + "decorators": [], + "loc": { + "start": { + "line": 26, + "column": 23 + }, + "end": { + "line": 26, + "column": 24 + } + } + }, + "optional": true, + "loc": { + "start": { + "line": 26, + "column": 23 + }, + "end": { + "line": 26, + "column": 40 + } + } + } + ], + "loc": { + "start": { + "line": 26, + "column": 10 + }, + "end": { + "line": 26, + "column": 41 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 26, + "column": 5 + }, + "end": { + "line": 26, + "column": 7 + } + } + }, + "init": null, + "loc": { + "start": { + "line": 26, + "column": 5 + }, + "end": { + "line": 26, + "column": 7 + } + } + } + ], + "kind": "var", + "loc": { + "start": { + "line": 26, + "column": 1 + }, + "end": { + "line": 26, + "column": 42 + } + } + }, + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "x8", + "typeAnnotation": { + "type": "TSTupleType", + "elementTypes": [ + { + "type": "TSNumberKeyword", + "loc": { + "start": { + "line": 27, + "column": 11 + }, + "end": { + "line": 27, + "column": 17 + } + } + }, + { + "type": "TSRestType", + "typeAnnotation": { + "type": "TSArrayType", + "elementType": { + "type": "TSTypeReference", + "typeName": { + "type": "Identifier", + "name": "ForTupleTest", + "decorators": [], + "loc": { + "start": { + "line": 27, + "column": 22 + }, + "end": { + "line": 27, + "column": 34 + } + } + }, + "loc": { + "start": { + "line": 27, + "column": 22 + }, + "end": { + "line": 27, + "column": 34 + } + } + }, + "loc": { + "start": { + "line": 27, + "column": 22 + }, + "end": { + "line": 27, + "column": 36 + } + } + }, + "loc": { + "start": { + "line": 27, + "column": 19 + }, + "end": { + "line": 27, + "column": 36 + } + } + }, + { + "type": "TSStringKeyword", + "loc": { + "start": { + "line": 27, + "column": 38 + }, + "end": { + "line": 27, + "column": 44 + } + } + } + ], + "loc": { + "start": { + "line": 27, + "column": 10 + }, + "end": { + "line": 27, + "column": 45 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 27, + "column": 5 + }, + "end": { + "line": 27, + "column": 7 + } + } + }, + "init": null, + "loc": { + "start": { + "line": 27, + "column": 5 + }, + "end": { + "line": 27, + "column": 7 + } + } + } + ], + "kind": "var", + "loc": { + "start": { + "line": 27, + "column": 1 + }, + "end": { + "line": 27, + "column": 46 + } + } + }, + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "x9", + "typeAnnotation": { + "type": "TSTupleType", + "elementTypes": [ + { + "type": "TSNamedTupleMember", + "elementType": { + "type": "TSStringKeyword", + "loc": { + "start": { + "line": 28, + "column": 15 + }, + "end": { + "line": 28, + "column": 21 + } + } + }, + "label": { + "type": "Identifier", + "name": "a", + "decorators": [], + "loc": { + "start": { + "line": 28, + "column": 11 + }, + "end": { + "line": 28, + "column": 12 + } + } + }, + "loc": { + "start": { + "line": 28, + "column": 11 + }, + "end": { + "line": 28, + "column": 21 + } + } + }, + { + "type": "TSNamedTupleMember", + "elementType": { + "type": "TSArrayType", + "elementType": { + "type": "TSTypeReference", + "typeName": { + "type": "Identifier", + "name": "C", + "decorators": [], + "loc": { + "start": { + "line": 28, + "column": 30 + }, + "end": { + "line": 28, + "column": 31 + } + } + }, + "loc": { + "start": { + "line": 28, + "column": 30 + }, + "end": { + "line": 28, + "column": 31 + } + } + }, + "loc": { + "start": { + "line": 28, + "column": 30 + }, + "end": { + "line": 28, + "column": 33 + } + } + }, + "label": { + "type": "Identifier", + "name": "b", + "decorators": [], + "loc": { + "start": { + "line": 28, + "column": 26 + }, + "end": { + "line": 28, + "column": 27 + } + } + }, + "rest": true, + "loc": { + "start": { + "line": 28, + "column": 23 + }, + "end": { + "line": 28, + "column": 33 + } + } + }, + { + "type": "TSNamedTupleMember", + "elementType": { + "type": "TSStringKeyword", + "loc": { + "start": { + "line": 28, + "column": 37 + }, + "end": { + "line": 28, + "column": 43 + } + } + }, + "label": { + "type": "Identifier", + "name": "c", + "decorators": [], + "loc": { + "start": { + "line": 28, + "column": 35 + }, + "end": { + "line": 28, + "column": 36 + } + } + }, + "loc": { + "start": { + "line": 28, + "column": 35 + }, + "end": { + "line": 28, + "column": 43 + } + } + } + ], + "loc": { + "start": { + "line": 28, + "column": 10 + }, + "end": { + "line": 28, + "column": 44 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 28, + "column": 5 + }, + "end": { + "line": 28, + "column": 7 + } + } + }, + "init": null, + "loc": { + "start": { + "line": 28, + "column": 5 + }, + "end": { + "line": 28, + "column": 7 + } + } + } + ], + "kind": "var", + "loc": { + "start": { + "line": 28, + "column": 1 + }, + "end": { + "line": 28, + "column": 45 + } + } + }, + { + "type": "TSTypeAliasDeclaration", + "id": { + "type": "Identifier", + "name": "StringsForTupleTest", + "decorators": [], + "loc": { + "start": { + "line": 30, + "column": 6 + }, + "end": { + "line": 30, + "column": 25 + } + } + }, + "typeAnnotation": { + "type": "TSTupleType", + "elementTypes": [ + { + "type": "TSStringKeyword", + "loc": { + "start": { + "line": 30, + "column": 29 + }, + "end": { + "line": 30, + "column": 35 + } + } + }, + { + "type": "TSStringKeyword", + "loc": { + "start": { + "line": 30, + "column": 37 + }, + "end": { + "line": 30, + "column": 43 + } + } + } + ], + "loc": { + "start": { + "line": 30, + "column": 28 + }, + "end": { + "line": 30, + "column": 44 + } + } + }, + "loc": { + "start": { + "line": 30, + "column": 1 + }, + "end": { + "line": 31, + "column": 5 + } + } + }, + { + "type": "TSTypeAliasDeclaration", + "id": { + "type": "Identifier", + "name": "NumbersForTupleTest", + "decorators": [], + "loc": { + "start": { + "line": 31, + "column": 6 + }, + "end": { + "line": 31, + "column": 25 + } + } + }, + "typeAnnotation": { + "type": "TSTupleType", + "elementTypes": [ + { + "type": "TSNumberKeyword", + "loc": { + "start": { + "line": 31, + "column": 29 + }, + "end": { + "line": 31, + "column": 35 + } + } + }, + { + "type": "TSNumberKeyword", + "loc": { + "start": { + "line": 31, + "column": 37 + }, + "end": { + "line": 31, + "column": 43 + } + } + } + ], + "loc": { + "start": { + "line": 31, + "column": 28 + }, + "end": { + "line": 31, + "column": 44 + } + } + }, + "loc": { + "start": { + "line": 31, + "column": 1 + }, + "end": { + "line": 32, + "column": 5 + } + } + }, + { + "type": "TSTypeAliasDeclaration", + "id": { + "type": "Identifier", + "name": "x10", + "decorators": [], + "loc": { + "start": { + "line": 32, + "column": 6 + }, + "end": { + "line": 32, + "column": 9 + } + } + }, + "typeAnnotation": { + "type": "TSTupleType", + "elementTypes": [ + { + "type": "TSRestType", + "typeAnnotation": { + "type": "TSTypeReference", + "typeName": { + "type": "Identifier", + "name": "StringsForTupleTest", + "decorators": [], + "loc": { + "start": { + "line": 32, + "column": 16 + }, + "end": { + "line": 32, + "column": 35 + } + } + }, + "loc": { + "start": { + "line": 32, + "column": 16 + }, + "end": { + "line": 32, + "column": 35 + } + } + }, + "loc": { + "start": { + "line": 32, + "column": 13 + }, + "end": { + "line": 32, + "column": 35 + } + } + }, + { + "type": "TSRestType", + "typeAnnotation": { + "type": "TSTypeReference", + "typeName": { + "type": "Identifier", + "name": "NumbersForTupleTest", + "decorators": [], + "loc": { + "start": { + "line": 32, + "column": 40 + }, + "end": { + "line": 32, + "column": 59 + } + } + }, + "loc": { + "start": { + "line": 32, + "column": 40 + }, + "end": { + "line": 32, + "column": 59 + } + } + }, + "loc": { + "start": { + "line": 32, + "column": 37 + }, + "end": { + "line": 32, + "column": 59 + } + } + } + ], + "loc": { + "start": { + "line": 32, + "column": 12 + }, + "end": { + "line": 32, + "column": 60 + } + } + }, + "loc": { + "start": { + "line": 32, + "column": 1 + }, + "end": { + "line": 33, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 33, + "column": 1 + } + } +} diff --git a/es2panda/test/parser/ts/test-tuple-type5.ts b/es2panda/test/parser/ts/test-tuple-type5.ts new file mode 100644 index 0000000000..9fa1dd4432 --- /dev/null +++ b/es2panda/test/parser/ts/test-tuple-type5.ts @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +var x1 : [number, string]; +var x2 : [string, ...number[], string]; +var x3 : [a : boolean, ...b :string[], c : number]; +var x4 : [string, number?]; +var x5 : [a : number, b ?: string]; + +class ForTupleTest { +} +var x6 : [ForTupleTest, ForTupleTest?]; +var x7 : [a : number, b ?: ForTupleTest]; +var x8 : [number, ...ForTupleTest[], string]; +var x9 : [a : string, ...b : C[], c:string]; + +type StringsForTupleTest = [string, string] +type NumbersForTupleTest = [number, number] +type x10 = [...StringsForTupleTest, ...NumbersForTupleTest] diff --git a/es2panda/test/parser/ts/test_generic-expected.txt b/es2panda/test/parser/ts/test_generic-expected.txt index 6618f07c9d..854d904212 100644 --- a/es2panda/test/parser/ts/test_generic-expected.txt +++ b/es2panda/test/parser/ts/test_generic-expected.txt @@ -833,7 +833,7 @@ }, "end": { "line": 23, - "column": 75 + "column": 74 } } }, @@ -846,7 +846,7 @@ }, "end": { "line": 23, - "column": 83 + "column": 82 } } } @@ -1633,7 +1633,7 @@ }, "end": { "line": 29, - "column": 31 + "column": 30 } } }, @@ -1646,7 +1646,7 @@ }, "end": { "line": 29, - "column": 39 + "column": 38 } } } @@ -1900,7 +1900,7 @@ }, "end": { "line": 36, - "column": 44 + "column": 43 } } }, @@ -1926,7 +1926,7 @@ }, "end": { "line": 36, - "column": 54 + "column": 53 } } } @@ -2015,7 +2015,7 @@ }, "end": { "line": 34, - "column": 107 + "column": 106 } } }, @@ -2028,7 +2028,7 @@ }, "end": { "line": 34, - "column": 115 + "column": 114 } } } @@ -2114,7 +2114,7 @@ }, "end": { "line": 34, - "column": 40 + "column": 39 } } }, @@ -2127,7 +2127,7 @@ }, "end": { "line": 34, - "column": 48 + "column": 47 } } }, @@ -2230,7 +2230,7 @@ }, "end": { "line": 34, - "column": 74 + "column": 73 } } } @@ -2408,7 +2408,7 @@ }, "end": { "line": 39, - "column": 26 + "column": 25 } } }, @@ -2435,7 +2435,7 @@ }, "end": { "line": 39, - "column": 29 + "column": 28 } } }, @@ -2462,7 +2462,7 @@ }, "end": { "line": 39, - "column": 32 + "column": 31 } } } @@ -4072,7 +4072,7 @@ }, "end": { "line": 53, - "column": 54 + "column": 53 } } } @@ -4513,7 +4513,7 @@ }, "end": { "line": 57, - "column": 75 + "column": 74 } } } @@ -5680,7 +5680,7 @@ }, "end": { "line": 65, - "column": 52 + "column": 51 } } }, @@ -5693,7 +5693,7 @@ }, "end": { "line": 65, - "column": 60 + "column": 59 } } } @@ -6391,7 +6391,7 @@ }, "end": { "line": 69, - "column": 23 + "column": 22 } } }, @@ -6404,7 +6404,7 @@ }, "end": { "line": 69, - "column": 31 + "column": 30 } } }, @@ -6417,7 +6417,7 @@ }, "end": { "line": 69, - "column": 39 + "column": 38 } } } @@ -6906,7 +6906,7 @@ }, "end": { "line": 74, - "column": 34 + "column": 33 } } }, @@ -6919,7 +6919,7 @@ }, "end": { "line": 74, - "column": 42 + "column": 41 } } } diff --git a/es2panda/test/parser/ts/test_import_type-expected.txt b/es2panda/test/parser/ts/test_import_type-expected.txt index 1f19c1b27a..7edda133f4 100644 --- a/es2panda/test/parser/ts/test_import_type-expected.txt +++ b/es2panda/test/parser/ts/test_import_type-expected.txt @@ -605,7 +605,7 @@ }, "end": { "line": 24, - "column": 104 + "column": 103 } } }, @@ -618,7 +618,7 @@ }, "end": { "line": 24, - "column": 112 + "column": 111 } } } diff --git a/es2panda/test/parser/ts/test_this_type-expected.txt b/es2panda/test/parser/ts/test_this_type-expected.txt index df31b0ada7..86ddf76c31 100644 --- a/es2panda/test/parser/ts/test_this_type-expected.txt +++ b/es2panda/test/parser/ts/test_this_type-expected.txt @@ -313,7 +313,7 @@ }, "end": { "line": 22, - "column": 40 + "column": 39 } } }, @@ -327,7 +327,7 @@ }, "end": { "line": 22, - "column": 44 + "column": 43 } } } diff --git a/es2panda/test/parser/ts/type_checker/arrayDestructuring-expected.txt b/es2panda/test/parser/ts/type_checker/arrayDestructuring-expected.txt index ae094194a0..7bc3d54070 100644 --- a/es2panda/test/parser/ts/type_checker/arrayDestructuring-expected.txt +++ b/es2panda/test/parser/ts/type_checker/arrayDestructuring-expected.txt @@ -2607,7 +2607,7 @@ }, "end": { "line": 45, - "column": 40 + "column": 39 } } }, @@ -2620,7 +2620,7 @@ }, "end": { "line": 45, - "column": 48 + "column": 47 } } } @@ -2766,7 +2766,7 @@ }, "end": { "line": 47, - "column": 40 + "column": 39 } } }, @@ -2807,7 +2807,7 @@ }, "end": { "line": 47, - "column": 57 + "column": 56 } } }, @@ -2833,7 +2833,7 @@ }, "end": { "line": 47, - "column": 68 + "column": 67 } } } @@ -3063,7 +3063,7 @@ }, "end": { "line": 48, - "column": 42 + "column": 41 } } }, @@ -3076,7 +3076,7 @@ }, "end": { "line": 48, - "column": 50 + "column": 49 } } }, @@ -3089,7 +3089,7 @@ }, "end": { "line": 48, - "column": 58 + "column": 57 } } } @@ -3410,7 +3410,7 @@ }, "end": { "line": 49, - "column": 77 + "column": 76 } } }, @@ -3567,7 +3567,7 @@ }, "end": { "line": 49, - "column": 117 + "column": 116 } } } @@ -4048,7 +4048,7 @@ }, "end": { "line": 50, - "column": 81 + "column": 80 } } }, @@ -4062,7 +4062,7 @@ }, "end": { "line": 50, - "column": 85 + "column": 84 } } } @@ -4074,7 +4074,7 @@ }, "end": { "line": 50, - "column": 86 + "column": 85 } } }, @@ -4093,7 +4093,7 @@ }, "end": { "line": 50, - "column": 96 + "column": 95 } } } @@ -4105,7 +4105,7 @@ }, "end": { "line": 50, - "column": 97 + "column": 96 } } } @@ -4117,7 +4117,7 @@ }, "end": { "line": 50, - "column": 98 + "column": 97 } } } @@ -4436,7 +4436,7 @@ }, "end": { "line": 51, - "column": 44 + "column": 43 } } }, @@ -4495,7 +4495,7 @@ }, "end": { "line": 51, - "column": 63 + "column": 62 } } }, @@ -4508,7 +4508,7 @@ }, "end": { "line": 51, - "column": 71 + "column": 70 } } }, @@ -4521,7 +4521,7 @@ }, "end": { "line": 51, - "column": 79 + "column": 78 } } } diff --git a/es2panda/test/parser/ts/type_checker/arrayDestructuring12-expected.txt b/es2panda/test/parser/ts/type_checker/arrayDestructuring12-expected.txt index 17ef89fd5c..d34db2bbe1 100644 --- a/es2panda/test/parser/ts/type_checker/arrayDestructuring12-expected.txt +++ b/es2panda/test/parser/ts/type_checker/arrayDestructuring12-expected.txt @@ -95,7 +95,7 @@ }, "end": { "line": 17, - "column": 28 + "column": 27 } } }, @@ -108,7 +108,7 @@ }, "end": { "line": 17, - "column": 36 + "column": 35 } } }, @@ -121,7 +121,7 @@ }, "end": { "line": 17, - "column": 45 + "column": 44 } } } diff --git a/es2panda/test/parser/ts/type_checker/arrayDestructuring13-expected.txt b/es2panda/test/parser/ts/type_checker/arrayDestructuring13-expected.txt index c618887393..0761baa416 100644 --- a/es2panda/test/parser/ts/type_checker/arrayDestructuring13-expected.txt +++ b/es2panda/test/parser/ts/type_checker/arrayDestructuring13-expected.txt @@ -21,7 +21,7 @@ }, "end": { "line": 17, - "column": 16 + "column": 15 } } }, @@ -34,7 +34,7 @@ }, "end": { "line": 17, - "column": 24 + "column": 23 } } }, @@ -47,7 +47,7 @@ }, "end": { "line": 17, - "column": 32 + "column": 31 } } } diff --git a/es2panda/test/parser/ts/type_checker/arrayDestructuring15-expected.txt b/es2panda/test/parser/ts/type_checker/arrayDestructuring15-expected.txt index cb1ccc7a92..941bcf4a45 100644 --- a/es2panda/test/parser/ts/type_checker/arrayDestructuring15-expected.txt +++ b/es2panda/test/parser/ts/type_checker/arrayDestructuring15-expected.txt @@ -21,7 +21,7 @@ }, "end": { "line": 17, - "column": 16 + "column": 15 } } } diff --git a/es2panda/test/parser/ts/type_checker/arrayDestructuring16-expected.txt b/es2panda/test/parser/ts/type_checker/arrayDestructuring16-expected.txt index 0a708c25c2..261780eec2 100644 --- a/es2panda/test/parser/ts/type_checker/arrayDestructuring16-expected.txt +++ b/es2panda/test/parser/ts/type_checker/arrayDestructuring16-expected.txt @@ -21,7 +21,7 @@ }, "end": { "line": 17, - "column": 16 + "column": 15 } } } diff --git a/es2panda/test/parser/ts/type_checker/arrayDestructuring17-expected.txt b/es2panda/test/parser/ts/type_checker/arrayDestructuring17-expected.txt index 20dec895eb..a345589dbb 100644 --- a/es2panda/test/parser/ts/type_checker/arrayDestructuring17-expected.txt +++ b/es2panda/test/parser/ts/type_checker/arrayDestructuring17-expected.txt @@ -93,7 +93,7 @@ }, "end": { "line": 17, - "column": 43 + "column": 42 } } }, @@ -106,7 +106,7 @@ }, "end": { "line": 17, - "column": 51 + "column": 50 } } } diff --git a/es2panda/test/parser/ts/type_checker/arrayDestructuring18-expected.txt b/es2panda/test/parser/ts/type_checker/arrayDestructuring18-expected.txt index 77f6869313..0ec15d22da 100644 --- a/es2panda/test/parser/ts/type_checker/arrayDestructuring18-expected.txt +++ b/es2panda/test/parser/ts/type_checker/arrayDestructuring18-expected.txt @@ -53,7 +53,7 @@ }, "end": { "line": 17, - "column": 21 + "column": 20 } } }, @@ -66,7 +66,7 @@ }, "end": { "line": 17, - "column": 29 + "column": 28 } } } @@ -120,7 +120,7 @@ }, "end": { "line": 17, - "column": 52 + "column": 51 } } }, @@ -133,7 +133,7 @@ }, "end": { "line": 17, - "column": 58 + "column": 57 } } }, @@ -147,7 +147,7 @@ }, "end": { "line": 17, - "column": 62 + "column": 61 } } } diff --git a/es2panda/test/parser/ts/type_checker/arrayDestructuring19-expected.txt b/es2panda/test/parser/ts/type_checker/arrayDestructuring19-expected.txt index 206661a324..0fd5d2daa3 100644 --- a/es2panda/test/parser/ts/type_checker/arrayDestructuring19-expected.txt +++ b/es2panda/test/parser/ts/type_checker/arrayDestructuring19-expected.txt @@ -68,7 +68,7 @@ }, "end": { "line": 17, - "column": 24 + "column": 23 } } }, @@ -81,7 +81,7 @@ }, "end": { "line": 17, - "column": 32 + "column": 31 } } } @@ -135,7 +135,7 @@ }, "end": { "line": 17, - "column": 55 + "column": 54 } } }, @@ -148,7 +148,7 @@ }, "end": { "line": 17, - "column": 61 + "column": 60 } } }, @@ -162,7 +162,7 @@ }, "end": { "line": 17, - "column": 65 + "column": 64 } } } diff --git a/es2panda/test/parser/ts/type_checker/arrayDestructuring27-expected.txt b/es2panda/test/parser/ts/type_checker/arrayDestructuring27-expected.txt index 34f429253f..1ca9df943f 100644 --- a/es2panda/test/parser/ts/type_checker/arrayDestructuring27-expected.txt +++ b/es2panda/test/parser/ts/type_checker/arrayDestructuring27-expected.txt @@ -149,7 +149,7 @@ }, "end": { "line": 17, - "column": 41 + "column": 40 } } }, @@ -190,7 +190,7 @@ }, "end": { "line": 17, - "column": 58 + "column": 57 } } } diff --git a/es2panda/test/parser/ts/type_checker/arrayDestructuring4-expected.txt b/es2panda/test/parser/ts/type_checker/arrayDestructuring4-expected.txt index fd2657f8e5..4573dc6ff5 100644 --- a/es2panda/test/parser/ts/type_checker/arrayDestructuring4-expected.txt +++ b/es2panda/test/parser/ts/type_checker/arrayDestructuring4-expected.txt @@ -37,7 +37,7 @@ }, "end": { "line": 17, - "column": 18 + "column": 17 } } }, @@ -50,7 +50,7 @@ }, "end": { "line": 17, - "column": 26 + "column": 25 } } } diff --git a/es2panda/test/parser/ts/type_checker/arrayDestructuring5-expected.txt b/es2panda/test/parser/ts/type_checker/arrayDestructuring5-expected.txt index d16b14b993..93433e43a4 100644 --- a/es2panda/test/parser/ts/type_checker/arrayDestructuring5-expected.txt +++ b/es2panda/test/parser/ts/type_checker/arrayDestructuring5-expected.txt @@ -106,7 +106,7 @@ }, "end": { "line": 17, - "column": 33 + "column": 32 } } }, @@ -119,7 +119,7 @@ }, "end": { "line": 17, - "column": 41 + "column": 40 } } } diff --git a/es2panda/test/parser/ts/type_checker/arrayDestructuring6-expected.txt b/es2panda/test/parser/ts/type_checker/arrayDestructuring6-expected.txt index 90445bd028..574169bfdd 100644 --- a/es2panda/test/parser/ts/type_checker/arrayDestructuring6-expected.txt +++ b/es2panda/test/parser/ts/type_checker/arrayDestructuring6-expected.txt @@ -81,7 +81,7 @@ }, "end": { "line": 17, - "column": 32 + "column": 31 } } }, @@ -94,7 +94,7 @@ }, "end": { "line": 17, - "column": 40 + "column": 39 } } } diff --git a/es2panda/test/parser/ts/type_checker/functionOverload2-expected.txt b/es2panda/test/parser/ts/type_checker/functionOverload2-expected.txt index e0e28b9775..90dcd0e40c 100644 --- a/es2panda/test/parser/ts/type_checker/functionOverload2-expected.txt +++ b/es2panda/test/parser/ts/type_checker/functionOverload2-expected.txt @@ -93,7 +93,7 @@ }, "end": { "line": 17, - "column": 45 + "column": 44 } } }, @@ -106,7 +106,7 @@ }, "end": { "line": 17, - "column": 53 + "column": 52 } } } @@ -236,7 +236,7 @@ }, "end": { "line": 18, - "column": 46 + "column": 45 } } }, @@ -249,7 +249,7 @@ }, "end": { "line": 18, - "column": 54 + "column": 53 } } } @@ -379,7 +379,7 @@ }, "end": { "line": 19, - "column": 46 + "column": 45 } } }, @@ -392,7 +392,7 @@ }, "end": { "line": 19, - "column": 54 + "column": 53 } } } @@ -591,7 +591,7 @@ }, "end": { "line": 20, - "column": 73 + "column": 72 } } }, @@ -604,7 +604,7 @@ }, "end": { "line": 20, - "column": 81 + "column": 80 } } } diff --git a/es2panda/test/parser/ts/type_checker/interfaceAssignment-expected.txt b/es2panda/test/parser/ts/type_checker/interfaceAssignment-expected.txt index 8aa74554e2..b07a122969 100644 --- a/es2panda/test/parser/ts/type_checker/interfaceAssignment-expected.txt +++ b/es2panda/test/parser/ts/type_checker/interfaceAssignment-expected.txt @@ -2369,7 +2369,7 @@ }, "end": { "line": 71, - "column": 16 + "column": 15 } } }, @@ -2382,7 +2382,7 @@ }, "end": { "line": 71, - "column": 24 + "column": 23 } } } diff --git a/es2panda/test/parser/ts/type_checker/interfaceAssignment3-expected.txt b/es2panda/test/parser/ts/type_checker/interfaceAssignment3-expected.txt index 5df9b64a64..689b9ebbe4 100644 --- a/es2panda/test/parser/ts/type_checker/interfaceAssignment3-expected.txt +++ b/es2panda/test/parser/ts/type_checker/interfaceAssignment3-expected.txt @@ -386,7 +386,7 @@ }, "end": { "line": 30, - "column": 16 + "column": 15 } } }, @@ -399,7 +399,7 @@ }, "end": { "line": 30, - "column": 24 + "column": 23 } } } diff --git a/es2panda/test/parser/ts/type_checker/memberExpTests-expected.txt b/es2panda/test/parser/ts/type_checker/memberExpTests-expected.txt index 6f0b1ce2ed..03d7b8e97a 100644 --- a/es2panda/test/parser/ts/type_checker/memberExpTests-expected.txt +++ b/es2panda/test/parser/ts/type_checker/memberExpTests-expected.txt @@ -4677,7 +4677,7 @@ }, "end": { "line": 96, - "column": 36 + "column": 35 } } }, @@ -4690,7 +4690,7 @@ }, "end": { "line": 96, - "column": 44 + "column": 43 } } }, @@ -4703,7 +4703,7 @@ }, "end": { "line": 96, - "column": 52 + "column": 51 } } } diff --git a/es2panda/test/parser/ts/type_checker/objectDestructuring23-expected.txt b/es2panda/test/parser/ts/type_checker/objectDestructuring23-expected.txt index 571f0454aa..4c94ce5b0c 100644 --- a/es2panda/test/parser/ts/type_checker/objectDestructuring23-expected.txt +++ b/es2panda/test/parser/ts/type_checker/objectDestructuring23-expected.txt @@ -67,7 +67,7 @@ }, "end": { "line": 17, - "column": 26 + "column": 25 } } }, @@ -80,7 +80,7 @@ }, "end": { "line": 17, - "column": 34 + "column": 33 } } } diff --git a/es2panda/test/parser/ts/type_checker/objectDestructuring24-expected.txt b/es2panda/test/parser/ts/type_checker/objectDestructuring24-expected.txt index 927c614e68..876eff3598 100644 --- a/es2panda/test/parser/ts/type_checker/objectDestructuring24-expected.txt +++ b/es2panda/test/parser/ts/type_checker/objectDestructuring24-expected.txt @@ -139,7 +139,7 @@ }, "end": { "line": 17, - "column": 46 + "column": 45 } } }, @@ -165,7 +165,7 @@ }, "end": { "line": 17, - "column": 57 + "column": 56 } } } diff --git a/es2panda/test/parser/ts/type_checker/objectDestructuring25-expected.txt b/es2panda/test/parser/ts/type_checker/objectDestructuring25-expected.txt index 6d2874ba30..bb41fbdf51 100644 --- a/es2panda/test/parser/ts/type_checker/objectDestructuring25-expected.txt +++ b/es2panda/test/parser/ts/type_checker/objectDestructuring25-expected.txt @@ -145,7 +145,7 @@ }, "end": { "line": 17, - "column": 50 + "column": 49 } } }, @@ -158,7 +158,7 @@ }, "end": { "line": 17, - "column": 58 + "column": 57 } } } diff --git a/es2panda/test/parser/ts/type_checker/objectLiteralAssignability-expected.txt b/es2panda/test/parser/ts/type_checker/objectLiteralAssignability-expected.txt index 9d55aed3b3..eeb880e0da 100644 --- a/es2panda/test/parser/ts/type_checker/objectLiteralAssignability-expected.txt +++ b/es2panda/test/parser/ts/type_checker/objectLiteralAssignability-expected.txt @@ -6675,7 +6675,7 @@ }, "end": { "line": 69, - "column": 36 + "column": 35 } } }, @@ -6688,7 +6688,7 @@ }, "end": { "line": 69, - "column": 44 + "column": 43 } } }, @@ -6701,7 +6701,7 @@ }, "end": { "line": 69, - "column": 52 + "column": 51 } } } 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 b982eec261..84cd0798c9 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 @@ -699,7 +699,7 @@ }, "end": { "line": 19, - "column": 66 + "column": 65 } } } diff --git a/es2panda/test/parser/ts/type_checker/tupleAssignability-expected.txt b/es2panda/test/parser/ts/type_checker/tupleAssignability-expected.txt index 8225600c82..1dde88edcb 100644 --- a/es2panda/test/parser/ts/type_checker/tupleAssignability-expected.txt +++ b/es2panda/test/parser/ts/type_checker/tupleAssignability-expected.txt @@ -97,7 +97,7 @@ }, "end": { "line": 18, - "column": 18 + "column": 17 } } } @@ -109,7 +109,7 @@ }, "end": { "line": 18, - "column": 19 + "column": 18 } } } @@ -225,7 +225,7 @@ }, "end": { "line": 19, - "column": 21 + "column": 20 } } }, @@ -238,7 +238,7 @@ }, "end": { "line": 19, - "column": 29 + "column": 28 } } }, @@ -251,7 +251,7 @@ }, "end": { "line": 19, - "column": 37 + "column": 36 } } } @@ -395,7 +395,7 @@ }, "end": { "line": 20, - "column": 28 + "column": 27 } } }, @@ -408,7 +408,7 @@ }, "end": { "line": 20, - "column": 36 + "column": 35 } } } @@ -554,7 +554,7 @@ }, "end": { "line": 21, - "column": 25 + "column": 24 } } }, @@ -596,7 +596,7 @@ }, "end": { "line": 21, - "column": 37 + "column": 36 } } } @@ -608,7 +608,7 @@ }, "end": { "line": 21, - "column": 38 + "column": 37 } } }, @@ -652,7 +652,7 @@ }, "end": { "line": 21, - "column": 57 + "column": 56 } } }, @@ -678,7 +678,7 @@ }, "end": { "line": 21, - "column": 67 + "column": 66 } } } @@ -690,7 +690,7 @@ }, "end": { "line": 21, - "column": 68 + "column": 67 } } } @@ -895,7 +895,7 @@ }, "end": { "line": 23, - "column": 21 + "column": 20 } } } @@ -923,7 +923,7 @@ }, "end": { "line": 23, - "column": 32 + "column": 31 } } } @@ -1039,7 +1039,7 @@ }, "end": { "line": 24, - "column": 21 + "column": 20 } } }, @@ -1052,7 +1052,7 @@ }, "end": { "line": 24, - "column": 29 + "column": 28 } } } @@ -1365,7 +1365,7 @@ }, "end": { "line": 25, - "column": 62 + "column": 61 } } }, @@ -1406,7 +1406,7 @@ }, "end": { "line": 25, - "column": 79 + "column": 78 } } } @@ -1626,7 +1626,7 @@ }, "end": { "line": 27, - "column": 21 + "column": 20 } } }, @@ -1667,7 +1667,7 @@ }, "end": { "line": 27, - "column": 38 + "column": 37 } } }, @@ -1708,7 +1708,7 @@ }, "end": { "line": 27, - "column": 56 + "column": 55 } } } @@ -1781,7 +1781,7 @@ }, "end": { "line": 28, - "column": 22 + "column": 21 } } }, @@ -1794,7 +1794,7 @@ }, "end": { "line": 28, - "column": 30 + "column": 29 } } }, @@ -1807,7 +1807,7 @@ }, "end": { "line": 28, - "column": 38 + "column": 37 } } } @@ -1908,7 +1908,7 @@ }, "end": { "line": 29, - "column": 25 + "column": 24 } } }, @@ -1977,7 +1977,7 @@ }, "end": { "line": 29, - "column": 45 + "column": 44 } } }, @@ -2018,7 +2018,7 @@ }, "end": { "line": 29, - "column": 57 + "column": 56 } } } @@ -2119,7 +2119,7 @@ }, "end": { "line": 30, - "column": 25 + "column": 24 } } }, @@ -2160,7 +2160,7 @@ }, "end": { "line": 30, - "column": 36 + "column": 35 } } }, @@ -2201,7 +2201,7 @@ }, "end": { "line": 30, - "column": 48 + "column": 47 } } }, @@ -2243,7 +2243,7 @@ }, "end": { "line": 30, - "column": 57 + "column": 56 } } } @@ -2345,7 +2345,7 @@ }, "end": { "line": 31, - "column": 26 + "column": 25 } } }, @@ -2387,7 +2387,7 @@ }, "end": { "line": 31, - "column": 38 + "column": 37 } } }, @@ -2429,7 +2429,7 @@ }, "end": { "line": 31, - "column": 50 + "column": 49 } } } @@ -2994,7 +2994,7 @@ }, "end": { "line": 40, - "column": 63 + "column": 62 } } }, @@ -3007,7 +3007,7 @@ }, "end": { "line": 40, - "column": 71 + "column": 70 } } } @@ -3046,7 +3046,7 @@ }, "end": { "line": 40, - "column": 72 + "column": 71 } } }, @@ -3092,7 +3092,7 @@ }, "end": { "line": 40, - "column": 88 + "column": 87 } } }, @@ -3147,7 +3147,7 @@ }, "end": { "line": 40, - "column": 103 + "column": 102 } } } @@ -3186,7 +3186,7 @@ }, "end": { "line": 40, - "column": 104 + "column": 103 } } }, @@ -3228,7 +3228,7 @@ }, "end": { "line": 40, - "column": 117 + "column": 116 } } } @@ -4042,7 +4042,7 @@ }, "end": { "line": 47, - "column": 50 + "column": 49 } } }, @@ -4097,7 +4097,7 @@ }, "end": { "line": 47, - "column": 65 + "column": 64 } } } @@ -4136,7 +4136,7 @@ }, "end": { "line": 48, - "column": 26 + "column": 25 } } } @@ -4357,7 +4357,7 @@ }, "end": { "line": 53, - "column": 30 + "column": 29 } } }, @@ -4385,7 +4385,7 @@ }, "end": { "line": 53, - "column": 45 + "column": 44 } } }, @@ -4398,7 +4398,7 @@ }, "end": { "line": 53, - "column": 53 + "column": 52 } } } @@ -4532,7 +4532,7 @@ }, "end": { "line": 55, - "column": 47 + "column": 46 } } }, @@ -4545,7 +4545,7 @@ }, "end": { "line": 55, - "column": 56 + "column": 55 } } } @@ -4602,7 +4602,7 @@ }, "end": { "line": 55, - "column": 73 + "column": 72 } } }, @@ -4615,7 +4615,7 @@ }, "end": { "line": 55, - "column": 81 + "column": 80 } } } @@ -5502,7 +5502,7 @@ }, "end": { "line": 66, - "column": 22 + "column": 21 } } }, @@ -5515,7 +5515,7 @@ }, "end": { "line": 66, - "column": 30 + "column": 29 } } } @@ -5543,7 +5543,7 @@ }, "end": { "line": 66, - "column": 41 + "column": 40 } } }, @@ -5556,7 +5556,7 @@ }, "end": { "line": 66, - "column": 49 + "column": 48 } } } @@ -5669,7 +5669,7 @@ }, "end": { "line": 67, - "column": 25 + "column": 24 } } }, @@ -5710,7 +5710,7 @@ }, "end": { "line": 67, - "column": 36 + "column": 35 } } }, @@ -5752,7 +5752,7 @@ }, "end": { "line": 67, - "column": 49 + "column": 48 } } } @@ -5897,7 +5897,7 @@ }, "end": { "line": 68, - "column": 51 + "column": 50 } } }, @@ -5938,7 +5938,7 @@ }, "end": { "line": 68, - "column": 62 + "column": 61 } } } @@ -6023,7 +6023,7 @@ }, "end": { "line": 69, - "column": 22 + "column": 21 } } }, @@ -6036,7 +6036,7 @@ }, "end": { "line": 69, - "column": 30 + "column": 29 } } } @@ -6226,7 +6226,7 @@ }, "end": { "line": 73, - "column": 22 + "column": 21 } } }, @@ -6239,7 +6239,7 @@ }, "end": { "line": 73, - "column": 30 + "column": 29 } } }, @@ -6252,7 +6252,7 @@ }, "end": { "line": 73, - "column": 38 + "column": 37 } } } @@ -6280,7 +6280,7 @@ }, "end": { "line": 73, - "column": 49 + "column": 48 } } }, @@ -6293,7 +6293,7 @@ }, "end": { "line": 73, - "column": 57 + "column": 56 } } }, @@ -6306,7 +6306,7 @@ }, "end": { "line": 73, - "column": 65 + "column": 64 } } }, @@ -6319,7 +6319,7 @@ }, "end": { "line": 73, - "column": 73 + "column": 72 } } } @@ -6700,7 +6700,7 @@ }, "end": { "line": 77, - "column": 49 + "column": 48 } } }, @@ -6713,7 +6713,7 @@ }, "end": { "line": 77, - "column": 57 + "column": 56 } } } @@ -6725,7 +6725,7 @@ }, "end": { "line": 77, - "column": 58 + "column": 57 } } }, @@ -6741,7 +6741,7 @@ }, "end": { "line": 77, - "column": 67 + "column": 66 } } }, @@ -6754,7 +6754,7 @@ }, "end": { "line": 77, - "column": 75 + "column": 74 } } } @@ -6766,7 +6766,7 @@ }, "end": { "line": 77, - "column": 76 + "column": 75 } } } @@ -7251,7 +7251,7 @@ }, "end": { "line": 82, - "column": 33 + "column": 32 } } }, @@ -7264,7 +7264,7 @@ }, "end": { "line": 82, - "column": 41 + "column": 40 } } } diff --git a/es2panda/test/parser/ts/type_checker/tupleAssignability10-expected.txt b/es2panda/test/parser/ts/type_checker/tupleAssignability10-expected.txt index fab701bc9e..8e0a7ec1e5 100644 --- a/es2panda/test/parser/ts/type_checker/tupleAssignability10-expected.txt +++ b/es2panda/test/parser/ts/type_checker/tupleAssignability10-expected.txt @@ -36,7 +36,7 @@ }, "end": { "line": 17, - "column": 23 + "column": 22 } } }, @@ -49,7 +49,7 @@ }, "end": { "line": 17, - "column": 31 + "column": 30 } } } diff --git a/es2panda/test/parser/ts/type_checker/tupleAssignability11-expected.txt b/es2panda/test/parser/ts/type_checker/tupleAssignability11-expected.txt index 2a4a99e04d..232430f442 100644 --- a/es2panda/test/parser/ts/type_checker/tupleAssignability11-expected.txt +++ b/es2panda/test/parser/ts/type_checker/tupleAssignability11-expected.txt @@ -81,7 +81,7 @@ }, "end": { "line": 18, - "column": 12 + "column": 11 } } } diff --git a/es2panda/test/parser/ts/type_checker/tupleAssignability12-expected.txt b/es2panda/test/parser/ts/type_checker/tupleAssignability12-expected.txt index e930d5c202..d3e876743b 100644 --- a/es2panda/test/parser/ts/type_checker/tupleAssignability12-expected.txt +++ b/es2panda/test/parser/ts/type_checker/tupleAssignability12-expected.txt @@ -49,7 +49,7 @@ }, "end": { "line": 17, - "column": 19 + "column": 18 } } }, @@ -90,7 +90,7 @@ }, "end": { "line": 17, - "column": 30 + "column": 29 } } }, @@ -132,7 +132,7 @@ }, "end": { "line": 17, - "column": 42 + "column": 41 } } } @@ -233,7 +233,7 @@ }, "end": { "line": 18, - "column": 19 + "column": 18 } } }, @@ -274,7 +274,7 @@ }, "end": { "line": 18, - "column": 30 + "column": 29 } } }, @@ -315,7 +315,7 @@ }, "end": { "line": 18, - "column": 41 + "column": 40 } } }, @@ -356,7 +356,7 @@ }, "end": { "line": 18, - "column": 52 + "column": 51 } } } diff --git a/es2panda/test/parser/ts/type_checker/tupleAssignability13-expected.txt b/es2panda/test/parser/ts/type_checker/tupleAssignability13-expected.txt index 229790ab7a..5a43e0365c 100644 --- a/es2panda/test/parser/ts/type_checker/tupleAssignability13-expected.txt +++ b/es2panda/test/parser/ts/type_checker/tupleAssignability13-expected.txt @@ -21,7 +21,7 @@ }, "end": { "line": 17, - "column": 16 + "column": 15 } } }, @@ -34,7 +34,7 @@ }, "end": { "line": 17, - "column": 24 + "column": 23 } } }, @@ -47,7 +47,7 @@ }, "end": { "line": 17, - "column": 32 + "column": 31 } } } diff --git a/es2panda/test/parser/ts/type_checker/tupleAssignability15-expected.txt b/es2panda/test/parser/ts/type_checker/tupleAssignability15-expected.txt index d58442c37c..b9946ff2a9 100644 --- a/es2panda/test/parser/ts/type_checker/tupleAssignability15-expected.txt +++ b/es2panda/test/parser/ts/type_checker/tupleAssignability15-expected.txt @@ -21,7 +21,7 @@ }, "end": { "line": 17, - "column": 16 + "column": 15 } } }, @@ -34,7 +34,7 @@ }, "end": { "line": 17, - "column": 24 + "column": 23 } } }, @@ -47,7 +47,7 @@ }, "end": { "line": 17, - "column": 32 + "column": 31 } } } diff --git a/es2panda/test/parser/ts/type_checker/tupleAssignability16-expected.txt b/es2panda/test/parser/ts/type_checker/tupleAssignability16-expected.txt index 9c79280695..c6e240b9bf 100644 --- a/es2panda/test/parser/ts/type_checker/tupleAssignability16-expected.txt +++ b/es2panda/test/parser/ts/type_checker/tupleAssignability16-expected.txt @@ -34,7 +34,7 @@ }, "end": { "line": 17, - "column": 18 + "column": 17 } } }, @@ -60,7 +60,7 @@ }, "end": { "line": 17, - "column": 28 + "column": 27 } } } diff --git a/es2panda/test/parser/ts/type_checker/tupleAssignability17-expected.txt b/es2panda/test/parser/ts/type_checker/tupleAssignability17-expected.txt index 7bfefd46a3..ecb4531cdb 100644 --- a/es2panda/test/parser/ts/type_checker/tupleAssignability17-expected.txt +++ b/es2panda/test/parser/ts/type_checker/tupleAssignability17-expected.txt @@ -21,7 +21,7 @@ }, "end": { "line": 17, - "column": 16 + "column": 15 } } }, @@ -34,7 +34,7 @@ }, "end": { "line": 17, - "column": 24 + "column": 23 } } } @@ -237,7 +237,7 @@ }, "end": { "line": 19, - "column": 26 + "column": 25 } } }, @@ -250,7 +250,7 @@ }, "end": { "line": 19, - "column": 34 + "column": 33 } } }, @@ -263,7 +263,7 @@ }, "end": { "line": 19, - "column": 42 + "column": 41 } } } diff --git a/es2panda/test/parser/ts/type_checker/tupleAssignability18-expected.txt b/es2panda/test/parser/ts/type_checker/tupleAssignability18-expected.txt index a5cbc53f9a..6b78712229 100644 --- a/es2panda/test/parser/ts/type_checker/tupleAssignability18-expected.txt +++ b/es2panda/test/parser/ts/type_checker/tupleAssignability18-expected.txt @@ -54,7 +54,7 @@ }, "end": { "line": 16, - "column": 24 + "column": 23 } } }, @@ -96,7 +96,7 @@ }, "end": { "line": 16, - "column": 36 + "column": 35 } } } @@ -135,7 +135,7 @@ }, "end": { "line": 16, - "column": 37 + "column": 36 } } }, @@ -181,7 +181,7 @@ }, "end": { "line": 16, - "column": 59 + "column": 58 } } } @@ -220,7 +220,7 @@ }, "end": { "line": 16, - "column": 60 + "column": 59 } } }, @@ -277,7 +277,7 @@ }, "end": { "line": 16, - "column": 74 + "column": 73 } } } @@ -502,7 +502,7 @@ }, "end": { "line": 17, - "column": 18 + "column": 17 } } } @@ -514,7 +514,7 @@ }, "end": { "line": 17, - "column": 19 + "column": 18 } } } @@ -526,7 +526,7 @@ }, "end": { "line": 17, - "column": 20 + "column": 19 } } } @@ -671,7 +671,7 @@ }, "end": { "line": 19, - "column": 46 + "column": 45 } } } diff --git a/es2panda/test/parser/ts/type_checker/tupleAssignability19-expected.txt b/es2panda/test/parser/ts/type_checker/tupleAssignability19-expected.txt index e9d768f19e..f314840647 100644 --- a/es2panda/test/parser/ts/type_checker/tupleAssignability19-expected.txt +++ b/es2panda/test/parser/ts/type_checker/tupleAssignability19-expected.txt @@ -24,7 +24,7 @@ }, "end": { "line": 17, - "column": 16 + "column": 15 } } } @@ -52,7 +52,7 @@ }, "end": { "line": 17, - "column": 27 + "column": 26 } } } diff --git a/es2panda/test/parser/ts/type_checker/tupleAssignability2-expected.txt b/es2panda/test/parser/ts/type_checker/tupleAssignability2-expected.txt index 8995836528..88719da8e3 100644 --- a/es2panda/test/parser/ts/type_checker/tupleAssignability2-expected.txt +++ b/es2panda/test/parser/ts/type_checker/tupleAssignability2-expected.txt @@ -21,7 +21,7 @@ }, "end": { "line": 17, - "column": 16 + "column": 15 } } }, @@ -34,7 +34,7 @@ }, "end": { "line": 17, - "column": 24 + "column": 23 } } } diff --git a/es2panda/test/parser/ts/type_checker/tupleAssignability20-expected.txt b/es2panda/test/parser/ts/type_checker/tupleAssignability20-expected.txt index 7ff77df587..d04b61cf30 100644 --- a/es2panda/test/parser/ts/type_checker/tupleAssignability20-expected.txt +++ b/es2panda/test/parser/ts/type_checker/tupleAssignability20-expected.txt @@ -50,7 +50,7 @@ }, "end": { "line": 17, - "column": 27 + "column": 26 } } }, @@ -63,7 +63,7 @@ }, "end": { "line": 17, - "column": 35 + "column": 34 } } } diff --git a/es2panda/test/parser/ts/type_checker/tupleAssignability21-expected.txt b/es2panda/test/parser/ts/type_checker/tupleAssignability21-expected.txt index 06397b7a4d..31da016982 100644 --- a/es2panda/test/parser/ts/type_checker/tupleAssignability21-expected.txt +++ b/es2panda/test/parser/ts/type_checker/tupleAssignability21-expected.txt @@ -24,7 +24,7 @@ }, "end": { "line": 17, - "column": 16 + "column": 15 } } }, @@ -37,7 +37,7 @@ }, "end": { "line": 17, - "column": 24 + "column": 23 } } } @@ -65,7 +65,7 @@ }, "end": { "line": 17, - "column": 35 + "column": 34 } } }, @@ -78,7 +78,7 @@ }, "end": { "line": 17, - "column": 43 + "column": 42 } } }, @@ -91,7 +91,7 @@ }, "end": { "line": 17, - "column": 51 + "column": 50 } } } diff --git a/es2panda/test/parser/ts/type_checker/tupleAssignability22-expected.txt b/es2panda/test/parser/ts/type_checker/tupleAssignability22-expected.txt index 5b2bb31018..d20f35f39f 100644 --- a/es2panda/test/parser/ts/type_checker/tupleAssignability22-expected.txt +++ b/es2panda/test/parser/ts/type_checker/tupleAssignability22-expected.txt @@ -24,7 +24,7 @@ }, "end": { "line": 17, - "column": 16 + "column": 15 } } }, @@ -37,7 +37,7 @@ }, "end": { "line": 17, - "column": 24 + "column": 23 } } } diff --git a/es2panda/test/parser/ts/type_checker/tupleAssignability23-expected.txt b/es2panda/test/parser/ts/type_checker/tupleAssignability23-expected.txt index 376f24f06b..ffbdad77cb 100644 --- a/es2panda/test/parser/ts/type_checker/tupleAssignability23-expected.txt +++ b/es2panda/test/parser/ts/type_checker/tupleAssignability23-expected.txt @@ -24,7 +24,7 @@ }, "end": { "line": 17, - "column": 17 + "column": 16 } } }, @@ -37,7 +37,7 @@ }, "end": { "line": 17, - "column": 25 + "column": 24 } } } @@ -49,7 +49,7 @@ }, "end": { "line": 17, - "column": 26 + "column": 25 } } }, @@ -65,7 +65,7 @@ }, "end": { "line": 17, - "column": 35 + "column": 34 } } }, @@ -78,7 +78,7 @@ }, "end": { "line": 17, - "column": 43 + "column": 42 } } } @@ -90,7 +90,7 @@ }, "end": { "line": 17, - "column": 44 + "column": 43 } } } diff --git a/es2panda/test/parser/ts/type_checker/tupleAssignability24-expected.txt b/es2panda/test/parser/ts/type_checker/tupleAssignability24-expected.txt index b048ecbd21..10a93bc586 100644 --- a/es2panda/test/parser/ts/type_checker/tupleAssignability24-expected.txt +++ b/es2panda/test/parser/ts/type_checker/tupleAssignability24-expected.txt @@ -24,7 +24,7 @@ }, "end": { "line": 17, - "column": 16 + "column": 15 } } }, @@ -37,7 +37,7 @@ }, "end": { "line": 17, - "column": 24 + "column": 23 } } }, @@ -50,7 +50,7 @@ }, "end": { "line": 17, - "column": 32 + "column": 31 } } } @@ -164,7 +164,7 @@ }, "end": { "line": 18, - "column": 16 + "column": 15 } } }, @@ -177,7 +177,7 @@ }, "end": { "line": 18, - "column": 24 + "column": 23 } } }, @@ -190,7 +190,7 @@ }, "end": { "line": 18, - "column": 32 + "column": 31 } } }, @@ -203,7 +203,7 @@ }, "end": { "line": 18, - "column": 40 + "column": 39 } } } diff --git a/es2panda/test/parser/ts/type_checker/tupleAssignability3-expected.txt b/es2panda/test/parser/ts/type_checker/tupleAssignability3-expected.txt index 90960da60e..a1b5c6b9e0 100644 --- a/es2panda/test/parser/ts/type_checker/tupleAssignability3-expected.txt +++ b/es2panda/test/parser/ts/type_checker/tupleAssignability3-expected.txt @@ -21,7 +21,7 @@ }, "end": { "line": 17, - "column": 16 + "column": 15 } } }, @@ -34,7 +34,7 @@ }, "end": { "line": 17, - "column": 24 + "column": 23 } } }, @@ -47,7 +47,7 @@ }, "end": { "line": 17, - "column": 32 + "column": 31 } } } diff --git a/es2panda/test/parser/ts/type_checker/tupleAssignability4-expected.txt b/es2panda/test/parser/ts/type_checker/tupleAssignability4-expected.txt index 5bb14fc852..eefbe2fc77 100644 --- a/es2panda/test/parser/ts/type_checker/tupleAssignability4-expected.txt +++ b/es2panda/test/parser/ts/type_checker/tupleAssignability4-expected.txt @@ -21,7 +21,7 @@ }, "end": { "line": 17, - "column": 16 + "column": 15 } } }, @@ -34,7 +34,7 @@ }, "end": { "line": 17, - "column": 24 + "column": 23 } } } @@ -107,7 +107,7 @@ }, "end": { "line": 18, - "column": 16 + "column": 15 } } }, @@ -120,7 +120,7 @@ }, "end": { "line": 18, - "column": 24 + "column": 23 } } } diff --git a/es2panda/test/parser/ts/type_checker/tupleAssignability5-expected.txt b/es2panda/test/parser/ts/type_checker/tupleAssignability5-expected.txt index 519b07fa0d..7e72bd6578 100644 --- a/es2panda/test/parser/ts/type_checker/tupleAssignability5-expected.txt +++ b/es2panda/test/parser/ts/type_checker/tupleAssignability5-expected.txt @@ -21,7 +21,7 @@ }, "end": { "line": 17, - "column": 16 + "column": 15 } } }, @@ -34,7 +34,7 @@ }, "end": { "line": 17, - "column": 24 + "column": 23 } } } diff --git a/es2panda/test/parser/ts/type_checker/tupleAssignability6-expected.txt b/es2panda/test/parser/ts/type_checker/tupleAssignability6-expected.txt index 3bc4258f37..bb5579aac6 100644 --- a/es2panda/test/parser/ts/type_checker/tupleAssignability6-expected.txt +++ b/es2panda/test/parser/ts/type_checker/tupleAssignability6-expected.txt @@ -52,7 +52,7 @@ }, "end": { "line": 17, - "column": 20 + "column": 19 } } }, @@ -94,7 +94,7 @@ }, "end": { "line": 17, - "column": 32 + "column": 31 } } } @@ -106,7 +106,7 @@ }, "end": { "line": 17, - "column": 33 + "column": 32 } } }, @@ -150,7 +150,7 @@ }, "end": { "line": 17, - "column": 52 + "column": 51 } } }, @@ -176,7 +176,7 @@ }, "end": { "line": 17, - "column": 62 + "column": 61 } } } @@ -188,7 +188,7 @@ }, "end": { "line": 17, - "column": 63 + "column": 62 } } } diff --git a/es2panda/test/parser/ts/type_checker/tupleAssignability7-expected.txt b/es2panda/test/parser/ts/type_checker/tupleAssignability7-expected.txt index 25e8e2aad4..efcfc4bcf1 100644 --- a/es2panda/test/parser/ts/type_checker/tupleAssignability7-expected.txt +++ b/es2panda/test/parser/ts/type_checker/tupleAssignability7-expected.txt @@ -52,7 +52,7 @@ }, "end": { "line": 17, - "column": 20 + "column": 19 } } }, @@ -94,7 +94,7 @@ }, "end": { "line": 17, - "column": 32 + "column": 31 } } } @@ -106,7 +106,7 @@ }, "end": { "line": 17, - "column": 33 + "column": 32 } } }, @@ -150,7 +150,7 @@ }, "end": { "line": 17, - "column": 52 + "column": 51 } } }, @@ -176,7 +176,7 @@ }, "end": { "line": 17, - "column": 62 + "column": 61 } } } @@ -188,7 +188,7 @@ }, "end": { "line": 17, - "column": 63 + "column": 62 } } } diff --git a/es2panda/test/parser/ts/type_checker/tupleAssignability8-expected.txt b/es2panda/test/parser/ts/type_checker/tupleAssignability8-expected.txt index dc38074f31..635194598f 100644 --- a/es2panda/test/parser/ts/type_checker/tupleAssignability8-expected.txt +++ b/es2panda/test/parser/ts/type_checker/tupleAssignability8-expected.txt @@ -21,7 +21,7 @@ }, "end": { "line": 17, - "column": 16 + "column": 15 } } }, @@ -34,7 +34,7 @@ }, "end": { "line": 17, - "column": 24 + "column": 23 } } }, @@ -47,7 +47,7 @@ }, "end": { "line": 17, - "column": 33 + "column": 32 } } }, @@ -60,7 +60,7 @@ }, "end": { "line": 17, - "column": 41 + "column": 40 } } }, @@ -73,7 +73,7 @@ }, "end": { "line": 17, - "column": 49 + "column": 48 } } } diff --git a/es2panda/test/parser/ts/type_checker/tupleAssignability9-expected.txt b/es2panda/test/parser/ts/type_checker/tupleAssignability9-expected.txt index 7cc4abea32..de9f2473eb 100644 --- a/es2panda/test/parser/ts/type_checker/tupleAssignability9-expected.txt +++ b/es2panda/test/parser/ts/type_checker/tupleAssignability9-expected.txt @@ -21,7 +21,7 @@ }, "end": { "line": 17, - "column": 16 + "column": 15 } } }, @@ -34,7 +34,7 @@ }, "end": { "line": 17, - "column": 24 + "column": 23 } } } @@ -122,7 +122,7 @@ }, "end": { "line": 19, - "column": 23 + "column": 22 } } }, @@ -135,7 +135,7 @@ }, "end": { "line": 19, - "column": 31 + "column": 30 } } } diff --git a/es2panda/test/parser/ts/type_checker/typeAliasUsedAsValue-expected.txt b/es2panda/test/parser/ts/type_checker/typeAliasUsedAsValue-expected.txt index 1e0d42f3ff..641a5c0e37 100644 --- a/es2panda/test/parser/ts/type_checker/typeAliasUsedAsValue-expected.txt +++ b/es2panda/test/parser/ts/type_checker/typeAliasUsedAsValue-expected.txt @@ -149,7 +149,7 @@ }, "end": { "line": 17, - "column": 55 + "column": 54 } } }, @@ -162,7 +162,7 @@ }, "end": { "line": 17, - "column": 63 + "column": 62 } } }, @@ -175,7 +175,7 @@ }, "end": { "line": 17, - "column": 71 + "column": 70 } } } diff --git a/es2panda/test/parser/ts/type_checker/varRedeclaration-expected.txt b/es2panda/test/parser/ts/type_checker/varRedeclaration-expected.txt index a18fe84cd5..9f3c7ef5c2 100644 --- a/es2panda/test/parser/ts/type_checker/varRedeclaration-expected.txt +++ b/es2panda/test/parser/ts/type_checker/varRedeclaration-expected.txt @@ -5575,7 +5575,7 @@ }, "end": { "line": 94, - "column": 19 + "column": 18 } } }, @@ -5616,7 +5616,7 @@ }, "end": { "line": 94, - "column": 30 + "column": 29 } } }, @@ -5657,7 +5657,7 @@ }, "end": { "line": 94, - "column": 42 + "column": 41 } } } @@ -5730,7 +5730,7 @@ }, "end": { "line": 95, - "column": 16 + "column": 15 } } }, @@ -5743,7 +5743,7 @@ }, "end": { "line": 95, - "column": 24 + "column": 23 } } }, @@ -5756,7 +5756,7 @@ }, "end": { "line": 95, - "column": 33 + "column": 32 } } } @@ -5872,7 +5872,7 @@ }, "end": { "line": 97, - "column": 22 + "column": 21 } } }, @@ -5899,7 +5899,7 @@ }, "end": { "line": 97, - "column": 25 + "column": 24 } } }, @@ -5926,7 +5926,7 @@ }, "end": { "line": 97, - "column": 28 + "column": 27 } } } @@ -6028,7 +6028,7 @@ }, "end": { "line": 98, - "column": 11 + "column": 10 } } }, @@ -6055,7 +6055,7 @@ }, "end": { "line": 98, - "column": 14 + "column": 13 } } }, @@ -6082,7 +6082,7 @@ }, "end": { "line": 98, - "column": 17 + "column": 16 } } } diff --git a/es2panda/test/parser/ts/type_checker/varRedeclaration6-expected.txt b/es2panda/test/parser/ts/type_checker/varRedeclaration6-expected.txt index 9619ac59c8..99b307b72e 100644 --- a/es2panda/test/parser/ts/type_checker/varRedeclaration6-expected.txt +++ b/es2panda/test/parser/ts/type_checker/varRedeclaration6-expected.txt @@ -21,7 +21,7 @@ }, "end": { "line": 17, - "column": 16 + "column": 15 } } }, @@ -34,7 +34,7 @@ }, "end": { "line": 17, - "column": 24 + "column": 23 } } }, @@ -47,7 +47,7 @@ }, "end": { "line": 17, - "column": 32 + "column": 31 } } } @@ -148,7 +148,7 @@ }, "end": { "line": 18, - "column": 19 + "column": 18 } } }, @@ -189,7 +189,7 @@ }, "end": { "line": 18, - "column": 30 + "column": 29 } } }, @@ -231,7 +231,7 @@ }, "end": { "line": 18, - "column": 42 + "column": 41 } } } diff --git a/es2panda/typescript/checker.h b/es2panda/typescript/checker.h index 734017f290..b2da9878e9 100644 --- a/es2panda/typescript/checker.h +++ b/es2panda/typescript/checker.h @@ -152,6 +152,11 @@ public: return globalTypes_->GlobalStringType(); } + Type *GlobalSymbolType() + { + return globalTypes_->GlobalSymbolType(); + } + Type *GlobalBooleanType() { return globalTypes_->GlobalBooleanType(); diff --git a/es2panda/typescript/types/globalTypesHolder.cpp b/es2panda/typescript/types/globalTypesHolder.cpp index b3078e90bc..3092855603 100644 --- a/es2panda/typescript/types/globalTypesHolder.cpp +++ b/es2panda/typescript/types/globalTypesHolder.cpp @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include @@ -41,6 +42,7 @@ GlobalTypesHolder::GlobalTypesHolder(ArenaAllocator *allocator) globalTypes_[static_cast(GlobalTypeId::NUMBER)] = allocator->New(); globalTypes_[static_cast(GlobalTypeId::ANY)] = allocator->New(); globalTypes_[static_cast(GlobalTypeId::STRING)] = allocator->New(); + globalTypes_[static_cast(GlobalTypeId::SYMBOL)] = allocator->New(); globalTypes_[static_cast(GlobalTypeId::BOOLEAN)] = allocator->New(); globalTypes_[static_cast(GlobalTypeId::VOID)] = allocator->New(); globalTypes_[static_cast(GlobalTypeId::NULL_ID)] = allocator->New(); @@ -61,7 +63,7 @@ GlobalTypesHolder::GlobalTypesHolder(ArenaAllocator *allocator) globalTypes_[static_cast(GlobalTypeId::PRIMITIVE)] = allocator->New( allocator, std::initializer_list {GlobalNumberType(), GlobalStringType(), GlobalBigintType(), GlobalBooleanType(), - GlobalVoidType(), GlobalUndefinedType(), GlobalNullType()}); + GlobalVoidType(), GlobalUndefinedType(), GlobalNullType(), GlobalSymbolType()}); globalTypes_[static_cast(GlobalTypeId::EMPTY_TUPLE)] = allocator->New(allocator); globalTypes_[static_cast(GlobalTypeId::EMPTY_OBJECT)] = allocator->New(); globalTypes_[static_cast(GlobalTypeId::RESOLVING_RETURN_TYPE)] = allocator->New(); @@ -83,6 +85,11 @@ Type *GlobalTypesHolder::GlobalStringType() return globalTypes_.at(static_cast(GlobalTypeId::STRING)); } +Type *GlobalTypesHolder::GlobalSymbolType() +{ + return globalTypes_.at(static_cast(GlobalTypeId::SYMBOL)); +} + Type *GlobalTypesHolder::GlobalBooleanType() { return globalTypes_.at(static_cast(GlobalTypeId::BOOLEAN)); diff --git a/es2panda/typescript/types/globalTypesHolder.h b/es2panda/typescript/types/globalTypesHolder.h index fefecfa2e5..68b13c3537 100644 --- a/es2panda/typescript/types/globalTypesHolder.h +++ b/es2panda/typescript/types/globalTypesHolder.h @@ -24,6 +24,7 @@ enum class GlobalTypeId { NUMBER, ANY, STRING, + SYMBOL, BOOLEAN, VOID, NULL_ID, @@ -57,6 +58,7 @@ public: Type *GlobalNumberType(); Type *GlobalAnyType(); Type *GlobalStringType(); + Type *GlobalSymbolType(); Type *GlobalBooleanType(); Type *GlobalVoidType(); Type *GlobalNullType(); diff --git a/es2panda/typescript/types/symbolType.cpp b/es2panda/typescript/types/symbolType.cpp new file mode 100644 index 0000000000..65d1ce5fe3 --- /dev/null +++ b/es2panda/typescript/types/symbolType.cpp @@ -0,0 +1,50 @@ +/* + * 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. + */ + +#include "symbolType.h" + +namespace panda::es2panda::checker { + +void SymbolType::ToString(std::stringstream &ss) const +{ + ss << "symbol"; +} + +void SymbolType::Identical(TypeRelation *relation, Type *other) +{ + if (other->IsSymbolType()) { + relation->Result(true); + } +} + +void SymbolType::AssignmentTarget(TypeRelation *relation, Type *source) +{ + if (source->IsSymbolType()) { + relation->Result(true); + } +} + +TypeFacts SymbolType::GetTypeFacts() const +{ + return TypeFacts::SYMBOL_FACTS; +} + +Type *SymbolType::Instantiate([[maybe_unused]] ArenaAllocator *allocator, [[maybe_unused]] TypeRelation *relation, + [[maybe_unused]] GlobalTypesHolder *globalTypes) +{ + return this; +} + +} // namespace panda::es2panda::checker diff --git a/es2panda/typescript/types/symbolType.h b/es2panda/typescript/types/symbolType.h new file mode 100644 index 0000000000..8ee6484e3c --- /dev/null +++ b/es2panda/typescript/types/symbolType.h @@ -0,0 +1,36 @@ +/* + * 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. + */ + +#ifndef ES2PANDA_COMPILER_TYPESCRIPT_TYPES_SYMBOL_TYPE_H +#define ES2PANDA_COMPILER_TYPESCRIPT_TYPES_SYMBOL_TYPE_H + +#include "type.h" + +namespace panda::es2panda::checker { + +class SymbolType : public Type { +public: + SymbolType() : Type(TypeFlag::SYMBOL) {} + + void ToString(std::stringstream &ss) const override; + void Identical(TypeRelation *relation, Type *other) override; + void AssignmentTarget(TypeRelation *relation, Type *source) override; + TypeFacts GetTypeFacts() const override; + Type *Instantiate(ArenaAllocator *allocator, TypeRelation *relation, GlobalTypesHolder *globalTypes) override; +}; + +} // namespace panda::es2panda::checker + +#endif /* TYPESCRIPT_TYPES_STRING_TYPE_H */ diff --git a/es2panda/typescript/types/typeFacts.h b/es2panda/typescript/types/typeFacts.h index 1988b6a09c..165c03fa9b 100644 --- a/es2panda/typescript/types/typeFacts.h +++ b/es2panda/typescript/types/typeFacts.h @@ -68,6 +68,13 @@ enum class TypeFacts { EMPTY_STRING_FACTS = BASE_STRING_FACTS, NON_EMPTY_STRING_FACTS = BASE_STRING_FACTS | TRUTHY, + // Symbol facts + BASE_SYMBOL_STRICT_FACTS = TYPEOF_EQ_SYMBOL | TYPEOF_NE_NUMBER | TYPEOF_NE_BIGINT | TYPEOF_NE_BOOLEAN | + TYPEOF_NE_STRING | TYPEOF_NE_OBJECT | TYPEOF_NE_FUNCTION | TYPEOF_NE_HOST_OBJECT | + NE_UNDEFINED | NE_NULL | NE_UNDEFINED_OR_NULL, + BASE_SYMBOL_FACTS = BASE_SYMBOL_STRICT_FACTS | EQ_UNDEFINED | EQ_NULL | EQ_UNDEFINED_OR_NULL | FALSY, + SYMBOL_FACTS = BASE_SYMBOL_FACTS | TRUTHY, + // Bigint facts BASE_BIGINT_STRICT_FACTS = TYPEOF_EQ_BIGINT | TYPEOF_NE_STRING | TYPEOF_NE_NUMBER | TYPEOF_NE_BOOLEAN | TYPEOF_NE_SYMBOL | TYPEOF_NE_OBJECT | TYPEOF_NE_FUNCTION | TYPEOF_NE_HOST_OBJECT | diff --git a/es2panda/typescript/types/typeMapping.h b/es2panda/typescript/types/typeMapping.h index 85383ee2ae..3ad47aadec 100644 --- a/es2panda/typescript/types/typeMapping.h +++ b/es2panda/typescript/types/typeMapping.h @@ -24,6 +24,7 @@ _(TypeFlag::BIGINT_LITERAL, BigintLiteralType) \ _(TypeFlag::NUMBER, NumberType) \ _(TypeFlag::STRING, StringType) \ + _(TypeFlag::SYMBOL, SymbolType) \ _(TypeFlag::BOOLEAN, BooleanType) \ _(TypeFlag::VOID, VoidType) \ _(TypeFlag::NULL_TYPE, NullType) \ diff --git a/es2panda/typescript/types/types.h b/es2panda/typescript/types/types.h index 7b3d981006..939919f94a 100644 --- a/es2panda/typescript/types/types.h +++ b/es2panda/typescript/types/types.h @@ -36,6 +36,7 @@ #include "objectType.h" #include "stringLiteralType.h" #include "stringType.h" +#include "symbolType.h" #include "tupleType.h" #include "undefinedType.h" #include "unionType.h" -- Gitee