Skip to content

Commit b62ab95

Browse files
dgollahonmatzbot
authored andcommitted
[ruby/prism] Document IfNode fields
- Adds documentation for the fields of the `IfNode`. Also updates the overall description to mention ternary expressions. - Part of #2123 ruby/prism@fd17c0733d
1 parent b3350e3 commit b62ab95

File tree

1 file changed

+62
-1
lines changed

1 file changed

+62
-1
lines changed

prism/config.yml

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1976,26 +1976,87 @@ nodes:
19761976
fields:
19771977
- name: if_keyword_loc
19781978
type: location?
1979+
comment: |
1980+
The location of the `if` keyword if present.
1981+
1982+
bar if foo
1983+
^^
1984+
1985+
The `if_keyword_loc` field will be `nil` when the `IfNode` represents a ternary expression.
19791986
- name: predicate
19801987
type: node
1988+
comment: |
1989+
The node for the condition the `IfNode` is testing.
1990+
1991+
if foo
1992+
^^^
1993+
bar
1994+
end
1995+
1996+
bar if foo
1997+
^^^
1998+
1999+
foo ? bar : baz
2000+
^^^
19812001
- name: then_keyword_loc
19822002
type: location?
2003+
comment: |
2004+
The location of the `then` keyword (if present) or the `?` in a ternary expression, `nil` otherwise.
2005+
2006+
if foo then bar end
2007+
^^^^
2008+
2009+
a ? b : c
2010+
^
19832011
- name: statements
19842012
type: node?
19852013
kind: StatementsNode
2014+
comment: |
2015+
Represents the body of statements that will be executed when the predicate is evaluated as truthy. Will be `nil` when no body is provided.
2016+
2017+
if foo
2018+
bar
2019+
^^^
2020+
baz
2021+
^^^
2022+
end
19862023
- name: consequent
19872024
type: node?
2025+
comment: |
2026+
Represents an `ElseNode` or an `IfNode` when there is an `else` or an `elsif` in the `if` statement.
2027+
2028+
if foo
2029+
bar
2030+
elsif baz
2031+
^^^^^^^^^
2032+
qux
2033+
^^^
2034+
end
2035+
^^^
2036+
2037+
if foo then bar else baz end
2038+
^^^^^^^^^^^^
19882039
- name: end_keyword_loc
19892040
type: location?
2041+
comment: |
2042+
The location of the `end` keyword if present, `nil` otherwise.
2043+
2044+
if foo
2045+
bar
2046+
end
2047+
^^^
19902048
newline: predicate
19912049
comment: |
1992-
Represents the use of the `if` keyword, either in the block form or the modifier form.
2050+
Represents the use of the `if` keyword, either in the block form or the modifier form, or a ternary expression.
19932051
19942052
bar if foo
19952053
^^^^^^^^^^
19962054
19972055
if foo then bar end
19982056
^^^^^^^^^^^^^^^^^^^
2057+
2058+
foo ? bar : baz
2059+
^^^^^^^^^^^^^^^
19992060
- name: ImaginaryNode
20002061
fields:
20012062
- name: numeric

0 commit comments

Comments
 (0)