Skip to content

Commit

Permalink
Rename AnyMap
Browse files Browse the repository at this point in the history
  • Loading branch information
jridgewell committed Mar 2, 2024
1 parent fc036e1 commit 0a08a6a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 17 deletions.
8 changes: 4 additions & 4 deletions src/any-map.ts → src/flatten-map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ import type {
} from './types';
import type { SourceMapSegment } from './sourcemap-segment';

type AnyMap = {
type FlattenMap = {
new (map: SectionedSourceMapInput, mapUrl?: string | null): TraceMap;
(map: SectionedSourceMapInput, mapUrl?: string | null): TraceMap;
};

export const AnyMap: AnyMap = function (map, mapUrl) {
const parsed = parse(map);
export const FlattenMap: FlattenMap = function (map, mapUrl) {
const parsed = parse(map as SectionedSourceMapInput);

if (!('sections' in parsed)) {
return new TraceMap(parsed as DecodedSourceMapXInput | EncodedSourceMapXInput, mapUrl);
Expand Down Expand Up @@ -60,7 +60,7 @@ export const AnyMap: AnyMap = function (map, mapUrl) {
};

return presortedDecodedMap(joined);
} as AnyMap;
} as FlattenMap;

function parse<T>(map: T): Exclude<T, string> {
return typeof map === 'string' ? JSON.parse(map) : map;
Expand Down
2 changes: 1 addition & 1 deletion src/trace-mapping.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ const COL_GTR_EQ_ZERO = '`column` must be greater than or equal to 0 (columns st
export const LEAST_UPPER_BOUND = -1;
export const GREATEST_LOWER_BOUND = 1;

export { AnyMap } from './any-map';
export { FlattenMap, FlattenMap as AnyMap } from './any-map';

export class TraceMap implements SourceMap {
declare version: SourceMapV3['version'];
Expand Down
24 changes: 12 additions & 12 deletions test/any-map.test.ts → test/flatten-map.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/// <reference lib="esnext" />

import { strict as assert } from 'assert';
import { AnyMap, encodedMappings, decodedMappings } from '../src/trace-mapping';
import { FlattenMap, encodedMappings, decodedMappings } from '../src/trace-mapping';

import type { SectionedSourceMap, SourceMapSegment } from '../src/trace-mapping';

describe('AnyMap', () => {
describe('FlattenMap', () => {
const map: SectionedSourceMap = {
version: 3,
file: 'sectioned.js',
Expand Down Expand Up @@ -74,37 +74,37 @@ describe('AnyMap', () => {

describe('map properties', () => {
it('version', () => {
const tracer = new AnyMap(map);
const tracer = new FlattenMap(map);
assert.equal(tracer.version, map.version);
});

it('file', () => {
const tracer = new AnyMap(map);
const tracer = new FlattenMap(map);
assert.equal(tracer.file, map.file);
});

it('sourceRoot', () => {
const tracer = new AnyMap(map);
const tracer = new FlattenMap(map);
assert.equal(tracer.sourceRoot, undefined);
});

it('sources', () => {
const tracer = new AnyMap(map);
const tracer = new FlattenMap(map);
assert.deepEqual(tracer.sources, ['first.js', 'second.js', 'nested/third.js', 'fourth.js']);
});

it('names', () => {
const tracer = new AnyMap(map);
const tracer = new FlattenMap(map);
assert.deepEqual(tracer.names, ['first', 'second', 'third']);
});

it('encodedMappings', () => {
const tracer = new AnyMap(map);
const tracer = new FlattenMap(map);
assert.equal(encodedMappings(tracer), ';EAAAA,CCAAC;ACAAC,CCAA');
});

it('decodedMappings', () => {
const tracer = new AnyMap(map);
const tracer = new FlattenMap(map);
assert.deepEqual(decodedMappings(tracer), [
[],
[
Expand All @@ -119,7 +119,7 @@ describe('AnyMap', () => {
});

it('sourcesContent', () => {
const tracer = new AnyMap(map);
const tracer = new FlattenMap(map);
assert.deepEqual(tracer.sourcesContent, [
'firstsource',
'secondsource',
Expand All @@ -129,7 +129,7 @@ describe('AnyMap', () => {
});

it('ignoreList', () => {
const tracer = new AnyMap(map);
const tracer = new FlattenMap(map);
assert.deepEqual(tracer.ignoreList, [0, 3]);
});
});
Expand All @@ -145,7 +145,7 @@ describe('AnyMap', () => {
sourcesContent: [] as readonly string[],
};

new AnyMap(decodedMap);
new FlattenMap(decodedMap);
});
});
});

0 comments on commit 0a08a6a

Please sign in to comment.