@lingui/macro 4.0.0-next.8 → 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 +22 -3
- package/dist/index.mjs +22 -3
- package/index.d.ts +3 -5
- package/package.json +6 -6
package/dist/index.cjs
CHANGED
|
@@ -434,6 +434,9 @@ class MacroJSX {
|
|
|
434
434
|
);
|
|
435
435
|
};
|
|
436
436
|
this.replacePath = (path) => {
|
|
437
|
+
if (!path.isJSXElement()) {
|
|
438
|
+
return path;
|
|
439
|
+
}
|
|
437
440
|
const tokens = this.tokenizeNode(path);
|
|
438
441
|
const messageFormat = new ICUMessageFormat();
|
|
439
442
|
const {
|
|
@@ -813,13 +816,21 @@ function macro({ references, state, babel, config: config2 }) {
|
|
|
813
816
|
stripNonEssentialProps,
|
|
814
817
|
nameMap
|
|
815
818
|
});
|
|
816
|
-
|
|
817
|
-
|
|
819
|
+
try {
|
|
820
|
+
if (macro2.replacePath(path))
|
|
821
|
+
needsI18nImport = true;
|
|
822
|
+
} catch (e) {
|
|
823
|
+
reportUnsupportedSyntax(path, e);
|
|
824
|
+
}
|
|
818
825
|
});
|
|
819
826
|
const jsxNodesArray = Array.from(jsxNodes);
|
|
820
827
|
jsxNodesArray.filter(isRootPath(jsxNodesArray)).forEach((path) => {
|
|
821
828
|
const macro2 = new MacroJSX(babel, { stripNonEssentialProps, nameMap });
|
|
822
|
-
|
|
829
|
+
try {
|
|
830
|
+
macro2.replacePath(path);
|
|
831
|
+
} catch (e) {
|
|
832
|
+
reportUnsupportedSyntax(path, e);
|
|
833
|
+
}
|
|
823
834
|
});
|
|
824
835
|
if (needsI18nImport) {
|
|
825
836
|
addImport(babel, state, i18nImportModule, i18nImportName);
|
|
@@ -828,6 +839,14 @@ function macro({ references, state, babel, config: config2 }) {
|
|
|
828
839
|
addImport(babel, state, TransImportModule, TransImportName);
|
|
829
840
|
}
|
|
830
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
|
+
}
|
|
831
850
|
function addImport(babel, state, module2, importName) {
|
|
832
851
|
const { types: t } = babel;
|
|
833
852
|
const linguiImport = state.file.path.node.body.find(
|
package/dist/index.mjs
CHANGED
|
@@ -432,6 +432,9 @@ class MacroJSX {
|
|
|
432
432
|
);
|
|
433
433
|
};
|
|
434
434
|
this.replacePath = (path) => {
|
|
435
|
+
if (!path.isJSXElement()) {
|
|
436
|
+
return path;
|
|
437
|
+
}
|
|
435
438
|
const tokens = this.tokenizeNode(path);
|
|
436
439
|
const messageFormat = new ICUMessageFormat();
|
|
437
440
|
const {
|
|
@@ -811,13 +814,21 @@ function macro({ references, state, babel, config: config2 }) {
|
|
|
811
814
|
stripNonEssentialProps,
|
|
812
815
|
nameMap
|
|
813
816
|
});
|
|
814
|
-
|
|
815
|
-
|
|
817
|
+
try {
|
|
818
|
+
if (macro2.replacePath(path))
|
|
819
|
+
needsI18nImport = true;
|
|
820
|
+
} catch (e) {
|
|
821
|
+
reportUnsupportedSyntax(path, e);
|
|
822
|
+
}
|
|
816
823
|
});
|
|
817
824
|
const jsxNodesArray = Array.from(jsxNodes);
|
|
818
825
|
jsxNodesArray.filter(isRootPath(jsxNodesArray)).forEach((path) => {
|
|
819
826
|
const macro2 = new MacroJSX(babel, { stripNonEssentialProps, nameMap });
|
|
820
|
-
|
|
827
|
+
try {
|
|
828
|
+
macro2.replacePath(path);
|
|
829
|
+
} catch (e) {
|
|
830
|
+
reportUnsupportedSyntax(path, e);
|
|
831
|
+
}
|
|
821
832
|
});
|
|
822
833
|
if (needsI18nImport) {
|
|
823
834
|
addImport(babel, state, i18nImportModule, i18nImportName);
|
|
@@ -826,6 +837,14 @@ function macro({ references, state, babel, config: config2 }) {
|
|
|
826
837
|
addImport(babel, state, TransImportModule, TransImportName);
|
|
827
838
|
}
|
|
828
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
|
+
}
|
|
829
848
|
function addImport(babel, state, module2, importName) {
|
|
830
849
|
const { types: t } = babel;
|
|
831
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": "
|
|
62
|
-
"@lingui/core": "
|
|
63
|
-
"@lingui/message-utils": "
|
|
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
|
}
|