Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
liuxingbaoyu committed Jan 24, 2025
1 parent 053bc7b commit d687d01
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions packages/babel-traverse/test/scope.js
Original file line number Diff line number Diff line change
Expand Up @@ -1240,4 +1240,21 @@ describe("scope", () => {
expect(bindingA.constantViolations).toHaveLength(1);
});
});

describe("hasBinding", () => {
it("upToScope", () => {
const program = getPath(`
function x() {
function y() {
var a = 1;
}
}
`);

const scope = program.get("body.0.body.body.0").scope;
expect(scope.hasBinding("a", { upToScope: program.scope })).toBe(true);
expect(scope.hasBinding("a", { upToScope: scope })).toBe(false);
expect(scope.hasBinding("a", { upToScope: scope.parent })).toBe(true);
});
});
});

0 comments on commit d687d01

Please sign in to comment.