Refactor JS sourcemap generator (#21053)
* Parse the new line format * Fix pattern Didn't have space after the path * Remove duplicate sources Sources would sometimes double up with a new line at the end * Remove unused variable * Refactor sourcemap.nim Removes the multiple translations needed, now goes from single high level type to the final SourceMap Adds documentation for procs * Line numbers line up properly now Files aren't linking correctly though * Files now link up correctly Lines are sometimes off but overall seems pretty good Just need to implement parser * Add column info to output Add sourceMappingURL to rope directly to prevent copy * Properly handle columns * Remove debug lines * Add testcase * Finish testcase * Use the outdir folder instead of the folder the test is in to find the sourcemap Co-authored-by: ringabout <43030857+ringabout@users.noreply.github.com>
This commit is contained in:
parent
d84f64d2e7
commit
1fefb8e92a
3 changed files with 283 additions and 361 deletions
|
|
@ -724,8 +724,9 @@ proc hasFrameInfo(p: PProc): bool =
|
|||
((p.prc == nil) or not (sfPure in p.prc.flags))
|
||||
|
||||
proc lineDir(config: ConfigRef, info: TLineInfo, line: int): Rope =
|
||||
ropes.`%`("/* line $2 \"$1\" */$n",
|
||||
[rope(toFullPath(config, info)), rope(line)])
|
||||
"/* line $2:$3 \"$1\" */$n" % [
|
||||
rope(toFullPath(config, info)), rope(line), rope(info.toColumn)
|
||||
]
|
||||
|
||||
proc genLineDir(p: PProc, n: PNode) =
|
||||
let line = toLinenumber(n.info)
|
||||
|
|
@ -2885,7 +2886,8 @@ proc myClose(graph: ModuleGraph; b: PPassContext, n: PNode): PNode =
|
|||
# Generate an optional source map.
|
||||
if optSourcemap in m.config.globalOptions:
|
||||
var map: SourceMap
|
||||
(code, map) = genSourceMap($(code), outFile.string)
|
||||
map = genSourceMap($code, outFile.string)
|
||||
code &= "\n//# sourceMappingURL=$#.map" % [outFile.string]
|
||||
writeFile(outFile.string & ".map", $(%map))
|
||||
# Check if the generated JS code matches the output file, or else
|
||||
# write it to the file.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue