refactor(ts'ify): ts’ify mocks, directives and test_lib

Also cleans up global types.
This commit is contained in:
Tobias Bosch
2015-05-20 17:19:46 -07:00
parent c5996529c3
commit aec51d616b
51 changed files with 610 additions and 671 deletions
+1 -1
View File
@@ -1,7 +1,7 @@
/// <reference path="../../typings/es6-promise/es6-promise.d.ts" />
/// <reference path="../../typings/rx/rx.all.d.ts" />
import {int, global, isPresent} from 'angular2/src/facade/lang';
import {global, isPresent} from 'angular2/src/facade/lang';
import {List} from 'angular2/src/facade/collection';
import * as Rx from 'rx';
+1 -1
View File
@@ -6,7 +6,7 @@ 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;
export var gc = window['gc'] ? () => window['gc']() : () => null;
export const Event = Event;
export const MouseEvent = MouseEvent;
export const KeyboardEvent = KeyboardEvent;
+1 -1
View File
@@ -1,4 +1,4 @@
import {int, isJsObject, global} from 'angular2/src/facade/lang';
import {isJsObject, global} from 'angular2/src/facade/lang';
export var List = global.Array;
export var Map = global.Map;
+14 -21
View File
@@ -1,4 +1,4 @@
var _global = typeof window === 'undefined' ? global : window;
var _global: BrowserNodeGlobal = <any>(typeof window === 'undefined' ? global : window);
export {_global as global};
export var Type = Function;
@@ -19,23 +19,20 @@ export class BaseException extends Error {
export var Math = _global.Math;
export var Date = _global.Date;
var assertionsEnabled_ = typeof assert !== 'undefined';
var int;
// global assert support, as Dart has it...
// TODO: `assert` calls need to be removed in production code!
if (assertionsEnabled_) {
_global.assert = assert;
// `int` is not a valid JS type
int = assert.define('int',
function(value) { return typeof value === 'number' && value % 1 === 0; });
} else {
int = {};
_global.assert = function() {};
var assertionsEnabled_ = typeof _global['assert'] !== 'undefined';
export function assertionsEnabled(): boolean {
return assertionsEnabled_;
}
export {int};
// TODO: remove calls to assert in production environment
// Note: Can't just export this and import in in other files
// as `assert` is a reserved keyword in Dart
_global.assert =
function assert(condition) {
if (assertionsEnabled_) {
_global['assert'].call(condition);
}
}
// This function is needed only to properly support Dart's const expressions
// see https://github.com/angular/ts2dart/pull/151 for more info
export function CONST_EXPR<T>(expr: T): T {
@@ -114,7 +111,7 @@ export class StringWrapper {
}
static replaceAllMapped(s: string, from: RegExp, cb: Function): string {
return s.replace(from, function(...matches) {
return s.replace(from, function(... matches) {
// Remove offset & string from the result array
matches.splice(-2, 2);
// The callback receives match, p1, ..., pn
@@ -232,10 +229,6 @@ export function isJsObject(o): boolean {
return o !== null && (typeof o === "function" || typeof o === "object");
}
export function assertionsEnabled(): boolean {
return assertionsEnabled_;
}
export function print(obj) {
if (obj instanceof Error) {
console.log(obj.stack);