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

fix: variable interpolation outputs the correct css. #3728

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 9 additions & 2 deletions packages/less/src/less/tree/quoted.js
Expand Up @@ -34,13 +34,20 @@ Quoted.prototype = Object.assign(new Node(), {
eval(context) {
const that = this;
let value = this.value;
const toCSSOptions = {
compress: !!context.compress,
dumpLineNumbers: !!context.dumpLineNumbers,
strictUnits: !!context.strictUnits,
numPrecision: 8
};

const variableReplacement = function (_, name) {
const v = new Variable(`@${name}`, that.getIndex(), that.fileInfo()).eval(context, true);
return (v instanceof Quoted) ? v.value : v.toCSS();
return (v instanceof Quoted) ? v.value : v.toCSS(toCSSOptions);
};
const propertyReplacement = function (_, name) {
const v = new Property(`$${name}`, that.getIndex(), that.fileInfo()).eval(context, true);
return (v instanceof Quoted) ? v.value : v.toCSS();
return (v instanceof Quoted) ? v.value : v.toCSS(toCSSOptions);
};
function iterativeReplace(value, regexp, replacementFnc) {
let evaluatedValue = value;
Expand Down
1 change: 1 addition & 0 deletions packages/test-data/css/_main/colors.css
Expand Up @@ -99,6 +99,7 @@
test-10: #55FF5599;
test-11: hsla(120, 100%, 66.66666667%, 0.6);
test-12: hsla(120, 100%, 66.66666667%, 0.5);
test-13: hsl(56, 8%, 14%);
--semi-transparent-dark-background: #001e00ee;
--semi-transparent-dark-background-2: #001e00;
}
2 changes: 2 additions & 0 deletions packages/test-data/less/_main/colors.less
Expand Up @@ -97,6 +97,7 @@
border-color: rgba(100%, 0, 0, 50%);
}

@color1: hsl(56, 8%, 14%);
#rrggbbaa {
test-1: #55FF5599;
test-2: #5F59;
Expand All @@ -111,6 +112,7 @@
test-10: color('#55FF5599');
test-11: hsla(#5F59);
test-12: hsla(#5F59, 0.5);
test-13: ~"@{color1}";
--semi-transparent-dark-background: #001e00ee;
--semi-transparent-dark-background-2: rgba(0, 30, 0, 238); // invalid opacity will be capped
}