Skip to content

Commit d9fce93

Browse files
committed
Emit with cancellation token enabled esp now that declaration emit can resolve types etc without type checking
1 parent 23f7204 commit d9fce93

File tree

5 files changed

+121
-134
lines changed

5 files changed

+121
-134
lines changed

src/compiler/program.ts

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2870,18 +2870,27 @@ export function createProgram(rootNamesOrOptions: readonly string[] | CreateProg
28702870
// This is because in the -out scenario all files need to be emitted, and therefore all
28712871
// files need to be type checked. And the way to specify that all files need to be type
28722872
// checked is to not pass the file to getEmitResolver.
2873-
const emitResolver = getTypeChecker().getEmitResolver(options.outFile ? undefined : sourceFile, cancellationToken, forceDtsEmit);
2873+
const typeChecker = getTypeChecker();
2874+
const emitResolver = typeChecker.getEmitResolver(
2875+
options.outFile ? undefined : sourceFile,
2876+
cancellationToken,
2877+
forceDtsEmit,
2878+
);
28742879

28752880
performance.mark("beforeEmit");
28762881

2877-
const emitResult = emitFiles(
2878-
emitResolver,
2879-
getEmitHost(writeFileCallback),
2880-
sourceFile,
2881-
getTransformers(options, customTransformers, emitOnly),
2882-
emitOnly,
2883-
/*onlyBuildInfo*/ false,
2884-
forceDtsEmit,
2882+
const emitResult = typeChecker.runWithCancellationToken(
2883+
cancellationToken,
2884+
() =>
2885+
emitFiles(
2886+
emitResolver,
2887+
getEmitHost(writeFileCallback),
2888+
sourceFile,
2889+
getTransformers(options, customTransformers, emitOnly),
2890+
emitOnly,
2891+
/*onlyBuildInfo*/ false,
2892+
forceDtsEmit,
2893+
),
28852894
);
28862895

28872896
performance.mark("afterEmit");

src/compiler/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5354,6 +5354,8 @@ export interface TypeChecker {
53545354
* and the operation is cancelled, then it should be discarded, otherwise it is safe to keep.
53555355
*/
53565356
runWithCancellationToken<T>(token: CancellationToken, cb: (checker: TypeChecker) => T): T;
5357+
/**@internal */
5358+
runWithCancellationToken<T>(token: CancellationToken | undefined, cb: (checker: TypeChecker) => T): T; // eslint-disable-line @typescript-eslint/unified-signatures
53575359

53585360
/** @internal */ getLocalTypeParametersOfClassOrInterfaceOrTypeAlias(symbol: Symbol): readonly TypeParameter[] | undefined;
53595361
/** @internal */ isDeclarationVisible(node: Declaration | AnyImportSyntax): boolean;

src/testRunner/unittests/tsc/cancellationToken.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import {
1717
libFile,
1818
} from "../helpers/virtualFileSystemWithWatch.js";
1919

20-
describe("unittests:: tsc:: builder cancellationToken", () => {
20+
describe("unittests:: tsc:: builder cancellationToken:: sheetal", () => {
2121
verifyCancellation(/*useBuildInfo*/ true, "when emitting buildInfo");
2222
verifyCancellation(/*useBuildInfo*/ false, "when using state");
2323
function verifyCancellation(useBuildInfo: boolean, scenario: string) {
@@ -41,9 +41,9 @@ describe("unittests:: tsc:: builder cancellationToken", () => {
4141
const cFile: File = {
4242
path: `/user/username/projects/myproject/c.ts`,
4343
content: Utils.dedent`
44-
export class C {
44+
export var C = class CReal {
4545
d = 1;
46-
}`,
46+
};`,
4747
};
4848
const dFile: File = {
4949
path: `/user/username/projects/myproject/d.ts`,

0 commit comments

Comments
 (0)