olum-compiler 1.5.0 → 1.6.0

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.
Files changed (48) hide show
  1. package/.claude/settings.local.json +2 -1
  2. package/bin/build.js +1 -1
  3. package/bin/bundle.js +32 -30
  4. package/bin/compiler.js +20 -10
  5. package/bin/copySrc.js +45 -41
  6. package/bin/dev.js +46 -39
  7. package/bin/index.js +6 -4
  8. package/bin/server.js +58 -33
  9. package/bin/watcher.js +11 -14
  10. package/bin/ws.js +16 -11
  11. package/lib/attr.js +1 -25
  12. package/lib/boolAttr.js +32 -15
  13. package/lib/chokidar.js +52 -101
  14. package/lib/colors.js +1 -7
  15. package/lib/compPlaceholder.js +5 -3
  16. package/lib/compiler.js +3 -6
  17. package/lib/coreLibs.js +1 -10
  18. package/lib/cross-spawn.js +45 -59
  19. package/lib/cssParser.js +61 -37
  20. package/lib/domEvents.js +6 -2
  21. package/lib/events.js +75 -77
  22. package/lib/for.js +56 -28
  23. package/lib/getImports.js +35 -17
  24. package/lib/getTempPath.js +8 -4
  25. package/lib/helpers.js +289 -184
  26. package/lib/html.js +3 -10
  27. package/lib/htmlParser.js +45 -45
  28. package/lib/if.js +40 -20
  29. package/lib/importMap.js +49 -24
  30. package/lib/jsParser.js +8 -13
  31. package/lib/lineCounter.js +18 -5
  32. package/lib/liveProps.js +124 -78
  33. package/lib/log.js +30 -0
  34. package/lib/magic-string.js +45 -52
  35. package/lib/models.js +8 -7
  36. package/lib/parser.js +76 -44
  37. package/lib/placeholder.js +73 -58
  38. package/lib/regex.js +4 -3
  39. package/lib/show.js +16 -8
  40. package/lib/sourcemap.js +23 -24
  41. package/lib/styles.js +7 -13
  42. package/lib/textarea.js +3 -6
  43. package/lib/toJs.js +1 -1
  44. package/lib/tokens.js +10 -22
  45. package/lib/transition.js +86 -0
  46. package/lib/websocket.js +68 -62
  47. package/package.json +1 -1
  48. package/tests/compiler.test.js +423 -188
package/lib/html.js CHANGED
@@ -1,20 +1,13 @@
1
1
  const { RAW_OPEN, RAW_CLOSE, shieldOps } = require("./tokens");
2
2
 
3
- // `html="expr"` — render the expression as UNESCAPED HTML, replacing the element's content
4
- // (like Vue's v-html / React's dangerouslySetInnerHTML). It's a "code attribute": the "" holds a
5
- // JS expression. Output is a raw `${expr}` interpolation (NOT wrapped in olum.esc), so use it only
6
- // on trusted/sanitized HTML. The per-value primitive olum.html(x) still exists for inline/mixed use.
7
- //
8
- // Runs before the control-flow handlers (which dissolve elements into template text), so an html
9
- // element inside <for>/<if> is rewritten while it's still a real DOM node.
10
3
  function handleHtml(body) {
11
4
  const elms = new Array().slice.call(body.querySelectorAll("[html]"));
12
5
  elms.forEach((item) => {
13
- const expr = shieldOps((item.getAttribute("html") || "").trim()); // protect <,> from the DOM round-trip
6
+ const expr = shieldOps((item.getAttribute("html") || "").trim());
14
7
  item.removeAttribute("html");
15
8
  if (!expr) return;
16
- const encoded = expr.replace(/{/g, "&lt;-olum-&gt;"); // hide JS braces from the {expr} escape pass
17
- item.innerHTML = RAW_OPEN + encoded + RAW_CLOSE; // raw ${expr} — replaces the element's content
9
+ const encoded = expr.replace(/{/g, "&lt;-olum-&gt;");
10
+ item.innerHTML = RAW_OPEN + encoded + RAW_CLOSE;
18
11
  });
19
12
  }
20
13
 
package/lib/htmlParser.js CHANGED
@@ -6,38 +6,50 @@ const handleIfStatement = require("./if");
6
6
  const handleForStatement = require("./for");
7
7
  const handleShowStatement = require("./show");
8
8
  const handleEvents = require("./events");
9
- // const handleStyles = require("./styles");
10
- // const handleModels = require("./models");
11
- // const handleAttr = require("./attr");
9
+
12
10
  const handleCompPlaceholder = require("./compPlaceholder");
13
11
  const handleHtml = require("./html");
12
+ const handleLog = require("./log");
13
+ const handleTransition = require("./transition");
14
14
  const handleBoolAttrs = require("./boolAttr");
15
15
  const handleTextarea = require("./textarea");
16
- const { RAW_OPEN, RAW_CLOSE, LT, GT, shieldTags, unshieldTags } = require("./tokens");
16
+ const {
17
+ RAW_OPEN,
18
+ RAW_CLOSE,
19
+ LT,
20
+ GT,
21
+ QUOT,
22
+ shieldTags,
23
+ unshieldTags,
24
+ } = require("./tokens");
17
25
 
18
26
  function htmlparser(str, counter, filePath, parentMethods, propsAliases) {
19
- let content = str.replace(script, "").replace(style, "");
20
- content = clean(content); // clean html comments to avoid runtime errors
21
- content = placeholder(content, selfClosingTag, "self", parentMethods, propsAliases);
22
- content = placeholder(content, normalTag, "normal", parentMethods, propsAliases);
27
+ let content = clean(str);
28
+ content = content.replace(script, "").replace(style, "");
29
+ content = placeholder(
30
+ content,
31
+ selfClosingTag,
32
+ "self",
33
+ parentMethods,
34
+ propsAliases,
35
+ );
36
+ content = placeholder(
37
+ content,
38
+ normalTag,
39
+ "normal",
40
+ parentMethods,
41
+ propsAliases,
42
+ );
23
43
 
24
- // Inline arrow/function event handlers (oninput="(e)=> expr") are extracted into named
25
- // __olumAnon_ methods inside handleEvents (collected here, injected into the component JS later).
26
44
  const anonHandlers = [];
27
45
 
28
- // using dom parser — shieldTags renames parser-restricted containers (select/table/tr/…) to
29
- // unknown elements so a <for>/<if>/<show> inside them survives the parse; restored after serialize
30
46
  const body = new jsdom.JSDOM(shieldTags(content)).window.document.body;
31
- handleHtml(body); // html="expr" -> unescaped ${expr} content (before control-flow dissolves elements)
32
- handleTextarea(body); // textarea value="..." -> text content (no value attribute exists on textarea)
47
+ handleHtml(body);
48
+ handleLog(body, counter, filePath);
49
+ handleTransition(body, counter, filePath);
50
+ handleTextarea(body);
33
51
  handleEvents(body, counter, filePath, anonHandlers, propsAliases);
34
- // DISABLED — :style object binding. Colon attributes are gone; use a string style with
35
- // {expr} interpolation instead, e.g. style="color:{state.color}". Uncomment to re-enable.
36
- // handleStyles(body, counter, filePath);
37
- // handleAttr(body, counter, filePath);
38
- // DISABLED — `model` two-way binding. Bind manually instead: value="{state.x}" + an
39
- // oninput handler that writes state.x. Uncomment to re-enable.
40
- // handleModels(body, counter, filePath);
52
+
41
53
  handleIfStatement(body, counter, filePath);
42
54
  handleForStatement(body, counter, filePath);
43
55
  handleShowStatement(body, counter, filePath);
@@ -45,41 +57,29 @@ function htmlparser(str, counter, filePath, parentMethods, propsAliases) {
45
57
 
46
58
  content = unshieldTags(body.innerHTML);
47
59
 
48
- // presence-based boolean attributes: checked="{expr}" -> ${(expr) ? "checked" : ""}.
49
- // Must run before the {expr} escape pass below, which would otherwise interpolate the VALUE
50
- // (checked="false" is still checked — the browser only checks attribute presence).
51
60
  content = handleBoolAttrs(content);
52
61
 
53
- // #2 (escape-by-default): at this point every literal `{expr}` left in the markup is a USER value
54
- // interpolation (text like `{props.todo.text}` or a simple attribute like `id="todo-{x.id}"`).
55
- // Control-flow interpolations were emitted with RAW_OPEN/RAW_CLOSE sentinels instead of braces,
56
- // and nested function-body / object-literal braces are entity-encoded as `<-olum->`, so neither
57
- // appears as a literal `{` here. Wrapping each remaining `{expr}` in `olum.esc(...)` therefore
58
- // escapes user-facing output (preventing XSS and "special characters break the page" bugs) while
59
- // leaving structural code untouched. `[^{}]+` keeps each match to a single, non-nested pair.
60
- // slot content (`children` and `props().children`) is trusted markup authored in the parent
61
- // template, not user input, so it is emitted RAW (no esc) — escaping it would show its tags as text.
62
62
  content = content.replace(/\{([^{}]+)\}/g, (match, expr) => {
63
63
  const raw = expr.trim();
64
64
  if (raw === "children") return "${children}";
65
65
  if (/^props\(\s*\)\.children$/.test(raw)) return "${" + raw + "}";
66
- // the captured expr is JS, but if it sat in a TEXT node jsdom entity-encoded its <,>,& on
67
- // serialize — decode them back so comparisons like {width > 380 ? a : b} stay valid JS
68
- const js = expr.replace(/&lt;/g, "<").replace(/&gt;/g, ">").replace(/&amp;/g, "&");
66
+
67
+ const js = expr
68
+ .replace(/&lt;/g, "<")
69
+ .replace(/&gt;/g, ">")
70
+ .replace(/&amp;/g, "&");
69
71
  return "${olum.esc(" + js + ")}";
70
72
  });
71
73
 
72
- content = content.replace(/&amp;/g, "&"); // fix entity
73
- content = content.replace(/=&gt;/g, "=>"); // preserve arrow functions
74
- content = content.replace(/&lt;-olum-&gt;|&amp;lt;-olum-&amp;gt;/g, "{"); // fix curly braces sign
75
- content = content.split(LT).join("<").split(GT).join(">"); // restore shielded <,> in directive expressions
74
+ content = content.replace(/&amp;/g, "&");
75
+ content = content.replace(/=&gt;/g, "=>");
76
+ content = content.replace(/&lt;-olum-&gt;|&amp;lt;-olum-&amp;gt;/g, "{");
77
+ content = content.split(LT).join("<").split(GT).join(">");
78
+ content = content.split(QUOT).join('"');
76
79
 
77
- // #2: structural (compiler-generated) interpolations produce raw HTML, so emit them as plain
78
- // `${...}` WITHOUT esc(). Done after the escape pass so user braces are already handled.
79
80
  content = content.split(RAW_OPEN).join("${").split(RAW_CLOSE).join("}");
80
- // todo check if var html is empty string then return nothing for better performance
81
- // return "__template__() {\n var html = `\n" + content.trim() + "`;\nvar data = olum.lifeCycle.temp(this, html);\nolum.handelEvents(data.$wrapper,this);\nreturn data;\n},";
82
- return {html: content.trim(), comps, anonHandlers};
81
+
82
+ return { html: content.trim(), comps, anonHandlers };
83
83
  }
84
84
 
85
85
  module.exports = htmlparser;
package/lib/if.js CHANGED
@@ -3,27 +3,35 @@ const { RAW_OPEN, RAW_CLOSE, shieldOps } = require("./tokens");
3
3
 
4
4
  function hasElseIfOrElse(node) {
5
5
  const nextNode = node.nextElementSibling;
6
- if (nextNode && (nextNode.nodeName === "ELSE-IF" || nextNode.nodeName === "ELSE")) {
6
+ if (
7
+ nextNode &&
8
+ (nextNode.nodeName === "ELSE-IF" || nextNode.nodeName === "ELSE")
9
+ ) {
7
10
  return nextNode;
8
11
  }
9
12
  return false;
10
13
  }
11
14
 
12
15
  function handleIfStatement(body, counter, filePath) {
13
- const ifElms = new Array().slice.call(body.querySelectorAll("if")).reverse(); // we must reverse to start with the very deep if tag which doesn't have nested if tags inside it
14
- ifElms.forEach(item => {
15
- // console.log(item.outerHTML + "\n----------");
16
+ const ifElms = new Array().slice.call(body.querySelectorAll("if")).reverse();
17
+ ifElms.forEach((item) => {
16
18
  if (item.hasAttribute("when")) {
17
- // `when` is a plain JS expression (no braces): <if when="state.n > 0">
18
- // shieldOps: protect <,> from the jsdom text round-trip (restored in htmlParser)
19
19
  const condition = shieldOps(item.getAttribute("when").trim());
20
20
 
21
- // start: store if statement value in olum tag
22
21
  const olums = item.querySelectorAll("olum");
23
- // Structural interpolation -> RAW_OPEN/RAW_CLOSE so #2's escape pass leaves it raw (it yields
24
- // the JSON "true"/"false" the runtime reads from the `if` attribute, not user-facing text).
25
- olums.forEach(olum => olum.setAttribute("if","-[[-"+ RAW_OPEN +"JSON.stringify(!!"+ condition + ")"+ RAW_CLOSE +"-]]-")); // convert condition value to truthy/falsy value
26
- // end: store if statement value in olum tag
22
+
23
+ olums.forEach((olum) =>
24
+ olum.setAttribute(
25
+ "if",
26
+ "-[[-" +
27
+ RAW_OPEN +
28
+ "JSON.stringify(!!" +
29
+ condition +
30
+ ")" +
31
+ RAW_CLOSE +
32
+ "-]]-",
33
+ ),
34
+ );
27
35
 
28
36
  const innerContent = item.innerHTML;
29
37
 
@@ -32,29 +40,41 @@ function handleIfStatement(body, counter, filePath) {
32
40
  let nodesArr = [{ content: innerContent, when: condition }];
33
41
  function recursive(item) {
34
42
  const node = hasElseIfOrElse(item);
35
- nodesArr.push({ content: node.innerHTML, when: shieldOps((node.getAttribute("when") || "").trim()) });
43
+ nodesArr.push({
44
+ content: node.innerHTML,
45
+ when: shieldOps((node.getAttribute("when") || "").trim()),
46
+ });
36
47
  toBeRemovedArr.push(node);
37
48
  if (hasElseIfOrElse(node)) recursive(node);
38
49
  }
39
50
  recursive(item);
40
- // console.log(nodesArr);
41
- // RAW_OPEN/RAW_CLOSE mark the structural interpolation braces so #2's escape pass keeps the
42
- // ternary raw (its branches return HTML). User braces inside each branch are still escaped.
51
+
43
52
  let ternaryOperator = RAW_OPEN;
44
53
  nodesArr.forEach((node, index) => {
45
54
  if (index === nodesArr.length - 1) {
46
- if (node.when) ternaryOperator += node.when + "?`" + node.content + "`:''" + RAW_CLOSE;
55
+ if (node.when)
56
+ ternaryOperator +=
57
+ node.when + "?`" + node.content + "`:''" + RAW_CLOSE;
47
58
  else ternaryOperator += "`" + node.content + "`" + RAW_CLOSE;
48
59
  } else {
49
60
  ternaryOperator += node.when + "?`" + node.content + "`:";
50
61
  }
51
62
  });
52
- // console.log(ternaryOperator);
63
+
53
64
  item.insertAdjacentHTML("beforebegin", ternaryOperator);
54
- toBeRemovedArr.forEach(item => item.remove());
65
+ toBeRemovedArr.forEach((item) => item.remove());
55
66
  } else {
56
- // RAW_OPEN/RAW_CLOSE: structural ternary (raw HTML); user braces in innerContent stay escaped.
57
- item.insertAdjacentHTML("beforebegin", RAW_OPEN + condition + "?" + "`" + innerContent + "`" + ":''" + RAW_CLOSE);
67
+ item.insertAdjacentHTML(
68
+ "beforebegin",
69
+ RAW_OPEN +
70
+ condition +
71
+ "?" +
72
+ "`" +
73
+ innerContent +
74
+ "`" +
75
+ ":''" +
76
+ RAW_CLOSE,
77
+ );
58
78
  }
59
79
  item.remove();
60
80
  } else {
package/lib/importMap.js CHANGED
@@ -3,9 +3,8 @@ const path = require("path");
3
3
  const colors = require("./colors");
4
4
  const { ls, isFile } = require("./helpers");
5
5
 
6
- const { useLocalCore, localLibs } = require("./coreLibs"); // shared flag — keeps main.js and the import map on the same runtime copy
6
+ const { useLocalCore, localLibs } = require("./coreLibs");
7
7
 
8
- // pick the browser-usable file from a package.json "exports" condition tree
9
8
  function pickEntry(exp) {
10
9
  if (typeof exp === "string") return exp;
11
10
  if (Array.isArray(exp)) {
@@ -27,11 +26,16 @@ function pickEntry(exp) {
27
26
  }
28
27
 
29
28
  function resolvePackage(rootDir, pkgName) {
30
- const pkgJsonPath = path.join(rootDir, "node_modules", pkgName, "package.json");
29
+ const pkgJsonPath = path.join(
30
+ rootDir,
31
+ "node_modules",
32
+ pkgName,
33
+ "package.json",
34
+ );
31
35
  if (!fs.existsSync(pkgJsonPath)) return null;
32
36
  const pkg = JSON.parse(fs.readFileSync(pkgJsonPath, "utf8"));
33
37
  let exp = pkg.exports;
34
- // subpath map ("." keys) vs plain condition object — take the root subpath
38
+
35
39
  if (exp && typeof exp === "object" && !Array.isArray(exp)) {
36
40
  const keys = Object.keys(exp);
37
41
  if (keys.some((k) => k.startsWith("."))) exp = exp["."];
@@ -41,17 +45,19 @@ function resolvePackage(rootDir, pkgName) {
41
45
  return "/node_modules/" + pkgName + "/" + entry;
42
46
  }
43
47
 
44
- // collect bare specifiers used in src: from "pkg" | import "pkg" | import("pkg")
45
48
  function getBareSpecifiers(srcDir) {
46
49
  const specifiers = new Set();
47
- const files = ls(srcDir, { absolute: true }).filter((p) => isFile(p) && /\.(html|js)$/i.test(p));
50
+ const files = ls(srcDir, { absolute: true }).filter(
51
+ (p) => isFile(p) && /\.(html|js)$/i.test(p),
52
+ );
48
53
  const regex = /(?:from\s+|import\s+|import\s*\(\s*)["']([^"'\n]+)["']/g;
49
54
  files.forEach((file) => {
50
55
  const content = fs.readFileSync(file, "utf8");
51
56
  let match;
52
57
  while ((match = regex.exec(content))) {
53
58
  const spec = match[1];
54
- if (spec.startsWith(".") || spec.startsWith("/") || /^https?:/.test(spec)) continue;
59
+ if (spec.startsWith(".") || spec.startsWith("/") || /^https?:/.test(spec))
60
+ continue;
55
61
  specifiers.add(spec);
56
62
  }
57
63
  });
@@ -60,44 +66,59 @@ function getBareSpecifiers(srcDir) {
60
66
 
61
67
  function toPkgName(specifier) {
62
68
  const segments = specifier.split("/");
63
- return specifier.startsWith("@") ? segments.slice(0, 2).join("/") : segments[0];
69
+ return specifier.startsWith("@")
70
+ ? segments.slice(0, 2).join("/")
71
+ : segments[0];
64
72
  }
65
73
 
66
- // map a package AND its transitive deps — a package's own ESM files import their deps as bare
67
- // specifiers too (d3-scale imports "d3-array"), and the browser resolves those via the import map
68
74
  function addPackage(rootDir, pkgName, imports) {
69
75
  if (imports[pkgName]) return;
70
76
  const entry = resolvePackage(rootDir, pkgName);
71
77
  if (!entry) {
72
- console.warn(colors("yellow", 'Can\'t resolve "' + pkgName + '" — install it at the project root: npm i ' + pkgName));
78
+ console.warn(
79
+ colors(
80
+ "yellow",
81
+ "Can't resolve \"" +
82
+ pkgName +
83
+ '" — install it at the project root: npm i ' +
84
+ pkgName,
85
+ ),
86
+ );
73
87
  return;
74
88
  }
75
89
  imports[pkgName] = entry;
76
- imports[pkgName + "/"] = "/node_modules/" + pkgName + "/"; // subpath imports e.g. "pkg/x.js"
77
- const pkgJsonPath = path.join(rootDir, "node_modules", pkgName, "package.json");
90
+ imports[pkgName + "/"] = "/node_modules/" + pkgName + "/";
91
+ const pkgJsonPath = path.join(
92
+ rootDir,
93
+ "node_modules",
94
+ pkgName,
95
+ "package.json",
96
+ );
78
97
  const pkg = JSON.parse(fs.readFileSync(pkgJsonPath, "utf8"));
79
- Object.keys(pkg.dependencies || {}).forEach((dep) => addPackage(rootDir, dep, imports));
98
+ Object.keys(pkg.dependencies || {}).forEach((dep) =>
99
+ addPackage(rootDir, dep, imports),
100
+ );
80
101
  }
81
102
 
82
- /**
83
- * Build the <script type="importmap"> tag injected into index.html so bare imports
84
- * (e.g. import { marked } from "marked") resolve in the browser without a bundler.
85
- * App deps install at the project root (rootDir = srcDir/..); framework libs map to /core.
86
- * @param {*} srcDir absolute path of the project's src directory
87
- */
88
103
  function importMap(srcDir) {
89
104
  const rootDir = path.resolve(srcDir, "..");
90
105
  const imports = {};
91
106
 
92
- // handle internal libs
93
107
  if (useLocalCore) {
94
108
  Object.assign(imports, localLibs);
95
109
  } else {
96
- // npm mode: the framework resolves like any other root dependency
97
110
  Object.keys(localLibs).forEach((pkgName) => {
98
111
  const entry = resolvePackage(rootDir, pkgName);
99
112
  if (!entry) {
100
- console.warn(colors("yellow", 'Can\'t resolve "' + pkgName + '" — install it at the project root: npm i ' + pkgName));
113
+ console.warn(
114
+ colors(
115
+ "yellow",
116
+ "Can't resolve \"" +
117
+ pkgName +
118
+ '" — install it at the project root: npm i ' +
119
+ pkgName,
120
+ ),
121
+ );
101
122
  return;
102
123
  }
103
124
  imports[pkgName] = entry;
@@ -110,7 +131,11 @@ function importMap(srcDir) {
110
131
  if (pkgName in localLibs) return;
111
132
  addPackage(rootDir, pkgName, imports);
112
133
  });
113
- return '<script type="importmap">' + JSON.stringify({ imports }, null, 2) + "</script>";
134
+ return (
135
+ '<script type="importmap">' +
136
+ JSON.stringify({ imports }, null, 2) +
137
+ "</script>"
138
+ );
114
139
  }
115
140
 
116
141
  module.exports = importMap;
package/lib/jsParser.js CHANGED
@@ -6,27 +6,22 @@ function jsParser(str) {
6
6
  str = clean(str);
7
7
  const arr = str.match(script);
8
8
  let content = Array.isArray(arr) && arr.length ? arr[0] : "";
9
-
10
- // fill empty logic to make component works if there is no script tag
11
- // if (content === "") return `__isInitial__: true,\n__render__(obj, prop) { olum.lifeCycle.render(obj, prop); },\n};`;
12
-
13
- // handle script tag attributes
9
+
14
10
  const attrsObj = {};
15
- if(content !== "") {
11
+ if (content !== "") {
16
12
  const dom = new jsdom.JSDOM(content).window.document;
17
13
  const scriptElm = dom.querySelector("script");
18
14
  const attrs = scriptElm.getAttributeNames();
19
- if (attrs.length) attrs.forEach(key =>attrsObj[key] = scriptElm.getAttribute(key))
20
- // console.warn(attrsObj);
15
+ if (attrs.length)
16
+ attrs.forEach((key) => (attrsObj[key] = scriptElm.getAttribute(key)));
21
17
  }
22
18
 
23
19
  content = content.replace(/(<script.*>)/, "");
24
20
  content = content.replace(/(<\/script>)$/, "");
25
- content = content.replace(/onMount\(/, "var mounted = onMount("); // handle onMount hook if imported -- wrape it to another name (mounted) to continue the old flow
26
- // content = content.replace(exportDefault, "").trim();
27
- // return "__isInitial__: true,\n__render__(obj, prop) { olum.lifeCycle.render(obj, prop); },\n" + content;
28
- content = content.replace(/const state/g, "var state"); // todo make this solid
29
- return {js: content, jsAttrs: attrsObj};
21
+ content = content.replace(/onMount\(/, "var mounted = onMount(");
22
+
23
+ content = content.replace(/const state/g, "var state");
24
+ return { js: content, jsAttrs: attrsObj };
30
25
  }
31
26
 
32
27
  module.exports = jsParser;
@@ -2,24 +2,37 @@ const colors = require("./colors");
2
2
  const fs = require("fs");
3
3
  const path = require("path");
4
4
 
5
- const lineCounter = str => str.split("\n").map(line => line);
5
+ const lineCounter = (str) => str.split("\n").map((line) => line);
6
6
 
7
7
  function getLineInfo(counter, item, filePath, msg) {
8
8
  const portion = item.outerHTML.split("\n")[0].trim();
9
9
  counter.forEach((line, index) => {
10
10
  index = index + 1;
11
11
  const origin = line;
12
- line = line.replace(/(\s+)?\/\>/g, ">").trim(); // fix jsdom bug which removes self closing tag
12
+ line = line.replace(/(\s+)?\/\>/g, ">").trim();
13
13
  if (line === portion) {
14
14
  const log =
15
15
  colors("yellow.bold", "\n<<Olum Warning>>\n") +
16
- colors("yellow", " File: " + filePath + "\n Line: " + index + "\n " + msg + "\n") +
16
+ colors(
17
+ "yellow",
18
+ " File: " + filePath + "\n Line: " + index + "\n " + msg + "\n",
19
+ ) +
17
20
  colors("red", " " + origin.trim()) +
18
21
  "\n";
19
22
  console.warn(log);
20
23
 
21
- // append logs to log.txt
22
- const _log = "\n<<Olum Warning>>\n" + " File: " + filePath + "\n Line: " + index + "\n " + msg + "\n" + " " + origin.trim() + "\n";
24
+ const _log =
25
+ "\n<<Olum Warning>>\n" +
26
+ " File: " +
27
+ filePath +
28
+ "\n Line: " +
29
+ index +
30
+ "\n " +
31
+ msg +
32
+ "\n" +
33
+ " " +
34
+ origin.trim() +
35
+ "\n";
23
36
  const logFilePath = path.resolve(__dirname, "./log.txt");
24
37
  if (!fs.existsSync(logFilePath)) fs.writeFileSync(logFilePath, "");
25
38
  fs.appendFileSync(logFilePath, _log);