File tree 5 files changed +100
-3
lines changed
5 files changed +100
-3
lines changed Original file line number Diff line number Diff line change 6
6
7
7
* Add support for parsing selector expressions.
8
8
9
+ * Add support for parsing the ` supports() ` function in ` @import ` modifiers.
10
+
9
11
## 0.4.15
10
12
11
13
* Add support for parsing list expressions.
Original file line number Diff line number Diff line change 1
1
// Jest Snapshot v1, https://goo.gl/fbAQLP
2
2
3
- exports [` a string expression toJSON 1` ] = `
3
+ exports [` a string expression toJSON a quoted string 1` ] = `
4
4
{
5
5
" inputs" : [
6
6
{
@@ -16,3 +16,56 @@ exports[`a string expression toJSON 1`] = `
16
16
" text" : <foo >,
17
17
}
18
18
`;
19
+
20
+ exports[`a string expression toJSON a string with interpolation 1`] = `
21
+ {
22
+ " inputs" : [
23
+ {
24
+ " css" : " @#{f#{o}o}" ,
25
+ " hasBOM" : false ,
26
+ " id" : " <input css _____>" ,
27
+ },
28
+ ],
29
+ " quotes" : false ,
30
+ " raws" : {},
31
+ " sassType" : " string" ,
32
+ " source" : < 1 :4 - 1 :10 in 0 > ,
33
+ " text" : < f #{o }o > ,
34
+ }
35
+ `;
36
+
37
+ exports[`a string expression toJSON an unquoted string 1`] = `
38
+ {
39
+ " inputs" : [
40
+ {
41
+ " css" : " @#{foo}" ,
42
+ " hasBOM" : false ,
43
+ " id" : " <input css _____>" ,
44
+ },
45
+ ],
46
+ " quotes" : false ,
47
+ " raws" : {},
48
+ " sassType" : " string" ,
49
+ " source" : < 1 :4 - 1 :7 in 0 > ,
50
+ " text" : <foo >,
51
+ }
52
+ `;
53
+
54
+ exports[`a string expression toJSON supports() 1`] = `
55
+ {
56
+ " inputs" : [
57
+ {
58
+ " css" : " @import " foo " supports(width: 1 + 1)" ,
59
+ " hasBOM" : false ,
60
+ " id" : " <input css _____>" ,
61
+ },
62
+ ],
63
+ " nodes" : [
64
+ " supports" ,
65
+ < (width : #{1 + 1})> ,
66
+ ],
67
+ " raws" : {},
68
+ " sassType" : " interpolation" ,
69
+ " source" : < 1 :15 - 1 :37 in 0 > ,
70
+ }
71
+ `;
Original file line number Diff line number Diff line change 5
5
import * as sassInternal from '../sass-internal' ;
6
6
7
7
import { ArgumentList } from '../argument-list' ;
8
+ import { Interpolation } from '../interpolation' ;
9
+ import { LazySource } from '../lazy-source' ;
8
10
import { Expression } from '.' ;
9
11
import { BinaryOperationExpression } from './binary-operation' ;
10
12
import { BooleanExpression } from './boolean' ;
@@ -41,6 +43,15 @@ const visitor = sassInternal.createExpressionVisitor<Expression>({
41
43
new ParenthesizedExpression ( undefined , inner ) ,
42
44
visitSelectorExpression : inner => new SelectorExpression ( undefined , inner ) ,
43
45
visitStringExpression : inner => new StringExpression ( undefined , inner ) ,
46
+ visitSupportsExpression : inner =>
47
+ new StringExpression ( {
48
+ text : new Interpolation ( [
49
+ '(' ,
50
+ new Interpolation ( undefined , inner . condition . toInterpolation ( ) ) ,
51
+ ')' ,
52
+ ] ) ,
53
+ source : new LazySource ( inner ) ,
54
+ } ) ,
44
55
} ) ;
45
56
46
57
/** Converts an internal expression AST node into an external one. */
Original file line number Diff line number Diff line change 2
2
// MIT-style license that can be found in the LICENSE file or at
3
3
// https://opensource.org/licenses/MIT.
4
4
5
- import { Interpolation , StringExpression } from '../..' ;
5
+ import {
6
+ ImportRule ,
7
+ Interpolation ,
8
+ StaticImport ,
9
+ StringExpression ,
10
+ scss ,
11
+ } from '../..' ;
6
12
import * as utils from '../../../test/utils' ;
7
13
8
14
describe ( 'a string expression' , ( ) => {
@@ -284,5 +290,24 @@ describe('a string expression', () => {
284
290
} ) ;
285
291
} ) ;
286
292
287
- it ( 'toJSON' , ( ) => expect ( utils . parseExpression ( '"foo"' ) ) . toMatchSnapshot ( ) ) ;
293
+ describe ( 'toJSON' , ( ) => {
294
+ it ( 'a quoted string' , ( ) =>
295
+ expect ( utils . parseExpression ( '"foo"' ) ) . toMatchSnapshot ( ) ) ;
296
+
297
+ it ( 'an unquoted string' , ( ) =>
298
+ expect ( utils . parseExpression ( 'foo' ) ) . toMatchSnapshot ( ) ) ;
299
+
300
+ it ( 'a string with interpolation' , ( ) =>
301
+ expect ( utils . parseExpression ( 'f#{o}o' ) ) . toMatchSnapshot ( ) ) ;
302
+
303
+ it ( 'supports()' , ( ) =>
304
+ expect (
305
+ (
306
+ (
307
+ scss . parse ( '@import "foo" supports(width: 1 + 1)' )
308
+ . nodes [ 0 ] as ImportRule
309
+ ) . imports . nodes [ 0 ] as StaticImport
310
+ ) . modifiers ,
311
+ ) . toMatchSnapshot ( ) ) ;
312
+ } ) ;
288
313
} ) ;
Original file line number Diff line number Diff line change @@ -384,6 +384,10 @@ declare namespace SassInternal {
384
384
readonly text : Interpolation ;
385
385
readonly hasQuotes : boolean ;
386
386
}
387
+
388
+ class SupportsExpression extends Expression {
389
+ readonly condition : SupportsCondition ;
390
+ }
387
391
}
388
392
389
393
const sassInternal = (
@@ -446,6 +450,7 @@ export type NumberExpression = SassInternal.NumberExpression;
446
450
export type ParenthesizedExpression = SassInternal . ParenthesizedExpression ;
447
451
export type SelectorExpression = SassInternal . SelectorExpression ;
448
452
export type StringExpression = SassInternal . StringExpression ;
453
+ export type SupportsExpression = SassInternal . SupportsExpression ;
449
454
450
455
export interface StatementVisitorObject < T > {
451
456
visitAtRootRule ( node : AtRootRule ) : T ;
@@ -489,6 +494,7 @@ export interface ExpressionVisitorObject<T> {
489
494
visitParenthesizedExpression ( node : ParenthesizedExpression ) : T ;
490
495
visitSelectorExpression ( node : SelectorExpression ) : T ;
491
496
visitStringExpression ( node : StringExpression ) : T ;
497
+ visitSupportsExpression ( node : SupportsExpression ) : T ;
492
498
}
493
499
494
500
export const createExpressionVisitor = sassInternal . createExpressionVisitor ;
You can’t perform that action at this time.
0 commit comments