@idomatic/parser-js 1.0.2 → 1.0.21
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 +26 -0
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -2,6 +2,7 @@ import fs from "fs";
|
|
|
2
2
|
import { parse, print, types } from "recast";
|
|
3
3
|
import { randomUUID } from "crypto";
|
|
4
4
|
import { createRequire } from "module";
|
|
5
|
+
import cheerio from "cheerio";
|
|
5
6
|
|
|
6
7
|
const require = createRequire(import.meta.url);
|
|
7
8
|
const b = types.builders;
|
|
@@ -38,6 +39,31 @@ export default function parseJS(filePath, config) {
|
|
|
38
39
|
|
|
39
40
|
return false;
|
|
40
41
|
},
|
|
42
|
+
// Process Angular inline templates defined in TS files
|
|
43
|
+
visitObjectProperty(path) {
|
|
44
|
+
if (
|
|
45
|
+
path.node.key.name === "template" &&
|
|
46
|
+
path.node.value.type === "StringLiteral"
|
|
47
|
+
) {
|
|
48
|
+
const templateValue = path.node.value.value;
|
|
49
|
+
|
|
50
|
+
const $ = cheerio.load(templateValue, { xmlMode: false });
|
|
51
|
+
|
|
52
|
+
$("*").each((i, elem) => {
|
|
53
|
+
const tagName = elem.tagName.toLowerCase();
|
|
54
|
+
const tagsToExclude = config.excludeTags || [];
|
|
55
|
+
if (tagsToExclude.includes(tagName)) return;
|
|
56
|
+
if (!$(elem).attr("id")) {
|
|
57
|
+
const idValue = `${config.prefix}${randomUUID()}`;
|
|
58
|
+
$(elem).attr("id", idValue);
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
const newTemplate = $.html();
|
|
63
|
+
path.node.value.value = newTemplate;
|
|
64
|
+
}
|
|
65
|
+
this.traverse(path);
|
|
66
|
+
},
|
|
41
67
|
});
|
|
42
68
|
|
|
43
69
|
const output = print(ast).code;
|