From 9b4b9e7cf4eac215080b57668da1048191c28646 Mon Sep 17 00:00:00 2001 From: Hans Larsen Date: Thu, 11 Feb 2016 12:33:48 -0800 Subject: [PATCH] build(): Add a dartanalyzer run to Travis. It is required. --- docs/dart/writing-compatible-typescript.md | 1 + package.json | 2 +- scripts/ci/build-and-test.sh | 3 +-- scripts/ci/dart_analyzer.ts | 9 +++++++-- .../progress-circle/progress_circle.spec.ts | 10 +++++++++- .../progress-circle/progress_circle.ts | 16 +++++++--------- src/components/sidenav/sidenav.spec.ts | 8 ++++---- src/demo-app/demo-app.ts | 12 ++++++------ tools/build/dart_analyzer.ts | 2 +- 9 files changed, 37 insertions(+), 26 deletions(-) diff --git a/docs/dart/writing-compatible-typescript.md b/docs/dart/writing-compatible-typescript.md index 9eecda2f62b..a482bd70161 100644 --- a/docs/dart/writing-compatible-typescript.md +++ b/docs/dart/writing-compatible-typescript.md @@ -41,3 +41,4 @@ Here's a list of gotchas to keep in mind when writing TypeScript code that will * **Default values need to be constants.** This mean that code like `function myFunction(arg1: string = callToSomething()) {}` will not compile. * **The const keyword must have a const value.** Because of that, we cannot do `const x = a + b;` even if the value of `x`, `a` and `b` will not change. * **Lambdas need to abide to the type required.** Meaning that if a function requires a function that takes one argument, the lambda cannot be `() => {}`. Use `_` for temporary parameters. This is notable in Promises. +* **Dynamic return values fat arrows can't return non-primitive types without casting.** For example, a fat arrow that return a promise (or Future) generates a warning if using directly, like so: `promiseA.then(() => promiseB)`. In this case simply using a block works as expected; `promiseA.then(() => { return promiseB; })`. \ No newline at end of file diff --git a/package.json b/package.json index ea3e85c0dbc..215a664164e 100644 --- a/package.json +++ b/package.json @@ -51,7 +51,7 @@ "strip-ansi": "^3.0.0", "symlink-or-copy": "^1.0.1", "ts-node": "^0.5.5", - "ts2dart": "^0.7.24", + "ts2dart": "^0.7.25", "tslint": "^3.2.2", "typescript": "^1.7.5", "which": "^1.2.4" diff --git a/scripts/ci/build-and-test.sh b/scripts/ci/build-and-test.sh index b510bc82c11..abdba6e17a3 100755 --- a/scripts/ci/build-and-test.sh +++ b/scripts/ci/build-and-test.sh @@ -18,8 +18,7 @@ is_dart && pub install wait_for_tunnel if is_dart; then - # npm run dartanalyzer - echo 'TODO(hans): Implement dartanalyzer' + npm run dartanalyzer else karma start test/karma.conf.js --single-run --no-auto-watch --reporters='dots' fi diff --git a/scripts/ci/dart_analyzer.ts b/scripts/ci/dart_analyzer.ts index 9ec134aea8b..ff62c5478ff 100644 --- a/scripts/ci/dart_analyzer.ts +++ b/scripts/ci/dart_analyzer.ts @@ -5,8 +5,13 @@ import {detect} from '../../tools/build/dart'; const command = detect()['ANALYZER']; analyze('dist/dart', command, true) - .then(() => { + .then((err) => { + if (err) { + throw err; + } console.log('Done.'); - }, (err) => { + }) + .catch((err) => { console.error('Error:', err); + process.exit(1); }); diff --git a/src/components/progress-circle/progress_circle.spec.ts b/src/components/progress-circle/progress_circle.spec.ts index 5198f0fc5b4..583dd84d40c 100644 --- a/src/components/progress-circle/progress_circle.spec.ts +++ b/src/components/progress-circle/progress_circle.spec.ts @@ -1,4 +1,12 @@ -import {beforeEach, ddescribe, expect, inject, it, TestComponentBuilder} from 'angular2/testing'; +import {inject, TestComponentBuilder} from 'angular2/testing'; +import { + it, + iit, + describe, + ddescribe, + expect, + beforeEach, +} from '../../core/facade/testing'; import {Component, DebugElement} from 'angular2/core'; import {By} from 'angular2/platform/browser' import {MdProgressCircle} from './progress_circle'; diff --git a/src/components/progress-circle/progress_circle.ts b/src/components/progress-circle/progress_circle.ts index ffe9982728a..ae2f9cb3bac 100644 --- a/src/components/progress-circle/progress_circle.ts +++ b/src/components/progress-circle/progress_circle.ts @@ -8,6 +8,7 @@ import { ViewEncapsulation, } from 'angular2/core'; import {isPresent, CONST} from 'angular2/src/facade/lang'; +import {Math} from 'angular2/src/facade/math'; import {OneOf} from '../../core/annotations/one-of'; @@ -42,12 +43,9 @@ export class MdProgressCircle { * Input:number, defaults to 0. * value_ is bound to the host as the attribute aria-valuenow. */ + @HostBinding('attr.aria-valuenow') @Input('value') value_: number = 0; - @HostBinding('attr.aria-valuenow') - get _value() { - return this.value_; - } /** * Mode of the progress circle @@ -55,13 +53,10 @@ export class MdProgressCircle { * Input must be one of the values from ProgressMode, defaults to 'determinate'. * mode is bound to the host as the attribute host. */ + @HostBinding('attr.mode') @Input() @OneOf([ProgressMode.DETERMINATE, ProgressMode.INDETERMINATE]) mode: string; - @HostBinding('attr.mode') - get _mode() { - return this.mode; - } /** @@ -119,5 +114,8 @@ export class MdProgressCircle { changeDetection: ChangeDetectionStrategy.OnPush, }) export class MdSpinner extends MdProgressCircle { - mode: string = ProgressMode.INDETERMINATE; + constructor() { + super(); + this.mode = ProgressMode.INDETERMINATE; + } } diff --git a/src/components/sidenav/sidenav.spec.ts b/src/components/sidenav/sidenav.spec.ts index 31287fb95b8..9a883f9e981 100644 --- a/src/components/sidenav/sidenav.spec.ts +++ b/src/components/sidenav/sidenav.spec.ts @@ -138,8 +138,8 @@ export function main() { .then((_: any) => { expect(called).toBe(false); }) - .then((_: any) => promise) - .then((_: any) => expect(called).toBe(true)) + .then((_: any) => { return promise; }) + .then((_: any) => { expect(called).toBe(true); }) .then((_: any) => { // Close it now. called = false; @@ -151,8 +151,8 @@ export function main() { .then((_: any) => { expect(called).toBe(false); }) - .then((_: any) => promise) - .then((_: any) => expect(called).toBe(true)) + .then((_: any) => { return promise; }) + .then((_: any) => { expect(called).toBe(true); }) .then((_: any) => { done(); }); }, 8000); diff --git a/src/demo-app/demo-app.ts b/src/demo-app/demo-app.ts index 5c64d3d348e..c605849491a 100644 --- a/src/demo-app/demo-app.ts +++ b/src/demo-app/demo-app.ts @@ -3,7 +3,7 @@ import {CardDemo} from './card/card-demo'; import {ButtonDemo} from './button/button-demo'; import {SidenavDemo} from './sidenav/sidenav-demo'; import {ProgressCircleDemo} from './progress-circle/progress-circle-demo'; -import {RouteConfig, ROUTER_DIRECTIVES} from 'angular2/router'; +import {Route, RouteConfig, ROUTER_DIRECTIVES} from 'angular2/router'; import {Dir} from '../directives/dir/dir'; import {MdButton} from '../components/button/button'; @@ -22,10 +22,10 @@ export class Home {} pipes: [] }) @RouteConfig([ - {path: '/', name: 'Home', component: Home, useAsDefault: true}, - {path: '/button', name: 'ButtonDemo', component: ButtonDemo}, - {path: '/card', name: 'CardDemo', component: CardDemo}, - {path: '/sidenav', name: 'SidenavDemo', component: SidenavDemo}, - {path: '/progress-circle', name: 'ProgressCircleDemo', component: ProgressCircleDemo}, + new Route({path: '/', name: 'Home', component: Home, useAsDefault: true}), + new Route({path: '/button', name: 'ButtonDemo', component: ButtonDemo}), + new Route({path: '/card', name: 'CardDemo', component: CardDemo}), + new Route({path: '/sidenav', name: 'SidenavDemo', component: SidenavDemo}), + new Route({path: '/progress-circle', name: 'ProgressCircleDemo', component: ProgressCircleDemo}), ]) export class DemoApp { } diff --git a/tools/build/dart_analyzer.ts b/tools/build/dart_analyzer.ts index 08112e5c69c..d4c15887f8d 100644 --- a/tools/build/dart_analyzer.ts +++ b/tools/build/dart_analyzer.ts @@ -23,7 +23,7 @@ const tempFile = '_analyzer.dart'; * @param command The command to use for dartanalyzer. * @param use_ddc Enable strong static type checking (see https://goo.gl/DqcBsw). */ -export function analyze(dir: string, command: string, use_ddc: boolean = false): Promise { +export function analyze(dir: string, command: string, use_ddc: boolean = false): Promise { var travisFoldEnd = travisFoldStart(`dartanalyzer-${use_ddc ? 'ddc' : ''}-${dir}`); var pubspecContents = fs.readFileSync(path.join(dir, 'pubspec.yaml'));