Jshint: Incomplete instanceof crashes

Created on 2 Oct 2016  ·  8Comments  ·  Source: jshint/jshint

Writing an incomplete instanceof throws Cannot read property 'id' of undefined.

The following input code should reproduce the problem:

var something = [];
if(something instanceof) {
    // Notice the instanceof is missing the class name
}

I'm currently using JSHint 2.9.3

Has PR P2

Most helpful comment

Confirmed; thanks for the report! I've submitted a patch to fix this bug: https://github.com/jshint/jshint/pull/3046.

All 8 comments

I'm having this problem through the atom package linter-jshint with jshint v2.9.3.

Error: C:\Users\emile.bergeron.CAMINO\.atom\packages\linter-jshint\node_modules\jshint\src\jshint.js:5386
        throw err;
        ^

TypeError: Cannot read property 'id' of undefined
    at C:\Users\emile.bergeron.CAMINO\.atom\packages\linter-jshint\node_modules\jshint\src\jshint.js:2131:14
    at Object.x.led (C:\Users\emile.bergeron.CAMINO\.atom\packages\linter-jshint\node_modules\jshint\src\jshint.js:1155:16)
    at expression (C:\Users\emile.bergeron.CAMINO\.atom\packages\linter-jshint\node_modules\jshint\src\jshint.js:926:36)
    at C:\Users\emile.bergeron.CAMINO\.atom\packages\linter-jshint\node_modules\jshint\src\jshint.js:2051:18
    at Object.x.led (C:\Users\emile.bergeron.CAMINO\.atom\packages\linter-jshint\node_modules\jshint\src\jshint.js:1155:16)
    at expression (C:\Users\emile.bergeron.CAMINO\.atom\packages\linter-jshint\node_modules\jshint\src\jshint.js:926:36)
    at Object.fud (C:\Users\emile.bergeron.CAMINO\.atom\packages\linter-jshint\node_modules\jshint\src\jshint.js:4423:22)
    at expression (C:\Users\emile.bergeron.CAMINO\.atom\packages\linter-jshint\node_modules\jshint\src\jshint.js:885:32)
    at statement (C:\Users\emile.bergeron.CAMINO\.atom\packages\linter-jshint\node_modules\jshint\src\jshint.js:1636:9)
    at statements (C:\Users\emile.bergeron.CAMINO\.atom\packages\linter-jshint\node_modules\jshint\src\jshint.js:1681:16)
    at ChildProcess.<anonymous> (C:\Users\emile.bergeron.CAMINO\.atom\packages\linter-jshint\node_modules\atom-linter\node_modules\sb-exec\lib\index.js:56:20)
    at emitTwo (events.js:100:13)
    at ChildProcess.emit (events.js:185:7)
    at maybeClose (internal/child_process.js:850:16)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:215:5)

Same error when opening comment like this:

module.exports = {
    attributes: {},
    /*sth: {},
    sth2: function(){}
};

Is this caused by a tool that runs automatically on code presently being edited?

In atom i use linter-jshint. But also when i save file with that content and run jshint from CLI got same error.

jshint test.js

on file

module.exports = {
    attributes: {},
    /*sth: {}
};

generates error:

/usr/local/lib/node_modules/jshint/src/jshint.js:5386
        throw err;
        ^

TypeError: Cannot read property 'id' of null
    at Object.x.nud (/usr/local/lib/node_modules/jshint/src/jshint.js:3240:26)
    at expression (/usr/local/lib/node_modules/jshint/src/jshint.js:888:34)
    at /usr/local/lib/node_modules/jshint/src/jshint.js:1389:20
    at Object.x.led (/usr/local/lib/node_modules/jshint/src/jshint.js:1155:16)
    at expression (/usr/local/lib/node_modules/jshint/src/jshint.js:926:36)
    at statement (/usr/local/lib/node_modules/jshint/src/jshint.js:1636:9)
    at statements (/usr/local/lib/node_modules/jshint/src/jshint.js:1681:16)
    at itself (/usr/local/lib/node_modules/jshint/src/jshint.js:5365:9)
    at lint (/usr/local/lib/node_modules/jshint/src/cli.js:495:8)

    at /usr/local/lib/node_modules/jshint/src/cli.js:656:7

I think that there should be parsing error like 'unclosed comment'.

Seems related to #2932.

And for atom linter-jshint, they are still on jshint v2.9.2. Opening issue AtomLinter/linter-jshint#353 there to update jshint.

It's actually using a range, but as updating that requires re-installation of the package for most users I'm just going to pin it.

I can confirm it throws the same error on the JSHint demo.

Confirmed; thanks for the report! I've submitted a patch to fix this bug: https://github.com/jshint/jshint/pull/3046.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

helmus picture helmus  ·  48Comments

Arcanemagus picture Arcanemagus  ·  29Comments

kharandziuk picture kharandziuk  ·  19Comments

jncraton picture jncraton  ·  37Comments

rhernandog picture rhernandog  ·  19Comments