Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for logical AND, NULL, and OR assignments #1992

Merged
merged 6 commits into from
Mar 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions js/src/javascript/tokenizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,15 @@ var digit = /[0-9]/;
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 =
">>>= " +
"... >>= <<= === >>> !== **= " +
"... >>= <<= === >>> !== **= &&= ??= ||= " +
"=> ^= :: /= << <= == && -= >= >> != -- += ** || ?? ++ %= &= *= |= |> " +
"= ! ? > < : / ^ - + * & % ~ |";

Expand Down
6 changes: 4 additions & 2 deletions python/jsbeautifier/javascript/tokenizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,15 @@ def __init__(self):

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

punct = (
">>>= "
+ "... >>= <<= === >>> !== **= "
+ "... >>= <<= === >>> !== **= &&= ??= ||= "
+ "=> ^= :: /= << <= == && -= >= >> != -- += ** || ?? ++ %= &= *= |= |> "
+ "= ! ? > < : / ^ - + * & % ~ |"
)
Expand Down
4 changes: 4 additions & 0 deletions test/data/javascript/inputlib.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ var operator_position = {
'var res = (k && l || m) ? n ?? nn : o;',
'var res = p >> q << r >>> s;',
'var res = t === u !== v != w == x >= y <= z > aa < ab;',
'res ??= a;',
'res ||= b;',
'res &&= c;',
'ac + -ad'
],
comprehensive: [
Expand Down Expand Up @@ -41,6 +44,7 @@ var operator_position = {
'== x >=',
'y <= z > aa <',
'ab;',
'res??=a;res||=b;res&&=c;',
'ac +',
'-ad'
],
Expand Down
9 changes: 9 additions & 0 deletions test/data/javascript/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -1805,6 +1805,9 @@ exports.test_data = {
' x >=',
' y <= z > aa <',
' ab;',
'res ??= a;',
'res ||= b;',
'res &&= c;',
'ac +',
' -ad'
]
Expand Down Expand Up @@ -1878,6 +1881,9 @@ exports.test_data = {
' == x',
' >= y <= z > aa',
' < ab;',
'res ??= a;',
'res ||= b;',
'res &&= c;',
'ac',
' + -ad'
]
Expand Down Expand Up @@ -1953,6 +1959,9 @@ exports.test_data = {
' == x >=',
' y <= z > aa <',
' ab;',
'res ??= a;',
'res ||= b;',
'res &&= c;',
'ac +',
' -ad'
]
Expand Down