Skip to content

Commit

Permalink
simple eval: fix switch-case
Browse files Browse the repository at this point in the history
  • Loading branch information
gdh1995 committed Sep 22, 2024
1 parent ad30cb8 commit 21d29b6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
10 changes: 7 additions & 3 deletions lib/simple_eval.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ let g_exc: { g: Isolate, l: StackFrame[], d: number } | null = null
const kTokenNames = Build.NDEBUG ? [] as never
: ("block, blockEnd, semiColon, prefix, action, group, dict, array, groupEnd, comma, question, colon, fn, assign"
+ ", or, and, bitOr, bitXor, bitAnd, compare1, compare2, bitMove, math1, math2, math3"
+ ", unary, rightUnary, callOrAccess, dot, ref, literal").split(", ")
+ ", unary, rightUnary, callOrAccess, dot, literal, ref").split(", ")
const kOpNames = Build.NDEBUG ? [] as never
: "block,stats,stat,comma,pair,fn,assign,ifElse,binary,unary,call,access,composed,literal,ref,fnDesc".split(",")

Expand All @@ -213,7 +213,7 @@ const kLabelled = "labelled", kProto = "__proto__", kDots = "..."
//#region helper functions

const Op = ((o: O, q: unknown, x: unknown, y: unknown): BaseOp<O>=>{
return (NDEBUG ? { o, q, x, y } : { n: o === O.composed ? q === "{"
return (NDEBUG ? { o, q, x, y } : { n: o === O.composed ? x as OpValues[O.composed]["x"] === "{"
? "dict" : "array" : kOpNames[o], q, x, y, o }) as BaseOp<O>
}) as {
<O extends Exclude<keyof OpValues, O.stat | O.literal>> (
Expand Down Expand Up @@ -645,7 +645,11 @@ const parseTree = (tokens_: readonly Token[], inNewFunc: boolean | null | undefi
ctx_.push(cur), topIsDict = false
} else {
type = T.groupEnd, Build.NDEBUG || ((cur as OverriddenToken).w = Token(T.groupEnd, ")"))
"case default".includes(ctx_[ctx_.length - 1].v) && values_.push(Op(O.literal, L.plain, null, null))
const prefix = ctx_[ctx_.length - 1].v
if (prefix === "case" || prefix === "default") {
values_.push(Op(O.literal, L.plain, null, null))
consume()
}
}
continue
case T.fn: /* T.fn: */
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/simple-js-eval.html
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@
c: ret |= 2
case '1':
ret |= 4
function b2 () {}
function b2() { }
break
case a + 2 - 3 + 1:
try {
Expand Down

0 comments on commit 21d29b6

Please sign in to comment.