Skip to content

Commit

Permalink
Merge pull request #1690 from DanielXMoore/bind-jsx
Browse files Browse the repository at this point in the history
Fix bind property shorthand in JSX
  • Loading branch information
edemaine authored Jan 24, 2025
2 parents 35444f8 + 8f0451c commit 997f5f0
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
13 changes: 12 additions & 1 deletion source/parser.hera
Original file line number Diff line number Diff line change
Expand Up @@ -1868,6 +1868,7 @@ PropertyGlob

PropertyBind
# NOTE: foo@.bar and foo@bar shorthand for foo.bar.bind(foo)
# foo@bar(baz) shorthand for foo.bar.bind(foo, baz)
PropertyAccessModifier?:modifier At OptionalDot:dot ( IdentifierName / PrivateIdentifier ):id Arguments?:args ->
return {
type: "PropertyBind",
Expand All @@ -1876,6 +1877,16 @@ PropertyBind
args: args?.children.slice(1, -1) ?? [], // remove the parens from the arg list, or give an empty list
}

# Variation on PropertyBind that forbids implicit arguments (for JSX)
PropertyBindExplicitArguments
PropertyAccessModifier?:modifier At OptionalDot:dot ( IdentifierName / PrivateIdentifier ):id ExplicitArguments?:args ->
return {
type: "PropertyBind",
name: id.name,
children: [modifier, dot, id], // omit `@` from children
args: args?.children.slice(1, -1) ?? [], // remove the parens from the arg list, or give an empty list
}

SuperProperty
Super MemberBracketContent
Super !PropertyAccessModifier PropertyAccess
Expand Down Expand Up @@ -7529,7 +7540,7 @@ InlineJSXMemberExpressionRest
return [...comments, content]
PropertyAccess
PropertyGlob
PropertyBind
PropertyBindExplicitArguments
NonNullAssertion

# Subset of PrimaryExpression; omissions documented below.
Expand Down
16 changes: 16 additions & 0 deletions test/jsx/attr.civet
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,22 @@ describe "braced JSX attributes", ->
<Component x={a.b.bind(a)} />
"""

testCase """
bind shorthand explicit argument
---
<Component x=a@b(c) />
---
<Component x={a.b.bind(a, c)} />
"""

testCase """
bind shorthand no implicit argument
---
<Component x=a@b c />
---
<Component x={a.b.bind(a)} c />
"""

testCase """
++ and --
---
Expand Down

0 comments on commit 997f5f0

Please sign in to comment.