/**
 * This file is part of the NocoBase (R) project.
 * Copyright (c) 2020-2024 NocoBase Co., Ltd.
 * Authors: NocoBase Team.
 *
 * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
 * For more information, please refer to: https://www.nocobase.com/agreement.
 */

var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var source_exports = {};
__export(source_exports, {
  collectArrowExpressionRanges: () => collectArrowExpressionRanges,
  collectAstFunctionBodyRanges: () => collectAstFunctionBodyRanges,
  collectBraceRanges: () => collectBraceRanges,
  collectComputedMethodCandidates: () => collectComputedMethodCandidates,
  collectFunctionRanges: () => collectFunctionRanges,
  collectMethodCandidates: () => collectMethodCandidates,
  collectMethodFunctionRanges: () => collectMethodFunctionRanges,
  collectStaticBlockRanges: () => collectStaticBlockRanges,
  escapeRegExp: () => escapeRegExp,
  findArrowExpressionEnd: () => findArrowExpressionEnd,
  findBraceBodyAfter: () => findBraceBodyAfter,
  findFunctionRanges: () => findFunctionRanges,
  findMatches: () => findMatches,
  findMatchingBrace: () => findMatchingBrace,
  findMatchingDelimiter: () => findMatchingDelimiter,
  findMethodPrefixToken: () => findMethodPrefixToken,
  findTemplateExpressionEnd: () => findTemplateExpressionEnd,
  findTopLevelChar: () => findTopLevelChar,
  getAstSource: () => getAstSource,
  getCallArgumentSource: () => getCallArgumentSource,
  getCallArgumentSources: () => getCallArgumentSources,
  getCallFirstArgumentSource: () => getCallFirstArgumentSource,
  getPreviousSignificantToken: () => getPreviousSignificantToken,
  getPreviousSignificantTokenInfo: () => getPreviousSignificantTokenInfo,
  isInsideRanges: () => isInsideRanges,
  isRegexLiteralStart: () => isRegexLiteralStart,
  maskJavaScriptComments: () => maskJavaScriptComments,
  maskJavaScriptSource: () => maskJavaScriptSource,
  maskTemplateLiteral: () => maskTemplateLiteral,
  maskTemplateLiteralComments: () => maskTemplateLiteralComments,
  mergeRanges: () => mergeRanges,
  readCompleteStringLiteral: () => readCompleteStringLiteral,
  readLeadingStringLiteral: () => readLeadingStringLiteral,
  skipJavaScriptTrivia: () => skipJavaScriptTrivia,
  skipQuotedLiteral: () => skipQuotedLiteral,
  skipRegexLiteral: () => skipRegexLiteral,
  skipTemplateLiteral: () => skipTemplateLiteral,
  splitTopLevel: () => splitTopLevel,
  splitTopLevelWithRanges: () => splitTopLevelWithRanges,
  stripEnclosure: () => stripEnclosure,
  trimBindingElement: () => trimBindingElement
});
module.exports = __toCommonJS(source_exports);
var import_constants = require("../runtime/constants");
var import_walk = require("./walk");
function maskJavaScriptSource(source) {
  const chars = source.split("");
  const maskRange = (start, end) => {
    for (let index2 = start; index2 < end; index2 += 1) {
      if (chars[index2] !== "\n" && chars[index2] !== "\r") {
        chars[index2] = " ";
      }
    }
  };
  let index = 0;
  while (index < source.length) {
    const char = source[index];
    const next = source[index + 1];
    if (char === "/" && next === "/") {
      const start = index;
      index += 2;
      while (index < source.length && source[index] !== "\n") {
        index += 1;
      }
      maskRange(start, index);
      continue;
    }
    if (char === "/" && next === "*") {
      const start = index;
      index += 2;
      while (index < source.length && !(source[index] === "*" && source[index + 1] === "/")) {
        index += 1;
      }
      index = Math.min(source.length, index + 2);
      maskRange(start, index);
      continue;
    }
    if (char === "`") {
      index = maskTemplateLiteral(source, chars, index);
      continue;
    }
    if (char === "/" && isRegexLiteralStart(chars, index)) {
      const start = index;
      index = skipRegexLiteral(source, index);
      maskRange(start, index);
      continue;
    }
    if (char === '"' || char === "'") {
      const quote = char;
      const start = index;
      index += 1;
      while (index < source.length) {
        if (source[index] === "\\") {
          index += 2;
          continue;
        }
        if (source[index] === quote) {
          index += 1;
          break;
        }
        index += 1;
      }
      maskRange(start, index);
      continue;
    }
    index += 1;
  }
  return chars.join("");
}
function maskJavaScriptComments(source) {
  const chars = source.split("");
  const maskRange = (start, end) => {
    for (let index2 = start; index2 < end; index2 += 1) {
      if (chars[index2] !== "\n" && chars[index2] !== "\r") {
        chars[index2] = " ";
      }
    }
  };
  let index = 0;
  while (index < source.length) {
    const char = source[index];
    const next = source[index + 1];
    if (char === "/" && next === "/") {
      const start = index;
      index += 2;
      while (index < source.length && source[index] !== "\n") {
        index += 1;
      }
      maskRange(start, index);
      continue;
    }
    if (char === "/" && next === "*") {
      const start = index;
      index += 2;
      while (index < source.length && !(source[index] === "*" && source[index + 1] === "/")) {
        index += 1;
      }
      index = Math.min(source.length, index + 2);
      maskRange(start, index);
      continue;
    }
    if (char === "`") {
      index = maskTemplateLiteralComments(source, chars, index);
      continue;
    }
    if (char === "/" && isRegexLiteralStart(chars, index)) {
      index = skipRegexLiteral(source, index);
      continue;
    }
    if (char === '"' || char === "'") {
      index = skipQuotedLiteral(source, index, char);
      continue;
    }
    index += 1;
  }
  return chars.join("");
}
function maskTemplateLiteralComments(source, chars, start) {
  let index = start + 1;
  while (index < source.length) {
    if (source[index] === "\\") {
      index += 2;
      continue;
    }
    if (source[index] === "`") {
      return index + 1;
    }
    if (source[index] === "$" && source[index + 1] === "{") {
      const expressionStart = index + 2;
      const expressionEnd = findTemplateExpressionEnd(source, expressionStart);
      const expressionMasked = maskJavaScriptComments(source.slice(expressionStart, expressionEnd));
      for (let offset = 0; offset < expressionMasked.length; offset += 1) {
        chars[expressionStart + offset] = expressionMasked[offset];
      }
      index = Math.min(source.length, expressionEnd + 1);
      continue;
    }
    index += 1;
  }
  return source.length;
}
function maskTemplateLiteral(source, chars, start) {
  const maskRange = (from, to) => {
    for (let index2 = from; index2 < to; index2 += 1) {
      if (chars[index2] !== "\n" && chars[index2] !== "\r") {
        chars[index2] = " ";
      }
    }
  };
  maskRange(start, start + 1);
  let index = start + 1;
  let chunkStart = index;
  while (index < source.length) {
    if (source[index] === "\\") {
      index += 2;
      continue;
    }
    if (source[index] === "`") {
      maskRange(chunkStart, index + 1);
      return index + 1;
    }
    if (source[index] === "$" && source[index + 1] === "{") {
      maskRange(chunkStart, index + 2);
      const expressionStart = index + 2;
      const expressionEnd = findTemplateExpressionEnd(source, expressionStart);
      const expressionMasked = maskJavaScriptSource(source.slice(expressionStart, expressionEnd));
      for (let offset = 0; offset < expressionMasked.length; offset += 1) {
        chars[expressionStart + offset] = expressionMasked[offset];
      }
      if (expressionEnd < source.length) {
        maskRange(expressionEnd, expressionEnd + 1);
      }
      index = Math.min(source.length, expressionEnd + 1);
      chunkStart = index;
      continue;
    }
    index += 1;
  }
  maskRange(chunkStart, source.length);
  return source.length;
}
function findTemplateExpressionEnd(source, start) {
  let depth = 1;
  let index = start;
  while (index < source.length) {
    const char = source[index];
    const next = source[index + 1];
    if (char === "/" && next === "/") {
      index += 2;
      while (index < source.length && source[index] !== "\n") {
        index += 1;
      }
      continue;
    }
    if (char === "/" && next === "*") {
      index += 2;
      while (index < source.length && !(source[index] === "*" && source[index + 1] === "/")) {
        index += 1;
      }
      index = Math.min(source.length, index + 2);
      continue;
    }
    if (char === '"' || char === "'") {
      index = skipQuotedLiteral(source, index, char);
      continue;
    }
    if (char === "`") {
      index = skipTemplateLiteral(source, index);
      continue;
    }
    if (char === "/" && isRegexLiteralStart(source, index)) {
      index = skipRegexLiteral(source, index);
      continue;
    }
    if (char === "{") {
      depth += 1;
    } else if (char === "}") {
      depth -= 1;
      if (depth === 0) {
        return index;
      }
    }
    index += 1;
  }
  return source.length;
}
function skipRegexLiteral(source, start) {
  let index = start + 1;
  let inCharacterClass = false;
  while (index < source.length) {
    const char = source[index];
    if (char === "\\") {
      index += 2;
      continue;
    }
    if (char === "[") {
      inCharacterClass = true;
      index += 1;
      continue;
    }
    if (char === "]" && inCharacterClass) {
      inCharacterClass = false;
      index += 1;
      continue;
    }
    if ((char === "\n" || char === "\r") && !inCharacterClass) {
      return index;
    }
    if (char === "/" && !inCharacterClass) {
      index += 1;
      while (index < source.length && /[A-Za-z]/.test(source[index])) {
        index += 1;
      }
      return index;
    }
    index += 1;
  }
  return source.length;
}
function isRegexLiteralStart(sourceLike, slashIndex) {
  const previous = getPreviousSignificantToken(sourceLike, slashIndex);
  if (!previous) {
    return true;
  }
  if (/^[([{=,:;!~?&|^+\-*%<>]$/.test(previous)) {
    return true;
  }
  return ["return", "throw", "case", "delete", "void", "typeof", "instanceof", "yield", "await", "else"].includes(
    previous
  );
}
function getPreviousSignificantToken(sourceLike, beforeIndex) {
  var _a;
  return ((_a = getPreviousSignificantTokenInfo(sourceLike, beforeIndex)) == null ? void 0 : _a.token) || "";
}
function getPreviousSignificantTokenInfo(sourceLike, beforeIndex) {
  let index = beforeIndex - 1;
  while (index >= 0 && /\s/.test(sourceLike[index])) {
    index -= 1;
  }
  if (index < 0) {
    return void 0;
  }
  const char = sourceLike[index];
  if (/[A-Za-z_$]/.test(char)) {
    let start = index;
    while (start > 0 && /[\w$]/.test(sourceLike[start - 1])) {
      start -= 1;
    }
    return {
      token: Array.isArray(sourceLike) ? sourceLike.slice(start, index + 1).join("") : sourceLike.slice(start, index + 1),
      start,
      end: index + 1
    };
  }
  return {
    token: char,
    start: index,
    end: index + 1
  };
}
function skipQuotedLiteral(source, start, quote) {
  let index = start + 1;
  while (index < source.length) {
    if (source[index] === "\\") {
      index += 2;
      continue;
    }
    if (source[index] === quote) {
      return index + 1;
    }
    index += 1;
  }
  return source.length;
}
function skipTemplateLiteral(source, start) {
  let index = start + 1;
  while (index < source.length) {
    if (source[index] === "\\") {
      index += 2;
      continue;
    }
    if (source[index] === "`") {
      return index + 1;
    }
    if (source[index] === "$" && source[index + 1] === "{") {
      const expressionEnd = findTemplateExpressionEnd(source, index + 2);
      index = Math.min(source.length, expressionEnd + 1);
      continue;
    }
    index += 1;
  }
  return source.length;
}
function findFunctionRanges(masked) {
  const ranges = [];
  collectFunctionRanges(masked, /\bfunction\b[^{]*\{/g, ranges);
  collectFunctionRanges(masked, /=>\s*\{/g, ranges);
  collectArrowExpressionRanges(masked, ranges);
  collectMethodFunctionRanges(masked, ranges);
  return mergeRanges(ranges);
}
function collectAstFunctionBodyRanges(ast) {
  const ranges = [];
  const addBodyRange = (node) => {
    var _a, _b;
    const start = (_a = node.body) == null ? void 0 : _a.start;
    const end = (_b = node.body) == null ? void 0 : _b.end;
    if (typeof start === "number" && typeof end === "number" && end > start) {
      ranges.push({ start, end });
    }
  };
  (0, import_walk.walkAstSimple)(ast, {
    FunctionDeclaration: addBodyRange,
    FunctionExpression: addBodyRange,
    ArrowFunctionExpression: addBodyRange
  });
  return mergeRanges(ranges);
}
function collectFunctionRanges(masked, pattern, ranges) {
  for (const match of masked.matchAll(pattern)) {
    const openBrace = masked.indexOf("{", match.index || 0);
    if (openBrace < 0) {
      continue;
    }
    const closeBrace = findMatchingBrace(masked, openBrace);
    if (closeBrace > openBrace) {
      ranges.push({ start: openBrace, end: closeBrace + 1 });
    }
  }
}
function collectArrowExpressionRanges(masked, ranges) {
  for (const match of masked.matchAll(/=>/g)) {
    let start = (match.index || 0) + match[0].length;
    while (start < masked.length && /\s/.test(masked[start])) {
      start += 1;
    }
    if (masked[start] === "{") {
      continue;
    }
    const end = findArrowExpressionEnd(masked, start);
    if (end > start) {
      ranges.push({ start, end });
    }
  }
}
function collectMethodFunctionRanges(masked, ranges) {
  collectMethodCandidates(masked).forEach((candidate) => {
    ranges.push(candidate.bodyRange);
  });
}
function findBraceBodyAfter(masked, afterIndex) {
  let cursor = afterIndex + 1;
  while (cursor < masked.length && /\s/.test(masked[cursor])) {
    cursor += 1;
  }
  if (masked[cursor] !== "{") {
    return void 0;
  }
  const closeBrace = findMatchingDelimiter(masked, cursor);
  return closeBrace > cursor ? { start: cursor, end: closeBrace + 1 } : void 0;
}
function collectMethodCandidates(masked) {
  const candidates = [];
  const pattern = /\b(?:(?:static|async|get|set)\s+)*(?:\*\s*)?([A-Za-z_$][\w$]*)\s*\(/g;
  for (const match of masked.matchAll(pattern)) {
    const matchIndex = match.index || 0;
    const methodName = match[1];
    if (import_constants.NON_METHOD_CALL_KEYWORDS.has(methodName)) {
      continue;
    }
    const previous = getPreviousSignificantToken(masked, matchIndex);
    if (!["{", ",", ";", "}"].includes(previous)) {
      continue;
    }
    const openParen = masked.indexOf("(", matchIndex);
    const closeParen = findMatchingDelimiter(masked, openParen);
    const bodyRange = findBraceBodyAfter(masked, closeParen);
    if (closeParen > openParen && bodyRange) {
      candidates.push({
        paramsStart: openParen + 1,
        paramsEnd: closeParen,
        bodyRange
      });
    }
  }
  collectComputedMethodCandidates(masked, candidates);
  return candidates;
}
function collectComputedMethodCandidates(masked, candidates) {
  for (const match of masked.matchAll(/\[/g)) {
    const openBracket = match.index || 0;
    const previous = findMethodPrefixToken(masked, openBracket);
    if (!["{", ",", ";", "}"].includes(previous)) {
      continue;
    }
    const closeBracket = findMatchingDelimiter(masked, openBracket);
    if (closeBracket <= openBracket) {
      continue;
    }
    let openParen = closeBracket + 1;
    while (openParen < masked.length && /\s/.test(masked[openParen])) {
      openParen += 1;
    }
    if (masked[openParen] !== "(") {
      continue;
    }
    const closeParen = findMatchingDelimiter(masked, openParen);
    const bodyRange = findBraceBodyAfter(masked, closeParen);
    if (closeParen > openParen && bodyRange) {
      candidates.push({
        paramsStart: openParen + 1,
        paramsEnd: closeParen,
        bodyRange
      });
    }
  }
}
function findMethodPrefixToken(masked, beforeIndex) {
  let previous = getPreviousSignificantTokenInfo(masked, beforeIndex);
  while (previous && ["static", "async", "get", "set", "*"].includes(previous.token)) {
    previous = getPreviousSignificantTokenInfo(masked, previous.start);
  }
  return (previous == null ? void 0 : previous.token) || "";
}
function findArrowExpressionEnd(masked, start) {
  let parenDepth = 0;
  let bracketDepth = 0;
  let braceDepth = 0;
  for (let index = start; index < masked.length; index += 1) {
    const char = masked[index];
    if (parenDepth === 0 && bracketDepth === 0 && braceDepth === 0) {
      if (char === ";" || char === "," || char === "\n" || char === "\r") {
        return index;
      }
      if (char === ")") {
        return index;
      }
    }
    if (char === "(") {
      parenDepth += 1;
    } else if (char === "[") {
      bracketDepth += 1;
    } else if (char === "{") {
      braceDepth += 1;
    } else if (char === ")" && parenDepth > 0) {
      parenDepth -= 1;
    } else if (char === "]" && bracketDepth > 0) {
      bracketDepth -= 1;
    } else if (char === "}" && braceDepth > 0) {
      braceDepth -= 1;
    }
  }
  return masked.length;
}
function findMatchingBrace(masked, openBrace) {
  return findMatchingDelimiter(masked, openBrace);
}
function findMatchingDelimiter(masked, openIndex) {
  const closeByOpen = {
    "(": ")",
    "[": "]",
    "{": "}"
  };
  const stack = [closeByOpen[masked[openIndex]]];
  if (!stack[0]) {
    return -1;
  }
  for (let index = openIndex + 1; index < masked.length; index += 1) {
    const char = masked[index];
    if (closeByOpen[char]) {
      stack.push(closeByOpen[char]);
      continue;
    }
    if (char === stack[stack.length - 1]) {
      stack.pop();
      if (!stack.length) {
        return index;
      }
    }
  }
  return -1;
}
function collectBraceRanges(masked) {
  const ranges = [];
  for (let index = 0; index < masked.length; index += 1) {
    if (masked[index] !== "{") {
      continue;
    }
    const closeBrace = findMatchingDelimiter(masked, index);
    if (closeBrace > index) {
      ranges.push({ start: index, end: closeBrace + 1 });
    }
  }
  return ranges;
}
function collectStaticBlockRanges(masked) {
  const ranges = [];
  for (const match of masked.matchAll(/\bstatic\s*\{/g)) {
    const openBrace = masked.indexOf("{", match.index || 0);
    const closeBrace = findMatchingDelimiter(masked, openBrace);
    if (closeBrace > openBrace) {
      ranges.push({ start: openBrace, end: closeBrace + 1 });
    }
  }
  return mergeRanges(ranges);
}
function mergeRanges(ranges) {
  const sorted = ranges.slice().sort((left, right) => left.start - right.start);
  const merged = [];
  sorted.forEach((range) => {
    const last = merged[merged.length - 1];
    if (last && range.start <= last.end) {
      last.end = Math.max(last.end, range.end);
      return;
    }
    merged.push({ ...range });
  });
  return merged;
}
function isInsideRanges(index, ranges) {
  return ranges.some((range) => index >= range.start && index < range.end);
}
function findMatches(masked, pattern) {
  return [...masked.matchAll(pattern)].map((match) => ({
    index: match.index || 0,
    match: match[0]
  }));
}
function trimBindingElement(pattern) {
  const withoutRest = pattern.trim().replace(/^\.\.\./, "").trim();
  const equal = findTopLevelChar(withoutRest, "=");
  return (equal >= 0 ? withoutRest.slice(0, equal) : withoutRest).trim();
}
function stripEnclosure(pattern, open, close) {
  const trimmed = pattern.trim();
  return trimmed.startsWith(open) && trimmed.endsWith(close) ? trimmed.slice(1, -1) : trimmed;
}
function splitTopLevel(value, separator) {
  const parts = [];
  let start = 0;
  let parenDepth = 0;
  let bracketDepth = 0;
  let braceDepth = 0;
  for (let index = 0; index < value.length; index += 1) {
    const char = value[index];
    if (char === "(") {
      parenDepth += 1;
    } else if (char === ")" && parenDepth > 0) {
      parenDepth -= 1;
    } else if (char === "[") {
      bracketDepth += 1;
    } else if (char === "]" && bracketDepth > 0) {
      bracketDepth -= 1;
    } else if (char === "{") {
      braceDepth += 1;
    } else if (char === "}" && braceDepth > 0) {
      braceDepth -= 1;
    } else if (char === separator && parenDepth === 0 && bracketDepth === 0 && braceDepth === 0) {
      parts.push(value.slice(start, index));
      start = index + 1;
    }
  }
  parts.push(value.slice(start));
  return parts;
}
function splitTopLevelWithRanges(value, separator) {
  const parts = [];
  let start = 0;
  let parenDepth = 0;
  let bracketDepth = 0;
  let braceDepth = 0;
  for (let index = 0; index < value.length; index += 1) {
    const char = value[index];
    if (char === "(") {
      parenDepth += 1;
    } else if (char === ")" && parenDepth > 0) {
      parenDepth -= 1;
    } else if (char === "[") {
      bracketDepth += 1;
    } else if (char === "]" && bracketDepth > 0) {
      bracketDepth -= 1;
    } else if (char === "{") {
      braceDepth += 1;
    } else if (char === "}" && braceDepth > 0) {
      braceDepth -= 1;
    } else if (char === separator && parenDepth === 0 && bracketDepth === 0 && braceDepth === 0) {
      parts.push({ source: value.slice(start, index), start, end: index });
      start = index + 1;
    }
  }
  parts.push({ source: value.slice(start), start, end: value.length });
  return parts;
}
function findTopLevelChar(value, target) {
  let parenDepth = 0;
  let bracketDepth = 0;
  let braceDepth = 0;
  for (let index = 0; index < value.length; index += 1) {
    const char = value[index];
    if (char === "(") {
      parenDepth += 1;
    } else if (char === ")" && parenDepth > 0) {
      parenDepth -= 1;
    } else if (char === "[") {
      bracketDepth += 1;
    } else if (char === "]" && bracketDepth > 0) {
      bracketDepth -= 1;
    } else if (char === "{") {
      braceDepth += 1;
    } else if (char === "}" && braceDepth > 0) {
      braceDepth -= 1;
    } else if (char === target && parenDepth === 0 && bracketDepth === 0 && braceDepth === 0) {
      return index;
    }
  }
  return -1;
}
function readLeadingStringLiteral(value) {
  const index = skipJavaScriptTrivia(value, 0);
  const quote = value[index];
  if (quote !== '"' && quote !== "'" && quote !== "`") {
    return void 0;
  }
  let cursor = index + 1;
  let output = "";
  while (cursor < value.length) {
    const char = value[cursor];
    if (char === "\\") {
      output += value.slice(cursor, Math.min(value.length, cursor + 2));
      cursor += 2;
      continue;
    }
    if (char === quote) {
      return {
        value: output,
        end: cursor + 1
      };
    }
    output += char;
    cursor += 1;
  }
  return void 0;
}
function readCompleteStringLiteral(value) {
  const index = skipJavaScriptTrivia(value, 0);
  const literal = readLeadingStringLiteral(value);
  if (!literal) {
    return void 0;
  }
  const rawLiteral = value.slice(index, literal.end);
  if (rawLiteral.startsWith("`") && rawLiteral.includes("${")) {
    return void 0;
  }
  const rest = value.slice(literal.end);
  if (/^[ \t]*(?:\r\n|\r|\n)/.test(rest)) {
    return literal;
  }
  const restIndex = skipJavaScriptTrivia(rest, 0);
  const next = rest[restIndex];
  if (!next || /[,;)\]}]/.test(next)) {
    return literal;
  }
  return void 0;
}
function skipJavaScriptTrivia(value, start) {
  let index = start;
  while (index < value.length) {
    while (index < value.length && /\s/.test(value[index])) {
      index += 1;
    }
    if (value[index] === "/" && value[index + 1] === "/") {
      index += 2;
      while (index < value.length && value[index] !== "\n" && value[index] !== "\r") {
        index += 1;
      }
      continue;
    }
    if (value[index] === "/" && value[index + 1] === "*") {
      index += 2;
      while (index < value.length && !(value[index] === "*" && value[index + 1] === "/")) {
        index += 1;
      }
      index = Math.min(value.length, index + 2);
      continue;
    }
    return index;
  }
  return index;
}
function getCallFirstArgumentSource(source, masked, index) {
  var _a;
  return ((_a = getCallArgumentSources(source, masked, index)[0]) == null ? void 0 : _a.source) || "";
}
function getCallArgumentSources(source, masked, index) {
  const args = [];
  const openParen = masked.indexOf("(", index);
  if (openParen < 0) {
    return args;
  }
  let parenDepth = 1;
  let bracketDepth = 0;
  let braceDepth = 0;
  let argStart = openParen + 1;
  for (let cursor = openParen + 1; cursor < masked.length; cursor += 1) {
    const char = masked[cursor];
    if (char === "(") {
      parenDepth += 1;
    } else if (char === ")" && parenDepth > 0) {
      parenDepth -= 1;
      if (parenDepth === 0) {
        if (cursor > argStart || source.slice(argStart, cursor).trim()) {
          args.push({
            source: source.slice(argStart, cursor),
            start: argStart,
            end: cursor
          });
        }
        return args;
      }
    } else if (char === "[") {
      bracketDepth += 1;
    } else if (char === "]" && bracketDepth > 0) {
      bracketDepth -= 1;
    } else if (char === "{") {
      braceDepth += 1;
    } else if (char === "}" && braceDepth > 0) {
      braceDepth -= 1;
    } else if (char === "," && parenDepth === 1 && bracketDepth === 0 && braceDepth === 0) {
      args.push({
        source: source.slice(argStart, cursor),
        start: argStart,
        end: cursor
      });
      argStart = cursor + 1;
    }
  }
  return args;
}
function getCallArgumentSource(source, masked, index) {
  const openParen = masked.indexOf("(", index);
  if (openParen < 0) {
    return "";
  }
  let depth = 0;
  for (let cursor = openParen; cursor < masked.length; cursor += 1) {
    if (masked[cursor] === "(") {
      depth += 1;
    } else if (masked[cursor] === ")") {
      depth -= 1;
      if (depth === 0) {
        return source.slice(openParen + 1, cursor);
      }
    }
  }
  return "";
}
function escapeRegExp(value) {
  return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
}
function getAstSource(node, source) {
  return source.slice((node == null ? void 0 : node.start) || 0, (node == null ? void 0 : node.end) || (node == null ? void 0 : node.start) || 0).trim();
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  collectArrowExpressionRanges,
  collectAstFunctionBodyRanges,
  collectBraceRanges,
  collectComputedMethodCandidates,
  collectFunctionRanges,
  collectMethodCandidates,
  collectMethodFunctionRanges,
  collectStaticBlockRanges,
  escapeRegExp,
  findArrowExpressionEnd,
  findBraceBodyAfter,
  findFunctionRanges,
  findMatches,
  findMatchingBrace,
  findMatchingDelimiter,
  findMethodPrefixToken,
  findTemplateExpressionEnd,
  findTopLevelChar,
  getAstSource,
  getCallArgumentSource,
  getCallArgumentSources,
  getCallFirstArgumentSource,
  getPreviousSignificantToken,
  getPreviousSignificantTokenInfo,
  isInsideRanges,
  isRegexLiteralStart,
  maskJavaScriptComments,
  maskJavaScriptSource,
  maskTemplateLiteral,
  maskTemplateLiteralComments,
  mergeRanges,
  readCompleteStringLiteral,
  readLeadingStringLiteral,
  skipJavaScriptTrivia,
  skipQuotedLiteral,
  skipRegexLiteral,
  skipTemplateLiteral,
  splitTopLevel,
  splitTopLevelWithRanges,
  stripEnclosure,
  trimBindingElement
});
