diff --git a/packages/babel-traverse/src/path/introspection.ts b/packages/babel-traverse/src/path/introspection.ts index 32c0e5f14616..e5f7e7b49368 100644 --- a/packages/babel-traverse/src/path/introspection.ts +++ b/packages/babel-traverse/src/path/introspection.ts @@ -175,16 +175,18 @@ export function isStatementOrBlock(this: NodePath): boolean { */ export function referencesImport( - this: NodePath, + this: NodePath, moduleSource: string, importName: string, ): boolean { if (!this.isReferencedIdentifier()) { if ( - (this.isMemberExpression() || this.isOptionalMemberExpression()) && - (this.node.computed - ? isStringLiteral(this.node.property, { value: importName }) - : (this.node.property as t.Identifier).name === importName) + (this.isJSXMemberExpression() && + this.node.property.name === importName) || + ((this.isMemberExpression() || this.isOptionalMemberExpression()) && + (this.node.computed + ? isStringLiteral(this.node.property, { value: importName }) + : (this.node.property as t.Identifier).name === importName)) ) { const object = ( this as NodePath diff --git a/packages/babel-traverse/test/introspection.js b/packages/babel-traverse/test/introspection.js index ab3647ac53ed..eb020035cef1 100644 --- a/packages/babel-traverse/test/introspection.js +++ b/packages/babel-traverse/test/introspection.js @@ -161,6 +161,14 @@ describe("path/introspection", function () { const reference = program.get("body.1.expression"); expect(reference.referencesImport("source", "😅")).toBe(true); }); + it("accepts a named import via a namespace import jsx member expression", function () { + const program = getPath(`import * as ns from "source"; ;`, { + sourceType: "module", + plugins: ["jsx"], + }); + const reference = program.get("body.1.expression.openingElement.name"); + expect(reference.referencesImport("source", "dep")).toBe(true); + }); it("rejects a named import from the wrong module", function () { const program = getPath(`import { dep } from "wrong-source"; dep;`, { sourceType: "module",