tract
  // all the scripts. Fastest/easiest way is with a regular expression.
  // Don't worry, the rules of using a <script> tag are really strict,
  // this will work.
  const regexp = /<script[^>]*?(?:>([^]*?)<\/script\s*>|\/>)/gim;
  const syntaxTrees = [];
  const scriptMatches = [];
  let scriptMatch;

  if (source.match(/^\s*</)) {
    // First non whitespace character is &lt, so most definitely HTML.
    while ((scriptMatch = regexp.exec(source))) {
      // Contents are captured at index 1 or nothing: Self-closing scripts
      // won't capture code content
      scriptMatches.push(scriptMatch[1] || "");
    }
  }

  // If there are no script matches, send the whole source directly to the
  // reflection API to generate the AST nodes.
  if (!scriptMatches.length) {
    // Reflect.parse throws when encounters a syntax error.
    try {
      syntaxTrees.push(Reflect.parse(source));
    } catch (e) {
      if (logExceptions) {
        DevToolsUtils.reportException("Parser:get", e);
      }
    }
  } else {
    // Generate the AST nodes for each script.
    for (const script of scriptMatches) {
      // Reflect.parse throws when encounters a syntax error.
      try {
        syntaxTrees.push(Reflect.parse(script));
      } catch (e) {
        if (logExceptions) {
          DevToolsUtils.reportException("Parser:get", e);
        }
      }
    }
  }

  return syntaxTrees;
}

exports.getSyntaxTrees = getSyntaxTrees;
PK