Skip to content

Commit

Permalink
fix(typescript): correctly process diagnostics in worker mode (#3441)
Browse files Browse the repository at this point in the history
  • Loading branch information
thesayyn authored May 3, 2022
1 parent 55a84d1 commit e4842c1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
10 changes: 7 additions & 3 deletions packages/typescript/internal/worker/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ function emitOnce(args) {
consolidateChangesCallback();
}
workerRequestTimestamp = Date.now();
const result = yield (watchProgram === null || watchProgram === void 0 ? void 0 : watchProgram.getProgram().emit(undefined, undefined, {
const program = watchProgram === null || watchProgram === void 0 ? void 0 : watchProgram.getProgram();
const cancellationToken = {
isCancellationRequested: function (timestamp) {
return timestamp !== workerRequestTimestamp;
}.bind(null, workerRequestTimestamp),
Expand All @@ -66,8 +67,11 @@ function emitOnce(args) {
throw new ts.OperationCanceledException();
}
}.bind(null, workerRequestTimestamp),
}));
return Boolean(result && result.diagnostics.length === 0);
};
const result = program.emit(undefined, undefined, cancellationToken);
const diagnostics = ts.getPreEmitDiagnostics(program, undefined, cancellationToken);
let succeded = result && result.diagnostics.length === 0 && diagnostics.length == 0;
return succeded;
});
}
function main() {
Expand Down
13 changes: 8 additions & 5 deletions packages/typescript/internal/worker/worker_adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,9 @@ async function emitOnce(args: string[]) {
consolidateChangesCallback();
}


workerRequestTimestamp = Date.now();
const result = await watchProgram ?.getProgram().emit(undefined, undefined, {
const program = watchProgram?.getProgram()
const cancellationToken: ts.CancellationToken = {
isCancellationRequested: function(timestamp: number) {
return timestamp !== workerRequestTimestamp;
}.bind(null, workerRequestTimestamp),
Expand All @@ -110,9 +110,12 @@ async function emitOnce(args: string[]) {
throw new ts.OperationCanceledException();
}
}.bind(null, workerRequestTimestamp),
});

return Boolean(result && result.diagnostics.length === 0);
}

const result = program.emit(undefined, undefined, cancellationToken);
const diagnostics = ts.getPreEmitDiagnostics(program as unknown as ts.Program, undefined, cancellationToken)
let succeded = result && result.diagnostics.length === 0 && diagnostics.length == 0
return succeded
}

function main() {
Expand Down

0 comments on commit e4842c1

Please sign in to comment.