fix: fall back to silence when empty
removes annoying error
This commit is contained in:
parent
10ac7c353c
commit
1cc15c7e8d
1 changed files with 12 additions and 2 deletions
|
|
@ -113,8 +113,18 @@ export function transpiler(input, options = {}) {
|
||||||
leave(node, parent, prop, index) {},
|
leave(node, parent, prop, index) {},
|
||||||
});
|
});
|
||||||
|
|
||||||
const { body } = ast;
|
let { body } = ast;
|
||||||
if (!body?.[body.length - 1]?.expression) {
|
|
||||||
|
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');
|
throw new Error('unexpected ast format without body expression');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue