1
- // const fs = require('fs')
2
1
import * as fs from 'fs' ;
3
2
import * as path from 'path' ;
4
- // const path = require('path')
5
- // const babel = require('@babel/parser');
6
3
import * as babel from '@babel/parser' ;
7
4
import { 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')
12
5
import { ImportObj } from './types/ImportObj' ;
13
6
import { Tree } from "./types/tree" ;
14
7
import { File } from '@babel/types' ;
@@ -164,7 +157,6 @@ export class Parser {
164
157
165
158
// Recursively builds the React component tree structure starting from root node
166
159
private parser ( componentTree : Tree ) : Tree | undefined {
167
- // console.log('componentTree:', componentTree);
168
160
// If import is a node module, do not parse any deeper
169
161
if ( ! [ '\\' , '/' , '.' ] . includes ( componentTree . importPath [ 0 ] ) ) {
170
162
componentTree . thirdParty = true ;
@@ -180,7 +172,7 @@ export class Parser {
180
172
// Check that file has valid fileName/Path, if not found, add error to node and halt
181
173
const fileName = this . getFileName ( componentTree ) ;
182
174
if ( ! fileName ) {
183
- componentTree . error = 'File not found. ' ;
175
+ componentTree . error = 'File not found' ;
184
176
return ;
185
177
}
186
178
@@ -309,11 +301,8 @@ export class Parser {
309
301
}
310
302
} ;
311
303
312
- // console.log('ast.program.body', body);
313
304
const bodyCallee = body . filter ( ( item ) => item . type === 'VariableDeclaration' ) ;
314
305
if ( bodyCallee . length === 0 ) return false ;
315
- // console.log('bodyCallee', bodyCallee);
316
- // console.log('bodyCallee.length', bodyCallee.length)
317
306
318
307
const calleeHelper = ( item ) => {
319
308
const hooksObj = {
@@ -368,7 +357,6 @@ export class Parser {
368
357
const calleeArr = bodyCallee [ 0 ] . declarations [ 0 ] ?. init ?. body ?. body ;
369
358
if ( calleeArr === undefined ) return false ;
370
359
371
- // console.log('calleArr:', calleeArr);
372
360
let checkTrue = false ;
373
361
for ( let i = 0 ; i < calleeArr . length ; i ++ ) {
374
362
if ( checkTrue ) return true ;
@@ -382,7 +370,6 @@ export class Parser {
382
370
try {
383
371
if ( bodyCallee [ i ] . declarations [ 0 ] ?. init ?. body ?. body ) {
384
372
calleeArr = bodyCallee [ i ] . declarations [ 0 ] . init . body . body ;
385
- // console.log('calleeArr from body', calleeArr);
386
373
}
387
374
}
388
375
catch ( err ) {
@@ -407,9 +394,7 @@ export class Parser {
407
394
importsObj : ImportObj ,
408
395
parentNode : Tree
409
396
) : Tree [ ] {
410
- // let childNodes = {};
411
- // let props = {};
412
- // let token;
397
+
413
398
let childNodes : { [ key : string ] : Tree } = { } ;
414
399
let props : { [ key : string ] : boolean } = { } ;
415
400
let token : { [ key : string ] : any } ;
@@ -483,6 +468,7 @@ export class Parser {
483
468
count : 1 ,
484
469
props : props ,
485
470
children : [ ] ,
471
+ // consider adding the id to the parentList array somehow for D3 integration...
486
472
parentList : [ parent . filePath ] . concat ( parent . parentList ) ,
487
473
error : '' ,
488
474
isClientComponent : false
@@ -540,5 +526,3 @@ export class Parser {
540
526
return false ;
541
527
}
542
528
}
543
-
544
- // module.exports = { Parser };
0 commit comments