Fix parsing bug in SelectorParser (#20090)
While working on another feature, I noticed that a selector such as
`.foo::before` was parsed as:
```ts
[
{
kind: 'compound',
nodes: [
{ kind: 'selector', value: '.foo' },
{ kind: 'selector', value: ':' },
{ kind: 'selector', value: '::before' },
],
},
]
```
Instead of:
```ts
[
{
kind: 'compound',
nodes: [
{ kind: 'selector', value: '.foo' },
{ kind: 'selector', value: '::before' },
],
},
]
```
So far this hasn't been a real issue in practice, but it is in a
follow-up PR that I'm working on. To keep things separated, I wanted to
fix this behavior in a dedicated PR instead.
## Test plan
1. Added a test case for this situation
2. Other tests still pass
This commit is contained in:
parent
2c4726d3d5
commit
d03edefd19
2 changed files with 17 additions and 0 deletions
|
|
@ -21,6 +21,18 @@ describe('parse', () => {
|
|||
])
|
||||
})
|
||||
|
||||
it('should parse a pseudo-element selector with double ::', () => {
|
||||
expect(parse('.foo::before')).toEqual([
|
||||
{
|
||||
kind: 'compound',
|
||||
nodes: [
|
||||
{ kind: 'selector', value: '.foo' },
|
||||
{ kind: 'selector', value: '::before' },
|
||||
],
|
||||
},
|
||||
])
|
||||
})
|
||||
|
||||
it('should parse a selector list', () => {
|
||||
expect(parse('.foo,.bar')).toEqual([
|
||||
{
|
||||
|
|
|
|||
|
|
@ -387,6 +387,11 @@ export function parse(input: string) {
|
|||
case FULL_STOP:
|
||||
case COLON:
|
||||
case NUMBER_SIGN: {
|
||||
if (currentChar === COLON && buffer === ':') {
|
||||
buffer += input[i]
|
||||
break
|
||||
}
|
||||
|
||||
// Handle everything before the combinator as a selector and
|
||||
// start a new selector
|
||||
if (buffer.length > 0) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue