21
vendor/gopkg.in/godo.v2/LICENSE
generated
vendored
Normal file
21
vendor/gopkg.in/godo.v2/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2013-2014 Mario L. Gutierrez <mario@mgutz.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
20
vendor/gopkg.in/godo.v2/glob/fileAsset.go
generated
vendored
Normal file
20
vendor/gopkg.in/godo.v2/glob/fileAsset.go
generated
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
package glob
|
||||
|
||||
import "os"
|
||||
|
||||
// FileAsset contains file information and path from globbing.
|
||||
type FileAsset struct {
|
||||
os.FileInfo
|
||||
// Path to asset
|
||||
Path string
|
||||
}
|
||||
|
||||
// Stat updates the stat of this asset.
|
||||
func (fa *FileAsset) Stat() (*os.FileInfo, error) {
|
||||
fi, err := os.Stat(fa.Path)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
fa.FileInfo = fi
|
||||
return &fa.FileInfo, nil
|
||||
}
|
||||
277
vendor/gopkg.in/godo.v2/glob/glob.go
generated
vendored
Normal file
277
vendor/gopkg.in/godo.v2/glob/glob.go
generated
vendored
Normal file
@@ -0,0 +1,277 @@
|
||||
package glob
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
//"log"
|
||||
"os"
|
||||
gpath "path"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"strings"
|
||||
"sync"
|
||||
"unicode/utf8"
|
||||
|
||||
"github.com/MichaelTJones/walk"
|
||||
)
|
||||
|
||||
const (
|
||||
// NotSlash is any rune but path separator.
|
||||
notSlash = "[^/]"
|
||||
// AnyRune is zero or more non-path separators.
|
||||
anyRune = notSlash + "*"
|
||||
// ZeroOrMoreDirectories is used by ** patterns.
|
||||
zeroOrMoreDirectories = `(?:[.{}\w\-\ ]+\/)*`
|
||||
// TrailingStarStar matches everything inside directory.
|
||||
trailingStarStar = "/**"
|
||||
// SlashStarStarSlash maches zero or more directories.
|
||||
slashStarStarSlash = "/**/"
|
||||
)
|
||||
|
||||
// RegexpInfo contains additional info about the Regexp created by a glob pattern.
|
||||
type RegexpInfo struct {
|
||||
Regexp *regexp.Regexp
|
||||
Negate bool
|
||||
Path string
|
||||
Glob string
|
||||
}
|
||||
|
||||
// MatchString matches a string with either a regexp or direct string match
|
||||
func (ri *RegexpInfo) MatchString(s string) bool {
|
||||
if ri.Regexp != nil {
|
||||
return ri.Regexp.MatchString(s)
|
||||
} else if ri.Path != "" {
|
||||
return strings.HasSuffix(s, ri.Path)
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// Globexp builds a regular express from from extended glob pattern and then
|
||||
// returns a Regexp object.
|
||||
func Globexp(glob string) *regexp.Regexp {
|
||||
var re bytes.Buffer
|
||||
|
||||
re.WriteString("^")
|
||||
|
||||
i, inGroup, L := 0, false, len(glob)
|
||||
|
||||
for i < L {
|
||||
r, w := utf8.DecodeRuneInString(glob[i:])
|
||||
|
||||
switch r {
|
||||
default:
|
||||
re.WriteRune(r)
|
||||
|
||||
case '\\', '$', '^', '+', '.', '(', ')', '=', '!', '|':
|
||||
re.WriteRune('\\')
|
||||
re.WriteRune(r)
|
||||
|
||||
case '/':
|
||||
// TODO optimize later, string could be long
|
||||
rest := glob[i:]
|
||||
re.WriteRune('/')
|
||||
if strings.HasPrefix(rest, "/**/") {
|
||||
re.WriteString(zeroOrMoreDirectories)
|
||||
w *= 4
|
||||
} else if rest == "/**" {
|
||||
re.WriteString(".*")
|
||||
w *= 3
|
||||
}
|
||||
|
||||
case '?':
|
||||
re.WriteRune('.')
|
||||
|
||||
case '[', ']':
|
||||
re.WriteRune(r)
|
||||
|
||||
case '{':
|
||||
if i < L-1 {
|
||||
if glob[i+1:i+2] == "{" {
|
||||
re.WriteString("\\{")
|
||||
w *= 2
|
||||
break
|
||||
}
|
||||
}
|
||||
inGroup = true
|
||||
re.WriteRune('(')
|
||||
|
||||
case '}':
|
||||
if inGroup {
|
||||
inGroup = false
|
||||
re.WriteRune(')')
|
||||
} else {
|
||||
re.WriteRune('}')
|
||||
}
|
||||
|
||||
case ',':
|
||||
if inGroup {
|
||||
re.WriteRune('|')
|
||||
} else {
|
||||
re.WriteRune('\\')
|
||||
re.WriteRune(r)
|
||||
}
|
||||
|
||||
case '*':
|
||||
rest := glob[i:]
|
||||
if strings.HasPrefix(rest, "**/") {
|
||||
re.WriteString(zeroOrMoreDirectories)
|
||||
w *= 3
|
||||
} else {
|
||||
re.WriteString(anyRune)
|
||||
}
|
||||
}
|
||||
|
||||
i += w
|
||||
}
|
||||
|
||||
re.WriteString("$")
|
||||
//log.Printf("regex string %s", re.String())
|
||||
return regexp.MustCompile(re.String())
|
||||
}
|
||||
|
||||
// Glob returns files and dirctories that match patterns. Patterns must use
|
||||
// slashes, even Windows.
|
||||
//
|
||||
// Special chars.
|
||||
//
|
||||
// /**/ - match zero or more directories
|
||||
// {a,b} - match a or b, no spaces
|
||||
// * - match any non-separator char
|
||||
// ? - match a single non-separator char
|
||||
// **/ - match any directory, start of pattern only
|
||||
// /** - match any this directory, end of pattern only
|
||||
// ! - removes files from resultset, start of pattern only
|
||||
//
|
||||
func Glob(patterns []string) ([]*FileAsset, []*RegexpInfo, error) {
|
||||
// TODO very inefficient and unintelligent, optimize later
|
||||
|
||||
m := map[string]*FileAsset{}
|
||||
regexps := []*RegexpInfo{}
|
||||
|
||||
for _, pattern := range patterns {
|
||||
remove := strings.HasPrefix(pattern, "!")
|
||||
if remove {
|
||||
pattern = pattern[1:]
|
||||
if hasMeta(pattern) {
|
||||
re := Globexp(pattern)
|
||||
regexps = append(regexps, &RegexpInfo{Regexp: re, Glob: pattern, Negate: true})
|
||||
for path := range m {
|
||||
if re.MatchString(path) {
|
||||
m[path] = nil
|
||||
}
|
||||
}
|
||||
} else {
|
||||
path := gpath.Clean(pattern)
|
||||
m[path] = nil
|
||||
regexps = append(regexps, &RegexpInfo{Path: path, Glob: pattern, Negate: true})
|
||||
}
|
||||
} else {
|
||||
if hasMeta(pattern) {
|
||||
re := Globexp(pattern)
|
||||
regexps = append(regexps, &RegexpInfo{Regexp: re, Glob: pattern})
|
||||
root := PatternRoot(pattern)
|
||||
if root == "" {
|
||||
return nil, nil, fmt.Errorf("Cannot get root from pattern: %s", pattern)
|
||||
}
|
||||
fileAssets, err := walkFiles(root)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
for _, file := range fileAssets {
|
||||
if re.MatchString(file.Path) {
|
||||
// TODO closure problem assigning &file
|
||||
tmp := file
|
||||
m[file.Path] = tmp
|
||||
}
|
||||
}
|
||||
} else {
|
||||
path := gpath.Clean(pattern)
|
||||
info, err := os.Stat(path)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
regexps = append(regexps, &RegexpInfo{Path: path, Glob: pattern, Negate: false})
|
||||
fa := &FileAsset{Path: path, FileInfo: info}
|
||||
m[path] = fa
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//log.Printf("m %v", m)
|
||||
keys := []*FileAsset{}
|
||||
for _, it := range m {
|
||||
if it != nil {
|
||||
keys = append(keys, it)
|
||||
}
|
||||
}
|
||||
return keys, regexps, nil
|
||||
}
|
||||
|
||||
// hasMeta determines if a path has special chars used to build a Regexp.
|
||||
func hasMeta(path string) bool {
|
||||
return strings.IndexAny(path, "*?[{") >= 0
|
||||
}
|
||||
|
||||
func isDir(path string) bool {
|
||||
st, err := os.Stat(path)
|
||||
if os.IsNotExist(err) {
|
||||
return false
|
||||
}
|
||||
return st.IsDir()
|
||||
}
|
||||
|
||||
// PatternRoot gets a real directory root from a pattern. The directory
|
||||
// returned is used as the start location for globbing.
|
||||
func PatternRoot(s string) string {
|
||||
if isDir(s) {
|
||||
return s
|
||||
}
|
||||
|
||||
// No directory in pattern
|
||||
parts := strings.Split(s, "/")
|
||||
if len(parts) == 1 {
|
||||
return "."
|
||||
}
|
||||
// parts returns an empty string at positio 0 if the s starts with "/"
|
||||
root := ""
|
||||
|
||||
// Build path until a dirname has a char used to build regex
|
||||
for i, part := range parts {
|
||||
if hasMeta(part) {
|
||||
break
|
||||
}
|
||||
if i > 0 {
|
||||
root += "/"
|
||||
}
|
||||
root += part
|
||||
}
|
||||
// Default to cwd
|
||||
if root == "" {
|
||||
root = "."
|
||||
}
|
||||
return root
|
||||
}
|
||||
|
||||
// walkFiles walks a directory starting at root returning all directories and files
|
||||
// include those found in subdirectories.
|
||||
func walkFiles(root string) ([]*FileAsset, error) {
|
||||
fileAssets := []*FileAsset{}
|
||||
var lock sync.Mutex
|
||||
visitor := func(path string, info os.FileInfo, err error) error {
|
||||
// if err != nil {
|
||||
// fmt.Println("visitor err", err.Error(), "root", root)
|
||||
// }
|
||||
if err == nil {
|
||||
lock.Lock()
|
||||
fileAssets = append(fileAssets, &FileAsset{FileInfo: info, Path: filepath.ToSlash(path)})
|
||||
lock.Unlock()
|
||||
}
|
||||
return nil
|
||||
}
|
||||
err := walk.Walk(root, visitor)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return fileAssets, nil
|
||||
}
|
||||
164
vendor/gopkg.in/godo.v2/glob/watchCriteria.go
generated
vendored
Normal file
164
vendor/gopkg.in/godo.v2/glob/watchCriteria.go
generated
vendored
Normal file
@@ -0,0 +1,164 @@
|
||||
package glob
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
"github.com/mgutz/str"
|
||||
)
|
||||
|
||||
// WatchCriterion is the criteria needed to test if a file
|
||||
// matches a pattern.
|
||||
type WatchCriterion struct {
|
||||
// Root is the root directory to start watching.
|
||||
Root string
|
||||
// Includes are the regexp for including files
|
||||
IncludesRegexp []*regexp.Regexp
|
||||
// Excludes are the regexp for excluding files
|
||||
ExcludesRegexp []*regexp.Regexp
|
||||
Includes []string
|
||||
Excludes []string
|
||||
}
|
||||
|
||||
func newWatchCriterion(r string) *WatchCriterion {
|
||||
return &WatchCriterion{
|
||||
Root: r,
|
||||
IncludesRegexp: []*regexp.Regexp{},
|
||||
ExcludesRegexp: []*regexp.Regexp{},
|
||||
Includes: []string{},
|
||||
Excludes: []string{},
|
||||
}
|
||||
}
|
||||
|
||||
// WatchCriteria is the set of criterion to watch one or more glob patterns.
|
||||
type WatchCriteria struct {
|
||||
Items []*WatchCriterion
|
||||
}
|
||||
|
||||
func newWatchCriteria() *WatchCriteria {
|
||||
return &WatchCriteria{
|
||||
Items: []*WatchCriterion{},
|
||||
}
|
||||
}
|
||||
|
||||
func (cr *WatchCriteria) findParent(root string) *WatchCriterion {
|
||||
for _, item := range cr.Items {
|
||||
if item.Root == root || strings.Contains(item.Root, root) {
|
||||
return item
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (cr *WatchCriteria) add(glob string) error {
|
||||
var err error
|
||||
|
||||
if glob == "" || glob == "!" {
|
||||
return nil
|
||||
}
|
||||
|
||||
isExclude := strings.HasPrefix(glob, "!")
|
||||
if isExclude {
|
||||
glob = glob[1:]
|
||||
}
|
||||
|
||||
// determine if the root of pattern already exists
|
||||
root := PatternRoot(glob)
|
||||
root, err = filepath.Abs(root)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
root = filepath.ToSlash(root)
|
||||
cri := cr.findParent(root)
|
||||
if cri == nil {
|
||||
cri = newWatchCriterion(root)
|
||||
cr.Items = append(cr.Items, cri)
|
||||
}
|
||||
|
||||
glob, err = filepath.Abs(glob)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// add glob to {in,ex}cludes
|
||||
if isExclude {
|
||||
if str.SliceIndexOf(cri.Excludes, glob) < 0 {
|
||||
re := Globexp(glob)
|
||||
cri.ExcludesRegexp = append(cri.ExcludesRegexp, re)
|
||||
cri.Excludes = append(cri.Excludes, glob)
|
||||
}
|
||||
} else {
|
||||
if str.SliceIndexOf(cri.Includes, glob) < 0 {
|
||||
re := Globexp(glob)
|
||||
cri.IncludesRegexp = append(cri.IncludesRegexp, re)
|
||||
cri.Includes = append(cri.Includes, glob)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Roots returns the root paths of all criteria.
|
||||
func (cr *WatchCriteria) Roots() []string {
|
||||
if cr.Items == nil || len(cr.Items) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
roots := make([]string, len(cr.Items))
|
||||
for i, it := range cr.Items {
|
||||
roots[i] = it.Root
|
||||
}
|
||||
return roots
|
||||
}
|
||||
|
||||
// Matches determines if pth is matched by internal criteria.
|
||||
func (cr *WatchCriteria) Matches(pth string) bool {
|
||||
match := false
|
||||
pth = filepath.ToSlash(pth)
|
||||
for _, it := range cr.Items {
|
||||
// if sub path
|
||||
if strings.HasPrefix(pth, it.Root) {
|
||||
// check if matches an include pattern
|
||||
for _, re := range it.IncludesRegexp {
|
||||
if re.MatchString(pth) {
|
||||
match = true
|
||||
break
|
||||
}
|
||||
}
|
||||
// when found, check if it is excluded
|
||||
if match {
|
||||
for _, re := range it.ExcludesRegexp {
|
||||
if re.MatchString(pth) {
|
||||
match = false
|
||||
break
|
||||
}
|
||||
}
|
||||
if match {
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
// EffectiveCriteria is the minimum set of criteria to watch the
|
||||
// items in patterns
|
||||
func EffectiveCriteria(globs ...string) (*WatchCriteria, error) {
|
||||
if len(globs) == 0 {
|
||||
return nil, nil
|
||||
}
|
||||
result := newWatchCriteria()
|
||||
for _, glob := range globs {
|
||||
err := result.add(glob)
|
||||
if err != nil {
|
||||
fmt.Println(err.Error())
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
16
vendor/gopkg.in/sourcemap.v1/.travis.yml
generated
vendored
Normal file
16
vendor/gopkg.in/sourcemap.v1/.travis.yml
generated
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
sudo: false
|
||||
language: go
|
||||
|
||||
go:
|
||||
- 1.6
|
||||
- 1.7
|
||||
- tip
|
||||
|
||||
matrix:
|
||||
allow_failures:
|
||||
- go: tip
|
||||
|
||||
install:
|
||||
- mkdir -p $HOME/gopath/src/gopkg.in
|
||||
- mv $HOME/gopath/src/github.com/go-sourcemap/sourcemap $HOME/gopath/src/gopkg.in/sourcemap.v1
|
||||
- cd $HOME/gopath/src/gopkg.in/sourcemap.v1
|
||||
25
vendor/gopkg.in/sourcemap.v1/LICENSE
generated
vendored
Normal file
25
vendor/gopkg.in/sourcemap.v1/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,25 @@
|
||||
Copyright (c) 2016 The github.com/go-sourcemap/sourcemap Contributors.
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are
|
||||
met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above
|
||||
copyright notice, this list of conditions and the following disclaimer
|
||||
in the documentation and/or other materials provided with the
|
||||
distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
4
vendor/gopkg.in/sourcemap.v1/Makefile
generated
vendored
Normal file
4
vendor/gopkg.in/sourcemap.v1/Makefile
generated
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
all:
|
||||
go test ./...
|
||||
go test ./... -short -race
|
||||
go vet
|
||||
35
vendor/gopkg.in/sourcemap.v1/README.md
generated
vendored
Normal file
35
vendor/gopkg.in/sourcemap.v1/README.md
generated
vendored
Normal file
@@ -0,0 +1,35 @@
|
||||
# Source Maps consumer for Golang [](https://travis-ci.org/go-sourcemap/sourcemap)
|
||||
|
||||
## Installation
|
||||
|
||||
Install:
|
||||
|
||||
go get gopkg.in/sourcemap.v1
|
||||
|
||||
## Quickstart
|
||||
|
||||
```go
|
||||
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
|
||||
}
|
||||
```
|
||||
92
vendor/gopkg.in/sourcemap.v1/base64vlq/base64_vlq.go
generated
vendored
Normal file
92
vendor/gopkg.in/sourcemap.v1/base64vlq/base64_vlq.go
generated
vendored
Normal file
@@ -0,0 +1,92 @@
|
||||
package base64vlq
|
||||
|
||||
import (
|
||||
"io"
|
||||
)
|
||||
|
||||
const encodeStd = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
|
||||
|
||||
const (
|
||||
vlqBaseShift = 5
|
||||
vlqBase = 1 << vlqBaseShift
|
||||
vlqBaseMask = vlqBase - 1
|
||||
vlqSignBit = 1
|
||||
vlqContinuationBit = vlqBase
|
||||
)
|
||||
|
||||
var decodeMap [256]byte
|
||||
|
||||
func init() {
|
||||
for i := 0; i < len(encodeStd); i++ {
|
||||
decodeMap[encodeStd[i]] = byte(i)
|
||||
}
|
||||
}
|
||||
|
||||
func toVLQSigned(n int) int {
|
||||
if n < 0 {
|
||||
return -n<<1 + 1
|
||||
}
|
||||
return n << 1
|
||||
}
|
||||
|
||||
func fromVLQSigned(n int) int {
|
||||
isNeg := n&vlqSignBit != 0
|
||||
n >>= 1
|
||||
if isNeg {
|
||||
return -n
|
||||
}
|
||||
return n
|
||||
}
|
||||
|
||||
type Encoder struct {
|
||||
w io.ByteWriter
|
||||
}
|
||||
|
||||
func NewEncoder(w io.ByteWriter) *Encoder {
|
||||
return &Encoder{
|
||||
w: w,
|
||||
}
|
||||
}
|
||||
|
||||
func (enc Encoder) Encode(n int) error {
|
||||
n = toVLQSigned(n)
|
||||
for digit := vlqContinuationBit; digit&vlqContinuationBit != 0; {
|
||||
digit = n & vlqBaseMask
|
||||
n >>= vlqBaseShift
|
||||
if n > 0 {
|
||||
digit |= vlqContinuationBit
|
||||
}
|
||||
|
||||
err := enc.w.WriteByte(encodeStd[digit])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type Decoder struct {
|
||||
r io.ByteReader
|
||||
}
|
||||
|
||||
func NewDecoder(r io.ByteReader) *Decoder {
|
||||
return &Decoder{
|
||||
r: r,
|
||||
}
|
||||
}
|
||||
|
||||
func (dec Decoder) Decode() (n int, err error) {
|
||||
shift := uint(0)
|
||||
for continuation := true; continuation; {
|
||||
c, err := dec.r.ReadByte()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
c = decodeMap[c]
|
||||
continuation = c&vlqContinuationBit != 0
|
||||
n += int(c&vlqBaseMask) << shift
|
||||
shift += vlqBaseShift
|
||||
}
|
||||
return fromVLQSigned(n), nil
|
||||
}
|
||||
134
vendor/gopkg.in/sourcemap.v1/consumer.go
generated
vendored
Normal file
134
vendor/gopkg.in/sourcemap.v1/consumer.go
generated
vendored
Normal file
@@ -0,0 +1,134 @@
|
||||
package sourcemap
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"path"
|
||||
"sort"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
type Consumer struct {
|
||||
sourceRootURL *url.URL
|
||||
smap *sourceMap
|
||||
mappings []mapping
|
||||
}
|
||||
|
||||
func Parse(mapURL string, b []byte) (*Consumer, error) {
|
||||
smap := new(sourceMap)
|
||||
err := json.Unmarshal(b, smap)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if smap.Version != 3 {
|
||||
return nil, fmt.Errorf(
|
||||
"sourcemap: got version=%d, but only 3rd version is supported",
|
||||
smap.Version,
|
||||
)
|
||||
}
|
||||
|
||||
var sourceRootURL *url.URL
|
||||
if smap.SourceRoot != "" {
|
||||
u, err := url.Parse(smap.SourceRoot)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if u.IsAbs() {
|
||||
sourceRootURL = u
|
||||
}
|
||||
} else if mapURL != "" {
|
||||
u, err := url.Parse(mapURL)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if u.IsAbs() {
|
||||
u.Path = path.Dir(u.Path)
|
||||
sourceRootURL = u
|
||||
}
|
||||
}
|
||||
|
||||
mappings, err := parseMappings(smap.Mappings)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// Free memory.
|
||||
smap.Mappings = ""
|
||||
|
||||
return &Consumer{
|
||||
sourceRootURL: sourceRootURL,
|
||||
smap: smap,
|
||||
mappings: mappings,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (c *Consumer) File() string {
|
||||
return c.smap.File
|
||||
}
|
||||
|
||||
func (c *Consumer) Source(genLine, genCol int) (source, name string, line, col int, ok bool) {
|
||||
i := sort.Search(len(c.mappings), func(i int) bool {
|
||||
m := &c.mappings[i]
|
||||
if m.genLine == genLine {
|
||||
return m.genCol >= genCol
|
||||
}
|
||||
return m.genLine >= genLine
|
||||
})
|
||||
|
||||
// Mapping not found.
|
||||
if i == len(c.mappings) {
|
||||
return
|
||||
}
|
||||
|
||||
match := &c.mappings[i]
|
||||
|
||||
// Fuzzy match.
|
||||
if match.genLine > genLine || match.genCol > genCol {
|
||||
if i == 0 {
|
||||
return
|
||||
}
|
||||
match = &c.mappings[i-1]
|
||||
}
|
||||
|
||||
if match.sourcesInd >= 0 {
|
||||
source = c.absSource(c.smap.Sources[match.sourcesInd])
|
||||
}
|
||||
if match.namesInd >= 0 {
|
||||
v := c.smap.Names[match.namesInd]
|
||||
switch v := v.(type) {
|
||||
case string:
|
||||
name = v
|
||||
case float64:
|
||||
name = strconv.FormatFloat(v, 'f', -1, 64)
|
||||
default:
|
||||
name = fmt.Sprint(v)
|
||||
}
|
||||
}
|
||||
line = match.sourceLine
|
||||
col = match.sourceCol
|
||||
ok = true
|
||||
return
|
||||
}
|
||||
|
||||
func (c *Consumer) absSource(source string) string {
|
||||
if path.IsAbs(source) {
|
||||
return source
|
||||
}
|
||||
|
||||
if u, err := url.Parse(source); err == nil && u.IsAbs() {
|
||||
return source
|
||||
}
|
||||
|
||||
if c.sourceRootURL != nil {
|
||||
u := *c.sourceRootURL
|
||||
u.Path = path.Join(c.sourceRootURL.Path, source)
|
||||
return u.String()
|
||||
}
|
||||
|
||||
if c.smap.SourceRoot != "" {
|
||||
return path.Join(c.smap.SourceRoot, source)
|
||||
}
|
||||
|
||||
return source
|
||||
}
|
||||
157
vendor/gopkg.in/sourcemap.v1/sourcemap.go
generated
vendored
Normal file
157
vendor/gopkg.in/sourcemap.v1/sourcemap.go
generated
vendored
Normal file
@@ -0,0 +1,157 @@
|
||||
package sourcemap // import "gopkg.in/sourcemap.v1"
|
||||
|
||||
import (
|
||||
"io"
|
||||
"strings"
|
||||
|
||||
"gopkg.in/sourcemap.v1/base64vlq"
|
||||
)
|
||||
|
||||
type fn func(m *mappings) (fn, error)
|
||||
|
||||
type sourceMap struct {
|
||||
Version int `json:"version"`
|
||||
File string `json:"file"`
|
||||
SourceRoot string `json:"sourceRoot"`
|
||||
Sources []string `json:"sources"`
|
||||
Names []interface{} `json:"names"`
|
||||
Mappings string `json:"mappings"`
|
||||
}
|
||||
|
||||
type mapping struct {
|
||||
genLine int
|
||||
genCol int
|
||||
sourcesInd int
|
||||
sourceLine int
|
||||
sourceCol int
|
||||
namesInd int
|
||||
}
|
||||
|
||||
type mappings struct {
|
||||
rd *strings.Reader
|
||||
dec *base64vlq.Decoder
|
||||
|
||||
hasName bool
|
||||
value mapping
|
||||
|
||||
values []mapping
|
||||
}
|
||||
|
||||
func parseMappings(s string) ([]mapping, error) {
|
||||
rd := strings.NewReader(s)
|
||||
m := &mappings{
|
||||
rd: rd,
|
||||
dec: base64vlq.NewDecoder(rd),
|
||||
}
|
||||
m.value.genLine = 1
|
||||
m.value.sourceLine = 1
|
||||
|
||||
err := m.parse()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m.values, nil
|
||||
}
|
||||
|
||||
func (m *mappings) parse() error {
|
||||
next := parseGenCol
|
||||
for {
|
||||
c, err := m.rd.ReadByte()
|
||||
if err == io.EOF {
|
||||
m.pushValue()
|
||||
return nil
|
||||
}
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
switch c {
|
||||
case ',':
|
||||
m.pushValue()
|
||||
next = parseGenCol
|
||||
case ';':
|
||||
m.pushValue()
|
||||
|
||||
m.value.genLine++
|
||||
m.value.genCol = 0
|
||||
|
||||
next = parseGenCol
|
||||
default:
|
||||
err := m.rd.UnreadByte()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
next, err = next(m)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func parseGenCol(m *mappings) (fn, error) {
|
||||
n, err := m.dec.Decode()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
m.value.genCol += n
|
||||
return parseSourcesInd, nil
|
||||
}
|
||||
|
||||
func parseSourcesInd(m *mappings) (fn, error) {
|
||||
n, err := m.dec.Decode()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
m.value.sourcesInd += n
|
||||
return parseSourceLine, nil
|
||||
}
|
||||
|
||||
func parseSourceLine(m *mappings) (fn, error) {
|
||||
n, err := m.dec.Decode()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
m.value.sourceLine += n
|
||||
return parseSourceCol, nil
|
||||
}
|
||||
|
||||
func parseSourceCol(m *mappings) (fn, error) {
|
||||
n, err := m.dec.Decode()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
m.value.sourceCol += n
|
||||
return parseNamesInd, nil
|
||||
}
|
||||
|
||||
func parseNamesInd(m *mappings) (fn, error) {
|
||||
n, err := m.dec.Decode()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
m.hasName = true
|
||||
m.value.namesInd += n
|
||||
return parseGenCol, nil
|
||||
}
|
||||
|
||||
func (m *mappings) pushValue() {
|
||||
if m.value.sourceLine == 1 && m.value.sourceCol == 0 {
|
||||
return
|
||||
}
|
||||
|
||||
if m.hasName {
|
||||
m.values = append(m.values, m.value)
|
||||
m.hasName = false
|
||||
} else {
|
||||
m.values = append(m.values, mapping{
|
||||
genLine: m.value.genLine,
|
||||
genCol: m.value.genCol,
|
||||
sourcesInd: m.value.sourcesInd,
|
||||
sourceLine: m.value.sourceLine,
|
||||
sourceCol: m.value.sourceCol,
|
||||
namesInd: -1,
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user