Skip to content

Commit ef32e6b

Browse files
alexeaglemhevery
authored andcommitted
fix: build and test fixes for TS 2.1 (angular#13294)
1 parent 5c431ce commit ef32e6b

File tree

21 files changed

+66
-39
lines changed

21 files changed

+66
-39
lines changed

integration/hello_world__closure/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"google-closure-compiler": "^20161201.0.0",
1414
"rxjs": "file:../../node_modules/rxjs",
1515
"source-map-explorer": "^1.3.3",
16-
"typescript": "~2.0",
16+
"typescript": "~2.1",
1717
"zone.js": "^0.7.6"
1818
},
1919
"devDependencies": {

integration/rxjs.tsconfig.json

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@
55
"annotateForClosureCompiler": true
66
},
77

8-
/**
9-
* Remaining options are copied from
10-
* https://github.com/ReactiveX/rxjs/blob/cba74135810a8e6bbe0b3c7732e8544b0869589e/tsconfig.json
11-
* TODO(alexeagle): use "extends" instead when Angular is on TS 2.1
12-
*/
138
"compilerOptions": {
9+
"types": [],
10+
/**
11+
* Remaining options are copied from
12+
* https://github.com/ReactiveX/rxjs/blob/cba74135810a8e6bbe0b3c7732e8544b0869589e/tsconfig.json
13+
* TODO(alexeagle): use "extends" instead when Angular is on TS 2.1
14+
*/
1415
"removeComments": false,
1516
"preserveConstEnums": true,
1617
"sourceMap": true,

integration/typings_test_ts20/package.json renamed to integration/typings_test_ts21/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"@types/jasmine": "^2.5.41",
1919
"rxjs": "file:../../node_modules/rxjs",
2020
"source-map-explorer": "^1.3.3",
21-
"typescript": "~2.0",
21+
"typescript": "~2.1",
2222
"zone.js": "^0.7.6"
2323
},
2424
"scripts": {

modules/@angular/benchpress/src/webdriver/chrome_driver_extension.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ export class ChromeDriverExtension extends WebDriverExtension {
6868
.then((_) => this._driver.logs('performance'))
6969
.then((entries) => {
7070
const events: PerfLogEvent[] = [];
71-
entries.forEach(entry => {
71+
entries.forEach((entry: any) => {
7272
const message = JSON.parse(entry['message'])['message'];
7373
if (message['method'] === 'Tracing.dataCollected') {
7474
events.push(message['params']);

modules/@angular/benchpress/src/webdriver/ios_driver_extension.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export class IOsDriverExtension extends WebDriverExtension {
4040
.then((_) => this._driver.logs('performance'))
4141
.then((entries) => {
4242
const records: any[] = [];
43-
entries.forEach(entry => {
43+
entries.forEach((entry: any) => {
4444
const message = JSON.parse(entry['message'])['message'];
4545
if (message['method'] === 'Timeline.eventRecorded') {
4646
records.push(message['params']['record']);

modules/@angular/compiler-cli/test/main_spec.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,8 @@ describe('compiler-cli', () => {
154154
expect(mockConsole.error)
155155
.toHaveBeenCalledWith(
156156
'Error at ' + path.join(basePath, 'test.ts') +
157-
':3:7: Cannot invoke an expression whose type lacks a call signature.');
157+
':3:7: Cannot invoke an expression whose type lacks a call signature. ' +
158+
'Type \'String\' has no compatible call signatures.');
158159
expect(mockConsole.error).not.toHaveBeenCalledWith('Compilation failed');
159160
expect(exitCode).toEqual(1);
160161
done();

modules/@angular/compiler/src/expression_parser/lexer.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,8 @@ class _Scanner {
294294
buffer += input.substring(marker, this.index);
295295
this.advance();
296296
let unescapedCode: number;
297+
// Workaround for TS2.1-introduced type strictness
298+
this.peek = this.peek;
297299
if (this.peek == chars.$u) {
298300
// 4 character hex code for unicode character.
299301
const hex: string = input.substring(this.index + 1, this.index + 5);

modules/@angular/core/src/reflection/reflection_capabilities.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import {GetterFn, MethodFn, SetterFn} from './types';
1616
* Attention: This regex has to hold even if the code is minified!
1717
*/
1818
export const DELEGATE_CTOR =
19-
/^function\s+\S+\(\)\s*{\s*("use strict";)?\s*(return\s+)?\S+\.apply\(this,\s*arguments\)/;
19+
/^function\s+\S+\(\)\s*{\s*("use strict";)?\s*(return\s+)?(\S+\s+!==\s+null\s+&&\s+)?\S+\.apply\(this,\s*arguments\)/;
2020

2121
export class ReflectionCapabilities implements PlatformReflectionCapabilities {
2222
private _reflect: any;

modules/@angular/examples/upgrade/static/ts/module.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ class Ng2AppModule {
115115
// #docregion Angular 1 Stuff
116116
// #docregion ng1-module
117117
// This Angular 1 module represents the AngularJS pieces of the application
118+
declare var angular: ng.IAngularStatic;
118119
const ng1AppModule = angular.module('ng1AppModule', []);
119120
// #enddocregion
120121

modules/@angular/language-service/src/ts_plugin.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,12 @@ export function create(info: any /* ts.server.PluginCreateInfo */): ts.LanguageS
5454
const results = ls.getCompletionsAt(fileName, position);
5555
if (results && results.length) {
5656
if (base === undefined) {
57-
base = {isMemberCompletion: false, isNewIdentifierLocation: false, entries: []};
57+
base = {
58+
isGlobalCompletion: false,
59+
isMemberCompletion: false,
60+
isNewIdentifierLocation: false,
61+
entries: []
62+
};
5863
}
5964
for (const entry of results) {
6065
base.entries.push(completionToEntry(entry));
@@ -78,7 +83,8 @@ export function create(info: any /* ts.server.PluginCreateInfo */): ts.LanguageS
7883
documentation: [],
7984
kind: 'angular',
8085
kindModifiers: 'what does this do?',
81-
textSpan: {start: ours.span.start, length: ours.span.end - ours.span.start}
86+
textSpan: {start: ours.span.start, length: ours.span.end - ours.span.start},
87+
tags: [],
8288
};
8389
}
8490
});

modules/@angular/router/src/apply_redirects.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import {EmptyError} from 'rxjs/util/EmptyError';
2020

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

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

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

modules/@angular/router/src/router.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import {DetachedRouteHandle, DetachedRouteHandleInternal, RouteReuseStrategy} fr
3131
import {LoadedRouterConfig, RouterConfigLoader} from './router_config_loader';
3232
import {RouterOutletMap} from './router_outlet_map';
3333
import {ActivatedRoute, ActivatedRouteSnapshot, RouterState, RouterStateSnapshot, advanceActivatedRoute, createEmptyState, equalParamsAndUrlSegments, inheritedParamsDataResolve} from './router_state';
34-
import {NavigationCancelingError, PRIMARY_OUTLET, Params} from './shared';
34+
import {PRIMARY_OUTLET, Params, isNavigationCancelingError} from './shared';
3535
import {DefaultUrlHandlingStrategy, UrlHandlingStrategy} from './url_handling_strategy';
3636
import {UrlSerializer, UrlTree, containsTree, createEmptyUrlTree} from './url_tree';
3737
import {andObservables, forEach, merge, waitForMap, wrapIntoObservable} from './utils/collection';
@@ -802,7 +802,7 @@ export class Router {
802802
}
803803
},
804804
(e: any) => {
805-
if (e instanceof NavigationCancelingError) {
805+
if (isNavigationCancelingError(e)) {
806806
this.resetUrlToCurrentUrlTree();
807807
this.navigated = true;
808808
this.routerEvents.next(

modules/@angular/router/src/shared.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,16 @@ export type Params = {
2727
[key: string]: any
2828
};
2929

30-
export class NavigationCancelingError extends Error {
31-
public stack: any;
32-
constructor(public message: string) {
33-
super(message);
34-
this.stack = (<any>new Error(message)).stack;
35-
}
36-
toString(): string { return this.message; }
30+
const NAVIGATION_CANCELING_ERROR = 'ngNavigationCancelingError';
31+
32+
export function navigationCancelingError(message: string) {
33+
const error = Error('NavigationCancelingError: ' + message);
34+
(error as any)[NAVIGATION_CANCELING_ERROR] = true;
35+
return error;
36+
}
37+
38+
export function isNavigationCancelingError(error: Error) {
39+
return (error as any)[NAVIGATION_CANCELING_ERROR];
3740
}
3841

3942
export function defaultUrlMatcher(

modules/@angular/router/test/apply_redirects.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ describe('applyRedirects', () => {
214214
() => { throw 'Should not reach'; },
215215
(e) => {
216216
expect(e.message).toEqual(
217-
`Cannot load children because the guard of the route "path: 'a'" returned false`);
217+
`NavigationCancelingError: Cannot load children because the guard of the route "path: 'a'" returned false`);
218218
});
219219
});
220220

tools/@angular/tsc-wrapped/src/main.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ export function main(
8787
};
8888

8989
const tsickleHost: tsickle.TsickleHost = {
90-
shouldSkipTsickleProcessing: (fileName) => false,
90+
shouldSkipTsickleProcessing: (fileName) => /\.d\.ts$/.test(fileName),
9191
pathToModuleName: (context, importPath) => '',
9292
shouldIgnoreWarningsForPath: (filePath) => false,
9393
fileNameToModuleId: (fileName) => fileName,

tools/@angular/tsc-wrapped/src/tsc.ts

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,27 @@ export class UserError extends Error {
3030
private _nativeError: Error;
3131

3232
constructor(message: string) {
33-
// Errors don't use current this, instead they create a new instance.
34-
// We have to do forward all of our api to the nativeInstance.
35-
const nativeError = super(message) as any as Error;
33+
super(message);
34+
// Required for TS 2.1, see
35+
// https://github.com/Microsoft/TypeScript/wiki/Breaking-Changes#extending-built-ins-like-error-array-and-map-may-no-longer-work
36+
Object.setPrototypeOf(this, UserError.prototype);
37+
38+
const nativeError = new Error(message) as any as Error;
3639
this._nativeError = nativeError;
3740
}
3841

3942
get message() { return this._nativeError.message; }
40-
set message(message) { this._nativeError.message = message; }
41-
get name() { return 'UserError'; }
43+
set message(message) {
44+
if (this._nativeError) this._nativeError.message = message;
45+
}
46+
get name() { return this._nativeError.name; }
47+
set name(name) {
48+
if (this._nativeError) this._nativeError.name = name;
49+
}
4250
get stack() { return (this._nativeError as any).stack; }
43-
set stack(value) { (this._nativeError as any).stack = value; }
51+
set stack(value) {
52+
if (this._nativeError) (this._nativeError as any).stack = value;
53+
}
4454
toString() { return this._nativeError.toString(); }
4555
}
4656

@@ -133,7 +143,8 @@ export class Tsc implements CompilerInterface {
133143
const host = {
134144
useCaseSensitiveFileNames: true,
135145
fileExists: existsSync,
136-
readDirectory: this.readDirectory
146+
readDirectory: this.readDirectory,
147+
readFile: ts.sys.readFile
137148
};
138149
this.parsed = ts.parseJsonConfigFileContent(config, host, basePath, existingOptions);
139150

tools/@angular/tsc-wrapped/test/tsc.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*/
88

99
import * as ts from 'typescript';
10-
import {Tsc, tsc as pureTsc} from '../src/tsc';
10+
import {Tsc} from '../src/tsc';
1111
import {VinylFile} from '../src/vinyl_file';
1212

1313
describe('options parsing', () => {
@@ -41,7 +41,7 @@ describe('options parsing', () => {
4141
});
4242

4343
it('should combine all options into ngOptions from vinyl like object', () => {
44-
const {parsed, ngOptions} = pureTsc.readConfiguration(config as VinylFile, 'basePath');
44+
const {parsed, ngOptions} = tsc.readConfiguration(config as VinylFile, 'basePath');
4545

4646
expect(ngOptions).toEqual({
4747
genDir: 'basePath',

tools/@angular/tsc-wrapped/test/typescript.mocks.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,8 @@ export class MockIdentifier extends MockNode implements ts.Identifier {
8989
public _expressionBrand: any;
9090

9191
constructor(
92-
public name: string, kind: ts.SyntaxKind = ts.SyntaxKind.Identifier, flags: ts.NodeFlags = 0,
93-
pos: number = 0, end: number = 0) {
92+
public name: string, public kind: ts.SyntaxKind.Identifier = ts.SyntaxKind.Identifier,
93+
flags: ts.NodeFlags = 0, pos: number = 0, end: number = 0) {
9494
super(kind, flags, pos, end);
9595
this.text = name;
9696
}
@@ -100,7 +100,8 @@ export class MockVariableDeclaration extends MockNode implements ts.VariableDecl
100100
public _declarationBrand: any;
101101

102102
constructor(
103-
public name: ts.Identifier, kind: ts.SyntaxKind = ts.SyntaxKind.VariableDeclaration,
103+
public name: ts.Identifier,
104+
public kind: ts.SyntaxKind.VariableDeclaration = ts.SyntaxKind.VariableDeclaration,
104105
flags: ts.NodeFlags = 0, pos: number = 0, end: number = 0) {
105106
super(kind, flags, pos, end);
106107
}
@@ -119,6 +120,7 @@ export class MockSymbol implements ts.Symbol {
119120
getName(): string { return this.name; }
120121
getDeclarations(): ts.Declaration[] { return [this.node]; }
121122
getDocumentationComment(): ts.SymbolDisplayPart[] { return []; }
123+
getJsDocTags(): ts.JSDocTagInfo[]{return []};
122124

123125
static of (name: string): MockSymbol { return new MockSymbol(name); }
124126
}

tools/tslint/requireInternalWithUnderscoreRule.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class TypedefWalker extends RuleWalker {
3737

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

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

0 commit comments

Comments
 (0)