diff --git a/crates/swc_ecma_lexer/src/common/parser/expr.rs b/crates/swc_ecma_lexer/src/common/parser/expr.rs index 8a74f6fb7899..36f929421983 100644 --- a/crates/swc_ecma_lexer/src/common/parser/expr.rs +++ b/crates/swc_ecma_lexer/src/common/parser/expr.rs @@ -1296,6 +1296,26 @@ pub fn parse_bin_op_recursively<'a>( } } +/// Returns true if the type cannot be followed by type parameters. +/// After these types, `<` should be lexed as a comparison operator, not as +/// the start of type parameters. +fn type_cannot_have_type_params(type_ann: &TsType) -> bool { + matches!( + type_ann, + TsType::TsKeywordType(_) + | TsType::TsLitType(_) + | TsType::TsThisType(_) + | TsType::TsArrayType(_) + | TsType::TsTupleType(_) + | TsType::TsUnionOrIntersectionType(_) + | TsType::TsTypePredicate(_) + | TsType::TsIndexedAccessType(_) + | TsType::TsConditionalType(_) + | TsType::TsMappedType(_) + | TsType::TsTypeOperator(_) + ) +} + /// Returns `(left, Some(next_prec))` or `(expr, None)`. fn parse_bin_op_recursively_inner<'a, P: Parser<'a>>( p: &mut P, @@ -1308,39 +1328,54 @@ fn parse_bin_op_recursively_inner<'a, P: Parser<'a>>( if PREC_OF_IN > min_prec && p.input().is(&P::Token::AS) { let start = left.span_lo(); let expr = left; - let node = if peek!(p).is_some_and(|cur| cur.is_const()) { + return if peek!(p).is_some_and(|cur| cur.is_const()) { p.bump(); // as p.bump(); // const - TsConstAssertion { + let node = TsConstAssertion { span: p.span(start), expr, } - .into() + .into(); + // as const is treated as primitive type + p.do_inside_of_context(Context::ShouldNotLexLtOrGtAsType, |p| { + parse_bin_op_recursively_inner(p, node, min_prec) + }) } else { let type_ann = next_then_parse_ts_type(p)?; - TsAsExpr { + let prevent_type_params = type_cannot_have_type_params(&type_ann); + let node = TsAsExpr { span: p.span(start), expr, type_ann, } - .into() + .into(); + if prevent_type_params { + p.do_inside_of_context(Context::ShouldNotLexLtOrGtAsType, |p| { + parse_bin_op_recursively_inner(p, node, min_prec) + }) + } else { + parse_bin_op_recursively_inner(p, node, min_prec) + } }; - - return parse_bin_op_recursively_inner(p, node, min_prec); } else if p.input().is(&P::Token::SATISFIES) { let start = left.span_lo(); let expr = left; - let node = { - let type_ann = next_then_parse_ts_type(p)?; - TsSatisfiesExpr { - span: p.span(start), - expr, - type_ann, - } - .into() - }; + let type_ann = next_then_parse_ts_type(p)?; + let prevent_type_params = type_cannot_have_type_params(&type_ann); + let node = TsSatisfiesExpr { + span: p.span(start), + expr, + type_ann, + } + .into(); - return parse_bin_op_recursively_inner(p, node, min_prec); + return if prevent_type_params { + p.do_inside_of_context(Context::ShouldNotLexLtOrGtAsType, |p| { + parse_bin_op_recursively_inner(p, node, min_prec) + }) + } else { + parse_bin_op_recursively_inner(p, node, min_prec) + }; } } diff --git a/crates/swc_ecma_lexer/src/common/parser/typescript.rs b/crates/swc_ecma_lexer/src/common/parser/typescript.rs index ae2dc5f458ed..31fa7959746f 100644 --- a/crates/swc_ecma_lexer/src/common/parser/typescript.rs +++ b/crates/swc_ecma_lexer/src/common/parser/typescript.rs @@ -931,12 +931,12 @@ pub(super) fn next_then_parse_ts_type<'a, P: Parser<'a>>(p: &mut P) -> PResult= should be comparison operator +i as number >= 5; +i as string >= "hello"; +i as boolean >= true; +i as any >= foo; +i as void >= bar; +i as undefined >= baz; +i as null >= qux; +i as never >= abc; +i as unknown >= def; +i as object >= ghi; +i as symbol >= jkl; +i as bigint >= 10n; + +// satisfies with primitive types +i satisfies number >= 5; +i satisfies string >= "test"; + +// Literal types - should be treated as primitives +i as 2 >= 5; +i as "x" >= "y"; +i as true >= false; +i as 10n >= 20n; + +// this type - non-callable +i as this >= 5; + +// Array types +i as X[] >= 5; + +// Generic types +i as X >= 5; + +// Tuple types - non-callable +i as [X, Y] >= 5; + +// Union types - non-callable +i as A | string >= 5; +i as A | B >= 5; + +// Intersection types - non-callable +i as A & string >= 5; +i as A & B >= 5; + +// Type operators - non-callable +i as keyof T >= 5; +i as readonly number[] >= 5; +i as unique symbol >= 5; + +// Indexed access types - non-callable +i as T[K] >= 5; + +// Conditional types - non-callable +i as T extends U ? X : string >= 5; +i as T extends U ? X : Y >= 5; + +// Mapped types - non-callable +i as { [K in keyof T]: V } >= 5; diff --git a/crates/swc_ecma_parser/tests/typescript/cast/primitive-vs-reference/input.ts.json b/crates/swc_ecma_parser/tests/typescript/cast/primitive-vs-reference/input.ts.json new file mode 100644 index 000000000000..44d7348f9791 --- /dev/null +++ b/crates/swc_ecma_parser/tests/typescript/cast/primitive-vs-reference/input.ts.json @@ -0,0 +1,2292 @@ +{ + "type": "Script", + "span": { + "start": 63, + "end": 1161 + }, + "body": [ + { + "type": "ExpressionStatement", + "span": { + "start": 63, + "end": 80 + }, + "expression": { + "type": "BinaryExpression", + "span": { + "start": 63, + "end": 79 + }, + "operator": ">=", + "left": { + "type": "TsAsExpression", + "span": { + "start": 63, + "end": 74 + }, + "expression": { + "type": "Identifier", + "span": { + "start": 63, + "end": 64 + }, + "ctxt": 0, + "value": "i", + "optional": false + }, + "typeAnnotation": { + "type": "TsKeywordType", + "span": { + "start": 68, + "end": 74 + }, + "kind": "number" + } + }, + "right": { + "type": "NumericLiteral", + "span": { + "start": 78, + "end": 79 + }, + "value": 5.0, + "raw": "5" + } + } + }, + { + "type": "ExpressionStatement", + "span": { + "start": 81, + "end": 104 + }, + "expression": { + "type": "BinaryExpression", + "span": { + "start": 81, + "end": 103 + }, + "operator": ">=", + "left": { + "type": "TsAsExpression", + "span": { + "start": 81, + "end": 92 + }, + "expression": { + "type": "Identifier", + "span": { + "start": 81, + "end": 82 + }, + "ctxt": 0, + "value": "i", + "optional": false + }, + "typeAnnotation": { + "type": "TsKeywordType", + "span": { + "start": 86, + "end": 92 + }, + "kind": "string" + } + }, + "right": { + "type": "StringLiteral", + "span": { + "start": 96, + "end": 103 + }, + "value": "hello", + "raw": "\"hello\"" + } + } + }, + { + "type": "ExpressionStatement", + "span": { + "start": 105, + "end": 126 + }, + "expression": { + "type": "BinaryExpression", + "span": { + "start": 105, + "end": 125 + }, + "operator": ">=", + "left": { + "type": "TsAsExpression", + "span": { + "start": 105, + "end": 117 + }, + "expression": { + "type": "Identifier", + "span": { + "start": 105, + "end": 106 + }, + "ctxt": 0, + "value": "i", + "optional": false + }, + "typeAnnotation": { + "type": "TsKeywordType", + "span": { + "start": 110, + "end": 117 + }, + "kind": "boolean" + } + }, + "right": { + "type": "BooleanLiteral", + "span": { + "start": 121, + "end": 125 + }, + "value": true + } + } + }, + { + "type": "ExpressionStatement", + "span": { + "start": 127, + "end": 143 + }, + "expression": { + "type": "BinaryExpression", + "span": { + "start": 127, + "end": 142 + }, + "operator": ">=", + "left": { + "type": "TsAsExpression", + "span": { + "start": 127, + "end": 135 + }, + "expression": { + "type": "Identifier", + "span": { + "start": 127, + "end": 128 + }, + "ctxt": 0, + "value": "i", + "optional": false + }, + "typeAnnotation": { + "type": "TsKeywordType", + "span": { + "start": 132, + "end": 135 + }, + "kind": "any" + } + }, + "right": { + "type": "Identifier", + "span": { + "start": 139, + "end": 142 + }, + "ctxt": 0, + "value": "foo", + "optional": false + } + } + }, + { + "type": "ExpressionStatement", + "span": { + "start": 144, + "end": 161 + }, + "expression": { + "type": "BinaryExpression", + "span": { + "start": 144, + "end": 160 + }, + "operator": ">=", + "left": { + "type": "TsAsExpression", + "span": { + "start": 144, + "end": 153 + }, + "expression": { + "type": "Identifier", + "span": { + "start": 144, + "end": 145 + }, + "ctxt": 0, + "value": "i", + "optional": false + }, + "typeAnnotation": { + "type": "TsKeywordType", + "span": { + "start": 149, + "end": 153 + }, + "kind": "void" + } + }, + "right": { + "type": "Identifier", + "span": { + "start": 157, + "end": 160 + }, + "ctxt": 0, + "value": "bar", + "optional": false + } + } + }, + { + "type": "ExpressionStatement", + "span": { + "start": 162, + "end": 184 + }, + "expression": { + "type": "BinaryExpression", + "span": { + "start": 162, + "end": 183 + }, + "operator": ">=", + "left": { + "type": "TsAsExpression", + "span": { + "start": 162, + "end": 176 + }, + "expression": { + "type": "Identifier", + "span": { + "start": 162, + "end": 163 + }, + "ctxt": 0, + "value": "i", + "optional": false + }, + "typeAnnotation": { + "type": "TsKeywordType", + "span": { + "start": 167, + "end": 176 + }, + "kind": "undefined" + } + }, + "right": { + "type": "Identifier", + "span": { + "start": 180, + "end": 183 + }, + "ctxt": 0, + "value": "baz", + "optional": false + } + } + }, + { + "type": "ExpressionStatement", + "span": { + "start": 185, + "end": 202 + }, + "expression": { + "type": "BinaryExpression", + "span": { + "start": 185, + "end": 201 + }, + "operator": ">=", + "left": { + "type": "TsAsExpression", + "span": { + "start": 185, + "end": 194 + }, + "expression": { + "type": "Identifier", + "span": { + "start": 185, + "end": 186 + }, + "ctxt": 0, + "value": "i", + "optional": false + }, + "typeAnnotation": { + "type": "TsKeywordType", + "span": { + "start": 190, + "end": 194 + }, + "kind": "null" + } + }, + "right": { + "type": "Identifier", + "span": { + "start": 198, + "end": 201 + }, + "ctxt": 0, + "value": "qux", + "optional": false + } + } + }, + { + "type": "ExpressionStatement", + "span": { + "start": 203, + "end": 221 + }, + "expression": { + "type": "BinaryExpression", + "span": { + "start": 203, + "end": 220 + }, + "operator": ">=", + "left": { + "type": "TsAsExpression", + "span": { + "start": 203, + "end": 213 + }, + "expression": { + "type": "Identifier", + "span": { + "start": 203, + "end": 204 + }, + "ctxt": 0, + "value": "i", + "optional": false + }, + "typeAnnotation": { + "type": "TsKeywordType", + "span": { + "start": 208, + "end": 213 + }, + "kind": "never" + } + }, + "right": { + "type": "Identifier", + "span": { + "start": 217, + "end": 220 + }, + "ctxt": 0, + "value": "abc", + "optional": false + } + } + }, + { + "type": "ExpressionStatement", + "span": { + "start": 222, + "end": 242 + }, + "expression": { + "type": "BinaryExpression", + "span": { + "start": 222, + "end": 241 + }, + "operator": ">=", + "left": { + "type": "TsAsExpression", + "span": { + "start": 222, + "end": 234 + }, + "expression": { + "type": "Identifier", + "span": { + "start": 222, + "end": 223 + }, + "ctxt": 0, + "value": "i", + "optional": false + }, + "typeAnnotation": { + "type": "TsKeywordType", + "span": { + "start": 227, + "end": 234 + }, + "kind": "unknown" + } + }, + "right": { + "type": "Identifier", + "span": { + "start": 238, + "end": 241 + }, + "ctxt": 0, + "value": "def", + "optional": false + } + } + }, + { + "type": "ExpressionStatement", + "span": { + "start": 243, + "end": 262 + }, + "expression": { + "type": "BinaryExpression", + "span": { + "start": 243, + "end": 261 + }, + "operator": ">=", + "left": { + "type": "TsAsExpression", + "span": { + "start": 243, + "end": 254 + }, + "expression": { + "type": "Identifier", + "span": { + "start": 243, + "end": 244 + }, + "ctxt": 0, + "value": "i", + "optional": false + }, + "typeAnnotation": { + "type": "TsKeywordType", + "span": { + "start": 248, + "end": 254 + }, + "kind": "object" + } + }, + "right": { + "type": "Identifier", + "span": { + "start": 258, + "end": 261 + }, + "ctxt": 0, + "value": "ghi", + "optional": false + } + } + }, + { + "type": "ExpressionStatement", + "span": { + "start": 263, + "end": 282 + }, + "expression": { + "type": "BinaryExpression", + "span": { + "start": 263, + "end": 281 + }, + "operator": ">=", + "left": { + "type": "TsAsExpression", + "span": { + "start": 263, + "end": 274 + }, + "expression": { + "type": "Identifier", + "span": { + "start": 263, + "end": 264 + }, + "ctxt": 0, + "value": "i", + "optional": false + }, + "typeAnnotation": { + "type": "TsKeywordType", + "span": { + "start": 268, + "end": 274 + }, + "kind": "symbol" + } + }, + "right": { + "type": "Identifier", + "span": { + "start": 278, + "end": 281 + }, + "ctxt": 0, + "value": "jkl", + "optional": false + } + } + }, + { + "type": "ExpressionStatement", + "span": { + "start": 283, + "end": 302 + }, + "expression": { + "type": "BinaryExpression", + "span": { + "start": 283, + "end": 301 + }, + "operator": ">=", + "left": { + "type": "TsAsExpression", + "span": { + "start": 283, + "end": 294 + }, + "expression": { + "type": "Identifier", + "span": { + "start": 283, + "end": 284 + }, + "ctxt": 0, + "value": "i", + "optional": false + }, + "typeAnnotation": { + "type": "TsKeywordType", + "span": { + "start": 288, + "end": 294 + }, + "kind": "bigint" + } + }, + "right": { + "type": "BigIntLiteral", + "span": { + "start": 298, + "end": 301 + }, + "value": [ + 1, + [ + 10 + ] + ], + "raw": "10n" + } + } + }, + { + "type": "ExpressionStatement", + "span": { + "start": 338, + "end": 362 + }, + "expression": { + "type": "BinaryExpression", + "span": { + "start": 338, + "end": 361 + }, + "operator": ">=", + "left": { + "type": "TsSatisfiesExpression", + "span": { + "start": 338, + "end": 356 + }, + "expression": { + "type": "Identifier", + "span": { + "start": 338, + "end": 339 + }, + "ctxt": 0, + "value": "i", + "optional": false + }, + "typeAnnotation": { + "type": "TsKeywordType", + "span": { + "start": 350, + "end": 356 + }, + "kind": "number" + } + }, + "right": { + "type": "NumericLiteral", + "span": { + "start": 360, + "end": 361 + }, + "value": 5.0, + "raw": "5" + } + } + }, + { + "type": "ExpressionStatement", + "span": { + "start": 363, + "end": 392 + }, + "expression": { + "type": "BinaryExpression", + "span": { + "start": 363, + "end": 391 + }, + "operator": ">=", + "left": { + "type": "TsSatisfiesExpression", + "span": { + "start": 363, + "end": 381 + }, + "expression": { + "type": "Identifier", + "span": { + "start": 363, + "end": 364 + }, + "ctxt": 0, + "value": "i", + "optional": false + }, + "typeAnnotation": { + "type": "TsKeywordType", + "span": { + "start": 375, + "end": 381 + }, + "kind": "string" + } + }, + "right": { + "type": "StringLiteral", + "span": { + "start": 385, + "end": 391 + }, + "value": "test", + "raw": "\"test\"" + } + } + }, + { + "type": "ExpressionStatement", + "span": { + "start": 445, + "end": 457 + }, + "expression": { + "type": "BinaryExpression", + "span": { + "start": 445, + "end": 456 + }, + "operator": ">=", + "left": { + "type": "TsAsExpression", + "span": { + "start": 445, + "end": 451 + }, + "expression": { + "type": "Identifier", + "span": { + "start": 445, + "end": 446 + }, + "ctxt": 0, + "value": "i", + "optional": false + }, + "typeAnnotation": { + "type": "TsLiteralType", + "span": { + "start": 450, + "end": 451 + }, + "literal": { + "type": "NumericLiteral", + "span": { + "start": 450, + "end": 451 + }, + "value": 2.0, + "raw": "2" + } + } + }, + "right": { + "type": "NumericLiteral", + "span": { + "start": 455, + "end": 456 + }, + "value": 5.0, + "raw": "5" + } + } + }, + { + "type": "ExpressionStatement", + "span": { + "start": 458, + "end": 474 + }, + "expression": { + "type": "BinaryExpression", + "span": { + "start": 458, + "end": 473 + }, + "operator": ">=", + "left": { + "type": "TsAsExpression", + "span": { + "start": 458, + "end": 466 + }, + "expression": { + "type": "Identifier", + "span": { + "start": 458, + "end": 459 + }, + "ctxt": 0, + "value": "i", + "optional": false + }, + "typeAnnotation": { + "type": "TsLiteralType", + "span": { + "start": 463, + "end": 466 + }, + "literal": { + "type": "StringLiteral", + "span": { + "start": 463, + "end": 466 + }, + "value": "x", + "raw": "\"x\"" + } + } + }, + "right": { + "type": "StringLiteral", + "span": { + "start": 470, + "end": 473 + }, + "value": "y", + "raw": "\"y\"" + } + } + }, + { + "type": "ExpressionStatement", + "span": { + "start": 475, + "end": 494 + }, + "expression": { + "type": "BinaryExpression", + "span": { + "start": 475, + "end": 493 + }, + "operator": ">=", + "left": { + "type": "TsAsExpression", + "span": { + "start": 475, + "end": 484 + }, + "expression": { + "type": "Identifier", + "span": { + "start": 475, + "end": 476 + }, + "ctxt": 0, + "value": "i", + "optional": false + }, + "typeAnnotation": { + "type": "TsLiteralType", + "span": { + "start": 480, + "end": 484 + }, + "literal": { + "type": "BooleanLiteral", + "span": { + "start": 480, + "end": 484 + }, + "value": true + } + } + }, + "right": { + "type": "BooleanLiteral", + "span": { + "start": 488, + "end": 493 + }, + "value": false + } + } + }, + { + "type": "ExpressionStatement", + "span": { + "start": 495, + "end": 511 + }, + "expression": { + "type": "BinaryExpression", + "span": { + "start": 495, + "end": 510 + }, + "operator": ">=", + "left": { + "type": "TsAsExpression", + "span": { + "start": 495, + "end": 503 + }, + "expression": { + "type": "Identifier", + "span": { + "start": 495, + "end": 496 + }, + "ctxt": 0, + "value": "i", + "optional": false + }, + "typeAnnotation": { + "type": "TsLiteralType", + "span": { + "start": 500, + "end": 503 + }, + "literal": { + "type": "BigIntLiteral", + "span": { + "start": 500, + "end": 503 + }, + "value": [ + 1, + [ + 10 + ] + ], + "raw": "10n" + } + } + }, + "right": { + "type": "BigIntLiteral", + "span": { + "start": 507, + "end": 510 + }, + "value": [ + 1, + [ + 20 + ] + ], + "raw": "20n" + } + } + }, + { + "type": "ExpressionStatement", + "span": { + "start": 541, + "end": 556 + }, + "expression": { + "type": "BinaryExpression", + "span": { + "start": 541, + "end": 555 + }, + "operator": ">=", + "left": { + "type": "TsAsExpression", + "span": { + "start": 541, + "end": 550 + }, + "expression": { + "type": "Identifier", + "span": { + "start": 541, + "end": 542 + }, + "ctxt": 0, + "value": "i", + "optional": false + }, + "typeAnnotation": { + "type": "TsThisType", + "span": { + "start": 546, + "end": 550 + } + } + }, + "right": { + "type": "NumericLiteral", + "span": { + "start": 554, + "end": 555 + }, + "value": 5.0, + "raw": "5" + } + } + }, + { + "type": "ExpressionStatement", + "span": { + "start": 573, + "end": 587 + }, + "expression": { + "type": "BinaryExpression", + "span": { + "start": 573, + "end": 586 + }, + "operator": ">=", + "left": { + "type": "TsAsExpression", + "span": { + "start": 573, + "end": 581 + }, + "expression": { + "type": "Identifier", + "span": { + "start": 573, + "end": 574 + }, + "ctxt": 0, + "value": "i", + "optional": false + }, + "typeAnnotation": { + "type": "TsArrayType", + "span": { + "start": 578, + "end": 581 + }, + "elemType": { + "type": "TsTypeReference", + "span": { + "start": 578, + "end": 579 + }, + "typeName": { + "type": "Identifier", + "span": { + "start": 578, + "end": 579 + }, + "ctxt": 0, + "value": "X", + "optional": false + }, + "typeParams": null + } + } + }, + "right": { + "type": "NumericLiteral", + "span": { + "start": 585, + "end": 586 + }, + "value": 5.0, + "raw": "5" + } + } + }, + { + "type": "ExpressionStatement", + "span": { + "start": 606, + "end": 621 + }, + "expression": { + "type": "BinaryExpression", + "span": { + "start": 606, + "end": 620 + }, + "operator": ">=", + "left": { + "type": "TsAsExpression", + "span": { + "start": 606, + "end": 615 + }, + "expression": { + "type": "Identifier", + "span": { + "start": 606, + "end": 607 + }, + "ctxt": 0, + "value": "i", + "optional": false + }, + "typeAnnotation": { + "type": "TsTypeReference", + "span": { + "start": 611, + "end": 615 + }, + "typeName": { + "type": "Identifier", + "span": { + "start": 611, + "end": 612 + }, + "ctxt": 0, + "value": "X", + "optional": false + }, + "typeParams": { + "type": "TsTypeParameterInstantiation", + "span": { + "start": 612, + "end": 615 + }, + "params": [ + { + "type": "TsTypeReference", + "span": { + "start": 613, + "end": 614 + }, + "typeName": { + "type": "Identifier", + "span": { + "start": 613, + "end": 614 + }, + "ctxt": 0, + "value": "Y", + "optional": false + }, + "typeParams": null + } + ] + } + } + }, + "right": { + "type": "NumericLiteral", + "span": { + "start": 619, + "end": 620 + }, + "value": 5.0, + "raw": "5" + } + } + }, + { + "type": "ExpressionStatement", + "span": { + "start": 653, + "end": 670 + }, + "expression": { + "type": "BinaryExpression", + "span": { + "start": 653, + "end": 669 + }, + "operator": ">=", + "left": { + "type": "TsAsExpression", + "span": { + "start": 653, + "end": 664 + }, + "expression": { + "type": "Identifier", + "span": { + "start": 653, + "end": 654 + }, + "ctxt": 0, + "value": "i", + "optional": false + }, + "typeAnnotation": { + "type": "TsTupleType", + "span": { + "start": 658, + "end": 664 + }, + "elemTypes": [ + { + "type": "TsTupleElement", + "span": { + "start": 659, + "end": 660 + }, + "label": null, + "ty": { + "type": "TsTypeReference", + "span": { + "start": 659, + "end": 660 + }, + "typeName": { + "type": "Identifier", + "span": { + "start": 659, + "end": 660 + }, + "ctxt": 0, + "value": "X", + "optional": false + }, + "typeParams": null + } + }, + { + "type": "TsTupleElement", + "span": { + "start": 662, + "end": 663 + }, + "label": null, + "ty": { + "type": "TsTypeReference", + "span": { + "start": 662, + "end": 663 + }, + "typeName": { + "type": "Identifier", + "span": { + "start": 662, + "end": 663 + }, + "ctxt": 0, + "value": "Y", + "optional": false + }, + "typeParams": null + } + } + ] + } + }, + "right": { + "type": "NumericLiteral", + "span": { + "start": 668, + "end": 669 + }, + "value": 5.0, + "raw": "5" + } + } + }, + { + "type": "ExpressionStatement", + "span": { + "start": 702, + "end": 723 + }, + "expression": { + "type": "BinaryExpression", + "span": { + "start": 702, + "end": 722 + }, + "operator": ">=", + "left": { + "type": "TsAsExpression", + "span": { + "start": 702, + "end": 717 + }, + "expression": { + "type": "Identifier", + "span": { + "start": 702, + "end": 703 + }, + "ctxt": 0, + "value": "i", + "optional": false + }, + "typeAnnotation": { + "type": "TsUnionType", + "span": { + "start": 707, + "end": 717 + }, + "types": [ + { + "type": "TsTypeReference", + "span": { + "start": 707, + "end": 708 + }, + "typeName": { + "type": "Identifier", + "span": { + "start": 707, + "end": 708 + }, + "ctxt": 0, + "value": "A", + "optional": false + }, + "typeParams": null + }, + { + "type": "TsKeywordType", + "span": { + "start": 711, + "end": 717 + }, + "kind": "string" + } + ] + } + }, + "right": { + "type": "NumericLiteral", + "span": { + "start": 721, + "end": 722 + }, + "value": 5.0, + "raw": "5" + } + } + }, + { + "type": "ExpressionStatement", + "span": { + "start": 724, + "end": 743 + }, + "expression": { + "type": "BinaryExpression", + "span": { + "start": 724, + "end": 742 + }, + "operator": ">=", + "left": { + "type": "TsAsExpression", + "span": { + "start": 724, + "end": 737 + }, + "expression": { + "type": "Identifier", + "span": { + "start": 724, + "end": 725 + }, + "ctxt": 0, + "value": "i", + "optional": false + }, + "typeAnnotation": { + "type": "TsUnionType", + "span": { + "start": 729, + "end": 737 + }, + "types": [ + { + "type": "TsTypeReference", + "span": { + "start": 729, + "end": 730 + }, + "typeName": { + "type": "Identifier", + "span": { + "start": 729, + "end": 730 + }, + "ctxt": 0, + "value": "A", + "optional": false + }, + "typeParams": null + }, + { + "type": "TsTypeReference", + "span": { + "start": 733, + "end": 737 + }, + "typeName": { + "type": "Identifier", + "span": { + "start": 733, + "end": 734 + }, + "ctxt": 0, + "value": "B", + "optional": false + }, + "typeParams": { + "type": "TsTypeParameterInstantiation", + "span": { + "start": 734, + "end": 737 + }, + "params": [ + { + "type": "TsTypeReference", + "span": { + "start": 735, + "end": 736 + }, + "typeName": { + "type": "Identifier", + "span": { + "start": 735, + "end": 736 + }, + "ctxt": 0, + "value": "T", + "optional": false + }, + "typeParams": null + } + ] + } + } + ] + } + }, + "right": { + "type": "NumericLiteral", + "span": { + "start": 741, + "end": 742 + }, + "value": 5.0, + "raw": "5" + } + } + }, + { + "type": "ExpressionStatement", + "span": { + "start": 782, + "end": 803 + }, + "expression": { + "type": "BinaryExpression", + "span": { + "start": 782, + "end": 802 + }, + "operator": ">=", + "left": { + "type": "TsAsExpression", + "span": { + "start": 782, + "end": 797 + }, + "expression": { + "type": "Identifier", + "span": { + "start": 782, + "end": 783 + }, + "ctxt": 0, + "value": "i", + "optional": false + }, + "typeAnnotation": { + "type": "TsIntersectionType", + "span": { + "start": 787, + "end": 797 + }, + "types": [ + { + "type": "TsTypeReference", + "span": { + "start": 787, + "end": 788 + }, + "typeName": { + "type": "Identifier", + "span": { + "start": 787, + "end": 788 + }, + "ctxt": 0, + "value": "A", + "optional": false + }, + "typeParams": null + }, + { + "type": "TsKeywordType", + "span": { + "start": 791, + "end": 797 + }, + "kind": "string" + } + ] + } + }, + "right": { + "type": "NumericLiteral", + "span": { + "start": 801, + "end": 802 + }, + "value": 5.0, + "raw": "5" + } + } + }, + { + "type": "ExpressionStatement", + "span": { + "start": 804, + "end": 823 + }, + "expression": { + "type": "BinaryExpression", + "span": { + "start": 804, + "end": 822 + }, + "operator": ">=", + "left": { + "type": "TsAsExpression", + "span": { + "start": 804, + "end": 817 + }, + "expression": { + "type": "Identifier", + "span": { + "start": 804, + "end": 805 + }, + "ctxt": 0, + "value": "i", + "optional": false + }, + "typeAnnotation": { + "type": "TsIntersectionType", + "span": { + "start": 809, + "end": 817 + }, + "types": [ + { + "type": "TsTypeReference", + "span": { + "start": 809, + "end": 810 + }, + "typeName": { + "type": "Identifier", + "span": { + "start": 809, + "end": 810 + }, + "ctxt": 0, + "value": "A", + "optional": false + }, + "typeParams": null + }, + { + "type": "TsTypeReference", + "span": { + "start": 813, + "end": 817 + }, + "typeName": { + "type": "Identifier", + "span": { + "start": 813, + "end": 814 + }, + "ctxt": 0, + "value": "B", + "optional": false + }, + "typeParams": { + "type": "TsTypeParameterInstantiation", + "span": { + "start": 814, + "end": 817 + }, + "params": [ + { + "type": "TsTypeReference", + "span": { + "start": 815, + "end": 816 + }, + "typeName": { + "type": "Identifier", + "span": { + "start": 815, + "end": 816 + }, + "ctxt": 0, + "value": "T", + "optional": false + }, + "typeParams": null + } + ] + } + } + ] + } + }, + "right": { + "type": "NumericLiteral", + "span": { + "start": 821, + "end": 822 + }, + "value": 5.0, + "raw": "5" + } + } + }, + { + "type": "ExpressionStatement", + "span": { + "start": 858, + "end": 879 + }, + "expression": { + "type": "BinaryExpression", + "span": { + "start": 858, + "end": 878 + }, + "operator": ">=", + "left": { + "type": "TsAsExpression", + "span": { + "start": 858, + "end": 873 + }, + "expression": { + "type": "Identifier", + "span": { + "start": 858, + "end": 859 + }, + "ctxt": 0, + "value": "i", + "optional": false + }, + "typeAnnotation": { + "type": "TsTypeOperator", + "span": { + "start": 863, + "end": 873 + }, + "op": "keyof", + "typeAnnotation": { + "type": "TsTypeReference", + "span": { + "start": 869, + "end": 873 + }, + "typeName": { + "type": "Identifier", + "span": { + "start": 869, + "end": 870 + }, + "ctxt": 0, + "value": "T", + "optional": false + }, + "typeParams": { + "type": "TsTypeParameterInstantiation", + "span": { + "start": 870, + "end": 873 + }, + "params": [ + { + "type": "TsTypeReference", + "span": { + "start": 871, + "end": 872 + }, + "typeName": { + "type": "Identifier", + "span": { + "start": 871, + "end": 872 + }, + "ctxt": 0, + "value": "U", + "optional": false + }, + "typeParams": null + } + ] + } + } + } + }, + "right": { + "type": "NumericLiteral", + "span": { + "start": 877, + "end": 878 + }, + "value": 5.0, + "raw": "5" + } + } + }, + { + "type": "ExpressionStatement", + "span": { + "start": 880, + "end": 908 + }, + "expression": { + "type": "BinaryExpression", + "span": { + "start": 880, + "end": 907 + }, + "operator": ">=", + "left": { + "type": "TsAsExpression", + "span": { + "start": 880, + "end": 902 + }, + "expression": { + "type": "Identifier", + "span": { + "start": 880, + "end": 881 + }, + "ctxt": 0, + "value": "i", + "optional": false + }, + "typeAnnotation": { + "type": "TsTypeOperator", + "span": { + "start": 885, + "end": 902 + }, + "op": "readonly", + "typeAnnotation": { + "type": "TsArrayType", + "span": { + "start": 894, + "end": 902 + }, + "elemType": { + "type": "TsKeywordType", + "span": { + "start": 894, + "end": 900 + }, + "kind": "number" + } + } + } + }, + "right": { + "type": "NumericLiteral", + "span": { + "start": 906, + "end": 907 + }, + "value": 5.0, + "raw": "5" + } + } + }, + { + "type": "ExpressionStatement", + "span": { + "start": 909, + "end": 933 + }, + "expression": { + "type": "BinaryExpression", + "span": { + "start": 909, + "end": 932 + }, + "operator": ">=", + "left": { + "type": "TsAsExpression", + "span": { + "start": 909, + "end": 927 + }, + "expression": { + "type": "Identifier", + "span": { + "start": 909, + "end": 910 + }, + "ctxt": 0, + "value": "i", + "optional": false + }, + "typeAnnotation": { + "type": "TsTypeOperator", + "span": { + "start": 914, + "end": 927 + }, + "op": "unique", + "typeAnnotation": { + "type": "TsKeywordType", + "span": { + "start": 921, + "end": 927 + }, + "kind": "symbol" + } + } + }, + "right": { + "type": "NumericLiteral", + "span": { + "start": 931, + "end": 932 + }, + "value": 5.0, + "raw": "5" + } + } + }, + { + "type": "ExpressionStatement", + "span": { + "start": 974, + "end": 989 + }, + "expression": { + "type": "BinaryExpression", + "span": { + "start": 974, + "end": 988 + }, + "operator": ">=", + "left": { + "type": "TsAsExpression", + "span": { + "start": 974, + "end": 983 + }, + "expression": { + "type": "Identifier", + "span": { + "start": 974, + "end": 975 + }, + "ctxt": 0, + "value": "i", + "optional": false + }, + "typeAnnotation": { + "type": "TsIndexedAccessType", + "span": { + "start": 979, + "end": 983 + }, + "readonly": false, + "objectType": { + "type": "TsTypeReference", + "span": { + "start": 979, + "end": 980 + }, + "typeName": { + "type": "Identifier", + "span": { + "start": 979, + "end": 980 + }, + "ctxt": 0, + "value": "T", + "optional": false + }, + "typeParams": null + }, + "indexType": { + "type": "TsTypeReference", + "span": { + "start": 981, + "end": 982 + }, + "typeName": { + "type": "Identifier", + "span": { + "start": 981, + "end": 982 + }, + "ctxt": 0, + "value": "K", + "optional": false + }, + "typeParams": null + } + } + }, + "right": { + "type": "NumericLiteral", + "span": { + "start": 987, + "end": 988 + }, + "value": 5.0, + "raw": "5" + } + } + }, + { + "type": "ExpressionStatement", + "span": { + "start": 1027, + "end": 1062 + }, + "expression": { + "type": "BinaryExpression", + "span": { + "start": 1027, + "end": 1061 + }, + "operator": ">=", + "left": { + "type": "TsAsExpression", + "span": { + "start": 1027, + "end": 1056 + }, + "expression": { + "type": "Identifier", + "span": { + "start": 1027, + "end": 1028 + }, + "ctxt": 0, + "value": "i", + "optional": false + }, + "typeAnnotation": { + "type": "TsConditionalType", + "span": { + "start": 1032, + "end": 1056 + }, + "checkType": { + "type": "TsTypeReference", + "span": { + "start": 1032, + "end": 1033 + }, + "typeName": { + "type": "Identifier", + "span": { + "start": 1032, + "end": 1033 + }, + "ctxt": 0, + "value": "T", + "optional": false + }, + "typeParams": null + }, + "extendsType": { + "type": "TsTypeReference", + "span": { + "start": 1042, + "end": 1043 + }, + "typeName": { + "type": "Identifier", + "span": { + "start": 1042, + "end": 1043 + }, + "ctxt": 0, + "value": "U", + "optional": false + }, + "typeParams": null + }, + "trueType": { + "type": "TsTypeReference", + "span": { + "start": 1046, + "end": 1047 + }, + "typeName": { + "type": "Identifier", + "span": { + "start": 1046, + "end": 1047 + }, + "ctxt": 0, + "value": "X", + "optional": false + }, + "typeParams": null + }, + "falseType": { + "type": "TsKeywordType", + "span": { + "start": 1050, + "end": 1056 + }, + "kind": "string" + } + } + }, + "right": { + "type": "NumericLiteral", + "span": { + "start": 1060, + "end": 1061 + }, + "value": 5.0, + "raw": "5" + } + } + }, + { + "type": "ExpressionStatement", + "span": { + "start": 1063, + "end": 1096 + }, + "expression": { + "type": "BinaryExpression", + "span": { + "start": 1063, + "end": 1095 + }, + "operator": ">=", + "left": { + "type": "TsAsExpression", + "span": { + "start": 1063, + "end": 1090 + }, + "expression": { + "type": "Identifier", + "span": { + "start": 1063, + "end": 1064 + }, + "ctxt": 0, + "value": "i", + "optional": false + }, + "typeAnnotation": { + "type": "TsConditionalType", + "span": { + "start": 1068, + "end": 1090 + }, + "checkType": { + "type": "TsTypeReference", + "span": { + "start": 1068, + "end": 1069 + }, + "typeName": { + "type": "Identifier", + "span": { + "start": 1068, + "end": 1069 + }, + "ctxt": 0, + "value": "T", + "optional": false + }, + "typeParams": null + }, + "extendsType": { + "type": "TsTypeReference", + "span": { + "start": 1078, + "end": 1079 + }, + "typeName": { + "type": "Identifier", + "span": { + "start": 1078, + "end": 1079 + }, + "ctxt": 0, + "value": "U", + "optional": false + }, + "typeParams": null + }, + "trueType": { + "type": "TsTypeReference", + "span": { + "start": 1082, + "end": 1083 + }, + "typeName": { + "type": "Identifier", + "span": { + "start": 1082, + "end": 1083 + }, + "ctxt": 0, + "value": "X", + "optional": false + }, + "typeParams": null + }, + "falseType": { + "type": "TsTypeReference", + "span": { + "start": 1086, + "end": 1090 + }, + "typeName": { + "type": "Identifier", + "span": { + "start": 1086, + "end": 1087 + }, + "ctxt": 0, + "value": "Y", + "optional": false + }, + "typeParams": { + "type": "TsTypeParameterInstantiation", + "span": { + "start": 1087, + "end": 1090 + }, + "params": [ + { + "type": "TsTypeReference", + "span": { + "start": 1088, + "end": 1089 + }, + "typeName": { + "type": "Identifier", + "span": { + "start": 1088, + "end": 1089 + }, + "ctxt": 0, + "value": "T", + "optional": false + }, + "typeParams": null + } + ] + } + } + } + }, + "right": { + "type": "NumericLiteral", + "span": { + "start": 1094, + "end": 1095 + }, + "value": 5.0, + "raw": "5" + } + } + }, + { + "type": "ExpressionStatement", + "span": { + "start": 1129, + "end": 1161 + }, + "expression": { + "type": "BinaryExpression", + "span": { + "start": 1129, + "end": 1160 + }, + "operator": ">=", + "left": { + "type": "TsAsExpression", + "span": { + "start": 1129, + "end": 1155 + }, + "expression": { + "type": "Identifier", + "span": { + "start": 1129, + "end": 1130 + }, + "ctxt": 0, + "value": "i", + "optional": false + }, + "typeAnnotation": { + "type": "TsMappedType", + "span": { + "start": 1134, + "end": 1155 + }, + "readonly": null, + "typeParam": { + "type": "TsTypeParameter", + "span": { + "start": 1137, + "end": 1149 + }, + "name": { + "type": "Identifier", + "span": { + "start": 1137, + "end": 1138 + }, + "ctxt": 0, + "value": "K", + "optional": false + }, + "in": false, + "out": false, + "const": false, + "constraint": { + "type": "TsTypeOperator", + "span": { + "start": 1142, + "end": 1149 + }, + "op": "keyof", + "typeAnnotation": { + "type": "TsTypeReference", + "span": { + "start": 1148, + "end": 1149 + }, + "typeName": { + "type": "Identifier", + "span": { + "start": 1148, + "end": 1149 + }, + "ctxt": 0, + "value": "T", + "optional": false + }, + "typeParams": null + } + }, + "default": null + }, + "nameType": null, + "optional": null, + "typeAnnotation": { + "type": "TsTypeReference", + "span": { + "start": 1152, + "end": 1153 + }, + "typeName": { + "type": "Identifier", + "span": { + "start": 1152, + "end": 1153 + }, + "ctxt": 0, + "value": "V", + "optional": false + }, + "typeParams": null + } + } + }, + "right": { + "type": "NumericLiteral", + "span": { + "start": 1159, + "end": 1160 + }, + "value": 5.0, + "raw": "5" + } + } + } + ], + "interpreter": null +}