feat: update source-map api to latest version (#12379)

This commit is contained in:
Scott(JuJiang)
2016-11-01 22:17:17 +09:00
committed by Masahiro Wakame
parent 5661e33ce1
commit 79f48dd449
2 changed files with 67 additions and 14 deletions
+53 -7
View File
@@ -10,14 +10,17 @@ declare namespace SourceMap {
interface StartOfSourceMap {
file?: string;
sourceRoot?: string;
skipValidation?: boolean;
}
interface RawSourceMap extends StartOfSourceMap {
version: string;
sources: Array<string>;
names: Array<string>;
interface RawSourceMap {
version: number;
sources: string[];
names: string[];
sourceRoot?: string;
sourcesContent?: string[];
mappings: string;
file: string;
}
interface Position {
@@ -56,35 +59,78 @@ declare namespace SourceMap {
public static ORIGINAL_ORDER: number;
constructor(rawSourceMap: RawSourceMap);
public computeColumnSpans(): void;
public originalPositionFor(generatedPosition: Position): MappedPosition;
public generatedPositionFor(originalPosition: MappedPosition): Position;
public sourceContentFor(source: string): string;
public allGeneratedPositionsFor(originalPosition: MappedPosition): Position[];
public hasContentsOfAllSources(): boolean;
public sourceContentFor(source: string, returnNullOnMissing?: boolean): string;
public eachMapping(callback: (mapping: MappingItem) => void, context?: any, order?: number): void;
}
class SourceMapGenerator {
constructor(startOfSourceMap?: StartOfSourceMap);
public static fromSourceMap(sourceMapConsumer: SourceMapConsumer): SourceMapGenerator;
public addMapping(mapping: Mapping): void;
public setSourceContent(sourceFile: string, sourceContent: string): void;
public applySourceMap(sourceMapConsumer: SourceMapConsumer, sourceFile?: string, sourceMapPath?: string): void;
public toString(): string;
public toJSON(): RawSourceMap;
}
class SourceNode {
children: SourceNode [];
sourceContents: any;
line: number;
column: number;
source: string;
name: string;
constructor();
constructor(line: number, column: number, source: string);
constructor(line: number, column: number, source: string, chunk?: string, name?: string);
public static fromStringWithSourceMap(code: string, sourceMapConsumer: SourceMapConsumer, relativePath?: string): SourceNode;
constructor(
line: number,
column: number,
source: string,
chunks?: (string | SourceNode)[] | SourceNode | string,
name?: string
);
public static fromStringWithSourceMap(
code: string,
sourceMapConsumer: SourceMapConsumer,
relativePath?: string
): SourceNode;
public add(chunk: any): SourceNode;
public prepend(chunk: any): SourceNode;
public setSourceContent(sourceFile: string, sourceContent: string): void;
public walk(fn: (chunk: string, mapping: MappedPosition) => void): void;
public walkSourceContents(fn: (file: string, content: string) => void): void;
public join(sep: string): SourceNode;
public replaceRight(pattern: string, replacement: string): SourceNode;
public toString(): string;
public toStringWithSourceMap(startOfSourceMap?: StartOfSourceMap): CodeWithSourceMap;
}
}
+14 -7
View File
@@ -1,6 +1,4 @@
import SourceMap = require('source-map');
import SourceMap = require('source-map');
function testSourceMapConsumer() {
function testConstructor() {
@@ -8,19 +6,21 @@ function testSourceMapConsumer() {
// create with full RawSourceMap
scm = new SourceMap.SourceMapConsumer({
version: 'foo',
version: 3,
sources: ['foo', 'bar'],
names: ['foo', 'bar'],
sourcesContent: ['foo'],
mappings: 'foo'
mappings: 'foo',
file: 'sdf'
});
// create with partial RawSourceMap
scm = new SourceMap.SourceMapConsumer({
version: 'foo',
version: 3,
sources: ['foo', 'bar'],
names: ['foo', 'bar'],
mappings: 'foo'
mappings: 'foo',
file: 'sdf'
});
}
@@ -29,6 +29,12 @@ function testSourceMapConsumer() {
origPos = scm.originalPositionFor({ line: 42, column: 42 });
}
function testAllGeneratedPositionsFor(scm: SourceMap.SourceMapConsumer) {
var origPos: SourceMap.MappedPosition;
var origPoses: SourceMap.Position[];
origPoses = scm.allGeneratedPositionsFor(origPos);
}
function testGeneratedPositionFor(scm: SourceMap.SourceMapConsumer) {
var genPos: SourceMap.Position;
genPos = scm.generatedPositionFor({ line: 42, column: 42, source: 'foo' });
@@ -111,6 +117,7 @@ function testSourceNode() {
node = new SourceMap.SourceNode(42, 42, 'foo');
node = new SourceMap.SourceNode(42, 42, 'foo', 'bar');
node = new SourceMap.SourceNode(42, 42, 'foo', 'bar', 'slam');
node = new SourceMap.SourceNode(42, 42, 'foo', ['bar', 'slam']);
}
function testFromStringWithSourceMap(scm: SourceMap.SourceMapConsumer) {