File tree Expand file tree Collapse file tree 2 files changed +65
-0
lines changed Expand file tree Collapse file tree 2 files changed +65
-0
lines changed Original file line number Diff line number Diff line change @@ -7,6 +7,18 @@ class AtWord extends Container {
77 super ( opts ) ;
88 this . type = 'atword' ;
99 }
10+
11+ toString ( ) {
12+ let quote = this . quoted ? this . raws . quote : '' ;
13+ return [
14+ this . raws . before ,
15+ '@' ,
16+ // we can't use String() here because it'll try using itself
17+ // as the constructor
18+ String . prototype . toString . call ( this . value ) ,
19+ this . raws . after
20+ ] . join ( '' ) ;
21+ }
1022}
1123
1224Container . registerWalker ( AtWord ) ;
Original file line number Diff line number Diff line change 1+ 'use strict' ;
2+
3+ const chai = require ( 'chai' ) ;
4+ const shallowDeepEqual = require ( 'chai-shallow-deep-equal' ) ;
5+ const Parser = require ( '../lib/parser' ) ;
6+
7+ let expect = chai . expect ;
8+
9+ describe ( 'Parser → Atrule' , ( ) => {
10+
11+ chai . use ( shallowDeepEqual ) ;
12+
13+ let fixtures ,
14+ failures ;
15+
16+ fixtures = [
17+ {
18+ it : 'should parse atword' ,
19+ test : ' @word ' ,
20+ expected : [
21+ { type : 'atword' , value : 'word' , raws : { before : ' ' , after : ' ' } }
22+ ]
23+ } ,
24+ {
25+ it : 'should not parse escaped @ after @ (@\\@)' ,
26+ test : ' @\\@word ' ,
27+ expected : [
28+ { type : 'atword' , value : '\\' , raws : { before : ' ' , after : '' } }
29+ ]
30+ }
31+ ] ;
32+
33+ fixtures . forEach ( ( fixture ) => {
34+ it ( fixture . it , ( ) => {
35+ let ast = new Parser ( fixture . test ) . parse ( ) ;
36+
37+ ast . first . walk ( ( node , index ) => {
38+ let expected = fixture . expected [ index ] ;
39+
40+ if ( expected ) {
41+ expect ( node ) . to . shallowDeepEqual ( expected ) ;
42+ }
43+ } ) ;
44+ } ) ;
45+ } ) ;
46+
47+ failures && failures . forEach ( ( fixture ) => {
48+ it ( fixture . it , ( ) => {
49+ expect ( ( ) => new Parser ( fixture . test ) . parse ( ) ) . to . throw ( Error ) ;
50+ } ) ;
51+ } ) ;
52+
53+ } ) ;
You can’t perform that action at this time.
0 commit comments