Skip to content

Commit

Permalink
Merge pull request DefinitelyTyped#2504 from poelstra/master
Browse files Browse the repository at this point in the history
Expand typings for source-map-support.
  • Loading branch information
Bartvds committed Jul 14, 2014
2 parents 33bf97b + a8fbeb0 commit 7ae2aa6
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 2 deletions.
36 changes: 36 additions & 0 deletions source-map-support/source-map-support-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,39 @@
import sms = require('source-map-support');

sms.install();

function retrieveFile(path: string): string {
return "foo";
}

function retrieveSourceMap(source: string): sms.UrlAndMap {
return {
url: "http://foo",
map: "foo"
};
}

var options: sms.Options = {
emptyCacheBetweenOperations: false,
handleUncaughtExceptions: false,
retrieveFile: retrieveFile,
retrieveSourceMap: retrieveSourceMap
};

sms.install(options);

var stackFrame: any; // TODO: this should be a StackFrame, but it seems this would need to be defined elsewhere (in e.g. lib.d.ts)
stackFrame = sms.wrapCallSite(stackFrame);

var s: string;
s = sms.getErrorSource(new Error("foo"));

var p: sms.Position = {
column: 0,
line: 0,
source: "foo"
};
p = sms.mapSourcePosition(p);

var u: sms.UrlAndMap;
u = retrieveSourceMap("foo");
37 changes: 35 additions & 2 deletions source-map-support/source-map-support.d.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,41 @@
// Type definitions for source-map-support 0.2.5
// Type definitions for source-map-support 0.2.6
// Project: https://github.com/evanw/source-map-support
// Definitions by: Bart van der Schoor <https://github.com/Bartvds>
// Definitions: https://github.com/borisyankov/DefinitelyTyped

declare module 'source-map-support' {
export function install(): any;
/**
* Output of retrieveSourceMap().
*/
export interface UrlAndMap {
url: string;
map: any; // string or Buffer
}

/**
* Options to install().
*/
export interface Options {
handleUncaughtExceptions?: boolean;
emptyCacheBetweenOperations?: boolean;
retrieveFile?: (path: string) => string;
retrieveSourceMap?: (source: string) => UrlAndMap;
}

export interface Position {
source: string;
line: number;
column: number;
}

export function wrapCallSite(frame: any /* StackFrame */): any /* StackFrame */;
export function getErrorSource(error: Error): string;
export function mapSourcePosition(position: Position): Position;
export function retrieveSourceMap(source: string): UrlAndMap;

/**
* Install SourceMap support.
* @param options Can be used to e.g. disable uncaughtException handler.
*/
export function install(options?: Options): void;
}

0 comments on commit 7ae2aa6

Please sign in to comment.