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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: lib/src/js/printer.dart
diff --git a/lib/src/js/printer.dart b/lib/src/js/printer.dart
index 1903e81f09facf9378313a133d1b73f97caaccfb..4f5f24c647021d8a79e554079bccd6653ef7a14b 100644
--- a/lib/src/js/printer.dart
+++ b/lib/src/js/printer.dart
@@ -1127,6 +1127,76 @@ class Printer implements NodeVisitor {
}
}
+ visitImportDeclaration(ImportDeclaration node) {
+ indent();
+ out('import ');
+ if (node.defaultBinding != null) {
+ visit(node.defaultBinding);
+ if (node.namedImports != null) {
+ out(',');
+ spaceOut();
+ }
+ }
+ nameSpecifierListOut(node.namedImports);
+ fromClauseOut(node.from);
+ outSemicolonLn();
+ }
+
+ visitExportDeclaration(ExportDeclaration node) {
+ indent();
+ out('export ');
+ if (node.isDefault) out('default ');
+ // TODO(jmesserly): we need to avoid indent/newline if this is a statement.
+ visit(node.exported);
+ outSemicolonLn();
+ }
+
+ visitExportClause(ExportClause node) {
+ nameSpecifierListOut(node.exports);
+ fromClauseOut(node.from);
+ }
+
+ nameSpecifierListOut(List<NameSpecifier> names) {
+ if (names == null) return;
+
+ if (names.length == 1 && names[0].name == '*') {
+ visit(names[0]);
+ return;
+ }
+
+ out('{');
+ spaceOut();
+ for (int i = 0; i < names.length; i++) {
+ if (i != 0) {
+ out(',');
+ spaceOut();
+ }
+ visit(names[i]);
+ }
+ spaceOut();
+ out('}');
+ }
+
+ fromClauseOut(LiteralString from) {
+ if (from != null) {
+ out(' from');
+ spaceOut();
+ visit(from);
+ }
+ }
+
+ visitNameSpecifier(NameSpecifier node) {
+ out(node.name);
+ if (node.asName != null) {
+ out(' as ');
+ out(node.asName);
+ }
+ }
+
+ visitModule(Module node) {
+ visitAll(node.body);
+ }
+
visitLiteralExpression(LiteralExpression node) {
String template = node.template;
List<Expression> inputs = node.inputs;
« 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