Skip to content

Commit 21d29b6

Browse files
committed
simple eval: fix switch-case
1 parent ad30cb8 commit 21d29b6

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

lib/simple_eval.ts

+7-3
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ let g_exc: { g: Isolate, l: StackFrame[], d: number } | null = null
200200
const kTokenNames = Build.NDEBUG ? [] as never
201201
: ("block, blockEnd, semiColon, prefix, action, group, dict, array, groupEnd, comma, question, colon, fn, assign"
202202
+ ", or, and, bitOr, bitXor, bitAnd, compare1, compare2, bitMove, math1, math2, math3"
203-
+ ", unary, rightUnary, callOrAccess, dot, ref, literal").split(", ")
203+
+ ", unary, rightUnary, callOrAccess, dot, literal, ref").split(", ")
204204
const kOpNames = Build.NDEBUG ? [] as never
205205
: "block,stats,stat,comma,pair,fn,assign,ifElse,binary,unary,call,access,composed,literal,ref,fnDesc".split(",")
206206

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

215215
const Op = ((o: O, q: unknown, x: unknown, y: unknown): BaseOp<O>=>{
216-
return (NDEBUG ? { o, q, x, y } : { n: o === O.composed ? q === "{"
216+
return (NDEBUG ? { o, q, x, y } : { n: o === O.composed ? x as OpValues[O.composed]["x"] === "{"
217217
? "dict" : "array" : kOpNames[o], q, x, y, o }) as BaseOp<O>
218218
}) as {
219219
<O extends Exclude<keyof OpValues, O.stat | O.literal>> (
@@ -645,7 +645,11 @@ const parseTree = (tokens_: readonly Token[], inNewFunc: boolean | null | undefi
645645
ctx_.push(cur), topIsDict = false
646646
} else {
647647
type = T.groupEnd, Build.NDEBUG || ((cur as OverriddenToken).w = Token(T.groupEnd, ")"))
648-
"case default".includes(ctx_[ctx_.length - 1].v) && values_.push(Op(O.literal, L.plain, null, null))
648+
const prefix = ctx_[ctx_.length - 1].v
649+
if (prefix === "case" || prefix === "default") {
650+
values_.push(Op(O.literal, L.plain, null, null))
651+
consume()
652+
}
649653
}
650654
continue
651655
case T.fn: /* T.fn: */

tests/unit/simple-js-eval.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@
300300
c: ret |= 2
301301
case '1':
302302
ret |= 4
303-
function b2 () {}
303+
function b2() { }
304304
break
305305
case a + 2 - 3 + 1:
306306
try {

0 commit comments

Comments
 (0)