@@ -1155,6 +1155,15 @@ module ts {
1155
1155
return false ;
1156
1156
}
1157
1157
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
+
1158
1167
function canParseSemicolon ( ) {
1159
1168
// If there's a real semicolon, then we can always parse it out.
1160
1169
if ( token === SyntaxKind . SemicolonToken ) {
@@ -2202,10 +2211,7 @@ module ts {
2202
2211
2203
2212
if ( ! scanner . hasPrecedingLineBreak ( ) &&
2204
2213
( token === SyntaxKind . AsteriskToken || isStartOfExpression ( ) ) ) {
2205
- if ( parseOptional ( SyntaxKind . AsteriskToken ) ) {
2206
- node . flags = NodeFlags . YieldStar ;
2207
- }
2208
-
2214
+ node . asteriskToken = parseOptionalToken ( SyntaxKind . AsteriskToken ) ;
2209
2215
node . expression = parseAssignmentExpression ( ) ;
2210
2216
return finishNode ( node ) ;
2211
2217
}
@@ -2255,7 +2261,7 @@ module ts {
2255
2261
}
2256
2262
else {
2257
2263
// 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 ( ) ) ;
2259
2265
}
2260
2266
}
2261
2267
@@ -2395,7 +2401,7 @@ module ts {
2395
2401
body = parseAssignmentExpression ( ) ;
2396
2402
}
2397
2403
2398
- return makeFunctionExpression ( SyntaxKind . ArrowFunction , pos , /* name */ undefined , sig , body ) ;
2404
+ return makeFunctionExpression ( SyntaxKind . ArrowFunction , pos , /*asteriskToken:*/ undefined , /*name: */ undefined , sig , body ) ;
2399
2405
}
2400
2406
2401
2407
function parseConditionalExpression ( ) : Expression {
@@ -2731,26 +2737,23 @@ module ts {
2731
2737
2732
2738
function parsePropertyAssignment ( ) : Declaration {
2733
2739
var nodePos = scanner . getStartPos ( ) ;
2734
- var isGenerator = parseOptional ( SyntaxKind . AsteriskToken ) ;
2740
+ var asteriskToken = parseOptionalToken ( SyntaxKind . AsteriskToken ) ;
2735
2741
var tokenIsIdentifier = isIdentifier ( ) ;
2736
2742
var nameToken = token ;
2737
2743
var propertyName = parsePropertyName ( ) ;
2738
2744
var node : Declaration ;
2739
- if ( isGenerator || token === SyntaxKind . OpenParenToken || token === SyntaxKind . LessThanToken ) {
2745
+ if ( asteriskToken || token === SyntaxKind . OpenParenToken || token === SyntaxKind . LessThanToken ) {
2740
2746
node = < PropertyDeclaration > createNode ( SyntaxKind . PropertyAssignment , nodePos ) ;
2741
2747
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 ) ;
2746
2749
2747
- var body = parseFunctionBlock ( isGenerator , /* ignoreMissingOpenBrace */ false ) ;
2750
+ var body = parseFunctionBlock ( ! ! asteriskToken , /* ignoreMissingOpenBrace */ false ) ;
2748
2751
// do not propagate property name as name for function expression
2749
2752
// for scenarios like
2750
2753
// var x = 1;
2751
2754
// var y = { x() { } }
2752
2755
// 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 ) ;
2754
2757
return finishNode ( node ) ;
2755
2758
}
2756
2759
@@ -2808,24 +2811,21 @@ module ts {
2808
2811
2809
2812
var pos = getNodePos ( ) ;
2810
2813
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 ) ;
2814
2817
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 ) ;
2817
2820
}
2818
2821
2819
2822
function parseOptionalIdentifier ( ) {
2820
2823
return isIdentifier ( ) ? parseIdentifier ( ) : undefined ;
2821
2824
}
2822
2825
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 {
2824
2827
var node = < FunctionExpression > createNode ( kind , pos ) ;
2825
- if ( flags ) {
2826
- node . flags = flags ;
2827
- }
2828
-
2828
+ node . asteriskToken = asteriskToken ;
2829
2829
node . name = name ;
2830
2830
node . typeParameters = sig . typeParameters ;
2831
2831
node . parameters = sig . parameters ;
@@ -3292,14 +3292,10 @@ module ts {
3292
3292
var node = < FunctionLikeDeclaration > createNode ( SyntaxKind . FunctionDeclaration , fullStart ) ;
3293
3293
setModifiers ( node , modifiers ) ;
3294
3294
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 ) ;
3300
3296
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 ) ;
3303
3299
return finishNode ( node ) ;
3304
3300
}
3305
3301
@@ -3314,27 +3310,24 @@ module ts {
3314
3310
3315
3311
function parsePropertyMemberDeclaration ( fullStart : number , modifiers : ModifiersArray ) : Declaration {
3316
3312
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 ) ;
3322
3314
var name = parsePropertyName ( ) ;
3323
3315
if ( parseOptional ( SyntaxKind . QuestionToken ) ) {
3324
3316
// Note: this is not legal as per the grammar. But we allow it in the parser and
3325
3317
// report an error in the grammar checker.
3326
3318
flags |= NodeFlags . QuestionMark ;
3327
3319
}
3328
3320
3329
- if ( isGenerator || token === SyntaxKind . OpenParenToken || token === SyntaxKind . LessThanToken ) {
3321
+ if ( asteriskToken || token === SyntaxKind . OpenParenToken || token === SyntaxKind . LessThanToken ) {
3330
3322
var method = < MethodDeclaration > createNode ( SyntaxKind . Method , fullStart ) ;
3331
3323
setModifiers ( method , modifiers ) ;
3332
3324
if ( flags ) {
3333
3325
method . flags = flags ;
3334
3326
}
3327
+ method . asteriskToken = asteriskToken ;
3335
3328
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 ) ;
3338
3331
return finishNode ( method ) ;
3339
3332
}
3340
3333
else {
@@ -4306,9 +4299,9 @@ module ts {
4306
4299
checkForGenerator ( node ) ;
4307
4300
}
4308
4301
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 ) ;
4312
4305
}
4313
4306
}
4314
4307
@@ -4741,8 +4734,7 @@ module ts {
4741
4734
}
4742
4735
4743
4736
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 ) ;
4746
4738
}
4747
4739
4748
4740
function checkForInvalidQuestionMark ( node : Declaration , message : DiagnosticMessage ) {
0 commit comments