Skip to content

Commit 1514359

Browse files
committed
Merge pull request #48 from eslint/superfunc
New: Allow super references in functions (refs #10)
2 parents 6d7208c + f7bd5d7 commit 1514359

13 files changed

+883
-3
lines changed

espree.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -2760,7 +2760,8 @@ function parseGroupExpression() {
27602760
function parsePrimaryExpression() {
27612761
var type, token, expr,
27622762
marker,
2763-
allowJSX = extra.ecmaFeatures.jsx;
2763+
allowJSX = extra.ecmaFeatures.jsx,
2764+
allowSuper = extra.ecmaFeatures.superInFunctions;
27642765

27652766
if (match("(")) {
27662767
return parseGroupExpression();
@@ -2792,6 +2793,13 @@ function parsePrimaryExpression() {
27922793
if (matchKeyword("function")) {
27932794
return parseFunctionExpression();
27942795
}
2796+
2797+
if (allowSuper && matchKeyword("super") && state.inFunctionBody) {
2798+
marker = markerCreate();
2799+
lex();
2800+
return markerApply(marker, astNodeFactory.createIdentifier("super"));
2801+
}
2802+
27952803
if (matchKeyword("this")) {
27962804
lex();
27972805
expr = astNodeFactory.createThisExpression();

lib/features.js

+3
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@ module.exports = {
8282
// enable parsing of generators/yield
8383
generators: false,
8484

85+
// enable super in functions
86+
superInFunctions: false,
87+
8588
// React JSX parsing
8689
jsx: false,
8790

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

0 commit comments

Comments
 (0)