Skip to content

Conversation

@yisibl
Copy link
Contributor

@yisibl yisibl commented Oct 30, 2025

@yisibl yisibl force-pushed the add-revert-rule branch 4 times, most recently from e6cdc61 to 2f5d56a Compare October 31, 2025 04:41
@yisibl yisibl marked this pull request as ready for review October 31, 2025 04:42
Copy link
Owner

@evanw evanw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for noticing this new CSS keyword and getting this change together. The addition of revert-rule to cssWideAndReservedKeywords looks good to me. But you marked this as a draft so I'm commenting instead of accepting it in case you're still working on it.

expectPrinted(t, "div { animation: 2s linear 'name 2', 3s infinite 'name 3' }", "div {\n animation: 2s linear name\\ 2, 3s infinite name\\ 3;\n}\n", "")
}

func TestCSSWideKeywords(t *testing.T) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do these tests cover? I could be misunderstanding something but it seems like these tests would behave the same with and without this change, which means the tests in this function aren't covering anything and can be removed.

expectPrintedMangleMinify(t, "a {font-family: 'unset', serif;}", "a{font-family:\"unset\",serif}", "")
expectPrintedMangleMinify(t, "a {font-family: 'revert', serif;}", "a{font-family:\"revert\",serif}", "")
expectPrintedMangleMinify(t, "a {font-family: 'revert-layer', 'Segoe UI', serif;}", "a{font-family:\"revert-layer\",Segoe UI,serif}", "")
expectPrintedMangleMinify(t, "a {font-family: 'revert-rule', 'Segoe UI', serif;}", "a{font-family:\"revert-rule\",Segoe UI,serif}", "")
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test helped me understand the implications of this change. Thank you very much for adding it!

@@ -1,5 +1,20 @@
# Changelog

* Add support for the new [`revert-rule`](https://drafts.csswg.org/css-cascade-5/#revert-rule-keyword) CSS-wide keyword ([#4312](https://github.com/evanw/esbuild/pull/4312))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure this change needs to be called out in the release notes as it's a very subtle change (basically esbuild will now keep quotes around fonts, containers, and animations named revert-rule) that seems unlikely to come up in practice. These release notes make it seem like esbuild has added some kind of support for if() expressions, which is not the case.

Copy link
Contributor Author

@yisibl yisibl Nov 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing the if() statement also works. I think modifying the example like this might make it easier to understand.

The revert-rule allows CSS custom properties to switch to a predefined value. When --radius-flag is undefined, the revert-rule can reset it to border-radius: 20px. Once a value is defined, it switches to the size you want.

 data:text/html;charset=UTF-8,<!DOCTYPE html>
<style>
div {
  width: 100px;
  height: 100px;
  border: 1px solid;
  border-radius: 20px;
}
.apply-square {
  --radius-flag: 0px;
  border-radius: var(--radius-flag, revert-rule);
}
</style>
<div class="apply-square"></div>

Therefore, I believe this could become a popular feature in the future, and incorporating it into documentation will help people better understand it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants