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