styled-jsx-postcss icon indicating copy to clipboard operation
styled-jsx-postcss copied to clipboard

Capture the CssSyntaxError object and throw error.

Open aga5tya opened this issue 8 years ago • 12 comments

Fixes giuseppeg/styled-jsx-postcss#5

aga5tya avatar Jan 22 '17 19:01 aga5tya

@aga5tya thank you! Can you add a test?

giuseppeg avatar Jan 23 '17 08:01 giuseppeg

@giuseppeg,, do i have to include a failure test case ? like a scenario expecting an error on the wrong styles. I'm new to unit testing stuff,, apologies in case its a trivial question.

aga5tya avatar Jan 23 '17 12:01 aga5tya

@aga5tya hey no worries!

like a scenario expecting an error on the wrong styles

correct I would add a new fixture to tests/fixtures with some css error e.g. a missing semicolon:

export default () => (
  <div>
    <style jsx>{`
        p {
           color: red
           width: 100%
        }
    `}</style>
  </div>
)

And then the test in test/index.js use t.throws https://github.com/avajs/ava#throwsfunctionpromise-error-message

giuseppeg avatar Jan 23 '17 15:01 giuseppeg

@giuseppeg , please review and guide. Updated the PR.

aga5tya avatar Feb 01 '17 17:02 aga5tya

+1 Great

rickyrauch avatar Feb 02 '17 20:02 rickyrauch

@aga5tya sorry I've been busy. The PR looks good, thank you!

While we are on it I was thinking that maybe we can print out some info about the error source too, what do you think?

I saw that the postcss error object has a showSourceCode method that is really nice!

Also since the PostCSS processor is not loading the css from a file we get something like:

CssSyntaxError: <css input>:1:32: Missed semicolon

Would you be interested in fixing this too? <css input> should be replaced with the component path and 1:32 with the locs in the component. Basically getCss should also return start and end – something like this

giuseppeg avatar Feb 03 '17 18:02 giuseppeg

@aga5tya want me to finish this branch?

giuseppeg avatar Mar 08 '17 14:03 giuseppeg

can't wait for this

rickyrauch avatar Mar 20 '17 21:03 rickyrauch

@giuseppeg, please do if you have time, i have been busy with lot of other things, won't have time until a month.

aga5tya avatar Mar 23 '17 06:03 aga5tya

we have styled-jsx-postcss working on scaleapi.com 💯

rickyrauch avatar May 24 '17 03:05 rickyrauch

Just curious, when will this get pulled into the current release?

metasean avatar Jun 28 '17 00:06 metasean

I want to see if we can ship plugins support to styled-jsx (there is an open PR for it) and in case convert this repo to a plugin for styled-jsx instead of doing parallel development.

giuseppeg avatar Jun 28 '17 08:06 giuseppeg