summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/tests/modules/function-redeclaration.js
blob: b84704641d2f9fabf68433d4831764b6ce21fc62 (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
load(libdir + "asserts.js");

var functionDeclarations = [
    "function f(){}",
    "function* f(){}",
    "async function f(){}",
];

var varDeclarations = [
    "var f",
    "{ var f; }",
    "for (var f in null);",
    "for (var f of null);",
    "for (var f; ;);",
];

var lexicalDeclarations = [
    "let f;",
    "const f = 0;",
    "class f {};",
];

var imports = [
    "import f from '';",
    "import f, {} from '';",
    "import d, {f} from '';",
    "import d, {f as f} from '';",
    "import d, {foo as f} from '';",
    "import f, * as d from '';",
    "import d, * as f from '';",
    "import {f} from '';",
    "import {f as f} from '';",
    "import {foo as f} from '';",
    "import* as f from '';",
];

var exports = [
    "export var f;",
    ...functionDeclarations.map(fn => `export ${fn};`),
    ...lexicalDeclarations.map(ld => `export ${ld};`),
    ...functionDeclarations.map(fn => `export default ${fn};`),
    "export default class f {};",
];

var redeclarations = [
    ...functionDeclarations,
    ...varDeclarations,
    ...lexicalDeclarations,
    ...imports,
    ...exports,
];

var noredeclarations = [
    ...functionDeclarations.map(fn => `{ ${fn} }`),
    ...lexicalDeclarations.map(ld => `{ ${ld} }`),
    ...["let", "const"].map(ld => `for (${ld} f in null);`),
    ...["let", "const"].map(ld => `for (${ld} f of null);`),
    ...["let", "const"].map(ld => `for (${ld} f = 0; ;);`),
    "export {f};",
    "export {f as f};",
    "export {foo as f}; var foo;",
    "export {f} from '';",
    "export {f as f} from '';",
    "export {foo as f} from '';",
];

for (var decl of functionDeclarations) {
    for (var redecl of redeclarations) {
        assertThrowsInstanceOf(() => {
            parseModule(`
                ${decl}
                ${redecl}
            `);
        }, SyntaxError);

        assertThrowsInstanceOf(() => {
            parseModule(`
                ${redecl}
                ${decl}
            `);
        }, SyntaxError);
    }

    for (var redecl of noredeclarations) {
        parseModule(`
            ${decl}
            ${redecl}
        `);
        parseModule(`
            ${redecl}
            ${decl}
        `);
    }
}