Nicolò Ribaudo fced5cea43
Fix tdz checks in transform-block-scoping plugin (#9498)
* Better tdz tests

- Use jest's expect.toThrow/expect.not.toThrow
- Add input/output tests

* Fix basic tdz (a = 2; let a)

Fixes #6848

* Make _guessExecutionStatusRelativeTo more robust

* Add tests

* Return less "unkown" execution status

* "function" execution status does not exist

* Fix recursive functions

* Update helper version

* "finally" blocks are always executed

* Typo
2019-07-21 06:34:43 +02:00

39 lines
731 B
JavaScript

var code = `var foo = 1;
if (x) {
const bar = 1;
}`;
var innerScope = true;
var res = transform(code, {
configFile: false,
plugins: opts.plugins.concat([
function (b) {
var t = b.types;
return {
visitor: {
Scope: {
exit: function(path) {
if (innerScope) {
expect(Object.keys(path.scope.bindings)).toHaveLength(0);
innerScope = false;
return;
}
expect(Object.keys(path.scope.bindings)).toHaveLength(2);
}
}
}
}
}
]),
});
var expected = `var foo = 1;
if (x) {
var bar = 1;
}`;
expect(res.code).toBe(expected);
expect(innerScope).toBe(false);