Skip to content

Commit

Permalink
refactor(build): no force transpile optional chaining / nullish
Browse files Browse the repository at this point in the history
  • Loading branch information
SukkaW committed Apr 7, 2022
1 parent 0164ac6 commit c058735
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 88 deletions.
4 changes: 0 additions & 4 deletions packages/next/build/babel/preset.ts
Expand Up @@ -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'],
}

Expand Down
14 changes: 0 additions & 14 deletions packages/next/build/swc/options.js
Expand Up @@ -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',
Expand Down Expand Up @@ -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 {
Expand Down
70 changes: 0 additions & 70 deletions test/unit/next-babel-loader-prod.test.ts
Expand Up @@ -323,75 +323,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');"`
)
})
})
})

0 comments on commit c058735

Please sign in to comment.