]> git.kaiwu.me - njs.git/commit
Generator: stop parking a for-in index in the AST
authorDmitry Volyntsev <xeioex@nginx.com>
Tue, 1 Sep 2026 14:01:44 +0000 (07:01 -0700)
committerDmitry Volyntsev <xeioexception@gmail.com>
Fri, 4 Sep 2026 20:56:37 +0000 (13:56 -0700)
commit192f878ac28dd8af99e48ab25414c5747e6d4339
treeb42994a2470a741aae760c4b9e1106ccbcd7973d
parentaf553ec27b9c7e7b17f395b29fc1f2e8e166b7f8
Generator: stop parking a for-in index in the AST

Previously, the declaration route of a for-in loop stored the resolved
variable index in the AST wrapper njs_parser_node_t, and read it back one
generator state later.  The other two routes keep the same value in
ctx->index_next_value, a field njs_generator_loop_ctx_t already has for it.
The inconsistency was the only difference between
njs_generate_for_in_body_wo_decl() and njs_generate_for_in_body(): the rest
was duplicated verbatim, including a guard that is dead in the copy.

The fix is to use the context on the declaration route as well and delete the
duplicate.  One AST field is no longer written by the generator, and one of
the three shape-selected for-in paths is gone.  The emitted code is unchanged.
src/njs_generator.c
src/test/njs_unit_test.c