Skip to content

Commit d56a50b

Browse files
authored
Merge pull request #9485 from Microsoft/getEmitOutputAsObject
add new method getEmitOutputObject to return result of the emit as object
2 parents c2730ce + f9a5593 commit d56a50b

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

src/services/shims.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,7 @@ namespace ts {
231231
isValidBraceCompletionAtPosition(fileName: string, position: number, openingBrace: number): string;
232232

233233
getEmitOutput(fileName: string): string;
234+
getEmitOutputObject(fileName: string): EmitOutput;
234235
}
235236

236237
export interface ClassifierShim extends Shim {
@@ -518,9 +519,13 @@ namespace ts {
518519
}
519520

520521
function forwardJSONCall(logger: Logger, actionDescription: string, action: () => any, logPerformance: boolean): string {
522+
return <string>forwardCall(logger, actionDescription, /*returnJson*/ true, action, logPerformance);
523+
}
524+
525+
function forwardCall<T>(logger: Logger, actionDescription: string, returnJson: boolean, action: () => T, logPerformance: boolean): T | string {
521526
try {
522527
const result = simpleForwardCall(logger, actionDescription, action, logPerformance);
523-
return JSON.stringify({ result });
528+
return returnJson ? JSON.stringify({ result }) : result;
524529
}
525530
catch (err) {
526531
if (err instanceof OperationCanceledException) {
@@ -532,6 +537,7 @@ namespace ts {
532537
}
533538
}
534539

540+
535541
class ShimBase implements Shim {
536542
constructor(private factory: ShimFactory) {
537543
factory.registerShim(this);
@@ -918,6 +924,15 @@ namespace ts {
918924
() => this.languageService.getEmitOutput(fileName)
919925
);
920926
}
927+
928+
public getEmitOutputObject(fileName: string): any {
929+
return forwardCall(
930+
this.logger,
931+
`getEmitOutput('${fileName}')`,
932+
/*returnJson*/ false,
933+
() => this.languageService.getEmitOutput(fileName),
934+
this.logPerformance);
935+
}
921936
}
922937

923938
function convertClassifications(classifications: Classifications): { spans: string, endOfLineState: EndOfLineState } {

0 commit comments

Comments
 (0)