Repository navigation
Deprioritize import paths made up of only dots and slashes - #47432
Merged
Andrew Branch (andrewbranch) merged 4 commits intoJan 14, 2022
Merged
Conversation
Ryan Cavanaugh (RyanCavanaugh)
approved these changes
Jan 14, 2022
Gabriela Araujo Britto (gabritto)
approved these changes
Jan 14, 2022
| } | ||
|
|
||
| function isOnlyDotsAndSlashes(path: string) { | ||
| return !/[^.\/]/g.test(path); |
There was a problem hiding this comment.
More coding superstition - just avoid the regex 😄
Suggested change
| 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; |
Member
Author
There was a problem hiding this comment.
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.
Fair.
There was a problem hiding this comment.
If you do care about perf though, consider hoisting the regex out.
Member
Author
There was a problem hiding this comment.
I tested that too, and it was only 5% faster 😉 I’ll probably do it anyway.
Daniel Rosenwasser (DanielRosenwasser)
approved these changes
Jan 14, 2022
This was referenced Jan 19, 2022
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

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.