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
Conversation
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.
Need fix CI
Those look like legit test failures. I'l need to investigate what is happening. |
74bdc5f
to
c1224f5
Compare
Cannot update past Interestingly there's a regression in See the |
c1224f5
to
8f9f3f4
Compare
We should wait fix in this case |
We could maybe skip the |
Sounds good |
As there is no practical difference between an invalid SVG and an SVG that SVGO cannot parse, just try to parse input with SVGO directly. Also remove dependency on extra XML parsers.
8f9f3f4
to
22d2a18
Compare
@@ -203,19 +209,6 @@ test( | |||
) | |||
); | |||
|
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 the svgo
stage.
packages/postcss-svgo/src/index.js
Outdated
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 comment
The 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 comment
The 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 postcss-calc
, if we can't parse it just log warning, so developers can report about it and we still continue work), let's use console.warn
and continue work
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.
Doesn't postcss have warn
method?
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.
oh, yep, forgot about it
I don't get why do we even need to check something? |
I 99% agree with you. Except in the context of cssnano I would not throw on invalid SVG , as it might be preferable to skip minification of that particular section rather than crashing completely. |
So let's avoid using |
Handle all SVGO failures in the same way, as there is no practical difference between being unable to parse and being unable to optimise.
Hopefully this will stop further alarmed comments.