Skip to content

Commit

Permalink
fix: missing space for repeating unary operator (#315)
Browse files Browse the repository at this point in the history
  • Loading branch information
CompuIves authored Jan 2, 2021
1 parent 745fe39 commit 48e8a2e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/astring.js
Original file line number Diff line number Diff line change
Expand Up @@ -818,7 +818,7 @@ export const baseGenerator = {
UnaryExpression(node, state) {
if (node.prefix) {
state.write(node.operator)
if (node.operator.length > 1) {
if (node.operator.length > 1 || node.argument.type === 'UnaryExpression') {
state.write(' ')
}
if (
Expand Down
4 changes: 3 additions & 1 deletion src/tests/fixtures/syntax/precedence.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ a = !false;
b = !x instanceof Number;
c = !(x instanceof Number);
d = typeof a === 'boolean';
e = !typeof a === 'boolean';
e = ! typeof a === 'boolean';
f = !(typeof a === 'boolean');
a = (1.1).toString();
b = new A().toString();
Expand All @@ -29,3 +29,5 @@ e = 2 ** +3;
f = a + (b = 3);
g = 1 && (() => {});
g = (() => {}) && 1;
g = (1, + +2);
g = (1, + +(2 + 3));

0 comments on commit 48e8a2e

Please sign in to comment.