diff --git a/src/astring.js b/src/astring.js index 2d1e6717..ff5b62cb 100644 --- a/src/astring.js +++ b/src/astring.js @@ -830,15 +830,13 @@ export const baseGenerator = { UnaryExpression(node, state) { if (node.prefix) { state.write(node.operator) - if ( - node.operator.length > 1 || - node.argument.type === 'UnaryExpression' - ) { + if (node.operator.length > 1) { state.write(' ') } if ( EXPRESSIONS_PRECEDENCE[node.argument.type] < - EXPRESSIONS_PRECEDENCE.UnaryExpression + EXPRESSIONS_PRECEDENCE.UnaryExpression || + node.argument.prefix ) { state.write('(') this[node.argument.type](node.argument, state) diff --git a/src/tests/fixtures/syntax/precedence.js b/src/tests/fixtures/syntax/precedence.js index 2d6d7fbd..c2d9eb9d 100644 --- a/src/tests/fixtures/syntax/precedence.js +++ b/src/tests/fixtures/syntax/precedence.js @@ -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(); @@ -29,5 +29,6 @@ e = 2 ** +3; f = a + (b = 3); g = 1 && (() => {}); g = (() => {}) && 1; -g = (1, + +2); -g = (1, + +(2 + 3)); +g = (1, +(+2)); +g = (1, +(+(2 + 3))); +a = -(--i);