diff --git a/src/types.ts b/src/types.ts index 964e290..b6490b2 100644 --- a/src/types.ts +++ b/src/types.ts @@ -57,8 +57,17 @@ export type InvalidGeneratedMapping = { export type Bias = typeof GREATEST_LOWER_BOUND | typeof LEAST_UPPER_BOUND; -export type SourceMapInput = string | EncodedSourceMap | DecodedSourceMap | TraceMap; -export type SectionedSourceMapInput = SourceMapInput | SectionedSourceMap; +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; export type Needle = { line: number; column: number; bias?: Bias }; export type SourceNeedle = { source: string; line: number; column: number; bias?: Bias }; diff --git a/test/any-map.test.ts b/test/any-map.test.ts index b9ba1ff..2169115 100644 --- a/test/any-map.test.ts +++ b/test/any-map.test.ts @@ -3,7 +3,7 @@ import { test, describe } from './setup'; import { AnyMap, encodedMappings, decodedMappings } from '../src/trace-mapping'; -import type { SectionedSourceMap } from '../src/trace-mapping'; +import type { SectionedSourceMap, SourceMapSegment } from '../src/trace-mapping'; describe('AnyMap', () => { const map: SectionedSourceMap = { @@ -126,4 +126,21 @@ describe('AnyMap', () => { ]); }); }); + + describe('typescript readonly type', () => { + test('decoded source map', (t) => { + // This is a TS lint test, not a real one. + t.pass(); + + const decodedMap = { + version: 3 as const, + sources: ['input.js'] as readonly string[], + names: [] as readonly string[], + mappings: [] as readonly SourceMapSegment[][], + sourcesContent: [] as readonly string[], + }; + + new AnyMap(decodedMap); + }); + }); }); diff --git a/test/trace-mapping.test.ts b/test/trace-mapping.test.ts index ab0da2a..b740908 100644 --- a/test/trace-mapping.test.ts +++ b/test/trace-mapping.test.ts @@ -24,6 +24,7 @@ import type { EncodedSourceMap, DecodedSourceMap, EachMapping, + SourceMapSegment, } from '../src/trace-mapping'; describe('TraceMap', () => { @@ -462,4 +463,21 @@ describe('TraceMap', () => { t.is(encodedMappings(tracer), ''); }); }); + + describe('typescript readonly type', () => { + test('decoded source map', (t) => { + // This is a TS lint test, not a real one. + t.pass(); + + const decodedMap = { + version: 3 as const, + sources: ['input.js'] as readonly string[], + names: [] as readonly string[], + mappings: [] as readonly SourceMapSegment[][], + sourcesContent: [] as readonly string[], + }; + + new TraceMap(decodedMap); + }); + }); });