From 6ad7e19a27a21e9c42ee7491e050dd3a8dd201d0 Mon Sep 17 00:00:00 2001 From: Siddhant N Trivedi Date: Thu, 16 Jan 2020 04:00:28 +0530 Subject: [PATCH] Fix parentheses removal in nullish-coalescing operation (#11014) * Added precedence for nullish-coalescing-operator * Made precedence equal to logical OR * Renamed the folders made for testing * Fixed the output test file of nullish-coalescing op --- packages/babel-generator/src/node/parentheses.js | 1 + .../test/fixtures/parentheses/nullish-coalescing/input.js | 2 ++ .../test/fixtures/parentheses/nullish-coalescing/output.js | 2 ++ 3 files changed, 5 insertions(+) create mode 100644 packages/babel-generator/test/fixtures/parentheses/nullish-coalescing/input.js create mode 100644 packages/babel-generator/test/fixtures/parentheses/nullish-coalescing/output.js diff --git a/packages/babel-generator/src/node/parentheses.js b/packages/babel-generator/src/node/parentheses.js index 0a1ab115c5..1222f2d34a 100644 --- a/packages/babel-generator/src/node/parentheses.js +++ b/packages/babel-generator/src/node/parentheses.js @@ -2,6 +2,7 @@ import * as t from "@babel/types"; const PRECEDENCE = { "||": 0, + "??": 0, "&&": 1, "|": 2, "^": 3, diff --git a/packages/babel-generator/test/fixtures/parentheses/nullish-coalescing/input.js b/packages/babel-generator/test/fixtures/parentheses/nullish-coalescing/input.js new file mode 100644 index 0000000000..2e5054151a --- /dev/null +++ b/packages/babel-generator/test/fixtures/parentheses/nullish-coalescing/input.js @@ -0,0 +1,2 @@ +const foo = 'test' +console.log((foo ?? '') == '') \ No newline at end of file diff --git a/packages/babel-generator/test/fixtures/parentheses/nullish-coalescing/output.js b/packages/babel-generator/test/fixtures/parentheses/nullish-coalescing/output.js new file mode 100644 index 0000000000..767c8f1b02 --- /dev/null +++ b/packages/babel-generator/test/fixtures/parentheses/nullish-coalescing/output.js @@ -0,0 +1,2 @@ +const foo = 'test'; +console.log((foo ?? '') == ''); \ No newline at end of file