summaryrefslogtreecommitdiff
path: root/Libraries/LibJS/Tests/automatic-semicolon-insertion.js
blob: f3c4d3bc00bceb1e9963bdaf40e3d1e55b213220 (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
load("test-common.js");

/**
 * This file tests automatic semicolon insertion rules.
 * If this file produces syntax errors, something is wrong.
 */

function bar() {
    // https://github.com/SerenityOS/serenity/issues/1829
    if (1)
        return 1;
    else
        return 0;

    if (1)
        return 1
    else
        return 0

    if (1)
        return 1
    else
        return 0;
    
}

function foo() {
    label:
    for (var i = 0; i < 4; i++) {
        break // semicolon inserted here
        continue // semicolon inserted here

        break label // semicolon inserted here
        continue label // semicolon inserted here
    }

    var j // semicolon inserted here

    do {
    } while (1 === 2) // semicolon inserted here

    return // semicolon inserted here
    1;
var curly/* semicolon inserted here */}

function baz() {
    let counter = 0;
    let outer;

    outer:
    for (let i = 0; i < 5; ++i) {
        for (let j = 0; j < 5; ++j) {
            continue // semicolon inserted here
            outer // semicolon inserted here
        }
        counter++;
    }

    return counter;
}

try {
    assert(foo() === undefined);
    assert(baz() === 5);

    console.log("PASS");
} catch (e) {
    console.log("FAIL: " + e);
}

// This vardecl must appear exactly at the end of the file (no newline or whitespace after it)
var eof