Code Monkey home page Code Monkey logo

sourcemaps's Introduction

SourceMaps

.NET Standard 2.0 library for parsing and using SourceMaps

Packages

SourceMaps NuGet Version

SourceMaps library that handles parsing of the sourcemap and has methods for getting the original position, name and file for a generated position.

SourceMaps.StackTraces NuGet Version

SourceMaps.StackTraces is an additional package that can be used to parse JavaScript stack traces and map them with the source map to the original files.

Usage

SourceMaps

To parse a sourcemap

using SourceMaps;

var sourceMap = SourceMapParser.Parse(sourceMapAsString);

To get the original mapping for a given generated position, use

var mapping = sourceMap.OriginalPositionFor(generatedLineNumber: 1, generatedColumnNumber: 1);

mapping.OriginalName; // original token name
mapping.OriginalFileName; // original file name
mapping.OriginalSourcePosition.LineNumber; // original line number
mapping.OriginalSourcePosition.ColumnNumber; // original column number

SourceMaps.StackTraces

To get the original stack trace using the source maps

StackTraceParser.ReTrace(
    sourceMap,
    stackTrace: @"ReferenceError: ""getExceptionProps"" is undefined
    at eval code (eval code:1:1)
    at foo (http://path/to/file.js:58:17)
    at bar (http://path/to/file.js:109:1)",
    sourceRoot: "https://localhost:5001/js/");

sourcemaps's People

Contributors

dependabot[bot] avatar sleeuwen avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

sourcemaps's Issues

Incorrect source map parsing?

Hi,

I'm trying to trace a stacktrace for a script that has been created by webpack. The stacktrace comes from server side rendering this using ReactJS.NET and "V8JsEngine".

The original stacktrace looks like

at useFilterQs (hbd-ssr.1d6f13df.js:283:9)
    at ProductList (hbd-ssr.1d6f13df.js:4774:79)
    at processChild (hbd-ssr.1d6f13df.js:56618:14)
    at resolve (hbd-ssr.1d6f13df.js:56535:5)
    at render (hbd-ssr.1d6f13df.js:57010:22)
    at read (hbd-ssr.1d6f13df.js:56948:29)
    at renderToString (hbd-ssr.1d6f13df.js:57563:27)
    at Script [3]:1:16

Using this library I get:

test at Error (webpack:///../src/UI/hbd-ui/src/base/hooks/use-filter-qs.ts:14:11)
 at webpack:///../src/UI/hbd-ui/src/components/products/list/index.tsx:79:25
 at webpack:///../node_modules/react-dom/cjs/react-dom-server.browser.development.js:3042:1
 at webpack:///../node_modules/react-dom/cjs/react-dom-server.browser.development.js:2959:1
 at webpack:///../node_modules/react-dom/cjs/react-dom-server.browser.development.js:3434:1
 at webpack:///../node_modules/react-dom/cjs/react-dom-server.browser.development.js:3372:1
 at webpack:///../node_modules/react-dom/cjs/react-dom-server.browser.development.js:3987:1
 at Script ([3]:1:16)

If I instead of rendering this on the server let the client render I get the following stacktrace:

Uncaught Error: test
    at useFilterQs (use-filter-qs.ts:14)
    at ProductList (index.tsx:79)
    at renderWithHooks (react-dom.development.js:14803)
    at mountIndeterminateComponent (react-dom.development.js:17482)
    at beginWork (react-dom.development.js:18596)
    at HTMLUnknownElement.callCallback (react-dom.development.js:188)
    at Object.invokeGuardedCallbackDev (react-dom.development.js:237)
    at invokeGuardedCallback (react-dom.development.js:292)
    at beginWork$1 (react-dom.development.js:23203)
    at performUnitOfWork (react-dom.development.js:22154)

It seems like I'm loosing the function names? I tried validating this using tools like stacktracify (https://github.com/mifi/stacktracify). This tools gives me the same result as you library. This lead me to that maybe its a webpack problem. But it seems like the browser is able to parse the source map correclty. Is is it just doing something else to make it work?

I can see that the Frame has the correct method names but it get overriden by the OriginalName property from the SourceMapMappingEntry. Is this correct?

{SourceMaps.SourceMapMappingEntry}
    GeneratedColumnNumber: 74
    GeneratedLineNumber: 88920
    OriginalColumnNumber: 31
    OriginalFileName: "webpack:///../src/UI/hbd-ui/src/base/hooks/use-filter-qs.ts"
    OriginalLineNumber: 13
    OriginalName: "location"

{SourceMaps.SourceMapMappingEntry}
    GeneratedColumnNumber: 85
    GeneratedLineNumber: 93715
    OriginalColumnNumber: 24
    OriginalFileName: "webpack:///../src/UI/hbd-ui/src/components/products/list/index.tsx"
    OriginalLineNumber: 78
    OriginalName: null
frame.File = originalPosition?.OriginalFileName;
frame.Method = originalPosition?.OriginalName;
frame.LineNumber = originalPosition?.OriginalLineNumber + 1;
frame.ColumnNumber = originalPosition?.OriginalColumnNumber + 1;

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.