fix: build and test fixes for TS 2.1 (#13294)

This commit is contained in:
Alex Eagle
2017-01-24 09:05:34 -08:00
committed by Miško Hevery
parent 5c431cee02
commit ef32e6b0d0
21 changed files with 66 additions and 39 deletions

View File

@ -87,7 +87,7 @@ export function main(
};
const tsickleHost: tsickle.TsickleHost = {
shouldSkipTsickleProcessing: (fileName) => false,
shouldSkipTsickleProcessing: (fileName) => /\.d\.ts$/.test(fileName),
pathToModuleName: (context, importPath) => '',
shouldIgnoreWarningsForPath: (filePath) => false,
fileNameToModuleId: (fileName) => fileName,

View File

@ -30,17 +30,27 @@ export class UserError extends Error {
private _nativeError: Error;
constructor(message: string) {
// Errors don't use current this, instead they create a new instance.
// We have to do forward all of our api to the nativeInstance.
const nativeError = super(message) as any as Error;
super(message);
// Required for TS 2.1, see
// https://github.com/Microsoft/TypeScript/wiki/Breaking-Changes#extending-built-ins-like-error-array-and-map-may-no-longer-work
Object.setPrototypeOf(this, UserError.prototype);
const nativeError = new Error(message) as any as Error;
this._nativeError = nativeError;
}
get message() { return this._nativeError.message; }
set message(message) { this._nativeError.message = message; }
get name() { return 'UserError'; }
set message(message) {
if (this._nativeError) this._nativeError.message = message;
}
get name() { return this._nativeError.name; }
set name(name) {
if (this._nativeError) this._nativeError.name = name;
}
get stack() { return (this._nativeError as any).stack; }
set stack(value) { (this._nativeError as any).stack = value; }
set stack(value) {
if (this._nativeError) (this._nativeError as any).stack = value;
}
toString() { return this._nativeError.toString(); }
}
@ -133,7 +143,8 @@ export class Tsc implements CompilerInterface {
const host = {
useCaseSensitiveFileNames: true,
fileExists: existsSync,
readDirectory: this.readDirectory
readDirectory: this.readDirectory,
readFile: ts.sys.readFile
};
this.parsed = ts.parseJsonConfigFileContent(config, host, basePath, existingOptions);