@@ -1055,25 +1055,25 @@ module ts {
1055
1055
function parseLiteralNode ( ) : LiteralExpression {
1056
1056
var node = < LiteralExpression > createNode ( token ) ;
1057
1057
node . text = scanner . getTokenValue ( ) ;
1058
+ var tokenPos = scanner . getTokenPos ( ) ;
1058
1059
nextToken ( ) ;
1059
1060
finishNode ( node ) ;
1060
1061
1061
1062
// Octal literals are not allowed in strict mode or ES5
1062
- if ( node . kind === SyntaxKind . NumericLiteral && ( isInStrictMode || languageVersion >= ScriptTarget . ES5 ) ) {
1063
- var numberLiteralSource = getSourceTextOfNodeFromSourceText ( sourceText , node ) ;
1064
- // This regex checks if the number is written in octal
1065
- // Note that theoretically would match literals like 009, which is not octal. But because
1066
- // of how the scanner separates the tokens, we would never get a token like this. Instead,
1067
- // we would get 00 and 9 as two separate tokens.
1068
- // We also do not need to check for negatives because any prefix operator would be part of a
1069
- // parent unary expression.
1070
- if ( / 0 [ 0 - 7 ] + / . test ( numberLiteralSource ) ) {
1071
- if ( isInStrictMode ) {
1072
- grammarErrorOnNode ( node , Diagnostics . Octal_literals_are_not_allowed_in_strict_mode ) ;
1073
- }
1074
- else {
1075
- grammarErrorOnNode ( node , Diagnostics . Octal_literals_are_not_available_when_targeting_ECMAScript_5_and_higher ) ;
1076
- }
1063
+ // Note that theoretically the following condition would hold true literals like 009,
1064
+ // which is not octal.But because of how the scanner separates the tokens, we would
1065
+ // never get a token like this.Instead, we would get 00 and 9 as two separate tokens.
1066
+ // We also do not need to check for negatives because any prefix operator would be part of a
1067
+ // parent unary expression.
1068
+ if ( node . kind === SyntaxKind . NumericLiteral
1069
+ && sourceText . charCodeAt ( tokenPos ) === CharacterCodes . _0
1070
+ && isOctalDigit ( sourceText . charCodeAt ( tokenPos + 1 ) ) ) {
1071
+
1072
+ if ( isInStrictMode ) {
1073
+ grammarErrorOnNode ( node , Diagnostics . Octal_literals_are_not_allowed_in_strict_mode ) ;
1074
+ }
1075
+ else if ( languageVersion >= ScriptTarget . ES5 ) {
1076
+ grammarErrorOnNode ( node , Diagnostics . Octal_literals_are_not_available_when_targeting_ECMAScript_5_and_higher ) ;
1077
1077
}
1078
1078
}
1079
1079
0 commit comments