facebook / jscodeshift

A JavaScript codemod toolkit.
https://jscodeshift.com
MIT License
9.23k stars 477 forks source link

Why can't I specify `typeParameters` to a `CallExpression`? #330

Open lyleunderwood opened 5 years ago

lyleunderwood commented 5 years ago

I can't get the following code to add type parameters to my CallExpression in any of the parsers I've tried (flow and babylon7):

  const myExpression = j.callExpression(
    j.identifier('withTheme'), 
    [j.identifier('Thing')],
    j.typeParameterInstantiation([
      j.genericTypeAnnotation(j.identifier('Props'), null),
    ])
  );

AST Explorer

Forgive me if I've entered this issue in the wrong place, I don't yet really follow how the jscodeshift ecosystem fits together.

Here it looks like the callExpression builder function is being decorated with a third argument for type parameters, but if I just pass junk into that argument there is no type error.

valerybugakov commented 4 years ago

Similar issue with TS parser. typeParameters are wiped out from the call expression on toSource() call.

valerybugakov commented 4 years ago

It seems that it's an issue of recast https://github.com/benjamn/recast/issues/266

valerybugakov commented 4 years ago

This issue is resolved in the latest versions of recast, https://github.com/benjamn/recast/pull/613. Version is even updated in jscodeshift, it's just not published to the registry.