@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
|
@@ -34,7 +34,12 @@ __export(loaderRuntime_exports, {
|
|
|
34
34
|
});
|
|
35
35
|
module.exports = __toCommonJS(loaderRuntime_exports);
|
|
36
36
|
var import_node_path = require("path");
|
|
37
|
-
var
|
|
37
|
+
var import_core2 = require("@babel/core");
|
|
38
|
+
var import_plugin_proposal_decorators = __toESM(require("@babel/plugin-proposal-decorators"), 1);
|
|
39
|
+
var import_plugin_transform_modules_commonjs = __toESM(require("@babel/plugin-transform-modules-commonjs"), 1);
|
|
40
|
+
var import_plugin_transform_react_jsx = __toESM(require("@babel/plugin-transform-react-jsx"), 1);
|
|
41
|
+
var import_plugin_transform_typescript = __toESM(require("@babel/plugin-transform-typescript"), 1);
|
|
42
|
+
var import_get_tsconfig = require("get-tsconfig");
|
|
38
43
|
|
|
39
44
|
// ../bitfab-typescript-transform/src/transformOptions.ts
|
|
40
45
|
var AUTO_TRACE_FUNCTION_ID_VERSION = "ts-auto-v1";
|
|
@@ -42,6 +47,14 @@ var AUTO_TRACE_TRANSFORM_MARKER = "__bitfab_auto_trace_transformed_v1__";
|
|
|
42
47
|
function autoTraceFunctionId(file, name) {
|
|
43
48
|
return `${AUTO_TRACE_FUNCTION_ID_VERSION}:${file}#${name}`;
|
|
44
49
|
}
|
|
50
|
+
function sourceFilename(filename) {
|
|
51
|
+
return filename.replace(/\\/g, "/").split(/[?#]/, 1)[0] ?? "";
|
|
52
|
+
}
|
|
53
|
+
function autoTraceFilename(filename, cwd) {
|
|
54
|
+
const normalized = sourceFilename(filename);
|
|
55
|
+
const normalizedCwd = cwd.replace(/\\/g, "/").replace(/\/$/, "");
|
|
56
|
+
return normalized.startsWith(`${normalizedCwd}/`) ? normalized.slice(normalizedCwd.length + 1) : normalized;
|
|
57
|
+
}
|
|
45
58
|
function shouldTransformBitfabFile(filename, options) {
|
|
46
59
|
if (!filename) {
|
|
47
60
|
return false;
|
|
@@ -49,7 +62,7 @@ function shouldTransformBitfabFile(filename, options) {
|
|
|
49
62
|
if (options.include && !options.include(filename)) {
|
|
50
63
|
return false;
|
|
51
64
|
}
|
|
52
|
-
const normalized = filename
|
|
65
|
+
const normalized = sourceFilename(filename);
|
|
53
66
|
const normalizedCwd = options.cwd?.replace(/\\/g, "/").replace(/\/$/, "");
|
|
54
67
|
const isAbsolute = normalized.startsWith("/") || /^[A-Za-z]:\//.test(normalized);
|
|
55
68
|
if (normalizedCwd && isAbsolute && normalized !== normalizedCwd && !normalized.startsWith(`${normalizedCwd}/`)) {
|
|
@@ -58,566 +71,503 @@ function shouldTransformBitfabFile(filename, options) {
|
|
|
58
71
|
return !normalized.includes("/node_modules/") && !normalized.endsWith(".d.ts") && /\.[cm]?[jt]sx?$/.test(normalized);
|
|
59
72
|
}
|
|
60
73
|
|
|
61
|
-
// ../bitfab-typescript-transform/src/
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
)
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
return
|
|
70
|
-
(statement) => import_typescript.default.isVariableStatement(statement) && statement.declarationList.declarations.some(
|
|
71
|
-
(declaration) => import_typescript.default.isIdentifier(declaration.name) && declaration.name.text === AUTO_TRACE_TRANSFORM_MARKER
|
|
72
|
-
)
|
|
73
|
-
);
|
|
74
|
-
}
|
|
75
|
-
function isBitfabMemberCall(node, memberName) {
|
|
76
|
-
return import_typescript.default.isCallExpression(node) && import_typescript.default.isPropertyAccessExpression(node.expression) && node.expression.name.text === memberName;
|
|
74
|
+
// ../bitfab-typescript-transform/src/babelPlugin.ts
|
|
75
|
+
function propertyName(node, types) {
|
|
76
|
+
if (types.isIdentifier(node)) {
|
|
77
|
+
return node.name;
|
|
78
|
+
}
|
|
79
|
+
if (types.isStringLiteral(node)) {
|
|
80
|
+
return node.value;
|
|
81
|
+
}
|
|
82
|
+
return null;
|
|
77
83
|
}
|
|
78
|
-
function
|
|
79
|
-
|
|
80
|
-
|
|
84
|
+
function functionName(path, types) {
|
|
85
|
+
const node = path.node;
|
|
86
|
+
if (types.isFunctionDeclaration(node) || types.isFunctionExpression(node)) {
|
|
87
|
+
if (node.id) {
|
|
88
|
+
return node.id.name;
|
|
89
|
+
}
|
|
81
90
|
}
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
return fn.text;
|
|
91
|
+
if ((types.isClassMethod(node) || types.isObjectMethod(node)) && !node.computed && types.isIdentifier(node.key)) {
|
|
92
|
+
return node.key.name;
|
|
85
93
|
}
|
|
86
|
-
|
|
87
|
-
|
|
94
|
+
const parent = path.parentPath?.node;
|
|
95
|
+
if (types.isVariableDeclarator(parent)) {
|
|
96
|
+
return propertyName(parent.id, types) ?? "anonymous";
|
|
88
97
|
}
|
|
89
|
-
if (
|
|
90
|
-
return
|
|
98
|
+
if (types.isObjectProperty(parent) && !parent.computed) {
|
|
99
|
+
return propertyName(parent.key, types) ?? "anonymous";
|
|
91
100
|
}
|
|
92
|
-
|
|
101
|
+
const { line, column } = sourcePosition(path);
|
|
102
|
+
return `anonymous-${line}-${column}`;
|
|
93
103
|
}
|
|
94
|
-
function
|
|
95
|
-
if (
|
|
96
|
-
return
|
|
104
|
+
function isInstrumentableFunction(node, types) {
|
|
105
|
+
if (node.generator || types.isClassPrivateMethod(node)) {
|
|
106
|
+
return false;
|
|
97
107
|
}
|
|
98
|
-
return
|
|
108
|
+
return !(types.isClassMethod(node) || types.isObjectMethod(node)) || node.kind === "method";
|
|
99
109
|
}
|
|
100
|
-
function
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
110
|
+
function sourcePosition(path) {
|
|
111
|
+
const exportDeclaration = path.parentPath?.isExportDeclaration() ? path.parentPath.node : void 0;
|
|
112
|
+
const start = (exportDeclaration ?? path.node).loc?.start;
|
|
113
|
+
return { line: start?.line ?? 0, column: start?.column ?? 0 };
|
|
104
114
|
}
|
|
105
|
-
function
|
|
106
|
-
const
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
+
function qualifiedFunctionName(path, types) {
|
|
116
|
+
const ownName = functionName(path, types);
|
|
117
|
+
if (ownName.startsWith("anonymous-")) {
|
|
118
|
+
return ownName;
|
|
119
|
+
}
|
|
120
|
+
const scopes = [];
|
|
121
|
+
let ancestor = path.parentPath;
|
|
122
|
+
while (ancestor) {
|
|
123
|
+
if (ancestor.isFunction()) {
|
|
124
|
+
if (!isInstrumentableFunction(ancestor.node, types)) {
|
|
125
|
+
ancestor = ancestor.parentPath;
|
|
126
|
+
continue;
|
|
127
|
+
}
|
|
128
|
+
const name = functionName(
|
|
129
|
+
ancestor,
|
|
130
|
+
types
|
|
131
|
+
);
|
|
132
|
+
if (!name.startsWith("anonymous-")) {
|
|
133
|
+
scopes.unshift(name);
|
|
134
|
+
}
|
|
135
|
+
} else if ((ancestor.isClassDeclaration() || ancestor.isClassExpression()) && ancestor.node.id) {
|
|
136
|
+
scopes.unshift(ancestor.node.id.name);
|
|
137
|
+
} else if (ancestor.isObjectExpression()) {
|
|
138
|
+
const parent = ancestor.parentPath?.node;
|
|
139
|
+
if (types.isVariableDeclarator(parent)) {
|
|
140
|
+
const name = propertyName(parent.id, types);
|
|
141
|
+
if (name) {
|
|
142
|
+
scopes.unshift(name);
|
|
143
|
+
}
|
|
144
|
+
} else if (types.isObjectProperty(parent) && !parent.computed) {
|
|
145
|
+
const name = propertyName(parent.key, types);
|
|
146
|
+
if (name) {
|
|
147
|
+
scopes.unshift(name);
|
|
148
|
+
}
|
|
115
149
|
}
|
|
116
150
|
}
|
|
117
|
-
|
|
151
|
+
ancestor = ancestor.parentPath;
|
|
118
152
|
}
|
|
119
|
-
|
|
120
|
-
return { inlineRoots, referencedRoots };
|
|
153
|
+
return [...scopes, ownName].join(".");
|
|
121
154
|
}
|
|
122
|
-
function
|
|
123
|
-
|
|
124
|
-
|
|
155
|
+
function isTraceDecoratorRoot(path, types) {
|
|
156
|
+
const node = path.node;
|
|
157
|
+
if (!types.isClassMethod(node) && !types.isClassPrivateMethod(node)) {
|
|
158
|
+
return false;
|
|
125
159
|
}
|
|
126
|
-
|
|
127
|
-
|
|
160
|
+
return node.decorators?.some((decorator) => {
|
|
161
|
+
const expression = decorator.expression;
|
|
162
|
+
if (!types.isCallExpression(expression)) {
|
|
163
|
+
return false;
|
|
164
|
+
}
|
|
165
|
+
const callee = expression.callee;
|
|
166
|
+
return types.isMemberExpression(callee) && !callee.computed && types.isIdentifier(callee.property, { name: "trace" });
|
|
167
|
+
}) ?? false;
|
|
168
|
+
}
|
|
169
|
+
function isBitfabWrapperArgument(path, types) {
|
|
170
|
+
const parent = path.parentPath?.node;
|
|
171
|
+
if (!types.isCallExpression(parent)) {
|
|
172
|
+
return false;
|
|
128
173
|
}
|
|
129
|
-
if (
|
|
130
|
-
return
|
|
174
|
+
if (!parent.arguments.some((argument) => argument === path.node)) {
|
|
175
|
+
return false;
|
|
131
176
|
}
|
|
132
|
-
|
|
177
|
+
const callee = parent.callee;
|
|
178
|
+
return types.isMemberExpression(callee) && !callee.computed && types.isIdentifier(callee.property) && (callee.property.name === "withTrace" || callee.property.name === "withSpan");
|
|
133
179
|
}
|
|
134
|
-
function
|
|
135
|
-
if (
|
|
136
|
-
return
|
|
180
|
+
function withNodeFunctionName(path, types) {
|
|
181
|
+
if (path.node.arguments.length > 2) {
|
|
182
|
+
return null;
|
|
183
|
+
}
|
|
184
|
+
const callee = path.node.callee;
|
|
185
|
+
if (!types.isMemberExpression(callee) || callee.computed || !types.isIdentifier(callee.property, { name: "withNode" })) {
|
|
186
|
+
return null;
|
|
187
|
+
}
|
|
188
|
+
const fn = path.node.arguments[path.node.arguments.length - 1];
|
|
189
|
+
if (types.isIdentifier(fn)) {
|
|
190
|
+
return fn.name;
|
|
137
191
|
}
|
|
138
|
-
if (
|
|
139
|
-
return
|
|
192
|
+
if (types.isMemberExpression(fn) && !fn.computed) {
|
|
193
|
+
return propertyName(fn.property, types);
|
|
194
|
+
}
|
|
195
|
+
if (types.isFunctionExpression(fn) && fn.id) {
|
|
196
|
+
return fn.id.name;
|
|
140
197
|
}
|
|
141
198
|
return null;
|
|
142
199
|
}
|
|
143
|
-
function
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
const scopes = [];
|
|
147
|
-
let ancestor = node.parent;
|
|
148
|
-
while (ancestor) {
|
|
149
|
-
if (isInstrumentableFunction(ancestor)) {
|
|
150
|
-
const name = declaredFunctionName(ancestor);
|
|
151
|
-
if (name) {
|
|
152
|
-
scopes.unshift(name);
|
|
153
|
-
}
|
|
154
|
-
} else if ((import_typescript.default.isClassDeclaration(ancestor) || import_typescript.default.isClassExpression(ancestor)) && ancestor.name) {
|
|
155
|
-
scopes.unshift(ancestor.name.text);
|
|
156
|
-
} else if (import_typescript.default.isObjectLiteralExpression(ancestor)) {
|
|
157
|
-
const name = objectContainerName(ancestor);
|
|
158
|
-
if (name) {
|
|
159
|
-
scopes.unshift(name);
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
ancestor = ancestor.parent;
|
|
163
|
-
}
|
|
164
|
-
return [...scopes, ownName].join(".");
|
|
200
|
+
function functionBindingName(path, types) {
|
|
201
|
+
if (types.isFunctionDeclaration(path.node) && path.node.id) {
|
|
202
|
+
return path.node.id.name;
|
|
165
203
|
}
|
|
166
|
-
const
|
|
167
|
-
|
|
168
|
-
|
|
204
|
+
const parent = path.parentPath?.node;
|
|
205
|
+
if (types.isVariableDeclarator(parent) && types.isIdentifier(parent.id)) {
|
|
206
|
+
return parent.id.name;
|
|
207
|
+
}
|
|
208
|
+
return null;
|
|
169
209
|
}
|
|
170
|
-
function isBitfabWrappedFunction(
|
|
171
|
-
if (
|
|
210
|
+
function isBitfabWrappedFunction(path, types) {
|
|
211
|
+
if (isBitfabWrapperArgument(path, types)) {
|
|
172
212
|
return true;
|
|
173
213
|
}
|
|
174
|
-
const
|
|
175
|
-
|
|
176
|
-
}
|
|
177
|
-
function isInstrumentableFunction(node) {
|
|
178
|
-
if (!import_typescript.default.isFunctionDeclaration(node) && !import_typescript.default.isFunctionExpression(node) && !import_typescript.default.isArrowFunction(node) && !import_typescript.default.isMethodDeclaration(node)) {
|
|
214
|
+
const bindingName = functionBindingName(path, types);
|
|
215
|
+
if (!bindingName) {
|
|
179
216
|
return false;
|
|
180
217
|
}
|
|
181
|
-
|
|
218
|
+
const binding = path.scope.getBinding(bindingName);
|
|
219
|
+
return binding?.referencePaths.some(
|
|
220
|
+
(referencePath) => isBitfabWrapperArgument(referencePath, types)
|
|
221
|
+
) ?? false;
|
|
182
222
|
}
|
|
183
|
-
function
|
|
184
|
-
|
|
185
|
-
const normalizedCwd = cwd.replace(/\\/g, "/").replace(/\/$/, "");
|
|
186
|
-
return normalized.startsWith(`${normalizedCwd}/`) ? normalized.slice(normalizedCwd.length + 1) : normalized;
|
|
223
|
+
function isBitfabManagedFunction(path, types) {
|
|
224
|
+
return isTraceDecoratorRoot(path, types) || isBitfabWrappedFunction(path, types);
|
|
187
225
|
}
|
|
188
|
-
function
|
|
189
|
-
return
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
226
|
+
function runtimeParameters(node, types) {
|
|
227
|
+
return node.params.filter(
|
|
228
|
+
(parameter) => !types.isIdentifier(parameter, { name: "this" })
|
|
229
|
+
);
|
|
230
|
+
}
|
|
231
|
+
function parameterInputs(path, types) {
|
|
232
|
+
const elements = [];
|
|
233
|
+
for (const [index, parameter] of runtimeParameters(
|
|
234
|
+
path.node,
|
|
235
|
+
types
|
|
236
|
+
).entries()) {
|
|
237
|
+
if (!types.isArrowFunctionExpression(path.node)) {
|
|
238
|
+
if (types.isRestElement(parameter)) {
|
|
239
|
+
elements.push(
|
|
240
|
+
types.spreadElement(
|
|
241
|
+
types.callExpression(
|
|
242
|
+
types.memberExpression(
|
|
243
|
+
types.arrayExpression([
|
|
244
|
+
types.spreadElement(types.identifier("arguments"))
|
|
200
245
|
]),
|
|
201
|
-
"slice"
|
|
246
|
+
types.identifier("slice")
|
|
202
247
|
),
|
|
203
|
-
|
|
204
|
-
[factory.createNumericLiteral(index)]
|
|
248
|
+
[types.numericLiteral(index)]
|
|
205
249
|
)
|
|
206
|
-
)
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
250
|
+
)
|
|
251
|
+
);
|
|
252
|
+
} else {
|
|
253
|
+
elements.push(
|
|
254
|
+
types.memberExpression(
|
|
255
|
+
types.identifier("arguments"),
|
|
256
|
+
types.numericLiteral(index),
|
|
257
|
+
true
|
|
258
|
+
)
|
|
211
259
|
);
|
|
212
260
|
}
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
261
|
+
continue;
|
|
262
|
+
}
|
|
263
|
+
if (types.isIdentifier(parameter)) {
|
|
264
|
+
elements.push(types.identifier(parameter.name));
|
|
265
|
+
} else if (types.isRestElement(parameter) && types.isIdentifier(parameter.argument)) {
|
|
266
|
+
elements.push(
|
|
267
|
+
types.spreadElement(types.identifier(parameter.argument.name))
|
|
219
268
|
);
|
|
220
|
-
}
|
|
221
|
-
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
return types.arrayExpression(elements);
|
|
222
272
|
}
|
|
223
|
-
function needsArgumentWrapper(
|
|
224
|
-
return
|
|
225
|
-
(parameter) => !
|
|
273
|
+
function needsArgumentWrapper(path, types) {
|
|
274
|
+
return types.isArrowFunctionExpression(path.node) && path.node.params.some(
|
|
275
|
+
(parameter) => !types.isIdentifier(parameter) && !(types.isRestElement(parameter) && types.isIdentifier(parameter.argument))
|
|
226
276
|
);
|
|
227
277
|
}
|
|
228
|
-
function isRestWrapper(
|
|
229
|
-
|
|
278
|
+
function isRestWrapper(path, types) {
|
|
279
|
+
const parameters = runtimeParameters(path.node, types);
|
|
280
|
+
return parameters.length === 1 && types.isRestElement(parameters[0]);
|
|
230
281
|
}
|
|
231
|
-
function
|
|
232
|
-
const
|
|
233
|
-
(statement) => !(import_typescript.default.isExpressionStatement(statement) && import_typescript.default.isStringLiteral(statement.expression))
|
|
234
|
-
);
|
|
235
|
-
if (firstNonDirective === -1) {
|
|
236
|
-
return { directives: body.statements, statements: [] };
|
|
237
|
-
}
|
|
282
|
+
function bitfabBabelPlugin(api) {
|
|
283
|
+
const { types } = api;
|
|
238
284
|
return {
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
node,
|
|
247
|
-
node.modifiers,
|
|
248
|
-
node.asteriskToken,
|
|
249
|
-
node.name,
|
|
250
|
-
node.typeParameters,
|
|
251
|
-
node.parameters,
|
|
252
|
-
node.type,
|
|
253
|
-
body
|
|
254
|
-
);
|
|
255
|
-
}
|
|
256
|
-
if (import_typescript.default.isFunctionExpression(node)) {
|
|
257
|
-
return factory.updateFunctionExpression(
|
|
258
|
-
node,
|
|
259
|
-
node.modifiers,
|
|
260
|
-
node.asteriskToken,
|
|
261
|
-
node.name,
|
|
262
|
-
node.typeParameters,
|
|
263
|
-
node.parameters,
|
|
264
|
-
node.type,
|
|
265
|
-
body
|
|
266
|
-
);
|
|
267
|
-
}
|
|
268
|
-
if (import_typescript.default.isArrowFunction(node)) {
|
|
269
|
-
return factory.updateArrowFunction(
|
|
270
|
-
node,
|
|
271
|
-
node.modifiers,
|
|
272
|
-
node.typeParameters,
|
|
273
|
-
node.parameters,
|
|
274
|
-
node.type,
|
|
275
|
-
node.equalsGreaterThanToken,
|
|
276
|
-
body
|
|
277
|
-
);
|
|
278
|
-
}
|
|
279
|
-
if (import_typescript.default.isMethodDeclaration(node)) {
|
|
280
|
-
return factory.updateMethodDeclaration(
|
|
281
|
-
node,
|
|
282
|
-
node.modifiers,
|
|
283
|
-
node.asteriskToken,
|
|
284
|
-
node.name,
|
|
285
|
-
node.questionToken,
|
|
286
|
-
node.typeParameters,
|
|
287
|
-
node.parameters,
|
|
288
|
-
node.type,
|
|
289
|
-
body
|
|
290
|
-
);
|
|
291
|
-
}
|
|
292
|
-
return node;
|
|
293
|
-
}
|
|
294
|
-
function createBitfabTypeScriptTransformer(options = {}) {
|
|
295
|
-
return (context) => (sourceFile) => {
|
|
296
|
-
if (hasUseClientDirective(sourceFile) || hasTransformMarker(sourceFile) || !shouldTransformBitfabFile(sourceFile.fileName, options)) {
|
|
297
|
-
return sourceFile;
|
|
298
|
-
}
|
|
299
|
-
const { factory } = context;
|
|
300
|
-
const { inlineRoots, referencedRoots } = collectBitfabWrappedFunctions(sourceFile);
|
|
301
|
-
const runtimeIdentifier = factory.createUniqueName("bitfabAutoSpan");
|
|
302
|
-
const activeIdentifier = factory.createUniqueName("bitfabAutoTraceActive");
|
|
303
|
-
const wrapperIdentifier = factory.createUniqueName("bitfabAutoWrap");
|
|
304
|
-
const transformedNodes = /* @__PURE__ */ new Set();
|
|
305
|
-
const definitions = [];
|
|
306
|
-
let usedRuntime = false;
|
|
307
|
-
let usedWrapper = false;
|
|
308
|
-
const cwd = options.cwd ?? process.cwd();
|
|
309
|
-
const file = normalizedFilename(sourceFile.fileName, cwd);
|
|
310
|
-
const visitor = (node) => {
|
|
311
|
-
const visited = import_typescript.default.visitEachChild(node, visitor, context);
|
|
312
|
-
if (import_typescript.default.isCallExpression(node) && import_typescript.default.isCallExpression(visited)) {
|
|
313
|
-
const configuredName = withNodeFunctionName(node);
|
|
314
|
-
if (configuredName !== null) {
|
|
315
|
-
const args = [...visited.arguments];
|
|
316
|
-
if (args.length === 1) {
|
|
317
|
-
args.push(factory.createIdentifier("undefined"));
|
|
318
|
-
}
|
|
319
|
-
args.push(factory.createStringLiteral(configuredName));
|
|
320
|
-
return factory.updateCallExpression(
|
|
321
|
-
visited,
|
|
322
|
-
visited.expression,
|
|
323
|
-
visited.typeArguments,
|
|
324
|
-
args
|
|
285
|
+
name: "bitfab-auto-trace",
|
|
286
|
+
visitor: {
|
|
287
|
+
Program: {
|
|
288
|
+
enter(path, state) {
|
|
289
|
+
const filename = state.file.opts.filename ?? "unknown";
|
|
290
|
+
state.skipFile = !shouldTransformBitfabFile(filename, state.opts) || path.scope.hasBinding(AUTO_TRACE_TRANSFORM_MARKER) || path.node.directives.some(
|
|
291
|
+
(directive) => directive.value.value === "use client"
|
|
325
292
|
);
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
"id",
|
|
343
|
-
factory.createStringLiteral(autoTraceFunctionId(file, name))
|
|
344
|
-
),
|
|
345
|
-
factory.createPropertyAssignment(
|
|
346
|
-
"name",
|
|
347
|
-
factory.createStringLiteral(name)
|
|
348
|
-
),
|
|
349
|
-
factory.createPropertyAssignment(
|
|
350
|
-
"file",
|
|
351
|
-
factory.createStringLiteral(file)
|
|
352
|
-
),
|
|
353
|
-
factory.createPropertyAssignment(
|
|
354
|
-
"line",
|
|
355
|
-
factory.createNumericLiteral(position.line + 1)
|
|
356
|
-
),
|
|
357
|
-
factory.createPropertyAssignment(
|
|
358
|
-
"column",
|
|
359
|
-
factory.createNumericLiteral(position.character)
|
|
360
|
-
),
|
|
361
|
-
...node.modifiers?.some(
|
|
362
|
-
(modifier) => modifier.kind === import_typescript.default.SyntaxKind.AsyncKeyword
|
|
363
|
-
) ? [factory.createPropertyAssignment("async", factory.createTrue())] : [],
|
|
364
|
-
...isRestWrapper(node) ? [
|
|
365
|
-
factory.createPropertyAssignment(
|
|
366
|
-
"wrapper",
|
|
367
|
-
factory.createTrue()
|
|
368
|
-
)
|
|
369
|
-
] : []
|
|
370
|
-
],
|
|
371
|
-
false
|
|
372
|
-
);
|
|
373
|
-
const definitionIdentifier = factory.createUniqueName(
|
|
374
|
-
"bitfabAutoDefinition"
|
|
375
|
-
);
|
|
376
|
-
definitions.push(
|
|
377
|
-
factory.createVariableStatement(
|
|
378
|
-
void 0,
|
|
379
|
-
factory.createVariableDeclarationList(
|
|
380
|
-
[
|
|
381
|
-
factory.createVariableDeclaration(
|
|
382
|
-
definitionIdentifier,
|
|
383
|
-
void 0,
|
|
384
|
-
void 0,
|
|
385
|
-
definition
|
|
386
|
-
)
|
|
387
|
-
],
|
|
388
|
-
import_typescript.default.NodeFlags.Const
|
|
389
|
-
)
|
|
390
|
-
)
|
|
391
|
-
);
|
|
392
|
-
if (needsArgumentWrapper(visited)) {
|
|
393
|
-
usedRuntime = true;
|
|
394
|
-
usedWrapper = true;
|
|
395
|
-
return factory.createCallExpression(wrapperIdentifier, void 0, [
|
|
396
|
-
definitionIdentifier,
|
|
397
|
-
visited
|
|
398
|
-
]);
|
|
399
|
-
}
|
|
400
|
-
const visitedBody = visited.body;
|
|
401
|
-
const originalBody = import_typescript.default.isBlock(visitedBody) ? visitedBody : factory.createBlock(
|
|
402
|
-
[factory.createReturnStatement(visitedBody)],
|
|
403
|
-
true
|
|
404
|
-
);
|
|
405
|
-
const { directives, statements } = splitDirectivePrologue(originalBody);
|
|
406
|
-
const invoke = factory.createArrowFunction(
|
|
407
|
-
hasAsyncModifier(node) ? [factory.createModifier(import_typescript.default.SyntaxKind.AsyncKeyword)] : void 0,
|
|
408
|
-
void 0,
|
|
409
|
-
[],
|
|
410
|
-
void 0,
|
|
411
|
-
factory.createToken(import_typescript.default.SyntaxKind.EqualsGreaterThanToken),
|
|
412
|
-
factory.updateBlock(originalBody, statements)
|
|
413
|
-
);
|
|
414
|
-
const body = factory.createBlock(
|
|
415
|
-
[
|
|
416
|
-
...directives,
|
|
417
|
-
factory.createIfStatement(
|
|
418
|
-
factory.createCallExpression(activeIdentifier, void 0, []),
|
|
419
|
-
factory.createBlock(
|
|
293
|
+
state.runtimeIdentifier = path.scope.generateUidIdentifier("bitfabAutoSpan");
|
|
294
|
+
state.activeIdentifier = path.scope.generateUidIdentifier(
|
|
295
|
+
"bitfabAutoTraceActive"
|
|
296
|
+
);
|
|
297
|
+
state.wrapperIdentifier = path.scope.generateUidIdentifier("bitfabAutoWrap");
|
|
298
|
+
state.definitions = [];
|
|
299
|
+
state.usedRuntime = false;
|
|
300
|
+
state.usedWrapper = false;
|
|
301
|
+
},
|
|
302
|
+
exit(path, state) {
|
|
303
|
+
if (state.skipFile || !state.usedRuntime || !state.runtimeIdentifier || !state.activeIdentifier || !state.wrapperIdentifier) {
|
|
304
|
+
return;
|
|
305
|
+
}
|
|
306
|
+
state.file.metadata[AUTO_TRACE_TRANSFORM_MARKER] = true;
|
|
307
|
+
path.unshiftContainer("body", [
|
|
308
|
+
types.importDeclaration(
|
|
420
309
|
[
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
parameterInputs(factory, visited),
|
|
425
|
-
invoke
|
|
426
|
-
])
|
|
427
|
-
)
|
|
428
|
-
],
|
|
429
|
-
true
|
|
430
|
-
)
|
|
431
|
-
),
|
|
432
|
-
...statements
|
|
433
|
-
],
|
|
434
|
-
true
|
|
435
|
-
);
|
|
436
|
-
const updated = updateFunctionBody(factory, visited, body);
|
|
437
|
-
transformedNodes.add(updated);
|
|
438
|
-
usedRuntime = true;
|
|
439
|
-
return updated;
|
|
440
|
-
};
|
|
441
|
-
const transformed = import_typescript.default.visitEachChild(sourceFile, visitor, context);
|
|
442
|
-
if (!usedRuntime) {
|
|
443
|
-
return transformed;
|
|
444
|
-
}
|
|
445
|
-
const runtimeImport = factory.createImportDeclaration(
|
|
446
|
-
void 0,
|
|
447
|
-
factory.createImportClause(
|
|
448
|
-
false,
|
|
449
|
-
void 0,
|
|
450
|
-
factory.createNamedImports([
|
|
451
|
-
factory.createImportSpecifier(
|
|
452
|
-
false,
|
|
453
|
-
factory.createIdentifier("__bitfabAutoSpan"),
|
|
454
|
-
runtimeIdentifier
|
|
455
|
-
),
|
|
456
|
-
factory.createImportSpecifier(
|
|
457
|
-
false,
|
|
458
|
-
factory.createIdentifier("__bitfabAutoTraceActive"),
|
|
459
|
-
activeIdentifier
|
|
460
|
-
),
|
|
461
|
-
...usedWrapper ? [
|
|
462
|
-
factory.createImportSpecifier(
|
|
463
|
-
false,
|
|
464
|
-
factory.createIdentifier("__bitfabAutoWrap"),
|
|
465
|
-
wrapperIdentifier
|
|
466
|
-
)
|
|
467
|
-
] : []
|
|
468
|
-
])
|
|
469
|
-
),
|
|
470
|
-
factory.createStringLiteral(options.runtimeModule ?? "@bitfab/sdk/auto")
|
|
471
|
-
);
|
|
472
|
-
const transformMarker = factory.createVariableStatement(
|
|
473
|
-
void 0,
|
|
474
|
-
factory.createVariableDeclarationList(
|
|
475
|
-
[
|
|
476
|
-
factory.createVariableDeclaration(
|
|
477
|
-
factory.createIdentifier(AUTO_TRACE_TRANSFORM_MARKER),
|
|
478
|
-
void 0,
|
|
479
|
-
void 0,
|
|
480
|
-
factory.createAssignment(
|
|
481
|
-
factory.createPropertyAccessExpression(
|
|
482
|
-
factory.createIdentifier("globalThis"),
|
|
483
|
-
factory.createIdentifier(AUTO_TRACE_TRANSFORM_MARKER)
|
|
484
|
-
),
|
|
485
|
-
factory.createTrue()
|
|
486
|
-
)
|
|
487
|
-
)
|
|
488
|
-
],
|
|
489
|
-
import_typescript.default.NodeFlags.Const
|
|
490
|
-
)
|
|
491
|
-
);
|
|
492
|
-
return factory.updateSourceFile(transformed, [
|
|
493
|
-
context.getCompilerOptions().module === import_typescript.default.ModuleKind.CommonJS ? factory.createVariableStatement(
|
|
494
|
-
void 0,
|
|
495
|
-
factory.createVariableDeclarationList(
|
|
496
|
-
[
|
|
497
|
-
factory.createVariableDeclaration(
|
|
498
|
-
factory.createObjectBindingPattern([
|
|
499
|
-
factory.createBindingElement(
|
|
500
|
-
void 0,
|
|
501
|
-
"__bitfabAutoSpan",
|
|
502
|
-
runtimeIdentifier
|
|
310
|
+
types.importSpecifier(
|
|
311
|
+
state.runtimeIdentifier,
|
|
312
|
+
types.identifier("__bitfabAutoSpan")
|
|
503
313
|
),
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
"__bitfabAutoTraceActive"
|
|
507
|
-
activeIdentifier
|
|
314
|
+
types.importSpecifier(
|
|
315
|
+
state.activeIdentifier,
|
|
316
|
+
types.identifier("__bitfabAutoTraceActive")
|
|
508
317
|
),
|
|
509
|
-
...usedWrapper ? [
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
"__bitfabAutoWrap"
|
|
513
|
-
wrapperIdentifier
|
|
318
|
+
...state.usedWrapper ? [
|
|
319
|
+
types.importSpecifier(
|
|
320
|
+
state.wrapperIdentifier,
|
|
321
|
+
types.identifier("__bitfabAutoWrap")
|
|
514
322
|
)
|
|
515
323
|
] : []
|
|
516
|
-
]
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
factory.createCallExpression(
|
|
520
|
-
factory.createIdentifier("require"),
|
|
521
|
-
void 0,
|
|
522
|
-
[
|
|
523
|
-
factory.createStringLiteral(
|
|
524
|
-
options.runtimeModule ?? "@bitfab/sdk/auto"
|
|
525
|
-
)
|
|
526
|
-
]
|
|
324
|
+
],
|
|
325
|
+
types.stringLiteral(
|
|
326
|
+
state.opts.runtimeModule ?? "@bitfab/sdk/auto"
|
|
527
327
|
)
|
|
528
|
-
)
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
328
|
+
),
|
|
329
|
+
types.variableDeclaration("const", [
|
|
330
|
+
types.variableDeclarator(
|
|
331
|
+
types.identifier(AUTO_TRACE_TRANSFORM_MARKER),
|
|
332
|
+
types.assignmentExpression(
|
|
333
|
+
"=",
|
|
334
|
+
types.memberExpression(
|
|
335
|
+
types.identifier("globalThis"),
|
|
336
|
+
types.identifier(AUTO_TRACE_TRANSFORM_MARKER)
|
|
337
|
+
),
|
|
338
|
+
types.booleanLiteral(true)
|
|
339
|
+
)
|
|
340
|
+
)
|
|
341
|
+
]),
|
|
342
|
+
...state.definitions ?? []
|
|
343
|
+
]);
|
|
344
|
+
}
|
|
345
|
+
},
|
|
346
|
+
CallExpression: {
|
|
347
|
+
exit(path, state) {
|
|
348
|
+
if (state.skipFile) {
|
|
349
|
+
return;
|
|
350
|
+
}
|
|
351
|
+
const configuredName = withNodeFunctionName(path, types);
|
|
352
|
+
if (configuredName === null) {
|
|
353
|
+
return;
|
|
354
|
+
}
|
|
355
|
+
if (path.node.arguments.length === 1) {
|
|
356
|
+
path.node.arguments.push(types.identifier("undefined"));
|
|
357
|
+
}
|
|
358
|
+
path.node.arguments.push(types.stringLiteral(configuredName));
|
|
359
|
+
}
|
|
360
|
+
},
|
|
361
|
+
Function: {
|
|
362
|
+
exit(path, state) {
|
|
363
|
+
const node = path.node;
|
|
364
|
+
if (state.skipFile || node._bitfabInstrumented || !isInstrumentableFunction(node, types) || isBitfabManagedFunction(path, types) || !state.runtimeIdentifier || !state.activeIdentifier || !state.wrapperIdentifier) {
|
|
365
|
+
return;
|
|
366
|
+
}
|
|
367
|
+
const name = qualifiedFunctionName(path, types);
|
|
368
|
+
if (name.startsWith("anonymous-")) {
|
|
369
|
+
return;
|
|
370
|
+
}
|
|
371
|
+
const normalizedFilename = autoTraceFilename(
|
|
372
|
+
state.file.opts.filename ?? "unknown",
|
|
373
|
+
state.opts.cwd ?? state.file.opts.cwd ?? process.cwd()
|
|
374
|
+
);
|
|
375
|
+
const { line, column } = sourcePosition(path);
|
|
376
|
+
const definition = types.objectExpression([
|
|
377
|
+
types.objectProperty(
|
|
378
|
+
types.identifier("id"),
|
|
379
|
+
types.stringLiteral(
|
|
380
|
+
autoTraceFunctionId(normalizedFilename, name)
|
|
381
|
+
)
|
|
382
|
+
),
|
|
383
|
+
types.objectProperty(
|
|
384
|
+
types.identifier("name"),
|
|
385
|
+
types.stringLiteral(name)
|
|
386
|
+
),
|
|
387
|
+
types.objectProperty(
|
|
388
|
+
types.identifier("file"),
|
|
389
|
+
types.stringLiteral(normalizedFilename)
|
|
390
|
+
),
|
|
391
|
+
types.objectProperty(
|
|
392
|
+
types.identifier("line"),
|
|
393
|
+
types.numericLiteral(line)
|
|
394
|
+
),
|
|
395
|
+
types.objectProperty(
|
|
396
|
+
types.identifier("column"),
|
|
397
|
+
types.numericLiteral(column)
|
|
398
|
+
),
|
|
399
|
+
...node.async ? [
|
|
400
|
+
types.objectProperty(
|
|
401
|
+
types.identifier("async"),
|
|
402
|
+
types.booleanLiteral(true)
|
|
403
|
+
)
|
|
404
|
+
] : [],
|
|
405
|
+
...isRestWrapper(path, types) ? [
|
|
406
|
+
types.objectProperty(
|
|
407
|
+
types.identifier("wrapper"),
|
|
408
|
+
types.booleanLiteral(true)
|
|
409
|
+
)
|
|
410
|
+
] : []
|
|
411
|
+
]);
|
|
412
|
+
const definitionIdentifier = path.scope.getProgramParent().generateUidIdentifier("bitfabAutoDefinition");
|
|
413
|
+
state.definitions?.push(
|
|
414
|
+
types.variableDeclaration("const", [
|
|
415
|
+
types.variableDeclarator(definitionIdentifier, definition)
|
|
416
|
+
])
|
|
417
|
+
);
|
|
418
|
+
if (needsArgumentWrapper(path, types)) {
|
|
419
|
+
node._bitfabInstrumented = true;
|
|
420
|
+
path.replaceWith(
|
|
421
|
+
types.callExpression(types.cloneNode(state.wrapperIdentifier), [
|
|
422
|
+
types.cloneNode(definitionIdentifier),
|
|
423
|
+
node
|
|
424
|
+
])
|
|
425
|
+
);
|
|
426
|
+
state.usedRuntime = true;
|
|
427
|
+
state.usedWrapper = true;
|
|
428
|
+
return;
|
|
429
|
+
}
|
|
430
|
+
const originalBody = types.isBlockStatement(node.body) ? node.body : types.blockStatement([types.returnStatement(node.body)]);
|
|
431
|
+
const directives = originalBody.directives;
|
|
432
|
+
originalBody.directives = [];
|
|
433
|
+
const body = types.blockStatement(
|
|
434
|
+
[
|
|
435
|
+
types.ifStatement(
|
|
436
|
+
types.callExpression(
|
|
437
|
+
types.cloneNode(state.activeIdentifier),
|
|
438
|
+
[]
|
|
439
|
+
),
|
|
440
|
+
types.blockStatement([
|
|
441
|
+
types.returnStatement(
|
|
442
|
+
types.callExpression(
|
|
443
|
+
types.cloneNode(state.runtimeIdentifier),
|
|
444
|
+
[
|
|
445
|
+
types.cloneNode(definitionIdentifier),
|
|
446
|
+
parameterInputs(path, types),
|
|
447
|
+
types.arrowFunctionExpression(
|
|
448
|
+
[],
|
|
449
|
+
types.cloneNode(originalBody, true),
|
|
450
|
+
node.async ?? false
|
|
451
|
+
)
|
|
452
|
+
]
|
|
453
|
+
)
|
|
454
|
+
)
|
|
455
|
+
])
|
|
456
|
+
),
|
|
457
|
+
...originalBody.body
|
|
458
|
+
],
|
|
459
|
+
directives
|
|
460
|
+
);
|
|
461
|
+
node.body = body;
|
|
462
|
+
node._bitfabInstrumented = true;
|
|
463
|
+
state.usedRuntime = true;
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
}
|
|
537
467
|
};
|
|
538
468
|
}
|
|
539
|
-
|
|
540
|
-
|
|
469
|
+
|
|
470
|
+
// ../bitfab-typescript-transform/src/transform.ts
|
|
471
|
+
var import_core = require("@babel/core");
|
|
472
|
+
function parserPlugins(filename) {
|
|
473
|
+
const path = sourceFilename(filename);
|
|
474
|
+
const typescript = /\.[cm]?tsx?$/.test(path);
|
|
475
|
+
const jsx = /\.tsx$/.test(path) || /\.[cm]?jsx?$/.test(path);
|
|
476
|
+
return [
|
|
477
|
+
...typescript ? ["typescript"] : [],
|
|
478
|
+
...jsx ? ["jsx"] : [],
|
|
479
|
+
"decorators"
|
|
480
|
+
];
|
|
541
481
|
}
|
|
542
482
|
|
|
543
483
|
// ../bitfab-typescript-transform/src/loaderRuntime.ts
|
|
544
|
-
var OPTIONS_THAT_ONLY_APPLY_TO_A_WHOLE_PROGRAM = [
|
|
545
|
-
"composite",
|
|
546
|
-
"declarationDir",
|
|
547
|
-
"incremental",
|
|
548
|
-
"outDir",
|
|
549
|
-
"rootDir",
|
|
550
|
-
"rootDirs",
|
|
551
|
-
"tsBuildInfoFile"
|
|
552
|
-
];
|
|
553
484
|
function readCompilerOptions(filename, configuredPath) {
|
|
554
|
-
const
|
|
555
|
-
|
|
556
|
-
return {};
|
|
557
|
-
}
|
|
558
|
-
const config = import_typescript2.default.readConfigFile(configPath, import_typescript2.default.sys.readFile);
|
|
559
|
-
if (config.error) {
|
|
560
|
-
throw new Error(
|
|
561
|
-
import_typescript2.default.flattenDiagnosticMessageText(config.error.messageText, "\n")
|
|
562
|
-
);
|
|
563
|
-
}
|
|
564
|
-
const { options } = import_typescript2.default.parseJsonConfigFileContent(
|
|
565
|
-
config.config,
|
|
566
|
-
import_typescript2.default.sys,
|
|
567
|
-
(0, import_node_path.dirname)(configPath)
|
|
568
|
-
);
|
|
569
|
-
for (const option of OPTIONS_THAT_ONLY_APPLY_TO_A_WHOLE_PROGRAM) {
|
|
570
|
-
delete options[option];
|
|
571
|
-
}
|
|
572
|
-
return options;
|
|
485
|
+
const config = configuredPath ? (0, import_get_tsconfig.parseTsconfig)(configuredPath) : (0, import_get_tsconfig.getTsconfig)((0, import_node_path.dirname)(filename))?.config;
|
|
486
|
+
return config?.compilerOptions ?? {};
|
|
573
487
|
}
|
|
574
|
-
function
|
|
575
|
-
if (
|
|
576
|
-
return
|
|
488
|
+
function reactJsxOptions(compilerOptions) {
|
|
489
|
+
if (compilerOptions.jsx === "react") {
|
|
490
|
+
return [
|
|
491
|
+
import_plugin_transform_react_jsx.default,
|
|
492
|
+
{
|
|
493
|
+
runtime: "classic",
|
|
494
|
+
...compilerOptions.jsxFactory && {
|
|
495
|
+
pragma: compilerOptions.jsxFactory
|
|
496
|
+
},
|
|
497
|
+
...compilerOptions.jsxFragmentFactory && {
|
|
498
|
+
pragmaFrag: compilerOptions.jsxFragmentFactory
|
|
499
|
+
}
|
|
500
|
+
}
|
|
501
|
+
];
|
|
577
502
|
}
|
|
578
|
-
return
|
|
503
|
+
return [
|
|
504
|
+
import_plugin_transform_react_jsx.default,
|
|
505
|
+
{
|
|
506
|
+
runtime: "automatic",
|
|
507
|
+
importSource: compilerOptions.jsxImportSource ?? "react"
|
|
508
|
+
}
|
|
509
|
+
];
|
|
510
|
+
}
|
|
511
|
+
function compilePlugins(filename, compilerOptions, format) {
|
|
512
|
+
const path = sourceFilename(filename);
|
|
513
|
+
const isTypeScript = /\.[cm]?tsx?$/.test(path);
|
|
514
|
+
const hasJsx = /\.[jt]sx$/.test(path);
|
|
515
|
+
const isCommonJs = format === "commonjs" || path.endsWith(".cts");
|
|
516
|
+
return [
|
|
517
|
+
...isTypeScript ? [
|
|
518
|
+
[
|
|
519
|
+
import_plugin_transform_typescript.default,
|
|
520
|
+
{
|
|
521
|
+
onlyRemoveTypeImports: compilerOptions.verbatimModuleSyntax === true
|
|
522
|
+
}
|
|
523
|
+
]
|
|
524
|
+
] : [],
|
|
525
|
+
[
|
|
526
|
+
import_plugin_proposal_decorators.default,
|
|
527
|
+
{
|
|
528
|
+
version: compilerOptions.experimentalDecorators ? "legacy" : "2023-11"
|
|
529
|
+
}
|
|
530
|
+
],
|
|
531
|
+
...hasJsx ? [reactJsxOptions(compilerOptions)] : [],
|
|
532
|
+
...isCommonJs ? [import_plugin_transform_modules_commonjs.default] : []
|
|
533
|
+
];
|
|
579
534
|
}
|
|
580
535
|
function transformBitfabModuleToJavaScript(source, filename, options = {}, format, sourceMapMode = "external") {
|
|
581
536
|
const { tsconfig, ...transformOptions } = options;
|
|
582
537
|
if (!shouldTransformBitfabFile(filename, transformOptions)) {
|
|
583
538
|
return { code: source };
|
|
584
539
|
}
|
|
585
|
-
const
|
|
586
|
-
const
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
module: moduleKindForFormat(filename, format),
|
|
595
|
-
moduleResolution: format === "commonjs" ? import_typescript2.default.ModuleResolutionKind.Node10 : import_typescript2.default.ModuleResolutionKind.Bundler,
|
|
596
|
-
noEmit: false,
|
|
597
|
-
noEmitOnError: false,
|
|
598
|
-
sourceMap: sourceMapMode === "external"
|
|
599
|
-
},
|
|
600
|
-
fileName: filename,
|
|
601
|
-
reportDiagnostics: true,
|
|
602
|
-
transformers: {
|
|
603
|
-
before: [createBitfabTypeScriptTransformer(transformOptions)]
|
|
604
|
-
}
|
|
540
|
+
const sourceFile = sourceFilename(filename);
|
|
541
|
+
const instrumented = (0, import_core2.transformSync)(source, {
|
|
542
|
+
ast: true,
|
|
543
|
+
babelrc: false,
|
|
544
|
+
code: false,
|
|
545
|
+
configFile: false,
|
|
546
|
+
filename: sourceFile,
|
|
547
|
+
parserOpts: { plugins: parserPlugins(filename), sourceType: "module" },
|
|
548
|
+
plugins: [[bitfabBabelPlugin, transformOptions]]
|
|
605
549
|
});
|
|
606
|
-
|
|
607
|
-
(
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
550
|
+
if (!instrumented?.ast) {
|
|
551
|
+
throw new Error(`Bitfab could not parse ${sourceFile}`);
|
|
552
|
+
}
|
|
553
|
+
const compiled = (0, import_core2.transformFromAstSync)(instrumented.ast, source, {
|
|
554
|
+
babelrc: false,
|
|
555
|
+
cloneInputAst: false,
|
|
556
|
+
configFile: false,
|
|
557
|
+
filename: sourceFile,
|
|
558
|
+
plugins: compilePlugins(
|
|
559
|
+
filename,
|
|
560
|
+
readCompilerOptions(filename, tsconfig),
|
|
561
|
+
format
|
|
562
|
+
),
|
|
563
|
+
sourceMaps: sourceMapMode === "inline" ? "inline" : true
|
|
564
|
+
});
|
|
565
|
+
if (compiled?.code === void 0 || compiled.code === null) {
|
|
566
|
+
throw new Error(`Bitfab could not compile ${sourceFile}`);
|
|
617
567
|
}
|
|
618
568
|
return {
|
|
619
|
-
code:
|
|
620
|
-
...
|
|
569
|
+
code: compiled.code,
|
|
570
|
+
...compiled.map ? { map: JSON.stringify(compiled.map) } : {}
|
|
621
571
|
};
|
|
622
572
|
}
|
|
623
573
|
// Annotate the CommonJS export names for ESM import in node:
|