I am experimenting with Babel to understand better how it works. I created a simple API with Node.js and TypeScript. Everything works fine when I transpile code and the server runs properly. I have a question though: in node v14.15.3 optional chaining is supported, so why when I build with:
rm -rf build/ && babel src --source-maps --extensions '.js,.ts,.tsx' --ignore '**/*.test.ts' -d build
no matter what version of node I'm running in the shell (by using nvm - v12.18.3 or v14.15.3) the following line
console.log(x?.ciao ?? 10)
it's always transpiled to
console.log((_x$ciao = x === null || x === void 0 ? void 0 : x.ciao) !== null && _x$ciao !== void 0 ? _x$ciao : 10);
I would expect it to use .? and ?? in the transpiled code since they're supported. What am I missing?
I also tried to remove the @babel/preset-typescript preset and did a test with a single file, but yet the code is transpiled as above.
My .babelrc file:
{
"presets": ["@babel/preset-typescript", ["@babel/preset-env", { "shippedProposals": true }]],
"plugins": [
[
"module-resolver",
{
"root": "./src",
"alias": {
"@root": ["./"],
"@src": ["./src"]
},
"extensions": [".js", ".ts"]
}
]
],
"sourceMaps": true
}