Skip to content
This repository was archived by the owner on Jun 28, 2025. It is now read-only.

Commit b9f392f

Browse files
committed
Update to gen-mappings v0.1.0
1 parent b5e335c commit b9f392f

File tree

6 files changed

+55
-29
lines changed

6 files changed

+55
-29
lines changed

package-lock.json

Lines changed: 39 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
"typescript": "4.6.3"
5858
},
5959
"dependencies": {
60-
"@jridgewell/gen-mapping": "^0.0.0",
60+
"@jridgewell/gen-mapping": "^0.1.0",
6161
"@jridgewell/trace-mapping": "^0.3.9"
6262
}
6363
}

src/build-source-map-tree.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { TraceMap } from '@jridgewell/trace-mapping';
22

33
import { OriginalSource, MapSource } from './source-map-tree';
44

5-
import type { Sources } from './source-map-tree';
5+
import type { Sources, MapSource as MapSourceType } from './source-map-tree';
66
import type { SourceMapInput, SourceMapLoader, LoaderContext } from './types';
77

88
function asArray<T>(value: T | T[]): T[] {
@@ -24,7 +24,7 @@ function asArray<T>(value: T | T[]): T[] {
2424
export default function buildSourceMapTree(
2525
input: SourceMapInput | SourceMapInput[],
2626
loader: SourceMapLoader
27-
): Sources {
27+
): MapSourceType {
2828
const maps = asArray(input).map((m) => new TraceMap(m, ''));
2929
const map = maps.pop()!;
3030

@@ -49,7 +49,7 @@ function build(
4949
loader: SourceMapLoader,
5050
importer: string,
5151
importerDepth: number
52-
): Sources {
52+
): MapSourceType {
5353
const { resolvedSources, sourcesContent } = map;
5454

5555
const depth = importerDepth + 1;

src/source-map-tree.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,14 @@ const SOURCELESS_MAPPING = {
2828
};
2929
const EMPTY_SOURCES: Sources[] = [];
3030

31-
type OriginalSource = {
31+
export type OriginalSource = {
3232
map: TraceMap;
3333
sources: Sources[];
3434
source: string;
3535
content: string | null;
3636
};
3737

38-
type MapSource = {
38+
export type MapSource = {
3939
map: TraceMap;
4040
sources: Sources[];
4141
source: string;
@@ -78,8 +78,8 @@ export function OriginalSource(source: string, content: string | null): Original
7878
* traceMappings is only called on the root level SourceMapTree, and begins the process of
7979
* resolving each mapping in terms of the original source files.
8080
*/
81-
export function traceMappings(tree: Sources): GenMapping {
82-
const gen = new GenMapping(tree.map.file);
81+
export function traceMappings(tree: MapSource): GenMapping {
82+
const gen = new GenMapping({ file: tree.map.file });
8383
const { sources: rootSources, map } = tree;
8484
const rootNames = map.names;
8585
const rootMappings = decodedMappings(map);

src/source-map.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,15 @@ export default class SourceMap {
2020
const out = options.decodedMappings ? decodedMap(map) : encodedMap(map);
2121
this.version = out.version; // SourceMap spec says this should be first.
2222
this.file = out.file;
23-
this.mappings = out.mappings;
24-
this.names = out.names;
23+
this.mappings = out.mappings as SourceMap['mappings'];
24+
this.names = out.names as SourceMap['names'];
2525

2626
this.sourceRoot = out.sourceRoot;
2727

28-
this.sources = out.sources;
29-
if (!options.excludeContent) this.sourcesContent = out.sourcesContent;
28+
this.sources = out.sources as SourceMap['sources'];
29+
if (!options.excludeContent) {
30+
this.sourcesContent = out.sourcesContent as SourceMap['sourcesContent'];
31+
}
3032
}
3133

3234
toString(): string {

test/unit/source-map.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ describe('SourceMap', () => {
2020

2121
test('it can include a file', () => {
2222
const file = 'foobar.js';
23-
const traced = new GenMapping(file);
23+
const traced = new GenMapping({ file });
2424
addSegment(traced, 0, 0, 'file.js', 0, 0, '');
2525

2626
const map = new SourceMap(traced, opts);
@@ -30,7 +30,7 @@ describe('SourceMap', () => {
3030
// TODO: support sourceRoot
3131
test.skip('it can include a sourceRoot', () => {
3232
const sourceRoot = 'https://foo.com/';
33-
const traced = new GenMapping(undefined, sourceRoot);
33+
const traced = new GenMapping({ sourceRoot });
3434
addSegment(traced, 0, 0, 'file.js', 0, 0, '');
3535

3636
const map = new SourceMap(traced, opts);

0 commit comments

Comments
 (0)