1 | {"version":3,"names":["_core","require","pushAccessor","mutatorMap","node","_mutatorMap$alias","alias","t","toKeyAlias","map","_inherits","_key","key","push","value","functionExpression","params","body","generator","async","returnType","inheritsComments","kind","toDefineObject","objExpr","objectExpression","Object","keys","forEach","mutatorMapKey","configurable","booleanLiteral","enumerable","mapNode","propNode","objectProperty","_computed","prop","identifier","removeComments","properties"],"sources":["../src/define-map.ts"],"sourcesContent":["import { types as t } from \"@babel/core\";\n\ntype DefineMap = {\n _inherits: t.Node[];\n _key: t.Expression;\n get?: t.Expression;\n set?: t.Expression;\n kind: \"get\" | \"set\";\n};\n\nexport type MutatorMap = Record<string, DefineMap>;\n\nexport function pushAccessor(\n mutatorMap: MutatorMap,\n node: t.ObjectMethod & { kind: \"get\" | \"set\"; computed: false },\n) {\n const alias = t.toKeyAlias(node);\n const map = (mutatorMap[alias] ??= {\n _inherits: [],\n _key: node.key,\n } as DefineMap);\n\n map._inherits.push(node);\n\n const value = t.functionExpression(\n null,\n node.params,\n node.body,\n node.generator,\n node.async,\n );\n value.returnType = node.returnType;\n t.inheritsComments(value, node);\n map[node.kind] = value;\n\n return map;\n}\n\nexport function toDefineObject(mutatorMap: any) {\n const objExpr = t.objectExpression([]);\n\n Object.keys(mutatorMap).forEach(function (mutatorMapKey) {\n const map = mutatorMap[mutatorMapKey];\n map.configurable = t.booleanLiteral(true);\n map.enumerable = t.booleanLiteral(true);\n\n const mapNode = t.objectExpression([]);\n\n const propNode = t.objectProperty(map._key, mapNode, map._computed);\n\n Object.keys(map).forEach(function (key) {\n const node = map[key];\n if (key[0] === \"_\") return;\n\n const prop = t.objectProperty(t.identifier(key), node);\n t.inheritsComments(prop, node);\n t.removeComments(node);\n\n mapNode.properties.push(prop);\n });\n\n objExpr.properties.push(propNode);\n });\n\n return objExpr;\n}\n"],"mappings":";;;;;;;AAAA,IAAAA,KAAA,GAAAC,OAAA;AAYO,SAASC,YAAYA,CAC1BC,UAAsB,EACtBC,IAA+D,EAC/D;EAAA,IAAA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