Skip to content

Commit

Permalink
add container query lengths (#366)
Browse files Browse the repository at this point in the history
  • Loading branch information
aeschli authored Oct 5, 2023
1 parent 4d74676 commit 0f2dfc4
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/parser/cssParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1873,6 +1873,7 @@ export class Parser {
this.peek(TokenType.Angle) ||
this.peek(TokenType.Time) ||
this.peek(TokenType.Dimension) ||
this.peek(TokenType.ContainerQueryLength) ||
this.peek(TokenType.Freq)) {
const node = this.create(nodes.NumericValue);
this.consumeToken();
Expand Down
9 changes: 8 additions & 1 deletion src/parser/cssScanner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ export enum TokenType {
Comment,
SingleLineComment,
EOF,
CustomToken
CustomToken,
ContainerQueryLength
}

export interface IToken {
Expand Down Expand Up @@ -212,6 +213,12 @@ staticUnitTable['%'] = TokenType.Percentage;
staticUnitTable['fr'] = TokenType.Percentage;
staticUnitTable['dpi'] = TokenType.Resolution;
staticUnitTable['dpcm'] = TokenType.Resolution;
staticUnitTable['cqw'] = TokenType.ContainerQueryLength;
staticUnitTable['cqh'] = TokenType.ContainerQueryLength;
staticUnitTable['cqi'] = TokenType.ContainerQueryLength;
staticUnitTable['cqb'] = TokenType.ContainerQueryLength;
staticUnitTable['cqmin'] = TokenType.ContainerQueryLength;
staticUnitTable['cqmax'] = TokenType.ContainerQueryLength;

export class Scanner {

Expand Down
5 changes: 5 additions & 0 deletions src/test/css/parser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,11 @@ suite('CSS - Parser', () => {
assertNode(`@container card (inline-size > 30em) { @container style(--responsive: true) {} }`, parser, parser._parseStylesheet.bind(parser));
});

test('@container query length units', function () {
const parser = new Parser();
assertNode(`@container (min-width: 700px) { .card h2 { font-size: max(1.5em, 1.23em + 2cqi); } }`, parser, parser._parseStylesheet.bind(parser));
});

test('@import', function () {
const parser = new Parser();
assertNode('@import "asdasdsa"', parser, parser._parseImport.bind(parser));
Expand Down

0 comments on commit 0f2dfc4

Please sign in to comment.