Skip to content

Commit 0546cf7

Browse files
committed
css combinator can be a single byte
1 parent 39c3962 commit 0546cf7

File tree

4 files changed

+14
-14
lines changed

4 files changed

+14
-14
lines changed

internal/css_ast/css_ast.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,7 @@ func (r *RSelector) Hash() (uint32, bool) {
468468
for _, sub := range sel.SubclassSelectors {
469469
hash = helpers.HashCombine(hash, sub.Hash())
470470
}
471-
hash = helpers.HashCombineString(hash, sel.Combinator)
471+
hash = helpers.HashCombine(hash, uint32(sel.Combinator))
472472
}
473473
}
474474
hash = HashRules(hash, r.Rules)
@@ -629,10 +629,10 @@ func (a ComplexSelector) Equal(b ComplexSelector, check *CrossFileEqualityCheck)
629629
}
630630

631631
type CompoundSelector struct {
632-
Combinator string // Optional, may be ""
633632
TypeSelector *NamespacedName
634633
SubclassSelectors []SS
635-
HasNestingSelector bool // "&"
634+
Combinator uint8 // Optional, may be 0
635+
HasNestingSelector bool // "&"
636636
}
637637

638638
type NameToken struct {

internal/css_parser/css_parser.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -611,7 +611,7 @@ func isSafeSelectors(complexSelectors []css_ast.ComplexSelector) bool {
611611
return false
612612
}
613613

614-
if compound.Combinator != "" {
614+
if compound.Combinator != 0 {
615615
// "Before Internet Explorer 10, the combinator only works in standards mode"
616616
// Reference: https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Selectors
617617
return false

internal/css_parser/css_parser_selector.go

+7-7
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ func (p *parser) parseComplexSelector(opts parseSelectorOpts) (result css_ast.Co
5151
// This is an extension: https://drafts.csswg.org/css-nesting-1/
5252
r := p.current().Range
5353
combinator := p.parseCombinator()
54-
if combinator != "" {
54+
if combinator != 0 {
5555
if opts.isTopLevel {
5656
p.maybeWarnAboutNesting(r)
5757
}
@@ -74,7 +74,7 @@ func (p *parser) parseComplexSelector(opts parseSelectorOpts) (result css_ast.Co
7474

7575
// Optional combinator
7676
combinator := p.parseCombinator()
77-
if combinator != "" {
77+
if combinator != 0 {
7878
p.eat(css_lexer.TWhitespace)
7979
}
8080

@@ -366,21 +366,21 @@ loop:
366366
return tokens
367367
}
368368

369-
func (p *parser) parseCombinator() string {
369+
func (p *parser) parseCombinator() uint8 {
370370
switch p.current().Kind {
371371
case css_lexer.TDelimGreaterThan:
372372
p.advance()
373-
return ">"
373+
return '>'
374374

375375
case css_lexer.TDelimPlus:
376376
p.advance()
377-
return "+"
377+
return '+'
378378

379379
case css_lexer.TDelimTilde:
380380
p.advance()
381-
return "~"
381+
return '~'
382382

383383
default:
384-
return ""
384+
return 0
385385
}
386386
}

internal/css_printer/css_printer.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -351,18 +351,18 @@ func (p *printer) printComplexSelectors(selectors []css_ast.ComplexSelector, ind
351351
}
352352

353353
func (p *printer) printCompoundSelector(sel css_ast.CompoundSelector, isFirst bool, isLast bool) {
354-
if !isFirst && sel.Combinator == "" {
354+
if !isFirst && sel.Combinator == 0 {
355355
// A space is required in between compound selectors if there is no
356356
// combinator in the middle. It's fine to convert "a + b" into "a+b"
357357
// but not to convert "a b" into "ab".
358358
p.print(" ")
359359
}
360360

361-
if sel.Combinator != "" {
361+
if sel.Combinator != 0 {
362362
if !isFirst && !p.options.MinifyWhitespace {
363363
p.print(" ")
364364
}
365-
p.print(sel.Combinator)
365+
p.css = append(p.css, sel.Combinator)
366366
if !p.options.MinifyWhitespace {
367367
p.print(" ")
368368
}

0 commit comments

Comments
 (0)