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":
|
case "ArrowFunctionExpression":
|
||||||
return parent.body === node;
|
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 { #NODE; }
|
||||||
// no: class { get #NODE() {} }
|
// no: class { get #NODE() {} }
|
||||||
// no: class { #NODE() {} }
|
// no: class { #NODE() {} }
|
||||||
@ -120,6 +111,15 @@ export default function isReferenced(
|
|||||||
case "ExportDefaultSpecifier":
|
case "ExportDefaultSpecifier":
|
||||||
return false;
|
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 NODE from "foo";
|
||||||
// no: import * as NODE from "foo";
|
// no: import * as NODE from "foo";
|
||||||
// no: import { NODE as foo } from "foo";
|
// no: import { NODE as foo } from "foo";
|
||||||
|
|||||||
@ -247,6 +247,28 @@ describe("validators", function () {
|
|||||||
expect(t.isReferenced(node, parent)).toBe(false);
|
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 () {
|
describe("isBinding", function () {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user