File: es6ClassTest2.js

package info (click to toggle)
node-typescript 3.3.3333-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 324,548 kB
  • sloc: makefile: 6; sh: 3
file content (329 lines) | stat: -rw-r--r-- 8,150 bytes parent folder | download
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
//// [es6ClassTest2.ts]
class BasicMonster {
    constructor(public name: string, public health: number) {

    }

    attack(target) {
      // WScript.Echo("Attacks " + target);
    }

    isAlive = true;
}

var m1 = new BasicMonster("1", 100);
var m2 = new BasicMonster("2", 100);
m1.attack(m2);
m1.health = 0;
console.log((<any>m5.isAlive).toString());

class GetSetMonster {
    constructor(public name: string, private _health: number) {

    }

    attack(target) {
      // WScript.Echo("Attacks " + target);
    }
  // The contextual keyword "get" followed by an identifier and
  // a curly body defines a getter in the same way that "get"
  // defines one in an object literal.
    get isAlive() {
        return this._health > 0;
    }

  // Likewise, "set" can be used to define setters.
    set health(value: number) {
        if (value < 0) {
            throw new Error('Health must be non-negative.')
    }
        this._health = value
  }
}

var m3 = new BasicMonster("1", 100);
var m4 = new BasicMonster("2", 100);
m3.attack(m4);
m3.health = 0;
var x = (<any>m5.isAlive).toString()

class OverloadedMonster {
    constructor(name: string);
    constructor(public name: string, public health?: number) {

    }

    attack();
    attack(a: any);
    attack(target?) {
        //WScript.Echo("Attacks " + target);
    }

    isAlive = true;
}

var m5 = new OverloadedMonster("1");
var m6 = new OverloadedMonster("2");
m5.attack(m6);
m5.health = 0;
var y = (<any>m5.isAlive).toString()

class SplatMonster {
    constructor(...args: string[]) { }
    roar(name: string, ...args: number[]) { }
}


function foo() { return true; }
class PrototypeMonster {
    age: number = 1;
    name: string;
    b = foo();
}

class SuperParent {
    constructor(a: number) {

    }

    b(b: string) {

    }

    c() {

    }
}

class SuperChild extends SuperParent {
    constructor() {
        super(1);
    }

    b() {
        super.b('str');
    }

    c() {
        super.c();
    }
}

class Statics {
    static foo = 1;
    static bar: string;

    static baz() {
        return "";
    }
}

var stat = new Statics();

interface IFoo {
    x: number;
    z: string;
}

class ImplementsInterface implements IFoo {
    public x: number;
    public z: string;
    constructor() {
        this.x = 1;
        this.z = "foo";
    }
}

class Visibility {
    public foo() { }
    private bar() { }
    private x: number;
    public y: number;
    public z: number;
    constructor() {
        this.x = 1;
        this.y = 2;
    }
}

class BaseClassWithConstructor {
    constructor(public x: number, public s: string) { }
}

// used to test codegen
class ChildClassWithoutConstructor extends BaseClassWithConstructor { }


var ccwc = new ChildClassWithoutConstructor(1, "s");



//// [es6ClassTest2.js]
var __extends = (this && this.__extends) || (function () {
    var extendStatics = function (d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
        return extendStatics(d, b);
    };
    return function (d, b) {
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
var BasicMonster = /** @class */ (function () {
    function BasicMonster(name, health) {
        this.name = name;
        this.health = health;
        this.isAlive = true;
    }
    BasicMonster.prototype.attack = function (target) {
        // WScript.Echo("Attacks " + target);
    };
    return BasicMonster;
}());
var m1 = new BasicMonster("1", 100);
var m2 = new BasicMonster("2", 100);
m1.attack(m2);
m1.health = 0;
console.log(m5.isAlive.toString());
var GetSetMonster = /** @class */ (function () {
    function GetSetMonster(name, _health) {
        this.name = name;
        this._health = _health;
    }
    GetSetMonster.prototype.attack = function (target) {
        // WScript.Echo("Attacks " + target);
    };
    Object.defineProperty(GetSetMonster.prototype, "isAlive", {
        // The contextual keyword "get" followed by an identifier and
        // a curly body defines a getter in the same way that "get"
        // defines one in an object literal.
        get: function () {
            return this._health > 0;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(GetSetMonster.prototype, "health", {
        // Likewise, "set" can be used to define setters.
        set: function (value) {
            if (value < 0) {
                throw new Error('Health must be non-negative.');
            }
            this._health = value;
        },
        enumerable: true,
        configurable: true
    });
    return GetSetMonster;
}());
var m3 = new BasicMonster("1", 100);
var m4 = new BasicMonster("2", 100);
m3.attack(m4);
m3.health = 0;
var x = m5.isAlive.toString();
var OverloadedMonster = /** @class */ (function () {
    function OverloadedMonster(name, health) {
        this.name = name;
        this.health = health;
        this.isAlive = true;
    }
    OverloadedMonster.prototype.attack = function (target) {
        //WScript.Echo("Attacks " + target);
    };
    return OverloadedMonster;
}());
var m5 = new OverloadedMonster("1");
var m6 = new OverloadedMonster("2");
m5.attack(m6);
m5.health = 0;
var y = m5.isAlive.toString();
var SplatMonster = /** @class */ (function () {
    function SplatMonster() {
        var args = [];
        for (var _i = 0; _i < arguments.length; _i++) {
            args[_i] = arguments[_i];
        }
    }
    SplatMonster.prototype.roar = function (name) {
        var args = [];
        for (var _i = 1; _i < arguments.length; _i++) {
            args[_i - 1] = arguments[_i];
        }
    };
    return SplatMonster;
}());
function foo() { return true; }
var PrototypeMonster = /** @class */ (function () {
    function PrototypeMonster() {
        this.age = 1;
        this.b = foo();
    }
    return PrototypeMonster;
}());
var SuperParent = /** @class */ (function () {
    function SuperParent(a) {
    }
    SuperParent.prototype.b = function (b) {
    };
    SuperParent.prototype.c = function () {
    };
    return SuperParent;
}());
var SuperChild = /** @class */ (function (_super) {
    __extends(SuperChild, _super);
    function SuperChild() {
        return _super.call(this, 1) || this;
    }
    SuperChild.prototype.b = function () {
        _super.prototype.b.call(this, 'str');
    };
    SuperChild.prototype.c = function () {
        _super.prototype.c.call(this);
    };
    return SuperChild;
}(SuperParent));
var Statics = /** @class */ (function () {
    function Statics() {
    }
    Statics.baz = function () {
        return "";
    };
    Statics.foo = 1;
    return Statics;
}());
var stat = new Statics();
var ImplementsInterface = /** @class */ (function () {
    function ImplementsInterface() {
        this.x = 1;
        this.z = "foo";
    }
    return ImplementsInterface;
}());
var Visibility = /** @class */ (function () {
    function Visibility() {
        this.x = 1;
        this.y = 2;
    }
    Visibility.prototype.foo = function () { };
    Visibility.prototype.bar = function () { };
    return Visibility;
}());
var BaseClassWithConstructor = /** @class */ (function () {
    function BaseClassWithConstructor(x, s) {
        this.x = x;
        this.s = s;
    }
    return BaseClassWithConstructor;
}());
// used to test codegen
var ChildClassWithoutConstructor = /** @class */ (function (_super) {
    __extends(ChildClassWithoutConstructor, _super);
    function ChildClassWithoutConstructor() {
        return _super !== null && _super.apply(this, arguments) || this;
    }
    return ChildClassWithoutConstructor;
}(BaseClassWithConstructor));
var ccwc = new ChildClassWithoutConstructor(1, "s");