Skip to content

Commit 681f718

Browse files
jakebaileyD4N14L
andauthored
[api-extractor] pass compilerOptions into getModeForUsageLocation to 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]>
1 parent c4c5e3f commit 681f718

File tree

3 files changed

+20
-4
lines changed

3 files changed

+20
-4
lines changed

apps/api-extractor/src/analyzer/ExportAnalyzer.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,11 @@ export class ExportAnalyzer {
265265
: importOrExportDeclaration.moduleSpecifier;
266266
const mode: ts.ModuleKind.CommonJS | ts.ModuleKind.ESNext | undefined =
267267
specifier && ts.isStringLiteralLike(specifier)
268-
? TypeScriptInternals.getModeForUsageLocation(importOrExportDeclaration.getSourceFile(), specifier)
268+
? TypeScriptInternals.getModeForUsageLocation(
269+
importOrExportDeclaration.getSourceFile(),
270+
specifier,
271+
this._program.getCompilerOptions()
272+
)
269273
: undefined;
270274

271275
const resolvedModule: ts.ResolvedModuleFull | undefined = TypeScriptInternals.getResolvedModule(
@@ -905,7 +909,8 @@ export class ExportAnalyzer {
905909
ts.isStringLiteralLike(importOrExportDeclaration.moduleSpecifier)
906910
? TypeScriptInternals.getModeForUsageLocation(
907911
importOrExportDeclaration.getSourceFile(),
908-
importOrExportDeclaration.moduleSpecifier
912+
importOrExportDeclaration.moduleSpecifier,
913+
this._program.getCompilerOptions()
909914
)
910915
: undefined;
911916
const resolvedModule: ts.ResolvedModuleFull | undefined = TypeScriptInternals.getResolvedModule(

apps/api-extractor/src/analyzer/TypeScriptInternals.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,12 +102,13 @@ export class TypeScriptInternals {
102102
*/
103103
public static getModeForUsageLocation(
104104
file: { impliedNodeFormat?: ts.SourceFile['impliedNodeFormat'] },
105-
usage: ts.StringLiteralLike | undefined
105+
usage: ts.StringLiteralLike,
106+
compilerOptions: ts.CompilerOptions
106107
): ts.ModuleKind.CommonJS | ts.ModuleKind.ESNext | undefined {
107108
// Compiler internal:
108109
// https://github.com/microsoft/TypeScript/blob/v4.7.2/src/compiler/program.ts#L568
109110

110-
return (ts as any).getModeForUsageLocation?.(file, usage);
111+
return ts.getModeForUsageLocation?.(file, usage, compilerOptions);
111112
}
112113

113114
/**
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"changes": [
3+
{
4+
"packageName": "@microsoft/api-extractor",
5+
"comment": "Fix a compatibility issue with usage of `getModeForUsageLocation` in TypeScript 5.6",
6+
"type": "patch"
7+
}
8+
],
9+
"packageName": "@microsoft/api-extractor"
10+
}

0 commit comments

Comments
 (0)