Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve super property support #326

Merged
merged 1 commit into from
Feb 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions source/parser.hera
Original file line number Diff line number Diff line change
Expand Up @@ -619,16 +619,14 @@ NonNullAssertion
MemberExpression
# NOTE: "new" MemberExpression Arguments seems to be handled fine by other rules already
# NOTE: Eliminated left recursion
PrimaryExpression MemberExpressionRest*:rest ->
if (rest.length) {
( PrimaryExpression / SuperProperty / MetaProperty ) MemberExpressionRest*:rest ->
if (rest.length || Array.isArray($1)) {
return {
type: "MemberExpression",
children: [$1].concat(rest.flat()),
children: [$1, ...rest].flat(),
}
}
return $1
SuperProperty
MetaProperty

MemberExpressionRest
# NOTE: Added shorthand x?[3] -> x?.[3]
Expand Down Expand Up @@ -767,7 +765,7 @@ PropertyAccess
return p

SuperProperty
"super[" PostfixedExpression __ CloseBracket
"super" MemberBracketContent
"super" !( QuestionMark / NonNullAssertion ) PropertyAccess

MetaProperty
Expand Down
28 changes: 28 additions & 0 deletions test/class.civet
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,34 @@ describe "class", ->
}
"""

testCase """
super properties
---
class A
f()
super.id
---
class A {
f() {
return super.id
}
}
"""

testCase """
super splice
---
class A
f()
super[i...j]
---
class A {
f() {
return super.slice(i, j)
}
}
"""

describe "anonymous", ->
testCase """
anonymous with static
Expand Down
25 changes: 25 additions & 0 deletions test/object.civet
Original file line number Diff line number Diff line change
Expand Up @@ -590,3 +590,28 @@ describe "object", ->
---
({[y]: x[y]})
"""

testCase """
super access
---
{super.x}
---
({x: super.x})
"""

testCase """
super member access
---
{super[x]}
---
({[x]: super[x]})
"""

describe "no meta properties", ->
throws """
{new.target}
"""

throws """
{import.meta}
"""