summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/tests/modules/requested-modules.js
blob: ebbf8ce6c1cc188e6e1b934559e3b87bdd6928f6 (plain)
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
// |jit-test| --enable-import-assertions

// 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].assertions === null) {
            assertEq(actual[i].moduleRequest.assertions, null);
        }
        else {
            var expectedAssertions = expected[i].assertions;
            var actualAssertions = actual[i].moduleRequest.assertions;
            assertEq(actualAssertions.length, expectedAssertions.length);
            for (var j = 0; j < expectedAssertions.length; j++) {
                assertEq(expectedAssertions[j].type, actualAssertions[j].type);
            }
        }
    }
}

testRequestedModules("", []);

testRequestedModules("import a from 'foo'", [
    { specifier: 'foo', assertions: null }
]);

testRequestedModules("import a from 'foo'; import b from 'bar'", [
    { specifier: 'foo', assertions: null },
    { specifier: 'bar', assertions: null }
]);

testRequestedModules("import a from 'foo'; import b from 'bar'; import c from 'foo'", [
    { specifier: 'foo', assertions: null },
    { specifier: 'bar', assertions: null }
]);

testRequestedModules("export {} from 'foo'", [
    { specifier: 'foo', assertions: null }
]);

testRequestedModules("export * from 'bar'",[
    { specifier: 'bar', assertions: null }
]);

testRequestedModules("import a from 'foo'; export {} from 'bar'; export * from 'baz'", [
    { specifier: 'foo', assertions: null },
    { specifier: 'bar', assertions: null },
    { specifier: 'baz', assertions: null }
]);

if (getRealmConfiguration("importAttributes")) {
    testRequestedModules("import a from 'foo' assert {}", [
        { specifier: 'foo', assertions: null },
    ]);

    testRequestedModules("import a from 'foo' assert { type: 'js'}", [
        { specifier: 'foo', assertions: [ { type: 'js' } ] },
    ]);

    testRequestedModules("import a from 'foo' assert { unsupported: 'test'}", [
        { specifier: 'foo', assertions: null },
    ]);

    testRequestedModules("import a from 'foo' assert { unsupported: 'test', type: 'js', foo: 'bar' }", [
        { specifier: 'foo', assertions: [ { type: 'js' } ] },
    ]);

    testRequestedModules("import a from 'foo' assert { type: 'js1'}; export {} from 'bar' assert { type: 'js2'}; export * from 'baz' assert { type: 'js3'}", [
        { specifier: 'foo', assertions: [ { type: 'js1' } ] },
        { specifier: 'bar', assertions: [ { type: 'js2' } ] },
        { specifier: 'baz', assertions: [ { type: 'js3' } ] }
    ]);

    testRequestedModules("export {} from 'foo' assert { type: 'js'}", [
        { specifier: 'foo', assertions:  [ { type: 'js' } ] }
    ]);

    testRequestedModules("export * from 'bar' assert { type: 'json'}",[
        { specifier: 'bar', assertions:  [ { type: 'json' } ] }
    ]);

    testRequestedModules("import a from 'foo'; import b from 'bar' assert { type: 'json' };", [
        { specifier: 'foo', assertions: null },
        { specifier: 'bar', assertions: [ { type: 'json' } ] },
    ]);

    testRequestedModules("import b from 'bar' assert { type: 'json' }; import a from 'foo';", [
        { specifier: 'bar', assertions: [ { type: 'json' } ] },
        { specifier: 'foo', assertions: null },
    ]);
}