Skip to content

Commit 0ffe5ef

Browse files
committed
2 parents 22d14ef + f09e509 commit 0ffe5ef

File tree

5 files changed

+473
-2
lines changed

5 files changed

+473
-2
lines changed

.yarnrc

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
# yarn lockfile v1
33

44

5-
yarn-path ".yarn/releases/cli.js"
5+
yarn-path ".yarn/releases/yarn-1.18.0.js"

packages/react-components/react-link/library/package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@
4040
"@fluentui/react-theme": "^9.1.21",
4141
"@fluentui/react-utilities": "^9.18.16",
4242
"@griffel/react": "^1.5.22",
43-
"@swc/helpers": "^0.5.1"
43+
"@swc/helpers": "^0.5.1",
44+
"ts-morph": "24.0.0"
4445
},
4546
"peerDependencies": {
4647
"@types/react": ">=16.14.0 <19.0.0",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import { Project, SyntaxKind } from "ts-morph";
2+
import * as fs from "fs";
3+
4+
// Initialize a new project with ts-morph
5+
const project = new Project();
6+
const sourceFile = project.addSourceFileAtPath("useLinkStyles.styles.ts");
7+
8+
// Define the regex pattern
9+
const tokenPattern = /tokens\.[a-zA-Z0-9]+/gm;
10+
11+
// Function to recursively construct JSON structure for each node
12+
function constructNodeJSON(node) {
13+
// Check if node should be ignored
14+
const nodeKind = SyntaxKind[node.getKind()];
15+
16+
// Check if the node's text includes "tokens"
17+
if (!node.getText().includes("tokens.") || !node.getText().match(tokenPattern)) return null;
18+
19+
const nodeDetails = {
20+
kind: nodeKind,
21+
text: node.getText(),
22+
children: []
23+
};
24+
25+
// Recursively process each child node
26+
node.forEachChild((child) => {
27+
const childNode = constructNodeJSON(child);
28+
if (childNode) {
29+
nodeDetails.children.push(childNode);
30+
}
31+
});
32+
33+
return nodeDetails;
34+
}
35+
36+
// Construct JSON for the root node
37+
const astStructure = constructNodeJSON(sourceFile);
38+
39+
// Write results to LinkAST_output.json if the structure is valid
40+
if (astStructure) {
41+
fs.writeFileSync("LinkAST_output.json", JSON.stringify(astStructure, null, 2), "utf8");
42+
console.log("Output written to LinkAST_output.json");
43+
} else {
44+
console.log("No nodes found with 'tokens' in their text.");
45+
}

0 commit comments

Comments
 (0)