Skip to content

Commit 87e2e1c

Browse files
authored
Add support for the plain CSS type() function (#2630)
Closes #2539
1 parent 9009a64 commit 87e2e1c

File tree

3 files changed

+42
-36
lines changed

3 files changed

+42
-36
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44
the order they appear in the source even when they're interleaved with nested
55
rules. This obsoletes the `mixed-decls` deprecation.
66

7+
* **Breaking change:** The function name `type()` is now fully reserved for the
8+
plain CSS function. This means that `@function` definitions with the name
9+
`type` will produce errors, while function calls will be parsed as special
10+
function strings.
11+
712
* Fix a bug where `@extend` rules loaded through a mixture of `@import` and
813
`@use` rules could fail to apply correctly.
914

lib/src/deprecation.dart

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ enum Deprecation {
1515
// DO NOT EDIT. This section was generated from the language repo.
1616
// See tool/grind/generate_deprecations.dart for details.
1717
//
18-
// Checksum: 2a2a94a3dd8ab2f7e3880b24e8e7850d66998b33
18+
// Checksum: 247ee9ef1df8665b759064856492831661b08985
1919

2020
/// Deprecation for passing a string directly to meta.call().
2121
callString('call-string',
@@ -125,7 +125,9 @@ enum Deprecation {
125125

126126
/// Deprecation for functions named "type".
127127
typeFunction('type-function',
128-
deprecatedIn: '1.86.0', description: 'Functions named "type".'),
128+
deprecatedIn: '1.86.0',
129+
obsoleteIn: '1.92.0',
130+
description: 'Functions named "type".'),
129131

130132
/// Deprecation for passing a relative url to compileString().
131133
compileStringRelativeUrl('compile-string-relative-url',

lib/src/parse/stylesheet.dart

Lines changed: 33 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -932,14 +932,8 @@ abstract class StylesheetParser extends Parser {
932932
span: scanner.spanFrom(beforeName),
933933
));
934934
} else if (equalsIgnoreCase(name, 'type')) {
935-
warnings.add((
936-
deprecation: Deprecation.typeFunction,
937-
message: 'Sass @functions named "type" are deprecated for forward-'
938-
'compatibility with the plain CSS type() function.\n'
939-
'\n'
940-
'For details, see https://sass-lang.com/d/type-function',
941-
span: scanner.spanFrom(beforeName),
942-
));
935+
error('This name is reserved for the plain-CSS function.',
936+
scanner.spanFrom(beforeName));
943937
}
944938

945939
whitespace(consumeNewlines: true);
@@ -2966,35 +2960,40 @@ abstract class StylesheetParser extends Parser {
29662960
/// [name].
29672961
@protected
29682962
Expression? trySpecialFunction(String name, LineScannerState start) {
2969-
var normalized = unvendor(name);
2970-
29712963
InterpolationBuffer buffer;
2972-
switch (normalized) {
2973-
case "calc" when normalized != name && scanner.scanChar($lparen):
2974-
case "element" || "expression" when scanner.scanChar($lparen):
2975-
buffer = InterpolationBuffer()
2976-
..write(name)
2977-
..writeCharCode($lparen);
2978-
2979-
case "progid" when scanner.scanChar($colon):
2980-
buffer = InterpolationBuffer()
2981-
..write(name)
2982-
..writeCharCode($colon);
2983-
var next = scanner.peekChar();
2984-
while (next != null && (next.isAlphabetic || next == $dot)) {
2985-
buffer.writeCharCode(scanner.readChar());
2986-
next = scanner.peekChar();
2987-
}
2988-
scanner.expectChar($lparen);
2989-
buffer.writeCharCode($lparen);
2964+
if (name == "type" && scanner.scanChar($lparen)) {
2965+
buffer = InterpolationBuffer()
2966+
..write(name)
2967+
..writeCharCode($lparen);
2968+
} else {
2969+
var normalized = unvendor(name);
2970+
switch (normalized) {
2971+
case "calc" when normalized != name && scanner.scanChar($lparen):
2972+
case "element" || "expression" when scanner.scanChar($lparen):
2973+
buffer = InterpolationBuffer()
2974+
..write(name)
2975+
..writeCharCode($lparen);
2976+
2977+
case "progid" when scanner.scanChar($colon):
2978+
buffer = InterpolationBuffer()
2979+
..write(name)
2980+
..writeCharCode($colon);
2981+
var next = scanner.peekChar();
2982+
while (next != null && (next.isAlphabetic || next == $dot)) {
2983+
buffer.writeCharCode(scanner.readChar());
2984+
next = scanner.peekChar();
2985+
}
2986+
scanner.expectChar($lparen);
2987+
buffer.writeCharCode($lparen);
29902988

2991-
case "url":
2992-
return _tryUrlContents(
2993-
start,
2994-
).andThen((contents) => StringExpression(contents));
2989+
case "url":
2990+
return _tryUrlContents(
2991+
start,
2992+
).andThen((contents) => StringExpression(contents));
29952993

2996-
case _:
2997-
return null;
2994+
case _:
2995+
return null;
2996+
}
29982997
}
29992998

30002999
buffer.addInterpolation(_interpolatedDeclarationValue(allowEmpty: true));

0 commit comments

Comments
 (0)