Skip to content

Commit

Permalink
fix(typescript): transform source file for tsc
Browse files Browse the repository at this point in the history
  • Loading branch information
johnsoncodehk committed Mar 28, 2024
1 parent e6dcb83 commit a414785
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion packages/typescript/lib/node/transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type * as ts from 'typescript';
import { getServiceScript, notEmpty } from './utils';

const transformedDiagnostics = new WeakMap<ts.Diagnostic, ts.Diagnostic | undefined>();
const transformedSourceFiles = new WeakMap<ts.SourceFile, ts.SourceFile>();

export function transformCallHierarchyItem(language: Language, item: ts.CallHierarchyItem, filter: (data: CodeInformation) => boolean): ts.CallHierarchyItem {
const span = transformSpan(language, item.file, item.span, filter);
Expand All @@ -19,7 +20,6 @@ export function transformDiagnostic<T extends ts.Diagnostic>(language: Language,
transformedDiagnostics.set(diagnostic, undefined);

const { relatedInformation } = diagnostic;

if (relatedInformation) {
diagnostic.relatedInformation = relatedInformation
.map(d => transformDiagnostic(language, d))
Expand All @@ -39,6 +39,7 @@ export function transformDiagnostic<T extends ts.Diagnostic>(language: Language,
...diagnostic,
start: sourceSpan.start,
length: sourceSpan.length,
file: transformSourceFile(diagnostic.file, sourceScript.snapshot.getText(0, sourceScript.snapshot.getLength())),
});
}
}
Expand All @@ -53,6 +54,16 @@ export function transformDiagnostic<T extends ts.Diagnostic>(language: Language,
return transformedDiagnostics.get(diagnostic) as T | undefined;
}

export function transformSourceFile(sourceFile: ts.SourceFile, sourceText: string): ts.SourceFile {
if (!transformedSourceFiles.has(sourceFile)) {
transformedSourceFiles.set(sourceFile, {
...sourceFile,
text: sourceText,
});
}
return transformedSourceFiles.get(sourceFile)!;
}

export function transformFileTextChanges(language: Language, changes: ts.FileTextChanges, filter: (data: CodeInformation) => boolean): ts.FileTextChanges | undefined {
const [_, source] = getServiceScript(language, changes.fileName);
if (source) {
Expand Down

0 comments on commit a414785

Please sign in to comment.