perform function name inference on functions in properties before they're properly visited - fixes #1860

This commit is contained in:
Sebastian McKenzie 2015-06-29 00:20:47 +01:00
parent 81edc4c6ab
commit 0044100e3d
5 changed files with 46 additions and 6 deletions

View File

@ -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);
}
}
}
};

View File

@ -1,8 +1,6 @@
var obj = {
@foo
bar() {
},
bar() {},
@bar
foo: "lol",

View File

@ -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";
}
}]);
}]);

View File

@ -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");

View File

@ -0,0 +1,3 @@
{
"optional": ["es7.decorators"]
}