@@ -83,11 +83,13 @@ async function doParse(iterator, options = {}) {
8383 const src = options . src ;
8484 const stack = [ ] ;
8585 const stats = {
86+ src : options . src ?? '' ,
8687 bytesIn : 0 ,
8788 importedBytesIn : 0 ,
8889 parse : `0ms` ,
8990 minify : `0ms` ,
90- total : `0ms`
91+ total : `0ms` ,
92+ imports : [ ]
9193 } ;
9294 let ast = {
9395 typ : EnumToken . StyleSheetNodeType ,
@@ -133,7 +135,7 @@ async function doParse(iterator, options = {}) {
133135 ast . loc . end = item . end ;
134136 }
135137 if ( item . token == ';' || item . token == '{' ) {
136- node = parseNode ( tokens , context , stats , options , errors , src , map , rawTokens ) ;
138+ node = parseNode ( tokens , context , options , errors , src , map , rawTokens ) ;
137139 rawTokens . length = 0 ;
138140 if ( node != null ) {
139141 if ( 'chi' in node ) {
@@ -172,7 +174,7 @@ async function doParse(iterator, options = {}) {
172174 map = new Map ;
173175 }
174176 else if ( item . token == '}' ) {
175- parseNode ( tokens , context , stats , options , errors , src , map , rawTokens ) ;
177+ parseNode ( tokens , context , options , errors , src , map , rawTokens ) ;
176178 rawTokens . length = 0 ;
177179 if ( context . loc != null ) {
178180 context . loc . end = item . end ;
@@ -193,7 +195,7 @@ async function doParse(iterator, options = {}) {
193195 }
194196 }
195197 if ( tokens . length > 0 ) {
196- node = parseNode ( tokens , context , stats , options , errors , src , map , rawTokens ) ;
198+ node = parseNode ( tokens , context , options , errors , src , map , rawTokens ) ;
197199 rawTokens . length = 0 ;
198200 if ( node != null ) {
199201 if ( node . typ == EnumToken . AtRuleNodeType && node . nam == 'import' ) {
@@ -218,14 +220,14 @@ async function doParse(iterator, options = {}) {
218220 const url = token . typ == EnumToken . StringTokenType ? token . val . slice ( 1 , - 1 ) : token . val ;
219221 try {
220222 const root = await options . load ( url , options . src ) . then ( ( src ) => {
221- // console.error({url, src: options.src, resolved: options.resolve!(url, options.src as string)})
222223 return doParse ( src , Object . assign ( { } , options , {
223224 minify : false ,
224225 setParent : false ,
225226 src : options . resolve ( url , options . src ) . absolute
226227 } ) ) ;
227228 } ) ;
228229 stats . importedBytesIn += root . stats . bytesIn ;
230+ stats . imports . push ( root . stats ) ;
229231 node . parent . chi . splice ( node . parent . chi . indexOf ( node ) , 1 , ...root . ast . chi ) ;
230232 if ( root . errors . length > 0 ) {
231233 errors . push ( ...root . errors ) ;
@@ -317,7 +319,7 @@ function getLastNode(context) {
317319 }
318320 return null ;
319321}
320- function parseNode ( results , context , stats , options , errors , src , map , rawTokens ) {
322+ function parseNode ( results , context , options , errors , src , map , rawTokens ) {
321323 let tokens = [ ] ;
322324 for ( const t of results ) {
323325 const node = getTokenType ( t . token , t . hint ) ;
@@ -545,9 +547,11 @@ function parseNode(results, context, stats, options, errors, src, map, rawTokens
545547 removeComments : true
546548 } ) , '' ) ;
547549 }
548- // }
549550 context . chi . push ( node ) ;
550- Object . defineProperties ( node , { parent : { ...definedPropertySettings , value : context } , validSyntax : { ...definedPropertySettings , value : valid . valid == SyntaxValidationResult . Valid } } ) ;
551+ Object . defineProperties ( node , {
552+ parent : { ...definedPropertySettings , value : context } ,
553+ validSyntax : { ...definedPropertySettings , value : valid . valid == SyntaxValidationResult . Valid }
554+ } ) ;
551555 return node ;
552556 }
553557 else {
@@ -585,11 +589,9 @@ function parseNode(results, context, stats, options, errors, src, map, rawTokens
585589 let t = renderToken ( curr , { minify : false } ) ;
586590 if ( t == ',' ) {
587591 acc . push ( [ ] ) ;
588- // uniqTokens.push([]);
589592 }
590593 else {
591594 acc [ acc . length - 1 ] . push ( t ) ;
592- // uniqTokens[uniqTokens.length - 1].push(curr);
593595 }
594596 return acc ;
595597 } , [ [ ] ] ) . reduce ( ( acc , curr ) => {
@@ -621,7 +623,6 @@ function parseNode(results, context, stats, options, errors, src, map, rawTokens
621623 // @ts -ignore
622624 context . chi . push ( node ) ;
623625 Object . defineProperty ( node , 'parent' , { ...definedPropertySettings , value : context } ) ;
624- // if (options.validation) {
625626 // @ts -ignore
626627 const valid = options . validation == ValidationLevel . None ? {
627628 valid : SyntaxValidationResult . Valid ,
@@ -638,24 +639,10 @@ function parseNode(results, context, stats, options, errors, src, map, rawTokens
638639 location
639640 } ) ;
640641 }
641- // } else {
642- //
643- // Object.defineProperty(node, 'tokens', {
644- // ...definedPropertySettings,
645- // enumerable: false,
646- // value: tokens.slice()
647- // });
648- //
649- // let raw: string[][] = [...uniq.values()];
650- //
651- // Object.defineProperty(node, 'raw', {
652- // enumerable: false,
653- // configurable: true,
654- // writable: true,
655- // value: raw
656- // });
657- // }
658- Object . defineProperty ( node , 'validSyntax' , { ...definedPropertySettings , value : valid . valid == SyntaxValidationResult . Valid } ) ;
642+ Object . defineProperty ( node , 'validSyntax' , {
643+ ...definedPropertySettings ,
644+ value : valid . valid == SyntaxValidationResult . Valid
645+ } ) ;
659646 return node ;
660647 }
661648 else {
@@ -705,9 +692,7 @@ function parseNode(results, context, stats, options, errors, src, map, rawTokens
705692 parseColor ( tokens [ i ] ) ;
706693 }
707694 }
708- tokens . splice ( i , 0 , { typ : EnumToken . ColonTokenType } ) ;
709- // i++;
710- i -- ;
695+ tokens . splice ( i -- , 0 , { typ : EnumToken . ColonTokenType } ) ;
711696 continue ;
712697 }
713698 if ( 'chi' in tokens [ i ] ) {
@@ -792,11 +777,15 @@ function parseNode(results, context, stats, options, errors, src, map, rawTokens
792777 const result = parseDeclarationNode ( node , errors , location ) ;
793778 Object . defineProperty ( result , 'parent' , { ...definedPropertySettings , value : context } ) ;
794779 if ( result != null ) {
795- // console.error(doRender(result), result.val, location);
796780 if ( options . validation == ValidationLevel . All ) {
797781 const valid = evaluateSyntax ( result , options ) ;
798- Object . defineProperty ( result , 'validSyntax' , { ...definedPropertySettings , value : valid . valid == SyntaxValidationResult . Valid } ) ;
782+ Object . defineProperty ( result , 'validSyntax' , {
783+ ...definedPropertySettings ,
784+ value : valid . valid == SyntaxValidationResult . Valid
785+ } ) ;
799786 if ( valid . valid == SyntaxValidationResult . Drop ) {
787+ // console.error({result, valid});
788+ // console.error(JSON.stringify({result, options, valid}, null, 1));
800789 errors . push ( {
801790 action : 'drop' ,
802791 message : valid . error ,
@@ -1590,12 +1579,6 @@ function parseTokens(tokens, options = {}) {
15901579 if ( t . chi [ 0 ] . val . slice ( 1 , 5 ) != 'data:' && urlTokenMatcher . test ( value ) ) {
15911580 // @ts -ignore
15921581 t . chi [ 0 ] . typ = EnumToken . UrlTokenTokenType ;
1593- // console.error({t, v: t.chi[0], value,
1594- // src: options.src,
1595- // resolved: options.src !== '' && options.resolveUrls ? options.resolve(value, options.src).absolute : null,
1596- // val2: options.src !== '' && options.resolveUrls ? options.resolve(value, options.src).absolute : value });
1597- //
1598- // console.error(new Error('resolved'));
15991582 // @ts -ignore
16001583 t . chi [ 0 ] . val = options . src !== '' && options . resolveUrls ? options . resolve ( value , options . src ) . absolute : value ;
16011584 }
@@ -1648,4 +1631,4 @@ function parseTokens(tokens, options = {}) {
16481631 return tokens ;
16491632}
16501633
1651- export { doParse , parseAtRulePrelude , parseSelector , parseString , parseTokens , urlTokenMatcher } ;
1634+ export { doParse , getTokenType , parseAtRulePrelude , parseSelector , parseString , parseTokens , urlTokenMatcher } ;
0 commit comments