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
fix: use strip-literal
for more correct comments removal
#60
Conversation
fix: nested quotes in template string, multiline template string (unjs#49)
strip-literal
for more correct comments removal
Thanks for the effort on this. Rather than maintaining the complexity in the repo, I have switched to using https://github.com/antfu/strip-literal, a library that Vite is relying on to remove the comments internals. |
Yes, that's better, thanks |
This is so nice with |
When applying unimport on huge codebase, I've encountered many issues when global identifiers were not detected.
Some of them were fixed in #58 , but after that fix I've found several more complicated cases, e.g.:
"//" was detected as single-line comment, discarded rest of the line, and first "`" quote was left unclosed, which lead to discarding of entire code.
This is complex to fix via replacing regexes, because many combinations are possible depending on the order -
`str` // comment
vs`str // not comment`
.To fix it properly we probably need to parse the syntax tree, but if I understood correctly Vite doesn't want to do it for performance reasons. So I've written small "state machine" to correctly detect strings and comments regardless of nesting in in O(n) time.