Skip to content

Commit 6878709

Browse files
authored
Deprecate misplaced rest arguments (#2623)
See sass/sass-spec#2072
1 parent 6607204 commit 6878709

File tree

3 files changed

+38
-1
lines changed

3 files changed

+38
-1
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@
77
`meta.inspect()`, which is to provide full information about the structure of
88
a Sass value.
99

10+
* Passing a rest argument (`$arg...`) before a positional or named argument when
11+
calling a function or mixin is now deprecated. This was always outside the
12+
specified syntax, but it was historically treated the same as passing the rest
13+
argument at the end of the argument list whether or not that matched the
14+
visual order of the arguments.
15+
1016
## 1.90.0
1117

1218
* Allow a `@forward`ed module to be loaded with a configuration when that module

lib/src/deprecation.dart

Lines changed: 6 additions & 1 deletion
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: c57ab2eb07ab1df48581b8484ef9bdbad0ddceaa
18+
// Checksum: 1c1efc2604729aea755453fefd1e8f56e100698e
1919

2020
/// Deprecation for passing a string directly to meta.call().
2121
callString('call-string',
@@ -131,6 +131,11 @@ enum Deprecation {
131131
deprecatedIn: '1.88.0',
132132
description: 'Passing a relative url to compileString().'),
133133

134+
/// Deprecation for a rest parameter before a positional or named parameter.
135+
misplacedRest('misplaced-rest',
136+
deprecatedIn: '1.91.0',
137+
description: 'A rest parameter before a positional or named parameter.'),
138+
134139
// END AUTOGENERATED CODE
135140

136141
/// Used for deprecations coming from user-authored code.

lib/src/parse/stylesheet.dart

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import '../exception.dart';
1515
import '../interpolation_buffer.dart';
1616
import '../util/character.dart';
1717
import '../utils.dart';
18+
import '../util/multi_span.dart';
1819
import '../util/nullable.dart';
1920
import '../value.dart';
2021
import 'parser.dart';
@@ -1832,6 +1833,7 @@ abstract class StylesheetParser extends Parser {
18321833
var named = <String, Expression>{};
18331834
Expression? rest;
18341835
Expression? keywordRest;
1836+
var emittedRestDeprecation = false;
18351837
while (_lookingAtExpression()) {
18361838
var expression = expressionUntilComma(singleEquals: !mixin);
18371839
whitespace(consumeNewlines: true);
@@ -1842,6 +1844,19 @@ abstract class StylesheetParser extends Parser {
18421844
error("Duplicate argument.", expression.span);
18431845
}
18441846
named[expression.name] = expressionUntilComma(singleEquals: !mixin);
1847+
1848+
if (rest != null && !emittedRestDeprecation) {
1849+
emittedRestDeprecation = true;
1850+
warnings.add((
1851+
deprecation: Deprecation.misplacedRest,
1852+
message: 'Named arguments must come before rest arguments.\n'
1853+
'This will be an error in Dart Sass 2.0.0.',
1854+
span: MultiSpan(
1855+
scanner.spanFromPosition(expression.span.start.offset),
1856+
'named argument',
1857+
{rest.span: 'rest argument'})
1858+
));
1859+
}
18451860
} else if (scanner.scanChar($dot)) {
18461861
scanner.expectChar($dot);
18471862
scanner.expectChar($dot);
@@ -1860,6 +1875,17 @@ abstract class StylesheetParser extends Parser {
18601875
);
18611876
} else {
18621877
positional.add(expression);
1878+
1879+
if (rest != null && !emittedRestDeprecation) {
1880+
emittedRestDeprecation = true;
1881+
warnings.add((
1882+
deprecation: Deprecation.misplacedRest,
1883+
message: 'Positional arguments must come before rest arguments.\n'
1884+
'This will be an error in Dart Sass 2.0.0.',
1885+
span: MultiSpan(expression.span, 'positional argument',
1886+
{rest.span: 'rest argument'})
1887+
));
1888+
}
18631889
}
18641890

18651891
whitespace(consumeNewlines: true);

0 commit comments

Comments
 (0)