Skip to content

Commit 346c1b7

Browse files
authored
Merge branch 'less:master' into master
2 parents 749cdb3 + 67404cd commit 346c1b7

File tree

8 files changed

+83
-1
lines changed

8 files changed

+83
-1
lines changed

packages/less/src/less/tree/expression.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ Expression.prototype = Object.assign(new Node(), {
2020
},
2121

2222
eval(context) {
23+
const noSpacing = this.noSpacing;
2324
let returnValue;
2425
const mathOn = context.isMathOn();
2526
const inParenthesis = this.parens;
@@ -50,6 +51,7 @@ Expression.prototype = Object.assign(new Node(), {
5051
&& (!(returnValue instanceof Dimension))) {
5152
returnValue = new Paren(returnValue);
5253
}
54+
returnValue.noSpacing = returnValue.noSpacing || noSpacing;
5355
return returnValue;
5456
},
5557

packages/less/src/less/tree/import.js

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import Ruleset from './ruleset';
66
import Anonymous from './anonymous';
77
import * as utils from '../utils';
88
import LessError from '../less-error';
9+
import Expression from './expression';
910

1011
//
1112
// CSS @import node
@@ -157,6 +158,20 @@ Import.prototype = Object.assign(new Node(), {
157158
return [];
158159
}
159160
}
161+
if (this.features) {
162+
let featureValue = this.features.value;
163+
if (Array.isArray(featureValue) && featureValue.length >= 1) {
164+
const expr = featureValue[0];
165+
if (expr.type === 'Expression' && Array.isArray(expr.value) && expr.value.length >= 2) {
166+
featureValue = expr.value;
167+
const isLayer = featureValue[0].type === 'Keyword' && featureValue[0].value === 'layer'
168+
&& featureValue[1].type === 'Paren';
169+
if (isLayer) {
170+
this.css = false;
171+
}
172+
}
173+
}
174+
}
160175
if (this.options.inline) {
161176
const contents = new Anonymous(this.root, 0,
162177
{
@@ -165,18 +180,57 @@ Import.prototype = Object.assign(new Node(), {
165180
}, true, true);
166181

167182
return this.features ? new Media([contents], this.features.value) : [contents];
168-
} else if (this.css) {
183+
} else if (this.css || this.layerCss) {
169184
const newImport = new Import(this.evalPath(context), features, this.options, this._index);
185+
if (this.layerCss) {
186+
newImport.css = this.layerCss;
187+
newImport.path._fileInfo = this._fileInfo;
188+
}
170189
if (!newImport.css && this.error) {
171190
throw this.error;
172191
}
173192
return newImport;
174193
} else if (this.root) {
194+
if (this.features) {
195+
let featureValue = this.features.value;
196+
if (Array.isArray(featureValue) && featureValue.length === 1) {
197+
const expr = featureValue[0];
198+
if (expr.type === 'Expression' && Array.isArray(expr.value) && expr.value.length >= 2) {
199+
featureValue = expr.value;
200+
const isLayer = featureValue[0].type === 'Keyword' && featureValue[0].value === 'layer'
201+
&& featureValue[1].type === 'Paren';
202+
if (isLayer) {
203+
this.layerCss = true;
204+
featureValue[0] = new Expression(featureValue.slice(0, 2));
205+
featureValue.splice(1, 1);
206+
featureValue[0].noSpacing = true;
207+
return this;
208+
}
209+
}
210+
}
211+
}
175212
ruleset = new Ruleset(null, utils.copyArray(this.root.rules));
176213
ruleset.evalImports(context);
177214

178215
return this.features ? new Media(ruleset.rules, this.features.value) : ruleset.rules;
179216
} else {
217+
if (this.features) {
218+
let featureValue = this.features.value;
219+
if (Array.isArray(featureValue) && featureValue.length >= 1) {
220+
featureValue = featureValue[0].value;
221+
if (Array.isArray(featureValue) && featureValue.length >= 2) {
222+
const isLayer = featureValue[0].type === 'Keyword' && featureValue[0].value === 'layer'
223+
&& featureValue[1].type === 'Paren';
224+
if (isLayer) {
225+
this.css = true;
226+
featureValue[0] = new Expression(featureValue.slice(0, 2));
227+
featureValue.splice(1, 1);
228+
featureValue[0].noSpacing = true;
229+
return this;
230+
}
231+
}
232+
}
233+
}
180234
return [];
181235
}
182236
}

packages/test-data/css/_main/layer.css

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
@import url("/import/layer-import-2.css") layer(foo);
2+
@import url("/import/layer-import-3.css") layer(responsive) supports(display: flex) screen and (max-width: 768px);
3+
@import url("/import/layer-import-4.css") layer(print) print;
4+
@import url("/import/layer-import-4.css") layer(print) print, (max-width: 600px);
5+
@import url("/import/layer-import-5.css") layer(features) supports(display: grid);
16
@layer {
27
.main::before {
38
color: #f00;
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.sub-rule {
2+
ul {
3+
color: white;
4+
}
5+
}

packages/test-data/less/_main/import/layer-import-3.css

Whitespace-only changes.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.sub-rule {
2+
ul {
3+
color: white;
4+
}
5+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.sub-rule {
2+
ul {
3+
color: white;
4+
}
5+
}

packages/test-data/less/_main/layer.less

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@
1010
@import "./import/layer-import.less";
1111
}
1212

13+
@import url("/import/layer-import-2.css") layer(foo);
14+
@import url("/import/layer-import-3.css") layer(responsive) supports(display: flex) screen and (max-width: 768px);
15+
@import url("/import/layer-import-4.css") layer(print) print;
16+
@import url("/import/layer-import-4.css") layer(print) print, (max-width: 600px);
17+
@import url("/import/layer-import-5.css") layer(features) supports(display: grid);
18+
1319
@layer-name: primevue;
1420

1521
@layer @layer-name {

0 commit comments

Comments
 (0)