Justin Ridgewell a5bc48661b
Isolated exec tests (#11531)
* Run exec tests in fresh contexts

* Reevaluate modules in every context

* Cache module code when running tests

* Eliminate weakmap accesses as much as possible

* Remove old multiline usage

* Using bundled polyfill to significantly increase performance

The individual requires for each file were the part that was sooooo slow.

* Drop LRU cache size

* Fixes

* Fix test

Co-authored-by: Huáng Jùnliàng <jlhwung@gmail.com>
2020-08-10 18:57:48 -04:00

39 lines
880 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;
transform(code, {
configFile: false,
plugins: [
"../../../../lib",
{
post({ path }) {
programPath = path;
path.traverse({
ForOfStatement(path) { forOfPath = path },
FunctionExpression(path) { functionPath = path }
});
}
}
]
});
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"]);