Skip to content

Commit

Permalink
Merge pull request #11 from MaceWindu/master
Browse files Browse the repository at this point in the history
Release 1.0.0
  • Loading branch information
MaceWindu authored Jun 30, 2021
2 parents 26ae987 + 6697ae9 commit e84a866
Show file tree
Hide file tree
Showing 36 changed files with 603 additions and 693 deletions.
11 changes: 11 additions & 0 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<Project>
<ItemGroup>
<PackageVersion Include="esprima" Version="2.0.0" />
<PackageVersion Include="System.Text.Json" Version="5.0.2" />
<PackageVersion Include="Microsoft.SourceLink.GitHub" Version="1.0.0" />
<PackageVersion Include="NUnit3TestAdapter" Version="4.0.0" />
<PackageVersion Include="NUnit" Version="3.13.2" />
<PackageVersion Include="Moq" Version="4.16.1" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="16.10.0" />
</ItemGroup>
</Project>
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ TypeError: Cannot read property 'length' of undefined
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.

```csharp
StackTraceDeminifier sourceMapCallstackDeminifier = StackTraceDeminfierFactory.GetStackTraceDeminfier(new SourceMapProvider(), new SourceCodeProvider());
StackTraceDeminifier sourceMapCallstackDeminifier = StackTraceDeminifierFactory.GetStackTraceDeminfier(new SourceMapProvider(), new SourceCodeProvider());
DeminifyStackTraceResult deminifyStackTraceResult = sourceMapCallstackDeminifier.DeminifyStackTrace(callstack);
string deminifiedCallstack = deminifyStackTraceResult.ToString();
```
Expand Down
2 changes: 2 additions & 0 deletions Shared.props
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,7 @@
<AnalysisLevel>preview</AnalysisLevel>
<EnableNETAnalyzers>true</EnableNETAnalyzers>
<RunAnalyzers>true</RunAnalyzers>

<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
</PropertyGroup>
</Project>
1 change: 1 addition & 0 deletions SourcemapTools.sln
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "root", "root", "{38BD9C43-B
.gitattributes = .gitattributes
.gitignore = .gitignore
CONTRIBUTING.md = CONTRIBUTING.md
Directory.Packages.props = Directory.Packages.props
LICENSE.txt = LICENSE.txt
Package.nuspec = Package.nuspec
README.md = README.md
Expand Down
2 changes: 1 addition & 1 deletion ci/default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ variables:
- name: assemblyVersion
value: 1.0.0
- name: packageVersion
value: 1.0.0-rc.3
value: 1.0.0
- name: nugetDevVersion
value: 1.0.0

Expand Down
15 changes: 13 additions & 2 deletions src/SourceMapTools/CallstackDeminifier/AllAstVisitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace SourcemapToolkit.CallstackDeminifier
// should be removed if https://github.com/sebastienros/esprima-dotnet/pull/148 accepted
internal class AllAstVisitor
{
private readonly List<Node> _parentStack = new List<Node>();
private readonly List<Node> _parentStack = new ();
protected IReadOnlyList<Node> ParentStack => _parentStack;

/// <summary>
Expand Down Expand Up @@ -240,6 +240,9 @@ public virtual void Visit(Node node)
case Nodes.ClassExpression:
VisitClassExpression(node.As<ClassExpression>());
break;
case Nodes.ChainExpression:
VisitChainExpression(node.As<ChainExpression>());
break;
default:
VisitUnknownNode(node);
break;
Expand All @@ -248,6 +251,11 @@ public virtual void Visit(Node node)
_parentStack.RemoveAt(_parentStack.Count - 1);
}

protected virtual void VisitChainExpression(ChainExpression chainExpression)
{
Visit(chainExpression.Expression);
}

protected virtual void VisitProgram(Program program)
{
VisitNodeList(program.Body);
Expand All @@ -260,7 +268,10 @@ protected virtual void VisitUnknownNode(Node node)

protected virtual void VisitCatchClause(CatchClause catchClause)
{
Visit(catchClause.Param);
if (catchClause.Param != null)
{
Visit(catchClause.Param);
}
Visit(catchClause.Body);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,6 @@ public StackFrameDeminifier(ISourceMapStore sourceMapStore, IFunctionMapStore fu
/// <returns>Returns a StackFrameDeminificationResult that contains a stack trace that has been translated to the original source code. The DeminificationError Property indicates if the StackFrame could not be deminified. DeminifiedStackFrame will not be null, but any properties of DeminifiedStackFrame could be null if the value could not be extracted. </returns>
StackFrameDeminificationResult IStackFrameDeminifier.DeminifyStackFrame(StackFrame stackFrame, string? callerSymbolName)
{
if (stackFrame == null)
{
throw new ArgumentNullException(nameof(stackFrame));
}

var sourceMap = _sourceMapStore.GetSourceMapForUrl(stackFrame.FilePath);
var generatedSourcePosition = stackFrame.SourcePosition;

Expand Down
10 changes: 0 additions & 10 deletions src/SourceMapTools/CallstackDeminifier/StackTraceParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,6 @@ IReadOnlyList<StackFrame> IStackTraceParser.ParseStackTrace(string stackTraceStr
/// </returns>
public virtual IReadOnlyList<StackFrame> ParseStackTrace(string stackTraceString, out string? message)
{
if (stackTraceString == null)
{
throw new ArgumentNullException(nameof(stackTraceString));
}

message = null;

var stackFrameStrings = stackTraceString.SplitFast('\n');
Expand Down Expand Up @@ -137,11 +132,6 @@ public virtual IReadOnlyList<StackFrame> ParseStackTrace(string stackTraceString
/// </summary>
protected internal virtual StackFrame? TryParseSingleStackFrame(string frame)
{
if (frame == null)
{
throw new ArgumentNullException(nameof(frame));
}

var lineNumberMatch = _lineNumberRegex.Match(frame);

if (!lineNumberMatch.Success)
Expand Down
5 changes: 4 additions & 1 deletion src/SourceMapTools/SourcemapParser/MappingEntry.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
namespace SourcemapToolkit.SourcemapParser
using System.Diagnostics;

namespace SourcemapToolkit.SourcemapParser
{
/// <summary>
/// Source map entry.
/// </summary>
[DebuggerDisplay("(Column: {GeneratedSourcePosition.Column}, Line: {GeneratedSourcePosition.Line}): {OriginalName}")]
public struct MappingEntry
{
/// <summary>
Expand Down
5 changes: 0 additions & 5 deletions src/SourceMapTools/SourcemapParser/SourceMap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,6 @@ public SourceMap Clone()
/// </summary>
public SourceMap ApplySourceMap(SourceMap submap, string? sourceFile = null)
{
if (submap == null)
{
throw new ArgumentNullException(nameof(submap));
}

if (sourceFile == null)
{
if (submap.File == null)
Expand Down
5 changes: 0 additions & 5 deletions src/SourceMapTools/SourcemapParser/SourceMapGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,6 @@ public static string GenerateSourceMapInlineComment(SourceMap sourceMap, JsonSer
/// </summary>
public static string SerializeMapping(SourceMap sourceMap, JsonSerializerOptions? jsonSerializerSettings = null)
{
if (sourceMap == null)
{
throw new ArgumentNullException(nameof(sourceMap));
}

string? mappings = null;
if (sourceMap.ParsedMappings.Count > 0)
{
Expand Down
6 changes: 3 additions & 3 deletions src/SourceMapTools/SourcemapTools.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="esprima" Version="2.0.0-beta-1338" />
<PackageReference Include="System.Text.Json" Version="5.0.1" />
<PackageReference Include="esprima" />
<PackageReference Include="System.Text.Json" />

<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0">
<PackageReference Include="Microsoft.SourceLink.GitHub">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
using System.Collections.Generic;
using SourcemapToolkit.SourcemapParser;
using Xunit;
using NUnit.Framework;

namespace SourcemapToolkit.CallstackDeminifier.UnitTests
{

public class FunctionMapConsumerUnitTests
{
[Fact]
[Test]
public void GetWrappingFunctionForSourceLocation_EmptyFunctionMap_ReturnNull()
{
// Arrange
Expand All @@ -22,7 +22,7 @@ public void GetWrappingFunctionForSourceLocation_EmptyFunctionMap_ReturnNull()
Assert.Null(wrappingFunction);
}

[Fact]
[Test]
public void GetWrappingFunctionForSourceLocation_SingleIrrelevantFunctionMapEntry_ReturnNull()
{
// Arrange
Expand All @@ -44,7 +44,7 @@ public void GetWrappingFunctionForSourceLocation_SingleIrrelevantFunctionMapEntr
Assert.Null(wrappingFunction);
}

[Fact]
[Test]
public void GetWrappingFunctionForSourceLocation_SingleRelevantFunctionMapEntry_ReturnWrappingFunction()
{
// Arrange
Expand All @@ -65,10 +65,10 @@ public void GetWrappingFunctionForSourceLocation_SingleRelevantFunctionMapEntry_
var wrappingFunction = functionMapConsumer.GetWrappingFunctionForSourceLocation(sourcePosition, functionMap);

// Assert
Assert.Equal(functionMapEntry, wrappingFunction);
Assert.AreEqual(functionMapEntry, wrappingFunction);
}

[Fact]
[Test]
public void GetWrappingFunctionForSourceLocation_MultipleFunctionMapEntriesSingleRelevantFunctionMapEntry_ReturnWrappingFunction()
{
// Arrange
Expand Down Expand Up @@ -96,10 +96,10 @@ public void GetWrappingFunctionForSourceLocation_MultipleFunctionMapEntriesSingl
var wrappingFunction = functionMapConsumer.GetWrappingFunctionForSourceLocation(sourcePosition, functionMap);

// Assert
Assert.Equal(functionMapEntry2, wrappingFunction);
Assert.AreEqual(functionMapEntry2, wrappingFunction);
}

[Fact]
[Test]
public void GetWrappingFunctionForSourceLocation_MultipleFunctionMapEntriesMultipleRelevantFunctionMapEntry_ReturnClosestWrappingFunction()
{
// Arrange
Expand Down Expand Up @@ -127,7 +127,7 @@ public void GetWrappingFunctionForSourceLocation_MultipleFunctionMapEntriesMulti
var wrappingFunction = functionMapConsumer.GetWrappingFunctionForSourceLocation(sourcePosition, functionMap);

// Assert
Assert.Equal(functionMapEntry2, wrappingFunction);
Assert.AreEqual(functionMapEntry2, wrappingFunction);
}
}
}
Loading

0 comments on commit e84a866

Please sign in to comment.