@@ -1155,6 +1155,15 @@ module ts {
11551155 return false ;
11561156 }
11571157
1158+ function parseOptionalToken ( t : SyntaxKind ) : Node {
1159+ if ( token === t ) {
1160+ var node = createNode ( t ) ;
1161+ nextToken ( ) ;
1162+ return finishNode ( node ) ;
1163+ }
1164+ return undefined ;
1165+ }
1166+
11581167 function canParseSemicolon ( ) {
11591168 // If there's a real semicolon, then we can always parse it out.
11601169 if ( token === SyntaxKind . SemicolonToken ) {
@@ -2202,10 +2211,7 @@ module ts {
22022211
22032212 if ( ! scanner . hasPrecedingLineBreak ( ) &&
22042213 ( token === SyntaxKind . AsteriskToken || isStartOfExpression ( ) ) ) {
2205- if ( parseOptional ( SyntaxKind . AsteriskToken ) ) {
2206- node . flags = NodeFlags . YieldStar ;
2207- }
2208-
2214+ node . asteriskToken = parseOptionalToken ( SyntaxKind . AsteriskToken ) ;
22092215 node . expression = parseAssignmentExpression ( ) ;
22102216 return finishNode ( node ) ;
22112217 }
@@ -2255,7 +2261,7 @@ module ts {
22552261 }
22562262 else {
22572263 // If not, we're probably better off bailing out and returning a bogus function expression.
2258- return makeFunctionExpression ( SyntaxKind . ArrowFunction , pos , /* name */ undefined , sig , createMissingNode ( ) ) ;
2264+ return makeFunctionExpression ( SyntaxKind . ArrowFunction , pos , /*asteriskToken:*/ undefined , /*name: */ undefined , sig , createMissingNode ( ) ) ;
22592265 }
22602266 }
22612267
@@ -2395,7 +2401,7 @@ module ts {
23952401 body = parseAssignmentExpression ( ) ;
23962402 }
23972403
2398- return makeFunctionExpression ( SyntaxKind . ArrowFunction , pos , /* name */ undefined , sig , body ) ;
2404+ return makeFunctionExpression ( SyntaxKind . ArrowFunction , pos , /*asteriskToken:*/ undefined , /*name: */ undefined , sig , body ) ;
23992405 }
24002406
24012407 function parseConditionalExpression ( ) : Expression {
@@ -2731,26 +2737,23 @@ module ts {
27312737
27322738 function parsePropertyAssignment ( ) : Declaration {
27332739 var nodePos = scanner . getStartPos ( ) ;
2734- var isGenerator = parseOptional ( SyntaxKind . AsteriskToken ) ;
2740+ var asteriskToken = parseOptionalToken ( SyntaxKind . AsteriskToken ) ;
27352741 var tokenIsIdentifier = isIdentifier ( ) ;
27362742 var nameToken = token ;
27372743 var propertyName = parsePropertyName ( ) ;
27382744 var node : Declaration ;
2739- if ( isGenerator || token === SyntaxKind . OpenParenToken || token === SyntaxKind . LessThanToken ) {
2745+ if ( asteriskToken || token === SyntaxKind . OpenParenToken || token === SyntaxKind . LessThanToken ) {
27402746 node = < PropertyDeclaration > createNode ( SyntaxKind . PropertyAssignment , nodePos ) ;
27412747 node . name = propertyName ;
2742- if ( isGenerator ) {
2743- node . flags |= NodeFlags . Generator ;
2744- }
2745- var sig = parseSignature ( SyntaxKind . CallSignature , SyntaxKind . ColonToken , /* returnTokenRequired */ false , /*yieldAndGeneratorParameterContext:*/ isGenerator ) ;
2748+ var sig = parseSignature ( SyntaxKind . CallSignature , SyntaxKind . ColonToken , /* returnTokenRequired */ false , /*yieldAndGeneratorParameterContext:*/ ! ! asteriskToken ) ;
27462749
2747- var body = parseFunctionBlock ( isGenerator , /* ignoreMissingOpenBrace */ false ) ;
2750+ var body = parseFunctionBlock ( ! ! asteriskToken , /* ignoreMissingOpenBrace */ false ) ;
27482751 // do not propagate property name as name for function expression
27492752 // for scenarios like
27502753 // var x = 1;
27512754 // var y = { x() { } }
27522755 // otherwise this will bring y.x into the scope of x which is incorrect
2753- ( < PropertyDeclaration > node ) . initializer = makeFunctionExpression ( SyntaxKind . FunctionExpression , node . pos , undefined , sig , body ) ;
2756+ ( < PropertyDeclaration > node ) . initializer = makeFunctionExpression ( SyntaxKind . FunctionExpression , node . pos , asteriskToken , undefined , sig , body ) ;
27542757 return finishNode ( node ) ;
27552758 }
27562759
@@ -2808,24 +2811,21 @@ module ts {
28082811
28092812 var pos = getNodePos ( ) ;
28102813 parseExpected ( SyntaxKind . FunctionKeyword ) ;
2811- var isGenerator = parseOptional ( SyntaxKind . AsteriskToken ) ;
2812- var name = isGenerator ? doInYieldContext ( parseOptionalIdentifier ) : parseOptionalIdentifier ( ) ;
2813- var sig = parseSignature ( SyntaxKind . CallSignature , SyntaxKind . ColonToken , /* returnTokenRequired */ false , /*yieldAndGeneratorParameterContext:*/ isGenerator ) ;
2814+ var asteriskToken = parseOptionalToken ( SyntaxKind . AsteriskToken ) ;
2815+ var name = asteriskToken ? doInYieldContext ( parseOptionalIdentifier ) : parseOptionalIdentifier ( ) ;
2816+ var sig = parseSignature ( SyntaxKind . CallSignature , SyntaxKind . ColonToken , /* returnTokenRequired */ false , /*yieldAndGeneratorParameterContext:*/ ! ! asteriskToken ) ;
28142817
2815- var body = parseFunctionBlock ( /*allowYield:*/ isGenerator , /* ignoreMissingOpenBrace */ false ) ;
2816- return makeFunctionExpression ( SyntaxKind . FunctionExpression , pos , name , sig , body , isGenerator ? NodeFlags . Generator : undefined ) ;
2818+ var body = parseFunctionBlock ( /*allowYield:*/ ! ! asteriskToken , /* ignoreMissingOpenBrace */ false ) ;
2819+ return makeFunctionExpression ( SyntaxKind . FunctionExpression , pos , asteriskToken , name , sig , body ) ;
28172820 }
28182821
28192822 function parseOptionalIdentifier ( ) {
28202823 return isIdentifier ( ) ? parseIdentifier ( ) : undefined ;
28212824 }
28222825
2823- function makeFunctionExpression ( kind : SyntaxKind , pos : number , name : Identifier , sig : ParsedSignature , body : Node , flags ?: NodeFlags ) : FunctionExpression {
2826+ function makeFunctionExpression ( kind : SyntaxKind , pos : number , asteriskToken : Node , name : Identifier , sig : ParsedSignature , body : Node ) : FunctionExpression {
28242827 var node = < FunctionExpression > createNode ( kind , pos ) ;
2825- if ( flags ) {
2826- node . flags = flags ;
2827- }
2828-
2828+ node . asteriskToken = asteriskToken ;
28292829 node . name = name ;
28302830 node . typeParameters = sig . typeParameters ;
28312831 node . parameters = sig . parameters ;
@@ -3292,14 +3292,10 @@ module ts {
32923292 var node = < FunctionLikeDeclaration > createNode ( SyntaxKind . FunctionDeclaration , fullStart ) ;
32933293 setModifiers ( node , modifiers ) ;
32943294 parseExpected ( SyntaxKind . FunctionKeyword ) ;
3295- var isGenerator = parseOptional ( SyntaxKind . AsteriskToken ) ;
3296- if ( isGenerator ) {
3297- node . flags |= NodeFlags . Generator ;
3298- }
3299-
3295+ node . asteriskToken = parseOptionalToken ( SyntaxKind . AsteriskToken ) ;
33003296 node . name = parseIdentifier ( ) ;
3301- fillSignature ( SyntaxKind . CallSignature , SyntaxKind . ColonToken , /* returnTokenRequired */ false , /*yieldAndGeneratorParameterContext:*/ isGenerator , node ) ;
3302- node . body = parseFunctionBlockOrSemicolon ( isGenerator ) ;
3297+ fillSignature ( SyntaxKind . CallSignature , SyntaxKind . ColonToken , /* returnTokenRequired */ false , /*yieldAndGeneratorParameterContext:*/ ! ! node . asteriskToken , node ) ;
3298+ node . body = parseFunctionBlockOrSemicolon ( ! ! node . asteriskToken ) ;
33033299 return finishNode ( node ) ;
33043300 }
33053301
@@ -3314,27 +3310,24 @@ module ts {
33143310
33153311 function parsePropertyMemberDeclaration ( fullStart : number , modifiers : ModifiersArray ) : Declaration {
33163312 var flags = modifiers ? modifiers . flags : 0 ;
3317- var isGenerator = parseOptional ( SyntaxKind . AsteriskToken ) ;
3318- if ( isGenerator ) {
3319- flags |= NodeFlags . Generator ;
3320- }
3321-
3313+ var asteriskToken = parseOptionalToken ( SyntaxKind . AsteriskToken ) ;
33223314 var name = parsePropertyName ( ) ;
33233315 if ( parseOptional ( SyntaxKind . QuestionToken ) ) {
33243316 // Note: this is not legal as per the grammar. But we allow it in the parser and
33253317 // report an error in the grammar checker.
33263318 flags |= NodeFlags . QuestionMark ;
33273319 }
33283320
3329- if ( isGenerator || token === SyntaxKind . OpenParenToken || token === SyntaxKind . LessThanToken ) {
3321+ if ( asteriskToken || token === SyntaxKind . OpenParenToken || token === SyntaxKind . LessThanToken ) {
33303322 var method = < MethodDeclaration > createNode ( SyntaxKind . Method , fullStart ) ;
33313323 setModifiers ( method , modifiers ) ;
33323324 if ( flags ) {
33333325 method . flags = flags ;
33343326 }
3327+ method . asteriskToken = asteriskToken ;
33353328 method . name = name ;
3336- fillSignature ( SyntaxKind . CallSignature , SyntaxKind . ColonToken , /* returnTokenRequired */ false , /*yieldAndGeneratorParameterContext:*/ isGenerator , method ) ;
3337- method . body = parseFunctionBlockOrSemicolon ( isGenerator ) ;
3329+ fillSignature ( SyntaxKind . CallSignature , SyntaxKind . ColonToken , /* returnTokenRequired */ false , /*yieldAndGeneratorParameterContext:*/ ! ! asteriskToken , method ) ;
3330+ method . body = parseFunctionBlockOrSemicolon ( ! ! asteriskToken ) ;
33383331 return finishNode ( method ) ;
33393332 }
33403333 else {
@@ -4306,9 +4299,9 @@ module ts {
43064299 checkForGenerator ( node ) ;
43074300 }
43084301
4309- function checkForGenerator ( node : Node ) {
4310- if ( node . flags & NodeFlags . Generator ) {
4311- return grammarErrorOnFirstToken ( node , Diagnostics . generators_are_not_currently_supported ) ;
4302+ function checkForGenerator ( node : FunctionLikeDeclaration ) {
4303+ if ( node . asteriskToken ) {
4304+ return grammarErrorOnNode ( node . asteriskToken , Diagnostics . generators_are_not_currently_supported ) ;
43124305 }
43134306 }
43144307
@@ -4741,8 +4734,7 @@ module ts {
47414734 }
47424735
47434736 function checkPropertyAssignment ( node : PropertyDeclaration ) {
4744- return checkForInvalidQuestionMark ( node , Diagnostics . An_object_member_cannot_be_declared_optional ) ||
4745- checkForGenerator ( node ) ;
4737+ return checkForInvalidQuestionMark ( node , Diagnostics . An_object_member_cannot_be_declared_optional ) ;
47464738 }
47474739
47484740 function checkForInvalidQuestionMark ( node : Declaration , message : DiagnosticMessage ) {
0 commit comments