| 1 |
var res = transform('', { |
| 2 |
plugins: [ |
| 3 |
function (b) { |
| 4 |
var t = b.types; |
| 5 |
return { |
| 6 |
visitor: { |
| 7 |
Program: function(path) { |
| 8 |
if (this.done) return; |
| 9 |
// if (false) { if (true) 42; } else 23; |
| 10 |
var inner = t.ifStatement(t.booleanLiteral(true), t.expressionStatement(t.numericLiteral(42)), null); |
| 11 |
var outer = t.ifStatement(t.booleanLiteral(false), inner, t.expressionStatement(t.numericLiteral(23))); |
| 12 |
path.replaceWith(t.program([outer])); |
| 13 |
this.done = true; |
| 14 |
} |
| 15 |
} |
| 16 |
} |
| 17 |
}, |
| 18 |
], |
| 19 |
}); |
| 20 |
|
| 21 |
expect(eval(res.code)).toBe(23); |