New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor: remove is-svg #1034
refactor: remove is-svg #1034
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
import valueParser from 'postcss-value-parser'; | ||
import { optimize } from 'svgo'; | ||
import isSvg from 'is-svg'; | ||
import { encode, decode } from './lib/url'; | ||
|
||
const PLUGIN = 'postcss-svgo'; | ||
|
@@ -48,14 +47,13 @@ function minify(decl, opts) { | |
} | ||
} | ||
|
||
if (!isSvg(svg)) { | ||
return; | ||
} | ||
|
||
let result; | ||
try { | ||
result = optimize(svg, opts); | ||
if (result.error) { | ||
if (result.error.startsWith('Error in parsing SVG')) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I could not find a better way to detect the cause of the error. Maybe @TrySound has got a better suggestion? Anyway I wonder whether it makes sense to throw an error just because we cannot process sommething, instead of just leaving it alone. See this comment #910 (comment) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we don't need throw the error in this cases (and all cases, for example There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Doesn't postcss have There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. oh, yep, forgot about it |
||
return; | ||
} | ||
throw new Error(`${PLUGIN}: ${result.error}`); | ||
} | ||
} catch (error) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have changed these tests because I 've realized there is no meaningful difference between these cases. They're all invalid SVGs. They were handled separately because some failed at the
isSvg
stage and some at thesvgo
stage.