Make required span parameters positional (#1380)

Required non-boolean parameters should pretty much always be
positional. These were still named from back when spans were nullable
in Sass.
This commit is contained in:
Natalie Weizenbaum 2021-06-24 17:32:36 -07:00 committed by GitHub
parent 655fcfc950
commit 268f22e147
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 33 additions and 30 deletions

View File

@ -26,7 +26,7 @@ class Argument implements SassNode {
String get originalName => String get originalName =>
defaultValue == null ? span.text : declarationName(span); defaultValue == null ? span.text : declarationName(span);
Argument(this.name, {this.defaultValue, required this.span}); Argument(this.name, this.span, {this.defaultValue});
String toString() => defaultValue == null ? name : "$name: $defaultValue"; String toString() => defaultValue == null ? name : "$name: $defaultValue";
} }

View File

@ -52,12 +52,12 @@ class ArgumentDeclaration implements SassNode {
/// Returns whether this declaration takes no arguments. /// Returns whether this declaration takes no arguments.
bool get isEmpty => arguments.isEmpty && restArgument == null; bool get isEmpty => arguments.isEmpty && restArgument == null;
ArgumentDeclaration(Iterable<Argument> arguments, ArgumentDeclaration(Iterable<Argument> arguments, this.span,
{this.restArgument, required this.span}) {this.restArgument})
: arguments = List.unmodifiable(arguments); : arguments = List.unmodifiable(arguments);
/// Creates a declaration that declares no arguments. /// Creates a declaration that declares no arguments.
ArgumentDeclaration.empty({required this.span}) ArgumentDeclaration.empty(this.span)
: arguments = const [], : arguments = const [],
restArgument = null; restArgument = null;

View File

@ -23,8 +23,9 @@ class ListExpression implements Expression {
final FileSpan span; final FileSpan span;
ListExpression(Iterable<Expression> contents, ListSeparator separator, ListExpression(
{bool brackets = false, required FileSpan span}) Iterable<Expression> contents, ListSeparator separator, FileSpan span,
{bool brackets = false})
: this._(List.unmodifiable(contents), separator, brackets, span); : this._(List.unmodifiable(contents), separator, brackets, span);
ListExpression._( ListExpression._(

View File

@ -156,7 +156,7 @@ abstract class StylesheetParser extends Parser {
whitespace(); whitespace();
var arguments = scanner.peekChar() == $lparen var arguments = scanner.peekChar() == $lparen
? _argumentDeclaration() ? _argumentDeclaration()
: ArgumentDeclaration.empty(span: scanner.emptySpan); : ArgumentDeclaration.empty(scanner.emptySpan);
scanner.expectDone(); scanner.expectDone();
return Tuple2(name, arguments); return Tuple2(name, arguments);
}); });
@ -1202,8 +1202,8 @@ abstract class StylesheetParser extends Parser {
ContentBlock? content; ContentBlock? content;
if (contentArguments != null || lookingAtChildren()) { if (contentArguments != null || lookingAtChildren()) {
var contentArguments_ = contentArguments ?? var contentArguments_ =
ArgumentDeclaration.empty(span: scanner.emptySpan); contentArguments ?? ArgumentDeclaration.empty(scanner.emptySpan);
var wasInContentBlock = _inContentBlock; var wasInContentBlock = _inContentBlock;
_inContentBlock = true; _inContentBlock = true;
content = _withChildren(_statement, start, content = _withChildren(_statement, start,
@ -1239,7 +1239,7 @@ abstract class StylesheetParser extends Parser {
whitespace(); whitespace();
var arguments = scanner.peekChar() == $lparen var arguments = scanner.peekChar() == $lparen
? _argumentDeclaration() ? _argumentDeclaration()
: ArgumentDeclaration.empty(span: scanner.emptySpan); : ArgumentDeclaration.empty(scanner.emptySpan);
if (_inMixin || _inContentBlock) { if (_inMixin || _inContentBlock) {
error("Mixins may not contain mixin declarations.", error("Mixins may not contain mixin declarations.",
@ -1552,8 +1552,8 @@ abstract class StylesheetParser extends Parser {
break; break;
} }
arguments.add(Argument(name, arguments.add(Argument(name, scanner.spanFrom(variableStart),
span: scanner.spanFrom(variableStart), defaultValue: defaultValue)); defaultValue: defaultValue));
if (!named.add(name)) { if (!named.add(name)) {
error("Duplicate argument.", arguments.last.span); error("Duplicate argument.", arguments.last.span);
} }
@ -1562,8 +1562,8 @@ abstract class StylesheetParser extends Parser {
whitespace(); whitespace();
} }
scanner.expectChar($rparen); scanner.expectChar($rparen);
return ArgumentDeclaration(arguments, return ArgumentDeclaration(arguments, scanner.spanFrom(start),
restArgument: restArgument, span: scanner.spanFrom(start)); restArgument: restArgument);
} }
// ## Expressions // ## Expressions
@ -1642,8 +1642,9 @@ abstract class StylesheetParser extends Parser {
whitespace(); whitespace();
if (scanner.scanChar($rbracket)) { if (scanner.scanChar($rbracket)) {
return ListExpression([], ListSeparator.undecided, return ListExpression(
brackets: true, span: scanner.spanFrom(beforeBracket)); [], ListSeparator.undecided, scanner.spanFrom(beforeBracket),
brackets: true);
} }
} }
@ -1795,8 +1796,9 @@ abstract class StylesheetParser extends Parser {
spaceExpressions.add(singleExpression); spaceExpressions.add(singleExpression);
singleExpression_ = ListExpression( singleExpression_ = ListExpression(
spaceExpressions, ListSeparator.space, spaceExpressions,
span: spaceExpressions.first.span.expand(singleExpression.span)); ListSeparator.space,
spaceExpressions.first.span.expand(singleExpression.span));
spaceExpressions_ = null; spaceExpressions_ = null;
} }
} }
@ -2061,19 +2063,19 @@ abstract class StylesheetParser extends Parser {
var singleExpression = singleExpression_; var singleExpression = singleExpression_;
if (singleExpression != null) commaExpressions.add(singleExpression); if (singleExpression != null) commaExpressions.add(singleExpression);
return ListExpression(commaExpressions, ListSeparator.comma, return ListExpression(commaExpressions, ListSeparator.comma,
brackets: bracketList, scanner.spanFrom(beforeBracket ?? start),
span: scanner.spanFrom(beforeBracket ?? start)); brackets: bracketList);
} else if (bracketList && spaceExpressions != null) { } else if (bracketList && spaceExpressions != null) {
resolveOperations(); resolveOperations();
return ListExpression( return ListExpression(spaceExpressions..add(singleExpression_!),
spaceExpressions..add(singleExpression_!), ListSeparator.space, ListSeparator.space, scanner.spanFrom(beforeBracket!),
brackets: true, span: scanner.spanFrom(beforeBracket!)); brackets: true);
} else { } else {
resolveSpaceExpressions(); resolveSpaceExpressions();
if (bracketList) { if (bracketList) {
singleExpression_ = ListExpression( singleExpression_ = ListExpression([singleExpression_!],
[singleExpression_!], ListSeparator.undecided, ListSeparator.undecided, scanner.spanFrom(beforeBracket!),
brackets: true, span: scanner.spanFrom(beforeBracket!)); brackets: true);
} }
return singleExpression_!; return singleExpression_!;
} }
@ -2215,8 +2217,8 @@ abstract class StylesheetParser extends Parser {
whitespace(); whitespace();
if (!_lookingAtExpression()) { if (!_lookingAtExpression()) {
scanner.expectChar($rparen); scanner.expectChar($rparen);
return ListExpression([], ListSeparator.undecided, return ListExpression(
span: scanner.spanFrom(start)); [], ListSeparator.undecided, scanner.spanFrom(start));
} }
var first = _expressionUntilComma(); var first = _expressionUntilComma();
@ -2240,8 +2242,8 @@ abstract class StylesheetParser extends Parser {
} }
scanner.expectChar($rparen); scanner.expectChar($rparen);
return ListExpression(expressions, ListSeparator.comma, return ListExpression(
span: scanner.spanFrom(start)); expressions, ListSeparator.comma, scanner.spanFrom(start));
} finally { } finally {
_inParentheses = wasInParentheses; _inParentheses = wasInParentheses;
} }