mirror of
https://github.com/hanzoai/babel.git
synced 2026-09-24 16:56:45 +00:00
* 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
39 lines
934 B
JavaScript
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"]);
|
|
});
|