Put 'sys' into the 'ts' module.
This commit is contained in:
parent
c5510444d9
commit
be1eb3430c
|
@ -1,253 +1,255 @@
|
|||
|
||||
interface System {
|
||||
args: string[];
|
||||
newLine: string;
|
||||
useCaseSensitiveFileNames: boolean;
|
||||
write(s: string): void;
|
||||
readFile(fileName: string, encoding?: string): string;
|
||||
writeFile(fileName: string, data: string, writeByteOrderMark?: boolean): void;
|
||||
watchFile?(fileName: string, callback: (fileName: string) => void): FileWatcher;
|
||||
resolvePath(path: string): string;
|
||||
fileExists(path: string): boolean;
|
||||
directoryExists(path: string): boolean;
|
||||
createDirectory(directoryName: string): void;
|
||||
getExecutingFilePath(): string;
|
||||
getCurrentDirectory(): string;
|
||||
getMemoryUsage?(): number;
|
||||
exit(exitCode?: number): void;
|
||||
}
|
||||
module ts {
|
||||
export interface System {
|
||||
args: string[];
|
||||
newLine: string;
|
||||
useCaseSensitiveFileNames: boolean;
|
||||
write(s: string): void;
|
||||
readFile(fileName: string, encoding?: string): string;
|
||||
writeFile(fileName: string, data: string, writeByteOrderMark?: boolean): void;
|
||||
watchFile? (fileName: string, callback: (fileName: string) => void): FileWatcher;
|
||||
resolvePath(path: string): string;
|
||||
fileExists(path: string): boolean;
|
||||
directoryExists(path: string): boolean;
|
||||
createDirectory(directoryName: string): void;
|
||||
getExecutingFilePath(): string;
|
||||
getCurrentDirectory(): string;
|
||||
getMemoryUsage? (): number;
|
||||
exit(exitCode?: number): void;
|
||||
}
|
||||
|
||||
interface FileWatcher {
|
||||
close(): void;
|
||||
}
|
||||
export interface FileWatcher {
|
||||
close(): void;
|
||||
}
|
||||
|
||||
declare var require: any;
|
||||
declare var module: any;
|
||||
declare var process: any;
|
||||
declare var global: any;
|
||||
declare var __filename: string;
|
||||
declare var require: any;
|
||||
declare var module: any;
|
||||
declare var process: any;
|
||||
declare var global: any;
|
||||
declare var __filename: string;
|
||||
|
||||
var sys: System = (function () {
|
||||
export var sys: System = (function () {
|
||||
|
||||
function getWScriptSystem(): System {
|
||||
function getWScriptSystem(): System {
|
||||
|
||||
var fso = new ActiveXObject("Scripting.FileSystemObject");
|
||||
var fso = new ActiveXObject("Scripting.FileSystemObject");
|
||||
|
||||
var fileStream = new ActiveXObject("ADODB.Stream");
|
||||
fileStream.Type = 2 /*text*/;
|
||||
var fileStream = new ActiveXObject("ADODB.Stream");
|
||||
fileStream.Type = 2 /*text*/;
|
||||
|
||||
var binaryStream = new ActiveXObject("ADODB.Stream");
|
||||
binaryStream.Type = 1 /*binary*/;
|
||||
var binaryStream = new ActiveXObject("ADODB.Stream");
|
||||
binaryStream.Type = 1 /*binary*/;
|
||||
|
||||
var args: string[] = [];
|
||||
for (var i = 0; i < WScript.Arguments.length; i++) {
|
||||
args[i] = WScript.Arguments.Item(i);
|
||||
}
|
||||
|
||||
function readFile(fileName: string, encoding?: string): string {
|
||||
if (!fso.FileExists(fileName)) {
|
||||
return undefined;
|
||||
var args: string[] = [];
|
||||
for (var i = 0; i < WScript.Arguments.length; i++) {
|
||||
args[i] = WScript.Arguments.Item(i);
|
||||
}
|
||||
fileStream.Open();
|
||||
try {
|
||||
if (encoding) {
|
||||
fileStream.Charset = encoding;
|
||||
fileStream.LoadFromFile(fileName);
|
||||
|
||||
function readFile(fileName: string, encoding?: string): string {
|
||||
if (!fso.FileExists(fileName)) {
|
||||
return undefined;
|
||||
}
|
||||
else {
|
||||
// Load file and read the first two bytes into a string with no interpretation
|
||||
fileStream.Charset = "x-ansi";
|
||||
fileStream.LoadFromFile(fileName);
|
||||
var bom = fileStream.ReadText(2) || "";
|
||||
// Position must be at 0 before encoding can be changed
|
||||
fileStream.Position = 0;
|
||||
// [0xFF,0xFE] and [0xFE,0xFF] mean utf-16 (little or big endian), otherwise default to utf-8
|
||||
fileStream.Charset = bom.length >= 2 && (bom.charCodeAt(0) === 0xFF && bom.charCodeAt(1) === 0xFE || bom.charCodeAt(0) === 0xFE && bom.charCodeAt(1) === 0xFF) ? "unicode" : "utf-8";
|
||||
}
|
||||
// ReadText method always strips byte order mark from resulting string
|
||||
return fileStream.ReadText();
|
||||
}
|
||||
catch (e) {
|
||||
throw e;
|
||||
}
|
||||
finally {
|
||||
fileStream.Close();
|
||||
}
|
||||
}
|
||||
|
||||
function writeFile(fileName: string, data: string, writeByteOrderMark?: boolean): void {
|
||||
fileStream.Open();
|
||||
binaryStream.Open();
|
||||
try {
|
||||
// Write characters in UTF-8 encoding
|
||||
fileStream.Charset = "utf-8";
|
||||
fileStream.WriteText(data);
|
||||
// If we don't want the BOM, then skip it by setting the starting location to 3 (size of BOM).
|
||||
// If not, start from position 0, as the BOM will be added automatically when charset==utf8.
|
||||
if (writeByteOrderMark) {
|
||||
fileStream.Position = 0;
|
||||
}
|
||||
else {
|
||||
fileStream.Position = 3;
|
||||
}
|
||||
fileStream.CopyTo(binaryStream);
|
||||
binaryStream.SaveToFile(fileName, 2 /*overwrite*/);
|
||||
}
|
||||
finally {
|
||||
binaryStream.Close();
|
||||
fileStream.Close();
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
args,
|
||||
newLine: "\r\n",
|
||||
useCaseSensitiveFileNames: false,
|
||||
write(s: string): void {
|
||||
WScript.StdOut.Write(s);
|
||||
},
|
||||
readFile,
|
||||
writeFile,
|
||||
resolvePath(path: string): string {
|
||||
return fso.GetAbsolutePathName(path);
|
||||
},
|
||||
fileExists(path: string): boolean {
|
||||
return fso.FileExists(path);
|
||||
},
|
||||
directoryExists(path: string) {
|
||||
return fso.FolderExists(path);
|
||||
},
|
||||
createDirectory(directoryName: string) {
|
||||
if (!this.directoryExists(directoryName)) {
|
||||
fso.CreateFolder(directoryName);
|
||||
}
|
||||
},
|
||||
getExecutingFilePath() {
|
||||
return WScript.ScriptFullName;
|
||||
},
|
||||
getCurrentDirectory() {
|
||||
return new ActiveXObject("WScript.Shell").CurrentDirectory;
|
||||
},
|
||||
exit(exitCode?: number): void {
|
||||
fileStream.Open();
|
||||
try {
|
||||
WScript.Quit(exitCode);
|
||||
if (encoding) {
|
||||
fileStream.Charset = encoding;
|
||||
fileStream.LoadFromFile(fileName);
|
||||
}
|
||||
else {
|
||||
// Load file and read the first two bytes into a string with no interpretation
|
||||
fileStream.Charset = "x-ansi";
|
||||
fileStream.LoadFromFile(fileName);
|
||||
var bom = fileStream.ReadText(2) || "";
|
||||
// Position must be at 0 before encoding can be changed
|
||||
fileStream.Position = 0;
|
||||
// [0xFF,0xFE] and [0xFE,0xFF] mean utf-16 (little or big endian), otherwise default to utf-8
|
||||
fileStream.Charset = bom.length >= 2 && (bom.charCodeAt(0) === 0xFF && bom.charCodeAt(1) === 0xFE || bom.charCodeAt(0) === 0xFE && bom.charCodeAt(1) === 0xFF) ? "unicode" : "utf-8";
|
||||
}
|
||||
// ReadText method always strips byte order mark from resulting string
|
||||
return fileStream.ReadText();
|
||||
}
|
||||
catch (e) {
|
||||
throw e;
|
||||
}
|
||||
finally {
|
||||
fileStream.Close();
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
function getNodeSystem(): System {
|
||||
var _fs = require("fs");
|
||||
var _path = require("path");
|
||||
var _os = require('os');
|
||||
|
||||
var platform: string = _os.platform();
|
||||
// win32\win64 are case insensitive platforms, MacOS (darwin) by default is also case insensitive
|
||||
var useCaseSensitiveFileNames = platform !== "win32" && platform !== "win64" && platform !== "darwin";
|
||||
|
||||
function readFile(fileName: string, encoding?: string): string {
|
||||
if (!_fs.existsSync(fileName)) {
|
||||
return undefined;
|
||||
}
|
||||
var buffer = _fs.readFileSync(fileName);
|
||||
var len = buffer.length;
|
||||
if (len >= 2 && buffer[0] === 0xFE && buffer[1] === 0xFF) {
|
||||
// Big endian UTF-16 byte order mark detected. Since big endian is not supported by node.js,
|
||||
// flip all byte pairs and treat as little endian.
|
||||
len &= ~1;
|
||||
for (var i = 0; i < len; i += 2) {
|
||||
var temp = buffer[i];
|
||||
buffer[i] = buffer[i + 1];
|
||||
buffer[i + 1] = temp;
|
||||
}
|
||||
return buffer.toString("utf16le", 2);
|
||||
}
|
||||
if (len >= 2 && buffer[0] === 0xFF && buffer[1] === 0xFE) {
|
||||
// Little endian UTF-16 byte order mark detected
|
||||
return buffer.toString("utf16le", 2);
|
||||
}
|
||||
if (len >= 3 && buffer[0] === 0xEF && buffer[1] === 0xBB && buffer[2] === 0xBF) {
|
||||
// UTF-8 byte order mark detected
|
||||
return buffer.toString("utf8", 3);
|
||||
}
|
||||
// Default is UTF-8 with no byte order mark
|
||||
return buffer.toString("utf8");
|
||||
}
|
||||
|
||||
function writeFile(fileName: string, data: string, writeByteOrderMark?: boolean): void {
|
||||
// If a BOM is required, emit one
|
||||
if (writeByteOrderMark) {
|
||||
data = '\uFEFF' + data;
|
||||
}
|
||||
|
||||
_fs.writeFileSync(fileName, data, "utf8");
|
||||
}
|
||||
|
||||
return {
|
||||
args: process.argv.slice(2),
|
||||
newLine: _os.EOL,
|
||||
useCaseSensitiveFileNames: useCaseSensitiveFileNames,
|
||||
write(s: string): void {
|
||||
// 1 is a standard descriptor for stdout
|
||||
_fs.writeSync(1, s);
|
||||
},
|
||||
readFile,
|
||||
writeFile,
|
||||
watchFile: (fileName, callback) => {
|
||||
// watchFile polls a file every 250ms, picking up file notifications.
|
||||
_fs.watchFile(fileName, { persistent: true, interval: 250 }, fileChanged);
|
||||
|
||||
return {
|
||||
close() { _fs.unwatchFile(fileName, fileChanged); }
|
||||
};
|
||||
|
||||
function fileChanged(curr: any, prev: any) {
|
||||
if (+curr.mtime <= +prev.mtime) {
|
||||
return;
|
||||
function writeFile(fileName: string, data: string, writeByteOrderMark?: boolean): void {
|
||||
fileStream.Open();
|
||||
binaryStream.Open();
|
||||
try {
|
||||
// Write characters in UTF-8 encoding
|
||||
fileStream.Charset = "utf-8";
|
||||
fileStream.WriteText(data);
|
||||
// If we don't want the BOM, then skip it by setting the starting location to 3 (size of BOM).
|
||||
// If not, start from position 0, as the BOM will be added automatically when charset==utf8.
|
||||
if (writeByteOrderMark) {
|
||||
fileStream.Position = 0;
|
||||
}
|
||||
|
||||
callback(fileName);
|
||||
};
|
||||
},
|
||||
resolvePath: function (path: string): string {
|
||||
return _path.resolve(path);
|
||||
},
|
||||
fileExists(path: string): boolean {
|
||||
return _fs.existsSync(path);
|
||||
},
|
||||
directoryExists(path: string) {
|
||||
return _fs.existsSync(path) && _fs.statSync(path).isDirectory();
|
||||
},
|
||||
createDirectory(directoryName: string) {
|
||||
if (!this.directoryExists(directoryName)) {
|
||||
_fs.mkdirSync(directoryName);
|
||||
else {
|
||||
fileStream.Position = 3;
|
||||
}
|
||||
fileStream.CopyTo(binaryStream);
|
||||
binaryStream.SaveToFile(fileName, 2 /*overwrite*/);
|
||||
}
|
||||
},
|
||||
getExecutingFilePath() {
|
||||
return __filename;
|
||||
},
|
||||
getCurrentDirectory() {
|
||||
return process.cwd();
|
||||
},
|
||||
getMemoryUsage() {
|
||||
if (global.gc) {
|
||||
global.gc();
|
||||
finally {
|
||||
binaryStream.Close();
|
||||
fileStream.Close();
|
||||
}
|
||||
return process.memoryUsage().heapUsed;
|
||||
},
|
||||
exit(exitCode?: number): void {
|
||||
process.exit(exitCode);
|
||||
}
|
||||
};
|
||||
}
|
||||
if (typeof WScript !== "undefined" && typeof ActiveXObject === "function") {
|
||||
return getWScriptSystem();
|
||||
}
|
||||
else if (typeof module !== "undefined" && module.exports) {
|
||||
return getNodeSystem();
|
||||
}
|
||||
else {
|
||||
return undefined; // Unsupported host
|
||||
}
|
||||
})();
|
||||
|
||||
return {
|
||||
args,
|
||||
newLine: "\r\n",
|
||||
useCaseSensitiveFileNames: false,
|
||||
write(s: string): void {
|
||||
WScript.StdOut.Write(s);
|
||||
},
|
||||
readFile,
|
||||
writeFile,
|
||||
resolvePath(path: string): string {
|
||||
return fso.GetAbsolutePathName(path);
|
||||
},
|
||||
fileExists(path: string): boolean {
|
||||
return fso.FileExists(path);
|
||||
},
|
||||
directoryExists(path: string) {
|
||||
return fso.FolderExists(path);
|
||||
},
|
||||
createDirectory(directoryName: string) {
|
||||
if (!this.directoryExists(directoryName)) {
|
||||
fso.CreateFolder(directoryName);
|
||||
}
|
||||
},
|
||||
getExecutingFilePath() {
|
||||
return WScript.ScriptFullName;
|
||||
},
|
||||
getCurrentDirectory() {
|
||||
return new ActiveXObject("WScript.Shell").CurrentDirectory;
|
||||
},
|
||||
exit(exitCode?: number): void {
|
||||
try {
|
||||
WScript.Quit(exitCode);
|
||||
}
|
||||
catch (e) {
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
function getNodeSystem(): System {
|
||||
var _fs = require("fs");
|
||||
var _path = require("path");
|
||||
var _os = require('os');
|
||||
|
||||
var platform: string = _os.platform();
|
||||
// win32\win64 are case insensitive platforms, MacOS (darwin) by default is also case insensitive
|
||||
var useCaseSensitiveFileNames = platform !== "win32" && platform !== "win64" && platform !== "darwin";
|
||||
|
||||
function readFile(fileName: string, encoding?: string): string {
|
||||
if (!_fs.existsSync(fileName)) {
|
||||
return undefined;
|
||||
}
|
||||
var buffer = _fs.readFileSync(fileName);
|
||||
var len = buffer.length;
|
||||
if (len >= 2 && buffer[0] === 0xFE && buffer[1] === 0xFF) {
|
||||
// Big endian UTF-16 byte order mark detected. Since big endian is not supported by node.js,
|
||||
// flip all byte pairs and treat as little endian.
|
||||
len &= ~1;
|
||||
for (var i = 0; i < len; i += 2) {
|
||||
var temp = buffer[i];
|
||||
buffer[i] = buffer[i + 1];
|
||||
buffer[i + 1] = temp;
|
||||
}
|
||||
return buffer.toString("utf16le", 2);
|
||||
}
|
||||
if (len >= 2 && buffer[0] === 0xFF && buffer[1] === 0xFE) {
|
||||
// Little endian UTF-16 byte order mark detected
|
||||
return buffer.toString("utf16le", 2);
|
||||
}
|
||||
if (len >= 3 && buffer[0] === 0xEF && buffer[1] === 0xBB && buffer[2] === 0xBF) {
|
||||
// UTF-8 byte order mark detected
|
||||
return buffer.toString("utf8", 3);
|
||||
}
|
||||
// Default is UTF-8 with no byte order mark
|
||||
return buffer.toString("utf8");
|
||||
}
|
||||
|
||||
function writeFile(fileName: string, data: string, writeByteOrderMark?: boolean): void {
|
||||
// If a BOM is required, emit one
|
||||
if (writeByteOrderMark) {
|
||||
data = '\uFEFF' + data;
|
||||
}
|
||||
|
||||
_fs.writeFileSync(fileName, data, "utf8");
|
||||
}
|
||||
|
||||
return {
|
||||
args: process.argv.slice(2),
|
||||
newLine: _os.EOL,
|
||||
useCaseSensitiveFileNames: useCaseSensitiveFileNames,
|
||||
write(s: string): void {
|
||||
// 1 is a standard descriptor for stdout
|
||||
_fs.writeSync(1, s);
|
||||
},
|
||||
readFile,
|
||||
writeFile,
|
||||
watchFile: (fileName, callback) => {
|
||||
// watchFile polls a file every 250ms, picking up file notifications.
|
||||
_fs.watchFile(fileName, { persistent: true, interval: 250 }, fileChanged);
|
||||
|
||||
return {
|
||||
close() { _fs.unwatchFile(fileName, fileChanged); }
|
||||
};
|
||||
|
||||
function fileChanged(curr: any, prev: any) {
|
||||
if (+curr.mtime <= +prev.mtime) {
|
||||
return;
|
||||
}
|
||||
|
||||
callback(fileName);
|
||||
};
|
||||
},
|
||||
resolvePath: function (path: string): string {
|
||||
return _path.resolve(path);
|
||||
},
|
||||
fileExists(path: string): boolean {
|
||||
return _fs.existsSync(path);
|
||||
},
|
||||
directoryExists(path: string) {
|
||||
return _fs.existsSync(path) && _fs.statSync(path).isDirectory();
|
||||
},
|
||||
createDirectory(directoryName: string) {
|
||||
if (!this.directoryExists(directoryName)) {
|
||||
_fs.mkdirSync(directoryName);
|
||||
}
|
||||
},
|
||||
getExecutingFilePath() {
|
||||
return __filename;
|
||||
},
|
||||
getCurrentDirectory() {
|
||||
return process.cwd();
|
||||
},
|
||||
getMemoryUsage() {
|
||||
if (global.gc) {
|
||||
global.gc();
|
||||
}
|
||||
return process.memoryUsage().heapUsed;
|
||||
},
|
||||
exit(exitCode?: number): void {
|
||||
process.exit(exitCode);
|
||||
}
|
||||
};
|
||||
}
|
||||
if (typeof WScript !== "undefined" && typeof ActiveXObject === "function") {
|
||||
return getWScriptSystem();
|
||||
}
|
||||
else if (typeof module !== "undefined" && module.exports) {
|
||||
return getNodeSystem();
|
||||
}
|
||||
else {
|
||||
return undefined; // Unsupported host
|
||||
}
|
||||
})();
|
||||
}
|
|
@ -490,4 +490,4 @@ module ts {
|
|||
}
|
||||
}
|
||||
|
||||
ts.executeCommandLine(sys.args);
|
||||
ts.executeCommandLine(ts.sys.args);
|
||||
|
|
|
@ -363,7 +363,7 @@ module FourSlash {
|
|||
this.formatCodeOptions = {
|
||||
IndentSize: 4,
|
||||
TabSize: 4,
|
||||
NewLineCharacter: sys.newLine,
|
||||
NewLineCharacter: ts.sys.newLine,
|
||||
ConvertTabsToSpaces: true,
|
||||
InsertSpaceAfterCommaDelimiter: true,
|
||||
InsertSpaceAfterSemicolonInForStatements: true,
|
||||
|
@ -1747,9 +1747,9 @@ module FourSlash {
|
|||
}
|
||||
|
||||
function jsonMismatchString() {
|
||||
return sys.newLine +
|
||||
"expected: '" + sys.newLine + JSON.stringify(expected, (k,v) => v, 2) + "'" + sys.newLine +
|
||||
"actual: '" + sys.newLine + JSON.stringify(actual, (k, v) => v, 2) + "'";
|
||||
return ts.sys.newLine +
|
||||
"expected: '" + ts.sys.newLine + JSON.stringify(expected, (k,v) => v, 2) + "'" + ts.sys.newLine +
|
||||
"actual: '" + ts.sys.newLine + JSON.stringify(actual, (k, v) => v, 2) + "'";
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2246,7 +2246,7 @@ module FourSlash {
|
|||
{ unitName: fileName, content: content }],
|
||||
(fn, contents) => result = contents,
|
||||
ts.ScriptTarget.Latest,
|
||||
sys.useCaseSensitiveFileNames);
|
||||
ts.sys.useCaseSensitiveFileNames);
|
||||
// TODO (drosen): We need to enforce checking on these tests.
|
||||
var program = ts.createProgram([Harness.Compiler.fourslashFilename, fileName], { out: "fourslashTestOutput.js", noResolve: true }, host);
|
||||
var checker = ts.createTypeChecker(program, /*fullTypeCheckMode*/ true);
|
||||
|
|
|
@ -22,6 +22,9 @@
|
|||
/// <reference path='external\chai.d.ts'/>
|
||||
/// <reference path='sourceMapRecorder.ts'/>
|
||||
|
||||
declare var require: any;
|
||||
declare var process: any;
|
||||
|
||||
// this will work in the browser via browserify
|
||||
var _chai: typeof chai = require('chai');
|
||||
var assert: typeof _chai.assert = _chai.assert;
|
||||
|
@ -41,7 +44,7 @@ module Utils {
|
|||
export function getExecutionEnvironment() {
|
||||
if (typeof WScript !== "undefined" && typeof ActiveXObject === "function") {
|
||||
return ExecutionEnvironment.CScript;
|
||||
} else if (process && (<any>process).execPath && (<any>process).execPath.indexOf("node") !== -1) {
|
||||
} else if (process && process.execPath && process.execPath.indexOf("node") !== -1) {
|
||||
return ExecutionEnvironment.Node;
|
||||
} else {
|
||||
return ExecutionEnvironment.Browser;
|
||||
|
@ -93,7 +96,7 @@ module Utils {
|
|||
}
|
||||
|
||||
try {
|
||||
var content = sys.readFile(Harness.userSpecifiedroot + path);
|
||||
var content = ts.sys.readFile(Harness.userSpecifiedroot + path);
|
||||
}
|
||||
catch (err) {
|
||||
return undefined;
|
||||
|
@ -217,8 +220,8 @@ module Harness {
|
|||
fso = {};
|
||||
}
|
||||
|
||||
export var readFile: typeof IO.readFile = sys.readFile;
|
||||
export var writeFile: typeof IO.writeFile = sys.writeFile;
|
||||
export var readFile: typeof IO.readFile = ts.sys.readFile;
|
||||
export var writeFile: typeof IO.writeFile = ts.sys.writeFile;
|
||||
export var directoryName: typeof IO.directoryName = fso.GetParentFolderName;
|
||||
export var directoryExists: typeof IO.directoryExists = fso.FolderExists;
|
||||
export var fileExists: typeof IO.fileExists = fso.FileExists;
|
||||
|
@ -279,8 +282,8 @@ module Harness {
|
|||
fs = pathModule = {};
|
||||
}
|
||||
|
||||
export var readFile: typeof IO.readFile = sys.readFile;
|
||||
export var writeFile: typeof IO.writeFile = sys.writeFile;
|
||||
export var readFile: typeof IO.readFile = ts.sys.readFile;
|
||||
export var writeFile: typeof IO.writeFile = ts.sys.writeFile;
|
||||
export var fileExists: typeof IO.fileExists = fs.existsSync;
|
||||
export var log: typeof IO.log = console.log;
|
||||
|
||||
|
@ -608,7 +611,7 @@ module Harness {
|
|||
export var fourslashSourceFile: ts.SourceFile;
|
||||
|
||||
export function getCanonicalFileName(fileName: string): string {
|
||||
return sys.useCaseSensitiveFileNames ? fileName : fileName.toLowerCase();
|
||||
return ts.sys.useCaseSensitiveFileNames ? fileName : fileName.toLowerCase();
|
||||
}
|
||||
|
||||
export function createCompilerHost(inputFiles: { unitName: string; content: string; }[],
|
||||
|
@ -632,7 +635,7 @@ module Harness {
|
|||
inputFiles.forEach(register);
|
||||
|
||||
return {
|
||||
getCurrentDirectory: sys.getCurrentDirectory,
|
||||
getCurrentDirectory: ts.sys.getCurrentDirectory,
|
||||
getCancellationToken: (): any => undefined,
|
||||
getSourceFile: (fn, languageVersion) => {
|
||||
if (Object.prototype.hasOwnProperty.call(filemap, getCanonicalFileName(fn))) {
|
||||
|
@ -655,7 +658,7 @@ module Harness {
|
|||
writeFile,
|
||||
getCanonicalFileName,
|
||||
useCaseSensitiveFileNames: () => useCaseSensitiveFileNames,
|
||||
getNewLine: ()=> sys.newLine
|
||||
getNewLine: ()=> ts.sys.newLine
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -725,7 +728,7 @@ module Harness {
|
|||
settingsCallback(null);
|
||||
}
|
||||
|
||||
var useCaseSensitiveFileNames = sys.useCaseSensitiveFileNames;
|
||||
var useCaseSensitiveFileNames = ts.sys.useCaseSensitiveFileNames;
|
||||
this.settings.forEach(setting => {
|
||||
switch (setting.flag.toLowerCase()) {
|
||||
// "filename", "comments", "declaration", "module", "nolib", "sourcemap", "target", "out", "outdir", "noimplicitany", "noresolve"
|
||||
|
@ -803,7 +806,7 @@ module Harness {
|
|||
|
||||
case 'newline':
|
||||
case 'newlines':
|
||||
sys.newLine = setting.value;
|
||||
ts.sys.newLine = setting.value;
|
||||
break;
|
||||
|
||||
case 'comments':
|
||||
|
@ -878,11 +881,11 @@ module Harness {
|
|||
});
|
||||
this.lastErrors = errors;
|
||||
|
||||
var result = new CompilerResult(fileOutputs, errors, program, sys.getCurrentDirectory(), emitResult ? emitResult.sourceMaps : undefined);
|
||||
var result = new CompilerResult(fileOutputs, errors, program, ts.sys.getCurrentDirectory(), emitResult ? emitResult.sourceMaps : undefined);
|
||||
onComplete(result, checker);
|
||||
|
||||
// reset what newline means in case the last test changed it
|
||||
sys.newLine = '\r\n';
|
||||
ts.sys.newLine = '\r\n';
|
||||
return options;
|
||||
}
|
||||
|
||||
|
@ -977,7 +980,7 @@ module Harness {
|
|||
errorOutput += diagnotic.filename + "(" + diagnotic.line + "," + diagnotic.character + "): ";
|
||||
}
|
||||
|
||||
errorOutput += diagnotic.category + " TS" + diagnotic.code + ": " + diagnotic.message + sys.newLine;
|
||||
errorOutput += diagnotic.category + " TS" + diagnotic.code + ": " + diagnotic.message + ts.sys.newLine;
|
||||
});
|
||||
|
||||
return errorOutput;
|
||||
|
@ -1079,7 +1082,7 @@ module Harness {
|
|||
assert.equal(totalErrorsReported + numLibraryDiagnostics, diagnostics.length, 'total number of errors');
|
||||
|
||||
return minimalDiagnosticsToString(diagnostics) +
|
||||
sys.newLine + sys.newLine + outputLines.join('\r\n');
|
||||
ts.sys.newLine + ts.sys.newLine + outputLines.join('\r\n');
|
||||
}
|
||||
|
||||
export function collateOutputs(outputFiles: Harness.Compiler.GeneratedFile[], clean?: (s: string) => string) {
|
||||
|
|
|
@ -60,7 +60,7 @@ class ProjectRunner extends RunnerBase {
|
|||
var testCase: ProjectRunnerTestCase;
|
||||
|
||||
try {
|
||||
var testFileText = sys.readFile(testCaseFileName);
|
||||
var testFileText = ts.sys.readFile(testCaseFileName);
|
||||
}
|
||||
catch (e) {
|
||||
assert(false, "Unable to open testcase file: " + testCaseFileName + ": " + e.message);
|
||||
|
@ -96,7 +96,7 @@ class ProjectRunner extends RunnerBase {
|
|||
}
|
||||
|
||||
function cleanProjectUrl(url: string) {
|
||||
var diskProjectPath = ts.normalizeSlashes(sys.resolvePath(testCase.projectRoot));
|
||||
var diskProjectPath = ts.normalizeSlashes(ts.sys.resolvePath(testCase.projectRoot));
|
||||
var projectRootUrl = "file:///" + diskProjectPath;
|
||||
var normalizedProjectRoot = ts.normalizeSlashes(testCase.projectRoot);
|
||||
diskProjectPath = diskProjectPath.substr(0, diskProjectPath.lastIndexOf(normalizedProjectRoot));
|
||||
|
@ -119,7 +119,7 @@ class ProjectRunner extends RunnerBase {
|
|||
}
|
||||
|
||||
function getCurrentDirectory() {
|
||||
return sys.resolvePath(testCase.projectRoot);
|
||||
return ts.sys.resolvePath(testCase.projectRoot);
|
||||
}
|
||||
|
||||
function compileProjectFiles(moduleKind: ts.ModuleKind, getInputFiles: ()=> string[],
|
||||
|
@ -161,8 +161,8 @@ class ProjectRunner extends RunnerBase {
|
|||
sourceMap: !!testCase.sourceMap,
|
||||
out: testCase.out,
|
||||
outDir: testCase.outDir,
|
||||
mapRoot: testCase.resolveMapRoot && testCase.mapRoot ? sys.resolvePath(testCase.mapRoot) : testCase.mapRoot,
|
||||
sourceRoot: testCase.resolveSourceRoot && testCase.sourceRoot ? sys.resolvePath(testCase.sourceRoot) : testCase.sourceRoot,
|
||||
mapRoot: testCase.resolveMapRoot && testCase.mapRoot ? ts.sys.resolvePath(testCase.mapRoot) : testCase.mapRoot,
|
||||
sourceRoot: testCase.resolveSourceRoot && testCase.sourceRoot ? ts.sys.resolvePath(testCase.sourceRoot) : testCase.sourceRoot,
|
||||
module: moduleKind,
|
||||
noResolve: testCase.noResolve
|
||||
};
|
||||
|
@ -190,8 +190,8 @@ class ProjectRunner extends RunnerBase {
|
|||
writeFile,
|
||||
getCurrentDirectory,
|
||||
getCanonicalFileName: Harness.Compiler.getCanonicalFileName,
|
||||
useCaseSensitiveFileNames: () => sys.useCaseSensitiveFileNames,
|
||||
getNewLine: () => sys.newLine
|
||||
useCaseSensitiveFileNames: () => ts.sys.useCaseSensitiveFileNames,
|
||||
getNewLine: () => ts.sys.newLine
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -213,7 +213,7 @@ class ProjectRunner extends RunnerBase {
|
|||
|
||||
function getSourceFileText(filename: string): string {
|
||||
try {
|
||||
var text = sys.readFile(ts.isRootedDiskPath(filename)
|
||||
var text = ts.sys.readFile(ts.isRootedDiskPath(filename)
|
||||
? filename
|
||||
: ts.normalizeSlashes(testCase.projectRoot) + "/" + ts.normalizeSlashes(filename));
|
||||
}
|
||||
|
@ -260,14 +260,14 @@ class ProjectRunner extends RunnerBase {
|
|||
// Actual writing of file as in tc.ts
|
||||
function ensureDirectoryStructure(directoryname: string) {
|
||||
if (directoryname) {
|
||||
if (!sys.directoryExists(directoryname)) {
|
||||
if (!ts.sys.directoryExists(directoryname)) {
|
||||
ensureDirectoryStructure(ts.getDirectoryPath(directoryname));
|
||||
sys.createDirectory(directoryname);
|
||||
ts.sys.createDirectory(directoryname);
|
||||
}
|
||||
}
|
||||
}
|
||||
ensureDirectoryStructure(ts.getDirectoryPath(ts.normalizePath(outputFilePath)));
|
||||
sys.writeFile(outputFilePath, data, writeByteOrderMark);
|
||||
ts.sys.writeFile(outputFilePath, data, writeByteOrderMark);
|
||||
|
||||
outputFiles.push({ emittedFileName: filename, code: data, fileName: diskRelativeName, writeByteOrderMark: writeByteOrderMark });
|
||||
}
|
||||
|
@ -374,7 +374,7 @@ class ProjectRunner extends RunnerBase {
|
|||
it('Baseline of emitted result (' + moduleNameToString(compilerResult.moduleKind) + '): ' + testCaseFileName, () => {
|
||||
Harness.Baseline.runBaseline('Baseline of emitted result (' + moduleNameToString(compilerResult.moduleKind) + '): ' + testCaseFileName, getBaselineFolder(compilerResult.moduleKind) + outputFile.fileName, () => {
|
||||
try {
|
||||
return sys.readFile(getProjectOutputFolder(outputFile.fileName, compilerResult.moduleKind));
|
||||
return ts.sys.readFile(getProjectOutputFolder(outputFile.fileName, compilerResult.moduleKind));
|
||||
}
|
||||
catch (e) {
|
||||
return undefined;
|
||||
|
|
|
@ -94,6 +94,6 @@ if (runners.length === 0) {
|
|||
//runners.push(new GeneratedFourslashRunner());
|
||||
}
|
||||
|
||||
sys.newLine = '\r\n';
|
||||
ts.sys.newLine = '\r\n';
|
||||
|
||||
runTests(runners);
|
||||
|
|
|
@ -6,17 +6,17 @@
|
|||
|
||||
module RWC {
|
||||
function runWithIOLog(ioLog: IOLog, fn: () => void) {
|
||||
var oldSys = sys;
|
||||
var oldSys = ts.sys;
|
||||
|
||||
var wrappedSys = Playback.wrapSystem(sys);
|
||||
var wrappedSys = Playback.wrapSystem(ts.sys);
|
||||
wrappedSys.startReplayFromData(ioLog);
|
||||
sys = wrappedSys;
|
||||
ts.sys = wrappedSys;
|
||||
|
||||
try {
|
||||
fn();
|
||||
} finally {
|
||||
wrappedSys.endReplay();
|
||||
sys = oldSys;
|
||||
ts.sys = oldSys;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -74,7 +74,7 @@ module RWC {
|
|||
}
|
||||
|
||||
ts.forEach(ioLog.filesRead, fileRead => {
|
||||
var resolvedPath = ts.normalizeSlashes(sys.resolvePath(fileRead.path));
|
||||
var resolvedPath = ts.normalizeSlashes(ts.sys.resolvePath(fileRead.path));
|
||||
var inInputList = ts.forEach(inputFiles, inputFile=> inputFile.unitName === resolvedPath);
|
||||
if (!inInputList) {
|
||||
// Add the file to other files
|
||||
|
@ -92,9 +92,9 @@ module RWC {
|
|||
});
|
||||
|
||||
function getHarnessCompilerInputUnit(fileName: string) {
|
||||
var unitName = ts.normalizeSlashes(sys.resolvePath(fileName));
|
||||
var unitName = ts.normalizeSlashes(ts.sys.resolvePath(fileName));
|
||||
try {
|
||||
var content = sys.readFile(unitName);
|
||||
var content = ts.sys.readFile(unitName);
|
||||
}
|
||||
catch (e) {
|
||||
// Leave content undefined.
|
||||
|
@ -160,7 +160,7 @@ module RWC {
|
|||
}
|
||||
|
||||
return Harness.Compiler.minimalDiagnosticsToString(declFileCompilationResult.declResult.errors) +
|
||||
sys.newLine + sys.newLine +
|
||||
ts.sys.newLine + ts.sys.newLine +
|
||||
Harness.Compiler.getErrorBaseline(declFileCompilationResult.declInputFiles.concat(declFileCompilationResult.declOtherFiles), declFileCompilationResult.declResult.errors);
|
||||
}, false, baselineOpts);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue