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

Commit 1a97650

Browse files
soda0289JamesHenry
authored andcommitted
Fix: Handle case where class has extends but no super class (fixes #249) (#254)
1 parent 00ad71d commit 1a97650

9 files changed

+772
-1
lines changed

Diff for: lib/ast-converter.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1581,7 +1581,7 @@ module.exports = function(ast, extra) {
15811581
superClass,
15821582
hasImplements = false;
15831583

1584-
if (hasExtends) {
1584+
if (hasExtends && heritageClauses[0].types.length > 0) {
15851585
superClass = heritageClauses.shift();
15861586
if (superClass.types[0] && superClass.types[0].typeArguments) {
15871587
result.superTypeParameters = convertTypeArgumentsToTypeParameters(superClass.types[0].typeArguments);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,204 @@
1+
module.exports = {
2+
"type": "Program",
3+
"range": [
4+
0,
5+
37
6+
],
7+
"loc": {
8+
"start": {
9+
"line": 1,
10+
"column": 0
11+
},
12+
"end": {
13+
"line": 3,
14+
"column": 1
15+
}
16+
},
17+
"body": [
18+
{
19+
"type": "ClassDeclaration",
20+
"range": [
21+
0,
22+
37
23+
],
24+
"loc": {
25+
"start": {
26+
"line": 1,
27+
"column": 0
28+
},
29+
"end": {
30+
"line": 3,
31+
"column": 1
32+
}
33+
},
34+
"id": {
35+
"type": "Identifier",
36+
"range": [
37+
6,
38+
9
39+
],
40+
"loc": {
41+
"start": {
42+
"line": 1,
43+
"column": 6
44+
},
45+
"end": {
46+
"line": 1,
47+
"column": 9
48+
}
49+
},
50+
"name": "Foo"
51+
},
52+
"body": {
53+
"type": "ClassBody",
54+
"body": [],
55+
"range": [
56+
33,
57+
37
58+
],
59+
"loc": {
60+
"start": {
61+
"line": 1,
62+
"column": 33
63+
},
64+
"end": {
65+
"line": 3,
66+
"column": 1
67+
}
68+
}
69+
},
70+
"superClass": null,
71+
"implements": [],
72+
"decorators": []
73+
}
74+
],
75+
"sourceType": "script",
76+
"tokens": [
77+
{
78+
"type": "Keyword",
79+
"value": "class",
80+
"range": [
81+
0,
82+
5
83+
],
84+
"loc": {
85+
"start": {
86+
"line": 1,
87+
"column": 0
88+
},
89+
"end": {
90+
"line": 1,
91+
"column": 5
92+
}
93+
}
94+
},
95+
{
96+
"type": "Identifier",
97+
"value": "Foo",
98+
"range": [
99+
6,
100+
9
101+
],
102+
"loc": {
103+
"start": {
104+
"line": 1,
105+
"column": 6
106+
},
107+
"end": {
108+
"line": 1,
109+
"column": 9
110+
}
111+
}
112+
},
113+
{
114+
"type": "Keyword",
115+
"value": "extends",
116+
"range": [
117+
10,
118+
17
119+
],
120+
"loc": {
121+
"start": {
122+
"line": 1,
123+
"column": 10
124+
},
125+
"end": {
126+
"line": 1,
127+
"column": 17
128+
}
129+
}
130+
},
131+
{
132+
"type": "Keyword",
133+
"value": "implements",
134+
"range": [
135+
18,
136+
28
137+
],
138+
"loc": {
139+
"start": {
140+
"line": 1,
141+
"column": 18
142+
},
143+
"end": {
144+
"line": 1,
145+
"column": 28
146+
}
147+
}
148+
},
149+
{
150+
"type": "Identifier",
151+
"value": "Bar",
152+
"range": [
153+
29,
154+
32
155+
],
156+
"loc": {
157+
"start": {
158+
"line": 1,
159+
"column": 29
160+
},
161+
"end": {
162+
"line": 1,
163+
"column": 32
164+
}
165+
}
166+
},
167+
{
168+
"type": "Punctuator",
169+
"value": "{",
170+
"range": [
171+
33,
172+
34
173+
],
174+
"loc": {
175+
"start": {
176+
"line": 1,
177+
"column": 33
178+
},
179+
"end": {
180+
"line": 1,
181+
"column": 34
182+
}
183+
}
184+
},
185+
{
186+
"type": "Punctuator",
187+
"value": "}",
188+
"range": [
189+
36,
190+
37
191+
],
192+
"loc": {
193+
"start": {
194+
"line": 3,
195+
"column": 0
196+
},
197+
"end": {
198+
"line": 3,
199+
"column": 1
200+
}
201+
}
202+
}
203+
]
204+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
class Foo extends implements Bar {
2+
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
module.exports = {
2+
"type": "Program",
3+
"range": [
4+
0,
5+
22
6+
],
7+
"loc": {
8+
"start": {
9+
"line": 1,
10+
"column": 0
11+
},
12+
"end": {
13+
"line": 3,
14+
"column": 1
15+
}
16+
},
17+
"body": [
18+
{
19+
"type": "ClassDeclaration",
20+
"range": [
21+
0,
22+
22
23+
],
24+
"loc": {
25+
"start": {
26+
"line": 1,
27+
"column": 0
28+
},
29+
"end": {
30+
"line": 3,
31+
"column": 1
32+
}
33+
},
34+
"id": {
35+
"type": "Identifier",
36+
"range": [
37+
6,
38+
9
39+
],
40+
"loc": {
41+
"start": {
42+
"line": 1,
43+
"column": 6
44+
},
45+
"end": {
46+
"line": 1,
47+
"column": 9
48+
}
49+
},
50+
"name": "Foo"
51+
},
52+
"body": {
53+
"type": "ClassBody",
54+
"body": [],
55+
"range": [
56+
18,
57+
22
58+
],
59+
"loc": {
60+
"start": {
61+
"line": 1,
62+
"column": 18
63+
},
64+
"end": {
65+
"line": 3,
66+
"column": 1
67+
}
68+
}
69+
},
70+
"superClass": null,
71+
"implements": [],
72+
"decorators": []
73+
}
74+
],
75+
"sourceType": "script",
76+
"tokens": [
77+
{
78+
"type": "Keyword",
79+
"value": "class",
80+
"range": [
81+
0,
82+
5
83+
],
84+
"loc": {
85+
"start": {
86+
"line": 1,
87+
"column": 0
88+
},
89+
"end": {
90+
"line": 1,
91+
"column": 5
92+
}
93+
}
94+
},
95+
{
96+
"type": "Identifier",
97+
"value": "Foo",
98+
"range": [
99+
6,
100+
9
101+
],
102+
"loc": {
103+
"start": {
104+
"line": 1,
105+
"column": 6
106+
},
107+
"end": {
108+
"line": 1,
109+
"column": 9
110+
}
111+
}
112+
},
113+
{
114+
"type": "Keyword",
115+
"value": "extends",
116+
"range": [
117+
10,
118+
17
119+
],
120+
"loc": {
121+
"start": {
122+
"line": 1,
123+
"column": 10
124+
},
125+
"end": {
126+
"line": 1,
127+
"column": 17
128+
}
129+
}
130+
},
131+
{
132+
"type": "Punctuator",
133+
"value": "{",
134+
"range": [
135+
18,
136+
19
137+
],
138+
"loc": {
139+
"start": {
140+
"line": 1,
141+
"column": 18
142+
},
143+
"end": {
144+
"line": 1,
145+
"column": 19
146+
}
147+
}
148+
},
149+
{
150+
"type": "Punctuator",
151+
"value": "}",
152+
"range": [
153+
21,
154+
22
155+
],
156+
"loc": {
157+
"start": {
158+
"line": 3,
159+
"column": 0
160+
},
161+
"end": {
162+
"line": 3,
163+
"column": 1
164+
}
165+
}
166+
}
167+
]
168+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
class Foo extends {
2+
3+
}

0 commit comments

Comments
 (0)