From 10e056d3744384a029f05de5903c489898722fc3 Mon Sep 17 00:00:00 2001 From: Jo-Philipp Wich Date: Sun, 17 Jul 2022 23:21:03 +0200 Subject: compiler: add support for import/export statements This commit introduces syntax level support for ES6 style module import and export statements. Imports are resolved at compile time and the corresponding module code is compiled into the main program. Also add testcases to cover import and export statement semantics. Signed-off-by: Jo-Philipp Wich --- .../04_modules/01_export_variable_declaration | 29 ++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 tests/custom/04_modules/01_export_variable_declaration (limited to 'tests/custom/04_modules/01_export_variable_declaration') diff --git a/tests/custom/04_modules/01_export_variable_declaration b/tests/custom/04_modules/01_export_variable_declaration new file mode 100644 index 0000000..19a1c11 --- /dev/null +++ b/tests/custom/04_modules/01_export_variable_declaration @@ -0,0 +1,29 @@ +Variable declarations can be prepended with `export` to automatically +export each variable using the same name as the variable itself. + +Updates to the variable after the export are reflected properly in +the including scope. + +-- File test-var-decl.uc -- +export let a, b, c; +export let d = 4, e = 5, f = 6; +export const g = 7, h = 8, i = 9; + +a = 1; +b = 2; +c = 3; +-- End -- + +-- Testcase -- +import { a, b, c, d, e, f, g, h, i } from "./files/test-var-decl.uc"; + +print([ a, b, c, d, e, f, g, h, i ], "\n"); +-- End -- + +-- Args -- +-R +-- End -- + +-- Expect stdout -- +[ 1, 2, 3, 4, 5, 6, 7, 8, 9 ] +-- End -- -- cgit v1.2.3