Skip to content

Commit

Permalink
Update to gen-mappings v0.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
jridgewell committed Apr 27, 2022
1 parent b5e335c commit b9f392f
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 29 deletions.
54 changes: 39 additions & 15 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -57,7 +57,7 @@
"typescript": "4.6.3"
},
"dependencies": {
"@jridgewell/gen-mapping": "^0.0.0",
"@jridgewell/gen-mapping": "^0.1.0",
"@jridgewell/trace-mapping": "^0.3.9"
}
}
6 changes: 3 additions & 3 deletions src/build-source-map-tree.ts
Expand Up @@ -2,7 +2,7 @@ import { TraceMap } from '@jridgewell/trace-mapping';

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

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

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

Expand All @@ -49,7 +49,7 @@ function build(
loader: SourceMapLoader,
importer: string,
importerDepth: number
): Sources {
): MapSourceType {
const { resolvedSources, sourcesContent } = map;

const depth = importerDepth + 1;
Expand Down
8 changes: 4 additions & 4 deletions src/source-map-tree.ts
Expand Up @@ -28,14 +28,14 @@ const SOURCELESS_MAPPING = {
};
const EMPTY_SOURCES: Sources[] = [];

type OriginalSource = {
export type OriginalSource = {
map: TraceMap;
sources: Sources[];
source: string;
content: string | null;
};

type MapSource = {
export type MapSource = {
map: TraceMap;
sources: Sources[];
source: string;
Expand Down Expand Up @@ -78,8 +78,8 @@ export function OriginalSource(source: string, content: string | null): Original
* traceMappings is only called on the root level SourceMapTree, and begins the process of
* resolving each mapping in terms of the original source files.
*/
export function traceMappings(tree: Sources): GenMapping {
const gen = new GenMapping(tree.map.file);
export function traceMappings(tree: MapSource): GenMapping {
const gen = new GenMapping({ file: tree.map.file });
const { sources: rootSources, map } = tree;
const rootNames = map.names;
const rootMappings = decodedMappings(map);
Expand Down
10 changes: 6 additions & 4 deletions src/source-map.ts
Expand Up @@ -20,13 +20,15 @@ export default class SourceMap {
const out = options.decodedMappings ? decodedMap(map) : encodedMap(map);
this.version = out.version; // SourceMap spec says this should be first.
this.file = out.file;
this.mappings = out.mappings;
this.names = out.names;
this.mappings = out.mappings as SourceMap['mappings'];
this.names = out.names as SourceMap['names'];

this.sourceRoot = out.sourceRoot;

this.sources = out.sources;
if (!options.excludeContent) this.sourcesContent = out.sourcesContent;
this.sources = out.sources as SourceMap['sources'];
if (!options.excludeContent) {
this.sourcesContent = out.sourcesContent as SourceMap['sourcesContent'];
}
}

toString(): string {
Expand Down
4 changes: 2 additions & 2 deletions test/unit/source-map.ts
Expand Up @@ -20,7 +20,7 @@ describe('SourceMap', () => {

test('it can include a file', () => {
const file = 'foobar.js';
const traced = new GenMapping(file);
const traced = new GenMapping({ file });
addSegment(traced, 0, 0, 'file.js', 0, 0, '');

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

const map = new SourceMap(traced, opts);
Expand Down

0 comments on commit b9f392f

Please sign in to comment.