@saykit/transform-js 0.7.0 → 0.8.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/parser.mjs +13 -5
- package/package.json +2 -2
package/dist/parser.mjs
CHANGED
|
@@ -6,16 +6,23 @@ function parseTaggedTemplateExpression(tagged) {
|
|
|
6
6
|
const processed = processExpression(tagged.tag);
|
|
7
7
|
if (!processed) return null;
|
|
8
8
|
const [accessor, descriptor] = processed;
|
|
9
|
-
const children = tagged.quasi
|
|
10
|
-
c.push(new LiteralMessage(q.value.cooked ?? q.value.raw));
|
|
11
|
-
if (t.isExpression(tagged.quasi.expressions[i])) c.push(parseExpression(tagged.quasi.expressions[i], true));
|
|
12
|
-
return c;
|
|
13
|
-
}, []);
|
|
9
|
+
const children = buildTemplateChildren(tagged.quasi);
|
|
14
10
|
return new CompositeMessage({
|
|
15
11
|
id: descriptor ? findPropertyValueIfStringLiteralAsString(descriptor, "id") : void 0,
|
|
16
12
|
context: descriptor ? findPropertyValueIfStringLiteralAsString(descriptor, "context") : void 0
|
|
17
13
|
}, getTranslatorComments(tagged.leadingComments ?? []), tagged.loc ? [`${tagged.loc.filename}:${tagged.loc.start.line}`] : [], children, accessor);
|
|
18
14
|
}
|
|
15
|
+
/**
|
|
16
|
+
* The text and the values of a template literal, in the order they were
|
|
17
|
+
* written — the message the template spells out.
|
|
18
|
+
*/
|
|
19
|
+
function buildTemplateChildren(template) {
|
|
20
|
+
return template.quasis.reduce((c, q, i) => {
|
|
21
|
+
c.push(new LiteralMessage(q.value.cooked ?? q.value.raw));
|
|
22
|
+
if (t.isExpression(template.expressions[i])) c.push(parseExpression(template.expressions[i], true));
|
|
23
|
+
return c;
|
|
24
|
+
}, []);
|
|
25
|
+
}
|
|
19
26
|
function parseCallExpression(call) {
|
|
20
27
|
const processed = processExpression(call.callee);
|
|
21
28
|
if (!processed) return null;
|
|
@@ -41,6 +48,7 @@ function parseCallExpression(call) {
|
|
|
41
48
|
if (offset !== void 0 && getPropertyNameAsString(p.key) === "offset") return c;
|
|
42
49
|
let message = null;
|
|
43
50
|
if (!message && t.isStringLiteral(p.value)) message = new LiteralMessage(p.value.value);
|
|
51
|
+
if (!message && t.isTemplateLiteral(p.value)) message = new CompositeMessage({}, [], [], buildTemplateChildren(p.value), p.value);
|
|
44
52
|
if (!message) message = parseExpression(p.value, true);
|
|
45
53
|
c.push({
|
|
46
54
|
identifier: getPropertyNameAsString(p.key),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@saykit/transform-js",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.0",
|
|
4
4
|
"description": "JavaScript and TypeScript transformer for SayKit",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"i18n",
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
"@babel/parser": "^7.29.7",
|
|
48
48
|
"@babel/traverse": "^7.29.7",
|
|
49
49
|
"@babel/types": "^7.29.7",
|
|
50
|
-
"@saykit/config": "^0.
|
|
50
|
+
"@saykit/config": "^0.8.0"
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
|
53
53
|
"@babel/core": "^7.29.7",
|