source-map.mjs.map 6.8 KB

1
  1. {"version":3,"file":"source-map.mjs","sources":["../../src/source-map.ts"],"sourcesContent":["import {\n AnyMap,\n originalPositionFor,\n generatedPositionFor,\n allGeneratedPositionsFor,\n eachMapping,\n encodedMappings,\n sourceContentFor,\n} from '@jridgewell/trace-mapping';\nimport {\n GenMapping,\n maybeAddMapping,\n toDecodedMap,\n toEncodedMap,\n setSourceContent,\n fromMap,\n} from '@jridgewell/gen-mapping';\n\nimport type {\n TraceMap,\n SourceMapInput,\n SectionedSourceMapInput,\n DecodedSourceMap,\n} from '@jridgewell/trace-mapping';\nexport type { TraceMap, SourceMapInput, SectionedSourceMapInput, DecodedSourceMap };\n\nimport type { Mapping, EncodedSourceMap } from '@jridgewell/gen-mapping';\nexport type { Mapping, EncodedSourceMap };\n\nexport class SourceMapConsumer {\n private declare _map: TraceMap;\n declare file: TraceMap['file'];\n declare names: TraceMap['names'];\n declare sourceRoot: TraceMap['sourceRoot'];\n declare sources: TraceMap['sources'];\n declare sourcesContent: TraceMap['sourcesContent'];\n declare version: TraceMap['version'];\n\n constructor(map: ConstructorParameters<typeof AnyMap>[0], mapUrl: Parameters<typeof AnyMap>[1]) {\n const trace = (this._map = new AnyMap(map, mapUrl));\n\n this.file = trace.file;\n this.names = trace.names;\n this.sourceRoot = trace.sourceRoot;\n this.sources = trace.resolvedSources;\n this.sourcesContent = trace.sourcesContent;\n this.version = trace.version;\n }\n\n static fromSourceMap(map: SourceMapGenerator, mapUrl: Parameters<typeof AnyMap>[1]) {\n // This is more performant if we receive\n // a @jridgewell/source-map SourceMapGenerator\n if (map.toDecodedMap) {\n return new SourceMapConsumer(map.toDecodedMap() as SectionedSourceMapInput, mapUrl);\n }\n\n // This is a fallback for `source-map` and `source-map-js`\n return new SourceMapConsumer(map.toJSON() as SectionedSourceMapInput, mapUrl);\n }\n\n get mappings(): string {\n return encodedMappings(this._map);\n }\n\n originalPositionFor(\n needle: Parameters<typeof originalPositionFor>[1],\n ): ReturnType<typeof originalPositionFor> {\n return originalPositionFor(this._map, needle);\n }\n\n generatedPositionFor(\n originalPosition: Parameters<typeof generatedPositionFor>[1],\n ): ReturnType<typeof generatedPositionFor> {\n return generatedPositionFor(this._map, originalPosition);\n }\n\n allGeneratedPositionsFor(\n originalPosition: Parameters<typeof generatedPositionFor>[1],\n ): ReturnType<typeof generatedPositionFor>[] {\n return allGeneratedPositionsFor(this._map, originalPosition);\n }\n\n hasContentsOfAllSources(): boolean {\n if (!this.sourcesContent || this.sourcesContent.length !== this.sources.length) {\n return false;\n }\n\n for (const content of this.sourcesContent) {\n if (content == null) {\n return false;\n }\n }\n\n return true;\n }\n\n sourceContentFor(source: string, nullOnMissing?: boolean): string | null {\n const sourceContent = sourceContentFor(this._map, source);\n if (sourceContent != null) {\n return sourceContent;\n }\n\n if (nullOnMissing) {\n return null;\n }\n throw new Error(`\"${source}\" is not in the SourceMap.`);\n }\n\n eachMapping(\n callback: Parameters<typeof eachMapping>[1],\n context?: any /*, order?: number*/,\n ): void {\n // order is ignored as @jridgewell/trace-map doesn't implement it\n eachMapping(this._map, context ? callback.bind(context) : callback);\n }\n\n destroy() {\n // noop.\n }\n}\n\nexport class SourceMapGenerator {\n private declare _map: GenMapping;\n\n constructor(opts: ConstructorParameters<typeof GenMapping>[0] | GenMapping) {\n // TODO :: should this be duck-typed ?\n this._map = opts instanceof GenMapping ? opts : new GenMapping(opts);\n }\n\n static fromSourceMap(consumer: SourceMapConsumer) {\n return new SourceMapGenerator(fromMap(consumer));\n }\n\n addMapping(mapping: Parameters<typeof maybeAddMapping>[1]): ReturnType<typeof maybeAddMapping> {\n maybeAddMapping(this._map, mapping);\n }\n\n setSourceContent(\n source: Parameters<typeof setSourceContent>[1],\n content: Parameters<typeof setSourceContent>[2],\n ): ReturnType<typeof setSourceContent> {\n setSourceContent(this._map, source, content);\n }\n\n toJSON(): ReturnType<typeof toEncodedMap> {\n return toEncodedMap(this._map);\n }\n\n toString(): string {\n return JSON.stringify(this.toJSON());\n }\n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