Skip to content

Commit 5ad9c7e

Browse files
Fix tr-catch, folders closing
1 parent ae21729 commit 5ad9c7e

8 files changed

Lines changed: 123 additions & 119 deletions

File tree

‎src/public/dist/bundle.js‎

Lines changed: 34 additions & 34 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎src/public/dist/bundle.js.map‎

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎src/public/js/components/dataBus/store/reducer.js‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,17 @@ export default (state = DefaultState, action) => {
7272
};
7373

7474
case ACTIONS.TOGGLE_FOLDER:
75-
const { openedFolders } = state;
75+
const { openedFolders, activeItemsMap } = state;
7676
const folderPath = action.payload.path;
7777

7878
const openedStateValue =
79-
openedFolders[folderPath] === FOLDER_OPEN_STATE.OPEN
80-
? FOLDER_OPEN_STATE.CLOSED
81-
: openedFolders[folderPath] + 1;
79+
activeItemsMap[folderPath] !== undefined
80+
? openedFolders[folderPath] === FOLDER_OPEN_STATE.OPEN
81+
? FOLDER_OPEN_STATE.CLOSED
82+
: openedFolders[folderPath] + 1
83+
: openedFolders[folderPath] === FOLDER_OPEN_STATE.OPEN
84+
? FOLDER_OPEN_STATE.CLOSED
85+
: FOLDER_OPEN_STATE.OPEN;
8286

8387
return {
8488
...state,

‎src/public/js/components/sideBar/component/DependenciesTab/index.js‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ const DependenciesTab = props => {
4343

4444
const exportedDependencies = extractExportsForImports(
4545
fileNode.fileCode,
46-
file.specifiers
46+
file.specifiers,
47+
filePath
4748
);
4849
return (
4950
<Panel header={fileNode.path} key={i + 1}>

‎src/public/js/components/sideBar/component/shared/utils.js‎

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -32,38 +32,38 @@ export const findFileNode = (path, filesMap) => {
3232

3333
export const getNodeLines = node => [node.loc.start.line, node.loc.end.line];
3434

35-
export const extractExportsForImports = (fileCode, specifiers) => {
35+
export const extractExportsForImports = (fileCode, specifiers, path) => {
3636
let ast = {};
3737
const exports = [];
3838

3939
try {
4040
ast = babylon.parse(fileCode, astParseConfig);
41-
} catch (e) {
42-
console.log(e);
43-
return exports;
44-
}
4541

46-
const isDefaultImported = !!specifiers.find(({ type }) => type === 'ImportDefaultSpecifier');
47-
const namedImportsNames = specifiers
48-
.filter(({ type }) => type === 'ImportSpecifier')
49-
.map(({ name }) => name);
42+
const isDefaultImported = !!specifiers.find(({ type }) => type === 'ImportDefaultSpecifier');
43+
const namedImportsNames = specifiers
44+
.filter(({ type }) => type === 'ImportSpecifier')
45+
.map(({ name }) => name);
5046

51-
babelTraverse.default(ast, {
52-
enter(path) {
53-
const node = path.node;
47+
babelTraverse.default(ast, {
48+
enter(path) {
49+
const node = path.node;
5450

55-
if (isDefaultImported && node.type === 'ExportDefaultDeclaration') {
56-
exports.push(node);
57-
} else if (node.type === 'ExportNamedDeclaration') {
58-
const declaration = node.declaration.declarations.find(d =>
59-
namedImportsNames.includes(d.id.name)
60-
);
61-
if (declaration) {
51+
if (isDefaultImported && node.type === 'ExportDefaultDeclaration') {
6252
exports.push(node);
53+
} else if (node.type === 'ExportNamedDeclaration') {
54+
const declaration = node.declaration.declarations.find(d =>
55+
namedImportsNames.includes(d.id.name)
56+
);
57+
if (declaration) {
58+
exports.push(node);
59+
}
6360
}
6461
}
65-
}
66-
});
62+
});
6763

68-
return exports;
64+
return exports;
65+
} catch (e) {
66+
console.log(path, e);
67+
return exports;
68+
}
6969
};

‎src/server/codecrumbs/codecrumbs.js‎

Lines changed: 34 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ const parseCodecrumbComment = (node = {}) => {
3030
console.error('Parameters parsing failed: ', e);
3131
}
3232

33-
3433
return cc;
3534
};
3635

@@ -39,51 +38,51 @@ const isCodecrumb = (node = {}) => {
3938
return comment.startsWith(CRUMB) || comment.startsWith(CRUMB_SHORT_HANDLER);
4039
};
4140

42-
const getCrumbs = fileCode => {
41+
const getCrumbs = (fileCode, path) => {
4342
let ast = {};
4443
const crumbsList = [];
4544

4645
try {
4746
ast = babylon.parse(fileCode, astParseConfig);
48-
} catch (e) {
49-
console.log(e);
50-
return crumbsList;
51-
}
5247

53-
// TODO: ast has comments array, maybe use it
54-
babelTraverse.default(ast, {
55-
enter(path) {
56-
const node = path.node;
57-
if (!node || !(node.leadingComments || node.trailingComments)) return;
48+
// TODO: ast has comments array, maybe use it
49+
babelTraverse.default(ast, {
50+
enter(path) {
51+
const node = path.node;
52+
if (!node || !(node.leadingComments || node.trailingComments)) return;
5853

59-
const leadingComment = node.leadingComments
60-
? node.leadingComments[node.leadingComments.length - 1]
61-
: null;
54+
const leadingComment = node.leadingComments
55+
? node.leadingComments[node.leadingComments.length - 1]
56+
: null;
6257

63-
let trailingComment = node.trailingComments ? node.trailingComments[0] : null;
58+
let trailingComment = node.trailingComments ? node.trailingComments[0] : null;
6459

65-
if (trailingComment && trailingComment.loc.start.line !== node.loc.start.line) {
66-
trailingComment = null;
67-
}
68-
69-
[leadingComment, trailingComment].forEach(comment => {
70-
if (comment && isCodecrumb(comment)) {
71-
const params = parseCodecrumbComment(comment);
72-
73-
const loc = comment.loc.start;
74-
crumbsList.push({
75-
name: params.name || '', //TODO: check, can be bug with layout calc
76-
displayLoc: `#${loc.line}`,
77-
crumbedLineNode: node,
78-
crumbNode: comment,
79-
params
80-
});
60+
if (trailingComment && trailingComment.loc.start.line !== node.loc.start.line) {
61+
trailingComment = null;
8162
}
82-
});
83-
}
84-
});
8563

86-
return crumbsList;
64+
[leadingComment, trailingComment].forEach(comment => {
65+
if (comment && isCodecrumb(comment)) {
66+
const params = parseCodecrumbComment(comment);
67+
68+
const loc = comment.loc.start;
69+
crumbsList.push({
70+
name: params.name || '', //TODO: check, can be bug with layout calc
71+
displayLoc: `#${loc.line}`,
72+
crumbedLineNode: node,
73+
crumbNode: comment,
74+
params
75+
});
76+
}
77+
});
78+
}
79+
});
80+
81+
return crumbsList;
82+
} catch (e) {
83+
console.log(path, e);
84+
return crumbsList;
85+
}
8786
};
8887

8988
module.exports = {

‎src/server/dependencies/dependencies.js‎

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,36 +3,36 @@ const babelTraverse = require('@babel/traverse');
33

44
const astParseConfig = require('../../shared/astParse').config;
55

6-
const getImports = fileCode => {
6+
const getImports = (fileCode, path) => {
77
let ast = {};
88
const importedDependencies = [];
99

1010
//TODO: move to one file in util, to keep config in one place
1111
try {
1212
ast = babylon.parse(fileCode, astParseConfig);
13-
} catch (e) {
14-
console.log(e);
15-
return importedDependencies;
16-
}
1713

18-
babelTraverse.default(ast, {
19-
enter(path) {
20-
const node = path.node;
14+
babelTraverse.default(ast, {
15+
enter(path) {
16+
const node = path.node;
2117

22-
if (node.type === 'ImportDeclaration') {
23-
importedDependencies.push({
24-
node,
25-
sourceFile: node.source && node.source.value,
26-
specifiers: node.specifiers.map(({ type, imported, local }) => ({
27-
type,
28-
name: (imported || local || {}).name
29-
}))
30-
});
18+
if (node.type === 'ImportDeclaration') {
19+
importedDependencies.push({
20+
node,
21+
sourceFile: node.source && node.source.value,
22+
specifiers: node.specifiers.map(({ type, imported, local }) => ({
23+
type,
24+
name: (imported || local || {}).name
25+
}))
26+
});
27+
}
3128
}
32-
}
33-
});
29+
});
3430

35-
return importedDependencies;
31+
return importedDependencies;
32+
} catch (e) {
33+
console.log(path, e);
34+
return importedDependencies;
35+
}
3636
};
3737

3838
module.exports = {

‎src/server/project-source-watcher.js‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ const grabProjectSourceState = ({ filesMap, projectDir, entryPoint }) => {
7373
file.read(itemPath, 'utf8').then(code => {
7474
const item = filesMap[itemPath];
7575

76-
const codecrumbsList = codecrumbs.getCrumbs(code);
77-
const importedDependencies = dependencies.getImports(code);
76+
const codecrumbsList = codecrumbs.getCrumbs(code, itemPath);
77+
const importedDependencies = dependencies.getImports(code, itemPath);
7878

7979
if (codecrumbsList.length) {
8080
item.children = codecrumbsList;

0 commit comments

Comments
 (0)