Merge remote-tracking branch 'origin/master' into amd-port-interop

Conflicts:
	test/fixtures/transformation/es6-modules-amd/exports-default/expected.js
	test/fixtures/transformation/es6-modules-amd/overview/expected.js
	test/fixtures/transformation/es6-modules-umd/exports-default/expected.js
	test/fixtures/transformation/es6-modules-umd/overview/expected.js
This commit is contained in:
Lars Kappert
2015-01-06 20:21:00 +01:00
332 changed files with 1720 additions and 3910 deletions

View File

@@ -1,8 +1,9 @@
var fs = require("fs");
var _ = require("lodash");
var path = require("path");
var fs = require("fs");
var _ = require("lodash");
var humanise = function (val) {
return val.replace(/-/g, " ");
return path.basename(val, path.extname(val)).replace(/-/g, " ");
};
var readFile = exports.readFile = function (filename) {
@@ -15,11 +16,11 @@ var readFile = exports.readFile = function (filename) {
}
};
exports.get = function (entryName) {
exports.get = function (entryName, entryLoc) {
if (exports.cache[entryName]) return exports.cache[entryName];
var suites = [];
var entryLoc = __dirname + "/fixtures/" + entryName;
var entryLoc = entryLoc || __dirname + "/fixtures/" + entryName;
_.each(fs.readdirSync(entryLoc), function (suiteName) {
if (suiteName[0] === ".") return;
@@ -35,9 +36,18 @@ exports.get = function (entryName) {
var suiteOptsLoc = suite.filename + "/options.json";
if (fs.existsSync(suiteOptsLoc)) suite.options = require(suiteOptsLoc);
_.each(fs.readdirSync(suite.filename), function (taskName) {
var taskDir = suite.filename + "/" + taskName;
if (fs.statSync(taskDir).isFile()) return;
if (fs.statSync(suite.filename).isFile()) {
push(suiteName, suite.filename);
} else {
_.each(fs.readdirSync(suite.filename), function (taskName) {
var taskDir = suite.filename + "/" + taskName;
push(taskName, taskDir);
});
}
function push(taskName, taskDir) {
// tracuer error tests
if (taskName.indexOf("Error_") >= 0) return;
var actualLocAlias = suiteName + "/" + taskName + "/actual.js";
var expectLocAlias = suiteName + "/" + taskName + "/expected.js";
@@ -47,6 +57,13 @@ exports.get = function (entryName) {
var expectLoc = taskDir + "/expected.js";
var execLoc = taskDir + "/exec.js";
if (fs.statSync(taskDir).isFile()) {
var ext = path.extname(taskDir);
if (ext !== ".js" && ext !== ".module.js") return;
execLoc = taskDir;
}
var taskOpts = _.merge({
filenameRelative: expectLocAlias,
sourceFileName: actualLocAlias,
@@ -77,6 +94,18 @@ exports.get = function (entryName) {
}
};
// traceur checks
var shouldSkip = function (code) {
return code.indexOf("// Error:") >= 0 || code.indexOf("// Skip.") >= 0;
};
if (shouldSkip(test.actual.code) || shouldSkip(test.exec.code)) {
return;
} else if (test.exec.code.indexOf("// Async.") >= 0) {
//test.options.asyncExec = true;
}
suite.tests.push(test);
var sourceMappingsLoc = taskDir + "/source-mappings.json";
@@ -90,7 +119,7 @@ exports.get = function (entryName) {
test.options.sourceMap = true;
test.sourceMap = require(sourceMap);
}
});
}
});
return exports.cache[entryName] = suites;
@@ -104,4 +133,5 @@ try {
var cache = exports.cache = {};
cache.transformation = exports.get("transformation");
cache.generation = exports.get("generation");
cache.esnext = exports.get("esnext");
}

View File

@@ -0,0 +1,168 @@
var genHelpers = require("./_generator-helpers");
var transform = require("../lib/6to5/transformation/transform");
var sourceMap = require("source-map");
var esvalid = require("esvalid");
var Module = require("module");
var helper = require("./_helper");
var assert = require("assert");
var chai = require("chai");
var path = require("path");
var util = require("../lib/6to5/util");
var _ = require("lodash");
require("../lib/6to5/polyfill");
global.assertNoOwnProperties = function (obj) {
assert.equal(Object.getOwnPropertyNames(obj).length, 0);
};
global.assertArrayEquals = assert.deepEqual;
global.assert = chai.assert;
global.chai = chai;
global.genHelpers = genHelpers;
// Different Traceur generator message
chai.assert._throw = chai.assert.throw;
chai.assert.throw = function (fn, msg) {
if (msg === '"throw" on executing generator' ||
msg === '"next" on executing generator') {
msg = "Generator is already running";
} else if (msg === "Sent value to newborn generator") {
msg = /^attempt to send (.*?) to newborn generator$/;
}
return chai.assert._throw(fn, msg);
};
var run = function (task, done) {
var actual = task.actual;
var expect = task.expect;
var exec = task.exec;
var opts = task.options;
var getOpts = function (self) {
return _.merge({
filename: self.loc
}, opts);
};
var execCode = exec.code;
var result;
var checkAst = function (result) {
if (opts.noCheckAst) return;
var errors = esvalid.errors(result.ast.program);
if (errors.length) {
var msg = [];
_.each(errors, function (err) {
msg.push(err.message + " - " + JSON.stringify(err.node));
});
throw new Error(msg.join(". "));
}
};
if (execCode) {
result = transform(execCode, getOpts(exec));
checkAst(result);
execCode = result.code;
try {
var fakeRequire = function (loc) {
if (loc === "../../../src/runtime/polyfills/Number.js") {
return Number;
} else if (loc === "../../../src/runtime/polyfills/Math.js") {
return Math;
} else {
return require(path.resolve(exec.loc, "..", loc));
}
};
var fn = new Function("require", "done", execCode);
fn.call(global, fakeRequire, chai.assert, done);
} catch (err) {
err.message = exec.loc + ": " + err.message;
err.message += util.codeFrame(execCode);
throw err;
}
}
var actualCode = actual.code;
var expectCode = expect.code;
if (!execCode || actualCode) {
result = transform(actualCode, getOpts(actual));
checkAst(result);
actualCode = result.code;
chai.expect(actualCode).to.be.equal(expectCode, actual.loc + " !== " + expect.loc);
}
if (task.sourceMap) {
chai.expect(result.map).to.deep.equal(task.sourceMap);
}
if (task.sourceMappings) {
var consumer = new sourceMap.SourceMapConsumer(result.map);
_.each(task.sourceMappings, function (mapping, i) {
var expect = mapping.original;
var actual = consumer.originalPositionFor(mapping.generated);
chai.expect({ line: actual.line, column: actual.column }).to.deep.equal(expect);
});
}
};
module.exports = function (suiteOpts, taskOpts, dynamicOpts) {
taskOpts = taskOpts || {};
require("../register")(taskOpts);
_.each(helper.get(suiteOpts.name, suiteOpts.loc), function (testSuite) {
if (_.contains(suiteOpts.ignoreSuites, testSuite.title)) return;
suite(suiteOpts.name + "/" + testSuite.title, function () {
_.each(testSuite.tests, function (task) {
if (_.contains(suiteOpts.ignoreTasks, task.title) || _.contains(suiteOpts.ignoreTasks, testSuite.title + "/" + task.title)) return;
var runTest = function (done) {
var runTask = function () {
try {
run(task, done);
} catch (err) {
if (task.options.after) task.options.after();
throw err;
}
};
_.extend(task.options, taskOpts);
if (dynamicOpts) dynamicOpts(task.options, task);
var throwMsg = task.options.throws;
if (throwMsg) {
// internal api doesn't have this option but it's best not to pollute
// the options object with useless options
delete task.options.throws;
assert.throws(runTask, function (err) {
return throwMsg === true || err.message.indexOf(throwMsg) >= 0;
});
} else {
runTask();
}
};
var callback;
if (task.options.asyncExec) {
callback = runTest;
} else {
callback = function () {
return runTest();
};
}
test(task.title, !task.disabled && callback);
});
});
});
};

5
test/esnext.js Normal file
View File

@@ -0,0 +1,5 @@
if (!process.env.ALL_6TO5_TESTS) return;
require("./_transformation-helper")({
name: "esnext"
});

View File

@@ -0,0 +1,57 @@
function makeMultiplier() {
// `arguments` should refer to `makeMultiplier`'s arguments.
return (n) => [].slice.call(arguments).reduce((a, b) => a * b) * n;
}
function toArray() {
// Intentionally nest arrow functions to ensure `arguments` is put inside
// `toArray`'s scope.
return (() => (arguments, (() => [].slice.call(arguments)).call())).call();
}
function returnDotArguments(object) {
// Ensure `arguments` is not treated as a reference to the magic value.
return (() => object.arguments).call();
}
function returnArgumentsObject() {
// Ensure `arguments` is not treated as a reference to the magic value.
return (() => ({arguments: 1})).call();
}
function makeArgumentsReturner() {
return (() => function() {
return [].slice.call(arguments);
}).call();
}
// i.e. 2 * 3 * 4 == 24, not 16 (4 * 4)
assert.equal(
makeMultiplier(2, 3)(4),
24,
'ensure `arguments` is hoisted out to the first non-arrow scope'
);
assert.deepEqual(
toArray(1, 2, 3),
[1, 2, 3],
'ensure `arguments` is hoisted out to the first non-arrow scope'
);
assert.equal(
returnDotArguments({arguments: 1}),
1,
'member accesses with `arguments` property should not be replaced'
);
assert.deepEqual(
returnArgumentsObject(),
{arguments: 1},
'object property keys named `arguments` should not be replaced'
);
assert.deepEqual(
makeArgumentsReturner()(1, 2, 3),
[1, 2, 3],
'arguments should not be hoisted from inside non-arrow functions'
);

View File

@@ -0,0 +1,5 @@
var dynamicThisGetter = () => function () { return this; };
assert.equal(
'(' + dynamicThisGetter.toString() + ')',
'(function () {\n return function () {\n return this;\n };\n})'
);

View File

@@ -0,0 +1,2 @@
var empty = () => {};
assert.equal(empty(), undefined);

View File

@@ -0,0 +1,12 @@
var obj = {
method: function() {
return () => (this, () => this);
},
method2: function() {
return () => () => this;
}
};
assert.strictEqual(obj.method()()(), obj);
assert.strictEqual(obj.method2()()(), obj);

View File

@@ -0,0 +1,2 @@
var square = x => x * x;
assert.equal(square(4), 16);

View File

@@ -0,0 +1,2 @@
var keyMaker = val => ({ key: val });
assert.deepEqual(keyMaker(9), { key: 9 });

View File

@@ -0,0 +1,7 @@
var obj = {
method: function() {
return () => this;
}
};
assert.strictEqual(obj.method()(), obj);

View File

@@ -0,0 +1,2 @@
var odds = [0, 2, 4].map(v => v + 1);
assert.deepEqual(odds, [1, 3, 5]);

View File

@@ -0,0 +1,2 @@
var identity = x => x;
assert.equal(identity(1), 1);

View File

@@ -0,0 +1,29 @@
var Animal = class {
sayHi() {
return 'Hi, I am a '+this.type()+'.';
}
static getName() {
return 'Animal';
}
};
var Dog = class extends Animal {
type() { return 'dog'; }
sayHi() {
return super() + ' WOOF!';
}
static getName() {
return super() + '/Dog';
}
};
assert.equal(new Dog().sayHi(), 'Hi, I am a dog. WOOF!');
assert.equal(Dog.getName(), 'Animal/Dog');
var count = 0;
var Cat = class extends (function(){ count++; return Animal; })() {};
assert.equal(count, 1);

View File

@@ -0,0 +1,21 @@
class Animal {
sayHi() {
return 'I am an animal.'
}
sayOther() {
return 'WAT?!';
}
}
class Horse extends Animal {
sayHi() {
return super.sayOther();
}
sayOther() {
return 'I see dead objects.';
}
}
assert.equal(new Horse().sayHi(), 'WAT?!');

View File

@@ -0,0 +1,9 @@
var Person = (class Person {});
assert.equal(typeof Person, 'function');
assert.equal(
(function(){ return (class Person {}); })().name,
'Person'
);
assert.equal(typeof (class {}), 'function');

View File

@@ -0,0 +1,15 @@
class Animal {
sayHi() {
return 'Hi, I am a '+this.type()+'.';
}
}
class Dog extends Animal {
type() { return 'dog'; }
sayHi() {
return super() + ' WOOF!';
}
}
assert.equal(new Dog().sayHi(), 'Hi, I am a dog. WOOF!');

View File

@@ -0,0 +1,14 @@
class Multiplier {
constructor(n=1) {
this.n = n;
}
multiply(n=1) {
return n * this.n;
}
}
assert.equal(new Multiplier().n, 1);
assert.equal(new Multiplier(6).n, 6);
assert.equal(new Multiplier().multiply(), 1);
assert.equal(new Multiplier(2).multiply(3), 6);

View File

@@ -0,0 +1,10 @@
class Person {
getName() {
return this.firstName + ' ' + this.lastName;
}
}
var me = new Person();
me.firstName = 'Brian';
me.lastName = 'Donovan';
assert.equal(me.getName(), 'Brian Donovan');

View File

@@ -0,0 +1,5 @@
class Foo {
}
assert.equal(new Foo().constructor, Foo, 'Foo instances should have Foo as constructor');
assert.ok(new Foo() instanceof Foo, 'Foo instances should be `instanceof` Foo');

View File

@@ -0,0 +1,20 @@
class Point {
constructor(x, y) {
this.x = x;
this.y = y;
}
toString() {
return '(' + this.x + ', ' + this.y + ')';
}
}
var point = new Point(1, 2);
var keys = [];
for (var key in point) {
keys.push(key);
}
assert.equal(point.toString(), '(1, 2)');
assert.deepEqual(keys.sort(), ['toString', 'x', 'y']);

View File

@@ -0,0 +1,15 @@
class Point {
constructor(x, y) {
this.x = x;
this.y = y;
}
}
class ZeroPoint extends Point {
constructor() {
super(0, 0);
}
}
assert.equal(new ZeroPoint().x, 0);
assert.equal(new ZeroPoint().y, 0);

View File

@@ -0,0 +1,4 @@
class Obj extends null {}
assert.strictEqual(Obj.toString, Function.toString);
assert.strictEqual(new Obj().toString, undefined);

View File

@@ -0,0 +1,15 @@
class Animal {
get sound() {
return 'I am a ' + this.type + '.';
}
}
class Cat extends Animal {
get type() { return 'cat'; }
get sound() {
return super.sound + ' MEOW!';
}
}
assert.equal(new Cat().sound, 'I am a cat. MEOW!');

View File

@@ -0,0 +1,28 @@
class Person {
constructor(firstName, lastName) {
this.firstName = firstName;
this.lastName = lastName;
}
get name() {
return this.firstName + ' ' + this.lastName;
}
set name(name) {
var parts = name.split(' ');
this.firstName = parts[0];
this.lastName = parts[1];
}
}
var mazer = new Person('Mazer', 'Rackham');
assert.equal(mazer.name, 'Mazer Rackham');
mazer.name = 'Ender Wiggin';
assert.equal(mazer.firstName, 'Ender');
assert.equal(mazer.lastName, 'Wiggin');
var forLoopProperties = [];
for (var key in mazer) {
forLoopProperties.push(key);
}
assert.ok(forLoopProperties.indexOf('name') >= 0, 'getters/setters are enumerable');

View File

@@ -0,0 +1,9 @@
class Obj {
constructor() {
super();
}
}
assert.doesNotThrow(function() {
new Obj();
});

View File

@@ -0,0 +1,7 @@
class Tripler {
triple(n) {
return n * 3;
}
}
assert.equal(new Tripler().triple(2), 6);

View File

@@ -0,0 +1,12 @@
var value;
class Foo {
foo() {
value = 1;
}
}
var foo = new Foo();
foo.foo = function() { value = 2; };
foo.foo();
assert.equal(value, 2);

View File

@@ -0,0 +1,28 @@
class Joiner {
constructor(string) {
this.string = string;
}
join(...items) {
return items.join(this.string);
}
static join(string, ...items) {
var joiner = new this(string);
// TODO: use spread params here
return joiner.join.apply(joiner, items);
}
}
class ArrayLike {
constructor(...items) {
items.forEach(function(item, i) {
this[i] = item;
}.bind(this));
this.length = items.length;
}
}
var joiner = new Joiner(' & ');
assert.equal(joiner.join(4, 5, 6), '4 & 5 & 6');
assert.equal(new ArrayLike('a', 'b')[1], 'b');

View File

@@ -0,0 +1,12 @@
class Point {
constructor(x, y) {
this.x = x;
this.y = y;
}
static get ORIGIN() {
return new this(0, 0);
}
}
assert.deepEqual(Point.ORIGIN, new Point(0, 0));

View File

@@ -0,0 +1,30 @@
class Tripler {
static triple(n=1) {
return n * 3;
}
static toString() {
return '3' + super() + '3';
}
}
class MegaTripler extends Tripler {
static triple(n=1) {
return super(n) * super(n);
}
}
var tripler = new Tripler();
assert.equal(Tripler.triple(), 3);
assert.equal(Tripler.triple(2), 6);
assert.equal(tripler.triple, undefined);
assert.equal(Tripler.toString(), '3' + Object.toString.call(Tripler) + '3');
var mega = new MegaTripler();
assert.equal(MegaTripler.triple(2), 36);
assert.equal(mega.triple, undefined);
assert.equal(MegaTripler.toString(), '3' + Object.toString.call(MegaTripler) + '3');

View File

@@ -0,0 +1,7 @@
class Person {
static set DB(value) {
assert.equal(value, 'mysql');
}
}
Person.DB = 'mysql';

View File

@@ -0,0 +1,21 @@
var log = '';
class Base {
p() { log += '[Base]'; }
}
class OtherBase {
p() { log += '[OtherBase]'; }
}
class Derived extends Base {
p() {
log += '[Derived]';
super();
Derived.prototype.__proto__ = OtherBase.prototype;
super();
}
}
new Derived().p();
assert.equal(log, '[Derived][Base][OtherBase]');

View File

@@ -0,0 +1,8 @@
var x = 'y';
var foo = {
get [x]() { return this._y; },
set [x](v) { this._y = v; }
};
assert.equal((foo.y = 10, foo.y), 10);

View File

@@ -0,0 +1,3 @@
var x = 'y';
assert.equal({[x]: function() { return 10; }}.y(), 10);
assert.equal({[x + 'y']() { return 10; }}.yy(), 10);

View File

@@ -0,0 +1,4 @@
var x = 'y';
var foo = {[x]: 10, z: {[x]: 10}};
assert.equal(foo.y + foo.z.y, 20);
assert.equal({[x]: {[x]: {[x]: 10}}}.y.y.y, 10);

View File

@@ -0,0 +1,3 @@
var x = 'y';
assert.equal({[x]: 10}.y, 10);
assert.equal({[x + 'y']: 10}.yy, 10);

View File

@@ -0,0 +1,3 @@
assert.equal((function(a){}).length, 1);
assert.equal((function(a=5){}).length, 0);
assert.equal((function(a, b, c=5){}).length, 2);

View File

@@ -0,0 +1,8 @@
function makeMultiplier(x=1) {
return (y=1) => x * y;
}
assert.equal(makeMultiplier()(), 1);
assert.equal(makeMultiplier(2)(3), 6);
assert.deepEqual([1, 2, 3].map(makeMultiplier(2)), [2, 4, 6]);
assert.deepEqual([undefined, null, 0].map(makeMultiplier(2)), [2, 0, 0]);

View File

@@ -0,0 +1,5 @@
function foo(x=5, y=6) {
return [x, y];
}
assert.deepEqual(foo(undefined, null), [5, null]);

View File

@@ -0,0 +1,11 @@
function call(fn, context=this) {
return fn.call(context);
}
var context = {a: 99};
// use the default parameter
assert.strictEqual(call.call(context, function(){ return this.a; }), 99);
// explicitly provide the default parameter value
assert.strictEqual(call(function(){ return this.a; }, context), 99);

View File

@@ -0,0 +1,4 @@
function foo(x=5) {
return x;
}
assert.equal(foo(), 5);

View File

@@ -0,0 +1,7 @@
var a = {
echo(c) {
return c;
}
};
assert.strictEqual(a.echo(1), 1);

View File

@@ -0,0 +1,9 @@
var a = {
b() {
return this;
}
};
var context = {};
assert.strictEqual(a.b(), a);
assert.strictEqual(a.b.call(context), context);

View File

@@ -0,0 +1,7 @@
var a = {
b() {
return 'c';
}
};
assert.equal(a.b.name, 'b');

View File

@@ -0,0 +1,9 @@
var b = 1;
var a = {
b() {
return b;
}
};
assert.equal(a.b(), 1);

View File

@@ -0,0 +1,10 @@
var a = {
b() {
return b;
}
};
assert.ok(
/return b/.test(a.b.toString()),
'toString contains body'
);

View File

@@ -0,0 +1,7 @@
var a = {
b() {
return 'c';
}
};
assert.equal(a.b(), 'c');

View File

@@ -0,0 +1,5 @@
var join = (joinStr, ...items) => {
return items.join(joinStr);
};
assert.deepEqual(join(' ', 'a', 'b', 'c'), 'a b c');

View File

@@ -0,0 +1,5 @@
function join(joinStr, ...items) {
return items.join(joinStr);
}
assert.deepEqual(join(' ', 'a', 'b', 'c'), 'a b c');

View File

@@ -0,0 +1,5 @@
var join = function(joinStr, ...items) {
return items.join(joinStr);
};
assert.deepEqual(join(' ', 'a', 'b', 'c'), 'a b c');

View File

@@ -0,0 +1,6 @@
function arrayOf() {
return [...arguments];
}
assert.equal(Object.prototype.toString.call(arrayOf()), '[object Array]');
assert.deepEqual(arrayOf(1, 2, 3), [1, 2, 3]);

View File

@@ -0,0 +1,3 @@
var names = ['Brian', 'Madeline'];
assert.deepEqual(['Thomas', ...names], ['Thomas', 'Brian', 'Madeline']);
assert.deepEqual([1, 2, ...[3, 4, 5]], [1, 2, 3, 4, 5]);

View File

@@ -0,0 +1,5 @@
function sum(...numbers) {
return numbers.reduce(function(sum, n) { return n + sum; }, 0);
}
assert.equal(sum(4, 5, ...[10, 20, 30]), 69);

View File

@@ -0,0 +1,10 @@
var object = {
list: [],
append: function(...items) {
this.list.push(...items);
}
};
object.append(1, 2, ...[3, 4]);
assert.deepEqual(object.list, [1, 2, 3, 4]);

View File

@@ -0,0 +1,16 @@
var obj = {
[Symbol.iterator]: function() {
var ttl = 3;
return {
next: function() {
if (ttl === 0) {
return { done: true, value: null };
} else {
return { done: false, value: ttl-- };
}
}
};
}
};
assert.deepEqual([3, 2, 1], [...obj]);

View File

@@ -0,0 +1,11 @@
var callCount = 0;
function getArray() {
callCount++;
return Array;
}
assert.deepEqual([1, 2, 3], new Array(...[1, 2, 3]));
// Ensure the expression of the function being initialized is not copied.
assert.deepEqual([1, 2, 3], new (getArray())(...[1, 2, 3]));
assert.equal(callCount, 1);

View File

@@ -0,0 +1,35 @@
var MATH = {
sum: function(...numbers) {
return numbers.reduce(this.add, 0);
},
add: function(a, b) {
return a + b;
}
};
assert.equal(MATH.sum(1, ...[2, 3]), 6);
// Ensure that the below does not expand to this:
//
// obj.getSelf().call.apply(obj.getSelf(), []);
//
var ops = [];
var obj = {
getSelf: function() {
ops.push('getSelf');
return this;
},
doCall: function() {
ops.push('doCall', this);
}
};
obj.getSelf().doCall(...[]);
assert.deepEqual(ops, ['getSelf', 'doCall', obj]);
ops = [];
obj['getSelf']().doCall(...[]);
assert.deepEqual(ops, ['getSelf', 'doCall', obj]);

View File

@@ -0,0 +1,6 @@
function sum(...numbers) {
return numbers.reduce(function(sum, n) { return n + sum; }, 0);
}
var numbers = [1, 2, 3];
assert.equal(sum(...numbers), 6);

View File

@@ -0,0 +1,4 @@
var s = `a
b
c`;
assert.equal(s, 'a\n b\n c');

View File

@@ -0,0 +1,4 @@
assert.strictEqual(
`a${1}b${`${1+1}c`}3`,
'a1b2c3'
);

View File

@@ -0,0 +1,2 @@
var s = `str`;
assert.equal(s, 'str');

View File

@@ -0,0 +1,6 @@
function r(strings) {
assert.equal(strings.raw[0], '\\n');
return strings.raw.join('');
}
assert.equal(r `\n`, '\\n');

View File

@@ -0,0 +1,2 @@
var s = `1 + 1 = ${1 + 1}`;
assert.equal(s, '1 + 1 = 2');

View File

@@ -0,0 +1,26 @@
function tag(strings) {
var values = [].slice.call(arguments, 1);
assert.equal(strings[0], 'a');
assert.equal(strings[1], 'b');
assert.equal(values[0], 42);
return 'whatever';
}
assert.equal(tag `a${ 42 }b`, 'whatever');
function tagInterpolateFirst(strings) {
var values = [].slice.call(arguments, 1);
assert.equal(strings[0], '');
assert.equal(strings[1], 'b');
assert.equal(values[0], 42);
return 'whatever';
}
assert.equal(tagInterpolateFirst `${ 42 }b`, 'whatever');
function tagInterpolateLast(strings) {
var values = [].slice.call(arguments, 1);
assert.equal(strings[0], 'a');
assert.equal(strings[1], '');
assert.equal(values[0], 42);
return 'whatever';
}
assert.equal(tagInterpolateLast `a${ 42 }`, 'whatever');

View File

@@ -0,0 +1,3 @@
{
"noCheckAst": true
}

View File

@@ -1,7 +1,7 @@
"use strict";
var some = function (count) {
if (count === undefined) count = "30";
var some = function () {
var count = arguments[0] === undefined ? "30" : arguments[0];
console.log("count", count);
};

View File

@@ -2,6 +2,9 @@
var _slice = Array.prototype.slice;
var _inherits = function (child, parent) {
if (typeof parent !== "function" && parent !== null) {
throw new TypeError("Super expression must either be null or a function, not " + typeof parent);
}
child.prototype = Object.create(parent && parent.prototype, {
constructor: {
value: child,
@@ -22,8 +25,8 @@ var Test = (function () {
_Foo.prototype.test.call(this);
foob(_Foo);
_Foo.call.apply(null, [this].concat(_slice.call(arguments)));
_Foo.call.apply(null, [this, "test"].concat(_slice.call(arguments)));
_Foo.call.apply(_Foo, [this].concat(_slice.call(arguments)));
_Foo.call.apply(_Foo, [this, "test"].concat(_slice.call(arguments)));
(_Foo$prototype$test = _Foo.prototype.test).call.apply(_Foo$prototype$test, [this].concat(_slice.call(arguments)));
(_Foo$prototype$test2 = _Foo.prototype.test).call.apply(_Foo$prototype$test2, [this, "test"].concat(_slice.call(arguments)));

View File

@@ -1,6 +1,9 @@
"use strict";
var _inherits = function (child, parent) {
if (typeof parent !== "function" && parent !== null) {
throw new TypeError("Super expression must either be null or a function, not " + typeof parent);
}
child.prototype = Object.create(parent && parent.prototype, {
constructor: {
value: child,

View File

@@ -1,6 +1,9 @@
"use strict";
var _inherits = function (child, parent) {
if (typeof parent !== "function" && parent !== null) {
throw new TypeError("Super expression must either be null or a function, not " + typeof parent);
}
child.prototype = Object.create(parent && parent.prototype, {
constructor: {
value: child,

View File

@@ -1,6 +1,9 @@
"use strict";
var _inherits = function (child, parent) {
if (typeof parent !== "function" && parent !== null) {
throw new TypeError("Super expression must either be null or a function, not " + typeof parent);
}
child.prototype = Object.create(parent && parent.prototype, {
constructor: {
value: child,

View File

@@ -1,6 +1,9 @@
"use strict";
var _inherits = function (child, parent) {
if (typeof parent !== "function" && parent !== null) {
throw new TypeError("Super expression must either be null or a function, not " + typeof parent);
}
child.prototype = Object.create(parent && parent.prototype, {
constructor: {
value: child,
@@ -15,7 +18,7 @@ var _inherits = function (child, parent) {
var BaseController = (function () {
var _Chaplin$Controller = Chaplin.Controller;
var BaseController = function BaseController() {
if (_Chaplin$Controller) {
if (_Chaplin$Controller !== null) {
_Chaplin$Controller.apply(this, arguments);
}
};
@@ -28,7 +31,7 @@ var BaseController = (function () {
var BaseController2 = (function () {
var _Chaplin$Controller$Another = Chaplin.Controller.Another;
var BaseController2 = function BaseController2() {
if (_Chaplin$Controller$Another) {
if (_Chaplin$Controller$Another !== null) {
_Chaplin$Controller$Another.apply(this, arguments);
}
};

View File

@@ -1,6 +1,9 @@
"use strict";
var _inherits = function (child, parent) {
if (typeof parent !== "function" && parent !== null) {
throw new TypeError("Super expression must either be null or a function, not " + typeof parent);
}
child.prototype = Object.create(parent && parent.prototype, {
constructor: {
value: child,
@@ -15,7 +18,7 @@ var _inherits = function (child, parent) {
var Test = (function () {
var _Foo = Foo;
var Test = function Test() {
if (_Foo) {
if (_Foo !== null) {
_Foo.apply(this, arguments);
}
};

View File

@@ -1,12 +1,12 @@
"use strict";
var t = function (t, f) {
if (t === undefined) t = "foo";
if (f === undefined) f = 5;
var t = function () {
var t = arguments[0] === undefined ? "foo" : arguments[0];
var f = arguments[1] === undefined ? 5 : arguments[1];
return t + " bar " + f;
};
var a = function (t, f) {
if (f === undefined) f = 5;
var a = function (t) {
var f = arguments[1] === undefined ? 5 : arguments[1];
return t + " bar " + f;
};

View File

@@ -1,6 +1,6 @@
"use strict";
var t = function (t) {
if (t === undefined) t = "foo";
var t = function () {
var t = arguments[0] === undefined ? "foo" : arguments[0];
return t + " bar";
};

View File

@@ -1,7 +0,0 @@
Copyright (c) 2014, Facebook, Inc.
All rights reserved.
This source code is licensed under the BSD-style license found in the
https://raw.github.com/facebook/regenerator/master/LICENSE file. An
additional grant of patent rights can be found in the PATENTS file in
the same directory.

View File

@@ -1,24 +0,0 @@
function *gen() {
var a$0 = 0, a$1 = 1;
let a = 3;
{
let a = 1;
yield a + a$0;
}
{
let a = 2;
yield a - 1 + a$1;
}
yield a;
}
var g = gen();
assert.deepEqual(g.next(), { value: 1, done: false });
assert.deepEqual(g.next(), { value: 2, done: false });
assert.deepEqual(g.next(), { value: 3, done: false });
assert.deepEqual(g.next(), { value: void 0, done: true });

View File

@@ -1,22 +0,0 @@
function *gen() {
let arr = [];
for (let x = 0; x < 3; x++) {
let y = x;
arr.push(function() { return y; });
}
{
let x;
while( x = arr.pop() ) {
yield x;
}
}
}
var g = gen();
assert.equal(g.next().value(), 2);
assert.equal(g.next().value(), 1);
assert.equal(g.next().value(), 0);
assert.deepEqual(g.next(), { value: void 0, done: true });

View File

@@ -1,15 +0,0 @@
function *gen() {
try {
genHelpers.raise("e1");
} catch (e) {
yield e;
try {
genHelpers.raise("e2");
} catch (e) {
yield e;
}
yield e;
}
}
genHelpers.check(gen(), ["e1", "e2", "e1"]);

View File

@@ -1,22 +0,0 @@
function *gen(x) {
var y = x + 1;
try {
throw x + 2;
} catch (x) {
yield x;
x += 1;
yield x;
}
yield x;
try {
throw x + 3;
} catch (y) {
yield y;
y *= 2;
yield y;
}
yield y;
}
genHelpers.check(gen(1), [3, 4, 1, 4, 8, 2]);
genHelpers.check(gen(2), [4, 5, 2, 5, 10, 3]);

View File

@@ -1,32 +0,0 @@
function *gen(x) {
try {
throw x;
} catch (x) {
yield x;
yield (function(x) {
return x += 1;
}(x + 1));
yield (function() {
var x = arguments[0];
return x * 2;
}(x + 2));
yield (function() {
function notCalled(x) {
throw x;
}
x >>= 1;
return x;
}());
yield x -= 1;
}
yield x;
}
genHelpers.check(gen(10), [10, 12, 24, 5, 4, 10]);
genHelpers.check(gen(11), [11, 13, 26, 5, 4, 11]);

View File

@@ -1,42 +0,0 @@
function *gen(n) {
var count = 0;
yield n;
while (n !== 1) {
count += 1;
if (n % 2) {
yield n = n * 3 + 1;
} else {
yield n >>= 1;
}
}
return count;
}
function collatz(n) {
var result = [n];
while (n !== 1) {
if (n % 2) {
n *= 3;
n += 1;
} else {
n >>= 1;
}
result.push(n);
}
return result;
}
var seven = collatz(7);
var fiftyTwo = seven.slice(seven.indexOf(52));
var eightyTwo = collatz(82);
genHelpers.check(gen(7), seven, 16);
genHelpers.check(gen(52), fiftyTwo, 11);
genHelpers.check(gen(82), eightyTwo, 110);

View File

@@ -1,11 +0,0 @@
function *gen() {
return "ALL DONE";
}
var g = gen();
assert.deepEqual(g.next(), {
value: "ALL DONE", done: true
});
genHelpers.assertAlreadyFinished(g);

View File

@@ -1,27 +0,0 @@
var error = new Error("thrown");
function *outer(n) {
try {
yield 0;
yield* inner(n);
yield 1;
} catch (err) {
yield err.message;
}
yield 4;
}
function *inner(n) {
while (n --> 0) {
try {
if (n === 3) {
genHelpers.raise(error);
}
} finally {
yield n;
}
}
}
genHelpers.check(outer(3), [0, 2, 1, 0, 1, 4]);
genHelpers.check(outer(5), [0, 4, 3, "thrown", 4]);

View File

@@ -1,10 +0,0 @@
function *gen(condition) {
if (condition) {
yield 0;
yield* gen(false);
yield 1;
}
}
genHelpers.check(gen(true), [0, 1]);
genHelpers.check(gen(false), []);

View File

@@ -1,12 +0,0 @@
function *gen(condition) {
yield 0;
if (condition) {
yield 1;
yield* gen(false);
yield 2;
}
yield 3;
}
genHelpers.check(gen(true), [0, 1, 0, 3, 2, 3]);
genHelpers.check(gen(false), [0, 3]);

View File

@@ -1,37 +0,0 @@
var count = 0;
function *gen() {
yield* inner();
try {
yield* inner();
} catch (err) {
// pass
}
return yield* inner();
}
function *inner() {
return yield count++;
}
var g = gen();
assert.deepEqual(g.next(), {
value: 0,
done: false
});
assert.deepEqual(g.next(), {
value: 1,
done: false
});
assert.deepEqual(g.throw(new Error("lol")), {
value: 2,
done: false,
});
assert.deepEqual(g.next("sent"), {
value: "sent",
done: true
});

View File

@@ -1,15 +0,0 @@
function *outer(n) {
yield* inner(n << 1);
yield "zxcv";
}
function *inner(n) {
return yield yield yield n;
}
var g = outer(3);
assert.deepEqual(g.next(), { value: 6, done: false });
assert.deepEqual(g.next(1), { value: 1, done: false });
assert.deepEqual(g.next(2), { value: 2, done: false });
assert.deepEqual(g.next(4), { value: "zxcv", done: false });
assert.deepEqual(g.next(5), { value: void 0, done: true });

View File

@@ -1,18 +0,0 @@
function *outer(n) {
yield n;
yield* middle(n - 1, inner(n + 10));
yield n + 1;
}
function *middle(n, plusTen) {
yield n;
yield* inner(n - 1);
yield n + 1;
yield* plusTen;
}
function *inner(n) {
yield n;
}
genHelpers.check(outer(5), [5, 4, 3, 5, 15, 6]);

View File

@@ -1,11 +0,0 @@
function *gen() {
yield 0;
yield* [
yield "one",
yield "two",
yield "three"
];
yield 5;
}
genHelpers.check(gen(), [0, "one", "two", "three", 2, 3, 4, 5]);

View File

@@ -1,20 +0,0 @@
function *gen(x, fname) {
try {
return fns[fname](x);
} catch (thrown) {
yield thrown;
}
}
var fns = {
f: function(x) {
throw x;
},
g: function(x) {
return x;
}
};
genHelpers.check(gen("asdf", "f"), ["asdf"]);
genHelpers.check(gen("asdf", "g"), [], "asdf");

View File

@@ -1,16 +0,0 @@
function *gen(x) {
while (x) {
// empty while loop
}
do {
// empty do-while loop
} while (x);
return gen.toString();
}
var info = gen(false).next();
assert.strictEqual(info.done, true);
assert.ok(/do \{/.test(info.value));
assert.ok(/while \(/.test(info.value));

View File

@@ -1,19 +0,0 @@
function *gen(obj) {
var count = 0;
for (var key in (yield "why not", obj)) {
if (obj.hasOwnProperty(key)) {
if (key === "skip") {
break;
}
count += 1;
yield [key, obj[key]];
}
}
return count;
}
genHelpers.check(
gen({ a: 1, b: 2, skip: 3, c: 4 }),
["why not", ["a", 1], ["b", 2]],
2
);

View File

@@ -1,13 +0,0 @@
function *gen() {
var count = 0;
var obj = {foo: 1, bar: 2};
for (var key in obj) {
assert(obj.hasOwnProperty(key), key + " must be own property");
yield [key, obj[key]];
delete obj.bar;
count += 1;
}
return count;
}
genHelpers.check(gen(), [["foo", 1]], 1);

View File

@@ -1,26 +0,0 @@
function a(sent) {
assert.strictEqual(sent, 1);
a.called = true;
}
function b(sent) {
assert.strictEqual(sent, 2);
b.called = true;
return { callee: b };
}
function *gen() {
assert.ok(!a.called);
assert.ok(!b.called);
for (var key in a(yield 0), b(yield 1)) {
assert.ok(a.called);
assert.ok(b.called);
assert.strictEqual(yield key, 3);
}
for (var key in a(1), { foo: "foo", bar: "bar" }) {
yield key;
}
}
genHelpers.check(gen(), [0, 1, "callee", "foo", "bar"]);

View File

@@ -1,12 +0,0 @@
function *gen() {
var count = 0;
var obj = {foo: 1, bar: 2};
for (var key in obj) {
assert(obj.hasOwnProperty(key), key + " must be own property");
yield [key, obj[key]];
count += 1;
}
return count;
}
genHelpers.check(gen(), [["foo", 1], ["bar", 2]], 2);

View File

@@ -1,16 +0,0 @@
function *gen() {
var count = 0;
function Foo() {
this.baz = 1
}
Foo.prototype.bar = 2;
var foo = new Foo();
for (var key in foo) {
yield [key, foo[key]];
count += 1;
}
return count;
}
genHelpers.check(gen(), [["baz", 1], ["bar", 2]], 2);

View File

@@ -1,7 +0,0 @@
// https://github.com/facebook/regenerator/issues/103
function *range() {
for (var i = 0; false; ) {
}
}
genHelpers.check(range(), []);

View File

@@ -1,5 +0,0 @@
var sum = 0;
for (var x of [1, 2].concat(3)) {
sum += x;
}
assert.strictEqual(sum, 6);

View File

@@ -1,10 +0,0 @@
function *range(n) {
for (var i = 0; i < n; ++i) {
yield i;
}
}
var value, values = [];
for (value of range(3))
values.push(value);
assert.deepEqual(values, [0, 1, 2]);

View File

@@ -1,45 +0,0 @@
function *yieldPermutations(list) {
if (list.length < 2) {
yield list;
return 1;
}
var count = 0;
var first = list.slice(0, 1);
var genRest = yieldPermutations(list.slice(1));
for (var perm of genRest) {
for (var i = 0; i < list.length; ++i) {
var prefix = perm.slice(0, i);
var suffix = perm.slice(i);
yield prefix.concat(first, suffix);
}
count += i;
}
return count;
}
var count = 0;
for (var perm of yieldPermutations([])) {
assert.deepEqual(perm, []);
++count;
}
assert.strictEqual(count, 1);
genHelpers.check(yieldPermutations([1]), [[1]], 1);
genHelpers.check(yieldPermutations([2, 1]), [
[2, 1],
[1, 2]
], 2);
genHelpers.check(yieldPermutations([1,3,2]), [
[1, 3, 2],
[3, 1, 2],
[3, 2, 1],
[1, 2, 3],
[2, 1, 3],
[2, 3, 1]
], 6);

Some files were not shown because too many files have changed in this diff Show More