@lingui/macro 4.0.0 → 4.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -816,13 +816,21 @@ function macro({ references, state, babel, config: config2 }) {
816
816
  stripNonEssentialProps,
817
817
  nameMap
818
818
  });
819
- if (macro2.replacePath(path))
820
- needsI18nImport = true;
819
+ try {
820
+ if (macro2.replacePath(path))
821
+ needsI18nImport = true;
822
+ } catch (e) {
823
+ reportUnsupportedSyntax(path, e);
824
+ }
821
825
  });
822
826
  const jsxNodesArray = Array.from(jsxNodes);
823
827
  jsxNodesArray.filter(isRootPath(jsxNodesArray)).forEach((path) => {
824
828
  const macro2 = new MacroJSX(babel, { stripNonEssentialProps, nameMap });
825
- macro2.replacePath(path);
829
+ try {
830
+ macro2.replacePath(path);
831
+ } catch (e) {
832
+ reportUnsupportedSyntax(path, e);
833
+ }
826
834
  });
827
835
  if (needsI18nImport) {
828
836
  addImport(babel, state, i18nImportModule, i18nImportName);
@@ -831,6 +839,14 @@ function macro({ references, state, babel, config: config2 }) {
831
839
  addImport(babel, state, TransImportModule, TransImportName);
832
840
  }
833
841
  }
842
+ function reportUnsupportedSyntax(path, e) {
843
+ throw path.buildCodeFrameError(
844
+ `Unsupported macro usage. Please check the examples at https://lingui.dev/ref/macro#examples-of-js-macros.
845
+ If you think this is a bug, fill in an issue at https://github.com/lingui/js-lingui/issues
846
+
847
+ Error: ${e.message}`
848
+ );
849
+ }
834
850
  function addImport(babel, state, module2, importName) {
835
851
  const { types: t } = babel;
836
852
  const linguiImport = state.file.path.node.body.find(
package/dist/index.mjs CHANGED
@@ -814,13 +814,21 @@ function macro({ references, state, babel, config: config2 }) {
814
814
  stripNonEssentialProps,
815
815
  nameMap
816
816
  });
817
- if (macro2.replacePath(path))
818
- needsI18nImport = true;
817
+ try {
818
+ if (macro2.replacePath(path))
819
+ needsI18nImport = true;
820
+ } catch (e) {
821
+ reportUnsupportedSyntax(path, e);
822
+ }
819
823
  });
820
824
  const jsxNodesArray = Array.from(jsxNodes);
821
825
  jsxNodesArray.filter(isRootPath(jsxNodesArray)).forEach((path) => {
822
826
  const macro2 = new MacroJSX(babel, { stripNonEssentialProps, nameMap });
823
- macro2.replacePath(path);
827
+ try {
828
+ macro2.replacePath(path);
829
+ } catch (e) {
830
+ reportUnsupportedSyntax(path, e);
831
+ }
824
832
  });
825
833
  if (needsI18nImport) {
826
834
  addImport(babel, state, i18nImportModule, i18nImportName);
@@ -829,6 +837,14 @@ function macro({ references, state, babel, config: config2 }) {
829
837
  addImport(babel, state, TransImportModule, TransImportName);
830
838
  }
831
839
  }
840
+ function reportUnsupportedSyntax(path, e) {
841
+ throw path.buildCodeFrameError(
842
+ `Unsupported macro usage. Please check the examples at https://lingui.dev/ref/macro#examples-of-js-macros.
843
+ If you think this is a bug, fill in an issue at https://github.com/lingui/js-lingui/issues
844
+
845
+ Error: ${e.message}`
846
+ );
847
+ }
832
848
  function addImport(babel, state, module2, importName) {
833
849
  const { types: t } = babel;
834
850
  const linguiImport = state.file.path.node.body.find(
package/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  // eslint-disable-next-line import/no-extraneous-dependencies
2
- import type { ReactElement, ReactNode, VFC, FC } from "react"
2
+ import type { ReactNode, VFC, FC } from "react"
3
3
  import type { I18n, MessageDescriptor } from "@lingui/core"
4
- import type { TransRenderProps } from "@lingui/react"
4
+ import type { TransRenderCallbackOrComponent } from "@lingui/react"
5
5
 
6
6
  export type ChoiceOptions = {
7
7
  /** Offset of value when calculating plural forms */
@@ -216,12 +216,10 @@ export function defineMessage(
216
216
  */
217
217
  export const msg: typeof defineMessage
218
218
 
219
- type CommonProps = {
219
+ type CommonProps = TransRenderCallbackOrComponent & {
220
220
  id?: string
221
221
  comment?: string
222
222
  context?: string
223
- render?: (props: TransRenderProps) => ReactElement<any, any> | null
224
- i18n?: I18n
225
223
  }
226
224
 
227
225
  type TransProps = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lingui/macro",
3
- "version": "4.0.0",
3
+ "version": "4.1.1",
4
4
  "description": "Macro for generating messages in ICU MessageFormat syntax",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.mjs",
@@ -17,7 +17,14 @@
17
17
  },
18
18
  "license": "MIT",
19
19
  "keywords": [
20
- "babel-plugin-macros"
20
+ "babel-plugin-macros",
21
+ "i18n",
22
+ "internationalization",
23
+ "i10n",
24
+ "localization",
25
+ "i9n",
26
+ "translation",
27
+ "multilingual"
21
28
  ],
22
29
  "repository": {
23
30
  "type": "git",
@@ -58,12 +65,12 @@
58
65
  "dependencies": {
59
66
  "@babel/runtime": "^7.20.13",
60
67
  "@babel/types": "^7.20.7",
61
- "@lingui/conf": "4.0.0",
62
- "@lingui/core": "4.0.0",
63
- "@lingui/message-utils": "4.0.0"
68
+ "@lingui/conf": "4.1.1",
69
+ "@lingui/core": "4.1.1",
70
+ "@lingui/message-utils": "4.1.1"
64
71
  },
65
72
  "peerDependencies": {
66
- "@lingui/react": "4.0.0",
73
+ "@lingui/react": "^4.0.0",
67
74
  "babel-plugin-macros": "2 || 3"
68
75
  },
69
76
  "devDependencies": {
@@ -75,5 +82,5 @@
75
82
  "tsd": "^0.26.1",
76
83
  "unbuild": "^1.1.2"
77
84
  },
78
- "gitHead": "998996381f5e5a458c2eccf650f949d8c5d8ac89"
85
+ "gitHead": "dad2c065901a9574bc117a8ef7ed75465ad713d0"
79
86
  }