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

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

Issue 1458243002: implement ES6 modules in JS AST. (Closed) Base URL: git@github.com:dart-lang/dev_compiler.git@master
Patch Set: Created 5 years, 1 month 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 1109 matching lines...) Expand 10 before | Expand all | Expand 10 after
1120 } else { 1120 } else {
1121 // ComputedPropertyName 1121 // ComputedPropertyName
1122 out("["); 1122 out("[");
1123 visitNestedExpression(node, EXPRESSION, 1123 visitNestedExpression(node, EXPRESSION,
1124 newInForInit: false, newAtStatementBegin: false); 1124 newInForInit: false, newAtStatementBegin: false);
1125 out("]"); 1125 out("]");
1126 } 1126 }
1127 } 1127 }
1128 } 1128 }
1129 1129
1130 visitImportDeclaration(ImportDeclaration node) {
1131 indent();
1132 out('import ');
1133 if (node.defaultBinding != null) {
1134 visit(node.defaultBinding);
1135 if (node.namedImports != null) {
1136 out(',');
1137 spaceOut();
1138 }
1139 }
1140 nameSpecifierListOut(node.namedImports);
1141 fromClauseOut(node.from);
1142 outSemicolonLn();
1143 }
1144
1145 visitExportDeclaration(ExportDeclaration node) {
1146 indent();
1147 out('export ');
1148 if (node.isDefault) out('default ');
1149 // TODO(jmesserly): we need to avoid indent/newline if this is a statement.
1150 visit(node.exported);
1151 outSemicolonLn();
1152 }
1153
1154 visitExportClause(ExportClause node) {
1155 nameSpecifierListOut(node.exports);
1156 fromClauseOut(node.from);
1157 }
1158
1159 nameSpecifierListOut(List<NameSpecifier> names) {
1160 if (names == null) return;
1161
1162 if (names.length == 1 && names[0].name == '*') {
1163 visit(names[0]);
1164 return;
1165 }
1166
1167 out('{');
1168 spaceOut();
1169 for (int i = 0; i < names.length; i++) {
1170 if (i != 0) {
1171 out(',');
1172 spaceOut();
1173 }
1174 visit(names[i]);
1175 }
1176 spaceOut();
1177 out('}');
1178 }
1179
1180 fromClauseOut(LiteralString from) {
1181 if (from != null) {
1182 out(' from');
1183 spaceOut();
1184 visit(from);
1185 }
1186 }
1187
1188 visitNameSpecifier(NameSpecifier node) {
1189 out(node.name);
1190 if (node.asName != null) {
1191 out(' as ');
1192 out(node.asName);
1193 }
1194 }
1195
1196 visitModule(Module node) {
1197 visitAll(node.body);
1198 }
1199
1130 visitLiteralExpression(LiteralExpression node) { 1200 visitLiteralExpression(LiteralExpression node) {
1131 String template = node.template; 1201 String template = node.template;
1132 List<Expression> inputs = node.inputs; 1202 List<Expression> inputs = node.inputs;
1133 1203
1134 List<String> parts = template.split('#'); 1204 List<String> parts = template.split('#');
1135 int inputsLength = inputs == null ? 0 : inputs.length; 1205 int inputsLength = inputs == null ? 0 : inputs.length;
1136 if (parts.length != inputsLength + 1) { 1206 if (parts.length != inputsLength + 1) {
1137 context.error('Wrong number of arguments for JS: $template'); 1207 context.error('Wrong number of arguments for JS: $template');
1138 } 1208 }
1139 // Code that uses JS must take care of operator precedences, and 1209 // Code that uses JS must take care of operator precedences, and
(...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after
1497 declare(node.name); 1567 declare(node.name);
1498 node.function.accept(this); 1568 node.function.accept(this);
1499 } 1569 }
1500 1570
1501 visitClassExpression(ClassExpression node) { 1571 visitClassExpression(ClassExpression node) {
1502 declare(node.name); 1572 declare(node.name);
1503 if (node.heritage != null) node.heritage.accept(this); 1573 if (node.heritage != null) node.heritage.accept(this);
1504 for (Method element in node.methods) element.accept(this); 1574 for (Method element in node.methods) element.accept(this);
1505 } 1575 }
1506 } 1576 }
OLDNEW
« lib/src/js/nodes.dart ('K') | « lib/src/js/nodes.dart ('k') | lib/src/js/template.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698