originalPosition translates a generated 1-based line and 0-based column into the original source: index into Sources/SourcesContent and 0-based line.
(genLine, genCol int)
| 135 | // originalPosition translates a generated 1-based line and 0-based column into |
| 136 | // the original source: index into Sources/SourcesContent and 0-based line. |
| 137 | func (sm *sourceMap) originalPosition(genLine, genCol int) (srcIndex, origLine, origCol int, ok bool) { |
| 138 | lines := strings.Split(sm.Mappings, ";") |
| 139 | if genLine < 1 || genLine > len(lines) { |
| 140 | return 0, 0, 0, false |
| 141 | } |
| 142 | |
| 143 | // Source index / original line / original column are delta-encoded across the |
| 144 | // whole mappings string; the generated column resets at each generated line. |
| 145 | curSrc, curLine, curCol := 0, 0, 0 |
| 146 | found := false |
| 147 | var fSrc, fLine, fCol int |
| 148 | var firstSrc, firstLine, firstCol int |
| 149 | haveFirst := false |
| 150 | |
| 151 | for li := 0; li < genLine; li++ { |
| 152 | genColAbs := 0 |
| 153 | for _, seg := range strings.Split(lines[li], ",") { |
| 154 | if seg == "" { |
| 155 | continue |
| 156 | } |
| 157 | f := decodeVLQ(seg) |
| 158 | if len(f) == 0 { |
| 159 | continue |
| 160 | } |
| 161 | genColAbs += f[0] |
| 162 | if len(f) >= 4 { |
| 163 | curSrc += f[1] |
| 164 | curLine += f[2] |
| 165 | curCol += f[3] |
| 166 | } |
| 167 | if li == genLine-1 && len(f) >= 4 { |
| 168 | if !haveFirst { |
| 169 | firstSrc, firstLine, firstCol = curSrc, curLine, curCol |
| 170 | haveFirst = true |
| 171 | } |
| 172 | if genColAbs <= genCol { |
| 173 | fSrc, fLine, fCol = curSrc, curLine, curCol |
| 174 | found = true |
| 175 | } |
| 176 | } |
| 177 | } |
| 178 | } |
| 179 | |
| 180 | if found { |
| 181 | return fSrc, fLine, fCol, true |
| 182 | } |
| 183 | if haveFirst { |
| 184 | return firstSrc, firstLine, firstCol, true |
| 185 | } |
| 186 | return 0, 0, 0, false |
| 187 | } |
| 188 | |
| 189 | // originalSourceLines returns the split content of the given source index. |
| 190 | func (sm *sourceMap) originalSourceLines(srcIndex int) ([]string, bool) { |