Skip to content

Commit 505f991

Browse files
committed
[INTERNAL_BRANCH=status-selection-syntax]
1 parent b148b99 commit 505f991

File tree

4 files changed

+104
-0
lines changed

4 files changed

+104
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import {GraphQueryItem} from '../app/GraphQueryImpl';
2+
import {AssetNodeForGraphQueryFragment} from './types/useAssetGraphData.types';
3+
4+
export type AssetNode = AssetNodeForGraphQueryFragment;
5+
export type AssetGraphQueryItem = GraphQueryItem & {
6+
node: AssetNode;
7+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import {CharStreams, CommonTokenStream} from 'antlr4ts';
2+
import {AbstractParseTreeVisitor} from 'antlr4ts/tree/AbstractParseTreeVisitor';
3+
4+
import {AssetSelectionLexer} from './generated/AssetSelectionLexer';
5+
import {AssetSelectionParser, StatusAttributeExprContext} from './generated/AssetSelectionParser';
6+
import {AssetSelectionVisitor} from './generated/AssetSelectionVisitor';
7+
import {getValue} from './util';
8+
9+
export type Filter = {field: 'status'; value: string};
10+
11+
export class AssetSelectionSupplementaryDataVisitor
12+
extends AbstractParseTreeVisitor<void>
13+
implements AssetSelectionVisitor<void>
14+
{
15+
public filters: Filter[] = [];
16+
17+
constructor() {
18+
super();
19+
}
20+
21+
protected defaultResult() {}
22+
23+
visitStatusAttributeExpr(ctx: StatusAttributeExprContext) {
24+
const value: string = getValue(ctx.value());
25+
this.filters.push({field: 'status', value});
26+
}
27+
}
28+
29+
export const parseExpression = (expression: string) => {
30+
const inputStream = CharStreams.fromString(expression);
31+
const lexer = new AssetSelectionLexer(inputStream);
32+
const tokenStream = new CommonTokenStream(lexer);
33+
const parser = new AssetSelectionParser(tokenStream);
34+
const tree = parser.start();
35+
const visitor = new AssetSelectionSupplementaryDataVisitor();
36+
tree.accept(visitor);
37+
return visitor.filters;
38+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import {AssetKey} from '../assets/types';
2+
3+
export type SupplementaryInformation = Record<string, AssetKey[]> | null | undefined;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
// findCircularDeps.ts
2+
import path from 'path';
3+
4+
import {Project} from 'ts-morph';
5+
6+
const project = new Project({
7+
tsConfigFilePath: 'tsconfig.json',
8+
});
9+
10+
const graph = new Map<string, Set<string>>();
11+
12+
for (const sourceFile of project.getSourceFiles()) {
13+
const filePath = sourceFile.getFilePath();
14+
const imports = sourceFile
15+
.getImportDeclarations()
16+
.filter((decl) => !decl.isTypeOnly())
17+
.map((decl) =>
18+
path.resolve(sourceFile.getDirectoryPath(), decl.getModuleSpecifierValue() + '.ts'),
19+
);
20+
graph.set(filePath, new Set(imports.filter((f) => project.getSourceFile(f))));
21+
}
22+
23+
const visited = new Set<string>();
24+
const stack = new Set<string>();
25+
26+
function dfs(node: string, pathStack: string[]) {
27+
if (stack.has(node)) {
28+
const cycleStart = pathStack.indexOf(node);
29+
const cycle = pathStack.slice(cycleStart).concat(node);
30+
const isGenerated = cycle.every((p) => p.includes('/generated/'));
31+
if (!isGenerated) {
32+
console.log('\nCircular dependency detected:');
33+
console.log(cycle.join(' -> '));
34+
}
35+
return;
36+
}
37+
38+
if (visited.has(node)) {
39+
return;
40+
}
41+
42+
visited.add(node);
43+
stack.add(node);
44+
pathStack.push(node);
45+
46+
for (const neighbor of graph.get(node) || []) {
47+
dfs(neighbor, pathStack);
48+
}
49+
50+
stack.delete(node);
51+
pathStack.pop();
52+
}
53+
54+
for (const node of graph.keys()) {
55+
dfs(node, []);
56+
}

0 commit comments

Comments
 (0)