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);

View File

@ -7,7 +7,7 @@
*/
import * as ts from 'typescript';
import {Tsc, tsc as pureTsc} from '../src/tsc';
import {Tsc} from '../src/tsc';
import {VinylFile} from '../src/vinyl_file';
describe('options parsing', () => {
@ -41,7 +41,7 @@ describe('options parsing', () => {
});
it('should combine all options into ngOptions from vinyl like object', () => {
const {parsed, ngOptions} = pureTsc.readConfiguration(config as VinylFile, 'basePath');
const {parsed, ngOptions} = tsc.readConfiguration(config as VinylFile, 'basePath');
expect(ngOptions).toEqual({
genDir: 'basePath',

View File

@ -89,8 +89,8 @@ export class MockIdentifier extends MockNode implements ts.Identifier {
public _expressionBrand: any;
constructor(
public name: string, kind: ts.SyntaxKind = ts.SyntaxKind.Identifier, flags: ts.NodeFlags = 0,
pos: number = 0, end: number = 0) {
public name: string, public kind: ts.SyntaxKind.Identifier = ts.SyntaxKind.Identifier,
flags: ts.NodeFlags = 0, pos: number = 0, end: number = 0) {
super(kind, flags, pos, end);
this.text = name;
}
@ -100,7 +100,8 @@ export class MockVariableDeclaration extends MockNode implements ts.VariableDecl
public _declarationBrand: any;
constructor(
public name: ts.Identifier, kind: ts.SyntaxKind = ts.SyntaxKind.VariableDeclaration,
public name: ts.Identifier,
public kind: ts.SyntaxKind.VariableDeclaration = ts.SyntaxKind.VariableDeclaration,
flags: ts.NodeFlags = 0, pos: number = 0, end: number = 0) {
super(kind, flags, pos, end);
}
@ -119,6 +120,7 @@ export class MockSymbol implements ts.Symbol {
getName(): string { return this.name; }
getDeclarations(): ts.Declaration[] { return [this.node]; }
getDocumentationComment(): ts.SymbolDisplayPart[] { return []; }
getJsDocTags(): ts.JSDocTagInfo[]{return []};
static of (name: string): MockSymbol { return new MockSymbol(name); }
}