@generaltranslation/compiler 1.2.1 → 1.3.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/config.d.ts +23 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +26 -4
- package/dist/index.js.map +1 -1
- package/dist/passes/jsxInsertionPass.d.ts +11 -0
- package/dist/passes/jsxInsertionPass.d.ts.map +1 -0
- package/dist/passes/jsxInsertionPass.js +35 -0
- package/dist/passes/jsxInsertionPass.js.map +1 -0
- package/dist/processing/collection/processCallExpression.js +4 -0
- package/dist/processing/collection/processCallExpression.js.map +1 -1
- package/dist/processing/jsx-insertion/processCallExpression.d.ts +13 -0
- package/dist/processing/jsx-insertion/processCallExpression.d.ts.map +1 -0
- package/dist/processing/jsx-insertion/processCallExpression.js +424 -0
- package/dist/processing/jsx-insertion/processCallExpression.js.map +1 -0
- package/dist/processing/jsx-insertion/processImportDeclaration.d.ts +20 -0
- package/dist/processing/jsx-insertion/processImportDeclaration.d.ts.map +1 -0
- package/dist/processing/jsx-insertion/processImportDeclaration.js +87 -0
- package/dist/processing/jsx-insertion/processImportDeclaration.js.map +1 -0
- package/dist/processing/jsx-insertion/processProgram.d.ts +18 -0
- package/dist/processing/jsx-insertion/processProgram.d.ts.map +1 -0
- package/dist/processing/jsx-insertion/processProgram.js +69 -0
- package/dist/processing/jsx-insertion/processProgram.js.map +1 -0
- package/dist/state/types.d.ts +3 -0
- package/dist/state/types.d.ts.map +1 -1
- package/dist/state/utils/initializeState.d.ts.map +1 -1
- package/dist/state/utils/initializeState.js +19 -13
- package/dist/state/utils/initializeState.js.map +1 -1
- package/dist/transform/jsx-children/constructJsxChildren.d.ts.map +1 -1
- package/dist/transform/jsx-children/constructJsxChildren.js +11 -1
- package/dist/transform/jsx-children/constructJsxChildren.js.map +1 -1
- package/dist/transform/jsx-insertion/injectJsxInsertionImport.d.ts +8 -0
- package/dist/transform/jsx-insertion/injectJsxInsertionImport.d.ts.map +1 -0
- package/dist/transform/jsx-insertion/injectJsxInsertionImport.js +52 -0
- package/dist/transform/jsx-insertion/injectJsxInsertionImport.js.map +1 -0
- package/dist/transform/validation/validateTranslationComponentArgs.d.ts.map +1 -1
- package/dist/transform/validation/validateTranslationComponentArgs.js +1 -0
- package/dist/transform/validation/validateTranslationComponentArgs.js.map +1 -1
- package/dist/utils/constants/gt/constants.d.ts +21 -1
- package/dist/utils/constants/gt/constants.d.ts.map +1 -1
- package/dist/utils/constants/gt/constants.js +21 -1
- package/dist/utils/constants/gt/constants.js.map +1 -1
- package/dist/utils/constants/gt/helpers.d.ts +4 -0
- package/dist/utils/constants/gt/helpers.d.ts.map +1 -1
- package/dist/utils/constants/gt/helpers.js +17 -3
- package/dist/utils/constants/gt/helpers.js.map +1 -1
- package/dist/utils/constants/resolveIdentifier/isGTComponent.d.ts +17 -0
- package/dist/utils/constants/resolveIdentifier/isGTComponent.d.ts.map +1 -0
- package/dist/utils/constants/resolveIdentifier/isGTComponent.js +92 -0
- package/dist/utils/constants/resolveIdentifier/isGTComponent.js.map +1 -0
- package/dist/utils/constants/resolveIdentifier/isReactJsxFunction.d.ts +10 -0
- package/dist/utils/constants/resolveIdentifier/isReactJsxFunction.d.ts.map +1 -0
- package/dist/utils/constants/resolveIdentifier/isReactJsxFunction.js +93 -0
- package/dist/utils/constants/resolveIdentifier/isReactJsxFunction.js.map +1 -0
- package/package.json +2 -2
|
@@ -0,0 +1,424 @@
|
|
|
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 constants_1 = require("../../utils/constants/gt/constants");
|
|
39
|
+
const constants_2 = require("../../utils/constants/other/constants");
|
|
40
|
+
const constants_3 = require("../../utils/constants/react/constants");
|
|
41
|
+
const isReactJsxFunction_1 = require("../../utils/constants/resolveIdentifier/isReactJsxFunction");
|
|
42
|
+
const isGTComponent_1 = require("../../utils/constants/resolveIdentifier/isGTComponent");
|
|
43
|
+
/**
|
|
44
|
+
* Babel visitor entry point for the JSX insertion pass.
|
|
45
|
+
*
|
|
46
|
+
* All internal functions use NodePath-based traversal via .get() so that
|
|
47
|
+
* Babel binding lookups (scope.getBinding) work correctly at every depth.
|
|
48
|
+
* This handles aliased imports like `import { jsxDEV as _jsxDEV }`.
|
|
49
|
+
*/
|
|
50
|
+
function processCallExpression(state, calleeInfo) {
|
|
51
|
+
const jsxState = Object.assign(Object.assign({}, state), { processedNodes: new WeakSet(), calleeInfo, insideUserVarDepth: 0 });
|
|
52
|
+
return {
|
|
53
|
+
enter: (path) => {
|
|
54
|
+
// Check jsx callee first — needed for both user Var detection and processing
|
|
55
|
+
const calleePath = path.get('callee');
|
|
56
|
+
if ((!calleePath.isIdentifier() && !calleePath.isMemberExpression()) ||
|
|
57
|
+
!(0, isReactJsxFunction_1.isReactJsxFunction)(calleePath)) {
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
// Check if this is a user Var/Num/Currency/DateTime — suppress transforms inside.
|
|
61
|
+
// This must happen BEFORE the processedNodes check, because user T's
|
|
62
|
+
// markDescendantJsxCalls may have already added the Var call to processedNodes,
|
|
63
|
+
// but we still need to increment the depth counter so children are suppressed.
|
|
64
|
+
const firstArg = path.get('arguments')[0];
|
|
65
|
+
if ((firstArg === null || firstArg === void 0 ? void 0 : firstArg.isExpression()) && (0, isGTComponent_1.isUserVariableComponent)(firstArg)) {
|
|
66
|
+
jsxState.insideUserVarDepth++;
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
// Skip all processing when inside a user variable component
|
|
70
|
+
if (jsxState.insideUserVarDepth > 0)
|
|
71
|
+
return;
|
|
72
|
+
if (jsxState.processedNodes.has(path.node))
|
|
73
|
+
return;
|
|
74
|
+
processJsxNode({ path, insideAutoT: false, state: jsxState });
|
|
75
|
+
},
|
|
76
|
+
exit: (path) => {
|
|
77
|
+
// Decrement depth when exiting a user Var/Num/Currency/DateTime
|
|
78
|
+
const calleePath = path.get('callee');
|
|
79
|
+
if ((!calleePath.isIdentifier() && !calleePath.isMemberExpression()) ||
|
|
80
|
+
!(0, isReactJsxFunction_1.isReactJsxFunction)(calleePath)) {
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
const firstArg = path.get('arguments')[0];
|
|
84
|
+
if ((firstArg === null || firstArg === void 0 ? void 0 : firstArg.isExpression()) && (0, isGTComponent_1.isUserVariableComponent)(firstArg)) {
|
|
85
|
+
jsxState.insideUserVarDepth--;
|
|
86
|
+
}
|
|
87
|
+
},
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
// ===== Core recursive function =====
|
|
91
|
+
function processJsxNode({ path, insideAutoT, state, }) {
|
|
92
|
+
var _a, _b;
|
|
93
|
+
state.processedNodes.add(path.node);
|
|
94
|
+
const firstArgPath = path.get('arguments')[0];
|
|
95
|
+
if (!(firstArgPath === null || firstArgPath === void 0 ? void 0 : firstArgPath.isExpression()))
|
|
96
|
+
return;
|
|
97
|
+
// User T → mark all descendant jsx calls as processed, hands off
|
|
98
|
+
if ((0, isGTComponent_1.isUserTranslationComponent)(firstArgPath)) {
|
|
99
|
+
markDescendantJsxCalls({ jsxCallPath: path, state });
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
// User Var/Num/Currency/DateTime → mark descendants, hands off
|
|
103
|
+
if ((0, isGTComponent_1.isUserVariableComponent)(firstArgPath)) {
|
|
104
|
+
markDescendantJsxCalls({ jsxCallPath: path, state });
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
// Already auto-inserted → skip
|
|
108
|
+
const gtName = (0, isGTComponent_1.resolveFirstArgGTName)(firstArgPath);
|
|
109
|
+
if (gtName === constants_1.GT_COMPONENT_TYPES.GtInternalTranslateJsx ||
|
|
110
|
+
gtName === constants_1.GT_COMPONENT_TYPES.GtInternalVar) {
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
// Branch/Plural/Derive/Static → opaque for static JSX, dynamic props get _Var
|
|
114
|
+
if ((0, isGTComponent_1.isGTBranchComponent)(firstArgPath) || (0, isGTComponent_1.isGTDeriveComponent)(firstArgPath)) {
|
|
115
|
+
// Process props BEFORE wrapping — path still points to the opaque component
|
|
116
|
+
processOpaqueComponentProps({
|
|
117
|
+
jsxCallPath: path,
|
|
118
|
+
insideAutoT: !insideAutoT ? true : insideAutoT,
|
|
119
|
+
state,
|
|
120
|
+
});
|
|
121
|
+
if (!insideAutoT) {
|
|
122
|
+
// Root-level opaque component — wrap in _T (single child → use singleCallee)
|
|
123
|
+
const callee = (_b = (_a = state.calleeInfo.singleCallee) !== null && _a !== void 0 ? _a : state.calleeInfo.multiCallee) !== null && _b !== void 0 ? _b : constants_3.REACT_FUNTIONS.jsx;
|
|
124
|
+
const tWrapped = wrapInT(path.node, t.identifier(callee), state.calleeInfo);
|
|
125
|
+
state.processedNodes.add(tWrapped);
|
|
126
|
+
path.replaceWith(tWrapped);
|
|
127
|
+
state.statistics.jsxInsertionsCount++;
|
|
128
|
+
}
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
// --- Get children prop path ---
|
|
132
|
+
const childrenPropPath = getChildrenPropPath(path);
|
|
133
|
+
if (!childrenPropPath)
|
|
134
|
+
return;
|
|
135
|
+
const childrenPath = childrenPropPath.get('value');
|
|
136
|
+
if (!childrenPath.isExpression())
|
|
137
|
+
return;
|
|
138
|
+
// --- Determine if this level should claim T ---
|
|
139
|
+
const shouldClaimT = !insideAutoT &&
|
|
140
|
+
(hasNonWhitespaceText(childrenPath) || hasOpaqueGTChild(childrenPath));
|
|
141
|
+
if (shouldClaimT) {
|
|
142
|
+
processChildren({ childrenPath, insideAutoT: true, state });
|
|
143
|
+
const currentChildren = childrenPropPath.get('value').node;
|
|
144
|
+
const tCallee = t.isArrayExpression(currentChildren)
|
|
145
|
+
? state.calleeInfo.multiCallee
|
|
146
|
+
: state.calleeInfo.singleCallee;
|
|
147
|
+
const tWrapped = wrapInT(currentChildren, t.identifier(tCallee !== null && tCallee !== void 0 ? tCallee : 'jsx'), state.calleeInfo);
|
|
148
|
+
state.processedNodes.add(tWrapped);
|
|
149
|
+
childrenPropPath.get('value').replaceWith(tWrapped);
|
|
150
|
+
updateCalleeToSingle({ jsxCallPath: path, state });
|
|
151
|
+
state.statistics.jsxInsertionsCount++;
|
|
152
|
+
}
|
|
153
|
+
else if (insideAutoT) {
|
|
154
|
+
processChildren({ childrenPath, insideAutoT: true, state });
|
|
155
|
+
}
|
|
156
|
+
else {
|
|
157
|
+
recurseChildJsxCalls({ childrenPath, insideAutoT: false, state });
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
// ===== Children processing ===== //
|
|
161
|
+
function processChildren({ childrenPath, insideAutoT, state, }) {
|
|
162
|
+
if (childrenPath.isArrayExpression()) {
|
|
163
|
+
for (const elPath of childrenPath.get('elements')) {
|
|
164
|
+
if (elPath.isExpression()) {
|
|
165
|
+
processSingleChild({ childPath: elPath, insideAutoT, state });
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
processSingleChild({ childPath: childrenPath, insideAutoT, state });
|
|
171
|
+
}
|
|
172
|
+
function processSingleChild({ childPath, insideAutoT, state, }) {
|
|
173
|
+
var _a;
|
|
174
|
+
if (childPath.isCallExpression() && isJsxCallPath(childPath)) {
|
|
175
|
+
processJsxNode({ path: childPath, insideAutoT, state });
|
|
176
|
+
return;
|
|
177
|
+
}
|
|
178
|
+
// _Var always has a single child → use singleCallee
|
|
179
|
+
if (insideAutoT && needsVarWrapping(childPath)) {
|
|
180
|
+
const callee = (_a = state.calleeInfo.singleCallee) !== null && _a !== void 0 ? _a : constants_3.REACT_FUNTIONS.jsx;
|
|
181
|
+
const wrapped = wrapInVar(childPath.node, t.identifier(callee), state.calleeInfo);
|
|
182
|
+
state.processedNodes.add(wrapped);
|
|
183
|
+
childPath.replaceWith(wrapped);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
function recurseChildJsxCalls({ childrenPath, insideAutoT, state, }) {
|
|
187
|
+
if (childrenPath.isArrayExpression()) {
|
|
188
|
+
for (const elPath of childrenPath.get('elements')) {
|
|
189
|
+
if (elPath.isCallExpression() && isJsxCallPath(elPath)) {
|
|
190
|
+
processJsxNode({ path: elPath, insideAutoT, state });
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
else if (childrenPath.isCallExpression() && isJsxCallPath(childrenPath)) {
|
|
195
|
+
processJsxNode({ path: childrenPath, insideAutoT, state });
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
// ===== Helper functions =====
|
|
199
|
+
function getChildrenPropPath(jsxCallPath) {
|
|
200
|
+
const args = jsxCallPath.get('arguments');
|
|
201
|
+
const propsArg = args[1];
|
|
202
|
+
if (!(propsArg === null || propsArg === void 0 ? void 0 : propsArg.isObjectExpression()))
|
|
203
|
+
return undefined;
|
|
204
|
+
for (const propPath of propsArg.get('properties')) {
|
|
205
|
+
if (propPath.isObjectProperty() &&
|
|
206
|
+
t.isIdentifier(propPath.node.key, { name: 'children' })) {
|
|
207
|
+
return propPath;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
return undefined;
|
|
211
|
+
}
|
|
212
|
+
function isJsxCallPath(callPath) {
|
|
213
|
+
const callee = callPath.get('callee');
|
|
214
|
+
if (!callee.isIdentifier() && !callee.isMemberExpression())
|
|
215
|
+
return false;
|
|
216
|
+
return (0, isReactJsxFunction_1.isReactJsxFunction)(callee);
|
|
217
|
+
}
|
|
218
|
+
function hasNonWhitespaceText(childrenPath) {
|
|
219
|
+
const isText = (p) => {
|
|
220
|
+
var _a, _b;
|
|
221
|
+
if (p.isStringLiteral())
|
|
222
|
+
return p.node.value.trim().length > 0;
|
|
223
|
+
if (p.isTemplateLiteral()) {
|
|
224
|
+
return (p.node.expressions.length === 0 &&
|
|
225
|
+
((_b = (_a = p.node.quasis[0]) === null || _a === void 0 ? void 0 : _a.value.cooked) !== null && _b !== void 0 ? _b : '').trim().length > 0);
|
|
226
|
+
}
|
|
227
|
+
return false;
|
|
228
|
+
};
|
|
229
|
+
if (childrenPath.isArrayExpression()) {
|
|
230
|
+
return childrenPath
|
|
231
|
+
.get('elements')
|
|
232
|
+
.some((el) => el.isExpression() && isText(el));
|
|
233
|
+
}
|
|
234
|
+
return isText(childrenPath);
|
|
235
|
+
}
|
|
236
|
+
function hasOpaqueGTChild(childrenPath) {
|
|
237
|
+
const isOpaque = (elPath) => {
|
|
238
|
+
if (!elPath.isCallExpression() || !isJsxCallPath(elPath))
|
|
239
|
+
return false;
|
|
240
|
+
const firstArg = elPath.get('arguments')[0];
|
|
241
|
+
if (!(firstArg === null || firstArg === void 0 ? void 0 : firstArg.isExpression()))
|
|
242
|
+
return false;
|
|
243
|
+
return (0, isGTComponent_1.isGTBranchComponent)(firstArg) || (0, isGTComponent_1.isGTDeriveComponent)(firstArg);
|
|
244
|
+
};
|
|
245
|
+
if (childrenPath.isArrayExpression()) {
|
|
246
|
+
return childrenPath
|
|
247
|
+
.get('elements')
|
|
248
|
+
.some((el) => el.isExpression() && isOpaque(el));
|
|
249
|
+
}
|
|
250
|
+
return isOpaque(childrenPath);
|
|
251
|
+
}
|
|
252
|
+
function needsVarWrapping(exprPath) {
|
|
253
|
+
if (exprPath.isStringLiteral())
|
|
254
|
+
return false;
|
|
255
|
+
if (exprPath.isNumericLiteral())
|
|
256
|
+
return false;
|
|
257
|
+
if (exprPath.isBooleanLiteral())
|
|
258
|
+
return false;
|
|
259
|
+
if (exprPath.isNullLiteral())
|
|
260
|
+
return false;
|
|
261
|
+
if (exprPath.isTemplateLiteral() && exprPath.node.expressions.length === 0) {
|
|
262
|
+
return false;
|
|
263
|
+
}
|
|
264
|
+
if (exprPath.isUnaryExpression() &&
|
|
265
|
+
exprPath.node.operator === '-' &&
|
|
266
|
+
t.isNumericLiteral(exprPath.node.argument)) {
|
|
267
|
+
return false;
|
|
268
|
+
}
|
|
269
|
+
if (exprPath.isIdentifier()) {
|
|
270
|
+
return ![
|
|
271
|
+
constants_2.OTHER_IDENTIFIERS_ENUM.UNDEFINED,
|
|
272
|
+
constants_2.OTHER_IDENTIFIERS_ENUM.NAN,
|
|
273
|
+
constants_2.OTHER_IDENTIFIERS_ENUM.INFINITY,
|
|
274
|
+
].includes(exprPath.node.name);
|
|
275
|
+
}
|
|
276
|
+
if (exprPath.isCallExpression() && isJsxCallPath(exprPath)) {
|
|
277
|
+
return false;
|
|
278
|
+
}
|
|
279
|
+
return true;
|
|
280
|
+
}
|
|
281
|
+
/**
|
|
282
|
+
* After wrapping children in _T, the parent now has a single child.
|
|
283
|
+
* Update its callee from jsxs → jsx if needed.
|
|
284
|
+
*/
|
|
285
|
+
function updateCalleeToSingle({ jsxCallPath, state, }) {
|
|
286
|
+
const { singleCallee, multiCallee } = state.calleeInfo;
|
|
287
|
+
// Production (jsx/jsxs): update callee name jsxs → jsx
|
|
288
|
+
if (singleCallee && multiCallee && singleCallee !== multiCallee) {
|
|
289
|
+
const callee = jsxCallPath.get('callee');
|
|
290
|
+
if (callee.isIdentifier() && callee.node.name === multiCallee) {
|
|
291
|
+
callee.node.name = singleCallee;
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
// Dev (jsxDEV): update isStaticChildren (4th arg, index 3) to false
|
|
295
|
+
const args = jsxCallPath.get('arguments');
|
|
296
|
+
const isStaticArg = args[3];
|
|
297
|
+
if (isStaticArg === null || isStaticArg === void 0 ? void 0 : isStaticArg.isBooleanLiteral({ value: true })) {
|
|
298
|
+
isStaticArg.replaceWith(t.booleanLiteral(false));
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
// ===== AST construction =====
|
|
302
|
+
function wrapInVar(expr, callee, calleeInfo) {
|
|
303
|
+
const args = [
|
|
304
|
+
t.identifier(constants_1.GT_COMPONENT_TYPES.GtInternalVar),
|
|
305
|
+
t.objectExpression([t.objectProperty(t.identifier('children'), expr)]),
|
|
306
|
+
];
|
|
307
|
+
if (isDevMode(calleeInfo)) {
|
|
308
|
+
args.push(t.unaryExpression('void', t.numericLiteral(0)), t.booleanLiteral(false));
|
|
309
|
+
}
|
|
310
|
+
return t.callExpression(t.cloneNode(callee), args);
|
|
311
|
+
}
|
|
312
|
+
function wrapInT(children, callee, calleeInfo) {
|
|
313
|
+
const args = [
|
|
314
|
+
t.identifier(constants_1.GT_COMPONENT_TYPES.GtInternalTranslateJsx),
|
|
315
|
+
t.objectExpression([t.objectProperty(t.identifier('children'), children)]),
|
|
316
|
+
];
|
|
317
|
+
if (isDevMode(calleeInfo)) {
|
|
318
|
+
args.push(t.unaryExpression('void', t.numericLiteral(0)), t.booleanLiteral(t.isArrayExpression(children)));
|
|
319
|
+
}
|
|
320
|
+
return t.callExpression(t.cloneNode(callee), args);
|
|
321
|
+
}
|
|
322
|
+
function isDevMode(calleeInfo) {
|
|
323
|
+
return (calleeInfo.singleCallee != null &&
|
|
324
|
+
calleeInfo.singleCallee === calleeInfo.multiCallee);
|
|
325
|
+
}
|
|
326
|
+
// ===== Marking descendants as processed =====
|
|
327
|
+
function markDescendantJsxCalls({ jsxCallPath, state, }) {
|
|
328
|
+
const childrenPropPath = getChildrenPropPath(jsxCallPath);
|
|
329
|
+
if (!childrenPropPath)
|
|
330
|
+
return;
|
|
331
|
+
const valuePath = childrenPropPath.get('value');
|
|
332
|
+
if (valuePath.isExpression()) {
|
|
333
|
+
walkAndMark({ exprPath: valuePath, state });
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
function processOpaqueComponentProps({ jsxCallPath, insideAutoT, state, }) {
|
|
337
|
+
var _a;
|
|
338
|
+
const args = jsxCallPath.get('arguments');
|
|
339
|
+
const propsArg = args[1];
|
|
340
|
+
if (!(propsArg === null || propsArg === void 0 ? void 0 : propsArg.isObjectExpression()))
|
|
341
|
+
return;
|
|
342
|
+
// Resolve component type to filter control props
|
|
343
|
+
const firstArgPath = args[0];
|
|
344
|
+
const gtName = (firstArgPath === null || firstArgPath === void 0 ? void 0 : firstArgPath.isExpression())
|
|
345
|
+
? (0, isGTComponent_1.resolveFirstArgGTName)(firstArgPath)
|
|
346
|
+
: null;
|
|
347
|
+
for (const propPath of propsArg.get('properties')) {
|
|
348
|
+
if (!propPath.isObjectProperty())
|
|
349
|
+
continue;
|
|
350
|
+
// Determine prop name and skip control props
|
|
351
|
+
const key = propPath.node.key;
|
|
352
|
+
const propName = t.isIdentifier(key)
|
|
353
|
+
? key.name
|
|
354
|
+
: t.isStringLiteral(key)
|
|
355
|
+
? key.value
|
|
356
|
+
: null;
|
|
357
|
+
if (isControlProp(gtName, propName))
|
|
358
|
+
continue;
|
|
359
|
+
const valuePath = propPath.get('value');
|
|
360
|
+
if (!valuePath.isExpression())
|
|
361
|
+
continue;
|
|
362
|
+
// children is fallback content for Branch/Plural — process element-by-element
|
|
363
|
+
// For Derive/Static, children is opaque — skip entirely
|
|
364
|
+
if (propName === 'children') {
|
|
365
|
+
if (insideAutoT &&
|
|
366
|
+
(gtName === constants_1.GT_COMPONENT_TYPES.Branch ||
|
|
367
|
+
gtName === constants_1.GT_COMPONENT_TYPES.Plural)) {
|
|
368
|
+
processChildren({ childrenPath: valuePath, insideAutoT: true, state });
|
|
369
|
+
}
|
|
370
|
+
continue;
|
|
371
|
+
}
|
|
372
|
+
if (valuePath.isCallExpression() && isJsxCallPath(valuePath)) {
|
|
373
|
+
// Content prop with JSX value — recurse into children for Var-wrapping
|
|
374
|
+
if (insideAutoT) {
|
|
375
|
+
const childrenPropPath = getChildrenPropPath(valuePath);
|
|
376
|
+
if (childrenPropPath) {
|
|
377
|
+
const childrenPath = childrenPropPath.get('value');
|
|
378
|
+
if (childrenPath.isExpression()) {
|
|
379
|
+
processChildren({ childrenPath, insideAutoT: true, state });
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
state.processedNodes.add(valuePath.node);
|
|
384
|
+
walkAndMark({ exprPath: valuePath, state });
|
|
385
|
+
}
|
|
386
|
+
else if (insideAutoT && needsVarWrapping(valuePath)) {
|
|
387
|
+
const callee = (_a = state.calleeInfo.singleCallee) !== null && _a !== void 0 ? _a : constants_3.REACT_FUNTIONS.jsx;
|
|
388
|
+
const wrapped = wrapInVar(valuePath.node, t.identifier(callee), state.calleeInfo);
|
|
389
|
+
state.processedNodes.add(wrapped);
|
|
390
|
+
valuePath.replaceWith(wrapped);
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
function isControlProp(gtName, propName) {
|
|
395
|
+
if (!propName)
|
|
396
|
+
return false;
|
|
397
|
+
if (gtName === constants_1.GT_COMPONENT_TYPES.Branch) {
|
|
398
|
+
return constants_1.BRANCH_CONTROL_PROPS.has(propName) || propName.startsWith('data-');
|
|
399
|
+
}
|
|
400
|
+
if (gtName === constants_1.GT_COMPONENT_TYPES.Plural) {
|
|
401
|
+
return constants_1.PLURAL_CONTROL_PROPS.has(propName);
|
|
402
|
+
}
|
|
403
|
+
return false;
|
|
404
|
+
}
|
|
405
|
+
function walkAndMark({ exprPath, state, }) {
|
|
406
|
+
if (exprPath.isCallExpression() && isJsxCallPath(exprPath)) {
|
|
407
|
+
state.processedNodes.add(exprPath.node);
|
|
408
|
+
const childrenPropPath = getChildrenPropPath(exprPath);
|
|
409
|
+
if (childrenPropPath) {
|
|
410
|
+
const valuePath = childrenPropPath.get('value');
|
|
411
|
+
if (valuePath.isExpression()) {
|
|
412
|
+
walkAndMark({ exprPath: valuePath, state });
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
else if (exprPath.isArrayExpression()) {
|
|
417
|
+
for (const elPath of exprPath.get('elements')) {
|
|
418
|
+
if (elPath.isExpression()) {
|
|
419
|
+
walkAndMark({ exprPath: elPath, state });
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
//# sourceMappingURL=processCallExpression.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"processCallExpression.js","sourceRoot":"","sources":["../../../src/processing/jsx-insertion/processCallExpression.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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AG,gBAAgB,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;YAChD,IAAI,SAAS,CAAC,YAAY,EAAE,EAAE,CAAC;gBAC7B,WAAW,CAAC,EAAE,QAAQ,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC,CAAC;YAC9C,CAAC;QACH,CAAC;IACH,CAAC;SAAM,IAAI,QAAQ,CAAC,iBAAiB,EAAE,EAAE,CAAC;QACxC,KAAK,MAAM,MAAM,IAAI,QAAQ,CAAC,GAAG,CAAC,UAAU,CAAC,EAAE,CAAC;YAC9C,IAAI,MAAM,CAAC,YAAY,EAAE,EAAE,CAAC;gBAC1B,WAAW,CAAC,EAAE,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,CAAC;YAC3C,CAAC;QACH,CAAC;IACH,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { VisitNode } from '@babel/traverse';
|
|
2
|
+
import * as t from '@babel/types';
|
|
3
|
+
/**
|
|
4
|
+
* Info about the jsx callee names used in the file.
|
|
5
|
+
* Populated during import analysis so processCallExpression
|
|
6
|
+
* knows which callee to use for jsx (single child) vs jsxs (array children).
|
|
7
|
+
*/
|
|
8
|
+
export interface JsxCalleeInfo {
|
|
9
|
+
/** Local name for single-child calls (jsx or _jsx or _jsxDEV) */
|
|
10
|
+
singleCallee: string | null;
|
|
11
|
+
/** Local name for multi-child calls (jsxs or _jsxs or _jsxDEV) */
|
|
12
|
+
multiCallee: string | null;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Process import declarations during jsx insertion.
|
|
16
|
+
* - Checks if GtInternalTranslateJsx is already imported from a GT source.
|
|
17
|
+
* - Collects React jsx callee info (jsx vs jsxs vs jsxDEV, including aliases).
|
|
18
|
+
*/
|
|
19
|
+
export declare function processImportDeclaration(onGtImportFound: () => void, calleeInfo: JsxCalleeInfo): VisitNode<t.Node, t.ImportDeclaration>;
|
|
20
|
+
//# sourceMappingURL=processImportDeclaration.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"processImportDeclaration.d.ts","sourceRoot":"","sources":["../../../src/processing/jsx-insertion/processImportDeclaration.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,KAAK,CAAC,MAAM,cAAc,CAAC;AAMlC;;;;GAIG;AACH,MAAM,WAAW,aAAa;IAC5B,iEAAiE;IACjE,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,kEAAkE;IAClE,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;CAC5B;AAED;;;;GAIG;AACH,wBAAgB,wBAAwB,CACtC,eAAe,EAAE,MAAM,IAAI,EAC3B,UAAU,EAAE,aAAa,GACxB,SAAS,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,iBAAiB,CAAC,CA0CxC"}
|
|
@@ -0,0 +1,87 @@
|
|
|
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.processImportDeclaration = processImportDeclaration;
|
|
37
|
+
const t = __importStar(require("@babel/types"));
|
|
38
|
+
const helpers_1 = require("../../utils/constants/gt/helpers");
|
|
39
|
+
const helpers_2 = require("../../utils/constants/react/helpers");
|
|
40
|
+
const constants_1 = require("../../utils/constants/gt/constants");
|
|
41
|
+
const constants_2 = require("../../utils/constants/react/constants");
|
|
42
|
+
/**
|
|
43
|
+
* Process import declarations during jsx insertion.
|
|
44
|
+
* - Checks if GtInternalTranslateJsx is already imported from a GT source.
|
|
45
|
+
* - Collects React jsx callee info (jsx vs jsxs vs jsxDEV, including aliases).
|
|
46
|
+
*/
|
|
47
|
+
function processImportDeclaration(onGtImportFound, calleeInfo) {
|
|
48
|
+
const targetName = constants_1.GT_COMPONENT_TYPES.GtInternalTranslateJsx;
|
|
49
|
+
return (path) => {
|
|
50
|
+
const source = path.node.source.value;
|
|
51
|
+
// Check for existing GT import
|
|
52
|
+
if ((0, helpers_1.isGTImportSource)(source)) {
|
|
53
|
+
for (const specifier of path.node.specifiers) {
|
|
54
|
+
if (t.isImportSpecifier(specifier) &&
|
|
55
|
+
t.isIdentifier(specifier.imported) &&
|
|
56
|
+
specifier.imported.name === targetName) {
|
|
57
|
+
onGtImportFound();
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
// Collect React jsx callee names
|
|
63
|
+
if ((0, helpers_2.isReactImportSource)(source)) {
|
|
64
|
+
for (const specifier of path.node.specifiers) {
|
|
65
|
+
if (!t.isImportSpecifier(specifier))
|
|
66
|
+
continue;
|
|
67
|
+
const imported = specifier.imported;
|
|
68
|
+
const originalName = t.isIdentifier(imported)
|
|
69
|
+
? imported.name
|
|
70
|
+
: imported.value;
|
|
71
|
+
const localName = specifier.local.name;
|
|
72
|
+
if (originalName === constants_2.REACT_FUNTIONS.jsxDEV) {
|
|
73
|
+
// Dev mode: jsxDEV handles both single and multi children
|
|
74
|
+
calleeInfo.singleCallee = localName;
|
|
75
|
+
calleeInfo.multiCallee = localName;
|
|
76
|
+
}
|
|
77
|
+
else if (originalName === constants_2.REACT_FUNTIONS.jsx) {
|
|
78
|
+
calleeInfo.singleCallee = localName;
|
|
79
|
+
}
|
|
80
|
+
else if (originalName === constants_2.REACT_FUNTIONS.jsxs) {
|
|
81
|
+
calleeInfo.multiCallee = localName;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
//# sourceMappingURL=processImportDeclaration.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"processImportDeclaration.js","sourceRoot":"","sources":["../../../src/processing/jsx-insertion/processImportDeclaration.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwBA,4DA6CC;AApED,gDAAkC;AAClC,8DAAoE;AACpE,iEAA0E;AAC1E,kEAAwE;AACxE,qEAAuE;AAcvE;;;;GAIG;AACH,SAAgB,wBAAwB,CACtC,eAA2B,EAC3B,UAAyB;IAEzB,MAAM,UAAU,GAAG,8BAAkB,CAAC,sBAAsB,CAAC;IAE7D,OAAO,CAAC,IAAI,EAA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;qBAAM,IAAI,YAAY,KAAK,0BAAc,CAAC,IAAI,EAAE,CAAC;oBAChD,UAAU,CAAC,WAAW,GAAG,SAAS,CAAC;gBACrC,CAAC;YACH,CAAC;QACH,CAAC;IACH,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { TransformState } from '../../state/types';
|
|
2
|
+
import { VisitNode } from '@babel/traverse';
|
|
3
|
+
import * as t from '@babel/types';
|
|
4
|
+
import { JsxCalleeInfo } from './processImportDeclaration';
|
|
5
|
+
/**
|
|
6
|
+
* Process program:
|
|
7
|
+
* - on exit, injects GtInternalTranslateJsx/GtInternalVar import if needed
|
|
8
|
+
* - also injects `jsx` from React runtime if only `jsxs` was imported
|
|
9
|
+
* (Vite production builds only import what's needed — if a file has only
|
|
10
|
+
* multi-child elements, `jsx` is never imported, but our _Var wrappers need it)
|
|
11
|
+
*/
|
|
12
|
+
export declare function processProgram({ state, countBefore, isAlreadyImported, calleeInfo, }: {
|
|
13
|
+
state: TransformState;
|
|
14
|
+
countBefore: number;
|
|
15
|
+
isAlreadyImported: () => boolean;
|
|
16
|
+
calleeInfo: JsxCalleeInfo;
|
|
17
|
+
}): VisitNode<t.Node, t.Program>;
|
|
18
|
+
//# sourceMappingURL=processProgram.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"processProgram.d.ts","sourceRoot":"","sources":["../../../src/processing/jsx-insertion/processProgram.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,KAAK,CAAC,MAAM,cAAc,CAAC;AAElC,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAI3D;;;;;;GAMG;AACH,wBAAgB,cAAc,CAAC,EAC7B,KAAK,EACL,WAAW,EACX,iBAAiB,EACjB,UAAU,GACX,EAAE;IACD,KAAK,EAAE,cAAc,CAAC;IACtB,WAAW,EAAE,MAAM,CAAC;IACpB,iBAAiB,EAAE,MAAM,OAAO,CAAC;IACjC,UAAU,EAAE,aAAa,CAAC;CAC3B,GAAG,SAAS,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,OAAO,CAAC,CA2B/B"}
|
|
@@ -0,0 +1,69 @@
|
|
|
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.processProgram = processProgram;
|
|
37
|
+
const t = __importStar(require("@babel/types"));
|
|
38
|
+
const injectJsxInsertionImport_1 = require("../../transform/jsx-insertion/injectJsxInsertionImport");
|
|
39
|
+
const constants_1 = require("../../utils/constants/react/constants");
|
|
40
|
+
const constants_2 = require("../../utils/constants/react/constants");
|
|
41
|
+
/**
|
|
42
|
+
* Process program:
|
|
43
|
+
* - on exit, injects GtInternalTranslateJsx/GtInternalVar import if needed
|
|
44
|
+
* - also injects `jsx` from React runtime if only `jsxs` was imported
|
|
45
|
+
* (Vite production builds only import what's needed — if a file has only
|
|
46
|
+
* multi-child elements, `jsx` is never imported, but our _Var wrappers need it)
|
|
47
|
+
*/
|
|
48
|
+
function processProgram({ state, countBefore, isAlreadyImported, calleeInfo, }) {
|
|
49
|
+
return {
|
|
50
|
+
exit(path) {
|
|
51
|
+
const didInsert = state.statistics.jsxInsertionsCount > countBefore;
|
|
52
|
+
if (!didInsert)
|
|
53
|
+
return;
|
|
54
|
+
if (!isAlreadyImported()) {
|
|
55
|
+
(0, injectJsxInsertionImport_1.injectJsxInsertionImport)(path);
|
|
56
|
+
}
|
|
57
|
+
// If only jsxs was imported (no jsx), inject jsx import.
|
|
58
|
+
// _Var wrappers always use singleCallee which defaults to 'jsx'.
|
|
59
|
+
if (!calleeInfo.singleCallee && calleeInfo.multiCallee) {
|
|
60
|
+
const jsxImport = t.importDeclaration([
|
|
61
|
+
t.importSpecifier(t.identifier(constants_1.REACT_FUNTIONS.jsx), t.identifier(constants_1.REACT_FUNTIONS.jsx)),
|
|
62
|
+
], t.stringLiteral(constants_2.REACT_IMPORT_SOURCES.JSX_RUNTIME));
|
|
63
|
+
path.unshiftContainer('body', jsxImport);
|
|
64
|
+
calleeInfo.singleCallee = constants_1.REACT_FUNTIONS.jsx;
|
|
65
|
+
}
|
|
66
|
+
},
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
//# sourceMappingURL=processProgram.js.map
|