Skip to content

Commit f12a54b

Browse files
committed
Merge pull request #90 from eslint/issue87
Fix: Allow super in classes by default (fixes #87)
2 parents e09c76e + 6cae452 commit f12a54b

16 files changed

+401
-171
lines changed

espree.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -2710,6 +2710,7 @@ function parseObjectInitialiser() {
27102710
propertyFn,
27112711
kind,
27122712
storedKind,
2713+
previousInObjectLiteral = state.inObjectLiteral,
27132714
kindMap = new StringMap();
27142715

27152716
state.inObjectLiteral = true;
@@ -2760,7 +2761,7 @@ function parseObjectInitialiser() {
27602761

27612762
expect("}");
27622763

2763-
state.inObjectLiteral = false;
2764+
state.inObjectLiteral = previousInObjectLiteral;
27642765

27652766
return markerApply(marker, astNodeFactory.createObjectExpression(properties));
27662767
}
@@ -2826,8 +2827,8 @@ function parsePrimaryExpression() {
28262827
var type, token, expr,
28272828
marker,
28282829
allowJSX = extra.ecmaFeatures.jsx,
2829-
allowSuper = extra.ecmaFeatures.superInFunctions,
2830-
allowClasses = extra.ecmaFeatures.classes;
2830+
allowClasses = extra.ecmaFeatures.classes,
2831+
allowSuper = allowClasses || extra.ecmaFeatures.superInFunctions;
28312832

28322833
if (match("(")) {
28332834
return parseGroupExpression();
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
module.exports = {
2-
"index": 16,
3-
"lineNumber": 2,
4-
"column": 5,
5-
"description": "Unexpected token *"
6-
};
1+
module.exports = {
2+
"index": 16,
3+
"lineNumber": 2,
4+
"column": 5,
5+
"description": "Unexpected token *"
6+
};
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module.exports = {
2-
"index": 0,
3-
"lineNumber": 1,
4-
"column": 1,
5-
"description": "Unexpected reserved word"
2+
"index": 0,
3+
"lineNumber": 1,
4+
"column": 1,
5+
"description": "Unexpected reserved word"
66
};
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module.exports = {
2-
"index": 20,
3-
"lineNumber": 2,
4-
"column": 9,
5-
"description": "Unexpected token *"
2+
"index": 20,
3+
"lineNumber": 2,
4+
"column": 9,
5+
"description": "Unexpected token *"
66
};
Original file line numberDiff line numberDiff line change
@@ -1,107 +1,107 @@
11
module.exports = {
2-
"type": "Program",
3-
"body": [
4-
{
5-
"type": "ExportDefaultDeclaration",
6-
"declaration": {
7-
"type": "ClassDeclaration",
8-
"id": null,
9-
"superClass": {
10-
"type": "Identifier",
11-
"name": "bar",
12-
"range": [
13-
29,
14-
32
15-
],
16-
"loc": {
17-
"start": {
18-
"line": 1,
19-
"column": 29
20-
},
21-
"end": {
22-
"line": 1,
23-
"column": 32
24-
}
25-
}
26-
},
27-
"body": {
28-
"type": "ClassBody",
29-
"body": [],
30-
"range": [
31-
33,
32-
35
33-
],
34-
"loc": {
35-
"start": {
36-
"line": 1,
37-
"column": 33
38-
},
39-
"end": {
40-
"line": 1,
41-
"column": 35
42-
}
43-
}
44-
},
45-
"range": [
46-
15,
47-
35
48-
],
49-
"loc": {
50-
"start": {
51-
"line": 1,
52-
"column": 15
53-
},
54-
"end": {
55-
"line": 1,
56-
"column": 35
57-
}
58-
}
59-
},
60-
"range": [
61-
0,
62-
35
63-
],
64-
"loc": {
65-
"start": {
66-
"line": 1,
67-
"column": 0
68-
},
69-
"end": {
70-
"line": 1,
71-
"column": 35
72-
}
73-
}
74-
},
75-
{
76-
"type": "EmptyStatement",
77-
"range": [
78-
35,
79-
36
80-
],
81-
"loc": {
82-
"start": {
83-
"line": 1,
84-
"column": 35
85-
},
86-
"end": {
87-
"line": 1,
88-
"column": 36
89-
}
90-
}
91-
}
92-
],
93-
"range": [
94-
0,
95-
36
96-
],
97-
"loc": {
98-
"start": {
99-
"line": 1,
100-
"column": 0
101-
},
102-
"end": {
103-
"line": 1,
104-
"column": 36
105-
}
106-
}
2+
"type": "Program",
3+
"body": [
4+
{
5+
"type": "ExportDefaultDeclaration",
6+
"declaration": {
7+
"type": "ClassDeclaration",
8+
"id": null,
9+
"superClass": {
10+
"type": "Identifier",
11+
"name": "bar",
12+
"range": [
13+
29,
14+
32
15+
],
16+
"loc": {
17+
"start": {
18+
"line": 1,
19+
"column": 29
20+
},
21+
"end": {
22+
"line": 1,
23+
"column": 32
24+
}
25+
}
26+
},
27+
"body": {
28+
"type": "ClassBody",
29+
"body": [],
30+
"range": [
31+
33,
32+
35
33+
],
34+
"loc": {
35+
"start": {
36+
"line": 1,
37+
"column": 33
38+
},
39+
"end": {
40+
"line": 1,
41+
"column": 35
42+
}
43+
}
44+
},
45+
"range": [
46+
15,
47+
35
48+
],
49+
"loc": {
50+
"start": {
51+
"line": 1,
52+
"column": 15
53+
},
54+
"end": {
55+
"line": 1,
56+
"column": 35
57+
}
58+
}
59+
},
60+
"range": [
61+
0,
62+
35
63+
],
64+
"loc": {
65+
"start": {
66+
"line": 1,
67+
"column": 0
68+
},
69+
"end": {
70+
"line": 1,
71+
"column": 35
72+
}
73+
}
74+
},
75+
{
76+
"type": "EmptyStatement",
77+
"range": [
78+
35,
79+
36
80+
],
81+
"loc": {
82+
"start": {
83+
"line": 1,
84+
"column": 35
85+
},
86+
"end": {
87+
"line": 1,
88+
"column": 36
89+
}
90+
}
91+
}
92+
],
93+
"range": [
94+
0,
95+
36
96+
],
97+
"loc": {
98+
"start": {
99+
"line": 1,
100+
"column": 0
101+
},
102+
"end": {
103+
"line": 1,
104+
"column": 36
105+
}
106+
}
107107
};

tests/fixtures/ecma-features-mix/modules-and-classes/class-default-anonymous.result.js

+38-38
Original file line numberDiff line numberDiff line change
@@ -3,43 +3,43 @@ module.exports = {
33
"body": [
44
{
55
"type": "ExportDefaultDeclaration",
6-
"declaration": {
7-
"type": "ClassDeclaration",
8-
"id": null,
9-
"superClass": null,
10-
"body": {
11-
"type": "ClassBody",
12-
"body": [],
13-
"range": [
14-
21,
15-
23
16-
],
17-
"loc": {
18-
"start": {
19-
"line": 1,
20-
"column": 21
21-
},
22-
"end": {
23-
"line": 1,
24-
"column": 23
25-
}
26-
}
27-
},
28-
"range": [
29-
15,
30-
23
31-
],
32-
"loc": {
33-
"start": {
34-
"line": 1,
35-
"column": 15
36-
},
37-
"end": {
38-
"line": 1,
39-
"column": 23
40-
}
41-
}
42-
},
6+
"declaration": {
7+
"type": "ClassDeclaration",
8+
"id": null,
9+
"superClass": null,
10+
"body": {
11+
"type": "ClassBody",
12+
"body": [],
13+
"range": [
14+
21,
15+
23
16+
],
17+
"loc": {
18+
"start": {
19+
"line": 1,
20+
"column": 21
21+
},
22+
"end": {
23+
"line": 1,
24+
"column": 23
25+
}
26+
}
27+
},
28+
"range": [
29+
15,
30+
23
31+
],
32+
"loc": {
33+
"start": {
34+
"line": 1,
35+
"column": 15
36+
},
37+
"end": {
38+
"line": 1,
39+
"column": 23
40+
}
41+
}
42+
},
4343
"range": [
4444
0,
4545
23
@@ -87,4 +87,4 @@ module.exports = {
8787
"column": 24
8888
}
8989
}
90-
}
90+
};

tests/fixtures/ecma-features-mix/modules-and-classes/class-default-extends.result.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -121,4 +121,4 @@ module.exports = {
121121
"column": 40
122122
}
123123
}
124-
}
124+
};

tests/fixtures/ecma-features-mix/modules-and-classes/class-default.result.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -104,4 +104,4 @@ module.exports = {
104104
"column": 28
105105
}
106106
}
107-
}
107+
};

tests/fixtures/ecma-features-mix/modules-and-classes/class-extends.result.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -123,4 +123,4 @@ module.exports = {
123123
"column": 32
124124
}
125125
}
126-
}
126+
};

0 commit comments

Comments
 (0)