Debian Codegraph @

js/src/tests/non262/reflect-parse/module-export-name.js

raw
1 // |reftest| skip-if(!xulRuntime.shell) shell-option(--enable-import-attributes)
2
3 function moduleRequest(source, attributes) {
4 return {
5 type: "ModuleRequest",
6 source,
7 attributes,
8 };
9 }
10
11 function importAttribute(key, value) {
12 return {
13 type: "ImportAttribute",
14 key,
15 value,
16 };
17 }
18
19 function importDecl(specifiers, moduleRequest) {
20 return {
21 type: "ImportDeclaration",
22 specifiers,
23 moduleRequest,
24 };
25 }
26
27 function importSpec(id, name) {
28 return {
29 type: "ImportSpecifier",
30 id,
31 name,
32 };
33 }
34
35 function exportDecl(declaration, specifiers, moduleRequest, isDefault) {
36 return {
37 type: "ExportDeclaration",
38 declaration,
39 specifiers,
40 moduleRequest,
41 isDefault,
42 };
43 }
44
45 function exportSpec(id, name) {
46 return {
47 type: "ExportSpecifier",
48 id,
49 name,
50 };
51 }
52
53 function exportNamespaceSpec(name) {
54 return {
55 type: "ExportNamespaceSpecifier",
56 name,
57 };
58 }
59
60 function assertModule(src, patt) {
61 program(patt).assert(Reflect.parse(src, {target: "module"}));
62 }
63
64 assertModule(`
65 import {"x" as y} from "module";
66 `, [
67 importDecl([importSpec(literal("x"), ident("y"))], moduleRequest(literal("module"), [])),
68 ]);
69
70 assertModule(`
71 var x;
72 export {x as "y"};
73 `, [
74 varDecl([{id: ident("x"), init: null}]),
75 exportDecl(null, [exportSpec(ident("x"), literal("y"))], null, false),
76 ]);
77
78 assertModule(`
79 export {x as "y"} from "module";
80 `, [
81 exportDecl(null, [exportSpec(ident("x"), literal("y"))], moduleRequest(literal("module"), []), false),
82 ]);
83
84 assertModule(`
85 export {"x" as y} from "module";
86 `, [
87 exportDecl(null, [exportSpec(literal("x"), ident("y"))], moduleRequest(literal("module"), []), false),
88 ]);
89
90 assertModule(`
91 export {"x" as "y"} from "module";
92 `, [
93 exportDecl(null, [exportSpec(literal("x"), literal("y"))], moduleRequest(literal("module"), []), false),
94 ]);
95
96 assertModule(`
97 export {"x"} from "module";
98 `, [
99 exportDecl(null, [exportSpec(literal("x"), literal("x"))], moduleRequest(literal("module"), []), false),
100 ]);
101
102 assertModule(`
103 export * as "x" from "module";
104 `, [
105 exportDecl(null, [exportNamespaceSpec(literal("x"))], moduleRequest(literal("module"), []), false),
106 ]);
107 if (getRealmConfiguration("importAttributes")) {
108 assertModule(`
109 import {"x" as y} from "module" with {type: "json"};
110 `, [
111 importDecl([importSpec(literal("x"), ident("y"))], moduleRequest(literal("module"), [importAttribute(ident("type"), literal("json"))])),
112 ]);
113 }
114
115 if (typeof reportCompare === "function")
116 reportCompare(true, true);