Skip to content

Commit 6f59f2f

Browse files
committed
fix(transpile): fix usage of int and references to assert module
1 parent f39c6dc commit 6f59f2f

4 files changed

Lines changed: 30 additions & 53 deletions

File tree

modules/angular2/src/facade/collection.es6

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,8 +166,8 @@ export class ListWrapper {
166166
static isEmpty(list) {
167167
return list.length == 0;
168168
}
169-
static fill(list:List, value, start:int = 0, end:int = undefined) {
170-
list.fill(value, start, end);
169+
static fill(list:List, value, start:int = 0, end:int = null) {
170+
list.fill(value, start, end === null ? undefined: end);
171171
}
172172
static equals(a:List, b:List):boolean {
173173
if(a.length != b.length) return false;

modules/angular2/src/facade/lang.es6

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,24 @@
1-
import {assert} from 'rtts_assert/rtts_assert';
21
export {proxy} from 'rtts_assert/rtts_assert';
32

43
export var Type = Function;
54
export var Math = window.Math;
65

6+
var assertionsEnabled_ = typeof assert !== 'undefined';
7+
8+
var int;
79
// global assert support, as Dart has it...
810
// TODO: `assert` calls need to be removed in production code!
9-
window.assert = assert;
11+
if (assertionsEnabled_) {
12+
window.assert = assert;
13+
// `int` is not a valid JS type
14+
int = assert.define('int', function(value) {
15+
return typeof value === 'number' && value%1 === 0;
16+
});
17+
} else {
18+
int = {};
19+
window.assert = function() {};
20+
}
21+
export {int};
1022

1123
export class FIELD {
1224
constructor(definition) {
@@ -71,8 +83,8 @@ export class StringWrapper {
7183
return s.startsWith(start);
7284
}
7385

74-
static substring(s:string, start:int, end:int = undefined) {
75-
return s.substring(start, end);
86+
static substring(s:string, start:int, end:int = null) {
87+
return s.substring(start, end === null ? undefined: end);
7688
}
7789

7890
static replaceAllMapped(s:string, from:RegExp, cb:Function): string {
@@ -157,18 +169,18 @@ export class NumberWrapper {
157169
}
158170
}
159171

160-
export function int() {};
161-
int.assert = function(value) {
162-
return value == null || typeof value == 'number' && value === Math.floor(value);
172+
var RegExp;
173+
if (assertionsEnabled_) {
174+
RegExp = assert.define('RegExp', function(obj) {
175+
assert(obj).is(assert.structure({
176+
single: window.RegExp,
177+
multiple: window.RegExp
178+
}));
179+
});
180+
} else {
181+
RegExp = {};
163182
}
164183

165-
export var RegExp = assert.define('RegExp', function(obj) {
166-
assert(obj).is(assert.structure({
167-
single: window.RegExp,
168-
multiple: window.RegExp
169-
}));
170-
});
171-
172184
export class RegExpWrapper {
173185
static create(regExpStr, flags:string = ''):RegExp {
174186
flags = flags.replace(/g/g, '');
@@ -224,12 +236,7 @@ export function isJsObject(o):boolean {
224236
}
225237

226238
export function assertionsEnabled():boolean {
227-
try {
228-
var x:int = "string";
229-
return false;
230-
} catch (e) {
231-
return true;
232-
}
239+
return assertionsEnabled_;
233240
}
234241

235242
export function print(obj) {

modules/rtts_assert/src/rtts_assert.es6

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -230,13 +230,6 @@ function returnType(actual, T) {
230230
return actual;
231231
}
232232

233-
// `int` is not a valid JS type, and traceur will leave
234-
// it untouched. However, we want to be able to use it,
235-
// so we provide it as a global
236-
var intType = _global['int'] = define('int', function(value) {
237-
return typeof value === 'number' && value%1 === 0;
238-
});
239-
240233
// TODO(vojta): define these with DSL?
241234
var string = type.string = define('string', function(value) {
242235
return typeof value === 'string';
@@ -362,7 +355,6 @@ assert.fail = fail;
362355
assert.string = string;
363356
assert.number = number;
364357
assert.boolean = boolean;
365-
assert.int = intType;
366358

367359
// custom types
368360
assert.arrayOf = arrayOf;

modules/rtts_assert/test/rtts_assert_spec.es6

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@
1010
// - [assert.structure](#assert-structure)
1111
// - [Integrating with Traceur](#integrating-with-traceur)
1212

13-
import {assert} from 'rtts_assert/rtts_assert';
14-
13+
// Note: `assert` gets automatically included by traceur!
1514

1615
export function main() {
1716

@@ -370,27 +369,6 @@ describe('Traceur', function() {
370369
});
371370
});
372371

373-
// Note: `int` is not part of JS types, but rtts_assert exposes a global
374-
// so that it can be used as well.
375-
describe('int', function() {
376-
377-
it('should pass', function() {
378-
var x:int = 10;
379-
});
380-
381-
it('should fail', function() {
382-
expect(() => {
383-
var x:int = 'ok';
384-
}).toThrowError('Expected an instance of int, got "ok"!');
385-
});
386-
387-
it('should fail', function() {
388-
expect(() => {
389-
var x:int = 12.3;
390-
}).toThrowError('Expected an instance of int, got 12.3!');
391-
});
392-
393-
});
394372

395373
describe('generics', function() {
396374

0 commit comments

Comments
 (0)