Fixes#26290, #26291.
Also, many changes to follow refined parser acceptance line.
---
CI will fail until parser version bumped, needs oxc-project/oxc-css-parser/pull/166
- dispatcher
- string_embedder
- tailwind_sorter
Group these 3 together as `SessionServices`, make them available to `FormatSession`, and pass them around.
Fixes#23969, closes#23983.
Notably `oxc-css-parser@0.0.3` contains:
- partial `postcss-simple-vars` support
- fix glued css-in-js placeholder (`${C}:hover &`)
As `oxc_allocator` has also been added as a dependency in `oxc-css-parser`, this has caused a conflict with the latest local (workspace) instance, so a `patch.crates-io` section has also been added. Apparently, this is a technique also used in [Tokio](https://github.com/tokio-rs/tokio/blob/master/Cargo.toml#L18-L23).
Drop the manual custom-property reparse helper. Use the parser's `try_parsing_value_in_custom_property` option instead.
One new SCSS conformance failure (`scss/variables/apply-rule.scss`):
The new AST gives `SassNestingDeclaration` instead of token-soup, so the swallow case formats structurally instead of verbatim.
```scss
--p: { /* ... */ } /* <- nosemi */
--q: red;
```
CSS and Less are unaffected.
As we have forked the CSS parser, we can control how JS substitutions `${}` inside css-in-js are represented and how they interact.
We are no longer bound by Prettier’s conventions, allowing us to implement the code more efficiently.
- Before this PR: If `sortTailwindcss` option is enabled for CSS/LESS/SCSS, it was formatted by Prettier
- After this PR: `oxc_formatter_css` also handles `sortTailwindcss` as like `oxc_formatter` does
- Use `oxc_formatter_css` from Oxfmt to handle CSS/LESS/SCSS files
- css-in-js is also handled by `oxc_formatter_css`
- But it will fallback to Prettier if formatting failed
- No fallback for no-embedded path
- At the point of this PR, it will fallback to Prettier when tailwind is required to format
NOTE: Both fallback will be removed in later PR.
In that sense, as a result of this series of PRs, Oxfmt's CSS support will no longer be 100% compatible compared to Prettier.
Since the parsers used are also different, it will no longer be possible to support certain postcss-plugin-specific syntax, invalid syntax or legacy syntax.
> [!WARNING]
> TODO: Move fork under `oxc-project` org and replace refs
- Implement `oxc_formatter_css` crate
- Use `raffia` crate
- https://github.com/g-plane/raffia
- Supports CSS, LESS and SCSS
- Prettier uses `postcss` for parser
- https://github.com/prettier/prettier/blob/1c6ba5539141552e0e8e22d401ea620d8fdff468/package.json#L100-L105
Since design of `postcss`, this parser is very lenient with syntax.
Because of this, the AST is also less detailed, so formatting processes often rely on text-based.
On the other hand, `raffia` is relatively strict, so it cannot parse some postcss plugin syntax.
While this part clearly creates a difference from Prettier, we have judged that it is not an issue since it still supports major plugins syntax and aligns with current trends.