Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: update to typescript 2.8 #584

Merged
merged 2 commits into from
Apr 27, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2,015 changes: 1,208 additions & 807 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
"rxjs-compat": "^6.0.0",
"ts-node": "1.2.2",
"tslint": "^5.0.0",
"typescript": "2.4.0",
"typescript": "^2.8.0",
"zone.js": "^0.8.20"
},
"peerDependencies": {
Expand Down
9 changes: 5 additions & 4 deletions src/angular/metadataReader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
decoratorArgument
} from '../util/astQuery';
import { getTemplate, getInlineStyle } from '../util/ngQuery';
import { maybeNodeArray } from '../util/utils';

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

read(d: ts.ClassDeclaration): DirectiveMetadata {
let componentMetadata = unwrapFirst(
(d.decorators || ([] as ts.Decorator[])).map((dec: ts.Decorator) => {
const componentMetadata = unwrapFirst(
maybeNodeArray(d.decorators).map((dec: ts.Decorator) => {
return Maybe.lift(dec)
.bind(callExpression)
.bind(withIdentifier('Component'))
.fmap(() => this.readComponentMetadata(d, dec));
})
);

let directiveMetadata = unwrapFirst(
(d.decorators || ([] as ts.Decorator[])).map((dec: ts.Decorator) =>
const directiveMetadata = unwrapFirst(
maybeNodeArray(d.decorators).map((dec: ts.Decorator) =>
Maybe.lift(dec)
.bind(callExpression)
.bind(withIdentifier('Directive'))
Expand Down
12 changes: 6 additions & 6 deletions src/angular/ngWalker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { ngWalkerFactoryUtils } from './ngWalkerFactoryUtils';
import { Config } from './config';

import { logger } from '../util/logger';
import { getDecoratorName } from '../util/utils';
import { getDecoratorName, maybeNodeArray } from '../util/utils';

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

visitMethodDeclaration(method: ts.MethodDeclaration) {
(<ts.Decorator[]>method.decorators || []).forEach(this.visitMethodDecorator.bind(this));
maybeNodeArray(<ts.NodeArray<ts.Decorator>>method.decorators).forEach(this.visitMethodDecorator.bind(this));
super.visitMethodDeclaration(method);
}

visitPropertyDeclaration(prop: ts.PropertyDeclaration) {
(<ts.Decorator[]>prop.decorators || []).forEach(this.visitPropertyDecorator.bind(this));
maybeNodeArray(<ts.NodeArray<ts.Decorator>>prop.decorators).forEach(this.visitPropertyDecorator.bind(this));
super.visitPropertyDeclaration(prop);
}

Expand Down Expand Up @@ -227,10 +227,10 @@ export class NgWalker extends Lint.RuleWalker {
}
const sf = ts.createSourceFile(path, `\`${content}\``, ts.ScriptTarget.ES5);
const original = sf.getFullText;
sf.getFullText = function() {
sf.getFullText = () => {
const text = original.apply(sf);
return text.substring(1, text.length - 1);
}.bind(sf);
};
return sf;
}
}
2 changes: 1 addition & 1 deletion src/noTemplateCallExpressionRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export class Rule extends Lint.Rules.AbstractRule {

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

apply(sourceFile: ts.SourceFile) {
apply(sourceFile: ts.SourceFile): Lint.RuleFailure[] {
const walkerConfig: NgWalkerConfig = {
templateVisitorCtrl: TemplateVisitor,
expressionVisitorCtrl: ExpressionVisitor
Expand Down
2 changes: 1 addition & 1 deletion src/propertyDecoratorBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class DirectiveMetadataWalker extends Lint.RuleWalker {
}

visitClassDeclaration(node: ts.ClassDeclaration) {
(<ts.Decorator[]>node.decorators || []).forEach(this.validateDecorator.bind(this, node.name.text));
(<ts.NodeArray<ts.Decorator>>node.decorators).forEach(this.validateDecorator.bind(this, node.name.text));
super.visitClassDeclaration(node);
}

Expand Down
4 changes: 3 additions & 1 deletion src/selectorNameBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,9 @@ export class SelectorValidatorWalker extends Lint.RuleWalker {
}

visitClassDeclaration(node: ts.ClassDeclaration) {
(<ts.Decorator[]>node.decorators || []).forEach(this.validateDecorator.bind(this, node.name.text));
if (node.decorators) {
(<ts.NodeArray<ts.Decorator>>node.decorators).forEach(this.validateDecorator.bind(this, node.name.text));
}
super.visitClassDeclaration(node);
}

Expand Down
7 changes: 4 additions & 3 deletions src/usePipeDecoratorRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as Lint from 'tslint';
import * as ts from 'typescript';
import { sprintf } from 'sprintf-js';
import SyntaxKind = require('./util/syntaxKind');
import { maybeNodeArray } from './util/utils';

const getInterfaceName = (t: any) => {
if (t.expression && t.expression.name) {
Expand Down Expand Up @@ -32,9 +33,9 @@ export class Rule extends Lint.Rules.AbstractRule {
export class ClassMetadataWalker extends Lint.RuleWalker {
visitClassDeclaration(node: ts.ClassDeclaration) {
if (this.hasIPipeTransform(node)) {
let decorators = <any[]>node.decorators || [];
let className: string = node.name.text;
let pipes: Array<string> = decorators
const decorators = maybeNodeArray(<ts.NodeArray<any>>node.decorators);
const className: string = node.name.text;
const pipes: Array<string> = decorators
.map(d => (<any>d.expression).text || ((<any>d.expression).expression || {}).text)
.filter(t => t === 'Pipe');
if (pipes.length === 0) {
Expand Down
5 changes: 4 additions & 1 deletion src/util/astQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,10 @@ export function getInitializer(p: ts.ObjectLiteralElement): Maybe<ts.Expression>
return Maybe.lift(isPropertyAssignment(p) && isIdentifier(p.name) ? p.initializer : undefined);
}

export function getStringInitializerFromProperty(propertyName: string, ps: ts.ObjectLiteralElement[]): Maybe<WithStringInitializer> {
export function getStringInitializerFromProperty(
propertyName: string,
ps: ts.NodeArray<ts.ObjectLiteralElement>
): Maybe<WithStringInitializer> {
const property = ps.find(p => isProperty(propertyName, p));
return (
getInitializer(property)
Expand Down
9 changes: 8 additions & 1 deletion src/util/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export const getDecoratorName = (decorator: ts.Decorator) => {
};

export const getComponentDecorator = (declaration: ts.ClassDeclaration) => {
return (<ts.Decorator[]>declaration.decorators || [])
return ([].slice.apply(declaration.decorators) || [])
.filter((d: any) => {
if (
!(<ts.CallExpression>d.expression).arguments ||
Expand All @@ -60,3 +60,10 @@ export const getComponentDecorator = (declaration: ts.ClassDeclaration) => {
})
.pop();
};

export const maybeNodeArray = <T extends ts.Node>(nodes: ts.NodeArray<T>): ReadonlyArray<T> => {
if (!nodes) {
return [];
}
return nodes;
};
80 changes: 40 additions & 40 deletions test/angular/metadataReader.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import { Config } from '../../src/angular/config';

import { join, normalize } from 'path';

const getAst = (code: string, file = 'file.ts') => {
return ts.createSourceFile(file, code, ts.ScriptTarget.ES2015, true);
};
const getAst = (code: string, file = 'file.ts') => ts.createSourceFile(file, code, ts.ScriptTarget.ES2015, true);

const last = <T extends ts.Node>(nodes: ts.NodeArray<T>) => nodes[nodes.length - 1];

describe('metadataReader', () => {
describe('directive metadata', () => {
Expand All @@ -24,7 +24,7 @@ describe('metadataReader', () => {
`;
const reader = new MetadataReader(new DummyFileResolver());
const ast = getAst(code);
const metadata = reader.read(<ts.ClassDeclaration>ast.statements.pop());
const metadata = reader.read(<ts.ClassDeclaration>last(ast.statements));
chai.expect(metadata.selector).eq('foo');
});

Expand All @@ -35,7 +35,7 @@ describe('metadataReader', () => {
`;
const reader = new MetadataReader(new DummyFileResolver());
const ast = getAst(code);
const metadata = reader.read(<ts.ClassDeclaration>ast.statements.pop());
const metadata = reader.read(<ts.ClassDeclaration>last(ast.statements));
chai.expect(metadata.selector).eq(undefined);
});

Expand All @@ -46,7 +46,7 @@ describe('metadataReader', () => {
`;
const reader = new MetadataReader(new DummyFileResolver());
const ast = getAst(code);
const classDeclaration = <ts.ClassDeclaration>ast.statements.pop();
const classDeclaration = <ts.ClassDeclaration>last(ast.statements);
const metadata = reader.read(classDeclaration);
chai.expect(metadata.controller).eq(classDeclaration);
});
Expand All @@ -64,7 +64,7 @@ describe('metadataReader', () => {
`;
const reader = new MetadataReader(new DummyFileResolver());
const ast = getAst(code);
const classDeclaration = <ts.ClassDeclaration>ast.statements.pop();
const classDeclaration = <ts.ClassDeclaration>last(ast.statements);
const metadata = reader.read(classDeclaration);
chai.expect(metadata instanceof ComponentMetadata).eq(true);
chai.expect(metadata.selector).eq('foo');
Expand All @@ -86,7 +86,7 @@ describe('metadataReader', () => {
`;
const reader = new MetadataReader(new DummyFileResolver());
const ast = getAst(code);
const classDeclaration = <ts.ClassDeclaration>ast.statements.pop();
const classDeclaration = <ts.ClassDeclaration>last(ast.statements);
const metadata = reader.read(classDeclaration);
chai.expect(metadata instanceof ComponentMetadata).eq(true);
chai.expect(metadata.selector).eq('foo');
Expand All @@ -109,7 +109,7 @@ describe('metadataReader', () => {
`;
const reader = new MetadataReader(new DummyFileResolver());
const ast = getAst(code);
const classDeclaration = <ts.ClassDeclaration>ast.statements.pop();
const classDeclaration = <ts.ClassDeclaration>last(ast.statements);
const metadata = reader.read(classDeclaration);
chai.expect(metadata instanceof ComponentMetadata).eq(true);
chai.expect(metadata.selector).eq('foo');
Expand All @@ -131,7 +131,7 @@ describe('metadataReader', () => {
`;
const reader = new MetadataReader(new FsFileResolver());
const ast = getAst(code, __dirname + '/../../test/fixtures/metadataReader/moduleid/foo.ts');
const classDeclaration = <ts.ClassDeclaration>ast.statements.pop();
const classDeclaration = <ts.ClassDeclaration>last(ast.statements);
const metadata = reader.read(classDeclaration);
chai.expect(metadata instanceof ComponentMetadata).eq(true);
chai.expect(metadata.selector).eq('foo');
Expand All @@ -153,7 +153,7 @@ describe('metadataReader', () => {
`;
const reader = new MetadataReader(new FsFileResolver());
const ast = getAst(code, __dirname + '/../../test/fixtures/metadataReader/moduleid/foo.ts');
const classDeclaration = <ts.ClassDeclaration>ast.statements.pop();
const classDeclaration = <ts.ClassDeclaration>last(ast.statements);
const metadata = reader.read(classDeclaration);
chai.expect(metadata instanceof ComponentMetadata).eq(true);
chai.expect(metadata.selector).eq('foo');
Expand All @@ -174,17 +174,17 @@ describe('metadataReader', () => {
return url;
};
const code = `
@Component({
selector: 'foo',
moduleId: module.id,
templateUrl: 'foo.html',
styles: [\`baz\`]
})
class Bar {}
`;
@Component({
selector: 'foo',
moduleId: module.id,
templateUrl: 'foo.html',
styles: [\`baz\`]
})
class Bar {}
`;
const reader = new MetadataReader(new FsFileResolver());
const ast = getAst(code, __dirname + '/../../test/fixtures/metadataReader/moduleid/foo.ts');
const classDeclaration = <ts.ClassDeclaration>ast.statements.pop();
const classDeclaration = <ts.ClassDeclaration>last(ast.statements);
chai.expect(invoked).eq(false);
const metadata = reader.read(classDeclaration);
chai.expect(metadata instanceof ComponentMetadata).eq(true);
Expand All @@ -210,17 +210,17 @@ describe('metadataReader', () => {
return { code };
};
const code = `
@Component({
selector: 'foo',
moduleId: module.id,
templateUrl: 'foo.html',
styles: [\`baz\`]
})
class Bar {}
`;
@Component({
selector: 'foo',
moduleId: module.id,
templateUrl: 'foo.html',
styles: [\`baz\`]
})
class Bar {}
`;
const reader = new MetadataReader(new FsFileResolver());
const ast = getAst(code, __dirname + '/../../test/fixtures/metadataReader/moduleid/foo.ts');
const classDeclaration = <ts.ClassDeclaration>ast.statements.pop();
const classDeclaration = <ts.ClassDeclaration>last(ast.statements);
chai.expect(invoked).eq(false);
const metadata = reader.read(classDeclaration);
chai.expect(metadata instanceof ComponentMetadata).eq(true);
Expand All @@ -246,17 +246,17 @@ describe('metadataReader', () => {
return { code };
};
const code = `
@Component({
selector: 'foo',
moduleId: module.id,
templateUrl: 'foo.html',
styles: [\`baz\`]
})
class Bar {}
`;
@Component({
selector: 'foo',
moduleId: module.id,
templateUrl: 'foo.html',
styles: [\`baz\`]
})
class Bar {}
`;
const reader = new MetadataReader(new FsFileResolver());
const ast = getAst(code, __dirname + '/../../test/fixtures/metadataReader/moduleid/foo.ts');
const classDeclaration = <ts.ClassDeclaration>ast.statements.pop();
const classDeclaration = <ts.ClassDeclaration>last(ast.statements);
chai.expect(invoked).eq(false);
const metadata = reader.read(classDeclaration);
chai.expect(metadata instanceof ComponentMetadata).eq(true);
Expand Down Expand Up @@ -284,7 +284,7 @@ describe('metadataReader', () => {
`;
const reader = new MetadataReader(new FsFileResolver());
const ast = getAst(code, __dirname + '/../../test/fixtures/metadataReader/specialsymbols/foo.ts');
const classDeclaration = <ts.ClassDeclaration>ast.statements.pop();
const classDeclaration = <ts.ClassDeclaration>last(ast.statements);
const metadata = reader.read(classDeclaration);
chai.expect(metadata instanceof ComponentMetadata).eq(true);
chai.expect(metadata.selector).eq('foo');
Expand All @@ -307,7 +307,7 @@ describe('metadataReader', () => {
`;
const reader = new MetadataReader(new FsFileResolver());
const ast = getAst(code, __dirname + '/../../test/fixtures/metadataReader/notsupported/foo.ts');
const classDeclaration = <ts.ClassDeclaration>ast.statements.pop();
const classDeclaration = <ts.ClassDeclaration>last(ast.statements);
const metadata = reader.read(classDeclaration);
chai.expect(metadata instanceof ComponentMetadata).eq(true);
chai.expect(metadata.selector).eq('foo');
Expand Down
Loading