@lingui/macro 4.0.0 → 4.1.0
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 +19 -3
- package/dist/index.mjs +19 -3
- package/index.d.ts +3 -5
- package/package.json +6 -6
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
|
-
|
|
820
|
-
|
|
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
|
-
|
|
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
|
-
|
|
818
|
-
|
|
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
|
-
|
|
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 {
|
|
2
|
+
import type { ReactNode, VFC, FC } from "react"
|
|
3
3
|
import type { I18n, MessageDescriptor } from "@lingui/core"
|
|
4
|
-
import type {
|
|
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.
|
|
3
|
+
"version": "4.1.0",
|
|
4
4
|
"description": "Macro for generating messages in ICU MessageFormat syntax",
|
|
5
5
|
"main": "./dist/index.cjs",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
@@ -58,12 +58,12 @@
|
|
|
58
58
|
"dependencies": {
|
|
59
59
|
"@babel/runtime": "^7.20.13",
|
|
60
60
|
"@babel/types": "^7.20.7",
|
|
61
|
-
"@lingui/conf": "4.
|
|
62
|
-
"@lingui/core": "4.
|
|
63
|
-
"@lingui/message-utils": "4.
|
|
61
|
+
"@lingui/conf": "4.1.0",
|
|
62
|
+
"@lingui/core": "4.1.0",
|
|
63
|
+
"@lingui/message-utils": "4.1.0"
|
|
64
64
|
},
|
|
65
65
|
"peerDependencies": {
|
|
66
|
-
"@lingui/react": "4.0.0",
|
|
66
|
+
"@lingui/react": "^4.0.0",
|
|
67
67
|
"babel-plugin-macros": "2 || 3"
|
|
68
68
|
},
|
|
69
69
|
"devDependencies": {
|
|
@@ -75,5 +75,5 @@
|
|
|
75
75
|
"tsd": "^0.26.1",
|
|
76
76
|
"unbuild": "^1.1.2"
|
|
77
77
|
},
|
|
78
|
-
"gitHead": "
|
|
78
|
+
"gitHead": "471813c5de9ade3acccf647e18922b570a804577"
|
|
79
79
|
}
|