Skip to content

Commit e913d99

Browse files
committed
chore(typings): restrict Angular to es5+collections+promise
1 parent d204887 commit e913d99

File tree

5 files changed

+81
-14
lines changed

5 files changed

+81
-14
lines changed

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

+8-7
Original file line numberDiff line numberDiff line change
@@ -214,14 +214,15 @@ function findPosParam(
214214
}
215215

216216
function findOrCreatePath(part: string, paths: UrlPathWithParams[]): UrlPathWithParams {
217-
const matchingIndex = paths.findIndex(s => s.path === part);
218-
if (matchingIndex > -1) {
219-
const r = paths[matchingIndex];
220-
paths.splice(matchingIndex);
221-
return r;
222-
} else {
223-
return new UrlPathWithParams(part, {});
217+
let idx = 0;
218+
for (const s of paths) {
219+
if (s.path === part) {
220+
paths.splice(idx);
221+
return s;
222+
}
223+
idx++;
224224
}
225+
return new UrlPathWithParams(part, {});
225226
}
226227

227228

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

+5-6
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,12 @@ function createNode(curr: TreeNode<ActivatedRouteSnapshot>, prevState?: TreeNode
3737
function createOrReuseChildren(
3838
curr: TreeNode<ActivatedRouteSnapshot>, prevState: TreeNode<ActivatedRoute>) {
3939
return curr.children.map(child => {
40-
const index =
41-
prevState.children.findIndex(p => equalRouteSnapshots(p.value.snapshot, child.value));
42-
if (index >= 0) {
43-
return createNode(child, prevState.children[index]);
44-
} else {
45-
return createNode(child);
40+
for (const p of prevState.children) {
41+
if (equalRouteSnapshots(p.value.snapshot, child.value)) {
42+
return createNode(child, p);
43+
}
4644
}
45+
return createNode(child);
4746
});
4847
}
4948

modules/es6-subset.d.ts

+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
2+
/**
3+
* Subset of lib.es2015.core.d.ts typings.
4+
* Angular should not require use of ES6 runtime but some API usages are already present.
5+
* See https://github.com/angular/angular/issues/5242
6+
* TODO(alexeagle): remove methods below which may not be present in targeted browser
7+
*/
8+
9+
interface String {
10+
/**
11+
* Returns true if the sequence of elements of searchString converted to a String is the
12+
* same as the corresponding elements of this object (converted to a String) starting at
13+
* position. Otherwise returns false.
14+
*/
15+
startsWith(searchString: string, position?: number): boolean;
16+
17+
/**
18+
* Returns true if the sequence of elements of searchString converted to a String is the
19+
* same as the corresponding elements of this object (converted to a String) starting at
20+
* endPosition – length(this). Otherwise returns false.
21+
*/
22+
endsWith(searchString: string, endPosition?: number): boolean;
23+
}
24+
25+
interface Array<T> {
26+
/**
27+
* Returns the value of the first element in the array where predicate is true, and undefined
28+
* otherwise.
29+
* @param predicate find calls predicate once for each element of the array, in ascending
30+
* order, until it finds one where predicate returns true. If such an element is found, find
31+
* immediately returns that element value. Otherwise, find returns undefined.
32+
* @param thisArg If provided, it will be used as the this value for each invocation of
33+
* predicate. If it is not provided, undefined is used instead.
34+
*/
35+
find(predicate: (value: T, index: number, obj: Array<T>) => boolean, thisArg?: any): T;
36+
/**
37+
* Returns the this object after filling the section identified by start and end with value
38+
* @param value value to fill array section with
39+
* @param start index to start filling the array at. If start is negative, it is treated as
40+
* length+start where length is the length of the array.
41+
* @param end index to stop filling the array at. If end is negative, it is treated as
42+
* length+end.
43+
*/
44+
fill(value: T, start?: number, end?: number): T[];
45+
}
46+
47+
interface NumberConstructor {
48+
/**
49+
* Returns true if the value passed is an integer, false otherwise.
50+
* @param number A numeric value.
51+
*/
52+
isInteger(number: number): boolean;
53+
}
54+
55+
// Workaround https://github.com/Microsoft/TypeScript/issues/9193
56+
interface PromiseConstructor {
57+
all<T>(values: (T | PromiseLike<T>)[]): Promise<T[]>;
58+
}
59+
60+
interface Function {
61+
/**
62+
* Returns the name of the function. Function names are read-only and can not be changed.
63+
*/
64+
readonly name: string;
65+
}

modules/tsconfig.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
},
1717
"rootDir": ".",
1818
"inlineSourceMap": true,
19-
"lib": ["es6", "dom"],
19+
"lib": ["es5", "dom", "es2015.promise", "es2015.collection", "es2015.iterable"],
20+
"skipDefaultLibCheck": true,
2021
"target": "es5"
2122
},
2223
"exclude": [

modules/types.d.ts

+1
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,4 @@
1414
/// <reference path="../node_modules/@types/node/index.d.ts" />
1515
/// <reference path="../node_modules/@types/protractor/index.d.ts" />
1616
/// <reference path="../node_modules/@types/selenium-webdriver/index.d.ts" />
17+
/// <reference path="./es6-subset.d.ts" />

0 commit comments

Comments
 (0)