diff --git a/examples/npm/preact/ant.lockb b/examples/npm/preact/ant.lockb new file mode 100644 index 0000000000000000000000000000000000000000..585b0d319717f656789f5bb97aae57c9f415b7c0 GIT binary patch literal 744 zcmeZq_YPoWU|?WoU|;~z4h#$o_Zb)%6c`y8b}%t8oM2*LU}3-w3W`z_lS?v6N(zdt z^!1BU(=&@piYoQ;3UafG_413-^&txMb)gJhLjye{OFaXYxJKDc{+NvN7-OUP`YxUT|*XY0nte1NWw{^y58kYv4Dz{eAQCq$$4_e3!8| zFgVo4e01gE%{}GyKU{KdxXt8a!IbMe z+iQLYPnrgv_AVD#I;;26iS-`Fx174_&E`+KQQ>^Ra(+y(+)k}Drqexv>>>6Iu~*p| znYDgo$=0p2oRQ_E70AHA-~~1bJ29Jqfq@-K3YR-R#_-HnY_hnd^YZAr>Ll4EHSTjb zJ|C+wOWSv5VvOUhAJ3dK)~`s6ez1}4uCn@m$JsaHkNwYS_-rcGu{Yr~!y&Fk3=9nB wNcMo3p!694VnEaCO$G)AP`H88=aB;$;NXd<)@lN&>(zNx$^=#W|NsC00Ju%RivR!s literal 0 HcmV?d00001 diff --git a/examples/npm/preact/app.jsx b/examples/npm/preact/app.jsx new file mode 100644 index 0000000..c89185e --- /dev/null +++ b/examples/npm/preact/app.jsx @@ -0,0 +1,17 @@ +import { render } from 'https://esm.sh/preact-render-to-string'; + +const App = () => ( +
+

Hello from Preact!

+

Styled text

+ +
    +
  • No Babel
  • +
  • No Webpack
  • +
  • Just Preact
  • +
+
+); + +const html = render(); +console.log(html); diff --git a/examples/npm/preact/index.js b/examples/npm/preact/index.js new file mode 100644 index 0000000..d5c2b08 --- /dev/null +++ b/examples/npm/preact/index.js @@ -0,0 +1,15 @@ +import { build } from 'esbuild'; +import { join } from 'node:path'; + +const { outputFiles } = await build({ + entryPoints: [join(import.meta.dirname, 'app.jsx')], + bundle: true, + write: false, + jsx: 'automatic', + format: 'esm', + jsxImportSource: 'preact', + platform: 'neutral' +}); + +const code = outputFiles[0].text; +await import(`data:text/javascript,${encodeURIComponent(code)}`); diff --git a/examples/npm/preact/package.json b/examples/npm/preact/package.json new file mode 100644 index 0000000..135f0a2 --- /dev/null +++ b/examples/npm/preact/package.json @@ -0,0 +1,13 @@ +{ + "name": "preact", + "version": "1.0.0", + "type": "module", + "main": "index.js", + "scripts": { + "start": "ant index.js" + }, + "dependencies": { + "preact": "^10.29.0", + "esbuild": "^0.27.3" + } +} \ No newline at end of file diff --git a/src/silver/compiler.c b/src/silver/compiler.c index 07ec75f..7fb0434 100644 --- a/src/silver/compiler.c +++ b/src/silver/compiler.c @@ -34,6 +34,7 @@ typedef struct { int scope_depth; const char *label; uint32_t label_len; + bool is_switch; } sv_loop_t; typedef struct { @@ -533,7 +534,8 @@ static void patch_list_resolve(sv_compiler_t *c, sv_patch_list_t *pl) { static void push_loop( sv_compiler_t *c, int loop_start, - const char *label, uint32_t label_len + const char *label, uint32_t label_len, + bool is_switch ) { if (c->loop_count >= c->loop_cap) { c->loop_cap = c->loop_cap ? c->loop_cap * 2 : 4; @@ -549,6 +551,7 @@ static void push_loop( .loop_start = loop_start, .scope_depth = c->scope_depth, .label = label, .label_len = label_len, + .is_switch = is_switch, }; } @@ -2643,7 +2646,7 @@ static void compile_if(sv_compiler_t *c, sv_ast_t *node) { static void compile_while(sv_compiler_t *c, sv_ast_t *node) { int loop_start = c->code_len; - push_loop(c, loop_start, NULL, 0); + push_loop(c, loop_start, NULL, 0, false); compile_expr(c, node->cond); int exit_jump = emit_jump(c, OP_JMP_FALSE); @@ -2661,7 +2664,7 @@ static void compile_while(sv_compiler_t *c, sv_ast_t *node) { static void compile_do_while(sv_compiler_t *c, sv_ast_t *node) { int loop_start = c->code_len; - push_loop(c, loop_start, NULL, 0); + push_loop(c, loop_start, NULL, 0, false); compile_stmt(c, node->body); @@ -2761,7 +2764,7 @@ static void compile_for(sv_compiler_t *c, sv_ast_t *node) { } int loop_start = c->code_len; - push_loop(c, loop_start, NULL, 0); + push_loop(c, loop_start, NULL, 0, false); int exit_jump = -1; if (node->cond) { @@ -2947,7 +2950,7 @@ static void compile_for_each(sv_compiler_t *c, sv_ast_t *node, bool is_for_of) { } int loop_start = c->code_len; - push_loop(c, loop_start, NULL, 0); + push_loop(c, loop_start, NULL, 0, false); if (is_for_of) { emit_op(c, is_for_await ? OP_AWAIT_ITER_NEXT : OP_ITER_NEXT); @@ -3068,23 +3071,20 @@ static void compile_break(sv_compiler_t *c, sv_ast_t *node) { static void compile_continue(sv_compiler_t *c, sv_ast_t *node) { - if (c->loop_count == 0) return; - - int target = c->loop_count - 1; + for (int i = c->loop_count - 1; i >= 0; i--) { if (node->str) { - for (int i = c->loop_count - 1; i >= 0; i--) { - if (c->loops[i].label && - c->loops[i].label_len == node->len && - memcmp(c->loops[i].label, node->str, node->len) == 0) { - target = i; - break; - } + if ( + c->loops[i].label && + c->loops[i].label_len == node->len && + memcmp(c->loops[i].label, node->str, node->len) == 0) { + patch_list_add(&c->loops[i].continues, emit_jump(c, OP_JMP)); + return; } + } else if (!c->loops[i].is_switch) { + patch_list_add(&c->loops[i].continues, emit_jump(c, OP_JMP)); + return; } - - int offset = emit_jump(c, OP_JMP); - patch_list_add(&c->loops[target].continues, offset); -} +}} static void compile_finally_block(sv_compiler_t *c, sv_ast_t *finally_body) { int finally_jump = emit_jump(c, OP_FINALLY); @@ -3184,7 +3184,7 @@ static void compile_switch(sv_compiler_t *c, sv_ast_t *node) { compile_expr(c, node->cond); begin_scope(c); - push_loop(c, c->code_len, NULL, 0); + push_loop(c, c->code_len, NULL, 0, true); for (int i = 0; i < case_count; i++) { sv_ast_t *cas = node->args.items[i]; @@ -3250,7 +3250,7 @@ static void compile_label(sv_compiler_t *c, sv_ast_t *node) { c->pending_label = NULL; c->pending_label_len = 0; } else { - push_loop(c, c->code_len, node->str, node->len); + push_loop(c, c->code_len, node->str, node->len, false); compile_stmt(c, node->body); pop_loop(c); } diff --git a/tests/continue_inner_check.js b/tests/continue_inner_check.js new file mode 100644 index 0000000..8b1edce --- /dev/null +++ b/tests/continue_inner_check.js @@ -0,0 +1,16 @@ +// MVP: "continue" inside switch inside for...in loop + +const obj = { a: 1, b: 2, c: 3 }; +const results = []; + +for (let key in obj) { + switch (key) { + case "b": + continue; // should skip to next for...in iteration + default: + results.push(key); + } +} + +console.log("expected: ['a','c']"); +console.log("got:", JSON.stringify(results));