diff options
author | Jo-Philipp Wich <jo@mein.io> | 2023-11-06 15:59:17 +0100 |
---|---|---|
committer | Jo-Philipp Wich <jo@mein.io> | 2023-11-06 16:33:51 +0100 |
commit | 1468cc406bf9b46ae7942791eaa78f74a185062e (patch) | |
tree | dfdd03718e33e6a5b1a358b15191d0009f1d7ac3 /tests | |
parent | cfb24ea4f12131dcefe4f1ede2f51d3d16b88dec (diff) |
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 <jo@mein.io>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/custom/99_bugs/44_compiler_as_from_identifier | 44 |
1 files changed, 44 insertions, 0 deletions
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 -- |