Skip to content

Commit 5e5f8a0

Browse files
committed
changed javascript to typescript
1 parent bb91598 commit 5e5f8a0

9 files changed

+5
-67
lines changed

package.json

-5
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,6 @@
2828
"main": "./build/extension.js",
2929
"contributes": {
3030
"commands": [
31-
{
32-
"command": "react-labyrinth.helloWorld",
33-
"title": "Hello World",
34-
"category": "React Labyrinth"
35-
},
3631
{
3732
"command": "myExtension.showPanel",
3833
"title": "Show Panel",

postcss.config.cjs

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
const tailwindcss = require('tailwindcss');
2-
// import * as tailwindcss from 'tailwindcss';
32

43
module.exports = {
54
plugins: [

src/extension.ts

-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import * as vscode from 'vscode';
22
import {createPanel} from './panel';
3-
// const { createPanel } = require('./src/panel');
4-
// const { Parser } = require('./src/parser');
53
import { Parser } from './parser';
64

75
// This method is called when your extension is activated

src/getNonce.ts

-1
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,3 @@ export function getNonce() {
88
return text;
99
}
1010

11-
// module.exports = { getNonce }

src/panel.ts

-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// const vscode = require('vscode');
21
import * as vscode from 'vscode';
32
import { getNonce } from './getNonce';
43
import { Tree } from './types/tree';
@@ -83,5 +82,3 @@ function createWebviewHTML(URI: vscode.Uri, initialData: Tree) {
8382
`
8483
)
8584
}
86-
87-
// module.exports = { createPanel };

src/parser.ts

+3-19
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,7 @@
1-
// const fs = require('fs')
21
import * as fs from 'fs';
32
import * as path from 'path';
4-
// const path = require('path')
5-
// const babel = require('@babel/parser');
63
import * as babel from '@babel/parser';
74
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')
125
import { ImportObj } from './types/ImportObj';
136
import { Tree } from "./types/tree";
147
import { 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 };

src/webview/Flow.tsx

+1-3
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import FlowBuilder from './flowBuilder';
1616
const onInit = (reactFlowInstance: ReactFlowInstance) =>
1717
console.log("flow loaded:", reactFlowInstance);
1818

19-
const OverviewFlow: React.FC = () => {
19+
const OverviewFlow = () => {
2020
const initialNodes = [];
2121
const initialEdges = [];
2222

@@ -57,8 +57,6 @@ const OverviewFlow: React.FC = () => {
5757
<MiniMap
5858
nodeStrokeColor={(n): string => {
5959
if (n.style?.backgroundColor) return n.style.backgroundColor;
60-
// if (n.data.label.props.className.includes('orange')) return "#fdba74";
61-
// if (n.data.label.props.className.includes('blue')) return "#93C5FD";
6260
if (n.type === "default") return "#1a192b";
6361

6462
return "#eee";

src/webview/flowBuilder.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ class FlowBuilder {
116116

117117
public build(settings: Settings): void {
118118
const treeParsed = JSON.parse(JSON.stringify(this.parsedData[0]));
119-
console.log('settings: ', settings);
119+
// console.log('settings: ', settings);
120120
const traverse = (node: ParsedDataItem): void => {
121121
let validChildren: ParsedDataItem[] = [];
122122

webpack.config.ts

-32
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,3 @@
1-
// import * as path from 'path';
2-
3-
// module.exports = {
4-
// entry: './src/webview/index.tsx',
5-
// output: {
6-
// filename: 'bundle.js',
7-
// path: path.resolve(__dirname, './build'),
8-
// },
9-
// resolve: {
10-
// extensions: ['.js', '.ts', '.tsx', '.css'],
11-
// },
12-
// module: {
13-
// rules: [
14-
// // {
15-
// // test: /\.jsx?/,
16-
// // exclude: /node_modules/,
17-
// // use: {
18-
// // loader: "babel-loader",
19-
// // options: {
20-
// // presets: ['@babel/preset-env', '@babel/preset-react']
21-
// // }
22-
// // }
23-
// // },
24-
// { test: /\.tsx?$/, use: ['babel-loader', 'ts-loader'] },
25-
// {
26-
// test: /\.(css)$/,
27-
// use: ["style-loader", "css-loader", "postcss-loader"],
28-
// },
29-
// ]
30-
// },
31-
// mode: "development"
32-
// }
331

342
import * as path from 'path';
353
import * as webpack from 'webpack';

0 commit comments

Comments
 (0)