From 1a299b2bccaa5e4ff96c7fc22af8898bc17b9a06 Mon Sep 17 00:00:00 2001 From: Ingvar Stepanyan Date: Wed, 13 May 2015 18:20:33 +0300 Subject: [PATCH] Small fixes to es7.functionBind and generation tests added. --- src/babel/transformation/transformers/es7/function-bind.js | 7 ++----- .../fixtures/generation/types/BindExpression/actual.js | 5 +++++ .../fixtures/generation/types/BindExpression/expected.js | 5 +++++ test/core/generation.js | 3 ++- 4 files changed, 14 insertions(+), 6 deletions(-) create mode 100644 test/core/fixtures/generation/types/BindExpression/actual.js create mode 100644 test/core/fixtures/generation/types/BindExpression/expected.js diff --git a/src/babel/transformation/transformers/es7/function-bind.js b/src/babel/transformation/transformers/es7/function-bind.js index dc3af46ecd..2846999aa7 100644 --- a/src/babel/transformation/transformers/es7/function-bind.js +++ b/src/babel/transformation/transformers/es7/function-bind.js @@ -7,9 +7,6 @@ export var metadata = { stage: 0 }; -var CALL = t.identifier("call"); -var BIND = t.identifier("bind"); - function inferBindContext(bindExpr, scope) { // nothing to infer if (bindExpr.object) return bindExpr.object; @@ -27,11 +24,11 @@ export function CallExpression(node, parent, scope, file) { var bindExpr = node.callee; if (!t.isBindExpression(bindExpr)) return; var bindCtx = inferBindContext(bindExpr, scope); - node.callee = t.memberExpression(bindExpr.callee, CALL, false); + node.callee = t.memberExpression(bindExpr.callee, t.identifier("call")); node.arguments.unshift(bindCtx); } export function BindExpression(node, parent, scope, file) { var bindCtx = inferBindContext(node, scope); - return t.callExpression(t.memberExpression(node.callee, BIND, false), [bindCtx]); + return t.callExpression(t.memberExpression(node.callee, t.identifier("bind")), [bindCtx]); } diff --git a/test/core/fixtures/generation/types/BindExpression/actual.js b/test/core/fixtures/generation/types/BindExpression/actual.js new file mode 100644 index 0000000000..c78d72da44 --- /dev/null +++ b/test/core/fixtures/generation/types/BindExpression/actual.js @@ -0,0 +1,5 @@ +::foo.bar.foo; +::foo.bar["foo"]; + +ctx::foo.bar.foo; +ctx::foo.bar["foo"]; diff --git a/test/core/fixtures/generation/types/BindExpression/expected.js b/test/core/fixtures/generation/types/BindExpression/expected.js new file mode 100644 index 0000000000..c78d72da44 --- /dev/null +++ b/test/core/fixtures/generation/types/BindExpression/expected.js @@ -0,0 +1,5 @@ +::foo.bar.foo; +::foo.bar["foo"]; + +ctx::foo.bar.foo; +ctx::foo.bar["foo"]; diff --git a/test/core/generation.js b/test/core/generation.js index fa4dd81017..b1f08a2908 100644 --- a/test/core/generation.js +++ b/test/core/generation.js @@ -34,7 +34,8 @@ _.each(helper.get("generation"), function (testSuite) { features: { "es7.comprehensions": true, "es7.asyncFunctions": true, - "es7.exportExtensions": true + "es7.exportExtensions": true, + "es7.functionBind": true } }); var actualCode = generate(actualAst, task.options, actual.code).code;