Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JSX comments break Transformer API in TS 5.0 beta #52479

Closed
zOadT opened this issue Jan 28, 2023 · 1 comment Β· Fixed by #52482
Closed

JSX comments break Transformer API in TS 5.0 beta #52479

zOadT opened this issue Jan 28, 2023 · 1 comment Β· Fixed by #52482
Assignees
Labels
API Relates to the public API for TypeScript Bug A bug in TypeScript

Comments

@zOadT
Copy link

zOadT commented 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

@jakebailey
Copy link
Member

This looks like a bug I introduced in #49929.

I'll send a PR to fix it.

@jakebailey jakebailey self-assigned this Jan 28, 2023
@jakebailey jakebailey added Bug A bug in TypeScript API Relates to the public API for TypeScript labels Jan 28, 2023
@jakebailey jakebailey added this to the TypeScript 5.0.1 milestone Jan 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API Relates to the public API for TypeScript Bug A bug in TypeScript
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants