Discussion:
[njs] Fixed assignment expression from compound assignment.
Dmitry Volyntsev
2018-11-28 13:44:41 UTC
Permalink
details: https://hg.nginx.org/njs/rev/da67f08d365e
branches:
changeset: 675:da67f08d365e
user: Dmitry Volyntsev <***@nginx.com>
date: Wed Nov 28 15:47:05 2018 +0300
description:
Fixed assignment expression from compound assignment.

diffstat:

njs/njs_parser_expression.c | 2 +-
njs/test/njs_unit_test.c | 9 +++++++++
2 files changed, 10 insertions(+), 1 deletions(-)

diffs (31 lines):

diff -r 4e62b7a295e0 -r da67f08d365e njs/njs_parser_expression.c
--- a/njs/njs_parser_expression.c Tue Nov 27 18:58:30 2018 +0300
+++ b/njs/njs_parser_expression.c Wed Nov 28 15:47:05 2018 +0300
@@ -237,7 +237,7 @@ njs_parser_var_expression(njs_vm_t *vm,
njs_parser_node_t *node;
njs_vmcode_operation_t operation;

- token = njs_parser_conditional_expression(vm, parser, token);
+ token = njs_parser_assignment_expression(vm, parser, token);
if (nxt_slow_path(token <= NJS_TOKEN_ILLEGAL)) {
return token;
}
diff -r 4e62b7a295e0 -r da67f08d365e njs/test/njs_unit_test.c
--- a/njs/test/njs_unit_test.c Tue Nov 27 18:58:30 2018 +0300
+++ b/njs/test/njs_unit_test.c Wed Nov 28 15:47:05 2018 +0300
@@ -597,6 +597,15 @@ static njs_unit_test_t njs_test[] =
{ nxt_string("var a, b = (a = [2]) * (3 * 4); a +' '+ b"),
nxt_string("2 24") },

+ { nxt_string("var a = 1; var b = a += 1; b"),
+ nxt_string("2") },
+
+ { nxt_string("var a = 1; var b = a -= 1; b"),
+ nxt_string("0") },
+
+ { nxt_string("var a = 1; var b = a <<= 1; b"),
+ nxt_string("2") },
+
/* 3 address operation and side effect. */

{ nxt_string("var a = 1; function f(x) { a = x; return 2 }; a+f(5)+' '+a"),
Loading...