summaryrefslogtreecommitdiffhomepage
path: root/tests/custom/04_modules/07_import_default
blob: 7190a22a6cf9defa6851737c4eb7646ebc094dc3 (plain)
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
An `import` statement with a sole label will import the modules default
export and bind it to a local variable named after the label.

-- Testcase --
import defVal from "./files/test1.uc";

print(defVal, "\n");
-- End --

-- File test1.uc --
export default "This is the default export";
-- End --

-- Args --
-R
-- End --

-- Expect stdout --
This is the default export
-- End --


Attemping to import a default export from a module without default
export will raise an error.

-- Testcase --
import defVal from "./files/test2.uc";

print(defVal, "\n");
-- End --

-- File test2.uc --
export const x = "This is a non-default export";
-- End --

-- Args --
-R
-- End --

-- Expect stderr --
Syntax error: Module ./files/test2.uc has no default export
In line 1, byte 20:

 `import defVal from "./files/test2.uc";`
  Near here ---------^


-- End --


In import statements usign the list syntax, the `default` keyword can be
used to refer to default exports.

-- Testcase --
import { default as defVal } from "./files/test3.uc";

print(defVal, "\n");
-- End --

-- File test3.uc --
export default "This is the default export";
-- End --

-- Args --
-R
-- End --

-- Expect stdout --
This is the default export
-- End --


When using the default keyword within the list syntax, the `as` keyword is
mandatory to assign a non-reserved keyword as name.

-- Testcase --
import { default } from "./files/test4.uc";

print(defVal, "\n");
-- End --

-- File test4.uc --
export default "This is the default export";
-- End --

-- Args --
-R
-- End --

-- Expect stderr --
Syntax error: Unexpected token
Expecting 'as'
In line 1, byte 18:

 `import { default } from "./files/test4.uc";`
  Near here -------^


-- End --