Skip to content

Commit fd17c07

Browse files
committed
Document IfNode fields
- Adds documentation for the fields of the `IfNode`. Also updates the overall description to mention ternary expressions. - Part of #2123
1 parent 4ccf309 commit fd17c07

File tree

1 file changed

+62
-1
lines changed

1 file changed

+62
-1
lines changed

config.yml

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1589,26 +1589,87 @@ nodes:
15891589
fields:
15901590
- name: if_keyword_loc
15911591
type: location?
1592+
comment: |
1593+
The location of the `if` keyword if present.
1594+
1595+
bar if foo
1596+
^^
1597+
1598+
The `if_keyword_loc` field will be `nil` when the `IfNode` represents a ternary expression.
15921599
- name: predicate
15931600
type: node
1601+
comment: |
1602+
The node for the condition the `IfNode` is testing.
1603+
1604+
if foo
1605+
^^^
1606+
bar
1607+
end
1608+
1609+
bar if foo
1610+
^^^
1611+
1612+
foo ? bar : baz
1613+
^^^
15941614
- name: then_keyword_loc
15951615
type: location?
1616+
comment: |
1617+
The location of the `then` keyword (if present) or the `?` in a ternary expression, `nil` otherwise.
1618+
1619+
if foo then bar end
1620+
^^^^
1621+
1622+
a ? b : c
1623+
^
15961624
- name: statements
15971625
type: node?
15981626
kind: StatementsNode
1627+
comment: |
1628+
Represents the body of statements that will be executed when the predicate is evaluated as truthy. Will be `nil` when no body is provided.
1629+
1630+
if foo
1631+
bar
1632+
^^^
1633+
baz
1634+
^^^
1635+
end
15991636
- name: consequent
16001637
type: node?
1638+
comment: |
1639+
Represents an `ElseNode` or an `IfNode` when there is an `else` or an `elsif` in the `if` statement.
1640+
1641+
if foo
1642+
bar
1643+
elsif baz
1644+
^^^^^^^^^
1645+
qux
1646+
^^^
1647+
end
1648+
^^^
1649+
1650+
if foo then bar else baz end
1651+
^^^^^^^^^^^^
16011652
- name: end_keyword_loc
16021653
type: location?
1654+
comment: |
1655+
The location of the `end` keyword if present, `nil` otherwise.
1656+
1657+
if foo
1658+
bar
1659+
end
1660+
^^^
16031661
newline: predicate
16041662
comment: |
1605-
Represents the use of the `if` keyword, either in the block form or the modifier form.
1663+
Represents the use of the `if` keyword, either in the block form or the modifier form, or a ternary expression.
16061664
16071665
bar if foo
16081666
^^^^^^^^^^
16091667
16101668
if foo then bar end
16111669
^^^^^^^^^^^^^^^^^^^
1670+
1671+
foo ? bar : baz
1672+
^^^^^^^^^^^^^^^
16121673
- name: ImaginaryNode
16131674
fields:
16141675
- name: numeric

0 commit comments

Comments
 (0)