Skip to content

Commit 6651fae

Browse files
committed
Support optional fields in record patterns
1 parent 9af3e1f commit 6651fae

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

grammar.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -886,6 +886,7 @@ module.exports = grammar({
886886
record_pattern: $ => seq(
887887
'{',
888888
commaSep1t(seq(
889+
optional("?"),
889890
choice(
890891
$.value_identifier,
891892
$.value_identifier_path,

test/corpus/expressions.txt

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -762,6 +762,7 @@ switch person {
762762
}) => 20
763763
| Student({status: Sick}) => 30
764764
| Student({name}) => 40
765+
| Student({?age}) => 50
765766
}
766767

767768
--------------------------------------------------------------------------------
@@ -825,7 +826,16 @@ switch person {
825826
(value_identifier))))
826827
(sequence_expression
827828
(expression_statement
828-
(number)))))))
829+
(number))))
830+
(switch_match
831+
(variant_pattern
832+
(variant_identifier)
833+
(formal_parameters
834+
(record_pattern
835+
(value_identifier))))
836+
(sequence_expression
837+
(expression_statement
838+
(number)))))))
829839

830840
================================================================================
831841
Switch of lists

test/corpus/let_bindings.txt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@ Record destructuring
101101
let {bar, baz} = foo
102102
let {bar, baz: qux} = foo
103103
let {Bar.Bar.bar: bar} = foo
104+
let {?Bar.bar} = foo
105+
let {?bar} = foo
104106

105107
--------------------------------------------------------------------------------
106108

@@ -127,6 +129,18 @@ let {Bar.Bar.bar: bar} = foo
127129
(module_identifier))
128130
(value_identifier))
129131
(value_identifier))
132+
(value_identifier)))
133+
(let_declaration
134+
(let_binding
135+
(record_pattern
136+
(value_identifier_path
137+
(module_identifier)
138+
(value_identifier)))
139+
(value_identifier)))
140+
(let_declaration
141+
(let_binding
142+
(record_pattern
143+
(value_identifier))
130144
(value_identifier))))
131145

132146
================================================================================

0 commit comments

Comments
 (0)