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

Support export = TypeScript syntax #1818

Closed
AndrewLeedham opened this issue Jun 11, 2020 · 10 comments
Closed

Support export = TypeScript syntax #1818

AndrewLeedham opened this issue Jun 11, 2020 · 10 comments

Comments

@AndrewLeedham
Copy link
Contributor

When using the TypeScript syntax export = function name() {} I get the following error:

TypeError: Cannot read property 'name' of undefined
Occurred while linting *redacted*/rollup-plugin-strip-exports/source/__tests__/options.test.ts:1
    at *redacted*/rollup-plugin-strip-exports/node_modules/eslint-plugin-import/lib/ExportMap.js:599:70
    at Array.forEach (<anonymous>)
    at Function.ExportMap.parse (*redacted*/rollup-plugin-strip-exports/node_modules/eslint-plugin-import/lib/ExportMap.js:508:12)
    at Function.ExportMap.for (*redacted*/rollup-plugin-strip-exports/node_modules/eslint-plugin-import/lib/ExportMap.js:369:25)
    at Function.ExportMap.get (*redacted*/rollup-plugin-strip-exports/node_modules/eslint-plugin-import/lib/ExportMap.js:324:23)
    at processBodyStatement (*redacted*/rollup-plugin-strip-exports/node_modules/eslint-plugin-import/lib/rules/namespace.js:67:47)
    at Array.forEach (<anonymous>)
    at Program (*redacted*/rollup-plugin-strip-exports/node_modules/eslint-plugin-import/lib/rules/namespace.js:96:14)
    at *redacted*/rollup-plugin-strip-exports/node_modules/eslint/lib/linter/safe-emitter.js:45:58
    at Array.forEach (<anonymous>)

Swapping the code from export = function name() {} to export default function name() {} resolves the issue, so it seems the plugin is not accounting for the export = syntax.

Using eslint-plugin-import@2.21.2 with eslint@7.2.0 and @typescript-eslint/parser@3.2.0

@ljharb
Copy link
Member

ljharb commented Jun 11, 2020

hm, this test case is passing for me on master. is there more context you could provide? also are you sure that rollup-plugin-strip-exports's nested eslint-plugin-import is the newest version? (perhaps you need to update your lockfile?)

ljharb added a commit that referenced this issue Jun 11, 2020
@AndrewLeedham
Copy link
Contributor Author

I used a yarn resolution to update to the latest version and the lock-file is updated yes. The PR is here: xeroxinteractive/rollup-plugin-strip-exports#268 if you want to take a look. I will try and create a minimal repro tomorrow :)

@ljharb
Copy link
Member

ljharb commented Jun 11, 2020

I see the line that's erroring: https://github.com/benmosher/eslint-plugin-import/blob/master/src/ExportMap.js#L565 but i have no idea how to trigger it :-/

If you can put up a PR with a failing test, I can fix it in the next release.

@AndrewLeedham
Copy link
Contributor Author

@ljharb it seems to be occurring when importing the export =. The above PR adds a failing test for this.

@ljharb ljharb closed this as completed in b22a183 Jun 14, 2020
@AndrewLeedham
Copy link
Contributor Author

@ljharb any ideas when this might get published to npm?

@ljharb
Copy link
Member

ljharb commented Jun 26, 2020

nope! hopefully soon tho.

@dpinol
Copy link

dpinol commented Jun 30, 2020

I still get "TypeError: Cannot read property 'name' of undefined" when importing an index.d.ts with export = AnalyticsNode.Analytics;:
I have "eslint-plugin-import": "^2.22.0" I still get:


TypeError: Cannot read property 'name' of undefined
Occurred while linting /home/dani/hubtype/botonic/packages/botonic-cli/src/utils.ts:5
    at /home/dani/hubtype/botonic/node_modules/eslint-plugin-import/lib/ExportMap.js:712:221
    at Array.forEach (<anonymous>)
    at Function.ExportMap.parse (/home/dani/hubtype/botonic/node_modules/eslint-plugin-import/lib/ExportMap.js:706:248)
    at Function.ExportMap.for (/home/dani/hubtype/botonic/node_modules/eslint-plugin-import/lib/ExportMap.js:699:201)
    at Function.ExportMap.get (/home/dani/hubtype/botonic/node_modules/eslint-plugin-import/lib/ExportMap.js:693:370)
    at checkDefault (/home/dani/hubtype/botonic/node_modules/eslint-plugin-import/lib/rules/default.js:22:41)

It happens when importing a namespace from this file:

"analytics-node": "^3.4.0-beta.1",
"@types/analytics-node": "^3.1.3",

I added
console.log("exp", n.expression, n.expression.name, n.expression.id);
before
const exportedName = n.type === 'TSNamespaceExportDeclaration'
in ExportMap, and I got:

exp {
  type: 'MemberExpression',
  object: {
    type: 'Identifier',
    name: 'AnalyticsNode',
    range: [ 379, 392 ],
    loc: { start: [Object], end: [Object] }
  },
  property: {
    type: 'Identifier',
    name: 'Analytics',
    range: [ 393, 402 ],
    loc: { start: [Object], end: [Object] }
  },
  computed: false,
  optional: false,
  range: [ 379, 402 ],
  loc: { start: { line: 8, column: 9 }, end: { line: 8, column: 32 } }
} undefined undefined

It crashes because the expression has no name nor id fields.

I tried hard to generate a small test case, but I could not reproduce the issue then.

@AndrewLeedham
Copy link
Contributor Author

@dpinol 2.20.0 fixed my issue, so perhaps this would be better as a separate issue :)

@ljharb
Copy link
Member

ljharb commented Jun 30, 2020

@dpinol yes, please do file a separate issue and i'll try to get to it ASAP.

@dpinol
Copy link

dpinol commented Jul 1, 2020

@ljharb thank you, see #1841

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

No branches or pull requests

3 participants