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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: TypeScript parser does not set typeParameters for CallExpression #16389

Closed
1 task
gdbd opened this issue Mar 28, 2024 · 3 comments
Closed
1 task

[Bug]: TypeScript parser does not set typeParameters for CallExpression #16389

gdbd opened this issue Mar 28, 2024 · 3 comments

Comments

@gdbd
Copy link

gdbd commented Mar 28, 2024

馃捇

  • Would you like to work on a fix?

How are you using Babel?

Programmatic API (babel.transform, babel.parse)

Input code

const babel = require("@babel/core");

const result = babel.transformSync(
  `
    someFunction<TSomeType>();
`,
  {
    parserOpts: { plugins: ["typescript"] },
    plugins: ["@babel/plugin-transform-typescript"],
    ast: true,
  },
);

Configuration file name

No response

Configuration

 {
    parserOpts: { plugins: ["typescript"] },
    plugins: ["@babel/plugin-transform-typescript"],
    ast: true,
  }

Current and expected behavior

expected: result.ast.program.body[0].expression.typeParameters !== null

actual: result.ast.program.body[0].expression.typeParameters === null

Environment

  • babel: 7.24.0
  • node.js: 21
  • yarn: 1.22.21
  • OS: linux 6.7

Possible solution

No response

Additional context

reproduce repository: https://github.com/gdbd/babel-test

to start:

  1. clone
  2. yarn install
  3. yarn run 'transform-test'
  4. yarn run 'plugin-test'

look in the output:
at step 3:
image

at step 4:
image

So, typeParameters is not avalibale directly via CallExpression but availbale whwn it accesses through it parents.

Same time, AST explorer works as expected:
2024-03-28_18-50

@babel-bot
Copy link
Collaborator

Hey @gdbd! We really appreciate you taking the time to report an issue. The collaborators on this project attempt to help as many people as possible, but we're a limited number of volunteers, so it's possible this won't be addressed swiftly.

If you need any help, or just have general Babel or JavaScript questions, we have a vibrant Slack community that typically always has someone willing to help. You can sign-up here for an invite.

@gdbd gdbd changed the title [Bug]: TypeScript parser does not set typeParameters for json { parserOpts: { plugins: ["typescript"] }, plugins: ["@babel/plugin-transform-typescript"], ast: true, } [Bug]: TypeScript parser does not set typeParameters for CallExpression Mar 28, 2024
@JLHwung
Copy link
Contributor

JLHwung commented Mar 28, 2024

{
-    parserOpts: { plugins: ["typescript"] },
-    plugins: ["@babel/plugin-transform-typescript"],
+   plugins: ["@babel/plugin-syntax-typescript"],
    ast: true,
  }

Please remove the typescript transform if you are to inspect the AST, since the transform plugin will remove any typescript type annotations, while the syntax plugin is to only parse but not transform the typescript.

@gdbd
Copy link
Author

gdbd commented Mar 28, 2024

@JLHwung thank you, problem is solved!

@gdbd gdbd closed this as completed Mar 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants