Amjad Masad 30bb38c4bb Update scope binding info after transforming block-scoped bindings
When convert a const, let or any other block-bound binding to a var we
forget to update the scope info. This confuses other transforms that may
come after this as to which scope does the binding belongs to.

This also uncovered an issue where duplicate block-scoped bindings were allowed
to co-exist.
2016-03-01 17:03:06 -08:00

40 lines
829 B
JavaScript

var code = [
'var foo = 1;',
'if (x) {',
' const bar = 1;',
'}',
].join('\n');
var innerScope = true;
var res = transform(code, {
plugins: opts.plugins.concat([
function (b) {
var t = b.types;
return {
visitor: {
Scope: {
exit: function(path) {
if (innerScope) {
assert(Object.keys(path.scope.bindings).length === 0, 'Inner scope should not have any bindings');
innerScope = false;
return;
}
assert(Object.keys(path.scope.bindings).length === 2, 'Outer scope subsume the inner-scope binding');
}
}
}
}
}
]),
});
var expected = [
'var foo = 1;',
'if (x) {',
' var bar = 1;',
'}',
].join('\n');
assert.equal(res.code, expected);