From 3f801169760a1817876648e6d22288ebd8ce97b8 Mon Sep 17 00:00:00 2001 From: Jo-Philipp Wich Date: Tue, 11 May 2021 20:11:01 +0200 Subject: compiler: fix local for-loop initializer variable declarations In a loop statement like `for (let x = 1, y = 2; ...)` the initialization statement was incorrectly interpreted as `let x = 1; y = 2` instead of the correct `let ..., y = 2`, triggering reference error exceptions in strict mode. Solve the issue by continue parsing the rest of the comma expression seqence as declaration list expression when the initializer is compiled in local mode. Signed-off-by: Jo-Philipp Wich --- .../03_bugs/24_compiler_local_for_loop_declaration | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 tests/custom/03_bugs/24_compiler_local_for_loop_declaration (limited to 'tests/custom/03_bugs') diff --git a/tests/custom/03_bugs/24_compiler_local_for_loop_declaration b/tests/custom/03_bugs/24_compiler_local_for_loop_declaration new file mode 100644 index 0000000..aafde55 --- /dev/null +++ b/tests/custom/03_bugs/24_compiler_local_for_loop_declaration @@ -0,0 +1,18 @@ +When compiling a for-loop local variable initializer expression, the compiler +incorrectly treated subsequent declarations as global variable assignments, +triggering reference error exceptions in strict mode. + +-- Expect stdout -- +1 +-- End -- + +-- Testcase -- +{% + "use strict"; + + // The initializer expression below was incorrectly interpreted as + // `let x = 0; y = 1` instead of the correct `let ..., y = 1`. + for (let x = 0, y = 1; x < 1; x++) + print(y, "\n"); +%} +-- End -- -- cgit v1.2.3