Skip to content

Commit 04a5245

Browse files
committed
Add semver range parsing support
1 parent 37ec065 commit 04a5245

File tree

10 files changed

+483
-19
lines changed

10 files changed

+483
-19
lines changed

Gulpfile.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -570,12 +570,12 @@ gulp.task(
570570
});
571571
}, /*timeout*/ 100, { max: 500 });
572572

573-
gulp.watch(watchPatterns, () => project.wait().then(fn));
573+
gulp.watch(watchPatterns, () => project.wait(runTestsSource && runTestsSource.token).then(fn));
574574

575575
// NOTE: gulp.watch is far too slow when watching tests/cases/**/* as it first enumerates *every* file
576576
const testFilePattern = /(\.ts|[\\/]tsconfig\.json)$/;
577577
fs.watch("tests/cases", { recursive: true }, (_, file) => {
578-
if (testFilePattern.test(file)) project.wait().then(fn);
578+
if (testFilePattern.test(file)) project.wait(runTestsSource && runTestsSource.token).then(fn);
579579
});
580580

581581
function runTests() {

scripts/build/countdown.js

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
// @ts-check
2+
const { CancelToken } = require("./cancellation");
3+
4+
class Countdown {
5+
constructor(initialCount = 0) {
6+
if (initialCount < 0) throw new Error();
7+
this._remainingCount = initialCount;
8+
this._promise = undefined;
9+
this._resolve = undefined;
10+
}
11+
12+
get remainingCount() {
13+
return this._remainingCount;
14+
}
15+
16+
add(count = 1) {
17+
if (count < 1 || !isFinite(count) || Math.trunc(count) !== count) throw new Error();
18+
if (this._remainingCount === 0) {
19+
this._promise = undefined;
20+
this._resolve = undefined;
21+
}
22+
23+
this._remainingCount += count;
24+
}
25+
26+
signal(count = 1) {
27+
if (count < 1 || !isFinite(count) || Math.trunc(count) !== count) throw new Error();
28+
if (this._remainingCount - count < 0) throw new Error();
29+
this._remainingCount -= count;
30+
if (this._remainingCount == 0) {
31+
if (this._resolve) {
32+
this._resolve();
33+
}
34+
return true;
35+
}
36+
return false;
37+
}
38+
39+
/** @param {CancelToken} [token] */
40+
wait(token) {
41+
if (!this._promise) {
42+
this._promise = new Promise(resolve => { this._resolve = resolve; });
43+
}
44+
if (this._remainingCount === 0) {
45+
this._resolve();
46+
}
47+
if (!token) return this._promise;
48+
return new Promise((resolve, reject) => {
49+
const subscription = token.subscribe(reject);
50+
this._promise.then(
51+
value => {
52+
subscription.unsubscribe();
53+
resolve(value);
54+
},
55+
error => {
56+
subscription.unsubscribe();
57+
reject(error);
58+
});
59+
});
60+
}
61+
}
62+
exports.Countdown = Countdown;

scripts/build/exec.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,10 @@ function exec(cmd, args, options = {}) {
2525
const command = isWin ? [possiblyQuote(cmd), ...args] : [`${cmd} ${args.join(" ")}`];
2626
const ex = cp.spawn(isWin ? "cmd" : "/bin/sh", [subshellFlag, ...command], { stdio: "inherit", windowsVerbatimArguments: true });
2727
const subscription = options.cancelToken && options.cancelToken.subscribe(() => {
28+
log(`${chalk.red("killing")} '${chalk.green(cmd)} ${args.join(" ")}'...`);
2829
ex.kill("SIGINT");
2930
ex.kill("SIGTERM");
31+
ex.kill();
3032
reject(new CancelError());
3133
});
3234
ex.on("exit", exitCode => {

scripts/build/project.js

Lines changed: 33 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,27 @@ const del = require("del");
1313
const needsUpdate = require("./needsUpdate");
1414
const mkdirp = require("./mkdirp");
1515
const { reportDiagnostics } = require("./diagnostics");
16+
const { Countdown } = require("./countdown");
17+
const { CancelToken } = require("./cancellation");
18+
19+
const countdown = new Countdown();
1620

1721
class CompilationGulp extends gulp.Gulp {
22+
constructor() {
23+
super();
24+
this.on("start", () => {
25+
const onDone = () => {
26+
this.removeListener("stop", onDone);
27+
this.removeListener("err", onDone);
28+
countdown.signal();
29+
};
30+
31+
this.on("stop", onDone);
32+
this.on("err", onDone);
33+
countdown.add();
34+
});
35+
}
36+
1837
/**
1938
* @param {boolean} [verbose]
2039
*/
@@ -38,6 +57,17 @@ class ForkedGulp extends gulp.Gulp {
3857
constructor(tasks) {
3958
super();
4059
this.tasks = tasks;
60+
this.on("start", () => {
61+
const onDone = () => {
62+
this.removeListener("stop", onDone);
63+
this.removeListener("err", onDone);
64+
countdown.signal();
65+
};
66+
67+
this.on("stop", onDone);
68+
this.on("err", onDone);
69+
countdown.add();
70+
});
4171
}
4272

4373
// Do not reset tasks
@@ -211,22 +241,10 @@ exports.flatten = flatten;
211241

212242
/**
213243
* Returns a Promise that resolves when all pending build tasks have completed
244+
* @param {CancelToken} [token]
214245
*/
215-
function wait() {
216-
return new Promise(resolve => {
217-
if (compilationGulp.allDone()) {
218-
resolve();
219-
}
220-
else {
221-
const onDone = () => {
222-
compilationGulp.removeListener("onDone", onDone);
223-
compilationGulp.removeListener("err", onDone);
224-
resolve();
225-
};
226-
compilationGulp.on("stop", onDone);
227-
compilationGulp.on("err", onDone);
228-
}
229-
});
246+
function wait(token) {
247+
return countdown.wait(token);
230248
}
231249
exports.wait = wait;
232250

src/compiler/checker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22233,7 +22233,7 @@ namespace ts {
2223322233
for (const decl of indexSymbol.declarations) {
2223422234
const declaration = <SignatureDeclaration>decl;
2223522235
if (declaration.parameters.length === 1 && declaration.parameters[0].type) {
22236-
switch (declaration.parameters[0].type!.kind) {
22236+
switch (declaration.parameters[0].type.kind) {
2223722237
case SyntaxKind.StringKeyword:
2223822238
if (!seenStringIndexer) {
2223922239
seenStringIndexer = true;

src/compiler/core.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ namespace ts {
6565

6666
/* @internal */
6767
namespace ts {
68+
export const emptyArray: never[] = [] as never[];
6869

6970
/** Create a MapLike with good performance. */
7071
function createDictionaryObject<T>(): MapLike<T> {

0 commit comments

Comments
 (0)