From 41a4ae5d2c94bb3acc1d97c2f437b4b7961be3bf Mon Sep 17 00:00:00 2001 From: Yuqiang Xian Date: Thu, 18 May 2023 17:07:12 +0800 Subject: [PATCH 1/2] Add the frontend support to fine grained number types. So far they're parsed to generic number type. Issue: https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/I765MB Signed-off-by: Yuqiang Xian --- es2panda/lexer/scripts/keywords.rb | 11 +++++++++ es2panda/lexer/token/token.cpp | 11 +++++++++ es2panda/lexer/token/tokenType.h | 11 +++++++++ es2panda/parser/parserImpl.cpp | 37 ++++++++++++++++++++++++++++++ 4 files changed, 70 insertions(+) diff --git a/es2panda/lexer/scripts/keywords.rb b/es2panda/lexer/scripts/keywords.rb index 8fdbfc3766..34b8e026ef 100644 --- a/es2panda/lexer/scripts/keywords.rb +++ b/es2panda/lexer/scripts/keywords.rb @@ -33,12 +33,14 @@ keywords = [ "bigint" => ["TokenType::LITERAL_IDENT", "TokenType::KEYW_BIGINT"], "boolean" => ["TokenType::LITERAL_IDENT", "TokenType::KEYW_BOOLEAN"], "break" => ["TokenType::KEYW_BREAK", "TokenType::KEYW_BREAK"], + "byte" => ["TokenType::LITERAL_IDENT", "TokenType::KEYW_BYTE"], }, # keywords start with 'c' { "case" => ["TokenType::KEYW_CASE", "TokenType::KEYW_CASE"], "catch" => ["TokenType::KEYW_CATCH", "TokenType::KEYW_CATCH"], + "char" => ["TokenType::LITERAL_IDENT", "TokenType::KEYW_CHAR"], "class" => ["TokenType::KEYW_CLASS", "TokenType::KEYW_CLASS"], "const" => ["TokenType::KEYW_CONST", "TokenType::KEYW_CONST"], "continue" => ["TokenType::KEYW_CONTINUE", "TokenType::KEYW_CONTINUE"] @@ -51,6 +53,7 @@ keywords = [ "default" => ["TokenType::KEYW_DEFAULT", "TokenType::KEYW_DEFAULT"], "delete" => ["TokenType::KEYW_DELETE", "TokenType::KEYW_DELETE"], "do" => ["TokenType::KEYW_DO", "TokenType::KEYW_DO"], + "double" => ["TokenType::LITERAL_IDENT", "TokenType::KEYW_DOUBLE"], }, # keywords start with 'e' @@ -66,6 +69,7 @@ keywords = [ { "false" => ["TokenType::LITERAL_FALSE", "TokenType::LITERAL_FALSE"], "finally" => ["TokenType::KEYW_FINALLY", "TokenType::KEYW_FINALLY"], + "float" => ["TokenType::LITERAL_IDENT", "TokenType::KEYW_FLOAT"], "for" => ["TokenType::KEYW_FOR", "TokenType::KEYW_FOR"], "from" => ["TokenType::LITERAL_IDENT", "TokenType::KEYW_FROM"], "function" => ["TokenType::KEYW_FUNCTION", "TokenType::KEYW_FUNCTION"], @@ -85,6 +89,7 @@ keywords = [ "in" => ["TokenType::KEYW_IN", "TokenType::KEYW_IN"], "infer" => ["TokenType::LITERAL_IDENT", "TokenType::KEYW_INFER"], "instanceof" => ["TokenType::KEYW_INSTANCEOF", "TokenType::KEYW_INSTANCEOF"], + "int" => ["TokenType::LITERAL_IDENT", "TokenType::KEYW_INT"], "interface" => ["TokenType::LITERAL_IDENT", "TokenType::KEYW_INTERFACE"], "is" => ["TokenType::LITERAL_IDENT", "TokenType::KEYW_IS"], }, @@ -97,6 +102,7 @@ keywords = [ # keywords start with 'l' { "let" => ["TokenType::KEYW_LET", "TokenType::KEYW_LET"], + "long" => ["TokenType::LITERAL_IDENT", "TokenType::KEYW_LONG"], }, # keywords start with 'm' @@ -138,6 +144,7 @@ keywords = [ # keywords start with 's' { "set" => ["TokenType::LITERAL_IDENT", "TokenType::KEYW_SET"], + "short" => ["TokenType::LITERAL_IDENT", "TokenType::KEYW_SHORT"], "static" => ["TokenType::LITERAL_IDENT", "TokenType::KEYW_STATIC"], "string" => ["TokenType::LITERAL_IDENT", "TokenType::KEYW_STRING"], "super" => ["TokenType::KEYW_SUPER", "TokenType::KEYW_SUPER"], @@ -160,6 +167,10 @@ keywords = [ "undefined" => ["TokenType::LITERAL_IDENT", "TokenType::KEYW_UNDEFINED"], "unique" => ["TokenType::LITERAL_IDENT", "TokenType::KEYW_UNIQUE"], "unknown" => ["TokenType::LITERAL_IDENT", "TokenType::KEYW_UNKNOWN"], + "ubyte" => ["TokenType::LITERAL_IDENT", "TokenType::KEYW_UBYTE"], + "uint" => ["TokenType::LITERAL_IDENT", "TokenType::KEYW_UINT"], + "ulong" => ["TokenType::LITERAL_IDENT", "TokenType::KEYW_ULONG"], + "ushort" => ["TokenType::LITERAL_IDENT", "TokenType::KEYW_USHORT"], }, # keywords start with 'v' diff --git a/es2panda/lexer/token/token.cpp b/es2panda/lexer/token/token.cpp index 9bf5799002..2d670fca40 100644 --- a/es2panda/lexer/token/token.cpp +++ b/es2panda/lexer/token/token.cpp @@ -83,6 +83,17 @@ bool Token::IsReservedTypeName() const case TokenType::KEYW_UNKNOWN: case TokenType::KEYW_NEVER: case TokenType::KEYW_NUMBER: + case TokenType::KEYW_CHAR: + case TokenType::KEYW_BYTE: + case TokenType::KEYW_SHORT: + case TokenType::KEYW_INT: + case TokenType::KEYW_LONG: + case TokenType::KEYW_UBYTE: + case TokenType::KEYW_USHORT: + case TokenType::KEYW_UINT: + case TokenType::KEYW_ULONG: + case TokenType::KEYW_FLOAT: + case TokenType::KEYW_DOUBLE: case TokenType::KEYW_BIGINT: case TokenType::KEYW_BOOLEAN: case TokenType::KEYW_STRING: diff --git a/es2panda/lexer/token/tokenType.h b/es2panda/lexer/token/tokenType.h index 1c076bf81b..ed75b69a71 100644 --- a/es2panda/lexer/token/tokenType.h +++ b/es2panda/lexer/token/tokenType.h @@ -112,8 +112,10 @@ enum class TokenType { KEYW_BIGINT, KEYW_BOOLEAN, KEYW_BREAK, + KEYW_BYTE, KEYW_CASE, KEYW_CATCH, + KEYW_CHAR, KEYW_CLASS, KEYW_CONST, KEYW_CONTINUE, @@ -121,15 +123,19 @@ enum class TokenType { KEYW_DEFAULT, KEYW_DELETE, KEYW_DO, + KEYW_DOUBLE, KEYW_ELSE, KEYW_ENUM, KEYW_EXPORT, KEYW_EXTENDS, KEYW_FINALLY, + KEYW_FLOAT, KEYW_FOR, KEYW_FUNCTION, KEYW_IF, KEYW_IMPORT, + KEYW_INT, + KEYW_LONG, KEYW_NEVER, KEYW_NEW, KEYW_NULL, @@ -137,6 +143,7 @@ enum class TokenType { KEYW_OBJECT, KEYW_REGEXP, KEYW_RETURN, + KEYW_SHORT, KEYW_STRING, KEYW_SUPER, KEYW_SWITCH, @@ -146,8 +153,12 @@ enum class TokenType { KEYW_TYPE, KEYW_TRY, KEYW_TYPEOF, + KEYW_UBYTE, + KEYW_UINT, + KEYW_ULONG, KEYW_UNDEFINED, KEYW_UNKNOWN, + KEYW_USHORT, KEYW_VAR, KEYW_VOID, KEYW_WHILE, diff --git a/es2panda/parser/parserImpl.cpp b/es2panda/parser/parserImpl.cpp index 769f9b3ef6..cb70154c18 100644 --- a/es2panda/parser/parserImpl.cpp +++ b/es2panda/parser/parserImpl.cpp @@ -261,6 +261,17 @@ bool ParserImpl::CurrentLiteralIsBasicType() case lexer::TokenType::KEYW_ANY: case lexer::TokenType::KEYW_BOOLEAN: case lexer::TokenType::KEYW_NUMBER: + case lexer::TokenType::KEYW_CHAR: + case lexer::TokenType::KEYW_BYTE: + case lexer::TokenType::KEYW_SHORT: + case lexer::TokenType::KEYW_INT: + case lexer::TokenType::KEYW_LONG: + case lexer::TokenType::KEYW_UBYTE: + case lexer::TokenType::KEYW_USHORT: + case lexer::TokenType::KEYW_UINT: + case lexer::TokenType::KEYW_ULONG: + case lexer::TokenType::KEYW_FLOAT: + case lexer::TokenType::KEYW_DOUBLE: case lexer::TokenType::KEYW_STRING: case lexer::TokenType::KEYW_SYMBOL: case lexer::TokenType::KEYW_UNKNOWN: @@ -1884,6 +1895,32 @@ ir::Expression *ParserImpl::ParseTsBasicType(TypeAnnotationParsingOptions option typeAnnotation = AllocNode(); } else if (lexer_->GetToken().KeywordType() == lexer::TokenType::KEYW_NUMBER) { typeAnnotation = AllocNode(); + // Currently we treat all the types of the number type family as the generic number type. + } else if (lexer_->GetToken().KeywordType() == lexer::TokenType::KEYW_NUMBER) { + typeAnnotation = AllocNode(); + } else if (lexer_->GetToken().KeywordType() == lexer::TokenType::KEYW_CHAR) { + typeAnnotation = AllocNode(); + } else if (lexer_->GetToken().KeywordType() == lexer::TokenType::KEYW_BYTE) { + typeAnnotation = AllocNode(); + } else if (lexer_->GetToken().KeywordType() == lexer::TokenType::KEYW_SHORT) { + typeAnnotation = AllocNode(); + } else if (lexer_->GetToken().KeywordType() == lexer::TokenType::KEYW_INT) { + typeAnnotation = AllocNode(); + } else if (lexer_->GetToken().KeywordType() == lexer::TokenType::KEYW_LONG) { + typeAnnotation = AllocNode(); + } else if (lexer_->GetToken().KeywordType() == lexer::TokenType::KEYW_UBYTE) { + typeAnnotation = AllocNode(); + } else if (lexer_->GetToken().KeywordType() == lexer::TokenType::KEYW_USHORT) { + typeAnnotation = AllocNode(); + } else if (lexer_->GetToken().KeywordType() == lexer::TokenType::KEYW_UINT) { + typeAnnotation = AllocNode(); + } else if (lexer_->GetToken().KeywordType() == lexer::TokenType::KEYW_ULONG) { + typeAnnotation = AllocNode(); + } else if (lexer_->GetToken().KeywordType() == lexer::TokenType::KEYW_FLOAT) { + typeAnnotation = AllocNode(); + } else if (lexer_->GetToken().KeywordType() == lexer::TokenType::KEYW_DOUBLE) { + typeAnnotation = AllocNode(); + // Number type family ends. } else if (lexer_->GetToken().KeywordType() == lexer::TokenType::KEYW_STRING) { typeAnnotation = AllocNode(); } else if (lexer_->GetToken().KeywordType() == lexer::TokenType::KEYW_UNKNOWN) { -- Gitee From 527633e09a92d4a3151e66bcf026e7a8a1340408 Mon Sep 17 00:00:00 2001 From: Yuqiang Xian Date: Thu, 18 May 2023 18:41:16 +0800 Subject: [PATCH 2/2] Add test cases for fine grained numeric type keyword parsing For now they are treated as generic number type. Issue: https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/I765MB Signed-off-by: Yuqiang Xian --- .../test-type-annotation-numeric-expected.txt | 4029 +++++++++++++++++ .../parser/ts/test-type-annotation-numeric.ts | 55 + 2 files changed, 4084 insertions(+) create mode 100644 es2panda/test/parser/ts/test-type-annotation-numeric-expected.txt create mode 100644 es2panda/test/parser/ts/test-type-annotation-numeric.ts diff --git a/es2panda/test/parser/ts/test-type-annotation-numeric-expected.txt b/es2panda/test/parser/ts/test-type-annotation-numeric-expected.txt new file mode 100644 index 0000000000..ed0e9c2e0c --- /dev/null +++ b/es2panda/test/parser/ts/test-type-annotation-numeric-expected.txt @@ -0,0 +1,4029 @@ +{ + "type": "Program", + "statements": [ + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "a", + "typeAnnotation": { + "type": "TSNumberKeyword", + "loc": { + "start": { + "line": 18, + "column": 8 + }, + "end": { + "line": 18, + "column": 14 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 5 + }, + "end": { + "line": 18, + "column": 6 + } + } + }, + "init": null, + "loc": { + "start": { + "line": 18, + "column": 5 + }, + "end": { + "line": 18, + "column": 6 + } + } + } + ], + "kind": "var", + "loc": { + "start": { + "line": 18, + "column": 1 + }, + "end": { + "line": 18, + "column": 15 + } + } + }, + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "b", + "typeAnnotation": { + "type": "TSNumberKeyword", + "loc": { + "start": { + "line": 19, + "column": 8 + }, + "end": { + "line": 19, + "column": 12 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 5 + }, + "end": { + "line": 19, + "column": 6 + } + } + }, + "init": null, + "loc": { + "start": { + "line": 19, + "column": 5 + }, + "end": { + "line": 19, + "column": 6 + } + } + } + ], + "kind": "var", + "loc": { + "start": { + "line": 19, + "column": 1 + }, + "end": { + "line": 19, + "column": 13 + } + } + }, + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "c", + "typeAnnotation": { + "type": "TSNumberKeyword", + "loc": { + "start": { + "line": 20, + "column": 8 + }, + "end": { + "line": 20, + "column": 12 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 5 + }, + "end": { + "line": 20, + "column": 6 + } + } + }, + "init": null, + "loc": { + "start": { + "line": 20, + "column": 5 + }, + "end": { + "line": 20, + "column": 6 + } + } + } + ], + "kind": "var", + "loc": { + "start": { + "line": 20, + "column": 1 + }, + "end": { + "line": 20, + "column": 13 + } + } + }, + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "d", + "typeAnnotation": { + "type": "TSNumberKeyword", + "loc": { + "start": { + "line": 21, + "column": 8 + }, + "end": { + "line": 21, + "column": 13 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 5 + }, + "end": { + "line": 21, + "column": 6 + } + } + }, + "init": null, + "loc": { + "start": { + "line": 21, + "column": 5 + }, + "end": { + "line": 21, + "column": 6 + } + } + } + ], + "kind": "var", + "loc": { + "start": { + "line": 21, + "column": 1 + }, + "end": { + "line": 21, + "column": 14 + } + } + }, + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "e", + "typeAnnotation": { + "type": "TSNumberKeyword", + "loc": { + "start": { + "line": 22, + "column": 8 + }, + "end": { + "line": 22, + "column": 11 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 5 + }, + "end": { + "line": 22, + "column": 6 + } + } + }, + "init": null, + "loc": { + "start": { + "line": 22, + "column": 5 + }, + "end": { + "line": 22, + "column": 6 + } + } + } + ], + "kind": "var", + "loc": { + "start": { + "line": 22, + "column": 1 + }, + "end": { + "line": 22, + "column": 12 + } + } + }, + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "f", + "typeAnnotation": { + "type": "TSNumberKeyword", + "loc": { + "start": { + "line": 23, + "column": 8 + }, + "end": { + "line": 23, + "column": 12 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 5 + }, + "end": { + "line": 23, + "column": 6 + } + } + }, + "init": null, + "loc": { + "start": { + "line": 23, + "column": 5 + }, + "end": { + "line": 23, + "column": 6 + } + } + } + ], + "kind": "var", + "loc": { + "start": { + "line": 23, + "column": 1 + }, + "end": { + "line": 23, + "column": 13 + } + } + }, + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "g", + "typeAnnotation": { + "type": "TSNumberKeyword", + "loc": { + "start": { + "line": 24, + "column": 8 + }, + "end": { + "line": 24, + "column": 13 + } + } + }, + "loc": { + "start": { + "line": 24, + "column": 5 + }, + "end": { + "line": 24, + "column": 6 + } + } + }, + "init": null, + "loc": { + "start": { + "line": 24, + "column": 5 + }, + "end": { + "line": 24, + "column": 6 + } + } + } + ], + "kind": "var", + "loc": { + "start": { + "line": 24, + "column": 1 + }, + "end": { + "line": 24, + "column": 14 + } + } + }, + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "h", + "typeAnnotation": { + "type": "TSNumberKeyword", + "loc": { + "start": { + "line": 25, + "column": 8 + }, + "end": { + "line": 25, + "column": 14 + } + } + }, + "loc": { + "start": { + "line": 25, + "column": 5 + }, + "end": { + "line": 25, + "column": 6 + } + } + }, + "init": null, + "loc": { + "start": { + "line": 25, + "column": 5 + }, + "end": { + "line": 25, + "column": 6 + } + } + } + ], + "kind": "var", + "loc": { + "start": { + "line": 25, + "column": 1 + }, + "end": { + "line": 25, + "column": 15 + } + } + }, + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "i", + "typeAnnotation": { + "type": "TSNumberKeyword", + "loc": { + "start": { + "line": 26, + "column": 8 + }, + "end": { + "line": 26, + "column": 12 + } + } + }, + "loc": { + "start": { + "line": 26, + "column": 5 + }, + "end": { + "line": 26, + "column": 6 + } + } + }, + "init": null, + "loc": { + "start": { + "line": 26, + "column": 5 + }, + "end": { + "line": 26, + "column": 6 + } + } + } + ], + "kind": "var", + "loc": { + "start": { + "line": 26, + "column": 1 + }, + "end": { + "line": 26, + "column": 13 + } + } + }, + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "j", + "typeAnnotation": { + "type": "TSNumberKeyword", + "loc": { + "start": { + "line": 27, + "column": 8 + }, + "end": { + "line": 27, + "column": 13 + } + } + }, + "loc": { + "start": { + "line": 27, + "column": 5 + }, + "end": { + "line": 27, + "column": 6 + } + } + }, + "init": null, + "loc": { + "start": { + "line": 27, + "column": 5 + }, + "end": { + "line": 27, + "column": 6 + } + } + } + ], + "kind": "var", + "loc": { + "start": { + "line": 27, + "column": 1 + }, + "end": { + "line": 27, + "column": 14 + } + } + }, + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "k", + "typeAnnotation": { + "type": "TSNumberKeyword", + "loc": { + "start": { + "line": 28, + "column": 8 + }, + "end": { + "line": 28, + "column": 13 + } + } + }, + "loc": { + "start": { + "line": 28, + "column": 5 + }, + "end": { + "line": 28, + "column": 6 + } + } + }, + "init": null, + "loc": { + "start": { + "line": 28, + "column": 5 + }, + "end": { + "line": 28, + "column": 6 + } + } + } + ], + "kind": "var", + "loc": { + "start": { + "line": 28, + "column": 1 + }, + "end": { + "line": 28, + "column": 14 + } + } + }, + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "l", + "typeAnnotation": { + "type": "TSArrayType", + "elementType": { + "type": "TSNumberKeyword", + "loc": { + "start": { + "line": 31, + "column": 8 + }, + "end": { + "line": 31, + "column": 12 + } + } + }, + "loc": { + "start": { + "line": 31, + "column": 8 + }, + "end": { + "line": 31, + "column": 14 + } + } + }, + "loc": { + "start": { + "line": 31, + "column": 5 + }, + "end": { + "line": 31, + "column": 6 + } + } + }, + "init": null, + "loc": { + "start": { + "line": 31, + "column": 5 + }, + "end": { + "line": 31, + "column": 6 + } + } + } + ], + "kind": "var", + "loc": { + "start": { + "line": 31, + "column": 1 + }, + "end": { + "line": 31, + "column": 15 + } + } + }, + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "m", + "typeAnnotation": { + "type": "TSArrayType", + "elementType": { + "type": "TSArrayType", + "elementType": { + "type": "TSStringKeyword", + "loc": { + "start": { + "line": 32, + "column": 8 + }, + "end": { + "line": 32, + "column": 14 + } + } + }, + "loc": { + "start": { + "line": 32, + "column": 8 + }, + "end": { + "line": 32, + "column": 16 + } + } + }, + "loc": { + "start": { + "line": 32, + "column": 8 + }, + "end": { + "line": 32, + "column": 18 + } + } + }, + "loc": { + "start": { + "line": 32, + "column": 5 + }, + "end": { + "line": 32, + "column": 6 + } + } + }, + "init": null, + "loc": { + "start": { + "line": 32, + "column": 5 + }, + "end": { + "line": 32, + "column": 6 + } + } + } + ], + "kind": "var", + "loc": { + "start": { + "line": 32, + "column": 1 + }, + "end": { + "line": 32, + "column": 19 + } + } + }, + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "n", + "typeAnnotation": { + "type": "TSUnionType", + "types": [ + { + "type": "TSArrayType", + "elementType": { + "type": "TSUnknownKeyword", + "loc": { + "start": { + "line": 33, + "column": 8 + }, + "end": { + "line": 33, + "column": 15 + } + } + }, + "loc": { + "start": { + "line": 33, + "column": 8 + }, + "end": { + "line": 33, + "column": 17 + } + } + }, + { + "type": "TSArrayType", + "elementType": { + "type": "TSLiteralType", + "literal": { + "type": "BigIntLiteral", + "value": "5n", + "loc": { + "start": { + "line": 33, + "column": 20 + }, + "end": { + "line": 33, + "column": 22 + } + } + }, + "loc": { + "start": { + "line": 33, + "column": 20 + }, + "end": { + "line": 33, + "column": 22 + } + } + }, + "loc": { + "start": { + "line": 33, + "column": 20 + }, + "end": { + "line": 33, + "column": 24 + } + } + } + ], + "loc": { + "start": { + "line": 33, + "column": 8 + }, + "end": { + "line": 33, + "column": 24 + } + } + }, + "loc": { + "start": { + "line": 33, + "column": 5 + }, + "end": { + "line": 33, + "column": 6 + } + } + }, + "init": null, + "loc": { + "start": { + "line": 33, + "column": 5 + }, + "end": { + "line": 33, + "column": 6 + } + } + } + ], + "kind": "var", + "loc": { + "start": { + "line": 33, + "column": 1 + }, + "end": { + "line": 33, + "column": 25 + } + } + }, + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "o", + "typeAnnotation": { + "type": "TSUnionType", + "types": [ + { + "type": "TSArrayType", + "elementType": { + "type": "TSParenthesizedType", + "typeAnnotation": { + "type": "TSUnionType", + "types": [ + { + "type": "TSNumberKeyword", + "loc": { + "start": { + "line": 36, + "column": 9 + }, + "end": { + "line": 36, + "column": 13 + } + } + }, + { + "type": "TSStringKeyword", + "loc": { + "start": { + "line": 36, + "column": 16 + }, + "end": { + "line": 36, + "column": 22 + } + } + } + ], + "loc": { + "start": { + "line": 36, + "column": 9 + }, + "end": { + "line": 36, + "column": 22 + } + } + }, + "loc": { + "start": { + "line": 36, + "column": 8 + }, + "end": { + "line": 36, + "column": 23 + } + } + }, + "loc": { + "start": { + "line": 36, + "column": 8 + }, + "end": { + "line": 36, + "column": 25 + } + } + }, + { + "type": "TSLiteralType", + "literal": { + "type": "BooleanLiteral", + "value": true, + "loc": { + "start": { + "line": 36, + "column": 28 + }, + "end": { + "line": 36, + "column": 32 + } + } + }, + "loc": { + "start": { + "line": 36, + "column": 28 + }, + "end": { + "line": 36, + "column": 32 + } + } + }, + { + "type": "TSArrayType", + "elementType": { + "type": "TSParenthesizedType", + "typeAnnotation": { + "type": "TSUnionType", + "types": [ + { + "type": "TSArrayType", + "elementType": { + "type": "TSParenthesizedType", + "typeAnnotation": { + "type": "TSUnionType", + "types": [ + { + "type": "TSArrayType", + "elementType": { + "type": "TSUndefinedKeyword", + "loc": { + "start": { + "line": 36, + "column": 37 + }, + "end": { + "line": 36, + "column": 46 + } + } + }, + "loc": { + "start": { + "line": 36, + "column": 37 + }, + "end": { + "line": 36, + "column": 48 + } + } + }, + { + "type": "TSUnknownKeyword", + "loc": { + "start": { + "line": 36, + "column": 51 + }, + "end": { + "line": 36, + "column": 58 + } + } + } + ], + "loc": { + "start": { + "line": 36, + "column": 37 + }, + "end": { + "line": 36, + "column": 58 + } + } + }, + "loc": { + "start": { + "line": 36, + "column": 36 + }, + "end": { + "line": 36, + "column": 59 + } + } + }, + "loc": { + "start": { + "line": 36, + "column": 36 + }, + "end": { + "line": 36, + "column": 61 + } + } + }, + { + "type": "TSLiteralType", + "literal": { + "type": "StringLiteral", + "value": "foo", + "loc": { + "start": { + "line": 36, + "column": 64 + }, + "end": { + "line": 36, + "column": 69 + } + } + }, + "loc": { + "start": { + "line": 36, + "column": 64 + }, + "end": { + "line": 36, + "column": 69 + } + } + } + ], + "loc": { + "start": { + "line": 36, + "column": 36 + }, + "end": { + "line": 36, + "column": 69 + } + } + }, + "loc": { + "start": { + "line": 36, + "column": 35 + }, + "end": { + "line": 36, + "column": 70 + } + } + }, + "loc": { + "start": { + "line": 36, + "column": 35 + }, + "end": { + "line": 36, + "column": 72 + } + } + } + ], + "loc": { + "start": { + "line": 36, + "column": 8 + }, + "end": { + "line": 36, + "column": 72 + } + } + }, + "loc": { + "start": { + "line": 36, + "column": 5 + }, + "end": { + "line": 36, + "column": 6 + } + } + }, + "init": null, + "loc": { + "start": { + "line": 36, + "column": 5 + }, + "end": { + "line": 36, + "column": 6 + } + } + } + ], + "kind": "var", + "loc": { + "start": { + "line": 36, + "column": 1 + }, + "end": { + "line": 36, + "column": 73 + } + } + }, + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "p", + "typeAnnotation": { + "type": "TSUnionType", + "types": [ + { + "type": "TSArrayType", + "elementType": { + "type": "TSParenthesizedType", + "typeAnnotation": { + "type": "TSUnionType", + "types": [ + { + "type": "TSNumberKeyword", + "loc": { + "start": { + "line": 37, + "column": 9 + }, + "end": { + "line": 37, + "column": 14 + } + } + }, + { + "type": "TSStringKeyword", + "loc": { + "start": { + "line": 37, + "column": 17 + }, + "end": { + "line": 37, + "column": 23 + } + } + } + ], + "loc": { + "start": { + "line": 37, + "column": 9 + }, + "end": { + "line": 37, + "column": 23 + } + } + }, + "loc": { + "start": { + "line": 37, + "column": 8 + }, + "end": { + "line": 37, + "column": 24 + } + } + }, + "loc": { + "start": { + "line": 37, + "column": 8 + }, + "end": { + "line": 37, + "column": 26 + } + } + }, + { + "type": "TSArrayType", + "elementType": { + "type": "TSParenthesizedType", + "typeAnnotation": { + "type": "TSUnionType", + "types": [ + { + "type": "TSNumberKeyword", + "loc": { + "start": { + "line": 37, + "column": 30 + }, + "end": { + "line": 37, + "column": 33 + } + } + }, + { + "type": "TSStringKeyword", + "loc": { + "start": { + "line": 37, + "column": 36 + }, + "end": { + "line": 37, + "column": 42 + } + } + } + ], + "loc": { + "start": { + "line": 37, + "column": 30 + }, + "end": { + "line": 37, + "column": 42 + } + } + }, + "loc": { + "start": { + "line": 37, + "column": 29 + }, + "end": { + "line": 37, + "column": 43 + } + } + }, + "loc": { + "start": { + "line": 37, + "column": 29 + }, + "end": { + "line": 37, + "column": 45 + } + } + } + ], + "loc": { + "start": { + "line": 37, + "column": 8 + }, + "end": { + "line": 37, + "column": 45 + } + } + }, + "loc": { + "start": { + "line": 37, + "column": 5 + }, + "end": { + "line": 37, + "column": 6 + } + } + }, + "init": null, + "loc": { + "start": { + "line": 37, + "column": 5 + }, + "end": { + "line": 37, + "column": 6 + } + } + } + ], + "kind": "var", + "loc": { + "start": { + "line": 37, + "column": 1 + }, + "end": { + "line": 37, + "column": 46 + } + } + }, + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "q", + "typeAnnotation": { + "type": "TSUnionType", + "types": [ + { + "type": "TSParenthesizedType", + "typeAnnotation": { + "type": "TSUnionType", + "types": [ + { + "type": "TSArrayType", + "elementType": { + "type": "TSParenthesizedType", + "typeAnnotation": { + "type": "TSUnionType", + "types": [ + { + "type": "TSNumberKeyword", + "loc": { + "start": { + "line": 38, + "column": 10 + }, + "end": { + "line": 38, + "column": 14 + } + } + }, + { + "type": "TSNumberKeyword", + "loc": { + "start": { + "line": 38, + "column": 17 + }, + "end": { + "line": 38, + "column": 22 + } + } + } + ], + "loc": { + "start": { + "line": 38, + "column": 10 + }, + "end": { + "line": 38, + "column": 22 + } + } + }, + "loc": { + "start": { + "line": 38, + "column": 9 + }, + "end": { + "line": 38, + "column": 23 + } + } + }, + "loc": { + "start": { + "line": 38, + "column": 9 + }, + "end": { + "line": 38, + "column": 25 + } + } + }, + { + "type": "TSArrayType", + "elementType": { + "type": "TSParenthesizedType", + "typeAnnotation": { + "type": "TSUnionType", + "types": [ + { + "type": "TSNumberKeyword", + "loc": { + "start": { + "line": 38, + "column": 29 + }, + "end": { + "line": 38, + "column": 35 + } + } + }, + { + "type": "TSNumberKeyword", + "loc": { + "start": { + "line": 38, + "column": 38 + }, + "end": { + "line": 38, + "column": 42 + } + } + } + ], + "loc": { + "start": { + "line": 38, + "column": 29 + }, + "end": { + "line": 38, + "column": 42 + } + } + }, + "loc": { + "start": { + "line": 38, + "column": 28 + }, + "end": { + "line": 38, + "column": 43 + } + } + }, + "loc": { + "start": { + "line": 38, + "column": 28 + }, + "end": { + "line": 38, + "column": 45 + } + } + } + ], + "loc": { + "start": { + "line": 38, + "column": 9 + }, + "end": { + "line": 38, + "column": 45 + } + } + }, + "loc": { + "start": { + "line": 38, + "column": 8 + }, + "end": { + "line": 38, + "column": 46 + } + } + }, + { + "type": "TSStringKeyword", + "loc": { + "start": { + "line": 38, + "column": 49 + }, + "end": { + "line": 38, + "column": 55 + } + } + } + ], + "loc": { + "start": { + "line": 38, + "column": 8 + }, + "end": { + "line": 38, + "column": 55 + } + } + }, + "loc": { + "start": { + "line": 38, + "column": 5 + }, + "end": { + "line": 38, + "column": 6 + } + } + }, + "init": null, + "loc": { + "start": { + "line": 38, + "column": 5 + }, + "end": { + "line": 38, + "column": 6 + } + } + } + ], + "kind": "var", + "loc": { + "start": { + "line": 38, + "column": 1 + }, + "end": { + "line": 38, + "column": 56 + } + } + }, + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "r", + "typeAnnotation": { + "type": "TSArrayType", + "elementType": { + "type": "TSParenthesizedType", + "typeAnnotation": { + "type": "TSParenthesizedType", + "typeAnnotation": { + "type": "TSParenthesizedType", + "typeAnnotation": { + "type": "TSParenthesizedType", + "typeAnnotation": { + "type": "TSNumberKeyword", + "loc": { + "start": { + "line": 41, + "column": 12 + }, + "end": { + "line": 41, + "column": 17 + } + } + }, + "loc": { + "start": { + "line": 41, + "column": 11 + }, + "end": { + "line": 41, + "column": 18 + } + } + }, + "loc": { + "start": { + "line": 41, + "column": 10 + }, + "end": { + "line": 41, + "column": 19 + } + } + }, + "loc": { + "start": { + "line": 41, + "column": 9 + }, + "end": { + "line": 41, + "column": 20 + } + } + }, + "loc": { + "start": { + "line": 41, + "column": 8 + }, + "end": { + "line": 41, + "column": 21 + } + } + }, + "loc": { + "start": { + "line": 41, + "column": 8 + }, + "end": { + "line": 41, + "column": 23 + } + } + }, + "loc": { + "start": { + "line": 41, + "column": 5 + }, + "end": { + "line": 41, + "column": 6 + } + } + }, + "init": null, + "loc": { + "start": { + "line": 41, + "column": 5 + }, + "end": { + "line": 41, + "column": 6 + } + } + } + ], + "kind": "var", + "loc": { + "start": { + "line": 41, + "column": 1 + }, + "end": { + "line": 41, + "column": 24 + } + } + }, + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "s", + "typeAnnotation": { + "type": "TSUnionType", + "types": [ + { + "type": "TSParenthesizedType", + "typeAnnotation": { + "type": "TSUnionType", + "types": [ + { + "type": "TSParenthesizedType", + "typeAnnotation": { + "type": "TSUnionType", + "types": [ + { + "type": "TSStringKeyword", + "loc": { + "start": { + "line": 42, + "column": 10 + }, + "end": { + "line": 42, + "column": 16 + } + } + }, + { + "type": "TSBooleanKeyword", + "loc": { + "start": { + "line": 42, + "column": 19 + }, + "end": { + "line": 42, + "column": 26 + } + } + } + ], + "loc": { + "start": { + "line": 42, + "column": 10 + }, + "end": { + "line": 42, + "column": 26 + } + } + }, + "loc": { + "start": { + "line": 42, + "column": 9 + }, + "end": { + "line": 42, + "column": 27 + } + } + }, + { + "type": "TSParenthesizedType", + "typeAnnotation": { + "type": "TSUnionType", + "types": [ + { + "type": "TSLiteralType", + "literal": { + "type": "NumberLiteral", + "value": 5, + "loc": { + "start": { + "line": 42, + "column": 31 + }, + "end": { + "line": 42, + "column": 32 + } + } + }, + "loc": { + "start": { + "line": 42, + "column": 31 + }, + "end": { + "line": 42, + "column": 32 + } + } + }, + { + "type": "TSLiteralType", + "literal": { + "type": "BooleanLiteral", + "value": true, + "loc": { + "start": { + "line": 42, + "column": 35 + }, + "end": { + "line": 42, + "column": 39 + } + } + }, + "loc": { + "start": { + "line": 42, + "column": 35 + }, + "end": { + "line": 42, + "column": 39 + } + } + } + ], + "loc": { + "start": { + "line": 42, + "column": 31 + }, + "end": { + "line": 42, + "column": 39 + } + } + }, + "loc": { + "start": { + "line": 42, + "column": 30 + }, + "end": { + "line": 42, + "column": 40 + } + } + } + ], + "loc": { + "start": { + "line": 42, + "column": 9 + }, + "end": { + "line": 42, + "column": 40 + } + } + }, + "loc": { + "start": { + "line": 42, + "column": 8 + }, + "end": { + "line": 42, + "column": 41 + } + } + }, + { + "type": "TSParenthesizedType", + "typeAnnotation": { + "type": "TSVoidKeyword", + "loc": { + "start": { + "line": 42, + "column": 45 + }, + "end": { + "line": 42, + "column": 49 + } + } + }, + "loc": { + "start": { + "line": 42, + "column": 44 + }, + "end": { + "line": 42, + "column": 50 + } + } + } + ], + "loc": { + "start": { + "line": 42, + "column": 8 + }, + "end": { + "line": 42, + "column": 50 + } + } + }, + "loc": { + "start": { + "line": 42, + "column": 5 + }, + "end": { + "line": 42, + "column": 6 + } + } + }, + "init": null, + "loc": { + "start": { + "line": 42, + "column": 5 + }, + "end": { + "line": 42, + "column": 6 + } + } + } + ], + "kind": "var", + "loc": { + "start": { + "line": 42, + "column": 1 + }, + "end": { + "line": 42, + "column": 51 + } + } + }, + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "func1", + "typeAnnotation": { + "type": "TSFunctionType", + "params": [ + { + "type": "Identifier", + "name": "a", + "typeAnnotation": { + "type": "TSNumberKeyword", + "loc": { + "start": { + "line": 45, + "column": 16 + }, + "end": { + "line": 45, + "column": 19 + } + } + }, + "loc": { + "start": { + "line": 45, + "column": 13 + }, + "end": { + "line": 45, + "column": 14 + } + } + }, + { + "type": "Identifier", + "name": "b", + "typeAnnotation": { + "type": "TSStringKeyword", + "loc": { + "start": { + "line": 45, + "column": 24 + }, + "end": { + "line": 45, + "column": 30 + } + } + }, + "loc": { + "start": { + "line": 45, + "column": 21 + }, + "end": { + "line": 45, + "column": 22 + } + } + } + ], + "returnType": { + "type": "TSNumberKeyword", + "loc": { + "start": { + "line": 45, + "column": 35 + }, + "end": { + "line": 45, + "column": 41 + } + } + }, + "loc": { + "start": { + "line": 45, + "column": 12 + }, + "end": { + "line": 45, + "column": 41 + } + } + }, + "loc": { + "start": { + "line": 45, + "column": 5 + }, + "end": { + "line": 45, + "column": 10 + } + } + }, + "init": null, + "loc": { + "start": { + "line": 45, + "column": 5 + }, + "end": { + "line": 45, + "column": 10 + } + } + } + ], + "kind": "var", + "loc": { + "start": { + "line": 45, + "column": 1 + }, + "end": { + "line": 45, + "column": 42 + } + } + }, + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "func2", + "typeAnnotation": { + "type": "TSFunctionType", + "params": [ + { + "type": "Identifier", + "name": "a", + "typeAnnotation": { + "type": "TSUnionType", + "types": [ + { + "type": "TSArrayType", + "elementType": { + "type": "TSNumberKeyword", + "loc": { + "start": { + "line": 46, + "column": 16 + }, + "end": { + "line": 46, + "column": 20 + } + } + }, + "loc": { + "start": { + "line": 46, + "column": 16 + }, + "end": { + "line": 46, + "column": 22 + } + } + }, + { + "type": "TSStringKeyword", + "loc": { + "start": { + "line": 46, + "column": 25 + }, + "end": { + "line": 46, + "column": 31 + } + } + } + ], + "loc": { + "start": { + "line": 46, + "column": 16 + }, + "end": { + "line": 46, + "column": 31 + } + } + }, + "loc": { + "start": { + "line": 46, + "column": 13 + }, + "end": { + "line": 46, + "column": 14 + } + } + }, + { + "type": "Identifier", + "name": "b", + "typeAnnotation": { + "type": "TSLiteralType", + "literal": { + "type": "NumberLiteral", + "value": 5, + "loc": { + "start": { + "line": 46, + "column": 37 + }, + "end": { + "line": 46, + "column": 38 + } + } + }, + "loc": { + "start": { + "line": 46, + "column": 37 + }, + "end": { + "line": 46, + "column": 38 + } + } + }, + "optional": true, + "loc": { + "start": { + "line": 46, + "column": 33 + }, + "end": { + "line": 46, + "column": 34 + } + } + } + ], + "returnType": { + "type": "TSUnionType", + "types": [ + { + "type": "TSNumberKeyword", + "loc": { + "start": { + "line": 46, + "column": 43 + }, + "end": { + "line": 46, + "column": 48 + } + } + }, + { + "type": "TSStringKeyword", + "loc": { + "start": { + "line": 46, + "column": 51 + }, + "end": { + "line": 46, + "column": 57 + } + } + } + ], + "loc": { + "start": { + "line": 46, + "column": 43 + }, + "end": { + "line": 46, + "column": 57 + } + } + }, + "loc": { + "start": { + "line": 46, + "column": 12 + }, + "end": { + "line": 46, + "column": 57 + } + } + }, + "loc": { + "start": { + "line": 46, + "column": 5 + }, + "end": { + "line": 46, + "column": 10 + } + } + }, + "init": null, + "loc": { + "start": { + "line": 46, + "column": 5 + }, + "end": { + "line": 46, + "column": 10 + } + } + } + ], + "kind": "var", + "loc": { + "start": { + "line": 46, + "column": 1 + }, + "end": { + "line": 46, + "column": 58 + } + } + }, + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "func3", + "typeAnnotation": { + "type": "TSFunctionType", + "params": [ + { + "type": "Identifier", + "name": "f", + "typeAnnotation": { + "type": "TSFunctionType", + "params": [ + { + "type": "Identifier", + "name": "a", + "typeAnnotation": { + "type": "TSNumberKeyword", + "loc": { + "start": { + "line": 47, + "column": 20 + }, + "end": { + "line": 47, + "column": 25 + } + } + }, + "loc": { + "start": { + "line": 47, + "column": 17 + }, + "end": { + "line": 47, + "column": 18 + } + } + }, + { + "type": "Identifier", + "name": "b", + "typeAnnotation": { + "type": "TSStringKeyword", + "loc": { + "start": { + "line": 47, + "column": 30 + }, + "end": { + "line": 47, + "column": 36 + } + } + }, + "loc": { + "start": { + "line": 47, + "column": 27 + }, + "end": { + "line": 47, + "column": 28 + } + } + } + ], + "returnType": { + "type": "TSArrayType", + "elementType": { + "type": "TSNumberKeyword", + "loc": { + "start": { + "line": 47, + "column": 41 + }, + "end": { + "line": 47, + "column": 47 + } + } + }, + "loc": { + "start": { + "line": 47, + "column": 41 + }, + "end": { + "line": 47, + "column": 49 + } + } + }, + "loc": { + "start": { + "line": 47, + "column": 16 + }, + "end": { + "line": 47, + "column": 49 + } + } + }, + "loc": { + "start": { + "line": 47, + "column": 13 + }, + "end": { + "line": 47, + "column": 14 + } + } + }, + { + "type": "ArrayPattern", + "elements": [ + { + "type": "Identifier", + "name": "a", + "loc": { + "start": { + "line": 47, + "column": 52 + }, + "end": { + "line": 47, + "column": 53 + } + } + }, + { + "type": "Identifier", + "name": "b", + "loc": { + "start": { + "line": 47, + "column": 55 + }, + "end": { + "line": 47, + "column": 56 + } + } + } + ], + "typeAnnotation": { + "type": "TSArrayType", + "elementType": { + "type": "TSNumberKeyword", + "loc": { + "start": { + "line": 47, + "column": 59 + }, + "end": { + "line": 47, + "column": 63 + } + } + }, + "loc": { + "start": { + "line": 47, + "column": 59 + }, + "end": { + "line": 47, + "column": 65 + } + } + }, + "loc": { + "start": { + "line": 47, + "column": 51 + }, + "end": { + "line": 47, + "column": 57 + } + } + } + ], + "returnType": { + "type": "TSFunctionType", + "params": [ + { + "type": "Identifier", + "name": "a", + "typeAnnotation": { + "type": "TSNumberKeyword", + "loc": { + "start": { + "line": 47, + "column": 74 + }, + "end": { + "line": 47, + "column": 78 + } + } + }, + "loc": { + "start": { + "line": 47, + "column": 71 + }, + "end": { + "line": 47, + "column": 72 + } + } + }, + { + "type": "Identifier", + "name": "b", + "typeAnnotation": { + "type": "TSBooleanKeyword", + "loc": { + "start": { + "line": 47, + "column": 83 + }, + "end": { + "line": 47, + "column": 90 + } + } + }, + "loc": { + "start": { + "line": 47, + "column": 80 + }, + "end": { + "line": 47, + "column": 81 + } + } + } + ], + "returnType": { + "type": "TSLiteralType", + "literal": { + "type": "BooleanLiteral", + "value": true, + "loc": { + "start": { + "line": 47, + "column": 95 + }, + "end": { + "line": 47, + "column": 99 + } + } + }, + "loc": { + "start": { + "line": 47, + "column": 95 + }, + "end": { + "line": 47, + "column": 99 + } + } + }, + "loc": { + "start": { + "line": 47, + "column": 70 + }, + "end": { + "line": 47, + "column": 99 + } + } + }, + "loc": { + "start": { + "line": 47, + "column": 12 + }, + "end": { + "line": 47, + "column": 99 + } + } + }, + "loc": { + "start": { + "line": 47, + "column": 5 + }, + "end": { + "line": 47, + "column": 10 + } + } + }, + "init": null, + "loc": { + "start": { + "line": 47, + "column": 5 + }, + "end": { + "line": 47, + "column": 10 + } + } + } + ], + "kind": "var", + "loc": { + "start": { + "line": 47, + "column": 1 + }, + "end": { + "line": 47, + "column": 100 + } + } + }, + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "ctor1", + "typeAnnotation": { + "type": "TSConstructorType", + "params": [ + { + "type": "Identifier", + "name": "a", + "typeAnnotation": { + "type": "TSNumberKeyword", + "loc": { + "start": { + "line": 50, + "column": 20 + }, + "end": { + "line": 50, + "column": 25 + } + } + }, + "loc": { + "start": { + "line": 50, + "column": 17 + }, + "end": { + "line": 50, + "column": 18 + } + } + }, + { + "type": "Identifier", + "name": "b", + "typeAnnotation": { + "type": "TSStringKeyword", + "loc": { + "start": { + "line": 50, + "column": 30 + }, + "end": { + "line": 50, + "column": 36 + } + } + }, + "loc": { + "start": { + "line": 50, + "column": 27 + }, + "end": { + "line": 50, + "column": 28 + } + } + } + ], + "returnType": { + "type": "TSNumberKeyword", + "loc": { + "start": { + "line": 50, + "column": 41 + }, + "end": { + "line": 50, + "column": 44 + } + } + }, + "loc": { + "start": { + "line": 50, + "column": 12 + }, + "end": { + "line": 50, + "column": 44 + } + } + }, + "loc": { + "start": { + "line": 50, + "column": 5 + }, + "end": { + "line": 50, + "column": 10 + } + } + }, + "init": null, + "loc": { + "start": { + "line": 50, + "column": 5 + }, + "end": { + "line": 50, + "column": 10 + } + } + } + ], + "kind": "var", + "loc": { + "start": { + "line": 50, + "column": 1 + }, + "end": { + "line": 50, + "column": 45 + } + } + }, + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "ctor2", + "typeAnnotation": { + "type": "TSConstructorType", + "params": [ + { + "type": "Identifier", + "name": "a", + "typeAnnotation": { + "type": "TSUnionType", + "types": [ + { + "type": "TSArrayType", + "elementType": { + "type": "TSNumberKeyword", + "loc": { + "start": { + "line": 51, + "column": 20 + }, + "end": { + "line": 51, + "column": 24 + } + } + }, + "loc": { + "start": { + "line": 51, + "column": 20 + }, + "end": { + "line": 51, + "column": 26 + } + } + }, + { + "type": "TSStringKeyword", + "loc": { + "start": { + "line": 51, + "column": 29 + }, + "end": { + "line": 51, + "column": 35 + } + } + } + ], + "loc": { + "start": { + "line": 51, + "column": 20 + }, + "end": { + "line": 51, + "column": 35 + } + } + }, + "loc": { + "start": { + "line": 51, + "column": 17 + }, + "end": { + "line": 51, + "column": 18 + } + } + }, + { + "type": "Identifier", + "name": "b", + "typeAnnotation": { + "type": "TSLiteralType", + "literal": { + "type": "NumberLiteral", + "value": 5, + "loc": { + "start": { + "line": 51, + "column": 41 + }, + "end": { + "line": 51, + "column": 42 + } + } + }, + "loc": { + "start": { + "line": 51, + "column": 41 + }, + "end": { + "line": 51, + "column": 42 + } + } + }, + "optional": true, + "loc": { + "start": { + "line": 51, + "column": 37 + }, + "end": { + "line": 51, + "column": 38 + } + } + } + ], + "returnType": { + "type": "TSUnionType", + "types": [ + { + "type": "TSNumberKeyword", + "loc": { + "start": { + "line": 51, + "column": 47 + }, + "end": { + "line": 51, + "column": 52 + } + } + }, + { + "type": "TSStringKeyword", + "loc": { + "start": { + "line": 51, + "column": 55 + }, + "end": { + "line": 51, + "column": 61 + } + } + } + ], + "loc": { + "start": { + "line": 51, + "column": 47 + }, + "end": { + "line": 51, + "column": 61 + } + } + }, + "loc": { + "start": { + "line": 51, + "column": 12 + }, + "end": { + "line": 51, + "column": 61 + } + } + }, + "loc": { + "start": { + "line": 51, + "column": 5 + }, + "end": { + "line": 51, + "column": 10 + } + } + }, + "init": null, + "loc": { + "start": { + "line": 51, + "column": 5 + }, + "end": { + "line": 51, + "column": 10 + } + } + } + ], + "kind": "var", + "loc": { + "start": { + "line": 51, + "column": 1 + }, + "end": { + "line": 51, + "column": 62 + } + } + }, + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "ctor3", + "typeAnnotation": { + "type": "TSConstructorType", + "params": [ + { + "type": "Identifier", + "name": "f", + "typeAnnotation": { + "type": "TSFunctionType", + "params": [ + { + "type": "Identifier", + "name": "a", + "typeAnnotation": { + "type": "TSNumberKeyword", + "loc": { + "start": { + "line": 52, + "column": 24 + }, + "end": { + "line": 52, + "column": 30 + } + } + }, + "loc": { + "start": { + "line": 52, + "column": 21 + }, + "end": { + "line": 52, + "column": 22 + } + } + }, + { + "type": "Identifier", + "name": "b", + "typeAnnotation": { + "type": "TSStringKeyword", + "loc": { + "start": { + "line": 52, + "column": 35 + }, + "end": { + "line": 52, + "column": 41 + } + } + }, + "loc": { + "start": { + "line": 52, + "column": 32 + }, + "end": { + "line": 52, + "column": 33 + } + } + } + ], + "returnType": { + "type": "TSArrayType", + "elementType": { + "type": "TSNumberKeyword", + "loc": { + "start": { + "line": 52, + "column": 46 + }, + "end": { + "line": 52, + "column": 50 + } + } + }, + "loc": { + "start": { + "line": 52, + "column": 46 + }, + "end": { + "line": 52, + "column": 52 + } + } + }, + "loc": { + "start": { + "line": 52, + "column": 20 + }, + "end": { + "line": 52, + "column": 52 + } + } + }, + "loc": { + "start": { + "line": 52, + "column": 17 + }, + "end": { + "line": 52, + "column": 18 + } + } + }, + { + "type": "ArrayPattern", + "elements": [ + { + "type": "Identifier", + "name": "a", + "loc": { + "start": { + "line": 52, + "column": 55 + }, + "end": { + "line": 52, + "column": 56 + } + } + }, + { + "type": "Identifier", + "name": "b", + "loc": { + "start": { + "line": 52, + "column": 58 + }, + "end": { + "line": 52, + "column": 59 + } + } + } + ], + "typeAnnotation": { + "type": "TSArrayType", + "elementType": { + "type": "TSNumberKeyword", + "loc": { + "start": { + "line": 52, + "column": 62 + }, + "end": { + "line": 52, + "column": 67 + } + } + }, + "loc": { + "start": { + "line": 52, + "column": 62 + }, + "end": { + "line": 52, + "column": 69 + } + } + }, + "loc": { + "start": { + "line": 52, + "column": 54 + }, + "end": { + "line": 52, + "column": 60 + } + } + } + ], + "returnType": { + "type": "TSFunctionType", + "params": [ + { + "type": "Identifier", + "name": "a", + "typeAnnotation": { + "type": "TSNumberKeyword", + "loc": { + "start": { + "line": 52, + "column": 78 + }, + "end": { + "line": 52, + "column": 83 + } + } + }, + "loc": { + "start": { + "line": 52, + "column": 75 + }, + "end": { + "line": 52, + "column": 76 + } + } + }, + { + "type": "Identifier", + "name": "b", + "typeAnnotation": { + "type": "TSBooleanKeyword", + "loc": { + "start": { + "line": 52, + "column": 88 + }, + "end": { + "line": 52, + "column": 95 + } + } + }, + "loc": { + "start": { + "line": 52, + "column": 85 + }, + "end": { + "line": 52, + "column": 86 + } + } + } + ], + "returnType": { + "type": "TSLiteralType", + "literal": { + "type": "BooleanLiteral", + "value": true, + "loc": { + "start": { + "line": 52, + "column": 100 + }, + "end": { + "line": 52, + "column": 104 + } + } + }, + "loc": { + "start": { + "line": 52, + "column": 100 + }, + "end": { + "line": 52, + "column": 104 + } + } + }, + "loc": { + "start": { + "line": 52, + "column": 74 + }, + "end": { + "line": 52, + "column": 104 + } + } + }, + "loc": { + "start": { + "line": 52, + "column": 12 + }, + "end": { + "line": 52, + "column": 104 + } + } + }, + "loc": { + "start": { + "line": 52, + "column": 5 + }, + "end": { + "line": 52, + "column": 10 + } + } + }, + "init": null, + "loc": { + "start": { + "line": 52, + "column": 5 + }, + "end": { + "line": 52, + "column": 10 + } + } + } + ], + "kind": "var", + "loc": { + "start": { + "line": 52, + "column": 1 + }, + "end": { + "line": 52, + "column": 105 + } + } + }, + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "ctor4", + "typeAnnotation": { + "type": "TSConstructorType", + "params": [ + { + "type": "Identifier", + "name": "a", + "typeAnnotation": { + "type": "TSNumberKeyword", + "loc": { + "start": { + "line": 53, + "column": 29 + }, + "end": { + "line": 53, + "column": 35 + } + } + }, + "loc": { + "start": { + "line": 53, + "column": 26 + }, + "end": { + "line": 53, + "column": 27 + } + } + }, + { + "type": "Identifier", + "name": "b", + "typeAnnotation": { + "type": "TSStringKeyword", + "loc": { + "start": { + "line": 53, + "column": 40 + }, + "end": { + "line": 53, + "column": 46 + } + } + }, + "loc": { + "start": { + "line": 53, + "column": 37 + }, + "end": { + "line": 53, + "column": 38 + } + } + } + ], + "returnType": { + "type": "TSNumberKeyword", + "loc": { + "start": { + "line": 53, + "column": 51 + }, + "end": { + "line": 53, + "column": 55 + } + } + }, + "abstract": true, + "loc": { + "start": { + "line": 53, + "column": 12 + }, + "end": { + "line": 53, + "column": 55 + } + } + }, + "loc": { + "start": { + "line": 53, + "column": 5 + }, + "end": { + "line": 53, + "column": 10 + } + } + }, + "init": null, + "loc": { + "start": { + "line": 53, + "column": 5 + }, + "end": { + "line": 53, + "column": 10 + } + } + } + ], + "kind": "var", + "loc": { + "start": { + "line": 53, + "column": 1 + }, + "end": { + "line": 53, + "column": 56 + } + } + }, + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "ctor5", + "typeAnnotation": { + "type": "TSConstructorType", + "params": [ + { + "type": "Identifier", + "name": "a", + "typeAnnotation": { + "type": "TSUnionType", + "types": [ + { + "type": "TSArrayType", + "elementType": { + "type": "TSNumberKeyword", + "loc": { + "start": { + "line": 54, + "column": 29 + }, + "end": { + "line": 54, + "column": 33 + } + } + }, + "loc": { + "start": { + "line": 54, + "column": 29 + }, + "end": { + "line": 54, + "column": 35 + } + } + }, + { + "type": "TSStringKeyword", + "loc": { + "start": { + "line": 54, + "column": 38 + }, + "end": { + "line": 54, + "column": 44 + } + } + } + ], + "loc": { + "start": { + "line": 54, + "column": 29 + }, + "end": { + "line": 54, + "column": 44 + } + } + }, + "loc": { + "start": { + "line": 54, + "column": 26 + }, + "end": { + "line": 54, + "column": 27 + } + } + }, + { + "type": "Identifier", + "name": "b", + "typeAnnotation": { + "type": "TSLiteralType", + "literal": { + "type": "NumberLiteral", + "value": 5, + "loc": { + "start": { + "line": 54, + "column": 50 + }, + "end": { + "line": 54, + "column": 51 + } + } + }, + "loc": { + "start": { + "line": 54, + "column": 50 + }, + "end": { + "line": 54, + "column": 51 + } + } + }, + "optional": true, + "loc": { + "start": { + "line": 54, + "column": 46 + }, + "end": { + "line": 54, + "column": 47 + } + } + } + ], + "returnType": { + "type": "TSUnionType", + "types": [ + { + "type": "TSNumberKeyword", + "loc": { + "start": { + "line": 54, + "column": 56 + }, + "end": { + "line": 54, + "column": 61 + } + } + }, + { + "type": "TSStringKeyword", + "loc": { + "start": { + "line": 54, + "column": 64 + }, + "end": { + "line": 54, + "column": 70 + } + } + } + ], + "loc": { + "start": { + "line": 54, + "column": 56 + }, + "end": { + "line": 54, + "column": 70 + } + } + }, + "abstract": true, + "loc": { + "start": { + "line": 54, + "column": 12 + }, + "end": { + "line": 54, + "column": 70 + } + } + }, + "loc": { + "start": { + "line": 54, + "column": 5 + }, + "end": { + "line": 54, + "column": 10 + } + } + }, + "init": null, + "loc": { + "start": { + "line": 54, + "column": 5 + }, + "end": { + "line": 54, + "column": 10 + } + } + } + ], + "kind": "var", + "loc": { + "start": { + "line": 54, + "column": 1 + }, + "end": { + "line": 54, + "column": 71 + } + } + }, + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "ctor6", + "typeAnnotation": { + "type": "TSConstructorType", + "params": [ + { + "type": "Identifier", + "name": "f", + "typeAnnotation": { + "type": "TSFunctionType", + "params": [ + { + "type": "Identifier", + "name": "a", + "typeAnnotation": { + "type": "TSNumberKeyword", + "loc": { + "start": { + "line": 55, + "column": 33 + }, + "end": { + "line": 55, + "column": 36 + } + } + }, + "loc": { + "start": { + "line": 55, + "column": 30 + }, + "end": { + "line": 55, + "column": 31 + } + } + }, + { + "type": "Identifier", + "name": "b", + "typeAnnotation": { + "type": "TSStringKeyword", + "loc": { + "start": { + "line": 55, + "column": 41 + }, + "end": { + "line": 55, + "column": 47 + } + } + }, + "loc": { + "start": { + "line": 55, + "column": 38 + }, + "end": { + "line": 55, + "column": 39 + } + } + } + ], + "returnType": { + "type": "TSArrayType", + "elementType": { + "type": "TSNumberKeyword", + "loc": { + "start": { + "line": 55, + "column": 52 + }, + "end": { + "line": 55, + "column": 56 + } + } + }, + "loc": { + "start": { + "line": 55, + "column": 52 + }, + "end": { + "line": 55, + "column": 58 + } + } + }, + "loc": { + "start": { + "line": 55, + "column": 29 + }, + "end": { + "line": 55, + "column": 58 + } + } + }, + "loc": { + "start": { + "line": 55, + "column": 26 + }, + "end": { + "line": 55, + "column": 27 + } + } + }, + { + "type": "ArrayPattern", + "elements": [ + { + "type": "Identifier", + "name": "a", + "loc": { + "start": { + "line": 55, + "column": 61 + }, + "end": { + "line": 55, + "column": 62 + } + } + }, + { + "type": "Identifier", + "name": "b", + "loc": { + "start": { + "line": 55, + "column": 64 + }, + "end": { + "line": 55, + "column": 65 + } + } + } + ], + "typeAnnotation": { + "type": "TSArrayType", + "elementType": { + "type": "TSNumberKeyword", + "loc": { + "start": { + "line": 55, + "column": 68 + }, + "end": { + "line": 55, + "column": 73 + } + } + }, + "loc": { + "start": { + "line": 55, + "column": 68 + }, + "end": { + "line": 55, + "column": 75 + } + } + }, + "loc": { + "start": { + "line": 55, + "column": 60 + }, + "end": { + "line": 55, + "column": 66 + } + } + } + ], + "returnType": { + "type": "TSFunctionType", + "params": [ + { + "type": "Identifier", + "name": "a", + "typeAnnotation": { + "type": "TSNumberKeyword", + "loc": { + "start": { + "line": 55, + "column": 84 + }, + "end": { + "line": 55, + "column": 90 + } + } + }, + "loc": { + "start": { + "line": 55, + "column": 81 + }, + "end": { + "line": 55, + "column": 82 + } + } + }, + { + "type": "Identifier", + "name": "b", + "typeAnnotation": { + "type": "TSBooleanKeyword", + "loc": { + "start": { + "line": 55, + "column": 95 + }, + "end": { + "line": 55, + "column": 102 + } + } + }, + "loc": { + "start": { + "line": 55, + "column": 92 + }, + "end": { + "line": 55, + "column": 93 + } + } + } + ], + "returnType": { + "type": "TSLiteralType", + "literal": { + "type": "BooleanLiteral", + "value": true, + "loc": { + "start": { + "line": 55, + "column": 107 + }, + "end": { + "line": 55, + "column": 111 + } + } + }, + "loc": { + "start": { + "line": 55, + "column": 107 + }, + "end": { + "line": 55, + "column": 111 + } + } + }, + "loc": { + "start": { + "line": 55, + "column": 80 + }, + "end": { + "line": 55, + "column": 111 + } + } + }, + "abstract": true, + "loc": { + "start": { + "line": 55, + "column": 12 + }, + "end": { + "line": 55, + "column": 111 + } + } + }, + "loc": { + "start": { + "line": 55, + "column": 5 + }, + "end": { + "line": 55, + "column": 10 + } + } + }, + "init": null, + "loc": { + "start": { + "line": 55, + "column": 5 + }, + "end": { + "line": 55, + "column": 10 + } + } + } + ], + "kind": "var", + "loc": { + "start": { + "line": 55, + "column": 1 + }, + "end": { + "line": 55, + "column": 112 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 56, + "column": 1 + } + } +} diff --git a/es2panda/test/parser/ts/test-type-annotation-numeric.ts b/es2panda/test/parser/ts/test-type-annotation-numeric.ts new file mode 100644 index 0000000000..becac098f4 --- /dev/null +++ b/es2panda/test/parser/ts/test-type-annotation-numeric.ts @@ -0,0 +1,55 @@ +/* + * 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. + */ + + +// Test basic types +var a: double; +var b: char; +var c: byte; +var d: short; +var e: int; +var f: long; +var g: ubyte; +var h: ushort; +var i: uint; +var j: ulong; +var k: float; + +// Test array type +var l: char[]; +var m: string[][]; +var n: unknown[] | 5n[]; + +// Test union type +var o: (byte | string)[] | true | ((undefined[] | unknown)[] | "foo")[]; +var p: (short | string)[] | (int | string)[]; +var q: ((long | ubyte)[] | (ushort | uint)[]) | string; + +// Test parenthesized type +var r: ((((ulong))))[]; +var s: ((string | boolean) | (5 | true)) | (void); + +// Test function type +var func1: (a: int, b: string) => double; +var func2: (a: char[] | string, b?: 5) => ubyte | string; +var func3: (f: (a: float, b: string) => double[], [a, b]: char[]) => (a: byte, b: boolean) => true; + +// Test constructor type +var ctor1: new (a: short, b: string) => int; +var ctor2: new (a: long[] | string, b?: 5) => ubyte | string; +var ctor3: new (f: (a: ushort, b: string) => uint[], [a, b]: ulong[]) => (a: float, b: boolean) => true; +var ctor4: abstract new (a: double, b: string) => char; +var ctor5: abstract new (a: byte[] | string, b?: 5) => short | string; +var ctor6: abstract new (f: (a: int, b: string) => long[], [a, b]: ubyte[]) => (a: ushort, b: boolean) => true; -- Gitee