Skip to content

Commit

Permalink
Add Numeric Separator Support for TypeScript (#11308)
Browse files Browse the repository at this point in the history
* Add Numeric Separator Support for TypeScript

* Check for number in render
  • Loading branch information
Timer committed Mar 23, 2020
1 parent 541cd01 commit f19dcf9
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 1 deletion.
9 changes: 8 additions & 1 deletion packages/next/build/babel/preset.ts
Expand Up @@ -49,7 +49,7 @@ type BabelPreset = {
presets?: PluginItem[] | null
plugins?: PluginItem[] | null
sourceType?: 'script' | 'module' | 'unambiguous'
overrides?: any[]
overrides?: Array<{ test: RegExp } & Omit<BabelPreset, 'overrides'>>
}

// Taken from https://github.com/babel/babel/commit/d60c5e1736543a6eac4b549553e107a9ba967051#diff-b4beead8ad9195361b4537601cc22532R158
Expand Down Expand Up @@ -177,6 +177,13 @@ module.exports = (
require('@babel/plugin-proposal-optional-chaining'),
require('@babel/plugin-proposal-nullish-coalescing-operator'),
isServer && require('@babel/plugin-syntax-bigint'),
[require('@babel/plugin-proposal-numeric-separator').default, false],
].filter(Boolean),
overrides: [
{
test: /\.tsx?$/,
plugins: [require('@babel/plugin-proposal-numeric-separator').default],
},
],
}
}
1 change: 1 addition & 0 deletions packages/next/package.json
Expand Up @@ -61,6 +61,7 @@
"@babel/core": "7.7.2",
"@babel/plugin-proposal-class-properties": "7.7.0",
"@babel/plugin-proposal-nullish-coalescing-operator": "7.7.4",
"@babel/plugin-proposal-numeric-separator": "7.8.3",
"@babel/plugin-proposal-object-rest-spread": "7.6.2",
"@babel/plugin-proposal-optional-chaining": "7.7.4",
"@babel/plugin-syntax-bigint": "7.8.3",
Expand Down
@@ -0,0 +1 @@
export default () => `hello ${1_000}`
@@ -0,0 +1,22 @@
/* eslint-env jest */
/* global jasmine */
import { nextBuild } from 'next-test-utils'
import { join } from 'path'

jasmine.DEFAULT_TIMEOUT_INTERVAL = 1000 * 60 * 2

const appDir = join(__dirname, '../')

describe('TypeScript Exclusivity of Numeric Separator', () => {
it('should fail to build for a JavaScript file', async () => {
const { code, stderr } = await nextBuild(appDir, [], {
stderr: true,
})

expect(code).toBe(1)

expect(stderr).toContain('Failed to compile.')
expect(stderr).toContain('SyntaxError:')
expect(stderr).toContain('Identifier directly after number')
})
})
1 change: 1 addition & 0 deletions test/integration/typescript/pages/hello.tsx
Expand Up @@ -11,6 +11,7 @@ export default function HelloPage(): JSX.Element {
console.log(router.pathname)
return (
<div>
<p>One trillion dollars: {1_000_000_000_000}</p>
{hello()} <World />
<Router />
<Link />
Expand Down
1 change: 1 addition & 0 deletions test/integration/typescript/test/index.test.js
Expand Up @@ -43,6 +43,7 @@ describe('TypeScript Features', () => {
it('should render the page', async () => {
const $ = await get$('/hello')
expect($('body').text()).toMatch(/Hello World/)
expect($('body').text()).toMatch(/1000000000000/)
})

it('should report type checking to stdout', async () => {
Expand Down
15 changes: 15 additions & 0 deletions yarn.lock
Expand Up @@ -481,6 +481,14 @@
"@babel/helper-plugin-utils" "^7.0.0"
"@babel/plugin-syntax-nullish-coalescing-operator" "^7.7.4"

"@babel/plugin-proposal-numeric-separator@7.8.3":
version "7.8.3"
resolved "https://registry.yarnpkg.com/@babel/plugin-proposal-numeric-separator/-/plugin-proposal-numeric-separator-7.8.3.tgz#5d6769409699ec9b3b68684cd8116cedff93bad8"
integrity sha512-jWioO1s6R/R+wEHizfaScNsAx+xKgwTLNXSh7tTC4Usj3ItsPEhYkEpU4h+lpnBwq7NBVOJXfO6cRFYcX69JUQ==
dependencies:
"@babel/helper-plugin-utils" "^7.8.3"
"@babel/plugin-syntax-numeric-separator" "^7.8.3"

"@babel/plugin-proposal-object-rest-spread@7.6.2":
version "7.6.2"
resolved "https://registry.yarnpkg.com/@babel/plugin-proposal-object-rest-spread/-/plugin-proposal-object-rest-spread-7.6.2.tgz#8ffccc8f3a6545e9f78988b6bf4fe881b88e8096"
Expand Down Expand Up @@ -577,6 +585,13 @@
dependencies:
"@babel/helper-plugin-utils" "^7.0.0"

"@babel/plugin-syntax-numeric-separator@^7.8.3":
version "7.8.3"
resolved "https://registry.yarnpkg.com/@babel/plugin-syntax-numeric-separator/-/plugin-syntax-numeric-separator-7.8.3.tgz#0e3fb63e09bea1b11e96467271c8308007e7c41f"
integrity sha512-H7dCMAdN83PcCmqmkHB5dtp+Xa9a6LKSvA2hiFBC/5alSHxM5VgWZXFqDi0YFe8XNGT6iCa+z4V4zSt/PdZ7Dw==
dependencies:
"@babel/helper-plugin-utils" "^7.8.3"

"@babel/plugin-syntax-object-rest-spread@^7.0.0", "@babel/plugin-syntax-object-rest-spread@^7.2.0", "@babel/plugin-syntax-object-rest-spread@^7.7.4":
version "7.7.4"
resolved "https://registry.yarnpkg.com/@babel/plugin-syntax-object-rest-spread/-/plugin-syntax-object-rest-spread-7.7.4.tgz#47cf220d19d6d0d7b154304701f468fc1cc6ff46"
Expand Down

0 comments on commit f19dcf9

Please sign in to comment.