Skip to content

Commit 894a0f0

Browse files
committed
chore(ts): duplicate the .es6 files in the facade directory to TypeScript.
Adds a gulp task which builds the .ts files (in the cjs build only). The new files have extension .ts since they are now valid typescript. Unfortunately until Typescript can emit System.require, we have to keep the old .es6 version so traceur works inside the Karma preprocessor. This should be fixed soon.
1 parent abea92a commit 894a0f0

File tree

10 files changed

+669
-7
lines changed

10 files changed

+669
-7
lines changed

gulpfile.js

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
var format = require('gulp-clang-format');
12
var gulp = require('gulp');
23
var gulpPlugins = require('gulp-load-plugins')();
34
var shell = require('gulp-shell');
@@ -7,7 +8,6 @@ var merge = require('merge');
78
var path = require('path');
89

910
var gulpTraceur = require('./tools/transpiler/gulp-traceur');
10-
1111
var clean = require('./tools/build/clean');
1212
var transpile = require('./tools/build/transpile');
1313
var html = require('./tools/build/html');
@@ -143,7 +143,8 @@ var CONFIG = {
143143
}),
144144
cjs: merge(true, _COMPILER_CONFIG_JS_DEFAULT, {
145145
typeAssertionModule: 'rtts_assert/rtts_assert',
146-
typeAssertions: true,
146+
// Don't use type assertions since this is partly transpiled by typescript
147+
typeAssertions: false,
147148
modules: 'commonjs'
148149
})
149150
},
@@ -296,6 +297,26 @@ gulp.task('build/clean.docs', clean(gulp, gulpPlugins, {
296297
// ------------
297298
// transpile
298299

300+
gulp.task('build/transpile.ts.cjs', function() {
301+
var tsResult = gulp.src(CONFIG.transpile.src.ts)
302+
.pipe(sourcemaps.init())
303+
.pipe(tsc({
304+
target: 'ES5',
305+
module: /*system.js*/'commonjs',
306+
allowNonTsExtensions: false,
307+
typescript: require('typescript'),
308+
//declarationFiles: true,
309+
noEmitOnError: true
310+
}));
311+
var dest = gulp.dest(CONFIG.dest.js.cjs);
312+
return merge([
313+
// Write external sourcemap next to the js file
314+
tsResult.js.pipe(sourcemaps.write('.')).pipe(dest),
315+
tsResult.js.pipe(dest),
316+
tsResult.dts.pipe(dest),
317+
]);
318+
});
319+
299320
gulp.task('build/transpile.js.dev.es6', transpile(gulp, gulpPlugins, {
300321
src: CONFIG.transpile.src.js,
301322
dest: CONFIG.dest.js.dev.es6,
@@ -314,8 +335,7 @@ gulp.task('build/transpile.ts.dev.es5', function() {
314335
module: 'commonjs',
315336
typescript: require('typescript'),
316337
noEmitOnError: true
317-
}))
318-
.js;
338+
}));
319339
return merge([
320340
tsResult.js.pipe(sourcemaps.write('.'))
321341
.pipe(gulp.dest(CONFIG.dest.js.dev.es5)),
@@ -524,14 +544,19 @@ gulp.task('build/pubbuild.dart', pubbuild(gulp, gulpPlugins, {
524544
}));
525545

526546
// ------------
527-
// format dart
547+
// formatting
528548

529549
gulp.task('build/format.dart', rundartpackage(gulp, gulpPlugins, {
530550
pub: DART_SDK.PUB,
531551
packageName: CONFIG.formatDart.packageName,
532552
args: CONFIG.formatDart.args
533553
}));
534554

555+
gulp.task('check-format', function() {
556+
return gulp.src(['modules/**/*.ts', '!**/typings/**/*.d.ts'])
557+
.pipe(format.checkFormat('file'));
558+
});
559+
535560
// ------------
536561
// check circular dependencies in Node.js context
537562
gulp.task('build/checkCircularDependencies', function (done) {
@@ -786,6 +811,9 @@ gulp.task('build.js.prod', function(done) {
786811
gulp.task('build.js.cjs', function(done) {
787812
runSequence(
788813
['build/transpile.js.cjs', 'build/copy.js.cjs', 'build/multicopy.js.cjs'],
814+
// Overwrite the .js.cjs transpilation with typescript outputs
815+
// We still need traceur outputs everywhere else, for now.
816+
'build/transpile.ts.cjs',
789817
['build/linknodemodules.js.cjs'],
790818
'build/transformCJSTests',
791819
done

modules/angular2/globals.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/**
2+
* This file contains declarations of global symbols we reference in our code
3+
*/
4+
5+
declare var assert: any;
6+
declare var global: Window;
7+
type int = number;
8+
9+
interface List<T> extends Array<T> {}
10+
11+
interface Window {
12+
Object: typeof Object;
13+
Array: typeof Array;
14+
Map: typeof Map;
15+
Set: typeof Set;
16+
Date: typeof Date;
17+
RegExp: typeof RegExp;
18+
JSON: typeof JSON;
19+
Math: typeof Math;
20+
assert: typeof assert;
21+
NaN: typeof NaN;
22+
gc(): void;
23+
}

modules/angular2/src/core/compiler/pipeline/compile_element.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ export class CompileElement {
7676
this.ignoreBindings = false;
7777
this.contentTagSelector = null;
7878
// description is calculated here as compilation steps may change the element
79-
var tplDesc = assertionsEnabled()? getElementDescription(element) : null;
79+
var tplDesc = getElementDescription(element);
8080
if (compilationUnit !== '') {
8181
this.elementDescription = compilationUnit;
8282
if (isPresent(tplDesc)) this.elementDescription += ": " + tplDesc;
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
/// <reference path="../../typings/es6-promise/es6-promise.d.ts" />
2+
/// <reference path="../../typings/rx/rx.all.d.ts" />
3+
4+
// HACK: workaround for Traceur behavior.
5+
// It expects all transpiled modules to contain this marker.
6+
// TODO: remove this when we no longer use traceur
7+
export var __esModule = true;
8+
9+
import {int, global, isPresent} from 'angular2/src/facade/lang';
10+
import {List} from 'angular2/src/facade/collection';
11+
import * as Rx from 'rx';
12+
13+
export class PromiseWrapper {
14+
static resolve(obj): Promise<any> { return Promise.resolve(obj); }
15+
16+
static reject(obj): Promise<any> { return Promise.reject(obj); }
17+
18+
// Note: We can't rename this method into `catch`, as this is not a valid
19+
// method name in Dart.
20+
static catchError<T>(promise: Promise<T>, onError: (error: any) => T | Thenable<T>): Promise<T> {
21+
return promise.catch(onError);
22+
}
23+
24+
static all(promises: List<Promise<any>>): Promise<any> {
25+
if (promises.length == 0) return Promise.resolve([]);
26+
return Promise.all(promises);
27+
}
28+
29+
static then<T>(promise: Promise<T>, success: (value: any) => T | Thenable<T>,
30+
rejection: (error: any) => T | Thenable<T>): Promise<T> {
31+
return promise.then(success, rejection);
32+
}
33+
34+
static completer() {
35+
var resolve;
36+
var reject;
37+
38+
var p = new Promise(function(res, rej) {
39+
resolve = res;
40+
reject = rej;
41+
});
42+
43+
return {promise: p, resolve: resolve, reject: reject};
44+
}
45+
46+
static setTimeout(fn: Function, millis: int) { global.setTimeout(fn, millis); }
47+
48+
static isPromise(maybePromise): boolean { return maybePromise instanceof Promise; }
49+
}
50+
51+
52+
/**
53+
* Use Rx.Observable but provides an adapter to make it work as specified here:
54+
* https://github.com/jhusain/observable-spec
55+
*
56+
* Once a reference implementation of the spec is available, switch to it.
57+
*/
58+
type Observable = Rx.Observable<any>;
59+
type ObservableController = Rx.Subject<any>;
60+
61+
export class ObservableWrapper {
62+
static createController(): Rx.Subject<any> { return new Rx.Subject(); }
63+
64+
static createObservable<T>(subject: Rx.Subject<T>): Rx.Observable<T> { return subject; }
65+
66+
static subscribe(observable: Rx.Observable<any>, generatorOrOnNext, onThrow = null,
67+
onReturn = null) {
68+
if (isPresent(generatorOrOnNext.next)) {
69+
return observable.observeOn(Rx.Scheduler.timeout)
70+
.subscribe((value) => generatorOrOnNext.next(value),
71+
(error) => generatorOrOnNext.throw(error), () => generatorOrOnNext.return ());
72+
} else {
73+
return observable.observeOn(Rx.Scheduler.timeout)
74+
.subscribe(generatorOrOnNext, onThrow, onReturn);
75+
}
76+
}
77+
78+
static callNext(subject: Rx.Subject<any>, value: any) { subject.onNext(value); }
79+
80+
static callThrow(subject: Rx.Subject<any>, error: any) { subject.onError(error); }
81+
82+
static callReturn(subject: Rx.Subject<any>) { subject.onCompleted(); }
83+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/**
2+
* JS version of browser APIs. This library can only run in the browser.
3+
*/
4+
// HACK: workaround for Traceur behavior.
5+
// It expects all transpiled modules to contain this marker.
6+
// TODO: remove this when we no longer use traceur
7+
export var __esModule = true;
8+
9+
var win = window;
10+
11+
export {win as window};
12+
export var document = window.document;
13+
export var location = window.location;
14+
export var gc = window.gc ? () => window.gc() : () => null;

0 commit comments

Comments
 (0)