Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for list literals #2515

Merged
merged 3 commits into from
Feb 19, 2025
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
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