Merge pull request #1518 from babel/es7.functionBind

Add experimental support for ES7 function bind.
This commit is contained in:
Sebastian McKenzie
2015-05-14 16:22:21 +01:00
20 changed files with 174 additions and 5 deletions

View File

@@ -0,0 +1,5 @@
::foo.bar.foo;
::foo.bar["foo"];
ctx::foo.bar.foo;
ctx::foo.bar["foo"];

View File

@@ -0,0 +1,5 @@
::foo.bar.foo;
::foo.bar["foo"];
ctx::foo.bar.foo;
ctx::foo.bar["foo"];

View File

@@ -0,0 +1,3 @@
var f = ctx::ns.obj.func;
var g = ::ns.obj.func;
var h = new X::y;

View File

@@ -0,0 +1,7 @@
"use strict";
var _context;
var f = (_context = ctx, ns.obj.func).bind(_context);
var g = (_context = ns.obj).func.bind(_context);
var h = (_context = new X(), y).bind(_context);

View File

@@ -0,0 +1,4 @@
ctx::ns.obj.func();
::ns.obj.func();
ns.obj2::ns.obj1.func();

View File

@@ -0,0 +1,8 @@
"use strict";
var _context;
(_context = ctx, ns.obj.func).call(_context);
(_context = ns.obj).func.call(_context);
(_context = ns.obj2, ns.obj1.func).call(_context);

View File

@@ -0,0 +1,6 @@
import { map, takeWhile, forEach } from "iterlib";
getPlayers()
::map(x => x.character())
::takeWhile(x => x.strength > 100)
::forEach(x => console.log(x));

View File

@@ -0,0 +1,27 @@
var operations = [];
var lib = {};
for (let key of ['f', 'g', 'h']) {
let func = () => operations.push(`lib.${key}()`);
Object.defineProperty(lib, key, {
get() {
operations.push(`get lib.${key}`);
return func;
}
});
}
({prop:'value'})
::lib.f()
::lib.g()
::lib.h();
assert.deepEqual(operations, [
'get lib.f',
'lib.f()',
'get lib.g',
'lib.g()',
'get lib.h',
'lib.h()'
]);

View File

@@ -0,0 +1,13 @@
"use strict";
var _context;
var _iterlib = require("iterlib");
(_context = (_context = (_context = getPlayers(), _iterlib.map).call(_context, function (x) {
return x.character();
}), _iterlib.takeWhile).call(_context, function (x) {
return x.strength > 100;
}), _iterlib.forEach).call(_context, function (x) {
return console.log(x);
});

View File

@@ -0,0 +1,3 @@
{
"optional": "es7.functionBind"
}