This is a C# library for working with JavaScript SourceMaps. The library is expected to support basic parsing of SourceMaps with the goal of being able to deminify callstacks for code that has been minified.
Перейти к файлу
thomabr 0bd150bfe8 Do not do Bitwise or on DeminificationError, since the Flags attribute was removed in a previous commit. Additionally update the NoFunctionMapProvided error to be NoSourceCodeProvided since FunctionMap is not 2016-12-14 15:21:24 -08:00
src Do not do Bitwise or on DeminificationError, since the Flags attribute was removed in a previous commit. Additionally update the NoFunctionMapProvided error to be NoSourceCodeProvided since FunctionMap is not 2016-12-14 15:21:24 -08:00
tests Do not do Bitwise or on DeminificationError, since the Flags attribute was removed in a previous commit. Additionally update the NoFunctionMapProvided error to be NoSourceCodeProvided since FunctionMap is not 2016-12-14 15:21:24 -08:00
.gitignore Ajaxmin testapp (#6) 2016-09-20 16:05:26 -07:00
LICENSE.txt Add MIT License information to repository (#29) 2016-10-25 13:30:14 -05:00
Package.nuspec Include PDB files for the dlls in the NuGet package (#20) 2016-10-10 15:22:40 -07:00
README.md Updating documentation. 2016-12-14 15:20:50 -08:00
SourceMapToolkit.snk Dot net version downgrade (#13) 2016-10-04 09:52:59 -07:00
SourcemapToolkit.sln Callstack parsing (#5) 2016-09-20 15:49:25 -07:00

README.md

Source Map Toolkit

This is a C# library for working with JavaScript source maps and deminifying JavaScript callstacks.

Source Map Parsing

The SourcemapToolkit.SourcemapParser.dll provides an API for parsing a souce map into an object that is easy to work with. The source map class has a method GetMappingEntryForGeneratedSourcePosition, which can be used to find a source map mapping entry that likely corresponds to a piece of generated code.

Call Stack Deminification

The SourcemapToolkit.CallstackDeminifier.dll allows for the deminification of JavaScript call stacks.

Example

Call stack string

TypeError: Cannot read property 'length' of undefined
    at i (http://localhost:11323/crashcauser.min.js:1:113)
    at t (http://localhost:11323/crashcauser.min.js:1:75)
    at n (http://localhost:11323/crashcauser.min.js:1:50)
    at causeCrash (http://localhost:11323/crashcauser.min.js:1:222)
    at HTMLButtonElement.<anonymous> (http://localhost:11323/crashcauser.min.js:1:326)

Sample Minified StackFrame entry

    FilePath: "http://localhost:11323/crashcauser.min.js"
    MethodName: "i"
    SourcePosition.ZeroBasedColumnNumber: 49
    SourcePosition.ZeroBasedLineNumber: 0

Sample Deminified StackFrame entry

    FilePath: "crashcauser.js"
    MethodName: "level1"
    SourcePosition.ZeroBasedColumnNumber: 8
    SourcePosition.ZeroBasedLineNumber: 5

Usage

The top level API for call stack deminification is the StackTraceDeminifier.DeminifyStackTrace method. For each url that appears in a JavaScript callstack, the library requires the contents of the JavaScript file and corresponding source map in order to determine the original method name and code location. This information is provided by the consumer of the API by implementing the ISourceMapProvider and ISourceCodeProvider interfaces. These interfaces are expected to return a StreamReader that can be used to access the contents of the requested JavaScript code or corresponding source map. A sample usage of the library is shown below

StackTraceDeminifier sourceMapCallstackDeminifier = new StackTraceDeminifier(new SourceMapProvider(), new SourceCodeProvider());
DeminifyStackTraceResult deminifyStackTraceResult = sourceMapCallstackDeminifier.DeminifyStackTrace(callstack)

The result of DeminifyStackTrace is a DeminifyStackTraceResult, which is an object that contains a list of StackFrameDeminificationResults which contains the parsed minified StackFrame objects in the MinifiedStackFrame property and an enum indicating if any errors occured when attempting to deminify the StackFrame. The DeminifiedStackFrame property contains the best guess StackFrame object that maps to the MinifiedStackFrame element with the same index. Note that any of the properties on a StackTrace object may be null if no value could be extracted from the input callstack string or source map.

Remarks

Browsers return one based line and column numbers, while the source map spec calls for zero based line and column numbers. In order to minimize confusion, line and column numbers are normalized to be zero based throughout the library.

Acknowledgements

The Base64 VLQ decoding code was based on the implmentation in the Closure Compiler which is licensed under the Apache License, Version 2.0.

The source map parsing implementation and the relevant comments were based on the Source Maps V3 spec which is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.

The source map parser uses Json.NET which is licensed under the MIT License.

The call stack deminifier and test app both use Ajax Min which is licensed under the Apache License, Version 2.0.

The unit tests for this library leverage the functionality provided by Rhino Mocks. Rhino Mocks is Open Source and released under the BSD license.

License

Copyright (c) Microsoft Corporation. All rights reserved.

Licensed under the MIT License.