unplugin-auto-import icon indicating copy to clipboard operation
unplugin-auto-import copied to clipboard

Destructured exports are not registered

Open aaronklinker-st opened this issue 3 years ago • 0 comments

Describe the bug

First off, love your projects, I've been using them more and more of late! This one though, 👌 prefect. Love Nuxt 3's auto-imports and this gives me that on non-nuxt projects.

But to get to the bug, when a module has named exports exported directly from a destructured object/array like so:

export const [a, b] = ["a", "b"];
export const { c, d } = { c: "c", d: "d" };

None of the exports get registered for auto-import.

There is a work around, exporting the variables separate from their definitions.

const [a, b] = ["a", "b"];
const { c, d } = { c: "c", d: "d" };

export { a, b, c, d };

However, I expected this tool to work with all the different ways of exporting variables, and I spent more time than I'd like to admit trying to figure out what was wrong lol.

I spent a little time looking at the code, and it looks like this might actually be a problem with unimport's scanDirExports method? Not sure though.

https://github.com/antfu/unplugin-auto-import/blob/e3900bc12cd406cad922af202677b34ed588f499/src/core/ctx.ts#L115-L117

Reproduction

https://github.com/aaronklinker-st/unplugin-auto-import-bug

System Info

System:
    OS: macOS 12.6
    CPU: (12) x64 Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
    Memory: 8.39 GB / 32.00 GB
    Shell: 5.8.1 - /bin/zsh
  Binaries:
    Node: 18.12.1 - ~/.asdf/installs/nodejs/lts/bin/node
    npm: 8.19.2 - ~/.asdf/plugins/nodejs/shims/npm
  Browsers:
    Chrome: 108.0.5359.124
    Firefox: 103.0.1
    Firefox Developer Edition: 109.0
    Safari: 16.0

Used Package Manager

pnpm

Validations

  • [X] Follow our Code of Conduct
  • [X] Read the Contributing Guide.
  • [X] Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
  • [X] Check that this is a concrete bug. For Q&A, please open a GitHub Discussion instead.
  • [X] The provided reproduction is a minimal reproducible of the bug.

aaronklinker-st avatar Jan 05 '23 05:01 aaronklinker-st