From 1468cc406bf9b46ae7942791eaa78f74a185062e Mon Sep 17 00:00:00 2001 From: Jo-Philipp Wich Date: Mon, 6 Nov 2023 15:59:17 +0100 Subject: syntax: don't treat `as` and `from` as reserved keywords ECMAScript allows using `as` and `from` as identifiers so follow suit and don't treat them specially while parsing. Extend the compiler logic instead to check for TK_LABEL tokens with the expected value to properly parse import and export statements. Signed-off-by: Jo-Philipp Wich --- .../custom/99_bugs/44_compiler_as_from_identifier | 44 ++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 tests/custom/99_bugs/44_compiler_as_from_identifier (limited to 'tests') diff --git a/tests/custom/99_bugs/44_compiler_as_from_identifier b/tests/custom/99_bugs/44_compiler_as_from_identifier new file mode 100644 index 0000000..6897cb0 --- /dev/null +++ b/tests/custom/99_bugs/44_compiler_as_from_identifier @@ -0,0 +1,44 @@ +Ensure that `as` and `from` are valid identifiers while their special +meaning in import statements is retained. + +-- Testcase -- +import { foo as bar } from 'mod'; +import * as mod from 'mod'; + +function fn(as, from) { + return as + from; +} + +as = 1; +from = true; + +printf("%.J\n", [ + bar, + mod, + fn(1, 2), + as, + from +]); +-- End -- + +-- File mod.uc -- +export let foo = false; +export default 'test'; +-- End -- + +-- Args -- +-R -L files/ +-- End -- + +-- Expect stdout -- +[ + false, + { + "foo": false, + "default": "test" + }, + 3, + 1, + true +] +-- End -- -- cgit v1.2.3