| Index: sdk/lib/_internal/compiler/implementation/js/builder.dart
|
| diff --git a/sdk/lib/_internal/compiler/implementation/js/builder.dart b/sdk/lib/_internal/compiler/implementation/js/builder.dart
|
| index 838dbc82dbae9b2bb2f3addc4eae4cba91eede68..47a285e01eb287ed3c5db07f2f24574adb562b4f 100644
|
| --- a/sdk/lib/_internal/compiler/implementation/js/builder.dart
|
| +++ b/sdk/lib/_internal/compiler/implementation/js/builder.dart
|
| @@ -208,7 +208,9 @@ class JsBuilder {
|
| Expression call(String source, [var arguments]) {
|
| Template template = _findExpressionTemplate(source);
|
| if (arguments == null) return template.instantiate([]);
|
| - return template.instantiate(arguments is List ? arguments : [arguments]);
|
| + // We allow a single argument to be given directly.
|
| + if (arguments is! List && arguments is! Map) arguments = [arguments];
|
| + return template.instantiate(arguments);
|
| }
|
|
|
| /**
|
| @@ -217,7 +219,9 @@ class JsBuilder {
|
| Statement statement(String source, [var arguments]) {
|
| Template template = _findStatementTemplate(source);
|
| if (arguments == null) return template.instantiate([]);
|
| - return template.instantiate(arguments is List ? arguments : [arguments]);
|
| + // We allow a single argument to be given directly.
|
| + if (arguments is! List && arguments is! Map) arguments = [arguments];
|
| + return template.instantiate(arguments);
|
| }
|
|
|
| /**
|
| @@ -402,6 +406,11 @@ class MiniJsParser {
|
| int position = 0;
|
| bool skippedNewline = false; // skipped newline in last getToken?
|
| final String src;
|
| +
|
| + /// Whether the template uses named or positional holes.
|
| + ///
|
| + /// Initially set to `null`, and updated when the first hole is encountered.
|
| + bool hasNamedHoles;
|
| final List<InterpolatedNode> interpolatedValues = <InterpolatedNode>[];
|
|
|
| static const NONE = -1;
|
| @@ -664,6 +673,40 @@ class MiniJsParser {
|
| throw new MiniJsParserError(this, message);
|
| }
|
|
|
| + /// Returns either the name for the hole, or its integer position.
|
| + parseHash() {
|
| + String holeName = lastToken;
|
| + if (acceptCategory(ALPHA)) {
|
| + // Named hole. Example: 'function #funName() { ... }'
|
| + if (hasNamedHoles == false) {
|
| + error('Holes must all be positional or named. $holeName');
|
| + }
|
| + hasNamedHoles = true;
|
| + return holeName;
|
| + } else if (acceptCategory(LBRACE)) {
|
| + // Named guarded hole. Example: 'function #{funName}() { ... }'
|
| + String holeName = lastToken;
|
| + if (!acceptCategory(ALPHA)) {
|
| + error('Named hole does not contain alpha-characters.');
|
| + }
|
| + if (!acceptCategory(RBRACE)) {
|
| + error('Named hole is not correctly terminated with `}`');
|
| + }
|
| + if (hasNamedHoles == false) {
|
| + error('Holes must all be positional or named. $holeName');
|
| + }
|
| + hasNamedHoles = true;
|
| + return holeName;
|
| + } else {
|
| + if (hasNamedHoles == true) {
|
| + error('Holes must all be positional or named. $holeName');
|
| + }
|
| + hasNamedHoles = false;
|
| + int position = interpolatedValues.length;
|
| + return position;
|
| + }
|
| + }
|
| +
|
| Expression parsePrimary() {
|
| String last = lastToken;
|
| if (acceptCategory(ALPHA)) {
|
| @@ -705,8 +748,8 @@ class MiniJsParser {
|
| Expression expression = new RegExpLiteral(regexp + flags);
|
| return expression;
|
| } else if (acceptCategory(HASH)) {
|
| - InterpolatedExpression expression =
|
| - new InterpolatedExpression(interpolatedValues.length);
|
| + var name = parseHash();
|
| + InterpolatedExpression expression = new InterpolatedExpression(name);
|
| interpolatedValues.add(expression);
|
| return expression;
|
| } else {
|
| @@ -732,8 +775,8 @@ class MiniJsParser {
|
| if (!acceptCategory(RPAREN)) {
|
| for (;;) {
|
| if (acceptCategory(HASH)) {
|
| - InterpolatedParameter parameter =
|
| - new InterpolatedParameter(interpolatedValues.length);
|
| + var name = parseHash();
|
| + InterpolatedParameter parameter = new InterpolatedParameter(name);
|
| interpolatedValues.add(parameter);
|
| params.add(parameter);
|
| } else {
|
| @@ -766,8 +809,9 @@ class MiniJsParser {
|
| } else if (acceptCategory(SYMBOL)) { // e.g. void
|
| propertyName = new LiteralString('"$identifier"');
|
| } else if (acceptCategory(HASH)) {
|
| + var name = parseHash();
|
| InterpolatedLiteral interpolatedLiteral =
|
| - new InterpolatedLiteral(interpolatedValues.length);
|
| + new InterpolatedLiteral(name);
|
| interpolatedValues.add(interpolatedLiteral);
|
| propertyName = interpolatedLiteral;
|
| } else {
|
| @@ -833,8 +877,8 @@ class MiniJsParser {
|
|
|
| Expression getDotRhs(Expression receiver) {
|
| if (acceptCategory(HASH)) {
|
| - InterpolatedSelector property =
|
| - new InterpolatedSelector(interpolatedValues.length);
|
| + var name = parseHash();
|
| + InterpolatedSelector property = new InterpolatedSelector(name);
|
| interpolatedValues.add(property);
|
| return new PropertyAccess(receiver, property);
|
| }
|
|
|