Skip to content

Support at-rule property definitions in variable renaming#88

Merged
nex3 merged 5 commits intogoogle:masterfrom
ertgl:at-rule-property
Apr 10, 2026
Merged

Support at-rule property definitions in variable renaming#88
nex3 merged 5 commits intogoogle:masterfrom
ertgl:at-rule-property

Conversation

@ertgl
Copy link
Copy Markdown
Contributor

@ertgl ertgl commented Mar 31, 2026

This PR adds support for renaming variables in CSS @property definitions. Resolves #82.

To maintain consistency with the existing codebase, I've implemented an AtRule.property processor using:

  • renameVariable for property names
  • renameDeclaration for internal declarations

I have added test cases to verify the implementation across all core strategies:

  • none
  • debug
  • minimal (including both declaration-first and property-first orderings)

If any further adjustments are needed, please let me know.

@nex3 nex3 self-assigned this Apr 6, 2026
@nex3 nex3 self-requested a review April 6, 2026 20:51
Copy link
Copy Markdown
Collaborator

@nex3 nex3 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 working on this! A few relatively small changes and I think we can land it.

src/variable.ts Outdated
Comment on lines +136 to +138
atRuleNode.walkDecls(declarationNode => {
renameDeclaration(declarationNode);
});
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I don't think this is necessary, because it's never valid to refer to variables within a @property declaration.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the guidance! I initially handled this case to cover broader plugin scenarios, referencing the example in the related issue. I've simplified it now, and it turns out the refined version alone is still enough to implicitly support variable references in that example.


describe('with @property (contains initial-value)', () => {
const input =
'@property --test-property { syntax: "<angle>"; initial-value: var(--initial); }';
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This isn't a valid example for a couple reasons: not only can you not reference a variable in initial-value, a @property rule must contain inherits in order to not be discarded. We should probably make all examples run on valid @property rules.

Also, as a style nit, use a multi-line string if the string doesn't fit within 80 columns.

Copy link
Copy Markdown
Contributor Author

@ertgl ertgl Apr 8, 2026

Choose a reason for hiding this comment

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

Thanks for the clarification! I've updated the examples and the formatting.

By the way, Prettier suggests formatting for a few unrelated files:

  • .github/workflows/ci.yml
  • CHANGELOG.md
  • README.md

Should we apply those changes before the CI check?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Anything that's not covered by gts check I'm not particularly interested in keeping formatted to Prettier's standards.

Comment on lines +1029 to +1032
@property --test-property {
syntax: "<angle>";
inherits: false;
}`;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Either set syntax: "*" or give this an initial value; otherwise it's invalid per spec.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Updated to syntax: "*".

@nex3 nex3 merged commit b777060 into google:master Apr 10, 2026
3 checks passed
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.

Add support for @property in variable renaming

2 participants