]> git.kaiwu.me - njs.git/commit
Parser: parse the "for" initializer once
authorDmitry Volyntsev <xeioex@nginx.com>
Tue, 1 Sep 2026 04:07:06 +0000 (21:07 -0700)
committerDmitry Volyntsev <xeioexception@gmail.com>
Fri, 4 Sep 2026 20:56:37 +0000 (13:56 -0700)
commit6bf9c059e672480431638759755d03368ba1eb3a
tree0e69d9ecae97097d3682cdf35815be62fbafabd0
parentab709e37d0509c03a8ee71d67b6798f0bbbc5641
Parser: parse the "for" initializer once

Previously, the initializer was parsed twice: speculatively as a
LeftHandSideExpression so that the token after it could be inspected, and
then the rest of the expression was grafted onto that left-hand side by four
continuation states.  A dispatch list and an arrow pre-check existed only to
keep inputs away from the speculative parse.

The fix is to let [~In] end the initializer: the "in" operator is no longer
part of the expression, so the header is a single <Expression> and
njs_parser_for_var_in_of_expression(), which already classified the other
routes, classifies this one too.  Its post-hoc for-in detection goes with it.

A declaration header stopping at "in" now reports an invalid target instead
of an unexpected token:

    for (var a, b in []);

The first token's text was carried through the header only to be quoted in
the removed diagnostic, so the allocation goes with it.
src/njs_parser.c
src/test/njs_unit_test.c