Source File
sourcemap_parser.go
Belonging Package
github.com/evanw/esbuild/internal/js_parser
package js_parser
import (
)
func ( logger.Log, logger.Source) *sourcemap.SourceMap {
, := ParseJSON(, , JSONOptions{})
if ! {
return nil
}
, := .Data.(*js_ast.EObject)
if ! {
.AddError(&, .Loc, "Invalid source map")
return nil
}
var []string
var []sourcemap.SourceContent
var []uint16
var int32
:= false
for , := range .Properties {
:= .RangeOfString(.Key.Loc)
switch js_lexer.UTF16ToString(.Key.Data.(*js_ast.EString).Value) {
case "sections":
.AddRangeWarning(&, , "Source maps with \"sections\" are not supported")
return nil
case "version":
if , := .Value.Data.(*js_ast.ENumber); && .Value == 3 {
= true
}
case "mappings":
if , := .Value.Data.(*js_ast.EString); {
= .Value
= .Value.Loc.Start + 1
}
case "sources":
if , := .Value.Data.(*js_ast.EArray); {
= nil
for , := range .Items {
if , := .Data.(*js_ast.EString); {
= append(, js_lexer.UTF16ToString(.Value))
} else {
= append(, "")
}
}
}
case "sourcesContent":
if , := .Value.Data.(*js_ast.EArray); {
= nil
for , := range .Items {
if , := .Data.(*js_ast.EString); {
= append(, sourcemap.SourceContent{
Value: .Value,
Quoted: .TextForRange(.RangeOfString(.Loc)),
})
} else {
= append(, sourcemap.SourceContent{})
}
}
}
}
}
if ! {
return nil
}
if [] == ';' {
++
= 0
++
continue
}
, , := sourcemap.DecodeVLQUTF16([:])
if ! {
= "Missing generated column"
=
break
}
if == {
break
}
switch [] {
case ',':
++
continue
case ';':
continue
}
, , := sourcemap.DecodeVLQUTF16([:])
if ! {
= "Missing source index"
=
break
}
+=
if < 0 || >= {
= fmt.Sprintf("Invalid source index value: %d", )
=
break
}
+=
, , := sourcemap.DecodeVLQUTF16([:])
if ! {
= "Missing original line"
=
break
}
+=
if < 0 {
= fmt.Sprintf("Invalid original line value: %d", )
=
break
}
+=
, , := sourcemap.DecodeVLQUTF16([:])
if ! {
= "Missing original column"
=
break
}
+=
if < 0 {
= fmt.Sprintf("Invalid original column value: %d", )
=
break
}
+=
if , , := sourcemap.DecodeVLQUTF16([:]); {
+=
}
if < {
if := []; == ',' {
++
} else if != ';' {
= fmt.Sprintf("Invalid character after mapping: %q",
js_lexer.UTF16ToString([:+1]))
= 1
break
}
}
= append(, sourcemap.Mapping{
GeneratedLine: int32(),
GeneratedColumn: int32(),
SourceIndex: int32(),
OriginalLine: int32(),
OriginalColumn: int32(),
})
}
if != "" {
:= logger.Range{Loc: logger.Loc{Start: + int32()}, Len: int32()}
.AddRangeWarning(&, ,
fmt.Sprintf("Bad \"mappings\" data in source map at character %d: %s", , ))
return nil
}
type mappingArray []sourcemap.Mapping
func ( mappingArray) () int { return len() }
func ( mappingArray) ( int, int) { [], [] = [], [] }
func ( mappingArray) ( int, int) bool {
:= []
:= []
return .GeneratedLine < .GeneratedLine || (.GeneratedLine == .GeneratedLine && .GeneratedColumn <= .GeneratedColumn)
![]() |
The pages are generated with Golds v0.3.2-preview. (GOOS=darwin GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds. |