Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
1. Update tests: some were spurious failures
2. Address failing tests: introduce scope crawling in for statement
   cases
  • Loading branch information
peey committed Apr 26, 2022
1 parent d84141c commit 84d6c4a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 20 deletions.
2 changes: 2 additions & 0 deletions packages/babel-plugin-transform-destructuring/src/index.ts
Expand Up @@ -83,6 +83,7 @@ export default declare((api, options) => {
t.expressionStatement(t.assignmentExpression("=", left, temp)),
);

path.scope.crawl();
return;
}

Expand Down Expand Up @@ -116,6 +117,7 @@ export default declare((api, options) => {
const block = node.body;
// @ts-expect-error: ensureBlock ensures that node.body is a BlockStatement
block.body = nodes.concat(block.body);
path.scope.crawl();
},

CatchClause({ node, scope }) {
Expand Down
34 changes: 14 additions & 20 deletions packages/babel-plugin-transform-destructuring/test/api.js
Expand Up @@ -51,26 +51,20 @@ describe("regression-14438", function () {
});
});

it("transforms the ast", function () {
expect(transformed.ast).toBeTruthy();
});

it("has correct scope information for fixture before transform", function () {
traverse(originalAst, {
Identifier(path) {
const b = path.scope.getBinding(path.node.name);
expect(b).toBeTruthy();
},
});
});

it("has correct scope information for fixture after transform", function () {
traverse(transformed.ast, {
Identifier(path) {
const b = path.scope.getBinding(path.node.name);
expect(b).toBeTruthy();
},
});
it("has correct scope information after transform", function () {
if (transformed.ast) {
// exclude transformation failures: they're tested by the other cases
traverse(transformed.ast, {
VariableDeclarator(path) {
const b = path.scope.getBinding(path.get("id").node.name);
if (!b) {
throw new Error(
`No original binding for ${path.get("id").node.name}`,
);
}
},
});
}
});
});
});

0 comments on commit 84d6c4a

Please sign in to comment.