|
| 1 | +namespace ts { |
| 2 | +/* |
| 3 | + interface BuildContext { |
| 4 | + unchangedOutputs: FileMap<number>; |
| 5 | + } |
| 6 | +
|
| 7 | +
|
| 8 | +
|
| 9 | + interface FileMap<T> { |
| 10 | + setValue(fileName: string, value: T): void; |
| 11 | + getValue(fileName: string): T | never; |
| 12 | + getValueOrUndefined(fileName: string): T | undefined; |
| 13 | + getValueOrDefault(fileName: string, defaultValue: T): T; |
| 14 | + tryGetValue(fileName: string): [false, undefined] | [true, T]; |
| 15 | + } |
| 16 | +
|
| 17 | + function createFileMap<T>(): FileMap<T> { |
| 18 | + const lookup: { [key: string]: T } = Object.create(null); |
| 19 | +
|
| 20 | + return { |
| 21 | + setValue, |
| 22 | + getValue, |
| 23 | + getValueOrUndefined, |
| 24 | + getValueOrDefault, |
| 25 | + tryGetValue |
| 26 | + } |
| 27 | +
|
| 28 | + function setValue(fileName: string, value: T) { |
| 29 | + lookup[normalizePath(fileName)] = value; |
| 30 | + } |
| 31 | +
|
| 32 | + function getValue(fileName: string): T | never { |
| 33 | + const f = normalizePath(fileName); |
| 34 | + if (f in lookup) { |
| 35 | + return lookup[f]; |
| 36 | + } else { |
| 37 | + throw new Error(`No value corresponding to ${fileName} exists in this map`); |
| 38 | + } |
| 39 | + } |
| 40 | +
|
| 41 | + function getValueOrUndefined(fileName: string): T | undefined { |
| 42 | + const f = normalizePath(fileName); |
| 43 | + if (f in lookup) { |
| 44 | + return lookup[f]; |
| 45 | + } else { |
| 46 | + return undefined; |
| 47 | + } |
| 48 | + } |
| 49 | +
|
| 50 | + function getValueOrDefault(fileName: string, defaultValue: T): T { |
| 51 | + const f = normalizePath(fileName); |
| 52 | + if (f in lookup) { |
| 53 | + return lookup[f]; |
| 54 | + } else { |
| 55 | + return defaultValue; |
| 56 | + } |
| 57 | + } |
| 58 | +
|
| 59 | + function tryGetValue(fileName: string): [false, undefined] | [true, T] { |
| 60 | + const f = normalizePath(fileName); |
| 61 | + if (f in lookup) { |
| 62 | + return [true as true, lookup[f]]; |
| 63 | + } else { |
| 64 | + return [false as false, undefined]; |
| 65 | + } |
| 66 | + } |
| 67 | + } |
| 68 | + */ |
| 69 | +} |
0 commit comments