1- // const fs = require('fs')
21import * as fs from 'fs' ;
32import * as path from 'path' ;
4- // const path = require('path')
5- // const babel = require('@babel/parser');
63import * as babel from '@babel/parser' ;
74import { getNonce } from './getNonce' ;
8- // const { getNonce } = require('./getNonce');
9- // const { Tree } = require('./types/tree');
10- // const { File } = require('@babel/types');
11- // const ImportObj = require('./types/ImportObj')
125import { ImportObj } from './types/ImportObj' ;
136import { Tree } from "./types/tree" ;
147import { File } from '@babel/types' ;
@@ -164,7 +157,6 @@ export class Parser {
164157
165158 // Recursively builds the React component tree structure starting from root node
166159 private parser ( componentTree : Tree ) : Tree | undefined {
167- // console.log('componentTree:', componentTree);
168160 // If import is a node module, do not parse any deeper
169161 if ( ! [ '\\' , '/' , '.' ] . includes ( componentTree . importPath [ 0 ] ) ) {
170162 componentTree . thirdParty = true ;
@@ -180,7 +172,7 @@ export class Parser {
180172 // Check that file has valid fileName/Path, if not found, add error to node and halt
181173 const fileName = this . getFileName ( componentTree ) ;
182174 if ( ! fileName ) {
183- componentTree . error = 'File not found. ' ;
175+ componentTree . error = 'File not found' ;
184176 return ;
185177 }
186178
@@ -309,11 +301,8 @@ export class Parser {
309301 }
310302 } ;
311303
312- // console.log('ast.program.body', body);
313304 const bodyCallee = body . filter ( ( item ) => item . type === 'VariableDeclaration' ) ;
314305 if ( bodyCallee . length === 0 ) return false ;
315- // console.log('bodyCallee', bodyCallee);
316- // console.log('bodyCallee.length', bodyCallee.length)
317306
318307 const calleeHelper = ( item ) => {
319308 const hooksObj = {
@@ -368,7 +357,6 @@ export class Parser {
368357 const calleeArr = bodyCallee [ 0 ] . declarations [ 0 ] ?. init ?. body ?. body ;
369358 if ( calleeArr === undefined ) return false ;
370359
371- // console.log('calleArr:', calleeArr);
372360 let checkTrue = false ;
373361 for ( let i = 0 ; i < calleeArr . length ; i ++ ) {
374362 if ( checkTrue ) return true ;
@@ -382,7 +370,6 @@ export class Parser {
382370 try {
383371 if ( bodyCallee [ i ] . declarations [ 0 ] ?. init ?. body ?. body ) {
384372 calleeArr = bodyCallee [ i ] . declarations [ 0 ] . init . body . body ;
385- // console.log('calleeArr from body', calleeArr);
386373 }
387374 }
388375 catch ( err ) {
@@ -407,9 +394,7 @@ export class Parser {
407394 importsObj : ImportObj ,
408395 parentNode : Tree
409396 ) : Tree [ ] {
410- // let childNodes = {};
411- // let props = {};
412- // let token;
397+
413398 let childNodes : { [ key : string ] : Tree } = { } ;
414399 let props : { [ key : string ] : boolean } = { } ;
415400 let token : { [ key : string ] : any } ;
@@ -483,6 +468,7 @@ export class Parser {
483468 count : 1 ,
484469 props : props ,
485470 children : [ ] ,
471+ // consider adding the id to the parentList array somehow for D3 integration...
486472 parentList : [ parent . filePath ] . concat ( parent . parentList ) ,
487473 error : '' ,
488474 isClientComponent : false
@@ -540,5 +526,3 @@ export class Parser {
540526 return false ;
541527 }
542528}
543-
544- // module.exports = { Parser };
0 commit comments