Skip to content

Commit

Permalink
fix: build and test fixes for TS 2.1 (#13294)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexeagle authored and mhevery committed Feb 8, 2017
1 parent 5c431ce commit ef32e6b
Show file tree
Hide file tree
Showing 21 changed files with 66 additions and 39 deletions.
2 changes: 1 addition & 1 deletion integration/hello_world__closure/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"google-closure-compiler": "^20161201.0.0",
"rxjs": "file:../../node_modules/rxjs",
"source-map-explorer": "^1.3.3",
"typescript": "~2.0",
"typescript": "~2.1",
"zone.js": "^0.7.6"
},
"devDependencies": {
Expand Down
11 changes: 6 additions & 5 deletions integration/rxjs.tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@
"annotateForClosureCompiler": true
},

/**
* Remaining options are copied from
* https://github.com/ReactiveX/rxjs/blob/cba74135810a8e6bbe0b3c7732e8544b0869589e/tsconfig.json
* TODO(alexeagle): use "extends" instead when Angular is on TS 2.1
*/
"compilerOptions": {
"types": [],
/**
* Remaining options are copied from
* https://github.com/ReactiveX/rxjs/blob/cba74135810a8e6bbe0b3c7732e8544b0869589e/tsconfig.json
* TODO(alexeagle): use "extends" instead when Angular is on TS 2.1
*/
"removeComments": false,
"preserveConstEnums": true,
"sourceMap": true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"@types/jasmine": "^2.5.41",
"rxjs": "file:../../node_modules/rxjs",
"source-map-explorer": "^1.3.3",
"typescript": "~2.0",
"typescript": "~2.1",
"zone.js": "^0.7.6"
},
"scripts": {
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export class ChromeDriverExtension extends WebDriverExtension {
.then((_) => this._driver.logs('performance'))
.then((entries) => {
const events: PerfLogEvent[] = [];
entries.forEach(entry => {
entries.forEach((entry: any) => {
const message = JSON.parse(entry['message'])['message'];
if (message['method'] === 'Tracing.dataCollected') {
events.push(message['params']);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export class IOsDriverExtension extends WebDriverExtension {
.then((_) => this._driver.logs('performance'))
.then((entries) => {
const records: any[] = [];
entries.forEach(entry => {
entries.forEach((entry: any) => {
const message = JSON.parse(entry['message'])['message'];
if (message['method'] === 'Timeline.eventRecorded') {
records.push(message['params']['record']);
Expand Down
3 changes: 2 additions & 1 deletion modules/@angular/compiler-cli/test/main_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,8 @@ describe('compiler-cli', () => {
expect(mockConsole.error)
.toHaveBeenCalledWith(
'Error at ' + path.join(basePath, 'test.ts') +
':3:7: Cannot invoke an expression whose type lacks a call signature.');
':3:7: Cannot invoke an expression whose type lacks a call signature. ' +
'Type \'String\' has no compatible call signatures.');
expect(mockConsole.error).not.toHaveBeenCalledWith('Compilation failed');
expect(exitCode).toEqual(1);
done();
Expand Down
2 changes: 2 additions & 0 deletions modules/@angular/compiler/src/expression_parser/lexer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,8 @@ class _Scanner {
buffer += input.substring(marker, this.index);
this.advance();
let unescapedCode: number;
// Workaround for TS2.1-introduced type strictness
this.peek = this.peek;
if (this.peek == chars.$u) {
// 4 character hex code for unicode character.
const hex: string = input.substring(this.index + 1, this.index + 5);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {GetterFn, MethodFn, SetterFn} from './types';
* Attention: This regex has to hold even if the code is minified!
*/
export const DELEGATE_CTOR =
/^function\s+\S+\(\)\s*{\s*("use strict";)?\s*(return\s+)?\S+\.apply\(this,\s*arguments\)/;
/^function\s+\S+\(\)\s*{\s*("use strict";)?\s*(return\s+)?(\S+\s+!==\s+null\s+&&\s+)?\S+\.apply\(this,\s*arguments\)/;

export class ReflectionCapabilities implements PlatformReflectionCapabilities {
private _reflect: any;
Expand Down
1 change: 1 addition & 0 deletions modules/@angular/examples/upgrade/static/ts/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ class Ng2AppModule {
// #docregion Angular 1 Stuff
// #docregion ng1-module
// This Angular 1 module represents the AngularJS pieces of the application
declare var angular: ng.IAngularStatic;
const ng1AppModule = angular.module('ng1AppModule', []);
// #enddocregion

Expand Down
10 changes: 8 additions & 2 deletions modules/@angular/language-service/src/ts_plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,12 @@ export function create(info: any /* ts.server.PluginCreateInfo */): ts.LanguageS
const results = ls.getCompletionsAt(fileName, position);
if (results && results.length) {
if (base === undefined) {
base = {isMemberCompletion: false, isNewIdentifierLocation: false, entries: []};
base = {
isGlobalCompletion: false,
isMemberCompletion: false,
isNewIdentifierLocation: false,
entries: []
};
}
for (const entry of results) {
base.entries.push(completionToEntry(entry));
Expand All @@ -78,7 +83,8 @@ export function create(info: any /* ts.server.PluginCreateInfo */): ts.LanguageS
documentation: [],
kind: 'angular',
kindModifiers: 'what does this do?',
textSpan: {start: ours.span.start, length: ours.span.end - ours.span.start}
textSpan: {start: ours.span.start, length: ours.span.end - ours.span.start},
tags: [],
};
}
});
Expand Down
4 changes: 2 additions & 2 deletions modules/@angular/router/src/apply_redirects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {EmptyError} from 'rxjs/util/EmptyError';

import {Route, Routes} from './config';
import {LoadedRouterConfig, RouterConfigLoader} from './router_config_loader';
import {NavigationCancelingError, PRIMARY_OUTLET, Params, defaultUrlMatcher} from './shared';
import {PRIMARY_OUTLET, Params, defaultUrlMatcher, navigationCancelingError} from './shared';
import {UrlSegment, UrlSegmentGroup, UrlSerializer, UrlTree} from './url_tree';
import {andObservables, forEach, merge, waitForMap, wrapIntoObservable} from './utils/collection';

Expand Down Expand Up @@ -50,7 +50,7 @@ function namedOutletsRedirect(redirectTo: string): Observable<any> {

function canLoadFails(route: Route): Observable<LoadedRouterConfig> {
return new Observable<LoadedRouterConfig>(
(obs: Observer<LoadedRouterConfig>) => obs.error(new NavigationCancelingError(
(obs: Observer<LoadedRouterConfig>) => obs.error(navigationCancelingError(
`Cannot load children because the guard of the route "path: '${route.path}'" returned false`)));
}

Expand Down
4 changes: 2 additions & 2 deletions modules/@angular/router/src/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import {DetachedRouteHandle, DetachedRouteHandleInternal, RouteReuseStrategy} fr
import {LoadedRouterConfig, RouterConfigLoader} from './router_config_loader';
import {RouterOutletMap} from './router_outlet_map';
import {ActivatedRoute, ActivatedRouteSnapshot, RouterState, RouterStateSnapshot, advanceActivatedRoute, createEmptyState, equalParamsAndUrlSegments, inheritedParamsDataResolve} from './router_state';
import {NavigationCancelingError, PRIMARY_OUTLET, Params} from './shared';
import {PRIMARY_OUTLET, Params, isNavigationCancelingError} from './shared';
import {DefaultUrlHandlingStrategy, UrlHandlingStrategy} from './url_handling_strategy';
import {UrlSerializer, UrlTree, containsTree, createEmptyUrlTree} from './url_tree';
import {andObservables, forEach, merge, waitForMap, wrapIntoObservable} from './utils/collection';
Expand Down Expand Up @@ -802,7 +802,7 @@ export class Router {
}
},
(e: any) => {
if (e instanceof NavigationCancelingError) {
if (isNavigationCancelingError(e)) {
this.resetUrlToCurrentUrlTree();
this.navigated = true;
this.routerEvents.next(
Expand Down
17 changes: 10 additions & 7 deletions modules/@angular/router/src/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,16 @@ export type Params = {
[key: string]: any
};

export class NavigationCancelingError extends Error {
public stack: any;
constructor(public message: string) {
super(message);
this.stack = (<any>new Error(message)).stack;
}
toString(): string { return this.message; }
const NAVIGATION_CANCELING_ERROR = 'ngNavigationCancelingError';

export function navigationCancelingError(message: string) {
const error = Error('NavigationCancelingError: ' + message);
(error as any)[NAVIGATION_CANCELING_ERROR] = true;
return error;
}

export function isNavigationCancelingError(error: Error) {
return (error as any)[NAVIGATION_CANCELING_ERROR];
}

export function defaultUrlMatcher(
Expand Down
2 changes: 1 addition & 1 deletion modules/@angular/router/test/apply_redirects.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ describe('applyRedirects', () => {
() => { throw 'Should not reach'; },
(e) => {
expect(e.message).toEqual(
`Cannot load children because the guard of the route "path: 'a'" returned false`);
`NavigationCancelingError: Cannot load children because the guard of the route "path: 'a'" returned false`);
});
});

Expand Down
2 changes: 1 addition & 1 deletion tools/@angular/tsc-wrapped/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
25 changes: 18 additions & 7 deletions tools/@angular/tsc-wrapped/src/tsc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(); }
}

Expand Down Expand Up @@ -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);

Expand Down
4 changes: 2 additions & 2 deletions tools/@angular/tsc-wrapped/test/tsc.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down Expand Up @@ -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',
Expand Down
8 changes: 5 additions & 3 deletions tools/@angular/tsc-wrapped/test/typescript.mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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);
}
Expand All @@ -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); }
}
Expand Down
2 changes: 1 addition & 1 deletion tools/tslint/requireInternalWithUnderscoreRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class TypedefWalker extends RuleWalker {

private assertInternalAnnotationPresent(node: ts.Declaration) {
if (node.name.getText().charAt(0) !== '_') return;
if (node.modifiers && node.modifiers.flags & ts.NodeFlags.Private) return;
if (ts.getCombinedModifierFlags(node) & ts.ModifierFlags.Private) return;

const ranges = ts.getLeadingCommentRanges(this.getSourceFile().text, node.pos);
if (ranges) {
Expand Down

0 comments on commit ef32e6b

Please sign in to comment.