@@ -154,7 +154,6 @@ async function doParse(iter, options = {}) {
154154 const preVisitorsHandlersMap = new Map ;
155155 const visitorsHandlersMap = new Map ;
156156 const postVisitorsHandlersMap = new Map ;
157- // const allValuesHandlers = new Map as Map<EnumToken, Array<GenericVisitorHandler<Token>>>;
158157 const rawTokens = [ ] ;
159158 const imports = [ ] ;
160159 let item ;
@@ -240,42 +239,6 @@ async function doParse(iter, options = {}) {
240239 errors . push ( { action : 'ignore' , message : `doParse: visitor.${ key } is not a valid key name` } ) ;
241240 }
242241 }
243- // if (preValuesHandlers.size > 0) {
244- //
245- // for (const [key, value] of preValuesHandlers) {
246- //
247- // if (!allValuesHandlers.has(key)) {
248- //
249- // allValuesHandlers.set(key, []);
250- // }
251- //
252- // allValuesHandlers.get(key)!.push(...value);
253- // }
254- // }
255- // if (valuesHandlers.size > 0) {
256- //
257- // for (const [key, value] of valuesHandlers) {
258- //
259- // if (!allValuesHandlers.has(key)) {
260- //
261- // allValuesHandlers.set(key, []);
262- // }
263- //
264- // allValuesHandlers.get(key)!.push(...value);
265- // }
266- // }
267- // if (postValuesHandlers.size > 0) {
268- //
269- // for (const [key, value] of postValuesHandlers) {
270- //
271- // if (!postValuesHandlers.has(key)) {
272- //
273- // allValuesHandlers.set(key, []);
274- // }
275- //
276- // allValuesHandlers.get(key)!.push(...value);
277- // }
278- // }
279242 }
280243 while ( item = isAsync ? ( await iter . next ( ) ) . value : iter . next ( ) . value ) {
281244 stats . bytesIn = item . bytesIn ;
@@ -435,6 +398,8 @@ async function doParse(iter, options = {}) {
435398 if ( options . expandNestingRules ) {
436399 ast = expand ( ast ) ;
437400 }
401+ let replacement ;
402+ let callable ;
438403 for ( const result of walk ( ast ) ) {
439404 if ( valuesHandlers . size > 0 || preVisitorsHandlersMap . size > 0 || visitorsHandlersMap . size > 0 || postVisitorsHandlersMap . size > 0 ) {
440405 if ( ( result . node . typ == EnumToken . DeclarationNodeType &&
@@ -455,14 +420,13 @@ async function doParse(iter, options = {}) {
455420 // @ts -ignore
456421 handlers . push ( ...postVisitorsHandlersMap . get ( key ) ) ;
457422 }
458- let callable ;
459423 let node = result . node ;
460424 for ( const handler of handlers ) {
461425 callable = typeof handler == 'function' ? handler : handler [ normalizeVisitorKeyName ( node . typ == EnumToken . DeclarationNodeType || node . typ == EnumToken . AtRuleNodeType ? node . nam : node . val ) ] ;
462426 if ( callable == null ) {
463427 continue ;
464428 }
465- let replacement = callable ( node , result . parent ) ;
429+ replacement = callable ( node , result . parent ) ;
466430 if ( replacement == null ) {
467431 continue ;
468432 }
@@ -500,8 +464,7 @@ async function doParse(iter, options = {}) {
500464 }
501465 let node = result . node ;
502466 for ( const callable of handlers ) {
503- // @ts -ignore
504- let replacement = callable ( node , result . parent ) ;
467+ replacement = callable ( node , result . parent ) ;
505468 if ( replacement == null ) {
506469 continue ;
507470 }
@@ -526,13 +489,12 @@ async function doParse(iter, options = {}) {
526489 }
527490 }
528491 else if ( valuesHandlers . size > 0 ) {
529- let callable ;
530492 let node = null ;
531493 node = result . node ;
532494 if ( valuesHandlers . has ( node . typ ) ) {
533495 for ( const valueHandler of valuesHandlers . get ( node . typ ) ) {
534496 callable = valueHandler ;
535- let replacement = callable ( node , result . parent ) ;
497+ replacement = callable ( node , result . parent ) ;
536498 if ( replacement == null ) {
537499 continue ;
538500 }
@@ -828,7 +790,7 @@ function parseNode(results, context, options, errors, src, map, rawTokens, stats
828790 }
829791 const isAllowed = isNodeAllowedInContext ( node , context ) ;
830792 // @ts -ignore
831- const valid = options . validation == ValidationLevel . None ? {
793+ const valid = ( options . validation & ValidationLevel . AtRule ) == 0 ? {
832794 valid : SyntaxValidationResult . Valid ,
833795 error : '' ,
834796 node,
@@ -964,12 +926,11 @@ function parseNode(results, context, options, errors, src, map, rawTokens, stats
964926 value : loc ,
965927 enumerable : options . sourcemap !== false
966928 } ) ;
967- // @ts -ignore
968929 context . chi . push ( node ) ;
969930 Object . defineProperty ( node , 'parent' , { ...definedPropertySettings , value : context } ) ;
970931 const isAllowed = isNodeAllowedInContext ( node , context ) ;
971932 // @ts -ignore
972- const valid = options . validation == ValidationLevel . None ? {
933+ const valid = ( options . validation & ValidationLevel . Selector ) == 0 ? {
973934 valid : SyntaxValidationResult . Valid ,
974935 error : null
975936 } : ! isAllowed ? {
@@ -1084,7 +1045,11 @@ function parseNode(results, context, options, errors, src, map, rawTokens, stats
10841045 nam,
10851046 val : [ ]
10861047 } ;
1087- Object . defineProperty ( node , 'loc' , { ...definedPropertySettings , value : location , enumerable : options . sourcemap !== false } ) ;
1048+ Object . defineProperty ( node , 'loc' , {
1049+ ...definedPropertySettings ,
1050+ value : location ,
1051+ enumerable : options . sourcemap !== false
1052+ } ) ;
10881053 context . chi . push ( node ) ;
10891054 stats . nodesCount ++ ;
10901055 }
@@ -1110,7 +1075,11 @@ function parseNode(results, context, options, errors, src, map, rawTokens, stats
11101075 nam,
11111076 val : value
11121077 } ;
1113- Object . defineProperty ( node , 'loc' , { ...definedPropertySettings , value : location , enumerable : options . sourcemap !== false } ) ;
1078+ Object . defineProperty ( node , 'loc' , {
1079+ ...definedPropertySettings ,
1080+ value : location ,
1081+ enumerable : options . sourcemap !== false
1082+ } ) ;
11141083 node . loc . end = { ...map . get ( delim ) . end } ;
11151084 // do not allow declarations in style sheets
11161085 if ( context . typ == EnumToken . StyleSheetNodeType && options . lenient ) {
@@ -1122,7 +1091,7 @@ function parseNode(results, context, options, errors, src, map, rawTokens, stats
11221091 const result = parseDeclarationNode ( node , errors , location ) ;
11231092 Object . defineProperty ( result , 'parent' , { ...definedPropertySettings , value : context } ) ;
11241093 if ( result != null ) {
1125- if ( options . validation == ValidationLevel . All ) {
1094+ if ( options . validation & ValidationLevel . Declaration ) {
11261095 const isAllowed = isNodeAllowedInContext ( node , context ) ;
11271096 // @ts -ignore
11281097 const valid = ! isAllowed ? {
@@ -1471,7 +1440,11 @@ function parseString(src, options = { location: false }) {
14711440 return acc ;
14721441 }
14731442 const token = getTokenType ( t . token , t . hint ) ;
1474- Object . defineProperty ( token , 'loc' , { ...definedPropertySettings , value : { sta : t . sta } , enumerable : options . location !== false } ) ;
1443+ Object . defineProperty ( token , 'loc' , {
1444+ ...definedPropertySettings ,
1445+ value : { sta : t . sta } ,
1446+ enumerable : options . location !== false
1447+ } ) ;
14751448 acc . push ( token ) ;
14761449 return acc ;
14771450 } , [ ] ) ) ;
0 commit comments