diff --git a/packages/next/build/babel/preset.ts b/packages/next/build/babel/preset.ts index 45beb38ece891b6..8e95a8c2c0dccc5 100644 --- a/packages/next/build/babel/preset.ts +++ b/packages/next/build/babel/preset.ts @@ -177,6 +177,7 @@ module.exports = ( ], require('@babel/plugin-proposal-optional-chaining'), require('@babel/plugin-proposal-nullish-coalescing-operator'), + isServer && require('@babel/plugin-syntax-bigint'), ].filter(Boolean), } } diff --git a/packages/next/package.json b/packages/next/package.json index 82e83b697851d37..0d48e104397a5e1 100644 --- a/packages/next/package.json +++ b/packages/next/package.json @@ -63,6 +63,7 @@ "@babel/plugin-proposal-nullish-coalescing-operator": "7.7.4", "@babel/plugin-proposal-object-rest-spread": "7.6.2", "@babel/plugin-proposal-optional-chaining": "7.7.4", + "@babel/plugin-syntax-bigint": "7.8.3", "@babel/plugin-syntax-dynamic-import": "7.2.0", "@babel/plugin-transform-modules-commonjs": "7.7.0", "@babel/plugin-transform-runtime": "7.6.2", diff --git a/test/integration/bigint/pages/api/bigint.js b/test/integration/bigint/pages/api/bigint.js new file mode 100644 index 000000000000000..8baefcfb20304d4 --- /dev/null +++ b/test/integration/bigint/pages/api/bigint.js @@ -0,0 +1,4 @@ +export default (req, res) => { + res.statusCode = 200 + res.send((1n + 2n).toString()) +} diff --git a/test/integration/bigint/test/index.test.js b/test/integration/bigint/test/index.test.js new file mode 100644 index 000000000000000..b4d49886ab08bb1 --- /dev/null +++ b/test/integration/bigint/test/index.test.js @@ -0,0 +1,77 @@ +/* eslint-env jest */ +/* global jasmine */ +import fs from 'fs-extra' +import { join } from 'path' +import { + fetchViaHTTP, + launchApp, + nextBuild, + nextStart, + killApp, + findPort, +} from 'next-test-utils' + +jasmine.DEFAULT_TIMEOUT_INTERVAL = 1000 * 60 * 2 + +const appDir = join(__dirname, '..') +const nextConfig = join(appDir, 'next.config.js') +let appPort +let app + +const runTests = () => { + it('should return 200', async () => { + const res = await fetchViaHTTP(appPort, '/api/bigint', null, { + method: 'GET', + }) + expect(res.status).toEqual(200) + }) + + it('should return the BigInt result text', async () => { + const resText = await fetchViaHTTP(appPort, '/api/bigint', null, { + method: 'GET', + }).then(res => res.ok && res.text()) + expect(resText).toEqual('3') + }) +} + +describe('bigint API route support', () => { + describe('dev mode', () => { + beforeAll(async () => { + appPort = await findPort() + app = await launchApp(appDir, appPort) + }) + afterAll(() => killApp(app)) + + runTests() + }) + + describe('server mode', () => { + beforeAll(async () => { + await fs.remove(nextConfig) + await nextBuild(appDir) + appPort = await findPort() + app = await nextStart(appDir, appPort) + }) + afterAll(() => killApp(app)) + + runTests() + }) + + describe('serverless mode', () => { + beforeAll(async () => { + await fs.writeFile( + nextConfig, + `module.exports = { target: 'serverless' }` + ) + await nextBuild(appDir) + appPort = await findPort() + app = await nextStart(appDir, appPort) + }) + afterAll(async () => { + await killApp(app) + await fs.remove(nextConfig) + }) + + runTests() + }) +}) diff --git a/yarn.lock b/yarn.lock index e1b0f6dd1036547..9fb92865ae14067 100644 --- a/yarn.lock +++ b/yarn.lock @@ -220,6 +220,11 @@ resolved "https://registry.yarnpkg.com/@babel/helper-plugin-utils/-/helper-plugin-utils-7.0.0.tgz#bbb3fbee98661c569034237cc03967ba99b4f250" integrity sha512-CYAOUCARwExnEixLdB6sDm2dIJ/YgEAKDM1MOeMeZu9Ld/bDgVo8aiWrXwcY7OBh+1Ea2uUcVRcxKk0GJvW7QA== +"@babel/helper-plugin-utils@^7.8.0": + version "7.8.3" + resolved "https://registry.npmjs.org/@babel/helper-plugin-utils/-/helper-plugin-utils-7.8.3.tgz#9ea293be19babc0f52ff8ca88b34c3611b208670" + integrity sha512-j+fq49Xds2smCUNYmEHF9kGNkhbet6yVIBp4e6oeQpH1RUs/Ir06xUKzDjDkGcaaokPiTNs2JBWHjaE4csUkZQ== + "@babel/helper-regex@^7.0.0", "@babel/helper-regex@^7.4.4": version "7.5.5" resolved "https://registry.yarnpkg.com/@babel/helper-regex/-/helper-regex-7.5.5.tgz#0aa6824f7100a2e0e89c1527c23936c152cab351" @@ -384,6 +389,13 @@ dependencies: "@babel/helper-plugin-utils" "^7.0.0" +"@babel/plugin-syntax-bigint@7.8.3": + version "7.8.3" + resolved "https://registry.npmjs.org/@babel/plugin-syntax-bigint/-/plugin-syntax-bigint-7.8.3.tgz#4c9a6f669f5d0cdf1b90a1671e9a146be5300cea" + integrity sha512-wnTnFlG+YxQm3vDxpGE57Pj0srRU4sHE/mDkt1qv2YJJSeUAec2ma4WLUnUPeKjyrfntVwe/N6dCXpU+zL3Npg== + dependencies: + "@babel/helper-plugin-utils" "^7.8.0" + "@babel/plugin-syntax-dynamic-import@7.2.0": version "7.2.0" resolved "https://registry.yarnpkg.com/@babel/plugin-syntax-dynamic-import/-/plugin-syntax-dynamic-import-7.2.0.tgz#69c159ffaf4998122161ad8ebc5e6d1f55df8612"