@lingui/macro 3.17.0 → 3.17.2
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 +19 -0
- package/build/constants.js +1 -1
- package/build/global.d.ts +1 -3
- package/build/icu.js +6 -17
- package/build/index.d.ts +1 -3
- package/build/index.js +7 -28
- package/build/macroJs.js +31 -54
- package/build/macroJsx.js +28 -63
- package/build/utils.js +3 -9
- package/package.json +5 -4
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,25 @@
|
|
|
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.2](https://github.com/lingui/js-lingui/compare/v3.17.1...v3.17.2) (2023-02-24)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @lingui/macro
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
## [3.17.1](https://github.com/lingui/js-lingui/compare/v3.17.0...v3.17.1) (2023-02-07)
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
### Bug Fixes
|
|
18
|
+
|
|
19
|
+
* **build:** undeclared dependencies ([#1391](https://github.com/lingui/js-lingui/issues/1391)) ([f390ca4](https://github.com/lingui/js-lingui/commit/f390ca4517144344fcbbbf9c73a42a1a17d0e519))
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
6
25
|
# [3.17.0](https://github.com/lingui/js-lingui/compare/v3.16.1...v3.17.0) (2023-02-01)
|
|
7
26
|
|
|
8
27
|
|
package/build/constants.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
6
|
+
exports.MESSAGE = exports.ID = exports.EXTRACT_MARK = exports.CONTEXT = exports.COMMENT = void 0;
|
|
7
7
|
const ID = "id";
|
|
8
8
|
exports.ID = ID;
|
|
9
9
|
const MESSAGE = "message";
|
package/build/global.d.ts
CHANGED
|
@@ -72,9 +72,7 @@ declare module "@lingui/macro" {
|
|
|
72
72
|
* const message = t(i18n)({ message: `Hello ${name}` });
|
|
73
73
|
* ```
|
|
74
74
|
*/
|
|
75
|
-
export function t(
|
|
76
|
-
i18n: I18n
|
|
77
|
-
): {
|
|
75
|
+
export function t(i18n: I18n): {
|
|
78
76
|
(literals: TemplateStringsArray, ...placeholders: any[]): string
|
|
79
77
|
(descriptor: MessageDescriptor): string
|
|
80
78
|
}
|
package/build/icu.js
CHANGED
|
@@ -4,20 +4,20 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
|
|
8
7
|
var _types = require("@babel/types");
|
|
9
|
-
|
|
10
8
|
const metaOptions = ["id", "comment", "props"];
|
|
11
9
|
const escapedMetaOptionsRe = new RegExp(`^_(${metaOptions.join("|")})$`);
|
|
12
|
-
|
|
13
10
|
class ICUMessageFormat {
|
|
14
11
|
fromTokens(tokens) {
|
|
15
|
-
return (Array.isArray(tokens) ? tokens : [tokens]).map(token => this.processToken(token)).filter(Boolean).reduce((props, message) => ({
|
|
12
|
+
return (Array.isArray(tokens) ? tokens : [tokens]).map(token => this.processToken(token)).filter(Boolean).reduce((props, message) => ({
|
|
13
|
+
...message,
|
|
16
14
|
message: props.message + message.message,
|
|
17
|
-
values: {
|
|
15
|
+
values: {
|
|
16
|
+
...props.values,
|
|
18
17
|
...message.values
|
|
19
18
|
},
|
|
20
|
-
jsxElements: {
|
|
19
|
+
jsxElements: {
|
|
20
|
+
...props.jsxElements,
|
|
21
21
|
...message.jsxElements
|
|
22
22
|
}
|
|
23
23
|
}), {
|
|
@@ -26,10 +26,8 @@ class ICUMessageFormat {
|
|
|
26
26
|
jsxElements: {}
|
|
27
27
|
});
|
|
28
28
|
}
|
|
29
|
-
|
|
30
29
|
processToken(token) {
|
|
31
30
|
const jsxElements = {};
|
|
32
|
-
|
|
33
31
|
if (token.type === "text") {
|
|
34
32
|
return {
|
|
35
33
|
message: token.value
|
|
@@ -38,11 +36,9 @@ class ICUMessageFormat {
|
|
|
38
36
|
if (token.value !== undefined && (0, _types.isJSXEmptyExpression)(token.value)) {
|
|
39
37
|
return null;
|
|
40
38
|
}
|
|
41
|
-
|
|
42
39
|
const values = token.value !== undefined ? {
|
|
43
40
|
[token.name]: token.value
|
|
44
41
|
} : {};
|
|
45
|
-
|
|
46
42
|
switch (token.format) {
|
|
47
43
|
case "plural":
|
|
48
44
|
case "select":
|
|
@@ -50,12 +46,10 @@ class ICUMessageFormat {
|
|
|
50
46
|
const formatOptions = Object.keys(token.options).filter(key => token.options[key] != null).map(key => {
|
|
51
47
|
let value = token.options[key];
|
|
52
48
|
key = key.replace(escapedMetaOptionsRe, "$1");
|
|
53
|
-
|
|
54
49
|
if (key === "offset") {
|
|
55
50
|
// offset has special syntax `offset:number`
|
|
56
51
|
return `offset:${value}`;
|
|
57
52
|
}
|
|
58
|
-
|
|
59
53
|
if (typeof value !== "string") {
|
|
60
54
|
// process tokens from nested formatters
|
|
61
55
|
const {
|
|
@@ -67,7 +61,6 @@ class ICUMessageFormat {
|
|
|
67
61
|
Object.assign(jsxElements, childJsxElements);
|
|
68
62
|
value = message;
|
|
69
63
|
}
|
|
70
|
-
|
|
71
64
|
return `${key} {${value}}`;
|
|
72
65
|
}).join(" ");
|
|
73
66
|
return {
|
|
@@ -75,7 +68,6 @@ class ICUMessageFormat {
|
|
|
75
68
|
values,
|
|
76
69
|
jsxElements
|
|
77
70
|
};
|
|
78
|
-
|
|
79
71
|
default:
|
|
80
72
|
return {
|
|
81
73
|
message: `{${token.name}}`,
|
|
@@ -104,10 +96,7 @@ class ICUMessageFormat {
|
|
|
104
96
|
jsxElements
|
|
105
97
|
};
|
|
106
98
|
}
|
|
107
|
-
|
|
108
99
|
throw new Error(`Unknown token type ${token.type}`);
|
|
109
100
|
}
|
|
110
|
-
|
|
111
101
|
}
|
|
112
|
-
|
|
113
102
|
exports.default = ICUMessageFormat;
|
package/build/index.d.ts
CHANGED
|
@@ -77,9 +77,7 @@ export function t(
|
|
|
77
77
|
* const message = t(i18n)({ message: `Hello ${name}` });
|
|
78
78
|
* ```
|
|
79
79
|
*/
|
|
80
|
-
export function t(
|
|
81
|
-
i18n: I18n
|
|
82
|
-
): {
|
|
80
|
+
export function t(i18n: I18n): {
|
|
83
81
|
(literals: TemplateStringsArray, ...placeholders: any[]): string
|
|
84
82
|
(descriptor: MessageDescriptor): string
|
|
85
83
|
}
|
package/build/index.js
CHANGED
|
@@ -4,23 +4,15 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
|
|
8
7
|
var _babelPluginMacros = require("babel-plugin-macros");
|
|
9
|
-
|
|
10
8
|
var _conf = require("@lingui/conf");
|
|
11
|
-
|
|
12
9
|
var _macroJs = _interopRequireDefault(require("./macroJs"));
|
|
13
|
-
|
|
14
10
|
var _macroJsx = _interopRequireDefault(require("./macroJsx"));
|
|
15
|
-
|
|
16
11
|
var _types = require("@babel/types");
|
|
17
|
-
|
|
18
12
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
19
|
-
|
|
20
13
|
const config = (0, _conf.getConfig)({
|
|
21
14
|
configPath: process.env.LINGUI_CONFIG
|
|
22
15
|
});
|
|
23
|
-
|
|
24
16
|
const getSymbolSource = name => {
|
|
25
17
|
if (Array.isArray(config.runtimeConfigModule)) {
|
|
26
18
|
if (name === "i18n") {
|
|
@@ -36,12 +28,10 @@ const getSymbolSource = name => {
|
|
|
36
28
|
}
|
|
37
29
|
}
|
|
38
30
|
};
|
|
39
|
-
|
|
40
31
|
const [i18nImportModule, i18nImportName = "i18n"] = getSymbolSource("i18n");
|
|
41
32
|
const [TransImportModule, TransImportName = "Trans"] = getSymbolSource("Trans");
|
|
42
|
-
const jsMacroTags = new Set([
|
|
43
|
-
const jsxMacroTags = new Set([
|
|
44
|
-
|
|
33
|
+
const jsMacroTags = new Set(["defineMessage", "arg", "t", "plural", "select", "selectOrdinal"]);
|
|
34
|
+
const jsxMacroTags = new Set(["Trans", "Plural", "Select", "SelectOrdinal"]);
|
|
45
35
|
function macro({
|
|
46
36
|
references,
|
|
47
37
|
state,
|
|
@@ -52,7 +42,6 @@ function macro({
|
|
|
52
42
|
let needsI18nImport = false;
|
|
53
43
|
Object.keys(references).forEach(tagName => {
|
|
54
44
|
const nodes = references[tagName];
|
|
55
|
-
|
|
56
45
|
if (jsMacroTags.has(tagName)) {
|
|
57
46
|
nodes.forEach(node => {
|
|
58
47
|
jsNodes.push(node.parentPath);
|
|
@@ -78,30 +67,27 @@ function macro({
|
|
|
78
67
|
const macro = new _macroJsx.default(babel);
|
|
79
68
|
macro.replacePath(path);
|
|
80
69
|
});
|
|
81
|
-
|
|
82
70
|
if (needsI18nImport) {
|
|
83
71
|
addImport(babel, state, i18nImportModule, i18nImportName);
|
|
84
72
|
}
|
|
85
|
-
|
|
86
73
|
if (jsxNodes.length) {
|
|
87
74
|
addImport(babel, state, TransImportModule, TransImportName);
|
|
88
75
|
}
|
|
89
|
-
|
|
90
76
|
if (process.env.LINGUI_EXTRACT === "1") {
|
|
91
77
|
return {
|
|
92
78
|
keepImports: true
|
|
93
79
|
};
|
|
94
80
|
}
|
|
95
81
|
}
|
|
96
|
-
|
|
97
82
|
function addImport(babel, state, module, importName) {
|
|
98
83
|
const {
|
|
99
84
|
types: t
|
|
100
85
|
} = babel;
|
|
101
|
-
const linguiImport = state.file.path.node.body.find(importNode => t.isImportDeclaration(importNode) && importNode.source.value === module &&
|
|
86
|
+
const linguiImport = state.file.path.node.body.find(importNode => t.isImportDeclaration(importNode) && importNode.source.value === module &&
|
|
87
|
+
// https://github.com/lingui/js-lingui/issues/777
|
|
102
88
|
importNode.importKind !== "type");
|
|
103
|
-
const tIdentifier = t.identifier(importName);
|
|
104
|
-
|
|
89
|
+
const tIdentifier = t.identifier(importName);
|
|
90
|
+
// Handle adding the import or altering the existing import
|
|
105
91
|
if (linguiImport) {
|
|
106
92
|
if (linguiImport.specifiers.findIndex(specifier => (0, _types.isImportSpecifier)(specifier) && (0, _types.isIdentifier)(specifier.imported, {
|
|
107
93
|
name: importName
|
|
@@ -112,7 +98,6 @@ function addImport(babel, state, module, importName) {
|
|
|
112
98
|
state.file.path.node.body.unshift(t.importDeclaration([t.importSpecifier(tIdentifier, tIdentifier)], t.stringLiteral(module)));
|
|
113
99
|
}
|
|
114
100
|
}
|
|
115
|
-
|
|
116
101
|
function isRootPath(allPath) {
|
|
117
102
|
return node => function traverse(path) {
|
|
118
103
|
if (!path.parentPath) {
|
|
@@ -122,9 +107,7 @@ function isRootPath(allPath) {
|
|
|
122
107
|
}
|
|
123
108
|
}(node);
|
|
124
109
|
}
|
|
125
|
-
|
|
126
110
|
const alreadyVisitedCache = new WeakSet();
|
|
127
|
-
|
|
128
111
|
const alreadyVisited = path => {
|
|
129
112
|
if (alreadyVisitedCache.has(path)) {
|
|
130
113
|
return true;
|
|
@@ -133,16 +116,12 @@ const alreadyVisited = path => {
|
|
|
133
116
|
return false;
|
|
134
117
|
}
|
|
135
118
|
};
|
|
136
|
-
|
|
137
119
|
[...jsMacroTags, ...jsxMacroTags].forEach(name => {
|
|
138
120
|
Object.defineProperty(module.exports, name, {
|
|
139
121
|
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: ` +
|
|
122
|
+
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
123
|
}
|
|
142
|
-
|
|
143
124
|
});
|
|
144
125
|
});
|
|
145
|
-
|
|
146
126
|
var _default = (0, _babelPluginMacros.createMacro)(macro);
|
|
147
|
-
|
|
148
127
|
exports.default = _default;
|
package/build/macroJs.js
CHANGED
|
@@ -4,36 +4,26 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
|
|
8
7
|
var R = _interopRequireWildcard(require("ramda"));
|
|
9
|
-
|
|
10
8
|
var _types = require("@babel/types");
|
|
11
|
-
|
|
12
9
|
var _icu = _interopRequireDefault(require("./icu"));
|
|
13
|
-
|
|
14
10
|
var _utils = require("./utils");
|
|
15
|
-
|
|
16
11
|
var _constants = require("./constants");
|
|
17
|
-
|
|
18
12
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
19
|
-
|
|
20
|
-
function
|
|
21
|
-
|
|
22
|
-
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
23
|
-
|
|
13
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
14
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
24
15
|
const keepSpaceRe = /(?:\\(?:\r\n|\r|\n))+\s+/g;
|
|
25
16
|
const keepNewLineRe = /(?:\r\n|\r|\n)+\s+/g;
|
|
26
|
-
|
|
27
17
|
function normalizeWhitespace(text) {
|
|
28
18
|
return text.replace(keepSpaceRe, " ").replace(keepNewLineRe, "\n").trim();
|
|
29
19
|
}
|
|
30
|
-
|
|
31
20
|
class MacroJs {
|
|
32
21
|
// Babel Types
|
|
22
|
+
|
|
33
23
|
// Identifier of i18n object
|
|
24
|
+
|
|
34
25
|
// Positional expressions counter (e.g. for placeholders `Hello {0}, today is {1}`)
|
|
35
26
|
_expressionIndex = (0, _utils.makeCounter)();
|
|
36
|
-
|
|
37
27
|
constructor({
|
|
38
28
|
types
|
|
39
29
|
}, {
|
|
@@ -42,36 +32,34 @@ class MacroJs {
|
|
|
42
32
|
this.types = types;
|
|
43
33
|
this.i18nImportName = i18nImportName;
|
|
44
34
|
}
|
|
45
|
-
|
|
46
35
|
replacePathWithMessage = (path, {
|
|
47
36
|
message,
|
|
48
37
|
values
|
|
49
38
|
}, linguiInstance) => {
|
|
50
39
|
const args = [];
|
|
51
40
|
args.push(isString(message) ? this.types.stringLiteral(message) : message);
|
|
52
|
-
|
|
53
41
|
if (Object.keys(values).length) {
|
|
54
42
|
const valuesObject = Object.keys(values).map(key => this.types.objectProperty(this.types.identifier(key), values[key]));
|
|
55
43
|
args.push(this.types.objectExpression(valuesObject));
|
|
56
44
|
}
|
|
45
|
+
const newNode = this.types.callExpression(this.types.memberExpression(linguiInstance ?? this.types.identifier(this.i18nImportName), this.types.identifier("_")), args);
|
|
57
46
|
|
|
58
|
-
|
|
59
|
-
|
|
47
|
+
// preserve line number
|
|
60
48
|
newNode.loc = path.node.loc;
|
|
61
49
|
path.addComment("leading", _constants.EXTRACT_MARK);
|
|
62
50
|
path.replaceWith(newNode);
|
|
63
|
-
};
|
|
51
|
+
};
|
|
64
52
|
|
|
53
|
+
// Returns a boolean indicating if the replacement requires i18n import
|
|
65
54
|
replacePath = path => {
|
|
66
55
|
// reset the expression counter
|
|
67
56
|
this._expressionIndex = (0, _utils.makeCounter)();
|
|
68
|
-
|
|
69
57
|
if (this.isDefineMessage(path.node)) {
|
|
70
58
|
this.replaceDefineMessage(path);
|
|
71
59
|
return true;
|
|
72
|
-
}
|
|
73
|
-
|
|
60
|
+
}
|
|
74
61
|
|
|
62
|
+
// t(i18nInstance)`Message` -> i18nInstance._('Message')
|
|
75
63
|
if (this.types.isCallExpression(path.node) && this.types.isTaggedTemplateExpression(path.parentPath.node) && this.types.isIdentifier(path.node.arguments[0]) && this.isIdentifier(path.node.callee, "t")) {
|
|
76
64
|
// Use the first argument as i18n instance instead of the default i18n instance
|
|
77
65
|
const i18nInstance = path.node.arguments[0];
|
|
@@ -87,20 +75,18 @@ class MacroJs {
|
|
|
87
75
|
values
|
|
88
76
|
}, i18nInstance);
|
|
89
77
|
return false;
|
|
90
|
-
}
|
|
91
|
-
|
|
78
|
+
}
|
|
92
79
|
|
|
80
|
+
// t(i18nInstance)(messageDescriptor) -> i18nInstance._(messageDescriptor)
|
|
93
81
|
if (this.types.isCallExpression(path.node) && this.types.isCallExpression(path.parentPath.node) && this.types.isIdentifier(path.node.arguments[0]) && this.isIdentifier(path.node.callee, "t")) {
|
|
94
82
|
const i18nInstance = path.node.arguments[0];
|
|
95
83
|
this.replaceTAsFunction(path.parentPath, i18nInstance);
|
|
96
84
|
return false;
|
|
97
85
|
}
|
|
98
|
-
|
|
99
86
|
if (this.types.isCallExpression(path.node) && this.isIdentifier(path.node.callee, "t")) {
|
|
100
87
|
this.replaceTAsFunction(path);
|
|
101
88
|
return true;
|
|
102
89
|
}
|
|
103
|
-
|
|
104
90
|
const tokens = this.tokenizeNode(path.node);
|
|
105
91
|
const messageFormat = new _icu.default();
|
|
106
92
|
const {
|
|
@@ -114,6 +100,7 @@ class MacroJs {
|
|
|
114
100
|
});
|
|
115
101
|
return true;
|
|
116
102
|
};
|
|
103
|
+
|
|
117
104
|
/**
|
|
118
105
|
* macro `defineMessage` is called with MessageDescriptor. The only
|
|
119
106
|
* thing that happens is that any macros used in `message` property
|
|
@@ -135,23 +122,23 @@ class MacroJs {
|
|
|
135
122
|
* }
|
|
136
123
|
*
|
|
137
124
|
*/
|
|
138
|
-
|
|
139
125
|
replaceDefineMessage = path => {
|
|
140
126
|
// reset the expression counter
|
|
141
127
|
this._expressionIndex = (0, _utils.makeCounter)();
|
|
142
128
|
let descriptor = this.processDescriptor(path.node.arguments[0]);
|
|
143
129
|
path.replaceWith(descriptor);
|
|
144
130
|
};
|
|
131
|
+
|
|
145
132
|
/**
|
|
146
133
|
* macro `t` is called with MessageDescriptor, after that
|
|
147
134
|
* we create a new node to append it to i18n._
|
|
148
135
|
*/
|
|
149
|
-
|
|
150
136
|
replaceTAsFunction = (path, linguiInstance) => {
|
|
151
137
|
let descriptor = this.processDescriptor(path.node.arguments[0]);
|
|
152
138
|
const newNode = this.types.callExpression(this.types.memberExpression(linguiInstance ?? this.types.identifier(this.i18nImportName), this.types.identifier("_")), [descriptor]);
|
|
153
139
|
path.replaceWith(newNode);
|
|
154
140
|
};
|
|
141
|
+
|
|
155
142
|
/**
|
|
156
143
|
* `processDescriptor` expand macros inside message descriptor.
|
|
157
144
|
* Message descriptor is used in `defineMessage`.
|
|
@@ -169,23 +156,21 @@ class MacroJs {
|
|
|
169
156
|
* }
|
|
170
157
|
*
|
|
171
158
|
*/
|
|
172
|
-
|
|
173
159
|
processDescriptor = descriptor_ => {
|
|
174
160
|
const descriptor = descriptor_;
|
|
175
161
|
this.types.addComment(descriptor, "leading", _constants.EXTRACT_MARK);
|
|
176
162
|
const messageIndex = descriptor.properties.findIndex(property => (0, _types.isObjectProperty)(property) && this.isIdentifier(property.key, _constants.MESSAGE));
|
|
177
|
-
|
|
178
163
|
if (messageIndex === -1) {
|
|
179
164
|
return descriptor;
|
|
180
|
-
}
|
|
165
|
+
}
|
|
181
166
|
|
|
167
|
+
// if there's `message` property, replace macros with formatted message
|
|
168
|
+
const node = descriptor.properties[messageIndex];
|
|
182
169
|
|
|
183
|
-
|
|
170
|
+
// Inside message descriptor the `t` macro in `message` prop is optional.
|
|
184
171
|
// Template strings are always processed as if they were wrapped by `t`.
|
|
185
|
-
|
|
186
172
|
const tokens = this.types.isTemplateLiteral(node.value) ? this.tokenizeTemplateLiteral(node.value) : this.tokenizeNode(node.value, true);
|
|
187
173
|
let messageNode = node.value;
|
|
188
|
-
|
|
189
174
|
if (tokens != null) {
|
|
190
175
|
const messageFormat = new _icu.default();
|
|
191
176
|
const {
|
|
@@ -195,16 +180,14 @@ class MacroJs {
|
|
|
195
180
|
const message = normalizeWhitespace(messageRaw);
|
|
196
181
|
messageNode = this.types.stringLiteral(message);
|
|
197
182
|
this.addValues(descriptor.properties, values);
|
|
198
|
-
}
|
|
199
|
-
|
|
183
|
+
}
|
|
200
184
|
|
|
185
|
+
// Don't override custom ID
|
|
201
186
|
const hasId = descriptor.properties.findIndex(property => (0, _types.isObjectProperty)(property) && this.isIdentifier(property.key, _constants.ID)) !== -1;
|
|
202
187
|
descriptor.properties[messageIndex] = this.types.objectProperty(this.types.identifier(hasId ? _constants.MESSAGE : _constants.ID), messageNode);
|
|
203
|
-
|
|
204
188
|
if (process.env.NODE_ENV === "production") {
|
|
205
189
|
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
190
|
}
|
|
207
|
-
|
|
208
191
|
return descriptor;
|
|
209
192
|
};
|
|
210
193
|
addValues = (obj, values) => {
|
|
@@ -218,19 +201,20 @@ class MacroJs {
|
|
|
218
201
|
return this.tokenizeTemplateLiteral(node);
|
|
219
202
|
} else if (this.isChoiceMethod(node)) {
|
|
220
203
|
// plural, select and selectOrdinal
|
|
221
|
-
return [this.tokenizeChoiceComponent(node)];
|
|
204
|
+
return [this.tokenizeChoiceComponent(node)];
|
|
205
|
+
// } else if (isFormatMethod(node.callee)) {
|
|
222
206
|
// // date, number
|
|
223
207
|
// return transformFormatMethod(node, file, props, root)
|
|
224
208
|
} else if (!ignoreExpression) {
|
|
225
209
|
return this.tokenizeExpression(node);
|
|
226
210
|
}
|
|
227
211
|
};
|
|
212
|
+
|
|
228
213
|
/**
|
|
229
214
|
* `node` is a TemplateLiteral. node.quasi contains
|
|
230
215
|
* text chunks and node.expressions contains expressions.
|
|
231
216
|
* Both arrays must be zipped together to get the final list of tokens.
|
|
232
217
|
*/
|
|
233
|
-
|
|
234
218
|
tokenizeTemplateLiteral = node => {
|
|
235
219
|
const tokenize = R.pipe(R.evolve({
|
|
236
220
|
quasis: R.map(text => {
|
|
@@ -251,30 +235,29 @@ class MacroJs {
|
|
|
251
235
|
};
|
|
252
236
|
tokenizeChoiceComponent = node => {
|
|
253
237
|
const format = node.callee.name.toLowerCase();
|
|
254
|
-
const token = {
|
|
238
|
+
const token = {
|
|
239
|
+
...this.tokenizeExpression(node.arguments[0]),
|
|
255
240
|
format,
|
|
256
241
|
options: {
|
|
257
242
|
offset: undefined
|
|
258
243
|
}
|
|
259
244
|
};
|
|
260
245
|
const props = node.arguments[1].properties;
|
|
261
|
-
|
|
262
246
|
for (const attr of props) {
|
|
263
247
|
const {
|
|
264
248
|
key,
|
|
265
249
|
value: attrValue
|
|
266
|
-
} = attr;
|
|
250
|
+
} = attr;
|
|
251
|
+
|
|
252
|
+
// name is either:
|
|
267
253
|
// NumericLiteral => convert to `={number}`
|
|
268
254
|
// StringLiteral => key.value
|
|
269
255
|
// Identifier => key.name
|
|
270
|
-
|
|
271
256
|
const name = this.types.isNumericLiteral(key) ? `=${key.value}` : key.name || key.value;
|
|
272
|
-
|
|
273
257
|
if (format !== "select" && name === "offset") {
|
|
274
258
|
token.options.offset = attrValue.value;
|
|
275
259
|
} else {
|
|
276
260
|
let value;
|
|
277
|
-
|
|
278
261
|
if (this.types.isTemplateLiteral(attrValue)) {
|
|
279
262
|
value = this.tokenizeTemplateLiteral(attrValue);
|
|
280
263
|
} else if (this.types.isCallExpression(attrValue)) {
|
|
@@ -282,11 +265,9 @@ class MacroJs {
|
|
|
282
265
|
} else {
|
|
283
266
|
value = attrValue.value;
|
|
284
267
|
}
|
|
285
|
-
|
|
286
268
|
token.options[name] = value;
|
|
287
269
|
}
|
|
288
270
|
}
|
|
289
|
-
|
|
290
271
|
return token;
|
|
291
272
|
};
|
|
292
273
|
tokenizeExpression = node => {
|
|
@@ -297,7 +278,6 @@ class MacroJs {
|
|
|
297
278
|
value: undefined
|
|
298
279
|
};
|
|
299
280
|
}
|
|
300
|
-
|
|
301
281
|
return {
|
|
302
282
|
type: "arg",
|
|
303
283
|
name: this.expressionToArgument(node),
|
|
@@ -313,19 +293,18 @@ class MacroJs {
|
|
|
313
293
|
return String(this._expressionIndex());
|
|
314
294
|
}
|
|
315
295
|
};
|
|
296
|
+
|
|
316
297
|
/**
|
|
317
298
|
* We clean '//\` ' to just '`'
|
|
318
299
|
*/
|
|
319
|
-
|
|
320
300
|
clearBackslashes(value) {
|
|
321
301
|
// if not we replace the extra scaped literals
|
|
322
302
|
return value.replace(/\\`/g, "`");
|
|
323
303
|
}
|
|
304
|
+
|
|
324
305
|
/**
|
|
325
306
|
* Custom matchers
|
|
326
307
|
*/
|
|
327
|
-
|
|
328
|
-
|
|
329
308
|
isIdentifier = (node, name) => {
|
|
330
309
|
return this.types.isIdentifier(node, {
|
|
331
310
|
name
|
|
@@ -344,7 +323,5 @@ class MacroJs {
|
|
|
344
323
|
return this.types.isCallExpression(node) && (this.isIdentifier(node.callee, "plural") || this.isIdentifier(node.callee, "select") || this.isIdentifier(node.callee, "selectOrdinal"));
|
|
345
324
|
};
|
|
346
325
|
}
|
|
347
|
-
|
|
348
326
|
exports.default = MacroJs;
|
|
349
|
-
|
|
350
327
|
const isString = s => typeof s === "string";
|
package/build/macroJsx.js
CHANGED
|
@@ -3,32 +3,22 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.normalizeWhitespace = normalizeWhitespace;
|
|
7
6
|
exports.default = void 0;
|
|
8
|
-
|
|
7
|
+
exports.normalizeWhitespace = normalizeWhitespace;
|
|
9
8
|
var R = _interopRequireWildcard(require("ramda"));
|
|
10
|
-
|
|
11
9
|
var _icu = _interopRequireDefault(require("./icu"));
|
|
12
|
-
|
|
13
10
|
var _utils = require("./utils");
|
|
14
|
-
|
|
15
11
|
var _constants = require("./constants");
|
|
16
|
-
|
|
17
12
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
18
|
-
|
|
19
|
-
function
|
|
20
|
-
|
|
21
|
-
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
22
|
-
|
|
13
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
14
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
23
15
|
const pluralRuleRe = /(_[\d\w]+|zero|one|two|few|many|other)/;
|
|
16
|
+
const jsx2icuExactChoice = value => value.replace(/_(\d+)/, "=$1").replace(/_(\w+)/, "$1");
|
|
24
17
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
const keepSpaceRe = /\s*(?:\r\n|\r|\n)+\s*/g; // remove whitespace before/after tag or expression
|
|
29
|
-
|
|
18
|
+
// replace whitespace before/after newline with single space
|
|
19
|
+
const keepSpaceRe = /\s*(?:\r\n|\r|\n)+\s*/g;
|
|
20
|
+
// remove whitespace before/after tag or expression
|
|
30
21
|
const stripAroundTagsRe = /(?:([>}])(?:\r\n|\r|\n)+\s*|(?:\r\n|\r|\n)+\s*(?=[<{]))/g;
|
|
31
|
-
|
|
32
22
|
function maybeNodeValue(node) {
|
|
33
23
|
if (!node) return null;
|
|
34
24
|
if (node.type === "StringLiteral") return node.value;
|
|
@@ -37,23 +27,21 @@ function maybeNodeValue(node) {
|
|
|
37
27
|
if (node.type === "TemplateLiteral" && node.expressions.length === 0) return node.quasis[0].value.raw;
|
|
38
28
|
return null;
|
|
39
29
|
}
|
|
40
|
-
|
|
41
30
|
function normalizeWhitespace(text) {
|
|
42
|
-
return text.replace(stripAroundTagsRe, "$1").replace(keepSpaceRe, " ")
|
|
43
|
-
|
|
31
|
+
return text.replace(stripAroundTagsRe, "$1").replace(keepSpaceRe, " ")
|
|
32
|
+
// keep escaped newlines
|
|
33
|
+
.replace(/\\n/g, "\n").replace(/\\s/g, " ")
|
|
34
|
+
// we remove trailing whitespace inside Plural
|
|
44
35
|
.replace(/(\s+})/gm, "}").trim();
|
|
45
36
|
}
|
|
46
|
-
|
|
47
37
|
class MacroJSX {
|
|
48
38
|
expressionIndex = (0, _utils.makeCounter)();
|
|
49
39
|
elementIndex = (0, _utils.makeCounter)();
|
|
50
|
-
|
|
51
40
|
constructor({
|
|
52
41
|
types
|
|
53
42
|
}) {
|
|
54
43
|
this.types = types;
|
|
55
44
|
}
|
|
56
|
-
|
|
57
45
|
safeJsxAttribute = (name, value) => {
|
|
58
46
|
// This handles quoted JSX attributes and html entities.
|
|
59
47
|
return this.types.jsxAttribute(this.types.jsxIdentifier(name), this.types.jsxExpressionContainer(this.types.stringLiteral(value)));
|
|
@@ -73,14 +61,12 @@ class MacroJSX {
|
|
|
73
61
|
comment,
|
|
74
62
|
context
|
|
75
63
|
} = this.stripMacroAttributes(path.node);
|
|
76
|
-
|
|
77
64
|
if (!id && !message) {
|
|
78
65
|
return;
|
|
79
66
|
} else if (id && id !== message) {
|
|
80
67
|
// If `id` prop already exists and generated ID is different,
|
|
81
68
|
// add it as a `default` prop
|
|
82
69
|
attributes.push(this.types.jsxAttribute(this.types.jsxIdentifier(_constants.ID), this.types.stringLiteral(id)));
|
|
83
|
-
|
|
84
70
|
if (process.env.NODE_ENV !== "production") {
|
|
85
71
|
if (message) {
|
|
86
72
|
attributes.push(this.safeJsxAttribute(_constants.MESSAGE, message));
|
|
@@ -89,38 +75,26 @@ class MacroJSX {
|
|
|
89
75
|
} else {
|
|
90
76
|
attributes.push(this.safeJsxAttribute(_constants.ID, message));
|
|
91
77
|
}
|
|
92
|
-
|
|
93
78
|
if (process.env.NODE_ENV !== "production") {
|
|
94
79
|
if (comment) {
|
|
95
80
|
attributes.push(this.types.jsxAttribute(this.types.jsxIdentifier(_constants.COMMENT), this.types.stringLiteral(comment)));
|
|
96
81
|
}
|
|
97
82
|
}
|
|
98
|
-
|
|
99
83
|
if (context) {
|
|
100
84
|
attributes.push(this.types.jsxAttribute(this.types.jsxIdentifier(_constants.CONTEXT), this.types.stringLiteral(context)));
|
|
101
|
-
}
|
|
102
|
-
|
|
85
|
+
}
|
|
103
86
|
|
|
87
|
+
// Parameters for variable substitution
|
|
104
88
|
const valuesObject = Object.keys(values).map(key => this.types.objectProperty(this.types.identifier(key), values[key]));
|
|
105
|
-
|
|
106
89
|
if (valuesObject.length) {
|
|
107
90
|
attributes.push(this.types.jsxAttribute(this.types.jsxIdentifier("values"), this.types.jsxExpressionContainer(this.types.objectExpression(valuesObject))));
|
|
108
|
-
}
|
|
109
|
-
|
|
91
|
+
}
|
|
110
92
|
|
|
93
|
+
// Inline elements
|
|
111
94
|
if (Object.keys(jsxElements).length) {
|
|
112
95
|
attributes.push(this.types.jsxAttribute(this.types.jsxIdentifier("components"), this.types.jsxExpressionContainer(this.types.objectExpression(Object.keys(jsxElements).map(key => this.types.objectProperty(this.types.identifier(key), jsxElements[key]))))));
|
|
113
96
|
}
|
|
114
|
-
|
|
115
|
-
const newNode = this.types.jsxElement(this.types.jsxOpeningElement(this.types.jsxIdentifier("Trans"), attributes,
|
|
116
|
-
/*selfClosing*/
|
|
117
|
-
true),
|
|
118
|
-
/*closingElement*/
|
|
119
|
-
null,
|
|
120
|
-
/*children*/
|
|
121
|
-
[],
|
|
122
|
-
/*selfClosing*/
|
|
123
|
-
true);
|
|
97
|
+
const newNode = this.types.jsxElement(this.types.jsxOpeningElement(this.types.jsxIdentifier("Trans"), attributes, /*selfClosing*/true), /*closingElement*/null, /*children*/[], /*selfClosing*/true);
|
|
124
98
|
newNode.loc = path.node.loc;
|
|
125
99
|
path.replaceWith(newNode);
|
|
126
100
|
};
|
|
@@ -140,12 +114,11 @@ class MacroJSX {
|
|
|
140
114
|
const comment = attributes.filter(this.attrName([_constants.COMMENT]))[0];
|
|
141
115
|
const context = attributes.filter(this.attrName([_constants.CONTEXT]))[0];
|
|
142
116
|
let reserved = [_constants.ID, _constants.MESSAGE, _constants.COMMENT, _constants.CONTEXT];
|
|
143
|
-
|
|
144
|
-
|
|
117
|
+
if (this.isI18nComponent(node)) {
|
|
118
|
+
// no reserved prop names
|
|
145
119
|
} else if (this.isChoiceComponent(node)) {
|
|
146
120
|
reserved = [...reserved, "_\\w+", "_\\d+", "zero", "one", "two", "few", "many", "other", "value", "offset"];
|
|
147
121
|
}
|
|
148
|
-
|
|
149
122
|
return {
|
|
150
123
|
id: maybeNodeValue(id),
|
|
151
124
|
message: maybeNodeValue(message),
|
|
@@ -173,7 +146,6 @@ class MacroJSX {
|
|
|
173
146
|
tokenizeChildren = node => {
|
|
174
147
|
if (this.types.isJSXExpressionContainer(node)) {
|
|
175
148
|
const exp = node.expression;
|
|
176
|
-
|
|
177
149
|
if (this.types.isStringLiteral(exp)) {
|
|
178
150
|
// Escape forced newlines to keep them in message.
|
|
179
151
|
return {
|
|
@@ -181,7 +153,8 @@ class MacroJSX {
|
|
|
181
153
|
value: exp.value.replace(/\n/g, "\\n")
|
|
182
154
|
};
|
|
183
155
|
} else if (this.types.isTemplateLiteral(exp)) {
|
|
184
|
-
const tokenize = R.pipe(
|
|
156
|
+
const tokenize = R.pipe(
|
|
157
|
+
// Don"t output tokens without text.
|
|
185
158
|
R.evolve({
|
|
186
159
|
quasis: R.map(text => {
|
|
187
160
|
// if it's an unicode we keep the cooked value because it's the parsed value by babel (without unicode chars)
|
|
@@ -201,17 +174,20 @@ class MacroJSX {
|
|
|
201
174
|
}
|
|
202
175
|
} else if (this.types.isJSXElement(node)) {
|
|
203
176
|
return this.tokenizeNode(node);
|
|
204
|
-
} else if (this.types.isJSXSpreadChild(node)) {
|
|
177
|
+
} else if (this.types.isJSXSpreadChild(node)) {
|
|
178
|
+
// just do nothing
|
|
205
179
|
} else if (this.types.isJSXText(node)) {
|
|
206
180
|
return this.tokenizeText(node.value);
|
|
207
|
-
} else {
|
|
181
|
+
} else {
|
|
182
|
+
// impossible path
|
|
208
183
|
// return this.tokenizeText(node.value)
|
|
209
184
|
}
|
|
210
185
|
};
|
|
211
186
|
tokenizeChoiceComponent = node => {
|
|
212
187
|
const element = node.openingElement;
|
|
213
188
|
const format = this.getJsxTagName(node).toLowerCase();
|
|
214
|
-
const props = element.attributes.filter(this.attrName([_constants.ID, _constants.COMMENT, _constants.MESSAGE, _constants.CONTEXT, "key",
|
|
189
|
+
const props = element.attributes.filter(this.attrName([_constants.ID, _constants.COMMENT, _constants.MESSAGE, _constants.CONTEXT, "key",
|
|
190
|
+
// we remove <Trans /> react props that are not useful for translation
|
|
215
191
|
"render", "component", "components"], true));
|
|
216
192
|
const token = {
|
|
217
193
|
type: "arg",
|
|
@@ -222,18 +198,14 @@ class MacroJSX {
|
|
|
222
198
|
offset: undefined
|
|
223
199
|
}
|
|
224
200
|
};
|
|
225
|
-
|
|
226
201
|
for (const attr of props) {
|
|
227
202
|
if (this.types.isJSXSpreadAttribute(attr)) {
|
|
228
203
|
continue;
|
|
229
204
|
}
|
|
230
|
-
|
|
231
205
|
if (this.types.isJSXNamespacedName(attr.name)) {
|
|
232
206
|
continue;
|
|
233
207
|
}
|
|
234
|
-
|
|
235
208
|
const name = attr.name.name;
|
|
236
|
-
|
|
237
209
|
if (name === "value") {
|
|
238
210
|
const exp = this.types.isLiteral(attr.value) ? attr.value : attr.value.expression;
|
|
239
211
|
token.name = this.expressionToArgument(exp);
|
|
@@ -243,13 +215,11 @@ class MacroJSX {
|
|
|
243
215
|
token.options.offset = this.types.isStringLiteral(attr.value) ? attr.value.value : attr.value.expression.value;
|
|
244
216
|
} else {
|
|
245
217
|
let value;
|
|
246
|
-
|
|
247
218
|
if (this.types.isStringLiteral(attr.value)) {
|
|
248
219
|
value = attr.value.extra.raw.replace(/(["'])(.*)\1/, "$2");
|
|
249
220
|
} else {
|
|
250
221
|
value = this.tokenizeChildren(attr.value);
|
|
251
222
|
}
|
|
252
|
-
|
|
253
223
|
if (pluralRuleRe.test(name)) {
|
|
254
224
|
token.options[jsx2icuExactChoice(name)] = value;
|
|
255
225
|
} else {
|
|
@@ -257,7 +227,6 @@ class MacroJSX {
|
|
|
257
227
|
}
|
|
258
228
|
}
|
|
259
229
|
}
|
|
260
|
-
|
|
261
230
|
return token;
|
|
262
231
|
};
|
|
263
232
|
tokenizeElement = node => {
|
|
@@ -287,24 +256,21 @@ class MacroJSX {
|
|
|
287
256
|
value
|
|
288
257
|
};
|
|
289
258
|
};
|
|
290
|
-
|
|
291
259
|
expressionToArgument(exp) {
|
|
292
260
|
return this.types.isIdentifier(exp) ? exp.name : String(this.expressionIndex());
|
|
293
261
|
}
|
|
262
|
+
|
|
294
263
|
/**
|
|
295
264
|
* We clean '//\` ' to just '`'
|
|
296
265
|
**/
|
|
297
|
-
|
|
298
|
-
|
|
299
266
|
clearBackslashes(value) {
|
|
300
267
|
// if not we replace the extra scaped literals
|
|
301
268
|
return value.replace(/\\`/g, "`");
|
|
302
269
|
}
|
|
270
|
+
|
|
303
271
|
/**
|
|
304
272
|
* Custom matchers
|
|
305
273
|
*/
|
|
306
|
-
|
|
307
|
-
|
|
308
274
|
isIdentifier = (node, name) => {
|
|
309
275
|
return this.types.isIdentifier(node, {
|
|
310
276
|
name
|
|
@@ -324,5 +290,4 @@ class MacroJSX {
|
|
|
324
290
|
}
|
|
325
291
|
};
|
|
326
292
|
}
|
|
327
|
-
|
|
328
293
|
exports.default = MacroJSX;
|
package/build/utils.js
CHANGED
|
@@ -3,15 +3,11 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.zip = zip;
|
|
7
6
|
exports.makeCounter = void 0;
|
|
8
|
-
|
|
7
|
+
exports.zip = zip;
|
|
9
8
|
var R = _interopRequireWildcard(require("ramda"));
|
|
10
|
-
|
|
11
|
-
function
|
|
12
|
-
|
|
13
|
-
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
14
|
-
|
|
9
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
10
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
15
11
|
/**
|
|
16
12
|
* Custom zip method which takes length of the larger array
|
|
17
13
|
* (usually zip functions use the `smaller` length, discarding values in larger array)
|
|
@@ -19,7 +15,5 @@ function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj;
|
|
|
19
15
|
function zip(a, b) {
|
|
20
16
|
return R.range(0, Math.max(a.length, b.length)).map(index => [a[index], b[index]]);
|
|
21
17
|
}
|
|
22
|
-
|
|
23
18
|
const makeCounter = (index = 0) => () => index++;
|
|
24
|
-
|
|
25
19
|
exports.makeCounter = makeCounter;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lingui/macro",
|
|
3
|
-
"version": "3.17.
|
|
3
|
+
"version": "3.17.2",
|
|
4
4
|
"description": "Macro for generating messages in ICU MessageFormat syntax",
|
|
5
5
|
"main": "./build/index.js",
|
|
6
6
|
"author": {
|
|
@@ -27,8 +27,9 @@
|
|
|
27
27
|
"build/"
|
|
28
28
|
],
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@babel/runtime": "^7.
|
|
31
|
-
"@
|
|
30
|
+
"@babel/runtime": "^7.20.13",
|
|
31
|
+
"@babel/types": "^7.20.7",
|
|
32
|
+
"@lingui/conf": "3.17.2",
|
|
32
33
|
"ramda": "^0.27.1"
|
|
33
34
|
},
|
|
34
35
|
"peerDependencies": {
|
|
@@ -39,5 +40,5 @@
|
|
|
39
40
|
"devDependencies": {
|
|
40
41
|
"@types/babel-plugin-macros": "^2.8.5"
|
|
41
42
|
},
|
|
42
|
-
"gitHead": "
|
|
43
|
+
"gitHead": "31dcab5a9a8f88bfa8b3a2c7cd12aa2d908a1d80"
|
|
43
44
|
}
|