Fix t.isReferenced() for named re-exports (#12395)
This commit is contained in:
parent
695abb8dfc
commit
645fe637f2
@ -29,15 +29,6 @@ export default function isReferenced(
|
||||
case "ArrowFunctionExpression":
|
||||
return parent.body === node;
|
||||
|
||||
// no: export { foo as NODE };
|
||||
// yes: export { NODE as foo };
|
||||
// no: export { NODE as foo } from "foo";
|
||||
case "ExportSpecifier":
|
||||
if (parent.source) {
|
||||
return false;
|
||||
}
|
||||
return parent.local === node;
|
||||
|
||||
// no: class { #NODE; }
|
||||
// no: class { get #NODE() {} }
|
||||
// no: class { #NODE() {} }
|
||||
@ -120,6 +111,15 @@ export default function isReferenced(
|
||||
case "ExportDefaultSpecifier":
|
||||
return false;
|
||||
|
||||
// no: export { foo as NODE };
|
||||
// yes: export { NODE as foo };
|
||||
// no: export { NODE as foo } from "foo";
|
||||
case "ExportSpecifier":
|
||||
if (grandparent?.source) {
|
||||
return false;
|
||||
}
|
||||
return parent.local === node;
|
||||
|
||||
// no: import NODE from "foo";
|
||||
// no: import * as NODE from "foo";
|
||||
// no: import { NODE as foo } from "foo";
|
||||
|
||||
@ -247,6 +247,28 @@ describe("validators", function () {
|
||||
expect(t.isReferenced(node, parent)).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe("exports", function () {
|
||||
it("returns false for re-exports", function () {
|
||||
const node = t.identifier("foo");
|
||||
const parent = t.exportSpecifier(node, t.identifier("bar"));
|
||||
const grandparent = t.exportNamedDeclaration(
|
||||
null,
|
||||
[parent],
|
||||
t.stringLiteral("library"),
|
||||
);
|
||||
|
||||
expect(t.isReferenced(node, parent, grandparent)).toBe(false);
|
||||
});
|
||||
|
||||
it("returns true for local exports", function () {
|
||||
const node = t.identifier("foo");
|
||||
const parent = t.exportSpecifier(node, t.identifier("bar"));
|
||||
const grandparent = t.exportNamedDeclaration(null, [parent]);
|
||||
|
||||
expect(t.isReferenced(node, parent, grandparent)).toBe(true);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("isBinding", function () {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user