Justin Ridgewell 8cd4a62c02 Transform do-expressions on exit (#5694)
* Transform do-expressions on exit

This allows other transforms (notably, block scoping) to do their magic
first, possibly saving closures.

Also fixes a bug with declaring duplicate bindings (de-opts now).

* Use strict in exec test

* lint
2017-05-19 16:58:15 -04:00

21 lines
462 B
JavaScript

import syntaxDoExpressions from "babel-plugin-syntax-do-expressions";
export default function () {
return {
inherits: syntaxDoExpressions,
visitor: {
DoExpression: {
exit(path) {
const body = path.node.body.body;
if (body.length) {
path.replaceExpressionWithStatements(body);
} else {
path.replaceWith(path.scope.buildUndefinedNode());
}
},
},
},
};
}