Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

a problem of function e() #3345

Closed
zhnoah opened this issue Dec 17, 2018 · 3 comments
Closed

a problem of function e() #3345

zhnoah opened this issue Dec 17, 2018 · 3 comments
Labels

Comments

@zhnoah
Copy link

zhnoah commented Dec 17, 2018

I have a piece of code, that works fine:

// input
.mixin-create-width-style() {
    @list: e("90 100 110");

    each(@list, {
        .w-@{key} {
            width: @value;
        }
    })
}

.a {
    .mixin-create-width-style();
}

// output
.a .w-1 {
  width: 90;
}
.a .w-2 {
  width: 100;
}
.a .w-3 {
  width: 110;
}

but, When I want to pass a list string as a parameter:

// input
.mixin-create-width-style(@str) {
    @list: e(@str);

    each(@list, {
        .w-@{key} {
            width: @value;
        }
    })
}

.a {
    .mixin-create-width-style("90 100 110");
}

It doesn't work:

// output
.a .w-1 {
  width: 90 100 110;    // It's not I want
}

What's wrong with that?

@seven-phases-max
Copy link
Member

seven-phases-max commented Dec 17, 2018

Actually your first example looks like a bug (in each implementation?).
All of "1 2 3", ~"1 2 3", e("1 2 3") and similar create a single value and not a list (and should never be interpreted as a list implicitly).

Why are you using quotes at all? Shouldn't this be just:

.mixin-create-width-style(@list) {
    each(@list, {
        .w-@{key} {
            width: @value;
        }
    });
}

.a {
    .mixin-create-width-style(90 100 110);
}

?

matthew-dean added a commit to matthew-dean/less.js that referenced this issue Feb 12, 2019
@matthew-dean
Copy link
Member

@seven-phases-max The issue was actually in the e() function, which for legacy reasons created an Anonymous node instead of an escaped Quoted node like ~"" does.

This was all fine and good until late parsing was added, so any variable's value was first parsed as an Anonymous node, then the value was parsed later only when referenced. So since then, e() was always parsing the quoted value, which, in most cases wouldn't have been noticed until someone tried to use it in a list like this.

@zhnoah - @seven-phases-max is right though, there's no need to try to escape a list to iterate the list. Just use a list. I've also fixed the abberant e() behavior, which still won't give you what you want; it'll output a single value for every case.

@stale
Copy link

stale bot commented Jun 12, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants