Skip to content

Commit 626e90e

Browse files
Mark generator functions with an appropriate nodeflag.
1 parent bdaccf6 commit 626e90e

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

src/compiler/parser.ts

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2721,6 +2721,9 @@ module ts {
27212721
if (isGenerator || token === SyntaxKind.OpenParenToken || token === SyntaxKind.LessThanToken) {
27222722
node = <PropertyDeclaration>createNode(SyntaxKind.PropertyAssignment, nodePos);
27232723
node.name = propertyName;
2724+
if (isGenerator) {
2725+
node.flags |= NodeFlags.Generator;
2726+
}
27242727
var sig = parseSignature(SyntaxKind.CallSignature, SyntaxKind.ColonToken, /* returnTokenRequired */ false, /*isGenerator:*/ isGenerator);
27252728

27262729
var body = parseFunctionBlock(isGenerator, /* ignoreMissingOpenBrace */ false);
@@ -2792,15 +2795,19 @@ module ts {
27922795
var sig = parseSignature(SyntaxKind.CallSignature, SyntaxKind.ColonToken, /* returnTokenRequired */ false, /*isGenerator:*/ isGenerator);
27932796

27942797
var body = parseFunctionBlock(/*allowYield:*/ isGenerator, /* ignoreMissingOpenBrace */ false);
2795-
return makeFunctionExpression(SyntaxKind.FunctionExpression, pos, name, sig, body);
2798+
return makeFunctionExpression(SyntaxKind.FunctionExpression, pos, name, sig, body, isGenerator ? NodeFlags.Generator : undefined);
27962799
}
27972800

27982801
function parseOptionalIdentifier() {
27992802
return isIdentifier() ? parseIdentifier() : undefined;
28002803
}
28012804

2802-
function makeFunctionExpression(kind: SyntaxKind, pos: number, name: Identifier, sig: ParsedSignature, body: Node): FunctionExpression {
2805+
function makeFunctionExpression(kind: SyntaxKind, pos: number, name: Identifier, sig: ParsedSignature, body: Node, flags?: NodeFlags): FunctionExpression {
28032806
var node = <FunctionExpression>createNode(kind, pos);
2807+
if (flags) {
2808+
node.flags = flags;
2809+
}
2810+
28042811
node.name = name;
28052812
node.typeParameters = sig.typeParameters;
28062813
node.parameters = sig.parameters;
@@ -3268,6 +3275,10 @@ module ts {
32683275
setModifiers(node, modifiers);
32693276
parseExpected(SyntaxKind.FunctionKeyword);
32703277
var isGenerator = parseOptional(SyntaxKind.AsteriskToken);
3278+
if (isGenerator) {
3279+
node.flags |= NodeFlags.Generator;
3280+
}
3281+
32713282
node.name = parseIdentifier();
32723283
fillSignature(SyntaxKind.CallSignature, SyntaxKind.ColonToken, /* returnTokenRequired */ false, /*isGenerator:*/ isGenerator, node);
32733284
node.body = parseFunctionBlockOrSemicolon(isGenerator);
@@ -3284,9 +3295,13 @@ module ts {
32843295
}
32853296

32863297
function parsePropertyMemberDeclaration(fullStart: number, modifiers: ModifiersArray): Declaration {
3298+
var flags = modifiers ? modifiers.flags : 0;
32873299
var isGenerator = parseOptional(SyntaxKind.AsteriskToken);
3300+
if (isGenerator) {
3301+
flags |= NodeFlags.Generator;
3302+
}
3303+
32883304
var name = parsePropertyName();
3289-
var flags = modifiers ? modifiers.flags : 0;
32903305
if (parseOptional(SyntaxKind.QuestionToken)) {
32913306
// Note: this is not legal as per the grammar. But we allow it in the parser and
32923307
// report an error in the grammar checker.

src/compiler/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,8 +270,8 @@ module ts {
270270
DeclarationFile = 0x00000400, // Node is a .d.ts file
271271
Let = 0x00000800, // Variable declaration
272272
Const = 0x00001000, // Variable declaration
273-
274273
OctalLiteral = 0x00002000,
274+
Generator = 0x00004000,
275275

276276
Modifier = Export | Ambient | Public | Private | Protected | Static,
277277
AccessibilityModifier = Public | Private | Protected,

0 commit comments

Comments
 (0)