File tree Expand file tree Collapse file tree 1 file changed +22
-18
lines changed Expand file tree Collapse file tree 1 file changed +22
-18
lines changed Original file line number Diff line number Diff line change @@ -207,41 +207,45 @@ export async function redirectDtsImports(
207
207
const sgNode = ( await parseAsync ( 'typescript' , content ) ) . root ( ) ;
208
208
const matcher : NapiConfig = {
209
209
rule : {
210
- kind : 'string_fragment' ,
211
210
any : [
212
211
{
213
- inside : {
214
- stopBy : 'end' ,
215
- kind : 'import_statement' ,
212
+ kind : 'import_statement' ,
213
+ has : {
216
214
field : 'source' ,
215
+ has : {
216
+ pattern : '$IMP' ,
217
+ kind : 'string_fragment' ,
218
+ } ,
217
219
} ,
218
220
} ,
219
221
{
220
- inside : {
221
- stopBy : 'end' ,
222
- kind : 'export_statement' ,
222
+ kind : 'export_statement' ,
223
+ has : {
223
224
field : 'source' ,
225
+ has : {
226
+ pattern : '$IMP' ,
227
+ kind : 'string_fragment' ,
228
+ } ,
224
229
} ,
225
230
} ,
226
231
{
227
- inside : {
228
- kind : 'string' ,
229
- inside : {
230
- kind : 'arguments' ,
231
- inside : {
232
- kind : 'call_expression' ,
233
- has : {
234
- field : 'function' ,
235
- regex : '^(import|require)$' ,
236
- } ,
232
+ any : [ { pattern : 'require($A)' } , { pattern : 'import($A)' } ] ,
233
+ has : {
234
+ field : 'arguments' ,
235
+ has : {
236
+ has : {
237
+ pattern : '$IMP' ,
238
+ kind : 'string_fragment' ,
237
239
} ,
238
240
} ,
239
241
} ,
240
242
} ,
241
243
] ,
242
244
} ,
243
245
} ;
244
- const matchModule = sgNode . findAll ( matcher ) . map ( ( matchNode ) => {
246
+ const matchModule = sgNode . findAll ( matcher ) . map ( ( match ) => {
247
+ // we can guarantee $IMP is matched given the rule
248
+ const matchNode = match . getMatch ( 'IMP' ) ! ;
245
249
return {
246
250
n : matchNode . text ( ) ,
247
251
s : matchNode . range ( ) . start . index ,
You can’t perform that action at this time.
0 commit comments