| 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 794 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 805 if (!(charCodes.$a <= charCode && charCode <= charCodes.$z || | 805 if (!(charCodes.$a <= charCode && charCode <= charCodes.$z || |
| 806 charCodes.$A <= charCode && charCode <= charCodes.$Z || | 806 charCodes.$A <= charCode && charCode <= charCodes.$Z || |
| 807 charCode == charCodes.$$ || | 807 charCode == charCodes.$$ || |
| 808 charCode == charCodes.$_ || | 808 charCode == charCodes.$_ || |
| 809 i != 1 && isDigit(charCode))) { | 809 i != 1 && isDigit(charCode))) { |
| 810 return false; | 810 return false; |
| 811 } | 811 } |
| 812 } | 812 } |
| 813 | 813 |
| 814 if (options.avoidKeywordsInIdentifiers) { | 814 if (options.avoidKeywordsInIdentifiers) { |
| 815 return !_isJsKeyword(field.substring(1, field.length - 1)); | 815 return !isJsKeyword(field.substring(1, field.length - 1)); |
| 816 } else { | 816 } else { |
| 817 // TODO(floitsch): normally we should also check that the field is not a | 817 // TODO(floitsch): normally we should also check that the field is not a |
| 818 // reserved word. We don't generate fields with reserved word names excep
t | 818 // reserved word. We don't generate fields with reserved word names excep
t |
| 819 // for 'super'. | 819 // for 'super'. |
| 820 return field != '"super"'; | 820 return field != '"super"'; |
| 821 } | 821 } |
| 822 } | 822 } |
| 823 | 823 |
| 824 static bool _isJsKeyword(String keyword) { | |
| 825 switch (keyword) { | |
| 826 case "break": | |
| 827 case "case": | |
| 828 case "catch": | |
| 829 case "class": | |
| 830 case "const": | |
| 831 case "continue": | |
| 832 case "debugger": | |
| 833 case "default": | |
| 834 case "delete": | |
| 835 case "do": | |
| 836 case "else": | |
| 837 case "export": | |
| 838 case "extends": | |
| 839 case "finally": | |
| 840 case "for": | |
| 841 case "function": | |
| 842 case "if": | |
| 843 case "import": | |
| 844 case "in": | |
| 845 case "instanceof": | |
| 846 case "let": | |
| 847 case "new": | |
| 848 case "return": | |
| 849 case "static": | |
| 850 case "super": | |
| 851 case "switch": | |
| 852 case "this": | |
| 853 case "throw": | |
| 854 case "try": | |
| 855 case "typeof": | |
| 856 case "var": | |
| 857 case "void": | |
| 858 case "while": | |
| 859 case "with": | |
| 860 case "yield": | |
| 861 return true; | |
| 862 } | |
| 863 return false; | |
| 864 } | |
| 865 | |
| 866 visitAccess(PropertyAccess access) { | 824 visitAccess(PropertyAccess access) { |
| 867 visitNestedExpression(access.receiver, CALL, | 825 visitNestedExpression(access.receiver, CALL, |
| 868 newInForInit: inForInit, | 826 newInForInit: inForInit, |
| 869 newAtStatementBegin: atStatementBegin); | 827 newAtStatementBegin: atStatementBegin); |
| 870 propertyNameOut(access.selector, inAccess: true); | 828 propertyNameOut(access.selector, inAccess: true); |
| 871 } | 829 } |
| 872 | 830 |
| 873 visitNamedFunction(NamedFunction namedFunction) { | 831 visitNamedFunction(NamedFunction namedFunction) { |
| 874 VarCollector vars = new VarCollector(); | 832 VarCollector vars = new VarCollector(); |
| 875 vars.visitNamedFunction(namedFunction); | 833 vars.visitNamedFunction(namedFunction); |
| (...skipping 571 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1447 codes.add(nthLetter((n ~/ nameSpaceSize) % LETTERS)); | 1405 codes.add(nthLetter((n ~/ nameSpaceSize) % LETTERS)); |
| 1448 } | 1406 } |
| 1449 codes.add(charCodes.$0 + digit); | 1407 codes.add(charCodes.$0 + digit); |
| 1450 newName = new String.fromCharCodes(codes); | 1408 newName = new String.fromCharCodes(codes); |
| 1451 } | 1409 } |
| 1452 assert(new RegExp(r'[a-zA-Z][a-zA-Z0-9]*').hasMatch(newName)); | 1410 assert(new RegExp(r'[a-zA-Z][a-zA-Z0-9]*').hasMatch(newName)); |
| 1453 maps.last[oldName] = newName; | 1411 maps.last[oldName] = newName; |
| 1454 return newName; | 1412 return newName; |
| 1455 } | 1413 } |
| 1456 } | 1414 } |
| OLD | NEW |