parcel-bundler / parcel-bundler/lightningcss

Wrong selector output

Open
#595 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
7.7k
Forks
302
PR merge metrics
No merged PRs in 30d

Description

Repro: https://lightningcss.dev/playground/index.html#%7B%22minify%22%3Atrue%2C%22customMedia%22%3Atrue%2C%22cssModules%22%3Afalse%2C%22analyzeDependencies%22%3Afalse%2C%22targets%22%3A%7B%22chrome%22%3A6225920%7D%2C%22include%22%3A0%2C%22exclude%22%3A0%2C%22source%22%3A%22*%20%2B%20*%20%7B%5Cn%20%20color%3A%20red%3B%5Cn%7D%22%2C%22visitorEnabled%22%3Atrue%2C%22visitor%22%3A%22%7B%5Cn%20%20Selector(node)%20%7B%5Cn%20%20%20%20return%20%5B%5Cn%20%20%20%20%20%20%7B%20type%3A%20'universal'%20%7D%2C%5Cn%20%20%20%20%20%20%7B%20type%3A%20'combinator'%2C%20value%3A%20'descendant'%20%7D%2C%5Cn%20%20%20%20%20%20%7B%20type%3A%20'combinator'%2C%20value%3A%20'next-sibling'%20%7D%2C%5Cn%20%20%20%20%20%20%7B%20type%3A%20'combinator'%2C%20value%3A%20'descendant'%20%7D%2C%5Cn%20%20%20%20%20%20%7B%20type%3A%20'universal'%20%7D%5Cn%20%20%20%20%5D%3B%5Cn%20%20%7D%5Cn%7D%22%2C%22unusedSymbols%22%3A%5B%5D%2C%22version%22%3A%22local%22%7D

I'm trying to convert a sequence of tokens (from a custom-function) into a selector list.

For example (as seen in the repro), if we have * + * parsed as a token list:

[
  { type: 'token', value: { type: 'delim', value: '*' } },
  { type: 'token', value: { type: 'white-space', value: ' ' } },
  { type: 'token', value: { type: 'delim', value: '+' } },
  { type: 'token', value: { type: 'white-space', value: ' ' } },
  { type: 'token', value: { type: 'delim', value: '*' } }
]

the output selector list should be

[
  { type: 'universal' },
  { type: 'combinator', value: 'descendant' },
  { type: 'combinator', value: 'next-sibling' },
  { type: 'combinator', value: 'descendant' },
  { type: 'universal' }
]

the expected output should be * + *, but it emits * *+.

Version-wise, this used to work in 1.19 and 1.20, stopped working in 1.21

Edit: it seems in <1.21, whitespace token is always skipped, whereas in >1.21, it is included.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the playground reproduction and compare selector conversion behavior between versions 1.20 and 1.21. Trace how custom-function token lists handle whitespace and combinators; done means the supplied * + * tokens produce the expected selector list and serialize as * + *.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, rust
Domain
compilers, web-dev
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.