Skip to content

Commit

Permalink
Add variable feature for @layer
Browse files Browse the repository at this point in the history
  • Loading branch information
matthew-dean committed Feb 5, 2024
1 parent 0c123a9 commit a03e8d4
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 71 deletions.
22 changes: 7 additions & 15 deletions packages/less/src/less/parser/parser.js
Expand Up @@ -88,7 +88,6 @@ let Parser = function Parser(context, imports, fileInfo, currentIndex) {
Extend,
VariableCall,
NamespaceValue,
Layer,
mixin: {
Call: MixinCall,
Definition: MixinDefinition
Expand Down Expand Up @@ -1782,17 +1781,6 @@ let Parser = function Parser(context, imports, fileInfo, currentIndex) {
if (parserInput.$str('@container')) {
return prepareAndGetNestableAtRule(Container, index, debugInfo, ContainerSyntaxOptions);
}

if (parserInput.$re(/^@layer/)) {
const keyword = pKeyword();
const rules = parseBlock();
const atRule = new Layer(rules, keyword, index + currentIndex, fileInfo);
if (context.dumpLineNumbers) {
/** @type {*} */ (atRule).debugInfo = debugInfo;
}

return atRule;
}
}

parserInput.restore();
Expand Down Expand Up @@ -1870,6 +1858,7 @@ let Parser = function Parser(context, imports, fileInfo, currentIndex) {
let nonVendorSpecificName;
let hasIdentifier;
let hasExpression;
let hasOptionalExpression;
let hasUnknown;
let hasBlock = true;
let isRooted = true;
Expand Down Expand Up @@ -1908,10 +1897,13 @@ let Parser = function Parser(context, imports, fileInfo, currentIndex) {
/** @todo require optional keyword for `@layer` */
case '@document':
case '@supports':
case '@layer':
hasUnknown = true;
isRooted = false;
break;
case '@layer':
hasOptionalExpression = true;
isRooted = false;
break;
default:
hasUnknown = true;
break;
Expand All @@ -1924,9 +1916,9 @@ let Parser = function Parser(context, imports, fileInfo, currentIndex) {
if (!value) {
error(`expected ${name} identifier`);
}
} else if (hasExpression) {
} else if (hasExpression || hasOptionalExpression) {
value = parseExpression();
if (!value) {
if (hasExpression && !value) {
error(`expected ${name} expression`);
}
} else if (hasUnknown) {
Expand Down
3 changes: 1 addition & 2 deletions packages/less/src/less/tree/index.js
Expand Up @@ -34,7 +34,6 @@ import Negative from './negative';
import Extend from './extend';
import VariableCall from './variable-call';
import NamespaceValue from './namespace-value';
import Layer from './layer'

// mixins
import MixinCall from './mixin-call';
Expand All @@ -48,7 +47,7 @@ export default {
Comment, Anonymous, Value, JavaScript, Assignment,
Condition, Paren, Media, Container, QueryInParens,
UnicodeDescriptor, Negative, Extend, VariableCall,
NamespaceValue, Layer,
NamespaceValue,
mixin: {
Call: MixinCall,
Definition: MixinDefinition
Expand Down
54 changes: 0 additions & 54 deletions packages/less/src/less/tree/layer.js

This file was deleted.

5 changes: 5 additions & 0 deletions packages/test-data/css/_main/layer.css
Expand Up @@ -8,3 +8,8 @@
color: white;
}
}
@layer primevue {
.test {
foo: bar;
}
}
6 changes: 6 additions & 0 deletions packages/test-data/less/_main/layer.less
Expand Up @@ -9,4 +9,10 @@

@layer legacy {
@import "./import/layer-import.less";
}

@layer-name: primevue;

@layer @layer-name {
.test { foo: bar; }
}

0 comments on commit a03e8d4

Please sign in to comment.