Open ppershing opened 6 years ago
I'm writing my own transform and I observe that opening a block like that doesn't create a nested scope in codeshift, which is the reason why renameTo
is incorrect here.
Amazed that a correctness bug like this one is still open 2 years later :(
For my own background knowledge/context, it seems that jscodeshift
is basically a wrapper around recast
, which relies on ast-types
:
jscodeshift
is a reference to the wrapper around recast and provides a jQuery-like API to navigate and transform the AST
The transform file can let jscodeshift know with which parser to parse the source files (and features like templates).
To do that, the transform module can export parser, which can either be one of the strings "babel", "babylon", "flow", "ts", or "tsx", or it can be a parser object that is compatible with
recast
and follows theestree
spec.
Recast itself relies heavily on ast-types which defines methods to traverse the AST, access node fields and build new nodes.
ast-types
wraps every AST node into apath
object. Paths contain meta-information and helper methods to process AST nodes.
I'd have to look deeper to be sure where exactly the root issue is though.
Potentially related?
It also seems this/similar might be an issue shared across a number of the parsers / scope managers, e.g:
ES6 Block scoping seems to be broken in
renameTo
.Repro:
Transform:
Input:
Output:
Expected output: