Skip to content
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

swc_css_parser throws exception when parsing oklch/oklab color function with certain arguments #9766

Open
Dwlad90 opened this issue Nov 27, 2024 · 0 comments
Labels

Comments

@Dwlad90
Copy link

Dwlad90 commented Nov 27, 2024

Describe the bug

With certain arguments it is not possible to parse the CSS function oklch, as a result of which the following error occurs:

  • Expected 'e', 'pi', 'infinity', '-infinity' or 'NaN', ident tokens
  • Called Result::unwrap() on an Err value: x Unexpected value

The same problem also occur with the function oklab.

Input code

* { color: oklch(from green l c h / 0.5) }

* { color: oklch(from #0000FF calc(l + 0.1) c h) }

* { color: oklch(from #000 calc(l + 0.2) c h) }

* { background-image: radial-gradient(circle at 0% 0%, oklch(from var(--colors-tile-background) calc(l + 0.1) calc(c + 0.2) h) 0, transparent 15% ), radial-gradient( circle at 80% 100%, oklch(from var(--colors-tile-background) calc(l - 0.25) calc(c + 0.01) h) 0, transparent 30% ), linear-gradient( 45deg, var(--colors-tile-background) 0%, oklch(from var(--colors-tile-background) calc(l - 0.1) calc(c + 0.3) h) 100% ) }

* { box-shadow: 0 0 calc(var(--x1gppajd) * 10) 0 oklch(from var(--colors-tile-background) l c h / 0.15) }

* { color: oklch(from #021310 l c h / 0.9) }

* { color: oklab(from green l a b / 0.5) }

* { color: oklab(from #0000FF calc(l + 0.1) a b / calc(alpha * 0.9)) }

Config

No response

Playground link (or link to the minimal reproduction)

https://github.com/Dwlad90/swc/tree/bug/oklch

SWC Info output

---- pass_tests__fixture__value__color__input_css stdout ----
Input: ~/Projects/swc/crates/swc_css_parser/tests/fixture/value/color/input.css
thread 'pass_tests__fixture__value__color__input_css' panicked at crates/swc_css_parser/tests/fixture.rs:77:6:
called `Result::unwrap()` on an `Err` value:   x Expected 'e', 'pi', 'infinity', '-infinity' or 'NaN', ident tokens
    ,-[$DIR/tests/fixture/value/color/input.css:97:1]
 96 |     color: oklab(var(--a) var(--b) var(--c));
 97 |     color: oklab(from #0000FF calc(l + 0.1) a b / calc(alpha * 0.9));
    :                                    ^
 98 |     color: oklab(from green l a b / 0.5)
    `----
  x Expected 'none' value of an ident token
    ,-[$DIR/tests/fixture/value/color/input.css:97:1]
 96 |     color: oklab(var(--a) var(--b) var(--c));
 97 |     color: oklab(from #0000FF calc(l + 0.1) a b / calc(alpha * 0.9));
    :                                             ^
 98 |     color: oklab(from green l a b / 0.5)
    `----
  x Expected 'none' value of an ident token
    ,-[$DIR/tests/fixture/value/color/input.css:98:1]
 97 |     color: oklab(from #0000FF calc(l + 0.1) a b / calc(alpha * 0.9));
 98 |     color: oklab(from green l a b / 0.5)
    :                             ^
 99 | }
    `----
  x Expected 'e', 'pi', 'infinity', '-infinity' or 'NaN', ident tokens
     ,-[$DIR/tests/fixture/value/color/input.css:106:1]
 105 |     color: oklch(var(--a) var(--b) var(--c) / var(--d));
 106 |     color: oklch(from #000 calc(l + 0.2) c h);
     :                                 ^
 107 |     color: oklch(from #021310 l c h / 0.9);
     `----
  x Expected 'none' value of an ident token
     ,-[$DIR/tests/fixture/value/color/input.css:106:1]
 105 |     color: oklch(var(--a) var(--b) var(--c) / var(--d));
 106 |     color: oklch(from #000 calc(l + 0.2) c h);
     :                                          ^
 107 |     color: oklch(from #021310 l c h / 0.9);
     `----
  x Expected 'none' value of an ident token
     ,-[$DIR/tests/fixture/value/color/input.css:107:1]
 106 |     color: oklch(from #000 calc(l + 0.2) c h);
 107 |     color: oklch(from #021310 l c h / 0.9);
     :                               ^
 108 | }
     `----

note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace


failures:
    pass_tests__fixture__value__color__input_css

Expected behavior

Correct parsing to valid AST

Actual behavior

No response

Version

4.0.0

Additional context

Link to SWC CSS Playground

To reproduce the error, please run cargo test -p swc_css_parser in the provided repo

Thanks to @HQ92 for finding the bug,
Original issue: Dwlad90/stylex-swc-plugin#119

@Dwlad90 Dwlad90 added the C-bug label Nov 27, 2024
@Dwlad90 Dwlad90 changed the title swc_css_parser throws exception when parsing oklch color function with certain arguments swc_css_parser throws exception when parsing oklch/oklab color function with certain arguments Nov 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

1 participant