Merge pull request #1303 from thejoshwolfe/bigint

Add support for BigInt literals in JavaScript
This commit is contained in:
Liam Newman 2018-05-11 16:29:34 -07:00 committed by GitHub
commit 6ed2116c4c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 349 additions and 280 deletions

View File

@ -2371,6 +2371,7 @@ function Tokenizer(input_string, opts) {
if (digit.test(c) || (c === '.' && input.testChar(digit))) {
var allow_decimal = true;
var allow_e = true;
var allow_bigint = true;
var local_digit = digit;
if (c === '0' && input.testChar(/[XxOoBb]/)) {
@ -2388,6 +2389,7 @@ function Tokenizer(input_string, opts) {
} else if (c === '.') {
// Already have a decimal for this literal, don't allow another
allow_decimal = false;
allow_bigint = false;
} else {
// we know this first loop will run. It keeps the logic simpler.
c = '';
@ -2401,6 +2403,7 @@ function Tokenizer(input_string, opts) {
if (allow_decimal && input.peek() === '.') {
c += input.next();
allow_decimal = false;
allow_bigint = false;
}
// a = 1.e-7 is valid, so we test for . then e in one loop
@ -2413,9 +2416,14 @@ function Tokenizer(input_string, opts) {
allow_e = false;
allow_decimal = false;
allow_bigint = false;
}
}
if (allow_bigint && input.peek() === 'n') {
c += input.next();
}
return [c, 'TK_WORD'];
}

View File

@ -188,6 +188,7 @@ function Tokenizer(input_string, opts) {
if (digit.test(c) || (c === '.' && input.testChar(digit))) {
var allow_decimal = true;
var allow_e = true;
var allow_bigint = true;
var local_digit = digit;
if (c === '0' && input.testChar(/[XxOoBb]/)) {
@ -205,6 +206,7 @@ function Tokenizer(input_string, opts) {
} else if (c === '.') {
// Already have a decimal for this literal, don't allow another
allow_decimal = false;
allow_bigint = false;
} else {
// we know this first loop will run. It keeps the logic simpler.
c = '';
@ -218,6 +220,7 @@ function Tokenizer(input_string, opts) {
if (allow_decimal && input.peek() === '.') {
c += input.next();
allow_decimal = false;
allow_bigint = false;
}
// a = 1.e-7 is valid, so we test for . then e in one loop
@ -230,9 +233,14 @@ function Tokenizer(input_string, opts) {
allow_e = false;
allow_decimal = false;
allow_bigint = false;
}
}
if (allow_bigint && input.peek() === 'n') {
c += input.next();
}
return [c, 'TK_WORD'];
}

View File

@ -3484,6 +3484,112 @@ function run_javascript_tests(test_obj, Urlencoded, js_beautify, html_beautify,
bt('a >>= 2;');
//============================================================
//
reset_options();
// exponent literals
bt('a = 1e10');
bt('a = 1.3e10');
bt('a = 1.3e-10');
bt('a = -12345.3e-10');
bt('a = .12345e-10');
bt('a = 06789e-10');
bt('a = e - 10');
bt('a = 1.3e+10');
bt('a = 1.e-7');
bt('a = -12345.3e+10');
bt('a = .12345e+10');
bt('a = 06789e+10');
bt('a = e + 10');
bt('a=0e-12345.3e-10', 'a = 0e-12345 .3e-10');
bt('a=0.e-12345.3e-10', 'a = 0.e-12345 .3e-10');
bt('a=0x.e-12345.3e-10', 'a = 0x.e - 12345.3e-10');
bt('a=0x0.e-12345.3e-10', 'a = 0x0.e - 12345.3e-10');
bt('a=0x0.0e-12345.3e-10', 'a = 0x0 .0e-12345 .3e-10');
bt('a=0g-12345.3e-10', 'a = 0 g - 12345.3e-10');
bt('a=0.g-12345.3e-10', 'a = 0. g - 12345.3e-10');
bt('a=0x.g-12345.3e-10', 'a = 0x.g - 12345.3e-10');
bt('a=0x0.g-12345.3e-10', 'a = 0x0.g - 12345.3e-10');
bt('a=0x0.0g-12345.3e-10', 'a = 0x0 .0 g - 12345.3e-10');
// Decimal literals
bt('a = 0123456789;');
bt('a = 9876543210;');
bt('a = 5647308291;');
bt('a=030e-5', 'a = 030e-5');
bt('a=00+4', 'a = 00 + 4');
bt('a=32+4', 'a = 32 + 4');
bt('a=0.6g+4', 'a = 0.6 g + 4');
bt('a=01.10', 'a = 01.10');
bt('a=a.10', 'a = a .10');
bt('a=00B0x0', 'a = 00 B0x0');
bt('a=00B0xb0', 'a = 00 B0xb0');
bt('a=00B0x0b0', 'a = 00 B0x0b0');
bt('a=0090x0', 'a = 0090 x0');
bt('a=0g0b0o0', 'a = 0 g0b0o0');
// Hexadecimal literals
bt('a = 0x0123456789abcdef;');
bt('a = 0X0123456789ABCDEF;');
bt('a = 0xFeDcBa9876543210;');
bt('a=0x30e-5', 'a = 0x30e - 5');
bt('a=0xF0+4', 'a = 0xF0 + 4');
bt('a=0Xff+4', 'a = 0Xff + 4');
bt('a=0Xffg+4', 'a = 0Xff g + 4');
bt('a=0x01.10', 'a = 0x01 .10');
bt('a = 0xb0ce;');
bt('a = 0x0b0;');
bt('a=0x0B0x0', 'a = 0x0B0 x0');
bt('a=0x0B0xb0', 'a = 0x0B0 xb0');
bt('a=0x0B0x0b0', 'a = 0x0B0 x0b0');
bt('a=0X090x0', 'a = 0X090 x0');
bt('a=0Xg0b0o0', 'a = 0X g0b0o0');
// Octal literals
bt('a = 0o01234567;');
bt('a = 0O01234567;');
bt('a = 0o34120675;');
bt('a=0o30e-5', 'a = 0o30 e - 5');
bt('a=0o70+4', 'a = 0o70 + 4');
bt('a=0O77+4', 'a = 0O77 + 4');
bt('a=0O778+4', 'a = 0O77 8 + 4');
bt('a=0O77a+4', 'a = 0O77 a + 4');
bt('a=0o01.10', 'a = 0o01 .10');
bt('a=0o0B0x0', 'a = 0o0 B0x0');
bt('a=0o0B0xb0', 'a = 0o0 B0xb0');
bt('a=0o0B0x0b0', 'a = 0o0 B0x0b0');
bt('a=0O090x0', 'a = 0O0 90 x0');
bt('a=0Og0b0o0', 'a = 0O g0b0o0');
// Binary literals
bt('a = 0b010011;');
bt('a = 0B010011;');
bt('a = 0b01001100001111;');
bt('a=0b10e-5', 'a = 0b10 e - 5');
bt('a=0b10+4', 'a = 0b10 + 4');
bt('a=0B11+4', 'a = 0B11 + 4');
bt('a=0B112+4', 'a = 0B11 2 + 4');
bt('a=0B11a+4', 'a = 0B11 a + 4');
bt('a=0b01.10', 'a = 0b01 .10');
bt('a=0b0B0x0', 'a = 0b0 B0x0');
bt('a=0b0B0xb0', 'a = 0b0 B0xb0');
bt('a=0b0B0x0b0', 'a = 0b0 B0x0b0');
bt('a=0B090x0', 'a = 0B0 90 x0');
bt('a=0Bg0b0o0', 'a = 0B g0b0o0');
// BigInt literals
bt('a = 1n;');
bt('a = 1234567890123456789n;');
bt('a = -1234567890123456789n;');
bt('a = 1234567890123456789 N;');
bt('a=0b10e-5n', 'a = 0b10 e - 5n');
bt('a=.0n', 'a = .0 n');
bt('a=1.0n', 'a = 1.0 n');
bt('a=1e0n', 'a = 1e0 n');
bt('a=0n11a+4', 'a = 0n 11 a + 4');
//============================================================
// brace_style ,preserve-inline tests - (obo = " ", obot = "", oao = "\n", oaot = " ", obc = "\n", oac = " ", oact = "")
reset_options();
@ -3939,96 +4045,6 @@ function run_javascript_tests(test_obj, Urlencoded, js_beautify, html_beautify,
bt('a <= .5');
bt('a<.5', 'a < .5');
bt('a<=.5', 'a <= .5');
// exponent literals
bt('a = 1e10');
bt('a = 1.3e10');
bt('a = 1.3e-10');
bt('a = -12345.3e-10');
bt('a = .12345e-10');
bt('a = 06789e-10');
bt('a = e - 10');
bt('a = 1.3e+10');
bt('a = 1.e-7');
bt('a = -12345.3e+10');
bt('a = .12345e+10');
bt('a = 06789e+10');
bt('a = e + 10');
bt('a=0e-12345.3e-10', 'a = 0e-12345 .3e-10');
bt('a=0.e-12345.3e-10', 'a = 0.e-12345 .3e-10');
bt('a=0x.e-12345.3e-10', 'a = 0x.e - 12345.3e-10');
bt('a=0x0.e-12345.3e-10', 'a = 0x0.e - 12345.3e-10');
bt('a=0x0.0e-12345.3e-10', 'a = 0x0 .0e-12345 .3e-10');
bt('a=0g-12345.3e-10', 'a = 0 g - 12345.3e-10');
bt('a=0.g-12345.3e-10', 'a = 0. g - 12345.3e-10');
bt('a=0x.g-12345.3e-10', 'a = 0x.g - 12345.3e-10');
bt('a=0x0.g-12345.3e-10', 'a = 0x0.g - 12345.3e-10');
bt('a=0x0.0g-12345.3e-10', 'a = 0x0 .0 g - 12345.3e-10');
// Decimal literals
bt('a = 0123456789;');
bt('a = 9876543210;');
bt('a = 5647308291;');
bt('a=030e-5', 'a = 030e-5');
bt('a=00+4', 'a = 00 + 4');
bt('a=32+4', 'a = 32 + 4');
bt('a=0.6g+4', 'a = 0.6 g + 4');
bt('a=01.10', 'a = 01.10');
bt('a=a.10', 'a = a .10');
bt('a=00B0x0', 'a = 00 B0x0');
bt('a=00B0xb0', 'a = 00 B0xb0');
bt('a=00B0x0b0', 'a = 00 B0x0b0');
bt('a=0090x0', 'a = 0090 x0');
bt('a=0g0b0o0', 'a = 0 g0b0o0');
// Hexadecimal literals
bt('a = 0x0123456789abcdef;');
bt('a = 0X0123456789ABCDEF;');
bt('a = 0xFeDcBa9876543210;');
bt('a=0x30e-5', 'a = 0x30e - 5');
bt('a=0xF0+4', 'a = 0xF0 + 4');
bt('a=0Xff+4', 'a = 0Xff + 4');
bt('a=0Xffg+4', 'a = 0Xff g + 4');
bt('a=0x01.10', 'a = 0x01 .10');
bt('a = 0xb0ce;');
bt('a = 0x0b0;');
bt('a=0x0B0x0', 'a = 0x0B0 x0');
bt('a=0x0B0xb0', 'a = 0x0B0 xb0');
bt('a=0x0B0x0b0', 'a = 0x0B0 x0b0');
bt('a=0X090x0', 'a = 0X090 x0');
bt('a=0Xg0b0o0', 'a = 0X g0b0o0');
// Octal literals
bt('a = 0o01234567;');
bt('a = 0O01234567;');
bt('a = 0o34120675;');
bt('a=0o30e-5', 'a = 0o30 e - 5');
bt('a=0o70+4', 'a = 0o70 + 4');
bt('a=0O77+4', 'a = 0O77 + 4');
bt('a=0O778+4', 'a = 0O77 8 + 4');
bt('a=0O77a+4', 'a = 0O77 a + 4');
bt('a=0o01.10', 'a = 0o01 .10');
bt('a=0o0B0x0', 'a = 0o0 B0x0');
bt('a=0o0B0xb0', 'a = 0o0 B0xb0');
bt('a=0o0B0x0b0', 'a = 0o0 B0x0b0');
bt('a=0O090x0', 'a = 0O0 90 x0');
bt('a=0Og0b0o0', 'a = 0O g0b0o0');
// Binary literals
bt('a = 0b010011;');
bt('a = 0B010011;');
bt('a = 0b01001100001111;');
bt('a=0b10e-5', 'a = 0b10 e - 5');
bt('a=0b10+4', 'a = 0b10 + 4');
bt('a=0B11+4', 'a = 0B11 + 4');
bt('a=0B112+4', 'a = 0B11 2 + 4');
bt('a=0B11a+4', 'a = 0B11 a + 4');
bt('a=0b01.10', 'a = 0b01 .10');
bt('a=0b0B0x0', 'a = 0b0 B0x0');
bt('a=0b0B0xb0', 'a = 0b0 B0xb0');
bt('a=0b0B0x0b0', 'a = 0b0 B0x0b0');
bt('a=0B090x0', 'a = 0B0 90 x0');
bt('a=0Bg0b0o0', 'a = 0B g0b0o0');
bt('a = [1, 2, 3, 4]');
bt('F*(g/=f)*g+b', 'F * (g /= f) * g + b');
bt(

View File

@ -154,6 +154,7 @@ class Tokenizer:
if self.digit.match(c) or (c == '.' and self.input.testChar(self.digit)):
allow_decimal = True
allow_e = True
allow_bigint = True
local_digit = self.digit
if c == '0' and self.input.testChar(re.compile('[XxOoBb]')):
@ -170,6 +171,7 @@ class Tokenizer:
elif c == '.':
# Already have a decimal for this literal, don't allow another
allow_decimal = False
allow_bigint = False
else:
# we know this first loop will run. It keeps the logic simpler.
c = ''
@ -182,6 +184,7 @@ class Tokenizer:
if allow_decimal and self.input.peek() == '.':
c += self.input.next()
allow_decimal = False
allow_bigint = False
# a = 1.e-7 is valid, so we test for . then e in one loop
if allow_e and self.input.testChar(re.compile('[Ee]')):
@ -192,6 +195,10 @@ class Tokenizer:
allow_e = False
allow_decimal = False
allow_bigint = False
if allow_bigint and self.input.peek() == 'n':
c += self.input.next()
return c, 'TK_WORD'

View File

@ -3312,6 +3312,112 @@ class TestJSBeautifier(unittest.TestCase):
bt('a >>= 2;')
#============================================================
#
self.reset_options();
# exponent literals
bt('a = 1e10')
bt('a = 1.3e10')
bt('a = 1.3e-10')
bt('a = -12345.3e-10')
bt('a = .12345e-10')
bt('a = 06789e-10')
bt('a = e - 10')
bt('a = 1.3e+10')
bt('a = 1.e-7')
bt('a = -12345.3e+10')
bt('a = .12345e+10')
bt('a = 06789e+10')
bt('a = e + 10')
bt('a=0e-12345.3e-10', 'a = 0e-12345 .3e-10')
bt('a=0.e-12345.3e-10', 'a = 0.e-12345 .3e-10')
bt('a=0x.e-12345.3e-10', 'a = 0x.e - 12345.3e-10')
bt('a=0x0.e-12345.3e-10', 'a = 0x0.e - 12345.3e-10')
bt('a=0x0.0e-12345.3e-10', 'a = 0x0 .0e-12345 .3e-10')
bt('a=0g-12345.3e-10', 'a = 0 g - 12345.3e-10')
bt('a=0.g-12345.3e-10', 'a = 0. g - 12345.3e-10')
bt('a=0x.g-12345.3e-10', 'a = 0x.g - 12345.3e-10')
bt('a=0x0.g-12345.3e-10', 'a = 0x0.g - 12345.3e-10')
bt('a=0x0.0g-12345.3e-10', 'a = 0x0 .0 g - 12345.3e-10')
# Decimal literals
bt('a = 0123456789;')
bt('a = 9876543210;')
bt('a = 5647308291;')
bt('a=030e-5', 'a = 030e-5')
bt('a=00+4', 'a = 00 + 4')
bt('a=32+4', 'a = 32 + 4')
bt('a=0.6g+4', 'a = 0.6 g + 4')
bt('a=01.10', 'a = 01.10')
bt('a=a.10', 'a = a .10')
bt('a=00B0x0', 'a = 00 B0x0')
bt('a=00B0xb0', 'a = 00 B0xb0')
bt('a=00B0x0b0', 'a = 00 B0x0b0')
bt('a=0090x0', 'a = 0090 x0')
bt('a=0g0b0o0', 'a = 0 g0b0o0')
# Hexadecimal literals
bt('a = 0x0123456789abcdef;')
bt('a = 0X0123456789ABCDEF;')
bt('a = 0xFeDcBa9876543210;')
bt('a=0x30e-5', 'a = 0x30e - 5')
bt('a=0xF0+4', 'a = 0xF0 + 4')
bt('a=0Xff+4', 'a = 0Xff + 4')
bt('a=0Xffg+4', 'a = 0Xff g + 4')
bt('a=0x01.10', 'a = 0x01 .10')
bt('a = 0xb0ce;')
bt('a = 0x0b0;')
bt('a=0x0B0x0', 'a = 0x0B0 x0')
bt('a=0x0B0xb0', 'a = 0x0B0 xb0')
bt('a=0x0B0x0b0', 'a = 0x0B0 x0b0')
bt('a=0X090x0', 'a = 0X090 x0')
bt('a=0Xg0b0o0', 'a = 0X g0b0o0')
# Octal literals
bt('a = 0o01234567;')
bt('a = 0O01234567;')
bt('a = 0o34120675;')
bt('a=0o30e-5', 'a = 0o30 e - 5')
bt('a=0o70+4', 'a = 0o70 + 4')
bt('a=0O77+4', 'a = 0O77 + 4')
bt('a=0O778+4', 'a = 0O77 8 + 4')
bt('a=0O77a+4', 'a = 0O77 a + 4')
bt('a=0o01.10', 'a = 0o01 .10')
bt('a=0o0B0x0', 'a = 0o0 B0x0')
bt('a=0o0B0xb0', 'a = 0o0 B0xb0')
bt('a=0o0B0x0b0', 'a = 0o0 B0x0b0')
bt('a=0O090x0', 'a = 0O0 90 x0')
bt('a=0Og0b0o0', 'a = 0O g0b0o0')
# Binary literals
bt('a = 0b010011;')
bt('a = 0B010011;')
bt('a = 0b01001100001111;')
bt('a=0b10e-5', 'a = 0b10 e - 5')
bt('a=0b10+4', 'a = 0b10 + 4')
bt('a=0B11+4', 'a = 0B11 + 4')
bt('a=0B112+4', 'a = 0B11 2 + 4')
bt('a=0B11a+4', 'a = 0B11 a + 4')
bt('a=0b01.10', 'a = 0b01 .10')
bt('a=0b0B0x0', 'a = 0b0 B0x0')
bt('a=0b0B0xb0', 'a = 0b0 B0xb0')
bt('a=0b0B0x0b0', 'a = 0b0 B0x0b0')
bt('a=0B090x0', 'a = 0B0 90 x0')
bt('a=0Bg0b0o0', 'a = 0B g0b0o0')
# BigInt literals
bt('a = 1n;')
bt('a = 1234567890123456789n;')
bt('a = -1234567890123456789n;')
bt('a = 1234567890123456789 N;')
bt('a=0b10e-5n', 'a = 0b10 e - 5n')
bt('a=.0n', 'a = .0 n')
bt('a=1.0n', 'a = 1.0 n')
bt('a=1e0n', 'a = 1e0 n')
bt('a=0n11a+4', 'a = 0n 11 a + 4')
#============================================================
# brace_style ,preserve-inline tests - (obo = " ", obot = "", oao = "\n", oaot = " ", obc = "\n", oac = " ", oact = "")
self.reset_options();
@ -3767,96 +3873,6 @@ class TestJSBeautifier(unittest.TestCase):
bt('a <= .5')
bt('a<.5', 'a < .5')
bt('a<=.5', 'a <= .5')
# exponent literals
bt('a = 1e10')
bt('a = 1.3e10')
bt('a = 1.3e-10')
bt('a = -12345.3e-10')
bt('a = .12345e-10')
bt('a = 06789e-10')
bt('a = e - 10')
bt('a = 1.3e+10')
bt('a = 1.e-7')
bt('a = -12345.3e+10')
bt('a = .12345e+10')
bt('a = 06789e+10')
bt('a = e + 10')
bt('a=0e-12345.3e-10', 'a = 0e-12345 .3e-10')
bt('a=0.e-12345.3e-10', 'a = 0.e-12345 .3e-10')
bt('a=0x.e-12345.3e-10', 'a = 0x.e - 12345.3e-10')
bt('a=0x0.e-12345.3e-10', 'a = 0x0.e - 12345.3e-10')
bt('a=0x0.0e-12345.3e-10', 'a = 0x0 .0e-12345 .3e-10')
bt('a=0g-12345.3e-10', 'a = 0 g - 12345.3e-10')
bt('a=0.g-12345.3e-10', 'a = 0. g - 12345.3e-10')
bt('a=0x.g-12345.3e-10', 'a = 0x.g - 12345.3e-10')
bt('a=0x0.g-12345.3e-10', 'a = 0x0.g - 12345.3e-10')
bt('a=0x0.0g-12345.3e-10', 'a = 0x0 .0 g - 12345.3e-10')
# Decimal literals
bt('a = 0123456789;')
bt('a = 9876543210;')
bt('a = 5647308291;')
bt('a=030e-5', 'a = 030e-5')
bt('a=00+4', 'a = 00 + 4')
bt('a=32+4', 'a = 32 + 4')
bt('a=0.6g+4', 'a = 0.6 g + 4')
bt('a=01.10', 'a = 01.10')
bt('a=a.10', 'a = a .10')
bt('a=00B0x0', 'a = 00 B0x0')
bt('a=00B0xb0', 'a = 00 B0xb0')
bt('a=00B0x0b0', 'a = 00 B0x0b0')
bt('a=0090x0', 'a = 0090 x0')
bt('a=0g0b0o0', 'a = 0 g0b0o0')
# Hexadecimal literals
bt('a = 0x0123456789abcdef;')
bt('a = 0X0123456789ABCDEF;')
bt('a = 0xFeDcBa9876543210;')
bt('a=0x30e-5', 'a = 0x30e - 5')
bt('a=0xF0+4', 'a = 0xF0 + 4')
bt('a=0Xff+4', 'a = 0Xff + 4')
bt('a=0Xffg+4', 'a = 0Xff g + 4')
bt('a=0x01.10', 'a = 0x01 .10')
bt('a = 0xb0ce;')
bt('a = 0x0b0;')
bt('a=0x0B0x0', 'a = 0x0B0 x0')
bt('a=0x0B0xb0', 'a = 0x0B0 xb0')
bt('a=0x0B0x0b0', 'a = 0x0B0 x0b0')
bt('a=0X090x0', 'a = 0X090 x0')
bt('a=0Xg0b0o0', 'a = 0X g0b0o0')
# Octal literals
bt('a = 0o01234567;')
bt('a = 0O01234567;')
bt('a = 0o34120675;')
bt('a=0o30e-5', 'a = 0o30 e - 5')
bt('a=0o70+4', 'a = 0o70 + 4')
bt('a=0O77+4', 'a = 0O77 + 4')
bt('a=0O778+4', 'a = 0O77 8 + 4')
bt('a=0O77a+4', 'a = 0O77 a + 4')
bt('a=0o01.10', 'a = 0o01 .10')
bt('a=0o0B0x0', 'a = 0o0 B0x0')
bt('a=0o0B0xb0', 'a = 0o0 B0xb0')
bt('a=0o0B0x0b0', 'a = 0o0 B0x0b0')
bt('a=0O090x0', 'a = 0O0 90 x0')
bt('a=0Og0b0o0', 'a = 0O g0b0o0')
# Binary literals
bt('a = 0b010011;')
bt('a = 0B010011;')
bt('a = 0b01001100001111;')
bt('a=0b10e-5', 'a = 0b10 e - 5')
bt('a=0b10+4', 'a = 0b10 + 4')
bt('a=0B11+4', 'a = 0B11 + 4')
bt('a=0B112+4', 'a = 0B11 2 + 4')
bt('a=0B11a+4', 'a = 0B11 a + 4')
bt('a=0b01.10', 'a = 0b01 .10')
bt('a=0b0B0x0', 'a = 0b0 B0x0')
bt('a=0b0B0xb0', 'a = 0b0 B0xb0')
bt('a=0b0B0x0b0', 'a = 0b0 B0x0b0')
bt('a=0B090x0', 'a = 0B0 90 x0')
bt('a=0Bg0b0o0', 'a = 0B g0b0o0')
bt('a = [1, 2, 3, 4]')
bt('F*(g/=f)*g+b', 'F * (g /= f) * g + b')
bt(

View File

@ -2379,6 +2379,120 @@ exports.test_data = {
{ unchanged: 'a <<= 2;' },
{ unchanged: 'a >>= 2;' },
]
}, {
tests: [{
comment: 'exponent literals',
unchanged: 'a = 1e10'
},
{ unchanged: 'a = 1.3e10' },
{ unchanged: 'a = 1.3e-10' },
{ unchanged: 'a = -12345.3e-10' },
{ unchanged: 'a = .12345e-10' },
{ unchanged: 'a = 06789e-10' },
{ unchanged: 'a = e - 10' },
{ unchanged: 'a = 1.3e+10' },
{ unchanged: 'a = 1.e-7' },
{ unchanged: 'a = -12345.3e+10' },
{ unchanged: 'a = .12345e+10' },
{ unchanged: 'a = 06789e+10' },
{ unchanged: 'a = e + 10' },
{ input: 'a=0e-12345.3e-10', output: 'a = 0e-12345 .3e-10' },
{ input: 'a=0.e-12345.3e-10', output: 'a = 0.e-12345 .3e-10' },
{ input: 'a=0x.e-12345.3e-10', output: 'a = 0x.e - 12345.3e-10' },
{ input: 'a=0x0.e-12345.3e-10', output: 'a = 0x0.e - 12345.3e-10' },
{ input: 'a=0x0.0e-12345.3e-10', output: 'a = 0x0 .0e-12345 .3e-10' },
{ input: 'a=0g-12345.3e-10', output: 'a = 0 g - 12345.3e-10' },
{ input: 'a=0.g-12345.3e-10', output: 'a = 0. g - 12345.3e-10' },
{ input: 'a=0x.g-12345.3e-10', output: 'a = 0x.g - 12345.3e-10' },
{ input: 'a=0x0.g-12345.3e-10', output: 'a = 0x0.g - 12345.3e-10' },
{ input: 'a=0x0.0g-12345.3e-10', output: 'a = 0x0 .0 g - 12345.3e-10' },
{
comment: 'Decimal literals',
unchanged: 'a = 0123456789;'
},
{ unchanged: 'a = 9876543210;' },
{ unchanged: 'a = 5647308291;' },
{ input: 'a=030e-5', output: 'a = 030e-5' },
{ input: 'a=00+4', output: 'a = 00 + 4' },
{ input: 'a=32+4', output: 'a = 32 + 4' },
{ input: 'a=0.6g+4', output: 'a = 0.6 g + 4' },
{ input: 'a=01.10', output: 'a = 01.10' },
{ input: 'a=a.10', output: 'a = a .10' },
{ input: 'a=00B0x0', output: 'a = 00 B0x0' },
{ input: 'a=00B0xb0', output: 'a = 00 B0xb0' },
{ input: 'a=00B0x0b0', output: 'a = 00 B0x0b0' },
{ input: 'a=0090x0', output: 'a = 0090 x0' },
{ input: 'a=0g0b0o0', output: 'a = 0 g0b0o0' },
{
comment: 'Hexadecimal literals',
unchanged: 'a = 0x0123456789abcdef;'
},
{ unchanged: 'a = 0X0123456789ABCDEF;' },
{ unchanged: 'a = 0xFeDcBa9876543210;' },
{ input: 'a=0x30e-5', output: 'a = 0x30e - 5' },
{ input: 'a=0xF0+4', output: 'a = 0xF0 + 4' },
{ input: 'a=0Xff+4', output: 'a = 0Xff + 4' },
{ input: 'a=0Xffg+4', output: 'a = 0Xff g + 4' },
{ input: 'a=0x01.10', output: 'a = 0x01 .10' },
{ unchanged: 'a = 0xb0ce;' },
{ unchanged: 'a = 0x0b0;' },
{ input: 'a=0x0B0x0', output: 'a = 0x0B0 x0' },
{ input: 'a=0x0B0xb0', output: 'a = 0x0B0 xb0' },
{ input: 'a=0x0B0x0b0', output: 'a = 0x0B0 x0b0' },
{ input: 'a=0X090x0', output: 'a = 0X090 x0' },
{ input: 'a=0Xg0b0o0', output: 'a = 0X g0b0o0' },
{
comment: 'Octal literals',
unchanged: 'a = 0o01234567;'
},
{ unchanged: 'a = 0O01234567;' },
{ unchanged: 'a = 0o34120675;' },
{ input: 'a=0o30e-5', output: 'a = 0o30 e - 5' },
{ input: 'a=0o70+4', output: 'a = 0o70 + 4' },
{ input: 'a=0O77+4', output: 'a = 0O77 + 4' },
{ input: 'a=0O778+4', output: 'a = 0O77 8 + 4' },
{ input: 'a=0O77a+4', output: 'a = 0O77 a + 4' },
{ input: 'a=0o01.10', output: 'a = 0o01 .10' },
{ input: 'a=0o0B0x0', output: 'a = 0o0 B0x0' },
{ input: 'a=0o0B0xb0', output: 'a = 0o0 B0xb0' },
{ input: 'a=0o0B0x0b0', output: 'a = 0o0 B0x0b0' },
{ input: 'a=0O090x0', output: 'a = 0O0 90 x0' },
{ input: 'a=0Og0b0o0', output: 'a = 0O g0b0o0' },
{
comment: 'Binary literals',
unchanged: 'a = 0b010011;'
},
{ unchanged: 'a = 0B010011;' },
{ unchanged: 'a = 0b01001100001111;' },
{ input: 'a=0b10e-5', output: 'a = 0b10 e - 5' },
{ input: 'a=0b10+4', output: 'a = 0b10 + 4' },
{ input: 'a=0B11+4', output: 'a = 0B11 + 4' },
{ input: 'a=0B112+4', output: 'a = 0B11 2 + 4' },
{ input: 'a=0B11a+4', output: 'a = 0B11 a + 4' },
{ input: 'a=0b01.10', output: 'a = 0b01 .10' },
{ input: 'a=0b0B0x0', output: 'a = 0b0 B0x0' },
{ input: 'a=0b0B0xb0', output: 'a = 0b0 B0xb0' },
{ input: 'a=0b0B0x0b0', output: 'a = 0b0 B0x0b0' },
{ input: 'a=0B090x0', output: 'a = 0B0 90 x0' },
{ input: 'a=0Bg0b0o0', output: 'a = 0B g0b0o0' },
{
comment: 'BigInt literals',
unchanged: 'a = 1n;'
},
{ unchanged: 'a = 1234567890123456789n;' },
{ unchanged: 'a = -1234567890123456789n;' },
{ unchanged: 'a = 1234567890123456789 N;' },
{ input: 'a=0b10e-5n', output: 'a = 0b10 e - 5n' },
{ input: 'a=.0n', output: 'a = .0 n' },
{ input: 'a=1.0n', output: 'a = 1.0 n' },
{ input: 'a=1e0n', output: 'a = 1e0 n' },
{ input: 'a=0n11a+4', output: 'a = 0n 11 a + 4' },
]
}, {
//Relies on the tab being four spaces as default for the tests
name: "brace_style ,preserve-inline tests",
@ -2724,106 +2838,6 @@ exports.test_data = {
{ unchanged: 'a <= .5' },
{ input: 'a<.5', output: 'a < .5' },
{ input: 'a<=.5', output: 'a <= .5' },
{
comment: 'exponent literals',
unchanged: 'a = 1e10'
},
{ unchanged: 'a = 1.3e10' },
{ unchanged: 'a = 1.3e-10' },
{ unchanged: 'a = -12345.3e-10' },
{ unchanged: 'a = .12345e-10' },
{ unchanged: 'a = 06789e-10' },
{ unchanged: 'a = e - 10' },
{ unchanged: 'a = 1.3e+10' },
{ unchanged: 'a = 1.e-7' },
{ unchanged: 'a = -12345.3e+10' },
{ unchanged: 'a = .12345e+10' },
{ unchanged: 'a = 06789e+10' },
{ unchanged: 'a = e + 10' },
{ input: 'a=0e-12345.3e-10', output: 'a = 0e-12345 .3e-10' },
{ input: 'a=0.e-12345.3e-10', output: 'a = 0.e-12345 .3e-10' },
{ input: 'a=0x.e-12345.3e-10', output: 'a = 0x.e - 12345.3e-10' },
{ input: 'a=0x0.e-12345.3e-10', output: 'a = 0x0.e - 12345.3e-10' },
{ input: 'a=0x0.0e-12345.3e-10', output: 'a = 0x0 .0e-12345 .3e-10' },
{ input: 'a=0g-12345.3e-10', output: 'a = 0 g - 12345.3e-10' },
{ input: 'a=0.g-12345.3e-10', output: 'a = 0. g - 12345.3e-10' },
{ input: 'a=0x.g-12345.3e-10', output: 'a = 0x.g - 12345.3e-10' },
{ input: 'a=0x0.g-12345.3e-10', output: 'a = 0x0.g - 12345.3e-10' },
{ input: 'a=0x0.0g-12345.3e-10', output: 'a = 0x0 .0 g - 12345.3e-10' },
{
comment: 'Decimal literals',
unchanged: 'a = 0123456789;'
},
{ unchanged: 'a = 9876543210;' },
{ unchanged: 'a = 5647308291;' },
{ input: 'a=030e-5', output: 'a = 030e-5' },
{ input: 'a=00+4', output: 'a = 00 + 4' },
{ input: 'a=32+4', output: 'a = 32 + 4' },
{ input: 'a=0.6g+4', output: 'a = 0.6 g + 4' },
{ input: 'a=01.10', output: 'a = 01.10' },
{ input: 'a=a.10', output: 'a = a .10' },
{ input: 'a=00B0x0', output: 'a = 00 B0x0' },
{ input: 'a=00B0xb0', output: 'a = 00 B0xb0' },
{ input: 'a=00B0x0b0', output: 'a = 00 B0x0b0' },
{ input: 'a=0090x0', output: 'a = 0090 x0' },
{ input: 'a=0g0b0o0', output: 'a = 0 g0b0o0' },
{
comment: 'Hexadecimal literals',
unchanged: 'a = 0x0123456789abcdef;'
},
{ unchanged: 'a = 0X0123456789ABCDEF;' },
{ unchanged: 'a = 0xFeDcBa9876543210;' },
{ input: 'a=0x30e-5', output: 'a = 0x30e - 5' },
{ input: 'a=0xF0+4', output: 'a = 0xF0 + 4' },
{ input: 'a=0Xff+4', output: 'a = 0Xff + 4' },
{ input: 'a=0Xffg+4', output: 'a = 0Xff g + 4' },
{ input: 'a=0x01.10', output: 'a = 0x01 .10' },
{ unchanged: 'a = 0xb0ce;' },
{ unchanged: 'a = 0x0b0;' },
{ input: 'a=0x0B0x0', output: 'a = 0x0B0 x0' },
{ input: 'a=0x0B0xb0', output: 'a = 0x0B0 xb0' },
{ input: 'a=0x0B0x0b0', output: 'a = 0x0B0 x0b0' },
{ input: 'a=0X090x0', output: 'a = 0X090 x0' },
{ input: 'a=0Xg0b0o0', output: 'a = 0X g0b0o0' },
{
comment: 'Octal literals',
unchanged: 'a = 0o01234567;'
},
{ unchanged: 'a = 0O01234567;' },
{ unchanged: 'a = 0o34120675;' },
{ input: 'a=0o30e-5', output: 'a = 0o30 e - 5' },
{ input: 'a=0o70+4', output: 'a = 0o70 + 4' },
{ input: 'a=0O77+4', output: 'a = 0O77 + 4' },
{ input: 'a=0O778+4', output: 'a = 0O77 8 + 4' },
{ input: 'a=0O77a+4', output: 'a = 0O77 a + 4' },
{ input: 'a=0o01.10', output: 'a = 0o01 .10' },
{ input: 'a=0o0B0x0', output: 'a = 0o0 B0x0' },
{ input: 'a=0o0B0xb0', output: 'a = 0o0 B0xb0' },
{ input: 'a=0o0B0x0b0', output: 'a = 0o0 B0x0b0' },
{ input: 'a=0O090x0', output: 'a = 0O0 90 x0' },
{ input: 'a=0Og0b0o0', output: 'a = 0O g0b0o0' },
{
comment: 'Binary literals',
unchanged: 'a = 0b010011;'
},
{ unchanged: 'a = 0B010011;' },
{ unchanged: 'a = 0b01001100001111;' },
{ input: 'a=0b10e-5', output: 'a = 0b10 e - 5' },
{ input: 'a=0b10+4', output: 'a = 0b10 + 4' },
{ input: 'a=0B11+4', output: 'a = 0B11 + 4' },
{ input: 'a=0B112+4', output: 'a = 0B11 2 + 4' },
{ input: 'a=0B11a+4', output: 'a = 0B11 a + 4' },
{ input: 'a=0b01.10', output: 'a = 0b01 .10' },
{ input: 'a=0b0B0x0', output: 'a = 0b0 B0x0' },
{ input: 'a=0b0B0xb0', output: 'a = 0b0 B0xb0' },
{ input: 'a=0b0B0x0b0', output: 'a = 0b0 B0x0b0' },
{ input: 'a=0B090x0', output: 'a = 0B0 90 x0' },
{ input: 'a=0Bg0b0o0', output: 'a = 0B g0b0o0' },
{ unchanged: 'a = [1, 2, 3, 4]' },
{ input: 'F*(g/=f)*g+b', output: 'F * (g /= f) * g + b' },
{ input: 'a.b({c:d})', output: 'a.b({\n c: d\n})' },