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

Goal: Fix source map mappings key and use relative line values #4198

Merged
merged 3 commits into from
Jun 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions data/transactions/logic/sourcemap.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ type SourceMap struct {
SourceRoot string `json:"sourceRoot,omitempty"`
Sources []string `json:"sources"`
Names []string `json:"names"`
Mapping string `json:"mapping"`
// Mapping field is deprecated. Use `Mappings` field instead.
Mapping string `json:"mapping"`
Mappings string `json:"mappings"`
}

// GetSourceMap returns a struct containing details about
Expand All @@ -49,24 +51,25 @@ func GetSourceMap(sourceNames []string, offsetToLine map[int]int) SourceMap {
}
}

// Array where index is the PC and value is the line.
// Array where index is the PC and value is the line for `mappings` field.
prevSourceLine := 0
pcToLine := make([]string, maxPC+1)
for pc := range pcToLine {
if line, ok := offsetToLine[pc]; ok {
pcToLine[pc] = MakeSourceMapLine(0, 0, line, 0)
pcToLine[pc] = MakeSourceMapLine(0, 0, line-prevSourceLine, 0)
prevSourceLine = line
} else {
pcToLine[pc] = ""
}
}

// Encode the source map into a string
encodedMapping := strings.Join(pcToLine, ";")

return SourceMap{
Version: sourceMapVersion,
Sources: sourceNames,
Names: []string{}, // TEAL code does not generate any names.
Mapping: encodedMapping,
// Mapping is deprecated, and only for backwards compatibility.
Mapping: strings.Join(pcToLine, ";"),
Mappings: strings.Join(pcToLine, ";"),
}
}

Expand Down
12 changes: 7 additions & 5 deletions data/transactions/logic/sourcemap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,15 @@ func TestGetSourceMap(t *testing.T) {
a.Equal(sourceNames, actualSourceMap.Sources)
a.Equal([]string{}, actualSourceMap.Names)

// Check encoding for each line.
splitMapping := strings.Split(actualSourceMap.Mapping, ";")
for pc := range splitMapping {
// Check encoding for `mappings` field.
splitMappings := strings.Split(actualSourceMap.Mappings, ";")
prevLine := 0
for pc := range splitMappings {
if line, ok := offsetToLine[pc]; ok {
a.Equal(MakeSourceMapLine(0, 0, line, 0), splitMapping[pc])
a.Equal(MakeSourceMapLine(0, 0, line-prevLine, 0), splitMappings[pc])
prevLine = line
} else {
a.Equal("", splitMapping[pc])
a.Equal("", splitMappings[pc])
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion test/scripts/e2e_subs/tealprogs/quine.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.