@lingui/macro 4.4.1 → 4.5.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 +66 -43
- 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 +66 -43
- 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;
|
|
@@ -403,6 +416,12 @@ class MacroJs {
|
|
|
403
416
|
}
|
|
404
417
|
}
|
|
405
418
|
|
|
419
|
+
var __defProp = Object.defineProperty;
|
|
420
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
421
|
+
var __publicField = (obj, key, value) => {
|
|
422
|
+
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
423
|
+
return value;
|
|
424
|
+
};
|
|
406
425
|
const pluralRuleRe = /(_[\d\w]+|zero|one|two|few|many|other)/;
|
|
407
426
|
const jsx2icuExactChoice = (value) => value.replace(/_(\d+)/, "=$1").replace(/_(\w+)/, "$1");
|
|
408
427
|
const keepSpaceRe = /\s*(?:\r\n|\r|\n)+\s*/g;
|
|
@@ -425,15 +444,19 @@ function normalizeWhitespace(text) {
|
|
|
425
444
|
}
|
|
426
445
|
class MacroJSX {
|
|
427
446
|
constructor({ types }, opts) {
|
|
428
|
-
this
|
|
429
|
-
this
|
|
430
|
-
this
|
|
447
|
+
__publicField(this, "types");
|
|
448
|
+
__publicField(this, "expressionIndex", makeCounter());
|
|
449
|
+
__publicField(this, "elementIndex", makeCounter());
|
|
450
|
+
__publicField(this, "stripNonEssentialProps");
|
|
451
|
+
__publicField(this, "nameMap");
|
|
452
|
+
__publicField(this, "nameMapReversed");
|
|
453
|
+
__publicField(this, "createStringJsxAttribute", (name, value) => {
|
|
431
454
|
return this.types.jsxAttribute(
|
|
432
455
|
this.types.jsxIdentifier(name),
|
|
433
456
|
this.types.jsxExpressionContainer(this.types.stringLiteral(value))
|
|
434
457
|
);
|
|
435
|
-
};
|
|
436
|
-
this
|
|
458
|
+
});
|
|
459
|
+
__publicField(this, "replacePath", (path) => {
|
|
437
460
|
if (!path.isJSXElement()) {
|
|
438
461
|
return path;
|
|
439
462
|
}
|
|
@@ -526,15 +549,15 @@ class MacroJSX {
|
|
|
526
549
|
);
|
|
527
550
|
newNode.loc = path.node.loc;
|
|
528
551
|
path.replaceWith(newNode);
|
|
529
|
-
};
|
|
530
|
-
this
|
|
552
|
+
});
|
|
553
|
+
__publicField(this, "attrName", (names, exclude = false) => {
|
|
531
554
|
const namesRe = new RegExp("^(" + names.join("|") + ")$");
|
|
532
555
|
return (attr) => {
|
|
533
556
|
const name = attr.name.name;
|
|
534
557
|
return exclude ? !namesRe.test(name) : namesRe.test(name);
|
|
535
558
|
};
|
|
536
|
-
};
|
|
537
|
-
this
|
|
559
|
+
});
|
|
560
|
+
__publicField(this, "stripMacroAttributes", (path) => {
|
|
538
561
|
const { attributes } = path.node.openingElement;
|
|
539
562
|
const id = attributes.find(this.attrName([ID]));
|
|
540
563
|
const message = attributes.find(this.attrName([MESSAGE]));
|
|
@@ -563,8 +586,8 @@ class MacroJSX {
|
|
|
563
586
|
context: maybeNodeValue(context),
|
|
564
587
|
attributes: attributes.filter(this.attrName(reserved, true))
|
|
565
588
|
};
|
|
566
|
-
};
|
|
567
|
-
this
|
|
589
|
+
});
|
|
590
|
+
__publicField(this, "tokenizeNode", (path) => {
|
|
568
591
|
if (this.isTransComponent(path)) {
|
|
569
592
|
return this.tokenizeTrans(path);
|
|
570
593
|
} else if (this.isChoiceComponent(path)) {
|
|
@@ -574,11 +597,11 @@ class MacroJSX {
|
|
|
574
597
|
} else {
|
|
575
598
|
return [this.tokenizeExpression(path)];
|
|
576
599
|
}
|
|
577
|
-
};
|
|
578
|
-
this
|
|
600
|
+
});
|
|
601
|
+
__publicField(this, "tokenizeTrans", (path) => {
|
|
579
602
|
return path.get("children").flatMap((child) => this.tokenizeChildren(child)).filter(Boolean);
|
|
580
|
-
};
|
|
581
|
-
this
|
|
603
|
+
});
|
|
604
|
+
__publicField(this, "tokenizeChildren", (path) => {
|
|
582
605
|
if (path.isJSXExpressionContainer()) {
|
|
583
606
|
const exp = path.get("expression");
|
|
584
607
|
if (exp.isStringLiteral()) {
|
|
@@ -599,8 +622,8 @@ class MacroJSX {
|
|
|
599
622
|
} else if (path.isJSXSpreadChild()) ; else if (path.isJSXText()) {
|
|
600
623
|
return [this.tokenizeText(path.node.value)];
|
|
601
624
|
} else ;
|
|
602
|
-
};
|
|
603
|
-
this
|
|
625
|
+
});
|
|
626
|
+
__publicField(this, "tokenizeChoiceComponent", (path) => {
|
|
604
627
|
const element = path.get("openingElement");
|
|
605
628
|
const name = this.getJsxTagName(path.node);
|
|
606
629
|
const format = (this.nameMapReversed.get(name) || name).toLowerCase();
|
|
@@ -665,8 +688,8 @@ class MacroJSX {
|
|
|
665
688
|
}
|
|
666
689
|
}
|
|
667
690
|
return token;
|
|
668
|
-
};
|
|
669
|
-
this
|
|
691
|
+
});
|
|
692
|
+
__publicField(this, "tokenizeElement", (path) => {
|
|
670
693
|
const name = this.elementIndex();
|
|
671
694
|
return {
|
|
672
695
|
type: "element",
|
|
@@ -681,15 +704,15 @@ class MacroJSX {
|
|
|
681
704
|
},
|
|
682
705
|
children: this.tokenizeTrans(path)
|
|
683
706
|
};
|
|
684
|
-
};
|
|
685
|
-
this
|
|
707
|
+
});
|
|
708
|
+
__publicField(this, "tokenizeExpression", (path) => {
|
|
686
709
|
return {
|
|
687
710
|
type: "arg",
|
|
688
711
|
name: this.expressionToArgument(path),
|
|
689
712
|
value: path.node
|
|
690
713
|
};
|
|
691
|
-
};
|
|
692
|
-
this
|
|
714
|
+
});
|
|
715
|
+
__publicField(this, "tokenizeConditionalExpression", (exp) => {
|
|
693
716
|
exp.traverse({
|
|
694
717
|
JSXElement: (el) => {
|
|
695
718
|
if (this.isTransComponent(el) || this.isChoiceComponent(el)) {
|
|
@@ -703,29 +726,29 @@ class MacroJSX {
|
|
|
703
726
|
name: this.expressionToArgument(exp),
|
|
704
727
|
value: exp.node
|
|
705
728
|
};
|
|
706
|
-
};
|
|
707
|
-
this
|
|
729
|
+
});
|
|
730
|
+
__publicField(this, "tokenizeText", (value) => {
|
|
708
731
|
return {
|
|
709
732
|
type: "text",
|
|
710
733
|
value
|
|
711
734
|
};
|
|
712
|
-
};
|
|
713
|
-
this
|
|
735
|
+
});
|
|
736
|
+
__publicField(this, "isLinguiComponent", (path, name) => {
|
|
714
737
|
return path.isJSXElement() && this.types.isJSXIdentifier(path.node.openingElement.name, {
|
|
715
738
|
name: this.nameMap.get(name) || name
|
|
716
739
|
});
|
|
717
|
-
};
|
|
718
|
-
this
|
|
740
|
+
});
|
|
741
|
+
__publicField(this, "isTransComponent", (path) => {
|
|
719
742
|
return this.isLinguiComponent(path, "Trans");
|
|
720
|
-
};
|
|
721
|
-
this
|
|
743
|
+
});
|
|
744
|
+
__publicField(this, "isChoiceComponent", (path) => {
|
|
722
745
|
return this.isLinguiComponent(path, "Plural") || this.isLinguiComponent(path, "Select") || this.isLinguiComponent(path, "SelectOrdinal");
|
|
723
|
-
};
|
|
724
|
-
this
|
|
746
|
+
});
|
|
747
|
+
__publicField(this, "getJsxTagName", (node) => {
|
|
725
748
|
if (this.types.isJSXIdentifier(node.openingElement.name)) {
|
|
726
749
|
return node.openingElement.name.name;
|
|
727
750
|
}
|
|
728
|
-
};
|
|
751
|
+
});
|
|
729
752
|
this.types = types;
|
|
730
753
|
this.stripNonEssentialProps = opts.stripNonEssentialProps;
|
|
731
754
|
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;
|
|
@@ -401,6 +414,12 @@ class MacroJs {
|
|
|
401
414
|
}
|
|
402
415
|
}
|
|
403
416
|
|
|
417
|
+
var __defProp = Object.defineProperty;
|
|
418
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
419
|
+
var __publicField = (obj, key, value) => {
|
|
420
|
+
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
421
|
+
return value;
|
|
422
|
+
};
|
|
404
423
|
const pluralRuleRe = /(_[\d\w]+|zero|one|two|few|many|other)/;
|
|
405
424
|
const jsx2icuExactChoice = (value) => value.replace(/_(\d+)/, "=$1").replace(/_(\w+)/, "$1");
|
|
406
425
|
const keepSpaceRe = /\s*(?:\r\n|\r|\n)+\s*/g;
|
|
@@ -423,15 +442,19 @@ function normalizeWhitespace(text) {
|
|
|
423
442
|
}
|
|
424
443
|
class MacroJSX {
|
|
425
444
|
constructor({ types }, opts) {
|
|
426
|
-
this
|
|
427
|
-
this
|
|
428
|
-
this
|
|
445
|
+
__publicField(this, "types");
|
|
446
|
+
__publicField(this, "expressionIndex", makeCounter());
|
|
447
|
+
__publicField(this, "elementIndex", makeCounter());
|
|
448
|
+
__publicField(this, "stripNonEssentialProps");
|
|
449
|
+
__publicField(this, "nameMap");
|
|
450
|
+
__publicField(this, "nameMapReversed");
|
|
451
|
+
__publicField(this, "createStringJsxAttribute", (name, value) => {
|
|
429
452
|
return this.types.jsxAttribute(
|
|
430
453
|
this.types.jsxIdentifier(name),
|
|
431
454
|
this.types.jsxExpressionContainer(this.types.stringLiteral(value))
|
|
432
455
|
);
|
|
433
|
-
};
|
|
434
|
-
this
|
|
456
|
+
});
|
|
457
|
+
__publicField(this, "replacePath", (path) => {
|
|
435
458
|
if (!path.isJSXElement()) {
|
|
436
459
|
return path;
|
|
437
460
|
}
|
|
@@ -524,15 +547,15 @@ class MacroJSX {
|
|
|
524
547
|
);
|
|
525
548
|
newNode.loc = path.node.loc;
|
|
526
549
|
path.replaceWith(newNode);
|
|
527
|
-
};
|
|
528
|
-
this
|
|
550
|
+
});
|
|
551
|
+
__publicField(this, "attrName", (names, exclude = false) => {
|
|
529
552
|
const namesRe = new RegExp("^(" + names.join("|") + ")$");
|
|
530
553
|
return (attr) => {
|
|
531
554
|
const name = attr.name.name;
|
|
532
555
|
return exclude ? !namesRe.test(name) : namesRe.test(name);
|
|
533
556
|
};
|
|
534
|
-
};
|
|
535
|
-
this
|
|
557
|
+
});
|
|
558
|
+
__publicField(this, "stripMacroAttributes", (path) => {
|
|
536
559
|
const { attributes } = path.node.openingElement;
|
|
537
560
|
const id = attributes.find(this.attrName([ID]));
|
|
538
561
|
const message = attributes.find(this.attrName([MESSAGE]));
|
|
@@ -561,8 +584,8 @@ class MacroJSX {
|
|
|
561
584
|
context: maybeNodeValue(context),
|
|
562
585
|
attributes: attributes.filter(this.attrName(reserved, true))
|
|
563
586
|
};
|
|
564
|
-
};
|
|
565
|
-
this
|
|
587
|
+
});
|
|
588
|
+
__publicField(this, "tokenizeNode", (path) => {
|
|
566
589
|
if (this.isTransComponent(path)) {
|
|
567
590
|
return this.tokenizeTrans(path);
|
|
568
591
|
} else if (this.isChoiceComponent(path)) {
|
|
@@ -572,11 +595,11 @@ class MacroJSX {
|
|
|
572
595
|
} else {
|
|
573
596
|
return [this.tokenizeExpression(path)];
|
|
574
597
|
}
|
|
575
|
-
};
|
|
576
|
-
this
|
|
598
|
+
});
|
|
599
|
+
__publicField(this, "tokenizeTrans", (path) => {
|
|
577
600
|
return path.get("children").flatMap((child) => this.tokenizeChildren(child)).filter(Boolean);
|
|
578
|
-
};
|
|
579
|
-
this
|
|
601
|
+
});
|
|
602
|
+
__publicField(this, "tokenizeChildren", (path) => {
|
|
580
603
|
if (path.isJSXExpressionContainer()) {
|
|
581
604
|
const exp = path.get("expression");
|
|
582
605
|
if (exp.isStringLiteral()) {
|
|
@@ -597,8 +620,8 @@ class MacroJSX {
|
|
|
597
620
|
} else if (path.isJSXSpreadChild()) ; else if (path.isJSXText()) {
|
|
598
621
|
return [this.tokenizeText(path.node.value)];
|
|
599
622
|
} else ;
|
|
600
|
-
};
|
|
601
|
-
this
|
|
623
|
+
});
|
|
624
|
+
__publicField(this, "tokenizeChoiceComponent", (path) => {
|
|
602
625
|
const element = path.get("openingElement");
|
|
603
626
|
const name = this.getJsxTagName(path.node);
|
|
604
627
|
const format = (this.nameMapReversed.get(name) || name).toLowerCase();
|
|
@@ -663,8 +686,8 @@ class MacroJSX {
|
|
|
663
686
|
}
|
|
664
687
|
}
|
|
665
688
|
return token;
|
|
666
|
-
};
|
|
667
|
-
this
|
|
689
|
+
});
|
|
690
|
+
__publicField(this, "tokenizeElement", (path) => {
|
|
668
691
|
const name = this.elementIndex();
|
|
669
692
|
return {
|
|
670
693
|
type: "element",
|
|
@@ -679,15 +702,15 @@ class MacroJSX {
|
|
|
679
702
|
},
|
|
680
703
|
children: this.tokenizeTrans(path)
|
|
681
704
|
};
|
|
682
|
-
};
|
|
683
|
-
this
|
|
705
|
+
});
|
|
706
|
+
__publicField(this, "tokenizeExpression", (path) => {
|
|
684
707
|
return {
|
|
685
708
|
type: "arg",
|
|
686
709
|
name: this.expressionToArgument(path),
|
|
687
710
|
value: path.node
|
|
688
711
|
};
|
|
689
|
-
};
|
|
690
|
-
this
|
|
712
|
+
});
|
|
713
|
+
__publicField(this, "tokenizeConditionalExpression", (exp) => {
|
|
691
714
|
exp.traverse({
|
|
692
715
|
JSXElement: (el) => {
|
|
693
716
|
if (this.isTransComponent(el) || this.isChoiceComponent(el)) {
|
|
@@ -701,29 +724,29 @@ class MacroJSX {
|
|
|
701
724
|
name: this.expressionToArgument(exp),
|
|
702
725
|
value: exp.node
|
|
703
726
|
};
|
|
704
|
-
};
|
|
705
|
-
this
|
|
727
|
+
});
|
|
728
|
+
__publicField(this, "tokenizeText", (value) => {
|
|
706
729
|
return {
|
|
707
730
|
type: "text",
|
|
708
731
|
value
|
|
709
732
|
};
|
|
710
|
-
};
|
|
711
|
-
this
|
|
733
|
+
});
|
|
734
|
+
__publicField(this, "isLinguiComponent", (path, name) => {
|
|
712
735
|
return path.isJSXElement() && this.types.isJSXIdentifier(path.node.openingElement.name, {
|
|
713
736
|
name: this.nameMap.get(name) || name
|
|
714
737
|
});
|
|
715
|
-
};
|
|
716
|
-
this
|
|
738
|
+
});
|
|
739
|
+
__publicField(this, "isTransComponent", (path) => {
|
|
717
740
|
return this.isLinguiComponent(path, "Trans");
|
|
718
|
-
};
|
|
719
|
-
this
|
|
741
|
+
});
|
|
742
|
+
__publicField(this, "isChoiceComponent", (path) => {
|
|
720
743
|
return this.isLinguiComponent(path, "Plural") || this.isLinguiComponent(path, "Select") || this.isLinguiComponent(path, "SelectOrdinal");
|
|
721
|
-
};
|
|
722
|
-
this
|
|
744
|
+
});
|
|
745
|
+
__publicField(this, "getJsxTagName", (node) => {
|
|
723
746
|
if (this.types.isJSXIdentifier(node.openingElement.name)) {
|
|
724
747
|
return node.openingElement.name.name;
|
|
725
748
|
}
|
|
726
|
-
};
|
|
749
|
+
});
|
|
727
750
|
this.types = types;
|
|
728
751
|
this.stripNonEssentialProps = opts.stripNonEssentialProps;
|
|
729
752
|
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.5.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.5.0",
|
|
69
|
+
"@lingui/core": "4.5.0",
|
|
70
|
+
"@lingui/message-utils": "4.5.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": "62c92d1f8c60b3890bdda870f307fa780d423080"
|
|
86
86
|
}
|