Skip to content

Commit

Permalink
Fixed & search after consuming parenthesis
Browse files Browse the repository at this point in the history
  • Loading branch information
Andarist committed Dec 22, 2023
1 parent 7b0fac1 commit 97b7086
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/Parser.js
Expand Up @@ -43,8 +43,8 @@ export function parse (value, root, parent, rule, rules, rulesets, pseudo, point
switch (previous = character, character = next()) {
// (
case 40:
if (previous != 108 && charat(characters, length - 1) == 58) {
if (indexof(characters += replace(delimit(character), '&', '&\f'), '&\f') != -1)
if (charat(characters, length - 1) == 58) {
if (indexof(characters += replace(delimit(character), '&', '&\f'), '&\f', abs(points[index - 1])) != -1)
ampersand = -1
break
}
Expand Down
5 changes: 3 additions & 2 deletions src/Utility.js
Expand Up @@ -55,10 +55,11 @@ export function replace (value, pattern, replacement) {
/**
* @param {string} value
* @param {string} search
* @param {number} position
* @return {number}
*/
export function indexof (value, search) {
return value.indexOf(search)
export function indexof (value, search, position) {
return value.indexOf(search, position)
}

/**
Expand Down
15 changes: 15 additions & 0 deletions test/Parser.js
Expand Up @@ -142,6 +142,21 @@ describe('Parser', () => {
).to.equal(`.user [href="https://css-tricks.com?a=1&b=2"]{color:red;}`)
})

test('& in first selector within a comma-separated list', () => {
expect(
stylis(`
div {
display: flex;
&.foo,
p:not(:last-child) {
background: red;
}
}
`)
).to.equal(`.user div{display:flex;}.user div.foo,.user div p:not(:last-child){background:red;}`)
});

test('escaped chars in selector identifiers', () => {
expect(
stylis(`
Expand Down

0 comments on commit 97b7086

Please sign in to comment.