Skip to content

Commit

Permalink
Merge pull request #716 from DanielXMoore/629
Browse files Browse the repository at this point in the history
Fix #629: Unary op with late assignment
  • Loading branch information
STRd6 authored Sep 9, 2023
2 parents acc9ceb + 3b213d8 commit cf0ac02
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 4 deletions.
19 changes: 17 additions & 2 deletions source/parser.hera
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ UnaryExpression
# NOTE: Merged AwaitExpression with UnaryOp
# https://262.ecma-international.org/#prod-AwaitExpression
# NOTE: Eliminated left recursion
UnaryOp*:pre ( UpdateExpression / NestedNonAssignmentExtendedExpression ):exp UnaryPostfix?:post ->
UnaryOp*:pre UnaryBody:exp UnaryPostfix?:post ->
return processUnaryExpression(pre, exp, post)

# NOTE: This is a little hacky to match CoffeeScript's behavior
Expand All @@ -350,14 +350,29 @@ UnaryExpression
ws = insertTrimmingSpace(ws, "")
return ["(", ...ws, exp, ")()"]

UnaryWithoutParenthesizedAssignment
UnaryOp*:pre UnaryWithoutParenthesizedAssignmentBody:exp UnaryPostfix?:post ->
return processUnaryExpression(pre, exp, post)

UnaryBody
ParenthesizedAssignment
UpdateExpression
ExpressionizedStatementWithTrailingCallExpressions
NestedNonAssignmentExtendedExpression

UnaryWithoutParenthesizedAssignmentBody
UpdateExpression
ExpressionizedStatementWithTrailingCallExpressions
NestedNonAssignmentExtendedExpression

UnaryPostfix
QuestionMark
( __ ( As / Satisfies ) Type )+ -> { ts: true, children: $0 }

# https://262.ecma-international.org/#prod-UpdateExpression
UpdateExpression
# NOTE: Not allowing whitespace betwen prefix and postfix increment operators and operand
UpdateExpressionSymbol UnaryExpression ->
UpdateExpressionSymbol UnaryWithoutParenthesizedAssignment ->
return {
type: "UpdateExpression",
assigned: $2,
Expand Down
4 changes: 2 additions & 2 deletions test/assignment.civet
Original file line number Diff line number Diff line change
Expand Up @@ -525,9 +525,9 @@ describe "assignment", ->
"""

testCase """
not form isn't an assignment
not form is treated as late assignment
---
x not min= y
---
x(!min)= y
x(!(min= y))
"""
16 changes: 16 additions & 0 deletions test/unary-expression.civet
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,19 @@ describe "unary expression", ->
---
(x != null) + (y != null)
"""

testCase """
late assignment
---
!x = 1
---
!(x = 1)
"""

testCase """
expressionized statement
---
!debugger
---
!(()=>{debugger})()
"""

0 comments on commit cf0ac02

Please sign in to comment.