]> git.kaiwu.me - njs.git/commit
Generator: select a for-in route by the target's own token type
authorDmitry Volyntsev <xeioex@nginx.com>
Tue, 1 Sep 2026 14:42:49 +0000 (07:42 -0700)
committerDmitry Volyntsev <xeioexception@gmail.com>
Fri, 4 Sep 2026 20:56:37 +0000 (13:56 -0700)
commit3b1d9ad314415fecd615bd04f7f466978e60a529
treea848e63ba3526fcf363bfb3b98891ece988a9c07
parent6895e9fc51a9e42f890ae1527b3be845d8fb2b87
Generator: select a for-in route by the target's own token type

Previously, njs_generate_for_in_statement() worked out what a for-in header
declared from the shape of the tree: a declaration was recognised as a
STATEMENT wrapper whose right child held the kind, and the kind and the name
were reached through that wrapper.  The wrapper was navigated again in the
object and body states, and njs_generate_for_let_update() walked it to find
lexical bindings.  Nothing named the contract, and the property route used
the same "foreach->left->right" to mean the property key.

The fix is to let the parser put the declaration node under the "in" node
directly, so the target's token type says what it is: VAR, LET or CONST for a
declaration, PROPERTY or PROPERTY_REF for a member target, and NAME for a
plain one.  An unrecognised target is now an internal error instead of
falling into the plain-name route.  njs_generate_let_update() takes the
single declaration a for-in header has, and njs_generate_for_let_update()
keeps the list walk the classic "for" needs.

The instruction stream is unchanged.  The code map for PROPERTY_NEXT on the
declaration route now carries the line of the declaration instead of the zero
the removed wrapper held; backtraces are unaffected.
src/njs_generator.c
src/njs_parser.c
src/test/njs_unit_test.c