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

Fix: Use ts utilities function to determine variable type (#136) #138

Merged
merged 1 commit into from
Jan 10, 2017

Conversation

soda0289
Copy link
Member

@soda0289 soda0289 commented Jan 10, 2017

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

@eslintbot
Copy link

Thanks for the pull request, @soda0289! I took a look to make sure it's ready for merging and found some changes are needed:

  • Pull requests with code require an issue to be mentioned at the end of the commit summary, such as (fixes #1234). Please update the commit summary with an issue (file a new issue if one doesn't already exist).

Can you please update the pull request to address these?

(More information can be found in our pull request guide.)

@eslintbot
Copy link

LGTM

Copy link
Member

@JamesHenry JamesHenry left a 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

@JamesHenry
Copy link
Member

@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)
@eslintbot
Copy link

LGTM

@soda0289
Copy link
Member Author

@JamesHenry
I created a separate function for determining declaration kind and renamed the test.

@JamesHenry JamesHenry merged commit d53f1f8 into eslint:master Jan 10, 2017
soda0289 added a commit to soda0289/typescript-eslint-parser that referenced this pull request Feb 1, 2017
@soda0289 soda0289 deleted the fix-async-const branch May 23, 2017 13:27
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Async function makes all variables constant
3 participants