-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck_syntax.js
More file actions
41 lines (34 loc) · 1.13 KB
/
Copy pathcheck_syntax.js
File metadata and controls
41 lines (34 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
const fs = require('fs');
const content = fs.readFileSync('c:/Users/bingi/medo-veda/frontend/src/pages/AnalysisReport.jsx', 'utf8');
function checkJSX(code) {
let stack = [];
const tagRegex = /<(\/?[a-zA-Z0-9\.]+)(?:\s+[^>]*?)?(\/?)>/g;
let match;
while ((match = tagRegex.exec(code)) !== null) {
const tagName = match[1];
const isClosing = tagName.startsWith('/');
const isSelfClosing = match[2] === '/';
if (isSelfClosing) continue;
if (isClosing) {
const actualTag = tagName.substring(1);
if (stack.length === 0) {
console.log(`Error: Extra closing tag </${actualTag}> at index ${match.index}`);
return false;
}
const lastTag = stack.pop();
if (lastTag !== actualTag) {
console.log(`Error: Mismatched tag. Expected </${lastTag}> but found </${actualTag}> at index ${match.index}`);
return false;
}
} else {
stack.push(tagName);
}
}
if (stack.length > 0) {
console.log(`Error: Unclosed tags: ${stack.join(', ')}`);
return false;
}
console.log('JSX tags are balanced!');
return true;
}
checkJSX(content);