summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/tests/modules/import-entries.js
blob: e5f7066f10e6d50c3c369b6a9373f725cbc002cc (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
// Test importEntries property

function importEntryEq(a, b)
{
    return a['moduleRequest'] === b['moduleRequest'] &&
           a['importName'] === b['importName'] &&
           a['localName'] === b['localName'];
}

function findImportEntry(array, target)
{
    for (let i = 0; i < array.length; i++) {
        if (importEntryEq(array[i], target))
            return i;
    }
    return -1;
}

function testImportEntries(source, expected) {
    var module = parseModule(source);
    var actual = module.importEntries.slice(0);
    assertEq(actual.length, expected.length);
    for (var i = 0; i < expected.length; i++) {
        let index = findImportEntry(actual, expected[i]);
        assertEq(index >= 0, true);
        actual.splice(index, 1);
    }
}

testImportEntries('', []);

testImportEntries('import v from "mod";',
                  [{moduleRequest: 'mod', importName: 'default', localName: 'v'}]);

testImportEntries('import * as ns from "mod";',
                  [{moduleRequest: 'mod', importName: '*', localName: 'ns'}]);

testImportEntries('import {x} from "mod";',
                  [{moduleRequest: 'mod', importName: 'x', localName: 'x'}]);

testImportEntries('import {x as v} from "mod";',
                  [{moduleRequest: 'mod', importName: 'x', localName: 'v'}]);

testImportEntries('import "mod";',
                  []);

testImportEntries('import {x} from "a"; import {y} from "b";',
                  [{moduleRequest: 'a', importName: 'x', localName: 'x'},
                   {moduleRequest: 'b', importName: 'y', localName: 'y'}]);