At types prefix and import suffix#15545
Conversation
| } | ||
|
|
||
| if (startsWith(relativeFileName, "@types/")) { | ||
| relativeFileName = relativeFileName.substr(/*"@types".length*/ 7); |
There was a problem hiding this comment.
"@types".length is 6. Why not just use that expression? You could even add a stripStart(str, prefix): string | undefined helper so you don't have to repeat this kind of code.
| relativeFileName = getRelativePath(moduleFileName, sourceDirectory); | ||
| } | ||
|
|
||
| if (startsWith(relativeFileName, "@types/")) { |
There was a problem hiding this comment.
It would be nice to have this code next to mangleScopedPackage in moduleNameResolver.ts. Maybe call it getPackageNameFromAtTypesDirectory.
| /* @internal */ | ||
| export function startsWith(str: string, prefix: string): boolean { | ||
| return str.lastIndexOf(prefix, 0) === 0; | ||
| return str.indexOf(prefix) === 0; |
There was a problem hiding this comment.
This will change the performance -- previously it would only look at the start, now it will look everywhere and then check whether the result was the start.
| } | ||
|
|
||
| /* @internal */ | ||
| export function removePrefix(str: string, prefix: string | undefined): string { |
There was a problem hiding this comment.
Why allow an undefined prefix? This calls startsWith which demands a defined prefix.
We can't get --strictNullChecks on soon enough.
There was a problem hiding this comment.
startsWith works with an undefined prefix. I'll change the annotation there as well.
There was a problem hiding this comment.
Nevermind, it's unnecessary.
| export function endsWith(str: string, suffix: string): boolean { | ||
| const expectedPos = str.length - suffix.length; | ||
| return expectedPos >= 0 && str.indexOf(suffix, expectedPos) === expectedPos; | ||
| return expectedPos >= 0 && str.lastIndexOf(suffix, expectedPos) === expectedPos; |
| catch (e) { } | ||
| } | ||
|
|
||
| relativeFileName = getPackageNameFromAtTypesDirectory(relativeFileName); |
There was a problem hiding this comment.
Don't need an assignment statement if you're just returning that expression.
| } | ||
|
|
||
| export function fileExtensionIsAny(path: string, extensions: string[]): boolean { | ||
| export function fileExtensionIsOneOf(path: string, extensions: string[]): boolean { |
| return moduleName; | ||
| } | ||
|
|
||
| export function getPackageNameFromAtTypesDirectory(mangledName: string): string { |
|
|
||
| // @Filename: node_modules/@types/myLib/index.d.ts | ||
| //// export function f1() {} | ||
| //// export var v1 = 5; |
There was a problem hiding this comment.
It exercises whether we look through the set of exported members correctly.
|
@aozgaa is this PR ready to go? |
Fixes #14157