File tree 3 files changed +37
-3
lines changed
3 files changed +37
-3
lines changed Original file line number Diff line number Diff line change @@ -87,3 +87,22 @@ it('test', async () => {
87
87
Although I could possibly fix this for cases where it's easy to determine that the function has
88
88
no parameters, there could be cases where it's impossible to determine whether the identifier
89
89
` doSomething` is even a function or whether it has parameters.
90
+
91
+ ## Disabling ` recast` workaround
92
+
93
+ At the time I wrote ` asyncify` , there were some show-stopping bugs in old version of ` recast` that
94
+ ` jscodeshift` depended on. To avoid this problem, ` asyncify` parses with a newer version of ` recast` in its
95
+ own dependencies, instead of parsing with the ` jscodeshift` API. The author of ` putout` has asked to be able
96
+ to parse with the injected ` jscodeshift` API for performance, so you can access that version of the
97
+ ` jscodeshift` transform as:
98
+
99
+ ` ` ` js
100
+ import transform from ' @codemodsquad/asyncify/noRecastWorkaround'
101
+ ` ` `
102
+
103
+ Or there are two ways you can do it when running via ` jscodeshift` :
104
+
105
+ ` ` `
106
+ jscodeshift - t path/ to/ asyncify/ noRecastWorkaround .js
107
+ jscodeshift - t path/ to/ asyncify/ index .js -- noRecastWorkaround= true
108
+ ` ` `
Original file line number Diff line number Diff line change @@ -10,9 +10,11 @@ module.exports = function index(
10
10
api : API ,
11
11
options : Options
12
12
) : string | null | undefined | void {
13
- const ast = recast . parse ( fileInfo . source , {
14
- parser : require ( 'recast/parsers/babel' ) ,
15
- } )
13
+ const ast = options . noRecastWorkaround
14
+ ? api . jscodeshift ( fileInfo . source ) . get ( )
15
+ : recast . parse ( fileInfo . source , {
16
+ parser : require ( 'recast/parsers/babel' ) ,
17
+ } )
16
18
17
19
const ignoreChainsShorterThan = parseInt ( options . ignoreChainsShorterThan )
18
20
const commentWorkarounds = options . commentWorkarounds
Original file line number Diff line number Diff line change
1
+ import { API , FileInfo , Options } from 'jscodeshift'
2
+
3
+ module . exports = function (
4
+ fileInfo : FileInfo ,
5
+ api : API ,
6
+ options : Options
7
+ ) : string | null | undefined | void {
8
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
9
+ return require ( './index' ) ( fileInfo , api , {
10
+ ...options ,
11
+ noRecastWorkaround : true ,
12
+ } )
13
+ }
You can’t perform that action at this time.
0 commit comments