pedantic: misc_value
This commit is contained in:
parent
c83c9e1fc3
commit
84080c4fe3
2 changed files with 55 additions and 20 deletions
|
@ -3,46 +3,68 @@ import '../token.dart';
|
|||
import 'input_value.dart';
|
||||
import 'node.dart';
|
||||
|
||||
/// A GraphQL `null` literal.
|
||||
class NullValueContext extends InputValueContext<Null> {
|
||||
final Token NULL;
|
||||
/// The source token.
|
||||
final Token nullToken;
|
||||
|
||||
NullValueContext(this.NULL);
|
||||
NullValueContext(this.nullToken);
|
||||
|
||||
/// Use [nullToken] instead.
|
||||
@deprecated
|
||||
Token get NULL => nullToken;
|
||||
|
||||
@override
|
||||
FileSpan get span => NULL.span;
|
||||
FileSpan get span => nullToken.span;
|
||||
|
||||
@override
|
||||
Null computeValue(Map<String, dynamic> variables) => null;
|
||||
}
|
||||
|
||||
/// A GraphQL enumeration literal.
|
||||
class EnumValueContext extends InputValueContext<String> {
|
||||
final Token NAME;
|
||||
/// The source token.
|
||||
final Token nameToken;
|
||||
|
||||
EnumValueContext(this.NAME);
|
||||
EnumValueContext(this.nameToken);
|
||||
|
||||
/// Use [nameToken] instead.
|
||||
@deprecated
|
||||
Token get NAME => nameToken;
|
||||
|
||||
@override
|
||||
FileSpan get span => NAME.span;
|
||||
FileSpan get span => nameToken.span;
|
||||
|
||||
@override
|
||||
String computeValue(Map<String, dynamic> variables) => NAME.span.text;
|
||||
String computeValue(Map<String, dynamic> variables) => nameToken.span.text;
|
||||
}
|
||||
|
||||
/// A GraphQL object literal.
|
||||
class ObjectValueContext extends InputValueContext<Map<String, dynamic>> {
|
||||
final Token LBRACE;
|
||||
final List<ObjectFieldContext> fields;
|
||||
final Token RBRACE;
|
||||
/// The source tokens.
|
||||
final Token lBraceToken, rBraceToken;
|
||||
|
||||
ObjectValueContext(this.LBRACE, this.fields, this.RBRACE);
|
||||
/// The fields in the object.
|
||||
final List<ObjectFieldContext> fields;
|
||||
|
||||
ObjectValueContext(this.lBraceToken, this.fields, this.rBraceToken);
|
||||
|
||||
/// Use [lBraceToken] instead.
|
||||
Token get LBRACE => lBraceToken;
|
||||
|
||||
/// Use [rBraceToken] instead.
|
||||
@deprecated
|
||||
Token get RBRACE => rBraceToken;
|
||||
|
||||
@override
|
||||
FileSpan get span {
|
||||
var left = LBRACE.span;
|
||||
var left = lBraceToken.span;
|
||||
|
||||
for (var field in fields) {
|
||||
left = left.expand(field.span);
|
||||
}
|
||||
|
||||
return left.expand(RBRACE.span);
|
||||
return left.expand(rBraceToken.span);
|
||||
}
|
||||
|
||||
@override
|
||||
|
@ -52,19 +74,32 @@ class ObjectValueContext extends InputValueContext<Map<String, dynamic>> {
|
|||
} else {
|
||||
return fields.fold<Map<String, dynamic>>(<String, dynamic>{},
|
||||
(map, field) {
|
||||
return map..[field.NAME.text] = field.value.computeValue(variables);
|
||||
return map
|
||||
..[field.nameToken.text] = field.value.computeValue(variables);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// A field within an [ObjectValueContext].
|
||||
class ObjectFieldContext extends Node {
|
||||
final Token NAME;
|
||||
final Token COLON;
|
||||
/// The source tokens.
|
||||
final Token nameToken, colonToken;
|
||||
|
||||
/// The associated value.
|
||||
final InputValueContext value;
|
||||
|
||||
ObjectFieldContext(this.NAME, this.COLON, this.value);
|
||||
ObjectFieldContext(this.nameToken, this.colonToken, this.value);
|
||||
|
||||
/// Use [nameToken] instead.
|
||||
@deprecated
|
||||
Token get NAME => nameToken;
|
||||
|
||||
/// Use [colonToken] instead.
|
||||
@deprecated
|
||||
Token get COLON => colonToken;
|
||||
|
||||
@override
|
||||
FileSpan get span => NAME.span.expand(COLON.span).expand(value.span);
|
||||
FileSpan get span =>
|
||||
nameToken.span.expand(colonToken.span).expand(value.span);
|
||||
}
|
||||
|
|
|
@ -48,8 +48,8 @@ void main() {
|
|||
expect(condition.name, 'condition');
|
||||
expect(condition.value, TypeMatcher<ObjectValueContext>());
|
||||
var conditionValue = condition.value as ObjectValueContext;
|
||||
var memberId =
|
||||
conditionValue.fields.singleWhere((f) => f.NAME.text == 'memberId');
|
||||
var memberId = conditionValue.fields
|
||||
.singleWhere((f) => f.nameToken.text == 'memberId');
|
||||
expect(memberId.value, TypeMatcher<T>());
|
||||
print('Found \$memberId: Instance of $T');
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue