1414//
1515////////////////////////////////////////////////////////////////////////////////
1616
17- const { FuzzedDataProvider } = require ( '@jazzer.js/core' )
18- const postcss = require ( '../../lib/postcss' )
17+ let { FuzzedDataProvider } = require ( '@jazzer.js/core' )
18+
19+ let postcss = require ( '../../lib/postcss' )
1920
2021module . exports . fuzz = function ( data ) {
21- const provider = new FuzzedDataProvider ( data )
22+ let provider = new FuzzedDataProvider ( data )
2223
2324 // The CSS input itself is randomized: every byte the fuzzer produces (or
2425 // mutates from the seed corpus) flows directly into `cssString` via
@@ -27,15 +28,15 @@ module.exports.fuzz = function (data) {
2728 // tail), so seed CSS files from postcss-parser-tests are fed into the
2829 // parser nearly verbatim, with only their last few bytes nibbled off as
2930 // option control.
30- const useMap = provider . consumeBoolean ( )
31- const useFrom = provider . consumeBoolean ( )
32- const useProcessor = provider . consumeBoolean ( )
33- const splitMode = provider . consumeIntegralInRange ( 0 , 2 )
34- const cssString = provider . consumeRemainingAsString ( )
31+ let useMap = provider . consumeBoolean ( )
32+ let useFrom = provider . consumeBoolean ( )
33+ let useProcessor = provider . consumeBoolean ( )
34+ let splitMode = provider . consumeIntegralInRange ( 0 , 2 )
35+ let cssString = provider . consumeRemainingAsString ( )
3536
36- const parseOptions = { }
37+ let parseOptions = { }
3738 if ( useFrom ) parseOptions . from = 'fuzz.css'
38- if ( useMap ) parseOptions . map = { inline : false , annotation : false }
39+ if ( useMap ) parseOptions . map = { annotation : false , inline : false }
3940
4041 let root
4142 try {
@@ -77,21 +78,21 @@ module.exports.fuzz = function (data) {
7778
7879 // Exercise the JSON serialization round-trip.
7980 try {
80- const json = root . toJSON ( )
81+ let json = root . toJSON ( )
8182 postcss . fromJSON ( json )
8283 } catch ( e ) {
83- if ( ! isExpected ( e , postcss ) ) throw e
84+ if ( ! isExpected ( e ) ) throw e
8485 }
8586
8687 // Exercise the main public entry point: postcss().process(). This drives
8788 // the LazyResult / NoWorkResult pipeline that real plugin chains use.
8889 if ( useProcessor ) {
8990 try {
90- const result = postcss ( ) . process ( cssString , parseOptions )
91+ let result = postcss ( ) . process ( cssString , parseOptions )
9192 void result . css
9293 void result . warnings ( )
9394 } catch ( e ) {
94- if ( ! isExpected ( e , postcss ) ) throw e
95+ if ( ! isExpected ( e ) ) throw e
9596 }
9697 }
9798
@@ -105,16 +106,16 @@ module.exports.fuzz = function (data) {
105106 postcss . list . split ( cssString , [ ',' , ' ' ] , false )
106107 }
107108 } catch ( e ) {
108- if ( ! isExpected ( e , postcss ) ) throw e
109+ if ( ! isExpected ( e ) ) throw e
109110 }
110111}
111112
112- function isExpected ( error , postcss ) {
113+ function isExpected ( error ) {
113114 if ( error instanceof postcss . CssSyntaxError ) return true
114115 if ( ! error || typeof error . message !== 'string' ) return false
115116 // Some legitimate inputs reach known-shaped TypeErrors during stringify or
116117 // walk because the CSS allows constructs whose textual form is ambiguous.
117118 // Suppress only those well-defined cases so real bugs still surface.
118- const benign = [ 'Unknown node type' , 'Unknown word' ]
119+ let benign = [ 'Unknown node type' , 'Unknown word' ]
119120 return benign . some ( msg => error . message . indexOf ( msg ) !== - 1 )
120121}
0 commit comments