Skip to content

Commit

Permalink
add optional chaining support
Browse files Browse the repository at this point in the history
  • Loading branch information
haikyuu committed Sep 21, 2023
1 parent 1ce01d1 commit 691a334
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions src/builder.imba
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,9 @@ export default class Builder < BaseBuilder

indent do ["for ", left, " in ", walk(node.right),"\n", walk(node.body)]

def ChainExpression(node, ctx)
walk(node.expression)

def ForInStatement(node, ctx)
# debugger
const left = if node.left..type == 'VariableDeclaration'
Expand Down Expand Up @@ -646,13 +649,23 @@ export default class Builder < BaseBuilder
paren space [ walk(node.left), operator, walk(node.right) ]

def MemberExpression(node, ctx)
const optional? = node.optional

let right = if node.computed
[ '[', walk(node.property), ']' ]
if optional?
['..', '[', walk(node.property), ']' ]
else
[ '[', walk(node.property), ']' ]
else if node._prefixed
[ walk(node.property) ]
if optional?
['..', walk(node.property) ]
else
[ walk(node.property) ]
else
[ '.', walk(node.property) ]
if optional?
[ '..', walk(node.property) ]
else
[ '.', walk(node.property) ]

let expr = paren [ walk(node.object), right ]
if ctx.parent.type == 'Property'
Expand Down

0 comments on commit 691a334

Please sign in to comment.