Skip to content

Commit

Permalink
Fixed & search after consuming parenthesis
Browse files Browse the repository at this point in the history
  • Loading branch information
yoli799480165 committed May 29, 2024
1 parent 7fbc508 commit 0cd2484
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/Compiler/Parser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public static List<Element> Parse(Tokenizer tokenizer, string value, Element roo
case 40:
if (previous != 108 && CharAt(characters, length - 1) == 58)
{
if (IndexOf(characters += Replace(tokenizer.Delimit(character), "&", "&\f"), "&\f") != -1)
if (IndexOf(characters += Replace(tokenizer.Delimit(character), "&", "&\f"), "&\f", Abs(index != 0 ? points[index - 1] : 0)) != -1)
ampersand = -1;
break;
}
Expand Down
4 changes: 2 additions & 2 deletions src/Compiler/Utility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ public static int CharAt(string value, int index)
return (int) value[index];
}

public static int IndexOf(string value, string search)
public static int IndexOf(string value, string search, int position)
{
return value.IndexOf(search);
return value.IndexOf(search, position);
}

public static string Replace(string value, string pattern, string replacement, bool all = false)
Expand Down
19 changes: 19 additions & 0 deletions test/CssInCSharp.Tests/ParserTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,21 @@ public void Ampersand_In_String()
).ShouldBe(".user [href=\"https://css-tricks.com?a=1&b=2\"]{color:red;}");
}

[Fact]
public void Ampersand_In_First_Selector_Within_A_CommaSeparated_List()
{
stylis(@"
div {
display: flex;
&.foo,
p:not(:last-child) {
background: red;
}
}
").ShouldBe(".user div{display:flex;}.user div.foo,.user div p:not(:last-child){background:red;}");
}

[Fact]
public void Escaped_Chars_In_Selector_Identifiers()
{
Expand Down Expand Up @@ -769,6 +784,10 @@ public void Context_Character()
.ShouldBe(string.Join("",
".user{background:url[img}.png];}",
".user .a{background:url[img}.png];}"));
stylis("background: url(i&m&g.png);.a {background: url(i&m&g.png);}")
.ShouldBe(string.Join("",
".user{background:url(i&m&g.png);}",
".user .a{background:url(i&m&g.png);}"));
}

[Fact]
Expand Down

0 comments on commit 0cd2484

Please sign in to comment.