mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-05 16:38:05 -06:00
Add check and testcases for invalid binary digits and octal digits
This commit is contained in:
parent
123b2ebda7
commit
db51fbd65c
@ -757,6 +757,9 @@ module ts {
|
||||
Debug.assert(base !== 2 || base !== 8, "Expected either base 2 or base 8");
|
||||
|
||||
var value = 0;
|
||||
// For counting number of digits; Valid binaryIntegerLiteral must have at least one binary digit following B or b.
|
||||
// Similarly valid octalIntegerLiteral must have at least one octal digit following o or O.
|
||||
var numberOfDigits = 0;
|
||||
while (true) {
|
||||
var ch = text.charCodeAt(pos);
|
||||
var valueOfCh = ch - CharacterCodes._0;
|
||||
@ -765,6 +768,11 @@ module ts {
|
||||
}
|
||||
value = value * base + valueOfCh;
|
||||
pos++;
|
||||
numberOfDigits++;
|
||||
}
|
||||
// Invalid binaryIntegerLiteral or octalIntegerLiteral
|
||||
if (numberOfDigits === 0) {
|
||||
return -1;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
@ -0,0 +1,5 @@
|
||||
// Error
|
||||
var binary = 0b21010;
|
||||
var binary1 = 0B21010;
|
||||
var octal = 0o81010;
|
||||
var octal = 0O91010;
|
||||
Loading…
x
Reference in New Issue
Block a user