diff --git a/packages/babel-plugin-extract-messages/src/index.ts b/packages/babel-plugin-extract-messages/src/index.ts index cb95b8e02..0b937cb65 100644 --- a/packages/babel-plugin-extract-messages/src/index.ts +++ b/packages/babel-plugin-extract-messages/src/index.ts @@ -163,9 +163,9 @@ export default function ({ types: t }: { types: BabelTypes }): PluginObj { t.isMemberExpression(node) && (t.isIdentifier(node.object, { name: I18N_OBJECT }) || (t.isMemberExpression(node.object) && - t.isIdentifier(node.object.property, { name: I18N_OBJECT }) && - (t.isIdentifier(node.property, { name: "_" }) || - t.isIdentifier(node.property, { name: "t" })))) + t.isIdentifier(node.object.property, { name: I18N_OBJECT }))) && + (t.isIdentifier(node.property, { name: "_" }) || + t.isIdentifier(node.property, { name: "t" })) const extractFromMessageDescriptor = ( path: NodePath, diff --git a/packages/babel-plugin-extract-messages/test/index.ts b/packages/babel-plugin-extract-messages/test/index.ts index bd0453a7a..72832cd00 100644 --- a/packages/babel-plugin-extract-messages/test/index.ts +++ b/packages/babel-plugin-extract-messages/test/index.ts @@ -141,6 +141,16 @@ import { Trans } from "@lingui/react"; }) }) + it("should not extract from random i18n members", () => { + const code = ` + i18n.load("Message") + ` + expectNoConsole(() => { + const messages = transformCode(code) + expect(messages.length).toBe(0) + }) + }) + it("should not extract if disabled via annotation", () => { const code = ` /* lingui-extract-ignore */