UNPKG

babel-plugin-transform-object-enumerables

Version:

Helps obtain an array of keys, values, and key/value pairs (what the spec calls “entries”) from an object, for the purposes of iteration or serialization

25 lines (22 loc) 901 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = function () { return { visitor: { CallExpression: function CallExpression(path) { if (path.get("callee").matchesPattern("Object.enumerableKeys")) { path.replaceWithSourceString(keysSource); } else if (path.get("callee").matchesPattern("Object.enumerableValues")) { path.replaceWithSourceString(valuesSource); } else if (path.get("callee").matchesPattern("Object.enumerableEntries")) { path.replaceWithSourceString(entriesSource); } } } }; }; var keysSource = "((o) => { var r = []; for (var k in o) { r.push(k) } return r; })"; var valuesSource = "((o) => { var r = []; for (var k in o) { r.push(o[k]) } return r; })"; var entriesSource = "((o) => { var r = []; for (var k in o) { r.push([k, o[k]]) } return r; })";