Skip to content

Commit

Permalink
Fixed & search after consuming parenthesis (#322)
Browse files Browse the repository at this point in the history
* Fixed `&` search after consuming parenthesis

* add an extra test case

* perf squeezing

* bring back `'l'` check
  • Loading branch information
Andarist committed Dec 27, 2023
1 parent 7b0fac1 commit 3b9b321
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/Parser.js
Expand Up @@ -44,7 +44,7 @@ export function parse (value, root, parent, rule, rules, rulesets, pseudo, point
// (
case 40:
if (previous != 108 && charat(characters, length - 1) == 58) {
if (indexof(characters += replace(delimit(character), '&', '&\f'), '&\f') != -1)
if (indexof(characters += replace(delimit(character), '&', '&\f'), '&\f', abs(index ? points[index - 1] : 0)) != -1)
ampersand = -1
break
}
Expand Down
4 changes: 2 additions & 2 deletions src/Prefixer.js
Expand Up @@ -87,7 +87,7 @@ export function prefix (value, length, children) {
// grid-(row|column)-start
case 4384: case 3616:
if (children && children.some(function (element, index) { return length = index, match(element.props, /grid-\w+-end/) })) {
return ~indexof(value + (children = children[length].value), 'span') ? value : (MS + replace(value, '-start', '') + value + MS + 'grid-row-span:' + (~indexof(children, 'span') ? match(children, /\d+/) : +match(children, /\d+/) - +match(value, /\d+/)) + ';')
return ~indexof(value + (children = children[length].value), 'span', 0) ? value : (MS + replace(value, '-start', '') + value + MS + 'grid-row-span:' + (~indexof(children, 'span', 0) ? match(children, /\d+/) : +match(children, /\d+/) - +match(value, /\d+/)) + ';')
}
return MS + replace(value, '-start', '') + value
// grid-(row|column)-end
Expand All @@ -113,7 +113,7 @@ export function prefix (value, length, children) {
return replace(value, /(.+:)(.+)-([^]+)/, '$1' + WEBKIT + '$2-$3' + '$1' + MOZ + (charat(value, length + 3) == 108 ? '$3' : '$2-$3')) + value
// (s)tretch
case 115:
return ~indexof(value, 'stretch') ? prefix(replace(value, 'stretch', 'fill-available'), length, children) + value : value
return ~indexof(value, 'stretch', 0) ? prefix(replace(value, 'stretch', 'fill-available'), length, children) + value : value
}
break
// grid-(column|row)
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
24 changes: 24 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 Expand Up @@ -858,6 +873,15 @@ describe('Parser', () => {
].join(''))
})

test('context character IX', () => {
expect(
stylis(`background: url(i&m&g.png);.a {background: url(i&m&g.png);}`)
).to.equal([
`.user{background:url(i&m&g.png);}`,
`.user .a{background:url(i&m&g.png);}`
].join(''))
})

test('`--` in an identifier (#220)', () => {
expect(
stylis(`
Expand Down

0 comments on commit 3b9b321

Please sign in to comment.