2016-08-20 01:40:44 +02:00
|
|
|
// Copyright 2016 Google Inc. Use of this source code is governed by an
|
|
|
|
// MIT-style license that can be found in the LICENSE file or at
|
|
|
|
// https://opensource.org/licenses/MIT.
|
|
|
|
|
|
|
|
import 'package:source_span/source_span.dart';
|
|
|
|
|
|
|
|
import 'expression.dart';
|
|
|
|
import 'node.dart';
|
|
|
|
|
2016-10-01 03:42:41 +02:00
|
|
|
/// A set of arguments passed in to a function or mixin.
|
2016-08-20 01:40:44 +02:00
|
|
|
class ArgumentInvocation implements SassNode {
|
2016-10-01 03:42:41 +02:00
|
|
|
/// The arguments passed by position.
|
2016-08-20 01:40:44 +02:00
|
|
|
final List<Expression> positional;
|
|
|
|
|
2016-10-01 03:42:41 +02:00
|
|
|
/// The arguments passed by name.
|
2016-08-20 01:40:44 +02:00
|
|
|
final Map<String, Expression> named;
|
|
|
|
|
2016-10-01 03:42:41 +02:00
|
|
|
/// The first rest argument (as in `$args...`).
|
2016-08-20 01:40:44 +02:00
|
|
|
final Expression rest;
|
|
|
|
|
2016-10-01 03:42:41 +02:00
|
|
|
/// The second rest argument, which is expected to only contain a keyword map.
|
2016-08-20 01:40:44 +02:00
|
|
|
final Expression keywordRest;
|
|
|
|
|
|
|
|
final FileSpan span;
|
|
|
|
|
2016-08-29 00:04:48 +02:00
|
|
|
ArgumentInvocation(
|
|
|
|
Iterable<Expression> positional, Map<String, Expression> named, this.span,
|
|
|
|
{this.rest, this.keywordRest})
|
2016-08-20 01:40:44 +02:00
|
|
|
: positional = new List.unmodifiable(positional),
|
|
|
|
named = new Map.unmodifiable(named) {
|
|
|
|
assert(rest != null || keywordRest == null);
|
|
|
|
}
|
|
|
|
|
2016-10-01 03:42:41 +02:00
|
|
|
/// Creates an invocation that passes no arguments.
|
2016-08-28 23:53:20 +02:00
|
|
|
ArgumentInvocation.empty(this.span)
|
2016-08-29 00:04:48 +02:00
|
|
|
: positional = const [],
|
|
|
|
named = const {},
|
|
|
|
rest = null,
|
|
|
|
keywordRest = null;
|
2016-08-27 09:26:53 +02:00
|
|
|
|
2016-08-20 01:40:44 +02:00
|
|
|
String toString() {
|
|
|
|
var components = new List<Object>.from(positional)
|
|
|
|
..addAll(named.keys.map((name) => "$name: ${named[name]}"));
|
|
|
|
if (rest != null) components.add("$rest...");
|
|
|
|
if (keywordRest != null) components.add("$keywordRest...");
|
|
|
|
return "(${components.join(', ')})";
|
|
|
|
}
|
|
|
|
}
|