Skip to content

Commit a963f11

Browse files
committed
fix(issue:4224) improve CSS custom property logic
* Fixes issue less#4224 by improving CSS custom property handling.
1 parent 829a635 commit a963f11

File tree

4 files changed

+35
-0
lines changed

4 files changed

+35
-0
lines changed

packages/less/src/less/functions/math-helper.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
1+
import Call from '../tree/call';
2+
import CustomProperty from '../tree/custom-property';
13
import Dimension from '../tree/dimension';
24

35
const MathHelper = (fn, unit, n) => {
6+
if (n instanceof Call && n.name === 'var') {
7+
if (n.args && n.args.length === 1) {
8+
return new Call(fn.name, [new CustomProperty(n.args[0].toCSS(), n._index, n._fileInfo)], n._index, n._fileInfo);
9+
} else {
10+
throw { type: 'Argument', message: 'var must contain one expression' };
11+
}
12+
}
413
if (!(n instanceof Dimension)) {
514
throw { type: 'Argument', message: 'argument must be a number' };
615
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/* eslint-disable no-prototype-builtins */
2+
import Node from './node';
3+
4+
const CustomProperty = function (name, index, currentFileInfo) {
5+
this.name = name;
6+
this._index = index;
7+
this._fileInfo = currentFileInfo;
8+
};
9+
10+
CustomProperty.prototype = Object.assign(new Node(), {
11+
type: 'CustomProperty',
12+
13+
genCSS: function (context, output) {
14+
output.add('var(' + this.name + ')');
15+
}
16+
});
17+
18+
export default CustomProperty;
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.test {
2+
--basic-deg: 20deg;
3+
--basic-deg-tan: tan(var(--basic-deg));
4+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.test {
2+
--basic-deg: 20deg;
3+
--basic-deg-tan: tan(var(--basic-deg));
4+
}

0 commit comments

Comments
 (0)