Add computeValue

This commit is contained in:
Tobe O 2019-08-07 21:41:46 -04:00
parent 225a83078b
commit deb6673654
4 changed files with 14 additions and 5 deletions

View file

@ -1,17 +1,20 @@
import 'package:source_span/source_span.dart';
import '../token.dart';
import 'node.dart';
import 'value_or_variable.dart';
import 'input_value.dart';
class ArgumentContext extends Node {
final Token NAME, COLON;
final ValueOrVariableContext valueOrVariable;
final InputValueContext value;
ArgumentContext(this.NAME, this.COLON, this.valueOrVariable);
ArgumentContext(this.NAME, this.COLON, this.value);
/// Use [value] instead.
@deprecated
InputValueContext get valueOrVariable => value;
String get name => NAME.text;
@override
FileSpan get span =>
NAME.span.expand(COLON.span).expand(valueOrVariable.span);
FileSpan get span => NAME.span.expand(COLON.span).expand(value.span);
}

View file

@ -2,6 +2,7 @@ import 'node.dart';
abstract class ConstantContext<T> extends Node {
T get value;
T computeValue(Map<String, dynamic> variables) => value;
}
/// Use [ConstantContext] instead. This class remains solely for backwards compatibility.

View file

@ -13,4 +13,7 @@ class InputValueContext extends Node {
@override
FileSpan get span => constant?.span ?? variable.span;
Object computeValue(Map<String, dynamic> variables) =>
constant?.computeValue(variables) ?? variable?.computeValue(variables);
}

View file

@ -11,5 +11,7 @@ class VariableContext extends Node {
@override
FileSpan get span => DOLLAR.span.expand(NAME.span);
Object computeValue(Map<String, dynamic> variables) => variables[name];
// new FileSpan(DOLLAR?.span?.start, NAME?.span?.end, toSource());
}