Skip to content

Request: Reconstruct original file #15

@cameronbrill

Description

@cameronbrill

be able to reconstruct the original file from sourcemap. something like the following:

smap, err := sourcemap.Parse(mapURL, b)
if err != nil {
	panic(err)
}

originalFile, err := smap.Reconstruct()

or, for the purpose of not loading a whole un-minified file into memory, we can pass in an int denoting number of lines you want reconstructed when you call Source(). Then, return a slice containing n strings which each represent a like. maybe something like this:

smap, err := sourcemap.Parse(mapURL, b)
if err != nil {
	panic(err)
}
line, column, peekCount := 5, 6789, 10
var originalLines []string
file, fn, line, col, originalLines, ok := smap.Source(line, column, peekCount)

originalLines would then have 5 lines above the mapped line, the mapped line, and 4 lines below, like so:

{
	"package main",
	"",
	"import \"fmt\"",
	"",
	"func main() {",
	"\tfor i := 0; i < 5; i++ {", // Mapped line
	"\t\tfmt.Println(\"howdy\")",
	"\t}",
	"}",
	"",
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions