aboutsummaryrefslogtreecommitdiff
path: root/test/mocha/getter-setter.js
blob: fc78a25f4cd4ab8393f485fd85479614bf572fed (about) (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
var assert = require("assert");
var UglifyJS = require("../node");

describe("Getters and setters", function() {
    it("Should not accept operator symbols as getter/setter name", function() {
        [
            "++",
            "--",
            "+",
            "-",
            "!",
            "~",
            "&",
            "|",
            "^",
            "*",
            "/",
            "%",
            ">>",
            "<<",
            ">>>",
            "<",
            ">",
            "<=",
            ">=",
            "==",
            "===",
            "!=",
            "!==",
            "?",
            "=",
            "+=",
            "-=",
            "/=",
            "*=",
            "%=",
            ">>=",
            "<<=",
            ">>>=",
            "|=",
            "^=",
            "&=",
            "&&",
            "||"
        ].reduce(function(tests, illegalOperator) {
            tests.push({
                code: "var obj = { get " + illegalOperator + "() { return test; }};",
                operator: illegalOperator,
            });
            tests.push({
                code: "var obj = { set " + illegalOperator + "(value) { test = value; }};",
                operator: illegalOperator,
            });
            return tests;
        }, []).forEach(function(test) {
            assert.throws(function() {
                UglifyJS.parse(test.code);
            }, test.operator == "=" ? function(e) {
                return e instanceof UglifyJS.JS_Parse_Error
                    && /^Unexpected token: punc «{», expected: punc «.*?»$/.test(e.message);
            } : function(e) {
                return e instanceof UglifyJS.JS_Parse_Error
                    && e.message === "Unexpected token: operator «" + test.operator + "»";
            }, "Expected but didn't get a syntax error while parsing following line:\n" + test.code);
        });
    });
});