| 1 | import { toDecodedMap, toEncodedMap } from '@jridgewell/gen-mapping';
|
|---|
| 2 |
|
|---|
| 3 | import type { GenMapping } from '@jridgewell/gen-mapping';
|
|---|
| 4 | import type { DecodedSourceMap, EncodedSourceMap, Options } from './types';
|
|---|
| 5 |
|
|---|
| 6 | /**
|
|---|
| 7 | * A SourceMap v3 compatible sourcemap, which only includes fields that were
|
|---|
| 8 | * provided to it.
|
|---|
| 9 | */
|
|---|
| 10 | export default class SourceMap {
|
|---|
| 11 | declare file?: string | null;
|
|---|
| 12 | declare mappings: EncodedSourceMap['mappings'] | DecodedSourceMap['mappings'];
|
|---|
| 13 | declare sourceRoot?: string;
|
|---|
| 14 | declare names: string[];
|
|---|
| 15 | declare sources: (string | null)[];
|
|---|
| 16 | declare sourcesContent?: (string | null)[];
|
|---|
| 17 | declare version: 3;
|
|---|
| 18 | declare ignoreList: number[] | undefined;
|
|---|
| 19 |
|
|---|
| 20 | constructor(map: GenMapping, options: Options) {
|
|---|
| 21 | const out = options.decodedMappings ? toDecodedMap(map) : toEncodedMap(map);
|
|---|
| 22 | this.version = out.version; // SourceMap spec says this should be first.
|
|---|
| 23 | this.file = out.file;
|
|---|
| 24 | this.mappings = out.mappings as SourceMap['mappings'];
|
|---|
| 25 | this.names = out.names as SourceMap['names'];
|
|---|
| 26 | this.ignoreList = out.ignoreList as SourceMap['ignoreList'];
|
|---|
| 27 | this.sourceRoot = out.sourceRoot;
|
|---|
| 28 |
|
|---|
| 29 | this.sources = out.sources as SourceMap['sources'];
|
|---|
| 30 | if (!options.excludeContent) {
|
|---|
| 31 | this.sourcesContent = out.sourcesContent as SourceMap['sourcesContent'];
|
|---|
| 32 | }
|
|---|
| 33 | }
|
|---|
| 34 |
|
|---|
| 35 | toString(): string {
|
|---|
| 36 | return JSON.stringify(this);
|
|---|
| 37 | }
|
|---|
| 38 | }
|
|---|