diff --git a/src/astring.js b/src/astring.js index 19de39ed..a396ccfa 100644 --- a/src/astring.js +++ b/src/astring.js @@ -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 ( diff --git a/src/tests/fixtures/syntax/precedence.js b/src/tests/fixtures/syntax/precedence.js index 08312f35..2d6d7fbd 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,3 +29,5 @@ e = 2 ** +3; f = a + (b = 3); g = 1 && (() => {}); g = (() => {}) && 1; +g = (1, + +2); +g = (1, + +(2 + 3));