-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Closed
Closed
Copy link
Labels
Has PRSpec: Nullish Coalescing OperatoroutdatedA closed issue/PR that is archived due to age. Recommended to make a new issueA closed issue/PR that is archived due to age. Recommended to make a new issuepkg: generator
Description
Bug Report
Current Behavior
When transforming an AST containing a nullish coalescing operator, parentheses are removed falsely, leading to different behavior.
Input Code
const babel = require('@babel/core')
const { readFileSync, writeFileSync } = require('fs')
const code = readFileSync('src/index.js')
// src/index.js:
// const foo = 'test'
// console.log((foo ?? '') == '')
const babelConfig = {
plugins: [
'@babel/plugin-proposal-nullish-coalescing-operator',
],
}
// this works as expected
const ast = babel.parseSync(code, babelConfig)
// this removes the parentheses
const { code: transformedCode } = babel.transformFromAstSync(ast, code)
writeFileSync('dist/index.js', transformedCode)
// dist/index.js:
// const foo = 'test';
// console.log(foo ?? '' == '');
const babelRegister = require('@babel/register')
babelRegister(babelConfig)
require('./dist')
// outputs 'test' instead of falseSee also:
https://github.com/dword-design/test-babel-missing-parentheses
Expected behavior/code
The resulting file should still contain the parentheses.
Environment
- Babel version(s): 7.7.7
- Node/npm version: Node 11.15.0/npm 6.7.0
- OS: macOS 10.14.6
- Monorepo: no
- How you are using Babel: core, register
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
Has PRSpec: Nullish Coalescing OperatoroutdatedA closed issue/PR that is archived due to age. Recommended to make a new issueA closed issue/PR that is archived due to age. Recommended to make a new issuepkg: generator