fix(transpile): fix usage of int and references to assert module

This commit is contained in:
Tobias Bosch
2015-02-06 17:18:49 -08:00
parent f39c6dc2c7
commit 6f59f2f5a3
4 changed files with 30 additions and 53 deletions
+2 -2
View File
@@ -166,8 +166,8 @@ export class ListWrapper {
static isEmpty(list) {
return list.length == 0;
}
static fill(list:List, value, start:int = 0, end:int = undefined) {
list.fill(value, start, end);
static fill(list:List, value, start:int = 0, end:int = null) {
list.fill(value, start, end === null ? undefined: end);
}
static equals(a:List, b:List):boolean {
if(a.length != b.length) return false;
+27 -20
View File
@@ -1,12 +1,24 @@
import {assert} from 'rtts_assert/rtts_assert';
export {proxy} from 'rtts_assert/rtts_assert';
export var Type = Function;
export var Math = window.Math;
var assertionsEnabled_ = typeof assert !== 'undefined';
var int;
// global assert support, as Dart has it...
// TODO: `assert` calls need to be removed in production code!
window.assert = assert;
if (assertionsEnabled_) {
window.assert = assert;
// `int` is not a valid JS type
int = assert.define('int', function(value) {
return typeof value === 'number' && value%1 === 0;
});
} else {
int = {};
window.assert = function() {};
}
export {int};
export class FIELD {
constructor(definition) {
@@ -71,8 +83,8 @@ export class StringWrapper {
return s.startsWith(start);
}
static substring(s:string, start:int, end:int = undefined) {
return s.substring(start, end);
static substring(s:string, start:int, end:int = null) {
return s.substring(start, end === null ? undefined: end);
}
static replaceAllMapped(s:string, from:RegExp, cb:Function): string {
@@ -157,18 +169,18 @@ export class NumberWrapper {
}
}
export function int() {};
int.assert = function(value) {
return value == null || typeof value == 'number' && value === Math.floor(value);
var RegExp;
if (assertionsEnabled_) {
RegExp = assert.define('RegExp', function(obj) {
assert(obj).is(assert.structure({
single: window.RegExp,
multiple: window.RegExp
}));
});
} else {
RegExp = {};
}
export var RegExp = assert.define('RegExp', function(obj) {
assert(obj).is(assert.structure({
single: window.RegExp,
multiple: window.RegExp
}));
});
export class RegExpWrapper {
static create(regExpStr, flags:string = ''):RegExp {
flags = flags.replace(/g/g, '');
@@ -224,12 +236,7 @@ export function isJsObject(o):boolean {
}
export function assertionsEnabled():boolean {
try {
var x:int = "string";
return false;
} catch (e) {
return true;
}
return assertionsEnabled_;
}
export function print(obj) {