@boristype/bt-cli 0.1.0-alpha.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/LICENSE +21 -0
- package/README.md +66 -0
- package/build/builder/config.js +88 -0
- package/build/cli/commands/artifact.js +14 -0
- package/build/cli/commands/build.js +25 -0
- package/build/cli/commands/dev.js +190 -0
- package/build/cli/commands/index.js +18 -0
- package/build/cli/commands/init.js +15 -0
- package/build/cli/commands/link.js +18 -0
- package/build/cli/commands/push.js +28 -0
- package/build/cli/index.js +14 -0
- package/build/cli/types.js +2 -0
- package/build/core/artifacting/context.js +54 -0
- package/build/core/artifacting/index.js +37 -0
- package/build/core/artifacting/stages/index.js +10 -0
- package/build/core/artifacting/stages/main-archive.js +72 -0
- package/build/core/artifacting/stages/validate.js +70 -0
- package/build/core/artifacting/types.js +6 -0
- package/build/core/artifacting/utils/index.js +10 -0
- package/build/core/artifacting/utils/zip.js +94 -0
- package/build/core/babel.js +96 -0
- package/build/core/btconfig.types.js +6 -0
- package/build/core/build.js +280 -0
- package/build/core/building/compile-mode.js +146 -0
- package/build/core/building/compiler.js +281 -0
- package/build/core/building/coordinator.js +71 -0
- package/build/core/building/files.js +290 -0
- package/build/core/building/index.js +102 -0
- package/build/core/building/output.js +92 -0
- package/build/core/building/transformers.js +110 -0
- package/build/core/building/types.js +19 -0
- package/build/core/config.js +157 -0
- package/build/core/dependencies.js +223 -0
- package/build/core/linking/cache.js +260 -0
- package/build/core/linking/context.js +149 -0
- package/build/core/linking/dependencies.js +240 -0
- package/build/core/linking/executables.js +61 -0
- package/build/core/linking/generators/api-ext.js +57 -0
- package/build/core/linking/generators/component.js +83 -0
- package/build/core/linking/generators/filemap.js +53 -0
- package/build/core/linking/generators/index.js +21 -0
- package/build/core/linking/generators/init-xml.js +37 -0
- package/build/core/linking/generators/package-json.js +50 -0
- package/build/core/linking/index.js +213 -0
- package/build/core/linking/linkers/component.js +175 -0
- package/build/core/linking/linkers/index.js +69 -0
- package/build/core/linking/linkers/standalone.js +144 -0
- package/build/core/linking/linkers/system.js +86 -0
- package/build/core/linking/parsers.js +278 -0
- package/build/core/linking/types.js +6 -0
- package/build/core/linking/utils/copy.js +101 -0
- package/build/core/linking/utils/index.js +26 -0
- package/build/core/linking/utils/node-modules.js +226 -0
- package/build/core/linking/utils/package-type.js +101 -0
- package/build/core/linking/utils/url.js +73 -0
- package/build/core/linking/utils/write.js +91 -0
- package/build/core/logger.js +10 -0
- package/build/core/pushing/config.js +90 -0
- package/build/core/pushing/index.js +96 -0
- package/build/core/pushing/init-scripts.js +173 -0
- package/build/core/pushing/queue.js +95 -0
- package/build/core/pushing/reinit.js +61 -0
- package/build/core/pushing/session.js +167 -0
- package/build/core/pushing/types.js +6 -0
- package/build/core/pushing/upload.js +35 -0
- package/build/core/tsconfig.js +78 -0
- package/build/core/utils/index.js +17 -0
- package/build/core/utils/logger.js +46 -0
- package/build/core/utils/properties.js +81 -0
- package/build/core/utils/xml.js +44 -0
- package/build/core/utils.js +59 -0
- package/build/index.js +76 -0
- package/build/plugins/destructuring.js +83 -0
- package/build/plugins/forOfToForIn.js +14 -0
- package/build/plugins/loopHoistVariables.js +160 -0
- package/build/plugins/precedence.js +172 -0
- package/build/plugins/removeImportExport.js +42 -0
- package/build/plugins/replaceDollar.js +16 -0
- package/build/plugins/spreadArray.js +42 -0
- package/build/plugins/spreadObject.js +91 -0
- package/build/transformers/arrayFunctional.js +467 -0
- package/build/transformers/arrayGeneral.js +222 -0
- package/build/transformers/blockScoping.js +212 -0
- package/build/transformers/destructuring.js +133 -0
- package/build/transformers/dirname.js +79 -0
- package/build/transformers/enumsToObjects.js +25 -0
- package/build/transformers/execObj.js +220 -0
- package/build/transformers/forOfToForIn.js +45 -0
- package/build/transformers/funcSemantic.js +113 -0
- package/build/transformers/functions.js +270 -0
- package/build/transformers/globalCache.js +34 -0
- package/build/transformers/loopHoistVariables.js +352 -0
- package/build/transformers/math.js +39 -0
- package/build/transformers/namespaces.js +22 -0
- package/build/transformers/numericSeparator.js +46 -0
- package/build/transformers/objectProperties.js +54 -0
- package/build/transformers/precedence.js +192 -0
- package/build/transformers/propSemantic.js +467 -0
- package/build/transformers/remodule.js +620 -0
- package/build/transformers/removeImportExport.js +135 -0
- package/build/transformers/replaceDollar.js +46 -0
- package/build/transformers/shorthandProperties.js +34 -0
- package/build/transformers/spreadArray.js +68 -0
- package/build/transformers/spreadObject.js +134 -0
- package/build/transformers/string.js +138 -0
- package/build/transformers/templateLiterals.js +104 -0
- package/build/transformers/tocodelibrary.js +178 -0
- package/build/transformers/utils.js +202 -0
- package/build/wshcm/client.js +193 -0
- package/build/wshcm/evaluator.js +111 -0
- package/build/wshcm/exceptions.js +25 -0
- package/build/wshcm/index.js +20 -0
- package/build/wshcm/soap-utils.js +228 -0
- package/build/wshcm/types.js +2 -0
- package/build/wshcm/uploader.js +320 -0
- package/package.json +51 -0
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = precedencePlugin;
|
|
4
|
+
const core_1 = require("@babel/core");
|
|
5
|
+
// Таблица приоритетов операторов согласно MDN
|
|
6
|
+
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Operator_precedence
|
|
7
|
+
const PRECEDENCE = {
|
|
8
|
+
// 13: Exponentiation (right-to-left)
|
|
9
|
+
'**': 13,
|
|
10
|
+
// 12: Multiplicative operators (left-to-right)
|
|
11
|
+
'*': 12,
|
|
12
|
+
'/': 12,
|
|
13
|
+
'%': 12,
|
|
14
|
+
// 11: Additive operators (left-to-right)
|
|
15
|
+
'+': 11,
|
|
16
|
+
'-': 11,
|
|
17
|
+
// 10: Bitwise shift (left-to-right)
|
|
18
|
+
'<<': 10,
|
|
19
|
+
'>>': 10,
|
|
20
|
+
'>>>': 10,
|
|
21
|
+
// 9: Relational operators (left-to-right)
|
|
22
|
+
'<': 9,
|
|
23
|
+
'<=': 9,
|
|
24
|
+
'>': 9,
|
|
25
|
+
'>=': 9,
|
|
26
|
+
'in': 9,
|
|
27
|
+
'instanceof': 9,
|
|
28
|
+
// 8: Equality operators (left-to-right)
|
|
29
|
+
'==': 8,
|
|
30
|
+
'!=': 8,
|
|
31
|
+
'===': 8,
|
|
32
|
+
'!==': 8,
|
|
33
|
+
// 7: Bitwise AND (left-to-right)
|
|
34
|
+
'&': 7,
|
|
35
|
+
// 6: Bitwise XOR (left-to-right)
|
|
36
|
+
'^': 6,
|
|
37
|
+
// 5: Bitwise OR (left-to-right)
|
|
38
|
+
'|': 5,
|
|
39
|
+
// 4: Logical AND (left-to-right)
|
|
40
|
+
'&&': 4,
|
|
41
|
+
// 3: Logical OR, Nullish coalescing (left-to-right)
|
|
42
|
+
'||': 3,
|
|
43
|
+
'??': 3,
|
|
44
|
+
// 2: Assignment operators (right-to-left)
|
|
45
|
+
'=': 2,
|
|
46
|
+
'+=': 2,
|
|
47
|
+
'-=': 2,
|
|
48
|
+
'*=': 2,
|
|
49
|
+
'**=': 2,
|
|
50
|
+
'/=': 2,
|
|
51
|
+
'%=': 2,
|
|
52
|
+
'<<=': 2,
|
|
53
|
+
'>>=': 2,
|
|
54
|
+
'>>>=': 2,
|
|
55
|
+
'&=': 2,
|
|
56
|
+
'^=': 2,
|
|
57
|
+
'|=': 2,
|
|
58
|
+
'&&=': 2,
|
|
59
|
+
'||=': 2,
|
|
60
|
+
'??=': 2,
|
|
61
|
+
// 1: Comma operator (left-to-right)
|
|
62
|
+
',': 1,
|
|
63
|
+
};
|
|
64
|
+
// Операторы с правоассоциативностью (вычисляются справа налево)
|
|
65
|
+
const RIGHT_ASSOCIATIVE = new Set([
|
|
66
|
+
'**',
|
|
67
|
+
'=', '+=', '-=', '*=', '**=', '/=', '%=',
|
|
68
|
+
'<<=', '>>=', '>>>=',
|
|
69
|
+
'&=', '^=', '|=',
|
|
70
|
+
'&&=', '||=', '??=',
|
|
71
|
+
]);
|
|
72
|
+
function getPrecedence(operator) {
|
|
73
|
+
return PRECEDENCE[operator] ?? 999; // Высокий приоритет для неизвестных операторов
|
|
74
|
+
}
|
|
75
|
+
function isRightAssociative(operator) {
|
|
76
|
+
return RIGHT_ASSOCIATIVE.has(operator);
|
|
77
|
+
}
|
|
78
|
+
function needsParentheses(parentOp, childOp, isLeft) {
|
|
79
|
+
const parentPrec = getPrecedence(parentOp);
|
|
80
|
+
const childPrec = getPrecedence(childOp);
|
|
81
|
+
// Если приоритет разный, всегда нужны скобки
|
|
82
|
+
if (childPrec !== parentPrec) {
|
|
83
|
+
return true;
|
|
84
|
+
}
|
|
85
|
+
// Если приоритет одинаковый, ВСЕГДА нужны скобки, чтобы явно показать порядок
|
|
86
|
+
// Для left-to-right: 10 / 2 * 5 → (10 / 2) * 5 - оборачиваем левый
|
|
87
|
+
// Для right-to-left: 2 ** 3 ** 4 → 2 ** (3 ** 4) - оборачиваем правый
|
|
88
|
+
if (isRightAssociative(parentOp)) {
|
|
89
|
+
// Для right-to-left оборачиваем правый операнд
|
|
90
|
+
return !isLeft;
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
// Для left-to-right оборачиваем левый операнд
|
|
94
|
+
return isLeft;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
function precedencePlugin() {
|
|
98
|
+
return {
|
|
99
|
+
name: 'precedence-enforcer',
|
|
100
|
+
visitor: {
|
|
101
|
+
BinaryExpression(path) {
|
|
102
|
+
const node = path.node;
|
|
103
|
+
// Проверяем левый операнд
|
|
104
|
+
if (core_1.types.isBinaryExpression(node.left)) {
|
|
105
|
+
if (needsParentheses(node.operator, node.left.operator, true)) {
|
|
106
|
+
path.get('left').replaceWith(core_1.types.parenthesizedExpression(node.left));
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
// Проверяем правый операнд
|
|
110
|
+
if (core_1.types.isBinaryExpression(node.right)) {
|
|
111
|
+
if (needsParentheses(node.operator, node.right.operator, false)) {
|
|
112
|
+
path.get('right').replaceWith(core_1.types.parenthesizedExpression(node.right));
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
},
|
|
116
|
+
LogicalExpression(path) {
|
|
117
|
+
const node = path.node;
|
|
118
|
+
// Проверяем левый операнд
|
|
119
|
+
if (core_1.types.isLogicalExpression(node.left) || core_1.types.isBinaryExpression(node.left)) {
|
|
120
|
+
const leftOp = node.left.operator;
|
|
121
|
+
if (needsParentheses(node.operator, leftOp, true)) {
|
|
122
|
+
path.get('left').replaceWith(core_1.types.parenthesizedExpression(node.left));
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
// Проверяем правый операнд
|
|
126
|
+
if (core_1.types.isLogicalExpression(node.right) || core_1.types.isBinaryExpression(node.right)) {
|
|
127
|
+
const rightOp = node.right.operator;
|
|
128
|
+
if (needsParentheses(node.operator, rightOp, false)) {
|
|
129
|
+
path.get('right').replaceWith(core_1.types.parenthesizedExpression(node.right));
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
},
|
|
133
|
+
ConditionalExpression(path) {
|
|
134
|
+
const node = path.node;
|
|
135
|
+
// Условие: оборачиваем бинарные/логические выражения с приоритетом <= 2
|
|
136
|
+
if (core_1.types.isBinaryExpression(node.test) || core_1.types.isLogicalExpression(node.test)) {
|
|
137
|
+
const testOp = node.test.operator;
|
|
138
|
+
const testPrec = getPrecedence(testOp);
|
|
139
|
+
if (testPrec <= 2) {
|
|
140
|
+
path.get('test').replaceWith(core_1.types.parenthesizedExpression(node.test));
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
// consequent: оборачиваем запятую и присваивания
|
|
144
|
+
if (core_1.types.isBinaryExpression(node.consequent) || core_1.types.isLogicalExpression(node.consequent)) {
|
|
145
|
+
const trueOp = node.consequent.operator;
|
|
146
|
+
const truePrec = getPrecedence(trueOp);
|
|
147
|
+
if (truePrec <= 2) {
|
|
148
|
+
path.get('consequent').replaceWith(core_1.types.parenthesizedExpression(node.consequent));
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
// alternate: оборачиваем запятую и присваивания
|
|
152
|
+
if (core_1.types.isBinaryExpression(node.alternate) || core_1.types.isLogicalExpression(node.alternate)) {
|
|
153
|
+
const falseOp = node.alternate.operator;
|
|
154
|
+
const falsePrec = getPrecedence(falseOp);
|
|
155
|
+
if (falsePrec <= 2) {
|
|
156
|
+
path.get('alternate').replaceWith(core_1.types.parenthesizedExpression(node.alternate));
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
},
|
|
160
|
+
AssignmentExpression(path) {
|
|
161
|
+
const node = path.node;
|
|
162
|
+
// Проверяем правый операнд
|
|
163
|
+
if (core_1.types.isAssignmentExpression(node.right) || core_1.types.isBinaryExpression(node.right) || core_1.types.isLogicalExpression(node.right)) {
|
|
164
|
+
const rightOp = node.right.operator;
|
|
165
|
+
if (needsParentheses(node.operator, rightOp, false)) {
|
|
166
|
+
path.get('right').replaceWith(core_1.types.parenthesizedExpression(node.right));
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
},
|
|
170
|
+
},
|
|
171
|
+
};
|
|
172
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = removeImportExportPlugin;
|
|
4
|
+
function removeImportExportPlugin() {
|
|
5
|
+
return {
|
|
6
|
+
name: 'remove-import-export',
|
|
7
|
+
visitor: {
|
|
8
|
+
// Handle import declarations
|
|
9
|
+
ImportDeclaration(path) {
|
|
10
|
+
path.remove();
|
|
11
|
+
},
|
|
12
|
+
// Remove dummy export variables (marked with @__dummy_export comment)
|
|
13
|
+
VariableDeclaration(path) {
|
|
14
|
+
const leadingComments = path.node.leadingComments;
|
|
15
|
+
if (leadingComments?.some(comment => comment.value.includes('@__dummy_export'))) {
|
|
16
|
+
path.remove();
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
// Handle export declarations (named and default)
|
|
20
|
+
ExportNamedDeclaration(path) {
|
|
21
|
+
if (!path.node.declaration) {
|
|
22
|
+
// console.log('Warning: Export named declaration without declaration found.');
|
|
23
|
+
path.remove();
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
// console.log('Transforming export named declaration:', path.node.declaration.type);
|
|
27
|
+
// path.remove();
|
|
28
|
+
path.replaceWith(path.node.declaration);
|
|
29
|
+
},
|
|
30
|
+
ExportDefaultDeclaration(path) {
|
|
31
|
+
// export default может быть без declaration (например export default выражение)
|
|
32
|
+
// В Babel это представлено через ExportDefaultDeclaration где declaration это само выражение
|
|
33
|
+
// Мы просто удаляем весь export default
|
|
34
|
+
path.remove();
|
|
35
|
+
},
|
|
36
|
+
// Handle export all declarations
|
|
37
|
+
ExportAllDeclaration(path) {
|
|
38
|
+
path.remove();
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
};
|
|
42
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = replaceDollarPlugin;
|
|
4
|
+
function replaceDollarPlugin() {
|
|
5
|
+
return {
|
|
6
|
+
name: 'replace-dollar',
|
|
7
|
+
visitor: {
|
|
8
|
+
Identifier(path) {
|
|
9
|
+
if (path.node.name.includes('$')) {
|
|
10
|
+
const newName = path.node.name.replace(/\$/g, '_24_');
|
|
11
|
+
path.node.name = newName;
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
},
|
|
15
|
+
};
|
|
16
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = transformArraySpreadToArrayUnionPlugin;
|
|
4
|
+
const core_1 = require("@babel/core");
|
|
5
|
+
function transformArraySpreadToArrayUnionPlugin() {
|
|
6
|
+
return {
|
|
7
|
+
name: 'transform-array-spread-to-array-union',
|
|
8
|
+
visitor: {
|
|
9
|
+
ArrayExpression(path) {
|
|
10
|
+
// Проверяем наличие spread-элементов в массиве
|
|
11
|
+
const hasSpread = path.node.elements.some(element => element && core_1.types.isSpreadElement(element));
|
|
12
|
+
if (!hasSpread) {
|
|
13
|
+
return; // Пропускаем массивы без spread-элементов
|
|
14
|
+
}
|
|
15
|
+
const args = [];
|
|
16
|
+
let currentLiteralArray = [];
|
|
17
|
+
// Обрабатываем элементы массива
|
|
18
|
+
path.node.elements.forEach(element => {
|
|
19
|
+
if (element && core_1.types.isSpreadElement(element)) {
|
|
20
|
+
// Если есть накопленные литералы, добавляем их как массив
|
|
21
|
+
if (currentLiteralArray.length > 0) {
|
|
22
|
+
args.push(core_1.types.arrayExpression(currentLiteralArray));
|
|
23
|
+
currentLiteralArray = [];
|
|
24
|
+
}
|
|
25
|
+
// Добавляем аргумент spread-элемента
|
|
26
|
+
args.push(element.argument);
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
// Собираем не-spread элементы (t.Expression | null)
|
|
30
|
+
currentLiteralArray.push(element);
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
// Добавляем оставшиеся литералы как массив
|
|
34
|
+
if (currentLiteralArray.length > 0) {
|
|
35
|
+
args.push(core_1.types.arrayExpression(currentLiteralArray));
|
|
36
|
+
}
|
|
37
|
+
// Заменяем выражение массива вызовом ArrayUnion
|
|
38
|
+
path.replaceWith(core_1.types.callExpression(core_1.types.identifier('ArrayUnion'), args));
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = transformObjectSpreadToObjectUnionPlugin;
|
|
4
|
+
const core_1 = require("@babel/core");
|
|
5
|
+
function transformObjectSpreadToObjectUnionPlugin() {
|
|
6
|
+
return {
|
|
7
|
+
name: 'transform-object-spread-to-object-union',
|
|
8
|
+
pre() {
|
|
9
|
+
this.needsObjectUnion = false;
|
|
10
|
+
},
|
|
11
|
+
visitor: {
|
|
12
|
+
Program: {
|
|
13
|
+
exit(path, state) {
|
|
14
|
+
if (state.needsObjectUnion) {
|
|
15
|
+
// Вставляем определение функции ObjectUnion в начало программы
|
|
16
|
+
const functionDecl = core_1.types.functionDeclaration(core_1.types.identifier('ObjectUnion'), [core_1.types.identifier('obj1'), core_1.types.identifier('obj2')], core_1.types.blockStatement([
|
|
17
|
+
core_1.types.variableDeclaration('var', [
|
|
18
|
+
core_1.types.variableDeclarator(core_1.types.identifier('newObject'), core_1.types.objectExpression([]))
|
|
19
|
+
]),
|
|
20
|
+
core_1.types.variableDeclaration('var', [
|
|
21
|
+
core_1.types.variableDeclarator(core_1.types.identifier('key'))
|
|
22
|
+
]),
|
|
23
|
+
core_1.types.forInStatement(core_1.types.identifier('key'), core_1.types.identifier('obj1'), core_1.types.blockStatement([
|
|
24
|
+
core_1.types.expressionStatement(core_1.types.callExpression(core_1.types.memberExpression(core_1.types.identifier('newObject'), core_1.types.identifier('SetProperty')), [
|
|
25
|
+
core_1.types.identifier('key'),
|
|
26
|
+
core_1.types.callExpression(core_1.types.memberExpression(core_1.types.identifier('obj1'), core_1.types.identifier('GetProperty')), [core_1.types.identifier('key')])
|
|
27
|
+
]))
|
|
28
|
+
])),
|
|
29
|
+
core_1.types.forInStatement(core_1.types.identifier('key'), core_1.types.identifier('obj2'), core_1.types.blockStatement([
|
|
30
|
+
core_1.types.expressionStatement(core_1.types.callExpression(core_1.types.memberExpression(core_1.types.identifier('newObject'), core_1.types.identifier('SetProperty')), [
|
|
31
|
+
core_1.types.identifier('key'),
|
|
32
|
+
core_1.types.callExpression(core_1.types.memberExpression(core_1.types.identifier('obj2'), core_1.types.identifier('GetProperty')), [core_1.types.identifier('key')])
|
|
33
|
+
]))
|
|
34
|
+
])),
|
|
35
|
+
core_1.types.returnStatement(core_1.types.identifier('newObject'))
|
|
36
|
+
]));
|
|
37
|
+
path.unshiftContainer('body', functionDecl);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
ObjectExpression(path, state) {
|
|
42
|
+
// Проверяем наличие spread-элементов в объекте
|
|
43
|
+
const hasSpread = path.node.properties.some(property => core_1.types.isSpreadElement(property));
|
|
44
|
+
if (!hasSpread) {
|
|
45
|
+
return; // Пропускаем объекты без spread-элементов
|
|
46
|
+
}
|
|
47
|
+
state.needsObjectUnion = true;
|
|
48
|
+
const parts = [];
|
|
49
|
+
let currentLiteralProperties = [];
|
|
50
|
+
// Обрабатываем свойства объекта
|
|
51
|
+
path.node.properties.forEach(property => {
|
|
52
|
+
if (core_1.types.isSpreadElement(property)) {
|
|
53
|
+
// Если есть накопленные свойства, добавляем их как объект
|
|
54
|
+
if (currentLiteralProperties.length > 0) {
|
|
55
|
+
parts.push(core_1.types.objectExpression(currentLiteralProperties));
|
|
56
|
+
currentLiteralProperties = [];
|
|
57
|
+
}
|
|
58
|
+
// Добавляем аргумент spread-элемента
|
|
59
|
+
parts.push(property.argument);
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
// Собираем не-spread свойства (с кастом к t.ObjectMember)
|
|
63
|
+
currentLiteralProperties.push(property);
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
// Добавляем оставшиеся свойства как объект
|
|
67
|
+
if (currentLiteralProperties.length > 0) {
|
|
68
|
+
parts.push(core_1.types.objectExpression(currentLiteralProperties));
|
|
69
|
+
}
|
|
70
|
+
// Если частей нет, возвращаем пустой объект
|
|
71
|
+
if (parts.length === 0) {
|
|
72
|
+
path.replaceWith(core_1.types.objectExpression([]));
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
// Если только одна часть, заменяем на нее
|
|
76
|
+
if (parts.length === 1) {
|
|
77
|
+
// path.replaceWith(parts[0]);
|
|
78
|
+
path.replaceWith(core_1.types.callExpression(core_1.types.identifier('ObjectUnion'), [core_1.types.objectExpression([]), parts[0]]));
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
// Строим вложенные вызовы ObjectUnion попарно (left-associative)
|
|
82
|
+
let expression = parts[0];
|
|
83
|
+
for (let i = 1; i < parts.length; i++) {
|
|
84
|
+
expression = core_1.types.callExpression(core_1.types.identifier('ObjectUnion'), [expression, parts[i]]);
|
|
85
|
+
}
|
|
86
|
+
// Заменяем выражение объекта вложенными вызовами ObjectUnion
|
|
87
|
+
path.replaceWith(expression);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
}
|