| 1 |
import { declare } from "@babel/helper-plugin-utils"; |
| 2 |
import syntaxDoExpressions from "@babel/plugin-syntax-do-expressions"; |
| 3 |
|
| 4 |
export default declare(api => { |
| 5 |
api.assertVersion(7); |
| 6 |
|
| 7 |
return { |
| 8 |
name: "proposal-do-expressions", |
| 9 |
inherits: syntaxDoExpressions, |
| 10 |
|
| 11 |
visitor: { |
| 12 |
DoExpression: { |
| 13 |
exit(path) { |
| 14 |
const { node } = path; |
| 15 |
if (node.async) { |
| 16 |
// Async do expressions are not yet supported |
| 17 |
return; |
| 18 |
} |
| 19 |
const body = node.body.body; |
| 20 |
if (body.length) { |
| 21 |
path.replaceExpressionWithStatements(body); |
| 22 |
} else { |
| 23 |
path.replaceWith(path.scope.buildUndefinedNode()); |
| 24 |
} |
| 25 |
}, |
| 26 |
}, |
| 27 |
}, |
| 28 |
}; |
| 29 |
}); |