add braces around instrumented block-less if statements etc

pull/1839/head
Rich Harris 7 years ago
parent 2f49125441
commit 50c2b5b019

@ -163,7 +163,7 @@ export default function dom(
} }
}, },
leave(node) { leave(node, parent) {
if (map.has(node)) { if (map.has(node)) {
scope = scope.parent; scope = scope.parent;
} }
@ -211,6 +211,9 @@ export default function dom(
} else { } else {
code.prependRight(node.start, `${insert}; `); code.prependRight(node.start, `${insert}; `);
} }
} else if (parent && /(If|For(In|Of)?|While)Statement/.test(parent.type) && node.type !== 'BlockStatement') {
code.prependRight(node.start, '{ ');
code.appendLeft(node.end, `${code.original[node.end - 1] === ';' ? '' : ';'} ${insert}; }`);
} else { } else {
code.appendLeft(node.end, `${code.original[node.end - 1] === ';' ? '' : ';'} ${insert};`); code.appendLeft(node.end, `${code.original[node.end - 1] === ';' ? '' : ';'} ${insert};`);
} }

Loading…
Cancel
Save