1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
|
An `import` statement followed by a curly brace enclosed list of names
will import the corresponding exports from the module.
-- Testcase --
import { a, b, c } from "./files/test1.uc";
print([ a, b, c ], "\n");
-- End --
-- File test1.uc --
export const a = 1, b = 2, c = 3;
-- End --
-- Args --
-R
-- End --
-- Expect stdout --
[ 1, 2, 3 ]
-- End --
Attemping to import a not exported name will raise an error.
-- Testcase --
import y from "./files/test2.uc";
print(y, "\n");
-- End --
-- File test2.uc --
export const x = "This is a test";
-- End --
-- Args --
-R
-- End --
-- Expect stderr --
Syntax error: Module ./files/test2.uc has no default export
In [stdin], line 1, byte 15:
`import y from "./files/test2.uc";`
Near here ----^
-- End --
Imports may be renamed to assign an alternative local name to the
exported module symbols. Renaming is also required for string export
names which are no valid variable identifiers.
-- Testcase --
import { a as var1, bool as var2, "my function" as var3 } from "./files/test3.uc";
print([ var1, var2, var3 ], "\n");
-- End --
-- File test3.uc --
const a = "A string";
let b = 123;
function c() {
return "A function"
}
export {
a,
b as bool,
c as "my function"
};
-- End --
-- Args --
-R
-- End --
-- Expect stdout --
[ "A string", 123, "function c() { ... }" ]
-- End --
A list expression may follow a default import expression in an `import`
statment.
-- Testcase --
import defVal, { a as x, b as y, c as z } from "./files/test4.uc";
print([defVal, x, y, z], "\n");
-- End --
-- File test4.uc --
export const a = 1, b = 2, c = 3;
export default a + b + c;
-- End --
-- Args --
-R
-- End --
-- Expect stdout --
[ 6, 1, 2, 3 ]
-- End --
|