Skip to content

Commit 77900d8

Browse files
authored
fix(es/parser): Fix failure of TS instantiation followed by satisfies (#9583)
**Related issue:** it's already ok when followed by `as`. Closes #8627
1 parent 74e3d04 commit 77900d8

File tree

6 files changed

+257
-1
lines changed

6 files changed

+257
-1
lines changed

.changeset/forty-rats-flow.md

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
swc_ecma_parser: patch
3+
swc_core: patch
4+
---
5+
6+
fix(es/parser): Fix failure of TS instantiation followed by satisfies

crates/swc_ecma_parser/src/parser/expr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1245,7 +1245,7 @@ impl<I: Tokens> Parser<I> {
12451245
)
12461246
.map(|expr| (expr.into(), true))
12471247
.map(Some)
1248-
} else if is_one_of!(p, '=', "as") {
1248+
} else if is_one_of!(p, '=', "as", "satisfies") {
12491249
Ok(Some((
12501250
TsInstantiation {
12511251
span: span!(p, start),
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
class Module<T> {}
2+
3+
export default Module<number> as unknown;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
{
2+
"type": "Module",
3+
"span": {
4+
"start": 1,
5+
"end": 62
6+
},
7+
"body": [
8+
{
9+
"type": "ClassDeclaration",
10+
"identifier": {
11+
"type": "Identifier",
12+
"span": {
13+
"start": 7,
14+
"end": 13
15+
},
16+
"ctxt": 0,
17+
"value": "Module",
18+
"optional": false
19+
},
20+
"declare": false,
21+
"span": {
22+
"start": 1,
23+
"end": 19
24+
},
25+
"ctxt": 0,
26+
"decorators": [],
27+
"body": [],
28+
"superClass": null,
29+
"isAbstract": false,
30+
"typeParams": {
31+
"type": "TsTypeParameterDeclaration",
32+
"span": {
33+
"start": 13,
34+
"end": 16
35+
},
36+
"parameters": [
37+
{
38+
"type": "TsTypeParameter",
39+
"span": {
40+
"start": 14,
41+
"end": 15
42+
},
43+
"name": {
44+
"type": "Identifier",
45+
"span": {
46+
"start": 14,
47+
"end": 15
48+
},
49+
"ctxt": 0,
50+
"value": "T",
51+
"optional": false
52+
},
53+
"in": false,
54+
"out": false,
55+
"const": false,
56+
"constraint": null,
57+
"default": null
58+
}
59+
]
60+
},
61+
"superTypeParams": null,
62+
"implements": []
63+
},
64+
{
65+
"type": "ExportDefaultExpression",
66+
"span": {
67+
"start": 21,
68+
"end": 62
69+
},
70+
"expression": {
71+
"type": "TsAsExpression",
72+
"span": {
73+
"start": 36,
74+
"end": 61
75+
},
76+
"expression": {
77+
"type": "TsInstantiation",
78+
"span": {
79+
"start": 36,
80+
"end": 50
81+
},
82+
"expression": {
83+
"type": "Identifier",
84+
"span": {
85+
"start": 36,
86+
"end": 42
87+
},
88+
"ctxt": 0,
89+
"value": "Module",
90+
"optional": false
91+
},
92+
"typeArguments": {
93+
"type": "TsTypeParameterInstantiation",
94+
"span": {
95+
"start": 42,
96+
"end": 50
97+
},
98+
"params": [
99+
{
100+
"type": "TsKeywordType",
101+
"span": {
102+
"start": 43,
103+
"end": 49
104+
},
105+
"kind": "number"
106+
}
107+
]
108+
}
109+
},
110+
"typeAnnotation": {
111+
"type": "TsKeywordType",
112+
"span": {
113+
"start": 54,
114+
"end": 61
115+
},
116+
"kind": "unknown"
117+
}
118+
}
119+
}
120+
],
121+
"interpreter": null
122+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
class Module<T> {}
2+
3+
export default Module<number> satisfies unknown;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
{
2+
"type": "Module",
3+
"span": {
4+
"start": 1,
5+
"end": 69
6+
},
7+
"body": [
8+
{
9+
"type": "ClassDeclaration",
10+
"identifier": {
11+
"type": "Identifier",
12+
"span": {
13+
"start": 7,
14+
"end": 13
15+
},
16+
"ctxt": 0,
17+
"value": "Module",
18+
"optional": false
19+
},
20+
"declare": false,
21+
"span": {
22+
"start": 1,
23+
"end": 19
24+
},
25+
"ctxt": 0,
26+
"decorators": [],
27+
"body": [],
28+
"superClass": null,
29+
"isAbstract": false,
30+
"typeParams": {
31+
"type": "TsTypeParameterDeclaration",
32+
"span": {
33+
"start": 13,
34+
"end": 16
35+
},
36+
"parameters": [
37+
{
38+
"type": "TsTypeParameter",
39+
"span": {
40+
"start": 14,
41+
"end": 15
42+
},
43+
"name": {
44+
"type": "Identifier",
45+
"span": {
46+
"start": 14,
47+
"end": 15
48+
},
49+
"ctxt": 0,
50+
"value": "T",
51+
"optional": false
52+
},
53+
"in": false,
54+
"out": false,
55+
"const": false,
56+
"constraint": null,
57+
"default": null
58+
}
59+
]
60+
},
61+
"superTypeParams": null,
62+
"implements": []
63+
},
64+
{
65+
"type": "ExportDefaultExpression",
66+
"span": {
67+
"start": 21,
68+
"end": 69
69+
},
70+
"expression": {
71+
"type": "TsSatisfiesExpression",
72+
"span": {
73+
"start": 36,
74+
"end": 68
75+
},
76+
"expression": {
77+
"type": "TsInstantiation",
78+
"span": {
79+
"start": 36,
80+
"end": 50
81+
},
82+
"expression": {
83+
"type": "Identifier",
84+
"span": {
85+
"start": 36,
86+
"end": 42
87+
},
88+
"ctxt": 0,
89+
"value": "Module",
90+
"optional": false
91+
},
92+
"typeArguments": {
93+
"type": "TsTypeParameterInstantiation",
94+
"span": {
95+
"start": 42,
96+
"end": 50
97+
},
98+
"params": [
99+
{
100+
"type": "TsKeywordType",
101+
"span": {
102+
"start": 43,
103+
"end": 49
104+
},
105+
"kind": "number"
106+
}
107+
]
108+
}
109+
},
110+
"typeAnnotation": {
111+
"type": "TsKeywordType",
112+
"span": {
113+
"start": 61,
114+
"end": 68
115+
},
116+
"kind": "unknown"
117+
}
118+
}
119+
}
120+
],
121+
"interpreter": null
122+
}

0 commit comments

Comments
 (0)