| 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 | 10 |
| (...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 321 /// | 321 /// |
| 322 /// Note that this function only puts quotes around [value]. It does not do | 322 /// Note that this function only puts quotes around [value]. It does not do |
| 323 /// any escaping, so use only when you can guarantee that [value] does not | 323 /// any escaping, so use only when you can guarantee that [value] does not |
| 324 /// contain newlines or backslashes. For escaping the string use | 324 /// contain newlines or backslashes. For escaping the string use |
| 325 /// [escapedString]. | 325 /// [escapedString]. |
| 326 LiteralString string(String value) => new LiteralString('"$value"'); | 326 LiteralString string(String value) => new LiteralString('"$value"'); |
| 327 | 327 |
| 328 LiteralNumber number(num value) => new LiteralNumber('$value'); | 328 LiteralNumber number(num value) => new LiteralNumber('$value'); |
| 329 | 329 |
| 330 ArrayInitializer numArray(Iterable<int> list) => | 330 ArrayInitializer numArray(Iterable<int> list) => |
| 331 new ArrayInitializer.from(list.map(number)); | 331 new ArrayInitializer(list.map(number).toList()); |
| 332 | 332 |
| 333 ArrayInitializer stringArray(Iterable<String> list) => | 333 ArrayInitializer stringArray(Iterable<String> list) => |
| 334 new ArrayInitializer.from(list.map(string)); | 334 new ArrayInitializer(list.map(string).toList()); |
| 335 | 335 |
| 336 Comment comment(String text) => new Comment(text); | 336 Comment comment(String text) => new Comment(text); |
| 337 | 337 |
| 338 Call propertyCall(Expression receiver, | 338 Call propertyCall(Expression receiver, |
| 339 String fieldName, | 339 String fieldName, |
| 340 List<Expression> arguments) { | 340 List<Expression> arguments) { |
| 341 return new Call(new PropertyAccess.field(receiver, fieldName), arguments); | 341 return new Call(new PropertyAccess.field(receiver, fieldName), arguments); |
| 342 } | 342 } |
| 343 } | 343 } |
| 344 | 344 |
| (...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 720 Expression expression = parseExpression(); | 720 Expression expression = parseExpression(); |
| 721 expectCategory(RPAREN); | 721 expectCategory(RPAREN); |
| 722 return expression; | 722 return expression; |
| 723 } else if (acceptCategory(STRING)) { | 723 } else if (acceptCategory(STRING)) { |
| 724 return new LiteralString(last); | 724 return new LiteralString(last); |
| 725 } else if (acceptCategory(NUMERIC)) { | 725 } else if (acceptCategory(NUMERIC)) { |
| 726 return new LiteralNumber(last); | 726 return new LiteralNumber(last); |
| 727 } else if (acceptCategory(LBRACE)) { | 727 } else if (acceptCategory(LBRACE)) { |
| 728 return parseObjectInitializer(); | 728 return parseObjectInitializer(); |
| 729 } else if (acceptCategory(LSQUARE)) { | 729 } else if (acceptCategory(LSQUARE)) { |
| 730 var values = <ArrayElement>[]; | 730 var values = <Expression>[]; |
| 731 if (!acceptCategory(RSQUARE)) { | 731 if (!acceptCategory(RSQUARE)) { |
| 732 do { | 732 do { |
| 733 values.add(new ArrayElement(values.length, parseAssignment())); | 733 values.add(parseAssignment()); |
| 734 } while (acceptCategory(COMMA)); | 734 } while (acceptCategory(COMMA)); |
| 735 expectCategory(RSQUARE); | 735 expectCategory(RSQUARE); |
| 736 } | 736 } |
| 737 return new ArrayInitializer(values.length, values); | 737 return new ArrayInitializer(values); |
| 738 } else if (last != null && last.startsWith("/")) { | 738 } else if (last != null && last.startsWith("/")) { |
| 739 String regexp = getDelimited(lastPosition); | 739 String regexp = getDelimited(lastPosition); |
| 740 getToken(); | 740 getToken(); |
| 741 String flags = lastToken; | 741 String flags = lastToken; |
| 742 if (!acceptCategory(ALPHA)) flags = ""; | 742 if (!acceptCategory(ALPHA)) flags = ""; |
| 743 Expression expression = new RegExpLiteral(regexp + flags); | 743 Expression expression = new RegExpLiteral(regexp + flags); |
| 744 return expression; | 744 return expression; |
| 745 } else if (acceptCategory(HASH)) { | 745 } else if (acceptCategory(HASH)) { |
| 746 var nameOrPosition = parseHash(); | 746 var nameOrPosition = parseHash(); |
| 747 InterpolatedExpression expression = | 747 InterpolatedExpression expression = |
| (...skipping 483 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1231 Catch parseCatch() { | 1231 Catch parseCatch() { |
| 1232 expectCategory(LPAREN); | 1232 expectCategory(LPAREN); |
| 1233 String identifier = lastToken; | 1233 String identifier = lastToken; |
| 1234 expectCategory(ALPHA); | 1234 expectCategory(ALPHA); |
| 1235 expectCategory(RPAREN); | 1235 expectCategory(RPAREN); |
| 1236 expectCategory(LBRACE); | 1236 expectCategory(LBRACE); |
| 1237 Block body = parseBlock(); | 1237 Block body = parseBlock(); |
| 1238 return new Catch(new VariableDeclaration(identifier), body); | 1238 return new Catch(new VariableDeclaration(identifier), body); |
| 1239 } | 1239 } |
| 1240 } | 1240 } |
| OLD | NEW |