Skip to content

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.

}

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 subscribe to this conversation on GitHub. Already have an account? Sign in.

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