@generaltranslation/compiler 1.1.33 → 1.1.34
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/passes/macroExpansionPass.d.ts.map +1 -1
- package/dist/passes/macroExpansionPass.js +0 -2
- package/dist/passes/macroExpansionPass.js.map +1 -1
- package/package.json +1 -1
- package/dist/processing/macro-expansion/processCallExpression.d.ts +0 -13
- package/dist/processing/macro-expansion/processCallExpression.d.ts.map +0 -1
- package/dist/processing/macro-expansion/processCallExpression.js +0 -101
- package/dist/processing/macro-expansion/processCallExpression.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"macroExpansionPass.d.ts","sourceRoot":"","sources":["../../src/passes/macroExpansionPass.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAKhD;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,cAAc,GAAG,eAAe,
|
|
1
|
+
{"version":3,"file":"macroExpansionPass.d.ts","sourceRoot":"","sources":["../../src/passes/macroExpansionPass.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAKhD;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,cAAc,GAAG,eAAe,CAiBzE"}
|
|
@@ -20,8 +20,6 @@ function macroExpansionPass(state) {
|
|
|
20
20
|
return {
|
|
21
21
|
ImportDeclaration: (0, processImportDeclaration_1.processImportDeclaration)(onImportFound),
|
|
22
22
|
TaggedTemplateExpression: (0, processTaggedTemplateExpression_1.processTaggedTemplateExpression)(state),
|
|
23
|
-
// Disabling this to be re-enabled at stage 4
|
|
24
|
-
// CallExpression: processCallExpression(state),
|
|
25
23
|
Program: (0, processProgram_1.processProgram)({
|
|
26
24
|
state,
|
|
27
25
|
countBefore,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"macroExpansionPass.js","sourceRoot":"","sources":["../../src/passes/macroExpansionPass.ts"],"names":[],"mappings":";;AAaA,
|
|
1
|
+
{"version":3,"file":"macroExpansionPass.js","sourceRoot":"","sources":["../../src/passes/macroExpansionPass.ts"],"names":[],"mappings":";;AAaA,gDAiBC;AA5BD,mHAAgH;AAChH,qGAAkG;AAClG,iFAA8E;AAE9E;;;;;;GAMG;AACH,SAAgB,kBAAkB,CAAC,KAAqB;IACtD,IAAI,eAAe,GAAG,KAAK,CAAC;IAC5B,MAAM,WAAW,GAAG,KAAK,CAAC,UAAU,CAAC,oBAAoB,CAAC;IAE1D,MAAM,aAAa,GAAG,GAAG,EAAE;QACzB,eAAe,GAAG,IAAI,CAAC;IACzB,CAAC,CAAC;IAEF,OAAO;QACL,iBAAiB,EAAE,IAAA,mDAAwB,EAAC,aAAa,CAAC;QAC1D,wBAAwB,EAAE,IAAA,iEAA+B,EAAC,KAAK,CAAC;QAChE,OAAO,EAAE,IAAA,+BAAc,EAAC;YACtB,KAAK;YACL,WAAW;YACX,iBAAiB,EAAE,GAAG,EAAE,CAAC,eAAe;SACzC,CAAC;KACH,CAAC;AACJ,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { VisitNode } from '@babel/traverse';
|
|
2
|
-
import * as t from '@babel/types';
|
|
3
|
-
import { TransformState } from '../../state/types';
|
|
4
|
-
/**
|
|
5
|
-
* Process call expressions for macro expansion.
|
|
6
|
-
* Transforms:
|
|
7
|
-
* - t(`Hello, ${name}`) → t("Hello, {0}", { "0": name })
|
|
8
|
-
* - t("Hello, " + name) → t("Hello, {0}", { "0": name })
|
|
9
|
-
*
|
|
10
|
-
* Skips when t is bound to a non-GT import (e.g., i18next)
|
|
11
|
-
*/
|
|
12
|
-
export declare function processCallExpression(state: TransformState): VisitNode<t.Node, t.CallExpression>;
|
|
13
|
-
//# sourceMappingURL=processCallExpression.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"processCallExpression.d.ts","sourceRoot":"","sources":["../../../src/processing/macro-expansion/processCallExpression.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACtD,OAAO,KAAK,CAAC,MAAM,cAAc,CAAC;AAClC,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAKnD;;;;;;;GAOG;AACH,wBAAgB,qBAAqB,CACnC,KAAK,EAAE,cAAc,GACpB,SAAS,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,cAAc,CAAC,CA+CrC"}
|
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.processCallExpression = processCallExpression;
|
|
37
|
-
const t = __importStar(require("@babel/types"));
|
|
38
|
-
const transformTemplateLiteral_1 = require("../../transform/macro-expansion/transformTemplateLiteral");
|
|
39
|
-
const transformConcatenation_1 = require("../../transform/macro-expansion/transformConcatenation");
|
|
40
|
-
const constants_1 = require("../../utils/constants/gt/constants");
|
|
41
|
-
/**
|
|
42
|
-
* Process call expressions for macro expansion.
|
|
43
|
-
* Transforms:
|
|
44
|
-
* - t(`Hello, ${name}`) → t("Hello, {0}", { "0": name })
|
|
45
|
-
* - t("Hello, " + name) → t("Hello, {0}", { "0": name })
|
|
46
|
-
*
|
|
47
|
-
* Skips when t is bound to a non-GT import (e.g., i18next)
|
|
48
|
-
*/
|
|
49
|
-
function processCallExpression(state) {
|
|
50
|
-
const symbol = state.settings.stringTranslationMacro;
|
|
51
|
-
return (path) => {
|
|
52
|
-
var _a;
|
|
53
|
-
if (!t.isIdentifier(path.node.callee, { name: symbol }))
|
|
54
|
-
return;
|
|
55
|
-
// Only transform unbound t (global macro) or t imported from a GT source
|
|
56
|
-
const binding = path.scope.getBinding(symbol);
|
|
57
|
-
if (binding) {
|
|
58
|
-
if (!binding.path.isImportSpecifier())
|
|
59
|
-
return;
|
|
60
|
-
const importDecl = binding.path.parentPath;
|
|
61
|
-
if ((importDecl === null || importDecl === void 0 ? void 0 : importDecl.isImportDeclaration()) &&
|
|
62
|
-
importDecl.node.source.value !== constants_1.GT_IMPORT_SOURCES.GT_REACT_BROWSER) {
|
|
63
|
-
return;
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
const firstArg = path.node.arguments[0];
|
|
67
|
-
if (!firstArg)
|
|
68
|
-
return;
|
|
69
|
-
const firstArgPath = (_a = path.get('arguments')) === null || _a === void 0 ? void 0 : _a[0];
|
|
70
|
-
if (state.settings.enableTemplateLiteralArg &&
|
|
71
|
-
t.isTemplateLiteral(firstArg)) {
|
|
72
|
-
const { message, variables } = (0, transformTemplateLiteral_1.transformTemplateLiteral)(firstArgPath);
|
|
73
|
-
path.node.arguments[0] = message;
|
|
74
|
-
if (variables) {
|
|
75
|
-
mergeVariables(path.node.arguments, variables);
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
else if (state.settings.enableConcatenationArg &&
|
|
79
|
-
t.isBinaryExpression(firstArg, { operator: '+' })) {
|
|
80
|
-
const { message, variables } = (0, transformConcatenation_1.transformConcatenation)(firstArgPath);
|
|
81
|
-
path.node.arguments[0] = message;
|
|
82
|
-
if (variables) {
|
|
83
|
-
mergeVariables(path.node.arguments, variables);
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
};
|
|
87
|
-
}
|
|
88
|
-
/**
|
|
89
|
-
* Merge extracted variables into the call arguments.
|
|
90
|
-
* If the second argument is already an ObjectExpression, append properties to it.
|
|
91
|
-
* Otherwise, insert the variables object as the second argument.
|
|
92
|
-
*/
|
|
93
|
-
function mergeVariables(args, variables) {
|
|
94
|
-
if (args.length > 1 && t.isObjectExpression(args[1])) {
|
|
95
|
-
args[1].properties.push(...variables.properties);
|
|
96
|
-
}
|
|
97
|
-
else {
|
|
98
|
-
args.splice(1, 0, variables);
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
//# sourceMappingURL=processCallExpression.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"processCallExpression.js","sourceRoot":"","sources":["../../../src/processing/macro-expansion/processCallExpression.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAeA,sDAiDC;AA/DD,gDAAkC;AAElC,uGAAoG;AACpG,mGAAgG;AAChG,kEAAuE;AAEvE;;;;;;;GAOG;AACH,SAAgB,qBAAqB,CACnC,KAAqB;IAErB,MAAM,MAAM,GAAG,KAAK,CAAC,QAAQ,CAAC,sBAAsB,CAAC;IAErD,OAAO,CAAC,IAAI,EAAE,EAAE;;QACd,IAAI,CAAC,CAAC,CAAC,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;YAAE,OAAO;QAEhE,yEAAyE;QACzE,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC;QAC9C,IAAI,OAAO,EAAE,CAAC;YACZ,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,iBAAiB,EAAE;gBAAE,OAAO;YAC9C,MAAM,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC,UAAU,CAAC;YAC3C,IACE,CAAA,UAAU,aAAV,UAAU,uBAAV,UAAU,CAAE,mBAAmB,EAAE;gBACjC,UAAU,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,KAAK,6BAAiB,CAAC,gBAAgB,EACnE,CAAC;gBACD,OAAO;YACT,CAAC;QACH,CAAC;QAED,MAAM,QAAQ,GAAG,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;QACxC,IAAI,CAAC,QAAQ;YAAE,OAAO;QACtB,MAAM,YAAY,GAAG,MAAA,IAAI,CAAC,GAAG,CAAC,WAAW,CAAC,0CAAG,CAAC,CAAC,CAAC;QAEhD,IACE,KAAK,CAAC,QAAQ,CAAC,wBAAwB;YACvC,CAAC,CAAC,iBAAiB,CAAC,QAAQ,CAAC,EAC7B,CAAC;YAC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