| 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 // Utilities for building JS ASTs at runtime. Contains a builder class | 5 // Utilities for building JS ASTs at runtime. Contains a builder class |
| 6 // and a parser that parses part of the language. | 6 // and a parser that parses part of the language. |
| 7 | 7 |
| 8 part of js; | 8 part of js; |
| 9 | 9 |
| 10 class JsBuilder { | 10 class JsBuilder { |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 } else if (expression is num) { | 119 } else if (expression is num) { |
| 120 return new LiteralNumber('$expression'); | 120 return new LiteralNumber('$expression'); |
| 121 } else if (expression is bool) { | 121 } else if (expression is bool) { |
| 122 return new LiteralBool(expression); | 122 return new LiteralBool(expression); |
| 123 } else if (expression is Map) { | 123 } else if (expression is Map) { |
| 124 if (!expression.isEmpty) { | 124 if (!expression.isEmpty) { |
| 125 throw new ArgumentError('expression should be an empty Map'); | 125 throw new ArgumentError('expression should be an empty Map'); |
| 126 } | 126 } |
| 127 return new ObjectInitializer([]); | 127 return new ObjectInitializer([]); |
| 128 } else if (expression is List) { | 128 } else if (expression is List) { |
| 129 var values = new List<ArrayElement>(expression.length); | 129 var values = new List<ArrayElement>.generate(expression.length, |
| 130 int index = 0; | 130 (index) => new ArrayElement(index, toExpression(expression[index]))); |
| 131 for (var entry in expression) { | |
| 132 values[index] = new ArrayElement(index, toExpression(entry)); | |
| 133 index++; | |
| 134 } | |
| 135 return new ArrayInitializer(values.length, values); | 131 return new ArrayInitializer(values.length, values); |
| 136 } else { | 132 } else { |
| 137 throw new ArgumentError('expression should be an Expression, ' | 133 throw new ArgumentError('expression should be an Expression, ' |
| 138 'a String, a num, a bool, or a Map'); | 134 'a String, a num, a bool, a Map, or a List;'); |
| 139 } | 135 } |
| 140 } | 136 } |
| 141 | 137 |
| 142 ForIn forIn(String name, object, statement) { | 138 ForIn forIn(String name, object, statement) { |
| 143 return new ForIn(defineVar(name), | 139 return new ForIn(defineVar(name), |
| 144 toExpression(object), | 140 toExpression(object), |
| 145 toStatement(statement)); | 141 toStatement(statement)); |
| 146 } | 142 } |
| 147 | 143 |
| 148 For for_(init, condition, update, statement) { | 144 For for_(init, condition, update, statement) { |
| (...skipping 643 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 792 } | 788 } |
| 793 | 789 |
| 794 Node visitLiteralNull(LiteralNull node) { | 790 Node visitLiteralNull(LiteralNull node) { |
| 795 return node; | 791 return node; |
| 796 } | 792 } |
| 797 | 793 |
| 798 Node visitLiteralBool(LiteralBool node) { | 794 Node visitLiteralBool(LiteralBool node) { |
| 799 return node; | 795 return node; |
| 800 } | 796 } |
| 801 } | 797 } |
| OLD | NEW |