Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jridgewell committed Oct 7, 2022
1 parent 16f900b commit 8fe0daa
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
5 changes: 3 additions & 2 deletions src/any-map.ts
Expand Up @@ -12,6 +12,7 @@ import type {
SectionedSourceMap,
DecodedSourceMap,
SectionedSourceMapInput,
Ro,
} from './types';
import type { SourceMapSegment } from './sourcemap-segment';

Expand Down Expand Up @@ -46,7 +47,7 @@ export const AnyMap: AnyMap = function (map, mapUrl) {
} as AnyMap;

function recurse(
input: SectionedSourceMap,
input: Ro<SectionedSourceMap>,
mapUrl: string | null | undefined,
mappings: SourceMapSegment[][],
sources: string[],
Expand Down Expand Up @@ -90,7 +91,7 @@ function recurse(
}

function addSection(
input: Section['map'],
input: Ro<Section['map']>,
mapUrl: string | null | undefined,
mappings: SourceMapSegment[][],
sources: string[],
Expand Down
2 changes: 1 addition & 1 deletion src/trace-mapping.ts
Expand Up @@ -159,7 +159,7 @@ export class TraceMap implements SourceMap {

if (!isString && (map as unknown as { _decodedMemo: any })._decodedMemo) return map as TraceMap;

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

const { version, file, names, sourceRoot, sources, sourcesContent } = parsed;
this.version = version;
Expand Down
16 changes: 8 additions & 8 deletions src/types.ts
Expand Up @@ -57,14 +57,6 @@ export type InvalidGeneratedMapping = {

export type Bias = typeof GREATEST_LOWER_BOUND | typeof LEAST_UPPER_BOUND;

type Ro<T> = T extends Array<infer V>
? V[] | Readonly<V[]> | RoArray<V> | Readonly<RoArray<V>>
: T extends object
? T | Readonly<T> | RoObject<T> | Readonly<RoObject<T>>
: T;
type RoArray<T> = Ro<T>[];
type RoObject<T> = { [K in keyof T]: T[K] | Ro<T[K]> };

export type SourceMapInput = string | Ro<EncodedSourceMap> | Ro<DecodedSourceMap> | TraceMap;

export type SectionedSourceMapInput = SourceMapInput | Ro<SectionedSourceMap>;
Expand Down Expand Up @@ -99,3 +91,11 @@ export abstract class SourceMap {
declare sourcesContent: SourceMapV3['sourcesContent'];
declare resolvedSources: SourceMapV3['sources'];
}

export type Ro<T> = T extends Array<infer V>
? V[] | Readonly<V[]> | RoArray<V> | Readonly<RoArray<V>>
: T extends object
? T | Readonly<T> | RoObject<T> | Readonly<RoObject<T>>
: T;
type RoArray<T> = Ro<T>[];
type RoObject<T> = { [K in keyof T]: T[K] | Ro<T[K]> };

0 comments on commit 8fe0daa

Please sign in to comment.