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

Fixed & search after consuming parenthesis #322

Merged
merged 4 commits into from
Dec 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Parser.js
Original file line number Diff line number Diff line change
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) {
thysultan marked this conversation as resolved.
Show resolved Hide resolved
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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) {
Andarist marked this conversation as resolved.
Show resolved Hide resolved
return value.indexOf(search, position)
}

/**
Expand Down
24 changes: 24 additions & 0 deletions test/Parser.js
Original file line number Diff line number Diff line change
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