Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[regression] export * from 'typescript/lib/typescript.d throws after 2.19.0 #1801

Closed
JounQin opened this issue Jun 6, 2020 · 10 comments
Closed

Comments

@JounQin
Copy link
Collaborator

JounQin commented Jun 6, 2020

related: import-js/eslint-import-resolver-typescript#47

Minimal reproduction:

// test.ts
export * from 'typescript/lib/typescript.d'
# .eslint.yml
parserOptions:
  ecmaVersion: 2020
  sourceType: module
extends:
  - plugin:import/errors
  - plugin:import/typescript

run: eslint test.ts

error log:

TypeError: Cannot read property 'type' of null
Occurred while linting /workspace/eslint-import-resolver-typescript-repro/src.ts:1
    at /workspace/eslint-import-resolver-typescript-repro/node_modules/eslint-plugin-import/lib/ExportMap.js:569:30
    at Array.forEach (<anonymous>)
    at /workspace/eslint-import-resolver-typescript-repro/node_modules/eslint-plugin-import/lib/ExportMap.js:565:32
    at Array.forEach (<anonymous>)
    at /workspace/eslint-import-resolver-typescript-repro/node_modules/eslint-plugin-import/lib/ExportMap.js:563:19
    at Array.forEach (<anonymous>)
    at Function.ExportMap.parse (/workspace/eslint-import-resolver-typescript-repro/node_modules/eslint-plugin-import/lib/ExportMap.js:477:12)
    at Function.ExportMap.for (/workspace/eslint-import-resolver-typescript-repro/node_modules/eslint-plugin-import/lib/ExportMap.js:361:25)
    at Function.ExportMap.get (/workspace/eslint-import-resolver-typescript-repro/node_modules/eslint-plugin-import/lib/ExportMap.js:316:23)
    at processBodyStatement (/workspace/eslint-import-resolver-typescript-repro/node_modules/eslint-plugin-import/lib/rules/namespace.js:67:47)

After downgrading to ~2.18.2, there will be no error any more.

@JounQin JounQin changed the title [regression] export {} throws after 2.19.0 [regression] export * from 'typescript/lib/typescript.d throws after 2.19.0 Jun 6, 2020
@ljharb
Copy link
Member

ljharb commented Jun 6, 2020

If it's throwing from inside the resolver, that's a bug you'll need to file on the resolver, which is a different project.

cc @alexgorbatchev

@JounQin
Copy link
Collaborator Author

JounQin commented Jun 7, 2020

@ljharb Not at all. There's no resolver used in my reproduction.

The related issue throws because the resolver resolves typescript.d.ts correctly instead of typescript.js.

@ljharb
Copy link
Member

ljharb commented Jun 7, 2020

Hmm, I did misunderstand the stack trace - but the resolver is still the typescript resolver, which is a different package.

What's the exact stack trace on v2.20.2, the latest version?

@ljharb ljharb reopened this Jun 7, 2020
@JounQin
Copy link
Collaborator Author

JounQin commented Jun 7, 2020

@ljharb All versions after v2.19.0.

@ljharb
Copy link
Member

ljharb commented Jun 7, 2020

Right, but i need the file and line number on v2.20.2.

@JounQin
Copy link
Collaborator Author

JounQin commented Jun 7, 2020

What's the exact stack trace on v2.20.2, the latest version?

Yes, I tested it with the latest version.

@ljharb
Copy link
Member

ljharb commented Jun 7, 2020

Test seems to pass on latest master.

@ljharb ljharb closed this as completed in 0d6d12e Jun 7, 2020
@ljharb ljharb removed the invalid label Jun 7, 2020
@JounQin
Copy link
Collaborator Author

JounQin commented Jun 7, 2020

@ljharb I try to build latest eslint-plugin-import from master branch manually, but the error is still there.

$ /Users/JounQin/Workspaces/Local/eslint-import-issue/node_modules/.bin/eslint test.ts

Oops! Something went wrong! :(

ESLint: 7.2.0

TypeError: Cannot read property 'type' of null
Occurred while linting /Users/JounQin/Workspaces/Local/eslint-import-issue/test.ts:1
    at /Users/JounQin/Workspaces/Local/eslint-plugin-import/lib/ExportMap.js:616:33
    at Array.forEach (<anonymous>)
    at /Users/JounQin/Workspaces/Local/eslint-plugin-import/lib/ExportMap.js:611:28
    at Array.forEach (<anonymous>)
    at /Users/JounQin/Workspaces/Local/eslint-plugin-import/lib/ExportMap.js:606:21
    at Array.forEach (<anonymous>)
    at Function.ExportMap.parse (/Users/JounQin/Workspaces/Local/eslint-plugin-import/lib/ExportMap.js:501:12)
    at Function.ExportMap.for (/Users/JounQin/Workspaces/Local/eslint-plugin-import/lib/ExportMap.js:369:25)
    at Function.ExportMap.get (/Users/JounQin/Workspaces/Local/eslint-plugin-import/lib/ExportMap.js:324:23)
    at ExportAllDeclaration (/Users/JounQin/Workspaces/Local/eslint-plugin-import/lib/rules/export.js:125:51)

It comes from rules/export.js this time.

@JounQin
Copy link
Collaborator Author

JounQin commented Jun 7, 2020

@ljharb The minimal reproduction would be like following:

// file1.ts
declare namespace ts {
  const x: string;
  export { x };
}

export = ts;
// file2.ts
export * from './file1.ts'

run eslint file2.ts

I print moduleBlockNode at https://github.com/benmosher/eslint-plugin-import/blob/master/src/ExportMap.js#L593, it is:

{
  "type": "ExportNamedDeclaration",
  "source": null,
  "specifiers": [
    {
      "type": "ExportSpecifier",
      "local": {
        "type": "Identifier",
        "name": "x",
        "range": [
          53,
          54
        ],
        "loc": {
          "start": {
            "line": 3,
            "column": 11
          },
          "end": {
            "line": 3,
            "column": 12
          }
        }
      },
      "exported": {
        "type": "Identifier",
        "name": "x",
        "range": [
          53,
          54
        ],
        "loc": {
          "start": {
            "line": 3,
            "column": 11
          },
          "end": {
            "line": 3,
            "column": 12
          }
        }
      },
      "range": [
        53,
        54
      ],
      "loc": {
        "start": {
          "line": 3,
          "column": 11
        },
        "end": {
          "line": 3,
          "column": 12
        }
      }
    }
  ],
  "exportKind": "value",
  "declaration": null,
  "range": [
    44,
    57
  ],
  "loc": {
    "start": {
      "line": 3,
      "column": 2
    },
    "end": {
      "line": 3,
      "column": 15
    }
  }
}

@ljharb ljharb reopened this Jun 7, 2020
ljharb added a commit to ljharb/eslint-plugin-import that referenced this issue Jun 7, 2020
@ljharb
Copy link
Member

ljharb commented Jun 7, 2020

Thank you, got a properly failing test case with a proper fix :-)

@ljharb ljharb closed this as completed in 4ff9b92 Jun 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

2 participants