diff options
author | Jo-Philipp Wich <jo@mein.io> | 2022-11-22 17:54:00 +0100 |
---|---|---|
committer | Jo-Philipp Wich <jo@mein.io> | 2022-11-22 17:54:00 +0100 |
commit | 6c5ee537782970797700c99a79293b9590580817 (patch) | |
tree | fc008a5729efcb2fe0b5b2f168541120afede651 /compiler.c | |
parent | 8faa3059951a38bc9e6065470892d01a92fa785b (diff) |
compiler: ensure that arrow functions with block bodies return no value
Follow ES6 semantics and ensure that arrow functions with a block body
don't implicitly return the value of the last executed statement.
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
Diffstat (limited to 'compiler.c')
-rw-r--r-- | compiler.c | 14 |
1 files changed, 5 insertions, 9 deletions
@@ -1330,19 +1330,15 @@ uc_compiler_compile_arrowfn(uc_compiler_t *compiler, uc_value_t *args, bool rest if (uc_compiler_parse_match(&fncompiler, TK_LBRACE)) { while (!uc_compiler_parse_check(&fncompiler, TK_RBRACE) && !uc_compiler_parse_check(&fncompiler, TK_EOF)) - last_statement_type = uc_compiler_compile_declaration(&fncompiler); + uc_compiler_compile_declaration(&fncompiler); uc_compiler_parse_consume(&fncompiler, TK_RBRACE); - /* overwrite last pop result with return */ - if (last_statement_type == TK_SCOL) - uc_chunk_pop(&fn->chunk); - - /* else load implicit null */ - else + /* emit final return */ + if (last_statement_type != TK_RETURN) { uc_compiler_emit_insn(&fncompiler, 0, I_LNULL); - - uc_compiler_emit_insn(&fncompiler, 0, I_RETURN); + uc_compiler_emit_insn(&fncompiler, 0, I_RETURN); + } } else { uc_compiler_parse_precedence(&fncompiler, P_ASSIGN); |