Skip to content

Commit 94ea171

Browse files
committed
Fix: Label variable declartions as Ambient (fixes eslint#185)
1 parent 0fadfc3 commit 94ea171

File tree

3 files changed

+228
-1
lines changed

3 files changed

+228
-1
lines changed

lib/ast-converter.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -954,8 +954,14 @@ module.exports = function(ast, extra) {
954954
break;
955955

956956
case SyntaxKind.VariableStatement:
957+
var variableDeclarationType = "VariableDeclaration",
958+
variableIsAmbient = ts.isInAmbientContext(node);
959+
960+
if (variableIsAmbient) {
961+
variableDeclarationType = "TSAmbientVariableDefinition";
962+
}
957963
assign(result, {
958-
type: "VariableDeclaration",
964+
type: variableDeclarationType,
959965
declarations: node.declarationList.declarations.map(convertChild),
960966
kind: getDeclarationKind(node.declarationList)
961967
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,220 @@
1+
module.exports = {
2+
"body": [
3+
{
4+
"declarations": [
5+
{
6+
"id": {
7+
"loc": {
8+
"end": {
9+
"column": 13,
10+
"line": 1
11+
},
12+
"start": {
13+
"column": 12,
14+
"line": 1
15+
}
16+
},
17+
"name": "a",
18+
"range": [
19+
12,
20+
13
21+
],
22+
"type": "Identifier",
23+
"typeAnnotation": {
24+
"loc": {
25+
"end": {
26+
"column": 21,
27+
"line": 1
28+
},
29+
"start": {
30+
"column": 15,
31+
"line": 1
32+
}
33+
},
34+
"range": [
35+
15,
36+
21
37+
],
38+
"type": "TypeAnnotation",
39+
"typeAnnotation": {
40+
"loc": {
41+
"end": {
42+
"column": 21,
43+
"line": 1
44+
},
45+
"start": {
46+
"column": 15,
47+
"line": 1
48+
}
49+
},
50+
"range": [
51+
15,
52+
21
53+
],
54+
"type": "TSStringKeyword"
55+
}
56+
}
57+
},
58+
"init": null,
59+
"loc": {
60+
"end": {
61+
"column": 21,
62+
"line": 1
63+
},
64+
"start": {
65+
"column": 12,
66+
"line": 1
67+
}
68+
},
69+
"range": [
70+
12,
71+
21
72+
],
73+
"type": "VariableDeclarator"
74+
}
75+
],
76+
"kind": "let",
77+
"loc": {
78+
"end": {
79+
"column": 22,
80+
"line": 1
81+
},
82+
"start": {
83+
"column": 0,
84+
"line": 1
85+
}
86+
},
87+
"range": [
88+
0,
89+
22
90+
],
91+
"type": "TSAmbientVariableDefinition"
92+
}
93+
],
94+
"loc": {
95+
"end": {
96+
"column": 22,
97+
"line": 1
98+
},
99+
"start": {
100+
"column": 0,
101+
"line": 1
102+
}
103+
},
104+
"range": [
105+
0,
106+
22
107+
],
108+
"sourceType": "script",
109+
"tokens": [
110+
{
111+
"loc": {
112+
"end": {
113+
"column": 7,
114+
"line": 1
115+
},
116+
"start": {
117+
"column": 0,
118+
"line": 1
119+
}
120+
},
121+
"range": [
122+
0,
123+
7
124+
],
125+
"type": "Identifier",
126+
"value": "declare"
127+
},
128+
{
129+
"loc": {
130+
"end": {
131+
"column": 11,
132+
"line": 1
133+
},
134+
"start": {
135+
"column": 8,
136+
"line": 1
137+
}
138+
},
139+
"range": [
140+
8,
141+
11
142+
],
143+
"type": "Keyword",
144+
"value": "let"
145+
},
146+
{
147+
"loc": {
148+
"end": {
149+
"column": 13,
150+
"line": 1
151+
},
152+
"start": {
153+
"column": 12,
154+
"line": 1
155+
}
156+
},
157+
"range": [
158+
12,
159+
13
160+
],
161+
"type": "Identifier",
162+
"value": "a"
163+
},
164+
{
165+
"loc": {
166+
"end": {
167+
"column": 14,
168+
"line": 1
169+
},
170+
"start": {
171+
"column": 13,
172+
"line": 1
173+
}
174+
},
175+
"range": [
176+
13,
177+
14
178+
],
179+
"type": "Punctuator",
180+
"value": ":"
181+
},
182+
{
183+
"loc": {
184+
"end": {
185+
"column": 21,
186+
"line": 1
187+
},
188+
"start": {
189+
"column": 15,
190+
"line": 1
191+
}
192+
},
193+
"range": [
194+
15,
195+
21
196+
],
197+
"type": "Identifier",
198+
"value": "string"
199+
},
200+
{
201+
"loc": {
202+
"end": {
203+
"column": 22,
204+
"line": 1
205+
},
206+
"start": {
207+
"column": 21,
208+
"line": 1
209+
}
210+
},
211+
"range": [
212+
21,
213+
22
214+
],
215+
"type": "Punctuator",
216+
"value": ";"
217+
}
218+
],
219+
"type": "Program"
220+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
declare let a: string;

0 commit comments

Comments
 (0)