From 8fe0daa79c862f19e1afce51b1959c4a06c2dc1a Mon Sep 17 00:00:00 2001 From: Justin Ridgewell Date: Thu, 6 Oct 2022 22:28:09 -0400 Subject: [PATCH] Fixes --- src/any-map.ts | 5 +++-- src/trace-mapping.ts | 2 +- src/types.ts | 16 ++++++++-------- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/src/any-map.ts b/src/any-map.ts index 8b374ee..7138d73 100644 --- a/src/any-map.ts +++ b/src/any-map.ts @@ -12,6 +12,7 @@ import type { SectionedSourceMap, DecodedSourceMap, SectionedSourceMapInput, + Ro, } from './types'; import type { SourceMapSegment } from './sourcemap-segment'; @@ -46,7 +47,7 @@ export const AnyMap: AnyMap = function (map, mapUrl) { } as AnyMap; function recurse( - input: SectionedSourceMap, + input: Ro, mapUrl: string | null | undefined, mappings: SourceMapSegment[][], sources: string[], @@ -90,7 +91,7 @@ function recurse( } function addSection( - input: Section['map'], + input: Ro, mapUrl: string | null | undefined, mappings: SourceMapSegment[][], sources: string[], diff --git a/src/trace-mapping.ts b/src/trace-mapping.ts index 77c7fbf..4698e35 100644 --- a/src/trace-mapping.ts +++ b/src/trace-mapping.ts @@ -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; + const parsed = (isString ? JSON.parse(map) : map) as DecodedSourceMap | EncodedSourceMap; const { version, file, names, sourceRoot, sources, sourcesContent } = parsed; this.version = version; diff --git a/src/types.ts b/src/types.ts index b6490b2..b62f7c5 100644 --- a/src/types.ts +++ b/src/types.ts @@ -57,14 +57,6 @@ export type InvalidGeneratedMapping = { export type Bias = typeof GREATEST_LOWER_BOUND | typeof LEAST_UPPER_BOUND; -type Ro = T extends Array - ? V[] | Readonly | RoArray | Readonly> - : T extends object - ? T | Readonly | RoObject | Readonly> - : T; -type RoArray = Ro[]; -type RoObject = { [K in keyof T]: T[K] | Ro }; - export type SourceMapInput = string | Ro | Ro | TraceMap; export type SectionedSourceMapInput = SourceMapInput | Ro; @@ -99,3 +91,11 @@ export abstract class SourceMap { declare sourcesContent: SourceMapV3['sourcesContent']; declare resolvedSources: SourceMapV3['sources']; } + +export type Ro = T extends Array + ? V[] | Readonly | RoArray | Readonly> + : T extends object + ? T | Readonly | RoObject | Readonly> + : T; +type RoArray = Ro[]; +type RoObject = { [K in keyof T]: T[K] | Ro };