Skip to content

Commit 1b58aa9

Browse files
nex3Goodwine
andauthored
Add support for list literals (#2515)
Co-authored-by: Carlos (Goodwine) <[email protected]>
1 parent f32ec4f commit 1b58aa9

14 files changed

+1978
-4
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 1.85.1-dev
2+
3+
* No user-visible changes.
4+
15
## 1.85.0
26

37
* No longer fully trim redundant selectors generated by `@extend`. This caused

pkg/sass-parser/CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.4.15-dev
2+
3+
* Add support for parsing list expressions.
4+
15
## 0.4.14
26

37
* Add support for parsing color expressions.

pkg/sass-parser/lib/index.ts

+7
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,13 @@ export {
7070
ColorExpressionProps,
7171
ColorExpressionRaws,
7272
} from './src/expression/color';
73+
export {
74+
ListExpression,
75+
ListExpressionProps,
76+
ListExpressionRaws,
77+
ListSeparator,
78+
NewNodeForListExpression,
79+
} from './src/expression/list';
7380
export {
7481
NumberExpression,
7582
NumberExpressionProps,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`a list expression toJSON 1`] = `
4+
{
5+
"brackets": true,
6+
"inputs": [
7+
{
8+
"css": "@#{[foo, bar]}",
9+
"hasBOM": false,
10+
"id": "<input css _____>",
11+
},
12+
],
13+
"nodes": [
14+
<foo>,
15+
<bar>,
16+
],
17+
"raws": {},
18+
"sassType": "list",
19+
"separator": ",",
20+
"source": <1:4-1:14 in 0>,
21+
}
22+
`;

pkg/sass-parser/lib/src/expression/convert.ts

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {Expression} from '.';
88
import {BinaryOperationExpression} from './binary-operation';
99
import {BooleanExpression} from './boolean';
1010
import {ColorExpression} from './color';
11+
import {ListExpression} from './list';
1112
import {NumberExpression} from './number';
1213
import {StringExpression} from './string';
1314

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

pkg/sass-parser/lib/src/expression/from-props.ts

+2
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,15 @@ import {Expression, ExpressionProps} from '.';
77
import {BinaryOperationExpression} from './binary-operation';
88
import {BooleanExpression} from './boolean';
99
import {ColorExpression} from './color';
10+
import {ListExpression} from './list';
1011
import {NumberExpression} from './number';
1112
import {StringExpression} from './string';
1213

1314
/** Constructs an expression from {@link ExpressionProps}. */
1415
export function fromProps(props: ExpressionProps): Expression {
1516
if ('text' in props) return new StringExpression(props);
1617
if ('left' in props) return new BinaryOperationExpression(props);
18+
if ('separator' in props) return new ListExpression(props);
1719
if ('value' in props) {
1820
if (typeof props.value === 'boolean') return new BooleanExpression(props);
1921
if (typeof props.value === 'number') return new NumberExpression(props);

pkg/sass-parser/lib/src/expression/index.ts

+4
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import type {
99
} from './binary-operation';
1010
import {BooleanExpression, BooleanExpressionProps} from './boolean';
1111
import {ColorExpression, ColorExpressionProps} from './color';
12+
import {ListExpression, ListExpressionProps} from './list';
1213
import {NumberExpression, NumberExpressionProps} from './number';
1314
import type {StringExpression, StringExpressionProps} from './string';
1415

@@ -21,6 +22,7 @@ export type AnyExpression =
2122
| BinaryOperationExpression
2223
| BooleanExpression
2324
| ColorExpression
25+
| ListExpression
2426
| NumberExpression
2527
| StringExpression;
2628

@@ -33,6 +35,7 @@ export type ExpressionType =
3335
| 'binary-operation'
3436
| 'boolean'
3537
| 'color'
38+
| 'list'
3639
| 'number'
3740
| 'string';
3841

@@ -46,6 +49,7 @@ export type ExpressionProps =
4649
| BinaryOperationExpressionProps
4750
| BooleanExpressionProps
4851
| ColorExpressionProps
52+
| ListExpressionProps
4953
| NumberExpressionProps
5054
| StringExpressionProps;
5155

0 commit comments

Comments
 (0)