Eslint-plugin-import: Support `export =` TypeScript syntax

Created on 11 Jun 2020  路  10Comments  路  Source: benmosher/eslint-plugin-import

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 [email protected] with [email protected] and @typescript-eslint/[email protected]

bug typescript

All 10 comments

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?)

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

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.

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

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

nope! hopefully soon tho.

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.

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

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

@ljharb thank you, see #1841

Was this page helpful?
0 / 5 - 0 ratings

Related issues

yutin1987 picture yutin1987  路  3Comments

pahan35 picture pahan35  路  3Comments

daltonamitchell picture daltonamitchell  路  3Comments

xiaodi0003 picture xiaodi0003  路  3Comments

leonid-bauxy picture leonid-bauxy  路  3Comments