Skip to content

Commit f97ea03

Browse files
authored
fix(es/parser): Correctly check ambient context (#10802)
**Related issue:** - Closes #10800
1 parent ae22033 commit f97ea03

File tree

4 files changed

+113
-1
lines changed

4 files changed

+113
-1
lines changed

.changeset/slimy-ties-glow.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
swc_core: patch
3+
swc_ecma_lexer: patch
4+
---
5+
6+
fix(es/parser): Correctly check ambient context

crates/swc_ecma_lexer/src/common/parser/typescript.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2666,7 +2666,9 @@ pub fn try_parse_ts_declare<'a, P: Parser<'a>>(
26662666
return Ok(None);
26672667
}
26682668

2669-
if p.ctx().contains(Context::InDeclare) && p.syntax().dts() {
2669+
if p.ctx()
2670+
.contains(Context::InDeclare | Context::TsModuleBlock)
2671+
{
26702672
let span_of_declare = p.span(start);
26712673
p.emit_err(span_of_declare, SyntaxError::TS1038);
26722674
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// useTrigger.d.ts
2+
export declare const useTrigger: () => (() => void);
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
{
2+
"type": "Module",
3+
"span": {
4+
"start": 20,
5+
"end": 72
6+
},
7+
"body": [
8+
{
9+
"type": "ExportDeclaration",
10+
"span": {
11+
"start": 20,
12+
"end": 72
13+
},
14+
"declaration": {
15+
"type": "VariableDeclaration",
16+
"span": {
17+
"start": 27,
18+
"end": 72
19+
},
20+
"ctxt": 0,
21+
"kind": "const",
22+
"declare": true,
23+
"declarations": [
24+
{
25+
"type": "VariableDeclarator",
26+
"span": {
27+
"start": 41,
28+
"end": 71
29+
},
30+
"id": {
31+
"type": "Identifier",
32+
"span": {
33+
"start": 41,
34+
"end": 51
35+
},
36+
"ctxt": 0,
37+
"value": "useTrigger",
38+
"optional": false,
39+
"typeAnnotation": {
40+
"type": "TsTypeAnnotation",
41+
"span": {
42+
"start": 51,
43+
"end": 71
44+
},
45+
"typeAnnotation": {
46+
"type": "TsFunctionType",
47+
"span": {
48+
"start": 53,
49+
"end": 71
50+
},
51+
"params": [],
52+
"typeParams": null,
53+
"typeAnnotation": {
54+
"type": "TsTypeAnnotation",
55+
"span": {
56+
"start": 56,
57+
"end": 71
58+
},
59+
"typeAnnotation": {
60+
"type": "TsParenthesizedType",
61+
"span": {
62+
"start": 59,
63+
"end": 71
64+
},
65+
"typeAnnotation": {
66+
"type": "TsFunctionType",
67+
"span": {
68+
"start": 60,
69+
"end": 70
70+
},
71+
"params": [],
72+
"typeParams": null,
73+
"typeAnnotation": {
74+
"type": "TsTypeAnnotation",
75+
"span": {
76+
"start": 63,
77+
"end": 70
78+
},
79+
"typeAnnotation": {
80+
"type": "TsKeywordType",
81+
"span": {
82+
"start": 66,
83+
"end": 70
84+
},
85+
"kind": "void"
86+
}
87+
}
88+
}
89+
}
90+
}
91+
}
92+
}
93+
},
94+
"init": null,
95+
"definite": false
96+
}
97+
]
98+
}
99+
}
100+
],
101+
"interpreter": null
102+
}

0 commit comments

Comments
 (0)