Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion src/parse-atrule-prelude.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -812,6 +812,7 @@ describe('At-Rule Prelude Nodes', () => {
expect(children.length).toBe(2)
expect(children[0].type).toBe(URL)
expect(children[1].type).toBe(MEDIA_QUERY)
expect(children[1].text).toBe('(min-width: 768px)')
})

it('should parse with combined media query', () => {
Expand All @@ -834,6 +835,9 @@ describe('At-Rule Prelude Nodes', () => {
expect(children.length).toBe(3)
expect(children[0].type).toBe(URL)
expect(children[1].type).toBe(LAYER_NAME)
expect(children[1].text).toBe('layer(base)')
expect(children[1].value).toBe('base')
expect(children[1].name).toBe('base')
expect(children[2].type).toBe(MEDIA_QUERY)
})

Expand All @@ -845,8 +849,13 @@ describe('At-Rule Prelude Nodes', () => {

expect(children.length).toBe(3)
expect(children[0].type).toBe(URL)
expect(children[0].value).toBe('"styles.css"')
expect(children[1].type).toBe(LAYER_NAME)
expect(children[1].value).toBe('base')
expect(children[1].name).toBe('base')
expect(children[2].type).toBe(SUPPORTS_QUERY)
expect(children[2].value).toBe('display: grid')
expect(children[2].text).toBe('supports(display: grid)')
})

it('should parse with supports and media query', () => {
Expand Down Expand Up @@ -883,7 +892,8 @@ describe('At-Rule Prelude Nodes', () => {
expect(children.length).toBe(2)
expect(children[0].type).toBe(URL)
expect(children[1].type).toBe(SUPPORTS_QUERY)
expect(children[1].text).toContain('supports(')
expect(children[1].text).toBe('supports((display: grid) and (gap: 1rem))')
expect(children[1].value).toBe('(display: grid) and (gap: 1rem)')
})

it('should preserve prelude text', () => {
Expand Down
13 changes: 13 additions & 0 deletions src/parse-atrule-prelude.ts
Original file line number Diff line number Diff line change
Expand Up @@ -504,8 +504,11 @@ export class AtRulePreludeParser {
if (content_length > 0) {
let trimmed = trim_boundaries(this.source, content_start, content_start + content_length)
if (trimmed) {
// Set both content fields (for .name) and value fields (for .value)
this.arena.set_content_start_delta(layer_node, trimmed[0] - layer_start)
this.arena.set_content_length(layer_node, trimmed[1] - trimmed[0])
this.arena.set_value_start_delta(layer_node, trimmed[0] - layer_start)
this.arena.set_value_length(layer_node, trimmed[1] - trimmed[0])
}
}

Expand All @@ -530,10 +533,12 @@ export class AtRulePreludeParser {
let text = this.source.substring(this.lexer.token_start, this.lexer.token_end - 1) // -1 to exclude '('
if (str_equals('supports', text)) {
let supports_start = this.lexer.token_start
let content_start = this.lexer.token_end // After the opening '('

// Find matching closing parenthesis
let paren_depth = 1
let supports_end = this.lexer.token_end
let content_end = content_start

while (this.lexer.pos < this.prelude_end && paren_depth > 0) {
let tokenType = this.next_token()
Expand All @@ -542,6 +547,7 @@ export class AtRulePreludeParser {
} else if (tokenType === TOKEN_RIGHT_PAREN) {
paren_depth--
if (paren_depth === 0) {
content_end = this.lexer.token_start // Before the closing ')'
supports_end = this.lexer.token_end
}
} else if (tokenType === TOKEN_EOF) {
Expand All @@ -552,6 +558,13 @@ export class AtRulePreludeParser {
// Create supports node
let supports_node = this.create_node(SUPPORTS_QUERY, supports_start, supports_end)

// Store query content in value fields, trimmed
let trimmed = trim_boundaries(this.source, content_start, content_end)
if (trimmed) {
this.arena.set_value_start_delta(supports_node, trimmed[0] - supports_start)
this.arena.set_value_length(supports_node, trimmed[1] - trimmed[0])
}

return supports_node
}
}
Expand Down