2014-08-15 23:33:16 +02:00
|
|
|
=== tests/cases/conformance/expressions/functions/arrowFunctionExpressions.ts ===
|
|
|
|
// ArrowFormalParameters => AssignmentExpression is equivalent to ArrowFormalParameters => { return AssignmentExpression; }
|
|
|
|
var a = (p: string) => p.length;
|
|
|
|
>a : (p: string) => number
|
|
|
|
>(p: string) => p.length : (p: string) => number
|
|
|
|
>p : string
|
|
|
|
>p.length : number
|
|
|
|
>p : string
|
|
|
|
>length : number
|
|
|
|
|
|
|
|
var a = (p: string) => { return p.length; }
|
|
|
|
>a : (p: string) => number
|
|
|
|
>(p: string) => { return p.length; } : (p: string) => number
|
|
|
|
>p : string
|
|
|
|
>p.length : number
|
|
|
|
>p : string
|
|
|
|
>length : number
|
|
|
|
|
|
|
|
// Identifier => Block is equivalent to(Identifier) => Block
|
|
|
|
var b = j => { return 0; }
|
|
|
|
>b : (j: any) => number
|
|
|
|
>j => { return 0; } : (j: any) => number
|
|
|
|
>j : any
|
|
|
|
|
|
|
|
var b = (j) => { return 0; }
|
|
|
|
>b : (j: any) => number
|
|
|
|
>(j) => { return 0; } : (j: any) => number
|
|
|
|
>j : any
|
|
|
|
|
|
|
|
// Identifier => AssignmentExpression is equivalent to(Identifier) => AssignmentExpression
|
|
|
|
var c: number;
|
|
|
|
>c : number
|
|
|
|
|
|
|
|
var d = n => c = n;
|
|
|
|
>d : (n: any) => any
|
|
|
|
>n => c = n : (n: any) => any
|
|
|
|
>n : any
|
|
|
|
>c = n : any
|
|
|
|
>c : number
|
|
|
|
>n : any
|
|
|
|
|
|
|
|
var d = (n) => c = n;
|
|
|
|
>d : (n: any) => any
|
|
|
|
>(n) => c = n : (n: any) => any
|
|
|
|
>n : any
|
|
|
|
>c = n : any
|
|
|
|
>c : number
|
|
|
|
>n : any
|
|
|
|
|
|
|
|
var d: (n: any) => any;
|
|
|
|
>d : (n: any) => any
|
|
|
|
>n : any
|
|
|
|
|
|
|
|
|
|
|
|
// Arrow function used in class member initializer
|
|
|
|
// Arrow function used in class member function
|
|
|
|
class MyClass {
|
|
|
|
>MyClass : MyClass
|
|
|
|
|
|
|
|
m = (n) => n + 1;
|
|
|
|
>m : (n: any) => any
|
|
|
|
>(n) => n + 1 : (n: any) => any
|
|
|
|
>n : any
|
|
|
|
>n + 1 : any
|
|
|
|
>n : any
|
|
|
|
|
|
|
|
p = (n) => n && this;
|
|
|
|
>p : (n: any) => MyClass
|
|
|
|
>(n) => n && this : (n: any) => MyClass
|
|
|
|
>n : any
|
|
|
|
>n && this : MyClass
|
|
|
|
>n : any
|
|
|
|
>this : MyClass
|
|
|
|
|
|
|
|
fn() {
|
|
|
|
>fn : () => void
|
|
|
|
|
|
|
|
var m = (n) => n + 1;
|
|
|
|
>m : (n: any) => any
|
|
|
|
>(n) => n + 1 : (n: any) => any
|
|
|
|
>n : any
|
|
|
|
>n + 1 : any
|
|
|
|
>n : any
|
|
|
|
|
|
|
|
var p = (n) => n && this;
|
|
|
|
>p : (n: any) => MyClass
|
|
|
|
>(n) => n && this : (n: any) => MyClass
|
|
|
|
>n : any
|
|
|
|
>n && this : MyClass
|
|
|
|
>n : any
|
|
|
|
>this : MyClass
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Arrow function used in arrow function
|
|
|
|
var arrrr = () => (m: number) => () => (n: number) => m + n;
|
|
|
|
>arrrr : () => (m: number) => () => (n: number) => number
|
|
|
|
>() => (m: number) => () => (n: number) => m + n : () => (m: number) => () => (n: number) => number
|
|
|
|
>(m: number) => () => (n: number) => m + n : (m: number) => () => (n: number) => number
|
|
|
|
>m : number
|
|
|
|
>() => (n: number) => m + n : () => (n: number) => number
|
|
|
|
>(n: number) => m + n : (n: number) => number
|
|
|
|
>n : number
|
|
|
|
>m + n : number
|
|
|
|
>m : number
|
|
|
|
>n : number
|
|
|
|
|
|
|
|
var e = arrrr()(3)()(4);
|
|
|
|
>e : number
|
|
|
|
>arrrr()(3)()(4) : number
|
|
|
|
>arrrr()(3)() : (n: number) => number
|
|
|
|
>arrrr()(3) : () => (n: number) => number
|
|
|
|
>arrrr() : (m: number) => () => (n: number) => number
|
|
|
|
>arrrr : () => (m: number) => () => (n: number) => number
|
|
|
|
|
|
|
|
var e: number;
|
|
|
|
>e : number
|
|
|
|
|
|
|
|
// Arrow function used in arrow function used in function
|
|
|
|
function someFn() {
|
2014-08-28 21:52:44 +02:00
|
|
|
>someFn : () => void
|
2014-08-15 23:33:16 +02:00
|
|
|
|
|
|
|
var arr = (n: number) => (p: number) => p * n;
|
|
|
|
>arr : (n: number) => (p: number) => number
|
|
|
|
>(n: number) => (p: number) => p * n : (n: number) => (p: number) => number
|
|
|
|
>n : number
|
|
|
|
>(p: number) => p * n : (p: number) => number
|
|
|
|
>p : number
|
|
|
|
>p * n : number
|
|
|
|
>p : number
|
|
|
|
>n : number
|
|
|
|
|
|
|
|
arr(3)(4).toExponential();
|
|
|
|
>arr(3)(4).toExponential() : string
|
|
|
|
>arr(3)(4).toExponential : (fractionDigits?: number) => string
|
|
|
|
>arr(3)(4) : number
|
|
|
|
>arr(3) : (p: number) => number
|
|
|
|
>arr : (n: number) => (p: number) => number
|
|
|
|
>toExponential : (fractionDigits?: number) => string
|
|
|
|
}
|
|
|
|
|
|
|
|
// Arrow function used in function
|
|
|
|
function someOtherFn() {
|
2014-08-28 21:52:44 +02:00
|
|
|
>someOtherFn : () => void
|
2014-08-15 23:33:16 +02:00
|
|
|
|
|
|
|
var arr = (n: number) => '' + n;
|
|
|
|
>arr : (n: number) => string
|
|
|
|
>(n: number) => '' + n : (n: number) => string
|
|
|
|
>n : number
|
|
|
|
>'' + n : string
|
|
|
|
>n : number
|
|
|
|
|
|
|
|
arr(4).charAt(0);
|
|
|
|
>arr(4).charAt(0) : string
|
|
|
|
>arr(4).charAt : (pos: number) => string
|
|
|
|
>arr(4) : string
|
|
|
|
>arr : (n: number) => string
|
|
|
|
>charAt : (pos: number) => string
|
|
|
|
}
|
|
|
|
|
|
|
|
// Arrow function used in nested function in function
|
|
|
|
function outerFn() {
|
2014-08-28 21:52:44 +02:00
|
|
|
>outerFn : () => void
|
2014-08-15 23:33:16 +02:00
|
|
|
|
|
|
|
function innerFn() {
|
|
|
|
>innerFn : () => void
|
|
|
|
|
|
|
|
var arrowFn = () => { };
|
|
|
|
>arrowFn : () => void
|
|
|
|
>() => { } : () => void
|
|
|
|
|
|
|
|
var p = arrowFn();
|
|
|
|
>p : void
|
|
|
|
>arrowFn() : void
|
|
|
|
>arrowFn : () => void
|
|
|
|
|
|
|
|
var p: void;
|
|
|
|
>p : void
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Arrow function used in nested function in arrow function
|
|
|
|
var f = (n: string) => {
|
|
|
|
>f : (n: string) => () => string
|
2014-08-22 03:39:46 +02:00
|
|
|
>(n: string) => { function fn(x: number) { return () => n + x; } return fn(4);} : (n: string) => () => string
|
2014-08-15 23:33:16 +02:00
|
|
|
>n : string
|
|
|
|
|
|
|
|
function fn(x: number) {
|
|
|
|
>fn : (x: number) => () => string
|
|
|
|
>x : number
|
|
|
|
|
|
|
|
return () => n + x;
|
|
|
|
>() => n + x : () => string
|
|
|
|
>n + x : string
|
|
|
|
>n : string
|
|
|
|
>x : number
|
|
|
|
}
|
|
|
|
return fn(4);
|
|
|
|
>fn(4) : () => string
|
|
|
|
>fn : (x: number) => () => string
|
|
|
|
}
|
|
|
|
var g = f('')();
|
|
|
|
>g : string
|
|
|
|
>f('')() : string
|
|
|
|
>f('') : () => string
|
|
|
|
>f : (n: string) => () => string
|
|
|
|
|
|
|
|
var g: string;
|
|
|
|
>g : string
|
|
|
|
|
|
|
|
|
|
|
|
// Arrow function used in nested function in arrow function in nested function
|
|
|
|
function someOuterFn() {
|
2014-08-28 21:52:44 +02:00
|
|
|
>someOuterFn : () => (n: string) => () => () => number
|
2014-08-15 23:33:16 +02:00
|
|
|
|
|
|
|
var arr = (n: string) => {
|
|
|
|
>arr : (n: string) => () => () => number
|
2014-08-22 03:39:46 +02:00
|
|
|
>(n: string) => { function innerFn() { return () => n.length; } return innerFn; } : (n: string) => () => () => number
|
2014-08-15 23:33:16 +02:00
|
|
|
>n : string
|
|
|
|
|
|
|
|
function innerFn() {
|
|
|
|
>innerFn : () => () => number
|
|
|
|
|
|
|
|
return () => n.length;
|
|
|
|
>() => n.length : () => number
|
|
|
|
>n.length : number
|
|
|
|
>n : string
|
|
|
|
>length : number
|
|
|
|
}
|
|
|
|
return innerFn;
|
|
|
|
>innerFn : () => () => number
|
|
|
|
}
|
|
|
|
return arr;
|
|
|
|
>arr : (n: string) => () => () => number
|
|
|
|
}
|
|
|
|
var h = someOuterFn()('')()();
|
|
|
|
>h : number
|
|
|
|
>someOuterFn()('')()() : number
|
|
|
|
>someOuterFn()('')() : () => number
|
|
|
|
>someOuterFn()('') : () => () => number
|
|
|
|
>someOuterFn() : (n: string) => () => () => number
|
2014-08-28 21:52:44 +02:00
|
|
|
>someOuterFn : () => (n: string) => () => () => number
|
2014-08-15 23:33:16 +02:00
|
|
|
|
|
|
|
h.toExponential();
|
|
|
|
>h.toExponential() : string
|
|
|
|
>h.toExponential : (fractionDigits?: number) => string
|
|
|
|
>h : number
|
|
|
|
>toExponential : (fractionDigits?: number) => string
|
|
|
|
|
|
|
|
// Arrow function used in try/catch/finally in function
|
|
|
|
function tryCatchFn() {
|
2014-08-28 21:52:44 +02:00
|
|
|
>tryCatchFn : () => void
|
2014-08-15 23:33:16 +02:00
|
|
|
|
|
|
|
try {
|
|
|
|
var x = () => this;
|
|
|
|
>x : () => any
|
|
|
|
>() => this : () => any
|
|
|
|
>this : any
|
|
|
|
|
|
|
|
} catch (e) {
|
|
|
|
>e : any
|
|
|
|
|
|
|
|
var t = () => e + this;
|
|
|
|
>t : () => any
|
|
|
|
>() => e + this : () => any
|
|
|
|
>e + this : any
|
|
|
|
>e : any
|
|
|
|
>this : any
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
var m = () => this + '';
|
|
|
|
>m : () => string
|
|
|
|
>() => this + '' : () => string
|
|
|
|
>this + '' : string
|
|
|
|
>this : any
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|