Skip to content

Commit 4e616df

Browse files
JPeer264claude
andcommitted
fix(cloudflare): Count a default export re-exporting a wrapped class as auto-wrapped
`export default Foo`, where a named export already wrapped `Foo`, skips wrapping to avoid `withSentry(withSentry(...))`, but the binding still points at the wrapped class. Mark the default export as auto-wrapped so an entrypoint-less self service binding survives into `rpcTracePropagationBindings`. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
1 parent abccfb2 commit 4e616df

2 files changed

Lines changed: 23 additions & 2 deletions

File tree

packages/cloudflare/src/vite/transform.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -303,8 +303,12 @@ function wrapDefaultExport(node: ExportDefaultNode, ctx: TransformContext, state
303303

304304
// `export default Foo` where `Foo` is a local class already wrapped by a named
305305
// export (e.g. a self-bound WorkerEntrypoint also used as the default handler).
306-
// Wrapping again would produce `withSentry(withSentry(...))`.
307-
if (decl.type === 'Identifier' && state.renamedLocals.has((decl as IdentifierNode).name)) return;
306+
// Wrapping again would produce `withSentry(withSentry(...))`. The binding still
307+
// points at the wrapped class, so the default export counts as auto-wrapped.
308+
if (decl.type === 'Identifier' && state.renamedLocals.has((decl as IdentifierNode).name)) {
309+
state.autoWrapped.add(undefined);
310+
return;
311+
}
308312

309313
// `export default <expr>` → `const __SENTRY_DEFAULT_EXPORT__ = <expr>`
310314
// MagicString positions are always relative to the original source.

packages/cloudflare/test/vite/transform.test.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -726,6 +726,23 @@ describe('same-worker RPC binding floor', () => {
726726
expect(result.code).toContain('rpcTracePropagationBindings: ["SELF",');
727727
});
728728

729+
it('enables a self service binding when the default export re-exports an already wrapped class', () => {
730+
const code = [
731+
"import { WorkerEntrypoint } from 'cloudflare:workers';",
732+
'class AdminEntry extends WorkerEntrypoint {}',
733+
'export { AdminEntry };',
734+
'export default AdminEntry;',
735+
].join('\n');
736+
737+
const result = transform(code, {
738+
classWrappers: new Map(),
739+
optionsFn: '() => undefined',
740+
sameWorkerBindings: [{ bindingName: 'SELF' }],
741+
})!;
742+
743+
expect(result.code).toContain('rpcTracePropagationBindings: ["SELF",');
744+
});
745+
729746
it('drops a binding whose class was wrapped by hand', () => {
730747
// A hand-wrapped receiver runs on its own options and would see the trailing argument.
731748
const code = [

0 commit comments

Comments
 (0)