MCPcopy Create free account
hub / github.com/dop251/goja / parseSourceMap

Method parseSourceMap

parser/statement.go:915–958  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

913}
914
915func (self *_parser) parseSourceMap() *sourcemap.Consumer {
916 if self.opts.disableSourceMaps {
917 return nil
918 }
919 if smLine := extractSourceMapLine(self.str); smLine != "" {
920 urlIndex := strings.Index(smLine, "=")
921 urlStr := smLine[urlIndex+1:]
922
923 var data []byte
924 var err error
925 if strings.HasPrefix(urlStr, "data:application/json") {
926 b64Index := strings.Index(urlStr, ",")
927 b64 := urlStr[b64Index+1:]
928 data, err = base64.StdEncoding.DecodeString(b64)
929 } else {
930 if sourceURL := file.ResolveSourcemapURL(self.file.Name(), urlStr); sourceURL != nil {
931 if self.opts.sourceMapLoader != nil {
932 data, err = self.opts.sourceMapLoader(sourceURL.String())
933 } else {
934 if sourceURL.Scheme == "" || sourceURL.Scheme == "file" {
935 data, err = os.ReadFile(sourceURL.Path)
936 } else {
937 err = fmt.Errorf("unsupported source map URL scheme: %s", sourceURL.Scheme)
938 }
939 }
940 }
941 }
942
943 if err != nil {
944 self.error(file.Idx(0), "Could not load source map: %v", err)
945 return nil
946 }
947 if data == nil {
948 return nil
949 }
950
951 if sm, err := sourcemap.Parse(self.file.Name(), data); err == nil {
952 return sm
953 } else {
954 self.error(file.Idx(0), "Could not parse source map: %v", err)
955 }
956 }
957 return nil
958}
959
960func (self *_parser) parseBreakStatement() ast.Statement {
961 idx := self.expect(token.BREAK)

Callers 1

parseProgramMethod · 0.95

Calls 6

errorMethod · 0.95
ResolveSourcemapURLFunction · 0.92
IdxTypeAlias · 0.92
extractSourceMapLineFunction · 0.85
NameMethod · 0.80
StringMethod · 0.65

Tested by

no test coverage detected