| 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 826 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 837 | 837 |
| 838 visitNamedFunction(NamedFunction namedFunction) { | 838 visitNamedFunction(NamedFunction namedFunction) { |
| 839 functionOut(namedFunction.function, namedFunction.name); | 839 functionOut(namedFunction.function, namedFunction.name); |
| 840 } | 840 } |
| 841 | 841 |
| 842 visitFun(Fun fun) { | 842 visitFun(Fun fun) { |
| 843 functionOut(fun, null); | 843 functionOut(fun, null); |
| 844 } | 844 } |
| 845 | 845 |
| 846 visitArrowFun(ArrowFun fun) { | 846 visitArrowFun(ArrowFun fun) { |
| 847 if (fun.bindThisWorkaround) { | |
| 848 out("("); | |
| 849 } | |
| 850 localNamer.enterScope(fun); | 847 localNamer.enterScope(fun); |
| 851 if (fun.params.length == 1) { | 848 if (fun.params.length == 1) { |
| 852 visitNestedExpression(fun.params.single, PRIMARY, | 849 visitNestedExpression(fun.params.single, PRIMARY, |
| 853 newInForInit: false, newAtStatementBegin: false); | 850 newInForInit: false, newAtStatementBegin: false); |
| 854 } else { | 851 } else { |
| 855 out("("); | 852 out("("); |
| 856 visitCommaSeparated(fun.params, PRIMARY, | 853 visitCommaSeparated(fun.params, PRIMARY, |
| 857 newInForInit: false, newAtStatementBegin: false); | 854 newInForInit: false, newAtStatementBegin: false); |
| 858 out(")"); | 855 out(")"); |
| 859 } | 856 } |
| 860 spaceOut(); | 857 spaceOut(); |
| 861 out("=>"); | 858 out("=>"); |
| 862 if (fun.body is Expression) { | 859 if (fun.body is Expression) { |
| 863 spaceOut(); | 860 spaceOut(); |
| 864 // Object initializers require parenthesis to disambiguate | 861 // Object initializers require parenthesis to disambiguate |
| 865 // AssignmentExpression from FunctionBody. See: | 862 // AssignmentExpression from FunctionBody. See: |
| 866 // https://people.mozilla.org/~jorendorff/es6-draft.html#sec-arrow-functio
n-definitions | 863 // https://people.mozilla.org/~jorendorff/es6-draft.html#sec-arrow-functio
n-definitions |
| 867 var needsParen = fun.body is ObjectInitializer; | 864 var needsParen = fun.body is ObjectInitializer; |
| 868 if (needsParen) out("("); | 865 if (needsParen) out("("); |
| 869 visitNestedExpression(fun.body, ASSIGNMENT, | 866 visitNestedExpression(fun.body, ASSIGNMENT, |
| 870 newInForInit: false, newAtStatementBegin: false); | 867 newInForInit: false, newAtStatementBegin: false); |
| 871 if (needsParen) out(")"); | 868 if (needsParen) out(")"); |
| 872 } else { | 869 } else { |
| 873 blockBody(fun.body, needsSeparation: false, needsNewline: false); | 870 blockBody(fun.body, needsSeparation: false, needsNewline: false); |
| 874 } | 871 } |
| 875 localNamer.leaveScope(); | 872 localNamer.leaveScope(); |
| 876 if (fun.bindThisWorkaround) { | |
| 877 out(").bind(this)"); | |
| 878 } | |
| 879 } | 873 } |
| 880 | 874 |
| 881 visitLiteralBool(LiteralBool node) { | 875 visitLiteralBool(LiteralBool node) { |
| 882 out(node.value ? "true" : "false"); | 876 out(node.value ? "true" : "false"); |
| 883 } | 877 } |
| 884 | 878 |
| 885 visitLiteralString(LiteralString node) { | 879 visitLiteralString(LiteralString node) { |
| 886 out(node.value); | 880 out(node.value); |
| 887 } | 881 } |
| 888 | 882 |
| (...skipping 548 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1437 declare(node.name); | 1431 declare(node.name); |
| 1438 node.function.accept(this); | 1432 node.function.accept(this); |
| 1439 } | 1433 } |
| 1440 | 1434 |
| 1441 visitClassExpression(ClassExpression node) { | 1435 visitClassExpression(ClassExpression node) { |
| 1442 declare(node.name); | 1436 declare(node.name); |
| 1443 if (node.heritage != null) node.heritage.accept(this); | 1437 if (node.heritage != null) node.heritage.accept(this); |
| 1444 for (Method element in node.methods) element.accept(this); | 1438 for (Method element in node.methods) element.accept(this); |
| 1445 } | 1439 } |
| 1446 } | 1440 } |
| OLD | NEW |