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

Parsing multiple call signatures throws exception #92

Closed
@corbinu

Description

@corbinu

For fun I decided to test VSCode using this parser (seemed like a good large project to test) and my first error was this:

If you guys are open to it I would be happy to actually fork VSCode and setup Travis to smoke test the parser against it. That way I can easily open new issues as fixes are released.

What version of TypeScript are you using?
1.8.10

What version of typescript-eslint-parser are you using?
0.3.0

What code were you trying to parse?

export class Test {

    constructor() {
    }

    public test(param1: Number): Test;
    public test(param1: Test): Test;
    public test(param1: any): Test {
        return new Test();
    }

}

What did you expect to happen?
Should parse out the multiple function definitions

What happened?

Cannot read property 'type' of null
TypeError: Cannot read property 'type' of null
    at Referencer.visitFunction (/usr/local/lib/node_modules/eslint/node_modules/escope/lib/referencer.js:258:26)
    at Referencer.FunctionExpression (/usr/local/lib/node_modules/eslint/node_modules/escope/lib/referencer.js:569:18)
    at Referencer.Visitor.visit (/usr/local/lib/node_modules/eslint/node_modules/esrecurse/esrecurse.js:122:34)
    at Referencer.visitProperty (/usr/local/lib/node_modules/eslint/node_modules/escope/lib/referencer.js:297:18)
    at Referencer.MethodDefinition (/usr/local/lib/node_modules/eslint/node_modules/escope/lib/referencer.js:452:18)
    at Referencer.Visitor.visit (/usr/local/lib/node_modules/eslint/node_modules/esrecurse/esrecurse.js:122:34)
    at Referencer.Visitor.visitChildren (/usr/local/lib/node_modules/eslint/node_modules/esrecurse/esrecurse.js:101:38)
    at Referencer.Visitor.visit (/usr/local/lib/node_modules/eslint/node_modules/esrecurse/esrecurse.js:125:14)
    at Referencer.visitClass (/usr/local/lib/node_modules/eslint/node_modules/escope/lib/referencer.js:281:18)
    at Referencer.ClassDeclaration (/usr/local/lib/node_modules/eslint/node_modules/escope/lib/referencer.js:488:18)

Activity

changed the title [-]multiple call signatures [/-] [+]Parsing multiple call signatures throw exception[/+] on Sep 16, 2016
changed the title [-]Parsing multiple call signatures throw exception[/-] [+]Parsing multiple call signatures throws exception[/+] on Sep 16, 2016
corbinu

corbinu commented on Sep 17, 2016

@corbinu
Author
JamesHenry

JamesHenry commented on Sep 17, 2016

@JamesHenry
Member

Awesome, @corbinu! Thanks a lot for doing that.

I've never actually set up anything like that before, is there a way we could get those tests to run ahead of PRs being approved?

platinumazure

platinumazure commented on Sep 17, 2016

@platinumazure
Member

I know we have a "regression build" for ESLint which checks some common ESLint plugins and shared configs for regressions-- @nzakas would know how that's set up. (Not sure if we just used our Jenkins instance or what.)

This article by Ariya Hidayat (creator of esprima and other cool projects) talks about how he used CircleCI for similar purposes.

JamesHenry

JamesHenry commented on Sep 17, 2016

@JamesHenry
Member

Thanks, @platinumazure! Let's see what @nzakas thinks.

@corbinu, regarding the actual issue, this seems to be similar to other issues we have had where core rules rely on a function/method declaration to have a body.

@nzakas We could go a similar route to previous solutions here: Add a check for no body (currently we are just attaching the result of convertChild()) and prefix the converted MethodDefinition with TS if it returns true... What do you think?

JamesHenry

JamesHenry commented on Sep 17, 2016

@JamesHenry
Member

@corbinu Please could link to the actual source of this code?

corbinu

corbinu commented on Sep 17, 2016

@corbinu
Author

@JamesHenry I don't understand that is the source just clone, npm install && npm run clone, and then you can run any of the individual tests which are simply npm scripts

Relevant test for VSCode is here: https://gitlab.com/corbinu/eslint-typescript-smoketest/builds/4153769

It is a bit deceptive from the build as projects some of the tests are just failing on lint rules, but as things shake out here I should be able to get them all green.

JamesHenry

JamesHenry commented on Sep 17, 2016

@JamesHenry
Member

Sorry I should have been clearer - When I said source, I meant the source code that was being linted, and that caused the error. (i.e. the What code were you trying to parse? section above.)

Looking at the build output:

> eslint "src/vscode/**/*.ts"

Cannot read property 'type' of null
TypeError: Cannot read property 'type' of null
    at Referencer.visitFunction (/builds/corbinu/eslint-typescript-smoketest/node_modules/escope/lib/referencer.js:258:26)
    at Referencer.FunctionExpression (/builds/corbinu/eslint-typescript-smoketest/node_modules/escope/lib/referencer.js:569:18)
    at Referencer.Visitor.visit (/builds/corbinu/eslint-typescript-smoketest/node_modules/esrecurse/esrecurse.js:122:34)
    at Referencer.visitProperty (/builds/corbinu/eslint-typescript-smoketest/node_modules/escope/lib/referencer.js:297:18)
    at Referencer.MethodDefinition (/builds/corbinu/eslint-typescript-smoketest/node_modules/escope/lib/referencer.js:452:18)
    at Referencer.Visitor.visit (/builds/corbinu/eslint-typescript-smoketest/node_modules/esrecurse/esrecurse.js:122:34)
    at Referencer.Visitor.visitChildren (/builds/corbinu/eslint-typescript-smoketest/node_modules/esrecurse/esrecurse.js:101:38)
    at Referencer.Visitor.visit (/builds/corbinu/eslint-typescript-smoketest/node_modules/esrecurse/esrecurse.js:125:14)
    at Referencer.visitClass (/builds/corbinu/eslint-typescript-smoketest/node_modules/escope/lib/referencer.js:281:18)
    at Referencer.ClassDeclaration (/builds/corbinu/eslint-typescript-smoketest/node_modules/escope/lib/referencer.js:488:18)

It doesn't help determine what TypeScript code it was trying to parse when the TypeError: Cannot read property 'type' of null was thrown, and I was therefore wondering where you got this from:

export class Test {

    constructor() {
    }

    public test(param1: Number): Test;
    public test(param1: Test): Test;
    public test(param1: any): Test {
        return new Test();
    }

}
corbinu

corbinu commented on Sep 17, 2016

@corbinu
Author

@JamesHenry oh sorry that was trying to lint what it is "src/vscode" after the copy. I then linted the files one at a time and found the issue was present in: https://github.com/Microsoft/vscode/blob/master/src/vs/base/browser/builder.ts

At line 131 the builder class. I then simply reduced that code down till I got a simple example that caused the error. Thats where the test class comes from. However many of the projects I added in the smoke tests throw the same error when they have multiple call signatures.

JamesHenry

JamesHenry commented on Sep 17, 2016

@JamesHenry
Member

That's great, thanks!

corbinu

corbinu commented on Sep 18, 2016

@corbinu
Author

@JamesHenry So I tracked it down to visit function in escope when visiting a function assumes it has a body. I can do a PR over there to that simply checks if the node as a body

https://github.com/estools/escope/blob/master/src/referencer.js#L226

if (node.body) {
     if (node.body.type === Syntax.BlockStatement) {
        this.visitChildren(node.body);
     } else {
         this.visit(node.body);
     }
}

I made that change on my machine and VSCode started parsing fine!

Otherwise is there some better way for me to try to fix this in this repo?

Thanks

45 remaining items

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @nzakas@platinumazure@corbinu@awerlang@monolithed

        Issue actions

          Parsing multiple call signatures throws exception · Issue #92 · eslint/typescript-eslint-parser