Skip to content
This repository was archived by the owner on Jan 19, 2019. It is now read-only.

Commit d37bf04

Browse files
IgorbekJamesHenry
authored andcommitted
Fix: Type parameter start location calculation (fixes #260) (#259)
1 parent 1a97650 commit d37bf04

5 files changed

+236
-6
lines changed

Diff for: lib/ast-converter.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -632,8 +632,8 @@ module.exports = function(ast, extra) {
632632
* Have to manually calculate the start of the range,
633633
* because TypeScript includes leading whitespace but Flow does not
634634
*/
635-
var typeParameterStart = (typeParameter.typeName && typeParameter.typeName.text)
636-
? typeParameter.end - typeParameter.typeName.text.length
635+
var typeParameterStart = (typeParameter.name && typeParameter.name.text)
636+
? typeParameter.name.end - typeParameter.name.text.length
637637
: typeParameter.pos;
638638

639639
var defaultParameter = typeParameter.default

Diff for: tests/fixtures/typescript/basics/export-default-class-with-multiple-generics.result.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,13 @@ module.exports = {
7272
"line": 1
7373
},
7474
"start": {
75-
"column": 23,
75+
"column": 24,
7676
"line": 1
7777
}
7878
},
7979
"name": "U",
8080
"range": [
81-
23,
81+
24,
8282
25
8383
],
8484
"type": "TypeParameter",

Diff for: tests/fixtures/typescript/basics/export-named-class-with-multiple-generics.result.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,13 @@ module.exports = {
8989
"line": 1
9090
},
9191
"start": {
92-
"column": 19,
92+
"column": 20,
9393
"line": 1
9494
}
9595
},
9696
"name": "U",
9797
"range": [
98-
19,
98+
20,
9999
21
100100
],
101101
"type": "TypeParameter",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,229 @@
1+
module.exports = {
2+
body: [{
3+
async: false,
4+
body: {
5+
body: [],
6+
loc: {
7+
end: {
8+
column: 35,
9+
line: 1
10+
},
11+
start: {
12+
column: 33,
13+
line: 1
14+
}
15+
},
16+
range: [33, 35],
17+
type: "BlockStatement"
18+
},
19+
expression: false,
20+
generator: false,
21+
id: {
22+
loc: {
23+
end: {
24+
column: 16,
25+
line: 1
26+
},
27+
start: {
28+
column: 9,
29+
line: 1
30+
}
31+
},
32+
name: "compare",
33+
range: [9, 16],
34+
type: "Identifier"
35+
},
36+
loc: {
37+
end: {
38+
column: 35,
39+
line: 1
40+
},
41+
start: {
42+
column: 0,
43+
line: 1
44+
}
45+
},
46+
params: [],
47+
range: [0, 35],
48+
type: "FunctionDeclaration",
49+
typeParameters: {
50+
loc: {
51+
end: {
52+
column: 30,
53+
line: 1
54+
},
55+
start: {
56+
column: 16,
57+
line: 1
58+
}
59+
},
60+
params: [{
61+
constraint: null,
62+
loc: {
63+
end: {
64+
column: 29,
65+
line: 1
66+
},
67+
start: {
68+
column: 28,
69+
line: 1
70+
}
71+
},
72+
name: "T",
73+
range: [28, 29],
74+
type: "TypeParameter"
75+
}],
76+
range: [16, 30],
77+
type: "TypeParameterDeclaration"
78+
}
79+
}],
80+
loc: {
81+
end: {
82+
column: 35,
83+
line: 1
84+
},
85+
start: {
86+
column: 0,
87+
line: 1
88+
}
89+
},
90+
range: [0, 35],
91+
sourceType: "script",
92+
tokens: [{
93+
loc: {
94+
end: {
95+
column: 8,
96+
line: 1
97+
},
98+
start: {
99+
column: 0,
100+
line: 1
101+
}
102+
},
103+
range: [0, 8],
104+
type: "Keyword",
105+
value: "function"
106+
},
107+
{
108+
loc: {
109+
end: {
110+
column: 16,
111+
line: 1
112+
},
113+
start: {
114+
column: 9,
115+
line: 1
116+
}
117+
},
118+
range: [9, 16],
119+
type: "Identifier",
120+
value: "compare"
121+
},
122+
{
123+
loc: {
124+
end: {
125+
column: 17,
126+
line: 1
127+
},
128+
start: {
129+
column: 16,
130+
line: 1
131+
}
132+
},
133+
range: [16, 17],
134+
type: "Punctuator",
135+
value: "<"
136+
},
137+
{
138+
loc: {
139+
end: {
140+
column: 29,
141+
line: 1
142+
},
143+
start: {
144+
column: 28,
145+
line: 1
146+
}
147+
},
148+
range: [28, 29],
149+
type: "Identifier",
150+
value: "T"
151+
},
152+
{
153+
loc: {
154+
end: {
155+
column: 30,
156+
line: 1
157+
},
158+
start: {
159+
column: 29,
160+
line: 1
161+
}
162+
},
163+
range: [29, 30],
164+
type: "Punctuator",
165+
value: ">"
166+
},
167+
{
168+
loc: {
169+
end: {
170+
column: 31,
171+
line: 1
172+
},
173+
start: {
174+
column: 30,
175+
line: 1
176+
}
177+
},
178+
range: [30, 31],
179+
type: "Punctuator",
180+
value: "("
181+
},
182+
{
183+
loc: {
184+
end: {
185+
column: 32,
186+
line: 1
187+
},
188+
start: {
189+
column: 31,
190+
line: 1
191+
}
192+
},
193+
range: [31, 32],
194+
type: "Punctuator",
195+
value: ")"
196+
},
197+
{
198+
loc: {
199+
end: {
200+
column: 34,
201+
line: 1
202+
},
203+
start: {
204+
column: 33,
205+
line: 1
206+
}
207+
},
208+
range: [33, 34],
209+
type: "Punctuator",
210+
value: "{"
211+
},
212+
{
213+
loc: {
214+
end: {
215+
column: 35,
216+
line: 1
217+
},
218+
start: {
219+
column: 34,
220+
line: 1
221+
}
222+
},
223+
range: [34, 35],
224+
type: "Punctuator",
225+
value: "}"
226+
}
227+
],
228+
type: "Program"
229+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
function compare</*comment*/T>() {}

0 commit comments

Comments
 (0)