@@ -1226,18 +1226,6 @@ module ts {
1226
1226
error ( Diagnostics . _0_expected , "," ) ;
1227
1227
}
1228
1228
else if ( isListTerminator ( kind ) ) {
1229
- // Check if the last token was a comma.
1230
- if ( commaStart >= 0 ) {
1231
- if ( ! allowTrailingComma ) {
1232
- if ( file . syntacticErrors . length === errorCountBeforeParsingList ) {
1233
- // Report a grammar error so we don't affect lookahead
1234
- grammarErrorAtPos ( commaStart , scanner . getStartPos ( ) - commaStart , Diagnostics . Trailing_comma_not_allowed ) ;
1235
- }
1236
- }
1237
- // Always preserve a trailing comma by marking it on the NodeArray
1238
- result . hasTrailingComma = true ;
1239
- }
1240
-
1241
1229
break ;
1242
1230
}
1243
1231
else {
@@ -1248,6 +1236,23 @@ module ts {
1248
1236
nextToken ( ) ;
1249
1237
}
1250
1238
}
1239
+
1240
+ // Recording the trailing comma is deliberately done after the previous
1241
+ // loop, and not just if we see a list terminator. This is because the list
1242
+ // may have ended incorrectly, but it is still important to know if there
1243
+ // was a trailing comma.
1244
+ // Check if the last token was a comma.
1245
+ if ( commaStart >= 0 ) {
1246
+ if ( ! allowTrailingComma ) {
1247
+ if ( file . syntacticErrors . length === errorCountBeforeParsingList ) {
1248
+ // Report a grammar error so we don't affect lookahead
1249
+ grammarErrorAtPos ( commaStart , scanner . getStartPos ( ) - commaStart , Diagnostics . Trailing_comma_not_allowed ) ;
1250
+ }
1251
+ }
1252
+ // Always preserve a trailing comma by marking it on the NodeArray
1253
+ result . hasTrailingComma = true ;
1254
+ }
1255
+
1251
1256
result . end = getNodeEnd ( ) ;
1252
1257
parsingContext = saveParsingContext ;
1253
1258
return result ;
0 commit comments