Skip to content

Conversation

js07
Copy link
Contributor

@js07 js07 commented Nov 12, 2021

Changelog

  • Fix eslint failing with TypeError when default export is not an object (with properties)
  • Refactor reused logic for getting component from CJS and ESM files into separate function

Context

When linting .mjs files with a default export that is not an object, ESLint throws TypeError: Cannot read property 'map' of undefined.
This error happens because propertyArray.map() is called in cases where propertyArray could be undefined instead of an array. Specifically, in component checks where isDefaultExport(node), but node.declaration is something other than an ObjectExpression (e.g. an ArrayExpression), node.declaration.properties (i.e. component.properties) is undefined.

For example:
ESLint would fail when linting this file (region-data.mjs):

export default [
  "GLOBAL",
  "US",
  "AR",
  "AU",
]
  • ESLint: 7.26.0
  • eslint-plugin-pipedream: 0.2.2

To reproduce:

  1. Clone https://github.com/PipedreamHQ/pipedream
  2. Checkout commit 5e5832e81ba8fd2a1f55745221ff480ea41257e3 of branch feature/reddit-new-actions
  3. Install dependencies
npm ci
  1. Run ESLint
npx eslint components/reddit

@js07 js07 added the bug Something isn't working label Nov 12, 2021
@dylburger
Copy link
Contributor

Thank you @js07 , looks great. Could you rev the package version and I'll publish?

@js07
Copy link
Contributor Author

js07 commented Nov 13, 2021

Bumped the package version, @dylburger :)

@dylburger dylburger merged commit 8137396 into PipedreamHQ:master Nov 13, 2021
@dylburger
Copy link
Contributor

Thanks, publishing to npm now

@js07 js07 deleted the fix-typeerror-properties-undefined branch November 13, 2021 02:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants