Skip to content

Commit

Permalink
Allow TraceMap to be created with TraceMap instance
Browse files Browse the repository at this point in the history
  • Loading branch information
jridgewell committed Apr 20, 2022
1 parent 8db5df0 commit 174adb6
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/trace-mapping.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,10 @@ export class TraceMap implements SourceMap {

constructor(map: SourceMapInput, mapUrl?: string | null) {
const isString = typeof map === 'string';
const parsed = isString ? (JSON.parse(map) as Exclude<SourceMapInput, string>) : map;

if (!isString && map.constructor === TraceMap) return map;

const parsed = (isString ? JSON.parse(map) : map) as Exclude<SourceMapInput, string | TraceMap>;

const { version, file, names, sourceRoot, sources, sourcesContent } = parsed;
this.version = version;
Expand Down
3 changes: 2 additions & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { SourceMapSegment } from './sourcemap-segment';
import type { TraceMap } from './trace-mapping';

export interface SourceMapV3 {
file?: string | null;
Expand Down Expand Up @@ -54,7 +55,7 @@ export type InvalidGeneratedMapping = {
column: null;
};

export type SourceMapInput = string | EncodedSourceMap | DecodedSourceMap;
export type SourceMapInput = string | EncodedSourceMap | DecodedSourceMap | TraceMap;
export type SectionedSourceMapInput = SourceMapInput | SectionedSourceMap;

export type Needle = { line: number; column: number; bias?: 1 | -1 };
Expand Down

0 comments on commit 174adb6

Please sign in to comment.