-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
/
exec.js
38 lines (34 loc) 路 932 Bytes
/
exec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
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",
{
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", "bar", "qux", "quux"]);
});