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*)\/[^\/\*]|\/\*|\/\/|['"}`\)]|(?