function resolve(specifier, parsedImportMap, scriptURL) {
  const asURL = tryURLLikeSpecifierParse(specifier, scriptURL);
  const normalizedSpecifier = asURL ? asURL.href : specifier;
  const scriptURLString = scriptURL.href;

  for (const [scopePrefix, scopeImports] of Object.entries(parsedImportMap.scopes || {})) {
    if (
      scopePrefix === scriptURLString ||
      (scopePrefix.endsWith('/') && scriptURLString.startsWith(scopePrefix))
    ) {
      const scopeImportsMatch = resolveImportsMatch(normalizedSpecifier, scopeImports);

      if (scopeImportsMatch) {
        return { resolvedImport: scopeImportsMatch, matched: true };
      }
    }
  }

  const topLevelImportsMatch = resolveImportsMatch(
    normalizedSpecifier,
    parsedImportMap.imports || {},
  );

  if (topLevelImportsMatch) {
    return { resolvedImport: topLevelImportsMatch, matched: true };
  }

  // The specifier was able to be turned into a URL, but wasn't remapped into anything.
  if (asURL) {
    return { resolvedImport: asURL, matched: false };
  }

  return { resolvedImport: null, matched: false };
}
@param {string} specifier
@param {ParsedImportMap} parsedImportMap
@param {URL} scriptURL
@returns {{ resolvedImport: URL | null, matched: boolean }}