arche-highlight 0.3.1 → 0.4.1

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.
@@ -17,8 +17,8 @@ function testOperator(term) {
17
17
  return term == "+" || term == "-" || term == "*" || term == "/" || term == "**" || term == "=" || term == "+=" || term == "++" || term == "-=" || term == "*=" || term == "/=" || term == "**=" || term == "==" || term == "===" || term == "!=" || term == "!==" || term == ">" || term == ">=" || term == "<" || term == "<=" || term == "?" || term == ":" || term == "&&" || term == "||" || term == "??" || term == "&" || term == "|" || term == "^" || term == "~" || term == ">>" || term == "<<" || term == "&=" || term == "|=" || term == "^="
18
18
  }
19
19
 
20
- // pushWordTerm(parsedElements Array<object|string>, term string) -> ()
21
- function pushWordTerm(parsedElements, term) {
20
+ // pushWordTerm(parsedElements Array<object|string>, term string, index number, text string) -> ()
21
+ function pushWordTerm(parsedElements, term, index, text) {
22
22
  if (term == "process" || term == "require" || term == "console" || term == "window" || term == "global" || term == "globalThis" || term == "isNaN") {
23
23
  parsedElements.push(Span({ class: "global-object" }, term))
24
24
  } else if (term == "undefined") {
@@ -30,8 +30,21 @@ function pushWordTerm(parsedElements, term) {
30
30
  } else if (term == "NaN") {
31
31
  parsedElements.push(Span({ class: "not-a-number" }, term))
32
32
  } else {
33
- parsedElements.push(term)
33
+ const spaces = []
34
+ let c = text[index]
35
+ while (c === " " || c === "\n") {
36
+ spaces.push(c)
37
+ index += 1
38
+ c = text[index]
39
+ }
40
+ if (c === "(") {
41
+ parsedElements.push(Span({ class: "function-name" }, term))
42
+ } else {
43
+ parsedElements.push(term)
44
+ }
45
+ parsedElements.push(...spaces)
34
46
  }
47
+ return index
35
48
  }
36
49
 
37
50
  function parseJavaScript(text) {
@@ -236,7 +249,12 @@ function parseJavaScript(text) {
236
249
  }
237
250
  else {
238
251
  if (term.length > 0) {
239
- pushWordTerm(parsedElements, term, index, text)
252
+ index = pushWordTerm(parsedElements, term, index, text)
253
+ c = text[index]
254
+ if (c !== " " && c !== "\n") {
255
+ term = ""
256
+ continue
257
+ }
240
258
  }
241
259
  parsedElements.push(c)
242
260
  term = ""
package/ArcheHighlight.js CHANGED
@@ -23,8 +23,8 @@ function testOperator(term) {
23
23
  return term == "+" || term == "-" || term == "*" || term == "/" || term == "**" || term == "=" || term == "+=" || term == "++" || term == "-=" || term == "*=" || term == "/=" || term == "**=" || term == "==" || term == "===" || term == "!=" || term == "!==" || term == ">" || term == ">=" || term == "<" || term == "<=" || term == "?" || term == ":" || term == "&&" || term == "||" || term == "??" || term == "&" || term == "|" || term == "^" || term == "~" || term == ">>" || term == "<<" || term == "&=" || term == "|=" || term == "^="
24
24
  }
25
25
 
26
- // pushWordTerm(parsedElements Array<object|string>, term string) -> ()
27
- function pushWordTerm(parsedElements, term) {
26
+ // pushWordTerm(parsedElements Array<object|string>, term string, index number, text string) -> ()
27
+ function pushWordTerm(parsedElements, term, index, text) {
28
28
  if (term == "process" || term == "require" || term == "console" || term == "window" || term == "global" || term == "globalThis" || term == "isNaN") {
29
29
  parsedElements.push(Span({ class: "global-object" }, term))
30
30
  } else if (term == "undefined") {
@@ -36,8 +36,21 @@ function pushWordTerm(parsedElements, term) {
36
36
  } else if (term == "NaN") {
37
37
  parsedElements.push(Span({ class: "not-a-number" }, term))
38
38
  } else {
39
- parsedElements.push(term)
39
+ const spaces = []
40
+ let c = text[index]
41
+ while (c === " " || c === "\n") {
42
+ spaces.push(c)
43
+ index += 1
44
+ c = text[index]
45
+ }
46
+ if (c === "(") {
47
+ parsedElements.push(Span({ class: "function-name" }, term))
48
+ } else {
49
+ parsedElements.push(term)
50
+ }
51
+ parsedElements.push(...spaces)
40
52
  }
53
+ return index
41
54
  }
42
55
 
43
56
  function parseJavaScript(text) {
@@ -242,7 +255,12 @@ function parseJavaScript(text) {
242
255
  }
243
256
  else {
244
257
  if (term.length > 0) {
245
- pushWordTerm(parsedElements, term, index, text)
258
+ index = pushWordTerm(parsedElements, term, index, text)
259
+ c = text[index]
260
+ if (c !== " " && c !== "\n") {
261
+ term = ""
262
+ continue
263
+ }
246
264
  }
247
265
  parsedElements.push(c)
248
266
  term = ""
@@ -17,8 +17,8 @@ function testOperator(term) {
17
17
  return term == "+" || term == "-" || term == "*" || term == "/" || term == "**" || term == "=" || term == "+=" || term == "++" || term == "-=" || term == "*=" || term == "/=" || term == "**=" || term == "==" || term == "===" || term == "!=" || term == "!==" || term == ">" || term == ">=" || term == "<" || term == "<=" || term == "?" || term == ":" || term == "&&" || term == "||" || term == "??" || term == "&" || term == "|" || term == "^" || term == "~" || term == ">>" || term == "<<" || term == "&=" || term == "|=" || term == "^="
18
18
  }
19
19
 
20
- // pushWordTerm(parsedElements Array<object|string>, term string) -> ()
21
- function pushWordTerm(parsedElements, term) {
20
+ // pushWordTerm(parsedElements Array<object|string>, term string, index number, text string) -> ()
21
+ function pushWordTerm(parsedElements, term, index, text) {
22
22
  if (term == "process" || term == "require" || term == "console" || term == "window" || term == "global" || term == "globalThis" || term == "isNaN") {
23
23
  parsedElements.push(Span({ class: "global-object" }, term))
24
24
  } else if (term == "undefined") {
@@ -30,8 +30,21 @@ function pushWordTerm(parsedElements, term) {
30
30
  } else if (term == "NaN") {
31
31
  parsedElements.push(Span({ class: "not-a-number" }, term))
32
32
  } else {
33
- parsedElements.push(term)
33
+ const spaces = []
34
+ let c = text[index]
35
+ while (c === " " || c === "\n") {
36
+ spaces.push(c)
37
+ index += 1
38
+ c = text[index]
39
+ }
40
+ if (c === "(") {
41
+ parsedElements.push(Span({ class: "function-name" }, term))
42
+ } else {
43
+ parsedElements.push(term)
44
+ }
45
+ parsedElements.push(...spaces)
34
46
  }
47
+ return index
35
48
  }
36
49
 
37
50
  function parseJavaScript(text) {
@@ -236,7 +249,12 @@ function parseJavaScript(text) {
236
249
  }
237
250
  else {
238
251
  if (term.length > 0) {
239
- pushWordTerm(parsedElements, term, index, text)
252
+ index = pushWordTerm(parsedElements, term, index, text)
253
+ c = text[index]
254
+ if (c !== " " && c !== "\n") {
255
+ term = ""
256
+ continue
257
+ }
240
258
  }
241
259
  parsedElements.push(c)
242
260
  term = ""
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "arche-highlight",
3
- "version": "0.3.1",
3
+ "version": "0.4.1",
4
4
  "description": "Syntax highlighting for vanilla microfrontends",
5
5
  "author": "Richard Tong",
6
6
  "license": "CFOSS",