Skip to content

Commit cd5be81

Browse files
committed
fix(): fix a lot of dartanalyzer errors (not all).
1 parent 9337954 commit cd5be81

File tree

10 files changed

+119
-111
lines changed

10 files changed

+119
-111
lines changed

docs/dart/writing-compatible-typescript.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,6 @@ Here's a list of gotchas to keep in mind when writing TypeScript code that will
3838
* **Accessing any platform primitive must be done through a Facade.** For example, Promises or DOM manipulation. Facades are going to be provided on a need-to-have basis.
3939
* **Union types are a no-go.** Dart has them on its roadmap, but for now we must avoid them.
4040
* **Dart files cannot have the same name as a reserved keyword.** For example, `for.dart`, `switch.dart` or `class.dart` are all invalid names. Since the TypeScript files have the same name when transpiled to Dart, they also have the same restriction.
41+
* **Default values need to be constants.** This mean that code like `function myFunction(arg1: string = callToSomething()) {}` will not compile.
42+
* **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.
43+
* **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.

ember-cli-build.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ function getDartTree(root) {
5757

5858
const dartSources = new BroccoliFunnel(root, {
5959
include: ['**/*.dart'],
60-
destDir: 'dart/web',
60+
destDir: 'dart/lib',
6161
});
6262

6363
const allDartFiles = mergeTrees([
@@ -79,7 +79,7 @@ function getDartTree(root) {
7979
return mergeTrees([
8080
dartSources,
8181
pubSpecTree,
82-
new BroccoliDestCopy(formatter, 'dart/web'),
82+
new BroccoliDestCopy(formatter, 'dart/lib'),
8383
]);
8484
}
8585

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
},
1010
"scripts": {
1111
"build": "ng build",
12-
"dartanalyzer": "ts-node scripts/ci/dart_analyzer",
12+
"dartanalyzer": "cd dist/dart && pub install && cd ../.. && ts-node scripts/ci/dart_analyzer",
1313
"demo-app": "cd src && ng serve",
1414
"test": "karma start test/karma.conf.js"
1515
},
@@ -51,7 +51,7 @@
5151
"strip-ansi": "^3.0.0",
5252
"symlink-or-copy": "^1.0.1",
5353
"ts-node": "^0.5.5",
54-
"ts2dart": "^0.7.20",
54+
"ts2dart": "^0.7.24",
5555
"tslint": "^3.2.2",
5656
"typescript": "^1.7.5",
5757
"which": "^1.2.4"

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@ transformers:
1313
- angular2:
1414
platform_directives: 'package:angular2/src/common/directives.dart#CORE_DIRECTIVES'
1515
entry_points:
16-
- web/src/demo-app/demo-app.dart
16+
- lib/demo-app/demo-app.dart

src/components/card/card.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {Component, View, ViewEncapsulation} from 'angular2/core';
2-
import {CONST_EXPR, Type} from 'angular2/src/facade/lang';
2+
import {CONST_EXPR} from 'angular2/src/facade/lang';
33

44
/*
55
@@ -66,6 +66,5 @@ TODO(kara): update link to demo site when it exists
6666
})
6767
export class MdCardTitleGroup {}
6868

69-
export const MD_CARD_DIRECTIVES: Type[] =
70-
CONST_EXPR([MdCard, MdCardHeader, MdCardTitleGroup]);
69+
export const MD_CARD_DIRECTIVES: any[] = CONST_EXPR([MdCard, MdCardHeader, MdCardTitleGroup]);
7170

src/components/sidenav/sidenav.spec.ts

Lines changed: 68 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,17 @@ import {By} from 'angular2/platform/browser';
1515

1616
import {MdSidenav, MdSidenavLayout, MD_SIDENAV_DIRECTIVES} from './sidenav';
1717
import {AsyncTestFn, FunctionWithParamTokens} from 'angular2/testing';
18-
import {ComponentFixture} from "angular2/testing";
19-
import {EventEmitter} from "angular2/core";
20-
import {Predicate} from "angular2/src/facade/collection";
18+
import {ComponentFixture} from 'angular2/testing';
19+
import {EventEmitter} from 'angular2/core';
20+
import {Predicate} from 'angular2/src/facade/collection';
21+
import {PromiseWrapper} from 'angular2/src/facade/promise';
22+
import {TimerWrapper} from 'angular2/src/facade/async';
2123

2224

2325
function wait(msec: number) {
24-
return new Promise(resolve => window.setTimeout(() => resolve(), msec));
26+
let completer = PromiseWrapper.completer();
27+
TimerWrapper.setTimeout(completer.resolve, msec);
28+
return completer.promise;
2529
}
2630

2731

@@ -31,10 +35,10 @@ function waitOnEvent(fixture: ComponentFixture,
3135
fixture.detectChanges();
3236

3337
// Wait for the animation end.
34-
return new Promise(resolve => {
35-
const component: any = fixture.debugElement.query(by).componentInstance;
36-
component[propertyName].subscribe(resolve);
37-
});
38+
let completer = PromiseWrapper.completer();
39+
let component: any = fixture.debugElement.query(by).componentInstance;
40+
component[propertyName].subscribe(completer.resolve);
41+
return completer.promise;
3842
}
3943

4044

@@ -56,47 +60,47 @@ export function main() {
5660
fixture = f;
5761
testComponent = fixture.debugElement.componentInstance;
5862

59-
const openButtonElement = fixture.debugElement.query(By.css('.open'));
63+
let openButtonElement = fixture.debugElement.query(By.css('.open'));
6064
openButtonElement.nativeElement.click();
6165
})
62-
.then(() => wait(1))
63-
.then(() => {
66+
.then((_: any) => { wait(1); })
67+
.then((_: any) => {
6468
expect(testComponent.openStartCount).toBe(1);
6569
expect(testComponent.openCount).toBe(0);
6670
})
67-
.then(() => waitOnEvent(fixture, By.directive(MdSidenav), 'onOpen'))
68-
.then(() => {
71+
.then((_: any) => waitOnEvent(fixture, By.directive(MdSidenav), 'onOpen'))
72+
.then((_: any) => {
6973
expect(testComponent.openStartCount).toBe(1);
7074
expect(testComponent.openCount).toBe(1);
7175
expect(testComponent.closeStartCount).toBe(0);
7276
expect(testComponent.closeCount).toBe(0);
7377

74-
const sidenavElement = fixture.debugElement.query(By.css('md-sidenav'));
75-
const sidenavBackdropElement = fixture.debugElement.query(By.css('.md-sidenav-backdrop'));
78+
let sidenavElement = fixture.debugElement.query(By.css('md-sidenav'));
79+
let sidenavBackdropElement = fixture.debugElement.query(By.css('.md-sidenav-backdrop'));
7680
expect(window.getComputedStyle(sidenavElement.nativeElement).visibility).toEqual('visible');
7781
expect(window.getComputedStyle(sidenavBackdropElement.nativeElement).visibility).toEqual('visible');
7882

7983
// Close it.
80-
const closeButtonElement = fixture.debugElement.query(By.css('.close'));
84+
let closeButtonElement = fixture.debugElement.query(By.css('.close'));
8185
closeButtonElement.nativeElement.click();
8286
})
83-
.then(() => wait(1))
84-
.then(() => {
87+
.then((_: any) => wait(1))
88+
.then((_: any) => {
8589
expect(testComponent.openStartCount).toBe(1);
8690
expect(testComponent.openCount).toBe(1);
8791
expect(testComponent.closeStartCount).toBe(1);
8892
expect(testComponent.closeCount).toBe(0);
8993
})
90-
.then(() => waitOnEvent(fixture, By.directive(MdSidenav), 'onClose'))
91-
.then(() => fixture.detectChanges())
92-
.then(() => {
94+
.then((_: any) => waitOnEvent(fixture, By.directive(MdSidenav), 'onClose'))
95+
.then((_: any) => fixture.detectChanges())
96+
.then((_: any) => {
9397
expect(testComponent.openStartCount).toBe(1);
9498
expect(testComponent.openCount).toBe(1);
9599
expect(testComponent.closeStartCount).toBe(1);
96100
expect(testComponent.closeCount).toBe(1);
97101

98-
const sidenavElement = fixture.debugElement.query(By.css('md-sidenav'));
99-
const sidenavBackdropElement = fixture.debugElement.query(By.css('.md-sidenav-backdrop'));
102+
let sidenavElement = fixture.debugElement.query(By.css('md-sidenav'));
103+
let sidenavBackdropElement = fixture.debugElement.query(By.css('.md-sidenav-backdrop'));
100104
expect(window.getComputedStyle(sidenavElement.nativeElement).visibility).toEqual('hidden');
101105
expect(window.getComputedStyle(sidenavBackdropElement.nativeElement).visibility).toEqual('hidden');
102106
})
@@ -105,11 +109,10 @@ export function main() {
105109

106110
it('open() and close() return a promise that resolves after the animation ended',
107111
(done: any) => {
108-
let testComponent: BasicTestApp;
109112
let fixture: ComponentFixture;
110113
let sidenav: MdSidenav;
111114

112-
let promise: Promise<{}>;
115+
let promise: Promise<void>;
113116
let called: boolean = false;
114117

115118
return builder.createAsync(BasicTestApp)
@@ -118,38 +121,36 @@ export function main() {
118121
sidenav = fixture.debugElement.query(By.directive(MdSidenav)).componentInstance;
119122

120123
promise = sidenav.open();
121-
promise.then(() => called = true);
124+
promise.then((_: any) => called = true);
122125
})
123-
.then(() => wait(1))
124-
.then(() => fixture.detectChanges())
125-
.then(() => {
126+
.then((_: any) => wait(1))
127+
.then((_: any) => fixture.detectChanges())
128+
.then((_: any) => {
126129
expect(called).toBe(false);
127130
})
128-
.then(() => promise)
129-
.then(() => expect(called).toBe(true))
130-
.then(() => {
131+
.then((_: any) => promise)
132+
.then((_: any) => expect(called).toBe(true))
133+
.then((_: any) => {
131134
// Close it now.
132135
called = false;
133136
promise = sidenav.close();
134-
promise.then(() => called = true);
137+
promise.then((_: any) => called = true);
135138
})
136-
.then(() => wait(1))
137-
.then(() => fixture.detectChanges())
138-
.then(() => {
139+
.then((_: any) => wait(1))
140+
.then((_: any) => fixture.detectChanges())
141+
.then((_: any) => {
139142
expect(called).toBe(false);
140143
})
141-
.then(() => promise)
142-
.then(() => expect(called).toBe(true))
144+
.then((_: any) => promise)
145+
.then((_: any) => expect(called).toBe(true))
143146
.then(done, done.fail);
144147
}, 8000);
145148

146149
it('open() twice returns the same promise', (done: any) => {
147-
let testComponent: BasicTestApp;
148150
let fixture: ComponentFixture;
149151
let sidenav: MdSidenav;
150152

151-
let promise: Promise<{}>;
152-
let called: boolean = false;
153+
let promise: Promise<void>;
153154

154155
return builder.createAsync(BasicTestApp)
155156
.then((f) => {
@@ -159,12 +160,12 @@ export function main() {
159160
promise = sidenav.open();
160161
expect(sidenav.open()).toBe(promise);
161162
})
162-
.then(() => wait(1))
163-
.then(() => {
163+
.then((_: any) => wait(1))
164+
.then((_: any) => {
164165
fixture.detectChanges();
165166
return promise;
166167
})
167-
.then(() => {
168+
.then((_: any) => {
168169
promise = sidenav.close();
169170
expect(sidenav.close()).toBe(promise);
170171
})
@@ -173,12 +174,11 @@ export function main() {
173174

174175
it('open() then close() cancel animations when called too fast',
175176
(done: any) => {
176-
let testComponent: BasicTestApp;
177177
let fixture: ComponentFixture;
178178
let sidenav: MdSidenav;
179179

180-
let openPromise: Promise<any>;
181-
let closePromise: Promise<any>;
180+
let openPromise: Promise<void>;
181+
let closePromise: Promise<void>;
182182
let openCalled: boolean = false;
183183
let openCancelled: boolean = false;
184184
let closeCalled: boolean = false;
@@ -188,28 +188,28 @@ export function main() {
188188
fixture = f;
189189
sidenav = fixture.debugElement.query(By.directive(MdSidenav)).componentInstance;
190190

191-
openPromise = sidenav.open().then(() => {
191+
openPromise = sidenav.open().then((_: any) => {
192192
openCalled = true;
193193
},
194194
() => {
195195
openCancelled = true;
196196
});
197197
})
198-
.then(() => wait(1))
199-
.then(() => fixture.detectChanges())
198+
.then((_: any) => wait(1))
199+
.then((_: any) => fixture.detectChanges())
200200
// We need to wait for the browser to start the transition.
201-
.then(() => wait(50))
202-
.then(() => {
203-
closePromise = sidenav.close().then(() => {
201+
.then((_: any) => wait(50))
202+
.then((_: any) => {
203+
closePromise = sidenav.close().then((_: any) => {
204204
closeCalled = true;
205205
}, done.fail);
206206
return wait(1);
207207
})
208-
.then(() => {
208+
.then((_: any) => {
209209
fixture.detectChanges();
210210
return closePromise;
211211
})
212-
.then(() => {
212+
.then((_: any) => {
213213
expect(openCalled).toBe(false);
214214
expect(openCancelled).toBe(true);
215215
expect(closeCalled).toBe(true);
@@ -223,8 +223,8 @@ export function main() {
223223
let fixture: ComponentFixture;
224224
let sidenav: MdSidenav;
225225

226-
let openPromise: Promise<any>;
227-
let closePromise: Promise<any>;
226+
let openPromise: Promise<void>;
227+
let closePromise: Promise<void>;
228228
let closeCalled: boolean = false;
229229
let closeCancelled: boolean = false;
230230
let openCalled: boolean = false;
@@ -237,35 +237,35 @@ export function main() {
237237
/** First, open it. */
238238
openPromise = sidenav.open();
239239
})
240-
.then(() => wait(1))
241-
.then(() => {
240+
.then((_: any) => wait(1))
241+
.then((_: any) => {
242242
fixture.detectChanges();
243243
return openPromise;
244244
})
245-
.then(() => {
245+
.then((_: any) => {
246246
// Then close and check behavior.
247-
closePromise = sidenav.close().then(() => {
247+
closePromise = sidenav.close().then((_: any) => {
248248
closeCalled = true;
249249
},
250250
() => {
251251
closeCancelled = true;
252252
});
253253
})
254-
.then(() => wait(1))
255-
.then(() => fixture.detectChanges())
254+
.then((_: any) => wait(1))
255+
.then((_: any) => fixture.detectChanges())
256256
// We need to wait for the browser to start the transition.
257-
.then(() => wait(50))
258-
.then(() => {
259-
openPromise = sidenav.open().then(() => {
257+
.then((_: any) => wait(50))
258+
.then((_: any) => {
259+
openPromise = sidenav.open().then((_: any) => {
260260
openCalled = true;
261261
}, done.fail);
262262
return wait(1);
263263
})
264-
.then(() => {
264+
.then((_: any) => {
265265
fixture.detectChanges();
266266
return openPromise;
267267
})
268-
.then(() => {
268+
.then((_: any) => {
269269
expect(closeCalled).toBe(false);
270270
expect(closeCancelled).toBe(true);
271271
expect(openCalled).toBe(true);

0 commit comments

Comments
 (0)