diff --git a/packages/next/build/babel/preset.ts b/packages/next/build/babel/preset.ts index 5b3cff89ff832c6..b493622f29bce54 100644 --- a/packages/next/build/babel/preset.ts +++ b/packages/next/build/babel/preset.ts @@ -93,10 +93,6 @@ export default ( // In production/development this option is set to `false` so that webpack can handle import/export with tree-shaking modules: 'auto', exclude: ['transform-typeof-symbol'], - include: [ - '@babel/plugin-proposal-optional-chaining', - '@babel/plugin-proposal-nullish-coalescing-operator', - ], ...options['preset-env'], } diff --git a/packages/next/build/swc/options.js b/packages/next/build/swc/options.js index eeddb42fa76a24b..8bc1c3cfad4249d 100644 --- a/packages/next/build/swc/options.js +++ b/packages/next/build/swc/options.js @@ -164,13 +164,6 @@ export function getJestSWCOptions({ // Targets the current version of Node.js node: process.versions.node, }, - // we always transpile optional chaining and nullish coalescing - // since it can cause issues with webpack even if the node target - // supports them - include: [ - 'proposal-optional-chaining', - 'proposal-nullish-coalescing-operator', - ], }, module: { type: esm && !isNextDist ? 'es6' : 'commonjs', @@ -219,13 +212,6 @@ export function getLoaderSWCOptions({ // Targets the current version of Node.js node: process.versions.node, }, - // we always transpile optional chaining and nullish coalescing - // since it can cause issues with webpack even if the node target - // supports them - include: [ - 'proposal-optional-chaining', - 'proposal-nullish-coalescing-operator', - ], }, } } else { diff --git a/test/unit/next-babel-loader-prod.test.ts b/test/unit/next-babel-loader-prod.test.ts index e8d62bb7a9c6b43..101bdc7faeb8711 100644 --- a/test/unit/next-babel-loader-prod.test.ts +++ b/test/unit/next-babel-loader-prod.test.ts @@ -216,7 +216,6 @@ describe('next-babel-loader', () => { }) const pageFile = path.resolve(dir, 'pages', 'index.js') - const tsPageFile = pageFile.replace(/\.js$/, '.ts') it('should not drop unused exports by default in a page', async () => { const code = await babel( @@ -323,75 +322,5 @@ describe('next-babel-loader', () => { `var __jsx = React.createElement;import "core-js";import { bar } from "a";import baz from "b";import * as React from "react";import { yeet } from "c";import baz3, { cats } from "d";import { c, d } from "e";import { e as ee } from "f";export var __N_SSG = true;export default function () { return __jsx("div", { __self: this, __source: { fileName: _jsxFileName, lineNumber: 1, columnNumber: 326 } }, cats + bar());}` ) }) - - it('should support optional chaining for JS file', async () => { - const code = await babel( - `let hello;` + - `export default () => hello?.world ? 'something' : 'nothing' `, - { - resourcePath: pageFile, - } - ) - expect(code).toMatchInlineSnapshot( - `"let hello;export default (() => hello !== null && hello !== void 0 && hello.world ? 'something' : 'nothing');"` - ) - }) - - it('should support optional chaining for TS file', async () => { - const code = await babel( - `let hello;` + - `export default () => hello?.world ? 'something' : 'nothing' `, - { - resourcePath: tsPageFile, - } - ) - expect(code).toMatchInlineSnapshot( - `"let hello;export default (() => hello !== null && hello !== void 0 && hello.world ? 'something' : 'nothing');"` - ) - }) - - it('should support nullish coalescing for JS file', async () => { - const code = await babel( - `const res = { - status: 0, - nullVal: null, - statusText: '', - - } - const status = res.status ?? 999 - const nullVal = res.nullVal ?? 'another' - const statusText = res.nullVal ?? 'not found' - export default () => 'hello' - `, - { - resourcePath: pageFile, - } - ) - expect(code).toMatchInlineSnapshot( - `"var _res$status, _res$nullVal, _res$nullVal2;const res = { status: 0, nullVal: null, statusText: ''};const status = (_res$status = res.status) !== null && _res$status !== void 0 ? _res$status : 999;const nullVal = (_res$nullVal = res.nullVal) !== null && _res$nullVal !== void 0 ? _res$nullVal : 'another';const statusText = (_res$nullVal2 = res.nullVal) !== null && _res$nullVal2 !== void 0 ? _res$nullVal2 : 'not found';export default (() => 'hello');"` - ) - }) - - it('should support nullish coalescing for TS file', async () => { - const code = await babel( - `const res = { - status: 0, - nullVal: null, - statusText: '', - - } - const status = res.status ?? 999 - const nullVal = res.nullVal ?? 'another' - const statusText = res.nullVal ?? 'not found' - export default () => 'hello' - `, - { - resourcePath: tsPageFile, - } - ) - expect(code).toMatchInlineSnapshot( - `"var _res$status, _res$nullVal, _res$nullVal2;const res = { status: 0, nullVal: null, statusText: ''};const status = (_res$status = res.status) !== null && _res$status !== void 0 ? _res$status : 999;const nullVal = (_res$nullVal = res.nullVal) !== null && _res$nullVal !== void 0 ? _res$nullVal : 'another';const statusText = (_res$nullVal2 = res.nullVal) !== null && _res$nullVal2 !== void 0 ? _res$nullVal2 : 'not found';export default (() => 'hello');"` - ) - }) }) })