From 97b7086a9ac77f0f27c2056789a4405e4cb44325 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Burzy=C5=84ski?= Date: Sat, 23 Dec 2023 00:50:22 +0100 Subject: [PATCH] Fixed `&` search after consuming parenthesis --- src/Parser.js | 4 ++-- src/Utility.js | 5 +++-- test/Parser.js | 15 +++++++++++++++ 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/Parser.js b/src/Parser.js index e7472be..ed2d1ca 100644 --- a/src/Parser.js +++ b/src/Parser.js @@ -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 } diff --git a/src/Utility.js b/src/Utility.js index 8357dbc..d89838d 100644 --- a/src/Utility.js +++ b/src/Utility.js @@ -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) } /** diff --git a/test/Parser.js b/test/Parser.js index de0ddf4..e05a42f 100644 --- a/test/Parser.js +++ b/test/Parser.js @@ -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(`