UNPKG

code-workshop-kit

Version:
40 lines 1.95 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const createProperty = ({ types: t, key }) => t.objectProperty(t.identifier('appKey'), t.stringLiteral(key)); const propertyVistior = { ObjectProperty(path) { if (path.node === this.appKey && this.key) { path.replaceWith(createProperty({ types: this.types, key: this.key })); } }, }; exports.default = ({ types: t, }) => ({ visitor: { ExportDefaultDeclaration(path, state) { var _a, _b, _c, _d; if (path.node.declaration && path.node.declaration.type === 'ObjectExpression') { const existingAppKeyPropIndex = path.node.declaration.properties.findIndex((prop) => prop.type === 'ObjectProperty' && prop.key.type === 'Identifier' && prop.key.name === 'appKey'); let existingAppKey; if (existingAppKeyPropIndex !== -1) { if ((_a = state.opts) === null || _a === void 0 ? void 0 : _a.clear) { path.node.declaration.properties.splice(existingAppKeyPropIndex, 1); } else { existingAppKey = path.node.declaration.properties[existingAppKeyPropIndex]; path.traverse(propertyVistior, { appKey: existingAppKey, types: t, key: (_b = state.opts) === null || _b === void 0 ? void 0 : _b.key, }); } } else if ((_c = state.opts) === null || _c === void 0 ? void 0 : _c.key) { path.node.declaration.properties.unshift(createProperty({ types: t, key: (_d = state.opts) === null || _d === void 0 ? void 0 : _d.key })); } } }, }, }); //# sourceMappingURL=babel-plugin-app-key.js.map