Skip to content

JSX comments break Transformer API in TS 5.0 betaΒ #52479

@zOadT

Description

@zOadT

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

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptDomain: APIRelates to the public API for TypeScript

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions