mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
Merge pull request #1627 from Microsoft/emitArrowFunctionES6
Emit arrow function es6
This commit is contained in:
+13
-1
@@ -4861,6 +4861,16 @@ module ts {
|
||||
function checkIdentifier(node: Identifier): Type {
|
||||
var symbol = getResolvedSymbol(node);
|
||||
|
||||
// As noted in ECMAScript 6 language spec, arrow functions never have an arguments objects.
|
||||
// Although in down-level emit of arrow function, we emit it using function expression which means that
|
||||
// arguments objects will be bound to the inner object; emitting arrow function natively in ES6, arguments objects
|
||||
// will be bound to non-arrow function that contain this arrow function. This results in inconsistent behavior.
|
||||
// To avoid that we will give an error to users if they use arguments objects in arrow function so that they
|
||||
// can explicitly bound arguments objects
|
||||
if (symbol === argumentsSymbol && getContainingFunction(node).kind === SyntaxKind.ArrowFunction) {
|
||||
error(node, Diagnostics.The_arguments_object_cannot_be_referenced_in_an_arrow_function_Consider_using_a_standard_function_expression);
|
||||
}
|
||||
|
||||
if (symbol.flags & SymbolFlags.Import) {
|
||||
var symbolLinks = getSymbolLinks(symbol);
|
||||
if (!symbolLinks.referenced) {
|
||||
@@ -4915,7 +4925,9 @@ module ts {
|
||||
// Now skip arrow functions to get the "real" owner of 'this'.
|
||||
if (container.kind === SyntaxKind.ArrowFunction) {
|
||||
container = getThisContainer(container, /* includeArrowFunctions */ false);
|
||||
needToCaptureLexicalThis = true;
|
||||
|
||||
// When targeting es6, arrow function lexically bind "this" so we do not need to do the work of binding "this" in emitted code
|
||||
needToCaptureLexicalThis = (languageVersion < ScriptTarget.ES6);
|
||||
}
|
||||
|
||||
switch (container.kind) {
|
||||
|
||||
@@ -452,5 +452,6 @@ module ts {
|
||||
You_cannot_rename_this_element: { code: 8000, category: DiagnosticCategory.Error, key: "You cannot rename this element." },
|
||||
yield_expressions_are_not_currently_supported: { code: 9000, category: DiagnosticCategory.Error, key: "'yield' expressions are not currently supported.", isEarly: true },
|
||||
Generators_are_not_currently_supported: { code: 9001, category: DiagnosticCategory.Error, key: "Generators are not currently supported.", isEarly: true },
|
||||
The_arguments_object_cannot_be_referenced_in_an_arrow_function_Consider_using_a_standard_function_expression: { code: 9002, category: DiagnosticCategory.Error, key: "The 'arguments' object cannot be referenced in an arrow function. Consider using a standard function expression." },
|
||||
};
|
||||
}
|
||||
@@ -1612,7 +1612,7 @@
|
||||
"Property '{0}' does not exist on 'const' enum '{1}'.": {
|
||||
"category": "Error",
|
||||
"code": 4088,
|
||||
"isEarly": true
|
||||
"isEarly": true
|
||||
},
|
||||
"The current host does not support the '{0}' option.": {
|
||||
"category": "Error",
|
||||
@@ -1902,11 +1902,15 @@
|
||||
"'yield' expressions are not currently supported.": {
|
||||
"category": "Error",
|
||||
"code": 9000,
|
||||
"isEarly": true
|
||||
"isEarly": true
|
||||
},
|
||||
"Generators are not currently supported.": {
|
||||
"category": "Error",
|
||||
"code": 9001,
|
||||
"isEarly": true
|
||||
"isEarly": true
|
||||
},
|
||||
"The 'arguments' object cannot be referenced in an arrow function. Consider using a standard function expression.": {
|
||||
"category": "Error",
|
||||
"code": 9002
|
||||
}
|
||||
}
|
||||
|
||||
+31
-3
@@ -1487,7 +1487,6 @@ module ts {
|
||||
|
||||
// targetSourceFile is when users only want one file in entire project to be emitted. This is used in compilerOnSave feature
|
||||
export function emitFiles(resolver: EmitResolver, host: EmitHost, targetSourceFile?: SourceFile): EmitResult {
|
||||
// var program = resolver.getProgram();
|
||||
var compilerOptions = host.getCompilerOptions();
|
||||
var languageVersion = compilerOptions.target || ScriptTarget.ES3;
|
||||
var sourceMapDataList: SourceMapData[] = compilerOptions.sourceMap ? [] : undefined;
|
||||
@@ -3240,6 +3239,10 @@ module ts {
|
||||
emitSignatureAndBody(node);
|
||||
}
|
||||
|
||||
function shouldEmitAsArrowFunction(node: FunctionLikeDeclaration): boolean {
|
||||
return node.kind === SyntaxKind.ArrowFunction && languageVersion >= ScriptTarget.ES6;
|
||||
}
|
||||
|
||||
function emitFunctionDeclaration(node: FunctionLikeDeclaration) {
|
||||
if (nodeIsMissing(node.body)) {
|
||||
return emitPinnedOrTripleSlashComments(node);
|
||||
@@ -3249,7 +3252,13 @@ module ts {
|
||||
// Methods will emit the comments as part of emitting method declaration
|
||||
emitLeadingComments(node);
|
||||
}
|
||||
write("function ");
|
||||
|
||||
// For targeting below es6, emit functions-like declaration including arrow function using function keyword.
|
||||
// When targeting ES6, emit arrow function natively in ES6 by omitting function keyword and using fat arrow instead
|
||||
if (!shouldEmitAsArrowFunction(node)) {
|
||||
write("function ");
|
||||
}
|
||||
|
||||
if (node.kind === SyntaxKind.FunctionDeclaration || (node.kind === SyntaxKind.FunctionExpression && node.name)) {
|
||||
emit(node.name);
|
||||
}
|
||||
@@ -3280,6 +3289,15 @@ module ts {
|
||||
decreaseIndent();
|
||||
}
|
||||
|
||||
function emitSignatureParametersForArrow(node: FunctionLikeDeclaration) {
|
||||
// Check whether the parameter list needs parentheses and preserve no-parenthesis
|
||||
if (node.parameters.length === 1 && node.pos === node.parameters[0].pos) {
|
||||
emit(node.parameters[0]);
|
||||
return;
|
||||
}
|
||||
emitSignatureParameters(node);
|
||||
}
|
||||
|
||||
function emitSignatureAndBody(node: FunctionLikeDeclaration) {
|
||||
var saveTempCount = tempCount;
|
||||
var saveTempVariables = tempVariables;
|
||||
@@ -3287,7 +3305,16 @@ module ts {
|
||||
tempCount = 0;
|
||||
tempVariables = undefined;
|
||||
tempParameters = undefined;
|
||||
emitSignatureParameters(node);
|
||||
|
||||
// When targeting ES6, emit arrow function natively in ES6
|
||||
if (shouldEmitAsArrowFunction(node)) {
|
||||
emitSignatureParametersForArrow(node);
|
||||
write(" =>");
|
||||
}
|
||||
else {
|
||||
emitSignatureParameters(node);
|
||||
}
|
||||
|
||||
write(" {");
|
||||
scopeEmitStart(node);
|
||||
increaseIndent();
|
||||
@@ -3299,6 +3326,7 @@ module ts {
|
||||
startIndex = emitDirectivePrologues((<Block>node.body).statements, /*startWithNewLine*/ true);
|
||||
}
|
||||
var outPos = writer.getTextPos();
|
||||
|
||||
emitCaptureThisForNodeIfNecessary(node);
|
||||
emitDefaultValueAssignments(node);
|
||||
emitRestParameter(node);
|
||||
|
||||
@@ -107,7 +107,7 @@ module Utils {
|
||||
export function memoize<T extends Function>(f: T): T {
|
||||
var cache: { [idx: string]: any } = {};
|
||||
|
||||
return <any>(() => {
|
||||
return <any>(function () {
|
||||
var key = Array.prototype.join.call(arguments);
|
||||
var cachedResult = cache[key];
|
||||
if (cachedResult) {
|
||||
|
||||
@@ -138,7 +138,7 @@ module Playback {
|
||||
|
||||
function recordReplay<T extends Function>(original: T, underlying: any) {
|
||||
function createWrapper(record: T, replay: T): T {
|
||||
return <any>(() => {
|
||||
return <any>(function () {
|
||||
if (replayLog !== undefined) {
|
||||
return replay.apply(undefined, arguments);
|
||||
} else if (recordLog !== undefined) {
|
||||
|
||||
@@ -186,7 +186,7 @@ class ProjectRunner extends RunnerBase {
|
||||
function createCompilerHost(): ts.CompilerHost {
|
||||
return {
|
||||
getSourceFile,
|
||||
getDefaultLibFilename: options => options.target === ts.ScriptTarget.ES6 ? "lib.es6.d.ts" : "lib.d.ts",
|
||||
getDefaultLibFilename: options => Harness.Compiler.defaultLibFileName,
|
||||
writeFile,
|
||||
getCurrentDirectory,
|
||||
getCanonicalFileName: Harness.Compiler.getCanonicalFileName,
|
||||
|
||||
@@ -15,10 +15,9 @@ var C = (function () {
|
||||
function C() {
|
||||
}
|
||||
C.prototype.bar = function () {
|
||||
var _this = this;
|
||||
(function () {
|
||||
(() => {
|
||||
var obj = {
|
||||
[_this.bar()]() {
|
||||
[this.bar()]() {
|
||||
} // needs capture
|
||||
};
|
||||
});
|
||||
|
||||
@@ -16,7 +16,7 @@ var C = (function () {
|
||||
}
|
||||
C.prototype[0 + 1] = function () {
|
||||
};
|
||||
C[function () {
|
||||
C[() => {
|
||||
}] = function () {
|
||||
};
|
||||
Object.defineProperty(C.prototype, delete id, {
|
||||
|
||||
@@ -31,7 +31,7 @@ var C = (function (_super) {
|
||||
__extends(C, _super);
|
||||
function C() {
|
||||
_super.call(this);
|
||||
(function () {
|
||||
(() => {
|
||||
var obj = {
|
||||
// Ideally, we would capture this. But the reference is
|
||||
// illegal, and not capturing this is consistent with
|
||||
|
||||
@@ -37,7 +37,7 @@ var C = (function (_super) {
|
||||
}
|
||||
C.prototype.foo = function () {
|
||||
var _this = this;
|
||||
(function () {
|
||||
(() => {
|
||||
var obj = {
|
||||
[_super.prototype.bar.call(_this)]() {
|
||||
} // needs capture
|
||||
|
||||
@@ -14,5 +14,5 @@ var o = {
|
||||
["" + 0](y) {
|
||||
return y.length;
|
||||
},
|
||||
["" + 1]: function (y) { return y.length; }
|
||||
["" + 1]: y => { return y.length; }
|
||||
};
|
||||
|
||||
@@ -14,5 +14,5 @@ var o = {
|
||||
[+"foo"](y) {
|
||||
return y.length;
|
||||
},
|
||||
[+"bar"]: function (y) { return y.length; }
|
||||
[+"bar"]: y => { return y.length; }
|
||||
};
|
||||
|
||||
@@ -13,5 +13,5 @@ var o = {
|
||||
[+"foo"](y) {
|
||||
return y.length;
|
||||
},
|
||||
[+"bar"]: function (y) { return y.length; }
|
||||
[+"bar"]: y => { return y.length; }
|
||||
};
|
||||
|
||||
@@ -16,7 +16,7 @@ foo({
|
||||
//// [computedPropertyNamesContextualType6.js]
|
||||
foo({
|
||||
p: "",
|
||||
0: function () {
|
||||
0: () => {
|
||||
},
|
||||
["hi" + "bye"]: true,
|
||||
[0 + 1]: 0,
|
||||
|
||||
@@ -16,7 +16,7 @@ foo({
|
||||
//// [computedPropertyNamesContextualType7.js]
|
||||
foo({
|
||||
p: "",
|
||||
0: function () {
|
||||
0: () => {
|
||||
},
|
||||
["hi" + "bye"]: true,
|
||||
[0 + 1]: 0,
|
||||
|
||||
@@ -223,7 +223,7 @@ function F() {
|
||||
const c = 0;
|
||||
n = c;
|
||||
}
|
||||
var F2 = function () {
|
||||
var F2 = () => {
|
||||
const c = 0;
|
||||
n = c;
|
||||
};
|
||||
@@ -272,7 +272,7 @@ var o = {
|
||||
const c = 0;
|
||||
n = c;
|
||||
},
|
||||
f2: function () {
|
||||
f2: () => {
|
||||
const c = 0;
|
||||
n = c;
|
||||
}
|
||||
|
||||
@@ -186,7 +186,7 @@ const c18 = 0;
|
||||
function F() {
|
||||
const c19 = 0;
|
||||
}
|
||||
var F2 = function () {
|
||||
var F2 = () => {
|
||||
const c20 = 0;
|
||||
};
|
||||
var F3 = function () {
|
||||
@@ -226,7 +226,7 @@ var o = {
|
||||
f() {
|
||||
const c28 = 0;
|
||||
},
|
||||
f2: function () {
|
||||
f2: () => {
|
||||
const c29 = 0;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
//// [emitArrowFunction.ts]
|
||||
var f1 = () => { }
|
||||
var f2 = (x: string, y: string) => { }
|
||||
var f3 = (x: string, y: number, ...rest) => { }
|
||||
var f4 = (x: string, y: number, z = 10) => { }
|
||||
function foo(func: () => boolean) { }
|
||||
foo(() => true);
|
||||
foo(() => { return false; });
|
||||
|
||||
//// [emitArrowFunction.js]
|
||||
var f1 = function () {
|
||||
};
|
||||
var f2 = function (x, y) {
|
||||
};
|
||||
var f3 = function (x, y) {
|
||||
var rest = [];
|
||||
for (var _i = 2; _i < arguments.length; _i++) {
|
||||
rest[_i - 2] = arguments[_i];
|
||||
}
|
||||
};
|
||||
var f4 = function (x, y, z) {
|
||||
if (z === void 0) { z = 10; }
|
||||
};
|
||||
function foo(func) {
|
||||
}
|
||||
foo(function () { return true; });
|
||||
foo(function () {
|
||||
return false;
|
||||
});
|
||||
@@ -0,0 +1,39 @@
|
||||
=== tests/cases/conformance/es6/arrowFunction/emitArrowFunction.ts ===
|
||||
var f1 = () => { }
|
||||
>f1 : () => void
|
||||
>() => { } : () => void
|
||||
|
||||
var f2 = (x: string, y: string) => { }
|
||||
>f2 : (x: string, y: string) => void
|
||||
>(x: string, y: string) => { } : (x: string, y: string) => void
|
||||
>x : string
|
||||
>y : string
|
||||
|
||||
var f3 = (x: string, y: number, ...rest) => { }
|
||||
>f3 : (x: string, y: number, ...rest: any[]) => void
|
||||
>(x: string, y: number, ...rest) => { } : (x: string, y: number, ...rest: any[]) => void
|
||||
>x : string
|
||||
>y : number
|
||||
>rest : any[]
|
||||
|
||||
var f4 = (x: string, y: number, z = 10) => { }
|
||||
>f4 : (x: string, y: number, z?: number) => void
|
||||
>(x: string, y: number, z = 10) => { } : (x: string, y: number, z?: number) => void
|
||||
>x : string
|
||||
>y : number
|
||||
>z : number
|
||||
|
||||
function foo(func: () => boolean) { }
|
||||
>foo : (func: () => boolean) => void
|
||||
>func : () => boolean
|
||||
|
||||
foo(() => true);
|
||||
>foo(() => true) : void
|
||||
>foo : (func: () => boolean) => void
|
||||
>() => true : () => boolean
|
||||
|
||||
foo(() => { return false; });
|
||||
>foo(() => { return false; }) : void
|
||||
>foo : (func: () => boolean) => void
|
||||
>() => { return false; } : () => boolean
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
//// [emitArrowFunctionAsIs.ts]
|
||||
var arrow1 = a => { };
|
||||
var arrow2 = (a) => { };
|
||||
|
||||
var arrow3 = (a, b) => { };
|
||||
|
||||
//// [emitArrowFunctionAsIs.js]
|
||||
var arrow1 = function (a) {
|
||||
};
|
||||
var arrow2 = function (a) {
|
||||
};
|
||||
var arrow3 = function (a, b) {
|
||||
};
|
||||
@@ -0,0 +1,17 @@
|
||||
=== tests/cases/conformance/es6/arrowFunction/emitArrowFunctionAsIs.ts ===
|
||||
var arrow1 = a => { };
|
||||
>arrow1 : (a: any) => void
|
||||
>a => { } : (a: any) => void
|
||||
>a : any
|
||||
|
||||
var arrow2 = (a) => { };
|
||||
>arrow2 : (a: any) => void
|
||||
>(a) => { } : (a: any) => void
|
||||
>a : any
|
||||
|
||||
var arrow3 = (a, b) => { };
|
||||
>arrow3 : (a: any, b: any) => void
|
||||
>(a, b) => { } : (a: any, b: any) => void
|
||||
>a : any
|
||||
>b : any
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
//// [emitArrowFunctionAsIsES6.ts]
|
||||
var arrow1 = a => { };
|
||||
var arrow2 = (a) => { };
|
||||
|
||||
var arrow3 = (a, b) => { };
|
||||
|
||||
//// [emitArrowFunctionAsIsES6.js]
|
||||
var arrow1 = a => {
|
||||
};
|
||||
var arrow2 = (a) => {
|
||||
};
|
||||
var arrow3 = (a, b) => {
|
||||
};
|
||||
@@ -0,0 +1,17 @@
|
||||
=== tests/cases/conformance/es6/arrowFunction/emitArrowFunctionAsIsES6.ts ===
|
||||
var arrow1 = a => { };
|
||||
>arrow1 : (a: any) => void
|
||||
>a => { } : (a: any) => void
|
||||
>a : any
|
||||
|
||||
var arrow2 = (a) => { };
|
||||
>arrow2 : (a: any) => void
|
||||
>(a) => { } : (a: any) => void
|
||||
>a : any
|
||||
|
||||
var arrow3 = (a, b) => { };
|
||||
>arrow3 : (a: any, b: any) => void
|
||||
>(a, b) => { } : (a: any, b: any) => void
|
||||
>a : any
|
||||
>b : any
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
//// [emitArrowFunctionES6.ts]
|
||||
var f1 = () => { }
|
||||
var f2 = (x: string, y: string) => { }
|
||||
var f3 = (x: string, y: number, ...rest) => { }
|
||||
var f4 = (x: string, y: number, z=10) => { }
|
||||
function foo(func: () => boolean) { }
|
||||
foo(() => true);
|
||||
foo(() => { return false; });
|
||||
|
||||
|
||||
//// [emitArrowFunctionES6.js]
|
||||
var f1 = () => {
|
||||
};
|
||||
var f2 = (x, y) => {
|
||||
};
|
||||
var f3 = (x, y, ...rest) => {
|
||||
};
|
||||
var f4 = (x, y, z = 10) => {
|
||||
};
|
||||
function foo(func) {
|
||||
}
|
||||
foo(() => { return true; });
|
||||
foo(() => {
|
||||
return false;
|
||||
});
|
||||
@@ -0,0 +1,39 @@
|
||||
=== tests/cases/conformance/es6/arrowFunction/emitArrowFunctionES6.ts ===
|
||||
var f1 = () => { }
|
||||
>f1 : () => void
|
||||
>() => { } : () => void
|
||||
|
||||
var f2 = (x: string, y: string) => { }
|
||||
>f2 : (x: string, y: string) => void
|
||||
>(x: string, y: string) => { } : (x: string, y: string) => void
|
||||
>x : string
|
||||
>y : string
|
||||
|
||||
var f3 = (x: string, y: number, ...rest) => { }
|
||||
>f3 : (x: string, y: number, ...rest: any[]) => void
|
||||
>(x: string, y: number, ...rest) => { } : (x: string, y: number, ...rest: any[]) => void
|
||||
>x : string
|
||||
>y : number
|
||||
>rest : any[]
|
||||
|
||||
var f4 = (x: string, y: number, z=10) => { }
|
||||
>f4 : (x: string, y: number, z?: number) => void
|
||||
>(x: string, y: number, z=10) => { } : (x: string, y: number, z?: number) => void
|
||||
>x : string
|
||||
>y : number
|
||||
>z : number
|
||||
|
||||
function foo(func: () => boolean) { }
|
||||
>foo : (func: () => boolean) => void
|
||||
>func : () => boolean
|
||||
|
||||
foo(() => true);
|
||||
>foo(() => true) : void
|
||||
>foo : (func: () => boolean) => void
|
||||
>() => true : () => boolean
|
||||
|
||||
foo(() => { return false; });
|
||||
>foo(() => { return false; }) : void
|
||||
>foo : (func: () => boolean) => void
|
||||
>() => { return false; } : () => boolean
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
//// [emitArrowFunctionThisCapturing.ts]
|
||||
var f1 = () => {
|
||||
this.age = 10
|
||||
};
|
||||
|
||||
var f2 = (x: string) => {
|
||||
this.name = x
|
||||
}
|
||||
|
||||
function foo(func: () => boolean) { }
|
||||
foo(() => {
|
||||
this.age = 100;
|
||||
return true;
|
||||
});
|
||||
|
||||
|
||||
//// [emitArrowFunctionThisCapturing.js]
|
||||
var _this = this;
|
||||
var f1 = function () {
|
||||
_this.age = 10;
|
||||
};
|
||||
var f2 = function (x) {
|
||||
_this.name = x;
|
||||
};
|
||||
function foo(func) {
|
||||
}
|
||||
foo(function () {
|
||||
_this.age = 100;
|
||||
return true;
|
||||
});
|
||||
@@ -0,0 +1,44 @@
|
||||
=== tests/cases/conformance/es6/arrowFunction/emitArrowFunctionThisCapturing.ts ===
|
||||
var f1 = () => {
|
||||
>f1 : () => void
|
||||
>() => { this.age = 10} : () => void
|
||||
|
||||
this.age = 10
|
||||
>this.age = 10 : number
|
||||
>this.age : any
|
||||
>this : any
|
||||
>age : any
|
||||
|
||||
};
|
||||
|
||||
var f2 = (x: string) => {
|
||||
>f2 : (x: string) => void
|
||||
>(x: string) => { this.name = x} : (x: string) => void
|
||||
>x : string
|
||||
|
||||
this.name = x
|
||||
>this.name = x : string
|
||||
>this.name : any
|
||||
>this : any
|
||||
>name : any
|
||||
>x : string
|
||||
}
|
||||
|
||||
function foo(func: () => boolean) { }
|
||||
>foo : (func: () => boolean) => void
|
||||
>func : () => boolean
|
||||
|
||||
foo(() => {
|
||||
>foo(() => { this.age = 100; return true;}) : void
|
||||
>foo : (func: () => boolean) => void
|
||||
>() => { this.age = 100; return true;} : () => boolean
|
||||
|
||||
this.age = 100;
|
||||
>this.age = 100 : number
|
||||
>this.age : any
|
||||
>this : any
|
||||
>age : any
|
||||
|
||||
return true;
|
||||
});
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
//// [emitArrowFunctionThisCapturingES6.ts]
|
||||
var f1 = () => {
|
||||
this.age = 10
|
||||
};
|
||||
|
||||
var f2 = (x: string) => {
|
||||
this.name = x
|
||||
}
|
||||
|
||||
function foo(func: () => boolean){ }
|
||||
foo(() => {
|
||||
this.age = 100;
|
||||
return true;
|
||||
});
|
||||
|
||||
|
||||
//// [emitArrowFunctionThisCapturingES6.js]
|
||||
var f1 = () => {
|
||||
this.age = 10;
|
||||
};
|
||||
var f2 = (x) => {
|
||||
this.name = x;
|
||||
};
|
||||
function foo(func) {
|
||||
}
|
||||
foo(() => {
|
||||
this.age = 100;
|
||||
return true;
|
||||
});
|
||||
@@ -0,0 +1,44 @@
|
||||
=== tests/cases/conformance/es6/arrowFunction/emitArrowFunctionThisCapturingES6.ts ===
|
||||
var f1 = () => {
|
||||
>f1 : () => void
|
||||
>() => { this.age = 10} : () => void
|
||||
|
||||
this.age = 10
|
||||
>this.age = 10 : number
|
||||
>this.age : any
|
||||
>this : any
|
||||
>age : any
|
||||
|
||||
};
|
||||
|
||||
var f2 = (x: string) => {
|
||||
>f2 : (x: string) => void
|
||||
>(x: string) => { this.name = x} : (x: string) => void
|
||||
>x : string
|
||||
|
||||
this.name = x
|
||||
>this.name = x : string
|
||||
>this.name : any
|
||||
>this : any
|
||||
>name : any
|
||||
>x : string
|
||||
}
|
||||
|
||||
function foo(func: () => boolean){ }
|
||||
>foo : (func: () => boolean) => void
|
||||
>func : () => boolean
|
||||
|
||||
foo(() => {
|
||||
>foo(() => { this.age = 100; return true;}) : void
|
||||
>foo : (func: () => boolean) => void
|
||||
>() => { this.age = 100; return true;} : () => boolean
|
||||
|
||||
this.age = 100;
|
||||
>this.age = 100 : number
|
||||
>this.age : any
|
||||
>this : any
|
||||
>age : any
|
||||
|
||||
return true;
|
||||
});
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
tests/cases/conformance/es6/arrowFunction/emitArrowFunctionWhenUsingArguments.ts(2,15): error TS9002: The 'arguments' object cannot be referenced in an arrow function. Consider using a standard function expression.
|
||||
tests/cases/conformance/es6/arrowFunction/emitArrowFunctionWhenUsingArguments.ts(7,19): error TS9002: The 'arguments' object cannot be referenced in an arrow function. Consider using a standard function expression.
|
||||
tests/cases/conformance/es6/arrowFunction/emitArrowFunctionWhenUsingArguments.ts(13,13): error TS9002: The 'arguments' object cannot be referenced in an arrow function. Consider using a standard function expression.
|
||||
tests/cases/conformance/es6/arrowFunction/emitArrowFunctionWhenUsingArguments.ts(19,15): error TS9002: The 'arguments' object cannot be referenced in an arrow function. Consider using a standard function expression.
|
||||
|
||||
|
||||
==== tests/cases/conformance/es6/arrowFunction/emitArrowFunctionWhenUsingArguments.ts (4 errors) ====
|
||||
var a = () => {
|
||||
var arg = arguments[0]; // error
|
||||
~~~~~~~~~
|
||||
!!! error TS9002: The 'arguments' object cannot be referenced in an arrow function. Consider using a standard function expression.
|
||||
}
|
||||
|
||||
var b = function () {
|
||||
var a = () => {
|
||||
var arg = arguments[0]; // error
|
||||
~~~~~~~~~
|
||||
!!! error TS9002: The 'arguments' object cannot be referenced in an arrow function. Consider using a standard function expression.
|
||||
}
|
||||
}
|
||||
|
||||
function baz() {
|
||||
() => {
|
||||
var arg = arguments[0];
|
||||
~~~~~~~~~
|
||||
!!! error TS9002: The 'arguments' object cannot be referenced in an arrow function. Consider using a standard function expression.
|
||||
}
|
||||
}
|
||||
|
||||
function foo(inputFunc: () => void) { }
|
||||
foo(() => {
|
||||
var arg = arguments[0]; // error
|
||||
~~~~~~~~~
|
||||
!!! error TS9002: The 'arguments' object cannot be referenced in an arrow function. Consider using a standard function expression.
|
||||
});
|
||||
|
||||
function bar() {
|
||||
var arg = arguments[0]; // no error
|
||||
}
|
||||
|
||||
|
||||
() => {
|
||||
function foo() {
|
||||
var arg = arguments[0]; // no error
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
//// [emitArrowFunctionWhenUsingArguments.ts]
|
||||
var a = () => {
|
||||
var arg = arguments[0]; // error
|
||||
}
|
||||
|
||||
var b = function () {
|
||||
var a = () => {
|
||||
var arg = arguments[0]; // error
|
||||
}
|
||||
}
|
||||
|
||||
function baz() {
|
||||
() => {
|
||||
var arg = arguments[0];
|
||||
}
|
||||
}
|
||||
|
||||
function foo(inputFunc: () => void) { }
|
||||
foo(() => {
|
||||
var arg = arguments[0]; // error
|
||||
});
|
||||
|
||||
function bar() {
|
||||
var arg = arguments[0]; // no error
|
||||
}
|
||||
|
||||
|
||||
() => {
|
||||
function foo() {
|
||||
var arg = arguments[0]; // no error
|
||||
}
|
||||
}
|
||||
|
||||
//// [emitArrowFunctionWhenUsingArguments.js]
|
||||
var a = () => {
|
||||
var arg = arguments[0]; // error
|
||||
};
|
||||
var b = function () {
|
||||
var a = () => {
|
||||
var arg = arguments[0]; // error
|
||||
};
|
||||
};
|
||||
function baz() {
|
||||
(() => {
|
||||
var arg = arguments[0];
|
||||
});
|
||||
}
|
||||
function foo(inputFunc) {
|
||||
}
|
||||
foo(() => {
|
||||
var arg = arguments[0]; // error
|
||||
});
|
||||
function bar() {
|
||||
var arg = arguments[0]; // no error
|
||||
}
|
||||
(() => {
|
||||
function foo() {
|
||||
var arg = arguments[0]; // no error
|
||||
}
|
||||
});
|
||||
@@ -0,0 +1,46 @@
|
||||
tests/cases/conformance/es6/arrowFunction/emitArrowFunctionWhenUsingArgumentsES6.ts(2,15): error TS9002: The 'arguments' object cannot be referenced in an arrow function. Consider using a standard function expression.
|
||||
tests/cases/conformance/es6/arrowFunction/emitArrowFunctionWhenUsingArgumentsES6.ts(7,19): error TS9002: The 'arguments' object cannot be referenced in an arrow function. Consider using a standard function expression.
|
||||
tests/cases/conformance/es6/arrowFunction/emitArrowFunctionWhenUsingArgumentsES6.ts(13,13): error TS9002: The 'arguments' object cannot be referenced in an arrow function. Consider using a standard function expression.
|
||||
tests/cases/conformance/es6/arrowFunction/emitArrowFunctionWhenUsingArgumentsES6.ts(19,15): error TS9002: The 'arguments' object cannot be referenced in an arrow function. Consider using a standard function expression.
|
||||
|
||||
|
||||
==== tests/cases/conformance/es6/arrowFunction/emitArrowFunctionWhenUsingArgumentsES6.ts (4 errors) ====
|
||||
var a = () => {
|
||||
var arg = arguments[0]; // error
|
||||
~~~~~~~~~
|
||||
!!! error TS9002: The 'arguments' object cannot be referenced in an arrow function. Consider using a standard function expression.
|
||||
}
|
||||
|
||||
var b = function () {
|
||||
var a = () => {
|
||||
var arg = arguments[0]; // error
|
||||
~~~~~~~~~
|
||||
!!! error TS9002: The 'arguments' object cannot be referenced in an arrow function. Consider using a standard function expression.
|
||||
}
|
||||
}
|
||||
|
||||
function baz() {
|
||||
() => {
|
||||
var arg = arguments[0];
|
||||
~~~~~~~~~
|
||||
!!! error TS9002: The 'arguments' object cannot be referenced in an arrow function. Consider using a standard function expression.
|
||||
}
|
||||
}
|
||||
|
||||
function foo(inputFunc: () => void) { }
|
||||
foo(() => {
|
||||
var arg = arguments[0]; // error
|
||||
~~~~~~~~~
|
||||
!!! error TS9002: The 'arguments' object cannot be referenced in an arrow function. Consider using a standard function expression.
|
||||
});
|
||||
|
||||
function bar() {
|
||||
var arg = arguments[0]; // no error
|
||||
}
|
||||
|
||||
|
||||
() => {
|
||||
function foo() {
|
||||
var arg = arguments[0]; // no error
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
//// [emitArrowFunctionWhenUsingArgumentsES6.ts]
|
||||
var a = () => {
|
||||
var arg = arguments[0]; // error
|
||||
}
|
||||
|
||||
var b = function () {
|
||||
var a = () => {
|
||||
var arg = arguments[0]; // error
|
||||
}
|
||||
}
|
||||
|
||||
function baz() {
|
||||
() => {
|
||||
var arg = arguments[0];
|
||||
}
|
||||
}
|
||||
|
||||
function foo(inputFunc: () => void) { }
|
||||
foo(() => {
|
||||
var arg = arguments[0]; // error
|
||||
});
|
||||
|
||||
function bar() {
|
||||
var arg = arguments[0]; // no error
|
||||
}
|
||||
|
||||
|
||||
() => {
|
||||
function foo() {
|
||||
var arg = arguments[0]; // no error
|
||||
}
|
||||
}
|
||||
|
||||
//// [emitArrowFunctionWhenUsingArgumentsES6.js]
|
||||
var a = () => {
|
||||
var arg = arguments[0]; // error
|
||||
};
|
||||
var b = function () {
|
||||
var a = () => {
|
||||
var arg = arguments[0]; // error
|
||||
};
|
||||
};
|
||||
function baz() {
|
||||
(() => {
|
||||
var arg = arguments[0];
|
||||
});
|
||||
}
|
||||
function foo(inputFunc) {
|
||||
}
|
||||
foo(() => {
|
||||
var arg = arguments[0]; // error
|
||||
});
|
||||
function bar() {
|
||||
var arg = arguments[0]; // no error
|
||||
}
|
||||
(() => {
|
||||
function foo() {
|
||||
var arg = arguments[0]; // no error
|
||||
}
|
||||
});
|
||||
@@ -0,0 +1,13 @@
|
||||
//// [emitArrowFunctionsAsIs.ts]
|
||||
var arrow1 = a => { };
|
||||
var arrow2 = (a) => { };
|
||||
|
||||
var arrow3 = (a, b) => { };
|
||||
|
||||
//// [emitArrowFunctionsAsIs.js]
|
||||
var arrow1 = function (a) {
|
||||
};
|
||||
var arrow2 = function (a) {
|
||||
};
|
||||
var arrow3 = function (a, b) {
|
||||
};
|
||||
@@ -0,0 +1,17 @@
|
||||
=== tests/cases/conformance/es6/arrowFunction/emitArrowFunctionsAsIs.ts ===
|
||||
var arrow1 = a => { };
|
||||
>arrow1 : (a: any) => void
|
||||
>a => { } : (a: any) => void
|
||||
>a : any
|
||||
|
||||
var arrow2 = (a) => { };
|
||||
>arrow2 : (a: any) => void
|
||||
>(a) => { } : (a: any) => void
|
||||
>a : any
|
||||
|
||||
var arrow3 = (a, b) => { };
|
||||
>arrow3 : (a: any, b: any) => void
|
||||
>(a, b) => { } : (a: any, b: any) => void
|
||||
>a : any
|
||||
>b : any
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
//// [emitArrowFunctionsAsIsES6.ts]
|
||||
var arrow1 = a => { };
|
||||
var arrow2 = (a) => { };
|
||||
|
||||
var arrow3 = (a, b) => { };
|
||||
|
||||
//// [emitArrowFunctionsAsIsES6.js]
|
||||
var arrow1 = a => {
|
||||
};
|
||||
var arrow2 = (a) => {
|
||||
};
|
||||
var arrow3 = (a, b) => {
|
||||
};
|
||||
@@ -0,0 +1,17 @@
|
||||
=== tests/cases/conformance/es6/arrowFunction/emitArrowFunctionsAsIsES6.ts ===
|
||||
var arrow1 = a => { };
|
||||
>arrow1 : (a: any) => void
|
||||
>a => { } : (a: any) => void
|
||||
>a : any
|
||||
|
||||
var arrow2 = (a) => { };
|
||||
>arrow2 : (a: any) => void
|
||||
>(a) => { } : (a: any) => void
|
||||
>a : any
|
||||
|
||||
var arrow3 = (a, b) => { };
|
||||
>arrow3 : (a: any, b: any) => void
|
||||
>(a, b) => { } : (a: any, b: any) => void
|
||||
>a : any
|
||||
>b : any
|
||||
|
||||
@@ -9,13 +9,13 @@ var y = (function (num = 10, boo = false, ...rest) { })()
|
||||
var z = (function (num: number, boo = false, ...rest) { })(10)
|
||||
|
||||
//// [emitDefaultParametersFunctionExpressionES6.js]
|
||||
var lambda1 = function (y = "hello") {
|
||||
var lambda1 = (y = "hello") => {
|
||||
};
|
||||
var lambda2 = function (x, y = "hello") {
|
||||
var lambda2 = (x, y = "hello") => {
|
||||
};
|
||||
var lambda3 = function (x, y = "hello", ...rest) {
|
||||
var lambda3 = (x, y = "hello", ...rest) => {
|
||||
};
|
||||
var lambda4 = function (y = "hello", ...rest) {
|
||||
var lambda4 = (y = "hello", ...rest) => {
|
||||
};
|
||||
var x = function (str = "hello", ...rest) {
|
||||
};
|
||||
|
||||
@@ -5,9 +5,9 @@ var funcExp2 = function (...rest) { }
|
||||
var funcExp3 = (function (...rest) { })()
|
||||
|
||||
//// [emitRestParametersFunctionExpressionES6.js]
|
||||
var funcExp = function (...rest) {
|
||||
var funcExp = (...rest) => {
|
||||
};
|
||||
var funcExp1 = function (X, ...rest) {
|
||||
var funcExp1 = (X, ...rest) => {
|
||||
};
|
||||
var funcExp2 = function (...rest) {
|
||||
};
|
||||
|
||||
@@ -239,7 +239,7 @@ function F() {
|
||||
let l = 0;
|
||||
n = l;
|
||||
}
|
||||
var F2 = function () {
|
||||
var F2 = () => {
|
||||
let l = 0;
|
||||
n = l;
|
||||
};
|
||||
@@ -289,7 +289,7 @@ var o = {
|
||||
let l = 0;
|
||||
n = l;
|
||||
},
|
||||
f2: function () {
|
||||
f2: () => {
|
||||
let l = 0;
|
||||
n = l;
|
||||
}
|
||||
|
||||
@@ -206,7 +206,7 @@ let l18 = 0;
|
||||
function F() {
|
||||
let l19 = 0;
|
||||
}
|
||||
var F2 = function () {
|
||||
var F2 = () => {
|
||||
let l20 = 0;
|
||||
};
|
||||
var F3 = function () {
|
||||
@@ -246,7 +246,7 @@ var o = {
|
||||
f() {
|
||||
let l28 = 0;
|
||||
},
|
||||
f2: function () {
|
||||
f2: () => {
|
||||
let l29 = 0;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -25,11 +25,11 @@ var h = tempFun `${ (x => x) } ${ (((x => x))) } ${ undefined }`
|
||||
function tempFun(tempStrs, g, x) {
|
||||
return g(x);
|
||||
}
|
||||
var a = tempFun `${function (x) { return x; }} ${10}`;
|
||||
var b = tempFun `${(function (x) { return x; })} ${10}`;
|
||||
var c = tempFun `${((function (x) { return x; }))} ${10}`;
|
||||
var d = tempFun `${function (x) { return x; }} ${function (x) { return x; }} ${10}`;
|
||||
var e = tempFun `${function (x) { return x; }} ${(function (x) { return x; })} ${10}`;
|
||||
var f = tempFun `${function (x) { return x; }} ${((function (x) { return x; }))} ${10}`;
|
||||
var g = tempFun `${(function (x) { return x; })} ${(((function (x) { return x; })))} ${10}`;
|
||||
var h = tempFun `${(function (x) { return x; })} ${(((function (x) { return x; })))} ${undefined}`;
|
||||
var a = tempFun `${x => { return x; }} ${10}`;
|
||||
var b = tempFun `${(x => { return x; })} ${10}`;
|
||||
var c = tempFun `${((x => { return x; }))} ${10}`;
|
||||
var d = tempFun `${x => { return x; }} ${x => { return x; }} ${10}`;
|
||||
var e = tempFun `${x => { return x; }} ${(x => { return x; })} ${10}`;
|
||||
var f = tempFun `${x => { return x; }} ${((x => { return x; }))} ${10}`;
|
||||
var g = tempFun `${(x => { return x; })} ${(((x => { return x; })))} ${10}`;
|
||||
var h = tempFun `${(x => { return x; })} ${(((x => { return x; })))} ${undefined}`;
|
||||
|
||||
@@ -26,28 +26,28 @@ function tempTag1(...rest) {
|
||||
// Otherwise, the arrow functions' parameters will be typed as 'any',
|
||||
// and it is an error to invoke an any-typed value with type arguments,
|
||||
// so this test will error.
|
||||
tempTag1 `${function (x) {
|
||||
tempTag1 `${x => {
|
||||
x(undefined);
|
||||
return x;
|
||||
}}${10}`;
|
||||
tempTag1 `${function (x) {
|
||||
tempTag1 `${x => {
|
||||
x(undefined);
|
||||
return x;
|
||||
}}${function (y) {
|
||||
}}${y => {
|
||||
y(undefined);
|
||||
return y;
|
||||
}}${10}`;
|
||||
tempTag1 `${function (x) {
|
||||
tempTag1 `${x => {
|
||||
x(undefined);
|
||||
return x;
|
||||
}}${function (y) {
|
||||
}}${(y) => {
|
||||
y(undefined);
|
||||
return y;
|
||||
}}${undefined}`;
|
||||
tempTag1 `${function (x) {
|
||||
tempTag1 `${(x) => {
|
||||
x(undefined);
|
||||
return x;
|
||||
}}${function (y) {
|
||||
}}${y => {
|
||||
y(undefined);
|
||||
return y;
|
||||
}}${undefined}`;
|
||||
|
||||
@@ -25,18 +25,18 @@ function tempTag2(...rest) {
|
||||
// Otherwise, the arrow functions' parameters will be typed as 'any',
|
||||
// and it is an error to invoke an any-typed value with type arguments,
|
||||
// so this test will error.
|
||||
tempTag2 `${function (x) {
|
||||
tempTag2 `${x => {
|
||||
x(undefined);
|
||||
return x;
|
||||
}}${0}`;
|
||||
tempTag2 `${function (x) {
|
||||
tempTag2 `${x => {
|
||||
x(undefined);
|
||||
return x;
|
||||
}}${function (y) {
|
||||
}}${y => {
|
||||
y(null);
|
||||
return y;
|
||||
}}${"hello"}`;
|
||||
tempTag2 `${function (x) {
|
||||
tempTag2 `${x => {
|
||||
x(undefined);
|
||||
return x;
|
||||
}}${undefined}${"hello"}`;
|
||||
|
||||
@@ -111,40 +111,40 @@ someGenerics1b `${3}`;
|
||||
// Generic tag with argument of function type whose parameter is of type parameter type
|
||||
function someGenerics2a(strs, n) {
|
||||
}
|
||||
someGenerics2a `${function (n) { return n; }}`;
|
||||
someGenerics2a `${(n) => { return n; }}`;
|
||||
function someGenerics2b(strs, n) {
|
||||
}
|
||||
someGenerics2b `${function (n, x) { return n; }}`;
|
||||
someGenerics2b `${(n, x) => { return n; }}`;
|
||||
// Generic tag with argument of function type whose parameter is not of type parameter type but body/return type uses type parameter
|
||||
function someGenerics3(strs, producer) {
|
||||
}
|
||||
someGenerics3 `${function () { return ''; }}`;
|
||||
someGenerics3 `${function () { return undefined; }}`;
|
||||
someGenerics3 `${function () { return 3; }}`;
|
||||
someGenerics3 `${() => { return ''; }}`;
|
||||
someGenerics3 `${() => { return undefined; }}`;
|
||||
someGenerics3 `${() => { return 3; }}`;
|
||||
// 2 parameter generic tag with argument 1 of type parameter type and argument 2 of function type whose parameter is of type parameter type
|
||||
function someGenerics4(strs, n, f) {
|
||||
}
|
||||
someGenerics4 `${4}${function () { return null; }}`;
|
||||
someGenerics4 `${''}${function () { return 3; }}`;
|
||||
someGenerics4 `${4}${() => { return null; }}`;
|
||||
someGenerics4 `${''}${() => { return 3; }}`;
|
||||
someGenerics4 `${null}${null}`;
|
||||
// 2 parameter generic tag with argument 2 of type parameter type and argument 1 of function type whose parameter is of type parameter type
|
||||
function someGenerics5(strs, n, f) {
|
||||
}
|
||||
someGenerics5 `${4} ${function () { return null; }}`;
|
||||
someGenerics5 `${''}${function () { return 3; }}`;
|
||||
someGenerics5 `${4} ${() => { return null; }}`;
|
||||
someGenerics5 `${''}${() => { return 3; }}`;
|
||||
someGenerics5 `${null}${null}`;
|
||||
// Generic tag with multiple arguments of function types that each have parameters of the same generic type
|
||||
function someGenerics6(strs, a, b, c) {
|
||||
}
|
||||
someGenerics6 `${function (n) { return n; }}${function (n) { return n; }}${function (n) { return n; }}`;
|
||||
someGenerics6 `${function (n) { return n; }}${function (n) { return n; }}${function (n) { return n; }}`;
|
||||
someGenerics6 `${function (n) { return n; }}${function (n) { return n; }}${function (n) { return n; }}`;
|
||||
someGenerics6 `${n => { return n; }}${n => { return n; }}${n => { return n; }}`;
|
||||
someGenerics6 `${n => { return n; }}${n => { return n; }}${n => { return n; }}`;
|
||||
someGenerics6 `${(n) => { return n; }}${(n) => { return n; }}${(n) => { return n; }}`;
|
||||
// Generic tag with multiple arguments of function types that each have parameters of different generic type
|
||||
function someGenerics7(strs, a, b, c) {
|
||||
}
|
||||
someGenerics7 `${function (n) { return n; }}${function (n) { return n; }}${function (n) { return n; }}`;
|
||||
someGenerics7 `${function (n) { return n; }}${function (n) { return n; }}${function (n) { return n; }}`;
|
||||
someGenerics7 `${function (n) { return n; }}${function (n) { return n; }}${function (n) { return n; }}`;
|
||||
someGenerics7 `${n => { return n; }}${n => { return n; }}${n => { return n; }}`;
|
||||
someGenerics7 `${n => { return n; }}${n => { return n; }}${n => { return n; }}`;
|
||||
someGenerics7 `${(n) => { return n; }}${(n) => { return n; }}${(n) => { return n; }}`;
|
||||
// Generic tag with argument of generic function type
|
||||
function someGenerics8(strs, n) {
|
||||
return n;
|
||||
|
||||
@@ -118,5 +118,5 @@ fn4 `${null}${true}`;
|
||||
function fn5() {
|
||||
return undefined;
|
||||
}
|
||||
fn5 `${function (n) { return n.toFixed(); }}`; // will error; 'n' should have type 'string'.
|
||||
fn5 `${function (n) { return n.substr(0); }}`;
|
||||
fn5 `${(n) => { return n.toFixed(); }}`; // will error; 'n' should have type 'string'.
|
||||
fn5 `${(n) => { return n.substr(0); }}`;
|
||||
|
||||
@@ -2,4 +2,4 @@
|
||||
var x = x => `abc${ x }def`;
|
||||
|
||||
//// [templateStringInArrowFunctionES6.js]
|
||||
var x = function (x) { return `abc${x}def`; };
|
||||
var x = x => { return `abc${x}def`; };
|
||||
|
||||
@@ -2,4 +2,4 @@
|
||||
var x = `abc${ x => x }def`;
|
||||
|
||||
//// [templateStringWithEmbeddedArrowFunctionES6.js]
|
||||
var x = `abc${function (x) { return x; }}def`;
|
||||
var x = `abc${x => { return x; }}def`;
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
// @target:es5
|
||||
var f1 = () => { }
|
||||
var f2 = (x: string, y: string) => { }
|
||||
var f3 = (x: string, y: number, ...rest) => { }
|
||||
var f4 = (x: string, y: number, z = 10) => { }
|
||||
function foo(func: () => boolean) { }
|
||||
foo(() => true);
|
||||
foo(() => { return false; });
|
||||
@@ -0,0 +1,5 @@
|
||||
// @target:ES5
|
||||
var arrow1 = a => { };
|
||||
var arrow2 = (a) => { };
|
||||
|
||||
var arrow3 = (a, b) => { };
|
||||
@@ -0,0 +1,5 @@
|
||||
// @target:ES6
|
||||
var arrow1 = a => { };
|
||||
var arrow2 = (a) => { };
|
||||
|
||||
var arrow3 = (a, b) => { };
|
||||
@@ -0,0 +1,8 @@
|
||||
// @target:es6
|
||||
var f1 = () => { }
|
||||
var f2 = (x: string, y: string) => { }
|
||||
var f3 = (x: string, y: number, ...rest) => { }
|
||||
var f4 = (x: string, y: number, z=10) => { }
|
||||
function foo(func: () => boolean) { }
|
||||
foo(() => true);
|
||||
foo(() => { return false; });
|
||||
@@ -0,0 +1,14 @@
|
||||
// @target:es5
|
||||
var f1 = () => {
|
||||
this.age = 10
|
||||
};
|
||||
|
||||
var f2 = (x: string) => {
|
||||
this.name = x
|
||||
}
|
||||
|
||||
function foo(func: () => boolean) { }
|
||||
foo(() => {
|
||||
this.age = 100;
|
||||
return true;
|
||||
});
|
||||
@@ -0,0 +1,14 @@
|
||||
// @target:es6
|
||||
var f1 = () => {
|
||||
this.age = 10
|
||||
};
|
||||
|
||||
var f2 = (x: string) => {
|
||||
this.name = x
|
||||
}
|
||||
|
||||
function foo(func: () => boolean){ }
|
||||
foo(() => {
|
||||
this.age = 100;
|
||||
return true;
|
||||
});
|
||||
@@ -0,0 +1,32 @@
|
||||
// @target: es6
|
||||
var a = () => {
|
||||
var arg = arguments[0]; // error
|
||||
}
|
||||
|
||||
var b = function () {
|
||||
var a = () => {
|
||||
var arg = arguments[0]; // error
|
||||
}
|
||||
}
|
||||
|
||||
function baz() {
|
||||
() => {
|
||||
var arg = arguments[0];
|
||||
}
|
||||
}
|
||||
|
||||
function foo(inputFunc: () => void) { }
|
||||
foo(() => {
|
||||
var arg = arguments[0]; // error
|
||||
});
|
||||
|
||||
function bar() {
|
||||
var arg = arguments[0]; // no error
|
||||
}
|
||||
|
||||
|
||||
() => {
|
||||
function foo() {
|
||||
var arg = arguments[0]; // no error
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
// @target: es6
|
||||
var a = () => {
|
||||
var arg = arguments[0]; // error
|
||||
}
|
||||
|
||||
var b = function () {
|
||||
var a = () => {
|
||||
var arg = arguments[0]; // error
|
||||
}
|
||||
}
|
||||
|
||||
function baz() {
|
||||
() => {
|
||||
var arg = arguments[0];
|
||||
}
|
||||
}
|
||||
|
||||
function foo(inputFunc: () => void) { }
|
||||
foo(() => {
|
||||
var arg = arguments[0]; // error
|
||||
});
|
||||
|
||||
function bar() {
|
||||
var arg = arguments[0]; // no error
|
||||
}
|
||||
|
||||
|
||||
() => {
|
||||
function foo() {
|
||||
var arg = arguments[0]; // no error
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
// @target:ES5
|
||||
var arrow1 = a => { };
|
||||
var arrow2 = (a) => { };
|
||||
|
||||
var arrow3 = (a, b) => { };
|
||||
@@ -0,0 +1,5 @@
|
||||
// @target:ES6
|
||||
var arrow1 = a => { };
|
||||
var arrow2 = (a) => { };
|
||||
|
||||
var arrow3 = (a, b) => { };
|
||||
Reference in New Issue
Block a user