Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(122)

Side by Side Diff: lib/src/js/printer.dart

Issue 1030243002: [cleanup] remove PropertyName from js_ast (Closed) Base URL: git@github.com:dart-lang/dev_compiler.git@master
Patch Set: Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 1008 matching lines...) Expand 10 before | Expand all | Expand 10 after
1019 // TODO(jmesserly): async modifiers 1019 // TODO(jmesserly): async modifiers
1020 if (fun.body.statements.isEmpty) { 1020 if (fun.body.statements.isEmpty) {
1021 spaceOut(); 1021 spaceOut();
1022 out("{}"); 1022 out("{}");
1023 } else { 1023 } else {
1024 blockBody(fun.body, needsSeparation: false, needsNewline: false); 1024 blockBody(fun.body, needsSeparation: false, needsNewline: false);
1025 } 1025 }
1026 localNamer.leaveScope(); 1026 localNamer.leaveScope();
1027 } 1027 }
1028 1028
1029 visitPropertyName(PropertyName node) => propertyNameOut(node);
1030
1031 void propertyNameOut(Expression node, {bool inMethod: false, 1029 void propertyNameOut(Expression node, {bool inMethod: false,
1032 bool inAccess: false}) { 1030 bool inAccess: false}) {
1033 1031
1034 if (node is LiteralNumber) { 1032 if (node is LiteralNumber) {
1035 LiteralNumber nameNumber = node; 1033 LiteralNumber nameNumber = node;
1036 if (inAccess) out('['); 1034 if (inAccess) out('[');
1037 out(nameNumber.value); 1035 out(nameNumber.value);
1038 if (inAccess) out(']'); 1036 if (inAccess) out(']');
1039 } else { 1037 } else {
1040 String quotedName; 1038 if (node is LiteralString) {
1041 if (node is PropertyName) { 1039 var quotedName = node.value;
1042 quotedName = "'${node.name}'";
1043 } else if (node is LiteralString) {
1044 quotedName = node.value;
1045 }
1046 if (quotedName != null) {
1047 if (isValidJavaScriptId(quotedName)) { 1040 if (isValidJavaScriptId(quotedName)) {
1048 if (inAccess) out('.'); 1041 if (inAccess) out('.');
1049 out(quotedName.substring(1, quotedName.length - 1)); 1042 out(quotedName.substring(1, quotedName.length - 1));
1050 } else { 1043 } else {
1051 if (inMethod || inAccess) out("["); 1044 if (inMethod || inAccess) out("[");
1052 out(quotedName); 1045 out(quotedName);
1053 if (inMethod || inAccess) out("]"); 1046 if (inMethod || inAccess) out("]");
1054 } 1047 }
1055 } else { 1048 } else {
1056 // ComputedPropertyName 1049 // ComputedPropertyName
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
1093 1086
1094 visitInterpolatedLiteral(InterpolatedLiteral node) => 1087 visitInterpolatedLiteral(InterpolatedLiteral node) =>
1095 visitInterpolatedNode(node); 1088 visitInterpolatedNode(node);
1096 1089
1097 visitInterpolatedParameter(InterpolatedParameter node) => 1090 visitInterpolatedParameter(InterpolatedParameter node) =>
1098 visitInterpolatedNode(node); 1091 visitInterpolatedNode(node);
1099 1092
1100 visitInterpolatedSelector(InterpolatedSelector node) => 1093 visitInterpolatedSelector(InterpolatedSelector node) =>
1101 visitInterpolatedNode(node); 1094 visitInterpolatedNode(node);
1102 1095
1103 visitInterpolatedPropertyName(InterpolatedPropertyName node) =>
1104 visitInterpolatedNode(node);
1105
1106 visitInterpolatedMethod(InterpolatedMethod node) => 1096 visitInterpolatedMethod(InterpolatedMethod node) =>
1107 visitInterpolatedNode(node); 1097 visitInterpolatedNode(node);
1108 1098
1109 visitInterpolatedVariableDeclaration(InterpolatedVariableDeclaration node) => 1099 visitInterpolatedVariableDeclaration(InterpolatedVariableDeclaration node) =>
1110 visitInterpolatedNode(node); 1100 visitInterpolatedNode(node);
1111 1101
1112 visitInterpolatedStatement(InterpolatedStatement node) { 1102 visitInterpolatedStatement(InterpolatedStatement node) {
1113 outLn('#${node.nameOrPosition}'); 1103 outLn('#${node.nameOrPosition}');
1114 } 1104 }
1115 1105
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after
1405 codes.add(nthLetter((n ~/ nameSpaceSize) % LETTERS)); 1395 codes.add(nthLetter((n ~/ nameSpaceSize) % LETTERS));
1406 } 1396 }
1407 codes.add(charCodes.$0 + digit); 1397 codes.add(charCodes.$0 + digit);
1408 newName = new String.fromCharCodes(codes); 1398 newName = new String.fromCharCodes(codes);
1409 } 1399 }
1410 assert(new RegExp(r'[a-zA-Z][a-zA-Z0-9]*').hasMatch(newName)); 1400 assert(new RegExp(r'[a-zA-Z][a-zA-Z0-9]*').hasMatch(newName));
1411 maps.last[oldName] = newName; 1401 maps.last[oldName] = newName;
1412 return newName; 1402 return newName;
1413 } 1403 }
1414 } 1404 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698