postcss / postcss-safe-parser

Fault tolerant CSS parser for PostCSS
MIT License
120 stars 12 forks source link

SafeParser fails to parse line #7

Closed domderen closed 7 years ago

domderen commented 7 years ago

SafeParser has failed to parse this CSS contents:

.wrap .bluebutton {
    background: filter: progid:DXImageTransform.Microsoft.gradient(startColorStr='#2e9fbc', EndColorStr='#066791');
}

I know that background: filter: ... is not a correct usage, but it shouldn't crash the whole parsing process. Right now it fails with:

TypeError: Cannot read property '0' of undefined
    at SafeParser.decl (/proj/node_modules/postcss/lib/parser.js:203:25)
    at SafeParser.decl (/proj/node_modules/postcss-safe-parser/lib/safe-parser.js:60:36)
    at SafeParser.precheckMissedSemicolon (/proj/node_modules/postcss-safe-parser/lib/safe-parser.js:98:14)
    at SafeParser.decl (/proj/node_modules/postcss/lib/parser.js:236:14)
    at SafeParser.decl (/proj/node_modules/postcss-safe-parser/lib/safe-parser.js:60:36)
    at SafeParser.other (/proj/node_modules/postcss/lib/parser.js:135:30)
    at SafeParser.loop (/proj/node_modules/postcss/lib/parser.js:81:26)
    at safeParse (/proj/node_modules/postcss-safe-parser/lib/safe-parse.js:21:12)
    at new LazyResult (/proj/node_modules/postcss/lib/lazy-result.js:70:24)
    at Processor.process (/proj/node_modules/postcss/lib/processor.js:117:12)

Of if safe parser has to fail, it should throw an instance of CssSyntaxError to be able to find the faulty line number.

ai commented 7 years ago

Thanks. I will try to fix it on this weekend.

domderen commented 7 years ago

@ai Thanks, that would be great. I'm also happy to help with a PR, but just wasn't sure of the direction. Should the parser try to handle this exception gracefully? For example should it be handled in precheckMissedSemicolon? Or should it catch the exception, and return it as CssSyntaxError?

ai commented 7 years ago

Done 7c3e589

ai commented 7 years ago

SafeParser idea is never return CssSyntaxError :D. At least it should ignore the code.

ai commented 7 years ago

Released in 3.0.1

domderen commented 7 years ago

That was super fast, thanks! ;)