UNPKG

1.38 kBJavaScriptView Raw
1"use strict";
2
3exports.__esModule = true;
4exports.default = normalizeAttrs;
5
6var t = _interopRequireWildcard(require("@babel/types"));
7
8function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
9
10function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
11
12function normalizeAttrs(node) {
13 if (!node) return t.NullLiteral();
14 if (!t.isObjectExpression(node)) return node;
15 const {
16 properties
17 } = node;
18 const propsIdent = t.Identifier('props');
19 return t.ArrowFunctionExpression([propsIdent], t.ObjectExpression([t.SpreadElement(propsIdent), ...properties]));
20}
\No newline at end of file