@idomatic/parser-js 1.0.0 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +8 -5
- package/package.json +5 -2
package/index.js
CHANGED
|
@@ -16,18 +16,22 @@ export default function parseJS(filePath, config) {
|
|
|
16
16
|
types.visit(ast, {
|
|
17
17
|
visitJSXOpeningElement(path) {
|
|
18
18
|
const tag = path.node.name.name;
|
|
19
|
+
const tagsToExclude = config.excludeTags || [];
|
|
20
|
+
if (tagsToExclude.includes(tag)) return false;
|
|
19
21
|
|
|
20
|
-
|
|
22
|
+
// For MVP, attributeName is hardcoded as "id"
|
|
23
|
+
const attributeName = "id";
|
|
21
24
|
|
|
22
25
|
const hasId = path.node.attributes.some(
|
|
23
|
-
(attr) => attr.name?.name ===
|
|
26
|
+
(attr) => attr.name?.name === attributeName
|
|
24
27
|
);
|
|
25
28
|
|
|
26
29
|
if (!hasId) {
|
|
30
|
+
const idValue = `${config.prefix}${randomUUID()}`;
|
|
27
31
|
path.node.attributes.push(
|
|
28
32
|
b.jsxAttribute(
|
|
29
|
-
b.jsxIdentifier(
|
|
30
|
-
b.stringLiteral(
|
|
33
|
+
b.jsxIdentifier(attributeName),
|
|
34
|
+
b.stringLiteral(idValue)
|
|
31
35
|
)
|
|
32
36
|
);
|
|
33
37
|
}
|
|
@@ -37,6 +41,5 @@ export default function parseJS(filePath, config) {
|
|
|
37
41
|
});
|
|
38
42
|
|
|
39
43
|
const output = print(ast).code;
|
|
40
|
-
|
|
41
44
|
fs.writeFileSync(filePath, output);
|
|
42
45
|
}
|
package/package.json
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@idomatic/parser-js",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "JS/TSX parser for idomatic CLI",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "index.js",
|
|
7
7
|
"exports": {
|
|
8
|
-
"
|
|
8
|
+
".": {
|
|
9
|
+
"import": "./index.js",
|
|
10
|
+
"require": "./index.js"
|
|
11
|
+
}
|
|
9
12
|
},
|
|
10
13
|
"keywords": [
|
|
11
14
|
"idomatic",
|