@@ -5,7 +5,7 @@ import * as fs from "fs";
55
66import { assert } from "chai" ;
77import * as cssParse from "css-parse" ;
8- import { Parser , TokenType } from "../src/index" ;
8+ import { Parser , TokenType , ImportParser , KeyframesParser } from "../src/index" ;
99
1010describe ( "css" , ( ) => {
1111 let parser : Parser ;
@@ -312,6 +312,10 @@ describe("css", () => {
312312 name : "import" ,
313313 prelude : [ " " , { type : TokenType . url , source : `url(~/app.css)` , url : "~/app.css" } ] ,
314314 block : undefined ,
315+ position : {
316+ start : { line : 1 , column : 1 } ,
317+ end : { column : 24 , line : 1 }
318+ }
315319 } ,
316320 {
317321 type : "qualified-rule" ,
@@ -459,6 +463,10 @@ describe("css", () => {
459463 " " ,
460464 ] ,
461465 } ,
466+ position : {
467+ start : { line : 2 , column : 17 } ,
468+ end : { line : 5 , column : 18 }
469+ }
462470 } ,
463471 {
464472 type : "qualified-rule" ,
@@ -492,33 +500,64 @@ describe("css", () => {
492500 } ) ;
493501 } ) ;
494502 } ) ;
495- describe ( "css stylesheet as rework" , ( ) => {
496- function compare ( css : string ) : void {
497- const nativescript = parser . parseACSSStylesheet ( css ) ;
498- // console.log(JSON.stringify(nativescript));
499- // Strip type info and undefined properties.
500- const rework = JSON . parse ( JSON . stringify ( cssParse ( css ) ) ) ;
501- assert . deepEqual ( nativescript , rework ) ;
502- }
503- it ( "div{color:red}p{color:blue}" , ( ) => {
504- compare ( "div{color:red}p{color:blue}" ) ;
505- } ) ;
506- it ( "Button, Label { background: red; }" , ( ) => {
507- compare ( "Button, Label {\n background: red;\n}\n" ) ;
508- } ) ;
509- it ( "Label { color: argb(1, 255, 0, 0); }" , ( ) => {
510- compare ( "Label { color: argb(1, 255, 0, 0); }" ) ;
511- } ) ;
512- it ( "Div { width: 50%; height: 30px; border-width: 2; }" , ( ) => {
513- compare ( "Div { width: 50%; height: 30px; border-width: 2; }" ) ;
514- } ) ;
515- it ( "Div {color:#212121;opacity:.9}" , ( ) => {
516- compare ( "Div {color:#212121;opacity:.9}" ) ;
517- } ) ;
518- it ( "core.light.css" , ( ) => {
519- const css = fs . readFileSync ( "./test/assets/core.light.css" ) . toString ( ) ;
520- compare ( css ) ;
521- } ) ;
522- // TODO: Complete implementation of string-ly values for declarations and do extensive testing...
503+ } ) ;
504+
505+ describe ( "css as rework" , ( ) => {
506+ let parser : Parser ;
507+ before ( "create parser" , ( ) => {
508+ parser = new Parser ( ) ;
509+ parser . addAtRuleParser ( new ImportParser ( ) ) ;
510+ parser . addAtRuleParser ( new KeyframesParser ( ) ) ;
511+ } ) ;
512+ after ( "dispose parser" , ( ) => parser = null ) ;
513+
514+ function compare ( css : string ) : void {
515+ const nativescript = parser . parseACSSStylesheet ( css ) ;
516+ // console.log(JSON.stringify(nativescript));
517+ // Strip type info and undefined properties.
518+ const rework = JSON . parse ( JSON . stringify ( cssParse ( css ) ) ) ;
519+ // console.log("REWORK AST:\n" + JSON.stringify(rework, null, " "));
520+ // console.log("{N} AST:\n" + JSON.stringify(nativescript, null, " "));
521+ assert . deepEqual ( nativescript , rework ) ;
522+ }
523+ it ( "div{color:red}p{color:blue}" , ( ) => {
524+ compare ( "div{color:red}p{color:blue}" ) ;
525+ } ) ;
526+ it ( "Button, Label { background: red; }" , ( ) => {
527+ compare ( "Button, Label {\n background: red;\n}\n" ) ;
528+ } ) ;
529+ it ( "Label { color: argb(1, 255, 0, 0); }" , ( ) => {
530+ compare ( "Label { color: argb(1, 255, 0, 0); }" ) ;
531+ } ) ;
532+ it ( "Div { width: 50%; height: 30px; border-width: 2; }" , ( ) => {
533+ compare ( "Div { width: 50%; height: 30px; border-width: 2; }" ) ;
534+ } ) ;
535+ it ( "Div {color:#212121;opacity:.9}" , ( ) => {
536+ compare ( "Div {color:#212121;opacity:.9}" ) ;
537+ } ) ;
538+ it ( "core.light.css" , ( ) => {
539+ const css = fs . readFileSync ( "./test/assets/core.light.css" ) . toString ( ) ;
540+ compare ( css ) ;
541+ } ) ;
542+ it . skip ( "simple keyframe" , ( ) => {
543+ const css = `
544+ @keyframes example {
545+ 0% { transform: scale(1, 1); }
546+ 100% { transform: scale(1, 0); }
547+ }
548+ div {
549+ animation: example 5s linear 2s infinite alternate;
550+ }
551+ ` ;
552+ compare ( css ) ;
553+ } ) ;
554+ it ( "simple import" , ( ) => {
555+ const css = `
556+ @import url("mycomponent.css");
557+ @import url("mycomponent-print.css") print;
558+ div { background: red; }
559+ ` ;
560+ compare ( css ) ;
523561 } ) ;
524562} ) ;
563+
0 commit comments