Skip to content

Commit

Permalink
Fixes less#3368
Browse files Browse the repository at this point in the history
  • Loading branch information
matthew-dean committed Jul 16, 2020
1 parent 974298b commit 7ca2506
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 6 deletions.
20 changes: 14 additions & 6 deletions packages/less/src/less/functions/list.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Comment from '../tree/comment';
import Node from '../tree/node';
import Dimension from '../tree/dimension';
import Declaration from '../tree/declaration';
import Expression from '../tree/expression';
Expand Down Expand Up @@ -65,20 +66,27 @@ export default {
let newRules;
let iterator;

const tryEval = val => {
if (val instanceof Node) {
return val.eval(this.context);
}
return val;
};

if (list.value && !(list instanceof Quote)) {
if (Array.isArray(list.value)) {
iterator = list.value;
iterator = list.value.map(tryEval);
} else {
iterator = [list.value];
iterator = [tryEval(list.value)];
}
} else if (list.ruleset) {
iterator = list.ruleset.rules;
iterator = tryEval(list.ruleset).rules;
} else if (list.rules) {
iterator = list.rules;
iterator = list.rules.map(tryEval);
} else if (Array.isArray(list)) {
iterator = list;
iterator = list.map(tryEval);
} else {
iterator = [list];
iterator = [tryEval(list)];
}

let valueName = '@value';
Expand Down
10 changes: 10 additions & 0 deletions packages/test-data/css/namespacing/namespacing-8.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
:root {
--background-color: black;
--color: #fff;
}
div {
display: inline-block;
padding: 1rem;
background-color: var(--background-color);
color: var(--color);
}
31 changes: 31 additions & 0 deletions packages/test-data/less/namespacing/namespacing-8.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// see: https://github.com/less/less.js/issues/3368
@vars: {
background-color: black;
color: contrast($background-color, #000, #fff);
}

:root {
each(@vars, {
--@{key}: @value;
});
}

div {
display: inline-block;
padding: 1rem;
background-color: var(--background-color);
color: var(--color);
}

// see: https://github.com/less/less.js/issues/3339
// still fails - move to 4.0
// @components: {
// columns: true;
// ratios: false;
// };

// each(@components, {
// & when (@value = true) {
// @import (optional) "components/@{key}.less";
// }
// });

0 comments on commit 7ca2506

Please sign in to comment.