@@ -154,7 +154,6 @@ async function doParse(iter, options = {}) {
154
154
const preVisitorsHandlersMap = new Map ;
155
155
const visitorsHandlersMap = new Map ;
156
156
const postVisitorsHandlersMap = new Map ;
157
- // const allValuesHandlers = new Map as Map<EnumToken, Array<GenericVisitorHandler<Token>>>;
158
157
const rawTokens = [ ] ;
159
158
const imports = [ ] ;
160
159
let item ;
@@ -240,42 +239,6 @@ async function doParse(iter, options = {}) {
240
239
errors . push ( { action : 'ignore' , message : `doParse: visitor.${ key } is not a valid key name` } ) ;
241
240
}
242
241
}
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
- // }
279
242
}
280
243
while ( item = isAsync ? ( await iter . next ( ) ) . value : iter . next ( ) . value ) {
281
244
stats . bytesIn = item . bytesIn ;
@@ -435,6 +398,8 @@ async function doParse(iter, options = {}) {
435
398
if ( options . expandNestingRules ) {
436
399
ast = expand ( ast ) ;
437
400
}
401
+ let replacement ;
402
+ let callable ;
438
403
for ( const result of walk ( ast ) ) {
439
404
if ( valuesHandlers . size > 0 || preVisitorsHandlersMap . size > 0 || visitorsHandlersMap . size > 0 || postVisitorsHandlersMap . size > 0 ) {
440
405
if ( ( result . node . typ == EnumToken . DeclarationNodeType &&
@@ -455,14 +420,13 @@ async function doParse(iter, options = {}) {
455
420
// @ts -ignore
456
421
handlers . push ( ...postVisitorsHandlersMap . get ( key ) ) ;
457
422
}
458
- let callable ;
459
423
let node = result . node ;
460
424
for ( const handler of handlers ) {
461
425
callable = typeof handler == 'function' ? handler : handler [ normalizeVisitorKeyName ( node . typ == EnumToken . DeclarationNodeType || node . typ == EnumToken . AtRuleNodeType ? node . nam : node . val ) ] ;
462
426
if ( callable == null ) {
463
427
continue ;
464
428
}
465
- let replacement = callable ( node , result . parent ) ;
429
+ replacement = callable ( node , result . parent ) ;
466
430
if ( replacement == null ) {
467
431
continue ;
468
432
}
@@ -500,8 +464,7 @@ async function doParse(iter, options = {}) {
500
464
}
501
465
let node = result . node ;
502
466
for ( const callable of handlers ) {
503
- // @ts -ignore
504
- let replacement = callable ( node , result . parent ) ;
467
+ replacement = callable ( node , result . parent ) ;
505
468
if ( replacement == null ) {
506
469
continue ;
507
470
}
@@ -526,13 +489,12 @@ async function doParse(iter, options = {}) {
526
489
}
527
490
}
528
491
else if ( valuesHandlers . size > 0 ) {
529
- let callable ;
530
492
let node = null ;
531
493
node = result . node ;
532
494
if ( valuesHandlers . has ( node . typ ) ) {
533
495
for ( const valueHandler of valuesHandlers . get ( node . typ ) ) {
534
496
callable = valueHandler ;
535
- let replacement = callable ( node , result . parent ) ;
497
+ replacement = callable ( node , result . parent ) ;
536
498
if ( replacement == null ) {
537
499
continue ;
538
500
}
@@ -828,7 +790,7 @@ function parseNode(results, context, options, errors, src, map, rawTokens, stats
828
790
}
829
791
const isAllowed = isNodeAllowedInContext ( node , context ) ;
830
792
// @ts -ignore
831
- const valid = options . validation == ValidationLevel . None ? {
793
+ const valid = ( options . validation & ValidationLevel . AtRule ) == 0 ? {
832
794
valid : SyntaxValidationResult . Valid ,
833
795
error : '' ,
834
796
node,
@@ -964,12 +926,11 @@ function parseNode(results, context, options, errors, src, map, rawTokens, stats
964
926
value : loc ,
965
927
enumerable : options . sourcemap !== false
966
928
} ) ;
967
- // @ts -ignore
968
929
context . chi . push ( node ) ;
969
930
Object . defineProperty ( node , 'parent' , { ...definedPropertySettings , value : context } ) ;
970
931
const isAllowed = isNodeAllowedInContext ( node , context ) ;
971
932
// @ts -ignore
972
- const valid = options . validation == ValidationLevel . None ? {
933
+ const valid = ( options . validation & ValidationLevel . Selector ) == 0 ? {
973
934
valid : SyntaxValidationResult . Valid ,
974
935
error : null
975
936
} : ! isAllowed ? {
@@ -1084,7 +1045,11 @@ function parseNode(results, context, options, errors, src, map, rawTokens, stats
1084
1045
nam,
1085
1046
val : [ ]
1086
1047
} ;
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
+ } ) ;
1088
1053
context . chi . push ( node ) ;
1089
1054
stats . nodesCount ++ ;
1090
1055
}
@@ -1110,7 +1075,11 @@ function parseNode(results, context, options, errors, src, map, rawTokens, stats
1110
1075
nam,
1111
1076
val : value
1112
1077
} ;
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
+ } ) ;
1114
1083
node . loc . end = { ...map . get ( delim ) . end } ;
1115
1084
// do not allow declarations in style sheets
1116
1085
if ( context . typ == EnumToken . StyleSheetNodeType && options . lenient ) {
@@ -1122,7 +1091,7 @@ function parseNode(results, context, options, errors, src, map, rawTokens, stats
1122
1091
const result = parseDeclarationNode ( node , errors , location ) ;
1123
1092
Object . defineProperty ( result , 'parent' , { ...definedPropertySettings , value : context } ) ;
1124
1093
if ( result != null ) {
1125
- if ( options . validation == ValidationLevel . All ) {
1094
+ if ( options . validation & ValidationLevel . Declaration ) {
1126
1095
const isAllowed = isNodeAllowedInContext ( node , context ) ;
1127
1096
// @ts -ignore
1128
1097
const valid = ! isAllowed ? {
@@ -1471,7 +1440,11 @@ function parseString(src, options = { location: false }) {
1471
1440
return acc ;
1472
1441
}
1473
1442
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
+ } ) ;
1475
1448
acc . push ( token ) ;
1476
1449
return acc ;
1477
1450
} , [ ] ) ) ;
0 commit comments