Skip to content

Commit

Permalink
Add support for list literals (#2515)
Browse files Browse the repository at this point in the history
Co-authored-by: Carlos (Goodwine) <[email protected]>
  • Loading branch information
nex3 and Goodwine authored Feb 19, 2025
1 parent f32ec4f commit 1b58aa9
Show file tree
Hide file tree
Showing 14 changed files with 1,978 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 1.85.1-dev

* No user-visible changes.

## 1.85.0

* No longer fully trim redundant selectors generated by `@extend`. This caused
Expand Down
4 changes: 4 additions & 0 deletions pkg/sass-parser/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.4.15-dev

* Add support for parsing list expressions.

## 0.4.14

* Add support for parsing color expressions.
Expand Down
7 changes: 7 additions & 0 deletions pkg/sass-parser/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,13 @@ export {
ColorExpressionProps,
ColorExpressionRaws,
} from './src/expression/color';
export {
ListExpression,
ListExpressionProps,
ListExpressionRaws,
ListSeparator,
NewNodeForListExpression,
} from './src/expression/list';
export {
NumberExpression,
NumberExpressionProps,
Expand Down
22 changes: 22 additions & 0 deletions pkg/sass-parser/lib/src/expression/__snapshots__/list.test.ts.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`a list expression toJSON 1`] = `
{
"brackets": true,
"inputs": [
{
"css": "@#{[foo, bar]}",
"hasBOM": false,
"id": "<input css _____>",
},
],
"nodes": [
<foo>,
<bar>,
],
"raws": {},
"sassType": "list",
"separator": ",",
"source": <1:4-1:14 in 0>,
}
`;
2 changes: 2 additions & 0 deletions pkg/sass-parser/lib/src/expression/convert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {Expression} from '.';
import {BinaryOperationExpression} from './binary-operation';
import {BooleanExpression} from './boolean';
import {ColorExpression} from './color';
import {ListExpression} from './list';
import {NumberExpression} from './number';
import {StringExpression} from './string';

Expand All @@ -18,6 +19,7 @@ const visitor = sassInternal.createExpressionVisitor<Expression>({
visitStringExpression: inner => new StringExpression(undefined, inner),
visitBooleanExpression: inner => new BooleanExpression(undefined, inner),
visitColorExpression: inner => new ColorExpression(undefined, inner),
visitListExpression: inner => new ListExpression(undefined, inner),
visitNumberExpression: inner => new NumberExpression(undefined, inner),
});

Expand Down
2 changes: 2 additions & 0 deletions pkg/sass-parser/lib/src/expression/from-props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ import {Expression, ExpressionProps} from '.';
import {BinaryOperationExpression} from './binary-operation';
import {BooleanExpression} from './boolean';
import {ColorExpression} from './color';
import {ListExpression} from './list';
import {NumberExpression} from './number';
import {StringExpression} from './string';

/** Constructs an expression from {@link ExpressionProps}. */
export function fromProps(props: ExpressionProps): Expression {
if ('text' in props) return new StringExpression(props);
if ('left' in props) return new BinaryOperationExpression(props);
if ('separator' in props) return new ListExpression(props);
if ('value' in props) {
if (typeof props.value === 'boolean') return new BooleanExpression(props);
if (typeof props.value === 'number') return new NumberExpression(props);
Expand Down
4 changes: 4 additions & 0 deletions pkg/sass-parser/lib/src/expression/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import type {
} from './binary-operation';
import {BooleanExpression, BooleanExpressionProps} from './boolean';
import {ColorExpression, ColorExpressionProps} from './color';
import {ListExpression, ListExpressionProps} from './list';
import {NumberExpression, NumberExpressionProps} from './number';
import type {StringExpression, StringExpressionProps} from './string';

Expand All @@ -21,6 +22,7 @@ export type AnyExpression =
| BinaryOperationExpression
| BooleanExpression
| ColorExpression
| ListExpression
| NumberExpression
| StringExpression;

Expand All @@ -33,6 +35,7 @@ export type ExpressionType =
| 'binary-operation'
| 'boolean'
| 'color'
| 'list'
| 'number'
| 'string';

Expand All @@ -46,6 +49,7 @@ export type ExpressionProps =
| BinaryOperationExpressionProps
| BooleanExpressionProps
| ColorExpressionProps
| ListExpressionProps
| NumberExpressionProps
| StringExpressionProps;

Expand Down
Loading

0 comments on commit 1b58aa9

Please sign in to comment.