-
Notifications
You must be signed in to change notification settings - Fork 13.2k
Open
Labels
Domain: APIRelates to the public API for TypeScriptRelates to the public API for TypeScript
Description
Search Terms
canonical filename
Suggestion
I'd like to re-use the get-canonical-filename logic:
TypeScript/src/compiler/core.ts
Lines 1906 to 1909 in d68295e
| export type GetCanonicalFileName = (fileName: string) => string; | |
| export function createGetCanonicalFileName(useCaseSensitiveFileNames: boolean): GetCanonicalFileName { | |
| return useCaseSensitiveFileNames ? identity : toFileNameLowerCase; | |
| } |
Use Cases
I want to use ts.resolveModuleName and the accompanying ts.createModuleResolutionCache to resolve ImportDeclarations (as per this comment's suggestion).
createModuleResolutionCache requires a parameter getCanonicalFileName. I think it makes the most sense to use the same logic as the compiler itself here, which is the function I linked above.
I could just copy-and-paste this function, but that feels wrong and might lead to discrepancies in the future if toFileNameLowerCase (which is not exposed either) is ever updated.
Examples
const cache = ts.createModuleResolutionCache(currentDirectory, ts.createGetCanonicalFileName(true/false));
const resolved = ts.resolveModuleName(name, file, compilerOptions, host, cache);Checklist
My suggestion meets these guidelines:
- This wouldn't be a breaking change in existing TypeScript/JavaScript code
- This wouldn't change the runtime behavior of existing JavaScript code
- This could be implemented without emitting different JS based on the types of the expressions
- This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, etc.)
- This feature would agree with the rest of TypeScript's Design Goals.
rdsedmundo and andriyor
Metadata
Metadata
Assignees
Labels
Domain: APIRelates to the public API for TypeScriptRelates to the public API for TypeScript