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: When format the less-node, keep its context. #3726

Open
wants to merge 2 commits 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion packages/less/src/less/functions/string.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,18 @@ export default {
const args = Array.prototype.slice.call(arguments, 1);
let result = string.value;

const toCSSOptions = {
compress: !!this.context.compress,
dumpLineNumbers: !!this.context.dumpLineNumbers,
strictUnits: !!this.context.strictUnits,
numPrecision: 8
};

for (let i = 0; i < args.length; i++) {
/* jshint loopfunc:true */
result = result.replace(/%[sda]/i, token => {
const value = ((args[i].type === 'Quoted') &&
token.match(/s/i)) ? args[i].value : args[i].toCSS();
token.match(/s/i)) ? args[i].value : args[i].toCSS(toCSSOptions);
return token.match(/[A-Z]$/) ? encodeURIComponent(value) : value;
});
}
Expand Down
1 change: 1 addition & 0 deletions packages/test-data/css/_main/functions.css
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@
format-escaped-string: hello escaped world;
format-keyword: hello;
format-anonymous: hello anonymous world;
format-color: 'hsla(90, 100%, 50%, 0.5)';
}
#list-details {
length: 2;
Expand Down
9 changes: 5 additions & 4 deletions packages/test-data/less/_main/functions.less
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,11 @@

fade-out: fadeout(red, 5%); // support fadeOut and fadeout
fade-in: fadein(fadeout(red, 10%), 5%);
fade-out-relative: fadeout(red, 5%,relative);
fade-out-relative: fadeout(red, 5%,relative);
fade-in-relative: fadein(fadeout(red, 10%, relative), 5%, relative);
fade-out2: fadeout(fadeout(red, 50%), 50%);
fade-out2: fadeout(fadeout(red, 50%), 50%);
fade-out2-relative: fadeout(fadeout(red, 50%, relative), 50%, relative);

hsv: hsv(5, 50%, 30%);
hsva: hsva(3, 50%, 30%, 0.2);

Expand Down Expand Up @@ -223,6 +223,7 @@
format-escaped-string: %(~"hello %s", "escaped world");
format-keyword: %(hello);
format-anonymous: %(e("hello %s"), "anonymous world");
format-color: %('%s', hsla(90, 100%, 50%, 0.5));
}
}

Expand Down Expand Up @@ -269,7 +270,7 @@ html {
// see: https://github.com/less/less.js/issues/3371
@some: foo;
l: if((iscolor(@some)), darken(@some, 10%), black);


if((false), {g: 7}); /* results in void */

Expand Down