giuseppeg / styled-jsx-postcss

Use PostCSS with styled-jsx 💥
MIT License
64 stars 11 forks source link

Capture the CssSyntaxError object and throw error. #6

Open aga5tya opened 7 years ago

aga5tya commented 7 years ago

Fixes giuseppeg/styled-jsx-postcss#5

giuseppeg commented 7 years ago

@aga5tya thank you! Can you add a test?

aga5tya commented 7 years ago

@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.

giuseppeg commented 7 years ago

@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

aga5tya commented 7 years ago

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

rickyrauch commented 7 years ago

+1 Great

giuseppeg commented 7 years ago

@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 commented 7 years ago

@aga5tya want me to finish this branch?

rickyrauch commented 7 years ago

can't wait for this

aga5tya commented 7 years ago

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

rickyrauch commented 7 years ago

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

metasean commented 7 years ago

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

giuseppeg commented 7 years ago

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.