diff --git a/common/corpus/expressions.txt b/common/corpus/expressions.txt index a9b97b4b..342163e8 100644 --- a/common/corpus/expressions.txt +++ b/common/corpus/expressions.txt @@ -118,3 +118,32 @@ Objects with reserved words as keys (pair key: (property_identifier) value: (true)) (pair key: (property_identifier) value: (true)) (pair key: (property_identifier) value: (true))))) + +==================================== +Assignment to non-null LHS +==================================== + +foo! = bar; +foo! += bar; +(foo)! = bar; +(foo)! += bar; + +--- +(program + (expression_statement + (assignment_expression + (non_null_expression (identifier)) + (identifier))) + (expression_statement + (augmented_assignment_expression + (non_null_expression (identifier)) + (identifier))) + (expression_statement + (assignment_expression + (non_null_expression (parenthesized_expression (identifier))) + (identifier))) + (expression_statement + (augmented_assignment_expression + (non_null_expression + (parenthesized_expression (identifier))) + (identifier)))) diff --git a/common/define-grammar.js b/common/define-grammar.js index 3fcf7271..7653e865 100644 --- a/common/define-grammar.js +++ b/common/define-grammar.js @@ -114,6 +114,10 @@ module.exports = function defineGrammar(dialect) { field('arguments', optional($.arguments)) )), + _augmented_assignment_lhs: ($, previous) => choice(previous, $.non_null_expression), + + _lhs_expression: ($, previous) => choice(previous, $.non_null_expression), + // If the dialect is regular typescript, we exclude JSX expressions and // include type assertions. If the dialect is TSX, we do the opposite. _expression: ($, previous) => {