Skip to content

Commit be7b6b1

Browse files
committed
Merge branch 'master' of github.com:tdewolff/parse
2 parents 4ee1f02 + 570159f commit be7b6b1

File tree

3 files changed

+29
-14
lines changed

3 files changed

+29
-14
lines changed

css/hash.go

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,28 +8,33 @@ package css
88
// Hash defines perfect hashes for a predefined list of strings
99
type Hash uint32
1010

11-
// Unique hash definitions to be used instead of strings
11+
// Identifiers for the hashes associated with the text in the comments.
1212
const (
1313
Document Hash = 0x8 // document
1414
Font_Face Hash = 0x809 // font-face
1515
Keyframes Hash = 0x1109 // keyframes
16-
Media Hash = 0x2105 // media
17-
Page Hash = 0x2604 // page
16+
Layer Hash = 0x2105 // layer
17+
Media Hash = 0x2605 // media
18+
Page Hash = 0x2b04 // page
1819
Supports Hash = 0x1908 // supports
1920
)
2021

21-
// String returns the hash' name.
22+
// String returns the text associated with the hash.
2223
func (i Hash) String() string {
24+
return string(i.Bytes())
25+
}
26+
27+
// Bytes returns the text associated with the hash.
28+
func (i Hash) Bytes() []byte {
2329
start := uint32(i >> 8)
2430
n := uint32(i & 0xff)
2531
if start+n > uint32(len(_Hash_text)) {
26-
return ""
32+
return []byte{}
2733
}
2834
return _Hash_text[start : start+n]
2935
}
3036

31-
// ToHash returns the hash whose name is s. It returns zero if there is no
32-
// such hash. It is case sensitive.
37+
// ToHash returns a hash Hash for a given []byte. Hash is a uint32 that is associated with the text in []byte. It returns zero if no match found.
3338
func ToHash(s []byte) Hash {
3439
if len(s) == 0 || len(s) > _Hash_maxLen {
3540
return 0
@@ -61,15 +66,18 @@ NEXT:
6166
return 0
6267
}
6368

64-
const _Hash_hash0 = 0x9acb0442
69+
const _Hash_hash0 = 0x5aebcbca
6570
const _Hash_maxLen = 9
66-
const _Hash_text = "documentfont-facekeyframesupportsmediapage"
71+
72+
var _Hash_text = []byte("" +
73+
"documentfont-facekeyframesupportslayermediapage")
6774

6875
var _Hash_table = [1 << 3]Hash{
69-
0x1: 0x2604, // page
70-
0x2: 0x2105, // media
76+
0x0: 0x1109, // keyframes
77+
0x1: 0x2b04, // page
78+
0x2: 0x2605, // media
7179
0x3: 0x809, // font-face
72-
0x5: 0x1109, // keyframes
80+
0x4: 0x8, // document
7381
0x6: 0x1908, // supports
74-
0x7: 0x8, // document
82+
0x7: 0x2105, // layer
7583
}

css/parse.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ func (p *Parser) parseAtRule() GrammarType {
248248
if tt == LeftBraceToken && p.level == 0 {
249249
if atRule == Font_Face || atRule == Page {
250250
p.state = append(p.state, (*Parser).parseAtRuleDeclarationList)
251-
} else if atRule == Document || atRule == Keyframes || atRule == Media || atRule == Supports {
251+
} else if atRule == Document || atRule == Keyframes || atRule == Layer || atRule == Media || atRule == Supports {
252252
p.state = append(p.state, (*Parser).parseAtRuleRuleList)
253253
} else {
254254
p.state = append(p.state, (*Parser).parseAtRuleUnknown)

css/parse_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,13 @@ func TestParse(t *testing.T) {
3535
{true, "color: calc(100%/2 - 1em);", "color:calc(100%/2 - 1em);"},
3636
{true, "color: calc(100%/2--1em);", "color:calc(100%/2--1em);"},
3737
{false, "<!-- @charset; -->", "<!--@charset;-->"},
38+
{false, "@layer base, typography, layout ;", "@layer base,typography,layout;"},
39+
{false, "@layer base { }", "@layer base{}"},
40+
{false, "@layer typography { :root { font-size: 1.618rem } }", "@layer typography{:root{font-size:1.618rem;}}"},
41+
{false, "@layer { }", "@layer{}"},
42+
{false, "@layer { @layer base { } }", "@layer{@layer base{}}"},
43+
{false, "@layer { .foo { color: #fff } @layer base { } }", "@layer{.foo{color:#fff;}@layer base{}}"},
44+
{false, "@layer { @layer base, typography ; .foo { color: #fff } @layer base { } }", "@layer{@layer base,typography;.foo{color:#fff;}@layer base{}}"},
3845
{false, "@media print, screen { }", "@media print,screen{}"},
3946
{false, "@media { @viewport ; }", "@media{@viewport;}"},
4047
{false, "@keyframes 'diagonal-slide' { from { left: 0; top: 0; } to { left: 100px; top: 100px; } }", "@keyframes 'diagonal-slide'{from{left:0;top:0;}to{left:100px;top:100px;}}"},

0 commit comments

Comments
 (0)