check if ObjectExpression has any gets/sets before filtering
This commit is contained in:
parent
bdb3adfeea
commit
152ccb2ce8
@ -2,12 +2,19 @@ import * as defineMap from "../../helpers/define-map";
|
||||
import * as t from "../../../types";
|
||||
|
||||
export function ObjectExpression(node, parent, scope, file) {
|
||||
var mutatorMap = {};
|
||||
var hasAny = false;
|
||||
for (var prop of (node.properties: Array)) {
|
||||
if (prop.kind === "get" || prop.kind === "set") {
|
||||
hasAny = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!hasAny) return;
|
||||
|
||||
var mutatorMap = {};
|
||||
|
||||
node.properties = node.properties.filter(function (prop) {
|
||||
if (prop.kind === "get" || prop.kind === "set") {
|
||||
hasAny = true;
|
||||
defineMap.push(mutatorMap, prop, prop.kind, file);
|
||||
return false;
|
||||
} else {
|
||||
@ -15,8 +22,6 @@ export function ObjectExpression(node, parent, scope, file) {
|
||||
}
|
||||
});
|
||||
|
||||
if (!hasAny) return;
|
||||
|
||||
return t.callExpression(
|
||||
t.memberExpression(t.identifier("Object"), t.identifier("defineProperties")),
|
||||
[node, defineMap.toDefineObject(mutatorMap)]
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user