@bitfab/sdk 0.64.24 → 0.64.25
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/{chunk-3YAEAQI5.js → chunk-DY52FEEM.js} +2 -2
- package/dist/{chunk-3YAEAQI5.js.map → chunk-DY52FEEM.js.map} +1 -1
- package/dist/{chunk-E6YNESVO.js → chunk-EFGQRVMT.js} +2 -2
- package/dist/chunk-GSHCHCB5.js +433 -0
- package/dist/chunk-GSHCHCB5.js.map +1 -0
- package/dist/chunk-IBWW3SP4.js +45 -0
- package/dist/chunk-IBWW3SP4.js.map +1 -0
- package/dist/{chunk-EXTDH26A.js → chunk-JNVDKPFL.js} +6 -6
- package/dist/{chunk-OXFZJP4E.js → chunk-MN3E2RUU.js} +6 -8
- package/dist/chunk-MN3E2RUU.js.map +1 -0
- package/dist/{chunk-7A5E42SY.js → chunk-OMWPLB5R.js} +2 -2
- package/dist/{chunk-7A5E42SY.js.map → chunk-OMWPLB5R.js.map} +1 -1
- package/dist/{chunk-3NIUOINN.js → chunk-R7SJXFMB.js} +4 -4
- package/dist/{chunk-NOWQOHCR.js → chunk-ULKKTYOL.js} +2 -2
- package/dist/{http-UQTRAPDD.js → http-GDTWWWYY.js} +2 -2
- package/dist/{http-G3U247I4.js → http-QXJJB2F5.js} +2 -2
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +3 -3
- package/dist/node.cjs +1 -1
- package/dist/node.cjs.map +1 -1
- package/dist/node.js +3 -3
- package/dist/{replay-SK4FOKUB.js → replay-DC3PID7Q.js} +3 -3
- package/dist/{replay-MPMU3VBP.js → replay-VXQGVZXM.js} +3 -3
- package/dist/replayCli.js +3 -3
- package/dist/seedCli.js +3 -3
- package/dist/transform/babel.cjs +68 -34
- package/dist/transform/babel.cjs.map +1 -1
- package/dist/transform/babel.d.cts +2 -2
- package/dist/transform/babel.d.ts +2 -2
- package/dist/transform/babel.js +2 -374
- package/dist/transform/babel.js.map +1 -1
- package/dist/transform/bun.cjs +389 -464
- package/dist/transform/bun.cjs.map +1 -1
- package/dist/transform/bun.js +3 -3
- package/dist/transform/esbuild.cjs +389 -464
- package/dist/transform/esbuild.cjs.map +1 -1
- package/dist/transform/esbuild.js +3 -3
- package/dist/transform/loaderRuntime.cjs +448 -498
- package/dist/transform/loaderRuntime.cjs.map +1 -1
- package/dist/transform/loaderRuntime.js +90 -70
- package/dist/transform/loaderRuntime.js.map +1 -1
- package/dist/transform/nest.cjs +389 -464
- package/dist/transform/nest.cjs.map +1 -1
- package/dist/transform/nest.js +3 -3
- package/dist/transform/next.cjs +389 -464
- package/dist/transform/next.cjs.map +1 -1
- package/dist/transform/next.js +3 -3
- package/dist/transform/nodeLoader.js +451 -498
- package/dist/transform/nodeLoader.js.map +1 -1
- package/dist/transform/rolldown.cjs +389 -464
- package/dist/transform/rolldown.cjs.map +1 -1
- package/dist/transform/rolldown.js +3 -3
- package/dist/transform/rollup.cjs +389 -464
- package/dist/transform/rollup.cjs.map +1 -1
- package/dist/transform/rollup.js +3 -3
- package/dist/transform/rsbuild.cjs +389 -464
- package/dist/transform/rsbuild.cjs.map +1 -1
- package/dist/transform/rsbuild.js +3 -3
- package/dist/transform/rspack.cjs +389 -464
- package/dist/transform/rspack.cjs.map +1 -1
- package/dist/transform/rspack.js +3 -3
- package/dist/transform/swc.cjs +402 -471
- package/dist/transform/swc.cjs.map +1 -1
- package/dist/transform/swc.js +19 -13
- package/dist/transform/swc.js.map +1 -1
- package/dist/transform/unplugin.cjs +389 -464
- package/dist/transform/unplugin.cjs.map +1 -1
- package/dist/transform/unplugin.js +3 -3
- package/dist/transform/vite.cjs +389 -464
- package/dist/transform/vite.cjs.map +1 -1
- package/dist/transform/vite.js +3 -3
- package/dist/transform/webpack.cjs +389 -464
- package/dist/transform/webpack.cjs.map +1 -1
- package/dist/transform/webpack.js +3 -3
- package/package.json +10 -21
- package/dist/chunk-6R33XLNY.js +0 -28
- package/dist/chunk-6R33XLNY.js.map +0 -1
- package/dist/chunk-OXFZJP4E.js.map +0 -1
- package/dist/chunk-PACLPKDH.js +0 -513
- package/dist/chunk-PACLPKDH.js.map +0 -1
- package/dist/transform/typescript.cjs +0 -566
- package/dist/transform/typescript.cjs.map +0 -1
- package/dist/transform/typescript.d.cts +0 -22
- package/dist/transform/typescript.d.ts +0 -22
- package/dist/transform/typescript.js +0 -10
- package/dist/transform/typescript.js.map +0 -1
- /package/dist/{chunk-E6YNESVO.js.map → chunk-EFGQRVMT.js.map} +0 -0
- /package/dist/{chunk-EXTDH26A.js.map → chunk-JNVDKPFL.js.map} +0 -0
- /package/dist/{chunk-3NIUOINN.js.map → chunk-R7SJXFMB.js.map} +0 -0
- /package/dist/{chunk-NOWQOHCR.js.map → chunk-ULKKTYOL.js.map} +0 -0
- /package/dist/{http-G3U247I4.js.map → http-GDTWWWYY.js.map} +0 -0
- /package/dist/{http-UQTRAPDD.js.map → http-QXJJB2F5.js.map} +0 -0
- /package/dist/{replay-MPMU3VBP.js.map → replay-DC3PID7Q.js.map} +0 -0
- /package/dist/{replay-SK4FOKUB.js.map → replay-VXQGVZXM.js.map} +0 -0
package/dist/transform/swc.cjs
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
2
|
var __defProp = Object.defineProperty;
|
|
4
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
6
|
var __export = (target, all) => {
|
|
9
7
|
for (var name in all)
|
|
@@ -17,14 +15,6 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
17
15
|
}
|
|
18
16
|
return to;
|
|
19
17
|
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
19
|
|
|
30
20
|
// ../bitfab-typescript-transform/src/swcAdapter.ts
|
|
@@ -35,8 +25,8 @@ __export(swcAdapter_exports, {
|
|
|
35
25
|
});
|
|
36
26
|
module.exports = __toCommonJS(swcAdapter_exports);
|
|
37
27
|
|
|
38
|
-
// ../bitfab-typescript-transform/src/
|
|
39
|
-
var
|
|
28
|
+
// ../bitfab-typescript-transform/src/transform.ts
|
|
29
|
+
var import_core = require("@babel/core");
|
|
40
30
|
|
|
41
31
|
// ../bitfab-typescript-transform/src/transformOptions.ts
|
|
42
32
|
var AUTO_TRACE_FUNCTION_ID_VERSION = "ts-auto-v1";
|
|
@@ -44,6 +34,14 @@ var AUTO_TRACE_TRANSFORM_MARKER = "__bitfab_auto_trace_transformed_v1__";
|
|
|
44
34
|
function autoTraceFunctionId(file, name) {
|
|
45
35
|
return `${AUTO_TRACE_FUNCTION_ID_VERSION}:${file}#${name}`;
|
|
46
36
|
}
|
|
37
|
+
function sourceFilename(filename) {
|
|
38
|
+
return filename.replace(/\\/g, "/").split(/[?#]/, 1)[0] ?? "";
|
|
39
|
+
}
|
|
40
|
+
function autoTraceFilename(filename, cwd) {
|
|
41
|
+
const normalized = sourceFilename(filename);
|
|
42
|
+
const normalizedCwd = cwd.replace(/\\/g, "/").replace(/\/$/, "");
|
|
43
|
+
return normalized.startsWith(`${normalizedCwd}/`) ? normalized.slice(normalizedCwd.length + 1) : normalized;
|
|
44
|
+
}
|
|
47
45
|
function shouldTransformBitfabFile(filename, options) {
|
|
48
46
|
if (!filename) {
|
|
49
47
|
return false;
|
|
@@ -51,7 +49,7 @@ function shouldTransformBitfabFile(filename, options) {
|
|
|
51
49
|
if (options.include && !options.include(filename)) {
|
|
52
50
|
return false;
|
|
53
51
|
}
|
|
54
|
-
const normalized = filename
|
|
52
|
+
const normalized = sourceFilename(filename);
|
|
55
53
|
const normalizedCwd = options.cwd?.replace(/\\/g, "/").replace(/\/$/, "");
|
|
56
54
|
const isAbsolute = normalized.startsWith("/") || /^[A-Za-z]:\//.test(normalized);
|
|
57
55
|
if (normalizedCwd && isAbsolute && normalized !== normalizedCwd && !normalized.startsWith(`${normalizedCwd}/`)) {
|
|
@@ -60,529 +58,462 @@ function shouldTransformBitfabFile(filename, options) {
|
|
|
60
58
|
return !normalized.includes("/node_modules/") && !normalized.endsWith(".d.ts") && /\.[cm]?[jt]sx?$/.test(normalized);
|
|
61
59
|
}
|
|
62
60
|
|
|
63
|
-
// ../bitfab-typescript-transform/src/
|
|
64
|
-
function
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
(declaration) => import_typescript.default.isIdentifier(declaration.name) && declaration.name.text === AUTO_TRACE_TRANSFORM_MARKER
|
|
73
|
-
)
|
|
74
|
-
);
|
|
75
|
-
}
|
|
76
|
-
function isBitfabMemberCall(node, memberName) {
|
|
77
|
-
return import_typescript.default.isCallExpression(node) && import_typescript.default.isPropertyAccessExpression(node.expression) && node.expression.name.text === memberName;
|
|
61
|
+
// ../bitfab-typescript-transform/src/babelPlugin.ts
|
|
62
|
+
function propertyName(node, types) {
|
|
63
|
+
if (types.isIdentifier(node)) {
|
|
64
|
+
return node.name;
|
|
65
|
+
}
|
|
66
|
+
if (types.isStringLiteral(node)) {
|
|
67
|
+
return node.value;
|
|
68
|
+
}
|
|
69
|
+
return null;
|
|
78
70
|
}
|
|
79
|
-
function
|
|
80
|
-
|
|
81
|
-
|
|
71
|
+
function functionName(path, types) {
|
|
72
|
+
const node = path.node;
|
|
73
|
+
if (types.isFunctionDeclaration(node) || types.isFunctionExpression(node)) {
|
|
74
|
+
if (node.id) {
|
|
75
|
+
return node.id.name;
|
|
76
|
+
}
|
|
82
77
|
}
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
return fn.text;
|
|
78
|
+
if ((types.isClassMethod(node) || types.isObjectMethod(node)) && !node.computed && types.isIdentifier(node.key)) {
|
|
79
|
+
return node.key.name;
|
|
86
80
|
}
|
|
87
|
-
|
|
88
|
-
|
|
81
|
+
const parent = path.parentPath?.node;
|
|
82
|
+
if (types.isVariableDeclarator(parent)) {
|
|
83
|
+
return propertyName(parent.id, types) ?? "anonymous";
|
|
89
84
|
}
|
|
90
|
-
if (
|
|
91
|
-
return
|
|
85
|
+
if (types.isObjectProperty(parent) && !parent.computed) {
|
|
86
|
+
return propertyName(parent.key, types) ?? "anonymous";
|
|
92
87
|
}
|
|
93
|
-
|
|
88
|
+
const { line, column } = sourcePosition(path);
|
|
89
|
+
return `anonymous-${line}-${column}`;
|
|
94
90
|
}
|
|
95
|
-
function
|
|
96
|
-
if (
|
|
97
|
-
return
|
|
91
|
+
function isInstrumentableFunction(node, types) {
|
|
92
|
+
if (node.generator || types.isClassPrivateMethod(node)) {
|
|
93
|
+
return false;
|
|
98
94
|
}
|
|
99
|
-
return
|
|
95
|
+
return !(types.isClassMethod(node) || types.isObjectMethod(node)) || node.kind === "method";
|
|
100
96
|
}
|
|
101
|
-
function
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
97
|
+
function sourcePosition(path) {
|
|
98
|
+
const exportDeclaration = path.parentPath?.isExportDeclaration() ? path.parentPath.node : void 0;
|
|
99
|
+
const start = (exportDeclaration ?? path.node).loc?.start;
|
|
100
|
+
return { line: start?.line ?? 0, column: start?.column ?? 0 };
|
|
105
101
|
}
|
|
106
|
-
function
|
|
107
|
-
const
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
102
|
+
function qualifiedFunctionName(path, types) {
|
|
103
|
+
const ownName = functionName(path, types);
|
|
104
|
+
if (ownName.startsWith("anonymous-")) {
|
|
105
|
+
return ownName;
|
|
106
|
+
}
|
|
107
|
+
const scopes = [];
|
|
108
|
+
let ancestor = path.parentPath;
|
|
109
|
+
while (ancestor) {
|
|
110
|
+
if (ancestor.isFunction()) {
|
|
111
|
+
if (!isInstrumentableFunction(ancestor.node, types)) {
|
|
112
|
+
ancestor = ancestor.parentPath;
|
|
113
|
+
continue;
|
|
114
|
+
}
|
|
115
|
+
const name = functionName(
|
|
116
|
+
ancestor,
|
|
117
|
+
types
|
|
118
|
+
);
|
|
119
|
+
if (!name.startsWith("anonymous-")) {
|
|
120
|
+
scopes.unshift(name);
|
|
121
|
+
}
|
|
122
|
+
} else if ((ancestor.isClassDeclaration() || ancestor.isClassExpression()) && ancestor.node.id) {
|
|
123
|
+
scopes.unshift(ancestor.node.id.name);
|
|
124
|
+
} else if (ancestor.isObjectExpression()) {
|
|
125
|
+
const parent = ancestor.parentPath?.node;
|
|
126
|
+
if (types.isVariableDeclarator(parent)) {
|
|
127
|
+
const name = propertyName(parent.id, types);
|
|
128
|
+
if (name) {
|
|
129
|
+
scopes.unshift(name);
|
|
130
|
+
}
|
|
131
|
+
} else if (types.isObjectProperty(parent) && !parent.computed) {
|
|
132
|
+
const name = propertyName(parent.key, types);
|
|
133
|
+
if (name) {
|
|
134
|
+
scopes.unshift(name);
|
|
135
|
+
}
|
|
116
136
|
}
|
|
117
137
|
}
|
|
118
|
-
|
|
138
|
+
ancestor = ancestor.parentPath;
|
|
119
139
|
}
|
|
120
|
-
|
|
121
|
-
return { inlineRoots, referencedRoots };
|
|
140
|
+
return [...scopes, ownName].join(".");
|
|
122
141
|
}
|
|
123
|
-
function
|
|
124
|
-
|
|
125
|
-
|
|
142
|
+
function isTraceDecoratorRoot(path, types) {
|
|
143
|
+
const node = path.node;
|
|
144
|
+
if (!types.isClassMethod(node) && !types.isClassPrivateMethod(node)) {
|
|
145
|
+
return false;
|
|
126
146
|
}
|
|
127
|
-
|
|
128
|
-
|
|
147
|
+
return node.decorators?.some((decorator) => {
|
|
148
|
+
const expression = decorator.expression;
|
|
149
|
+
if (!types.isCallExpression(expression)) {
|
|
150
|
+
return false;
|
|
151
|
+
}
|
|
152
|
+
const callee = expression.callee;
|
|
153
|
+
return types.isMemberExpression(callee) && !callee.computed && types.isIdentifier(callee.property, { name: "trace" });
|
|
154
|
+
}) ?? false;
|
|
155
|
+
}
|
|
156
|
+
function isBitfabWrapperArgument(path, types) {
|
|
157
|
+
const parent = path.parentPath?.node;
|
|
158
|
+
if (!types.isCallExpression(parent)) {
|
|
159
|
+
return false;
|
|
129
160
|
}
|
|
130
|
-
if (
|
|
131
|
-
return
|
|
161
|
+
if (!parent.arguments.some((argument) => argument === path.node)) {
|
|
162
|
+
return false;
|
|
132
163
|
}
|
|
133
|
-
|
|
164
|
+
const callee = parent.callee;
|
|
165
|
+
return types.isMemberExpression(callee) && !callee.computed && types.isIdentifier(callee.property) && (callee.property.name === "withTrace" || callee.property.name === "withSpan");
|
|
134
166
|
}
|
|
135
|
-
function
|
|
136
|
-
if (
|
|
137
|
-
return
|
|
167
|
+
function withNodeFunctionName(path, types) {
|
|
168
|
+
if (path.node.arguments.length > 2) {
|
|
169
|
+
return null;
|
|
170
|
+
}
|
|
171
|
+
const callee = path.node.callee;
|
|
172
|
+
if (!types.isMemberExpression(callee) || callee.computed || !types.isIdentifier(callee.property, { name: "withNode" })) {
|
|
173
|
+
return null;
|
|
174
|
+
}
|
|
175
|
+
const fn = path.node.arguments[path.node.arguments.length - 1];
|
|
176
|
+
if (types.isIdentifier(fn)) {
|
|
177
|
+
return fn.name;
|
|
178
|
+
}
|
|
179
|
+
if (types.isMemberExpression(fn) && !fn.computed) {
|
|
180
|
+
return propertyName(fn.property, types);
|
|
138
181
|
}
|
|
139
|
-
if (
|
|
140
|
-
return
|
|
182
|
+
if (types.isFunctionExpression(fn) && fn.id) {
|
|
183
|
+
return fn.id.name;
|
|
141
184
|
}
|
|
142
185
|
return null;
|
|
143
186
|
}
|
|
144
|
-
function
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
const scopes = [];
|
|
148
|
-
let ancestor = node.parent;
|
|
149
|
-
while (ancestor) {
|
|
150
|
-
if (isInstrumentableFunction(ancestor)) {
|
|
151
|
-
const name = declaredFunctionName(ancestor);
|
|
152
|
-
if (name) {
|
|
153
|
-
scopes.unshift(name);
|
|
154
|
-
}
|
|
155
|
-
} else if ((import_typescript.default.isClassDeclaration(ancestor) || import_typescript.default.isClassExpression(ancestor)) && ancestor.name) {
|
|
156
|
-
scopes.unshift(ancestor.name.text);
|
|
157
|
-
} else if (import_typescript.default.isObjectLiteralExpression(ancestor)) {
|
|
158
|
-
const name = objectContainerName(ancestor);
|
|
159
|
-
if (name) {
|
|
160
|
-
scopes.unshift(name);
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
ancestor = ancestor.parent;
|
|
164
|
-
}
|
|
165
|
-
return [...scopes, ownName].join(".");
|
|
187
|
+
function functionBindingName(path, types) {
|
|
188
|
+
if (types.isFunctionDeclaration(path.node) && path.node.id) {
|
|
189
|
+
return path.node.id.name;
|
|
166
190
|
}
|
|
167
|
-
const
|
|
168
|
-
|
|
169
|
-
|
|
191
|
+
const parent = path.parentPath?.node;
|
|
192
|
+
if (types.isVariableDeclarator(parent) && types.isIdentifier(parent.id)) {
|
|
193
|
+
return parent.id.name;
|
|
194
|
+
}
|
|
195
|
+
return null;
|
|
170
196
|
}
|
|
171
|
-
function isBitfabWrappedFunction(
|
|
172
|
-
if (
|
|
197
|
+
function isBitfabWrappedFunction(path, types) {
|
|
198
|
+
if (isBitfabWrapperArgument(path, types)) {
|
|
173
199
|
return true;
|
|
174
200
|
}
|
|
175
|
-
const
|
|
176
|
-
|
|
177
|
-
}
|
|
178
|
-
function isInstrumentableFunction(node) {
|
|
179
|
-
if (!import_typescript.default.isFunctionDeclaration(node) && !import_typescript.default.isFunctionExpression(node) && !import_typescript.default.isArrowFunction(node) && !import_typescript.default.isMethodDeclaration(node)) {
|
|
201
|
+
const bindingName = functionBindingName(path, types);
|
|
202
|
+
if (!bindingName) {
|
|
180
203
|
return false;
|
|
181
204
|
}
|
|
182
|
-
|
|
205
|
+
const binding = path.scope.getBinding(bindingName);
|
|
206
|
+
return binding?.referencePaths.some(
|
|
207
|
+
(referencePath) => isBitfabWrapperArgument(referencePath, types)
|
|
208
|
+
) ?? false;
|
|
183
209
|
}
|
|
184
|
-
function
|
|
185
|
-
|
|
186
|
-
const normalizedCwd = cwd.replace(/\\/g, "/").replace(/\/$/, "");
|
|
187
|
-
return normalized.startsWith(`${normalizedCwd}/`) ? normalized.slice(normalizedCwd.length + 1) : normalized;
|
|
210
|
+
function isBitfabManagedFunction(path, types) {
|
|
211
|
+
return isTraceDecoratorRoot(path, types) || isBitfabWrappedFunction(path, types);
|
|
188
212
|
}
|
|
189
|
-
function
|
|
190
|
-
return
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
213
|
+
function runtimeParameters(node, types) {
|
|
214
|
+
return node.params.filter(
|
|
215
|
+
(parameter) => !types.isIdentifier(parameter, { name: "this" })
|
|
216
|
+
);
|
|
217
|
+
}
|
|
218
|
+
function parameterInputs(path, types) {
|
|
219
|
+
const elements = [];
|
|
220
|
+
for (const [index, parameter] of runtimeParameters(
|
|
221
|
+
path.node,
|
|
222
|
+
types
|
|
223
|
+
).entries()) {
|
|
224
|
+
if (!types.isArrowFunctionExpression(path.node)) {
|
|
225
|
+
if (types.isRestElement(parameter)) {
|
|
226
|
+
elements.push(
|
|
227
|
+
types.spreadElement(
|
|
228
|
+
types.callExpression(
|
|
229
|
+
types.memberExpression(
|
|
230
|
+
types.arrayExpression([
|
|
231
|
+
types.spreadElement(types.identifier("arguments"))
|
|
201
232
|
]),
|
|
202
|
-
"slice"
|
|
233
|
+
types.identifier("slice")
|
|
203
234
|
),
|
|
204
|
-
|
|
205
|
-
[factory.createNumericLiteral(index)]
|
|
235
|
+
[types.numericLiteral(index)]
|
|
206
236
|
)
|
|
207
|
-
)
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
237
|
+
)
|
|
238
|
+
);
|
|
239
|
+
} else {
|
|
240
|
+
elements.push(
|
|
241
|
+
types.memberExpression(
|
|
242
|
+
types.identifier("arguments"),
|
|
243
|
+
types.numericLiteral(index),
|
|
244
|
+
true
|
|
245
|
+
)
|
|
212
246
|
);
|
|
213
247
|
}
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
248
|
+
continue;
|
|
249
|
+
}
|
|
250
|
+
if (types.isIdentifier(parameter)) {
|
|
251
|
+
elements.push(types.identifier(parameter.name));
|
|
252
|
+
} else if (types.isRestElement(parameter) && types.isIdentifier(parameter.argument)) {
|
|
253
|
+
elements.push(
|
|
254
|
+
types.spreadElement(types.identifier(parameter.argument.name))
|
|
220
255
|
);
|
|
221
|
-
}
|
|
222
|
-
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
return types.arrayExpression(elements);
|
|
223
259
|
}
|
|
224
|
-
function needsArgumentWrapper(
|
|
225
|
-
return
|
|
226
|
-
(parameter) => !
|
|
260
|
+
function needsArgumentWrapper(path, types) {
|
|
261
|
+
return types.isArrowFunctionExpression(path.node) && path.node.params.some(
|
|
262
|
+
(parameter) => !types.isIdentifier(parameter) && !(types.isRestElement(parameter) && types.isIdentifier(parameter.argument))
|
|
227
263
|
);
|
|
228
264
|
}
|
|
229
|
-
function isRestWrapper(
|
|
230
|
-
|
|
265
|
+
function isRestWrapper(path, types) {
|
|
266
|
+
const parameters = runtimeParameters(path.node, types);
|
|
267
|
+
return parameters.length === 1 && types.isRestElement(parameters[0]);
|
|
231
268
|
}
|
|
232
|
-
function
|
|
233
|
-
const
|
|
234
|
-
(statement) => !(import_typescript.default.isExpressionStatement(statement) && import_typescript.default.isStringLiteral(statement.expression))
|
|
235
|
-
);
|
|
236
|
-
if (firstNonDirective === -1) {
|
|
237
|
-
return { directives: body.statements, statements: [] };
|
|
238
|
-
}
|
|
269
|
+
function bitfabBabelPlugin(api) {
|
|
270
|
+
const { types } = api;
|
|
239
271
|
return {
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
node,
|
|
248
|
-
node.modifiers,
|
|
249
|
-
node.asteriskToken,
|
|
250
|
-
node.name,
|
|
251
|
-
node.typeParameters,
|
|
252
|
-
node.parameters,
|
|
253
|
-
node.type,
|
|
254
|
-
body
|
|
255
|
-
);
|
|
256
|
-
}
|
|
257
|
-
if (import_typescript.default.isFunctionExpression(node)) {
|
|
258
|
-
return factory.updateFunctionExpression(
|
|
259
|
-
node,
|
|
260
|
-
node.modifiers,
|
|
261
|
-
node.asteriskToken,
|
|
262
|
-
node.name,
|
|
263
|
-
node.typeParameters,
|
|
264
|
-
node.parameters,
|
|
265
|
-
node.type,
|
|
266
|
-
body
|
|
267
|
-
);
|
|
268
|
-
}
|
|
269
|
-
if (import_typescript.default.isArrowFunction(node)) {
|
|
270
|
-
return factory.updateArrowFunction(
|
|
271
|
-
node,
|
|
272
|
-
node.modifiers,
|
|
273
|
-
node.typeParameters,
|
|
274
|
-
node.parameters,
|
|
275
|
-
node.type,
|
|
276
|
-
node.equalsGreaterThanToken,
|
|
277
|
-
body
|
|
278
|
-
);
|
|
279
|
-
}
|
|
280
|
-
if (import_typescript.default.isMethodDeclaration(node)) {
|
|
281
|
-
return factory.updateMethodDeclaration(
|
|
282
|
-
node,
|
|
283
|
-
node.modifiers,
|
|
284
|
-
node.asteriskToken,
|
|
285
|
-
node.name,
|
|
286
|
-
node.questionToken,
|
|
287
|
-
node.typeParameters,
|
|
288
|
-
node.parameters,
|
|
289
|
-
node.type,
|
|
290
|
-
body
|
|
291
|
-
);
|
|
292
|
-
}
|
|
293
|
-
return node;
|
|
294
|
-
}
|
|
295
|
-
function createBitfabTypeScriptTransformer(options = {}) {
|
|
296
|
-
return (context) => (sourceFile) => {
|
|
297
|
-
if (hasUseClientDirective(sourceFile) || hasTransformMarker(sourceFile) || !shouldTransformBitfabFile(sourceFile.fileName, options)) {
|
|
298
|
-
return sourceFile;
|
|
299
|
-
}
|
|
300
|
-
const { factory } = context;
|
|
301
|
-
const { inlineRoots, referencedRoots } = collectBitfabWrappedFunctions(sourceFile);
|
|
302
|
-
const runtimeIdentifier = factory.createUniqueName("bitfabAutoSpan");
|
|
303
|
-
const activeIdentifier = factory.createUniqueName("bitfabAutoTraceActive");
|
|
304
|
-
const wrapperIdentifier = factory.createUniqueName("bitfabAutoWrap");
|
|
305
|
-
const transformedNodes = /* @__PURE__ */ new Set();
|
|
306
|
-
const definitions = [];
|
|
307
|
-
let usedRuntime = false;
|
|
308
|
-
let usedWrapper = false;
|
|
309
|
-
const cwd = options.cwd ?? process.cwd();
|
|
310
|
-
const file = normalizedFilename(sourceFile.fileName, cwd);
|
|
311
|
-
const visitor = (node) => {
|
|
312
|
-
const visited = import_typescript.default.visitEachChild(node, visitor, context);
|
|
313
|
-
if (import_typescript.default.isCallExpression(node) && import_typescript.default.isCallExpression(visited)) {
|
|
314
|
-
const configuredName = withNodeFunctionName(node);
|
|
315
|
-
if (configuredName !== null) {
|
|
316
|
-
const args = [...visited.arguments];
|
|
317
|
-
if (args.length === 1) {
|
|
318
|
-
args.push(factory.createIdentifier("undefined"));
|
|
319
|
-
}
|
|
320
|
-
args.push(factory.createStringLiteral(configuredName));
|
|
321
|
-
return factory.updateCallExpression(
|
|
322
|
-
visited,
|
|
323
|
-
visited.expression,
|
|
324
|
-
visited.typeArguments,
|
|
325
|
-
args
|
|
272
|
+
name: "bitfab-auto-trace",
|
|
273
|
+
visitor: {
|
|
274
|
+
Program: {
|
|
275
|
+
enter(path, state) {
|
|
276
|
+
const filename = state.file.opts.filename ?? "unknown";
|
|
277
|
+
state.skipFile = !shouldTransformBitfabFile(filename, state.opts) || path.scope.hasBinding(AUTO_TRACE_TRANSFORM_MARKER) || path.node.directives.some(
|
|
278
|
+
(directive) => directive.value.value === "use client"
|
|
326
279
|
);
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
"id",
|
|
344
|
-
factory.createStringLiteral(autoTraceFunctionId(file, name))
|
|
345
|
-
),
|
|
346
|
-
factory.createPropertyAssignment(
|
|
347
|
-
"name",
|
|
348
|
-
factory.createStringLiteral(name)
|
|
349
|
-
),
|
|
350
|
-
factory.createPropertyAssignment(
|
|
351
|
-
"file",
|
|
352
|
-
factory.createStringLiteral(file)
|
|
353
|
-
),
|
|
354
|
-
factory.createPropertyAssignment(
|
|
355
|
-
"line",
|
|
356
|
-
factory.createNumericLiteral(position.line + 1)
|
|
357
|
-
),
|
|
358
|
-
factory.createPropertyAssignment(
|
|
359
|
-
"column",
|
|
360
|
-
factory.createNumericLiteral(position.character)
|
|
361
|
-
),
|
|
362
|
-
...node.modifiers?.some(
|
|
363
|
-
(modifier) => modifier.kind === import_typescript.default.SyntaxKind.AsyncKeyword
|
|
364
|
-
) ? [factory.createPropertyAssignment("async", factory.createTrue())] : [],
|
|
365
|
-
...isRestWrapper(node) ? [
|
|
366
|
-
factory.createPropertyAssignment(
|
|
367
|
-
"wrapper",
|
|
368
|
-
factory.createTrue()
|
|
369
|
-
)
|
|
370
|
-
] : []
|
|
371
|
-
],
|
|
372
|
-
false
|
|
373
|
-
);
|
|
374
|
-
const definitionIdentifier = factory.createUniqueName(
|
|
375
|
-
"bitfabAutoDefinition"
|
|
376
|
-
);
|
|
377
|
-
definitions.push(
|
|
378
|
-
factory.createVariableStatement(
|
|
379
|
-
void 0,
|
|
380
|
-
factory.createVariableDeclarationList(
|
|
381
|
-
[
|
|
382
|
-
factory.createVariableDeclaration(
|
|
383
|
-
definitionIdentifier,
|
|
384
|
-
void 0,
|
|
385
|
-
void 0,
|
|
386
|
-
definition
|
|
387
|
-
)
|
|
388
|
-
],
|
|
389
|
-
import_typescript.default.NodeFlags.Const
|
|
390
|
-
)
|
|
391
|
-
)
|
|
392
|
-
);
|
|
393
|
-
if (needsArgumentWrapper(visited)) {
|
|
394
|
-
usedRuntime = true;
|
|
395
|
-
usedWrapper = true;
|
|
396
|
-
return factory.createCallExpression(wrapperIdentifier, void 0, [
|
|
397
|
-
definitionIdentifier,
|
|
398
|
-
visited
|
|
399
|
-
]);
|
|
400
|
-
}
|
|
401
|
-
const visitedBody = visited.body;
|
|
402
|
-
const originalBody = import_typescript.default.isBlock(visitedBody) ? visitedBody : factory.createBlock(
|
|
403
|
-
[factory.createReturnStatement(visitedBody)],
|
|
404
|
-
true
|
|
405
|
-
);
|
|
406
|
-
const { directives, statements } = splitDirectivePrologue(originalBody);
|
|
407
|
-
const invoke = factory.createArrowFunction(
|
|
408
|
-
hasAsyncModifier(node) ? [factory.createModifier(import_typescript.default.SyntaxKind.AsyncKeyword)] : void 0,
|
|
409
|
-
void 0,
|
|
410
|
-
[],
|
|
411
|
-
void 0,
|
|
412
|
-
factory.createToken(import_typescript.default.SyntaxKind.EqualsGreaterThanToken),
|
|
413
|
-
factory.updateBlock(originalBody, statements)
|
|
414
|
-
);
|
|
415
|
-
const body = factory.createBlock(
|
|
416
|
-
[
|
|
417
|
-
...directives,
|
|
418
|
-
factory.createIfStatement(
|
|
419
|
-
factory.createCallExpression(activeIdentifier, void 0, []),
|
|
420
|
-
factory.createBlock(
|
|
280
|
+
state.runtimeIdentifier = path.scope.generateUidIdentifier("bitfabAutoSpan");
|
|
281
|
+
state.activeIdentifier = path.scope.generateUidIdentifier(
|
|
282
|
+
"bitfabAutoTraceActive"
|
|
283
|
+
);
|
|
284
|
+
state.wrapperIdentifier = path.scope.generateUidIdentifier("bitfabAutoWrap");
|
|
285
|
+
state.definitions = [];
|
|
286
|
+
state.usedRuntime = false;
|
|
287
|
+
state.usedWrapper = false;
|
|
288
|
+
},
|
|
289
|
+
exit(path, state) {
|
|
290
|
+
if (state.skipFile || !state.usedRuntime || !state.runtimeIdentifier || !state.activeIdentifier || !state.wrapperIdentifier) {
|
|
291
|
+
return;
|
|
292
|
+
}
|
|
293
|
+
state.file.metadata[AUTO_TRACE_TRANSFORM_MARKER] = true;
|
|
294
|
+
path.unshiftContainer("body", [
|
|
295
|
+
types.importDeclaration(
|
|
421
296
|
[
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
parameterInputs(factory, visited),
|
|
426
|
-
invoke
|
|
427
|
-
])
|
|
428
|
-
)
|
|
429
|
-
],
|
|
430
|
-
true
|
|
431
|
-
)
|
|
432
|
-
),
|
|
433
|
-
...statements
|
|
434
|
-
],
|
|
435
|
-
true
|
|
436
|
-
);
|
|
437
|
-
const updated = updateFunctionBody(factory, visited, body);
|
|
438
|
-
transformedNodes.add(updated);
|
|
439
|
-
usedRuntime = true;
|
|
440
|
-
return updated;
|
|
441
|
-
};
|
|
442
|
-
const transformed = import_typescript.default.visitEachChild(sourceFile, visitor, context);
|
|
443
|
-
if (!usedRuntime) {
|
|
444
|
-
return transformed;
|
|
445
|
-
}
|
|
446
|
-
const runtimeImport = factory.createImportDeclaration(
|
|
447
|
-
void 0,
|
|
448
|
-
factory.createImportClause(
|
|
449
|
-
false,
|
|
450
|
-
void 0,
|
|
451
|
-
factory.createNamedImports([
|
|
452
|
-
factory.createImportSpecifier(
|
|
453
|
-
false,
|
|
454
|
-
factory.createIdentifier("__bitfabAutoSpan"),
|
|
455
|
-
runtimeIdentifier
|
|
456
|
-
),
|
|
457
|
-
factory.createImportSpecifier(
|
|
458
|
-
false,
|
|
459
|
-
factory.createIdentifier("__bitfabAutoTraceActive"),
|
|
460
|
-
activeIdentifier
|
|
461
|
-
),
|
|
462
|
-
...usedWrapper ? [
|
|
463
|
-
factory.createImportSpecifier(
|
|
464
|
-
false,
|
|
465
|
-
factory.createIdentifier("__bitfabAutoWrap"),
|
|
466
|
-
wrapperIdentifier
|
|
467
|
-
)
|
|
468
|
-
] : []
|
|
469
|
-
])
|
|
470
|
-
),
|
|
471
|
-
factory.createStringLiteral(options.runtimeModule ?? "@bitfab/sdk/auto")
|
|
472
|
-
);
|
|
473
|
-
const transformMarker = factory.createVariableStatement(
|
|
474
|
-
void 0,
|
|
475
|
-
factory.createVariableDeclarationList(
|
|
476
|
-
[
|
|
477
|
-
factory.createVariableDeclaration(
|
|
478
|
-
factory.createIdentifier(AUTO_TRACE_TRANSFORM_MARKER),
|
|
479
|
-
void 0,
|
|
480
|
-
void 0,
|
|
481
|
-
factory.createAssignment(
|
|
482
|
-
factory.createPropertyAccessExpression(
|
|
483
|
-
factory.createIdentifier("globalThis"),
|
|
484
|
-
factory.createIdentifier(AUTO_TRACE_TRANSFORM_MARKER)
|
|
485
|
-
),
|
|
486
|
-
factory.createTrue()
|
|
487
|
-
)
|
|
488
|
-
)
|
|
489
|
-
],
|
|
490
|
-
import_typescript.default.NodeFlags.Const
|
|
491
|
-
)
|
|
492
|
-
);
|
|
493
|
-
return factory.updateSourceFile(transformed, [
|
|
494
|
-
context.getCompilerOptions().module === import_typescript.default.ModuleKind.CommonJS ? factory.createVariableStatement(
|
|
495
|
-
void 0,
|
|
496
|
-
factory.createVariableDeclarationList(
|
|
497
|
-
[
|
|
498
|
-
factory.createVariableDeclaration(
|
|
499
|
-
factory.createObjectBindingPattern([
|
|
500
|
-
factory.createBindingElement(
|
|
501
|
-
void 0,
|
|
502
|
-
"__bitfabAutoSpan",
|
|
503
|
-
runtimeIdentifier
|
|
297
|
+
types.importSpecifier(
|
|
298
|
+
state.runtimeIdentifier,
|
|
299
|
+
types.identifier("__bitfabAutoSpan")
|
|
504
300
|
),
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
"__bitfabAutoTraceActive"
|
|
508
|
-
activeIdentifier
|
|
301
|
+
types.importSpecifier(
|
|
302
|
+
state.activeIdentifier,
|
|
303
|
+
types.identifier("__bitfabAutoTraceActive")
|
|
509
304
|
),
|
|
510
|
-
...usedWrapper ? [
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
"__bitfabAutoWrap"
|
|
514
|
-
wrapperIdentifier
|
|
305
|
+
...state.usedWrapper ? [
|
|
306
|
+
types.importSpecifier(
|
|
307
|
+
state.wrapperIdentifier,
|
|
308
|
+
types.identifier("__bitfabAutoWrap")
|
|
515
309
|
)
|
|
516
310
|
] : []
|
|
517
|
-
]
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
factory.createCallExpression(
|
|
521
|
-
factory.createIdentifier("require"),
|
|
522
|
-
void 0,
|
|
523
|
-
[
|
|
524
|
-
factory.createStringLiteral(
|
|
525
|
-
options.runtimeModule ?? "@bitfab/sdk/auto"
|
|
526
|
-
)
|
|
527
|
-
]
|
|
311
|
+
],
|
|
312
|
+
types.stringLiteral(
|
|
313
|
+
state.opts.runtimeModule ?? "@bitfab/sdk/auto"
|
|
528
314
|
)
|
|
529
|
-
)
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
315
|
+
),
|
|
316
|
+
types.variableDeclaration("const", [
|
|
317
|
+
types.variableDeclarator(
|
|
318
|
+
types.identifier(AUTO_TRACE_TRANSFORM_MARKER),
|
|
319
|
+
types.assignmentExpression(
|
|
320
|
+
"=",
|
|
321
|
+
types.memberExpression(
|
|
322
|
+
types.identifier("globalThis"),
|
|
323
|
+
types.identifier(AUTO_TRACE_TRANSFORM_MARKER)
|
|
324
|
+
),
|
|
325
|
+
types.booleanLiteral(true)
|
|
326
|
+
)
|
|
327
|
+
)
|
|
328
|
+
]),
|
|
329
|
+
...state.definitions ?? []
|
|
330
|
+
]);
|
|
331
|
+
}
|
|
332
|
+
},
|
|
333
|
+
CallExpression: {
|
|
334
|
+
exit(path, state) {
|
|
335
|
+
if (state.skipFile) {
|
|
336
|
+
return;
|
|
337
|
+
}
|
|
338
|
+
const configuredName = withNodeFunctionName(path, types);
|
|
339
|
+
if (configuredName === null) {
|
|
340
|
+
return;
|
|
341
|
+
}
|
|
342
|
+
if (path.node.arguments.length === 1) {
|
|
343
|
+
path.node.arguments.push(types.identifier("undefined"));
|
|
344
|
+
}
|
|
345
|
+
path.node.arguments.push(types.stringLiteral(configuredName));
|
|
346
|
+
}
|
|
347
|
+
},
|
|
348
|
+
Function: {
|
|
349
|
+
exit(path, state) {
|
|
350
|
+
const node = path.node;
|
|
351
|
+
if (state.skipFile || node._bitfabInstrumented || !isInstrumentableFunction(node, types) || isBitfabManagedFunction(path, types) || !state.runtimeIdentifier || !state.activeIdentifier || !state.wrapperIdentifier) {
|
|
352
|
+
return;
|
|
353
|
+
}
|
|
354
|
+
const name = qualifiedFunctionName(path, types);
|
|
355
|
+
if (name.startsWith("anonymous-")) {
|
|
356
|
+
return;
|
|
357
|
+
}
|
|
358
|
+
const normalizedFilename = autoTraceFilename(
|
|
359
|
+
state.file.opts.filename ?? "unknown",
|
|
360
|
+
state.opts.cwd ?? state.file.opts.cwd ?? process.cwd()
|
|
361
|
+
);
|
|
362
|
+
const { line, column } = sourcePosition(path);
|
|
363
|
+
const definition = types.objectExpression([
|
|
364
|
+
types.objectProperty(
|
|
365
|
+
types.identifier("id"),
|
|
366
|
+
types.stringLiteral(
|
|
367
|
+
autoTraceFunctionId(normalizedFilename, name)
|
|
368
|
+
)
|
|
369
|
+
),
|
|
370
|
+
types.objectProperty(
|
|
371
|
+
types.identifier("name"),
|
|
372
|
+
types.stringLiteral(name)
|
|
373
|
+
),
|
|
374
|
+
types.objectProperty(
|
|
375
|
+
types.identifier("file"),
|
|
376
|
+
types.stringLiteral(normalizedFilename)
|
|
377
|
+
),
|
|
378
|
+
types.objectProperty(
|
|
379
|
+
types.identifier("line"),
|
|
380
|
+
types.numericLiteral(line)
|
|
381
|
+
),
|
|
382
|
+
types.objectProperty(
|
|
383
|
+
types.identifier("column"),
|
|
384
|
+
types.numericLiteral(column)
|
|
385
|
+
),
|
|
386
|
+
...node.async ? [
|
|
387
|
+
types.objectProperty(
|
|
388
|
+
types.identifier("async"),
|
|
389
|
+
types.booleanLiteral(true)
|
|
390
|
+
)
|
|
391
|
+
] : [],
|
|
392
|
+
...isRestWrapper(path, types) ? [
|
|
393
|
+
types.objectProperty(
|
|
394
|
+
types.identifier("wrapper"),
|
|
395
|
+
types.booleanLiteral(true)
|
|
396
|
+
)
|
|
397
|
+
] : []
|
|
398
|
+
]);
|
|
399
|
+
const definitionIdentifier = path.scope.getProgramParent().generateUidIdentifier("bitfabAutoDefinition");
|
|
400
|
+
state.definitions?.push(
|
|
401
|
+
types.variableDeclaration("const", [
|
|
402
|
+
types.variableDeclarator(definitionIdentifier, definition)
|
|
403
|
+
])
|
|
404
|
+
);
|
|
405
|
+
if (needsArgumentWrapper(path, types)) {
|
|
406
|
+
node._bitfabInstrumented = true;
|
|
407
|
+
path.replaceWith(
|
|
408
|
+
types.callExpression(types.cloneNode(state.wrapperIdentifier), [
|
|
409
|
+
types.cloneNode(definitionIdentifier),
|
|
410
|
+
node
|
|
411
|
+
])
|
|
412
|
+
);
|
|
413
|
+
state.usedRuntime = true;
|
|
414
|
+
state.usedWrapper = true;
|
|
415
|
+
return;
|
|
416
|
+
}
|
|
417
|
+
const originalBody = types.isBlockStatement(node.body) ? node.body : types.blockStatement([types.returnStatement(node.body)]);
|
|
418
|
+
const directives = originalBody.directives;
|
|
419
|
+
originalBody.directives = [];
|
|
420
|
+
const body = types.blockStatement(
|
|
421
|
+
[
|
|
422
|
+
types.ifStatement(
|
|
423
|
+
types.callExpression(
|
|
424
|
+
types.cloneNode(state.activeIdentifier),
|
|
425
|
+
[]
|
|
426
|
+
),
|
|
427
|
+
types.blockStatement([
|
|
428
|
+
types.returnStatement(
|
|
429
|
+
types.callExpression(
|
|
430
|
+
types.cloneNode(state.runtimeIdentifier),
|
|
431
|
+
[
|
|
432
|
+
types.cloneNode(definitionIdentifier),
|
|
433
|
+
parameterInputs(path, types),
|
|
434
|
+
types.arrowFunctionExpression(
|
|
435
|
+
[],
|
|
436
|
+
types.cloneNode(originalBody, true),
|
|
437
|
+
node.async ?? false
|
|
438
|
+
)
|
|
439
|
+
]
|
|
440
|
+
)
|
|
441
|
+
)
|
|
442
|
+
])
|
|
443
|
+
),
|
|
444
|
+
...originalBody.body
|
|
445
|
+
],
|
|
446
|
+
directives
|
|
447
|
+
);
|
|
448
|
+
node.body = body;
|
|
449
|
+
node._bitfabInstrumented = true;
|
|
450
|
+
state.usedRuntime = true;
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
}
|
|
538
454
|
};
|
|
539
455
|
}
|
|
540
|
-
|
|
541
|
-
|
|
456
|
+
|
|
457
|
+
// ../bitfab-typescript-transform/src/transform.ts
|
|
458
|
+
function parserPlugins(filename) {
|
|
459
|
+
const path = sourceFilename(filename);
|
|
460
|
+
const typescript = /\.[cm]?tsx?$/.test(path);
|
|
461
|
+
const jsx = /\.tsx$/.test(path) || /\.[cm]?jsx?$/.test(path);
|
|
462
|
+
return [
|
|
463
|
+
...typescript ? ["typescript"] : [],
|
|
464
|
+
...jsx ? ["jsx"] : [],
|
|
465
|
+
"decorators"
|
|
466
|
+
];
|
|
542
467
|
}
|
|
543
|
-
function
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
sourceFilename,
|
|
547
|
-
source,
|
|
548
|
-
import_typescript.default.ScriptTarget.Latest,
|
|
549
|
-
true,
|
|
550
|
-
sourceFilename.endsWith("x") ? import_typescript.default.ScriptKind.TSX : import_typescript.default.ScriptKind.TS
|
|
551
|
-
);
|
|
552
|
-
const result = import_typescript.default.transform(sourceFile, [
|
|
553
|
-
createBitfabTypeScriptTransformer(options)
|
|
554
|
-
]);
|
|
555
|
-
try {
|
|
556
|
-
return {
|
|
557
|
-
code: import_typescript.default.createPrinter().printFile(result.transformed[0])
|
|
558
|
-
};
|
|
559
|
-
} finally {
|
|
560
|
-
result.dispose();
|
|
468
|
+
function transformBitfabSource(source, filename, options = {}) {
|
|
469
|
+
if (!shouldTransformBitfabFile(filename, options)) {
|
|
470
|
+
return { code: source };
|
|
561
471
|
}
|
|
472
|
+
const result = (0, import_core.transformSync)(source, {
|
|
473
|
+
babelrc: false,
|
|
474
|
+
configFile: false,
|
|
475
|
+
filename: sourceFilename(filename),
|
|
476
|
+
parserOpts: { plugins: parserPlugins(filename), sourceType: "module" },
|
|
477
|
+
plugins: [[bitfabBabelPlugin, options]],
|
|
478
|
+
sourceMaps: true
|
|
479
|
+
});
|
|
480
|
+
if (!result?.code || !result.metadata?.[AUTO_TRACE_TRANSFORM_MARKER]) {
|
|
481
|
+
return { code: source };
|
|
482
|
+
}
|
|
483
|
+
return {
|
|
484
|
+
code: result.code,
|
|
485
|
+
...result.map ? { map: result.map } : {}
|
|
486
|
+
};
|
|
562
487
|
}
|
|
563
488
|
|
|
564
489
|
// ../bitfab-typescript-transform/src/swcAdapter.ts
|
|
490
|
+
function swcOptions(transformed, options) {
|
|
491
|
+
return {
|
|
492
|
+
filename: options.filename,
|
|
493
|
+
...transformed.map && {
|
|
494
|
+
inputSourceMap: JSON.stringify(transformed.map)
|
|
495
|
+
},
|
|
496
|
+
...options.swc
|
|
497
|
+
};
|
|
498
|
+
}
|
|
565
499
|
async function transformWithBitfabSwc(compiler, source, options) {
|
|
566
|
-
const transformed =
|
|
500
|
+
const transformed = transformBitfabSource(
|
|
567
501
|
source,
|
|
568
502
|
options.filename,
|
|
569
503
|
options.bitfab
|
|
570
504
|
);
|
|
571
|
-
return compiler.transform(transformed.code,
|
|
572
|
-
filename: options.filename,
|
|
573
|
-
...options.swc
|
|
574
|
-
});
|
|
505
|
+
return compiler.transform(transformed.code, swcOptions(transformed, options));
|
|
575
506
|
}
|
|
576
507
|
function transformWithBitfabSwcSync(compiler, source, options) {
|
|
577
|
-
const transformed =
|
|
508
|
+
const transformed = transformBitfabSource(
|
|
578
509
|
source,
|
|
579
510
|
options.filename,
|
|
580
511
|
options.bitfab
|
|
581
512
|
);
|
|
582
|
-
return compiler.transformSync(
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
513
|
+
return compiler.transformSync(
|
|
514
|
+
transformed.code,
|
|
515
|
+
swcOptions(transformed, options)
|
|
516
|
+
);
|
|
586
517
|
}
|
|
587
518
|
// Annotate the CommonJS export names for ESM import in node:
|
|
588
519
|
0 && (module.exports = {
|