Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1459)

Unified Diff: sdk/lib/_internal/compiler/implementation/js/template.dart

Issue 671513013: dart2js: Accept named holes in js-templates. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: sdk/lib/_internal/compiler/implementation/js/template.dart
diff --git a/sdk/lib/_internal/compiler/implementation/js/template.dart b/sdk/lib/_internal/compiler/implementation/js/template.dart
index 1c56d3726befb422c7ace823180d008d6e22eb43..8b0441432f15e5d81e70a0e0e1835b887e738f60 100644
--- a/sdk/lib/_internal/compiler/implementation/js/template.dart
+++ b/sdk/lib/_internal/compiler/implementation/js/template.dart
@@ -90,7 +90,11 @@ class Template {
positionalArgumentCount = generator.analysis.count;
}
- Node instantiate(List arguments) {
+ /// Instantiates the template with the given [arguments].
+ ///
+ /// This method fills in the holes with the given arguments. The [arguments]
+ /// must be either a [List] or a [Map].
+ Node instantiate(var arguments) {
if (arguments is List) {
if (arguments.length != positionalArgumentCount) {
throw 'Wrong number of template arguments, given ${arguments.length}, '
@@ -98,14 +102,14 @@ class Template {
}
return instantiator(arguments);
}
- // TODO(sra): Add named placeholders and a Map of arguments.
- throw new UnimplementedError('Template arguments must be a list');
+ assert(arguments is Map);
sra1 2014/10/22 21:50:28 It might be nice to collect the set of names in th
floitsch 2014/11/03 18:12:58 Done.
+ return instantiator(arguments);
}
}
/**
* An Instantiator is a Function that generates a JS AST tree or List of
- * trees. [arguments] is a List for positional templates, or (TODO) Map for
+ * trees. [arguments] is a List for positional templates, or Map for
* named templates.
*/
typedef Node Instantiator(var arguments);
@@ -169,24 +173,24 @@ class InstantiatorGeneratorVisitor implements NodeVisitor<Instantiator> {
}
Instantiator visitInterpolatedExpression(InterpolatedExpression node) {
- int position = node.name;
+ var name = node.name;
return (arguments) {
- var value = arguments[position];
+ var value = arguments[name];
if (value is Expression) return value;
if (value is String) return convertStringToVariableUse(value);;
- error('Interpolated value #$position is not an Expression: $value');
+ error('Interpolated value #$name is not an Expression: $value');
};
}
Instantiator visitSplayableExpression(Node node) {
if (node is InterpolatedExpression) {
- int position = node.name;
+ var name = node.name;
return (arguments) {
- var value = arguments[position];
+ var value = arguments[name];
Expression toExpression(item) {
if (item is Expression) return item;
if (item is String) return convertStringToVariableUse(item);
- return error('Interpolated value #$position is not '
+ return error('Interpolated value #$name is not '
'an Expression or List of Expressions: $value');
}
if (value is Iterable) return value.map(toExpression);
@@ -197,23 +201,23 @@ class InstantiatorGeneratorVisitor implements NodeVisitor<Instantiator> {
}
Instantiator visitInterpolatedLiteral(InterpolatedLiteral node) {
- int position = node.name;
+ var name = node.name;
return (arguments) {
- var value = arguments[position];
+ var value = arguments[name];
if (value is Literal) return value;
- error('Interpolated value #$position is not a Literal: $value');
+ error('Interpolated value #$name is not a Literal: $value');
};
}
Instantiator visitInterpolatedParameter(InterpolatedParameter node) {
- int position = node.name;
+ var name = node.name;
return (arguments) {
- var value = arguments[position];
+ var value = arguments[name];
Parameter toParameter(item) {
if (item is Parameter) return item;
if (item is String) return new Parameter(item);
- return error('Interpolated value #$position is not a Parameter or '
+ return error('Interpolated value #$name is not a Parameter or '
'List of Parameters: $value');
}
if (value is Iterable) return value.map(toParameter);
@@ -225,33 +229,33 @@ class InstantiatorGeneratorVisitor implements NodeVisitor<Instantiator> {
// A selector is an expression, as in `a[selector]`.
// A String argument converted into a LiteralString, so `a.#` with argument
// 'foo' generates `a["foo"]` which prints as `a.foo`.
- int position = node.name;
+ var name = node.name;
return (arguments) {
- var value = arguments[position];
+ var value = arguments[name];
if (value is Expression) return value;
if (value is String) return new LiteralString('"$value"');
- error('Interpolated value #$position is not a selector: $value');
+ error('Interpolated value #$name is not a selector: $value');
};
}
Instantiator visitInterpolatedStatement(InterpolatedStatement node) {
- int position = node.name;
+ var name = node.name;
return (arguments) {
- var value = arguments[position];
+ var value = arguments[name];
if (value is Node) return value.toStatement();
- error('Interpolated value #$position is not a Statement: $value');
+ error('Interpolated value #$name is not a Statement: $value');
};
}
Instantiator visitSplayableStatement(Node node) {
if (node is InterpolatedStatement) {
- int position = node.name;
+ var name = node.name;
return (arguments) {
- var value = arguments[position];
+ var value = arguments[name];
Statement toStatement(item) {
if (item is Statement) return item;
if (item is Expression) return item.toStatement();;
- return error('Interpolated value #$position is not '
+ return error('Interpolated value #$name is not '
'a Statement or List of Statements: $value');
}
if (value is Iterable) return value.map(toStatement);
@@ -322,13 +326,13 @@ class InstantiatorGeneratorVisitor implements NodeVisitor<Instantiator> {
Instantiator visitIfConditionalCompilation(If node) {
// Special version of visitInterpolatedExpression that permits bools.
compileCondition(InterpolatedExpression node) {
- int position = node.name;
+ var name = node.name;
return (arguments) {
- var value = arguments[position];
+ var value = arguments[name];
if (value is bool) return value;
if (value is Expression) return value;
if (value is String) return convertStringToVariableUse(value);;
- error('Interpolated value #$position is not an Expression: $value');
+ error('Interpolated value #$name is not an Expression: $value');
};
}
var makeCondition = compileCondition(node.condition);

Powered by Google App Engine
This is Rietveld 408576698