@@ -9,20 +9,20 @@ import '../../parse/scss.dart';
9
9
import '../../util/character.dart' ;
10
10
import '../../util/span.dart' ;
11
11
import '../../utils.dart' ;
12
- import 'argument .dart' ;
12
+ import 'parameter .dart' ;
13
13
import 'node.dart' ;
14
14
15
- /// An argument declaration, as for a function or mixin definition.
15
+ /// An parameter declaration, as for a function or mixin definition.
16
16
///
17
17
/// {@category AST}
18
18
/// {@category Parsing}
19
- final class ArgumentDeclaration implements SassNode {
20
- /// The arguments that are taken.
21
- final List <Argument > arguments ;
19
+ final class ParameterList implements SassNode {
20
+ /// The parameters that are taken.
21
+ final List <Parameter > parameters ;
22
22
23
- /// The name of the rest argument (as in `$args...` ), or `null` if none was
23
+ /// The name of the rest parameter (as in `$args...` ), or `null` if none was
24
24
/// declared.
25
- final String ? restArgument ;
25
+ final String ? restParameter ;
26
26
27
27
final FileSpan span;
28
28
@@ -31,7 +31,7 @@ final class ArgumentDeclaration implements SassNode {
31
31
FileSpan get spanWithName {
32
32
var text = span.file.getText (0 );
33
33
34
- // Move backwards through any whitespace between the name and the arguments .
34
+ // Move backwards through any whitespace between the name and the parameters .
35
35
var i = span.start.offset - 1 ;
36
36
while (i > 0 && text.codeUnitAt (i).isWhitespace) {
37
37
i-- ;
@@ -48,60 +48,59 @@ final class ArgumentDeclaration implements SassNode {
48
48
if (! text.codeUnitAt (i + 1 ).isNameStart) return span;
49
49
50
50
// Trim because it's possible that this span is empty (for example, a mixin
51
- // may be declared without an argument list).
51
+ // may be declared without an parameter list).
52
52
return span.file.span (i + 1 , span.end.offset).trim ();
53
53
}
54
54
55
- /// Returns whether this declaration takes no arguments .
56
- bool get isEmpty => arguments .isEmpty && restArgument == null ;
55
+ /// Returns whether this declaration takes no parameters .
56
+ bool get isEmpty => parameters .isEmpty && restParameter == null ;
57
57
58
- ArgumentDeclaration (Iterable <Argument > arguments, this .span,
59
- {this .restArgument})
60
- : arguments = List .unmodifiable (arguments);
58
+ ParameterList (Iterable <Parameter > parameters, this .span, {this .restParameter})
59
+ : parameters = List .unmodifiable (parameters);
61
60
62
- /// Creates a declaration that declares no arguments .
63
- ArgumentDeclaration .empty (this .span)
64
- : arguments = const [],
65
- restArgument = null ;
61
+ /// Creates a declaration that declares no parameters .
62
+ ParameterList .empty (this .span)
63
+ : parameters = const [],
64
+ restParameter = null ;
66
65
67
- /// Parses an argument declaration from [contents] , which should be of the
66
+ /// Parses an parameter declaration from [contents] , which should be of the
68
67
/// form `@rule name(args) {` .
69
68
///
70
69
/// If passed, [url] is the name of the file from which [contents] comes.
71
70
///
72
71
/// Throws a [SassFormatException] if parsing fails.
73
- factory ArgumentDeclaration .parse (String contents, {Object ? url}) =>
74
- ScssParser (contents, url: url).parseArgumentDeclaration ();
72
+ factory ParameterList .parse (String contents, {Object ? url}) =>
73
+ ScssParser (contents, url: url).parseParameterList ();
75
74
76
75
/// Throws a [SassScriptException] if [positional] and [names] aren't valid
77
- /// for this argument declaration.
76
+ /// for this parameter declaration.
78
77
void verify (int positional, Set <String > names) {
79
78
var namedUsed = 0 ;
80
- for (var i = 0 ; i < arguments .length; i++ ) {
81
- var argument = arguments [i];
79
+ for (var i = 0 ; i < parameters .length; i++ ) {
80
+ var parameter = parameters [i];
82
81
if (i < positional) {
83
- if (names.contains (argument .name)) {
82
+ if (names.contains (parameter .name)) {
84
83
throw SassScriptException (
85
- "Argument ${_originalArgumentName ( argument .name )} was passed "
84
+ "Argument ${_originalParameterName ( parameter .name )} was passed "
86
85
"both by position and by name." );
87
86
}
88
- } else if (names.contains (argument .name)) {
87
+ } else if (names.contains (parameter .name)) {
89
88
namedUsed++ ;
90
- } else if (argument .defaultValue == null ) {
89
+ } else if (parameter .defaultValue == null ) {
91
90
throw MultiSpanSassScriptException (
92
- "Missing argument ${_originalArgumentName ( argument .name )}." ,
91
+ "Missing argument ${_originalParameterName ( parameter .name )}." ,
93
92
"invocation" ,
94
93
{spanWithName: "declaration" });
95
94
}
96
95
}
97
96
98
- if (restArgument != null ) return ;
97
+ if (restParameter != null ) return ;
99
98
100
- if (positional > arguments .length) {
99
+ if (positional > parameters .length) {
101
100
throw MultiSpanSassScriptException (
102
- "Only ${arguments .length } "
101
+ "Only ${parameters .length } "
103
102
"${names .isEmpty ? '' : 'positional ' }"
104
- "${pluralize ('argument' , arguments .length )} allowed, but "
103
+ "${pluralize ('argument' , parameters .length )} allowed, but "
105
104
"$positional ${pluralize ('was' , positional , plural : 'were' )} "
106
105
"passed." ,
107
106
"invocation" ,
@@ -110,54 +109,54 @@ final class ArgumentDeclaration implements SassNode {
110
109
111
110
if (namedUsed < names.length) {
112
111
var unknownNames = Set .of (names)
113
- ..removeAll (arguments .map ((argument ) => argument .name));
112
+ ..removeAll (parameters .map ((parameter ) => parameter .name));
114
113
throw MultiSpanSassScriptException (
115
- "No ${pluralize ('argument ' , unknownNames .length )} named "
114
+ "No ${pluralize ('parameter ' , unknownNames .length )} named "
116
115
"${toSentence (unknownNames .map ((name ) => "\$ $name " ), 'or' )}." ,
117
116
"invocation" ,
118
117
{spanWithName: "declaration" });
119
118
}
120
119
}
121
120
122
- /// Returns the argument named [name] with a leading `$` and its original
121
+ /// Returns the parameter named [name] with a leading `$` and its original
123
122
/// underscores (which are otherwise converted to hyphens).
124
- String _originalArgumentName (String name) {
125
- if (name == restArgument ) {
123
+ String _originalParameterName (String name) {
124
+ if (name == restParameter ) {
126
125
var text = span.text;
127
126
var fromDollar = text.substring (text.lastIndexOf ("\$ " ));
128
127
return fromDollar.substring (0 , text.indexOf ("." ));
129
128
}
130
129
131
- for (var argument in arguments ) {
132
- if (argument .name == name) return argument .originalName;
130
+ for (var parameter in parameters ) {
131
+ if (parameter .name == name) return parameter .originalName;
133
132
}
134
133
135
- throw ArgumentError ('This declaration has no argument named "\$ $name ".' );
134
+ throw ArgumentError ('This declaration has no parameter named "\$ $name ".' );
136
135
}
137
136
138
- /// Returns whether [positional] and [names] are valid for this argument
137
+ /// Returns whether [positional] and [names] are valid for this parameter
139
138
/// declaration.
140
139
bool matches (int positional, Set <String > names) {
141
140
var namedUsed = 0 ;
142
- for (var i = 0 ; i < arguments .length; i++ ) {
143
- var argument = arguments [i];
141
+ for (var i = 0 ; i < parameters .length; i++ ) {
142
+ var parameter = parameters [i];
144
143
if (i < positional) {
145
- if (names.contains (argument .name)) return false ;
146
- } else if (names.contains (argument .name)) {
144
+ if (names.contains (parameter .name)) return false ;
145
+ } else if (names.contains (parameter .name)) {
147
146
namedUsed++ ;
148
- } else if (argument .defaultValue == null ) {
147
+ } else if (parameter .defaultValue == null ) {
149
148
return false ;
150
149
}
151
150
}
152
151
153
- if (restArgument != null ) return true ;
154
- if (positional > arguments .length) return false ;
152
+ if (restParameter != null ) return true ;
153
+ if (positional > parameters .length) return false ;
155
154
if (namedUsed < names.length) return false ;
156
155
return true ;
157
156
}
158
157
159
158
String toString () => [
160
- for (var arg in arguments ) '\$ $arg ' ,
161
- if (restArgument != null ) '\$ $restArgument ...'
159
+ for (var arg in parameters ) '\$ $arg ' ,
160
+ if (restParameter != null ) '\$ $restParameter ...'
162
161
].join (', ' );
163
162
}
0 commit comments