esbuild icon indicating copy to clipboard operation
esbuild copied to clipboard

Preserve V8 Explicit Compile Hints magic comments

Open Inqnuam opened this issue 7 months ago • 1 comments

Feature Request: Preserve //# allFunctionsCalledOnLoad Comment for V8 Explicit Compile Hints

V8 recently introduced a feature called Explicit Compile Hints, which is already available in Chrome 136 and newer.

Currently, esbuild only preserves hashbangs and legal comments by default. It would be helpful if esbuild could also preserve the new //# allFunctionsCalledOnLoad comment—either by default, via a new option, or based on the target configuration.

I'm not sure when exactly this should be enabled or disabled (e.g., during build vs transform), so I'm open to discussion on the best approach.


Input:

//# allFunctionsCalledOnLoad

function testfunc2() {
  // this is a comment
  console.log('testfunc2 called!');
}

testfunc2();

current output:

function testfunc2() {
  console.log("testfunc2 called!");
}
testfunc2();

desired output:

//# allFunctionsCalledOnLoad
function testfunc2() {
  console.log("testfunc2 called!");
}
testfunc2();

Inqnuam avatar Jul 18 '25 15:07 Inqnuam

This is already possible with esbuild's banner feature. Like this: link

Given that it's a niche feature for a single engine, it seems like it's really a decision for the developer doing the bundling instead of a property of the source code, and it sounds like it's still under development, I'm not convinced that support for this needs to be added to esbuild itself. The existing banner feature is intended for engine-specific things like this that need to be prepended to the generated source code.

evanw avatar Jul 18 '25 17:07 evanw