util.js
3.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/**
* @license
* Copyright Google Inc. All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
"use strict";
// toArray is a temporary function to help in the use of
// ES6 maps and sets when running on node 4, which doesn't
// support Iterators completely.
var ts = require("typescript");
function toArray(iterator) {
var array = [];
while (true) {
var ir = iterator.next();
if (ir.done) {
break;
}
array.push(ir.value);
}
return array;
}
exports.toArray = toArray;
/**
* Constructs a new ts.CompilerHost that overlays sources in substituteSource
* over another ts.CompilerHost.
*
* @param substituteSource A map of source file name -> overlay source text.
*/
function createSourceReplacingCompilerHost(substituteSource, delegate) {
return {
getSourceFile: getSourceFile,
getCancellationToken: delegate.getCancellationToken,
getDefaultLibFileName: delegate.getDefaultLibFileName,
writeFile: delegate.writeFile,
getCurrentDirectory: delegate.getCurrentDirectory,
getCanonicalFileName: delegate.getCanonicalFileName,
useCaseSensitiveFileNames: delegate.useCaseSensitiveFileNames,
getNewLine: delegate.getNewLine,
fileExists: delegate.fileExists,
readFile: delegate.readFile,
directoryExists: delegate.directoryExists,
getDirectories: delegate.getDirectories,
};
function getSourceFile(fileName, languageVersion, onError) {
var path = ts.sys.resolvePath(fileName);
var sourceText = substituteSource.get(path);
if (sourceText !== undefined) {
return ts.createSourceFile(fileName, sourceText, languageVersion);
}
return delegate.getSourceFile(path, languageVersion, onError);
}
}
exports.createSourceReplacingCompilerHost = createSourceReplacingCompilerHost;
/**
* Constructs a new ts.CompilerHost that overlays sources in substituteSource
* over another ts.CompilerHost.
*
* @param outputFiles map to fill with source file name -> output text.
*/
function createOutputRetainingCompilerHost(outputFiles, delegate) {
return {
getSourceFile: delegate.getSourceFile,
getCancellationToken: delegate.getCancellationToken,
getDefaultLibFileName: delegate.getDefaultLibFileName,
writeFile: writeFile,
getCurrentDirectory: delegate.getCurrentDirectory,
getCanonicalFileName: delegate.getCanonicalFileName,
useCaseSensitiveFileNames: delegate.useCaseSensitiveFileNames,
getNewLine: delegate.getNewLine,
fileExists: delegate.fileExists,
readFile: delegate.readFile,
directoryExists: delegate.directoryExists,
getDirectories: delegate.getDirectories,
};
function writeFile(fileName, content, writeByteOrderMark, onError, sourceFiles) {
outputFiles.set(fileName, content);
}
}
exports.createOutputRetainingCompilerHost = createOutputRetainingCompilerHost;
//# sourceMappingURL=util.js.map