@@ -300,6 +300,10 @@ module ts {
300
300
return ch >= CharacterCodes . _0 && ch <= CharacterCodes . _9 ;
301
301
}
302
302
303
+ function isOctalDigit ( ch : number ) : boolean {
304
+ return ch >= CharacterCodes . _0 && ch <= CharacterCodes . _7 ;
305
+ }
306
+
303
307
export function skipTrivia ( text : string , pos : number , stopAfterLineBreak ?: boolean ) : number {
304
308
while ( true ) {
305
309
var ch = text . charCodeAt ( pos ) ;
@@ -360,7 +364,9 @@ module ts {
360
364
var precedingLineBreak : boolean ;
361
365
362
366
function error ( message : DiagnosticMessage ) : void {
363
- if ( onError ) onError ( message ) ;
367
+ if ( onError ) {
368
+ onError ( message ) ;
369
+ }
364
370
}
365
371
366
372
function isIdentifierStart ( ch : number ) : boolean {
@@ -398,6 +404,14 @@ module ts {
398
404
return + ( text . substring ( start , end ) ) ;
399
405
}
400
406
407
+ function scanOctalDigits ( ) : number {
408
+ var start = pos ;
409
+ while ( isOctalDigit ( text . charCodeAt ( pos ) ) ) {
410
+ pos ++ ;
411
+ }
412
+ return + ( text . substring ( start , pos ) ) ;
413
+ }
414
+
401
415
function scanHexDigits ( count : number , exact ?: boolean ) : number {
402
416
var digits = 0 ;
403
417
var value = 0 ;
@@ -681,7 +695,7 @@ module ts {
681
695
682
696
if ( ! commentClosed ) {
683
697
pos ++ ;
684
- onError ( Diagnostics . Asterisk_Slash_expected ) ;
698
+ error ( Diagnostics . Asterisk_Slash_expected ) ;
685
699
}
686
700
687
701
if ( onComment ) {
@@ -708,6 +722,14 @@ module ts {
708
722
tokenValue = "" + value ;
709
723
return SyntaxKind . NumericLiteral ;
710
724
}
725
+ // Try to parse as an octal
726
+ if ( pos + 1 < len && isOctalDigit ( text . charCodeAt ( pos + 1 ) ) ) {
727
+ tokenValue = "" + scanOctalDigits ( ) ;
728
+ return SyntaxKind . NumericLiteral ;
729
+ }
730
+ // This fall-through is a deviation from the EcmaScript grammar. The grammar says that a leading zero
731
+ // can only be followed by an octal digit, a dot, or the end of the number literal. However, we are being
732
+ // permissive and allowing decimal digits of the form 08* and 09* (which many browsers also do).
711
733
case CharacterCodes . _1 :
712
734
case CharacterCodes . _2 :
713
735
case CharacterCodes . _3 :
0 commit comments