Skip to content

Commit d6c475b

Browse files
committed
Remove TS usage in CancellationToken
1 parent 1695211 commit d6c475b

File tree

4 files changed

+9
-7
lines changed

4 files changed

+9
-7
lines changed

src/CancellationToken.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as crypto from 'crypto';
22
import * as fs from 'fs';
33
import * as os from 'os';
44
import * as path from 'path';
5-
import * as ts from 'typescript';
5+
import { OperationCanceledException } from './OperationCanceledException';
66

77
interface CancellationTokenData {
88
isCancelled: boolean;
@@ -54,7 +54,7 @@ export class CancellationToken {
5454

5555
throwIfCancellationRequested() {
5656
if (this.isCancellationRequested()) {
57-
throw new ts.OperationCanceledException();
57+
throw new OperationCanceledException();
5858
}
5959
}
6060

src/OperationCanceledException.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export class OperationCanceledException {}

src/service.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import * as process from 'process';
2-
import * as ts from 'typescript';
32
import { IncrementalChecker } from './IncrementalChecker';
43
import { CancellationToken } from './CancellationToken';
54
import { NormalizedMessage } from './NormalizedMessage';
5+
import { OperationCanceledException } from './OperationCanceledException';
66

77
const checker = new IncrementalChecker(
88
process.env.TSCONFIG,
@@ -26,7 +26,7 @@ function run(cancellationToken: CancellationToken) {
2626
lints = checker.getLints(cancellationToken);
2727
}
2828
} catch (error) {
29-
if (error instanceof ts.OperationCanceledException) {
29+
if (error instanceof OperationCanceledException) {
3030
return;
3131
}
3232

test/unit/CancellationToken.spec.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
var describe = require('mocha').describe;
22
var it = require('mocha').it;
33
var os = require('os');
4-
var ts = require('typescript');
54
var fs = require('fs');
65
var beforeEach = require('mocha').beforeEach;
76
var afterEach = require('mocha').afterEach;
87
var expect = require('chai').expect;
98
var mockFs = require('mock-fs');
109
var CancellationToken = require('../../lib/CancellationToken')
1110
.CancellationToken;
11+
var OperationCanceledException = require('../../lib/OperationCanceledException')
12+
.OperationCanceledException;
1213

1314
describe('[UNIT] CancellationToken', function() {
1415
beforeEach(function() {
@@ -63,7 +64,7 @@ describe('[UNIT] CancellationToken', function() {
6364
);
6465
});
6566

66-
it('should throw ts.OperationCanceledException error on cancelled', function() {
67+
it('should throw OperationCanceledException error on cancelled', function() {
6768
var tokenA = new CancellationToken();
6869
expect(function() {
6970
tokenA.throwIfCancellationRequested();
@@ -72,7 +73,7 @@ describe('[UNIT] CancellationToken', function() {
7273
var tokenB = new CancellationToken('rgeer#R23r$#T$3t#$t43', true);
7374
expect(function() {
7475
tokenB.throwIfCancellationRequested();
75-
}).to.throw(ts.OperationCanceledException);
76+
}).to.throw(OperationCanceledException);
7677
});
7778

7879
it('should write file in filesystem on requestCancellation', function() {

0 commit comments

Comments
 (0)