Skip to content
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
21 changes: 19 additions & 2 deletions packages/less/lib/less/parser/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,23 @@ const Parser = function Parser(context, imports, fileInfo, currentIndex) {
}
},

//
// A CSS data type name, used by the `type()` notation of `attr()`
// and as a value component in custom properties, such as:
//
// <number> <length-percentage> <custom-ident>
//
// It is emitted verbatim so the surrounding CSS function is
// preserved instead of throwing a parse error.
//
dataType: function () {
const index = parserInput.i;
const k = parserInput.$re(/^<[\w-]+>/);
if (k) {
return new(tree.Anonymous)(k, index + currentIndex);
}
},

//
// A function call
//
Expand Down Expand Up @@ -1288,8 +1305,8 @@ const Parser = function Parser(context, imports, fileInfo, currentIndex) {
const entities = this.entities;

return this.comment() || entities.literal() || entities.variable() || entities.url() ||
entities.property() || entities.call() || entities.keyword() || this.mixin.call(true) ||
entities.javascript();
entities.dataType() || entities.property() || entities.call() || entities.keyword() ||
this.mixin.call(true) || entities.javascript();
},

//
Expand Down
12 changes: 12 additions & 0 deletions packages/test-data/tests-unit/css-attr/css-attr.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
img {
aspect-ratio: attr(width type(<number>)) / attr(height type(<number>));
}
.fallback {
width: attr(data-width type(<length>), 0px);
}
.string {
content: attr(data-text type(<string>));
}
.bare {
--my-syntax: <length-percentage>;
}
13 changes: 13 additions & 0 deletions packages/test-data/tests-unit/css-attr/css-attr.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// CSS attr() with the type() notation and bare data-type tokens (#4371)
img {
aspect-ratio: attr(width type(<number>)) / attr(height type(<number>));
}
.fallback {
width: attr(data-width type(<length>), 0px);
}
.string {
content: attr(data-text type(<string>));
}
.bare {
--my-syntax: <length-percentage>;
}
Loading