fix: fall back to silence when empty

removes annoying error
This commit is contained in:
Felix Roos
2025-06-18 22:25:05 +02:00
parent 10ac7c353c
commit 1cc15c7e8d
+12 -2
View File
@@ -113,8 +113,18 @@ export function transpiler(input, options = {}) {
leave(node, parent, prop, index) {},
});
const { body } = ast;
if (!body?.[body.length - 1]?.expression) {
let { body } = ast;
if (!body.length) {
console.warn('empty body -> fallback to silence');
body.push({
type: 'ExpressionStatement',
expression: {
type: 'Identifier',
name: 'silence',
},
});
} else if (!body?.[body.length - 1]?.expression) {
throw new Error('unexpected ast format without body expression');
}