Skip to content

Commit 41aeaae

Browse files
committed
Cleanup, add watch capabilities
1 parent 5b4553d commit 41aeaae

10 files changed

Lines changed: 2212 additions & 1098 deletions

File tree

Jakefile.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ var harnessCoreSources = [
9595
"harness.ts",
9696
"collections.ts",
9797
"vpath.ts",
98+
"events.ts",
9899
"vfs.ts",
99100
"virtualFileSystemWithWatch.ts",
100101
"sourceMapRecorder.ts",

src/harness/collections.ts

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,23 @@
11
/// <reference path="./harness.ts" />
2-
namespace Collections {
3-
import compareValues = ts.compareValues;
2+
namespace collections {
3+
// NOTE: Some of the functions here duplicate functionality from compiler/core.ts. They have been added
4+
// to reduce the number of direct dependencies on compiler and services to eventually break away
5+
// from depending directly on the compiler to speed up compilation time.
6+
47
import binarySearch = ts.binarySearch;
58
import removeAt = ts.orderedRemoveItemAt;
69

10+
export function compareValues<T>(a: T, b: T): number {
11+
if (a === b) return 0;
12+
if (a === undefined) return -1;
13+
if (b === undefined) return +1;
14+
return a < b ? -1 : +1;
15+
}
16+
717
const caseInsensitiveComparisonCollator = typeof Intl === "object" ? new Intl.Collator(/*locales*/ undefined, { usage: "sort", sensitivity: "accent" }) : undefined;
818
const caseSensitiveComparisonCollator = typeof Intl === "object" ? new Intl.Collator(/*locales*/ undefined, { usage: "sort", sensitivity: "variant" }) : undefined;
919

10-
export function compareStrings(a: string | undefined, b: string | undefined, ignoreCase?: boolean) {
20+
export function compareStrings(a: string | undefined, b: string | undefined, ignoreCase: boolean) {
1121
if (a === b) return 0;
1222
if (a === undefined) return -1;
1323
if (b === undefined) return +1;
@@ -23,13 +33,8 @@ namespace Collections {
2333
}
2434

2535
export namespace compareStrings {
26-
export function caseSensitive(a: string | undefined, b: string | undefined) {
27-
return compareStrings(a, b, /*ignoreCase*/ false);
28-
}
29-
30-
export function caseInsensitive(a: string | undefined, b: string | undefined) {
31-
return compareStrings(a, b, /*ignoreCase*/ true);
32-
}
36+
export function caseSensitive(a: string | undefined, b: string | undefined) { return compareStrings(a, b, /*ignoreCase*/ false); }
37+
export function caseInsensitive(a: string | undefined, b: string | undefined) { return compareStrings(a, b, /*ignoreCase*/ true); }
3338
}
3439

3540
function insertAt<T>(array: T[], index: number, value: T) {
@@ -50,7 +55,7 @@ namespace Collections {
5055
/**
5156
* A collection of key/value pairs sorted by key.
5257
*/
53-
export class KeyedCollection<K, V> {
58+
export class SortedCollection<K, V> {
5459
private _comparer: (a: K, b: K) => number;
5560
private _keys: K[] = [];
5661
private _values: V[] = [];
@@ -145,6 +150,14 @@ namespace Collections {
145150

146151
const undefinedSentinel = {};
147152

153+
function escapeKey(text: string) {
154+
return (text.length >= 2 && text.charAt(0) === "_" && text.charAt(1) === "_" ? "_" + text : text);
155+
}
156+
157+
function unescapeKey(text: string) {
158+
return (text.length >= 3 && text.charAt(0) === "_" && text.charAt(1) === "_" && text.charAt(2) === "_" ? text.slice(1) : text);
159+
}
160+
148161
/**
149162
* A collection of metadata that supports inheritance.
150163
*/
@@ -173,24 +186,25 @@ namespace Collections {
173186
}
174187

175188
public has(key: string): boolean {
176-
return this._map[key] !== undefined;
189+
return this._map[escapeKey(key)] !== undefined;
177190
}
178191

179192
public get(key: string): any {
180-
const value = this._map[key];
193+
const value = this._map[escapeKey(key)];
181194
return value === undefinedSentinel ? undefined : value;
182195
}
183196

184197
public set(key: string, value: any): this {
185-
this._map[key] = value === undefined ? undefinedSentinel : value;
198+
this._map[escapeKey(key)] = value === undefined ? undefinedSentinel : value;
186199
this._size = -1;
187200
this._version++;
188201
return this;
189202
}
190203

191204
public delete(key: string): boolean {
192-
if (this._map[key] !== undefined) {
193-
delete this._map[key];
205+
const escapedKey = escapeKey(key);
206+
if (this._map[escapedKey] !== undefined) {
207+
delete this._map[escapedKey];
194208
this._size = -1;
195209
this._version++;
196210
return true;
@@ -206,7 +220,7 @@ namespace Collections {
206220

207221
public forEach(callback: (value: any, key: string, map: this) => void) {
208222
for (const key in this._map) {
209-
callback(this._map[key], key, this);
223+
callback(this._map[key], unescapeKey(key), this);
210224
}
211225
}
212226
}

src/harness/events.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/// <reference path="./harness.ts" />
2+
namespace events {
3+
const _events = require("events");
4+
5+
export const EventEmitter: {
6+
new (): EventEmitter;
7+
prototype: EventEmitter;
8+
defaultMaxListeners: number;
9+
} = _events.EventEmitter;
10+
11+
export interface EventEmitter {
12+
on(event: string | symbol, listener: (...args: any[]) => void): this;
13+
once: this["on"];
14+
addListener: this["on"];
15+
prependListener: this["on"];
16+
prependOnceListener: this["on"];
17+
removeListener: this["on"];
18+
removeAllListeners(event?: string | symbol): this;
19+
setMaxListeners(n: number): this;
20+
getMaxListeners(): number;
21+
listeners(event: string | symbol): Function[];
22+
emit(event: string | symbol, ...args: any[]): boolean;
23+
eventNames(): (string | symbol)[];
24+
listenerCount(type: string | symbol): number;
25+
}
26+
}

0 commit comments

Comments
 (0)