- Notifications
You must be signed in to change notification settings - Fork36
Turns partial code location into precise code location
License
stacktracejs/stacktrace-gps
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
This library accepts a code location (in the form of aStackFrame) andreturns a new StackFrame with a more accurate location (usingsource maps) and guessed function names.
This is primarily a browser-centric library, but can be used with node.js. See theOffline Usage section below.
varstackframe=newStackFrame({fileName:'http://localhost:3000/file.min.js',lineNumber:1,columnNumber:3284});varcallback=functionmyCallback(foundFunctionName){console.log(foundFunctionName);};// Such meta. Wowvarerrback=functionmyErrback(error){console.log(StackTrace.fromError(error));};vargps=newStackTraceGPS();// Pinpoint actual function name and source-mapped locationgps.pinpoint(stackframe).then(callback,errback);//===> Promise(StackFrame({functionName: 'fun', fileName: 'file.js', lineNumber: 203, columnNumber: 9}), Error)// Better location/name information from source mapsgps.getMappedLocation(stackframe).then(callback,errback);//===> Promise(StackFrame({fileName: 'file.js', lineNumber: 203, columnNumber: 9}), Error)// Get function name from location informationgps.findFunctionName(stackframe).then(callback,errback);//===> Promise(StackFrame({functionName: 'fun', fileName: 'http://localhost:3000/file.min.js', lineNumber: 1, columnNumber: 3284}), Error)
With a bit of preparation, you can use this library offline in any environment. Any encountered fileNames not in the cache return resolvedPromises with the original StackFrame. StackTraceGPS will make a best effort to provide as good of response with what is given and willfallback to the original StackFrame if nothing better could be found.
varstack=ErrorStackParser.parse(newError('boom'));console.assert(stack[0]==newStackFrame({fileName:'http://localhost:9999/file.min.js',lineNumber:1,columnNumber:32}));varsourceCache={'http://localhost:9999/file.min.js':'var foo=function(){};function bar(){}var baz=eval("XXX");\n//# sourceMappingURL=file.js.map'};varsourceMap='{"version":3,"sources":["./file.js"],"sourceRoot":"http://localhost:4000/","names":["foo","bar","baz","eval"],"mappings":"AAAA,GAAIA,KAAM,YACV,SAASC,QACT,GAAIC,KAAMC,KAAK","file":"file.min.js"}';varsourceMapConsumerCache={'http://localhost:4000/file.js.map':newSourceMap.SourceMapConsumer(sourceMap)};vargps=newStackTraceGPS({offline:true,sourceCache:sourceCache,sourceMapConsumerCache:sourceMapConsumerCache});gps.pinpoint(stack[0]).then(function(betterStackFrame){console.assert(betterStackFrame===newStackFrame({functionName:'bar',fileName:'http://localhost:9999/file.js',lineNumber:2,columnNumber:9}));});
npm install stacktrace-gpsbower install stacktrace-gpshttps://raw.githubusercontent.com/stacktracejs/stacktrace-gps/master/dist/stacktrace-gps.min.jsoptions: Object
- sourceCache: Object (String URL : String Source) - Pre-populate source cache to avoid network requests
- sourceMapConsumerCache: Object (Source Mapping URL : SourceMap.SourceMapConsumer) - Pre-populate source cache to avoid network requests
- offline: Boolean (default false) - Set to
trueto prevent all network requests - ajax: Function (String URL => Promise(responseText)) - Function to be used for making X-Domain requests
- atob: Function (String => String) - Function to convert base64-encoded strings to their original representation
Enhance function name and use source maps to produce a better StackFrame.
- stackframe -StackFrame or like objecte.g. {fileName: 'path/to/file.js', lineNumber: 100, columnNumber: 5}
Enhance function name and use source maps to produce a better StackFrame.
- stackframe -StackFrame or like object
Enhance function name and use source maps to produce a better StackFrame.
- stackframe -StackFrame or like object
Functions that rely onSource Maps(pinpoint andgetMappedLocation) require recent browsers.
Want to be listed as aContributor? Start with theContributing Guide!
About
Turns partial code location into precise code location
Topics
Resources
License
Contributing
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Uh oh!
There was an error while loading.Please reload this page.