Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Request: Reconstruct original file #15

Open
cameronbrill opened this issue Jun 25, 2021 · 1 comment
Open

Request: Reconstruct original file #15

cameronbrill opened this issue Jun 25, 2021 · 1 comment

Comments

@cameronbrill
Copy link

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}",
	"}",
	"",
}
@cameronbrill
Copy link
Author

I might try to implement this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant