Closed
Description
openedon Jan 28, 2023
Bug Report
π Search Terms
transformer jsx comment 5.0
π Version & Regression Information
- This is a crash
- This changed between versions 4.9.4 and 5.0.0-beta
- Still present in @next
β― Playground Link
Not available because Playground has not transformer options
π» Code
Given the following file:
// src/index.tsx
function test () {
return <>
{/* This comment breaks the transformer */}
</>
}
and the following transformer
// transformer.js
const ts = require('typescript');
// noop transformer
module.exports = (context) => {
function visitor(node) {
return ts.visitEachChild(node, visitor, context);
}
return (node) => {
return ts.visitNode(node, visitor, context);
};
}
TypeScript throws this Error when compiling
Error: Debug Failure.
at visitEachChildOfJsxExpression (/.../node_modules/typescript/lib/typescript.js:85838:19)
at Object.visitEachChild (/.../node_modules/typescript/lib/typescript.js:84879:35)
at visitor (/.../transformer.js:6:13)
[...]
To run this I used this setup with Webpack and ts-loader: (I tried to keep it as short as possible)
// package.json
{
"name": "ts-test",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"build": "webpack --mode production"
},
"author": "",
"license": "ISC",
"dependencies": {
"react": "^18.2.0",
"ts-loader": "^9.4.2",
"typescript": "^5.0.0-beta",
"webpack": "^5.75.0",
"webpack-cli": "^5.0.1"
}
}
// webpack.config.js
const transformer = require('./transformer');
module.exports = {
resolve: {
extensions: [".tsx", ".ts", ".js"],
},
module: {
rules: [{
test: /\.tsx?$/,
use: {
loader: 'ts-loader',
options: {
getCustomTransformers: (program) => ({
before: [transformer],
}),
},
},
}]
},
}
// tsconfig.json
{
"compilerOptions": {
"jsx": "react-jsx"
}
}
π Actual behavior
Running npm run build
throws the described error
π Expected behavior
No error is thrown
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment