Skip to content

Commit 426fe08

Browse files
committed
fix nuget dependencies, bump esprima to 2.0.2, cleanup/fix readme
1 parent 6697ae9 commit 426fe08

5 files changed

Lines changed: 30 additions & 86 deletions

File tree

Directory.Packages.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<Project>
22
<ItemGroup>
3-
<PackageVersion Include="esprima" Version="2.0.0" />
3+
<PackageVersion Include="esprima" Version="2.0.2" />
44
<PackageVersion Include="System.Text.Json" Version="5.0.2" />
55
<PackageVersion Include="Microsoft.SourceLink.GitHub" Version="1.0.0" />
66
<PackageVersion Include="NUnit3TestAdapter" Version="4.0.0" />

README.md

Lines changed: 24 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -4,64 +4,15 @@ This is a C# library for working with JavaScript source maps and deminifying Jav
44

55
This is a fork of [microsoft/sourcemap-toolkit](https://github.com/microsoft/sourcemap-toolkit) project that solves following outstanding issues with original project:
66

7-
- no active development is done anymore for original project
7+
- no active development is done anymore for original project, mostly support-only changes for use inside MS teams
88
- no nuget publishing for recent changes: [#64](https://github.com/microsoft/sourcemap-toolkit/issues/64)
99
- lack of support for modern frameworks (.net core): [#57](https://github.com/microsoft/sourcemap-toolkit/issues/57)
1010
- lack of support for ES6+: [#66](https://github.com/microsoft/sourcemap-toolkit/issues/66)
1111

1212
## Source Map Parsing
1313
The `SourcemapTools.dll` provides an API for parsing a souce map into an object that is easy to work with and an API for serializing source map object back to json string.
1414
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.
15-
### Example
16-
#### Source map string
17-
```
18-
{
19-
"version": 3,
20-
"file": "CommonIntl",
21-
"mappings": "AACAA,aAAA,CAAc",
22-
"sources": ["CommonIntl.js"],
23-
"names": ["CommonStrings", "afrikaans"]
24-
}
25-
```
26-
#### Sample source map object
27-
|Name|Value|Type
28-
|--- | --- | ---
29-
|map&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|{SourcemapToolkit.SourcemapParser.SourceMap}|SourcemapToolkit.SourcemapParser.SourceMap
30-
|&nbsp;\|--File|"CommonIntl"|string
31-
|&nbsp;\|--Mappings|"AACAA,aAAA,CAAc"|string
32-
|&nbsp;\|--Names|Count=2|System.Collections.Generic.List<string>
33-
|&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\|--[0]|"CommonStrings"|string
34-
|&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\|--[1]|"afrikaans"|string
35-
|&nbsp;\|--ParsedMappings|Count=3|System.Collections.Generic.List<SourcemapToolkit.SourcemapParser.MappingEntry>
36-
|&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\|--[0]|{SourcemapToolkit.SourcemapParser.MappingEntry}|SourcemapToolkit.SourcemapParser.MappingEntry
37-
|&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\|--GeneratedSourcePosition|{SourcemapToolkit.SourcemapParser.SourcePosition}|SourcemapToolkit.SourcemapParser.SourcePosition
38-
|&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\|--ZeroBasedColumnNumber|0|int
39-
|&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\|--ZeroBasedLineNumber|0|int
40-
|&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\|--OriginalFileName|"CommonIntl.js"|string
41-
|&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\|--OriginalName|"CommonStrings"|string
42-
|&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\|--OriginalSourcePosition|{SourcemapToolkit.SourcemapParser.SourcePosition}|SourcemapToolkit.SourcemapParser.SourcePosition
43-
|&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\|--ZeroBasedColumnNumber|0|int
44-
|&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\|--ZeroBasedLineNumber|1|int
45-
|&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\|--[1]|{SourcemapToolkit.SourcemapParser.MappingEntry}|SourcemapToolkit.SourcemapParser.MappingEntry
46-
|&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\|--GeneratedSourcePosition|{SourcemapToolkit.SourcemapParser.SourcePosition}|SourcemapToolkit.SourcemapParser.SourcePosition
47-
|&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\|--ZeroBasedColumnNumber|13|int
48-
|&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\|--ZeroBasedLineNumber|0|int
49-
|&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\|--OriginalFileName|"CommonIntl.js"|string
50-
|&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\|--OriginalName|null|string
51-
|&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\|--OriginalSourcePosition|{SourcemapToolkit.SourcemapParser.SourcePosition}|SourcemapToolkit.SourcemapParser.SourcePosition
52-
|&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\|--ZeroBasedColumnNumber|0|int
53-
|&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\|--ZeroBasedLineNumber|1|int
54-
|&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\|--[2]|{SourcemapToolkit.SourcemapParser.MappingEntry}|SourcemapToolkit.SourcemapParser.MappingEntry
55-
|&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\|--GeneratedSourcePosition|{SourcemapToolkit.SourcemapParser.SourcePosition}|SourcemapToolkit.SourcemapParser.SourcePosition
56-
|&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\|--ZeroBasedColumnNumber|14|int
57-
|&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\|--ZeroBasedLineNumber|0|int
58-
|&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\|--OriginalFileName|"CommonIntl.js"|string
59-
|&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\|--OriginalName|null|string
60-
|&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\|--OriginalSourcePosition|{SourcemapToolkit.SourcemapParser.SourcePosition}|SourcemapToolkit.SourcemapParser.SourcePosition
61-
|&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\|--ZeroBasedColumnNumber|14|int
62-
|&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\|--ZeroBasedLineNumber|1|int
63-
|&nbsp;\|--Sources|Count=1|System.Collections.Generic.List<string>
64-
|&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\|--[0]|"CommonIntl.js"|string
15+
6516
### Usage
6617
The top level API for source map parsing is the `SourceMapParser.ParseSourceMap` method. The input is a `Stream` that can be used to access the contents of the source map.
6718
The top level API for source map serializing is the `SourceMapGenerator.SerializeMapping` method. The input is a `SourceMap` that to be serialized and an optional JsonSerializerSettings that can be used to control the json serialization.
@@ -70,7 +21,7 @@ A sample usage of the library is shown below.
7021
```csharp
7122
// Parse the source map from file
7223
SourceMap sourceMap;
73-
using (FileStream stream = new FileStream(@"sample.sourcemap", FileMode.Open))
24+
using (var stream = new FileStream(@"sample.sourcemap", FileMode.Open))
7425
{
7526
sourceMap = SourceMapParser.ParseSourceMap(stream);
7627
}
@@ -86,37 +37,30 @@ File.WriteAllText(@"updatedSample.sourcemap", serializedMap);
8637
### Chaining source maps
8738
A common use case when dealing with source maps is multiple mapping layers. You can use `ApplySourceMap` to chain maps together to link back to the source
8839

89-
```csharp
90-
SourcePosition inOriginal = new SourcePosition { ZeroBasedLineNumber = 34, ZeroBasedColumnNumber = 23 };
91-
SourcePosition inBundled = new SourcePosition { ZeroBasedLineNumber = 23, ZeroBasedColumnNumber = 12 };
92-
SourcePosition inMinified = new SourcePosition { ZeroBasedLineNumber = 3, ZeroBasedColumnNumber = 2 };
93-
94-
MappingEntry originalToBundledEntry = new MappingEntry {
95-
GeneratedSourcePosition = inBundled,
96-
OriginalSourcePosition = inOriginal,
97-
OriginalFileName = "original.js"
98-
};
99-
100-
MappingEntry bundledToMinifiedEntry = new MappingEntry {
101-
GeneratedSourcePosition = inMinified,
102-
OriginalSourcePosition = inBundled,
103-
OriginalFileName = "bundle.js"
104-
};
105-
106-
SourceMap bundledToOriginal = new SourceMap {
40+
```cs
41+
var inOriginal = new SourcePosition(34, 23);
42+
var inBundled = new SourcePosition(23, 12);
43+
var inMinified = new SourcePosition(3 , 2 );
44+
45+
var originalToBundledEntry = new MappingEntry(inBundled, inOriginal, null, "original.js");
46+
var bundledToMinifiedEntry = new MappingEntry(inMinified, inBundled, null, "bundle.js");
47+
48+
var bundledToOriginal = new SourceMap()
49+
{
10750
File = "bundled.js",
10851
Sources = new List<string> { "original.js" },
109-
ParsedMappings = new List<MappingEntry> { originalToBundledEntry }
52+
ParsedMappings = new List<MappingEntry> { originalToBundledEntry }
11053
}
11154

112-
SourceMap minifiedToBundled = new SourceMap {
55+
var minifiedToBundled = new SourceMap()
56+
{
11357
File = "bundled.min.js",
11458
Sources = new List<string> { "bundled.js" },
11559
ParsedMappings = new List<MappingEntry> { bundledToMinifiedEntry }
11660
}
11761

11862
// will contain mapping for line 3, column 2 in the minified file to line 34, column 23 in the original file
119-
SourceMap minifiedToOriginal = minifiedToBundled.ApplySourceMap(bundledToOriginal);
63+
var minifiedToOriginal = minifiedToBundled.ApplySourceMap(bundledToOriginal);
12064
```
12165

12266
## Call Stack Deminification
@@ -135,23 +79,23 @@ TypeError: Cannot read property 'length' of undefined
13579
```
13680
FilePath: "http://localhost:11323/crashcauser.min.js"
13781
MethodName: "i"
138-
SourcePosition.ZeroBasedColumnNumber: 49
139-
SourcePosition.ZeroBasedLineNumber: 0
82+
SourcePosition.Column: 49
83+
SourcePosition.Line: 0
14084
```
14185
#### Sample Deminified `StackFrame` entry
14286
```
14387
FilePath: "crashcauser.js"
14488
MethodName: "level1"
145-
SourcePosition.ZeroBasedColumnNumber: 8
146-
SourcePosition.ZeroBasedLineNumber: 5
89+
SourcePosition.Column: 8
90+
SourcePosition.Line: 5
14791
```
14892
### Usage
14993
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 `Stream` that can be used to access the contents of the requested JavaScript code or corresponding source map. A `StackTraceDeminifier` can be instantiated using one of the methods on `StackTraceDeminfierFactory`. A sample usage of the library is shown below.
15094

15195
```csharp
152-
StackTraceDeminifier sourceMapCallstackDeminifier = StackTraceDeminifierFactory.GetStackTraceDeminfier(new SourceMapProvider(), new SourceCodeProvider());
153-
DeminifyStackTraceResult deminifyStackTraceResult = sourceMapCallstackDeminifier.DeminifyStackTrace(callstack);
154-
string deminifiedCallstack = deminifyStackTraceResult.ToString();
96+
var sourceMapCallstackDeminifier = StackTraceDeminifierFactory.GetStackTraceDeminfier(new SourceMapProvider(), new SourceCodeProvider());
97+
var deminifyStackTraceResult = sourceMapCallstackDeminifier.DeminifyStackTrace(callstack);
98+
var deminifiedCallstack = deminifyStackTraceResult.ToString();
15599
```
156100

157101
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.

ci/SourceMapTools.nuspec

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515

1616
<dependencies>
1717
<group targetFramework=".NETStandard2.0">
18-
<dependency id="esprima" version="2.0.0-beta-1338" />
19-
<dependency id="System.Text.Json" version="5.0.1" />
18+
<dependency id="esprima" version="2.0.2" />
19+
<dependency id="System.Text.Json" version="5.0.2" />
2020
</group>
2121
</dependencies>
2222
</metadata>

ci/default.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ variables:
66
- name: assemblyVersion
77
value: 1.0.0
88
- name: packageVersion
9-
value: 1.0.0
9+
value: 1.0.1
1010
- name: nugetDevVersion
11-
value: 1.0.0
11+
value: 1.0.2
1212

1313
trigger:
1414
- master

src/SourceMapTools/SourcemapParser/SourcePosition.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public struct SourcePosition : IComparable<SourcePosition>, IEquatable<SourcePos
1010
/// <summary>
1111
/// Unresolved stack frame postion token.
1212
/// </summary>
13-
public static readonly SourcePosition NotFound = new SourcePosition(-1, -1);
13+
public static readonly SourcePosition NotFound = new (-1, -1);
1414

1515
/// <summary>
1616
/// Zero-based position line number.

0 commit comments

Comments
 (0)