]> git.kaiwu.me - njs.git/commit
Parser: carry the declaration kind across nested parsing
authorDmitry Volyntsev <xeioex@nginx.com>
Tue, 1 Sep 2026 13:46:16 +0000 (06:46 -0700)
committerDmitry Volyntsev <xeioexception@gmail.com>
Fri, 4 Sep 2026 20:56:37 +0000 (13:56 -0700)
commitaf553ec27b9c7e7b17f395b29fc1f2e8e166b7f8
treec8ebaa9348adbcb33b8ec498c831f56453fe82b8
parent35744a3ec85c2fe91d17e17c50d64ce5dd651f1c
Parser: carry the declaration kind across nested parsing

Previously, the kind of a declaration being parsed lived in a mutable
parser->var_type, written once when "var", "let" or "const" was seen and read
for every declarator in the list.  A declaration nested in a declarator
initializer overwrote it, so the declarators after it were recorded with the
wrong kind and lexical ones lost their per-iteration binding:

    let out = [];
    for (let a = function() { var z; }, b = 0; b < 2; b++) out.push(() => b);
    out[0]() + ',' + out[1]()

gave "2,2" instead of "0,1", because "b" was recorded as a var.

The fix is to carry the kind in njs_parser_stack_entry_t, as the [In]
parameter already is, so a continuation restores the kind in effect when it
was pushed.  njs_parser_stack_entry_t does not grow.
src/njs_parser.c
src/njs_parser.h
src/test/njs_unit_test.c