File tree Expand file tree Collapse file tree 3 files changed +13
-3
lines changed Expand file tree Collapse file tree 3 files changed +13
-3
lines changed Original file line number Diff line number Diff line change 193
193
},
194
194
"dependencies" : {
195
195
"@babel/runtime" : " ^7.8.4" ,
196
+ "flow-parser" : " ^0.117.1" ,
196
197
"jscodeshift" : " ^0.7.0" ,
197
198
"jscodeshift-choose-parser" : " ^1.0.0" ,
198
199
"require-glob" : " ^3.2.0" ,
Original file line number Diff line number Diff line change @@ -13,11 +13,20 @@ export default function getExistingImports(
13
13
14
14
let insertLine = 0
15
15
16
- j ( text )
16
+ let root
17
+ try {
18
+ root = j ( text )
19
+ } catch ( error ) {
20
+ // fall back to trying with flow parser, because it tends to be
21
+ // very tolerant of errors and we might at least get the import
22
+ // nodes
23
+ root = j . withParser ( 'flow' ) ( text )
24
+ }
25
+ root
17
26
. find ( j . ImportDeclaration )
18
27
. forEach ( ( { node } : ASTPath < ImportDeclaration > ) : void => {
19
28
if ( ! node ) return
20
- if ( node . loc ) insertLine = node . loc . end . line + 1
29
+ if ( node . loc ) insertLine = node . loc . end . line
21
30
const source = node . source . value
22
31
if ( typeof source === 'string' && source . startsWith ( '@material-ui' ) ) {
23
32
result . add ( source )
Original file line number Diff line number Diff line change @@ -3676,7 +3676,7 @@ flatted@^2.0.0:
3676
3676
resolved "https://registry.yarnpkg.com/flatted/-/flatted-2.0.1.tgz#69e57caa8f0eacbc281d2e2cb458d46fdb449e08"
3677
3677
integrity sha512-a1hQMktqW9Nmqr5aktAux3JMNqaucxGcjtjWnZLHX7yyPCmlSV3M54nGYbqT8K+0GhF3NBgmJCc3ma+WOgX8Jg==
3678
3678
3679
- flow-parser@0.* :
3679
+ flow-parser@0.*, flow-parser@^0.117.1 :
3680
3680
version "0.117.1"
3681
3681
resolved "https://registry.yarnpkg.com/flow-parser/-/flow-parser-0.117.1.tgz#ad52b866c16fe36a084a73056909731c9d538bdb"
3682
3682
integrity sha512-ybDdkcZOFw8rkpoLGzNH5xoKp4TrL5Kikrov0K/IFawNC6K8S3czWzxi+e1NJydgNHFZEKrrTcsO/9ftrQToHA==
You can’t perform that action at this time.
0 commit comments