Skip to content

Commit 0232e87

Browse files
committed
Merge branch 'master' of github.com:tdewolff/minify
2 parents cfd8940 + 98ad61c commit 0232e87

File tree

10 files changed

+54
-57
lines changed

10 files changed

+54
-57
lines changed

common.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010

1111
var (
1212
textMimeBytes = []byte("text/plain")
13-
charsetAsciiBytes = []byte("charset=us-ascii")
13+
charsetASCIIBytes = []byte("charset=us-ascii")
1414
dataBytes = []byte("data:")
1515
base64Bytes = []byte(";base64")
1616
)
@@ -77,7 +77,7 @@ func DataURI(m *M, dataURI []byte) []byte {
7777
}
7878
for i := 0; i+len(";charset=us-ascii") <= len(mediatype); i++ {
7979
// must start with semicolon and be followed by end of mediatype or semicolon
80-
if mediatype[i] == ';' && parse.EqualFold(mediatype[i+1:i+len(";charset=us-ascii")], charsetAsciiBytes) && (i+len(";charset=us-ascii") >= len(mediatype) || mediatype[i+len(";charset=us-ascii")] == ';') {
80+
if mediatype[i] == ';' && parse.EqualFold(mediatype[i+1:i+len(";charset=us-ascii")], charsetASCIIBytes) && (i+len(";charset=us-ascii") >= len(mediatype) || mediatype[i+len(";charset=us-ascii")] == ';') {
8181
mediatype = append(mediatype[:i], mediatype[i+len(";charset=us-ascii"):]...)
8282
break
8383
}

css/css.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,10 @@ func (t Token) String() string {
8383
}
8484

8585
// Equal returns true if both tokens are equal.
86-
func (a Token) Equal(b Token) bool {
87-
if a.TokenType == b.TokenType && bytes.Equal(a.Data, b.Data) && len(a.Args) == len(b.Args) {
88-
for i := 0; i < len(a.Args); i++ {
89-
if a.Args[i].TokenType != b.Args[i].TokenType || !bytes.Equal(a.Args[i].Data, b.Args[i].Data) {
86+
func (t Token) Equal(t2 Token) bool {
87+
if t.TokenType == t2.TokenType && bytes.Equal(t.Data, t2.Data) && len(t.Args) == len(t2.Args) {
88+
for i := 0; i < len(t.Args); i++ {
89+
if t.Args[i].TokenType != t2.Args[i].TokenType || !bytes.Equal(t.Args[i].Data, t2.Args[i].Data) {
9090
return false
9191
}
9292
}
@@ -885,7 +885,7 @@ func (c *cssMinifier) minifyProperty(prop Hash, values []Token) []Token {
885885
}
886886

887887
if end-start == 0 {
888-
values = append(values[:start], append([]Token{{css.NumberToken, zeroBytes, nil, 0, 0}, Token{css.NumberToken, zeroBytes, nil, 0, 0}}, values[end:]...)...)
888+
values = append(values[:start], append([]Token{{css.NumberToken, zeroBytes, nil, 0, 0}, {css.NumberToken, zeroBytes, nil, 0, 0}}, values[end:]...)...)
889889
end += 2
890890
}
891891
start = end + 1
@@ -1532,5 +1532,5 @@ func (c *cssMinifier) minifyDimension(value Token) (Token, []byte) {
15321532
// }
15331533
// value.Data = append(num, dim...)
15341534
//}
1535-
return value, dim
1535+
//return value, dim
15361536
}

css/table.go

+31-31
Original file line numberDiff line numberDiff line change
@@ -164,35 +164,35 @@ var ShortenColorName = map[Hash][]byte{
164164

165165
// PropertyOverrides is a map of which properties are overridden by the given property.
166166
var PropertyOverrides = map[Hash][]Hash{
167-
Background: []Hash{Background, Background_Image, Background_Position, Background_Size, Background_Repeat, Background_Origin, Background_Clip, Background_Attachment, Background_Color},
168-
Font: []Hash{Font, Font_Style, Font_Variant, Font_Weight, Font_Stretch, Font_Size, Font_Family, Line_Height},
169-
Border: []Hash{Border, Border_Width, Border_Top_Width, Border_Right_Width, Border_Bottom_Width, Border_Left_Width, Border_Style, Border_Top_Style, Border_Right_Style, Border_Bottom_Style, Border_Left_Style, Border_Color, Border_Top_Color, Border_Right_Color, Border_Bottom_Color, Border_Left_Color},
170-
Border_Width: []Hash{Border_Width, Border_Top_Width, Border_Right_Width, Border_Bottom_Width, Border_Left_Width},
171-
Border_Style: []Hash{Border_Style, Border_Top_Style, Border_Right_Style, Border_Bottom_Style, Border_Left_Style},
172-
Border_Color: []Hash{Border_Color, Border_Top_Color, Border_Right_Color, Border_Bottom_Color, Border_Left_Color},
173-
Border_Top: []Hash{Border_Top, Border_Top_Width, Border_Top_Style, Border_Top_Color},
174-
Border_Right: []Hash{Border_Right, Border_Right_Width, Border_Right_Style, Border_Right_Color},
175-
Border_Bottom: []Hash{Border_Bottom, Border_Bottom_Width, Border_Bottom_Style, Border_Bottom_Color},
176-
Border_Left: []Hash{Border_Left, Border_Left_Width, Border_Left_Style, Border_Left_Color},
177-
Margin: []Hash{Margin, Margin_Top, Margin_Right, Margin_Bottom, Margin_Left},
178-
Padding: []Hash{Padding, Padding_Top, Padding_Right, Padding_Bottom, Padding_Left},
179-
Column_Rule: []Hash{Column_Rule, Column_Rule_Width, Column_Rule_Style, Column_Rule_Color},
180-
Animation: []Hash{Animation, Animation_Name, Animation_Duration, Animation_Timing_Function, Animation_Delay, Animation_Iteration_Count, Animation_Direction, Animation_Fill_Mode, Animation_Play_State},
181-
Columns: []Hash{Columns, Column_Width, Column_Count},
182-
Flex: []Hash{Flex, Flex_Basis, Flex_Grow, Flex_Shrink},
183-
Flex_Flow: []Hash{Flex_Flow, Flex_Direction, Flex_Wrap},
184-
Grid: []Hash{Grid, Grid_Template_Rows, Grid_Template_Columns, Grid_Template_Areas, Grid_Auto_Rows, Grid_Auto_Columns, Grid_Auto_Flow, Grid_Column_Gap, Grid_Row_Gap, Column_Gap, Row_Gap},
185-
Grid_Area: []Hash{Grid_Area, Grid_Row_Start, Grid_Column_Start, Grid_Row_End, Grid_Column_End},
186-
Grid_Row: []Hash{Grid_Row, Grid_Row_Start, Grid_Row_End},
187-
Grid_Column: []Hash{Grid_Column, Grid_Column_Start, Grid_Column_End},
188-
Grid_Template: []Hash{Grid_Template, Grid_Template_Rows, Grid_Template_Columns, Grid_Template_Areas},
189-
List_Style: []Hash{List_Style, List_Style_Image, List_Style_Position, List_Style_Type},
190-
Offset: []Hash{Offset, Offset_Position, Offset_Path, Offset_Distance, Offset_Anchor, Offset_Rotate},
191-
Outline: []Hash{Outline, Outline_Width, Outline_Style, Outline_Color},
192-
Overflow: []Hash{Overflow, Overflow_X, Overflow_Y},
193-
Place_Content: []Hash{Place_Content, Align_Content, Justify_Content},
194-
Place_Items: []Hash{Place_Items, Align_Items, Justify_Items},
195-
Place_Self: []Hash{Place_Self, Align_Self, Justify_Self},
196-
Text_Decoration: []Hash{Text_Decoration, Text_Decoration_Color, Text_Decoration_Color, Text_Decoration_Line, Text_Decoration_Thickness},
197-
Transition: []Hash{Transition, Transition_Property, Transition_Duration, Transition_Timing_Function, Transition_Delay},
167+
Background: {Background, Background_Image, Background_Position, Background_Size, Background_Repeat, Background_Origin, Background_Clip, Background_Attachment, Background_Color},
168+
Font: {Font, Font_Style, Font_Variant, Font_Weight, Font_Stretch, Font_Size, Font_Family, Line_Height},
169+
Border: {Border, Border_Width, Border_Top_Width, Border_Right_Width, Border_Bottom_Width, Border_Left_Width, Border_Style, Border_Top_Style, Border_Right_Style, Border_Bottom_Style, Border_Left_Style, Border_Color, Border_Top_Color, Border_Right_Color, Border_Bottom_Color, Border_Left_Color},
170+
Border_Width: {Border_Width, Border_Top_Width, Border_Right_Width, Border_Bottom_Width, Border_Left_Width},
171+
Border_Style: {Border_Style, Border_Top_Style, Border_Right_Style, Border_Bottom_Style, Border_Left_Style},
172+
Border_Color: {Border_Color, Border_Top_Color, Border_Right_Color, Border_Bottom_Color, Border_Left_Color},
173+
Border_Top: {Border_Top, Border_Top_Width, Border_Top_Style, Border_Top_Color},
174+
Border_Right: {Border_Right, Border_Right_Width, Border_Right_Style, Border_Right_Color},
175+
Border_Bottom: {Border_Bottom, Border_Bottom_Width, Border_Bottom_Style, Border_Bottom_Color},
176+
Border_Left: {Border_Left, Border_Left_Width, Border_Left_Style, Border_Left_Color},
177+
Margin: {Margin, Margin_Top, Margin_Right, Margin_Bottom, Margin_Left},
178+
Padding: {Padding, Padding_Top, Padding_Right, Padding_Bottom, Padding_Left},
179+
Column_Rule: {Column_Rule, Column_Rule_Width, Column_Rule_Style, Column_Rule_Color},
180+
Animation: {Animation, Animation_Name, Animation_Duration, Animation_Timing_Function, Animation_Delay, Animation_Iteration_Count, Animation_Direction, Animation_Fill_Mode, Animation_Play_State},
181+
Columns: {Columns, Column_Width, Column_Count},
182+
Flex: {Flex, Flex_Basis, Flex_Grow, Flex_Shrink},
183+
Flex_Flow: {Flex_Flow, Flex_Direction, Flex_Wrap},
184+
Grid: {Grid, Grid_Template_Rows, Grid_Template_Columns, Grid_Template_Areas, Grid_Auto_Rows, Grid_Auto_Columns, Grid_Auto_Flow, Grid_Column_Gap, Grid_Row_Gap, Column_Gap, Row_Gap},
185+
Grid_Area: {Grid_Area, Grid_Row_Start, Grid_Column_Start, Grid_Row_End, Grid_Column_End},
186+
Grid_Row: {Grid_Row, Grid_Row_Start, Grid_Row_End},
187+
Grid_Column: {Grid_Column, Grid_Column_Start, Grid_Column_End},
188+
Grid_Template: {Grid_Template, Grid_Template_Rows, Grid_Template_Columns, Grid_Template_Areas},
189+
List_Style: {List_Style, List_Style_Image, List_Style_Position, List_Style_Type},
190+
Offset: {Offset, Offset_Position, Offset_Path, Offset_Distance, Offset_Anchor, Offset_Rotate},
191+
Outline: {Outline, Outline_Width, Outline_Style, Outline_Color},
192+
Overflow: {Overflow, Overflow_X, Overflow_Y},
193+
Place_Content: {Place_Content, Align_Content, Justify_Content},
194+
Place_Items: {Place_Items, Align_Items, Justify_Items},
195+
Place_Self: {Place_Self, Align_Self, Justify_Self},
196+
Text_Decoration: {Text_Decoration, Text_Decoration_Color, Text_Decoration_Color, Text_Decoration_Line, Text_Decoration_Thickness},
197+
Transition: {Transition, Transition_Property, Transition_Duration, Transition_Timing_Function, Transition_Delay},
198198
}

js/util.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -602,12 +602,12 @@ func minifyString(b []byte) []byte {
602602
}
603603
} else if '0' <= c && c <= '7' {
604604
// octal escapes (legacy), \0 already handled
605-
num := byte(c - '0')
605+
num := c - '0'
606606
if i+2 < len(b)-1 && '0' <= b[i+2] && b[i+2] <= '7' {
607-
num = num*8 + byte(b[i+2]-'0')
607+
num = num*8 + b[i+2] - '0'
608608
n++
609609
if num < 32 && i+3 < len(b)-1 && '0' <= b[i+3] && b[i+3] <= '7' {
610-
num = num*8 + byte(b[i+3]-'0')
610+
num = num*8 + b[i+3] - '0'
611611
n++
612612
}
613613
}

parse/buffer/buffer.go

+4-7
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
1-
/*
2-
Package buffer contains buffer and wrapper types for byte slices. It is useful for writing lexers or other high-performance byte slice handling.
3-
4-
The `Reader` and `Writer` types implement the `io.Reader` and `io.Writer` respectively and provide a thinner and faster interface than `bytes.Buffer`.
5-
The `Lexer` 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.
6-
The `StreamLexer` does the same, but keeps a buffer pool so that it reads a limited amount at a time, allowing to parse from streaming sources.
7-
*/
1+
// Package buffer contains buffer and wrapper types for byte slices. It is useful for writing lexers or other high-performance byte slice handling.
2+
// The `Reader` and `Writer` types implement the `io.Reader` and `io.Writer` respectively and provide a thinner and faster interface than `bytes.Buffer`.
3+
// The `Lexer` 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.
4+
// The `StreamLexer` does the same, but keeps a buffer pool so that it reads a limited amount at a time, allowing to parse from streaming sources.
85
package buffer
96

107
// defaultBufSize specifies the default initial length of internal buffers.

parse/html/lex.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ func (l *Lexer) shiftStartTag() (TokenType, []byte) {
326326
l.text = parse.ToLower(l.r.Lexeme()[1:])
327327
if h := ToHash(l.text); h == Textarea || h == Title || h == Style || h == Xmp || h == Iframe || h == Script || h == Plaintext || h == Svg || h == Math {
328328
if h == Svg || h == Math {
329-
data := l.shiftXml(h)
329+
data := l.shiftXML(h)
330330
if l.err != nil {
331331
return ErrorToken, nil
332332
}
@@ -425,9 +425,9 @@ func (l *Lexer) shiftEndTag() []byte {
425425
return parse.ToLower(l.r.Shift())
426426
}
427427

428-
// shiftXml parses the content of a svg or math tag according to the XML 1.1 specifications, including the tag itself.
428+
// shiftXML parses the content of a svg or math tag according to the XML 1.1 specifications, including the tag itself.
429429
// So far we have already parsed `<svg` or `<math`.
430-
func (l *Lexer) shiftXml(rawTag Hash) []byte {
430+
func (l *Lexer) shiftXML(rawTag Hash) []byte {
431431
inQuote := false
432432
for {
433433
c := l.r.Peek(0)

parse/html/util_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ func TestEscapeAttrVal(t *testing.T) {
3333
if len(b) > 1 && (b[0] == '"' || b[0] == '\'') && b[0] == b[len(b)-1] {
3434
b = b[1 : len(b)-1]
3535
}
36-
val := EscapeAttrVal(&buf, orig, []byte(b), false)
36+
val := EscapeAttrVal(&buf, orig, b, false)
3737
test.String(t, string(val), tt.expected)
3838
})
3939
}
@@ -55,7 +55,7 @@ func TestEscapeAttrValXML(t *testing.T) {
5555
if len(b) > 1 && (b[0] == '"' || b[0] == '\'') && b[0] == b[len(b)-1] {
5656
b = b[1 : len(b)-1]
5757
}
58-
val := EscapeAttrVal(&buf, orig, []byte(b), true)
58+
val := EscapeAttrVal(&buf, orig, b, true)
5959
test.String(t, string(val), tt.expected)
6060
})
6161
}

parse/xml/util_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ func TestEscapeAttrVal(t *testing.T) {
2727
if len(b) > 1 && (b[0] == '"' || b[0] == '\'') && b[0] == b[len(b)-1] {
2828
b = b[1 : len(b)-1]
2929
}
30-
val := EscapeAttrVal(&buf, []byte(b))
30+
val := EscapeAttrVal(&buf, b)
3131
test.String(t, string(val), tt.expected)
3232
})
3333
}

svg/buffer.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
package svg
22

33
import (
4-
minifyXML "github.com/tdewolff/minify/v2/xml"
54
"github.com/tdewolff/minify/v2/parse"
65
"github.com/tdewolff/minify/v2/parse/xml"
6+
minifyXML "github.com/tdewolff/minify/v2/xml"
77
)
88

99
// Token is a single token unit with an attribute value (if given) and hash of the data.

svg/svg.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ import (
77

88
"github.com/tdewolff/minify/v2"
99
"github.com/tdewolff/minify/v2/css"
10-
minifyXML "github.com/tdewolff/minify/v2/xml"
1110
"github.com/tdewolff/minify/v2/parse"
1211
"github.com/tdewolff/minify/v2/parse/buffer"
1312
"github.com/tdewolff/minify/v2/parse/xml"
13+
minifyXML "github.com/tdewolff/minify/v2/xml"
1414
)
1515

1616
var (

0 commit comments

Comments
 (0)