File: css_decls_container.go

package info (click to toggle)
golang-github-evanw-esbuild 0.25.10-1
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 10,184 kB
  • sloc: javascript: 28,602; makefile: 856; sh: 17
file content (53 lines) | stat: -rw-r--r-- 1,207 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package css_parser

import (
	"strings"

	"github.com/evanw/esbuild/internal/css_ast"
	"github.com/evanw/esbuild/internal/css_lexer"
)

// Scan for container names in the "container" shorthand property
func (p *parser) processContainerShorthand(tokens []css_ast.Token) {
	// Validate the syntax
	for i, t := range tokens {
		if t.Kind == css_lexer.TIdent {
			continue
		}
		if t.Kind == css_lexer.TDelimSlash && i+2 == len(tokens) && tokens[i+1].Kind == css_lexer.TIdent {
			break
		}
		return
	}

	// Convert any local names
	for i, t := range tokens {
		if t.Kind != css_lexer.TIdent {
			break
		}
		p.handleSingleContainerName(&tokens[i])
	}
}

func (p *parser) processContainerName(tokens []css_ast.Token) {
	// Validate the syntax
	for _, t := range tokens {
		if t.Kind != css_lexer.TIdent {
			return
		}
	}

	// Convert any local names
	for i := range tokens {
		p.handleSingleContainerName(&tokens[i])
	}
}

func (p *parser) handleSingleContainerName(token *css_ast.Token) {
	if lower := strings.ToLower(token.Text); lower == "none" || cssWideAndReservedKeywords[lower] {
		return
	}

	token.Kind = css_lexer.TSymbol
	token.PayloadIndex = p.symbolForName(token.Loc, token.Text).Ref.InnerIndex
}