-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Deprioritize import paths made up of only dots and slashes #47432
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
Conversation
|| compareNumberOfDirectorySeparators(a.moduleSpecifier, b.moduleSpecifier); | ||
} | ||
return Comparison.EqualTo; | ||
} | ||
|
||
function isOnlyDotsAndSlashes(path: string) { | ||
return !/[^.\/]/g.test(path); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
More coding superstition - just avoid the regex 😄
return !/[^.\/]/g.test(path); | |
for (let i = 0; i < path.length; i++) { | |
const ch = path.charCodeAt(i); | |
if (i !== CharacterCodes.dot && i !== CharacterCodes.slash) return false; | |
} | |
return true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Set up a test on https://jsbench.me (can't share without giving them my email) and that's 25% slower.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you do care about perf though, consider hoisting the regex out.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tested that too, and it was only 5% faster 😉 I’ll probably do it anyway.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixes #45953
Paths like
"."
and".."
are still available in the codefix dropdown, but sorted to the end of the list. Completions takes only the first module specifier from the list, so they should be gone from completions entirely.