lukastaegert/eslint-plugin-tree-shaking

Throws exception when processing specific code (object spread with babel-eslint)

swernerx opened this issue · 2 comments

When using the preset in some of my projects I see such an error:

Cannot read property 'type' of undefined
TypeError: Cannot read property 'type' of undefined
    at verifyNodeTypeIsKnown (/Users/swerner/Workspace/open-source/babel-preset-edge/node_modules/eslint-plugin-tree-shaking/lib/rules/no-side-effects-in-initialization.js:1013:21)
    at reportSideEffects (/Users/swerner/Workspace/open-source/babel-preset-edge/node_modules/eslint-plugin-tree-shaking/lib/rules/no-side-effects-in-initialization.js:1021:10)
    at node.properties.forEach.subNode (/Users/swerner/Workspace/open-source/babel-preset-edge/node_modules/eslint-plugin-tree-shaking/lib/rules/no-side-effects-in-initialization.js:814:11)
    at Array.forEach (<anonymous>)
    at Object.reportEffects (/Users/swerner/Workspace/open-source/babel-preset-edge/node_modules/eslint-plugin-tree-shaking/lib/rules/no-side-effects-in-initialization.js:813:25)
    at reportSideEffects (/Users/swerner/Workspace/open-source/babel-preset-edge/node_modules/eslint-plugin-tree-shaking/lib/rules/no-side-effects-in-initialization.js:1025:24)
    at Object.reportEffects (/Users/swerner/Workspace/open-source/babel-preset-edge/node_modules/eslint-plugin-tree-shaking/lib/rules/no-side-effects-in-initialization.js:991:22)
    at reportSideEffects (/Users/swerner/Workspace/open-source/babel-preset-edge/node_modules/eslint-plugin-tree-shaking/lib/rules/no-side-effects-in-initialization.js:1025:24)
    at node.declarations.node.declarations.forEach.declarator (/Users/swerner/Workspace/open-source/babel-preset-edge/node_modules/eslint-plugin-tree-shaking/lib/rules/no-side-effects-in-initialization.js:976:13)
    at Array.forEach (<anonymous>)

I identified the file which fails. It's actually pretty simple:

let original = { bar: 10 }
let variant = { foo: 1, ...original }

I am using babel-eslint as my parser inside my eslint config.

Hi @swernerx, thanks for pointing this out, just deployed a quick fix as 1.7.1!