Skip to content

Commit

Permalink
Add type definitions for source-map library.
Browse files Browse the repository at this point in the history
  • Loading branch information
loganfsmyth committed Apr 25, 2018
1 parent e31e907 commit 9e7fe0a
Show file tree
Hide file tree
Showing 2 changed files with 111 additions and 4 deletions.
106 changes: 104 additions & 2 deletions lib/third-party-libs.js.flow
Expand Up @@ -26,22 +26,124 @@ declare module "lodash/defaults" {

declare module "lodash/clone" {
declare export default <T>(obj: T) => T;
}
}

declare module "lodash/merge" {
declare export default <T: Object>(T, Object) => T;
}

declare module "convert-source-map" {
declare module "source-map" {
declare export type SourceMap = {
version: 3,
file: ?string,
sourceRoot: ?string,
sources: [?string],
sourcesContent: [?string],
names: [?string],
mappings: string,
};

declare module.exports: {
SourceMapConsumer: typeof SourceMapConsumer,
SourceMapGenerator: typeof SourceMapGenerator,
}

declare class SourceMapConsumer {
static GENERATED_ORDER: 1;
static ORIGINAL_ORDER: 2;

file: string | null;
sourceRoot: string | null;
sources: Array<string>;

constructor(?SourceMap): this;

computeColumnSpans(): string;
originalPositionFor({
line: number,
column: number,
}): {|
source: string,
line: number,
column: number,
name: string | null
|} | {|
source: null,
line: null,
column: null,
name: null
|};

generatedPositionFor({
source: string,
line: number,
column: number,
}): {|
line: number,
column: number,
lastColumn: number | null | void,
|} | {|
line: null,
column: null,
lastColumn: null | void,
|};

allGeneratedPositionsFor({
source: string,
line: number,
column: number,
}): Array<{|
line: number,
column: number,
lastColumn: number,
|}>;

sourceContentFor(string, boolean | void): string | null;

eachMapping(
({|
generatedLine: number,
generatedColumn: number,
source: string,
originalLine: number,
originalColumn: number,
name: string | null,
|} | {|
generatedLine: number,
generatedColumn: number,
source: null,
originalLine: null,
originalColumn: null,
name: null,
|}) => mixed,
context: mixed,
order: ?(1 | 2),
): void;
}

declare class SourceMapGenerator {
constructor(?{
file?: string | null,
sourceRoot?: string | null,
skipValidation?: boolean | null,
}): this;

addMapping({
generated: {
line: number,
column: number,
}
}): void;

setSourceContent(string, string): void;

toJSON(): SourceMap;
}
}

declare module "convert-source-map" {
import type { SourceMap } from "source-map";

declare class Converter {
toJSON(): string;
toBase64(): string;
Expand Down
9 changes: 7 additions & 2 deletions packages/babel-core/src/transformation/file/merge-map.js
Expand Up @@ -25,7 +25,12 @@ export default function mergeSourceMap(
column: mapping.generatedColumn,
source: source,
});
if (generatedPosition.column != null) {
if (generatedPosition.line != null && generatedPosition.column != null) {
const generated = {
line: generatedPosition.line,
column: generatedPosition.column,
};

mergedGenerator.addMapping({
source: mapping.source,

Expand All @@ -37,7 +42,7 @@ export default function mergeSourceMap(
column: mapping.originalColumn,
},

generated: generatedPosition,
generated,

name: mapping.name,
});
Expand Down

0 comments on commit 9e7fe0a

Please sign in to comment.