Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 part of js_ast; | 5 part of js_ast; |
| 6 | 6 |
| 7 | 7 |
| 8 class JavaScriptPrintingOptions { | 8 class JavaScriptPrintingOptions { |
| 9 final bool shouldCompressOutput; | 9 final bool shouldCompressOutput; |
| 10 final bool minifyLocalVariables; | 10 final bool minifyLocalVariables; |
| (...skipping 843 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 854 } else { | 854 } else { |
| 855 out("("); | 855 out("("); |
| 856 visitCommaSeparated(fun.params, PRIMARY, | 856 visitCommaSeparated(fun.params, PRIMARY, |
| 857 newInForInit: false, newAtStatementBegin: false); | 857 newInForInit: false, newAtStatementBegin: false); |
| 858 out(")"); | 858 out(")"); |
| 859 } | 859 } |
| 860 spaceOut(); | 860 spaceOut(); |
| 861 out("=>"); | 861 out("=>"); |
| 862 if (fun.body is Expression) { | 862 if (fun.body is Expression) { |
| 863 spaceOut(); | 863 spaceOut(); |
| 864 // Object initializers require parenthesis to disambiguate | |
| 865 // AssignmentExpression from FunctionBody. See: | |
| 866 // https://people.mozilla.org/~jorendorff/es6-draft.html#sec-arrow-functio n-defi... | |
|
Jennifer Messerly
2015/05/19 22:49:48
`sec-arrow-function-definitions` seems to have got
Leaf
2015/05/19 23:24:07
Done.
| |
| 867 var needsParen = fun.body is ObjectInitializer; | |
| 868 if (needsParen) out("("); | |
| 864 visitNestedExpression(fun.body, ASSIGNMENT, | 869 visitNestedExpression(fun.body, ASSIGNMENT, |
| 865 newInForInit: false, newAtStatementBegin: false); | 870 newInForInit: false, newAtStatementBegin: false); |
| 871 if (needsParen) out(")"); | |
| 866 } else { | 872 } else { |
| 867 blockBody(fun.body, needsSeparation: false, needsNewline: false); | 873 blockBody(fun.body, needsSeparation: false, needsNewline: false); |
| 868 } | 874 } |
| 869 localNamer.leaveScope(); | 875 localNamer.leaveScope(); |
| 870 if (fun.bindThisWorkaround) { | 876 if (fun.bindThisWorkaround) { |
| 871 out(").bind(this)"); | 877 out(").bind(this)"); |
| 872 } | 878 } |
| 873 } | 879 } |
| 874 | 880 |
| 875 visitLiteralBool(LiteralBool node) { | 881 visitLiteralBool(LiteralBool node) { |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 913 if (i != elements.length - 1) out(","); | 919 if (i != elements.length - 1) out(","); |
| 914 } | 920 } |
| 915 out("]"); | 921 out("]"); |
| 916 } | 922 } |
| 917 | 923 |
| 918 visitArrayHole(ArrayHole node) { | 924 visitArrayHole(ArrayHole node) { |
| 919 throw "Unreachable"; | 925 throw "Unreachable"; |
| 920 } | 926 } |
| 921 | 927 |
| 922 visitObjectInitializer(ObjectInitializer node) { | 928 visitObjectInitializer(ObjectInitializer node) { |
| 923 // Print all the properties on one line until we see a function-valued | |
| 924 // property. Ideally, we would use a proper pretty-printer to make the | |
| 925 // decision based on layout. | |
| 926 List<Property> properties = node.properties; | 929 List<Property> properties = node.properties; |
| 927 out("{"); | 930 out("{"); |
| 928 indentMore(); | 931 indentMore(); |
| 929 | 932 |
| 930 var isOneLiner = !properties.any((p) => p.value is FunctionExpression); | 933 var isOneLiner = !node.vertical; |
| 931 for (int i = 0; i < properties.length; i++) { | 934 for (int i = 0; i < properties.length; i++) { |
| 932 if (i != 0) { | 935 if (i != 0) { |
| 933 out(","); | 936 out(","); |
| 934 if (isOneLiner) spaceOut(); | 937 if (isOneLiner) spaceOut(); |
| 935 } | 938 } |
| 936 if (!isOneLiner) { | 939 if (!isOneLiner) { |
| 937 forceLine(); | 940 forceLine(); |
| 938 indent(); | 941 indent(); |
| 939 } | 942 } |
| 940 visit(properties[i]); | 943 visit(properties[i]); |
| (...skipping 493 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1434 declare(node.name); | 1437 declare(node.name); |
| 1435 node.function.accept(this); | 1438 node.function.accept(this); |
| 1436 } | 1439 } |
| 1437 | 1440 |
| 1438 visitClassExpression(ClassExpression node) { | 1441 visitClassExpression(ClassExpression node) { |
| 1439 declare(node.name); | 1442 declare(node.name); |
| 1440 if (node.heritage != null) node.heritage.accept(this); | 1443 if (node.heritage != null) node.heritage.accept(this); |
| 1441 for (Method element in node.methods) element.accept(this); | 1444 for (Method element in node.methods) element.accept(this); |
| 1442 } | 1445 } |
| 1443 } | 1446 } |
| OLD | NEW |