Skip to content

Commit d4bf62d

Browse files
mgechevwKoza
authored andcommitted
chore: update to typescript 2.8 (#584)
* chore: update to typescript 2.8 Migrate to TypeScript 2.8 and open the version range.
1 parent 204c8ef commit d4bf62d

14 files changed

+1315
-897
lines changed

package-lock.json

Lines changed: 1208 additions & 807 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@
8686
"rxjs-compat": "^6.0.0",
8787
"ts-node": "1.2.2",
8888
"tslint": "^5.0.0",
89-
"typescript": "2.4.0",
89+
"typescript": "^2.8.0",
9090
"zone.js": "^0.8.20"
9191
},
9292
"peerDependencies": {

src/angular/metadataReader.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import {
1919
decoratorArgument
2020
} from '../util/astQuery';
2121
import { getTemplate, getInlineStyle } from '../util/ngQuery';
22+
import { maybeNodeArray } from '../util/utils';
2223

2324
const normalizeTransformed = (t: CodeWithSourceMap) => {
2425
if (!t.map) {
@@ -36,17 +37,17 @@ export class MetadataReader {
3637
}
3738

3839
read(d: ts.ClassDeclaration): DirectiveMetadata {
39-
let componentMetadata = unwrapFirst(
40-
(d.decorators || ([] as ts.Decorator[])).map((dec: ts.Decorator) => {
40+
const componentMetadata = unwrapFirst(
41+
maybeNodeArray(d.decorators).map((dec: ts.Decorator) => {
4142
return Maybe.lift(dec)
4243
.bind(callExpression)
4344
.bind(withIdentifier('Component'))
4445
.fmap(() => this.readComponentMetadata(d, dec));
4546
})
4647
);
4748

48-
let directiveMetadata = unwrapFirst(
49-
(d.decorators || ([] as ts.Decorator[])).map((dec: ts.Decorator) =>
49+
const directiveMetadata = unwrapFirst(
50+
maybeNodeArray(d.decorators).map((dec: ts.Decorator) =>
5051
Maybe.lift(dec)
5152
.bind(callExpression)
5253
.bind(withIdentifier('Directive'))

src/angular/ngWalker.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import { ngWalkerFactoryUtils } from './ngWalkerFactoryUtils';
1818
import { Config } from './config';
1919

2020
import { logger } from '../util/logger';
21-
import { getDecoratorName } from '../util/utils';
21+
import { getDecoratorName, maybeNodeArray } from '../util/utils';
2222

2323
const getDecoratorStringArgs = (decorator: ts.Decorator) => {
2424
let baseExpr = <any>decorator.expression || {};
@@ -59,17 +59,17 @@ export class NgWalker extends Lint.RuleWalker {
5959
} else if (metadata instanceof DirectiveMetadata) {
6060
this.visitNgDirective(metadata);
6161
}
62-
(<ts.Decorator[]>declaration.decorators || []).forEach(this.visitClassDecorator.bind(this));
62+
maybeNodeArray(<ts.NodeArray<ts.Decorator>>declaration.decorators).forEach(this.visitClassDecorator.bind(this));
6363
super.visitClassDeclaration(declaration);
6464
}
6565

6666
visitMethodDeclaration(method: ts.MethodDeclaration) {
67-
(<ts.Decorator[]>method.decorators || []).forEach(this.visitMethodDecorator.bind(this));
67+
maybeNodeArray(<ts.NodeArray<ts.Decorator>>method.decorators).forEach(this.visitMethodDecorator.bind(this));
6868
super.visitMethodDeclaration(method);
6969
}
7070

7171
visitPropertyDeclaration(prop: ts.PropertyDeclaration) {
72-
(<ts.Decorator[]>prop.decorators || []).forEach(this.visitPropertyDecorator.bind(this));
72+
maybeNodeArray(<ts.NodeArray<ts.Decorator>>prop.decorators).forEach(this.visitPropertyDecorator.bind(this));
7373
super.visitPropertyDeclaration(prop);
7474
}
7575

@@ -227,10 +227,10 @@ export class NgWalker extends Lint.RuleWalker {
227227
}
228228
const sf = ts.createSourceFile(path, `\`${content}\``, ts.ScriptTarget.ES5);
229229
const original = sf.getFullText;
230-
sf.getFullText = function() {
230+
sf.getFullText = () => {
231231
const text = original.apply(sf);
232232
return text.substring(1, text.length - 1);
233-
}.bind(sf);
233+
};
234234
return sf;
235235
}
236236
}

src/noTemplateCallExpressionRule.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export class Rule extends Lint.Rules.AbstractRule {
1818

1919
static FAILURE_STRING = 'Call expressions are not allowed in templates except in output handlers.';
2020

21-
apply(sourceFile: ts.SourceFile) {
21+
apply(sourceFile: ts.SourceFile): Lint.RuleFailure[] {
2222
const walkerConfig: NgWalkerConfig = {
2323
templateVisitorCtrl: TemplateVisitor,
2424
expressionVisitorCtrl: ExpressionVisitor

src/propertyDecoratorBase.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class DirectiveMetadataWalker extends Lint.RuleWalker {
3636
}
3737

3838
visitClassDeclaration(node: ts.ClassDeclaration) {
39-
(<ts.Decorator[]>node.decorators || []).forEach(this.validateDecorator.bind(this, node.name.text));
39+
(<ts.NodeArray<ts.Decorator>>node.decorators).forEach(this.validateDecorator.bind(this, node.name.text));
4040
super.visitClassDeclaration(node);
4141
}
4242

src/selectorNameBase.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,9 @@ export class SelectorValidatorWalker extends Lint.RuleWalker {
103103
}
104104

105105
visitClassDeclaration(node: ts.ClassDeclaration) {
106-
(<ts.Decorator[]>node.decorators || []).forEach(this.validateDecorator.bind(this, node.name.text));
106+
if (node.decorators) {
107+
(<ts.NodeArray<ts.Decorator>>node.decorators).forEach(this.validateDecorator.bind(this, node.name.text));
108+
}
107109
super.visitClassDeclaration(node);
108110
}
109111

src/usePipeDecoratorRule.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import * as Lint from 'tslint';
22
import * as ts from 'typescript';
33
import { sprintf } from 'sprintf-js';
44
import SyntaxKind = require('./util/syntaxKind');
5+
import { maybeNodeArray } from './util/utils';
56

67
const getInterfaceName = (t: any) => {
78
if (t.expression && t.expression.name) {
@@ -32,9 +33,9 @@ export class Rule extends Lint.Rules.AbstractRule {
3233
export class ClassMetadataWalker extends Lint.RuleWalker {
3334
visitClassDeclaration(node: ts.ClassDeclaration) {
3435
if (this.hasIPipeTransform(node)) {
35-
let decorators = <any[]>node.decorators || [];
36-
let className: string = node.name.text;
37-
let pipes: Array<string> = decorators
36+
const decorators = maybeNodeArray(<ts.NodeArray<any>>node.decorators);
37+
const className: string = node.name.text;
38+
const pipes: Array<string> = decorators
3839
.map(d => (<any>d.expression).text || ((<any>d.expression).expression || {}).text)
3940
.filter(t => t === 'Pipe');
4041
if (pipes.length === 0) {

src/util/astQuery.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,10 @@ export function getInitializer(p: ts.ObjectLiteralElement): Maybe<ts.Expression>
5353
return Maybe.lift(isPropertyAssignment(p) && isIdentifier(p.name) ? p.initializer : undefined);
5454
}
5555

56-
export function getStringInitializerFromProperty(propertyName: string, ps: ts.ObjectLiteralElement[]): Maybe<WithStringInitializer> {
56+
export function getStringInitializerFromProperty(
57+
propertyName: string,
58+
ps: ts.NodeArray<ts.ObjectLiteralElement>
59+
): Maybe<WithStringInitializer> {
5760
const property = ps.find(p => isProperty(propertyName, p));
5861
return (
5962
getInitializer(property)

src/util/utils.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export const getDecoratorName = (decorator: ts.Decorator) => {
4444
};
4545

4646
export const getComponentDecorator = (declaration: ts.ClassDeclaration) => {
47-
return (<ts.Decorator[]>declaration.decorators || [])
47+
return ([].slice.apply(declaration.decorators) || [])
4848
.filter((d: any) => {
4949
if (
5050
!(<ts.CallExpression>d.expression).arguments ||
@@ -60,3 +60,10 @@ export const getComponentDecorator = (declaration: ts.ClassDeclaration) => {
6060
})
6161
.pop();
6262
};
63+
64+
export const maybeNodeArray = <T extends ts.Node>(nodes: ts.NodeArray<T>): ReadonlyArray<T> => {
65+
if (!nodes) {
66+
return [];
67+
}
68+
return nodes;
69+
};

0 commit comments

Comments
 (0)