1
0
mirror of https://github.com/robertkrimen/otto synced 2025-10-26 20:28:49 +08:00

add support for inline source maps

This commit is contained in:
deoxxa
2016-05-08 21:17:26 +10:00
parent c562e464c6
commit 99d478d5e8
2 changed files with 37 additions and 0 deletions

View File

@@ -35,6 +35,7 @@ package parser
import (
"bytes"
"encoding/base64"
"errors"
"io"
"io/ioutil"
@@ -161,6 +162,19 @@ func ParseFileWithSourceMap(fileSet *file.FileSet, filename string, javascriptSo
return nil, err
}
if sourcemapSource == nil {
lines := bytes.Split(src, []byte("\n"))
lastLine := lines[len(lines)-1]
if bytes.HasPrefix(lastLine, []byte("//# sourceMappingURL=data:application/json")) {
bits := bytes.SplitN(lastLine, []byte(","), 2)
if len(bits) == 2 {
if d, err := base64.StdEncoding.DecodeString(string(bits[1])); err == nil {
sourcemapSource = d
}
}
}
}
sm, err := ReadSourceMap(filename, sourcemapSource)
if err != nil {
return nil, err