| 1 |
var code = ` |
| 2 |
(function() { |
| 3 |
var bar = 'lol'; |
| 4 |
function foo(b){ |
| 5 |
b === bar |
| 6 |
foo(b); |
| 7 |
} |
| 8 |
})(); |
| 9 |
`; |
| 10 |
|
| 11 |
transform(code, { |
| 12 |
plugins: [ |
| 13 |
function (b) { |
| 14 |
var t = b.types; |
| 15 |
return { |
| 16 |
visitor: { |
| 17 |
// Replace block statements with a new node without changing anything |
| 18 |
BlockStatement: function(path) { |
| 19 |
if (path.node.seen) { |
| 20 |
return; |
| 21 |
} |
| 22 |
|
| 23 |
var node = t.blockStatement(path.node.body); |
| 24 |
node.seen = true; |
| 25 |
path.replaceWith(node); |
| 26 |
}, |
| 27 |
|
| 28 |
// do type inference |
| 29 |
BinaryExpression: function(path) { |
| 30 |
var left = path.get("left"); |
| 31 |
var right = path.get("right"); |
| 32 |
left.baseTypeStrictlyMatches(right); |
| 33 |
} |
| 34 |
} |
| 35 |
}; |
| 36 |
} |
| 37 |
] |
| 38 |
}); |