Skip to content

Namespace with parameters  #1525

Closed
Closed

Description

@SomMeri

Namespace can have parameters, but work differently then namespaces without parameters.

Following less compiles:

#namespace-with-parameter(@parameter, @argument) {
  #nested-just-because(@p1, @p2) {
     use-params: @p1 @parameter;
    .mixin() {
      this: works;
    }
  }
}

#use-place {
  #namespace-with-parameter > #nested-just-because > .mixin();
}

into:

#use-place {
  this: works;
}

The difference against normal namespaces is that mixins importing/unlocking does not work. This:

.importer() {
  .mixin() {
    declaration: 222;
  }
}
#namespace-with-parameter {
  #nested-just-because(@p1, @p2) { //unused parameters
    .importer();
    .mixin() {
      this: works;
    }
  }
}

#use-place {
  #namespace-with-parameter > #nested-just-because > .mixin();
}

compiles into:

#use-place {
  this: works;
}

if you would remove parameters, then it would compile into:

#use-place {
  declaration: 222;
  this: works;
}

I think that correct solution would be either:

  • not matching namespaces with parameters,
  • mixins unlocking into namespaces with and without parameters should be the same.

Activity

  1. lukeapage commented on Sep 10, 2013

    @lukeapage
    Member

    I've never seen namespaces with parameters.. but yes

    https://github.com/less/less.js/blob/master/lib/less/parser.js#L1074

    it seems mixins can begin #

    and actually your example also happens with mixins..

    .importer() {
      .mixin() {
        declaration: 222;
      }
    }
    .namespace-with-parameter {
      .nested-just-because(@p1, @p2) { //unused parameters
        .importer();
        .mixin() {
          this: works;
        }
      }
    }
    
    #use-place {
      .namespace-with-parameter > .nested-just-because > .mixin();
    }

    I think

    • not matching namespaces (e.g. mixins) with parameters,

    is the solution.. but also probably low priority as it is making less more restrictive, not changing behaviour from one thing to another

  2. seven-phases-max commented on Sep 10, 2013

    @seven-phases-max
    Member

    Just a thought (a bit offtopic maybe): Since namespaces and mixins are pure logical abstractions (at least for now) - maybe it would make more sense to use "parametric ruleset" and "non-parametric ruleset" terms instead? Simply because this is where the real difference is (and not in the # and . designation). I mean when it goes into technical/implementation details (not for the "end-user" documentation of course).

  3. lukeapage commented on Sep 10, 2013

    @lukeapage
    Member

    I think they should just be described as

    .mixin(@a)
    #mixin(@a)
     .namespace {
      #namespace {
    

    where something is a namespace if it is used as a namespace, not if it is defined like the above (in the same way .mixin { can be used like a mixin or a namespace or neither)

  4. SomMeri commented on Sep 10, 2013

    @SomMeri
    MemberAuthor

    @lukeapage Thank you. I found parametrized namespace in a huge less I was send to. I expected it to fail in both less.js and less4j. Instead, both less.js and less4j compiled it the same way.

    I agree that "not matching namespaces (e.g. mixins) with parameters" would be the best solution.

  5. SomMeri commented on Jan 13, 2015

    @SomMeri
    MemberAuthor

    Closing, because this was already fixed.

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

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