2014-07-13 01:04:16 +02:00
|
|
|
//// [arrowFunctionContexts.ts]
|
|
|
|
|
|
|
|
// Arrow function used in with statement
|
|
|
|
with (window) {
|
|
|
|
var p = () => this;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Arrow function as argument to super call
|
|
|
|
class Base {
|
|
|
|
constructor(n: any) { }
|
|
|
|
}
|
|
|
|
|
|
|
|
class Derived extends Base {
|
|
|
|
constructor() {
|
|
|
|
super(() => this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Arrow function as function argument
|
|
|
|
window.setTimeout(() => null, 100);
|
|
|
|
|
|
|
|
// Arrow function as value in array literal
|
|
|
|
|
|
|
|
var obj = (n: number) => '';
|
|
|
|
var obj: { (n: number): string; }; // OK
|
|
|
|
|
|
|
|
var arr = [(n: number) => ''];
|
|
|
|
var arr: { (n: number): string; }[]; // Incorrect error here (bug 829597)
|
|
|
|
|
|
|
|
// Arrow function as enum value
|
|
|
|
enum E {
|
|
|
|
x = () => 4, // Error expected
|
|
|
|
y = (() => this).length // error, can't use this in enum
|
|
|
|
}
|
|
|
|
|
|
|
|
// Arrow function as module variable initializer
|
|
|
|
module M {
|
|
|
|
export var a = (s) => '';
|
|
|
|
var b = (s) => s;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Repeat above for module members that are functions? (necessary to redo all of them?)
|
|
|
|
module M2 {
|
|
|
|
// Arrow function used in with statement
|
|
|
|
with (window) {
|
|
|
|
var p = () => this;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Arrow function as argument to super call
|
|
|
|
class Base {
|
|
|
|
constructor(n: any) { }
|
|
|
|
}
|
|
|
|
|
|
|
|
class Derived extends Base {
|
|
|
|
constructor() {
|
|
|
|
super(() => this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Arrow function as function argument
|
|
|
|
window.setTimeout(() => null, 100);
|
|
|
|
|
|
|
|
// Arrow function as value in array literal
|
|
|
|
|
|
|
|
var obj = (n: number) => '';
|
|
|
|
var obj: { (n: number): string; }; // OK
|
|
|
|
|
|
|
|
var arr = [(n: number) => ''];
|
|
|
|
var arr: { (n: number): string; }[]; // Incorrect error here (bug 829597)
|
|
|
|
|
|
|
|
// Arrow function as enum value
|
|
|
|
enum E {
|
|
|
|
x = () => 4, // Error expected
|
|
|
|
y = (() => this).length
|
|
|
|
}
|
|
|
|
|
|
|
|
// Arrow function as module variable initializer
|
|
|
|
module M {
|
|
|
|
export var a = (s) => '';
|
|
|
|
var b = (s) => s;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// <Identifier>(ParamList) => { ... } is a generic arrow function
|
|
|
|
var generic1 = <T>(n: T) => [n];
|
|
|
|
var generic1: { <T>(n: T): T[] }; // Incorrect error, Bug 829597
|
|
|
|
var generic2 = <T>(n: T) => { return [n]; };
|
|
|
|
var generic2: { <T>(n: T): T[] };
|
|
|
|
|
|
|
|
// <Identifier> ((ParamList) => { ... } ) is a type assertion to an arrow function
|
|
|
|
var asserted1 = <any>((n) => [n]);
|
|
|
|
var asserted1: any;
|
|
|
|
var asserted2 = <any>((n) => { return n; });
|
|
|
|
var asserted2: any;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//// [arrowFunctionContexts.js]
|
|
|
|
var __extends = this.__extends || function (d, b) {
|
|
|
|
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
|
|
|
|
function __() { this.constructor = d; }
|
|
|
|
__.prototype = b.prototype;
|
|
|
|
d.prototype = new __();
|
|
|
|
};
|
2015-01-23 00:58:00 +01:00
|
|
|
// Arrow function used in with statement
|
2014-07-13 01:04:16 +02:00
|
|
|
with (window) {
|
2014-07-22 02:09:14 +02:00
|
|
|
var p = function () { return this; };
|
2014-07-13 01:04:16 +02:00
|
|
|
}
|
2014-08-14 15:42:18 +02:00
|
|
|
// Arrow function as argument to super call
|
2014-07-13 01:04:16 +02:00
|
|
|
var Base = (function () {
|
|
|
|
function Base(n) {
|
|
|
|
}
|
|
|
|
return Base;
|
|
|
|
})();
|
|
|
|
var Derived = (function (_super) {
|
|
|
|
__extends(Derived, _super);
|
|
|
|
function Derived() {
|
|
|
|
var _this = this;
|
2014-08-01 20:16:09 +02:00
|
|
|
_super.call(this, function () { return _this; });
|
2014-07-13 01:04:16 +02:00
|
|
|
}
|
|
|
|
return Derived;
|
|
|
|
})(Base);
|
2014-08-16 00:49:09 +02:00
|
|
|
// Arrow function as function argument
|
2014-07-13 01:04:16 +02:00
|
|
|
window.setTimeout(function () { return null; }, 100);
|
2014-08-12 00:54:12 +02:00
|
|
|
// Arrow function as value in array literal
|
2014-07-13 01:04:16 +02:00
|
|
|
var obj = function (n) { return ''; };
|
2014-08-15 22:18:54 +02:00
|
|
|
var obj; // OK
|
2014-07-13 01:04:16 +02:00
|
|
|
var arr = [function (n) { return ''; }];
|
2014-08-15 22:18:54 +02:00
|
|
|
var arr; // Incorrect error here (bug 829597)
|
2014-08-14 15:48:40 +02:00
|
|
|
// Arrow function as enum value
|
2014-07-13 01:04:16 +02:00
|
|
|
var E;
|
|
|
|
(function (E) {
|
|
|
|
E[E["x"] = function () { return 4; }] = "x";
|
2014-08-15 22:18:54 +02:00
|
|
|
E[E["y"] = (function () { return _this; }).length] = "y"; // error, can't use this in enum
|
2014-07-13 01:04:16 +02:00
|
|
|
})(E || (E = {}));
|
2014-08-14 15:53:37 +02:00
|
|
|
// Arrow function as module variable initializer
|
2014-07-13 01:04:16 +02:00
|
|
|
var M;
|
|
|
|
(function (M) {
|
|
|
|
M.a = function (s) { return ''; };
|
|
|
|
var b = function (s) { return s; };
|
|
|
|
})(M || (M = {}));
|
2014-08-14 15:53:37 +02:00
|
|
|
// Repeat above for module members that are functions? (necessary to redo all of them?)
|
2014-07-13 01:04:16 +02:00
|
|
|
var M2;
|
|
|
|
(function (M2) {
|
2015-01-23 00:58:00 +01:00
|
|
|
// Arrow function used in with statement
|
2014-07-13 01:04:16 +02:00
|
|
|
with (window) {
|
2014-07-22 02:09:14 +02:00
|
|
|
var p = function () { return this; };
|
2014-07-13 01:04:16 +02:00
|
|
|
}
|
2014-08-14 15:42:18 +02:00
|
|
|
// Arrow function as argument to super call
|
2014-07-13 01:04:16 +02:00
|
|
|
var Base = (function () {
|
|
|
|
function Base(n) {
|
|
|
|
}
|
|
|
|
return Base;
|
|
|
|
})();
|
|
|
|
var Derived = (function (_super) {
|
|
|
|
__extends(Derived, _super);
|
|
|
|
function Derived() {
|
|
|
|
var _this = this;
|
2014-08-01 20:16:09 +02:00
|
|
|
_super.call(this, function () { return _this; });
|
2014-07-13 01:04:16 +02:00
|
|
|
}
|
|
|
|
return Derived;
|
|
|
|
})(Base);
|
2014-08-16 00:49:09 +02:00
|
|
|
// Arrow function as function argument
|
2014-07-13 01:04:16 +02:00
|
|
|
window.setTimeout(function () { return null; }, 100);
|
2014-08-12 00:54:12 +02:00
|
|
|
// Arrow function as value in array literal
|
2014-07-13 01:04:16 +02:00
|
|
|
var obj = function (n) { return ''; };
|
2014-08-15 22:18:54 +02:00
|
|
|
var obj; // OK
|
2014-07-13 01:04:16 +02:00
|
|
|
var arr = [function (n) { return ''; }];
|
2014-08-15 22:18:54 +02:00
|
|
|
var arr; // Incorrect error here (bug 829597)
|
2014-08-14 15:48:40 +02:00
|
|
|
// Arrow function as enum value
|
2014-07-13 01:04:16 +02:00
|
|
|
var E;
|
|
|
|
(function (E) {
|
|
|
|
E[E["x"] = function () { return 4; }] = "x";
|
|
|
|
E[E["y"] = (function () { return _this; }).length] = "y";
|
|
|
|
})(E || (E = {}));
|
2014-08-14 15:53:37 +02:00
|
|
|
// Arrow function as module variable initializer
|
2014-07-13 01:04:16 +02:00
|
|
|
var M;
|
|
|
|
(function (M) {
|
|
|
|
M.a = function (s) { return ''; };
|
|
|
|
var b = function (s) { return s; };
|
|
|
|
})(M || (M = {}));
|
|
|
|
})(M2 || (M2 = {}));
|
2014-08-12 00:54:12 +02:00
|
|
|
// <Identifier>(ParamList) => { ... } is a generic arrow function
|
2014-07-13 01:04:16 +02:00
|
|
|
var generic1 = function (n) { return [n]; };
|
2014-08-15 22:18:54 +02:00
|
|
|
var generic1; // Incorrect error, Bug 829597
|
2015-02-07 05:03:24 +01:00
|
|
|
var generic2 = function (n) { return [n]; };
|
2014-07-13 01:04:16 +02:00
|
|
|
var generic2;
|
2014-08-12 00:54:12 +02:00
|
|
|
// <Identifier> ((ParamList) => { ... } ) is a type assertion to an arrow function
|
2014-07-13 01:04:16 +02:00
|
|
|
var asserted1 = (function (n) { return [n]; });
|
|
|
|
var asserted1;
|
2015-02-07 05:03:24 +01:00
|
|
|
var asserted2 = (function (n) { return n; });
|
2014-07-13 01:04:16 +02:00
|
|
|
var asserted2;
|