Skip to content

fix: error when a mixin call is used as a property value - #4478

Open
Lfan-ke wants to merge 1 commit into
less:masterfrom
Lfan-ke:fix/mixin-ruleset-as-value-error
Open

fix: error when a mixin call is used as a property value#4478
Lfan-ke wants to merge 1 commit into
less:masterfrom
Lfan-ke:fix/mixin-ruleset-as-value-error

Conversation

@Lfan-ke

@Lfan-ke Lfan-ke commented Jul 25, 2026

Copy link
Copy Markdown
Contributor

Using a mixin call directly as a property value (without a lookup) silently
emitted [object Object]:

#rgbify(@color) { @rgb: red(@color), green(@color), blue(@color); }
.x { color: #rgbify(#fff); }   // -> color: [object Object];

The mixin call resolves to its ruleset, which reaches the declaration as an
array of rules and renders as [object Object]. Declaration.eval already
rejects a DetachedRuleset used on a property with "Rulesets cannot be
evaluated on a property."; this extends that same guard to the array case, so
the mistake surfaces as a clear error instead of invalid output.

Only non-variable (property) declarations are affected, so valid uses such as
#ns.mixin()[@var] lookups, statement mixin calls, and passing a ruleset to
each() are unchanged. Added an eval-error test; pnpm test passes.

Closes #4305

Summary by CodeRabbit

  • Bug Fixes
    • Improved validation for mixins used directly as property values.
    • Prevented invalid mixin results from rendering as [object Object].
    • Added a clearer error indicating that rulesets cannot be evaluated on a property.

Signed-off-by: 林晨 (Leo Cheng) <leo-cheng@vip.qq.com>
@dosubot dosubot Bot added the size:S This PR changes 10-29 lines, ignoring generated files. label Jul 25, 2026
@coderabbitai

coderabbitai Bot commented Jul 25, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: ac841316-5cb7-47a4-9634-0b0dbbe16954

📥 Commits

Reviewing files that changed from the base of the PR and between ebbce6d and 41035ea.

📒 Files selected for processing (3)
  • packages/less/lib/less/tree/declaration.js
  • packages/test-data/tests-error/eval/mixin-as-value.less
  • packages/test-data/tests-error/eval/mixin-as-value.txt

📝 Walkthrough

Walkthrough

The declaration evaluator now reports an error when a mixin used as a property value evaluates to an array, and a regression fixture records the expected syntax error.

Changes

Mixin property-value validation

Layer / File(s) Summary
Reject array mixin results and verify the error
packages/less/lib/less/tree/declaration.js, packages/test-data/tests-error/eval/mixin-as-value.less, packages/test-data/tests-error/eval/mixin-as-value.txt
Declaration.eval rejects array results alongside detached rulesets, while the mixin-as-value fixture and expected output cover the resulting SyntaxError.

Estimated code review effort: 2 (Simple) | ~10 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the main change: raising an error for mixin calls used as property values.
Linked Issues check ✅ Passed The code and test changes address #4305 by erroring on mixin values that would otherwise render as [object Object].
Out of Scope Changes check ✅ Passed The PR stays focused on the mixin-as-value error fix and its test coverage, with no evident unrelated changes.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@greptile-apps

greptile-apps Bot commented Jul 25, 2026

Copy link
Copy Markdown

Greptile Summary

The PR prevents bare mixin calls used as property values from rendering as [object Object].

  • Extends Declaration.eval validation to reject array-valued ruleset results for non-variable declarations.
  • Adds an evaluation-error fixture covering a mixin call used directly as a property value.

Confidence Score: 5/5

The PR appears safe to merge, with the new guard narrowly covering raw rule arrays produced by mixin calls in property-value position.

The changed validation rejects the invalid array result before rendering, retains the existing detached-ruleset behavior, and excludes variable declarations; no other supported property-value evaluation path was found to produce a raw array.

Reviews (1): Last reviewed commit: "fix: error when a mixin call is used as ..." | Re-trigger Greptile

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

Labels

size:S This PR changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Provide error when mixin results in [object Object] value

1 participant