| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 /** | 5 /** |
| 6 * This provides classes to represent the internal structure of the | 6 * This provides classes to represent the internal structure of the |
| 7 * arguments to `Intl.message`. It is used when parsing sources to extract | 7 * arguments to `Intl.message`. It is used when parsing sources to extract |
| 8 * messages or to generate code for message substitution. Normal programs | 8 * messages or to generate code for message substitution. Normal programs |
| 9 * using Intl would not import this library. | 9 * using Intl would not import this library. |
| 10 * | 10 * |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 return "The 'args' argument for Intl.message must be specified"; | 70 return "The 'args' argument for Intl.message must be specified"; |
| 71 } | 71 } |
| 72 | 72 |
| 73 var messageName = arguments.firstWhere( | 73 var messageName = arguments.firstWhere( |
| 74 (eachArg) => eachArg is NamedExpression && | 74 (eachArg) => eachArg is NamedExpression && |
| 75 eachArg.name.label.name == 'name', | 75 eachArg.name.label.name == 'name', |
| 76 orElse: () => null); | 76 orElse: () => null); |
| 77 if (messageName == null) { | 77 if (messageName == null) { |
| 78 return "The 'name' argument for Intl.message must be specified"; | 78 return "The 'name' argument for Intl.message must be specified"; |
| 79 } | 79 } |
| 80 if ((messageName.expression is! SimpleStringLiteral) | 80 if (messageName.expression is! SimpleStringLiteral) { |
| 81 || messageName.expression.value != outerName) { | |
| 82 return "The 'name' argument for Intl.message must be a simple string " | 81 return "The 'name' argument for Intl.message must be a simple string " |
| 83 "literal and match the containing function name."; | 82 "literal."; |
| 84 } | 83 } |
| 85 var simpleArguments = arguments.where( | 84 var simpleArguments = arguments.where( |
| 86 (each) => each is NamedExpression | 85 (each) => each is NamedExpression |
| 87 && ["desc", "locale", "name"].contains(each.name.label.name)); | 86 && ["desc", "name"].contains(each.name.label.name)); |
| 88 var values = simpleArguments.map((each) => each.expression).toList(); | 87 var values = simpleArguments.map((each) => each.expression).toList(); |
| 89 for (var arg in values) { | 88 for (var arg in values) { |
| 90 if (arg is! SimpleStringLiteral) { | 89 if (arg is! SimpleStringLiteral) { |
| 91 return "Intl.message argument '${arg.name.label.name}' must be " | 90 return "Intl.message argument '$arg' must be " |
| 92 "a simple string literal"; | 91 "a simple string literal"; |
| 93 } | 92 } |
| 94 } | 93 } |
| 95 } | 94 } |
| 96 | 95 |
| 97 /** | 96 /** |
| 98 * Turn a value, typically read from a translation file or created out of an | 97 * Turn a value, typically read from a translation file or created out of an |
| 99 * AST for a source program, into the appropriate | 98 * AST for a source program, into the appropriate |
| 100 * subclass. We expect to get literal Strings, variable substitutions | 99 * subclass. We expect to get literal Strings, variable substitutions |
| 101 * represented by integers, things that are already MessageChunks and | 100 * represented by integers, things that are already MessageChunks and |
| (...skipping 533 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 635 out.write('('); | 634 out.write('('); |
| 636 out.write(mainArgument); | 635 out.write(mainArgument); |
| 637 var args = codeAttributeNames; | 636 var args = codeAttributeNames; |
| 638 out.write(", {"); | 637 out.write(", {"); |
| 639 args.fold(out, (buffer, arg) => buffer..write( | 638 args.fold(out, (buffer, arg) => buffer..write( |
| 640 "'$arg': '${this[arg].toCode()}', ")); | 639 "'$arg': '${this[arg].toCode()}', ")); |
| 641 out.write("})}"); | 640 out.write("})}"); |
| 642 return out.toString(); | 641 return out.toString(); |
| 643 } | 642 } |
| 644 } | 643 } |
| OLD | NEW |