Skip to content

Print eventual lightning CSS parsing errors when the CSS matcher fail #14034

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

Merged
merged 1 commit into from
Jul 23, 2024

Conversation

philipp-spiess
Copy link
Member

@philipp-spiess philipp-spiess commented Jul 22, 2024

When working on adding a test case with the slightly more complex arbitrary variants names:

[&[data-foo=1]+.bar]:underline

we noticed that the CSS formatting helpers were giving us unhelpful diff outputs that would make it hard to find the issue.

It turns out that we try to normalize the CSS with lightningcss and automatically fall back to prettier if lightning fails. This caused confusion and quite a bit of time to understand what's going on. In our case, the CSS being generated by Tailwind was not adding quotes around attribute selectors which caused lightning to fail but prettier to automatically insert these quotes.

To fix this, we now capture any eventual lightning error and include it when the test matcher is going to fail (so we keep the tests that currently rely on this behavior clean while adding useful debug information for new tests).

Here's an example of the new error message:

Error: Error formatting using Lightning CSS:

```css
    text-decoration-line: underline
}
.data-\[id\=0\]\:underline[data-id=0] {
                                    ^-- SyntaxError: Invalid value in attribute selector: Number { has_sign: false, value: 0.0, int_value: Some(0) }
    text-decoration-line: underline
}
```

@philipp-spiess philipp-spiess merged commit 866860e into master Jul 23, 2024
13 checks passed
@philipp-spiess philipp-spiess deleted the ps/log-when-lightning-fails branch July 23, 2024 12:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants