From 626e90ed3f342c1f268bad7d2936e3841e2f67bd Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Tue, 25 Nov 2014 00:45:25 -0800 Subject: [PATCH] Mark generator functions with an appropriate nodeflag. --- src/compiler/parser.ts | 23 +++++++++++++++++++---- src/compiler/types.ts | 2 +- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 15e7692e019..8906bde9525 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -2721,6 +2721,9 @@ module ts { if (isGenerator || token === SyntaxKind.OpenParenToken || token === SyntaxKind.LessThanToken) { node = createNode(SyntaxKind.PropertyAssignment, nodePos); node.name = propertyName; + if (isGenerator) { + node.flags |= NodeFlags.Generator; + } var sig = parseSignature(SyntaxKind.CallSignature, SyntaxKind.ColonToken, /* returnTokenRequired */ false, /*isGenerator:*/ isGenerator); var body = parseFunctionBlock(isGenerator, /* ignoreMissingOpenBrace */ false); @@ -2792,15 +2795,19 @@ module ts { var sig = parseSignature(SyntaxKind.CallSignature, SyntaxKind.ColonToken, /* returnTokenRequired */ false, /*isGenerator:*/ isGenerator); var body = parseFunctionBlock(/*allowYield:*/ isGenerator, /* ignoreMissingOpenBrace */ false); - return makeFunctionExpression(SyntaxKind.FunctionExpression, pos, name, sig, body); + return makeFunctionExpression(SyntaxKind.FunctionExpression, pos, name, sig, body, isGenerator ? NodeFlags.Generator : undefined); } function parseOptionalIdentifier() { return isIdentifier() ? parseIdentifier() : undefined; } - function makeFunctionExpression(kind: SyntaxKind, pos: number, name: Identifier, sig: ParsedSignature, body: Node): FunctionExpression { + function makeFunctionExpression(kind: SyntaxKind, pos: number, name: Identifier, sig: ParsedSignature, body: Node, flags?: NodeFlags): FunctionExpression { var node = createNode(kind, pos); + if (flags) { + node.flags = flags; + } + node.name = name; node.typeParameters = sig.typeParameters; node.parameters = sig.parameters; @@ -3268,6 +3275,10 @@ module ts { setModifiers(node, modifiers); parseExpected(SyntaxKind.FunctionKeyword); var isGenerator = parseOptional(SyntaxKind.AsteriskToken); + if (isGenerator) { + node.flags |= NodeFlags.Generator; + } + node.name = parseIdentifier(); fillSignature(SyntaxKind.CallSignature, SyntaxKind.ColonToken, /* returnTokenRequired */ false, /*isGenerator:*/ isGenerator, node); node.body = parseFunctionBlockOrSemicolon(isGenerator); @@ -3284,9 +3295,13 @@ module ts { } function parsePropertyMemberDeclaration(fullStart: number, modifiers: ModifiersArray): Declaration { - var isGenerator = parseOptional(SyntaxKind.AsteriskToken); - var name = parsePropertyName(); var flags = modifiers ? modifiers.flags : 0; + var isGenerator = parseOptional(SyntaxKind.AsteriskToken); + if (isGenerator) { + flags |= NodeFlags.Generator; + } + + var name = parsePropertyName(); if (parseOptional(SyntaxKind.QuestionToken)) { // Note: this is not legal as per the grammar. But we allow it in the parser and // report an error in the grammar checker. diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 328422d9f6e..0003317a9ce 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -270,8 +270,8 @@ module ts { DeclarationFile = 0x00000400, // Node is a .d.ts file Let = 0x00000800, // Variable declaration Const = 0x00001000, // Variable declaration - OctalLiteral = 0x00002000, + Generator = 0x00004000, Modifier = Export | Ambient | Public | Private | Protected | Static, AccessibilityModifier = Public | Private | Protected,