Skip to content

Commit

Permalink
Sourcemap fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
dop251 committed Feb 25, 2018
1 parent ba650e5 commit 26e5c57
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 16 deletions.
2 changes: 1 addition & 1 deletion compiler.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
)

const (
blockLoop = iota
blockLoop = iota
blockTry
blockBranch
blockSwitch
Expand Down
31 changes: 17 additions & 14 deletions parser/statement.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"strings"
"os"
"io/ioutil"
"net/url"
)

func (self *_parser) parseBlockStatement() *ast.BlockStatement {
Expand Down Expand Up @@ -557,25 +558,27 @@ func (self *_parser) parseSourceMap() *sourcemap.Consumer {
lastLine := self.str[strings.LastIndexByte(self.str, '\n') + 1:]
if strings.HasPrefix(lastLine, "//# sourceMappingURL") {
urlIndex := strings.Index(lastLine, "=")
url := lastLine[urlIndex+1:]
urlStr := lastLine[urlIndex+1:]

var data []byte
if strings.HasPrefix(url, "data:application/json;base64") {
b64Index := strings.Index(url, ",")
b64 := url[b64Index+1:]
if strings.HasPrefix(urlStr, "data:application/json") {
b64Index := strings.Index(urlStr, ",")
b64 := urlStr[b64Index+1:]
if d, err := base64.StdEncoding.DecodeString(b64); err == nil {
data = d
}
}

if strings.HasPrefix(strings.ToLower(url), "http") {
// Not implemented - compile error?
return nil
}

if f, err := os.Open(url); err == nil {
if d, err := ioutil.ReadAll(f); err == nil {
data = d
} else {
if smUrl, err := url.Parse(urlStr); err == nil {
if smUrl.Scheme == "" || smUrl.Scheme == "file" {
if f, err := os.Open(smUrl.Path); err == nil {
if d, err := ioutil.ReadAll(f); err == nil {
data = d
}
}
} else {
// Not implemented - compile error?
return nil
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion srcfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ package goja

import (
"fmt"
"github.com/go-sourcemap/sourcemap"
"sort"
"strings"
"github.com/go-sourcemap/sourcemap"
)

type Position struct {
Expand Down

0 comments on commit 26e5c57

Please sign in to comment.