package js_parser

import (
	
	

	
	
	
	
)
Specification: https://sourcemaps.info/spec.html
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{})
					}
				}
			}
		}
	}
Silently fail if the version was missing or incorrect
	if ! {
		return nil
	}
Silently fail if the source map is pointless (i.e. empty)
	if len() == 0 || len() == 0 {
		return nil
	}

	var  mappingArray
	 := len()
	 := len()
	 := 0
	 := 0
	 := 0
	 := 0
	 := 0
	 := 0
	 := ""
	 := 0
	 := false
Parse the mappings
Handle a line break
		if [] == ';' {
			++
			 = 0
			++
			continue
		}
Read the generated column
		, ,  := sourcemap.DecodeVLQUTF16([:])
		if ! {
			 = "Missing generated column"
			 = 
			break
		}
This would mess up binary search
			 = true
		}
		 += 
		if  < 0 {
			 = fmt.Sprintf("Invalid generated column value: %d", )
			 = 
			break
		}
		 += 
According to the specification, it's valid for a mapping to have 1, 4, or 5 variable-length fields. Having one field means there's no original location information, which is pretty useless. Just ignore those entries.
		if  ==  {
			break
		}
		switch [] {
		case ',':
			++
			continue
		case ';':
			continue
		}
Read the original source
		, ,  := sourcemap.DecodeVLQUTF16([:])
		if ! {
			 = "Missing source index"
			 = 
			break
		}
		 += 
		if  < 0 ||  >=  {
			 = fmt.Sprintf("Invalid source index value: %d", )
			 = 
			break
		}
		 += 
Read the original line
		, ,  := sourcemap.DecodeVLQUTF16([:])
		if ! {
			 = "Missing original line"
			 = 
			break
		}
		 += 
		if  < 0 {
			 = fmt.Sprintf("Invalid original line value: %d", )
			 = 
			break
		}
		 += 
Read the original column
		, ,  := sourcemap.DecodeVLQUTF16([:])
		if ! {
			 = "Missing original column"
			 = 
			break
		}
		 += 
		if  < 0 {
			 = fmt.Sprintf("Invalid original column value: %d", )
			 = 
			break
		}
		 += 
Ignore the optional name index
		if , ,  := sourcemap.DecodeVLQUTF16([:]);  {
			 += 
		}
Handle the next character
		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
	}

If we get here, some mappings are out of order. Lines can't be out of order by construction but columns can. This is a pretty rare situation because almost all source map generators always write out mappings in order as they write the output instead of scrambling the order.
		sort.Stable()
	}

	return &sourcemap.SourceMap{
		Sources:        ,
		SourcesContent: ,
		Mappings:       ,
	}
}
This type is just so we can use Go's native sort function
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)