source-map.js.map 4.42 KB
{"version":3,"names":["SourceMap","constructor","opts","code","_map","_rawMappings","_sourceFileName","_lastGenLine","_lastSourceLine","_lastSourceColumn","map","GenMapping","sourceRoot","sourceFileName","replace","undefined","setSourceContent","Object","keys","forEach","get","toEncodedMap","getDecoded","toDecodedMap","getRawMappings","allMappings","mark","generated","line","column","identifierName","filename","maybeAddMapping","name","source","original"],"sources":["../src/source-map.ts"],"sourcesContent":["import {\n  GenMapping,\n  maybeAddMapping,\n  setSourceContent,\n  allMappings,\n  toEncodedMap,\n  toDecodedMap,\n} from \"@jridgewell/gen-mapping\";\n\nimport type {\n  EncodedSourceMap,\n  DecodedSourceMap,\n  Mapping,\n} from \"@jridgewell/gen-mapping\";\n\n/**\n * Build a sourcemap.\n */\n\nexport default class SourceMap {\n  private _map: GenMapping;\n  private _rawMappings: Mapping[] | undefined;\n  private _sourceFileName: string | undefined;\n\n  // Any real line is > 0, so init to 0 is fine.\n  private _lastGenLine = 0;\n  private _lastSourceLine = 0;\n\n  // Source columns can be 0, but we ony check in unison with sourceLine, which\n  // inits to an impossible value. So init to 0 is fine.\n  private _lastSourceColumn = 0;\n\n  constructor(\n    opts: { sourceFileName?: string; sourceRoot?: string },\n    code: string | { [sourceFileName: string]: string },\n  ) {\n    const map = (this._map = new GenMapping({ sourceRoot: opts.sourceRoot }));\n    this._sourceFileName = opts.sourceFileName?.replace(/\\\\/g, \"/\");\n    this._rawMappings = undefined;\n\n    if (typeof code === \"string\") {\n      setSourceContent(map, this._sourceFileName, code);\n    } else if (typeof code === \"object\") {\n      Object.keys(code).forEach(sourceFileName => {\n        setSourceContent(\n          map,\n          sourceFileName.replace(/\\\\/g, \"/\"),\n          code[sourceFileName],\n        );\n      });\n    }\n  }\n\n  /**\n   * Get the sourcemap.\n   */\n  get(): EncodedSourceMap {\n    return toEncodedMap(this._map);\n  }\n\n  getDecoded(): DecodedSourceMap {\n    return toDecodedMap(this._map);\n  }\n\n  getRawMappings(): Mapping[] {\n    return (this._rawMappings ||= allMappings(this._map));\n  }\n\n  /**\n   * Mark the current generated position with a source position. May also be passed null line/column\n   * values to insert a mapping to nothing.\n   */\n\n  mark(\n    generated: { line: number; column: number },\n    line: number,\n    column: number,\n    identifierName?: string | null,\n    filename?: string | null,\n  ) {\n    this._rawMappings = undefined;\n\n    maybeAddMapping(this._map, {\n      name: identifierName,\n      generated,\n      source:\n        line == null\n          ? undefined\n          : filename?.replace(/\\\\/g, \"/\") || this._sourceFileName,\n      original:\n        line == null\n          ? undefined\n          : {\n              line: line,\n              column: column,\n            },\n    });\n  }\n}\n"],"mappings":";;;;;;AAAA;;AAmBe,MAAMA,SAAS,CAAC;;EAa7BC,WAAW,CACTC,IAAsD,EACtDC,IAAmD,EACnD;IAAA;IAAA,KAfMC,IAAI;IAAA,KACJC,YAAY;IAAA,KACZC,eAAe;IAAA,KAGfC,YAAY,GAAG,CAAC;IAAA,KAChBC,eAAe,GAAG,CAAC;IAAA,KAInBC,iBAAiB,GAAG,CAAC;IAM3B,MAAMC,GAAG,GAAI,IAAI,CAACN,IAAI,GAAG,IAAIO,sBAAU,CAAC;MAAEC,UAAU,EAAEV,IAAI,CAACU;IAAW,CAAC,CAAE;IACzE,IAAI,CAACN,eAAe,2BAAGJ,IAAI,CAACW,cAAc,qBAAnB,qBAAqBC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC;IAC/D,IAAI,CAACT,YAAY,GAAGU,SAAS;IAE7B,IAAI,OAAOZ,IAAI,KAAK,QAAQ,EAAE;MAC5B,IAAAa,4BAAgB,EAACN,GAAG,EAAE,IAAI,CAACJ,eAAe,EAAEH,IAAI,CAAC;IACnD,CAAC,MAAM,IAAI,OAAOA,IAAI,KAAK,QAAQ,EAAE;MACnCc,MAAM,CAACC,IAAI,CAACf,IAAI,CAAC,CAACgB,OAAO,CAACN,cAAc,IAAI;QAC1C,IAAAG,4BAAgB,EACdN,GAAG,EACHG,cAAc,CAACC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,EACl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