💻
How are you using Babel?
Programmatic API (babel.transform, babel.parse)
Input code
const { transformSync } = require('@babel/core')
let result = transformSync(`
const fn = <T,>(t: T) => t;
`, {
babelrc: false,
configFile: false,
parserOpts: {
plugins: [
'jsx',
'typescript',
]
},
})
console.log(result.code)
Configuration file name
No response
Configuration
No response
Current and expected behavior
The current output:
const fn = <T>(t: T) => t;
This is valid in TS, but invalid in TSX, because <T> is treated as a tag in TSX context.
Expected output:
const fn = <T,>(t: T) => t;
Environment
System:
OS: macOS 11.5.2
Binaries:
Node: 16.9.1 - /usr/local/bin/node
Yarn: 1.22.11 - /usr/local/bin/yarn
npm: 7.23.0 - /usr/local/bin/npm
Possible solution
No response
Additional context
Original Issue: vitejs/vite#4949.
💻
How are you using Babel?
Programmatic API (
babel.transform,babel.parse)Input code
Configuration file name
No response
Configuration
No response
Current and expected behavior
The current output:
This is valid in TS, but invalid in TSX, because
<T>is treated as a tag in TSX context.Expected output:
Environment
Possible solution
No response
Additional context
Original Issue: vitejs/vite#4949.