| 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 577 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 588 } | 588 } |
| 589 | 589 |
| 590 visitVariableDeclarationList(VariableDeclarationList list) { | 590 visitVariableDeclarationList(VariableDeclarationList list) { |
| 591 outClosureAnnotation(list); | 591 outClosureAnnotation(list); |
| 592 out(list.keyword); | 592 out(list.keyword); |
| 593 out(" "); | 593 out(" "); |
| 594 visitCommaSeparated(list.declarations, ASSIGNMENT, | 594 visitCommaSeparated(list.declarations, ASSIGNMENT, |
| 595 newInForInit: inForInit, newAtStatementBegin: false); | 595 newInForInit: inForInit, newAtStatementBegin: false); |
| 596 } | 596 } |
| 597 | 597 |
| 598 visitArrayDestructuring(ArrayDestructuring node) { |
| 599 out("["); |
| 600 visitCommaSeparated(node.variables, EXPRESSION, |
| 601 newInForInit: false, newAtStatementBegin: false); |
| 602 out("]"); |
| 603 } |
| 604 visitObjectDestructuring(ObjectDestructuring node) { |
| 605 out("{"); |
| 606 visitCommaSeparated(node.variables, EXPRESSION, |
| 607 newInForInit: false, newAtStatementBegin: false); |
| 608 out("}"); |
| 609 } |
| 610 |
| 611 visitDestructuredVariable(DestructuredVariable node) { |
| 612 var hasName = node.name != null; |
| 613 if (hasName) visit(node.name); |
| 614 if (node.structure != null) { |
| 615 if (hasName) { |
| 616 out(":"); |
| 617 spaceOut(); |
| 618 } |
| 619 visit(node.structure); |
| 620 } |
| 621 if (node.defaultValue != null) { |
| 622 spaceOut(); |
| 623 out("="); |
| 624 spaceOut(); |
| 625 visitNestedExpression(node.defaultValue, EXPRESSION, |
| 626 newInForInit: false, newAtStatementBegin: false); |
| 627 } |
| 628 } |
| 629 |
| 598 visitAssignment(Assignment assignment) { | 630 visitAssignment(Assignment assignment) { |
| 599 visitNestedExpression(assignment.leftHandSide, LEFT_HAND_SIDE, | 631 visitNestedExpression(assignment.leftHandSide, LEFT_HAND_SIDE, |
| 600 newInForInit: inForInit, | 632 newInForInit: inForInit, |
| 601 newAtStatementBegin: atStatementBegin); | 633 newAtStatementBegin: atStatementBegin); |
| 602 if (assignment.value != null) { | 634 if (assignment.value != null) { |
| 603 spaceOut(); | 635 spaceOut(); |
| 604 String op = assignment.op; | 636 String op = assignment.op; |
| 605 if (op != null) out(op); | 637 if (op != null) out(op); |
| 606 out("="); | 638 out("="); |
| 607 spaceOut(); | 639 spaceOut(); |
| (...skipping 857 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1465 return newName; | 1497 return newName; |
| 1466 } | 1498 } |
| 1467 } | 1499 } |
| 1468 | 1500 |
| 1469 /// Like [BaseVisitor], but calls [declare] for [Identifier] declarations, and | 1501 /// Like [BaseVisitor], but calls [declare] for [Identifier] declarations, and |
| 1470 /// [visitIdentifier] otherwise. | 1502 /// [visitIdentifier] otherwise. |
| 1471 abstract class VariableDeclarationVisitor<T> extends BaseVisitor<T> { | 1503 abstract class VariableDeclarationVisitor<T> extends BaseVisitor<T> { |
| 1472 declare(Identifier node); | 1504 declare(Identifier node); |
| 1473 | 1505 |
| 1474 visitFunctionExpression(FunctionExpression node) { | 1506 visitFunctionExpression(FunctionExpression node) { |
| 1475 for (var p in node.params) { | 1507 node.params.forEach(_scanDeclarator); |
| 1476 declare(p is RestParameter ? p.parameter : p); | |
| 1477 } | |
| 1478 node.body.accept(this); | 1508 node.body.accept(this); |
| 1479 } | 1509 } |
| 1480 | 1510 |
| 1511 _scanDeclarator(Declarator d) { |
| 1512 if (d is Identifier) declare(d); |
| 1513 if (d is RestParameter) _scanDeclarator(d.parameter); |
| 1514 else if (d is Destructuring) { |
| 1515 for (var v in d.variables) { |
| 1516 if (v.name != null) declare(v.name); |
| 1517 if (v.structure != null) _scanDeclarator(v.structure); |
| 1518 } |
| 1519 } |
| 1520 } |
| 1521 |
| 1481 visitVariableInitialization(VariableInitialization node) { | 1522 visitVariableInitialization(VariableInitialization node) { |
| 1482 declare(node.declaration); | 1523 _scanDeclarator(node.declaration); |
| 1483 if (node.value != null) node.value.accept(this); | 1524 if (node.value != null) node.value.accept(this); |
| 1484 } | 1525 } |
| 1485 | 1526 |
| 1486 visitCatch(Catch node) { | 1527 visitCatch(Catch node) { |
| 1487 declare(node.declaration); | 1528 declare(node.declaration); |
| 1488 node.body.accept(this); | 1529 node.body.accept(this); |
| 1489 } | 1530 } |
| 1490 | 1531 |
| 1491 visitFunctionDeclaration(FunctionDeclaration node) { | 1532 visitFunctionDeclaration(FunctionDeclaration node) { |
| 1492 declare(node.name); | 1533 declare(node.name); |
| 1493 node.function.accept(this); | 1534 node.function.accept(this); |
| 1494 } | 1535 } |
| 1495 | 1536 |
| 1496 visitNamedFunction(NamedFunction node) { | 1537 visitNamedFunction(NamedFunction node) { |
| 1497 declare(node.name); | 1538 declare(node.name); |
| 1498 node.function.accept(this); | 1539 node.function.accept(this); |
| 1499 } | 1540 } |
| 1500 | 1541 |
| 1501 visitClassExpression(ClassExpression node) { | 1542 visitClassExpression(ClassExpression node) { |
| 1502 declare(node.name); | 1543 declare(node.name); |
| 1503 if (node.heritage != null) node.heritage.accept(this); | 1544 if (node.heritage != null) node.heritage.accept(this); |
| 1504 for (Method element in node.methods) element.accept(this); | 1545 for (Method element in node.methods) element.accept(this); |
| 1505 } | 1546 } |
| 1506 } | 1547 } |
| OLD | NEW |