Files
Nicolò RibaudoandGitHub d0ffdeb9f5 Rewrite transform-block-scoping plugin (#15200)
* Add test for `const` with `tdz`

* Rewrite block-scoping plugin

* Update block-scoping fixtures

* Update other fixtures

* Fix `let` shadowing variable read in a sibling scope

* Update fixtures

* Update Babel 8 fixtures

* Add minNodeVersion

* Fix block scoped vars shadowing globals

* Review by JLHwung

* minNodeVersion to class fields test
2022-12-14 19:38:57 +01:00

39 lines
934 B
JavaScript

const code = `
for (const {foo, ...bar} of { bar: [] }) {
() => foo;
const [qux] = bar;
try {} catch (e) {
let quux = qux;
}
}
`;
let programPath;
let forOfPath;
let functionPath;
return transformAsync(code, {
configFile: false,
plugins: [
__dirname + "/../../../../lib/index.js",
{
post({ path }) {
programPath = path;
path.traverse({
ForOfStatement(path) { forOfPath = path },
FunctionExpression(path) { functionPath = path }
});
}
}
]
}).then(() => {
expect(Object.keys(programPath.scope.bindings)).toEqual(["foo", "bar"]);
// for declarations should be transformed to for bindings
expect(forOfPath.scope.bindings).toEqual({});
// The body should be wrapped into closure
expect(forOfPath.get("body").scope.bindings).toEqual({});
expect(Object.keys(functionPath.scope.bindings)).toEqual(["foo", "qux", "quux"]);
});