mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
Emit Arrow function natively in ES6
This commit is contained in:
+15
-1
@@ -3219,7 +3219,15 @@ module ts {
|
||||
// Methods will emit the comments as part of emitting method declaration
|
||||
emitLeadingComments(node);
|
||||
}
|
||||
write("function ");
|
||||
|
||||
if (node.kind !== SyntaxKind.ArrowFunction) {
|
||||
write("function ");
|
||||
}
|
||||
else if (node.kind === SyntaxKind.ArrowFunction && compilerOptions.target < ScriptTarget.ES6) {
|
||||
// When targeting ES6, emit arrow function natively in ES6 by omitting function keyword and using fat arrow instead
|
||||
write("function ");
|
||||
}
|
||||
|
||||
if (node.kind === SyntaxKind.FunctionDeclaration || (node.kind === SyntaxKind.FunctionExpression && node.name)) {
|
||||
emit(node.name);
|
||||
}
|
||||
@@ -3258,6 +3266,12 @@ module ts {
|
||||
tempVariables = undefined;
|
||||
tempParameters = undefined;
|
||||
emitSignatureParameters(node);
|
||||
|
||||
// When targeting ES6, emit arrow function natively in ES6
|
||||
if (node.kind === SyntaxKind.ArrowFunction && compilerOptions.target >= ScriptTarget.ES6) {
|
||||
write(" => ");
|
||||
}
|
||||
|
||||
write(" {");
|
||||
scopeEmitStart(node);
|
||||
increaseIndent();
|
||||
|
||||
@@ -165,7 +165,7 @@ class ProjectRunner extends RunnerBase {
|
||||
sourceRoot: testCase.resolveSourceRoot && testCase.sourceRoot ? ts.sys.resolvePath(testCase.sourceRoot) : testCase.sourceRoot,
|
||||
module: moduleKind,
|
||||
noResolve: testCase.noResolve,
|
||||
target: ts.ScriptTarget.ES6
|
||||
target: ts.ScriptTarget.Latest
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user