sourcemap

package module
v2.1.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 11, 2020 License: BSD-2-Clause Imports: 9 Imported by: 2

README

Source maps consumer for Golang

Build Status

API docs: https://godoc.org/github.com/go-sourcemap/sourcemap. Examples: https://godoc.org/github.com/go-sourcemap/sourcemap#pkg-examples. Spec: https://docs.google.com/document/d/1U1RGAehQwRypUTovF1KRlpiOFze0b-_2gc6fAH0KY0k/edit.

Installation

Install:

go get -u github.com/go-sourcemap/sourcemap

Quickstart

func ExampleParse() {
	mapURL := "http://code.jquery.com/jquery-2.0.3.min.map"
	resp, err := http.Get(mapURL)
	if err != nil {
		panic(err)
	}
	defer resp.Body.Close()

	b, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		panic(err)
	}

	smap, err := sourcemap.Parse(mapURL, b)
	if err != nil {
		panic(err)
	}

	line, column := 5, 6789
	file, fn, line, col, ok := smap.Source(line, column)
	fmt.Println(file, fn, line, col, ok)
	// Output: http://code.jquery.com/jquery-2.0.3.js apply 4360 27 true
}

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Consumer

type Consumer struct {
	// contains filtered or unexported fields
}

func Parse

func Parse(sourcemapURL string, b []byte) (*Consumer, error)
Example
package main

import (
	"fmt"
	"io/ioutil"
	"net/http"

	"github.com/go-sourcemap/sourcemap"
)

func main() {
	mapURL := "http://code.jquery.com/jquery-2.0.3.min.map"
	resp, err := http.Get(mapURL)
	if err != nil {
		panic(err)
	}
	defer resp.Body.Close()

	b, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		panic(err)
	}

	smap, err := sourcemap.Parse(mapURL, b)
	if err != nil {
		panic(err)
	}

	line, column := 5, 6789
	file, fn, line, col, ok := smap.Source(line, column)
	fmt.Println(file, fn, line, col, ok)
}
Output:

http://code.jquery.com/jquery-2.0.3.js apply 4360 27 true

func (*Consumer) File

func (c *Consumer) File() string

File returns an optional name of the generated code that this source map is associated with.

func (*Consumer) Source

func (c *Consumer) Source(
	genLine, genColumn int,
) (source, name string, line, column int, ok bool)

Source returns the original source, name, line, and column information for the generated source's line and column positions.

func (*Consumer) SourceContent added in v2.0.2

func (c *Consumer) SourceContent(source string) string

SourceContent returns the original source content for the source.

func (*Consumer) SourcemapURL added in v2.1.2

func (c *Consumer) SourcemapURL() string

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL