Added definitions for source-map

This commit is contained in:
Morten Houston Ludvigsen
2014-08-18 15:33:03 +02:00
parent 17f8e5aca2
commit 094c4b5750
3 changed files with 256 additions and 0 deletions
+1
View File
@@ -325,6 +325,7 @@ All definitions files include a header with the author and editors, so at some p
* [SockJS](https://github.com/sockjs/sockjs-client) (by [Emil Ivanov](https://github.com/vladev))
* [sockjs-node](https://github.com/sockjs/sockjs-node) (by [Phil McCloghry-Laing](https://github.com/pmccloghrylaing))
* [SoundJS](http://www.createjs.com/#!/SoundJS) (by [Pedro Ferreira](https://bitbucket.org/drk4))
* [source-map](https://github.com/mozilla/source-map) (by [Morten Houston Ludvigsen](https://github.com/MortenHoustonLudvigsen))
* [Spin](http://fgnass.github.com/spin.js/) (by [Boris Yankov](https://github.com/borisyankov))
* [sqlite3](https://github.com/mapbox/node-sqlite3) (by [Nick Malaguti](https://github.com/nmalaguti))
* [status-bar](https://github.com/atom/status-bar) (by [vvakame](https://github.com/vvakame))
+165
View File
@@ -0,0 +1,165 @@
import SourceMap = require('source-map');
function testSourceMapConsumer() {
function testConstructor() {
var scm: SourceMap.SourceMapConsumer;
// create with full RawSourceMap
scm = new SourceMap.SourceMapConsumer({
version: 'foo',
sources: ['foo', 'bar'],
names: ['foo', 'bar'],
sourcesContent: 'foo',
mappings: 'foo'
});
// create with partial RawSourceMap
scm = new SourceMap.SourceMapConsumer({
version: 'foo',
sources: ['foo', 'bar'],
names: ['foo', 'bar'],
mappings: 'foo'
});
}
function testOriginalPositionFor(scm: SourceMap.SourceMapConsumer) {
var origPos: SourceMap.MappedPosition;
origPos = scm.originalPositionFor({ line: 42, column: 42 });
}
function testGeneratedPositionFor(scm: SourceMap.SourceMapConsumer) {
var genPos: SourceMap.Position;
genPos = scm.generatedPositionFor({ line: 42, column: 42, source: 'foo' });
genPos = scm.generatedPositionFor({ line: 42, column: 42, source: 'foo', name: 'bar' });
}
function testSourceContentFor(scm: SourceMap.SourceMapConsumer) {
var content: string;
content = scm.sourceContentFor('foo');
}
function testEachMapping(scm: SourceMap.SourceMapConsumer) {
var x: SourceMap.MappingItem;
var context: {};
scm.eachMapping(mapping => { x = mapping; });
scm.eachMapping(mapping => { x = mapping; }, context);
scm.eachMapping(mapping => { x = mapping; }, context, SourceMap.SourceMapConsumer.GENERATED_ORDER);
scm.eachMapping(mapping => { x = mapping; }, context, SourceMap.SourceMapConsumer.ORIGINAL_ORDER);
}
}
function testSourceMapGenerator() {
function testConstructor() {
var generator: SourceMap.SourceMapGenerator;
generator = new SourceMap.SourceMapGenerator();
generator = new SourceMap.SourceMapGenerator({
file: 'foo'
});
generator = new SourceMap.SourceMapGenerator({
sourceRoot: 'foo'
});
generator = new SourceMap.SourceMapGenerator({
file: 'foo',
sourceRoot: 'bar'
});
}
function testFromSourceMap(generator: SourceMap.SourceMapGenerator, scm: SourceMap.SourceMapConsumer) {
generator = SourceMap.SourceMapGenerator.fromSourceMap(scm);
}
function testAddMapping(generator: SourceMap.SourceMapGenerator) {
generator.addMapping({
generated: { line: 42, column: 42 },
original: { line: 42, column: 42 },
source: 'foo',
name: 'foo'
});
generator.addMapping({
generated: { line: 42, column: 42 },
original: { line: 42, column: 42 },
source: 'foo'
});
}
function testSetSourceContent(generator: SourceMap.SourceMapGenerator) {
generator.setSourceContent('foo', 'bar');
}
function testApplySourceMap(generator: SourceMap.SourceMapGenerator, scm: SourceMap.SourceMapConsumer) {
generator.applySourceMap(scm);
generator.applySourceMap(scm, 'foo');
generator.applySourceMap(scm, 'foo', 'bar');
}
function testToString(generator: SourceMap.SourceMapGenerator) {
var str: string;
str = generator.toString();
}
}
function testSourceNode() {
function testConstructor() {
var node: SourceMap.SourceNode;
node = new SourceMap.SourceNode();
node = new SourceMap.SourceNode(42, 42, 'foo');
node = new SourceMap.SourceNode(42, 42, 'foo', 'bar');
node = new SourceMap.SourceNode(42, 42, 'foo', 'bar', 'slam');
}
function testFromStringWithSourceMap(scm: SourceMap.SourceMapConsumer) {
var node: SourceMap.SourceNode;
node = SourceMap.SourceNode.fromStringWithSourceMap('foo', scm);
node = SourceMap.SourceNode.fromStringWithSourceMap('foo', scm, 'bar');
}
function testAdd(node: SourceMap.SourceNode) {
node.add('foo');
}
function testPrepend(node: SourceMap.SourceNode) {
node.prepend('foo');
}
function testSetSourceContent(node: SourceMap.SourceNode) {
node.setSourceContent('foo', 'bar');
}
function testWalk(node: SourceMap.SourceNode) {
var chunk: string;
var mapping: SourceMap.MappedPosition;
node.walk((c, m) => { chunk = c; mapping = m; });
}
function testWalkSourceContents(node: SourceMap.SourceNode) {
var file: string;
var content: string;
node.walkSourceContents((f, c) => { file = f; content = c; });
}
function testJoin(node: SourceMap.SourceNode) {
node = node.join('foo');
}
function testReplaceRight(node: SourceMap.SourceNode) {
node = node.replaceRight('foo', 'bar');
}
function testToString(node: SourceMap.SourceNode) {
var str: string;
str = node.toString();
}
function testToStringWithSourceMap(node: SourceMap.SourceNode, sos: SourceMap.StartOfSourceMap) {
var result: SourceMap.CodeWithSourceMap;
result = node.toStringWithSourceMap();
result = node.toStringWithSourceMap(sos);
}
}
+90
View File
@@ -0,0 +1,90 @@
// Type definitions for source-map v0.1.38
// Project: https://github.com/mozilla/source-map
// Definitions by: Morten Houston Ludvigsen <https://github.com/MortenHoustonLudvigsen>
// Definitions: https://github.com/borisyankov/DefinitelyTyped
declare module SourceMap {
interface StartOfSourceMap {
file?: string;
sourceRoot?: string;
}
interface RawSourceMap extends StartOfSourceMap {
version: string;
sources: Array<string>;
names: Array<string>;
sourcesContent?: string;
mappings: string;
}
interface Position {
line: number;
column: number;
}
interface MappedPosition extends Position {
source: string;
name?: string;
}
interface MappingItem {
source: string;
generatedLine: number;
generatedColumn: number;
originalLine: number;
originalColumn: number;
name: string;
}
interface Mapping {
generated: Position;
original: Position;
source: string;
name?: string;
}
interface CodeWithSourceMap {
code: string;
map: SourceMapGenerator;
}
class SourceMapConsumer {
public static GENERATED_ORDER: number;
public static ORIGINAL_ORDER: number;
constructor(rawSourceMap: RawSourceMap);
public originalPositionFor(generatedPosition: Position): MappedPosition;
public generatedPositionFor(originalPosition: MappedPosition): Position;
public sourceContentFor(source: string): 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;
}
class SourceNode {
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;
public add(chunk: string): void;
public prepend(chunk: string): void;
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;
}
}
declare module 'source-map' {
export = SourceMap;
}