Add new-style octal literals and make the B and the O case insensitive.

This commit is contained in:
Fábio Santos
2015-08-17 11:50:56 +01:00
parent 6f864402d3
commit a8f8aa518b
2 changed files with 19 additions and 1 deletions

View File

@@ -59,7 +59,8 @@ var OPERATOR_CHARS = makePredicate(characters("+-*&%=<>!?|~^"));
var RE_HEX_NUMBER = /^0x[0-9a-f]+$/i;
var RE_OCT_NUMBER = /^0[0-7]+$/;
var RE_BIN_NUMBER = /^0b[01]+$/;
var RE_ES6_OCT_NUMBER = /^0o[0-7]+$/i;
var RE_BIN_NUMBER = /^0b[01]+$/i;
var RE_DEC_NUMBER = /^\d*\.?\d*(?:e[+-]?\d*(?:\d\.?|\.?\d)\d*)?$/i;
var OPERATORS = makePredicate([
@@ -183,6 +184,8 @@ function parse_js_number(num) {
return parseInt(num.substr(2), 16);
} else if (RE_OCT_NUMBER.test(num)) {
return parseInt(num.substr(1), 8);
} else if (RE_ES6_OCT_NUMBER.test(num)) {
return parseInt(num.substr(2), 8);
} else if (RE_BIN_NUMBER.test(num)) {
return parseInt(num.substr(2), 2);
} else if (RE_DEC_NUMBER.test(num)) {

View File

@@ -97,3 +97,18 @@ destructuring_arguments: {
}
}
binary_literals: {
input: {
0b1001;
0B1001;
0o11;
0O11;
}
expect: {
9;
9;
9;
9;
}
}