-
-
Notifications
You must be signed in to change notification settings - Fork 75
Fix: Use ts utilities function to determine variable type (#136) #138
Conversation
Thanks for the pull request, @soda0289! I took a look to make sure it's ready for merging and found some changes are needed:
Can you please update the pull request to address these? (More information can be found in our pull request guide.) |
752b6d6
to
7b8072c
Compare
LGTM |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot for this, @soda0289!
Can we please abstract this into a helper function similar to the following:
/**
* Returns the declaration kind of the given TSNode
* @param {TSNode} node TypeScript AST node
* @returns {string} declaration kind
*/
function getDeclarationKind(node) {
if (node.kind === SyntaxKind.TypeAliasDeclaration) {
return "type";
}
switch (true) {
case ts.isLet(node):
return "let";
case ts.isConst(node):
return "const";
default:
return "var";
}
}
...and then make use of getDeclarationKind
for all three of the relevant cases:
-
SyntaxKind.VariableStatement (
kind: getDeclarationKind(node.declarationList)
) -
SyntaxKind.VariableDeclarationList (
kind: getDeclarationKind(node)
) -
SyntaxKind.TypeAliasDeclaration (
kind: getDeclarationKind(node)
)
Very minor point, but as there are changes to be made anyway, please can we go for async-function-with-var-declaration
as the test name
@soda0289 Please be sure to rebase against master before making those changes, a PR was just merged that also touches one of those cases |
…nt#136) This fixes an issue where async functions will mark all variable declarations as constant. We change the way node flags are read by using ts utilities functions (isLet and isConst)
7b8072c
to
e7a33f0
Compare
LGTM |
@JamesHenry |
This fixes issue an where an async function would mark all variable declarations as constant. It uses the isConst and isLet functions from TypeScript compiler utilities file.
Fixes #136