diff --git a/src/babel/transformation/transformers/spec/function-name.js b/src/babel/transformation/transformers/spec/function-name.js index 9cd2e6ef5b..42dcaa21d0 100644 --- a/src/babel/transformation/transformers/spec/function-name.js +++ b/src/babel/transformation/transformers/spec/function-name.js @@ -4,8 +4,24 @@ export var metadata = { group: "builtin-basic" }; +// visit Property functions first - https://github.com/babel/babel/issues/1860 export var visitor = { "ArrowFunctionExpression|FunctionExpression": { - exit: bare + exit() { + if (!this.parentPath.isProperty()) { + return bare.apply(this, arguments); + } + } + }, + + ObjectExpression() { + var props = this.get("properties"); + for (var prop of (props: Array)) { + var value = prop.get("value"); + if (value.isFunction()) { + var newNode = bare(value.node, prop.node, value.scope); + if (newNode) value.replaceWith(newNode); + } + } } }; diff --git a/test/core/fixtures/transformation/es7.decorators/object/actual.js b/test/core/fixtures/transformation/es7.decorators/object/actual.js index 03c6a75573..16a6041b30 100644 --- a/test/core/fixtures/transformation/es7.decorators/object/actual.js +++ b/test/core/fixtures/transformation/es7.decorators/object/actual.js @@ -1,8 +1,6 @@ var obj = { @foo - bar() { - - }, + bar() {}, @bar foo: "lol", diff --git a/test/core/fixtures/transformation/es7.decorators/object/expected.js b/test/core/fixtures/transformation/es7.decorators/object/expected.js index c6ad34a161..448ac93fc9 100644 --- a/test/core/fixtures/transformation/es7.decorators/object/expected.js +++ b/test/core/fixtures/transformation/es7.decorators/object/expected.js @@ -3,7 +3,7 @@ var obj = babelHelpers.createDecoratedObject([{ key: "bar", decorators: [foo], - value: function value() {} + value: function bar() {} }, { key: "foo", decorators: [bar], @@ -15,4 +15,4 @@ var obj = babelHelpers.createDecoratedObject([{ initializer: function initializer() { return "wow"; } -}]); \ No newline at end of file +}]); diff --git a/test/core/fixtures/transformation/spec.function-name/smoke/exec.js b/test/core/fixtures/transformation/spec.function-name/smoke/exec.js new file mode 100644 index 0000000000..593aef207e --- /dev/null +++ b/test/core/fixtures/transformation/spec.function-name/smoke/exec.js @@ -0,0 +1,23 @@ +var foo = function () {}; +assert.equal(foo.name, "foo"); + +var obj = { foo: function () {} }; +assert.equal(obj.foo.name, "foo"); + +var obj = { "foo": function () {} }; +assert.equal(obj.foo.name, "foo"); + +var obj = { foo() {} }; +assert.equal(obj.foo.name, "foo"); + +var obj = { "foo"() {} }; +assert.equal(obj.foo.name, "foo"); + +function noop() {} + +var obj = { @noop foo() {} }; +assert.equal(obj.foo.name, "foo"); + + +var obj = { @noop foo: function () {} }; +assert.equal(obj.foo.name, "foo"); diff --git a/test/core/fixtures/transformation/spec.function-name/smoke/options.json b/test/core/fixtures/transformation/spec.function-name/smoke/options.json new file mode 100644 index 0000000000..b4851aeb98 --- /dev/null +++ b/test/core/fixtures/transformation/spec.function-name/smoke/options.json @@ -0,0 +1,3 @@ +{ + "optional": ["es7.decorators"] +}