Debian Codegraph @

js/src/jit-test/tests/modules/requested-modules.js

raw
1 // |jit-test| --enable-import-attributes
2
3 // Test requestedModules property
4
5 function testRequestedModules(source, expected) {
6 var module = parseModule(source);
7 var actual = module.requestedModules;
8 assertEq(actual.length, expected.length);
9 for (var i = 0; i < actual.length; i++) {
10 assertEq(actual[i].moduleRequest.specifier, expected[i].specifier);
11 assertEq(actual[i].moduleRequest.moduleType, expected[i].moduleType);
12 if (actual[i].moduleRequest.firstUnsupportedAttributeKey != expected[i].firstUnsupportedAttributeKey) {
13 assertEq(true, false);
14 }
15 }
16 }
17
18 testRequestedModules("", []);
19
20 testRequestedModules("import a from 'foo'", [
21 { specifier: 'foo', moduleType: 'js' }
22 ]);
23
24 testRequestedModules("import a from 'foo'; import b from 'bar'", [
25 { specifier: 'foo', moduleType: 'js' },
26 { specifier: 'bar', moduleType: 'js' }
27 ]);
28
29 testRequestedModules("import a from 'foo'; import b from 'foo'", [
30 { specifier: 'foo', moduleType: 'js' }
31 ]);
32
33 testRequestedModules("import a from 'foo'; import b from 'bar'; import c from 'foo'", [
34 { specifier: 'foo', moduleType: 'js' },
35 { specifier: 'bar', moduleType: 'js' }
36 ]);
37
38 testRequestedModules("export {} from 'foo'", [
39 { specifier: 'foo', moduleType: 'js' }
40 ]);
41
42 testRequestedModules("export * from 'bar'",[
43 { specifier: 'bar', moduleType: 'js' }
44 ]);
45
46 testRequestedModules("import a from 'foo'; export {} from 'bar'; export * from 'baz'", [
47 { specifier: 'foo', moduleType: 'js' },
48 { specifier: 'bar', moduleType: 'js' },
49 { specifier: 'baz', moduleType: 'js' }
50 ]);
51
52 if (getRealmConfiguration("importAttributes")) {
53 testRequestedModules("import a from 'foo' with {}", [
54 { specifier: 'foo', moduleType: 'js' },
55 ]);
56
57 testRequestedModules("import a from 'foo' with { type: 'json'}", [
58 { specifier: 'foo', moduleType: 'json' },
59 ]);
60
61 testRequestedModules("import a from 'foo' with { unsupported: 'test'}", [
62 { specifier: 'foo', moduleType: 'js', firstUnsupportedAttributeKey: 'unsupported'},
63 ]);
64
65 testRequestedModules("import a from 'foo' with { unsupported: 'test', type: 'js', foo: 'bar' }", [
66 { specifier: 'foo', moduleType: 'unknown', firstUnsupportedAttributeKey: 'unsupported' },
67 ]);
68
69 testRequestedModules("import a from 'foo' with { type: 'js1'}; export {} from 'bar' with { type: 'js2'}; export * from 'baz' with { type: 'js3'}", [
70 { specifier: 'foo', moduleType: 'unknown' },
71 { specifier: 'bar', moduleType: 'unknown' },
72 { specifier: 'baz', moduleType: 'unknown' }
73 ]);
74
75 testRequestedModules("export {} from 'foo' with { type: 'js'}", [
76 { specifier: 'foo', moduleType: 'unknown' }
77 ]);
78
79 testRequestedModules("export * from 'bar' with { type: 'json'}",[
80 { specifier: 'bar', moduleType: 'json' }
81 ]);
82
83 testRequestedModules("import a from 'foo'; import b from 'bar' with { type: 'json' };", [
84 { specifier: 'foo', moduleType: 'js' },
85 { specifier: 'bar', moduleType: 'json' },
86 ]);
87
88 testRequestedModules("import a from 'foo'; import b from 'foo' with { type: 'json' };", [
89 { specifier: 'foo', moduleType: 'js' },
90 { specifier: 'foo', moduleType: 'json' },
91 ]);
92
93 testRequestedModules("import a from 'foo'; import b from 'foo' with { type: 'js1' };", [
94 { specifier: 'foo', moduleType: 'js' },
95 { specifier: 'foo', moduleType: 'unknown' },
96 ]);
97
98 testRequestedModules("import a from 'foo'; import b from 'foo' with { type: 'json' }; import c from 'foo' with { type: 'json' };", [
99 { specifier: 'foo', moduleType: 'js' },
100 { specifier: 'foo', moduleType: 'json' }
101 ]);
102
103 testRequestedModules("import a from 'foo'; import b from 'foo' with { type: 'json' }; import c from 'foo' with { type: 'json', foo: 'bar'};", [
104 { specifier: 'foo', moduleType: 'js' },
105 { specifier: 'foo', moduleType: 'json' },
106 { specifier: 'foo', moduleType: 'json', firstUnsupportedAttributeKey: 'foo' }
107 ]);
108
109 testRequestedModules("import a from 'foo' with { type: 'json' }; import b from 'foo' with { type: 'json' };", [
110 { specifier: 'foo', moduleType: 'json' },
111 ]);
112
113 testRequestedModules("import b from 'bar' with { type: 'json' }; import a from 'foo';", [
114 { specifier: 'bar', moduleType: 'json' },
115 { specifier: 'foo', moduleType: 'js' },
116 ]);
117
118 testRequestedModules("export {} from 'foo' with { type: 'someValueThatWillNeverBeSupported'}", [
119 { specifier: 'foo', moduleType: 'unknown' }
120 ]);
121 }