Skip to content

Variable redefinition more like php, js, etc #905

Closed

Description

@nathanielks

Here's the problem:

When I define a variable, then redefine it later, LESS's compiler seems to use the latter variable definition as opposed to using the first until it's been redefined.

Here's an example:

Style.less
-> import variables.less
-> Import base.less
-> import theme.less
-> import phone.less

If I define @Variable1 in variables.less, then redefine it in phone.less, LESS uses phone.less's @Variable1 definition across the entire project, instead of using it as it's been defined in variables.less until its been redefined in phone.less

Here's a real world scenario:
Style.less
-> import variables.less : set @font-size: 16;
-> Import base.less: body{ font-size: @font-size_1px; }
-> import theme.less
-> import phone.less, set @font-size: 12; body{ font-size: @font-size_1px; }

In both base.less and phone.less, body's font size will be 12px, and not 16 and 12 respectively. Anyway we can rework this, or do I have to use different variables?

Activity

  1. dmcass commented on Aug 16, 2012

    @dmcass
    Contributor

    Looks like this might be a duplicate of #297 perhaps?

  2. nathanielks commented on Aug 16, 2012

    @nathanielks
    Author

    Hmm, I just read that and it seems we're having the opposite problems? They're saying that their variables are being redefined (which is what I want), but in my case they're not... Let me go back and look at my project and see if I'm doing something wrong.

  3. nathanielks commented on Aug 16, 2012

    @nathanielks
    Author

    Ok, so this is weird. Here's the code I used lesso to test:

    @red: #D14728;

    #test1{
    color: @red;
    }

    @red: #444;

    #test2{
    color: @red;
    }

    I used Lesso to test and it produces this output:

    /* downloaded from http://www.below.ch/lesso/parse/23c8990f/1 */

    #test1 { color:#d14728; }
    #test2 { color:#444444; }

    But when I use CodeKit to compile my less, it returns this:

    #test1{color:#444444;}
    #test2{color:#444444;}

    And then when I use less.js, it gives me the same output. For one, I think lesso is possibly using a different Less compiler. Either way, any thoughts?

  4. nathanielks commented on Aug 16, 2012

    @nathanielks
    Author

    From #297, lesso is using a different compiler

  5. lukeapage commented on Oct 25, 2012

    @lukeapage
    Member

    just to be clear, is this issue this one

    #297 (comment)

    ?

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