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
|
// |jit-test| --enable-import-attributes
// Test requestedModules property
function testRequestedModules(source, expected) {
var module = parseModule(source);
var actual = module.requestedModules;
assertEq(actual.length, expected.length);
for (var i = 0; i < actual.length; i++) {
assertEq(actual[i].moduleRequest.specifier, expected[i].specifier);
if(expected[i].attributes === null) {
assertEq(actual[i].moduleRequest.attributes, null);
}
else {
var expectedAttributes = expected[i].attributes;
var actualAttributes = actual[i].moduleRequest.attributes;
assertEq(actualAttributes.length, expectedAttributes.length);
for (var j = 0; j < expectedAttributes.length; j++) {
assertEq(expectedAttributes[j]['key'], actualAttributes[j]['key']);
assertEq(expectedAttributes[j]['value'], actualAttributes[j]['value']);
}
}
}
}
testRequestedModules("", []);
testRequestedModules("import a from 'foo'", [
{ specifier: 'foo', attributes: null }
]);
testRequestedModules("import a from 'foo'; import b from 'bar'", [
{ specifier: 'foo', attributes: null },
{ specifier: 'bar', attributes: null }
]);
testRequestedModules("import a from 'foo'; import b from 'bar'; import c from 'foo'", [
{ specifier: 'foo', attributes: null },
{ specifier: 'bar', attributes: null }
]);
testRequestedModules("export {} from 'foo'", [
{ specifier: 'foo', attributes: null }
]);
testRequestedModules("export * from 'bar'",[
{ specifier: 'bar', attributes: null }
]);
testRequestedModules("import a from 'foo'; export {} from 'bar'; export * from 'baz'", [
{ specifier: 'foo', attributes: null },
{ specifier: 'bar', attributes: null },
{ specifier: 'baz', attributes: null }
]);
if (getRealmConfiguration("importAttributes")) {
testRequestedModules("import a from 'foo' with {}", [
{ specifier: 'foo', attributes: null },
]);
testRequestedModules("import a from 'foo' with { type: 'js'}", [
{ specifier: 'foo', attributes: [ { key: 'type', value: 'js'} ] },
]);
testRequestedModules("import a from 'foo' with { unsupported: 'test'}", [
{ specifier: 'foo', attributes: [ { key: 'unsupported', value: 'test'} ] },
]);
testRequestedModules("import a from 'foo' with { unsupported: 'test', type: 'js', foo: 'bar' }", [
{ specifier: 'foo', attributes: [ { key: 'unsupported', value: 'test'}, { key: 'type', value: 'js'}, { key: 'foo', value: 'bar'} ] },
]);
testRequestedModules("import a from 'foo' with { type: 'js1'}; export {} from 'bar' with { type: 'js2'}; export * from 'baz' with { type: 'js3'}", [
{ specifier: 'foo', attributes: [ { key: 'type', value: 'js1'} ] },
{ specifier: 'bar', attributes: [ { key: 'type', value: 'js2'} ] },
{ specifier: 'baz', attributes: [ { key: 'type', value: 'js3'} ] }
]);
testRequestedModules("export {} from 'foo' with { type: 'js'}", [
{ specifier: 'foo', attributes: [ { key: 'type', value: 'js'} ] }
]);
testRequestedModules("export * from 'bar' with { type: 'json'}",[
{ specifier: 'bar', attributes: [ { key: 'type', value: 'json'} ] }
]);
testRequestedModules("import a from 'foo'; import b from 'bar' with { type: 'json' };", [
{ specifier: 'foo', attributes: null },
{ specifier: 'bar', attributes: [ { key: 'type', value: 'json'} ] },
]);
testRequestedModules("import b from 'bar' with { type: 'json' }; import a from 'foo';", [
{ specifier: 'bar', attributes: [ { key: 'type', value: 'json'} ] },
{ specifier: 'foo', attributes: null },
]);
}
|