Skip to content

Commit f777011

Browse files
Emit generator functions and yield expressions in ES6.
1 parent f318515 commit f777011

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+228
-28
lines changed

src/compiler/emitter.ts

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1097,6 +1097,7 @@ var __param = this.__param || function(index, decorator) { return function (targ
10971097
default:
10981098
return Comparison.LessThan;
10991099
}
1100+
case SyntaxKind.YieldExpression:
11001101
case SyntaxKind.ConditionalExpression:
11011102
return Comparison.LessThan;
11021103
default:
@@ -1305,6 +1306,17 @@ var __param = this.__param || function(index, decorator) { return function (targ
13051306
emit((<SpreadElementExpression>node).expression);
13061307
}
13071308

1309+
function emitYieldExpression(node: YieldExpression) {
1310+
write(tokenToString(SyntaxKind.YieldKeyword));
1311+
if (node.asteriskToken) {
1312+
write("*");
1313+
}
1314+
if (node.expression) {
1315+
write(" ");
1316+
emit(node.expression);
1317+
}
1318+
}
1319+
13081320
function needsParenthesisForPropertyAccessOrInvocation(node: Expression) {
13091321
switch (node.kind) {
13101322
case SyntaxKind.Identifier:
@@ -1601,6 +1613,10 @@ var __param = this.__param || function(index, decorator) { return function (targ
16011613
}
16021614

16031615
function emitMethod(node: MethodDeclaration) {
1616+
if (languageVersion >= ScriptTarget.ES6 && node.asteriskToken) {
1617+
write("*");
1618+
}
1619+
16041620
emit(node.name, /*allowGeneratedIdentifiers*/ false);
16051621
if (languageVersion < ScriptTarget.ES6) {
16061622
write(": function ");
@@ -2960,7 +2976,12 @@ var __param = this.__param || function(index, decorator) { return function (targ
29602976
write("default ");
29612977
}
29622978
}
2963-
write("function ");
2979+
2980+
write("function");
2981+
if (languageVersion >= ScriptTarget.ES6 && node.asteriskToken) {
2982+
write("*");
2983+
}
2984+
write(" ");
29642985
}
29652986

29662987
if (shouldEmitFunctionName(node)) {
@@ -3344,6 +3365,9 @@ var __param = this.__param || function(index, decorator) { return function (targ
33443365
else if (member.kind === SyntaxKind.SetAccessor) {
33453366
write("set ");
33463367
}
3368+
if ((<MethodDeclaration>member).asteriskToken) {
3369+
write("*");
3370+
}
33473371
emit((<MethodDeclaration>member).name);
33483372
emitSignatureAndBody(<MethodDeclaration>member);
33493373
emitEnd(member);
@@ -4922,6 +4946,8 @@ var __param = this.__param || function(index, decorator) { return function (targ
49224946
return emitConditionalExpression(<ConditionalExpression>node);
49234947
case SyntaxKind.SpreadElementExpression:
49244948
return emitSpreadElementExpression(<SpreadElementExpression>node);
4949+
case SyntaxKind.YieldExpression:
4950+
return emitYieldExpression(<YieldExpression>node);
49254951
case SyntaxKind.OmittedExpression:
49264952
return;
49274953
case SyntaxKind.Block:

tests/baselines/reference/FunctionDeclaration9_es6.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@ function * foo() {
55

66
//// [FunctionDeclaration9_es6.js]
77
function foo() {
8-
var v = (_a = {}, _a[] = foo, _a);
8+
var v = (_a = {}, _a[yield] = foo, _a);
99
var _a;
1010
}

tests/baselines/reference/YieldExpression10_es6.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ var v = { * foo() {
77

88
//// [YieldExpression10_es6.js]
99
var v = { foo: function () {
10-
;
10+
yield (foo);
1111
}
1212
};

tests/baselines/reference/YieldExpression11_es6.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ var C = (function () {
1010
function C() {
1111
}
1212
C.prototype.foo = function () {
13-
;
13+
yield (foo);
1414
};
1515
return C;
1616
})();

tests/baselines/reference/YieldExpression12_es6.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class C {
88
//// [YieldExpression12_es6.js]
99
var C = (function () {
1010
function C() {
11-
;
11+
yield foo;
1212
}
1313
return C;
1414
})();

tests/baselines/reference/YieldExpression13_es6.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
function* foo() { yield }
33

44
//// [YieldExpression13_es6.js]
5-
function foo() { ; }
5+
function foo() { yield; }

tests/baselines/reference/YieldExpression14_es6.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ var C = (function () {
1010
function C() {
1111
}
1212
C.prototype.foo = function () {
13-
;
13+
yield foo;
1414
};
1515
return C;
1616
})();

tests/baselines/reference/YieldExpression15_es6.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ var v = () => {
55

66
//// [YieldExpression15_es6.js]
77
var v = function () {
8-
;
8+
yield foo;
99
};

tests/baselines/reference/YieldExpression16_es6.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ function* foo() {
88
//// [YieldExpression16_es6.js]
99
function foo() {
1010
function bar() {
11-
;
11+
yield foo;
1212
}
1313
}

tests/baselines/reference/YieldExpression17_es6.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
var v = { get foo() { yield foo; } }
33

44
//// [YieldExpression17_es6.js]
5-
var v = { get foo() { ; } };
5+
var v = { get foo() { yield foo; } };

0 commit comments

Comments
 (0)