@@ -7,6 +7,7 @@ import * as walk from 'acorn-walk'
77import { minimatch } from 'minimatch'
88// Only import types given this is an optional dependency
99import type { TSESTree , AST_NODE_TYPES } from '@typescript-eslint/typescript-estree'
10+ import Debug from 'debug'
1011
1112import { Collector } from './collector'
1213import { DependencyParseError } from './errors'
@@ -16,6 +17,8 @@ import { findFilesWithPattern, pathToPosix } from '../util'
1617import { Workspace } from './package-files/workspace'
1718import { isCoreExtension , isTSExtension } from './package-files/extension'
1819
20+ const debug = Debug ( 'checkly:cli:services:check-parser:parser' )
21+
1922// Our custom configuration to handle walking errors
2023
2124// eslint-disable-next-line @typescript-eslint/no-unused-vars
@@ -71,12 +74,11 @@ function getTsParser (): any {
7174 // Our custom configuration to handle walking errors
7275
7376 Object . values ( AST_NODE_TYPES ) . forEach ( astType => {
74- // Only handle the TS specific ones
75- if ( ! astType . startsWith ( 'TS' ) ) {
76- return
77+ // Only handle the TS/JSX specific ones
78+ if ( astType . startsWith ( 'TS' ) || astType . startsWith ( 'JSX' ) ) {
79+ const base : any = walk . base
80+ base [ astType ] = base [ astType ] ?? ignore
7781 }
78- const base : any = walk . base
79- base [ astType ] = base [ astType ] ?? ignore
8082 } )
8183 return tsParser
8284 } catch ( err : any ) {
@@ -375,6 +377,7 @@ export class Parser {
375377
376378 static parseDependencies ( filePath : string , contents : string ) :
377379 { module : Module , error ?: any } {
380+ debug ( `Parsing dependencies of ${ filePath } ` )
378381 const dependencies = new RawDependencyCollector ( )
379382
380383 const extension = path . extname ( filePath )
@@ -389,13 +392,17 @@ export class Parser {
389392 walk . simple ( ast , Parser . jsNodeVisitor ( dependencies ) )
390393 } else if ( isTSExtension ( extension ) ) {
391394 const tsParser = getTsParser ( )
392- const ast = tsParser . parse ( contents , { } )
395+ const ast = tsParser . parse ( contents , {
396+ jsx : true ,
397+ } )
393398 // The AST from typescript-estree is slightly different from the type used by acorn-walk.
394399 // This doesn't actually cause problems (both are "ESTree's"), but we need to ignore type errors here.
395400 // @ts -ignore
396401 walk . simple ( ast , Parser . tsNodeVisitor ( tsParser , dependencies ) )
397402 }
398403 } catch ( err ) {
404+ debug ( `Failed to parse dependencies of ${ filePath } : ${ err } ` )
405+
399406 return {
400407 module : {
401408 dependencies : dependencies . state ( ) ,
0 commit comments