Skip to content

Commit

Permalink
Support for nullish coalescing
Browse files Browse the repository at this point in the history
  • Loading branch information
mayankshouche committed Aug 12, 2020
1 parent a4d6cb9 commit ba04879
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 4 deletions.
4 changes: 2 additions & 2 deletions js/src/javascript/tokenizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,15 @@ var dot_pattern = /[^\d\.]/;

var positionable_operators = (
">>> === !== " +
"<< && >= ** != == <= >> || |> " +
"<< && >= ** != == <= >> || ?? |> " +
"< / - + > : & % ? ^ | *").split(' ');

// IMPORTANT: this must be sorted longest to shortest or tokenizing many not work.
// Also, you must update possitionable operators separately from punct
var punct =
">>>= " +
"... >>= <<= === >>> !== **= " +
"=> ^= :: /= << <= == && -= >= >> != -- += ** || ++ %= &= *= |= |> " +
"=> ^= :: /= << <= == && -= >= >> != -- += ** || ?? ++ %= &= *= |= |> " +
"= ! ? > < : / ^ - + * & % ~ |";

punct = punct.replace(/[-[\]{}()*+?.,\\^$|#]/g, "\\$&");
Expand Down
3 changes: 3 additions & 0 deletions js/test/generated/beautify-javascript-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -7001,6 +7001,9 @@ function run_javascript_tests(test_obj, Urlencoded, js_beautify, html_beautify,
' return x;\n' +
' };');

// Issue #1794 - support nullish-coalescing
bt('a = b ?? c');

// Issue #569 - function should not have blank line in a number of cases
bt(
'(function(global) {\n' +
Expand Down
4 changes: 2 additions & 2 deletions python/jsbeautifier/javascript/tokenizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,14 @@ def __init__(self):

positionable_operators = frozenset(
(
">>> === !== " + "<< && >= ** != == <= >> || |> " + "< / - + > : & % ? ^ | *"
">>> === !== " + "<< && >= ** != == <= >> || ?? |> " + "< / - + > : & % ? ^ | *"
).split(" ")
)

punct = (
">>>= "
+ "... >>= <<= === >>> !== **= "
+ "=> ^= :: /= << <= == && -= >= >> != -- += ** || ++ %= &= *= |= |> "
+ "=> ^= :: /= << <= == && -= >= >> != -- += ** || ?? ++ %= &= *= |= |> "
+ "= ! ? > < : / ^ - + * & % ~ |"
)

Expand Down
3 changes: 3 additions & 0 deletions python/jsbeautifier/tests/generated/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -6712,6 +6712,9 @@ def unicode_char(value):
' return x;\n' +
' };')

# Issue #1794 - support nullish-coalescing
bt('a = b ?? c')

# Issue #569 - function should not have blank line in a number of cases
bt(
'(function(global) {\n' +
Expand Down
6 changes: 6 additions & 0 deletions test/data/javascript/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -3805,6 +3805,12 @@ exports.test_data = {
' };'
]
},
{
comment: 'Issue #1794 - support nullish-coalescing',
unchanged: [
'a = b ?? c'
]
},
{
comment: "Issue #569 - function should not have blank line in a number of cases",
unchanged: [
Expand Down

0 comments on commit ba04879

Please sign in to comment.