microsoft / microsoft/TypeScript

Exposing canonical filename logic

Offen
#37,772 3 Kommentare 3 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Domain: API
Vorherrschende Sprache
Go
Sterne
111k
Forks
14.3k
Ø Merge
2 T. 4 Std.
Gemergte PRs (30 T.)
132

Beschreibung

Search Terms

canonical filename

Suggestion

I'd like to re-use the get-canonical-filename logic:
https://github.com/microsoft/TypeScript/blob/d68295e74e4897f588e73edf72089eb238904f02/src/compiler/core.ts#L1906-L1909

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.

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Beginne mit der kanonischen Dateinamenlogik in src/compiler/core.ts in den Zeilen 1906-1909 und untersuche den Einstiegspunkt createModuleResolutionCache. Vergleiche ihn mit toFileNameLowerCase, das ebenfalls im Issue verlinkt ist, und ermittle die benötigte Form des öffentlichen Helpers anhand des Beispiels. Erledigt ist die Aufgabe, wenn Consumers das kanonische Dateinamenverhalten des Compilers für die Modulauflösung wiederverwenden können, ohne die Logik zu kopieren.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
typescript
Bereich
api, compilers
Issue-Typ
Feature
Schwierigkeit
3/5
Geschätzter Aufwand
1-2 Tage
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
35/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.