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

Replace if by case in JS isSimpleExpr #20267

Merged
merged 6 commits into from
Sep 6, 2022
Merged
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
12 changes: 7 additions & 5 deletions compiler/jsgen.nim
Original file line number Diff line number Diff line change
Expand Up @@ -315,17 +315,19 @@ proc useMagic(p: PProc, name: string) =

proc isSimpleExpr(p: PProc; n: PNode): bool =
# calls all the way down --> can stay expression based
if n.kind in nkCallKinds+{nkBracketExpr, nkDotExpr, nkPar, nkTupleConstr} or
(n.kind in {nkObjConstr, nkBracket, nkCurly}):
case n.kind
of nkCallKinds, nkBracketExpr, nkDotExpr, nkPar, nkTupleConstr,
nkObjConstr, nkBracket, nkCurly:
for c in n:
if not p.isSimpleExpr(c): return false
result = true
elif n.kind == nkStmtListExpr:
of nkStmtListExpr:
for i in 0..<n.len-1:
if n[i].kind notin {nkCommentStmt, nkEmpty}: return false
result = isSimpleExpr(p, n.lastSon)
elif n.isAtom:
result = true
else:
if n.isAtom:
result = true

proc getTemp(p: PProc, defineInLocals: bool = true): Rope =
inc(p.unique)
Expand Down