From a8fbeb0d2883ccccd90ab68ad3ea218bbc3bfe7a Mon Sep 17 00:00:00 2001 From: Martin Poelstra Date: Mon, 14 Jul 2014 10:57:13 +0200 Subject: [PATCH] Expand typings for source-map-support. --- .../source-map-support-tests.ts | 36 ++++++++++++++++++ source-map-support/source-map-support.d.ts | 37 ++++++++++++++++++- 2 files changed, 71 insertions(+), 2 deletions(-) diff --git a/source-map-support/source-map-support-tests.ts b/source-map-support/source-map-support-tests.ts index ddd6308cc2..09a4fff459 100644 --- a/source-map-support/source-map-support-tests.ts +++ b/source-map-support/source-map-support-tests.ts @@ -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"); diff --git a/source-map-support/source-map-support.d.ts b/source-map-support/source-map-support.d.ts index 8d4e225796..b0de346a7b 100644 --- a/source-map-support/source-map-support.d.ts +++ b/source-map-support/source-map-support.d.ts @@ -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 // 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; }