-
Notifications
You must be signed in to change notification settings - Fork 50
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Auto-import fails when a identifier is the same as a name to be imported #270
Comments
solid-js
preset, children
are not automatically imported in certain scenarios
We've also encountered this… I wonder if the only way to make Related: #250 (comment) @antfu what do you think? We keep seeing auto-import issues every now and then in our large code-base, and I can't always figure out why, or find the time to create a bug report. Most of the time, I do changes where I then rename a variable (as here), or change the way the auto-imported function is used. It's not exactly inspiring confidence… |
Yeah, this is indeed sometimes impossible to fix with regex. I think that makes sense to introduce an optional mode to do full parsing. |
Created #304 to track on that. |
#304 is implemented, try with |
Environment
unimport version: v3.3.0
node.js version: v18.16.0
Reproduction
Describe the bug
unimport/src/context.ts
Lines 247 to 256 in 28cf011
Before
Remove those already defined
, the value ofoccurrenceMap
is{ size:1, [{ "fn" => 30 }] }
, wherefn
refers to the function which is called outside of the block scope.While run into the for loop,
strippedCode
will match regexp/\b(?:const|let|var)\s+?(\[.*?\]|\{.*?\}|.+?)\s*?[=;\n]/gs
, and matching result is[ "const fn =", "fn" ]
, wherefn
refers to the function defined inside the block scope. SooccurrenceMap.delete(identifier)
will be executed,occurrenceMap
will be cleared, and finally noimport
statement will be prepended to the code.Seems in this situation, regexp matching is not enough, and lexical analysis may be needed?
Additional context
No response
Logs
No response
The text was updated successfully, but these errors were encountered: