Merge pull request #201 from kraftwerk28/fix-template-literal-type

Add intersection/union types to `_primary_type`
pull/261/head
Martin Jambon 2022-01-04 14:14:01 +07:00 committed by GitHub
commit 54931b39ae
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 168758 additions and 169166 deletions

@ -1102,6 +1102,7 @@ type A<B, C> = B extends C
: never
: never
type Trim<S extends string> = S extends `${infer R}` ? Trim<R> : S;
type A = `${true & ('foo' | false)}`;
---
(program
(type_alias_declaration
@ -1189,7 +1190,22 @@ type Trim<S extends string> = S extends `${infer R}` ? Trim<R> : S;
(type_identifier)
(type_arguments
(type_identifier)))
(type_identifier))))
(type_identifier)))
(type_alias_declaration
(type_identifier)
(template_literal_type
(template_type
(intersection_type
(literal_type
(true))
(parenthesized_type
(union_type
(literal_type
(string
(string_fragment)))
(literal_type
(false)))))))))
==================================
Mapped type 'as' clauses
==================================

@ -587,8 +587,6 @@ module.exports = function defineGrammar(dialect) {
_type: $ => choice(
$._primary_type,
$.union_type,
$.intersection_type,
$.function_type,
$.readonly_type,
$.constructor_type,
@ -642,12 +640,14 @@ module.exports = function defineGrammar(dialect) {
$.literal_type,
$.lookup_type,
$.conditional_type,
$.template_literal_type
$.template_literal_type,
$.intersection_type,
$.union_type
),
template_type: $ => seq('${',choice($._primary_type, $.infer_type),'}'),
template_type: $ => seq('${', choice($._primary_type, $.infer_type), '}'),
template_literal_type: $ => seq(
template_literal_type: $ => seq(
'`',
repeat(choice(
$._template_chars,

@ -8347,14 +8347,6 @@
"type": "SYMBOL",
"name": "_primary_type"
},
{
"type": "SYMBOL",
"name": "union_type"
},
{
"type": "SYMBOL",
"name": "intersection_type"
},
{
"type": "SYMBOL",
"name": "function_type"
@ -8613,6 +8605,14 @@
{
"type": "SYMBOL",
"name": "template_literal_type"
},
{
"type": "SYMBOL",
"name": "intersection_type"
},
{
"type": "SYMBOL",
"name": "union_type"
}
]
},

@ -27,6 +27,10 @@
"type": "index_type_query",
"named": true
},
{
"type": "intersection_type",
"named": true
},
{
"type": "literal_type",
"named": true
@ -70,6 +74,10 @@
{
"type": "type_query",
"named": true
},
{
"type": "union_type",
"named": true
}
]
},
@ -596,10 +604,6 @@
"type": "infer_type",
"named": true
},
{
"type": "intersection_type",
"named": true
},
{
"type": "property_identifier",
"named": true
@ -611,10 +615,6 @@
{
"type": "statement_block",
"named": true
},
{
"type": "union_type",
"named": true
}
]
}
@ -787,17 +787,9 @@
"type": "infer_type",
"named": true
},
{
"type": "intersection_type",
"named": true
},
{
"type": "readonly_type",
"named": true
},
{
"type": "union_type",
"named": true
}
]
}
@ -1509,17 +1501,9 @@
"type": "infer_type",
"named": true
},
{
"type": "intersection_type",
"named": true
},
{
"type": "readonly_type",
"named": true
},
{
"type": "union_type",
"named": true
}
]
},
@ -1543,17 +1527,9 @@
"type": "infer_type",
"named": true
},
{
"type": "intersection_type",
"named": true
},
{
"type": "readonly_type",
"named": true
},
{
"type": "union_type",
"named": true
}
]
},
@ -1577,17 +1553,9 @@
"type": "infer_type",
"named": true
},
{
"type": "intersection_type",
"named": true
},
{
"type": "readonly_type",
"named": true
},
{
"type": "union_type",
"named": true
}
]
},
@ -1611,17 +1579,9 @@
"type": "infer_type",
"named": true
},
{
"type": "intersection_type",
"named": true
},
{
"type": "readonly_type",
"named": true
},
{
"type": "union_type",
"named": true
}
]
}
@ -1651,17 +1611,9 @@
"type": "infer_type",
"named": true
},
{
"type": "intersection_type",
"named": true
},
{
"type": "readonly_type",
"named": true
},
{
"type": "union_type",
"named": true
}
]
}
@ -1736,17 +1688,9 @@
"type": "infer_type",
"named": true
},
{
"type": "intersection_type",
"named": true
},
{
"type": "readonly_type",
"named": true
},
{
"type": "union_type",
"named": true
}
]
},
@ -1830,17 +1774,9 @@
"type": "infer_type",
"named": true
},
{
"type": "intersection_type",
"named": true
},
{
"type": "readonly_type",
"named": true
},
{
"type": "union_type",
"named": true
}
]
}
@ -2622,10 +2558,6 @@
"type": "infer_type",
"named": true
},
{
"type": "intersection_type",
"named": true
},
{
"type": "readonly_type",
"named": true
@ -2633,10 +2565,6 @@
{
"type": "type_predicate",
"named": true
},
{
"type": "union_type",
"named": true
}
]
},
@ -2870,17 +2798,9 @@
"type": "infer_type",
"named": true
},
{
"type": "intersection_type",
"named": true
},
{
"type": "readonly_type",
"named": true
},
{
"type": "union_type",
"named": true
}
]
}
@ -3038,17 +2958,9 @@
"type": "infer_type",
"named": true
},
{
"type": "intersection_type",
"named": true
},
{
"type": "readonly_type",
"named": true
},
{
"type": "union_type",
"named": true
}
]
},
@ -3236,17 +3148,9 @@
"type": "infer_type",
"named": true
},
{
"type": "intersection_type",
"named": true
},
{
"type": "readonly_type",
"named": true
},
{
"type": "union_type",
"named": true
}
]
}
@ -3650,17 +3554,9 @@
"type": "infer_type",
"named": true
},
{
"type": "intersection_type",
"named": true
},
{
"type": "readonly_type",
"named": true
},
{
"type": "union_type",
"named": true
}
]
}
@ -3689,17 +3585,9 @@
"type": "infer_type",
"named": true
},
{
"type": "intersection_type",
"named": true
},
{
"type": "readonly_type",
"named": true
},
{
"type": "union_type",
"named": true
}
]
},
@ -3733,17 +3621,9 @@
"type": "infer_type",
"named": true
},
{
"type": "intersection_type",
"named": true
},
{
"type": "readonly_type",
"named": true
},
{
"type": "union_type",
"named": true
}
]
}
@ -4288,17 +4168,9 @@
"type": "infer_type",
"named": true
},
{
"type": "intersection_type",
"named": true
},
{
"type": "readonly_type",
"named": true
},
{
"type": "union_type",
"named": true
}
]
}
@ -4327,17 +4199,9 @@
"type": "infer_type",
"named": true
},
{
"type": "intersection_type",
"named": true
},
{
"type": "readonly_type",
"named": true
},
{
"type": "union_type",
"named": true
}
]
}
@ -4440,17 +4304,9 @@
"type": "infer_type",
"named": true
},
{
"type": "intersection_type",
"named": true
},
{
"type": "readonly_type",
"named": true
},
{
"type": "union_type",
"named": true
}
]
}
@ -4602,17 +4458,9 @@
"type": "infer_type",
"named": true
},
{
"type": "intersection_type",
"named": true
},
{
"type": "readonly_type",
"named": true
},
{
"type": "union_type",
"named": true
}
]
}
@ -4787,17 +4635,9 @@
"type": "infer_type",
"named": true
},
{
"type": "intersection_type",
"named": true
},
{
"type": "readonly_type",
"named": true
},
{
"type": "union_type",
"named": true
}
]
}
@ -4969,17 +4809,9 @@
"type": "infer_type",
"named": true
},
{
"type": "intersection_type",
"named": true
},
{
"type": "readonly_type",
"named": true
},
{
"type": "union_type",
"named": true
}
]
}
@ -5402,10 +5234,6 @@
"type": "infer_type",
"named": true
},
{
"type": "intersection_type",
"named": true
},
{
"type": "optional_parameter",
"named": true
@ -5425,10 +5253,6 @@
{
"type": "rest_type",
"named": true
},
{
"type": "union_type",
"named": true
}
]
}
@ -5477,17 +5301,9 @@
"type": "infer_type",
"named": true
},
{
"type": "intersection_type",
"named": true
},
{
"type": "readonly_type",
"named": true
},
{
"type": "union_type",
"named": true
}
]
}
@ -5517,17 +5333,9 @@
"type": "infer_type",
"named": true
},
{
"type": "intersection_type",
"named": true
},
{
"type": "readonly_type",
"named": true
},
{
"type": "union_type",
"named": true
}
]
}
@ -5556,17 +5364,9 @@
"type": "infer_type",
"named": true
},
{
"type": "intersection_type",
"named": true
},
{
"type": "readonly_type",
"named": true
},
{
"type": "union_type",
"named": true
}
]
}
@ -5660,17 +5460,9 @@
"type": "infer_type",
"named": true
},
{
"type": "intersection_type",
"named": true
},
{
"type": "readonly_type",
"named": true
},
{
"type": "union_type",
"named": true
}
]
}
@ -5796,17 +5588,9 @@
"type": "infer_type",
"named": true
},
{
"type": "intersection_type",
"named": true
},
{
"type": "readonly_type",
"named": true
},
{
"type": "union_type",
"named": true
}
]
}

179824
tsx/src/parser.c vendored

File diff suppressed because it is too large Load Diff

@ -8343,14 +8343,6 @@
"type": "SYMBOL",
"name": "_primary_type"
},
{
"type": "SYMBOL",
"name": "union_type"
},
{
"type": "SYMBOL",
"name": "intersection_type"
},
{
"type": "SYMBOL",
"name": "function_type"
@ -8609,6 +8601,14 @@
{
"type": "SYMBOL",
"name": "template_literal_type"
},
{
"type": "SYMBOL",
"name": "intersection_type"
},
{
"type": "SYMBOL",
"name": "union_type"
}
]
},

@ -27,6 +27,10 @@
"type": "index_type_query",
"named": true
},
{
"type": "intersection_type",
"named": true
},
{
"type": "literal_type",
"named": true
@ -70,6 +74,10 @@
{
"type": "type_query",
"named": true
},
{
"type": "union_type",
"named": true
}
]
},
@ -588,10 +596,6 @@
"type": "infer_type",
"named": true
},
{
"type": "intersection_type",
"named": true
},
{
"type": "property_identifier",
"named": true
@ -603,10 +607,6 @@
{
"type": "statement_block",
"named": true
},
{
"type": "union_type",
"named": true
}
]
}
@ -779,17 +779,9 @@
"type": "infer_type",
"named": true
},
{
"type": "intersection_type",
"named": true
},
{
"type": "readonly_type",
"named": true
},
{
"type": "union_type",
"named": true
}
]
}
@ -1501,17 +1493,9 @@
"type": "infer_type",
"named": true
},
{
"type": "intersection_type",
"named": true
},
{
"type": "readonly_type",
"named": true
},
{
"type": "union_type",
"named": true
}
]
},
@ -1535,17 +1519,9 @@
"type": "infer_type",
"named": true
},
{
"type": "intersection_type",
"named": true
},
{
"type": "readonly_type",
"named": true
},
{
"type": "union_type",
"named": true
}
]
},
@ -1569,17 +1545,9 @@
"type": "infer_type",
"named": true
},
{
"type": "intersection_type",
"named": true
},
{
"type": "readonly_type",
"named": true
},
{
"type": "union_type",
"named": true
}
]
},
@ -1603,17 +1571,9 @@
"type": "infer_type",
"named": true
},
{
"type": "intersection_type",
"named": true
},
{
"type": "readonly_type",
"named": true
},
{
"type": "union_type",
"named": true
}
]
}
@ -1643,17 +1603,9 @@
"type": "infer_type",
"named": true
},
{
"type": "intersection_type",
"named": true
},
{
"type": "readonly_type",
"named": true
},
{
"type": "union_type",
"named": true
}
]
}
@ -1728,17 +1680,9 @@
"type": "infer_type",
"named": true
},
{
"type": "intersection_type",
"named": true
},
{
"type": "readonly_type",
"named": true
},
{
"type": "union_type",
"named": true
}
]
},
@ -1822,17 +1766,9 @@
"type": "infer_type",
"named": true
},
{
"type": "intersection_type",
"named": true
},
{
"type": "readonly_type",
"named": true
},
{
"type": "union_type",
"named": true
}
]
}
@ -2614,10 +2550,6 @@
"type": "infer_type",
"named": true
},
{
"type": "intersection_type",
"named": true
},
{
"type": "readonly_type",
"named": true
@ -2625,10 +2557,6 @@
{
"type": "type_predicate",
"named": true
},
{
"type": "union_type",
"named": true
}
]
},
@ -2862,17 +2790,9 @@
"type": "infer_type",
"named": true
},
{
"type": "intersection_type",
"named": true
},
{
"type": "readonly_type",
"named": true
},
{
"type": "union_type",
"named": true
}
]
}
@ -3030,17 +2950,9 @@
"type": "infer_type",
"named": true
},
{
"type": "intersection_type",
"named": true
},
{
"type": "readonly_type",
"named": true
},
{
"type": "union_type",
"named": true
}
]
},
@ -3228,17 +3140,9 @@
"type": "infer_type",
"named": true
},
{
"type": "intersection_type",
"named": true
},
{
"type": "readonly_type",
"named": true
},
{
"type": "union_type",
"named": true
}
]
}
@ -3642,17 +3546,9 @@
"type": "infer_type",
"named": true
},
{
"type": "intersection_type",
"named": true
},
{
"type": "readonly_type",
"named": true
},
{
"type": "union_type",
"named": true
}
]
}
@ -3681,17 +3577,9 @@
"type": "infer_type",
"named": true
},
{
"type": "intersection_type",
"named": true
},
{
"type": "readonly_type",
"named": true
},
{
"type": "union_type",
"named": true
}
]
},
@ -3725,17 +3613,9 @@
"type": "infer_type",
"named": true
},
{
"type": "intersection_type",
"named": true
},
{
"type": "readonly_type",
"named": true
},
{
"type": "union_type",
"named": true
}
]
}
@ -4280,17 +4160,9 @@
"type": "infer_type",
"named": true
},
{
"type": "intersection_type",
"named": true
},
{
"type": "readonly_type",
"named": true
},
{
"type": "union_type",
"named": true
}
]
}
@ -4319,17 +4191,9 @@
"type": "infer_type",
"named": true
},
{
"type": "intersection_type",
"named": true
},
{
"type": "readonly_type",
"named": true
},
{
"type": "union_type",
"named": true
}
]
}
@ -4432,17 +4296,9 @@
"type": "infer_type",
"named": true
},
{
"type": "intersection_type",
"named": true
},
{
"type": "readonly_type",
"named": true
},
{
"type": "union_type",
"named": true
}
]
}
@ -4594,17 +4450,9 @@
"type": "infer_type",
"named": true
},
{
"type": "intersection_type",
"named": true
},
{
"type": "readonly_type",
"named": true
},
{
"type": "union_type",
"named": true
}
]
}
@ -4779,17 +4627,9 @@
"type": "infer_type",
"named": true
},
{
"type": "intersection_type",
"named": true
},
{
"type": "readonly_type",
"named": true
},
{
"type": "union_type",
"named": true
}
]
}
@ -4961,17 +4801,9 @@
"type": "infer_type",
"named": true
},
{
"type": "intersection_type",
"named": true
},
{
"type": "readonly_type",
"named": true
},
{
"type": "union_type",
"named": true
}
]
}
@ -5394,10 +5226,6 @@
"type": "infer_type",
"named": true
},
{
"type": "intersection_type",
"named": true
},
{
"type": "optional_parameter",
"named": true
@ -5417,10 +5245,6 @@
{
"type": "rest_type",
"named": true
},
{
"type": "union_type",
"named": true
}
]
}
@ -5469,17 +5293,9 @@
"type": "infer_type",
"named": true
},
{
"type": "intersection_type",
"named": true
},
{
"type": "readonly_type",
"named": true
},
{
"type": "union_type",
"named": true
}
]
}
@ -5509,17 +5325,9 @@
"type": "infer_type",
"named": true
},
{
"type": "intersection_type",
"named": true
},
{
"type": "readonly_type",
"named": true
},
{
"type": "union_type",
"named": true
}
]
}
@ -5548,17 +5356,9 @@
"type": "infer_type",
"named": true
},
{
"type": "intersection_type",
"named": true
},
{
"type": "readonly_type",
"named": true
},
{
"type": "union_type",
"named": true
}
]
}
@ -5671,17 +5471,9 @@
"type": "infer_type",
"named": true
},
{
"type": "intersection_type",
"named": true
},
{
"type": "readonly_type",
"named": true
},
{
"type": "union_type",
"named": true
}
]
}
@ -5807,17 +5599,9 @@
"type": "infer_type",
"named": true
},
{
"type": "intersection_type",
"named": true
},
{
"type": "readonly_type",
"named": true
},
{
"type": "union_type",
"named": true
}
]
}

157570
typescript/src/parser.c vendored

File diff suppressed because it is too large Load Diff

@ -12,8 +12,8 @@
"resolved" "https://registry.npmjs.org/tree-sitter-cli/-/tree-sitter-cli-0.20.0.tgz"
"version" "0.20.0"
"tree-sitter-javascript@github:tree-sitter/tree-sitter-javascript#2c5b138":
"resolved" "git+ssh://git@github.com/tree-sitter/tree-sitter-javascript.git#2c5b138ea488259dbf11a34595042eb261965259"
"version" "0.19.0"
"tree-sitter-javascript@github:tree-sitter/tree-sitter-javascript#fdeb68a":
"resolved" "git+ssh://git@github.com/tree-sitter/tree-sitter-javascript.git#fdeb68ac8d2bd5a78b943528bb68ceda3aade2eb"
"version" "0.20.0"
dependencies:
"nan" "^2.12.1"