Skip to content

Detached Rulesets and local scope protection #2064

Closed
@SomMeri

Description

@SomMeri

Variables returned from detached ruleset behave differently then variables returned from mixins:

  • Variables returned from mixins are copied into caller scope only if they are not present in local scope. However, there is no protection for parent scope.
  • Variables returned from detached rulesets are copied into caller scope only if the caller scope does not contain them at all. Both local and parent scope are protected.

Example with detached rulesets:

.wrap-mixin(@ruleset) {
  @b: non-local; // parent scope is protected
  .wrap-selector {
      @ruleset(); // variable returned from detached ruleset is ignored
      visible-one: @b; 
    }
}

.wrap-mixin({
  @b: returned from detached ruleset;
}); // call the whole thing

compiles into:

.wrap-selector {
  visible-one: non-local;
}

Example with mixins:

.ruleset-mixin() {
  @b-mixin: returned from mixin;
}

.wrap-mixin-mixin() {
  @b-mixin: non-local; // parent scope - no protection
  .wrap-selector {
      .ruleset-mixin(); // variable returned from mixin wins over the one defined in parent scope
      visible-one: @b-mixin;
    }
}

.wrap-mixin-mixin(); // call the whole thing

compiles into:

.wrap-selector {
  visible-one: returned from mixin;
}

Expected behavior: mixins and detached rulesets should implement the same caller scope protection. Since detached rulesets are new feature and mixins old one, mixins should win and both of them should protect only local scope.

Tested with lessc 1.7.0 on windows node-js.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions