@bitfab/sdk 0.64.24 → 0.64.26

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.
Files changed (100) hide show
  1. package/dist/{chunk-EXTDH26A.js → chunk-26WDOYFS.js} +27 -6
  2. package/dist/chunk-26WDOYFS.js.map +1 -0
  3. package/dist/{chunk-E6YNESVO.js → chunk-FSVGIKQT.js} +2 -2
  4. package/dist/chunk-GSHCHCB5.js +433 -0
  5. package/dist/chunk-GSHCHCB5.js.map +1 -0
  6. package/dist/chunk-IBWW3SP4.js +45 -0
  7. package/dist/chunk-IBWW3SP4.js.map +1 -0
  8. package/dist/{chunk-3YAEAQI5.js → chunk-IHQKJWNN.js} +2 -2
  9. package/dist/{chunk-3YAEAQI5.js.map → chunk-IHQKJWNN.js.map} +1 -1
  10. package/dist/{chunk-OXFZJP4E.js → chunk-MN3E2RUU.js} +6 -8
  11. package/dist/chunk-MN3E2RUU.js.map +1 -0
  12. package/dist/{chunk-7A5E42SY.js → chunk-NK5RZ3UH.js} +2 -2
  13. package/dist/{chunk-7A5E42SY.js.map → chunk-NK5RZ3UH.js.map} +1 -1
  14. package/dist/{chunk-NOWQOHCR.js → chunk-PPNFMVOH.js} +2 -2
  15. package/dist/{chunk-3NIUOINN.js → chunk-W6I5QA62.js} +4 -4
  16. package/dist/{http-UQTRAPDD.js → http-3WBKIQI4.js} +2 -2
  17. package/dist/{http-G3U247I4.js → http-BK6UJNXI.js} +2 -2
  18. package/dist/index.cjs +23 -1
  19. package/dist/index.cjs.map +1 -1
  20. package/dist/index.d.cts +14 -2
  21. package/dist/index.d.ts +14 -2
  22. package/dist/index.js +3 -3
  23. package/dist/node.cjs +23 -1
  24. package/dist/node.cjs.map +1 -1
  25. package/dist/node.d.cts +1 -1
  26. package/dist/node.d.ts +1 -1
  27. package/dist/node.js +3 -3
  28. package/dist/{replay-MPMU3VBP.js → replay-OEANLAUE.js} +3 -3
  29. package/dist/{replay-SK4FOKUB.js → replay-ZTEDZUSG.js} +3 -3
  30. package/dist/replayCli.js +3 -3
  31. package/dist/seedCli.js +3 -3
  32. package/dist/transform/babel.cjs +68 -34
  33. package/dist/transform/babel.cjs.map +1 -1
  34. package/dist/transform/babel.d.cts +2 -2
  35. package/dist/transform/babel.d.ts +2 -2
  36. package/dist/transform/babel.js +2 -374
  37. package/dist/transform/babel.js.map +1 -1
  38. package/dist/transform/bun.cjs +389 -464
  39. package/dist/transform/bun.cjs.map +1 -1
  40. package/dist/transform/bun.js +3 -3
  41. package/dist/transform/esbuild.cjs +389 -464
  42. package/dist/transform/esbuild.cjs.map +1 -1
  43. package/dist/transform/esbuild.js +3 -3
  44. package/dist/transform/loaderRuntime.cjs +448 -498
  45. package/dist/transform/loaderRuntime.cjs.map +1 -1
  46. package/dist/transform/loaderRuntime.js +90 -70
  47. package/dist/transform/loaderRuntime.js.map +1 -1
  48. package/dist/transform/nest.cjs +389 -464
  49. package/dist/transform/nest.cjs.map +1 -1
  50. package/dist/transform/nest.js +3 -3
  51. package/dist/transform/next.cjs +389 -464
  52. package/dist/transform/next.cjs.map +1 -1
  53. package/dist/transform/next.js +3 -3
  54. package/dist/transform/nodeLoader.js +451 -498
  55. package/dist/transform/nodeLoader.js.map +1 -1
  56. package/dist/transform/rolldown.cjs +389 -464
  57. package/dist/transform/rolldown.cjs.map +1 -1
  58. package/dist/transform/rolldown.js +3 -3
  59. package/dist/transform/rollup.cjs +389 -464
  60. package/dist/transform/rollup.cjs.map +1 -1
  61. package/dist/transform/rollup.js +3 -3
  62. package/dist/transform/rsbuild.cjs +389 -464
  63. package/dist/transform/rsbuild.cjs.map +1 -1
  64. package/dist/transform/rsbuild.js +3 -3
  65. package/dist/transform/rspack.cjs +389 -464
  66. package/dist/transform/rspack.cjs.map +1 -1
  67. package/dist/transform/rspack.js +3 -3
  68. package/dist/transform/swc.cjs +402 -471
  69. package/dist/transform/swc.cjs.map +1 -1
  70. package/dist/transform/swc.js +19 -13
  71. package/dist/transform/swc.js.map +1 -1
  72. package/dist/transform/unplugin.cjs +389 -464
  73. package/dist/transform/unplugin.cjs.map +1 -1
  74. package/dist/transform/unplugin.js +3 -3
  75. package/dist/transform/vite.cjs +389 -464
  76. package/dist/transform/vite.cjs.map +1 -1
  77. package/dist/transform/vite.js +3 -3
  78. package/dist/transform/webpack.cjs +389 -464
  79. package/dist/transform/webpack.cjs.map +1 -1
  80. package/dist/transform/webpack.js +3 -3
  81. package/package.json +10 -21
  82. package/dist/chunk-6R33XLNY.js +0 -28
  83. package/dist/chunk-6R33XLNY.js.map +0 -1
  84. package/dist/chunk-EXTDH26A.js.map +0 -1
  85. package/dist/chunk-OXFZJP4E.js.map +0 -1
  86. package/dist/chunk-PACLPKDH.js +0 -513
  87. package/dist/chunk-PACLPKDH.js.map +0 -1
  88. package/dist/transform/typescript.cjs +0 -566
  89. package/dist/transform/typescript.cjs.map +0 -1
  90. package/dist/transform/typescript.d.cts +0 -22
  91. package/dist/transform/typescript.d.ts +0 -22
  92. package/dist/transform/typescript.js +0 -10
  93. package/dist/transform/typescript.js.map +0 -1
  94. /package/dist/{chunk-E6YNESVO.js.map → chunk-FSVGIKQT.js.map} +0 -0
  95. /package/dist/{chunk-NOWQOHCR.js.map → chunk-PPNFMVOH.js.map} +0 -0
  96. /package/dist/{chunk-3NIUOINN.js.map → chunk-W6I5QA62.js.map} +0 -0
  97. /package/dist/{http-G3U247I4.js.map → http-3WBKIQI4.js.map} +0 -0
  98. /package/dist/{http-UQTRAPDD.js.map → http-BK6UJNXI.js.map} +0 -0
  99. /package/dist/{replay-MPMU3VBP.js.map → replay-OEANLAUE.js.map} +0 -0
  100. /package/dist/{replay-SK4FOKUB.js.map → replay-ZTEDZUSG.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 import_typescript2 = __toESM(require("typescript"), 1);
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.replace(/\\/g, "/").split(/[?#]/, 1)[0] ?? "";
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/typescriptTransformer.ts
62
- var import_typescript = __toESM(require("typescript"), 1);
63
- function hasUseClientDirective(sourceFile) {
64
- return sourceFile.statements.some(
65
- (statement) => import_typescript.default.isExpressionStatement(statement) && import_typescript.default.isStringLiteral(statement.expression) && statement.expression.text === "use client"
66
- );
67
- }
68
- function hasTransformMarker(sourceFile) {
69
- return sourceFile.statements.some(
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 withNodeFunctionName(node) {
79
- if (!isBitfabMemberCall(node, "withNode") || node.arguments.length > 2) {
80
- return null;
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
- const fn = node.arguments[node.arguments.length - 1];
83
- if (import_typescript.default.isIdentifier(fn)) {
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
- if (import_typescript.default.isPropertyAccessExpression(fn)) {
87
- return fn.name.text;
94
+ const parent = path.parentPath?.node;
95
+ if (types.isVariableDeclarator(parent)) {
96
+ return propertyName(parent.id, types) ?? "anonymous";
88
97
  }
89
- if (import_typescript.default.isFunctionExpression(fn) && fn.name) {
90
- return fn.name.text;
98
+ if (types.isObjectProperty(parent) && !parent.computed) {
99
+ return propertyName(parent.key, types) ?? "anonymous";
91
100
  }
92
- return null;
101
+ const { line, column } = sourcePosition(path);
102
+ return `anonymous-${line}-${column}`;
93
103
  }
94
- function traceDecorators(node) {
95
- if (!import_typescript.default.canHaveDecorators(node)) {
96
- return [];
104
+ function isInstrumentableFunction(node, types) {
105
+ if (node.generator || types.isClassPrivateMethod(node)) {
106
+ return false;
97
107
  }
98
- return import_typescript.default.getDecorators(node) ?? [];
108
+ return !(types.isClassMethod(node) || types.isObjectMethod(node)) || node.kind === "method";
99
109
  }
100
- function isTraceDecoratorRoot(node) {
101
- return traceDecorators(node).some(
102
- (decorator) => isBitfabMemberCall(decorator.expression, "trace")
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 collectBitfabWrappedFunctions(sourceFile) {
106
- const inlineRoots = /* @__PURE__ */ new Set();
107
- const referencedRoots = /* @__PURE__ */ new Set();
108
- function visit(node) {
109
- if (isBitfabMemberCall(node, "withTrace") || isBitfabMemberCall(node, "withSpan")) {
110
- const fn = node.arguments[node.arguments.length - 1];
111
- if (fn && (import_typescript.default.isArrowFunction(fn) || import_typescript.default.isFunctionExpression(fn))) {
112
- inlineRoots.add(fn);
113
- } else if (fn && import_typescript.default.isIdentifier(fn)) {
114
- referencedRoots.add(fn.text);
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
- import_typescript.default.forEachChild(node, visit);
151
+ ancestor = ancestor.parentPath;
118
152
  }
119
- visit(sourceFile);
120
- return { inlineRoots, referencedRoots };
153
+ return [...scopes, ownName].join(".");
121
154
  }
122
- function declaredFunctionName(node) {
123
- if (node.name && import_typescript.default.isIdentifier(node.name)) {
124
- return node.name.text;
155
+ function isTraceDecoratorRoot(path, types) {
156
+ const node = path.node;
157
+ if (!types.isClassMethod(node) && !types.isClassPrivateMethod(node)) {
158
+ return false;
125
159
  }
126
- if ((import_typescript.default.isArrowFunction(node) || import_typescript.default.isFunctionExpression(node)) && import_typescript.default.isVariableDeclaration(node.parent) && import_typescript.default.isIdentifier(node.parent.name)) {
127
- return node.parent.name.text;
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 ((import_typescript.default.isArrowFunction(node) || import_typescript.default.isFunctionExpression(node)) && import_typescript.default.isPropertyAssignment(node.parent) && (import_typescript.default.isIdentifier(node.parent.name) || import_typescript.default.isStringLiteral(node.parent.name))) {
130
- return node.parent.name.text;
174
+ if (!parent.arguments.some((argument) => argument === path.node)) {
175
+ return false;
131
176
  }
132
- return null;
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 objectContainerName(node) {
135
- if (import_typescript.default.isVariableDeclaration(node.parent) && import_typescript.default.isIdentifier(node.parent.name)) {
136
- return node.parent.name.text;
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 (import_typescript.default.isPropertyAssignment(node.parent) && (import_typescript.default.isIdentifier(node.parent.name) || import_typescript.default.isStringLiteral(node.parent.name))) {
139
- return node.parent.name.text;
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 functionName(node) {
144
- const ownName = declaredFunctionName(node);
145
- if (ownName) {
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 sourceFile = node.getSourceFile();
167
- const position = sourceFile.getLineAndCharacterOfPosition(node.getStart());
168
- return `anonymous-${position.line + 1}-${position.character}`;
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(node, inlineRoots, referencedRoots) {
171
- if (inlineRoots.has(node)) {
210
+ function isBitfabWrappedFunction(path, types) {
211
+ if (isBitfabWrapperArgument(path, types)) {
172
212
  return true;
173
213
  }
174
- const name = declaredFunctionName(node);
175
- return name !== null && referencedRoots.has(name);
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
- return node.body !== void 0 && node.asteriskToken === void 0 && (!node.name || !import_typescript.default.isPrivateIdentifier(node.name));
218
+ const binding = path.scope.getBinding(bindingName);
219
+ return binding?.referencePaths.some(
220
+ (referencePath) => isBitfabWrapperArgument(referencePath, types)
221
+ ) ?? false;
182
222
  }
183
- function normalizedFilename(filename, cwd) {
184
- const normalized = filename.replace(/\\/g, "/").split(/[?#]/, 1)[0] ?? "";
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 parameterInputs(factory, node) {
189
- return factory.createArrayLiteralExpression(
190
- node.parameters.map((parameter, index) => {
191
- if (!import_typescript.default.isArrowFunction(node)) {
192
- if (parameter.dotDotDotToken) {
193
- return factory.createSpreadElement(
194
- factory.createCallExpression(
195
- factory.createPropertyAccessExpression(
196
- factory.createArrayLiteralExpression([
197
- factory.createSpreadElement(
198
- factory.createIdentifier("arguments")
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
- void 0,
204
- [factory.createNumericLiteral(index)]
248
+ [types.numericLiteral(index)]
205
249
  )
206
- );
207
- }
208
- return factory.createElementAccessExpression(
209
- factory.createIdentifier("arguments"),
210
- factory.createNumericLiteral(index)
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
- if (import_typescript.default.isIdentifier(parameter.name)) {
214
- const identifier = factory.createIdentifier(parameter.name.text);
215
- return parameter.dotDotDotToken ? factory.createSpreadElement(identifier) : identifier;
216
- }
217
- throw new Error(
218
- "Bitfab transform invariant: arrow parameter requires argument wrapper"
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(node) {
224
- return import_typescript.default.isArrowFunction(node) && node.parameters.some(
225
- (parameter) => !import_typescript.default.isIdentifier(parameter.name) || parameter.initializer !== void 0
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(node) {
229
- return node.parameters.length === 1 && node.parameters[0]?.dotDotDotToken !== void 0;
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 splitDirectivePrologue(body) {
232
- const firstNonDirective = body.statements.findIndex(
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
- directives: body.statements.slice(0, firstNonDirective),
240
- statements: body.statements.slice(firstNonDirective)
241
- };
242
- }
243
- function updateFunctionBody(factory, node, body) {
244
- if (import_typescript.default.isFunctionDeclaration(node)) {
245
- return factory.updateFunctionDeclaration(
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
- if (!isInstrumentableFunction(node)) {
329
- return visited;
330
- }
331
- if (!isInstrumentableFunction(visited) || transformedNodes.has(visited) || isTraceDecoratorRoot(node) || isBitfabWrappedFunction(node, inlineRoots, referencedRoots)) {
332
- return visited;
333
- }
334
- const name = functionName(node);
335
- if (name.startsWith("anonymous-")) {
336
- return visited;
337
- }
338
- const position = sourceFile.getLineAndCharacterOfPosition(node.getStart());
339
- const definition = factory.createObjectLiteralExpression(
340
- [
341
- factory.createPropertyAssignment(
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
- factory.createReturnStatement(
422
- factory.createCallExpression(runtimeIdentifier, void 0, [
423
- definitionIdentifier,
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
- factory.createBindingElement(
505
- void 0,
506
- "__bitfabAutoTraceActive",
507
- activeIdentifier
314
+ types.importSpecifier(
315
+ state.activeIdentifier,
316
+ types.identifier("__bitfabAutoTraceActive")
508
317
  ),
509
- ...usedWrapper ? [
510
- factory.createBindingElement(
511
- void 0,
512
- "__bitfabAutoWrap",
513
- wrapperIdentifier
318
+ ...state.usedWrapper ? [
319
+ types.importSpecifier(
320
+ state.wrapperIdentifier,
321
+ types.identifier("__bitfabAutoWrap")
514
322
  )
515
323
  ] : []
516
- ]),
517
- void 0,
518
- void 0,
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
- import_typescript.default.NodeFlags.Const
531
- )
532
- ) : runtimeImport,
533
- transformMarker,
534
- ...definitions,
535
- ...transformed.statements
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
- function hasAsyncModifier(node) {
540
- return import_typescript.default.canHaveModifiers(node) ? import_typescript.default.getModifiers(node)?.some((modifier) => modifier.kind === import_typescript.default.SyntaxKind.AsyncKeyword) ?? false : false;
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 configPath = configuredPath ?? import_typescript2.default.findConfigFile((0, import_node_path.dirname)(filename), import_typescript2.default.sys.fileExists, "tsconfig.json");
555
- if (!configPath) {
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 moduleKindForFormat(filename, format) {
575
- if (format === "commonjs" || filename.endsWith(".cts")) {
576
- return import_typescript2.default.ModuleKind.CommonJS;
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 import_typescript2.default.ModuleKind.ESNext;
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 compilerOptions = readCompilerOptions(filename, tsconfig);
586
- const result = import_typescript2.default.transpileModule(source, {
587
- compilerOptions: {
588
- ...compilerOptions,
589
- allowJs: true,
590
- declaration: false,
591
- emitDeclarationOnly: false,
592
- inlineSourceMap: sourceMapMode === "inline",
593
- inlineSources: sourceMapMode === "inline",
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
- const errors = result.diagnostics?.filter(
607
- (diagnostic) => diagnostic.category === import_typescript2.default.DiagnosticCategory.Error
608
- );
609
- if (errors && errors.length > 0) {
610
- throw new Error(
611
- import_typescript2.default.formatDiagnostics(errors, {
612
- getCanonicalFileName: (file) => file,
613
- getCurrentDirectory: () => process.cwd(),
614
- getNewLine: () => "\n"
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: result.outputText,
620
- ...result.sourceMapText ? { map: result.sourceMapText } : {}
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: