GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — feat(bundler-plugins): Add the call-site rewriter core by timfish · Pull Request #26101 · getsentry/sentry-javascript

feat(bundler-plugins): Add the call-site rewriter core #26101

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Sign up for GitHub

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
timfish merged 8 commits into develop from feat/call-site-rewriter-core
Nov 26, 2026
+2,341 −0
Merged

feat(bundler-plugins): Add the call-site rewriter core #26101

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
8 commits
Select commit Hold shift + click to select a range
39cf664
feat(bundler-plugins): Add the call-site rewriter core
timfish Oct 22, 2026
22917ac
fix(bundler-plugins): Strip the id query without a backtracking regex
timfish Nov 4, 2026
90c171d
ref(bundler-plugins): Drop non-null assertions from the rewriter
timfish Nov 25, 2026
31eb366
fix(bundler-plugins): Find destructured bindings when wrapping a loca…
timfish Nov 25, 2026
3867957
fix(bundler-plugins): Allow wrapping two names of one inline export
timfish Nov 25, 2026
6cc0d67
fix(bundler-plugins): Keep decorators before the export clause of an …
timfish Nov 26, 2026
03ec3d4
fix(bundler-plugins): Ignore type-only imports when collecting declar…
timfish Nov 26, 2026
f54f2e3
fix(bundler-plugins): Ignore type-only imports when finding base classes
timfish Nov 26, 2026
File filter
Filter by extension


Clear filters
Conversations
Failed to load comments.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Jump to
Jump to file
Failed to load files.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Diff view
Diff view

There are no files selected for viewing

5 changes: 5 additions & 0 deletions 5 packages/bundler-plugins/package.json
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@
"import": "./build/esm/babel-plugin/index.js",
"require": "./build/cjs/babel-plugin/index.js"
},
"./rewriter": {
"types": "./build/types/rewriter/index.d.ts",
"import": "./build/esm/rewriter/index.js",
"require": "./build/cjs/rewriter/index.js"
},
Comment thread

@cursor cursor Bot Nov 25, 2026

Copy link
Copy Markdown

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rewriter export missing runtime-entries coverage

Low Severity

This was flagged because it is called out in the review rules file: a new ./rewriter export that can load on Node, while @sentry/bundler-plugins has no entry in CASES or BUILD_TIME_CASES in dev-packages/bundler-tests/tests/runtime-entries.test.ts. That test is what keeps server runtime entries from pulling in build-time tooling.

Fix in Cursor Fix in Web

Triggered by project rule: PR Review Guidelines for Cursor Bot

Reviewed by Cursor Bugbot for commit 8b2355d. Configure here.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@timfish timfish Nov 26, 2026

Copy link
Copy Markdown
Collaborator Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

./rewriter is build-time code that only the SDK Vite plugins import, and BUILD_TIME_PATTERNS already fails any runtime entry that pulls in @sentry/bundler-plugins.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
"./sentry-release-injection-file": {
"import": "./sentry-release-injection-file.js",
"require": "./sentry-release-injection-file.js"
Expand Down
1 change: 1 addition & 0 deletions 1 packages/bundler-plugins/rollup.npm.config.mjs
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export default makeNPMConfigVariants(
'src/webpack/index.ts',
'src/webpack/component-annotation-transform.ts',
'src/babel-plugin/index.ts',
'src/rewriter/index.ts',
],
packageSpecificConfig: {
// This package only ever runs in Node, at build time. Without pinning the platform, rolldown
Expand Down
31 changes: 31 additions & 0 deletions 31 packages/bundler-plugins/src/rewriter/arrays.ts
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import type { ArrayExpressionNode, BaseNode, IdentifierNode } from './ast';
import type { RewriteState } from './rewriter';

/**
* Replace an array literal of identifiers with `build(names)`, where `names`
* holds each identifier once, in source order. An empty array is left alone.
* An array holding anything other than plain identifiers is left alone and
* recorded as skipped under `label`.
*
* @returns whether the array was replaced
*/
export function wrapArrayLiteral(
state: RewriteState,
arrayNode: BaseNode,
label: string,
build: (names: string[]) => string,
): boolean {
const elements = (arrayNode as ArrayExpressionNode).elements ?? [];
if (elements.length === 0) return false;

if (!elements.every(element => element?.type === 'Identifier')) {
state.report.skipped.push(label);
return false;
}

const names = [...new Set(elements.map(element => (element as IdentifierNode).name))];
state.ms.overwrite(arrayNode.start, arrayNode.end, build(names));
state.needsImport = true;
state.report.wrapped.push(label);
return true;
}
215 changes: 215 additions & 0 deletions 215 packages/bundler-plugins/src/rewriter/ast.ts
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,215 @@
// Minimal ESTree node shapes. Any parser that puts `start`/`end` offsets on
// every node fits (oxc, acorn, Rollup's `this.parse`).

export interface BaseNode {
type: string;
start: number;
end: number;
}

export interface ProgramBody {
body: BaseNode[];
hashbang?: BaseNode | null;
}

export interface IdentifierNode extends BaseNode {
name: string;
}

/** An `Identifier` or, for `export { x as "name" }`, a string `Literal`. */
export interface NameNode {
type: string;
name?: string;
value?: unknown;
}

export interface CallExpressionNode extends BaseNode {
callee?: { type: string; name?: string; property?: { type: string; name?: string } };
arguments?: BaseNode[];
}

export interface MemberExpressionNode extends BaseNode {
object?: { type: string; name?: string };
property?: { type: string; name?: string };
}

export interface ClassDeclarationNode extends BaseNode {
id?: IdentifierNode | null;
superClass?: BaseNode | null;
decorators?: BaseNode[] | null;
}

export interface ExportDefaultNode extends BaseNode {
declaration: BaseNode;
}

export interface ExportSpecifierNode extends BaseNode {
local?: NameNode;
exported?: NameNode;
exportKind?: string;
}

export interface ExportNamedNode extends BaseNode {
declaration?: BaseNode | null;
source?: (BaseNode & { value?: unknown }) | null;
specifiers?: ExportSpecifierNode[];
exportKind?: string;
}

export interface ExportAllNode extends BaseNode {
source?: { value?: unknown };
exported?: NameNode | null;
exportKind?: string;
}

export interface VariableDeclaratorNode {
id?: BaseNode | null;
init?: BaseNode | null;
}

export interface VariableDeclarationNode extends BaseNode {
declarations?: VariableDeclaratorNode[];
}

export interface ImportSpecifierNode {
type: string;
imported?: NameNode;
local?: NameNode;
importKind?: string;
}

export interface ImportDeclarationNode extends BaseNode {
source?: { value?: unknown };
specifiers?: ImportSpecifierNode[];
importKind?: string;
}

export interface ArrayExpressionNode extends BaseNode {
elements?: Array<BaseNode | null>;
}

export interface PropertyNode extends BaseNode {
key?: NameNode;
value?: BaseNode;
computed?: boolean;
}

/** The declaration a top-level statement makes, looking through `export` (`export const x = ...`). */
export function declarationOf(node: BaseNode): BaseNode | null | undefined {
return node.type === 'ExportNamedDeclaration' ? (node as ExportNamedNode).declaration : node;
}
Comment thread

@cursor cursor Bot Nov 26, 2026

Copy link
Copy Markdown

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Default-exported classes are not found

Medium Severity

declarationOf only unwraps ExportNamedDeclaration, so findClassesExtending, collectTopLevelClasses, and collectDeclaringStatements never see export default class Foo {} or export default function foo() {}. shapeFromAst already records those named default classes, so the collectors disagree on the same module. A default-exported WorkerEntrypoint subclass is a common Cloudflare form and would not be found.

Additional Locations (2)
  • packages/bundler-plugins/src/rewriter/class-extends.ts#L39-L45
  • packages/bundler-plugins/src/rewriter/exports.ts#L40-L66
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 65ef1b6. Configure here.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

sentry-warden[bot] reacted with eyes emoji
All reactions
  • 👀 1 reaction

@timfish timfish Nov 26, 2026

Copy link
Copy Markdown
Collaborator Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Cloudflare class scans on develop also skip export default class, so this is not new in this PR.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

/** Whether `node` calls `methodName`, either bare (`fn()`) or as a member (`ns.fn()`). */
export function isCallToMethod(node: BaseNode, methodName: string): boolean {
if (node.type !== 'CallExpression') return false;
const callee = (node as CallExpressionNode).callee;
if (!callee) return false;
if (callee.type === 'Identifier' && callee.name === methodName) return true;
return (
callee.type === 'MemberExpression' && callee.property?.type === 'Identifier' && callee.property.name === methodName
);
}

export function isAnonymousFunctionOrClass(node: BaseNode): boolean {
if (node.type === 'ArrowFunctionExpression') return true;
const isFunctionOrClass = [
'FunctionExpression',
'FunctionDeclaration',
'ClassExpression',
'ClassDeclaration',
].includes(node.type);
return isFunctionOrClass && !(node as ClassDeclarationNode).id;
}

/** `export type { X }` or `export { type X }`, which TypeScript erases. */
export function isTypeOnlyExport(node: { exportKind?: string }): boolean {
return node.exportKind === 'type';
}

/** The name an export or import specifier refers to, for both `x` and `"x"`. */
export function exportedName(node: NameNode | undefined): string | undefined {
if (node?.type === 'Identifier') return node.name;
if (node?.type === 'Literal' && typeof node.value === 'string') return node.value;
return undefined;
}

/**
* The offset after the hashbang and the directive prologue (`'use server'`),
* where code may be inserted without changing what the module means.
*/
export function directivesEnd(ast: ProgramBody): number {
let end = ast.hashbang?.end ?? 0;
for (const node of ast.body) {
if (node.type !== 'ExpressionStatement' || typeof (node as { directive?: unknown }).directive !== 'string') break;
end = node.end;
}
return end;
}

/**
* The binding names a declaration introduces, including names inside
* destructuring patterns. `undefined` for a declaration that binds no runtime
* value (`interface`, `type`).
*/
export function declaredNames(declaration: BaseNode): string[] | undefined {
switch (declaration.type) {
case 'ClassDeclaration':
case 'FunctionDeclaration': {
const name = (declaration as ClassDeclarationNode).id?.name;
return name ? [name] : undefined;
}
case 'VariableDeclaration': {
const names: string[] = [];
for (const declarator of (declaration as VariableDeclarationNode).declarations ?? []) {
collectPatternNames(declarator.id, names);
}
return names;
}
default:
return undefined;
}
}

function collectPatternNames(pattern: BaseNode | null | undefined, names: string[]): void {
if (!pattern) return;
const node = pattern as BaseNode & {
name?: string;
properties?: Array<BaseNode & { value?: BaseNode; argument?: BaseNode }>;
elements?: Array<BaseNode | null>;
left?: BaseNode;
argument?: BaseNode;
};
switch (node.type) {
case 'Identifier':
if (node.name) names.push(node.name);
break;
case 'ObjectPattern':
for (const property of node.properties ?? []) {
collectPatternNames(property.type === 'RestElement' ? property.argument : property.value, names);
}
break;
case 'ArrayPattern':
for (const element of node.elements ?? []) collectPatternNames(element, names);
break;
case 'AssignmentPattern':
collectPatternNames(node.left, names);
break;
case 'RestElement':
collectPatternNames(node.argument, names);
break;
}
}

/** Visit `node` and every node below it, parents first. */
export function walk(node: unknown, visit: (node: BaseNode) => void): void {
if (Array.isArray(node)) {
for (const child of node) walk(child, visit);
return;
}
if (!node || typeof node !== 'object' || typeof (node as BaseNode).type !== 'string') return;

visit(node as BaseNode);
for (const value of Object.values(node)) {
if (value && typeof value === 'object') walk(value, visit);
}
}
104 changes: 104 additions & 0 deletions 104 packages/bundler-plugins/src/rewriter/class-extends.ts
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
import type {
BaseNode,
ClassDeclarationNode,
IdentifierNode,
ImportDeclarationNode,
MemberExpressionNode,
ProgramBody,
} from './ast';
import { declarationOf } from './ast';

/** A base class, named by the module it is imported from and its export name. */
export interface BaseClassRef {
module: string;
name: string;
}

interface BaseBindings {
/** Local identifiers bound to the named import of the base class. */
named: Set<string>;
/** Local identifiers bound to a `* as ns` import of the base module. */
namespaces: Set<string>;
}

/**
* Find top-level classes that (transitively, within this module) extend the
* given base class. A superclass must be a plain identifier (`extends Base`)
* or member access (`extends ns.Base`).
*
* Only same-file base chains are resolvable here; a base class imported from
* another module under a different name is invisible.
*/
export function findClassesExtending(ast: ProgramBody, base: BaseClassRef): Set<string> {
const bases = collectBaseImports(ast, base);
if (bases.named.size === 0 && bases.namespaces.size === 0) {
return new Set<string>();
}

// Every top-level class, including the `export class Foo {}` form.
const classes = new Map<string, ClassDeclarationNode>();
for (const node of ast.body) {
const declaration = declarationOf(node);
if (declaration?.type !== 'ClassDeclaration') continue;
const classNode = declaration as ClassDeclarationNode;
if (classNode.id?.name) classes.set(classNode.id.name, classNode);
}
Comment thread
sentry-warden[bot] marked this conversation as resolved.
Resolved

Uh oh!

There was an error while loading. Please reload this page.


const found = new Set<string>();
// Iterate to a fixed point so an indirect chain (A extends B extends Base) is
// fully resolved regardless of declaration order.
let changed = true;
while (changed) {
changed = false;
for (const [name, classNode] of classes) {
if (found.has(name)) continue;
if (extendsBase(classNode.superClass, base, bases, found)) {
found.add(name);
changed = true;
}
}
}
return found;
}

function collectBaseImports(ast: ProgramBody, base: BaseClassRef): BaseBindings {
const named = new Set<string>();
const namespaces = new Set<string>();
for (const node of ast.body) {
if (node.type !== 'ImportDeclaration') continue;
const importNode = node as ImportDeclarationNode;
if (importNode.source?.value !== base.module || importNode.importKind === 'type') continue;
for (const specifier of importNode.specifiers ?? []) {
if (specifier.importKind === 'type') continue;
if (specifier.type === 'ImportSpecifier' && specifier.imported?.name === base.name && specifier.local?.name) {
named.add(specifier.local.name);
} else if (specifier.type === 'ImportNamespaceSpecifier' && specifier.local?.name) {
namespaces.add(specifier.local.name);
}
}
}
return { named, namespaces };
}
Comment thread
sentry-warden[bot] marked this conversation as resolved.
Resolved

Uh oh!

There was an error while loading. Please reload this page.


function extendsBase(
superClass: BaseNode | null | undefined,
base: BaseClassRef,
bases: BaseBindings,
detected: Set<string>,
): boolean {
if (!superClass) return false;
if (superClass.type === 'Identifier') {
const name = (superClass as IdentifierNode).name;
return bases.named.has(name) || detected.has(name);
}
if (superClass.type === 'MemberExpression') {
const member = superClass as MemberExpressionNode;
return (
member.object?.type === 'Identifier' &&
!!member.object.name &&
bases.namespaces.has(member.object.name) &&
member.property?.name === base.name
);
}
return false;
}
Loading
Oops, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Loading
Oops, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.