@@ -539,6 +539,7 @@ CSSParserToken.prototype.toJSON = function() {
539
539
return { token : this . tokenType } ;
540
540
}
541
541
CSSParserToken . prototype . toString = function ( ) { return this . tokenType ; }
542
+ CSSParserToken . prototype . toSource = function ( ) { return '' + this ; }
542
543
543
544
function BadStringToken ( ) { return this ; }
544
545
BadStringToken . prototype = Object . create ( CSSParserToken . prototype ) ;
@@ -552,14 +553,17 @@ function WhitespaceToken() { return this; }
552
553
WhitespaceToken . prototype = Object . create ( CSSParserToken . prototype ) ;
553
554
WhitespaceToken . prototype . tokenType = "WHITESPACE" ;
554
555
WhitespaceToken . prototype . toString = function ( ) { return "WS" ; }
556
+ WhitespaceToken . prototype . toSource = function ( ) { return " " ; }
555
557
556
558
function CDOToken ( ) { return this ; }
557
559
CDOToken . prototype = Object . create ( CSSParserToken . prototype ) ;
558
560
CDOToken . prototype . tokenType = "CDO" ;
561
+ CDOToken . prototype . toSource = function ( ) { return "<!--" ; }
559
562
560
563
function CDCToken ( ) { return this ; }
561
564
CDCToken . prototype = Object . create ( CSSParserToken . prototype ) ;
562
565
CDCToken . prototype . tokenType = "CDC" ;
566
+ CDCToken . prototype . toSource = function ( ) { return "-->" ; }
563
567
564
568
function ColonToken ( ) { return this ; }
565
569
ColonToken . prototype = Object . create ( CSSParserToken . prototype ) ;
@@ -627,6 +631,7 @@ ColumnToken.prototype.tokenType = "||";
627
631
function EOFToken ( ) { return this ; }
628
632
EOFToken . prototype = Object . create ( CSSParserToken . prototype ) ;
629
633
EOFToken . prototype . tokenType = "EOF" ;
634
+ EOFToken . prototype . toSource = function ( ) { return "" ; }
630
635
631
636
function DelimToken ( code ) {
632
637
this . value = stringFromCode ( code ) ;
@@ -640,6 +645,12 @@ DelimToken.prototype.toJSON = function() {
640
645
json . value = this . value ;
641
646
return json ;
642
647
}
648
+ DelimToken . prototype . toSource = function ( ) {
649
+ if ( this . value == "\\" )
650
+ return "\\\n" ;
651
+ else
652
+ return this . value ;
653
+ }
643
654
644
655
function StringValuedToken ( ) { throw "Abstract Base Class" ; }
645
656
StringValuedToken . prototype = Object . create ( CSSParserToken . prototype ) ;
@@ -658,6 +669,9 @@ function IdentToken(val) {
658
669
IdentToken . prototype = Object . create ( StringValuedToken . prototype ) ;
659
670
IdentToken . prototype . tokenType = "IDENT" ;
660
671
IdentToken . prototype . toString = function ( ) { return "IDENT(" + this . value + ")" ; }
672
+ IdentToken . prototype . toSource = function ( ) {
673
+ return escapeIdent ( this . value ) ;
674
+ }
661
675
662
676
function FunctionToken ( val ) {
663
677
this . value = val ;
@@ -666,13 +680,19 @@ function FunctionToken(val) {
666
680
FunctionToken . prototype = Object . create ( StringValuedToken . prototype ) ;
667
681
FunctionToken . prototype . tokenType = "FUNCTION" ;
668
682
FunctionToken . prototype . toString = function ( ) { return "FUNCTION(" + this . value + ")" ; }
683
+ FunctionToken . prototype . toSource = function ( ) {
684
+ return escapeIdent ( this . value ) + "(" ;
685
+ }
669
686
670
687
function AtKeywordToken ( val ) {
671
688
this . value = val ;
672
689
}
673
690
AtKeywordToken . prototype = Object . create ( StringValuedToken . prototype ) ;
674
691
AtKeywordToken . prototype . tokenType = "AT-KEYWORD" ;
675
692
AtKeywordToken . prototype . toString = function ( ) { return "AT(" + this . value + ")" ; }
693
+ AtKeywordToken . prototype . toSource = function ( ) {
694
+ return "@" + escapeIdent ( this . value ) ;
695
+ }
676
696
677
697
function HashToken ( val ) {
678
698
this . value = val ;
@@ -687,20 +707,32 @@ HashToken.prototype.toJSON = function() {
687
707
json . type = this . type ;
688
708
return json ;
689
709
}
710
+ HashToken . prototype . toSource = function ( ) {
711
+ if ( this . type == "id" ) {
712
+ return "#" + escapeIdent ( this . value ) ;
713
+ } else {
714
+ return "#" + escapeHash ( this . value ) ;
715
+ }
716
+ }
690
717
691
718
function StringToken ( val ) {
692
719
this . value = val ;
693
720
}
694
721
StringToken . prototype = Object . create ( StringValuedToken . prototype ) ;
695
722
StringToken . prototype . tokenType = "STRING" ;
696
- StringToken . prototype . toString = function ( ) { return "\"" + this . value + "\"" ; }
723
+ StringToken . prototype . toString = function ( ) {
724
+ return '"' + escapeString ( this . value ) + '"' ;
725
+ }
697
726
698
727
function URLToken ( val ) {
699
728
this . value = val ;
700
729
}
701
730
URLToken . prototype = Object . create ( StringValuedToken . prototype ) ;
702
731
URLToken . prototype . tokenType = "URL" ;
703
732
URLToken . prototype . toString = function ( ) { return "URL(" + this . value + ")" ; }
733
+ URLToken . prototype . toSource = function ( ) {
734
+ return "url(" + escapeURL ( this . value ) + ")" ;
735
+ }
704
736
705
737
function NumberToken ( ) {
706
738
this . value = null ;
@@ -721,6 +753,7 @@ NumberToken.prototype.toJSON = function() {
721
753
json . repr = this . repr ;
722
754
return json ;
723
755
}
756
+ NumberToken . prototype . toSource = function ( ) { return this . repr ; } ;
724
757
725
758
function PercentageToken ( ) {
726
759
this . value = null ;
@@ -735,6 +768,7 @@ PercentageToken.prototype.toJSON = function() {
735
768
json . repr = this . repr ;
736
769
return json ;
737
770
}
771
+ PercentageToken . prototype . toSource = function ( ) { return this . repr + "%" ; }
738
772
739
773
function DimensionToken ( ) {
740
774
this . value = null ;
@@ -753,6 +787,36 @@ DimensionToken.prototype.toJSON = function() {
753
787
json . unit = this . unit ;
754
788
return json ;
755
789
}
790
+ DimensionToken . prototype . toSource = function ( ) {
791
+ var source = this . repr ;
792
+ var unit = escapeIdent ( this . unit ) ;
793
+ if ( unit [ 0 ] . toLowerCase ( ) == "e" && ( unit [ 1 ] == "-" || between ( unit . charCodeAt ( 1 ) , 0x30 , 0x39 ) ) ) {
794
+ // Unit is ambiguous with scinot
795
+ // Remove the leading "e", replace with escape.
796
+ unit = "\\65 " + unit . slice ( 1 , unit . length ) ;
797
+ }
798
+ return source + unit ;
799
+ }
800
+
801
+ function escapeIdent ( string ) {
802
+ // TODO
803
+ return string ;
804
+ }
805
+
806
+ function escapeHash ( string ) {
807
+ // TODO
808
+ return string ;
809
+ }
810
+
811
+ function escapeString ( string ) {
812
+ // TODO
813
+ return string ;
814
+ }
815
+
816
+ function escapeURL ( string ) {
817
+ // TODO
818
+ return string ;
819
+ }
756
820
757
821
// Exportation.
758
822
exports . tokenize = tokenize ;
0 commit comments