Skip to content

Commit

Permalink
fix: mark conditional consequents as optional.
Browse files Browse the repository at this point in the history
This can happen in such cases:

    if a
      # nothing here
    else
      b
  • Loading branch information
eventualbuddha committed Jun 23, 2016
1 parent b01e08e commit da90bfe
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/Visitor.js
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,9 @@ export default class Visitor extends BasicVisitor {

visitConditional(node: Conditional) {
this.descend(node.condition);
this.descend(node.consequent);
if (node.consequent) {
this.descend(node.consequent);
}
if (node.alternate) {
this.descend(node.alternate);
}
Expand Down
2 changes: 1 addition & 1 deletion src/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ export type CompoundAssignOp = {
export type Conditional = {
type: 'Conditional';
condition: Expression;
consequent: Block;
consequent: ?Block;
alternate: ?Block;
isUnless: boolean;
raw: string;
Expand Down
2 changes: 1 addition & 1 deletion types.json
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@
},
{
"name": "consequent",
"type": "Block"
"type": "?Block"
},
{
"name": "alternate",
Expand Down

0 comments on commit da90bfe

Please sign in to comment.