@lingui/macro 3.16.0 → 3.17.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/CHANGELOG.md +24 -0
- package/LICENSE +1 -1
- package/README.md +2 -2
- package/build/LICENSE +1 -1
- package/build/index.js +14 -24
- package/build/macroJs.js +7 -2
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,30 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
# [3.17.0](https://github.com/lingui/js-lingui/compare/v3.16.1...v3.17.0) (2023-02-01)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Bug Fixes
|
|
10
|
+
|
|
11
|
+
* **macro:** JS macros don't strip non-essential props in production ([#1389](https://github.com/lingui/js-lingui/issues/1389)) ([0ff55d6](https://github.com/lingui/js-lingui/commit/0ff55d606e4eba496548675e42c744d0d872d838))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
### Features
|
|
15
|
+
|
|
16
|
+
* **macro:** throw useful error message if macro used without a plugin ([#1355](https://github.com/lingui/js-lingui/issues/1355)) ([7d55904](https://github.com/lingui/js-lingui/commit/7d55904bb76fae384558945863423145978b9bd6))
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
## [3.16.1](https://github.com/lingui/js-lingui/compare/v3.16.0...v3.16.1) (2023-01-24)
|
|
23
|
+
|
|
24
|
+
**Note:** Version bump only for package @lingui/macro
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
|
|
6
30
|
# [3.16.0](https://github.com/lingui/js-lingui/compare/v3.15.0...v3.16.0) (2023-01-18)
|
|
7
31
|
|
|
8
32
|
|
package/LICENSE
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
The MIT License (MIT)
|
|
2
2
|
|
|
3
|
-
Copyright (c) 2017 Tomáš Ehrlich
|
|
3
|
+
Copyright (c) 2017-2022 Tomáš Ehrlich, (c) 2022-2023 Crowdin.
|
|
4
4
|
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
6
|
of this software and associated documentation files (the "Software"), to deal
|
package/README.md
CHANGED
|
@@ -40,8 +40,8 @@ const message = i18n._(t`Hello, my name is ${name} and today is ${date(now)}`)
|
|
|
40
40
|
|
|
41
41
|
[license]: https://github.com/lingui/js-lingui/blob/main/LICENSE
|
|
42
42
|
[linguijs]: https://github.com/lingui/js-lingui
|
|
43
|
-
[documentation]: https://lingui.
|
|
44
|
-
[reference]: https://lingui.
|
|
43
|
+
[documentation]: https://lingui.dev
|
|
44
|
+
[reference]: https://lingui.dev/ref/macro/
|
|
45
45
|
[package]: https://www.npmjs.com/package/@lingui/macro
|
|
46
46
|
[badge-downloads]: https://img.shields.io/npm/dw/@lingui/macro.svg
|
|
47
47
|
[badge-version]: https://img.shields.io/npm/v/@lingui/macro.svg
|
package/build/LICENSE
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
The MIT License (MIT)
|
|
2
2
|
|
|
3
|
-
Copyright (c) 2017 Tomáš Ehrlich
|
|
3
|
+
Copyright (c) 2017-2022 Tomáš Ehrlich, (c) 2022-2023 Crowdin.
|
|
4
4
|
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
6
|
of this software and associated documentation files (the "Software"), to deal
|
package/build/index.js
CHANGED
|
@@ -39,6 +39,8 @@ const getSymbolSource = name => {
|
|
|
39
39
|
|
|
40
40
|
const [i18nImportModule, i18nImportName = "i18n"] = getSymbolSource("i18n");
|
|
41
41
|
const [TransImportModule, TransImportName = "Trans"] = getSymbolSource("Trans");
|
|
42
|
+
const jsMacroTags = new Set(['defineMessage', 'arg', 't', 'plural', 'select', 'selectOrdinal']);
|
|
43
|
+
const jsxMacroTags = new Set(['Trans', 'Plural', 'Select', 'SelectOrdinal']);
|
|
42
44
|
|
|
43
45
|
function macro({
|
|
44
46
|
references,
|
|
@@ -50,21 +52,18 @@ function macro({
|
|
|
50
52
|
let needsI18nImport = false;
|
|
51
53
|
Object.keys(references).forEach(tagName => {
|
|
52
54
|
const nodes = references[tagName];
|
|
53
|
-
const macroType = getMacroType(tagName);
|
|
54
55
|
|
|
55
|
-
if (
|
|
56
|
-
throw nodes[0].buildCodeFrameError(`Unknown macro ${tagName}`);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
if (macroType === "js") {
|
|
56
|
+
if (jsMacroTags.has(tagName)) {
|
|
60
57
|
nodes.forEach(node => {
|
|
61
58
|
jsNodes.push(node.parentPath);
|
|
62
59
|
});
|
|
63
|
-
} else {
|
|
60
|
+
} else if (jsxMacroTags.has(tagName)) {
|
|
64
61
|
nodes.forEach(node => {
|
|
65
62
|
// identifier.openingElement.jsxElement
|
|
66
63
|
jsxNodes.push(node.parentPath.parentPath);
|
|
67
64
|
});
|
|
65
|
+
} else {
|
|
66
|
+
throw nodes[0].buildCodeFrameError(`Unknown macro ${tagName}`);
|
|
68
67
|
}
|
|
69
68
|
});
|
|
70
69
|
jsNodes.filter(isRootPath(jsNodes)).forEach(path => {
|
|
@@ -135,23 +134,14 @@ const alreadyVisited = path => {
|
|
|
135
134
|
}
|
|
136
135
|
};
|
|
137
136
|
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
return "js";
|
|
147
|
-
|
|
148
|
-
case "Trans":
|
|
149
|
-
case "Plural":
|
|
150
|
-
case "Select":
|
|
151
|
-
case "SelectOrdinal":
|
|
152
|
-
return "jsx";
|
|
153
|
-
}
|
|
154
|
-
}
|
|
137
|
+
[...jsMacroTags, ...jsxMacroTags].forEach(name => {
|
|
138
|
+
Object.defineProperty(module.exports, name, {
|
|
139
|
+
get() {
|
|
140
|
+
throw new Error(`The macro you imported from "@lingui/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');
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
});
|
|
144
|
+
});
|
|
155
145
|
|
|
156
146
|
var _default = (0, _babelPluginMacros.createMacro)(macro);
|
|
157
147
|
|
package/build/macroJs.js
CHANGED
|
@@ -139,7 +139,7 @@ class MacroJs {
|
|
|
139
139
|
replaceDefineMessage = path => {
|
|
140
140
|
// reset the expression counter
|
|
141
141
|
this._expressionIndex = (0, _utils.makeCounter)();
|
|
142
|
-
|
|
142
|
+
let descriptor = this.processDescriptor(path.node.arguments[0]);
|
|
143
143
|
path.replaceWith(descriptor);
|
|
144
144
|
};
|
|
145
145
|
/**
|
|
@@ -148,7 +148,7 @@ class MacroJs {
|
|
|
148
148
|
*/
|
|
149
149
|
|
|
150
150
|
replaceTAsFunction = (path, linguiInstance) => {
|
|
151
|
-
|
|
151
|
+
let descriptor = this.processDescriptor(path.node.arguments[0]);
|
|
152
152
|
const newNode = this.types.callExpression(this.types.memberExpression(linguiInstance ?? this.types.identifier(this.i18nImportName), this.types.identifier("_")), [descriptor]);
|
|
153
153
|
path.replaceWith(newNode);
|
|
154
154
|
};
|
|
@@ -200,6 +200,11 @@ class MacroJs {
|
|
|
200
200
|
|
|
201
201
|
const hasId = descriptor.properties.findIndex(property => (0, _types.isObjectProperty)(property) && this.isIdentifier(property.key, _constants.ID)) !== -1;
|
|
202
202
|
descriptor.properties[messageIndex] = this.types.objectProperty(this.types.identifier(hasId ? _constants.MESSAGE : _constants.ID), messageNode);
|
|
203
|
+
|
|
204
|
+
if (process.env.NODE_ENV === "production") {
|
|
205
|
+
descriptor.properties = descriptor.properties.filter(property => (0, _types.isObjectProperty)(property) && !this.isIdentifier(property.key, _constants.MESSAGE) && (0, _types.isObjectProperty)(property) && !this.isIdentifier(property.key, _constants.COMMENT));
|
|
206
|
+
}
|
|
207
|
+
|
|
203
208
|
return descriptor;
|
|
204
209
|
};
|
|
205
210
|
addValues = (obj, values) => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lingui/macro",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.17.0",
|
|
4
4
|
"description": "Macro for generating messages in ICU MessageFormat syntax",
|
|
5
5
|
"main": "./build/index.js",
|
|
6
6
|
"author": {
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
],
|
|
29
29
|
"dependencies": {
|
|
30
30
|
"@babel/runtime": "^7.11.2",
|
|
31
|
-
"@lingui/conf": "3.
|
|
31
|
+
"@lingui/conf": "3.17.0",
|
|
32
32
|
"ramda": "^0.27.1"
|
|
33
33
|
},
|
|
34
34
|
"peerDependencies": {
|
|
@@ -39,5 +39,5 @@
|
|
|
39
39
|
"devDependencies": {
|
|
40
40
|
"@types/babel-plugin-macros": "^2.8.5"
|
|
41
41
|
},
|
|
42
|
-
"gitHead": "
|
|
42
|
+
"gitHead": "1c8bc46213b35b25da8fe7a80ddcf6f6a5d9d539"
|
|
43
43
|
}
|