benjamn / ast-types

Esprima-compatible implementation of the Mozilla JS Parser API
MIT License
1.13k stars 195 forks source link

`b.functionExpression.from(functionDeclaration)` is failing on Windows #814

Open MichaelDeBoey opened 2 years ago

MichaelDeBoey commented 2 years ago

When we got this problem in the remix repo (https://github.com/remix-run/remix/pull/3987), I reported this in the jscodeshift repo (https://github.com/facebook/jscodeshift/issues/520), but since all their builders are coming from recast (https://github.com/benjamn/recast/issues/1170), which on themselves are re-exported from ast-types, I thought it would be a good idea to also report it in this repo

When we got this problem in the remix repo (https://github.com/remix-run/remix/pull/3987), I reported this in the jscodeshift repo (https://github.com/facebook/jscodeshift/issues/520), but since all their builders are coming from recast, I thought it would be a good idea to also report it in this repo

For some reason Windows is throwing an error when converting a FunctionDeclaration to a FunctionExpression, while this is perfectly working (as expected) on Linux.

As @mcansh pointed out in https://github.com/remix-run/remix/pull/3987#issuecomment-1218239753, the origin of this problem is coming from ast-types https://github.com/benjamn/ast-types/blob/master/lib/types.ts#L656-L658

AST Explorer example (which is failing as well): https://astexplorer.net/#/gist/31f7305e1a29c0565f6efb13709e93a8/latest

MichaelDeBoey commented 1 year ago

@benjamn If you can point me into the right direction, I would be happy to create a PR to fix this.