@lingui/macro 4.4.2 → 4.6.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 +71 -52
- package/dist/index.d.cts +9 -0
- package/dist/index.d.mts +9 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.mjs +71 -52
- package/package.json +6 -6
package/dist/index.cjs
CHANGED
|
@@ -99,6 +99,12 @@ const COMMENT = "comment";
|
|
|
99
99
|
const EXTRACT_MARK = "i18n";
|
|
100
100
|
const CONTEXT = "context";
|
|
101
101
|
|
|
102
|
+
var __defProp$1 = Object.defineProperty;
|
|
103
|
+
var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
104
|
+
var __publicField$1 = (obj, key, value) => {
|
|
105
|
+
__defNormalProp$1(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
106
|
+
return value;
|
|
107
|
+
};
|
|
102
108
|
const keepSpaceRe$1 = /(?:\\(?:\r\n|\r|\n))+\s+/g;
|
|
103
109
|
const keepNewLineRe = /(?:\r\n|\r|\n)+\s+/g;
|
|
104
110
|
function normalizeWhitespace$1(text) {
|
|
@@ -111,17 +117,24 @@ function buildICUFromTokens(tokens) {
|
|
|
111
117
|
}
|
|
112
118
|
class MacroJs {
|
|
113
119
|
constructor({ types }, opts) {
|
|
120
|
+
// Babel Types
|
|
121
|
+
__publicField$1(this, "types");
|
|
122
|
+
// Identifier of i18n object
|
|
123
|
+
__publicField$1(this, "i18nImportName");
|
|
124
|
+
__publicField$1(this, "stripNonEssentialProps");
|
|
125
|
+
__publicField$1(this, "nameMap");
|
|
126
|
+
__publicField$1(this, "nameMapReversed");
|
|
114
127
|
// Positional expressions counter (e.g. for placeholders `Hello {0}, today is {1}`)
|
|
115
|
-
this
|
|
116
|
-
this
|
|
128
|
+
__publicField$1(this, "_expressionIndex", makeCounter());
|
|
129
|
+
__publicField$1(this, "replacePathWithMessage", (path, tokens, linguiInstance) => {
|
|
117
130
|
const newNode = this.createI18nCall(
|
|
118
131
|
this.createMessageDescriptorFromTokens(tokens, path.node.loc),
|
|
119
132
|
linguiInstance
|
|
120
133
|
);
|
|
121
134
|
path.replaceWith(newNode);
|
|
122
|
-
};
|
|
135
|
+
});
|
|
123
136
|
// Returns a boolean indicating if the replacement requires i18n import
|
|
124
|
-
this
|
|
137
|
+
__publicField$1(this, "replacePath", (path) => {
|
|
125
138
|
this._expressionIndex = makeCounter();
|
|
126
139
|
if (this.types.isCallExpression(path.node) && this.isDefineMessage(path.node.callee)) {
|
|
127
140
|
let descriptor = this.processDescriptor(path.node.arguments[0]);
|
|
@@ -158,15 +171,15 @@ class MacroJs {
|
|
|
158
171
|
const tokens = this.tokenizeNode(path.node);
|
|
159
172
|
this.replacePathWithMessage(path, tokens);
|
|
160
173
|
return true;
|
|
161
|
-
};
|
|
174
|
+
});
|
|
162
175
|
/**
|
|
163
176
|
* macro `t` is called with MessageDescriptor, after that
|
|
164
177
|
* we create a new node to append it to i18n._
|
|
165
178
|
*/
|
|
166
|
-
this
|
|
179
|
+
__publicField$1(this, "replaceTAsFunction", (path, linguiInstance) => {
|
|
167
180
|
const descriptor = this.processDescriptor(path.node.arguments[0]);
|
|
168
181
|
path.replaceWith(this.createI18nCall(descriptor, linguiInstance));
|
|
169
|
-
};
|
|
182
|
+
});
|
|
170
183
|
/**
|
|
171
184
|
* `processDescriptor` expand macros inside message descriptor.
|
|
172
185
|
* Message descriptor is used in `defineMessage`.
|
|
@@ -185,7 +198,7 @@ class MacroJs {
|
|
|
185
198
|
* }
|
|
186
199
|
*
|
|
187
200
|
*/
|
|
188
|
-
this
|
|
201
|
+
__publicField$1(this, "processDescriptor", (descriptor_) => {
|
|
189
202
|
const descriptor = descriptor_;
|
|
190
203
|
const messageProperty = this.getObjectPropertyByKey(descriptor, MESSAGE);
|
|
191
204
|
const idProperty = this.getObjectPropertyByKey(descriptor, ID);
|
|
@@ -216,7 +229,7 @@ class MacroJs {
|
|
|
216
229
|
properties.push(this.getObjectPropertyByKey(descriptor, COMMENT));
|
|
217
230
|
}
|
|
218
231
|
return this.createMessageDescriptor(properties, descriptor.loc);
|
|
219
|
-
};
|
|
232
|
+
});
|
|
220
233
|
this.types = types;
|
|
221
234
|
this.i18nImportName = opts.i18nImportName;
|
|
222
235
|
this.stripNonEssentialProps = opts.stripNonEssentialProps;
|
|
@@ -267,15 +280,11 @@ class MacroJs {
|
|
|
267
280
|
if (currExp) {
|
|
268
281
|
argTokens = this.types.isCallExpression(currExp) ? this.tokenizeNode(currExp) : [this.tokenizeExpression(currExp)];
|
|
269
282
|
}
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
}
|
|
276
|
-
] : [],
|
|
277
|
-
...argTokens
|
|
278
|
-
];
|
|
283
|
+
const textToken = {
|
|
284
|
+
type: "text",
|
|
285
|
+
value: this.clearBackslashes(value)
|
|
286
|
+
};
|
|
287
|
+
return [...value ? [textToken] : [], ...argTokens];
|
|
279
288
|
});
|
|
280
289
|
}
|
|
281
290
|
tokenizeChoiceComponent(node) {
|
|
@@ -403,6 +412,12 @@ class MacroJs {
|
|
|
403
412
|
}
|
|
404
413
|
}
|
|
405
414
|
|
|
415
|
+
var __defProp = Object.defineProperty;
|
|
416
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
417
|
+
var __publicField = (obj, key, value) => {
|
|
418
|
+
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
419
|
+
return value;
|
|
420
|
+
};
|
|
406
421
|
const pluralRuleRe = /(_[\d\w]+|zero|one|two|few|many|other)/;
|
|
407
422
|
const jsx2icuExactChoice = (value) => value.replace(/_(\d+)/, "=$1").replace(/_(\w+)/, "$1");
|
|
408
423
|
const keepSpaceRe = /\s*(?:\r\n|\r|\n)+\s*/g;
|
|
@@ -425,15 +440,19 @@ function normalizeWhitespace(text) {
|
|
|
425
440
|
}
|
|
426
441
|
class MacroJSX {
|
|
427
442
|
constructor({ types }, opts) {
|
|
428
|
-
this
|
|
429
|
-
this
|
|
430
|
-
this
|
|
443
|
+
__publicField(this, "types");
|
|
444
|
+
__publicField(this, "expressionIndex", makeCounter());
|
|
445
|
+
__publicField(this, "elementIndex", makeCounter());
|
|
446
|
+
__publicField(this, "stripNonEssentialProps");
|
|
447
|
+
__publicField(this, "nameMap");
|
|
448
|
+
__publicField(this, "nameMapReversed");
|
|
449
|
+
__publicField(this, "createStringJsxAttribute", (name, value) => {
|
|
431
450
|
return this.types.jsxAttribute(
|
|
432
451
|
this.types.jsxIdentifier(name),
|
|
433
452
|
this.types.jsxExpressionContainer(this.types.stringLiteral(value))
|
|
434
453
|
);
|
|
435
|
-
};
|
|
436
|
-
this
|
|
454
|
+
});
|
|
455
|
+
__publicField(this, "replacePath", (path) => {
|
|
437
456
|
if (!path.isJSXElement()) {
|
|
438
457
|
return path;
|
|
439
458
|
}
|
|
@@ -526,15 +545,15 @@ class MacroJSX {
|
|
|
526
545
|
);
|
|
527
546
|
newNode.loc = path.node.loc;
|
|
528
547
|
path.replaceWith(newNode);
|
|
529
|
-
};
|
|
530
|
-
this
|
|
548
|
+
});
|
|
549
|
+
__publicField(this, "attrName", (names, exclude = false) => {
|
|
531
550
|
const namesRe = new RegExp("^(" + names.join("|") + ")$");
|
|
532
551
|
return (attr) => {
|
|
533
552
|
const name = attr.name.name;
|
|
534
553
|
return exclude ? !namesRe.test(name) : namesRe.test(name);
|
|
535
554
|
};
|
|
536
|
-
};
|
|
537
|
-
this
|
|
555
|
+
});
|
|
556
|
+
__publicField(this, "stripMacroAttributes", (path) => {
|
|
538
557
|
const { attributes } = path.node.openingElement;
|
|
539
558
|
const id = attributes.find(this.attrName([ID]));
|
|
540
559
|
const message = attributes.find(this.attrName([MESSAGE]));
|
|
@@ -563,8 +582,8 @@ class MacroJSX {
|
|
|
563
582
|
context: maybeNodeValue(context),
|
|
564
583
|
attributes: attributes.filter(this.attrName(reserved, true))
|
|
565
584
|
};
|
|
566
|
-
};
|
|
567
|
-
this
|
|
585
|
+
});
|
|
586
|
+
__publicField(this, "tokenizeNode", (path) => {
|
|
568
587
|
if (this.isTransComponent(path)) {
|
|
569
588
|
return this.tokenizeTrans(path);
|
|
570
589
|
} else if (this.isChoiceComponent(path)) {
|
|
@@ -574,11 +593,11 @@ class MacroJSX {
|
|
|
574
593
|
} else {
|
|
575
594
|
return [this.tokenizeExpression(path)];
|
|
576
595
|
}
|
|
577
|
-
};
|
|
578
|
-
this
|
|
596
|
+
});
|
|
597
|
+
__publicField(this, "tokenizeTrans", (path) => {
|
|
579
598
|
return path.get("children").flatMap((child) => this.tokenizeChildren(child)).filter(Boolean);
|
|
580
|
-
};
|
|
581
|
-
this
|
|
599
|
+
});
|
|
600
|
+
__publicField(this, "tokenizeChildren", (path) => {
|
|
582
601
|
if (path.isJSXExpressionContainer()) {
|
|
583
602
|
const exp = path.get("expression");
|
|
584
603
|
if (exp.isStringLiteral()) {
|
|
@@ -599,8 +618,8 @@ class MacroJSX {
|
|
|
599
618
|
} else if (path.isJSXSpreadChild()) ; else if (path.isJSXText()) {
|
|
600
619
|
return [this.tokenizeText(path.node.value)];
|
|
601
620
|
} else ;
|
|
602
|
-
};
|
|
603
|
-
this
|
|
621
|
+
});
|
|
622
|
+
__publicField(this, "tokenizeChoiceComponent", (path) => {
|
|
604
623
|
const element = path.get("openingElement");
|
|
605
624
|
const name = this.getJsxTagName(path.node);
|
|
606
625
|
const format = (this.nameMapReversed.get(name) || name).toLowerCase();
|
|
@@ -665,8 +684,8 @@ class MacroJSX {
|
|
|
665
684
|
}
|
|
666
685
|
}
|
|
667
686
|
return token;
|
|
668
|
-
};
|
|
669
|
-
this
|
|
687
|
+
});
|
|
688
|
+
__publicField(this, "tokenizeElement", (path) => {
|
|
670
689
|
const name = this.elementIndex();
|
|
671
690
|
return {
|
|
672
691
|
type: "element",
|
|
@@ -681,15 +700,15 @@ class MacroJSX {
|
|
|
681
700
|
},
|
|
682
701
|
children: this.tokenizeTrans(path)
|
|
683
702
|
};
|
|
684
|
-
};
|
|
685
|
-
this
|
|
703
|
+
});
|
|
704
|
+
__publicField(this, "tokenizeExpression", (path) => {
|
|
686
705
|
return {
|
|
687
706
|
type: "arg",
|
|
688
707
|
name: this.expressionToArgument(path),
|
|
689
708
|
value: path.node
|
|
690
709
|
};
|
|
691
|
-
};
|
|
692
|
-
this
|
|
710
|
+
});
|
|
711
|
+
__publicField(this, "tokenizeConditionalExpression", (exp) => {
|
|
693
712
|
exp.traverse({
|
|
694
713
|
JSXElement: (el) => {
|
|
695
714
|
if (this.isTransComponent(el) || this.isChoiceComponent(el)) {
|
|
@@ -703,29 +722,29 @@ class MacroJSX {
|
|
|
703
722
|
name: this.expressionToArgument(exp),
|
|
704
723
|
value: exp.node
|
|
705
724
|
};
|
|
706
|
-
};
|
|
707
|
-
this
|
|
725
|
+
});
|
|
726
|
+
__publicField(this, "tokenizeText", (value) => {
|
|
708
727
|
return {
|
|
709
728
|
type: "text",
|
|
710
729
|
value
|
|
711
730
|
};
|
|
712
|
-
};
|
|
713
|
-
this
|
|
731
|
+
});
|
|
732
|
+
__publicField(this, "isLinguiComponent", (path, name) => {
|
|
714
733
|
return path.isJSXElement() && this.types.isJSXIdentifier(path.node.openingElement.name, {
|
|
715
734
|
name: this.nameMap.get(name) || name
|
|
716
735
|
});
|
|
717
|
-
};
|
|
718
|
-
this
|
|
736
|
+
});
|
|
737
|
+
__publicField(this, "isTransComponent", (path) => {
|
|
719
738
|
return this.isLinguiComponent(path, "Trans");
|
|
720
|
-
};
|
|
721
|
-
this
|
|
739
|
+
});
|
|
740
|
+
__publicField(this, "isChoiceComponent", (path) => {
|
|
722
741
|
return this.isLinguiComponent(path, "Plural") || this.isLinguiComponent(path, "Select") || this.isLinguiComponent(path, "SelectOrdinal");
|
|
723
|
-
};
|
|
724
|
-
this
|
|
742
|
+
});
|
|
743
|
+
__publicField(this, "getJsxTagName", (node) => {
|
|
725
744
|
if (this.types.isJSXIdentifier(node.openingElement.name)) {
|
|
726
745
|
return node.openingElement.name.name;
|
|
727
746
|
}
|
|
728
|
-
};
|
|
747
|
+
});
|
|
729
748
|
this.types = types;
|
|
730
749
|
this.stripNonEssentialProps = opts.stripNonEssentialProps;
|
|
731
750
|
this.nameMap = opts.nameMap;
|
package/dist/index.d.cts
ADDED
package/dist/index.d.mts
ADDED
package/dist/index.d.ts
CHANGED
package/dist/index.mjs
CHANGED
|
@@ -97,6 +97,12 @@ const COMMENT = "comment";
|
|
|
97
97
|
const EXTRACT_MARK = "i18n";
|
|
98
98
|
const CONTEXT = "context";
|
|
99
99
|
|
|
100
|
+
var __defProp$1 = Object.defineProperty;
|
|
101
|
+
var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
102
|
+
var __publicField$1 = (obj, key, value) => {
|
|
103
|
+
__defNormalProp$1(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
104
|
+
return value;
|
|
105
|
+
};
|
|
100
106
|
const keepSpaceRe$1 = /(?:\\(?:\r\n|\r|\n))+\s+/g;
|
|
101
107
|
const keepNewLineRe = /(?:\r\n|\r|\n)+\s+/g;
|
|
102
108
|
function normalizeWhitespace$1(text) {
|
|
@@ -109,17 +115,24 @@ function buildICUFromTokens(tokens) {
|
|
|
109
115
|
}
|
|
110
116
|
class MacroJs {
|
|
111
117
|
constructor({ types }, opts) {
|
|
118
|
+
// Babel Types
|
|
119
|
+
__publicField$1(this, "types");
|
|
120
|
+
// Identifier of i18n object
|
|
121
|
+
__publicField$1(this, "i18nImportName");
|
|
122
|
+
__publicField$1(this, "stripNonEssentialProps");
|
|
123
|
+
__publicField$1(this, "nameMap");
|
|
124
|
+
__publicField$1(this, "nameMapReversed");
|
|
112
125
|
// Positional expressions counter (e.g. for placeholders `Hello {0}, today is {1}`)
|
|
113
|
-
this
|
|
114
|
-
this
|
|
126
|
+
__publicField$1(this, "_expressionIndex", makeCounter());
|
|
127
|
+
__publicField$1(this, "replacePathWithMessage", (path, tokens, linguiInstance) => {
|
|
115
128
|
const newNode = this.createI18nCall(
|
|
116
129
|
this.createMessageDescriptorFromTokens(tokens, path.node.loc),
|
|
117
130
|
linguiInstance
|
|
118
131
|
);
|
|
119
132
|
path.replaceWith(newNode);
|
|
120
|
-
};
|
|
133
|
+
});
|
|
121
134
|
// Returns a boolean indicating if the replacement requires i18n import
|
|
122
|
-
this
|
|
135
|
+
__publicField$1(this, "replacePath", (path) => {
|
|
123
136
|
this._expressionIndex = makeCounter();
|
|
124
137
|
if (this.types.isCallExpression(path.node) && this.isDefineMessage(path.node.callee)) {
|
|
125
138
|
let descriptor = this.processDescriptor(path.node.arguments[0]);
|
|
@@ -156,15 +169,15 @@ class MacroJs {
|
|
|
156
169
|
const tokens = this.tokenizeNode(path.node);
|
|
157
170
|
this.replacePathWithMessage(path, tokens);
|
|
158
171
|
return true;
|
|
159
|
-
};
|
|
172
|
+
});
|
|
160
173
|
/**
|
|
161
174
|
* macro `t` is called with MessageDescriptor, after that
|
|
162
175
|
* we create a new node to append it to i18n._
|
|
163
176
|
*/
|
|
164
|
-
this
|
|
177
|
+
__publicField$1(this, "replaceTAsFunction", (path, linguiInstance) => {
|
|
165
178
|
const descriptor = this.processDescriptor(path.node.arguments[0]);
|
|
166
179
|
path.replaceWith(this.createI18nCall(descriptor, linguiInstance));
|
|
167
|
-
};
|
|
180
|
+
});
|
|
168
181
|
/**
|
|
169
182
|
* `processDescriptor` expand macros inside message descriptor.
|
|
170
183
|
* Message descriptor is used in `defineMessage`.
|
|
@@ -183,7 +196,7 @@ class MacroJs {
|
|
|
183
196
|
* }
|
|
184
197
|
*
|
|
185
198
|
*/
|
|
186
|
-
this
|
|
199
|
+
__publicField$1(this, "processDescriptor", (descriptor_) => {
|
|
187
200
|
const descriptor = descriptor_;
|
|
188
201
|
const messageProperty = this.getObjectPropertyByKey(descriptor, MESSAGE);
|
|
189
202
|
const idProperty = this.getObjectPropertyByKey(descriptor, ID);
|
|
@@ -214,7 +227,7 @@ class MacroJs {
|
|
|
214
227
|
properties.push(this.getObjectPropertyByKey(descriptor, COMMENT));
|
|
215
228
|
}
|
|
216
229
|
return this.createMessageDescriptor(properties, descriptor.loc);
|
|
217
|
-
};
|
|
230
|
+
});
|
|
218
231
|
this.types = types;
|
|
219
232
|
this.i18nImportName = opts.i18nImportName;
|
|
220
233
|
this.stripNonEssentialProps = opts.stripNonEssentialProps;
|
|
@@ -265,15 +278,11 @@ class MacroJs {
|
|
|
265
278
|
if (currExp) {
|
|
266
279
|
argTokens = this.types.isCallExpression(currExp) ? this.tokenizeNode(currExp) : [this.tokenizeExpression(currExp)];
|
|
267
280
|
}
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
}
|
|
274
|
-
] : [],
|
|
275
|
-
...argTokens
|
|
276
|
-
];
|
|
281
|
+
const textToken = {
|
|
282
|
+
type: "text",
|
|
283
|
+
value: this.clearBackslashes(value)
|
|
284
|
+
};
|
|
285
|
+
return [...value ? [textToken] : [], ...argTokens];
|
|
277
286
|
});
|
|
278
287
|
}
|
|
279
288
|
tokenizeChoiceComponent(node) {
|
|
@@ -401,6 +410,12 @@ class MacroJs {
|
|
|
401
410
|
}
|
|
402
411
|
}
|
|
403
412
|
|
|
413
|
+
var __defProp = Object.defineProperty;
|
|
414
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
415
|
+
var __publicField = (obj, key, value) => {
|
|
416
|
+
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
417
|
+
return value;
|
|
418
|
+
};
|
|
404
419
|
const pluralRuleRe = /(_[\d\w]+|zero|one|two|few|many|other)/;
|
|
405
420
|
const jsx2icuExactChoice = (value) => value.replace(/_(\d+)/, "=$1").replace(/_(\w+)/, "$1");
|
|
406
421
|
const keepSpaceRe = /\s*(?:\r\n|\r|\n)+\s*/g;
|
|
@@ -423,15 +438,19 @@ function normalizeWhitespace(text) {
|
|
|
423
438
|
}
|
|
424
439
|
class MacroJSX {
|
|
425
440
|
constructor({ types }, opts) {
|
|
426
|
-
this
|
|
427
|
-
this
|
|
428
|
-
this
|
|
441
|
+
__publicField(this, "types");
|
|
442
|
+
__publicField(this, "expressionIndex", makeCounter());
|
|
443
|
+
__publicField(this, "elementIndex", makeCounter());
|
|
444
|
+
__publicField(this, "stripNonEssentialProps");
|
|
445
|
+
__publicField(this, "nameMap");
|
|
446
|
+
__publicField(this, "nameMapReversed");
|
|
447
|
+
__publicField(this, "createStringJsxAttribute", (name, value) => {
|
|
429
448
|
return this.types.jsxAttribute(
|
|
430
449
|
this.types.jsxIdentifier(name),
|
|
431
450
|
this.types.jsxExpressionContainer(this.types.stringLiteral(value))
|
|
432
451
|
);
|
|
433
|
-
};
|
|
434
|
-
this
|
|
452
|
+
});
|
|
453
|
+
__publicField(this, "replacePath", (path) => {
|
|
435
454
|
if (!path.isJSXElement()) {
|
|
436
455
|
return path;
|
|
437
456
|
}
|
|
@@ -524,15 +543,15 @@ class MacroJSX {
|
|
|
524
543
|
);
|
|
525
544
|
newNode.loc = path.node.loc;
|
|
526
545
|
path.replaceWith(newNode);
|
|
527
|
-
};
|
|
528
|
-
this
|
|
546
|
+
});
|
|
547
|
+
__publicField(this, "attrName", (names, exclude = false) => {
|
|
529
548
|
const namesRe = new RegExp("^(" + names.join("|") + ")$");
|
|
530
549
|
return (attr) => {
|
|
531
550
|
const name = attr.name.name;
|
|
532
551
|
return exclude ? !namesRe.test(name) : namesRe.test(name);
|
|
533
552
|
};
|
|
534
|
-
};
|
|
535
|
-
this
|
|
553
|
+
});
|
|
554
|
+
__publicField(this, "stripMacroAttributes", (path) => {
|
|
536
555
|
const { attributes } = path.node.openingElement;
|
|
537
556
|
const id = attributes.find(this.attrName([ID]));
|
|
538
557
|
const message = attributes.find(this.attrName([MESSAGE]));
|
|
@@ -561,8 +580,8 @@ class MacroJSX {
|
|
|
561
580
|
context: maybeNodeValue(context),
|
|
562
581
|
attributes: attributes.filter(this.attrName(reserved, true))
|
|
563
582
|
};
|
|
564
|
-
};
|
|
565
|
-
this
|
|
583
|
+
});
|
|
584
|
+
__publicField(this, "tokenizeNode", (path) => {
|
|
566
585
|
if (this.isTransComponent(path)) {
|
|
567
586
|
return this.tokenizeTrans(path);
|
|
568
587
|
} else if (this.isChoiceComponent(path)) {
|
|
@@ -572,11 +591,11 @@ class MacroJSX {
|
|
|
572
591
|
} else {
|
|
573
592
|
return [this.tokenizeExpression(path)];
|
|
574
593
|
}
|
|
575
|
-
};
|
|
576
|
-
this
|
|
594
|
+
});
|
|
595
|
+
__publicField(this, "tokenizeTrans", (path) => {
|
|
577
596
|
return path.get("children").flatMap((child) => this.tokenizeChildren(child)).filter(Boolean);
|
|
578
|
-
};
|
|
579
|
-
this
|
|
597
|
+
});
|
|
598
|
+
__publicField(this, "tokenizeChildren", (path) => {
|
|
580
599
|
if (path.isJSXExpressionContainer()) {
|
|
581
600
|
const exp = path.get("expression");
|
|
582
601
|
if (exp.isStringLiteral()) {
|
|
@@ -597,8 +616,8 @@ class MacroJSX {
|
|
|
597
616
|
} else if (path.isJSXSpreadChild()) ; else if (path.isJSXText()) {
|
|
598
617
|
return [this.tokenizeText(path.node.value)];
|
|
599
618
|
} else ;
|
|
600
|
-
};
|
|
601
|
-
this
|
|
619
|
+
});
|
|
620
|
+
__publicField(this, "tokenizeChoiceComponent", (path) => {
|
|
602
621
|
const element = path.get("openingElement");
|
|
603
622
|
const name = this.getJsxTagName(path.node);
|
|
604
623
|
const format = (this.nameMapReversed.get(name) || name).toLowerCase();
|
|
@@ -663,8 +682,8 @@ class MacroJSX {
|
|
|
663
682
|
}
|
|
664
683
|
}
|
|
665
684
|
return token;
|
|
666
|
-
};
|
|
667
|
-
this
|
|
685
|
+
});
|
|
686
|
+
__publicField(this, "tokenizeElement", (path) => {
|
|
668
687
|
const name = this.elementIndex();
|
|
669
688
|
return {
|
|
670
689
|
type: "element",
|
|
@@ -679,15 +698,15 @@ class MacroJSX {
|
|
|
679
698
|
},
|
|
680
699
|
children: this.tokenizeTrans(path)
|
|
681
700
|
};
|
|
682
|
-
};
|
|
683
|
-
this
|
|
701
|
+
});
|
|
702
|
+
__publicField(this, "tokenizeExpression", (path) => {
|
|
684
703
|
return {
|
|
685
704
|
type: "arg",
|
|
686
705
|
name: this.expressionToArgument(path),
|
|
687
706
|
value: path.node
|
|
688
707
|
};
|
|
689
|
-
};
|
|
690
|
-
this
|
|
708
|
+
});
|
|
709
|
+
__publicField(this, "tokenizeConditionalExpression", (exp) => {
|
|
691
710
|
exp.traverse({
|
|
692
711
|
JSXElement: (el) => {
|
|
693
712
|
if (this.isTransComponent(el) || this.isChoiceComponent(el)) {
|
|
@@ -701,29 +720,29 @@ class MacroJSX {
|
|
|
701
720
|
name: this.expressionToArgument(exp),
|
|
702
721
|
value: exp.node
|
|
703
722
|
};
|
|
704
|
-
};
|
|
705
|
-
this
|
|
723
|
+
});
|
|
724
|
+
__publicField(this, "tokenizeText", (value) => {
|
|
706
725
|
return {
|
|
707
726
|
type: "text",
|
|
708
727
|
value
|
|
709
728
|
};
|
|
710
|
-
};
|
|
711
|
-
this
|
|
729
|
+
});
|
|
730
|
+
__publicField(this, "isLinguiComponent", (path, name) => {
|
|
712
731
|
return path.isJSXElement() && this.types.isJSXIdentifier(path.node.openingElement.name, {
|
|
713
732
|
name: this.nameMap.get(name) || name
|
|
714
733
|
});
|
|
715
|
-
};
|
|
716
|
-
this
|
|
734
|
+
});
|
|
735
|
+
__publicField(this, "isTransComponent", (path) => {
|
|
717
736
|
return this.isLinguiComponent(path, "Trans");
|
|
718
|
-
};
|
|
719
|
-
this
|
|
737
|
+
});
|
|
738
|
+
__publicField(this, "isChoiceComponent", (path) => {
|
|
720
739
|
return this.isLinguiComponent(path, "Plural") || this.isLinguiComponent(path, "Select") || this.isLinguiComponent(path, "SelectOrdinal");
|
|
721
|
-
};
|
|
722
|
-
this
|
|
740
|
+
});
|
|
741
|
+
__publicField(this, "getJsxTagName", (node) => {
|
|
723
742
|
if (this.types.isJSXIdentifier(node.openingElement.name)) {
|
|
724
743
|
return node.openingElement.name.name;
|
|
725
744
|
}
|
|
726
|
-
};
|
|
745
|
+
});
|
|
727
746
|
this.types = types;
|
|
728
747
|
this.stripNonEssentialProps = opts.stripNonEssentialProps;
|
|
729
748
|
this.nameMap = opts.nameMap;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lingui/macro",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.6.0",
|
|
4
4
|
"description": "Macro for generating messages in ICU MessageFormat syntax",
|
|
5
5
|
"main": "./dist/index.cjs",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
@@ -65,9 +65,9 @@
|
|
|
65
65
|
"dependencies": {
|
|
66
66
|
"@babel/runtime": "^7.20.13",
|
|
67
67
|
"@babel/types": "^7.20.7",
|
|
68
|
-
"@lingui/conf": "4.
|
|
69
|
-
"@lingui/core": "4.
|
|
70
|
-
"@lingui/message-utils": "4.
|
|
68
|
+
"@lingui/conf": "4.6.0",
|
|
69
|
+
"@lingui/core": "4.6.0",
|
|
70
|
+
"@lingui/message-utils": "4.6.0"
|
|
71
71
|
},
|
|
72
72
|
"peerDependencies": {
|
|
73
73
|
"@lingui/react": "^4.0.0",
|
|
@@ -80,7 +80,7 @@
|
|
|
80
80
|
"@types/babel-plugin-macros": "^2.8.5",
|
|
81
81
|
"prettier": "2.8.3",
|
|
82
82
|
"tsd": "^0.26.1",
|
|
83
|
-
"unbuild": "
|
|
83
|
+
"unbuild": "2.0.0"
|
|
84
84
|
},
|
|
85
|
-
"gitHead": "
|
|
85
|
+
"gitHead": "2afa0efb2d0cd1d47adc76e1eec9f5e57e34ae18"
|
|
86
86
|
}
|