Skip to content

Commit c540875

Browse files
nex3Goodwine
andauthored
Add support for function call expressions (#2519)
Co-authored-by: Carlos (Goodwine) <[email protected]>
1 parent 7c4ff8f commit c540875

File tree

10 files changed

+559
-0
lines changed

10 files changed

+559
-0
lines changed

lib/src/js/parser.dart

+6
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,12 @@ void _updateAstPrototypes() {
109109
getJSClass(
110110
ContentRule(arguments, bogusSpan),
111111
).defineGetter('arguments', (ContentRule self) => self.arguments);
112+
getJSClass(
113+
FunctionExpression('a', arguments, bogusSpan),
114+
).defineGetter('arguments', (FunctionExpression self) => self.arguments);
115+
getJSClass(
116+
IfExpression(arguments, bogusSpan),
117+
).defineGetter('arguments', (IfExpression self) => self.arguments);
112118

113119
_addSupportsConditionToInterpolation();
114120

pkg/sass-parser/CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
* Add support for parsing map expressions.
66

7+
* Add support for parsing function calls.
8+
79
## 0.4.14
810

911
* Add support for parsing color expressions.

pkg/sass-parser/lib/index.ts

+5
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,11 @@ export {
7070
ColorExpressionProps,
7171
ColorExpressionRaws,
7272
} from './src/expression/color';
73+
export {
74+
FunctionExpression,
75+
FunctionExpressionProps,
76+
FunctionExpressionRaws,
77+
} from './src/expression/function';
7378
export {
7479
ListExpression,
7580
ListExpressionProps,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`a function expression toJSON if() 1`] = `
4+
{
5+
"arguments": <(cond, true, false)>,
6+
"inputs": [
7+
{
8+
"css": "@#{if(cond, true, false)}",
9+
"hasBOM": false,
10+
"id": "<input css _____>",
11+
},
12+
],
13+
"name": "if",
14+
"raws": {},
15+
"sassType": "function-call",
16+
}
17+
`;
18+
19+
exports[`a function expression toJSON with a namespace 1`] = `
20+
{
21+
"arguments": <(bar)>,
22+
"inputs": [
23+
{
24+
"css": "@#{baz.foo(bar)}",
25+
"hasBOM": false,
26+
"id": "<input css _____>",
27+
},
28+
],
29+
"name": "foo",
30+
"namespace": "baz",
31+
"raws": {},
32+
"sassType": "function-call",
33+
"source": <1:4-1:16 in 0>,
34+
}
35+
`;
36+
37+
exports[`a function expression toJSON without a namespace 1`] = `
38+
{
39+
"arguments": <(bar)>,
40+
"inputs": [
41+
{
42+
"css": "@#{foo(bar)}",
43+
"hasBOM": false,
44+
"id": "<input css _____>",
45+
},
46+
],
47+
"name": "foo",
48+
"raws": {},
49+
"sassType": "function-call",
50+
"source": <1:4-1:12 in 0>,
51+
}
52+
`;

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

+8
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@
44

55
import * as sassInternal from '../sass-internal';
66

7+
import {ArgumentList} from '../argument-list';
78
import {Expression} from '.';
89
import {BinaryOperationExpression} from './binary-operation';
910
import {BooleanExpression} from './boolean';
1011
import {ColorExpression} from './color';
12+
import {FunctionExpression} from './function';
1113
import {ListExpression} from './list';
1214
import {MapExpression} from './map';
1315
import {NumberExpression} from './number';
@@ -20,6 +22,12 @@ const visitor = sassInternal.createExpressionVisitor<Expression>({
2022
visitStringExpression: inner => new StringExpression(undefined, inner),
2123
visitBooleanExpression: inner => new BooleanExpression(undefined, inner),
2224
visitColorExpression: inner => new ColorExpression(undefined, inner),
25+
visitFunctionExpression: inner => new FunctionExpression(undefined, inner),
26+
visitIfExpression: inner =>
27+
new FunctionExpression({
28+
name: 'if',
29+
arguments: new ArgumentList(undefined, inner.arguments),
30+
}),
2331
visitListExpression: inner => new ListExpression(undefined, inner),
2432
visitMapExpression: inner => new MapExpression(undefined, inner),
2533
visitNumberExpression: inner => new NumberExpression(undefined, inner),

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

+2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {Expression, ExpressionProps} from '.';
77
import {BinaryOperationExpression} from './binary-operation';
88
import {BooleanExpression} from './boolean';
99
import {ColorExpression} from './color';
10+
import {FunctionExpression} from './function';
1011
import {ListExpression} from './list';
1112
import {MapExpression} from './map';
1213
import {NumberExpression} from './number';
@@ -18,6 +19,7 @@ export function fromProps(props: ExpressionProps): Expression {
1819
if ('left' in props) return new BinaryOperationExpression(props);
1920
if ('separator' in props) return new ListExpression(props);
2021
if ('nodes' in props) return new MapExpression(props);
22+
if ('name' in props) return new FunctionExpression(props);
2123
if ('value' in props) {
2224
if (typeof props.value === 'boolean') return new BooleanExpression(props);
2325
if (typeof props.value === 'number') return new NumberExpression(props);

0 commit comments

Comments
 (0)