Skip to content

Commit 93ac97b

Browse files
flying-sheepsoda0289
authored andcommitted
Fix: Handle async/await (fixes eslint#119) (eslint#129)
1 parent 5431a1b commit 93ac97b

File tree

147 files changed

+634
-96
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

147 files changed

+634
-96
lines changed

lib/ast-converter.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,17 @@ function isESTreeClassMember(node) {
105105
return node.kind !== SyntaxKind.SemicolonClassElement;
106106
}
107107

108+
/**
109+
* Returns true if the given node is an async function
110+
* @param {TSNode} node TypeScript AST node
111+
* @returns {boolean} is an async function
112+
*/
113+
function isAsyncFunction(node) {
114+
return !!node.modifiers && !!node.modifiers.length && node.modifiers.some(function(modifier) {
115+
return modifier.kind === SyntaxKind.AsyncKeyword;
116+
});
117+
}
118+
108119
/**
109120
* Returns true if the given TSToken is a comma
110121
* @param {TSToken} token the TypeScript token
@@ -852,6 +863,7 @@ module.exports = function(ast, extra) {
852863
id: convertChild(node.name),
853864
generator: !!node.asteriskToken,
854865
expression: false,
866+
async: isAsyncFunction(node),
855867
params: node.parameters.map(convertChild),
856868
body: convertChild(node.body)
857869
});
@@ -1057,6 +1069,7 @@ module.exports = function(ast, extra) {
10571069
id: null,
10581070
generator: false,
10591071
expression: false,
1072+
async: isAsyncFunction(node),
10601073
body: convertChild(node.body),
10611074
range: [ node.parameters.pos - 1, result.range[1]],
10621075
loc: {
@@ -1158,6 +1171,7 @@ module.exports = function(ast, extra) {
11581171
}),
11591172
generator: false,
11601173
expression: false,
1174+
async: false,
11611175
body: convertChild(node.body),
11621176
range: [ result.range[0] + constructorStartOffset, result.range[1]],
11631177
loc: {
@@ -1226,6 +1240,7 @@ module.exports = function(ast, extra) {
12261240
generator: !!node.asteriskToken,
12271241
params: node.parameters.map(convertChild),
12281242
body: convertChild(node.body),
1243+
async: isAsyncFunction(node),
12291244
expression: false
12301245
});
12311246
// Process returnType
@@ -1308,6 +1323,7 @@ module.exports = function(ast, extra) {
13081323
id: null,
13091324
params: node.parameters.map(convertChild),
13101325
body: convertChild(node.body),
1326+
async: isAsyncFunction(node),
13111327
expression: node.body.kind !== SyntaxKind.Block
13121328
});
13131329
// Process returnType
@@ -1328,6 +1344,13 @@ module.exports = function(ast, extra) {
13281344
});
13291345
break;
13301346

1347+
case SyntaxKind.AwaitExpression:
1348+
assign(result, {
1349+
type: "AwaitExpression",
1350+
expression: convertChild(node.expression)
1351+
});
1352+
break;
1353+
13311354
// Template Literals
13321355

13331356
case SyntaxKind.NoSubstitutionTemplateLiteral:

lib/ast-node-types.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ module.exports = {
2323
ArrayExpression: "ArrayExpression",
2424
ArrayPattern: "ArrayPattern",
2525
ArrowFunctionExpression: "ArrowFunctionExpression",
26+
AwaitExpression: "AwaitExpression",
2627
BlockStatement: "BlockStatement",
2728
BinaryExpression: "BinaryExpression",
2829
BreakStatement: "BreakStatement",

tests/fixtures/attach-comments/export-default-anonymous-class.result.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ module.exports = {
5656
},
5757
"generator": false,
5858
"expression": false,
59+
"async": false,
5960
"range": [
6061
110,
6162
119

tests/fixtures/attach-comments/surrounding-call-comments.result.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ module.exports = {
123123
]
124124
},
125125
"expression": false,
126+
"async": false,
126127
"generator": false
127128
}
128129
],

tests/fixtures/attach-comments/surrounding-debugger-comments.result.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ module.exports = {
8787
]
8888
},
8989
"expression": false,
90+
"async": false,
9091
"generator": false
9192
}
9293
],

tests/fixtures/attach-comments/surrounding-return-comments.result.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ module.exports = {
8888
]
8989
},
9090
"expression": false,
91+
"async": false,
9192
"generator": false
9293
}
9394
],

tests/fixtures/attach-comments/surrounding-throw-comments.result.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ module.exports = {
106106
]
107107
},
108108
"expression": false,
109+
"async": false,
109110
"generator": false
110111
}
111112
],

tests/fixtures/attach-comments/surrounding-while-loop-comments.result.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ module.exports = {
5151
},
5252
"generator": false,
5353
"expression": false,
54+
"async": false,
5455
"params": [],
5556
"body": {
5657
"type": "BlockStatement",

tests/fixtures/attach-comments/switch-fallthrough-comment-in-function.result.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,7 @@ module.exports = {
254254
]
255255
},
256256
"expression": false,
257+
"async": false,
257258
"generator": false
258259
}
259260
],

tests/fixtures/attach-comments/switch-no-default-comment-in-function.result.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,7 @@ module.exports = {
238238
]
239239
},
240240
"expression": false,
241+
"async": false,
241242
"generator": false
242243
}
243244
],

0 commit comments

Comments
 (0)