-
Notifications
You must be signed in to change notification settings - Fork 105
Dev Tools: Source map decoder #335
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
Merged
Merged
Changes from all commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
efae689
Merge branch 'release/v1.14.1'
algojack 6b6dfc0
Merge branch 'release/v1.15.0'
algobarb 7c7bab4
Merge branch 'release/v1.16.0'
onetechnical fae5b08
Merge branch 'release/v1.17.0'
egieseke d4964bb
adding source map decoder
barnjamin f4d6c30
adding tests for source map
barnjamin 364a52e
Revert docker shell script
barnjamin f6775ba
Merge branch 'develop' into src-map-decoder
barnjamin 7b0d13b
Update logic/source_map.go
barnjamin d12ab29
adding correct name for mappings with bbackwards commpat option
barnjamin ec833c0
adding check for version and empty mappings
barnjamin 6d872ec
updated to new format for mappings
barnjamin a6de1cf
dont export decoder
barnjamin 0583896
rename test args to be more clear
barnjamin ad440ed
add test
barnjamin b4e37dc
Merge branch 'develop' into src-map-decoder
barnjamin d94d3a8
adding integration test, hack for teal compile with source map
barnjamin da90c91
use goquery to encode the get params
barnjamin c0444fc
tweak line to pc logic for new deltas
barnjamin 4348498
adding tealCompile change generated from generator
barnjamin 2c673b2
add new tests
barnjamin 78767cd
revert to master
barnjamin c76b0ac
Adding extra param for get params on post
barnjamin 763e945
swap arguments to make it cleaner
barnjamin 8a4964a
fix post
barnjamin 848ba91
fix arg names in client
barnjamin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,133 @@ | ||
| package logic | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "strings" | ||
| ) | ||
|
|
||
| // SourceMap provides a mapping of the source to assembled program | ||
| type SourceMap struct { | ||
| Version int `json:"version"` | ||
| File string `json:"file,omitempty"` | ||
| SourceRoot string `json:"sourceRoot,omitempty"` | ||
| Sources []string `json:"sources"` | ||
| Names []string `json:"names"` | ||
| Mappings string `json:"mappings"` | ||
| // Decoded mapping results | ||
| LineToPc map[int][]int | ||
| PcToLine map[int]int | ||
| } | ||
|
|
||
| func DecodeSourceMap(ism map[string]interface{}) (SourceMap, error) { | ||
| sm := SourceMap{} | ||
|
|
||
| if v, ok := ism["version"]; ok { | ||
| sm.Version = int(v.(float64)) | ||
| } | ||
|
|
||
| if sm.Version != 3 { | ||
| return sm, fmt.Errorf("only version 3 is supported") | ||
| } | ||
|
|
||
| if f, ok := ism["file"]; ok { | ||
| sm.File = f.(string) | ||
| } | ||
|
|
||
| if sr, ok := ism["sourceRoot"]; ok { | ||
| sm.SourceRoot = sr.(string) | ||
| } | ||
|
|
||
| if srcs, ok := ism["sources"]; ok { | ||
| srcSlice := srcs.([]interface{}) | ||
| sm.Sources = make([]string, len(srcSlice)) | ||
| for idx, s := range srcSlice { | ||
| sm.Sources[idx] = s.(string) | ||
| } | ||
| } | ||
|
|
||
| if names, ok := ism["names"]; ok { | ||
| nameSlice := names.([]interface{}) | ||
| sm.Names = make([]string, len(nameSlice)) | ||
| for idx, n := range nameSlice { | ||
| sm.Names[idx] = n.(string) | ||
| } | ||
| } | ||
|
|
||
| if m, ok := ism["mappings"]; ok { | ||
| sm.Mappings = m.(string) | ||
| } | ||
|
|
||
| if sm.Mappings == "" { | ||
| return sm, fmt.Errorf("no mappings defined") | ||
| } | ||
|
|
||
| sm.PcToLine = map[int]int{} | ||
| sm.LineToPc = map[int][]int{} | ||
|
|
||
| lastLine := 0 | ||
| for idx, chunk := range strings.Split(sm.Mappings, ";") { | ||
| vals := decodeSourceMapLine(chunk) | ||
| // If the vals length >= 3 the lineDelta | ||
| if len(vals) >= 3 { | ||
| lastLine = lastLine + vals[2] // Add the line delta | ||
| } | ||
|
|
||
| if _, ok := sm.LineToPc[lastLine]; !ok { | ||
| sm.LineToPc[lastLine] = []int{} | ||
| } | ||
|
|
||
| sm.LineToPc[lastLine] = append(sm.LineToPc[lastLine], idx) | ||
| sm.PcToLine[idx] = lastLine | ||
| } | ||
|
|
||
| return sm, nil | ||
| } | ||
|
|
||
| func (s *SourceMap) GetLineForPc(pc int) (int, bool) { | ||
| line, ok := s.PcToLine[pc] | ||
| return line, ok | ||
| } | ||
|
|
||
| func (s *SourceMap) GetPcsForLine(line int) []int { | ||
| return s.LineToPc[line] | ||
| } | ||
|
|
||
| const ( | ||
| // consts used for vlq encoding/decoding | ||
| b64table string = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/" | ||
| vlqShiftSize = 5 | ||
| vlqFlag = 1 << vlqShiftSize | ||
| vlqMask = vlqFlag - 1 | ||
| ) | ||
|
|
||
| func decodeSourceMapLine(vlq string) []int { | ||
|
|
||
| var ( | ||
| results []int | ||
| value, shift int | ||
| ) | ||
|
|
||
| for i := 0; i < len(vlq); i++ { | ||
| digit := strings.Index(b64table, string(vlq[i])) | ||
|
|
||
| value |= (digit & int(vlqMask)) << shift | ||
|
|
||
| if digit&vlqFlag > 0 { | ||
| shift += vlqShiftSize | ||
| continue | ||
| } | ||
|
|
||
| if value&1 > 0 { | ||
| value = (value >> 1) * -1 | ||
| } else { | ||
| value = value >> 1 | ||
| } | ||
|
|
||
| results = append(results, value) | ||
|
|
||
| // Reset | ||
| value, shift = 0, 0 | ||
| } | ||
|
|
||
| return results | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.