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

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

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: 'mod', importName: 'x', localName: null}]);

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

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

testIndirectExportEntries(
    'import {v as x} from "mod"; export {x as y};',
    [{exportName: 'y', moduleRequest: '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: 'mod', importName: '*', localName: null}]);