Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(build): no force transpile optional chaining #35976

Merged
merged 4 commits into from Apr 16, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
71 changes: 0 additions & 71 deletions test/unit/next-babel-loader-prod.test.ts
Expand Up @@ -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(
Expand Down Expand Up @@ -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 () => {
ijjk marked this conversation as resolved.
Show resolved Hide resolved
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');"`
)
})
})
})