import { applyReplacements } from "./replacements";
/**
* Slices a string until it hits a }, but keeping in mind JS comments,
* regex, template literals, comments, and matching {
*
* Used to extract function bodies without parsing the code.
*
* If you pass replace=true, it will run replacements on the code
*/
export function sliceSourceCode(
contents: string,
replace: boolean,
replaceRequire?: (specifier: string) => string,
endOnComma = false,
): { result: string; rest: string } {
let bracketCount = 0;
let i = 0;
let result = "";
while (contents.length) {
const match = contents.match(
endOnComma && bracketCount <= 1
? /((?:[(,=;:{]|return|\=\>)\s*)\/[^\/\*]|\/\*|\/\/|['"}`\),]|(?)\s*)\/[^\/\*]|\/\*|\/\/|['"}`\)]|(?
Unnamed repository; edit this file 'description' to name the repository.
The exit code support is between 0-255 and not only in the signed positive range
(0-127).
Node.js does not seam to throw on a bigger integer and just wraps around,
but throwing a error is a good approach and makes the behaviour more defined.
This allows the range to be 0-255
Fixes: https://github.com/oven-sh/bun/issues/6284
Returning undefined simply falls through to the next plugin, or to the default loader.
This is defined by esbuild, and supported by Bun, but the types don't reflect it properly.