From 0f07d91f54e8f98b2a5ba5b956e3be79b0186369 Mon Sep 17 00:00:00 2001 From: Tom Limoncelli Date: Wed, 12 Feb 2020 21:17:56 -0500 Subject: [PATCH] go mod vendor --- .../robertkrimen/otto/builtin_number.go | 7 + vendor/github.com/robertkrimen/otto/inline.go | 31 +++ vendor/github.com/robertkrimen/otto/inline.pl | 1 + .../github.com/robertkrimen/otto/runtime.go | 80 ++++--- .../robertkrimen/otto/type_go_array.go | 34 ++- .../robertkrimen/otto/type_go_struct.go | 22 +- vendor/github.com/tdewolff/buffer/LICENSE.md | 22 -- vendor/github.com/tdewolff/buffer/README.md | 40 ---- vendor/github.com/tdewolff/buffer/buffer.go | 15 -- vendor/github.com/tdewolff/buffer/lexer.go | 153 ------------ vendor/github.com/tdewolff/buffer/reader.go | 44 ---- .../github.com/tdewolff/buffer/streamlexer.go | 223 ------------------ vendor/github.com/tdewolff/buffer/writer.go | 41 ---- .../github.com/tdewolff/minify/.gitattributes | 1 + vendor/github.com/tdewolff/minify/.gitignore | 4 + .../tdewolff/minify/.goreleaser.yml | 28 +++ vendor/github.com/tdewolff/minify/.travis.yml | 2 - vendor/github.com/tdewolff/minify/README.md | 159 +++++++------ vendor/github.com/tdewolff/minify/common.go | 153 ++++++++++-- .../github.com/tdewolff/minify/json/json.go | 2 + vendor/github.com/tdewolff/minify/minify.go | 12 +- .../tdewolff/{ => parse}/strconv/float.go | 2 +- .../tdewolff/{ => parse}/strconv/int.go | 9 +- .../tdewolff/parse/strconv/price.go | 83 +++++++ vendor/github.com/tdewolff/strconv/LICENSE.md | 22 -- vendor/github.com/tdewolff/strconv/README.md | 10 - vendor/gopkg.in/sourcemap.v1/.travis.yml | 12 +- vendor/gopkg.in/sourcemap.v1/LICENSE | 25 ++ vendor/gopkg.in/sourcemap.v1/Makefile | 5 +- vendor/gopkg.in/sourcemap.v1/README.md | 2 +- .../sourcemap.v1/base64vlq/base64_vlq.go | 21 +- vendor/gopkg.in/sourcemap.v1/consumer.go | 202 +--------------- vendor/gopkg.in/sourcemap.v1/sourcemap.go | 157 ++++++++++++ vendor/modules.txt | 11 +- 34 files changed, 705 insertions(+), 930 deletions(-) delete mode 100644 vendor/github.com/tdewolff/buffer/LICENSE.md delete mode 100644 vendor/github.com/tdewolff/buffer/README.md delete mode 100644 vendor/github.com/tdewolff/buffer/buffer.go delete mode 100644 vendor/github.com/tdewolff/buffer/lexer.go delete mode 100644 vendor/github.com/tdewolff/buffer/reader.go delete mode 100644 vendor/github.com/tdewolff/buffer/streamlexer.go delete mode 100644 vendor/github.com/tdewolff/buffer/writer.go create mode 100644 vendor/github.com/tdewolff/minify/.gitattributes create mode 100644 vendor/github.com/tdewolff/minify/.gitignore create mode 100644 vendor/github.com/tdewolff/minify/.goreleaser.yml rename vendor/github.com/tdewolff/{ => parse}/strconv/float.go (98%) rename vendor/github.com/tdewolff/{ => parse}/strconv/int.go (90%) create mode 100644 vendor/github.com/tdewolff/parse/strconv/price.go delete mode 100644 vendor/github.com/tdewolff/strconv/LICENSE.md delete mode 100644 vendor/github.com/tdewolff/strconv/README.md create mode 100644 vendor/gopkg.in/sourcemap.v1/LICENSE create mode 100644 vendor/gopkg.in/sourcemap.v1/sourcemap.go diff --git a/vendor/github.com/robertkrimen/otto/builtin_number.go b/vendor/github.com/robertkrimen/otto/builtin_number.go index f99a42a2f..9f11ef68a 100644 --- a/vendor/github.com/robertkrimen/otto/builtin_number.go +++ b/vendor/github.com/robertkrimen/otto/builtin_number.go @@ -88,6 +88,13 @@ func builtinNumber_toPrecision(call FunctionCall) Value { return toValue_string(strconv.FormatFloat(call.This.float64(), 'g', int(precision), 64)) } +func builtinNumber_isNaN(call FunctionCall) Value { + if len(call.ArgumentList) < 1 { + return toValue_bool(false) + } + return toValue_bool(call.Argument(0).IsNaN()) +} + func builtinNumber_toLocaleString(call FunctionCall) Value { return builtinNumber_toString(call) } diff --git a/vendor/github.com/robertkrimen/otto/inline.go b/vendor/github.com/robertkrimen/otto/inline.go index 6e5df8393..149ffd8f3 100644 --- a/vendor/github.com/robertkrimen/otto/inline.go +++ b/vendor/github.com/robertkrimen/otto/inline.go @@ -2627,6 +2627,29 @@ func _newContext(runtime *_runtime) { call: builtinNumber_toLocaleString, }, } + isNaN_function := &_object{ + runtime: runtime, + class: "Function", + objectClass: _classObject, + prototype: runtime.global.FunctionPrototype, + extensible: true, + property: map[string]_property{ + "length": _property{ + mode: 0, + value: Value{ + kind: valueNumber, + value: 1, + }, + }, + }, + propertyOrder: []string{ + "length", + }, + value: _nativeFunctionObject{ + name: "isNaN", + call: builtinNumber_isNaN, + }, + } runtime.global.NumberPrototype = &_object{ runtime: runtime, class: "Number", @@ -2713,6 +2736,13 @@ func _newContext(runtime *_runtime) { value: runtime.global.NumberPrototype, }, }, + "isNaN": _property{ + mode: 0101, + value: Value{ + kind: valueObject, + value: isNaN_function, + }, + }, "MAX_VALUE": _property{ mode: 0, value: Value{ @@ -2752,6 +2782,7 @@ func _newContext(runtime *_runtime) { propertyOrder: []string{ "length", "prototype", + "isNaN", "MAX_VALUE", "MIN_VALUE", "NaN", diff --git a/vendor/github.com/robertkrimen/otto/inline.pl b/vendor/github.com/robertkrimen/otto/inline.pl index e90290489..e21444dd0 100644 --- a/vendor/github.com/robertkrimen/otto/inline.pl +++ b/vendor/github.com/robertkrimen/otto/inline.pl @@ -372,6 +372,7 @@ sub newContext { 1, $self->functionDeclare( $class, + "isNaN", 1, ), $self->numberConstantDeclare( "MAX_VALUE", "math.MaxFloat64", diff --git a/vendor/github.com/robertkrimen/otto/runtime.go b/vendor/github.com/robertkrimen/otto/runtime.go index 9941278f6..987a5132f 100644 --- a/vendor/github.com/robertkrimen/otto/runtime.go +++ b/vendor/github.com/robertkrimen/otto/runtime.go @@ -2,6 +2,7 @@ package otto import ( "encoding" + "encoding/json" "errors" "fmt" "math" @@ -264,6 +265,8 @@ func (self *_runtime) convertNumeric(v Value, t reflect.Type) reflect.Value { panic(self.panicRangeError(fmt.Sprintf("converting %v to %v would overflow", val.Type(), t))) } return val.Convert(t) + case reflect.Float32, reflect.Float64: + return val.Convert(t) } case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64: @@ -279,13 +282,48 @@ func (self *_runtime) convertNumeric(v Value, t reflect.Type) reflect.Value { panic(self.panicRangeError(fmt.Sprintf("converting %v to %v would overflow", val.Type(), t))) } return val.Convert(t) + case reflect.Float32, reflect.Float64: + return val.Convert(t) } } - panic(self.panicTypeError(fmt.Sprintf("unsupported type %v for numeric conversion", val.Type()))) + panic(self.panicTypeError(fmt.Sprintf("unsupported type %v -> %v for numeric conversion", val.Type(), t))) +} + +func fieldIndexByName(t reflect.Type, name string) []int { + for i := 0; i < t.NumField(); i++ { + f := t.Field(i) + + if !validGoStructName(f.Name) { + continue + } + + if f.Anonymous { + if a := fieldIndexByName(f.Type, name); a != nil { + return append([]int{i}, a...) + } + } + + if a := strings.SplitN(f.Tag.Get("json"), ",", 2); a[0] != "" { + if a[0] == "-" { + continue + } + + if a[0] == name { + return []int{i} + } + } + + if f.Name == name { + return []int{i} + } + } + + return nil } var typeOfValue = reflect.TypeOf(Value{}) +var typeOfJSONRawMessage = reflect.TypeOf(json.RawMessage{}) // convertCallParameter converts request val to type t if possible. // If the conversion fails due to overflow or type miss-match then it panics. @@ -295,6 +333,12 @@ func (self *_runtime) convertCallParameter(v Value, t reflect.Type) reflect.Valu return reflect.ValueOf(v) } + if t == typeOfJSONRawMessage { + if d, err := json.Marshal(v.export()); err == nil { + return reflect.ValueOf(d) + } + } + if v.kind == valueObject { if gso, ok := v._object().value.(*_goStructObject); ok { if gso.value.Type().AssignableTo(t) { @@ -467,41 +511,15 @@ func (self *_runtime) convertCallParameter(v Value, t reflect.Type) reflect.Valu s := reflect.New(t) for _, k := range o.propertyOrder { - var f *reflect.StructField + idx := fieldIndexByName(t, k) - for i := 0; i < t.NumField(); i++ { - ff := t.Field(i) - - if j := ff.Tag.Get("json"); j != "" { - if j == "-" { - continue - } - - a := strings.Split(j, ",") - - if a[0] == k { - f = &ff - break - } - } - - if ff.Name == k { - f = &ff - break - } - - if strings.EqualFold(ff.Name, k) { - f = &ff - } - } - - if f == nil { + if idx == nil { panic(self.panicTypeError("can't convert object; field %q was supplied but does not exist on target %v", k, t)) } ss := s - for _, i := range f.Index { + for _, i := range idx { if ss.Kind() == reflect.Ptr { if ss.IsNil() { if !ss.CanSet() { @@ -572,7 +590,7 @@ func (self *_runtime) convertCallParameter(v Value, t reflect.Type) reflect.Valu s = v.Class() } - panic(self.panicTypeError("can't convert from %q to %q", s, t.String())) + panic(self.panicTypeError("can't convert from %q to %q", s, t)) } func (self *_runtime) toValue(value interface{}) Value { diff --git a/vendor/github.com/robertkrimen/otto/type_go_array.go b/vendor/github.com/robertkrimen/otto/type_go_array.go index 13a0b10f2..fbe465dbb 100644 --- a/vendor/github.com/robertkrimen/otto/type_go_array.go +++ b/vendor/github.com/robertkrimen/otto/type_go_array.go @@ -33,16 +33,32 @@ func _newGoArrayObject(value reflect.Value) *_goArrayObject { return self } -func (self _goArrayObject) getValue(index int64) (reflect.Value, bool) { +func (self _goArrayObject) getValue(name string) (reflect.Value, bool) { + if index, err := strconv.ParseInt(name, 10, 64); err != nil { + v, ok := self.getValueIndex(index) + if ok { + return v, ok + } + } + + if m := self.value.MethodByName(name); m != (reflect.Value{}) { + return m, true + } + + return reflect.Value{}, false +} + +func (self _goArrayObject) getValueIndex(index int64) (reflect.Value, bool) { value := reflect.Indirect(self.value) if index < int64(value.Len()) { return value.Index(int(index)), true } + return reflect.Value{}, false } func (self _goArrayObject) setValue(index int64, value Value) bool { - indexValue, exists := self.getValue(index) + indexValue, exists := self.getValueIndex(index) if !exists { return false } @@ -64,11 +80,10 @@ func goArrayGetOwnProperty(self *_object, name string) *_property { } // .0, .1, .2, ... - index := stringToArrayIndex(name) - if index >= 0 { + if index := stringToArrayIndex(name); index >= 0 { object := self.value.(*_goArrayObject) value := Value{} - reflectValue, exists := object.getValue(index) + reflectValue, exists := object.getValueIndex(index) if exists { value = self.runtime.toValue(reflectValue.Interface()) } @@ -78,6 +93,13 @@ func goArrayGetOwnProperty(self *_object, name string) *_property { } } + if method := self.value.(*_goArrayObject).value.MethodByName(name); method != (reflect.Value{}) { + return &_property{ + self.runtime.toValue(method.Interface()), + 0110, + } + } + return objectGetOwnProperty(self, name) } @@ -121,7 +143,7 @@ func goArrayDelete(self *_object, name string, throw bool) bool { if index >= 0 { object := self.value.(*_goArrayObject) if object.writable { - indexValue, exists := object.getValue(index) + indexValue, exists := object.getValueIndex(index) if exists { indexValue.Set(reflect.Zero(reflect.Indirect(object.value).Type().Elem())) return true diff --git a/vendor/github.com/robertkrimen/otto/type_go_struct.go b/vendor/github.com/robertkrimen/otto/type_go_struct.go index 608ac6660..e22713c7c 100644 --- a/vendor/github.com/robertkrimen/otto/type_go_struct.go +++ b/vendor/github.com/robertkrimen/otto/type_go_struct.go @@ -36,6 +36,10 @@ func _newGoStructObject(value reflect.Value) *_goStructObject { } func (self _goStructObject) getValue(name string) reflect.Value { + if idx := fieldIndexByName(reflect.Indirect(self.value).Type(), name); len(idx) > 0 { + return reflect.Indirect(self.value).FieldByIndex(idx) + } + if validGoStructName(name) { // Do not reveal hidden or unexported fields if field := reflect.Indirect(self.value).FieldByName(name); (field != reflect.Value{}) { @@ -50,25 +54,21 @@ func (self _goStructObject) getValue(name string) reflect.Value { return reflect.Value{} } -func (self _goStructObject) field(name string) (reflect.StructField, bool) { - return reflect.Indirect(self.value).Type().FieldByName(name) +func (self _goStructObject) fieldIndex(name string) []int { + return fieldIndexByName(reflect.Indirect(self.value).Type(), name) } func (self _goStructObject) method(name string) (reflect.Method, bool) { return reflect.Indirect(self.value).Type().MethodByName(name) } -func (self _goStructObject) setValue(name string, value Value) bool { - field, exists := self.field(name) - if !exists { +func (self _goStructObject) setValue(rt *_runtime, name string, value Value) bool { + if idx := fieldIndexByName(reflect.Indirect(self.value).Type(), name); len(idx) == 0 { return false } + fieldValue := self.getValue(name) - reflectValue, err := value.toReflectValue(field.Type.Kind()) - if err != nil { - panic(err) - } - fieldValue.Set(reflectValue) + fieldValue.Set(rt.convertCallParameter(value, fieldValue.Type())) return true } @@ -128,7 +128,7 @@ func goStructCanPut(self *_object, name string) bool { func goStructPut(self *_object, name string, value Value, throw bool) { object := self.value.(*_goStructObject) - if object.setValue(name, value) { + if object.setValue(self.runtime, name, value) { return } diff --git a/vendor/github.com/tdewolff/buffer/LICENSE.md b/vendor/github.com/tdewolff/buffer/LICENSE.md deleted file mode 100644 index 41677de41..000000000 --- a/vendor/github.com/tdewolff/buffer/LICENSE.md +++ /dev/null @@ -1,22 +0,0 @@ -Copyright (c) 2015 Taco de Wolff - - 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. \ No newline at end of file diff --git a/vendor/github.com/tdewolff/buffer/README.md b/vendor/github.com/tdewolff/buffer/README.md deleted file mode 100644 index f04157e34..000000000 --- a/vendor/github.com/tdewolff/buffer/README.md +++ /dev/null @@ -1,40 +0,0 @@ -# Buffer [![GoDoc](http://godoc.org/github.com/tdewolff/buffer?status.svg)](http://godoc.org/github.com/tdewolff/buffer) - -This package contains several buffer types used in https://github.com/tdewolff/parse for example. - -## Installation -Run the following command - - go get github.com/tdewolff/buffer - -or add the following import and run the project with `go get` -``` go -import "github.com/tdewolff/buffer" -``` - -## Reader -Reader is a wrapper around a `[]byte` that implements the `io.Reader` interface. It is a much thinner layer than `bytes.Buffer` provides and is therefore faster. - -## Writer -Writer is a buffer that implements the `io.Writer` interface. It is a much thinner layer than `bytes.Buffer` provides and is therefore faster. It will expand the buffer when needed. - -The reset functionality allows for better memory reuse. After calling `Reset`, it will overwrite the current buffer and thus reduce allocations. - -## Lexer -Lexer is a read buffer specifically designed for building lexers. It keeps track of two positions: a start and end position. The start position is the beginning of the current token being parsed, the end position is being moved forward until a valid token is found. Calling `Shift` will collapse the positions to the end and return the parsed `[]byte`. - -Moving the end position can go through `Move(int)` which also accepts negative integers. One can also use `Pos() int` to try and parse a token, and if it fails rewind with `Rewind(int)`, passing the previously saved position. - -`Peek(int) byte` will peek forward (relative to the end position) and return the byte at that location. `PeekRune(int) (rune, int)` returns UTF-8 runes and its length at the given **byte** position. Upon an error `Peek` will return `0`, the **user must peek at every character** and not skip any, otherwise it may skip a `0` and panic on out-of-bounds indexing. - -`Lexeme() []byte` will return the currently selected bytes, `Skip()` will collapse the selection. `Shift() []byte` is a combination of `Lexeme() []byte` and `Skip()`. - -When the passed `io.Reader` returned an error, `Err() error` will return that error even if not at the end of the buffer. - -## StreamLexer -StreamLexer behaves like Lexer but uses a buffer pool to read in chunks from `io.Reader`, retaining old buffers in memory that are still in use, and re-using old buffers otherwise. Calling `Free(n int)` frees up `n` bytes from the internal buffer(s). It holds an array of buffers to accommodate for keeping everything in-memory. Calling `ShiftLen() int` returns the number of bytes that have been shifted since the previous call to `ShiftLen`, which can be used to specify how many bytes need to be freed up from the buffer. If you don't need to keep returned byte slices around, call `Free(ShiftLen())` after every `Shift` call. - -## License -Released under the [MIT license](LICENSE.md). - -[1]: http://golang.org/ "Go Language" diff --git a/vendor/github.com/tdewolff/buffer/buffer.go b/vendor/github.com/tdewolff/buffer/buffer.go deleted file mode 100644 index f16c7cc19..000000000 --- a/vendor/github.com/tdewolff/buffer/buffer.go +++ /dev/null @@ -1,15 +0,0 @@ -/* -Package buffer contains buffer and wrapper types for byte slices. It is useful for writing lexers or other high-performance byte slice handling. - -The `Reader` and `Writer` types implement the `io.Reader` and `io.Writer` respectively and provide a thinner and faster interface than `bytes.Buffer`. -The `Shifter` type is useful for building lexers because it keeps track of the start and end position of a byte selection, and shifts the bytes whenever a valid token is found. -The `Lexer` is however an improved version of `Shifter`, allowing zero-copy for the parser by using a (kind of) ring buffer underneath. -*/ -package buffer // import "github.com/tdewolff/buffer" - -// defaultBufSize specifies the default initial length of internal buffers. -var defaultBufSize = 4096 - -// MinBuf specifies the default initial length of internal buffers. -// Solely here to support old versions of parse. -var MinBuf = defaultBufSize diff --git a/vendor/github.com/tdewolff/buffer/lexer.go b/vendor/github.com/tdewolff/buffer/lexer.go deleted file mode 100644 index 1b9282da2..000000000 --- a/vendor/github.com/tdewolff/buffer/lexer.go +++ /dev/null @@ -1,153 +0,0 @@ -package buffer // import "github.com/tdewolff/buffer" - -import ( - "io" - "io/ioutil" -) - -var nullBuffer = []byte{0} - -// Lexer is a buffered reader that allows peeking forward and shifting, taking an io.Reader. -// It keeps data in-memory until Free, taking a byte length, is called to move beyond the data. -type Lexer struct { - buf []byte - pos int // index in buf - start int // index in buf - err error - - restore func() -} - -// NewLexerBytes returns a new Lexer for a given io.Reader, and uses ioutil.ReadAll to read it into a byte slice. -// If the io.Reader implements Bytes, that is used instead. -// It will append a NULL at the end of the buffer. -func NewLexer(r io.Reader) *Lexer { - var b []byte - if r != nil { - if buffer, ok := r.(interface { - Bytes() []byte - }); ok { - b = buffer.Bytes() - } else { - var err error - b, err = ioutil.ReadAll(r) - if err != nil { - return &Lexer{ - buf: []byte{0}, - err: err, - } - } - } - } - return NewLexerBytes(b) -} - -// NewLexerBytes returns a new Lexer for a given byte slice, and appends NULL at the end. -// To avoid reallocation, make sure the capacity has room for one more byte. -func NewLexerBytes(b []byte) *Lexer { - z := &Lexer{ - buf: b, - } - - n := len(b) - if n == 0 { - z.buf = nullBuffer - } else if b[n-1] != 0 { - // Append NULL to buffer, but try to avoid reallocation - if cap(b) > n { - // Overwrite next byte but restore when done - b = b[:n+1] - c := b[n] - b[n] = 0 - - z.buf = b - z.restore = func() { - b[n] = c - } - } else { - z.buf = append(b, 0) - } - } - return z -} - -// Restore restores the replaced byte past the end of the buffer by NULL. -func (z *Lexer) Restore() { - if z.restore != nil { - z.restore() - z.restore = nil - } -} - -// Err returns the error returned from io.Reader or io.EOF when the end has been reached. -func (z *Lexer) Err() error { - if z.err != nil { - return z.err - } else if z.pos >= len(z.buf)-1 { - return io.EOF - } - return nil -} - -// Peek returns the ith byte relative to the end position. -// Peek returns 0 when an error has occurred, Err returns the error. -func (z *Lexer) Peek(pos int) byte { - pos += z.pos - return z.buf[pos] -} - -// PeekRune returns the rune and rune length of the ith byte relative to the end position. -func (z *Lexer) PeekRune(pos int) (rune, int) { - // from unicode/utf8 - c := z.Peek(pos) - if c < 0xC0 || z.Peek(pos+1) == 0 { - return rune(c), 1 - } else if c < 0xE0 || z.Peek(pos+2) == 0 { - return rune(c&0x1F)<<6 | rune(z.Peek(pos+1)&0x3F), 2 - } else if c < 0xF0 || z.Peek(pos+3) == 0 { - return rune(c&0x0F)<<12 | rune(z.Peek(pos+1)&0x3F)<<6 | rune(z.Peek(pos+2)&0x3F), 3 - } - return rune(c&0x07)<<18 | rune(z.Peek(pos+1)&0x3F)<<12 | rune(z.Peek(pos+2)&0x3F)<<6 | rune(z.Peek(pos+3)&0x3F), 4 -} - -// Move advances the position. -func (z *Lexer) Move(n int) { - z.pos += n -} - -// Pos returns a mark to which can be rewinded. -func (z *Lexer) Pos() int { - return z.pos - z.start -} - -// Rewind rewinds the position to the given position. -func (z *Lexer) Rewind(pos int) { - z.pos = z.start + pos -} - -// Lexeme returns the bytes of the current selection. -func (z *Lexer) Lexeme() []byte { - return z.buf[z.start:z.pos] -} - -// Skip collapses the position to the end of the selection. -func (z *Lexer) Skip() { - z.start = z.pos -} - -// Shift returns the bytes of the current selection and collapses the position to the end of the selection. -func (z *Lexer) Shift() []byte { - b := z.buf[z.start:z.pos] - z.start = z.pos - return b -} - -// Offset returns the character position in the buffer. -func (z *Lexer) Offset() int { - return z.pos -} - -// Bytes returns the underlying buffer. -func (z *Lexer) Bytes() []byte { - return z.buf -} diff --git a/vendor/github.com/tdewolff/buffer/reader.go b/vendor/github.com/tdewolff/buffer/reader.go deleted file mode 100644 index 2c7faee57..000000000 --- a/vendor/github.com/tdewolff/buffer/reader.go +++ /dev/null @@ -1,44 +0,0 @@ -package buffer // import "github.com/tdewolff/buffer" - -import "io" - -// Reader implements an io.Reader over a byte slice. -type Reader struct { - buf []byte - pos int -} - -// NewReader returns a new Reader for a given byte slice. -func NewReader(buf []byte) *Reader { - return &Reader{ - buf: buf, - } -} - -// Read reads bytes into the given byte slice and returns the number of bytes read and an error if occurred. -func (r *Reader) Read(b []byte) (n int, err error) { - if len(b) == 0 { - return 0, nil - } - if r.pos >= len(r.buf) { - return 0, io.EOF - } - n = copy(b, r.buf[r.pos:]) - r.pos += n - return -} - -// Bytes returns the underlying byte slice. -func (r *Reader) Bytes() []byte { - return r.buf -} - -// Reset resets the position of the read pointer to the beginning of the underlying byte slice. -func (r *Reader) Reset() { - r.pos = 0 -} - -// Len returns the length of the buffer. -func (r *Reader) Len() int { - return len(r.buf) -} diff --git a/vendor/github.com/tdewolff/buffer/streamlexer.go b/vendor/github.com/tdewolff/buffer/streamlexer.go deleted file mode 100644 index d6e8d9a9b..000000000 --- a/vendor/github.com/tdewolff/buffer/streamlexer.go +++ /dev/null @@ -1,223 +0,0 @@ -package buffer // import "github.com/tdewolff/buffer" - -import ( - "io" -) - -type block struct { - buf []byte - next int // index in pool plus one - active bool -} - -type bufferPool struct { - pool []block - head int // index in pool plus one - tail int // index in pool plus one - - pos int // byte pos in tail -} - -func (z *bufferPool) swap(oldBuf []byte, size int) []byte { - // find new buffer that can be reused - swap := -1 - for i := 0; i < len(z.pool); i++ { - if !z.pool[i].active && size <= cap(z.pool[i].buf) { - swap = i - break - } - } - if swap == -1 { // no free buffer found for reuse - if z.tail == 0 && z.pos >= len(oldBuf) && size <= cap(oldBuf) { // but we can reuse the current buffer! - z.pos -= len(oldBuf) - return oldBuf[:0] - } - // allocate new - z.pool = append(z.pool, block{make([]byte, 0, size), 0, true}) - swap = len(z.pool) - 1 - } - - newBuf := z.pool[swap].buf - - // put current buffer into pool - z.pool[swap] = block{oldBuf, 0, true} - if z.head != 0 { - z.pool[z.head-1].next = swap + 1 - } - z.head = swap + 1 - if z.tail == 0 { - z.tail = swap + 1 - } - - return newBuf[:0] -} - -func (z *bufferPool) free(n int) { - z.pos += n - // move the tail over to next buffers - for z.tail != 0 && z.pos >= len(z.pool[z.tail-1].buf) { - z.pos -= len(z.pool[z.tail-1].buf) - newTail := z.pool[z.tail-1].next - z.pool[z.tail-1].active = false // after this, any thread may pick up the inactive buffer, so it can't be used anymore - z.tail = newTail - } - if z.tail == 0 { - z.head = 0 - } -} - -// StreamLexer is a buffered reader that allows peeking forward and shifting, taking an io.Reader. -// It keeps data in-memory until Free, taking a byte length, is called to move beyond the data. -type StreamLexer struct { - r io.Reader - err error - - pool bufferPool - - buf []byte - start int // index in buf - pos int // index in buf - prevStart int - - free int -} - -// NewStreamLexer returns a new StreamLexer for a given io.Reader with a 4kB estimated buffer size. -// If the io.Reader implements Bytes, that buffer is used instead. -func NewStreamLexer(r io.Reader) *StreamLexer { - return NewStreamLexerSize(r, defaultBufSize) -} - -// NewStreamLexerSize returns a new StreamLexer for a given io.Reader and estimated required buffer size. -// If the io.Reader implements Bytes, that buffer is used instead. -func NewStreamLexerSize(r io.Reader, size int) *StreamLexer { - // if reader has the bytes in memory already, use that instead - if buffer, ok := r.(interface { - Bytes() []byte - }); ok { - return &StreamLexer{ - err: io.EOF, - buf: buffer.Bytes(), - } - } - return &StreamLexer{ - r: r, - buf: make([]byte, 0, size), - } -} - -func (z *StreamLexer) read(pos int) byte { - if z.err != nil { - return 0 - } - - // free unused bytes - z.pool.free(z.free) - z.free = 0 - - // get new buffer - c := cap(z.buf) - p := pos - z.start + 1 - if 2*p > c { // if the token is larger than half the buffer, increase buffer size - c = 2*c + p - } - d := len(z.buf) - z.start - buf := z.pool.swap(z.buf[:z.start], c) - copy(buf[:d], z.buf[z.start:]) // copy the left-overs (unfinished token) from the old buffer - - // read in new data for the rest of the buffer - var n int - for pos-z.start >= d && z.err == nil { - n, z.err = z.r.Read(buf[d:cap(buf)]) - d += n - } - pos -= z.start - z.pos -= z.start - z.start, z.buf = 0, buf[:d] - if pos >= d { - return 0 - } - return z.buf[pos] -} - -// Err returns the error returned from io.Reader. It may still return valid bytes for a while though. -func (z *StreamLexer) Err() error { - if z.err == io.EOF && z.pos < len(z.buf) { - return nil - } - return z.err -} - -// Free frees up bytes of length n from previously shifted tokens. -// Each call to Shift should at one point be followed by a call to Free with a length returned by ShiftLen. -func (z *StreamLexer) Free(n int) { - z.free += n -} - -// Peek returns the ith byte relative to the end position and possibly does an allocation. -// Peek returns zero when an error has occurred, Err returns the error. -// TODO: inline function -func (z *StreamLexer) Peek(pos int) byte { - pos += z.pos - if uint(pos) < uint(len(z.buf)) { // uint for BCE - return z.buf[pos] - } - return z.read(pos) -} - -// PeekRune returns the rune and rune length of the ith byte relative to the end position. -func (z *StreamLexer) PeekRune(pos int) (rune, int) { - // from unicode/utf8 - c := z.Peek(pos) - if c < 0xC0 { - return rune(c), 1 - } else if c < 0xE0 { - return rune(c&0x1F)<<6 | rune(z.Peek(pos+1)&0x3F), 2 - } else if c < 0xF0 { - return rune(c&0x0F)<<12 | rune(z.Peek(pos+1)&0x3F)<<6 | rune(z.Peek(pos+2)&0x3F), 3 - } - return rune(c&0x07)<<18 | rune(z.Peek(pos+1)&0x3F)<<12 | rune(z.Peek(pos+2)&0x3F)<<6 | rune(z.Peek(pos+3)&0x3F), 4 -} - -// Move advances the position. -func (z *StreamLexer) Move(n int) { - z.pos += n -} - -// Pos returns a mark to which can be rewinded. -func (z *StreamLexer) Pos() int { - return z.pos - z.start -} - -// Rewind rewinds the position to the given position. -func (z *StreamLexer) Rewind(pos int) { - z.pos = z.start + pos -} - -// Lexeme returns the bytes of the current selection. -func (z *StreamLexer) Lexeme() []byte { - return z.buf[z.start:z.pos] -} - -// Skip collapses the position to the end of the selection. -func (z *StreamLexer) Skip() { - z.start = z.pos -} - -// Shift returns the bytes of the current selection and collapses the position to the end of the selection. -// It also returns the number of bytes we moved since the last call to Shift. This can be used in calls to Free. -func (z *StreamLexer) Shift() []byte { - if z.pos > len(z.buf) { // make sure we peeked at least as much as we shift - z.read(z.pos - 1) - } - b := z.buf[z.start:z.pos] - z.start = z.pos - return b -} - -// ShiftLen returns the number of bytes moved since the last call to ShiftLen. This can be used in calls to Free because it takes into account multiple Shifts or Skips. -func (z *StreamLexer) ShiftLen() int { - n := z.start - z.prevStart - z.prevStart = z.start - return n -} diff --git a/vendor/github.com/tdewolff/buffer/writer.go b/vendor/github.com/tdewolff/buffer/writer.go deleted file mode 100644 index 2cbde2528..000000000 --- a/vendor/github.com/tdewolff/buffer/writer.go +++ /dev/null @@ -1,41 +0,0 @@ -package buffer // import "github.com/tdewolff/buffer" - -// Writer implements an io.Writer over a byte slice. -type Writer struct { - buf []byte -} - -// NewWriter returns a new Writer for a given byte slice. -func NewWriter(buf []byte) *Writer { - return &Writer{ - buf: buf, - } -} - -// Write writes bytes from the given byte slice and returns the number of bytes written and an error if occurred. When err != nil, n == 0. -func (w *Writer) Write(b []byte) (int, error) { - n := len(b) - end := len(w.buf) - if end+n > cap(w.buf) { - buf := make([]byte, end, 2*cap(w.buf)+n) - copy(buf, w.buf) - w.buf = buf - } - w.buf = w.buf[:end+n] - return copy(w.buf[end:], b), nil -} - -// Len returns the length of the underlying byte slice. -func (w *Writer) Len() int { - return len(w.buf) -} - -// Bytes returns the underlying byte slice. -func (w *Writer) Bytes() []byte { - return w.buf -} - -// Reset empties and reuses the current buffer. Subsequent writes will overwrite the buffer, so any reference to the underlying slice is invalidated after this call. -func (w *Writer) Reset() { - w.buf = w.buf[:0] -} diff --git a/vendor/github.com/tdewolff/minify/.gitattributes b/vendor/github.com/tdewolff/minify/.gitattributes new file mode 100644 index 000000000..4c50ee14b --- /dev/null +++ b/vendor/github.com/tdewolff/minify/.gitattributes @@ -0,0 +1 @@ +benchmarks/sample_* linguist-generated=true diff --git a/vendor/github.com/tdewolff/minify/.gitignore b/vendor/github.com/tdewolff/minify/.gitignore new file mode 100644 index 000000000..3f3e864bf --- /dev/null +++ b/vendor/github.com/tdewolff/minify/.gitignore @@ -0,0 +1,4 @@ +dist/ +benchmarks/* +!benchmarks/*.go +!benchmarks/sample_* diff --git a/vendor/github.com/tdewolff/minify/.goreleaser.yml b/vendor/github.com/tdewolff/minify/.goreleaser.yml new file mode 100644 index 000000000..afaa1cb56 --- /dev/null +++ b/vendor/github.com/tdewolff/minify/.goreleaser.yml @@ -0,0 +1,28 @@ +builds: + - binary: minify + main: ./cmd/minify/ + ldflags: -s -w -X main.Version={{.Version}} -X main.Commit={{.Commit}} -X main.Date={{.Date}} + env: + - CGO_ENABLED=0 + goos: + - linux + - windows + - darwin + - freebsd + - netbsd + - openbsd + goarch: + - amd64 +archive: + format: tar.gz + format_overrides: + - goos: windows + format: zip + name_template: "{{.Binary}}_{{.Version}}_{{.Os}}_{{.Arch}}" + files: + - README.md + - LICENSE.md +snapshot: + name_template: "devel" +release: + draft: true diff --git a/vendor/github.com/tdewolff/minify/.travis.yml b/vendor/github.com/tdewolff/minify/.travis.yml index a9b09b1bb..4c14dfb2f 100644 --- a/vendor/github.com/tdewolff/minify/.travis.yml +++ b/vendor/github.com/tdewolff/minify/.travis.yml @@ -3,5 +3,3 @@ before_install: - go get github.com/mattn/goveralls script: - goveralls -v -service travis-ci -repotoken $COVERALLS_TOKEN -ignore=cmd/minify/* || go test -v ./... -addons: - srcclr: true diff --git a/vendor/github.com/tdewolff/minify/README.md b/vendor/github.com/tdewolff/minify/README.md index 98e9408d6..05cfaaa49 100644 --- a/vendor/github.com/tdewolff/minify/README.md +++ b/vendor/github.com/tdewolff/minify/README.md @@ -1,18 +1,14 @@ # Minify [![Build Status](https://travis-ci.org/tdewolff/minify.svg?branch=master)](https://travis-ci.org/tdewolff/minify) [![GoDoc](http://godoc.org/github.com/tdewolff/minify?status.svg)](http://godoc.org/github.com/tdewolff/minify) [![Coverage Status](https://coveralls.io/repos/github/tdewolff/minify/badge.svg?branch=master)](https://coveralls.io/github/tdewolff/minify?branch=master) [![Join the chat at https://gitter.im/tdewolff/minify](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/tdewolff/minify?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) -**The preferred stable release is v2. Master has some new changes for SVG that haven't yet endured the test of time, bug reports are appreciated.** - -**[Online demo](http://go.tacodewolff.nl/minify) if you need to minify files *now*.** +**[Online demo](https://go.tacodewolff.nl/minify) if you need to minify files *now*.** **[Command line tool](https://github.com/tdewolff/minify/tree/master/cmd/minify) that minifies concurrently and supports watching file changes.** -**[All releases](https://dl.equinox.io/tdewolff/minify/stable) on Equinox for various platforms.** - -If this software is useful to you, consider making a [donation](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=27MSRR5UJQQUL)! When a significant amount has been deposited, I will write a much improved JS minifier. +**[All releases](https://github.com/tdewolff/minify/releases) for various platforms.** --- -Minify is a minifier package written in [Go][1]. It provides HTML5, CSS3, JS, JSON, SVG and XML minifiers and an interface to implement any other minifier. Minification is the process of removing bytes from a file (such as whitespace) without changing its output and therefore shrinking its size and speeding up transmission over the internet and possibly parsing. The implemented minifiers are high performance and streaming, which implies O(n). +Minify is a minifier package written in [Go][1]. It provides HTML5, CSS3, JS, JSON, SVG and XML minifiers and an interface to implement any other minifier. Minification is the process of removing bytes from a file (such as whitespace) without changing its output and therefore shrinking its size and speeding up transmission over the internet and possibly parsing. The implemented minifiers are designed for high performance. The core functionality associates mimetypes with minification functions, allowing embedded resources (like CSS or JS within HTML files) to be minified as well. Users can add new implementations that are triggered based on a mimetype (or pattern), or redirect to an external command (like ClosureCompiler, UglifyCSS, ...). @@ -23,6 +19,7 @@ The core functionality associates mimetypes with minification functions, allowin - [Installation](#installation) - [API stability](#api-stability) - [Testing](#testing) + - [Performance](#performance) - [HTML](#html) - [Whitespace removal](#whitespace-removal) - [CSS](#css) @@ -47,24 +44,35 @@ The core functionality associates mimetypes with minification functions, allowin - [Templates](#templates) - [License](#license) -#### Status +### Status * CSS: **fully implemented** * HTML: **fully implemented** -* JS: basic JSmin-like implementation +* JS: improved JSmin implementation * JSON: **fully implemented** * SVG: partially implemented; in development * XML: **fully implemented** -## Prologue -Minifiers or bindings to minifiers exist in almost all programming languages. Some implementations are merely using several regular-expressions to trim whitespace and comments (even though regex for parsing HTML/XML is ill-advised, for a good read see [Regular Expressions: Now You Have Two Problems](http://blog.codinghorror.com/regular-expressions-now-you-have-two-problems/)). Some implementations are much more profound, such as the [YUI Compressor](http://yui.github.io/yuicompressor/) and [Google Closure Compiler](https://github.com/google/closure-compiler) for JS. As most existing implementations either use Java or JavaScript and don't focus on performance, they are pretty slow. And loading the whole file into memory is bad for really large files (or impossible for infinite streams). +### Roadmap -This minifier proves to be that fast and extensive minifier that can handle HTML and any other filetype it may contain (CSS, JS, ...). It streams the input and output and can minify files concurrently. +- [ ] General speed-up of all minifiers (use ASM for whitespace funcs) +- [ ] Improve JS minifiers by shortening variables and proper semicolon omission +- [ ] Speed-up SVG minifier, it is very slow +- [x] Proper parser error reporting and line number + column information +- [ ] Generation of source maps (uncertain, might slow down parsers too much if it cannot run separately nicely) +- [ ] Look into compression of images, fonts and other web resources (into package `compress`)? +- [ ] Create a cmd to pack webfiles (much like webpack), ie. merging CSS and JS files, inlining small external files, minification and gzipping. This would work on HTML files. +- [ ] Create a package to format files, much like `gofmt` for Go files? + +## Prologue +Minifiers or bindings to minifiers exist in almost all programming languages. Some implementations are merely using several regular-expressions to trim whitespace and comments (even though regex for parsing HTML/XML is ill-advised, for a good read see [Regular Expressions: Now You Have Two Problems](http://blog.codinghorror.com/regular-expressions-now-you-have-two-problems/)). Some implementations are much more profound, such as the [YUI Compressor](http://yui.github.io/yuicompressor/) and [Google Closure Compiler](https://github.com/google/closure-compiler) for JS. As most existing implementations either use JavaScript, use regexes, and don't focus on performance, they are pretty slow. + +This minifier proves to be that fast and extensive minifier that can handle HTML and any other filetype it may contain (CSS, JS, ...). It is usually orders of magnitude faster than existing minifiers. ## Installation Run the following command - go get github.com/tdewolff/minify + go get -u github.com/tdewolff/minify or add the following imports and run the project with `go get` ``` go @@ -82,37 +90,67 @@ import ( ## API stability There is no guarantee for absolute stability, but I take issues and bugs seriously and don't take API changes lightly. The library will be maintained in a compatible way unless vital bugs prevent me from doing so. There has been one API change after v1 which added options support and I took the opportunity to push through some more API clean up as well. There are no plans whatsoever for future API changes. -- minify-v1.0.0 depends on parse-v1.0.0 -- minify-v1.1.0 depends on parse-v1.1.0 -- minify-v2.0.0 depends on parse-v2.0.0 -- minify-v2.1.0 depends on parse-v2.1.0 -- minify-tip will always compile with my other packages on tip - -The API differences between v1 and v2 are listed below. If `m := minify.New()` and `w` and `r` are your writer and reader respectfully, then **v1** → **v2**: - - `minify.Bytes(m, ...)` → `m.Bytes(...)` - - `minify.String(m, ...)` → `m.String(...)` - - `html.Minify(m, "text/html", w, r)` → `html.Minify(m, w, r, nil)` also for `css`, `js`, ... - - `css.Minify(m, "text/css;inline=1", w, r)` → `css.Minify(m, w, r, map[string]string{"inline":"1"})` - ## Testing For all subpackages and the imported `parse` and `buffer` packages, test coverage of 100% is pursued. Besides full coverage, the minifiers are [fuzz tested](https://github.com/tdewolff/fuzz) using [github.com/dvyukov/go-fuzz](http://www.github.com/dvyukov/go-fuzz), see [the wiki](https://github.com/tdewolff/minify/wiki) for the most important bugs found by fuzz testing. Furthermore am I working on adding visual testing to ensure that minification doesn't change anything visually. By using the WebKit browser to render the original and minified pages we can check whether any pixel is different. These tests ensure that everything works as intended, the code does not crash (whatever the input) and that it doesn't change the final result visually. If you still encounter a bug, please report [here](https://github.com/tdewolff/minify/issues)! +## Performance +The benchmarks directory contains a number of standardized samples used to compare performance between changes. To give an indication of the speed of this library, I've ran the tests on my Thinkpad T460 (i5-6300U quad-core 2.4GHz running Arch Linux) using Go 1.9.2. + +``` +name time/op +CSS/sample_bootstrap.css-4 2.26ms ± 0% +CSS/sample_gumby.css-4 2.92ms ± 1% +HTML/sample_amazon.html-4 2.33ms ± 2% +HTML/sample_bbc.html-4 1.02ms ± 1% +HTML/sample_blogpost.html-4 171µs ± 2% +HTML/sample_es6.html-4 14.5ms ± 0% +HTML/sample_stackoverflow.html-4 2.41ms ± 1% +HTML/sample_wikipedia.html-4 4.76ms ± 0% +JS/sample_ace.js-4 7.41ms ± 0% +JS/sample_dot.js-4 63.7µs ± 0% +JS/sample_jquery.js-4 2.99ms ± 0% +JS/sample_jqueryui.js-4 5.92ms ± 2% +JS/sample_moment.js-4 1.09ms ± 1% +JSON/sample_large.json-4 2.95ms ± 0% +JSON/sample_testsuite.json-4 1.51ms ± 1% +JSON/sample_twitter.json-4 6.75µs ± 1% +SVG/sample_arctic.svg-4 62.3ms ± 1% +SVG/sample_gopher.svg-4 218µs ± 0% +SVG/sample_usa.svg-4 33.1ms ± 3% +XML/sample_books.xml-4 36.2µs ± 0% +XML/sample_catalog.xml-4 14.9µs ± 0% +XML/sample_omg.xml-4 6.31ms ± 1% + +name speed +CSS/sample_bootstrap.css-4 60.8MB/s ± 0% +CSS/sample_gumby.css-4 63.9MB/s ± 1% +HTML/sample_amazon.html-4 203MB/s ± 2% +HTML/sample_bbc.html-4 113MB/s ± 1% +HTML/sample_blogpost.html-4 123MB/s ± 2% +HTML/sample_es6.html-4 70.7MB/s ± 0% +HTML/sample_stackoverflow.html-4 85.2MB/s ± 1% +HTML/sample_wikipedia.html-4 93.6MB/s ± 0% +JS/sample_ace.js-4 86.9MB/s ± 0% +JS/sample_dot.js-4 81.0MB/s ± 0% +JS/sample_jquery.js-4 82.8MB/s ± 0% +JS/sample_jqueryui.js-4 79.3MB/s ± 2% +JS/sample_moment.js-4 91.2MB/s ± 1% +JSON/sample_large.json-4 258MB/s ± 0% +JSON/sample_testsuite.json-4 457MB/s ± 1% +JSON/sample_twitter.json-4 226MB/s ± 1% +SVG/sample_arctic.svg-4 23.6MB/s ± 1% +SVG/sample_gopher.svg-4 26.7MB/s ± 0% +SVG/sample_usa.svg-4 30.9MB/s ± 3% +XML/sample_books.xml-4 122MB/s ± 0% +XML/sample_catalog.xml-4 130MB/s ± 0% +XML/sample_omg.xml-4 180MB/s ± 1% +``` + ## HTML -HTML (with JS and CSS) minification typically runs at about 40MB/s ~= 140GB/h, depending on the composition of the file. - -Website | Original | Minified | Ratio | Time* -------- | -------- | -------- | ----- | ----------------------- -[Amazon](http://www.amazon.com/) | 463kB | **414kB** | 90% | 10ms -[BBC](http://www.bbc.com/) | 113kB | **96kB** | 85% | 3ms -[StackOverflow](http://stackoverflow.com/) | 201kB | **182kB** | 91% | 5ms -[Wikipedia](http://en.wikipedia.org/wiki/President_of_the_United_States) | 435kB | **410kB** | 94%** | 11ms - -*These times are measured on my home computer which is an average development computer. The duration varies a lot but it's important to see it's in the 10ms range! The benchmark uses all the minifiers and excludes reading from and writing to the file from the measurement. - -**Is already somewhat minified, so this doesn't reflect the full potential of this minifier. +HTML (with JS and CSS) minification typically shaves off about 10%. The HTML5 minifier uses these minifications: @@ -130,7 +168,7 @@ The HTML5 minifier uses these minifications: Options: - `KeepConditionalComments` preserve all IE conditional comments such as `` and ``, see https://msdn.microsoft.com/en-us/library/ms537512(v=vs.85).aspx#syntax -- `KeepDefaultAttrVals` preserve default attribute values such as `