{"version":3,"file":"polyfills.d.ts","sourceRoot":"","sources":["../../src/polyfills.ts"],"names":[],"mappings":"AAQA,qBAAa,WAAW;IACtB,IAAI,EAAE,KAAK,GAAG,UAAU,CAAA;IACxB,IAAI,EAAE,MAAM,CAAA;IACZ,GAAG,sBAA4B;IAC/B,YAAY,IAAI,EAAE,KAAK,GAAG,UAAU,EAAE,IAAI,EAAE,MAAM,EAGjD;IACD,OAAO,CAAC,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,CAAC,MAAM,CAAC,QAQtC;CAIF;AAED,QAAA,MAAM,SAAS,0BAEb,CAAA;AAoBF,eAAe,SAAS,CAAA","sourcesContent":["// the modules like -cjs.cts that override a module at .ts\nimport chalk from 'chalk'\nimport config from './config.js'\nimport * as console from './console.js'\nimport sources from './sources.js'\n\nconst { esmDialects = [], commonjsDialects = [] } = config\n\nexport class PolyfillSet {\n  type: 'esm' | 'commonjs'\n  name: string\n  map = new Map<string, string>()\n  constructor(type: 'esm' | 'commonjs', name: string) {\n    this.type = type\n    this.name = name\n  }\n  addFile(f: string, sources: Set<string>) {\n    const dotts = this.type === 'commonjs' ? 'cts' : 'mts'\n    const ending = `-${this.name}.${dotts}`\n    if (!f.endsWith(ending)) return\n    const ts = f.substring(0, f.length - ending.length) + '.ts'\n    const tsx = ts + 'x'\n    if (sources.has(ts)) this.map.set(f, ts)\n    else if (sources.has(tsx)) this.map.set(f, tsx)\n  }\n  [Symbol.for('nodejs.util.inspect.custom')]() {\n    return [this.name, this.map]\n  }\n}\n\nconst polyfills = new Map<string, PolyfillSet>([\n  ['cjs', new PolyfillSet('commonjs', 'cjs')],\n])\nfor (const d of commonjsDialects)\n  polyfills.set(d, new PolyfillSet('commonjs', d))\nfor (const d of esmDialects) polyfills.set(d, new PolyfillSet('esm', d))\n\nfor (const f of sources) {\n  for (const pf of polyfills.values()) {\n    pf.addFile(f, sources)\n  }\n}\n\n// delete any polyfill types that have no entries\nfor (const [name, pf] of polyfills.entries()) {\n  if (pf.map.size === 0) polyfills.delete(name)\n}\n\nif (polyfills.size) {\n  console.debug(chalk.cyan.dim('polyfills detected'), polyfills)\n}\n\nexport default polyfills\n"]}