Emit Arrow function natively in ES6

This commit is contained in:
Yui T
2015-01-06 18:18:37 -08:00
parent 436baafc72
commit b0ea40164c
12 changed files with 45 additions and 31 deletions
+15 -1
View File
@@ -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();
+1 -1
View File
@@ -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
};
}