@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,270 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.functionsTransformer = functionsTransformer;
|
|
7
|
+
const typescript_1 = __importDefault(require("typescript"));
|
|
8
|
+
const utils_1 = require("./utils");
|
|
9
|
+
// Helper function to extract lambda functions from a node tree
|
|
10
|
+
function extractLambdaFunctions(node) {
|
|
11
|
+
const lambdas = [];
|
|
12
|
+
function visit(n) {
|
|
13
|
+
if (n.__lambdaFunctions) {
|
|
14
|
+
lambdas.push(...n.__lambdaFunctions);
|
|
15
|
+
delete n.__lambdaFunctions;
|
|
16
|
+
}
|
|
17
|
+
typescript_1.default.forEachChild(n, visit);
|
|
18
|
+
}
|
|
19
|
+
visit(node);
|
|
20
|
+
return lambdas;
|
|
21
|
+
}
|
|
22
|
+
// Helper function to extract method functions from object literals
|
|
23
|
+
function extractMethodFunctions(node) {
|
|
24
|
+
const methods = [];
|
|
25
|
+
function visit(n) {
|
|
26
|
+
if (n.__methodFunctions) {
|
|
27
|
+
methods.push(...n.__methodFunctions);
|
|
28
|
+
delete n.__methodFunctions;
|
|
29
|
+
}
|
|
30
|
+
typescript_1.default.forEachChild(n, visit);
|
|
31
|
+
}
|
|
32
|
+
visit(node);
|
|
33
|
+
return methods;
|
|
34
|
+
}
|
|
35
|
+
function functionsTransformer() {
|
|
36
|
+
return (context) => {
|
|
37
|
+
return (sourceFile) => {
|
|
38
|
+
let lambdaCounter = 0;
|
|
39
|
+
// First pass: transform nodes and collect hoisted functions
|
|
40
|
+
const transformedStatements = [];
|
|
41
|
+
sourceFile.statements.forEach((statement) => {
|
|
42
|
+
const hoistedFunctions = [];
|
|
43
|
+
// lambdaCounter = 0; // Reset counter for each statement
|
|
44
|
+
const visitor = (node, isInsideFunction = false) => {
|
|
45
|
+
// Transform arrow functions assigned to const/let/var
|
|
46
|
+
if (typescript_1.default.isVariableStatement(node)) {
|
|
47
|
+
const declaration = node.declarationList.declarations[0];
|
|
48
|
+
if (declaration &&
|
|
49
|
+
declaration.initializer &&
|
|
50
|
+
typescript_1.default.isArrowFunction(declaration.initializer)) {
|
|
51
|
+
const arrowFunc = declaration.initializer;
|
|
52
|
+
const funcName = declaration.name.text;
|
|
53
|
+
// Create a regular function declaration
|
|
54
|
+
const functionDecl = typescript_1.default.factory.createFunctionDeclaration(undefined, undefined, funcName, undefined, arrowFunc.parameters, arrowFunc.type, arrowFunc.body && typescript_1.default.isBlock(arrowFunc.body)
|
|
55
|
+
? arrowFunc.body
|
|
56
|
+
: typescript_1.default.factory.createBlock([
|
|
57
|
+
typescript_1.default.factory.createReturnStatement(arrowFunc.body)
|
|
58
|
+
]));
|
|
59
|
+
return functionDecl;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
// Transform methods in object literals
|
|
63
|
+
if (typescript_1.default.isObjectLiteralExpression(node)) {
|
|
64
|
+
const objectLiteral = node;
|
|
65
|
+
const newProperties = [];
|
|
66
|
+
// Find the variable name of this object (if any)
|
|
67
|
+
let objectName = 'unknown';
|
|
68
|
+
if (typescript_1.default.isVariableDeclaration(node.parent)) {
|
|
69
|
+
objectName = node.parent.name.text;
|
|
70
|
+
}
|
|
71
|
+
objectLiteral.properties.forEach((prop) => {
|
|
72
|
+
if (typescript_1.default.isMethodDeclaration(prop)) {
|
|
73
|
+
const methodName = prop.name.text;
|
|
74
|
+
const hoistedFuncName = `${methodName}__method_of__${objectName}`;
|
|
75
|
+
// Create hoisted function
|
|
76
|
+
const hoistedFunc = typescript_1.default.factory.createFunctionDeclaration(undefined, undefined, hoistedFuncName, undefined, prop.parameters, prop.type, prop.body);
|
|
77
|
+
hoistedFunctions.push(hoistedFunc);
|
|
78
|
+
// Replace method with property assignment
|
|
79
|
+
const propertyAssignment = typescript_1.default.factory.createPropertyAssignment(prop.name, typescript_1.default.factory.createIdentifier(hoistedFuncName));
|
|
80
|
+
newProperties.push(propertyAssignment);
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
newProperties.push(prop);
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
const objLiteral = typescript_1.default.factory.createObjectLiteralExpression(newProperties, true);
|
|
87
|
+
return (0, utils_1.setParentNodes)(objLiteral);
|
|
88
|
+
}
|
|
89
|
+
// Transform arrow functions used as arguments (lambdas)
|
|
90
|
+
if (typescript_1.default.isCallExpression(node)) {
|
|
91
|
+
const newArgs = node.arguments.map((arg) => {
|
|
92
|
+
if (typescript_1.default.isArrowFunction(arg)) {
|
|
93
|
+
const lambdaName = `lambda_${lambdaCounter++}`;
|
|
94
|
+
// Create hoisted function
|
|
95
|
+
const hoistedFunc = typescript_1.default.factory.createFunctionDeclaration(undefined, undefined, lambdaName, undefined, arg.parameters, arg.type, arg.body && typescript_1.default.isBlock(arg.body)
|
|
96
|
+
? arg.body
|
|
97
|
+
: typescript_1.default.factory.createBlock([
|
|
98
|
+
typescript_1.default.factory.createReturnStatement(arg.body)
|
|
99
|
+
]));
|
|
100
|
+
// Only hoist if NOT inside a function
|
|
101
|
+
if (!isInsideFunction) {
|
|
102
|
+
hoistedFunctions.push(hoistedFunc);
|
|
103
|
+
}
|
|
104
|
+
return typescript_1.default.factory.createIdentifier(lambdaName);
|
|
105
|
+
}
|
|
106
|
+
return typescript_1.default.visitNode(arg, (n) => visitor(n, isInsideFunction));
|
|
107
|
+
});
|
|
108
|
+
return typescript_1.default.factory.updateCallExpression(node, typescript_1.default.visitNode(node.expression, (n) => visitor(n, isInsideFunction)), node.typeArguments, typescript_1.default.factory.createNodeArray(newArgs));
|
|
109
|
+
}
|
|
110
|
+
// Handle function declarations - mark that we're inside a function
|
|
111
|
+
if (typescript_1.default.isFunctionDeclaration(node) || typescript_1.default.isFunctionExpression(node) || typescript_1.default.isArrowFunction(node)) {
|
|
112
|
+
// Process function body with isInsideFunction = true
|
|
113
|
+
if (node.body && typescript_1.default.isBlock(node.body)) {
|
|
114
|
+
const functionBodyVisitor = (innerNode) => {
|
|
115
|
+
// Transform arrow functions assigned to const/let/var inside function body
|
|
116
|
+
if (typescript_1.default.isVariableStatement(innerNode)) {
|
|
117
|
+
const declaration = innerNode.declarationList.declarations[0];
|
|
118
|
+
if (declaration &&
|
|
119
|
+
declaration.initializer &&
|
|
120
|
+
typescript_1.default.isArrowFunction(declaration.initializer)) {
|
|
121
|
+
const arrowFunc = declaration.initializer;
|
|
122
|
+
const funcName = declaration.name.text;
|
|
123
|
+
// Create a regular function declaration
|
|
124
|
+
const functionDecl = typescript_1.default.factory.createFunctionDeclaration(undefined, undefined, funcName, undefined, arrowFunc.parameters, arrowFunc.type, arrowFunc.body && typescript_1.default.isBlock(arrowFunc.body)
|
|
125
|
+
? arrowFunc.body
|
|
126
|
+
: typescript_1.default.factory.createBlock([
|
|
127
|
+
typescript_1.default.factory.createReturnStatement(arrowFunc.body)
|
|
128
|
+
]));
|
|
129
|
+
return functionDecl;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
// Transform object literal methods inside functions
|
|
133
|
+
if (typescript_1.default.isObjectLiteralExpression(innerNode)) {
|
|
134
|
+
const objectLiteral = innerNode;
|
|
135
|
+
const newProperties = [];
|
|
136
|
+
const methodFunctions = [];
|
|
137
|
+
// Find the function name where this object is defined
|
|
138
|
+
let contextName = 'unknown';
|
|
139
|
+
if (typescript_1.default.isFunctionDeclaration(node)) {
|
|
140
|
+
contextName = node.name?.text || 'anonymous';
|
|
141
|
+
}
|
|
142
|
+
objectLiteral.properties.forEach((prop) => {
|
|
143
|
+
if (typescript_1.default.isMethodDeclaration(prop)) {
|
|
144
|
+
const methodName = prop.name.text;
|
|
145
|
+
const hoistedFuncName = `${methodName}__method_of__${contextName}`;
|
|
146
|
+
// Create hoisted function
|
|
147
|
+
const hoistedFunc = typescript_1.default.factory.createFunctionDeclaration(undefined, undefined, hoistedFuncName, undefined, prop.parameters, prop.type, prop.body);
|
|
148
|
+
methodFunctions.push(hoistedFunc);
|
|
149
|
+
// Replace method with property assignment
|
|
150
|
+
const propertyAssignment = typescript_1.default.factory.createPropertyAssignment(prop.name, typescript_1.default.factory.createIdentifier(hoistedFuncName));
|
|
151
|
+
newProperties.push(propertyAssignment);
|
|
152
|
+
}
|
|
153
|
+
else {
|
|
154
|
+
newProperties.push(prop);
|
|
155
|
+
}
|
|
156
|
+
});
|
|
157
|
+
// Store method functions to be added to the function body
|
|
158
|
+
if (methodFunctions.length > 0) {
|
|
159
|
+
const newObj = typescript_1.default.factory.createObjectLiteralExpression(newProperties, true);
|
|
160
|
+
newObj.__methodFunctions = methodFunctions;
|
|
161
|
+
return (0, utils_1.setParentNodes)(newObj);
|
|
162
|
+
}
|
|
163
|
+
const objLiteral = typescript_1.default.factory.createObjectLiteralExpression(newProperties, true);
|
|
164
|
+
return (0, utils_1.setParentNodes)(objLiteral, objectLiteral.parent);
|
|
165
|
+
}
|
|
166
|
+
return typescript_1.default.visitEachChild(innerNode, functionBodyVisitor, context);
|
|
167
|
+
};
|
|
168
|
+
// Transform expressions and collect lambda functions
|
|
169
|
+
const transformExpression = (expr, lambdas) => {
|
|
170
|
+
if (typescript_1.default.isCallExpression(expr)) {
|
|
171
|
+
// First, recursively transform nested call expressions
|
|
172
|
+
const transformedExpression = transformExpression(expr.expression, lambdas);
|
|
173
|
+
const newArgs = expr.arguments.map((arg) => {
|
|
174
|
+
if (typescript_1.default.isArrowFunction(arg)) {
|
|
175
|
+
const lambdaName = `lambda_${lambdaCounter++}`;
|
|
176
|
+
const hoistedFunc = typescript_1.default.factory.createFunctionDeclaration(undefined, undefined, lambdaName, undefined, arg.parameters, arg.type, arg.body && typescript_1.default.isBlock(arg.body)
|
|
177
|
+
? arg.body
|
|
178
|
+
: typescript_1.default.factory.createBlock([
|
|
179
|
+
typescript_1.default.factory.createReturnStatement(arg.body)
|
|
180
|
+
]));
|
|
181
|
+
lambdas.push(hoistedFunc);
|
|
182
|
+
return typescript_1.default.factory.createIdentifier(lambdaName);
|
|
183
|
+
}
|
|
184
|
+
else if (typescript_1.default.isCallExpression(arg)) {
|
|
185
|
+
// Recursively handle nested calls
|
|
186
|
+
return transformExpression(arg, lambdas);
|
|
187
|
+
}
|
|
188
|
+
return arg;
|
|
189
|
+
});
|
|
190
|
+
return typescript_1.default.factory.updateCallExpression(expr, transformedExpression, expr.typeArguments, typescript_1.default.factory.createNodeArray(newArgs));
|
|
191
|
+
}
|
|
192
|
+
return expr;
|
|
193
|
+
};
|
|
194
|
+
// Transform body statements and inject lambda functions before their usage
|
|
195
|
+
const transformedStatements = [];
|
|
196
|
+
node.body.statements.forEach((stmt) => {
|
|
197
|
+
// First transform variable statements and function declarations
|
|
198
|
+
const basicTransformed = typescript_1.default.visitNode(stmt, functionBodyVisitor);
|
|
199
|
+
// Extract method functions from object literals
|
|
200
|
+
const methodFunctions = extractMethodFunctions(basicTransformed);
|
|
201
|
+
if (methodFunctions.length > 0) {
|
|
202
|
+
methodFunctions.forEach((func) => transformedStatements.push(func));
|
|
203
|
+
}
|
|
204
|
+
// Check if this is a return statement with call expressions
|
|
205
|
+
if (typescript_1.default.isReturnStatement(basicTransformed) && basicTransformed.expression) {
|
|
206
|
+
const lambdas = [];
|
|
207
|
+
const transformedExpression = transformExpression(basicTransformed.expression, lambdas);
|
|
208
|
+
if (lambdas.length > 0) {
|
|
209
|
+
// Add lambda functions before the return statement
|
|
210
|
+
lambdas.forEach((func) => transformedStatements.push(func));
|
|
211
|
+
}
|
|
212
|
+
transformedStatements.push(typescript_1.default.factory.updateReturnStatement(basicTransformed, transformedExpression));
|
|
213
|
+
}
|
|
214
|
+
else if (typescript_1.default.isExpressionStatement(basicTransformed)) {
|
|
215
|
+
// Handle expression statements with call expressions
|
|
216
|
+
const lambdas = [];
|
|
217
|
+
const transformedExpression = transformExpression(basicTransformed.expression, lambdas);
|
|
218
|
+
if (lambdas.length > 0) {
|
|
219
|
+
lambdas.forEach((func) => transformedStatements.push(func));
|
|
220
|
+
}
|
|
221
|
+
transformedStatements.push(typescript_1.default.factory.updateExpressionStatement(basicTransformed, transformedExpression));
|
|
222
|
+
}
|
|
223
|
+
else {
|
|
224
|
+
transformedStatements.push(basicTransformed);
|
|
225
|
+
}
|
|
226
|
+
});
|
|
227
|
+
// Handle default parameters
|
|
228
|
+
const defaultParamChecks = [];
|
|
229
|
+
const newParameters = [];
|
|
230
|
+
if (typescript_1.default.isFunctionDeclaration(node)) {
|
|
231
|
+
node.parameters.forEach((param) => {
|
|
232
|
+
if (param.initializer) {
|
|
233
|
+
// Create parameter without default value
|
|
234
|
+
const newParam = typescript_1.default.factory.createParameterDeclaration(param.modifiers, param.dotDotDotToken, param.name, param.questionToken, param.type, undefined // Remove initializer
|
|
235
|
+
);
|
|
236
|
+
newParameters.push(newParam);
|
|
237
|
+
// Create if statement to check for undefined
|
|
238
|
+
const paramName = param.name;
|
|
239
|
+
const ifStatement = typescript_1.default.factory.createIfStatement(typescript_1.default.factory.createBinaryExpression(typescript_1.default.factory.createIdentifier(paramName.text), typescript_1.default.factory.createToken(typescript_1.default.SyntaxKind.EqualsEqualsEqualsToken), typescript_1.default.factory.createIdentifier('undefined')), typescript_1.default.factory.createBlock([
|
|
240
|
+
typescript_1.default.factory.createExpressionStatement(typescript_1.default.factory.createBinaryExpression(typescript_1.default.factory.createIdentifier(paramName.text), typescript_1.default.factory.createToken(typescript_1.default.SyntaxKind.EqualsToken), param.initializer))
|
|
241
|
+
], true));
|
|
242
|
+
defaultParamChecks.push(ifStatement);
|
|
243
|
+
}
|
|
244
|
+
else {
|
|
245
|
+
newParameters.push(param);
|
|
246
|
+
}
|
|
247
|
+
});
|
|
248
|
+
}
|
|
249
|
+
// Combine default param checks with transformed statements
|
|
250
|
+
const finalStatements = [...defaultParamChecks, ...transformedStatements];
|
|
251
|
+
const newBody = typescript_1.default.factory.createBlock(finalStatements, true);
|
|
252
|
+
if (typescript_1.default.isFunctionDeclaration(node)) {
|
|
253
|
+
return typescript_1.default.factory.updateFunctionDeclaration(node, node.modifiers, node.asteriskToken, node.name, node.typeParameters, newParameters.length > 0 ? newParameters : node.parameters, node.type, newBody);
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
return node;
|
|
257
|
+
}
|
|
258
|
+
return typescript_1.default.visitEachChild(node, (n) => visitor(n, isInsideFunction), context);
|
|
259
|
+
};
|
|
260
|
+
const transformedStatement = typescript_1.default.visitNode(statement, visitor);
|
|
261
|
+
// Add hoisted functions before the transformed statement
|
|
262
|
+
if (hoistedFunctions.length > 0) {
|
|
263
|
+
hoistedFunctions.forEach(func => transformedStatements.push(func));
|
|
264
|
+
}
|
|
265
|
+
transformedStatements.push(transformedStatement);
|
|
266
|
+
});
|
|
267
|
+
return typescript_1.default.factory.updateSourceFile(sourceFile, transformedStatements);
|
|
268
|
+
};
|
|
269
|
+
};
|
|
270
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.globalCacheTransformer = globalCacheTransformer;
|
|
7
|
+
const typescript_1 = __importDefault(require("typescript"));
|
|
8
|
+
const utils_1 = require("./utils");
|
|
9
|
+
function globalCacheTransformer(program) {
|
|
10
|
+
const typeChecker = program.getTypeChecker();
|
|
11
|
+
return (context) => (sourceFile) => {
|
|
12
|
+
const factory = context.factory;
|
|
13
|
+
function visit(node) {
|
|
14
|
+
// Проверяем, является ли узел вызовом метода (globalCache.set(), globalCache.get(), globalCache.has())
|
|
15
|
+
if (typescript_1.default.isCallExpression(node) && typescript_1.default.isPropertyAccessExpression(node.expression)) {
|
|
16
|
+
const propertyAccess = node.expression;
|
|
17
|
+
const objectExpression = propertyAccess.expression;
|
|
18
|
+
const methodName = propertyAccess.name.text;
|
|
19
|
+
// Проверяем тип объекта
|
|
20
|
+
const type = typeChecker.getTypeAtLocation(objectExpression);
|
|
21
|
+
const typeString = typeChecker.typeToString(type);
|
|
22
|
+
// Проверяем, что это тип GlobalCache и метод один из: set, get, has
|
|
23
|
+
if (typeString === 'GlobalCache' && ['set', 'get', 'has'].includes(methodName)) {
|
|
24
|
+
// Создаем bt.cache.method(...)
|
|
25
|
+
const btCache = factory.createPropertyAccessExpression(factory.createPropertyAccessExpression(factory.createIdentifier('bt'), factory.createIdentifier('cache')), factory.createIdentifier(methodName));
|
|
26
|
+
// Создаем новый вызов с теми же аргументами
|
|
27
|
+
return factory.createCallExpression((0, utils_1.markUntouchable)(btCache), node.typeArguments, node.arguments);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return typescript_1.default.visitEachChild(node, visit, context);
|
|
31
|
+
}
|
|
32
|
+
return (0, utils_1.setParentNodes)(typescript_1.default.visitNode(sourceFile, visit), sourceFile);
|
|
33
|
+
};
|
|
34
|
+
}
|