Skip to content

Commit

Permalink
[api-extractor] pass compilerOptions into getModeForUsageLocation to …
Browse files Browse the repository at this point in the history
…fix TS 5.6 (#4973)

* [api-extractor] pass compilerOptions into getModeForUsageLocation to fix TS 5.6

* change

* Update common/changes/@microsoft/api-extractor/fix-5.6_2024-10-14-19-47.json

---------

Co-authored-by: Daniel <[email protected]>
  • Loading branch information
jakebailey and D4N14L authored Oct 14, 2024
1 parent c4c5e3f commit 681f718
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
9 changes: 7 additions & 2 deletions apps/api-extractor/src/analyzer/ExportAnalyzer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,11 @@ export class ExportAnalyzer {
: importOrExportDeclaration.moduleSpecifier;
const mode: ts.ModuleKind.CommonJS | ts.ModuleKind.ESNext | undefined =
specifier && ts.isStringLiteralLike(specifier)
? TypeScriptInternals.getModeForUsageLocation(importOrExportDeclaration.getSourceFile(), specifier)
? TypeScriptInternals.getModeForUsageLocation(
importOrExportDeclaration.getSourceFile(),
specifier,
this._program.getCompilerOptions()
)
: undefined;

const resolvedModule: ts.ResolvedModuleFull | undefined = TypeScriptInternals.getResolvedModule(
Expand Down Expand Up @@ -905,7 +909,8 @@ export class ExportAnalyzer {
ts.isStringLiteralLike(importOrExportDeclaration.moduleSpecifier)
? TypeScriptInternals.getModeForUsageLocation(
importOrExportDeclaration.getSourceFile(),
importOrExportDeclaration.moduleSpecifier
importOrExportDeclaration.moduleSpecifier,
this._program.getCompilerOptions()
)
: undefined;
const resolvedModule: ts.ResolvedModuleFull | undefined = TypeScriptInternals.getResolvedModule(
Expand Down
5 changes: 3 additions & 2 deletions apps/api-extractor/src/analyzer/TypeScriptInternals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,13 @@ export class TypeScriptInternals {
*/
public static getModeForUsageLocation(
file: { impliedNodeFormat?: ts.SourceFile['impliedNodeFormat'] },
usage: ts.StringLiteralLike | undefined
usage: ts.StringLiteralLike,
compilerOptions: ts.CompilerOptions
): ts.ModuleKind.CommonJS | ts.ModuleKind.ESNext | undefined {
// Compiler internal:
// https://github.com/microsoft/TypeScript/blob/v4.7.2/src/compiler/program.ts#L568

return (ts as any).getModeForUsageLocation?.(file, usage);
return ts.getModeForUsageLocation?.(file, usage, compilerOptions);
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@microsoft/api-extractor",
"comment": "Fix a compatibility issue with usage of `getModeForUsageLocation` in TypeScript 5.6",
"type": "patch"
}
],
"packageName": "@microsoft/api-extractor"
}

0 comments on commit 681f718

Please sign in to comment.