SourceMaps in JS CodeGen

Issue #100 new
Former user created an issue

Is there any support for SourceMaps in JS CodeGen? I´m trying to use DWS + JS CodeGen with new JS code editors like VSCode or Atom, but without source maps I´m not able to debug the original source. I took a look at the source but it seems unfinished. Maybe I can help..

Comments (5)

  1. Eric Grange repo owner

    Hmm, it was working, but I'll admit I have not used it in years (essentially because browser support was spotty at the time, and the non-obfsucated source is quite debuggable), and there are no tests covering that section.

    I guess a first step would be to find a 3rd party reference source maps parser/debugger, so some tests could be put in place.

  2. gustavo hispagnol

    Where in the source the codegen is feeding the source map object? I couldn't find any place feeding it to start debugging.

  3. Eric Grange repo owner

    TdwsTextCodeGen.NotifyCompileExpr, which is invoked every time an expression is compiled.

    Just did a quick test with Chrome: the sourcemap code still runs (if a bit slow), and works "approximatively" in Chrome debugger: the transcoded source is displayed correctly (rather than compiled code), and when exception or assertions are fired, the correct line is reported in the console, and clicking there takes to the correct location. Evaluating transcoded variable & field names appears correct as well (did not check much).

    However when placing breakpoints or stepping, things are not quite working correctly.

  4. Eric Grange repo owner

    Btw, to get it working you need to

    • append to the generatee JS something like "//@ sourceMappingURL=yourcode.map" on a new line.
    • use JSCodeGen.CompiledSourceMap to generate out the source map file.
    • use JSCodeGen.DebuggingSourceFile to generate transcoded source files for all the source files that were used (use IdwsProgram.SourceList)

    The source file transcoding is required to replace all original variable/field names with their compiled names, so you can evaluate the actual variables (that was necessary a few years ago, but sourcemaps specs and support may have evolved since, so there may be other ways nowadays)

  5. Log in to comment