st-bundle
Version:
CLI for watching and bundling SpringType projects.
40 lines (39 loc) • 1.83 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const tracedVariable_1 = require("./tracedVariable");
const transformUtils_1 = require("../transformUtils");
function handleExportDefaultDeclaration(ctx, node, parent, prop, idx, context) {
if (prop && idx !== undefined) {
if (Array.isArray(parent[prop])) {
if (node.declaration && node.declaration.id && node.declaration.id.name) {
const name = node.declaration.id.name;
parent[prop][idx] = node.declaration; //2
ctx.exported.push({
exported: 'default',
local: name,
});
}
else {
// handle the case:
// expert default { foo, bar }
if (node.declaration.type === 'ObjectExpression' && node.declaration.properties) {
for (const propType of node.declaration.properties) {
if (propType.value) {
propType.value = tracedVariable_1.tracedVariable(ctx, propType.value, context);
if (propType.value.type !== 'Identifier') {
propType.shorthand = false;
}
}
}
}
if (node.declaration.type === 'Identifier') {
parent[prop][idx] = transformUtils_1.createModuleExports('default', tracedVariable_1.tracedVariable(ctx, node.declaration, context));
}
else {
parent[prop][idx] = transformUtils_1.createModuleExports('default', node.declaration);
}
}
}
}
}
exports.handleExportDefaultDeclaration = handleExportDefaultDeclaration;