diff --git a/src/parse-atrule-prelude.test.ts b/src/parse-atrule-prelude.test.ts index ef16187..e75332a 100644 --- a/src/parse-atrule-prelude.test.ts +++ b/src/parse-atrule-prelude.test.ts @@ -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', () => { @@ -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) }) @@ -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', () => { @@ -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', () => { diff --git a/src/parse-atrule-prelude.ts b/src/parse-atrule-prelude.ts index 5721a9b..51696b8 100644 --- a/src/parse-atrule-prelude.ts +++ b/src/parse-atrule-prelude.ts @@ -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]) } } @@ -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() @@ -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) { @@ -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 } }