inline traceur tests, removing git submodules
This commit is contained in:
parent
57fd619c76
commit
1a4f18aab7
3
.gitmodules
vendored
3
.gitmodules
vendored
@ -1,3 +0,0 @@
|
|||||||
[submodule "vendor/traceur"]
|
|
||||||
path = vendor/traceur
|
|
||||||
url = https://github.com/google/traceur-compiler
|
|
||||||
1
packages/babel/test/fixtures/traceur
vendored
1
packages/babel/test/fixtures/traceur
vendored
@ -1 +0,0 @@
|
|||||||
../../../../vendor/traceur/test/feature
|
|
||||||
12
packages/babel/test/fixtures/traceur/ArrayComprehension/ArgumentsInComprehension.js
vendored
Normal file
12
packages/babel/test/fixtures/traceur/ArrayComprehension/ArgumentsInComprehension.js
vendored
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
// Options: --array-comprehension
|
||||||
|
// https://github.com/google/traceur-compiler/issues/1086
|
||||||
|
|
||||||
|
function f() {
|
||||||
|
var a = [for (x of [1]) arguments[0]];
|
||||||
|
var b = [for (x of [1]) arguments[0]];
|
||||||
|
assert.deepEqual(a, [arguments[0]]);
|
||||||
|
assert.deepEqual(a, [42]);
|
||||||
|
assert.deepEqual(a, b);
|
||||||
|
}
|
||||||
|
|
||||||
|
f(42);
|
||||||
11
packages/babel/test/fixtures/traceur/ArrayComprehension/Closure.js
vendored
Normal file
11
packages/babel/test/fixtures/traceur/ArrayComprehension/Closure.js
vendored
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
// Options: --array-comprehension --block-binding
|
||||||
|
// Block binding is needed to get the right scoping semantics inside the arrow
|
||||||
|
// function in the comprehension.
|
||||||
|
|
||||||
|
var res = [for (x of [0, 1]) for (y of [2, 3]) () => [x, y]];
|
||||||
|
|
||||||
|
assert.equal(4, res.length);
|
||||||
|
assertArrayEquals([0, 2], res[0]());
|
||||||
|
assertArrayEquals([0, 3], res[1]());
|
||||||
|
assertArrayEquals([1, 2], res[2]());
|
||||||
|
assertArrayEquals([1, 3], res[3]());
|
||||||
4
packages/babel/test/fixtures/traceur/ArrayComprehension/Error_Disabled.js
vendored
Normal file
4
packages/babel/test/fixtures/traceur/ArrayComprehension/Error_Disabled.js
vendored
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
// Options: --array-comprehension=false
|
||||||
|
// Error: :4:14: Unexpected reserved word for
|
||||||
|
|
||||||
|
var array = [for (x of [0, 1, 2, 3, 4]) x];
|
||||||
5
packages/babel/test/fixtures/traceur/ArrayComprehension/Error_NotDefined.js
vendored
Normal file
5
packages/babel/test/fixtures/traceur/ArrayComprehension/Error_NotDefined.js
vendored
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
// Options: --array-comprehension --free-variable-checker
|
||||||
|
// Error: :5:1: notDefined is not defined
|
||||||
|
|
||||||
|
var array = [for (notDefined of [0]) notDefined];
|
||||||
|
notDefined;
|
||||||
32
packages/babel/test/fixtures/traceur/ArrayComprehension/Simple.js
vendored
Normal file
32
packages/babel/test/fixtures/traceur/ArrayComprehension/Simple.js
vendored
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
// Options: --array-comprehension
|
||||||
|
|
||||||
|
function* range() {
|
||||||
|
for (var i = 0; i < 5; i++) {
|
||||||
|
yield i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var array = [for (x of [0, 1, 2, 3]) x];
|
||||||
|
assertArrayEquals([0, 1, 2, 3], array);
|
||||||
|
|
||||||
|
var array2 = [for (x of [0, 1, 2]) for (y of [0, 1, 2]) x + '' + y];
|
||||||
|
assertArrayEquals(['00', '01', '02', '10', '11', '12', '20', '21', '22'],
|
||||||
|
array2);
|
||||||
|
|
||||||
|
var array3 = [
|
||||||
|
for (x of [0, 1, 2, 3, 4])
|
||||||
|
for (y of range())
|
||||||
|
if (x === y)
|
||||||
|
x + '' + y];
|
||||||
|
assertArrayEquals(['00', '11', '22', '33', '44'], array3);
|
||||||
|
|
||||||
|
// Ensure this works as expression statement
|
||||||
|
[for (testVar of []) testVar];
|
||||||
|
|
||||||
|
var array4 = [
|
||||||
|
for (x of range())
|
||||||
|
if (x % 2 === 0)
|
||||||
|
for (y of range())
|
||||||
|
if (y % 2 === 1)
|
||||||
|
x + '' + y];
|
||||||
|
assertArrayEquals(['01', '03', '21', '23', '41', '43'], array4);
|
||||||
14
packages/babel/test/fixtures/traceur/ArrayComprehension/ThisInComprehension.js
vendored
Normal file
14
packages/babel/test/fixtures/traceur/ArrayComprehension/ThisInComprehension.js
vendored
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
// Options: --array-comprehension
|
||||||
|
// https://github.com/google/traceur-compiler/issues/1086
|
||||||
|
|
||||||
|
var object = {};
|
||||||
|
|
||||||
|
function f() {
|
||||||
|
var a = [for (x of [1]) this];
|
||||||
|
var b = [for (x of [1]) this];
|
||||||
|
assert.deepEqual(a, [this]);
|
||||||
|
assert.deepEqual(a, [object]);
|
||||||
|
assert.deepEqual(a, b);
|
||||||
|
}
|
||||||
|
|
||||||
|
f.call(object);
|
||||||
47
packages/babel/test/fixtures/traceur/ArrayExtras/Fill.js
vendored
Normal file
47
packages/babel/test/fixtures/traceur/ArrayExtras/Fill.js
vendored
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
// should have a length of 1
|
||||||
|
assert.equal(Array.prototype.fill.length, 1);
|
||||||
|
|
||||||
|
// should fill from basic case
|
||||||
|
assert.deepEqual([1, 2, 3].fill(5), [5, 5, 5]);
|
||||||
|
|
||||||
|
// should fill from start
|
||||||
|
assert.deepEqual([1, 2, 3].fill(5, 1), [1, 5, 5]);
|
||||||
|
|
||||||
|
// should fill from start to end
|
||||||
|
assert.deepEqual([1, 2, 3].fill(5, 1, 2), [1, 5, 3]);
|
||||||
|
|
||||||
|
// should fill from negative start
|
||||||
|
assert.deepEqual([1, 2, 3].fill(5, -1), [1, 2, 5]);
|
||||||
|
|
||||||
|
// should fill from negative start to positive end
|
||||||
|
assert.deepEqual([1, 2, 3].fill(5, -2, 3), [1, 5, 5]);
|
||||||
|
|
||||||
|
// should fill from negative start to negative end
|
||||||
|
assert.deepEqual([1, 2, 3].fill(5, -3, -1), [5, 5, 3]);
|
||||||
|
|
||||||
|
// should fill from positive start to negative end
|
||||||
|
assert.deepEqual([1, 2, 3].fill(5, 1, -1), [1, 5, 3]);
|
||||||
|
|
||||||
|
// should fill custom object
|
||||||
|
assert.deepEqual(Array.prototype.fill.call({'0': 1, 'length': 3}, 5), {'0': 5, '1': 5, '2': 5, 'length': 3});
|
||||||
|
|
||||||
|
// should handle custom object with negative length
|
||||||
|
assert.deepEqual(Array.prototype.fill.call({'0': 2, 'length': -1}, 5), {'0': 2, 'length': -1});
|
||||||
|
|
||||||
|
// should handle no elements
|
||||||
|
assert.deepEqual([].fill(5), []);
|
||||||
|
|
||||||
|
// should handle bad start
|
||||||
|
assert.deepEqual([1, 2, 3].fill(5, 'hello'), [5, 5, 5]);
|
||||||
|
|
||||||
|
// should handle bad end
|
||||||
|
assert.deepEqual([1, 2, 3].fill(5, 1, {}), [1, 2, 3]);
|
||||||
|
|
||||||
|
// should handle bad start and end
|
||||||
|
assert.deepEqual([1, 2, 3].fill(5, 'hello', {}), [1, 2, 3]);
|
||||||
|
|
||||||
|
|
||||||
|
// should handle bad this
|
||||||
|
assert.throws(function() {
|
||||||
|
Array.prototype.fill.call(null, 5)
|
||||||
|
}, TypeError);
|
||||||
88
packages/babel/test/fixtures/traceur/ArrayExtras/Find.js
vendored
Normal file
88
packages/babel/test/fixtures/traceur/ArrayExtras/Find.js
vendored
Normal file
@ -0,0 +1,88 @@
|
|||||||
|
// should have a length of 1
|
||||||
|
assert.equal(Array.prototype.find.length, 1);
|
||||||
|
|
||||||
|
// should handle basic case
|
||||||
|
assert.equal([1, 2, 3].find(function(v) {
|
||||||
|
return v * v === 4;
|
||||||
|
}), 2);
|
||||||
|
|
||||||
|
// should handle arrow functions
|
||||||
|
assert.equal([1, 2, 3].find(v => v * v === 4), 2);
|
||||||
|
|
||||||
|
// should return undefined when not found
|
||||||
|
assert.equal([1, 2, 3].find(v => v > 10), undefined);
|
||||||
|
|
||||||
|
// should return first match
|
||||||
|
assert.equal([2, 2, 3].find(v => v * v === 4), 2);
|
||||||
|
|
||||||
|
// should handle custom objects
|
||||||
|
assert.equal(Array.prototype.find.call({
|
||||||
|
'length': 2,
|
||||||
|
'0': false,
|
||||||
|
'1': true
|
||||||
|
}, v => v), true);
|
||||||
|
|
||||||
|
// should handle bad predicate
|
||||||
|
assert.throws(function() {
|
||||||
|
[1, 2, 3].find(1)
|
||||||
|
}, TypeError);
|
||||||
|
|
||||||
|
// should handle bad this
|
||||||
|
assert.throws(function() {
|
||||||
|
Array.prototype.find.call(null, function() {})
|
||||||
|
}, TypeError);
|
||||||
|
|
||||||
|
// should correctly handle this
|
||||||
|
var global = this;
|
||||||
|
({
|
||||||
|
assert: function() {
|
||||||
|
var self = this;
|
||||||
|
|
||||||
|
// should be global this
|
||||||
|
[1, 2, 3].find(function() {
|
||||||
|
assert.notEqual(this, self);
|
||||||
|
assert.equal(this, global);
|
||||||
|
});
|
||||||
|
|
||||||
|
// should be the same this
|
||||||
|
[1, 2, 3].find(function() {
|
||||||
|
assert.equal(this, self);
|
||||||
|
}, self);
|
||||||
|
|
||||||
|
// should not have an effect on arrow functions
|
||||||
|
[1, 2, 3].find(() => assert.equal(this, self));
|
||||||
|
[1, 2, 3].find(() => assert.equal(this, self), self);
|
||||||
|
|
||||||
|
// should call with correct args
|
||||||
|
var arr = [5];
|
||||||
|
arr.find(function(value, i, object) {
|
||||||
|
assert.equal(value, 5);
|
||||||
|
assert.equal(i, 0);
|
||||||
|
assert.equal(arr, object);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}).assert();
|
||||||
|
|
||||||
|
var lengthCalls = 0;
|
||||||
|
var itemCalls = 0;
|
||||||
|
var callbackCalls = 0;
|
||||||
|
var object = {
|
||||||
|
length: {
|
||||||
|
valueOf() {
|
||||||
|
lengthCalls++;
|
||||||
|
return 3;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
get 2() {
|
||||||
|
itemCalls++;
|
||||||
|
return 'a';
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
assert.equal(Array.prototype.find.call(object, (v) => {
|
||||||
|
callbackCalls++;
|
||||||
|
return v === 'a';
|
||||||
|
}), 'a');
|
||||||
|
assert.equal(lengthCalls, 1);
|
||||||
|
assert.equal(itemCalls, 1);
|
||||||
|
assert.equal(callbackCalls, 3);
|
||||||
47
packages/babel/test/fixtures/traceur/ArrayExtras/FindIndex.js
vendored
Normal file
47
packages/babel/test/fixtures/traceur/ArrayExtras/FindIndex.js
vendored
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
// should have a length of 1
|
||||||
|
assert.equal(Array.prototype.findIndex.length, 1);
|
||||||
|
|
||||||
|
// should handle basic case
|
||||||
|
assert.equal([1, 2, 3].findIndex(function(v) {
|
||||||
|
return v * v === 4;
|
||||||
|
}), 1);
|
||||||
|
|
||||||
|
// should handle arrow functions
|
||||||
|
assert.equal([1, 2, 3].findIndex(v => v * v === 4), 1);
|
||||||
|
|
||||||
|
// should return -1 when not found
|
||||||
|
assert.equal([1, 2, 3].findIndex(v => v > 10), -1);
|
||||||
|
|
||||||
|
// should return first match
|
||||||
|
assert.equal([2, 2, 3].findIndex(v => v * v === 4), 0);
|
||||||
|
|
||||||
|
// should handle custom objects
|
||||||
|
assert.equal(Array.prototype.findIndex.call({
|
||||||
|
'length': 2,
|
||||||
|
'0': false,
|
||||||
|
'1': true
|
||||||
|
}, v => v), 1);
|
||||||
|
|
||||||
|
var lengthCalls = 0;
|
||||||
|
var itemCalls = 0;
|
||||||
|
var callbackCalls = 0;
|
||||||
|
var object = {
|
||||||
|
length: {
|
||||||
|
valueOf() {
|
||||||
|
lengthCalls++;
|
||||||
|
return 3;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
get 2() {
|
||||||
|
itemCalls++;
|
||||||
|
return 'a';
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
assert.equal(Array.prototype.findIndex.call(object, (v) => {
|
||||||
|
callbackCalls++;
|
||||||
|
return v === 'a';
|
||||||
|
}), 2);
|
||||||
|
assert.equal(lengthCalls, 1);
|
||||||
|
assert.equal(itemCalls, 1);
|
||||||
|
assert.equal(callbackCalls, 3);
|
||||||
158
packages/babel/test/fixtures/traceur/ArrayExtras/From.js
vendored
Normal file
158
packages/babel/test/fixtures/traceur/ArrayExtras/From.js
vendored
Normal file
@ -0,0 +1,158 @@
|
|||||||
|
// should have a length of 1
|
||||||
|
assert.equal(Array.from.length, 1);
|
||||||
|
var arr;
|
||||||
|
var obj;
|
||||||
|
|
||||||
|
// should make an array from arguments
|
||||||
|
function arrayFromArgs() {
|
||||||
|
return Array.from(arguments);
|
||||||
|
}
|
||||||
|
arr = arrayFromArgs('a', 1);
|
||||||
|
|
||||||
|
assert.equal(arr.length, 2);
|
||||||
|
assert.deepEqual(arr, ['a', 1]);
|
||||||
|
assert.isTrue(Array.isArray(arr));
|
||||||
|
|
||||||
|
// should handle undefined values
|
||||||
|
var arrayLike = {0: 'a', 2: 'c', length: 3};
|
||||||
|
arr = Array.from(arrayLike);
|
||||||
|
|
||||||
|
assert.equal(arr.length, 3);
|
||||||
|
assert.deepEqual(arr, ['a', undefined, 'c']);
|
||||||
|
assert.isTrue(Array.isArray(arr));
|
||||||
|
|
||||||
|
// should use a mapFn
|
||||||
|
arr = Array.from([{'a': 1}, {'a': 2}], function(item, i) {
|
||||||
|
return item.a + i;
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.deepEqual(arr, [1, 3]);
|
||||||
|
|
||||||
|
// should set this in mapFn
|
||||||
|
var thisObj = {a: 10};
|
||||||
|
arr = Array.from([{'a': 1}, {'a': 2}], function(item, i) {
|
||||||
|
return this.a + item.a + i;
|
||||||
|
}, thisObj);
|
||||||
|
|
||||||
|
assert.deepEqual(arr, [11, 13]);
|
||||||
|
|
||||||
|
// should map on array-like object
|
||||||
|
arr = Array.from({0: {'a': 5}, length: 1}, function(item, i) {
|
||||||
|
return item.a + i;
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.deepEqual(arr, [5]);
|
||||||
|
|
||||||
|
// should throw on bad map fn
|
||||||
|
assert.throws(function() {
|
||||||
|
Array.from([], null)
|
||||||
|
}, TypeError);
|
||||||
|
|
||||||
|
// should make from an array-like object
|
||||||
|
var arrayLikeObj = function(len) {
|
||||||
|
this.length = len;
|
||||||
|
};
|
||||||
|
arrayLikeObj.from = Array.from;
|
||||||
|
obj = arrayLikeObj.from(['a', 'b', 'c']);
|
||||||
|
|
||||||
|
assert.equal(obj.length, 3);
|
||||||
|
assert.deepEqual(obj, {0: 'a', 1: 'b', 2: 'c', length: 3});
|
||||||
|
|
||||||
|
// should make from a non-array iterable
|
||||||
|
var calledIterator = 0;
|
||||||
|
var Iterable = function(len) {
|
||||||
|
var self = this;
|
||||||
|
|
||||||
|
self.length = len;
|
||||||
|
self[Symbol.iterator] = function*() {
|
||||||
|
for (var i = 0; i < self.length; i++) {
|
||||||
|
calledIterator++;
|
||||||
|
yield self[i];
|
||||||
|
}
|
||||||
|
};
|
||||||
|
};
|
||||||
|
var it = new Iterable(3);
|
||||||
|
it[0] = 'a';
|
||||||
|
it[1] = 'b';
|
||||||
|
it[2] = 'c';
|
||||||
|
obj = Array.from(it);
|
||||||
|
|
||||||
|
assert.equal(obj.length, 3);
|
||||||
|
assert.equal(obj[0], 'a');
|
||||||
|
assert.equal(obj[1], 'b');
|
||||||
|
assert.equal(obj[2], 'c');
|
||||||
|
assert.equal(calledIterator, 3);
|
||||||
|
|
||||||
|
// should make from a sub-classed array
|
||||||
|
var length = 0;
|
||||||
|
var constructorCounter = 0;
|
||||||
|
var lengthSetCounter = 0;
|
||||||
|
var lengthGetCounter = 0;
|
||||||
|
|
||||||
|
class MyArray extends Array {
|
||||||
|
constructor(v) {
|
||||||
|
super();
|
||||||
|
constructorCounter++;
|
||||||
|
assert.isUndefined(v);
|
||||||
|
}
|
||||||
|
|
||||||
|
set length(v) {
|
||||||
|
lengthSetCounter++;
|
||||||
|
length = v;
|
||||||
|
}
|
||||||
|
|
||||||
|
get length() {
|
||||||
|
lengthGetCounter++;
|
||||||
|
return length;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var ma = MyArray.from(['a', 'b']);
|
||||||
|
assert.instanceOf(ma, MyArray);
|
||||||
|
assert.equal(constructorCounter, 1);
|
||||||
|
assert.equal(lengthSetCounter, 1);
|
||||||
|
assert.equal(lengthGetCounter, 0);
|
||||||
|
assert.isTrue(ma.hasOwnProperty('0'));
|
||||||
|
assert.isTrue(ma.hasOwnProperty('1'));
|
||||||
|
assert.isFalse(ma.hasOwnProperty('length'));
|
||||||
|
assert.equal(ma[0], 'a');
|
||||||
|
assert.equal(ma[1], 'b');
|
||||||
|
assert.equal(ma.length, 2);
|
||||||
|
|
||||||
|
// should make from a sub-classed array without iterable
|
||||||
|
length = 0;
|
||||||
|
constructorCounter = 0;
|
||||||
|
lengthSetCounter = 0;
|
||||||
|
lengthGetCounter = 0;
|
||||||
|
|
||||||
|
class MyArray2 extends MyArray {
|
||||||
|
constructor(v) {
|
||||||
|
super();
|
||||||
|
constructorCounter++;
|
||||||
|
assert.equal(v, 2);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
MyArray2.prototype[Symbol.iterator] = undefined;
|
||||||
|
|
||||||
|
class MyArray3 extends Array {
|
||||||
|
constructor(v) {
|
||||||
|
super();
|
||||||
|
this.length = v;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
MyArray3.prototype[Symbol.iterator] = undefined;
|
||||||
|
|
||||||
|
var ma3 = new MyArray3(2);
|
||||||
|
ma3[0] = 'a';
|
||||||
|
ma3[1] = 'b';
|
||||||
|
ma = MyArray2.from(ma3);
|
||||||
|
assert.instanceOf(ma, MyArray2);
|
||||||
|
assert.equal(constructorCounter, 2);
|
||||||
|
assert.equal(lengthSetCounter, 1);
|
||||||
|
assert.equal(lengthGetCounter, 0);
|
||||||
|
assert.isTrue(ma.hasOwnProperty('0'));
|
||||||
|
assert.isTrue(ma.hasOwnProperty('1'));
|
||||||
|
assert.isFalse(ma.hasOwnProperty('length'));
|
||||||
|
assert.equal(ma[0], 'a');
|
||||||
|
assert.equal(ma[1], 'b');
|
||||||
|
assert.equal(ma.length, 2);
|
||||||
37
packages/babel/test/fixtures/traceur/ArrayExtras/Of.js
vendored
Normal file
37
packages/babel/test/fixtures/traceur/ArrayExtras/Of.js
vendored
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
var arr;
|
||||||
|
|
||||||
|
// should have a length of 0
|
||||||
|
assert.equal(Array.of.length, 0);
|
||||||
|
|
||||||
|
//should return an array from arguments
|
||||||
|
arr = Array.of(1, 'a', 3);
|
||||||
|
assert.deepEqual(arr, [1, 'a', 3]);
|
||||||
|
assert.isTrue(arr instanceof Array);
|
||||||
|
|
||||||
|
//should work with no arguments
|
||||||
|
arr = Array.of();
|
||||||
|
assert.deepEqual(arr, []);
|
||||||
|
assert.isTrue(arr instanceof Array);
|
||||||
|
|
||||||
|
//should work with sub-classed array
|
||||||
|
class MyArray extends Array {}
|
||||||
|
|
||||||
|
arr = MyArray.of(4, 'b');
|
||||||
|
assert.equal(arr[0], 4);
|
||||||
|
assert.equal(arr[1], 'b');
|
||||||
|
assert.equal(arr.length, 2);
|
||||||
|
assert.isTrue(arr instanceof MyArray);
|
||||||
|
|
||||||
|
//should call with exotic array
|
||||||
|
class ExoticArray {
|
||||||
|
constructor(len) {
|
||||||
|
this.length = len;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
arr = Array.of.call(ExoticArray, 5, 'c', 6, 'd');
|
||||||
|
assert.equal(arr[0], 5);
|
||||||
|
assert.equal(arr[1], 'c');
|
||||||
|
assert.equal(arr[2], 6);
|
||||||
|
assert.equal(arr[3], 'd');
|
||||||
|
assert.equal(arr.length, 4);
|
||||||
|
assert.isTrue(arr instanceof ExoticArray);
|
||||||
27
packages/babel/test/fixtures/traceur/ArrayIterator.js
vendored
Normal file
27
packages/babel/test/fixtures/traceur/ArrayIterator.js
vendored
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
var a = ['a', 'b', 'c'];
|
||||||
|
|
||||||
|
var res = [];
|
||||||
|
for (var x of a) {
|
||||||
|
res.push(x);
|
||||||
|
}
|
||||||
|
assert.deepEqual(res, ['a', 'b', 'c']);
|
||||||
|
|
||||||
|
assert.equal(a[Symbol.iterator], a.values);
|
||||||
|
|
||||||
|
res = [];
|
||||||
|
for (var x of a.values()) {
|
||||||
|
res.push(x);
|
||||||
|
}
|
||||||
|
assert.deepEqual(res, ['a', 'b', 'c']);
|
||||||
|
|
||||||
|
res = [];
|
||||||
|
for (var x of a.keys()) {
|
||||||
|
res.push(x);
|
||||||
|
}
|
||||||
|
assert.deepEqual(res, [0, 1, 2]);
|
||||||
|
|
||||||
|
res = [];
|
||||||
|
for (var x of a.entries()) {
|
||||||
|
res.push(x);
|
||||||
|
}
|
||||||
|
assert.deepEqual(res, [[0, 'a'], [1, 'b'], [2, 'c']]);
|
||||||
22
packages/babel/test/fixtures/traceur/ArrowFunctions/AlphaRename.js
vendored
Normal file
22
packages/babel/test/fixtures/traceur/ArrowFunctions/AlphaRename.js
vendored
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
var global = this;
|
||||||
|
var self = {};
|
||||||
|
|
||||||
|
function outer() {
|
||||||
|
var f = () => {
|
||||||
|
assert.equal(this, self);
|
||||||
|
|
||||||
|
var g = () => {
|
||||||
|
assert.equal(this, self);
|
||||||
|
};
|
||||||
|
g();
|
||||||
|
|
||||||
|
var h = function() {
|
||||||
|
assert.equal(this, global);
|
||||||
|
};
|
||||||
|
h();
|
||||||
|
};
|
||||||
|
|
||||||
|
f();
|
||||||
|
}
|
||||||
|
|
||||||
|
outer.call(self);
|
||||||
42
packages/babel/test/fixtures/traceur/ArrowFunctions/AlphaRenameThisArguments.js
vendored
Normal file
42
packages/babel/test/fixtures/traceur/ArrowFunctions/AlphaRenameThisArguments.js
vendored
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
|
||||||
|
var self = {};
|
||||||
|
|
||||||
|
function f() {
|
||||||
|
(() => {
|
||||||
|
assert.equal(self, this);
|
||||||
|
assert.equal(1, arguments.length);
|
||||||
|
assert.equal(42, arguments[0]);
|
||||||
|
|
||||||
|
var THIS = 0;
|
||||||
|
var ARGUMENTS = 1;
|
||||||
|
|
||||||
|
var object = {
|
||||||
|
function: function() {
|
||||||
|
return [this, arguments];
|
||||||
|
},
|
||||||
|
method() {
|
||||||
|
return [this, arguments];
|
||||||
|
},
|
||||||
|
arrow: () => {
|
||||||
|
return [this, arguments];
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
assert.equal(object, object.function()[THIS]);
|
||||||
|
assert.equal(2, object.function('a', 'b')[ARGUMENTS].length);
|
||||||
|
assert.equal('a', object.function('a', 'b')[ARGUMENTS][0]);
|
||||||
|
assert.equal('b', object.function('a', 'b')[ARGUMENTS][1]);
|
||||||
|
|
||||||
|
assert.equal(object, object.method()[THIS]);
|
||||||
|
assert.equal(3, object.method('c', 'd', 'e')[ARGUMENTS].length);
|
||||||
|
assert.equal('c', object.method('c', 'd', 'e')[ARGUMENTS][0]);
|
||||||
|
assert.equal('d', object.method('c', 'd', 'e')[ARGUMENTS][1]);
|
||||||
|
assert.equal('e', object.method('c', 'd', 'e')[ARGUMENTS][2]);
|
||||||
|
|
||||||
|
assert.equal(self, object.arrow()[THIS]);
|
||||||
|
assert.equal(1, object.arrow('f', 'g')[ARGUMENTS].length);
|
||||||
|
assert.equal(42, object.arrow('f', 'g')[ARGUMENTS][0]);
|
||||||
|
})();
|
||||||
|
}
|
||||||
|
|
||||||
|
f.call(self, 42);
|
||||||
6
packages/babel/test/fixtures/traceur/ArrowFunctions/Arguments.js
vendored
Normal file
6
packages/babel/test/fixtures/traceur/ArrowFunctions/Arguments.js
vendored
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
function f() {
|
||||||
|
var args = (() => arguments)();
|
||||||
|
assert.equal(args, arguments);
|
||||||
|
}
|
||||||
|
|
||||||
|
f();
|
||||||
52
packages/babel/test/fixtures/traceur/ArrowFunctions/ArrowFunctions.js
vendored
Normal file
52
packages/babel/test/fixtures/traceur/ArrowFunctions/ArrowFunctions.js
vendored
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
// Options: --block-binding
|
||||||
|
|
||||||
|
// These tests are from:
|
||||||
|
// http://wiki.ecmascript.org/doku.php?id=strawman:arrow_function_syntax
|
||||||
|
|
||||||
|
let empty = () => undefined;
|
||||||
|
assert.equal(empty(), undefined);
|
||||||
|
|
||||||
|
// Expression bodies needs no parentheses or braces
|
||||||
|
let identity = (x) => x;
|
||||||
|
assert.equal(identity(empty), empty);
|
||||||
|
|
||||||
|
// Object literals needs to be wrapped in parens.
|
||||||
|
let keyMaker = (val) => ({key: val});
|
||||||
|
assert.equal(keyMaker(empty).key, empty);
|
||||||
|
|
||||||
|
// => { starts a block.
|
||||||
|
let emptyBlock = () => {a: 42};
|
||||||
|
assert.equal(emptyBlock(), undefined);
|
||||||
|
|
||||||
|
// Nullary arrow function starts with arrow (cannot begin statement)
|
||||||
|
const preamble = 'hello';
|
||||||
|
const body = 'world';
|
||||||
|
let nullary = () => preamble + ': ' + body;
|
||||||
|
assert.equal('hello: world', nullary());
|
||||||
|
|
||||||
|
// No need for parens even for lower-precedence expression body
|
||||||
|
let square = x => x * x;
|
||||||
|
assert.equal(81, square(9));
|
||||||
|
|
||||||
|
let oddArray = [];
|
||||||
|
let array = [2, 3, 4, 5, 6, 7];
|
||||||
|
array.forEach((v, i) => { if (i & 1) oddArray[i >>> 1] = v; });
|
||||||
|
assert.equal('3,5,7', oddArray.toString());
|
||||||
|
|
||||||
|
var f = (x = 42) => x;
|
||||||
|
assert.equal(42, f());
|
||||||
|
|
||||||
|
{
|
||||||
|
let g = (...xs) => xs;
|
||||||
|
assertArrayEquals([0, 1, true], g(0, 1, true));
|
||||||
|
}
|
||||||
|
|
||||||
|
var h = (x, ...xs) => xs;
|
||||||
|
assertArrayEquals([0, 1, true], h(-1, 0, 1, true));
|
||||||
|
|
||||||
|
assert.equal(typeof (() => {}), 'function');
|
||||||
|
assert.equal(Object.getPrototypeOf(() => {}), Function.prototype);
|
||||||
|
|
||||||
|
var i = ({a = 1}) => a;
|
||||||
|
assert.equal(i({}), 1);
|
||||||
|
assert.equal(i({a: 2}), 2);
|
||||||
5
packages/babel/test/fixtures/traceur/ArrowFunctions/CoverInitializer.js
vendored
Normal file
5
packages/babel/test/fixtures/traceur/ArrowFunctions/CoverInitializer.js
vendored
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
// https://github.com/google/traceur-compiler/issues/478
|
||||||
|
|
||||||
|
function f() {
|
||||||
|
(1 ? ({a=0}) => {} : 1);
|
||||||
|
}
|
||||||
5
packages/babel/test/fixtures/traceur/ArrowFunctions/Error_CoverInitializer.js
vendored
Normal file
5
packages/babel/test/fixtures/traceur/ArrowFunctions/Error_CoverInitializer.js
vendored
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
// Error: :4:16: Unexpected token =
|
||||||
|
|
||||||
|
function f() {
|
||||||
|
({a = (0, {a = 0})} = {})
|
||||||
|
}
|
||||||
3
packages/babel/test/fixtures/traceur/ArrowFunctions/Error_CoverInitializer2.js
vendored
Normal file
3
packages/babel/test/fixtures/traceur/ArrowFunctions/Error_CoverInitializer2.js
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
// Error: :3:5: Unexpected token =
|
||||||
|
|
||||||
|
({a = 0});
|
||||||
3
packages/babel/test/fixtures/traceur/ArrowFunctions/Error_CoverInitializer3.js
vendored
Normal file
3
packages/babel/test/fixtures/traceur/ArrowFunctions/Error_CoverInitializer3.js
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
// Error: :3:18: Unexpected token =
|
||||||
|
|
||||||
|
var f = ({x = {y = 1}) => 2;
|
||||||
4
packages/babel/test/fixtures/traceur/ArrowFunctions/Error_Disabled.js
vendored
Normal file
4
packages/babel/test/fixtures/traceur/ArrowFunctions/Error_Disabled.js
vendored
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
// Options: --arrow-functions=false
|
||||||
|
// Error: :4:21: Unexpected token >
|
||||||
|
|
||||||
|
var identity = (x) => x;
|
||||||
3
packages/babel/test/fixtures/traceur/ArrowFunctions/Error_FreeVariableChecker.js
vendored
Normal file
3
packages/babel/test/fixtures/traceur/ArrowFunctions/Error_FreeVariableChecker.js
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
// Options: --arrow-functions --free-variable-checker
|
||||||
|
// Error: :3:35: missingIdentifier is not defined
|
||||||
|
var identity = (identityParam) => missingIdentifier;
|
||||||
3
packages/babel/test/fixtures/traceur/ArrowFunctions/Error_InvalidFormalParameters.js
vendored
Normal file
3
packages/babel/test/fixtures/traceur/ArrowFunctions/Error_InvalidFormalParameters.js
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
// Error: :3:15: Unexpected token +
|
||||||
|
|
||||||
|
var f = (a, b + 5) => a + b;
|
||||||
4
packages/babel/test/fixtures/traceur/ArrowFunctions/Error_LineTerminator.js
vendored
Normal file
4
packages/babel/test/fixtures/traceur/ArrowFunctions/Error_LineTerminator.js
vendored
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
// Error: :4:1: Unexpected token =>
|
||||||
|
|
||||||
|
x
|
||||||
|
=>1
|
||||||
3
packages/babel/test/fixtures/traceur/ArrowFunctions/Error_Precedence.js
vendored
Normal file
3
packages/babel/test/fixtures/traceur/ArrowFunctions/Error_Precedence.js
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
// Error: :3:26: Semi-colon expected
|
||||||
|
|
||||||
|
var identity = (x) => {x}.bind({});
|
||||||
4
packages/babel/test/fixtures/traceur/ArrowFunctions/Error_Precedence2.js
vendored
Normal file
4
packages/babel/test/fixtures/traceur/ArrowFunctions/Error_Precedence2.js
vendored
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
// Error: :4:11: Semi-colon expected
|
||||||
|
// Error: :4:11: Unexpected token =>
|
||||||
|
|
||||||
|
(x) + (y) => y;
|
||||||
4
packages/babel/test/fixtures/traceur/ArrowFunctions/Error_Precedence3.js
vendored
Normal file
4
packages/babel/test/fixtures/traceur/ArrowFunctions/Error_Precedence3.js
vendored
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
// Error: :4:9: Semi-colon expected
|
||||||
|
// Error: :4:9: Unexpected token =>
|
||||||
|
|
||||||
|
(x) + y => y;
|
||||||
6
packages/babel/test/fixtures/traceur/ArrowFunctions/Error_SpreadNotLast.js
vendored
Normal file
6
packages/babel/test/fixtures/traceur/ArrowFunctions/Error_SpreadNotLast.js
vendored
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
// Error: :5:17: Unexpected token ,
|
||||||
|
// Error: :5:12: Unexpected token ...
|
||||||
|
|
||||||
|
{
|
||||||
|
let f = (...xs, x) => xs;
|
||||||
|
}
|
||||||
3
packages/babel/test/fixtures/traceur/ArrowFunctions/Error_SpreadOutsideFormals.js
vendored
Normal file
3
packages/babel/test/fixtures/traceur/ArrowFunctions/Error_SpreadOutsideFormals.js
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
// Error: :3:13: Unexpected token ...
|
||||||
|
|
||||||
|
var f = (x, ...xs);
|
||||||
2
packages/babel/test/fixtures/traceur/ArrowFunctions/FreeVariableChecker.js
vendored
Normal file
2
packages/babel/test/fixtures/traceur/ArrowFunctions/FreeVariableChecker.js
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
var identity = (identityParam) => identityParam;
|
||||||
|
assert.equal(1234, identity(1234));
|
||||||
19
packages/babel/test/fixtures/traceur/ArrowFunctions/Parens.js
vendored
Normal file
19
packages/babel/test/fixtures/traceur/ArrowFunctions/Parens.js
vendored
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
class C {
|
||||||
|
constructor() {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class D extends C {
|
||||||
|
constructor() {
|
||||||
|
super();
|
||||||
|
this.x = {
|
||||||
|
y: () => {
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var o = new D();
|
||||||
|
assert.equal(typeof o.x.y, 'function');
|
||||||
|
assert.equal(o.x.y(), o);
|
||||||
39
packages/babel/test/fixtures/traceur/ArrowFunctions/Skip_Frozen.js
vendored
Normal file
39
packages/babel/test/fixtures/traceur/ArrowFunctions/Skip_Frozen.js
vendored
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
// Skip. Not implemented.
|
||||||
|
|
||||||
|
// TODO: needs # prefix implemented for freezing
|
||||||
|
// Use # to freeze and join to nearest relevant closure
|
||||||
|
function return_pure() {
|
||||||
|
return #(a) -> a * a;
|
||||||
|
}
|
||||||
|
|
||||||
|
let p = return_pure(),
|
||||||
|
q = return_pure();
|
||||||
|
assert(p === q);
|
||||||
|
|
||||||
|
function check_frozen(o) {
|
||||||
|
try {
|
||||||
|
o.x = "expando";
|
||||||
|
assert(! "reached");
|
||||||
|
} catch (e) {
|
||||||
|
// e is something like "TypeError: o is not extensible"
|
||||||
|
assert(e.name == "TypeError");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
check_frozen(p);
|
||||||
|
|
||||||
|
function partial_mul(a) {
|
||||||
|
return #(b) -> a * b;
|
||||||
|
}
|
||||||
|
|
||||||
|
let x = partial_mul(3),
|
||||||
|
y = partial_mul(4),
|
||||||
|
z = partial_mul(3);
|
||||||
|
|
||||||
|
assert(x !== y);
|
||||||
|
assert(x !== z);
|
||||||
|
assert(y !== z);
|
||||||
|
|
||||||
|
check_frozen(x);
|
||||||
|
check_frozen(y);
|
||||||
|
check_frozen(z);
|
||||||
19
packages/babel/test/fixtures/traceur/ArrowFunctions/Skip_InitializerShorthand.js
vendored
Normal file
19
packages/babel/test/fixtures/traceur/ArrowFunctions/Skip_InitializerShorthand.js
vendored
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
// Skip. Not implemented.
|
||||||
|
|
||||||
|
// TODO: needs the intializer shorthand implemented for arrow functions
|
||||||
|
|
||||||
|
// Object intializer shorthand: "method" = function-valued property with dynamic ''this''
|
||||||
|
const obj = {
|
||||||
|
method() -> {
|
||||||
|
return => this;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
assert(obj.method() === obj);
|
||||||
|
assert(obj.method.call(u) === u);
|
||||||
|
|
||||||
|
// Name binding forms hoist to body (var) or block (let, const) top
|
||||||
|
var warmer(a) -> { return a; };
|
||||||
|
let warm(b) -> { return b; };
|
||||||
|
const colder(c) -> { return c; };
|
||||||
|
const #coldest(d) -> {...};
|
||||||
14
packages/babel/test/fixtures/traceur/ArrowFunctions/Skip_SoftBind.js
vendored
Normal file
14
packages/babel/test/fixtures/traceur/ArrowFunctions/Skip_SoftBind.js
vendored
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
// Skip. Not implemented.
|
||||||
|
|
||||||
|
// TODO: needs soft bind and ??= implemented
|
||||||
|
|
||||||
|
// A special form based on the default operator proposal
|
||||||
|
const self_default_bound = (this ??= self, a, b) -> {
|
||||||
|
this.c = a * b;
|
||||||
|
}
|
||||||
|
self_default_bound(6, 7);
|
||||||
|
assert(self.c === 42);
|
||||||
|
|
||||||
|
self_default_bound.call(other, 8, 9);
|
||||||
|
assert(other.c === 72);
|
||||||
|
assert(self.c === 42);
|
||||||
15
packages/babel/test/fixtures/traceur/ArrowFunctions/SloppyArguments.js
vendored
Normal file
15
packages/babel/test/fixtures/traceur/ArrowFunctions/SloppyArguments.js
vendored
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
|
||||||
|
var f1 = implements => implements;
|
||||||
|
var f2 = implements => { return implements; };
|
||||||
|
var f3 = (implements) => { return implements; };
|
||||||
|
assert.equal(1, f1(1));
|
||||||
|
assert.equal(2, f2(2));
|
||||||
|
assert.equal(3, f1(3));
|
||||||
|
|
||||||
|
var g = ({static}) => static;
|
||||||
|
assert.equal(4, g({static: 4}));
|
||||||
|
|
||||||
|
var h1 = ([protected]) => protected;
|
||||||
|
var h2 = ([...protected]) => protected[0];
|
||||||
|
assert.equal(5, h1([5]));
|
||||||
|
assert.equal(6, h2([6]));
|
||||||
15
packages/babel/test/fixtures/traceur/ArrowFunctions/ThisBindingInPropertyName.js
vendored
Normal file
15
packages/babel/test/fixtures/traceur/ArrowFunctions/ThisBindingInPropertyName.js
vendored
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
var obj = {
|
||||||
|
name: 'x',
|
||||||
|
method() {
|
||||||
|
var f = (x) => ({[this.name]: x});
|
||||||
|
|
||||||
|
var o = f(1);
|
||||||
|
assert.equal(1, o.x);
|
||||||
|
|
||||||
|
this.name = 2;
|
||||||
|
o = f(3);
|
||||||
|
assert.equal(3, o[2]);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
obj.method();
|
||||||
18
packages/babel/test/fixtures/traceur/ArrowFunctions/ThisBindings.js
vendored
Normal file
18
packages/babel/test/fixtures/traceur/ArrowFunctions/ThisBindings.js
vendored
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
// Options: --block-binding
|
||||||
|
|
||||||
|
// These tests are from:
|
||||||
|
// http://wiki.ecmascript.org/doku.php?id=strawman:arrow_function_syntax
|
||||||
|
|
||||||
|
const obj = {
|
||||||
|
method: function () {
|
||||||
|
return () => this;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
assert.equal(obj.method()(), obj);
|
||||||
|
|
||||||
|
let fake = {steal: obj.method()};
|
||||||
|
assert.equal(fake.steal(), obj);
|
||||||
|
|
||||||
|
let real = {borrow: obj.method};
|
||||||
|
assert.equal(real.borrow()(), real);
|
||||||
|
|
||||||
21
packages/babel/test/fixtures/traceur/AsyncFunctions/AlphaRenaming.js
vendored
Normal file
21
packages/babel/test/fixtures/traceur/AsyncFunctions/AlphaRenaming.js
vendored
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
// Options: --async-functions
|
||||||
|
// Async.
|
||||||
|
|
||||||
|
function asyncComplete(self, arg) {
|
||||||
|
return new Promise((resolve) => {
|
||||||
|
resolve([self, arg]);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
var self = {};
|
||||||
|
var obj = {};
|
||||||
|
var value;
|
||||||
|
|
||||||
|
async function A() {
|
||||||
|
assert.equal(this, self);
|
||||||
|
var value = await asyncComplete(this, arguments[0]);
|
||||||
|
assert.deepEqual([self, obj], value);
|
||||||
|
done();
|
||||||
|
}
|
||||||
|
|
||||||
|
A.call(self, obj);
|
||||||
9
packages/babel/test/fixtures/traceur/AsyncFunctions/AsyncArrow.js
vendored
Normal file
9
packages/babel/test/fixtures/traceur/AsyncFunctions/AsyncArrow.js
vendored
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
// Options: --async-functions
|
||||||
|
// Async.
|
||||||
|
|
||||||
|
var f = async () => 1;
|
||||||
|
|
||||||
|
f().then((result) => {
|
||||||
|
assert.equal(result, 1);
|
||||||
|
done();
|
||||||
|
}).catch(done);
|
||||||
9
packages/babel/test/fixtures/traceur/AsyncFunctions/AsyncArrow2.js
vendored
Normal file
9
packages/babel/test/fixtures/traceur/AsyncFunctions/AsyncArrow2.js
vendored
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
// Options: --async-functions
|
||||||
|
// Async.
|
||||||
|
|
||||||
|
var f = async x => x;
|
||||||
|
|
||||||
|
f(1).then((result) => {
|
||||||
|
assert.equal(result, 1);
|
||||||
|
done();
|
||||||
|
}).catch(done);
|
||||||
16
packages/babel/test/fixtures/traceur/AsyncFunctions/AsyncArrowArguments.js
vendored
Normal file
16
packages/babel/test/fixtures/traceur/AsyncFunctions/AsyncArrowArguments.js
vendored
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
// Options: --async-functions
|
||||||
|
// Async.
|
||||||
|
|
||||||
|
function g() {
|
||||||
|
var f = async (x = arguments) => [x, arguments];
|
||||||
|
|
||||||
|
f().then((result) => {
|
||||||
|
assert.equal(result[0][0], 1);
|
||||||
|
assert.equal(result[1][0], 1);
|
||||||
|
assert.equal(result[0][1], 2);
|
||||||
|
assert.equal(result[1][1], 2);
|
||||||
|
done();
|
||||||
|
}).catch(done);
|
||||||
|
}
|
||||||
|
|
||||||
|
g(1, 2);
|
||||||
15
packages/babel/test/fixtures/traceur/AsyncFunctions/AsyncArrowThis.js
vendored
Normal file
15
packages/babel/test/fixtures/traceur/AsyncFunctions/AsyncArrowThis.js
vendored
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
// Options: --async-functions
|
||||||
|
// Async.
|
||||||
|
|
||||||
|
function g() {
|
||||||
|
var f = async (x = this) => [x, this];
|
||||||
|
var p = {};
|
||||||
|
f.call(p).then((result) => {
|
||||||
|
assert.equal(result[0], o);
|
||||||
|
assert.equal(result[1], o);
|
||||||
|
done();
|
||||||
|
}).catch(done);
|
||||||
|
}
|
||||||
|
|
||||||
|
var o = {};
|
||||||
|
g.call(o);
|
||||||
31
packages/babel/test/fixtures/traceur/AsyncFunctions/AsyncMethod.js
vendored
Normal file
31
packages/babel/test/fixtures/traceur/AsyncFunctions/AsyncMethod.js
vendored
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
// Options: --async-functions
|
||||||
|
// Async.
|
||||||
|
|
||||||
|
function asyncTimeout(ms) {
|
||||||
|
return new Promise((resolve) => {
|
||||||
|
setTimeout(resolve, ms);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
class C {
|
||||||
|
async test() {
|
||||||
|
var x = 0;
|
||||||
|
await asyncTimeout(1);
|
||||||
|
assert.equal(1, ++x);
|
||||||
|
await asyncTimeout(1);
|
||||||
|
assert.equal(2, ++x);
|
||||||
|
C.test();
|
||||||
|
}
|
||||||
|
|
||||||
|
static async test() {
|
||||||
|
var x = 0;
|
||||||
|
await asyncTimeout(1);
|
||||||
|
assert.equal(1, ++x);
|
||||||
|
await asyncTimeout(1);
|
||||||
|
assert.equal(2, ++x);
|
||||||
|
|
||||||
|
done();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
new C().test();
|
||||||
21
packages/babel/test/fixtures/traceur/AsyncFunctions/AsyncMethodObjectLiteral.js
vendored
Normal file
21
packages/babel/test/fixtures/traceur/AsyncFunctions/AsyncMethodObjectLiteral.js
vendored
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
// Options: --async-functions
|
||||||
|
// Async.
|
||||||
|
|
||||||
|
function asyncTimeout(ms) {
|
||||||
|
return new Promise((resolve) => {
|
||||||
|
setTimeout(resolve, ms);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
var object = {
|
||||||
|
async test() {
|
||||||
|
var x = 0;
|
||||||
|
await asyncTimeout(1);
|
||||||
|
assert.equal(1, ++x);
|
||||||
|
await asyncTimeout(1);
|
||||||
|
assert.equal(2, ++x);
|
||||||
|
done();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
object.test();
|
||||||
18
packages/babel/test/fixtures/traceur/AsyncFunctions/AsyncSyntax.js
vendored
Normal file
18
packages/babel/test/fixtures/traceur/AsyncFunctions/AsyncSyntax.js
vendored
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
// Options: --async-functions
|
||||||
|
|
||||||
|
var async;
|
||||||
|
async
|
||||||
|
function f() {
|
||||||
|
return async + async;
|
||||||
|
}
|
||||||
|
|
||||||
|
async = 1;
|
||||||
|
assert.equal(async, 1);
|
||||||
|
assert.equal(f(), 2);
|
||||||
|
|
||||||
|
async = async
|
||||||
|
function g() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
assert.equal(async, 1);
|
||||||
46
packages/babel/test/fixtures/traceur/AsyncFunctions/Basics.js
vendored
Normal file
46
packages/babel/test/fixtures/traceur/AsyncFunctions/Basics.js
vendored
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
// Options: --async-functions --generators=false
|
||||||
|
// Async.
|
||||||
|
//
|
||||||
|
// The --generators=false part is to test #1231
|
||||||
|
|
||||||
|
var f = (x, y) => ({x, y});
|
||||||
|
|
||||||
|
(async function() {
|
||||||
|
var x = await 1;
|
||||||
|
assert.equal(1, x);
|
||||||
|
x = await (await 2);
|
||||||
|
assert.equal(2, x);
|
||||||
|
x = (await 3, await 4);
|
||||||
|
assert.equal(4, x);
|
||||||
|
|
||||||
|
x = f(await 5, await 6);
|
||||||
|
assert.deepEqual({x: 5, y: 6}, x);
|
||||||
|
x = await f(await 7, await 8);
|
||||||
|
assert.deepEqual({x: 7, y: 8}, x);
|
||||||
|
|
||||||
|
if (await true) {
|
||||||
|
x = 9;
|
||||||
|
} else {
|
||||||
|
x = 10;
|
||||||
|
}
|
||||||
|
assert.equal(9, x);
|
||||||
|
if (await false) {
|
||||||
|
x = 11;
|
||||||
|
} else {
|
||||||
|
x = 12;
|
||||||
|
}
|
||||||
|
assert.equal(12, x);
|
||||||
|
|
||||||
|
var j = 0;
|
||||||
|
for (var i = await 0; (await i) < (await 3); await i++) {
|
||||||
|
assert.equal(i, j++);
|
||||||
|
}
|
||||||
|
assert.equal(3, j);
|
||||||
|
|
||||||
|
var g = (x) => x;
|
||||||
|
var h = () => 13;
|
||||||
|
x = await g({z: await h()});
|
||||||
|
assert.deepEqual({z: 13}, x);
|
||||||
|
|
||||||
|
done();
|
||||||
|
})();
|
||||||
16
packages/babel/test/fixtures/traceur/AsyncFunctions/Complete.js
vendored
Normal file
16
packages/babel/test/fixtures/traceur/AsyncFunctions/Complete.js
vendored
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
// Options: --async-functions
|
||||||
|
// Async.
|
||||||
|
|
||||||
|
function asyncComplete() {
|
||||||
|
return new Promise((resolve) => {
|
||||||
|
resolve('complete');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
(async function() {
|
||||||
|
var value = await asyncComplete();
|
||||||
|
assert.equal('complete', value);
|
||||||
|
done();
|
||||||
|
})();
|
||||||
10
packages/babel/test/fixtures/traceur/AsyncFunctions/Empty.js
vendored
Normal file
10
packages/babel/test/fixtures/traceur/AsyncFunctions/Empty.js
vendored
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
// Options: --async-functions
|
||||||
|
// Async.
|
||||||
|
|
||||||
|
async function empty() {
|
||||||
|
}
|
||||||
|
|
||||||
|
empty().then((v) => {
|
||||||
|
assert.isUndefined(v);
|
||||||
|
done();
|
||||||
|
});
|
||||||
7
packages/babel/test/fixtures/traceur/AsyncFunctions/Error_AsyncArrow.js
vendored
Normal file
7
packages/babel/test/fixtures/traceur/AsyncFunctions/Error_AsyncArrow.js
vendored
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
// Options: --async-functions
|
||||||
|
// Error: :7:5: Semi-colon expected
|
||||||
|
// Error: :7:5: Unexpected token =>
|
||||||
|
|
||||||
|
var async = () => 1;
|
||||||
|
var x = async
|
||||||
|
(y) => y;
|
||||||
6
packages/babel/test/fixtures/traceur/AsyncFunctions/Error_AsyncArrow2.js
vendored
Normal file
6
packages/babel/test/fixtures/traceur/AsyncFunctions/Error_AsyncArrow2.js
vendored
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
// Options: --async-functions
|
||||||
|
// Error: :6:1: Unexpected token =>
|
||||||
|
|
||||||
|
var async = () => 1;
|
||||||
|
var x = async (y)
|
||||||
|
=> y;
|
||||||
15
packages/babel/test/fixtures/traceur/AsyncFunctions/Error_Disabled.js
vendored
Normal file
15
packages/babel/test/fixtures/traceur/AsyncFunctions/Error_Disabled.js
vendored
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
// Disabled by default.
|
||||||
|
// Error: :13:21: Semi-colon expected
|
||||||
|
|
||||||
|
function asyncComplete() {
|
||||||
|
return new Promise((resolve) => {
|
||||||
|
resolve('complete');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
(async function() {
|
||||||
|
var value = async asyncComplete();
|
||||||
|
assert.equal('complete', value);
|
||||||
|
})();
|
||||||
18
packages/babel/test/fixtures/traceur/AsyncFunctions/Export.module.js
vendored
Normal file
18
packages/babel/test/fixtures/traceur/AsyncFunctions/Export.module.js
vendored
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
// Options: --async-functions
|
||||||
|
// Async.
|
||||||
|
|
||||||
|
import {asyncFunction} from './resources/async-function.js';
|
||||||
|
import asyncFunctionDefault from './resources/async-function.js';
|
||||||
|
|
||||||
|
assert.instanceOf(asyncFunction(), Promise);
|
||||||
|
assert.instanceOf(asyncFunctionDefault(), Promise);
|
||||||
|
|
||||||
|
(async function() {
|
||||||
|
var x = await asyncFunction();
|
||||||
|
assert.equal(x, 1);
|
||||||
|
|
||||||
|
var y = await asyncFunctionDefault();
|
||||||
|
assert.equal(y, 2);
|
||||||
|
|
||||||
|
done();
|
||||||
|
})();
|
||||||
25
packages/babel/test/fixtures/traceur/AsyncFunctions/Finally.js
vendored
Normal file
25
packages/babel/test/fixtures/traceur/AsyncFunctions/Finally.js
vendored
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
// Options: --async-functions
|
||||||
|
// Async.
|
||||||
|
|
||||||
|
var finallyVisited = false;
|
||||||
|
|
||||||
|
var resolve;
|
||||||
|
var p = new Promise((r) => {
|
||||||
|
resolve = r;
|
||||||
|
});
|
||||||
|
var v;
|
||||||
|
|
||||||
|
async function test() {
|
||||||
|
try {
|
||||||
|
v = await p;
|
||||||
|
} finally {
|
||||||
|
finallyVisited = true;
|
||||||
|
}
|
||||||
|
assert.equal(42, v);
|
||||||
|
assert.isTrue(finallyVisited);
|
||||||
|
done();
|
||||||
|
}
|
||||||
|
|
||||||
|
test();
|
||||||
|
assert.isFalse(finallyVisited);
|
||||||
|
resolve(42);
|
||||||
21
packages/babel/test/fixtures/traceur/AsyncFunctions/Finally2.js
vendored
Normal file
21
packages/babel/test/fixtures/traceur/AsyncFunctions/Finally2.js
vendored
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
// Options: --async-functions
|
||||||
|
// Async.
|
||||||
|
|
||||||
|
var finallyVisited = false;
|
||||||
|
var resolve;
|
||||||
|
|
||||||
|
async function test() {
|
||||||
|
try {
|
||||||
|
await new Promise((r) => {
|
||||||
|
resolve = r;
|
||||||
|
});
|
||||||
|
} finally {
|
||||||
|
finallyVisited = true;
|
||||||
|
}
|
||||||
|
assert.isTrue(finallyVisited);
|
||||||
|
done();
|
||||||
|
}
|
||||||
|
|
||||||
|
test();
|
||||||
|
assert.isFalse(finallyVisited);
|
||||||
|
resolve();
|
||||||
12
packages/babel/test/fixtures/traceur/AsyncFunctions/PromiseCast.js
vendored
Normal file
12
packages/babel/test/fixtures/traceur/AsyncFunctions/PromiseCast.js
vendored
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
// Options: --async-functions
|
||||||
|
// Async.
|
||||||
|
|
||||||
|
async function f() {
|
||||||
|
var x = await 1;
|
||||||
|
assert.equal(x, 1);
|
||||||
|
x = await undefined;
|
||||||
|
assert.equal(x, undefined);
|
||||||
|
done();
|
||||||
|
}
|
||||||
|
|
||||||
|
f();
|
||||||
7
packages/babel/test/fixtures/traceur/AsyncFunctions/Prototype.js
vendored
Normal file
7
packages/babel/test/fixtures/traceur/AsyncFunctions/Prototype.js
vendored
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
// Options: --async-functions
|
||||||
|
|
||||||
|
async function f() {
|
||||||
|
}
|
||||||
|
|
||||||
|
assert.equal(Object.getPrototypeOf(f), Function.prototype);
|
||||||
|
assert.instanceOf(f(), Promise);
|
||||||
13
packages/babel/test/fixtures/traceur/AsyncFunctions/Rethrow.js
vendored
Normal file
13
packages/babel/test/fixtures/traceur/AsyncFunctions/Rethrow.js
vendored
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
// Options: --async-functions
|
||||||
|
// Async.
|
||||||
|
|
||||||
|
async function rethrow(x) {
|
||||||
|
1;
|
||||||
|
throw x;
|
||||||
|
2;
|
||||||
|
}
|
||||||
|
|
||||||
|
rethrow(2).catch((err) => {
|
||||||
|
assert.equal(err, 2)
|
||||||
|
done();
|
||||||
|
});
|
||||||
16
packages/babel/test/fixtures/traceur/AsyncFunctions/Return.js
vendored
Normal file
16
packages/babel/test/fixtures/traceur/AsyncFunctions/Return.js
vendored
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
// Options: --async-functions
|
||||||
|
// Async.
|
||||||
|
|
||||||
|
async function ret(x) {
|
||||||
|
if (x > 1)
|
||||||
|
return x - 2;
|
||||||
|
return x + 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
(async function() {
|
||||||
|
var v = await ret(4);
|
||||||
|
assert.equal(v, 2);
|
||||||
|
v = await ret(0);
|
||||||
|
assert.equal(v, 3);
|
||||||
|
done();
|
||||||
|
})();
|
||||||
30
packages/babel/test/fixtures/traceur/AsyncFunctions/Throw.js
vendored
Normal file
30
packages/babel/test/fixtures/traceur/AsyncFunctions/Throw.js
vendored
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
// Options: --async-functions
|
||||||
|
// Async.
|
||||||
|
|
||||||
|
async function asyncThrow(e) {
|
||||||
|
if (true)
|
||||||
|
throw e;
|
||||||
|
await asyncYield();
|
||||||
|
}
|
||||||
|
|
||||||
|
function asyncYield() {
|
||||||
|
return asyncTimeout(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
function asyncTimeout(ms) {
|
||||||
|
return new Promise((resolve) => {
|
||||||
|
setTimeout(resolve, ms);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
(async function() {
|
||||||
|
var value;
|
||||||
|
try {
|
||||||
|
value = await asyncThrow(1);
|
||||||
|
fail("shouldn't get here");
|
||||||
|
} catch (e) {
|
||||||
|
assert.equal(1, e);
|
||||||
|
}
|
||||||
|
|
||||||
|
done();
|
||||||
|
})();
|
||||||
21
packages/babel/test/fixtures/traceur/AsyncFunctions/Timeout.js
vendored
Normal file
21
packages/babel/test/fixtures/traceur/AsyncFunctions/Timeout.js
vendored
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
// Options: --async-functions
|
||||||
|
// Async.
|
||||||
|
|
||||||
|
function asyncTimeout(ms) {
|
||||||
|
return new Promise((resolve) => {
|
||||||
|
setTimeout(resolve, ms);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
(async function() {
|
||||||
|
var x = 0;
|
||||||
|
await asyncTimeout(1);
|
||||||
|
assert.equal(1, ++x);
|
||||||
|
await asyncTimeout(1);
|
||||||
|
assert.equal(2, ++x);
|
||||||
|
await asyncTimeout(1);
|
||||||
|
assert.equal(3, ++x);
|
||||||
|
await asyncTimeout(1);
|
||||||
|
assert.equal(4, ++x);
|
||||||
|
done();
|
||||||
|
})();
|
||||||
24
packages/babel/test/fixtures/traceur/AsyncFunctions/Value.js
vendored
Normal file
24
packages/babel/test/fixtures/traceur/AsyncFunctions/Value.js
vendored
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
// Options: --async-functions
|
||||||
|
// Async.
|
||||||
|
|
||||||
|
async function asyncValue(value) {
|
||||||
|
if (true)
|
||||||
|
return value;
|
||||||
|
await asyncYield();
|
||||||
|
}
|
||||||
|
|
||||||
|
function asyncYield() {
|
||||||
|
return asyncTimeout(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
function asyncTimeout(ms) {
|
||||||
|
return new Promise((resolve) => {
|
||||||
|
setTimeout(resolve, ms);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
(async function() {
|
||||||
|
var value = await asyncValue(42);
|
||||||
|
assert.equal(42, value);
|
||||||
|
done();
|
||||||
|
})();
|
||||||
17
packages/babel/test/fixtures/traceur/AsyncFunctions/Yield.js
vendored
Normal file
17
packages/babel/test/fixtures/traceur/AsyncFunctions/Yield.js
vendored
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
// Options: --async-functions
|
||||||
|
// Async.
|
||||||
|
|
||||||
|
function asyncYield() {
|
||||||
|
return asyncTimeout(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
function asyncTimeout(ms) {
|
||||||
|
return new Promise((resolve) => {
|
||||||
|
setTimeout(resolve, ms);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
(async function() {
|
||||||
|
await asyncYield();
|
||||||
|
done();
|
||||||
|
})();
|
||||||
7
packages/babel/test/fixtures/traceur/AsyncFunctions/resources/async-function.js
vendored
Normal file
7
packages/babel/test/fixtures/traceur/AsyncFunctions/resources/async-function.js
vendored
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
export async function asyncFunction() {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
export default async function() {
|
||||||
|
return 2;
|
||||||
|
};
|
||||||
14
packages/babel/test/fixtures/traceur/AsyncGenerators/Array.js
vendored
Normal file
14
packages/babel/test/fixtures/traceur/AsyncGenerators/Array.js
vendored
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
// Options: --for-on --async-functions
|
||||||
|
// Async.
|
||||||
|
|
||||||
|
(async function() {
|
||||||
|
const list = [];
|
||||||
|
const g = [1, 2, 3];
|
||||||
|
for (var i on g) {
|
||||||
|
list.push(i);
|
||||||
|
}
|
||||||
|
assert.deepEqual(list, [1, 2, 3]);
|
||||||
|
|
||||||
|
done();
|
||||||
|
})().catch(done);
|
||||||
|
|
||||||
18
packages/babel/test/fixtures/traceur/AsyncGenerators/AsyncGenerator.js
vendored
Normal file
18
packages/babel/test/fixtures/traceur/AsyncGenerators/AsyncGenerator.js
vendored
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
// Options: --async-generators --for-on --async-functions
|
||||||
|
// Async.
|
||||||
|
|
||||||
|
async function* f() {
|
||||||
|
yield 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
(async function() {
|
||||||
|
var list = [];
|
||||||
|
var g = f();
|
||||||
|
for (var i on g) {
|
||||||
|
list.push(i);
|
||||||
|
}
|
||||||
|
assert.deepEqual(list, [1]);
|
||||||
|
|
||||||
|
done();
|
||||||
|
})().catch(done);
|
||||||
|
|
||||||
21
packages/babel/test/fixtures/traceur/AsyncGenerators/AsyncObservable.js
vendored
Normal file
21
packages/babel/test/fixtures/traceur/AsyncGenerators/AsyncObservable.js
vendored
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
// Options: --async-generators --for-on --async-functions
|
||||||
|
// Async.
|
||||||
|
|
||||||
|
async function* f() {
|
||||||
|
await yield 1;
|
||||||
|
await yield 2;
|
||||||
|
await yield 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
(async function() {
|
||||||
|
var list = [];
|
||||||
|
var g = f();
|
||||||
|
for (var i on g) {
|
||||||
|
list.push(i);
|
||||||
|
await Promise.resolve().then(() => list.push(i + 3));
|
||||||
|
}
|
||||||
|
assert.deepEqual(list, [1, 4, 2, 5, 3, 6]);
|
||||||
|
|
||||||
|
done();
|
||||||
|
})().catch(done);
|
||||||
|
|
||||||
29
packages/babel/test/fixtures/traceur/AsyncGenerators/Demo.js
vendored
Normal file
29
packages/babel/test/fixtures/traceur/AsyncGenerators/Demo.js
vendored
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
// Options: --async-functions --async-generators --for-on
|
||||||
|
// Async.
|
||||||
|
|
||||||
|
function timeout(ms) {
|
||||||
|
return new Promise((resolve) => {
|
||||||
|
setTimeout(resolve, ms);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async function* asyncStream() {
|
||||||
|
var i = 0;
|
||||||
|
while (true) {
|
||||||
|
await timeout(5);
|
||||||
|
yield i;
|
||||||
|
++i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
(async function() {
|
||||||
|
var count = 0;
|
||||||
|
for (value on asyncStream()) {
|
||||||
|
count += value;
|
||||||
|
if (value === 3) {
|
||||||
|
break; // stops the async generator as well
|
||||||
|
}
|
||||||
|
}
|
||||||
|
assert.equal(count, 6); // 6 = 1 + 2 + 3
|
||||||
|
done();
|
||||||
|
})();
|
||||||
75
packages/babel/test/fixtures/traceur/AsyncGenerators/ForOn.module.js
vendored
Normal file
75
packages/babel/test/fixtures/traceur/AsyncGenerators/ForOn.module.js
vendored
Normal file
@ -0,0 +1,75 @@
|
|||||||
|
// Async.
|
||||||
|
// Options: --async-functions --for-on
|
||||||
|
|
||||||
|
import {AsyncGeneratorFunction} from './resources/observable.js';
|
||||||
|
|
||||||
|
var o1 = new AsyncGeneratorFunction(function* () {
|
||||||
|
// TODO(mnieper): As soon as proper async generators are implemented, they
|
||||||
|
// should be used here.
|
||||||
|
yield 1;
|
||||||
|
yield 2;
|
||||||
|
yield 3;
|
||||||
|
return 4;
|
||||||
|
});
|
||||||
|
|
||||||
|
(async function () {
|
||||||
|
|
||||||
|
// test for on
|
||||||
|
var squares = [];
|
||||||
|
for (var i on o1) {
|
||||||
|
squares.push(i * i);
|
||||||
|
}
|
||||||
|
assert.deepEqual(squares, [1, 4, 9]);
|
||||||
|
|
||||||
|
// test break
|
||||||
|
var cubes = [];
|
||||||
|
for (var i on o1) {
|
||||||
|
if (i > 2) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
cubes.push(i * i * i);
|
||||||
|
}
|
||||||
|
assert.deepEqual(cubes, [1, 8]);
|
||||||
|
|
||||||
|
// test continue
|
||||||
|
var list = [];
|
||||||
|
for (var i on o1) {
|
||||||
|
if (i === 2) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
list.push(i);
|
||||||
|
}
|
||||||
|
assert.deepEqual(list, [1, 3]);
|
||||||
|
|
||||||
|
// test outer continue
|
||||||
|
var almostEmpty = [];
|
||||||
|
label: do {
|
||||||
|
for (var i on o1) {
|
||||||
|
if (i === 2) {
|
||||||
|
continue label;
|
||||||
|
}
|
||||||
|
almostEmpty.push(i);
|
||||||
|
}
|
||||||
|
} while (false);
|
||||||
|
assert.deepEqual(almostEmpty, [1]);
|
||||||
|
|
||||||
|
// test return
|
||||||
|
var value = await (async function () {
|
||||||
|
for (var i on o1) {
|
||||||
|
if (i === 1) {
|
||||||
|
return 42;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})();
|
||||||
|
assert.equal(value, 42);
|
||||||
|
|
||||||
|
// test asynchronous loop body
|
||||||
|
var sum = 0;
|
||||||
|
for (var i on o1) {
|
||||||
|
sum += i;
|
||||||
|
await Promise.resolve();
|
||||||
|
}
|
||||||
|
assert.equal(sum, 6);
|
||||||
|
|
||||||
|
done();
|
||||||
|
}()).catch(done);
|
||||||
14
packages/babel/test/fixtures/traceur/AsyncGenerators/ForOnBody.js
vendored
Normal file
14
packages/babel/test/fixtures/traceur/AsyncGenerators/ForOnBody.js
vendored
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
// Options: --async-generators --for-on --async-functions
|
||||||
|
// Async.
|
||||||
|
|
||||||
|
async function* x() {
|
||||||
|
}
|
||||||
|
|
||||||
|
async function y() {
|
||||||
|
for (let a on x())
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
y()
|
||||||
|
|
||||||
|
done();
|
||||||
20
packages/babel/test/fixtures/traceur/AsyncGenerators/Method.js
vendored
Normal file
20
packages/babel/test/fixtures/traceur/AsyncGenerators/Method.js
vendored
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
// Options: --async-generators --for-on --async-functions
|
||||||
|
// Async.
|
||||||
|
|
||||||
|
class C {
|
||||||
|
static async* f() {
|
||||||
|
yield 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
(async function() {
|
||||||
|
var list = [];
|
||||||
|
var g = C.f();
|
||||||
|
for (var i on g) {
|
||||||
|
list.push(i);
|
||||||
|
}
|
||||||
|
assert.deepEqual(list, [1]);
|
||||||
|
|
||||||
|
done();
|
||||||
|
})().catch(done);
|
||||||
|
|
||||||
20
packages/babel/test/fixtures/traceur/AsyncGenerators/Property.js
vendored
Normal file
20
packages/babel/test/fixtures/traceur/AsyncGenerators/Property.js
vendored
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
// Options: --async-generators --for-on --async-functions
|
||||||
|
// Async.
|
||||||
|
|
||||||
|
var C = {
|
||||||
|
async* f() {
|
||||||
|
yield 1;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
(async function() {
|
||||||
|
var list = [];
|
||||||
|
var g = C.f();
|
||||||
|
for (var i on g) {
|
||||||
|
list.push(i);
|
||||||
|
}
|
||||||
|
assert.deepEqual(list, [1]);
|
||||||
|
|
||||||
|
done();
|
||||||
|
})().catch(done);
|
||||||
|
|
||||||
24
packages/babel/test/fixtures/traceur/AsyncGenerators/ReturnAsyncGenerator.js
vendored
Normal file
24
packages/babel/test/fixtures/traceur/AsyncGenerators/ReturnAsyncGenerator.js
vendored
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
// Options: --async-generators --for-on --async-functions
|
||||||
|
// Async.
|
||||||
|
|
||||||
|
async function* f() {
|
||||||
|
yield 1;
|
||||||
|
yield 2;
|
||||||
|
yield 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
(async function() {
|
||||||
|
var list = [];
|
||||||
|
var g = f();
|
||||||
|
for (var i on g) {
|
||||||
|
if (i === 2) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
list.push(i);
|
||||||
|
}
|
||||||
|
assert.deepEqual(list, [1]);
|
||||||
|
|
||||||
|
done();
|
||||||
|
})().catch(done);
|
||||||
|
|
||||||
19
packages/babel/test/fixtures/traceur/AsyncGenerators/ThisAndArguments.js
vendored
Normal file
19
packages/babel/test/fixtures/traceur/AsyncGenerators/ThisAndArguments.js
vendored
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
// Options: --async-generators --for-on --async-functions
|
||||||
|
// Async.
|
||||||
|
|
||||||
|
async function* f(a) {
|
||||||
|
yield this[0];
|
||||||
|
yield arguments[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
(async function() {
|
||||||
|
var list = [];
|
||||||
|
var g = f.call([1], 2);
|
||||||
|
for (var i on g) {
|
||||||
|
list.push(i);
|
||||||
|
}
|
||||||
|
assert.deepEqual(list, [1, 2]);
|
||||||
|
|
||||||
|
done();
|
||||||
|
})().catch(done);
|
||||||
|
|
||||||
28
packages/babel/test/fixtures/traceur/AsyncGenerators/ThrowInAsyncGenerator.js
vendored
Normal file
28
packages/babel/test/fixtures/traceur/AsyncGenerators/ThrowInAsyncGenerator.js
vendored
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
// Options: --async-generators --for-on --async-functions
|
||||||
|
// Async.
|
||||||
|
|
||||||
|
async function* f() {
|
||||||
|
for (var i = 1; i < 4; ++i) {
|
||||||
|
yield i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
(async function() {
|
||||||
|
var list = [];
|
||||||
|
var g = f();
|
||||||
|
try {
|
||||||
|
for (var i on g) {
|
||||||
|
if (i == 2) {
|
||||||
|
throw 'ex';
|
||||||
|
}
|
||||||
|
list.push(i);
|
||||||
|
}
|
||||||
|
} catch (ex) {
|
||||||
|
assert.equal(ex, 'ex');
|
||||||
|
}
|
||||||
|
assert.deepEqual(list, [1]);
|
||||||
|
|
||||||
|
done();
|
||||||
|
})().catch(done);
|
||||||
|
|
||||||
25
packages/babel/test/fixtures/traceur/AsyncGenerators/YieldFor.js
vendored
Normal file
25
packages/babel/test/fixtures/traceur/AsyncGenerators/YieldFor.js
vendored
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
// Options: --async-generators --for-on --async-functions
|
||||||
|
// Async.
|
||||||
|
|
||||||
|
async function* f1() {
|
||||||
|
yield 1;
|
||||||
|
yield* f2();
|
||||||
|
yield 4;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function* f2() {
|
||||||
|
yield 2;
|
||||||
|
yield 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
(async function() {
|
||||||
|
var list = [];
|
||||||
|
var g = f1();
|
||||||
|
for (var i on g) {
|
||||||
|
list.push(i);
|
||||||
|
}
|
||||||
|
assert.deepEqual(list, [1, 2, 3, 4]);
|
||||||
|
|
||||||
|
done();
|
||||||
|
})().catch(done);
|
||||||
|
|
||||||
24
packages/babel/test/fixtures/traceur/AsyncGenerators/YieldForOn.js
vendored
Normal file
24
packages/babel/test/fixtures/traceur/AsyncGenerators/YieldForOn.js
vendored
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
// Options: --async-generators --for-on --async-functions
|
||||||
|
// Async.
|
||||||
|
|
||||||
|
async function* f() {
|
||||||
|
yield 1;
|
||||||
|
yield 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function* g() {
|
||||||
|
for (i on f()) {
|
||||||
|
yield 2 * i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
(async function() {
|
||||||
|
var list = [];
|
||||||
|
for (var i on g()) {
|
||||||
|
list.push(i);
|
||||||
|
}
|
||||||
|
assert.deepEqual(list, [2, 4]);
|
||||||
|
|
||||||
|
done();
|
||||||
|
})().catch(done);
|
||||||
|
|
||||||
71
packages/babel/test/fixtures/traceur/AsyncGenerators/resources/observable.js
vendored
Normal file
71
packages/babel/test/fixtures/traceur/AsyncGenerators/resources/observable.js
vendored
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
const generator = Symbol();
|
||||||
|
const onDone = Symbol();
|
||||||
|
const generatorFunction = Symbol();
|
||||||
|
|
||||||
|
function schedule(asyncF) {
|
||||||
|
return Promise.resolve().then(asyncF);
|
||||||
|
}
|
||||||
|
|
||||||
|
class DecoratedGenerator {
|
||||||
|
constructor(_generator, _onDone) {
|
||||||
|
this[generator] = _generator;
|
||||||
|
this[onDone] = _onDone;
|
||||||
|
}
|
||||||
|
|
||||||
|
next(value) {
|
||||||
|
var result = this[generator].next();
|
||||||
|
if (result.done) {
|
||||||
|
this[onDone].call(this);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
throw(error) {
|
||||||
|
this[onDone].call(this);
|
||||||
|
return this[generator].throw(error);
|
||||||
|
}
|
||||||
|
|
||||||
|
return(value) {
|
||||||
|
this[onDone].call(this);
|
||||||
|
return this[generator].return(value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
export class AsyncGeneratorFunction {
|
||||||
|
constructor(_generatorFunction) {
|
||||||
|
this[generatorFunction] = _generatorFunction;
|
||||||
|
}
|
||||||
|
|
||||||
|
[Symbol.observer](observer) {
|
||||||
|
var generator = this[generatorFunction].call(this);
|
||||||
|
var done = false;
|
||||||
|
schedule(async function () {
|
||||||
|
var result;
|
||||||
|
while (!done) {
|
||||||
|
try {
|
||||||
|
result = generator.next();
|
||||||
|
} catch (e) {
|
||||||
|
observer.throw(e);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (result.done) {
|
||||||
|
observer.return(result.value);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
result = observer.next(result.value);
|
||||||
|
} catch (e) {
|
||||||
|
generator.throw(e);
|
||||||
|
}
|
||||||
|
if (result.done) {
|
||||||
|
generator.return();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
await result.value;
|
||||||
|
}
|
||||||
|
generator.return();
|
||||||
|
});
|
||||||
|
return new DecoratedGenerator(observer, () => { done = true });
|
||||||
|
}
|
||||||
|
}
|
||||||
23
packages/babel/test/fixtures/traceur/Classes/ClassMethodInheritance.js
vendored
Normal file
23
packages/babel/test/fixtures/traceur/Classes/ClassMethodInheritance.js
vendored
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
function B() {}
|
||||||
|
B.b = function() {
|
||||||
|
return 'B.b';
|
||||||
|
};
|
||||||
|
|
||||||
|
class C extends B {}
|
||||||
|
|
||||||
|
assert.equal(Object.getPrototypeOf(C), B);
|
||||||
|
assert.equal(Object.getPrototypeOf(C.prototype), B.prototype);
|
||||||
|
|
||||||
|
assert.equal(C.b(), 'B.b');
|
||||||
|
|
||||||
|
class D extends Object {}
|
||||||
|
|
||||||
|
assert.equal(Object.getPrototypeOf(D), Object);
|
||||||
|
assert.equal(Object.getPrototypeOf(D.prototype), Object.prototype);
|
||||||
|
assert.equal(D.keys, Object.keys);
|
||||||
|
|
||||||
|
class E {}
|
||||||
|
|
||||||
|
assert.equal(Object.getPrototypeOf(E), Function.prototype);
|
||||||
|
assert.equal(Object.getPrototypeOf(E.prototype), Object.prototype);
|
||||||
|
assert.isFalse('keys' in E);
|
||||||
41
packages/babel/test/fixtures/traceur/Classes/ClassNameBinding.js
vendored
Normal file
41
packages/babel/test/fixtures/traceur/Classes/ClassNameBinding.js
vendored
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
|
||||||
|
var ClassExpr = class {
|
||||||
|
m() {
|
||||||
|
return ClassExpr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var TempClass = ClassExpr;
|
||||||
|
ClassExpr = 42;
|
||||||
|
|
||||||
|
assert.equal(42, new TempClass().m());
|
||||||
|
assert.equal(TempClass.name, '');
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
var ClassExpr2 = class ClassExprInner {
|
||||||
|
m() {
|
||||||
|
return ClassExprInner;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
TempClass = ClassExpr2;
|
||||||
|
ClassExpr2 = 42;
|
||||||
|
|
||||||
|
assert.equal(TempClass, new TempClass().m());
|
||||||
|
assert.equal(TempClass.name, 'ClassExprInner');
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
class ClassDef {
|
||||||
|
m() {
|
||||||
|
return ClassDef;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var TempClass = ClassDef;
|
||||||
|
ClassDef = 42;
|
||||||
|
|
||||||
|
assert.equal(TempClass, new TempClass().m());
|
||||||
|
// IE does not have a name property on functions.
|
||||||
|
assert.isTrue(TempClass.name === 'ClassDef' || TempClass.name === undefined);
|
||||||
29
packages/babel/test/fixtures/traceur/Classes/ClassNameInStack.js
vendored
Normal file
29
packages/babel/test/fixtures/traceur/Classes/ClassNameInStack.js
vendored
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
class MyClassName {
|
||||||
|
m() {
|
||||||
|
throw new Error();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
new MyClassName().m();
|
||||||
|
fail('Should have thrown');
|
||||||
|
} catch (ex) {
|
||||||
|
if (ex.stack)
|
||||||
|
assert.isTrue(String(ex.stack).indexOf('MyClassName') >= 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
class MySecondClass extends MyClassName{
|
||||||
|
m() {
|
||||||
|
throw new Error();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
new MySecondClass().m();
|
||||||
|
fail('Should have thrown');
|
||||||
|
} catch (ex) {
|
||||||
|
if (ex.stack)
|
||||||
|
assert.isTrue(String(ex.stack).indexOf('MySecondClass') >= 0);
|
||||||
|
}
|
||||||
34
packages/babel/test/fixtures/traceur/Classes/Constructor.js
vendored
Normal file
34
packages/babel/test/fixtures/traceur/Classes/Constructor.js
vendored
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
class Point {
|
||||||
|
constructor(x, y) {
|
||||||
|
this.x = x;
|
||||||
|
this.y = y;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class A {
|
||||||
|
classRef() {
|
||||||
|
return A;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
var p = new Point(1, 2);
|
||||||
|
assert.equal(1, p.x);
|
||||||
|
assert.equal(2, p.y);
|
||||||
|
|
||||||
|
var p2 = new Point(3, 4);
|
||||||
|
assert.equal(3, p2.x);
|
||||||
|
assert.equal(4, p2.y);
|
||||||
|
assert.equal(1, p.x);
|
||||||
|
assert.equal(2, p.y);
|
||||||
|
|
||||||
|
for (var element in Point) {
|
||||||
|
fail('Point contains static member : ' + element);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Tests to ensure that we're not binding function identifier per class
|
||||||
|
var a = new A();
|
||||||
|
var tmpA = A;
|
||||||
|
A = 42;
|
||||||
|
assert.equal(tmpA, a.classRef());
|
||||||
|
// IE does not have a name property on functions.
|
||||||
|
assert.isTrue(tmpA.name === 'A' || tmpA.name === undefined);
|
||||||
22
packages/babel/test/fixtures/traceur/Classes/ConstructorChaining.js
vendored
Normal file
22
packages/babel/test/fixtures/traceur/Classes/ConstructorChaining.js
vendored
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
class ConstructorA {
|
||||||
|
constructor(x) {
|
||||||
|
this.x = x;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class ConstructorB extends ConstructorA {
|
||||||
|
constructor(x, y) {
|
||||||
|
super(x);
|
||||||
|
this.y = y;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
var a = new ConstructorA('ax');
|
||||||
|
assert.equal('ax', a.x);
|
||||||
|
assert.isFalse(a.hasOwnProperty('y'));
|
||||||
|
|
||||||
|
var b = new ConstructorB('bx', 'by');
|
||||||
|
assert.equal('bx', b.x);
|
||||||
|
assert.equal('by', b.y);
|
||||||
27
packages/babel/test/fixtures/traceur/Classes/ConstructorMember.js
vendored
Normal file
27
packages/babel/test/fixtures/traceur/Classes/ConstructorMember.js
vendored
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
class ConstructorMember {
|
||||||
|
constructor() {}
|
||||||
|
}
|
||||||
|
|
||||||
|
class DerivedConstructorMember extends ConstructorMember {
|
||||||
|
constructor() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
var cm = new ConstructorMember;
|
||||||
|
assert.equal(cm.constructor, ConstructorMember.prototype.constructor);
|
||||||
|
assert.isTrue(ConstructorMember.prototype.hasOwnProperty('constructor'));
|
||||||
|
|
||||||
|
for (var key in ConstructorMember) {
|
||||||
|
assert.notEqual('constructor should not be enumerable', 'constructor', key);
|
||||||
|
}
|
||||||
|
|
||||||
|
var dcm = new DerivedConstructorMember;
|
||||||
|
assert.equal(dcm.constructor, DerivedConstructorMember.prototype.constructor);
|
||||||
|
assert.isTrue(DerivedConstructorMember.prototype.hasOwnProperty('constructor'));
|
||||||
|
|
||||||
|
for (var key in DerivedConstructorMember) {
|
||||||
|
assert.notEqual('constructor should not be enumerable', 'constructor', key);
|
||||||
|
}
|
||||||
31
packages/babel/test/fixtures/traceur/Classes/DefaultConstructor.js
vendored
Normal file
31
packages/babel/test/fixtures/traceur/Classes/DefaultConstructor.js
vendored
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
class B {
|
||||||
|
constructor(x, y) {
|
||||||
|
this.x = x;
|
||||||
|
this.y = y;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class C extends B {
|
||||||
|
// No constructor
|
||||||
|
}
|
||||||
|
|
||||||
|
var c = new B(1, 2);
|
||||||
|
assert.equal(1, c.x);
|
||||||
|
assert.equal(2, c.y);
|
||||||
|
|
||||||
|
assert.isFalse(
|
||||||
|
Object.getOwnPropertyDescriptor(B.prototype, 'constructor').enumerable);
|
||||||
|
assert.isFalse(
|
||||||
|
Object.getOwnPropertyDescriptor(C.prototype, 'constructor').enumerable);
|
||||||
|
|
||||||
|
// Ensure that we don't try to call super() in the default constructor.
|
||||||
|
class D extends null {}
|
||||||
|
var d = new D();
|
||||||
|
|
||||||
|
|
||||||
|
class E extends function(x) {
|
||||||
|
this.x = x;
|
||||||
|
} {}
|
||||||
|
|
||||||
|
var e = new E(42)
|
||||||
|
assert.equal(42, e.x);
|
||||||
6
packages/babel/test/fixtures/traceur/Classes/DeriveFromObject.js
vendored
Normal file
6
packages/babel/test/fixtures/traceur/Classes/DeriveFromObject.js
vendored
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
class DerivedFromObject extends Object {
|
||||||
|
}
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// TODO(rnystrom): No tests for this?
|
||||||
29
packages/babel/test/fixtures/traceur/Classes/EmptyClass.js
vendored
Normal file
29
packages/babel/test/fixtures/traceur/Classes/EmptyClass.js
vendored
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
class Empty {}
|
||||||
|
|
||||||
|
class EmptyB extends Empty {
|
||||||
|
}
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
var e = new Empty();
|
||||||
|
assert.isNotNull(e);
|
||||||
|
|
||||||
|
for (var element in e) {
|
||||||
|
assert.equal('constructor', element);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (var element in Empty) {
|
||||||
|
fail('Empty contains static member : ' + element);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Instances should be different.
|
||||||
|
var e2 = new Empty();
|
||||||
|
assert.notEqual(e, e2);
|
||||||
|
|
||||||
|
assert.isTrue(e instanceof Empty);
|
||||||
|
assert.isFalse(e instanceof EmptyB);
|
||||||
|
|
||||||
|
var b = new EmptyB();
|
||||||
|
|
||||||
|
assert.isTrue(b instanceof Empty);
|
||||||
|
assert.isTrue(b instanceof EmptyB);
|
||||||
4
packages/babel/test/fixtures/traceur/Classes/Error_Disabled.js
vendored
Normal file
4
packages/babel/test/fixtures/traceur/Classes/Error_Disabled.js
vendored
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
// Options: --classes=false
|
||||||
|
// Error: :4:1: Unexpected reserved word
|
||||||
|
|
||||||
|
class C {}
|
||||||
5
packages/babel/test/fixtures/traceur/Classes/Error_GH1556.js
vendored
Normal file
5
packages/babel/test/fixtures/traceur/Classes/Error_GH1556.js
vendored
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
// Error: :5:19: Unexpected token =
|
||||||
|
|
||||||
|
// extends LeftHandSideExpression
|
||||||
|
// see https://github.com/google/traceur-compiler/issues/1556
|
||||||
|
class A extends B = C {}
|
||||||
22
packages/babel/test/fixtures/traceur/Classes/Error_NestedFunctionSuper.js
vendored
Normal file
22
packages/babel/test/fixtures/traceur/Classes/Error_NestedFunctionSuper.js
vendored
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
// Error: :8:14: super is only allowed in methods
|
||||||
|
// Error: :14:16: super is only allowed in methods
|
||||||
|
// Error: :19:19: super is only allowed in methods
|
||||||
|
|
||||||
|
class C {
|
||||||
|
superM() {
|
||||||
|
return (function() {
|
||||||
|
return super.m();
|
||||||
|
})();
|
||||||
|
}
|
||||||
|
superX2() {
|
||||||
|
return (function() {
|
||||||
|
return (function() {
|
||||||
|
return super.x;
|
||||||
|
})();
|
||||||
|
})();
|
||||||
|
}
|
||||||
|
constructor() {
|
||||||
|
(function() { super(); })();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
7
packages/babel/test/fixtures/traceur/Classes/Error_NewSuper.js
vendored
Normal file
7
packages/babel/test/fixtures/traceur/Classes/Error_NewSuper.js
vendored
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
// Error: :5:14: Unexpected token (
|
||||||
|
|
||||||
|
class C {
|
||||||
|
m() {
|
||||||
|
new super();
|
||||||
|
}
|
||||||
|
}
|
||||||
7
packages/babel/test/fixtures/traceur/Classes/Error_NewSuper2.js
vendored
Normal file
7
packages/babel/test/fixtures/traceur/Classes/Error_NewSuper2.js
vendored
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
// Error: :6:3: Unexpected token }
|
||||||
|
|
||||||
|
class C {
|
||||||
|
m() {
|
||||||
|
new super
|
||||||
|
}
|
||||||
|
}
|
||||||
9
packages/babel/test/fixtures/traceur/Classes/Error_NoSuperInDerivedClass.js
vendored
Normal file
9
packages/babel/test/fixtures/traceur/Classes/Error_NoSuperInDerivedClass.js
vendored
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
// Error: :6:3: Derived constructor must call super()
|
||||||
|
|
||||||
|
class B {}
|
||||||
|
|
||||||
|
class C extends B {
|
||||||
|
constructor() {
|
||||||
|
// no super call
|
||||||
|
}
|
||||||
|
}
|
||||||
10
packages/babel/test/fixtures/traceur/Classes/Error_Super.js
vendored
Normal file
10
packages/babel/test/fixtures/traceur/Classes/Error_Super.js
vendored
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
// Error: :7:17: Unexpected token ;
|
||||||
|
|
||||||
|
class A {}
|
||||||
|
|
||||||
|
class ImproperSuper extends A {
|
||||||
|
method() {
|
||||||
|
return super;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
10
packages/babel/test/fixtures/traceur/Classes/Error_SuperAsTemplateTag.js
vendored
Normal file
10
packages/babel/test/fixtures/traceur/Classes/Error_SuperAsTemplateTag.js
vendored
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
// Error: :7:18: Unexpected token `
|
||||||
|
|
||||||
|
class A {}
|
||||||
|
|
||||||
|
class ImproperSuper extends A {
|
||||||
|
method() {
|
||||||
|
return super ``;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
7
packages/babel/test/fixtures/traceur/Classes/Error_SuperCallInNonDerived.js
vendored
Normal file
7
packages/babel/test/fixtures/traceur/Classes/Error_SuperCallInNonDerived.js
vendored
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
// Error: :5:5: super call is only allowed in derived constructor
|
||||||
|
|
||||||
|
class C {
|
||||||
|
constructor() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
}
|
||||||
15
packages/babel/test/fixtures/traceur/Classes/Error_SuperNestedClass.js
vendored
Normal file
15
packages/babel/test/fixtures/traceur/Classes/Error_SuperNestedClass.js
vendored
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
// Error: :12:5: 'this' is not allowed before super()
|
||||||
|
|
||||||
|
class Animal {}
|
||||||
|
|
||||||
|
class Roo extends Animal {
|
||||||
|
constructor() {
|
||||||
|
class Koala extends Animal {
|
||||||
|
constructor() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.a = new Koala;
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
}
|
||||||
10
packages/babel/test/fixtures/traceur/Classes/Error_SuperPropertyOutsideMethod.js
vendored
Normal file
10
packages/babel/test/fixtures/traceur/Classes/Error_SuperPropertyOutsideMethod.js
vendored
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
// Error: :6:3: super is only allowed in methods
|
||||||
|
// Error: :9:15: super is only allowed in methods
|
||||||
|
// Error: :10:17: super is only allowed in methods
|
||||||
|
|
||||||
|
function f() {
|
||||||
|
super.x;
|
||||||
|
}
|
||||||
|
|
||||||
|
var g = () => super.y;
|
||||||
|
var h = () => { super.z; }
|
||||||
10
packages/babel/test/fixtures/traceur/Classes/ExtendCoverFormals.js
vendored
Normal file
10
packages/babel/test/fixtures/traceur/Classes/ExtendCoverFormals.js
vendored
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
class C {}
|
||||||
|
|
||||||
|
var x = 1;
|
||||||
|
var y = C;
|
||||||
|
class D extends (x, y) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
assert.instanceOf(new D(), C);
|
||||||
|
assert.instanceOf(new D(), D);
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user