Galooshi / import-js

A tool to simplify importing JS modules
MIT License
525 stars 55 forks source link

Doesn't import { [MY_VAR]: 'wegwegweg' } #476

Closed ivangeorgiew closed 6 years ago

ivangeorgiew commented 6 years ago

When running the fix imports command, variables that are noted as keys in objects like so are not imported:

const bla = {
  [MY_VAR]: 'gegwg'
}

I tried logging all the nodes inside the function normalizeNode and it is shown that: node.name is MY_VAR, context.key is key, context.parent is ObjectProperty.

Then I tried the same logging for:

const bla = {
  [MY_VAR]: 'gegwg',
  myVar: 'fwegweg',
  'myVar': 'fwegwegh' 
}

And saw that there is no difference between them in the logged information, so I can't make an if/else statement inside function normalizeNode.

Can you fix that or tell how to fix it myself? Thanks in advance.

trotzig commented 6 years ago

Wow, good catch! Thanks! These bugs can usually be solved pretty quickly with a test-driven approach (`findUndefinedIdentifiers-test.jsx), but knowing how tricky this bit of code is it's probably easiest for me to address. I'll push something soon.

ivangeorgiew commented 6 years ago

Thanks, its working now. However I found other bugs with fixImports: Here MY_VAR isn't imported.

const bla = {
  keyName: obj[MY_VAR]
}

Desctructured aliases are imported, but they shouldn't be: myAlias shouldn't be imported.

const { prop: myAlias } = obj
trotzig commented 6 years ago

Good catch! I've moved the new issues into a new ticket so that we can follow up better: #480