Skip to content

Commit be85b8e

Browse files
authored
Fix: async shorthand properties (fixes eslint#340) (eslint#341)
* Fix: async shorthand properties (fixes eslint#340) * Fix: and default parameters
1 parent ea08611 commit be85b8e

7 files changed

+882
-4
lines changed

espree.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,8 @@ function resetExtra() {
115115

116116

117117
var tt = acorn.tokTypes,
118-
getLineInfo = acorn.getLineInfo;
118+
getLineInfo = acorn.getLineInfo,
119+
lineBreak = acorn.lineBreak;
119120

120121
// custom type for JSX attribute values
121122
tt.jsxAttrValueToken = {};
@@ -427,9 +428,13 @@ acorn.plugins.espree = function(instance) {
427428
!prop.computed &&
428429
prop.key.type === "Identifier" &&
429430
prop.key.name === "async" &&
430-
this.type !== tt.parenL &&
431-
this.type !== tt.colon &&
432-
!this.canInsertSemicolon()
431+
(
432+
this.type === tt.name ||
433+
this.type === tt.num ||
434+
this.type === tt.string ||
435+
this.type === tt.bracketL
436+
) &&
437+
!lineBreak.test(this.input.slice(this.lastTokEnd, this.start))
433438
) {
434439
this.parsePropertyName(prop, refShorthandDefaultPos);
435440
isAsync = true;
Lines changed: 205 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,205 @@
1+
module.exports = {
2+
"type": "Program",
3+
"loc": {
4+
"start": {
5+
"line": 1,
6+
"column": 0
7+
},
8+
"end": {
9+
"line": 1,
10+
"column": 9
11+
}
12+
},
13+
"range": [
14+
0,
15+
9
16+
],
17+
"body": [
18+
{
19+
"type": "ExpressionStatement",
20+
"loc": {
21+
"start": {
22+
"line": 1,
23+
"column": 0
24+
},
25+
"end": {
26+
"line": 1,
27+
"column": 9
28+
}
29+
},
30+
"range": [
31+
0,
32+
9
33+
],
34+
"expression": {
35+
"type": "ObjectExpression",
36+
"loc": {
37+
"start": {
38+
"line": 1,
39+
"column": 1
40+
},
41+
"end": {
42+
"line": 1,
43+
"column": 8
44+
}
45+
},
46+
"range": [
47+
1,
48+
8
49+
],
50+
"properties": [
51+
{
52+
"type": "Property",
53+
"loc": {
54+
"start": {
55+
"line": 1,
56+
"column": 2
57+
},
58+
"end": {
59+
"line": 1,
60+
"column": 7
61+
}
62+
},
63+
"range": [
64+
2,
65+
7
66+
],
67+
"method": false,
68+
"shorthand": true,
69+
"computed": false,
70+
"key": {
71+
"type": "Identifier",
72+
"loc": {
73+
"start": {
74+
"line": 1,
75+
"column": 2
76+
},
77+
"end": {
78+
"line": 1,
79+
"column": 7
80+
}
81+
},
82+
"range": [
83+
2,
84+
7
85+
],
86+
"name": "async"
87+
},
88+
"kind": "init",
89+
"value": {
90+
"type": "Identifier",
91+
"loc": {
92+
"start": {
93+
"line": 1,
94+
"column": 2
95+
},
96+
"end": {
97+
"line": 1,
98+
"column": 7
99+
}
100+
},
101+
"range": [
102+
2,
103+
7
104+
],
105+
"name": "async"
106+
}
107+
}
108+
]
109+
}
110+
}
111+
],
112+
"sourceType": "script",
113+
"tokens": [
114+
{
115+
"type": "Punctuator",
116+
"value": "(",
117+
"loc": {
118+
"start": {
119+
"line": 1,
120+
"column": 0
121+
},
122+
"end": {
123+
"line": 1,
124+
"column": 1
125+
}
126+
},
127+
"range": [
128+
0,
129+
1
130+
]
131+
},
132+
{
133+
"type": "Punctuator",
134+
"value": "{",
135+
"loc": {
136+
"start": {
137+
"line": 1,
138+
"column": 1
139+
},
140+
"end": {
141+
"line": 1,
142+
"column": 2
143+
}
144+
},
145+
"range": [
146+
1,
147+
2
148+
]
149+
},
150+
{
151+
"type": "Identifier",
152+
"value": "async",
153+
"loc": {
154+
"start": {
155+
"line": 1,
156+
"column": 2
157+
},
158+
"end": {
159+
"line": 1,
160+
"column": 7
161+
}
162+
},
163+
"range": [
164+
2,
165+
7
166+
]
167+
},
168+
{
169+
"type": "Punctuator",
170+
"value": "}",
171+
"loc": {
172+
"start": {
173+
"line": 1,
174+
"column": 7
175+
},
176+
"end": {
177+
"line": 1,
178+
"column": 8
179+
}
180+
},
181+
"range": [
182+
7,
183+
8
184+
]
185+
},
186+
{
187+
"type": "Punctuator",
188+
"value": ")",
189+
"loc": {
190+
"start": {
191+
"line": 1,
192+
"column": 8
193+
},
194+
"end": {
195+
"line": 1,
196+
"column": 9
197+
}
198+
},
199+
"range": [
200+
8,
201+
9
202+
]
203+
}
204+
]
205+
};
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
({async})

0 commit comments

Comments
 (0)