guybedford / es-module-lexer

Low-overhead lexer dedicated to ES module parsing for fast analysis
MIT License
932 stars 48 forks source link

Support renamed destructured exports #175

Open timfish opened 5 months ago

timfish commented 5 months ago
const { init, parse } = require('es-module-lexer')

init.then(() => {
  const [imports, ex] = parse(`
const o = { name5: 1, name6: 1 }
export const { name5, name6: bar } = o`
  )
  console.log(imports, ex)
})

Outputs

[] [
  { s: 49, e: 54, ls: 49, le: 54, n: 'name5', ln: 'name5' },
  { s: 56, e: 61, ls: 56, le: 61, n: 'name6', ln: 'name6' }
]

But there should be a bar export instead of name6.

guybedford commented 5 months ago

Note the above should read:

[] [
  { s: 49, e: 54, ls: 49, le: 54, n: 'name5', ln: 'name5' },
  { s: 56, e: 61, ls: 56, le: 61, n: 'bar', ln: 'bar' }
]