Skip to content

Commit

Permalink
[Fix] no-extraneous-dependencies: ensure node.source exists
Browse files Browse the repository at this point in the history
  • Loading branch information
ljharb committed Dec 9, 2019
1 parent 9b76635 commit be7efb1
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/rules/no-extraneous-dependencies.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,9 @@ module.exports = {
reportIfMissing(context, deps, depsOptions, node, node.source.value)
},
ExportNamedDeclaration: function (node) {
reportIfMissing(context, deps, depsOptions, node, node.source.value)
if (node.source) {
reportIfMissing(context, deps, depsOptions, node, node.source.value)
}
},
ExportAllDeclaration: function (node) {
reportIfMissing(context, deps, depsOptions, node, node.source.value)
Expand Down

3 comments on commit be7efb1

@mapleeit
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ljharb Hello, I encountered this problem several minutes ago, with version 2.19.0.

Is there will be a new fixed version recently?

@ljharb
Copy link
Member Author

@ljharb ljharb commented on be7efb1 Dec 9, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would help a lot if you could provide a test case :-) but yes, i'll have a patch out soon.

@mapleeit
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm afraid it's not easy to make a reproduce repo. My project is too large. I try to console.log(node) in the beginning of ExportNamedDeclaration function. Hope it could help you.

{ type: 'ExportNamedDeclaration',
  declaration:
   { type: 'FunctionDeclaration',
     id:
      { type: 'Identifier',
        name: 'getToken',
        range: [Array],
        loc: [Object],
        parent: [Circular] },
     generator: false,
     expression: false,
     async: false,
     params: [ [Object], [Object] ],
     body:
      { type: 'BlockStatement',
        body: [Array],
        range: [Array],
        loc: [Object],
        parent: [Circular] },
     range: [ 1235, 1768 ],
     loc: { start: [Object], end: [Object] },
     parent: [Circular] },
  specifiers: [],
  source: null,
  range: [ 1228, 1768 ],
  loc:
   { start: { line: 52, column: 0 }, end: { line: 77, column: 1 } },
  parent:
   { type: 'Program',
     body:
      [ [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Circular],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object] ],
     sourceType: 'module',
     range: [ 0, 2965 ],
     loc: { start: [Object], end: [Object] },
     tokens:
      [ [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        ... 477 more items ],
     comments: [ [Object], [Object], [Object] ],
     parent: null } }
TypeError: Cannot read property 'value' of null
Occurred while linting /Users/maplemiao/Documents/gitoa/orange-ci/src/chat/api.ts:52
    at ExportNamedDeclaration (/Users/maplemiao/Documents/gitoa/orange-ci/node_modules/eslint-plugin-import/lib/rules/no-extraneous-dependencies.js:211:71)
    at listeners.(anonymous function).forEach.listener (/Users/maplemiao/Documents/gitoa/orange-ci/node_modules/eslint/lib/linter/safe-emitter.js:45:58)
    at Array.forEach (<anonymous>)
    at Object.emit (/Users/maplemiao/Documents/gitoa/orange-ci/node_modules/eslint/lib/linter/safe-emitter.js:45:38)
    at NodeEventGenerator.applySelector (/Users/maplemiao/Documents/gitoa/orange-ci/node_modules/eslint/lib/linter/node-event-generator.js:254:26)
    at NodeEventGenerator.applySelectors (/Users/maplemiao/Documents/gitoa/orange-ci/node_modules/eslint/lib/linter/node-event-generator.js:283:22)
    at NodeEventGenerator.enterNode (/Users/maplemiao/Documents/gitoa/orange-ci/node_modules/eslint/lib/linter/node-event-generator.js:297:14)
    at CodePathAnalyzer.enterNode (/Users/maplemiao/Documents/gitoa/orange-ci/node_modules/eslint/lib/linter/code-path-analysis/code-path-analyzer.js:634:23)
    at nodeQueue.forEach.traversalInfo (/Users/maplemiao/Documents/gitoa/orange-ci/node_modules/eslint/lib/linter/linter.js:936:32)
    at Array.forEach (<anonymous>)

And the code piece where threw error:

// typescript
// line 52 here
export function getToken(corpid: string, corpsecret: string) {
  const option: Axios.AxiosRequestConfig = {
    headers: {
      "Content-Type": "application/json"
    },
    method: "get",
    params: {
      corpid,
      corpsecret
    },
    responseType: "json",
    url: "http://in.qyapi.weixin.qq.com/cgi-bin/gettoken"
  };

  return retry(
    async () => (await axios(option)).data as {
      errcode: number;
      errmsg: string;
      access_token?: string;
      expires_in?: number;
    },
    {
      retries: 3
    },
  );
}

Please sign in to comment.