Skip to content

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

Merged
merged 4 commits into from
Jan 14, 2022

Conversation

andrewbranch
Copy link
Member

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.

|| compareNumberOfDirectorySeparators(a.moduleSpecifier, b.moduleSpecifier);
}
return Comparison.EqualTo;
}

function isOnlyDotsAndSlashes(path: string) {
return !/[^.\/]/g.test(path);
Copy link
Member

@DanielRosenwasser DanielRosenwasser Jan 14, 2022

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 😄

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;

Copy link
Member Author

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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair.

Copy link
Member

@DanielRosenwasser DanielRosenwasser Jan 14, 2022

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.

Copy link
Member Author

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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SanicTheHedgehobGIF

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Author: Team For Milestone Bug PRs that fix a bug with a specific milestone
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Auto-import prefers parent index.ts which leads to circular reference
5 participants