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
Description
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
[-]multiple call signatures [/-][+]Parsing multiple call signatures throw exception[/+][-]Parsing multiple call signatures throw exception[/-][+]Parsing multiple call signatures throws exception[/+]corbinu commentedon Sep 17, 2016
Setup a smoke test repo https://github.com/corbinu/eslint-typescript-smoketest
JamesHenry commentedon Sep 17, 2016
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 commentedon Sep 17, 2016
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 commentedon Sep 17, 2016
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 convertedMethodDefinition
withTS
if it returns true... What do you think?JamesHenry commentedon Sep 17, 2016
@corbinu Please could link to the actual source of this code?
corbinu commentedon Sep 17, 2016
@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 scriptsRelevant 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 commentedon Sep 17, 2016
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:
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:corbinu commentedon Sep 17, 2016
@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 commentedon Sep 17, 2016
That's great, thanks!
corbinu commentedon Sep 18, 2016
@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
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