Skip to content

Commit ada1521

Browse files
authored
support non_null_assertion in the LHS of augmented assignments (#119)
Co-authored-by: resolritter <[email protected]>
1 parent d7965b8 commit ada1521

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

common/corpus/expressions.txt

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,3 +118,32 @@ Objects with reserved words as keys
118118
(pair key: (property_identifier) value: (true))
119119
(pair key: (property_identifier) value: (true))
120120
(pair key: (property_identifier) value: (true)))))
121+
122+
====================================
123+
Assignment to non-null LHS
124+
====================================
125+
126+
foo! = bar;
127+
foo! += bar;
128+
(foo)! = bar;
129+
(foo)! += bar;
130+
131+
---
132+
(program
133+
(expression_statement
134+
(assignment_expression
135+
(non_null_expression (identifier))
136+
(identifier)))
137+
(expression_statement
138+
(augmented_assignment_expression
139+
(non_null_expression (identifier))
140+
(identifier)))
141+
(expression_statement
142+
(assignment_expression
143+
(non_null_expression (parenthesized_expression (identifier)))
144+
(identifier)))
145+
(expression_statement
146+
(augmented_assignment_expression
147+
(non_null_expression
148+
(parenthesized_expression (identifier)))
149+
(identifier))))

common/define-grammar.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,10 @@ module.exports = function defineGrammar(dialect) {
114114
field('arguments', optional($.arguments))
115115
)),
116116

117+
_augmented_assignment_lhs: ($, previous) => choice(previous, $.non_null_expression),
118+
119+
_lhs_expression: ($, previous) => choice(previous, $.non_null_expression),
120+
117121
// If the dialect is regular typescript, we exclude JSX expressions and
118122
// include type assertions. If the dialect is TSX, we do the opposite.
119123
_expression: ($, previous) => {

0 commit comments

Comments
 (0)