Skip to content

Commit

Permalink
chore(ts): duplicate the .es6 files in the facade directory to TypeSc…
Browse files Browse the repository at this point in the history
…ript.

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.
  • Loading branch information
alexeagle committed Apr 3, 2015
1 parent abea92a commit 894a0f0
Show file tree
Hide file tree
Showing 10 changed files with 669 additions and 7 deletions.
38 changes: 33 additions & 5 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
var format = require('gulp-clang-format');
var gulp = require('gulp');
var gulpPlugins = require('gulp-load-plugins')();
var shell = require('gulp-shell');
Expand All @@ -7,7 +8,6 @@ var merge = require('merge');
var path = require('path');

var gulpTraceur = require('./tools/transpiler/gulp-traceur');

var clean = require('./tools/build/clean');
var transpile = require('./tools/build/transpile');
var html = require('./tools/build/html');
Expand Down Expand Up @@ -143,7 +143,8 @@ var CONFIG = {
}),
cjs: merge(true, _COMPILER_CONFIG_JS_DEFAULT, {
typeAssertionModule: 'rtts_assert/rtts_assert',
typeAssertions: true,
// Don't use type assertions since this is partly transpiled by typescript
typeAssertions: false,
modules: 'commonjs'
})
},
Expand Down Expand Up @@ -296,6 +297,26 @@ gulp.task('build/clean.docs', clean(gulp, gulpPlugins, {
// ------------
// transpile

gulp.task('build/transpile.ts.cjs', function() {
var tsResult = gulp.src(CONFIG.transpile.src.ts)
.pipe(sourcemaps.init())
.pipe(tsc({
target: 'ES5',
module: /*system.js*/'commonjs',
allowNonTsExtensions: false,
typescript: require('typescript'),
//declarationFiles: true,
noEmitOnError: true
}));
var dest = gulp.dest(CONFIG.dest.js.cjs);
return merge([
// Write external sourcemap next to the js file
tsResult.js.pipe(sourcemaps.write('.')).pipe(dest),
tsResult.js.pipe(dest),
tsResult.dts.pipe(dest),
]);
});

gulp.task('build/transpile.js.dev.es6', transpile(gulp, gulpPlugins, {
src: CONFIG.transpile.src.js,
dest: CONFIG.dest.js.dev.es6,
Expand All @@ -314,8 +335,7 @@ gulp.task('build/transpile.ts.dev.es5', function() {
module: 'commonjs',
typescript: require('typescript'),
noEmitOnError: true
}))
.js;
}));
return merge([
tsResult.js.pipe(sourcemaps.write('.'))
.pipe(gulp.dest(CONFIG.dest.js.dev.es5)),
Expand Down Expand Up @@ -524,14 +544,19 @@ gulp.task('build/pubbuild.dart', pubbuild(gulp, gulpPlugins, {
}));

// ------------
// format dart
// formatting

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

gulp.task('check-format', function() {
return gulp.src(['modules/**/*.ts', '!**/typings/**/*.d.ts'])
.pipe(format.checkFormat('file'));
});

// ------------
// check circular dependencies in Node.js context
gulp.task('build/checkCircularDependencies', function (done) {
Expand Down Expand Up @@ -786,6 +811,9 @@ gulp.task('build.js.prod', function(done) {
gulp.task('build.js.cjs', function(done) {
runSequence(
['build/transpile.js.cjs', 'build/copy.js.cjs', 'build/multicopy.js.cjs'],
// Overwrite the .js.cjs transpilation with typescript outputs
// We still need traceur outputs everywhere else, for now.
'build/transpile.ts.cjs',
['build/linknodemodules.js.cjs'],
'build/transformCJSTests',
done
Expand Down
23 changes: 23 additions & 0 deletions modules/angular2/globals.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/**
* This file contains declarations of global symbols we reference in our code
*/

declare var assert: any;
declare var global: Window;
type int = number;

interface List<T> extends Array<T> {}

interface Window {
Object: typeof Object;
Array: typeof Array;
Map: typeof Map;
Set: typeof Set;
Date: typeof Date;
RegExp: typeof RegExp;
JSON: typeof JSON;
Math: typeof Math;
assert: typeof assert;
NaN: typeof NaN;
gc(): void;
}
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export class CompileElement {
this.ignoreBindings = false;
this.contentTagSelector = null;
// description is calculated here as compilation steps may change the element
var tplDesc = assertionsEnabled()? getElementDescription(element) : null;
var tplDesc = getElementDescription(element);
if (compilationUnit !== '') {
this.elementDescription = compilationUnit;
if (isPresent(tplDesc)) this.elementDescription += ": " + tplDesc;
Expand Down
83 changes: 83 additions & 0 deletions modules/angular2/src/facade/async.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/// <reference path="../../typings/es6-promise/es6-promise.d.ts" />
/// <reference path="../../typings/rx/rx.all.d.ts" />

// HACK: workaround for Traceur behavior.
// It expects all transpiled modules to contain this marker.
// TODO: remove this when we no longer use traceur
export var __esModule = true;

import {int, global, isPresent} from 'angular2/src/facade/lang';
import {List} from 'angular2/src/facade/collection';
import * as Rx from 'rx';

export class PromiseWrapper {
static resolve(obj): Promise<any> { return Promise.resolve(obj); }

static reject(obj): Promise<any> { return Promise.reject(obj); }

// Note: We can't rename this method into `catch`, as this is not a valid
// method name in Dart.
static catchError<T>(promise: Promise<T>, onError: (error: any) => T | Thenable<T>): Promise<T> {
return promise.catch(onError);
}

static all(promises: List<Promise<any>>): Promise<any> {
if (promises.length == 0) return Promise.resolve([]);
return Promise.all(promises);
}

static then<T>(promise: Promise<T>, success: (value: any) => T | Thenable<T>,
rejection: (error: any) => T | Thenable<T>): Promise<T> {
return promise.then(success, rejection);
}

static completer() {
var resolve;
var reject;

var p = new Promise(function(res, rej) {
resolve = res;
reject = rej;
});

return {promise: p, resolve: resolve, reject: reject};
}

static setTimeout(fn: Function, millis: int) { global.setTimeout(fn, millis); }

static isPromise(maybePromise): boolean { return maybePromise instanceof Promise; }
}


/**
* Use Rx.Observable but provides an adapter to make it work as specified here:
* https://github.com/jhusain/observable-spec
*
* Once a reference implementation of the spec is available, switch to it.
*/
type Observable = Rx.Observable<any>;
type ObservableController = Rx.Subject<any>;

export class ObservableWrapper {
static createController(): Rx.Subject<any> { return new Rx.Subject(); }

static createObservable<T>(subject: Rx.Subject<T>): Rx.Observable<T> { return subject; }

static subscribe(observable: Rx.Observable<any>, generatorOrOnNext, onThrow = null,
onReturn = null) {
if (isPresent(generatorOrOnNext.next)) {
return observable.observeOn(Rx.Scheduler.timeout)
.subscribe((value) => generatorOrOnNext.next(value),
(error) => generatorOrOnNext.throw(error), () => generatorOrOnNext.return ());
} else {
return observable.observeOn(Rx.Scheduler.timeout)
.subscribe(generatorOrOnNext, onThrow, onReturn);
}
}

static callNext(subject: Rx.Subject<any>, value: any) { subject.onNext(value); }

static callThrow(subject: Rx.Subject<any>, error: any) { subject.onError(error); }

static callReturn(subject: Rx.Subject<any>) { subject.onCompleted(); }
}
14 changes: 14 additions & 0 deletions modules/angular2/src/facade/browser.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/**
* JS version of browser APIs. This library can only run in the browser.
*/
// HACK: workaround for Traceur behavior.
// It expects all transpiled modules to contain this marker.
// TODO: remove this when we no longer use traceur
export var __esModule = true;

var win = window;

export {win as window};
export var document = window.document;
export var location = window.location;
export var gc = window.gc ? () => window.gc() : () => null;
Loading

0 comments on commit 894a0f0

Please sign in to comment.