• source navigation  • diff markup  • identifier search  • freetext search  • 

Sources/ucode/tests/custom/04_modules/09_import_wildcard

  1 By specifying `*` instead of a label or an import list after an `import`
  2 keyword, all of the modules exports are aggregated into an object whose
  3 keys and values refer to the exported names and their corresponding
  4 values respectively.
  5 
  6 -- Testcase --
  7 import * as mod from "./files/test1.uc";
  8 
  9 print(mod, "\n");
 10 -- End --
 11 
 12 -- File test1.uc --
 13 export const a = 1, b = 2, c = 3;
 14 export default a + b + c;
 15 -- End --
 16 
 17 -- Args --
 18 -R
 19 -- End --
 20 
 21 -- Expect stdout --
 22 { "a": 1, "b": 2, "c": 3, "default": 6 }
 23 -- End --
 24 
 25 
 26 When using the wildcard import syntax, assigning a name using the `as`
 27 expression is mandatory.
 28 
 29 -- Testcase --
 30 import * from "./files/test2.uc";
 31 -- End --
 32 
 33 -- File test2.uc --
 34 export const x = "This is a test";
 35 -- End --
 36 
 37 -- Args --
 38 -R
 39 -- End --
 40 
 41 -- Expect stderr --
 42 Syntax error: Unexpected token
 43 Expecting 'as'
 44 In line 1, byte 10:
 45 
 46  `import * from "./files/test2.uc";`
 47            ^-- Near here
 48 
 49 
 50 -- End --
 51 
 52 
 53 A wildcard expression may follow a default import expression in an `import`
 54 statment.
 55 
 56 -- Testcase --
 57 import defVal, * as mod from "./files/test3.uc";
 58 
 59 print([defVal, mod], "\n");
 60 -- End --
 61 
 62 -- File test3.uc --
 63 export const a = 1, b = 2, c = 3;
 64 export default a + b + c;
 65 -- End --
 66 
 67 -- Args --
 68 -R
 69 -- End --
 70 
 71 -- Expect stdout --
 72 [ 6, { "a": 1, "b": 2, "c": 3, "default": 6 } ]
 73 -- End --

This page was automatically generated by LXR 0.3.1.  •  OpenWrt