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

Fix async function and variable declartions #137

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
v1.0.1 - January 4, 2017

* 9882a8e Fix: Add missing async property (#133) (James Henry)
* 60843ad Fix: Handle async/await (fixes #119) (#129) (Philipp A)
* 0ff19dd Fix: Exception thrown when space occurs after function name (fixes #123) (#124) (Reyad Attiyat)
* ff283aa Fix: Allow running without options (fixes #121) (#120) (Philipp A)
* dd03b2f Docs: Changed --save to --save-dev in readme (#132) (Amila Welihinda)
* 41ccef5 Build: Add TS as dev-dep, only support minor range (#131) (James Henry)

v1.0.0 - November 11, 2016

* c60f216 Chore: Normalize .yml line endings (fixes #113) (#115) (James Henry)
Expand Down
31 changes: 28 additions & 3 deletions lib/ast-converter.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,17 @@ function isESTreeClassMember(node) {
return node.kind !== SyntaxKind.SemicolonClassElement;
}

/**
* Returns true if the given node is an async function
* @param {TSNode} node TypeScript AST node
* @returns {boolean} is an async function
*/
function isAsyncFunction(node) {
return !!node.modifiers && !!node.modifiers.length && node.modifiers.some(function(modifier) {
return modifier.kind === SyntaxKind.AsyncKeyword;
});
}

/**
* Returns true if the given TSToken is a comma
* @param {TSToken} token the TypeScript token
Expand Down Expand Up @@ -852,6 +863,7 @@ module.exports = function(ast, extra) {
id: convertChild(node.name),
generator: !!node.asteriskToken,
expression: false,
async: isAsyncFunction(node),
params: node.parameters.map(convertChild),
body: convertChild(node.body)
});
Expand Down Expand Up @@ -887,8 +899,10 @@ module.exports = function(ast, extra) {

var varStatementKind;

if (node.declarationList.flags) {
varStatementKind = (node.declarationList.flags === ts.NodeFlags.Let) ? "let" : "const";
if (ts.isLet(node.declarationList)) {
varStatementKind = "let";
} else if (ts.isConst(node.declarationList)) {
varStatementKind = "const";
} else {
varStatementKind = "var";
}
Expand Down Expand Up @@ -1057,8 +1071,9 @@ module.exports = function(ast, extra) {
id: null,
generator: false,
expression: false,
async: isAsyncFunction(node),
body: convertChild(node.body),
range: [ node.name.end, result.range[1]],
range: [ node.parameters.pos - 1, result.range[1]],
loc: {
start: {
line: methodLoc.line + 1,
Expand Down Expand Up @@ -1158,6 +1173,7 @@ module.exports = function(ast, extra) {
}),
generator: false,
expression: false,
async: false,
body: convertChild(node.body),
range: [ result.range[0] + constructorStartOffset, result.range[1]],
loc: {
Expand Down Expand Up @@ -1226,6 +1242,7 @@ module.exports = function(ast, extra) {
generator: !!node.asteriskToken,
params: node.parameters.map(convertChild),
body: convertChild(node.body),
async: isAsyncFunction(node),
expression: false
});
// Process returnType
Expand Down Expand Up @@ -1308,6 +1325,7 @@ module.exports = function(ast, extra) {
id: null,
params: node.parameters.map(convertChild),
body: convertChild(node.body),
async: isAsyncFunction(node),
expression: node.body.kind !== SyntaxKind.Block
});
// Process returnType
Expand All @@ -1328,6 +1346,13 @@ module.exports = function(ast, extra) {
});
break;

case SyntaxKind.AwaitExpression:
assign(result, {
type: "AwaitExpression",
expression: convertChild(node.expression)
});
break;

// Template Literals

case SyntaxKind.NoSubstitutionTemplateLiteral:
Expand Down
1 change: 1 addition & 0 deletions lib/ast-node-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ module.exports = {
ArrayExpression: "ArrayExpression",
ArrayPattern: "ArrayPattern",
ArrowFunctionExpression: "ArrowFunctionExpression",
AwaitExpression: "AwaitExpression",
BlockStatement: "BlockStatement",
BinaryExpression: "BinaryExpression",
BreakStatement: "BreakStatement",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"author": "Nicholas C. Zakas <[email protected]>",
"homepage": "https://github.com/eslint/typescript-eslint-parser",
"main": "parser.js",
"version": "1.0.0",
"version": "1.0.1",
"files": [
"lib",
"parser.js"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ module.exports = {
},
"generator": false,
"expression": false,
"async": false,
"range": [
110,
119
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ module.exports = {
]
},
"expression": false,
"async": false,
"generator": false
}
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ module.exports = {
]
},
"expression": false,
"async": false,
"generator": false
}
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ module.exports = {
]
},
"expression": false,
"async": false,
"generator": false
}
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ module.exports = {
]
},
"expression": false,
"async": false,
"generator": false
}
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ module.exports = {
},
"generator": false,
"expression": false,
"async": false,
"params": [],
"body": {
"type": "BlockStatement",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ module.exports = {
]
},
"expression": false,
"async": false,
"generator": false
}
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ module.exports = {
]
},
"expression": false,
"async": false,
"generator": false
}
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -630,11 +630,13 @@ module.exports = {
]
},
"expression": false,
"async": false,
"generator": false
}
]
},
"expression": false,
"async": false,
"generator": false
}
}
Expand Down
1 change: 1 addition & 0 deletions tests/fixtures/basics/new-without-parens.result.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ module.exports = {
},
"generator": false,
"expression": false,
"async": false,
"params": [],
"body": {
"type": "BlockStatement",
Expand Down
3 changes: 2 additions & 1 deletion tests/fixtures/basics/update-expression.result.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,9 @@ module.exports = {
],
"type": "BlockStatement"
},
"expression": false,
"generator": false,
"expression": false,
"async": false,
"id": {
"loc": {
"end": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ module.exports = {
},
"generator": true,
"expression": false,
"async": false,
"range": [
17,
24
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ module.exports = {
},
"generator": true,
"expression": false,
"async": false,
"range": [
31,
38
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ module.exports = {
},
"generator": true,
"expression": false,
"async": false,
"range": [
24,
31
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ module.exports = {
},
"generator": false,
"expression": false,
"async": false,
"range": [
6,
13
Expand Down Expand Up @@ -139,6 +140,7 @@ module.exports = {
},
"generator": false,
"expression": false,
"async": false,
"range": [
0,
20
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ module.exports = {
},
"generator": false,
"expression": true,
"async": false,
"range": [
0,
14
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ module.exports = {
},
"generator": false,
"expression": true,
"async": false,
"range": [
0,
20
Expand Down Expand Up @@ -329,4 +330,4 @@ module.exports = {
}
}
]
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ module.exports = {
},
"generator": false,
"expression": true,
"async": false,
"range": [
0,
17
Expand Down Expand Up @@ -275,4 +276,4 @@ module.exports = {
}
}
]
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ module.exports = {
},
"generator": false,
"expression": false,
"async": false,
"range": [
16,
33
Expand Down Expand Up @@ -153,6 +154,7 @@ module.exports = {
},
"generator": true,
"expression": false,
"async": false,
"range": [
0,
35
Expand Down Expand Up @@ -456,4 +458,4 @@ module.exports = {
}
}
]
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ module.exports = {
},
"generator": false,
"expression": true,
"async": false,
"range": [
0,
10
Expand Down Expand Up @@ -257,4 +258,4 @@ module.exports = {
}
}
]
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ module.exports = {
},
"generator": false,
"expression": true,
"async": false,
"range": [
0,
15
Expand Down Expand Up @@ -366,4 +367,4 @@ module.exports = {
}
}
]
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ module.exports = {
},
"generator": false,
"expression": true,
"async": false,
"range": [
0,
27
Expand Down Expand Up @@ -591,4 +592,4 @@ module.exports = {
}
}
]
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ module.exports = {
},
"generator": false,
"expression": true,
"async": false,
"range": [
0,
17
Expand Down Expand Up @@ -519,4 +520,4 @@ module.exports = {
}
}
]
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ module.exports = {
},
"generator": false,
"expression": true,
"async": false,
"range": [
0,
10
Expand Down Expand Up @@ -296,4 +297,4 @@ module.exports = {
}
}
]
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ module.exports = {
},
"generator": false,
"expression": true,
"async": false,
"range": [
0,
15
Expand Down
Loading