Skip to content

Commit

Permalink
Add exponential operator
Browse files Browse the repository at this point in the history
Fixes #825
  • Loading branch information
bitwiseman committed Jan 22, 2016
1 parent d7f4e36 commit 322502c
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 2 deletions.
2 changes: 1 addition & 1 deletion js/lib/beautify.js
Original file line number Diff line number Diff line change
Expand Up @@ -1567,7 +1567,7 @@
var digit_oct = /[01234567]/;
var digit_hex = /[0123456789abcdefABCDEF]/;

var punct = ('+ - * / % & ++ -- = += -= *= /= %= == === != !== > < >= <= >> << >>> >>>= >>= <<= && &= | || ! ~ , : ? ^ ^= |= :: =>').split(' ');
var punct = ('+ - * / % & ++ -- = += -= *= /= %= == === != !== > < >= <= >> << >>> >>>= >>= <<= && &= | || ! ~ , : ? ^ ^= |= :: => **').split(' ');
// words which should always start on new line.
this.line_starters = 'continue,try,throw,return,var,let,const,if,switch,case,default,for,while,break,function,import,export'.split(',');
var reserved_words = this.line_starters.concat(['do', 'in', 'else', 'get', 'set', 'new', 'catch', 'finally', 'typeof', 'yield', 'async', 'await']);
Expand Down
6 changes: 6 additions & 0 deletions js/test/generated/beautify-javascript-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,12 @@ function run_javascript_tests(test_obj, Urlencoded, js_beautify, html_beautify,
'})');



// ES7 exponential
bt('x ** 2');
bt('x ** -2');


// End With Newline - (eof = "\n")
opts.end_with_newline = true;
test_fragment('', '\n');
Expand Down
2 changes: 1 addition & 1 deletion python/jsbeautifier/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1419,7 +1419,7 @@ class Tokenizer:
digit_bin = re.compile('[01]')
digit_oct = re.compile('[01234567]')
digit_hex = re.compile('[0123456789abcdefABCDEF]')
punct = ('+ - * / % & ++ -- = += -= *= /= %= == === != !== > < >= <= >> << >>> >>>= >>= <<= && &= | || ! ~ , : ? ^ ^= |= :: =>').split(' ')
punct = ('+ - * / % & ++ -- = += -= *= /= %= == === != !== > < >= <= >> << >>> >>>= >>= <<= && &= | || ! ~ , : ? ^ ^= |= :: => **').split(' ')

# Words which always should start on a new line
line_starters = 'continue,try,throw,return,var,let,const,if,switch,case,default,for,while,break,function,import,export'.split(',')
Expand Down
4 changes: 4 additions & 0 deletions python/jsbeautifier/tests/generated/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ def unicode_char(value):
' implementation();\n' +
'})')

# ES7 exponential
bt('x ** 2')
bt('x ** -2')

# End With Newline - (eof = "\n")
self.options.end_with_newline = true
test_fragment('', '\n')
Expand Down
7 changes: 7 additions & 0 deletions test/data/javascript/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@ exports.test_data = {
'})'
]}
]
}, {
name: "ES7 exponential",
description: "ES7 exponential",
tests: [
{ unchanged: 'x ** 2' },
{ unchanged: 'x ** -2' }
]
}, {
name: "End With Newline",
description: "",
Expand Down

0 comments on commit 322502c

Please sign in to comment.