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

Commit c8e881a

Browse files
PajnJamesHenry
authored andcommitted
Breaking: Normalize type parameters (fixes #197) (#196)
1 parent d37bf04 commit c8e881a

16 files changed

+1573
-1032
lines changed

Diff for: lib/ast-converter.js

+8
Original file line numberDiff line numberDiff line change
@@ -709,6 +709,14 @@ module.exports = function(ast, extra) {
709709
}).forEach(function(key) {
710710
if (key === "type") {
711711
result.typeAnnotation = (node.type) ? convertTypeAnnotation(node.type) : null;
712+
} else if (key === "typeArguments") {
713+
result.typeParameters = (node.typeArguments)
714+
? convertTypeArgumentsToTypeParameters(node.typeArguments)
715+
: null;
716+
} else if (key === "typeParameters") {
717+
result.typeParameters = (node.typeParameters)
718+
? convertTSTypeParametersToTypeParametersDeclaration(node.typeParameters)
719+
: null;
712720
} else {
713721
if (Array.isArray(node[key])) {
714722
result[key] = node[key].map(convertChild);

Diff for: tests/fixtures/typescript/basics/abstract-class-with-abstract-method.result.js

+52-17
Original file line numberDiff line numberDiff line change
@@ -159,25 +159,60 @@ module.exports = {
159159
},
160160
"name": "Promise"
161161
},
162-
"typeArguments": [
163-
{
164-
"type": "TSStringKeyword",
165-
"range": [
166-
76,
167-
82
168-
],
169-
"loc": {
170-
"start": {
171-
"line": 2,
172-
"column": 37
162+
"typeParameters": {
163+
"loc": {
164+
"end": {
165+
"column": 44,
166+
"line": 2
167+
},
168+
"start": {
169+
"column": 36,
170+
"line": 2
171+
}
172+
},
173+
"params": [
174+
{
175+
"id": {
176+
"loc": {
177+
"end": {
178+
"column": 43,
179+
"line": 2
180+
},
181+
"start": {
182+
"column": 37,
183+
"line": 2
184+
}
185+
},
186+
"range": [
187+
76,
188+
82
189+
],
190+
"type": "TSStringKeyword"
173191
},
174-
"end": {
175-
"line": 2,
176-
"column": 43
177-
}
192+
"loc": {
193+
"end": {
194+
"column": 43,
195+
"line": 2
196+
},
197+
"start": {
198+
"column": 37,
199+
"line": 2
200+
}
201+
},
202+
"range": [
203+
76,
204+
82
205+
],
206+
"type": "GenericTypeAnnotation",
207+
"typeParameters": null
178208
}
179-
}
180-
]
209+
],
210+
"range": [
211+
75,
212+
83
213+
],
214+
"type": "TypeParameterInstantiation"
215+
}
181216
}
182217
},
183218
"params": []

Diff for: tests/fixtures/typescript/basics/abstract-class-with-optional-method.result.js

+54-19
Original file line numberDiff line numberDiff line change
@@ -97,25 +97,6 @@ module.exports = {
9797
75
9898
],
9999
"type": "TSTypeReference",
100-
"typeArguments": [
101-
{
102-
"loc": {
103-
"end": {
104-
"column": 35,
105-
"line": 2
106-
},
107-
"start": {
108-
"column": 29,
109-
"line": 2
110-
}
111-
},
112-
"range": [
113-
68,
114-
74
115-
],
116-
"type": "TSStringKeyword"
117-
}
118-
],
119100
"typeName": {
120101
"loc": {
121102
"end": {
@@ -133,6 +114,60 @@ module.exports = {
133114
67
134115
],
135116
"type": "Identifier"
117+
},
118+
"typeParameters": {
119+
"loc": {
120+
"end": {
121+
"column": 36,
122+
"line": 2
123+
},
124+
"start": {
125+
"column": 28,
126+
"line": 2
127+
}
128+
},
129+
"params": [
130+
{
131+
"id": {
132+
"loc": {
133+
"end": {
134+
"column": 35,
135+
"line": 2
136+
},
137+
"start": {
138+
"column": 29,
139+
"line": 2
140+
}
141+
},
142+
"range": [
143+
68,
144+
74
145+
],
146+
"type": "TSStringKeyword"
147+
},
148+
"loc": {
149+
"end": {
150+
"column": 35,
151+
"line": 2
152+
},
153+
"start": {
154+
"column": 29,
155+
"line": 2
156+
}
157+
},
158+
"range": [
159+
68,
160+
74
161+
],
162+
"type": "GenericTypeAnnotation",
163+
"typeParameters": null
164+
}
165+
],
166+
"range": [
167+
67,
168+
75
169+
],
170+
"type": "TypeParameterInstantiation"
136171
}
137172
}
138173
},

Diff for: tests/fixtures/typescript/basics/class-with-mixin.result.js

+56-19
Original file line numberDiff line numberDiff line change
@@ -300,26 +300,61 @@ module.exports = {
300300
},
301301
"name": "Constructor"
302302
},
303-
"typeArguments": [
304-
{
305-
"type": "TSTypeLiteral",
306-
"range": [
307-
33,
308-
35
309-
],
310-
"loc": {
311-
"start": {
312-
"line": 1,
313-
"column": 33
314-
},
315-
"end": {
316-
"line": 1,
317-
"column": 35
318-
}
303+
"typeParameters": {
304+
"loc": {
305+
"end": {
306+
"column": 36,
307+
"line": 1
319308
},
320-
"members": []
321-
}
322-
]
309+
"start": {
310+
"column": 32,
311+
"line": 1
312+
}
313+
},
314+
"params": [
315+
{
316+
"id": {
317+
"loc": {
318+
"end": {
319+
"column": 35,
320+
"line": 1
321+
},
322+
"start": {
323+
"column": 33,
324+
"line": 1
325+
}
326+
},
327+
"members": [],
328+
"range": [
329+
33,
330+
35
331+
],
332+
"type": "TSTypeLiteral"
333+
},
334+
"loc": {
335+
"end": {
336+
"column": 35,
337+
"line": 1
338+
},
339+
"start": {
340+
"column": 33,
341+
"line": 1
342+
}
343+
},
344+
"range": [
345+
33,
346+
35
347+
],
348+
"type": "GenericTypeAnnotation",
349+
"typeParameters": null
350+
}
351+
],
352+
"range": [
353+
32,
354+
36
355+
],
356+
"type": "TypeParameterInstantiation"
357+
}
323358
}
324359
}
325360
}
@@ -656,6 +691,7 @@ module.exports = {
656691
"declarations": [
657692
{
658693
"type": "VariableDeclarator",
694+
"typeParameters": null,
659695
"id": {
660696
"type": "Identifier",
661697
"range": [
@@ -778,6 +814,7 @@ module.exports = {
778814
}
779815
}
780816
],
817+
"typeParameters": null,
781818
"typeAnnotation": {
782819
"type": "TypeAnnotation",
783820
"loc": {

Diff for: tests/fixtures/typescript/basics/export-type-function-declaration.result.js

+1
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ module.exports = {
9999
"column": 27
100100
}
101101
},
102+
"typeParameters": null,
102103
"parameters": [
103104
{
104105
"type": "Identifier",

0 commit comments

Comments
 (0)