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
106
107
108
109
110
111
112
113
114
115
116
117
|
// |reftest| skip-if(!xulRuntime.shell)
function moduleRequest(source, assertions) {
return {
type: "ModuleRequest",
source,
assertions,
};
}
function importAssertion(key, value) {
return {
type: "ImportAssertion",
key,
value,
};
}
function importDecl(specifiers, moduleRequest) {
return {
type: "ImportDeclaration",
specifiers,
moduleRequest,
};
}
function importSpec(id, name) {
return {
type: "ImportSpecifier",
id,
name,
};
}
function exportDecl(declaration, specifiers, moduleRequest, isDefault) {
return {
type: "ExportDeclaration",
declaration,
specifiers,
moduleRequest,
isDefault,
};
}
function exportSpec(id, name) {
return {
type: "ExportSpecifier",
id,
name,
};
}
function exportNamespaceSpec(name) {
return {
type: "ExportNamespaceSpecifier",
name,
};
}
function assertModule(src, patt) {
program(patt).assert(Reflect.parse(src, {target: "module"}));
}
assertModule(`
import {"x" as y} from "module";
`, [
importDecl([importSpec(literal("x"), ident("y"))], moduleRequest(literal("module"), [])),
]);
assertModule(`
var x;
export {x as "y"};
`, [
varDecl([{id: ident("x"), init: null}]),
exportDecl(null, [exportSpec(ident("x"), literal("y"))], null, false),
]);
assertModule(`
export {x as "y"} from "module";
`, [
exportDecl(null, [exportSpec(ident("x"), literal("y"))], moduleRequest(literal("module"), []), false),
]);
assertModule(`
export {"x" as y} from "module";
`, [
exportDecl(null, [exportSpec(literal("x"), ident("y"))], moduleRequest(literal("module"), []), false),
]);
assertModule(`
export {"x" as "y"} from "module";
`, [
exportDecl(null, [exportSpec(literal("x"), literal("y"))], moduleRequest(literal("module"), []), false),
]);
assertModule(`
export {"x"} from "module";
`, [
exportDecl(null, [exportSpec(literal("x"), literal("x"))], moduleRequest(literal("module"), []), false),
]);
assertModule(`
export * as "x" from "module";
`, [
exportDecl(null, [exportNamespaceSpec(literal("x"))], moduleRequest(literal("module"), []), false),
]);
if (getRealmConfiguration()['importAssertions']) {
assertModule(`
import {"x" as y} from "module" assert {type: "json"};
`, [
importDecl([importSpec(literal("x"), ident("y"))], moduleRequest(literal("module"), [importAssertion(ident("type"), literal("json"))])),
]);
}
if (typeof reportCompare === "function")
reportCompare(true, true);
|