diff --git a/README.md b/README.md index e97e7a86c..09757b219 100644 --- a/README.md +++ b/README.md @@ -12,13 +12,13 @@ [![Join the community on Discord][Badge-Discord]][Discord] [**Documentation**][Documentation] · [**Quickstart**](#quickstart) · [**Example**](#example) · [**Support**](#support) · [**Contribute**](#contribute) · [**License**](#license) + > Internationalization is the design and development of a product, application or document content that enables easy localization for target audiences that vary in culture, region, or language. > > --- [ W3C Web Internationalization FAQ](https://www.w3.org/International/questions/qa-i18n) - Lingui is an easy yet powerful internationalization framework for global projects. - **Clean and readable** - Keep your code clean and readable, while the library uses @@ -76,14 +76,14 @@ If you're a react-intl user, check out [a comparison of react-intl and Lingui](h Short example how i18n looks with JSX: ```js -import { Trans } from "@lingui/macro" +import { Trans } from "@lingui/core/macro" function App() { return ( - - Read the documentation - for more info. - + + Read the documentation + for more info. + ) } ``` @@ -131,18 +131,15 @@ The project is licensed under the [MIT][License] license. [SetupVite]: https://lingui.dev/tutorials/setup-vite [RefCLI]: https://lingui.dev/ref/cli [Examples]: https://github.com/lingui/js-lingui/tree/main/examples - [SWCPlugin]: https://lingui.dev/ref/swc-plugin [VitePlugin]: https://lingui.dev/ref/vite-plugin [ESLintPlugin]: https://lingui.dev/ref/eslint-plugin - [Badge-MainSuite-GithubCI]: https://github.com/lingui/js-lingui/workflows/main-suite/badge.svg [Badge-ReleaseWorkflowTesting-GithubCI]: https://github.com/lingui/js-lingui/workflows/release-workflow-test/badge.svg [Badge-Coverage]: https://img.shields.io/codecov/c/github/lingui/js-lingui/main.svg [Badge-PRWelcome]: https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square [Badge-Discord]: https://img.shields.io/discord/974702239358783608.svg?label=Discord&logo=Discord&colorB=7289da&style=flat-square [Contributors]: https://github.com/lingui/js-lingui/graphs/contributors - [Coverage]: https://codecov.io/gh/lingui/js-lingui [License]: https://github.com/lingui/js-lingui/blob/main/LICENSE [Contributing]: https://github.com/lingui/js-lingui/blob/main/CONTRIBUTING.md diff --git a/examples/create-react-app/package.json b/examples/create-react-app/package.json index e4ca6c099..916f054db 100644 --- a/examples/create-react-app/package.json +++ b/examples/create-react-app/package.json @@ -34,7 +34,6 @@ "devDependencies": { "@lingui/cli": "^4.8.0-next.0", "@lingui/loader": "^4.8.0-next.0", - "@lingui/macro": "^4.8.0-next.0", "@testing-library/jest-dom": "^5.16.5", "@testing-library/react": "^14.0.0", "@testing-library/user-event": "^14.4.3", diff --git a/examples/create-react-app/src/App.tsx b/examples/create-react-app/src/App.tsx index 35b6ee77b..e25b3875c 100644 --- a/examples/create-react-app/src/App.tsx +++ b/examples/create-react-app/src/App.tsx @@ -1,6 +1,6 @@ import "./App.css" import React, { useState } from "react" -import { Trans, Plural } from "@lingui/react.macro" +import { Trans, Plural } from "@lingui/react/macro" import { locales, dynamicActivate } from "./i18n" import { useLingui } from "@lingui/react" diff --git a/examples/js/package.json b/examples/js/package.json index 6d67ccc6b..076ed79f1 100644 --- a/examples/js/package.json +++ b/examples/js/package.json @@ -12,8 +12,7 @@ "extract": "lingui extract --clean" }, "dependencies": { - "@lingui/core": "^4.1.2", - "@lingui/macro": "^4.1.2" + "@lingui/core": "^4.1.2" }, "devDependencies": { "@babel/core": "^7.20.12", diff --git a/examples/js/src/ids.js b/examples/js/src/ids.js index 42bb3159c..a5fd14cbb 100644 --- a/examples/js/src/ids.js +++ b/examples/js/src/ids.js @@ -1,5 +1,5 @@ import { i18n } from "@lingui/core" -import { t, plural, defineMessage } from "@lingui/macro" +import { t, plural, defineMessage } from "@lingui/core/macro" i18n.load({ en: require("./locale/en/messages").messages, diff --git a/examples/js/src/messages.js b/examples/js/src/messages.js index 378e17b13..3ec0210a6 100644 --- a/examples/js/src/messages.js +++ b/examples/js/src/messages.js @@ -1,5 +1,5 @@ import { i18n } from "@lingui/core" -import { t, plural, defineMessage } from "@lingui/macro" +import { t, plural, defineMessage } from "@lingui/core/macro" i18n.load({ en: require("./locale/en/messages").messages, diff --git a/examples/nextjs-babel/package.json b/examples/nextjs-babel/package.json index 0c72406f6..ccb31d28f 100644 --- a/examples/nextjs-babel/package.json +++ b/examples/nextjs-babel/package.json @@ -19,7 +19,6 @@ "devDependencies": { "@lingui/cli": "^4.8.0-next.0", "@lingui/loader": "^4.8.0-next.0", - "@lingui/macro": "^4.8.0-next.0", "@types/react": "^18.0.28", "babel-plugin-macros": "^3.1.0", "typescript": "^4.9.5", diff --git a/examples/nextjs-babel/src/components/Layout.tsx b/examples/nextjs-babel/src/components/Layout.tsx index 1779d2d41..c43f11538 100644 --- a/examples/nextjs-babel/src/components/Layout.tsx +++ b/examples/nextjs-babel/src/components/Layout.tsx @@ -1,7 +1,7 @@ import Head from "next/head" import classnames from "classnames" -import { Trans, useLingui } from "@lingui/react.macro" +import { Trans, useLingui } from "@lingui/react/macro" import styles from "./Layout.module.css" import { useRouter } from "next/router" diff --git a/examples/nextjs-babel/src/pages/examples.tsx b/examples/nextjs-babel/src/pages/examples.tsx index 7ba5cb9c5..5dfc2cb51 100644 --- a/examples/nextjs-babel/src/pages/examples.tsx +++ b/examples/nextjs-babel/src/pages/examples.tsx @@ -1,5 +1,5 @@ -import { plural, msg } from "@lingui/macro" -import { Trans, Plural } from "@lingui/react.macro" +import { plural, msg } from "@lingui/core/macro" +import { Trans, Plural } from "@lingui/react/macro" import { Layout } from "../components/Layout" import { PluralExample } from "../components/PluralExample" diff --git a/examples/nextjs-babel/src/pages/index.tsx b/examples/nextjs-babel/src/pages/index.tsx index 90aeb2691..260f36479 100644 --- a/examples/nextjs-babel/src/pages/index.tsx +++ b/examples/nextjs-babel/src/pages/index.tsx @@ -1,6 +1,6 @@ import Link from "next/link" -import { Trans } from "@lingui/react.macro" +import { Trans } from "@lingui/react/macro" import { Layout } from "../components/Layout" import styles from "./index.module.css" diff --git a/examples/nextjs-swc/package.json b/examples/nextjs-swc/package.json index d16d0d2ff..043a47aa4 100644 --- a/examples/nextjs-swc/package.json +++ b/examples/nextjs-swc/package.json @@ -20,7 +20,6 @@ "devDependencies": { "@lingui/cli": "^4.8.0-next.0", "@lingui/loader": "^4.8.0-next.0", - "@lingui/macro": "^4.8.0-next.0", "@lingui/swc-plugin": "4.0.6", "@types/react": "^18.0.14", "eslint": "8.35.0", diff --git a/examples/nextjs-swc/src/components/AboutText.tsx b/examples/nextjs-swc/src/components/AboutText.tsx index 23ac7e964..87f24d511 100644 --- a/examples/nextjs-swc/src/components/AboutText.tsx +++ b/examples/nextjs-swc/src/components/AboutText.tsx @@ -1,4 +1,4 @@ -import { Trans } from '@lingui/react.macro' +import { Trans } from '@lingui/react/macro' export function AboutText() { return ( diff --git a/examples/nextjs-swc/src/components/Developers.tsx b/examples/nextjs-swc/src/components/Developers.tsx index 3a5e7712d..013607233 100644 --- a/examples/nextjs-swc/src/components/Developers.tsx +++ b/examples/nextjs-swc/src/components/Developers.tsx @@ -1,5 +1,5 @@ import { useState } from 'react' -import { Trans, Plural } from '@lingui/react.macro' +import { Trans, Plural } from '@lingui/react/macro' export default function Developers() { const [selected, setSelected] = useState('1') diff --git a/examples/nextjs-swc/src/components/Switcher.tsx b/examples/nextjs-swc/src/components/Switcher.tsx index 2b43020ba..c1bd9cf95 100644 --- a/examples/nextjs-swc/src/components/Switcher.tsx +++ b/examples/nextjs-swc/src/components/Switcher.tsx @@ -1,7 +1,7 @@ import { useRouter } from 'next/router' import { useState } from 'react' -import { t, msg } from '@lingui/macro' -import { MessageDescriptor } from '@lingui/core/src' +import { t, msg } from '@lingui/core/macro' +import { MessageDescriptor } from '@lingui/core' import { useLingui } from '@lingui/react' type LOCALES = 'en' | 'sr' | 'es' | 'pseudo' diff --git a/examples/nextjs-swc/src/pages/index.tsx b/examples/nextjs-swc/src/pages/index.tsx index fa63fbe03..37e7b53fd 100644 --- a/examples/nextjs-swc/src/pages/index.tsx +++ b/examples/nextjs-swc/src/pages/index.tsx @@ -1,5 +1,5 @@ -import { msg } from '@lingui/macro' -import { Trans } from '@lingui/react.macro' +import { msg } from '@lingui/core/macro' +import { Trans } from '@lingui/react/macro' import { GetStaticProps, NextPage } from 'next' import Head from 'next/head' import { AboutText } from '../components/AboutText' diff --git a/examples/react-native/package.json b/examples/react-native/package.json index 374891e16..82e463067 100644 --- a/examples/react-native/package.json +++ b/examples/react-native/package.json @@ -28,7 +28,6 @@ "devDependencies": { "@babel/core": "^7.21.0", "@lingui/cli": "^4.1.2", - "@lingui/macro": "^4.1.2", "@react-native-community/eslint-config": "^3.2.0", "@types/react": "~18.0.14", "@typescript-eslint/eslint-plugin": "^5.59.11", diff --git a/examples/react-native/src/MainScreen.tsx b/examples/react-native/src/MainScreen.tsx index 21b90411d..a16990904 100644 --- a/examples/react-native/src/MainScreen.tsx +++ b/examples/react-native/src/MainScreen.tsx @@ -1,7 +1,7 @@ import React, { useState } from "react"; import { StyleSheet, Text, View, Alert, SafeAreaView } from "react-native"; -import { Plural, SelectOrdinal, Trans } from "@lingui/react.macro"; -import { useLingui } from "@lingui/react.macro"; +import { Plural, SelectOrdinal, Trans } from "@lingui/react/macro"; +import { useLingui } from "@lingui/react/macro"; import { Button } from "./PaddedButton"; import { Heading } from "./Components"; diff --git a/examples/rspack/package.json b/examples/rspack/package.json index 0d340aae2..622fdd34b 100644 --- a/examples/rspack/package.json +++ b/examples/rspack/package.json @@ -24,7 +24,6 @@ "devDependencies": { "@babel/core": "^7.22.10", "@lingui/cli": "^4.4.0", - "@lingui/macro": "^4.4.0", "@rspack/cli": "latest", "@types/react": "18.2.0", "@types/react-dom": "18.2.1", diff --git a/examples/rspack/src/Inbox.tsx b/examples/rspack/src/Inbox.tsx index 7923e57b8..a63db4210 100644 --- a/examples/rspack/src/Inbox.tsx +++ b/examples/rspack/src/Inbox.tsx @@ -2,7 +2,7 @@ import React from "react" import { useLingui } from "@lingui/react" -import { Trans, Plural } from "@lingui/react.macro" +import { Trans, Plural } from "@lingui/react/macro" import LocaleSwitcher from "./LocaleSwitcher" diff --git a/examples/vite-project-react-babel/package.json b/examples/vite-project-react-babel/package.json index f4e339a4e..feeffa105 100644 --- a/examples/vite-project-react-babel/package.json +++ b/examples/vite-project-react-babel/package.json @@ -10,8 +10,8 @@ "preview": "vite preview" }, "dependencies": { - "@lingui/macro": "^4.1.2", "@lingui/react": "^4.1.2", + "@lingui/core": "^4.1.2", "react": "^18.2.0", "react-dom": "^18.2.0" }, diff --git a/examples/vite-project-react-babel/src/App.tsx b/examples/vite-project-react-babel/src/App.tsx index 1a49d7924..6e4bf77c5 100644 --- a/examples/vite-project-react-babel/src/App.tsx +++ b/examples/vite-project-react-babel/src/App.tsx @@ -3,7 +3,7 @@ import reactLogo from "./assets/react.svg" import linguiLogo from "./assets/lingui-logo.svg" import viteLogo from "/vite.svg" import "./App.css" -import { Plural, Trans } from "@lingui/react.macro" +import { Plural, Trans } from "@lingui/react/macro" import { I18nProvider } from "@lingui/react" import { i18n } from "@lingui/core" import { loadCatalog } from "./i18n" diff --git a/examples/vite-project-react-swc/package.json b/examples/vite-project-react-swc/package.json index 2f4819bb7..8676a69ea 100644 --- a/examples/vite-project-react-swc/package.json +++ b/examples/vite-project-react-swc/package.json @@ -13,7 +13,7 @@ "@swc/core": "1.3.56" }, "dependencies": { - "@lingui/macro": "^4.2.0", + "@lingui/core": "^4.2.0", "@lingui/react": "^4.2.0", "react": "^18.2.0", "react-dom": "^18.2.0" diff --git a/examples/vite-project-react-swc/src/App.tsx b/examples/vite-project-react-swc/src/App.tsx index c5b325925..996e21c8e 100644 --- a/examples/vite-project-react-swc/src/App.tsx +++ b/examples/vite-project-react-swc/src/App.tsx @@ -3,7 +3,7 @@ import reactLogo from "./assets/react.svg" import linguiLogo from "./assets/lingui-logo.svg" import viteLogo from "/vite.svg" import "./App.css" -import { Plural, Trans } from "@lingui/react.macro" +import { Plural, Trans } from "@lingui/react/macro" import { I18nProvider } from "@lingui/react" import { i18n } from "@lingui/core" import { loadCatalog } from "./i18n" diff --git a/jest.config.js b/jest.config.js index 3c353b94a..19e6dc374 100644 --- a/jest.config.js +++ b/jest.config.js @@ -64,7 +64,6 @@ module.exports = { "/packages/conf", "/packages/loader", "/packages/macro", - "/packages/react.macro", "/packages/vite-plugin", "/packages/format-po", "/packages/format-po-gettext", diff --git a/packages/babel-plugin-extract-messages/test/__snapshots__/index.ts.snap b/packages/babel-plugin-extract-messages/test/__snapshots__/index.ts.snap index 8ad9b60f3..a121c767e 100644 --- a/packages/babel-plugin-extract-messages/test/__snapshots__/index.ts.snap +++ b/packages/babel-plugin-extract-messages/test/__snapshots__/index.ts.snap @@ -149,7 +149,7 @@ exports[`@lingui/babel-plugin-extract-messages should extract Plural messages fr message: {count, plural, one {# book} other {# books}}, origin: [ jsx-without-trans.js, - 3, + 2, ], }, { @@ -159,7 +159,7 @@ exports[`@lingui/babel-plugin-extract-messages should extract Plural messages fr message: {count, plural, one {# book} other {# books}}, origin: [ jsx-without-trans.js, - 4, + 3, ], }, ] diff --git a/packages/babel-plugin-extract-messages/test/fixtures/js-with-macros.js b/packages/babel-plugin-extract-messages/test/fixtures/js-with-macros.js index bc0ea0d85..564320d27 100644 --- a/packages/babel-plugin-extract-messages/test/fixtures/js-with-macros.js +++ b/packages/babel-plugin-extract-messages/test/fixtures/js-with-macros.js @@ -1,5 +1,5 @@ -import { t, defineMessage, msg, plural } from "@lingui/macro" -import { useLingui } from "@lingui/react.macro" +import { t, defineMessage, msg, plural } from "@lingui/core/macro" +import { useLingui } from "@lingui/react/macro" t`Message` diff --git a/packages/babel-plugin-extract-messages/test/fixtures/jsx-with-macros.js b/packages/babel-plugin-extract-messages/test/fixtures/jsx-with-macros.js index 17226caf7..c14c5c394 100644 --- a/packages/babel-plugin-extract-messages/test/fixtures/jsx-with-macros.js +++ b/packages/babel-plugin-extract-messages/test/fixtures/jsx-with-macros.js @@ -1,5 +1,5 @@ -import { Trans } from "@lingui/react.macro" -import { t, plural } from "@lingui/macro" +import { Trans } from "@lingui/react/macro" +import { t, plural } from "@lingui/core/macro" ;Hi, my name is {name} ;Some message ;Some other message diff --git a/packages/babel-plugin-extract-messages/test/fixtures/jsx-without-trans.js b/packages/babel-plugin-extract-messages/test/fixtures/jsx-without-trans.js index 455c74419..6a6d0eecc 100644 --- a/packages/babel-plugin-extract-messages/test/fixtures/jsx-without-trans.js +++ b/packages/babel-plugin-extract-messages/test/fixtures/jsx-without-trans.js @@ -1,4 +1,3 @@ -import { Plural } from "@lingui/react.macro" - +import { Plural } from "@lingui/react/macro" ; ; diff --git a/packages/babel-plugin-lingui-macro/src/constants.ts b/packages/babel-plugin-lingui-macro/src/constants.ts index f78dcf2df..e74209e98 100644 --- a/packages/babel-plugin-lingui-macro/src/constants.ts +++ b/packages/babel-plugin-lingui-macro/src/constants.ts @@ -3,8 +3,9 @@ export const MESSAGE = "message" export const COMMENT = "comment" export const EXTRACT_MARK = "i18n" export const CONTEXT = "context" -export const MACRO_PACKAGE = "@lingui/macro" -export const MACRO_REACT_PACKAGE = "@lingui/react.macro" +export const MACRO_LEGACY_PACKAGE = "@lingui/macro" +export const MACRO_CORE_PACKAGE = "@lingui/core/macro" +export const MACRO_REACT_PACKAGE = "@lingui/react/macro" export enum JsMacroName { t = "t", diff --git a/packages/babel-plugin-lingui-macro/src/index.ts b/packages/babel-plugin-lingui-macro/src/index.ts index 03d68efe4..99637953b 100644 --- a/packages/babel-plugin-lingui-macro/src/index.ts +++ b/packages/babel-plugin-lingui-macro/src/index.ts @@ -3,7 +3,11 @@ import type * as babelTypes from "@babel/types" import MacroJSX from "./macroJsx" import { NodePath } from "@babel/traverse" import MacroJs from "./macroJs" -import { MACRO_PACKAGE, MACRO_REACT_PACKAGE } from "./constants" +import { + MACRO_CORE_PACKAGE, + MACRO_REACT_PACKAGE, + MACRO_LEGACY_PACKAGE, +} from "./constants" import { type LinguiConfigNormalized, getConfig as loadConfig, @@ -83,8 +87,11 @@ export default function ({ return path.get("body").filter((statement) => { return ( statement.isImportDeclaration() && - (statement.get("source").node.value === MACRO_PACKAGE || - statement.get("source").node.value === MACRO_REACT_PACKAGE) + [ + MACRO_CORE_PACKAGE, + MACRO_REACT_PACKAGE, + MACRO_LEGACY_PACKAGE, + ].includes(statement.get("source").node.value) ) }) } diff --git a/packages/babel-plugin-lingui-macro/src/macro.ts b/packages/babel-plugin-lingui-macro/src/macro.ts index f9cc238f8..13319d82f 100644 --- a/packages/babel-plugin-lingui-macro/src/macro.ts +++ b/packages/babel-plugin-lingui-macro/src/macro.ts @@ -43,7 +43,7 @@ function macro({ state, babel, config }: MacroParams) { Object.defineProperty(module.exports, name, { get() { throw new Error( - `The macro you imported from "@lingui/macro" or "@lingui/react.macro" is being executed outside the context of compilation with babel-plugin-macros. ` + + `The macro you imported from "@lingui/core/macro" or "@lingui/react/macro" is being executed outside the context of compilation with babel-plugin-macros. ` + `This indicates that you don't have the babel plugin "babel-plugin-macros" configured correctly. ` + `Please see the documentation for how to configure babel-plugin-macros properly: ` + "https://github.com/kentcdodds/babel-plugin-macros/blob/main/other/docs/user.md" diff --git a/packages/babel-plugin-lingui-macro/src/macroJs.test.ts b/packages/babel-plugin-lingui-macro/src/macroJs.test.ts index 6284540fa..2fda267a1 100644 --- a/packages/babel-plugin-lingui-macro/src/macroJs.test.ts +++ b/packages/babel-plugin-lingui-macro/src/macroJs.test.ts @@ -8,7 +8,7 @@ import { JsMacroName } from "./constants" const parseExpression = (expression: string) => { let path: NodePath - const importExp = `import {t, plural, select, selectOrdinal} from "@lingui/macro"; \n` + const importExp = `import {t, plural, select, selectOrdinal} from "@lingui/core/macro"; \n` transformSync(importExp + expression, { filename: "unit-test.js", configFile: false, diff --git a/packages/babel-plugin-lingui-macro/src/macroJs.ts b/packages/babel-plugin-lingui-macro/src/macroJs.ts index 8ac43a352..e85332c3e 100644 --- a/packages/babel-plugin-lingui-macro/src/macroJs.ts +++ b/packages/babel-plugin-lingui-macro/src/macroJs.ts @@ -26,9 +26,10 @@ import { EXTRACT_MARK, ID, MESSAGE, - MACRO_PACKAGE, + MACRO_CORE_PACKAGE, JsMacroName, MACRO_REACT_PACKAGE, + MACRO_LEGACY_PACKAGE, } from "./constants" import { generateMessageId } from "@lingui/message-utils/generateMessageId" @@ -620,7 +621,11 @@ export default class MacroJs { * Custom matchers */ isLinguiIdentifier(path: NodePath, name: JsMacroName) { - if (path.isIdentifier() && path.referencesImport(MACRO_PACKAGE, name)) { + if ( + path.isIdentifier() && + (path.referencesImport(MACRO_CORE_PACKAGE, name) || + path.referencesImport(MACRO_LEGACY_PACKAGE, name)) + ) { return true } } @@ -628,7 +633,8 @@ export default class MacroJs { isUseLinguiHook(path: NodePath) { if ( path.isIdentifier() && - path.referencesImport(MACRO_REACT_PACKAGE, JsMacroName.useLingui) + (path.referencesImport(MACRO_REACT_PACKAGE, JsMacroName.useLingui) || + path.referencesImport(MACRO_LEGACY_PACKAGE, JsMacroName.useLingui)) ) { return true } diff --git a/packages/babel-plugin-lingui-macro/src/macroJsx.test.ts b/packages/babel-plugin-lingui-macro/src/macroJsx.test.ts index 0ce3faf13..1624c9ca1 100644 --- a/packages/babel-plugin-lingui-macro/src/macroJsx.test.ts +++ b/packages/babel-plugin-lingui-macro/src/macroJsx.test.ts @@ -8,7 +8,7 @@ import { JsxMacroName } from "./constants" const parseExpression = (expression: string) => { let path: NodePath - const importExp = `import {Trans, Plural, Select, SelectOrdinal} from "@lingui/react.macro";\n` + const importExp = `import {Trans, Plural, Select, SelectOrdinal} from "@lingui/react/macro";\n` transformSync(importExp + expression, { filename: "unit-test.js", diff --git a/packages/babel-plugin-lingui-macro/src/macroJsx.ts b/packages/babel-plugin-lingui-macro/src/macroJsx.ts index deae1781b..55786c2a9 100644 --- a/packages/babel-plugin-lingui-macro/src/macroJsx.ts +++ b/packages/babel-plugin-lingui-macro/src/macroJsx.ts @@ -28,6 +28,7 @@ import { MESSAGE, JsxMacroName, MACRO_REACT_PACKAGE, + MACRO_LEGACY_PACKAGE, } from "./constants" import { generateMessageId } from "@lingui/message-utils/generateMessageId" @@ -505,12 +506,15 @@ export default class MacroJSX { path: NodePath, name: JsxMacroName ): path is NodePath => { + if (!path.isJSXElement()) { + return false + } + + const identifier = path.get("openingElement").get("name") + return ( - path.isJSXElement() && - path - .get("openingElement") - .get("name") - .referencesImport(MACRO_REACT_PACKAGE, name) + identifier.referencesImport(MACRO_REACT_PACKAGE, name) || + identifier.referencesImport(MACRO_LEGACY_PACKAGE, name) ) } diff --git a/packages/babel-plugin-lingui-macro/test/fixtures/js-t-continuation-character.js b/packages/babel-plugin-lingui-macro/test/fixtures/js-t-continuation-character.js index 349a71dad..5af6829cf 100644 --- a/packages/babel-plugin-lingui-macro/test/fixtures/js-t-continuation-character.js +++ b/packages/babel-plugin-lingui-macro/test/fixtures/js-t-continuation-character.js @@ -1,4 +1,4 @@ -import { t } from '@lingui/macro' +import { t } from "@lingui/core/macro" t`Multiline\ with continuation` diff --git a/packages/babel-plugin-lingui-macro/test/fixtures/js-t-var/js-t-var.js b/packages/babel-plugin-lingui-macro/test/fixtures/js-t-var/js-t-var.js index 0cb13358a..c0156daf3 100644 --- a/packages/babel-plugin-lingui-macro/test/fixtures/js-t-var/js-t-var.js +++ b/packages/babel-plugin-lingui-macro/test/fixtures/js-t-var/js-t-var.js @@ -1,6 +1,6 @@ -import { t } from '@lingui/macro' +import { t } from "@lingui/core/macro" -function scoped (foo) { +function scoped(foo) { if (foo) { const bar = 50 t`This is bar ${bar}` diff --git a/packages/babel-plugin-lingui-macro/test/fixtures/jsx-plural-select-nested.js b/packages/babel-plugin-lingui-macro/test/fixtures/jsx-plural-select-nested.js index 9dcb4fa96..07d3ac8f8 100644 --- a/packages/babel-plugin-lingui-macro/test/fixtures/jsx-plural-select-nested.js +++ b/packages/babel-plugin-lingui-macro/test/fixtures/jsx-plural-select-nested.js @@ -1,5 +1,4 @@ -import { Select, Plural } from "@lingui/react.macro" - +import { Select, Plural } from "@lingui/react/macro" ;