| 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 { |
| 11 const JsBuilder(); | 11 const JsBuilder(); |
| 12 | 12 |
| 13 Expression operator [](String source) { | 13 Expression call(String source) { |
| 14 return new MiniJsParser(source).expression(); | 14 return new MiniJsParser(source).expression(); |
| 15 } | 15 } |
| 16 | 16 |
| 17 // TODO(ahe): Remove this method. | |
| 18 Binary equals(Expression left, Expression right) { | |
| 19 return new Binary('==', left, right); | |
| 20 } | |
| 21 | |
| 22 // TODO(ahe): Remove this method. | |
| 23 Binary strictEquals(Expression left, Expression right) { | |
| 24 return new Binary('===', left, right); | |
| 25 } | |
| 26 | |
| 27 LiteralString string(String value) => new LiteralString('"$value"'); | 17 LiteralString string(String value) => new LiteralString('"$value"'); |
| 28 | 18 |
| 29 If if_(condition, thenPart, [elsePart]) { | 19 If if_(condition, thenPart, [elsePart]) { |
| 30 condition = toExpression(condition); | 20 condition = toExpression(condition); |
| 31 return (elsePart == null) | 21 return (elsePart == null) |
| 32 ? new If.noElse(condition, toStatement(thenPart)) | 22 ? new If.noElse(condition, toStatement(thenPart)) |
| 33 : new If(condition, toStatement(thenPart), toStatement(elsePart)); | 23 : new If(condition, toStatement(thenPart), toStatement(elsePart)); |
| 34 } | 24 } |
| 35 | 25 |
| 36 Return return_([value]) { | 26 Return return_([value]) { |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 return statement.toStatement(); | 75 return statement.toStatement(); |
| 86 } else { | 76 } else { |
| 87 throw new ArgumentError('statement'); | 77 throw new ArgumentError('statement'); |
| 88 } | 78 } |
| 89 } | 79 } |
| 90 | 80 |
| 91 Expression toExpression(expression) { | 81 Expression toExpression(expression) { |
| 92 if (expression is Expression) { | 82 if (expression is Expression) { |
| 93 return expression; | 83 return expression; |
| 94 } else if (expression is String) { | 84 } else if (expression is String) { |
| 95 return this[expression]; | 85 return this(expression); |
| 96 } else if (expression is num) { | 86 } else if (expression is num) { |
| 97 return new LiteralNumber('$expression'); | 87 return new LiteralNumber('$expression'); |
| 98 } else if (expression is bool) { | 88 } else if (expression is bool) { |
| 99 return new LiteralBool(expression); | 89 return new LiteralBool(expression); |
| 100 } else if (expression is Map) { | 90 } else if (expression is Map) { |
| 101 if (!expression.isEmpty) { | 91 if (!expression.isEmpty) { |
| 102 throw new ArgumentError('expression should be an empty Map'); | 92 throw new ArgumentError('expression should be an empty Map'); |
| 103 } | 93 } |
| 104 return new ObjectInitializer([]); | 94 return new ObjectInitializer([]); |
| 105 } else { | 95 } else { |
| (...skipping 442 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 548 | 538 |
| 549 Expression expression() { | 539 Expression expression() { |
| 550 Expression expression = parseVarDeclarationOrExpression(); | 540 Expression expression = parseVarDeclarationOrExpression(); |
| 551 if (lastCategory != NONE || position != src.length) { | 541 if (lastCategory != NONE || position != src.length) { |
| 552 throw new MiniJsParserError( | 542 throw new MiniJsParserError( |
| 553 this, "Unparsed junk: ${categoryToString(lastCategory)}"); | 543 this, "Unparsed junk: ${categoryToString(lastCategory)}"); |
| 554 } | 544 } |
| 555 return expression; | 545 return expression; |
| 556 } | 546 } |
| 557 } | 547 } |
| OLD | NEW |