summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/tests/modules/export-entries.js
blob: bb0c50a69ee47041e9470c187285ad0b7c325624 (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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
// Test localExportEntries property

function testObjectContents(actual, expected) {
    for (var property in expected) {
        if(actual[property] instanceof Object) {
            testObjectContents(actual[property], expected[property]);
        }
        else {
            assertEq(actual[property], expected[property]);
        }
    }
}

function testArrayContents(actual, expected) {
    assertEq(actual.length, expected.length);
    for (var i = 0; i < actual.length; i++) {
        testObjectContents(actual[i], expected[i]);
    }
}

function testLocalExportEntries(source, expected) {
    var module = parseModule(source);
    testArrayContents(module.localExportEntries, expected);
}

testLocalExportEntries(
    'export var v;',
    [{exportName: 'v', moduleRequest: null, importName: null, localName: 'v'}]);

testLocalExportEntries(
    'export var v = 0;',
    [{exportName: 'v', moduleRequest: null, importName: null, localName: 'v'}]);

testLocalExportEntries(
    'export let x = 1;',
    [{exportName: 'x', moduleRequest: null, importName: null, localName: 'x'}]);

testLocalExportEntries(
    'export const x = 1;',
    [{exportName: 'x', moduleRequest: null, importName: null, localName: 'x'}]);

testLocalExportEntries(
    'export class foo { constructor() {} };',
    [{exportName: 'foo', moduleRequest: null, importName: null, localName: 'foo'}]);

testLocalExportEntries(
    'export default function f() {};',
    [{exportName: 'default', moduleRequest: null, importName: null, localName: 'f'}]);

testLocalExportEntries(
    'export default function() {};',
    [{exportName: 'default', moduleRequest: null, importName: null, localName: 'default'}]);

testLocalExportEntries(
    'export default 42;',
    [{exportName: 'default', moduleRequest: null, importName: null, localName: 'default'}]);

testLocalExportEntries(
    'let x = 1; export {x};',
    [{exportName: 'x', moduleRequest: null, importName: null, localName: 'x'}]);

testLocalExportEntries(
    'let v = 1; export {v as x};',
    [{exportName: 'x', moduleRequest: null, importName: null, localName: 'v'}]);

testLocalExportEntries(
    'export {x} from "mod";',
    []);

testLocalExportEntries(
    'export {v as x} from "mod";',
    []);

testLocalExportEntries(
    'export * from "mod";',
    []);

// Test indirectExportEntries property

function testIndirectExportEntries(source, expected) {
    var module = parseModule(source);
    testArrayContents(module.indirectExportEntries, expected);
}

testIndirectExportEntries(
    'export default function f() {};',
    []);

testIndirectExportEntries(
    'let x = 1; export {x};',
    []);

testIndirectExportEntries(
    'export {x} from "mod";',
    [{exportName: 'x', moduleRequest: {specifier:'mod'}, importName: 'x', localName: null}]);

testIndirectExportEntries(
    'export {v as x} from "mod";',
    [{exportName: 'x', moduleRequest: {specifier:'mod'}, importName: 'v', localName: null}]);

testIndirectExportEntries(
    'export * from "mod";',
    []);

testIndirectExportEntries(
    'import {v as x} from "mod"; export {x as y};',
    [{exportName: 'y', moduleRequest: {specifier:'mod'}, importName: 'v', localName: null}]);

// Test starExportEntries property

function testStarExportEntries(source, expected) {
    var module = parseModule(source);
    testArrayContents(module.starExportEntries, expected);
}

testStarExportEntries(
    'export default function f() {};',
    []);

testStarExportEntries(
    'let x = 1; export {x};',
    []);

testStarExportEntries(
    'export {x} from "mod";',
    []);

testStarExportEntries(
    'export * from "mod";',
    [{exportName: null, moduleRequest: {specifier:'mod'}, importName: null, localName: null}]);