@@ -1296,6 +1296,9 @@ class Stylesheet extends CSSParserRule {
1296
1296
rules : this . rules ,
1297
1297
}
1298
1298
}
1299
+ toSource ( ) {
1300
+ return "\n" . join ( this . rules . map ( x => x . toSource ( { indent :0 } ) ) ) + "\n" ;
1301
+ }
1299
1302
}
1300
1303
1301
1304
class AtRule extends CSSParserRule {
@@ -1316,6 +1319,24 @@ class AtRule extends CSSParserRule {
1316
1319
rules : this . rules ,
1317
1320
}
1318
1321
}
1322
+ toSource ( indent = 0 ) {
1323
+ let s = printIndent ( indent ) + "@" + escapeIdent ( this . name ) ;
1324
+ s += this . prelude . map ( x => x . toSource ( ) ) ;
1325
+ if ( this . declarations == null ) {
1326
+ s += ";\n" ;
1327
+ return s ;
1328
+ }
1329
+ s += "{\n" ;
1330
+ if ( this . declarations ) {
1331
+ s += "\n" . join ( this . declarations . map ( x => x . toSource ( indent + 1 ) ) ) ;
1332
+ s += "\n" ;
1333
+ }
1334
+ if ( this . rules ) {
1335
+ s += "\n" . join ( this . rules . map ( x => x . toSource ( indent + 1 ) ) ) ;
1336
+ s += "\n" ;
1337
+ }
1338
+ s += printIndent ( indent ) + "}" ;
1339
+ }
1319
1340
}
1320
1341
1321
1342
class QualifiedRule extends CSSParserRule {
@@ -1334,6 +1355,24 @@ class QualifiedRule extends CSSParserRule {
1334
1355
rules : this . rules ,
1335
1356
}
1336
1357
}
1358
+ toSource ( indent = 0 ) {
1359
+ let s = printIndent ( indent ) ;
1360
+ s += this . prelude . map ( x => x . toSource ( ) ) ;
1361
+ if ( this . declarations == null ) {
1362
+ s += ";\n" ;
1363
+ return s ;
1364
+ }
1365
+ s += "{\n" ;
1366
+ if ( this . declarations ) {
1367
+ s += "\n" . join ( this . declarations . map ( x => x . toSource ( indent + 1 ) ) ) ;
1368
+ s += "\n" ;
1369
+ }
1370
+ if ( this . rules ) {
1371
+ s += "\n" . join ( this . rules . map ( x => x . toSource ( indent + 1 ) ) ) ;
1372
+ s += "\n" ;
1373
+ }
1374
+ s += printIndent ( indent ) + "}" ;
1375
+ }
1337
1376
}
1338
1377
1339
1378
class Declaration extends CSSParserRule {
@@ -1352,6 +1391,14 @@ class Declaration extends CSSParserRule {
1352
1391
important : this . important ,
1353
1392
}
1354
1393
}
1394
+ toSource ( indent = 0 ) {
1395
+ let s = printIndent ( indent ) + escapeIdent ( this . name ) + ": " ;
1396
+ s += "" . join ( this . value . map ( x => x . toSource ( ) ) )
1397
+ if ( this . important ) {
1398
+ s += " !important" ;
1399
+ }
1400
+ s += ";" ;
1401
+ }
1355
1402
}
1356
1403
1357
1404
class SimpleBlock extends CSSParserRule {
@@ -1368,6 +1415,10 @@ class SimpleBlock extends CSSParserRule {
1368
1415
value : this . value ,
1369
1416
}
1370
1417
}
1418
+ toSource ( ) {
1419
+ const mirror = { "{" :"}" , "[" :"]" , "(" :")" } ;
1420
+ return this . name + "" . join ( this . value . map ( x => x . toSource ( ) ) ) + mirror [ this . name ] ;
1421
+ }
1371
1422
}
1372
1423
1373
1424
class Func extends CSSParserRule {
@@ -1384,6 +1435,13 @@ class Func extends CSSParserRule {
1384
1435
value : this . value ,
1385
1436
}
1386
1437
}
1438
+ toSource ( ) {
1439
+ return escapeIdent ( this . name ) + "(" + "" . join ( this . value . map ( x => x . toSource ( ) ) ) + ")" ;
1440
+ }
1441
+ }
1442
+
1443
+ function printIndent ( level ) {
1444
+ return "\t" . repeat ( level ) ;
1387
1445
}
1388
1446
1389
1447
0 commit comments