Apply only to ObjectProperty.
Fix T6779. It should be possible to apply this to ES5 functions without mutating ES2015 MethodDefinition's.
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
import * as t from "babel-types";
|
||||
import nameFunction from "babel-helper-function-name";
|
||||
|
||||
export default function () {
|
||||
@@ -13,25 +12,11 @@ export default function () {
|
||||
}
|
||||
},
|
||||
|
||||
ObjectExpression(path) {
|
||||
let props: Array<Object> = path.get("properties");
|
||||
|
||||
for (let prop of props) {
|
||||
if (prop.isObjectMethod({ kind: "method", computed: false })) {
|
||||
let node = prop.node;
|
||||
prop.replaceWith(t.objectProperty(
|
||||
node.key,
|
||||
t.functionExpression(null, node.params, node.body, node.generator, node.async)
|
||||
));
|
||||
}
|
||||
|
||||
if (prop.isObjectProperty()) {
|
||||
let value = prop.get("value");
|
||||
if (value.isFunction()) {
|
||||
let newNode = nameFunction(value);
|
||||
if (newNode) value.replaceWith(newNode);
|
||||
}
|
||||
}
|
||||
ObjectProperty(path) {
|
||||
let value = path.get("value");
|
||||
if (value.isFunction()) {
|
||||
let newNode = nameFunction(value);
|
||||
if (newNode) value.replaceWith(newNode);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user