arche-highlight 0.6.1 → 0.6.3

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.
@@ -6,12 +6,6 @@ function testOperatorSymbol(c) {
6
6
  return c === "+" || c === "-" || c === "*" || c === "/" || c === "=" || c === "&" || c === "|" || c === "<" || c === ">" || c === "~" || c === "^" || c === "!" || c === "?" || c === ":"
7
7
  }
8
8
 
9
- // testComment(term string) -> boolean
10
- function testComment(term) {
11
- return (term[0] === "/" && term[1] === "/")
12
- || (term[0] === "/" && term[1] === "*")
13
- }
14
-
15
9
  // pushWordTerm(parsedElements Array<object|string>, term string, index number, text string) -> ()
16
10
  function pushWordTerm(parsedElements, term, index, text) {
17
11
  if (term == "process" || term == "require" || term == "console" || term == "window" || term == "global" || term == "globalThis" || term == "isNaN") {
@@ -99,21 +93,21 @@ function parseJavaScript(text) {
99
93
  parsedElements.push(Span({ class: "operator" }, term))
100
94
  }
101
95
  term = ""
102
- } else if (isStringSingleQuote && c === "'") {
96
+ } else if (isStringSingleQuote && c === "'" && term[term.length - 1] !== "\\") {
103
97
  isStringSingleQuote = false
104
98
  term += c
105
99
  index += 1
106
100
  c = text[index]
107
101
  parsedElements.push(Span({ class: "string" }, term))
108
102
  term = ""
109
- } else if (isStringDoubleQuote && c === "\"") {
103
+ } else if (isStringDoubleQuote && c === "\"" && term[term.length - 1] !== "\\") {
110
104
  isStringDoubleQuote = false
111
105
  term += c
112
106
  index += 1
113
107
  c = text[index]
114
108
  parsedElements.push(Span({ class: "string" }, term))
115
109
  term = ""
116
- } else if (isTemplateLiteral && c === "`") {
110
+ } else if (isTemplateLiteral && c === "`" && term[term.length - 1] !== "\\") {
117
111
  isTemplateLiteral = false
118
112
  term += c
119
113
  index += 1
@@ -122,6 +116,10 @@ function parseJavaScript(text) {
122
116
  term = ""
123
117
  }
124
118
 
119
+ if (index == text.length) {
120
+ break
121
+ }
122
+
125
123
  if (isSingleLineComment) {
126
124
  term += c
127
125
  index += 1
@@ -157,6 +155,7 @@ function parseJavaScript(text) {
157
155
  term = ""
158
156
  index += 1
159
157
  } else {
158
+ term += templateVariable
160
159
  term += c
161
160
  index += 1
162
161
  }
@@ -187,16 +186,6 @@ function parseJavaScript(text) {
187
186
  isOperator = true
188
187
  term = c
189
188
  index += 1
190
- } else if (c === ":") {
191
- parsedElements.push(term)
192
- if (isTernaryOperator) {
193
- parsedElements.push(Span({ class: "operator" }, term))
194
- isTernaryOperator = false
195
- } else {
196
- parsedElements.push(Span({ class: "object-colon" }, c))
197
- }
198
- term = ""
199
- index += 1
200
189
  } else if (term.length == 0 && c === "'") {
201
190
  isStringSingleQuote = true
202
191
  term += c
@@ -218,7 +207,7 @@ function parseJavaScript(text) {
218
207
  parsedElements.push(c)
219
208
  term = ""
220
209
  index += 1
221
- } else if (term == "import" || term == "new" || term == "async" || term == "await" || term == "for" || term == "while" || term == "of") {
210
+ } else if (term == "import" || term == "new" || term == "async" || term == "await" || term == "for" || term == "while" || term == "of" || term == "from") {
222
211
  parsedElements.push(Span({ class: "keyword" }, term))
223
212
  parsedElements.push(c)
224
213
  term = ""
@@ -229,20 +218,13 @@ function parseJavaScript(text) {
229
218
  parsedElements.push(c)
230
219
  term = ""
231
220
  index += 1
232
- } else if (/^\d+$/.test(term)) {
233
- parsedElements.push(Span({ class: "number" }, term))
234
- parsedElements.push(c)
235
- term = ""
236
- index += 1
237
- }
238
- else if (isFunctionDeclaration) {
221
+ } else if (isFunctionDeclaration) {
239
222
  isFunctionDeclaration = false
240
223
  parsedElements.push(Span({ class: "function-name" }, term))
241
224
  parsedElements.push(c)
242
225
  term = ""
243
226
  index += 1
244
- }
245
- else {
227
+ } else {
246
228
  if (term.length > 0) {
247
229
  index = pushWordTerm(parsedElements, term, index, text)
248
230
  c = text[index]
@@ -273,8 +255,7 @@ function parseJavaScript(text) {
273
255
  parsedElements.push(Span({ class: "spread-operator" }, term))
274
256
  }
275
257
  term = ""
276
- }
277
- else if (c === "(") {
258
+ } else if (c === "(") {
278
259
  if (term === "") {
279
260
  // skip
280
261
  } else if (term == "require" || term == "isNaN") {
@@ -339,6 +320,14 @@ function parseJavaScript(text) {
339
320
  if (term.length > 0) {
340
321
  if (isSingleLineComment) {
341
322
  parsedElements.push(Span({ class: "comment" }, term))
323
+ } else if (isNumber) {
324
+ if (term[term.length - 1] === "n") {
325
+ parsedElements.push(Span({ class: "bigint" }, term))
326
+ } else if (term.includes("n")) {
327
+ parsedElements.push(term)
328
+ } else {
329
+ parsedElements.push(Span({ class: "number" }, term))
330
+ }
342
331
  } else {
343
332
  pushWordTerm(parsedElements, term, index, text)
344
333
  }
package/ArcheHighlight.js CHANGED
@@ -12,12 +12,6 @@ function testOperatorSymbol(c) {
12
12
  return c === "+" || c === "-" || c === "*" || c === "/" || c === "=" || c === "&" || c === "|" || c === "<" || c === ">" || c === "~" || c === "^" || c === "!" || c === "?" || c === ":"
13
13
  }
14
14
 
15
- // testComment(term string) -> boolean
16
- function testComment(term) {
17
- return (term[0] === "/" && term[1] === "/")
18
- || (term[0] === "/" && term[1] === "*")
19
- }
20
-
21
15
  // pushWordTerm(parsedElements Array<object|string>, term string, index number, text string) -> ()
22
16
  function pushWordTerm(parsedElements, term, index, text) {
23
17
  if (term == "process" || term == "require" || term == "console" || term == "window" || term == "global" || term == "globalThis" || term == "isNaN") {
@@ -105,21 +99,21 @@ function parseJavaScript(text) {
105
99
  parsedElements.push(Span({ class: "operator" }, term))
106
100
  }
107
101
  term = ""
108
- } else if (isStringSingleQuote && c === "'") {
102
+ } else if (isStringSingleQuote && c === "'" && term[term.length - 1] !== "\\") {
109
103
  isStringSingleQuote = false
110
104
  term += c
111
105
  index += 1
112
106
  c = text[index]
113
107
  parsedElements.push(Span({ class: "string" }, term))
114
108
  term = ""
115
- } else if (isStringDoubleQuote && c === "\"") {
109
+ } else if (isStringDoubleQuote && c === "\"" && term[term.length - 1] !== "\\") {
116
110
  isStringDoubleQuote = false
117
111
  term += c
118
112
  index += 1
119
113
  c = text[index]
120
114
  parsedElements.push(Span({ class: "string" }, term))
121
115
  term = ""
122
- } else if (isTemplateLiteral && c === "`") {
116
+ } else if (isTemplateLiteral && c === "`" && term[term.length - 1] !== "\\") {
123
117
  isTemplateLiteral = false
124
118
  term += c
125
119
  index += 1
@@ -128,6 +122,10 @@ function parseJavaScript(text) {
128
122
  term = ""
129
123
  }
130
124
 
125
+ if (index == text.length) {
126
+ break
127
+ }
128
+
131
129
  if (isSingleLineComment) {
132
130
  term += c
133
131
  index += 1
@@ -163,6 +161,7 @@ function parseJavaScript(text) {
163
161
  term = ""
164
162
  index += 1
165
163
  } else {
164
+ term += templateVariable
166
165
  term += c
167
166
  index += 1
168
167
  }
@@ -193,16 +192,6 @@ function parseJavaScript(text) {
193
192
  isOperator = true
194
193
  term = c
195
194
  index += 1
196
- } else if (c === ":") {
197
- parsedElements.push(term)
198
- if (isTernaryOperator) {
199
- parsedElements.push(Span({ class: "operator" }, term))
200
- isTernaryOperator = false
201
- } else {
202
- parsedElements.push(Span({ class: "object-colon" }, c))
203
- }
204
- term = ""
205
- index += 1
206
195
  } else if (term.length == 0 && c === "'") {
207
196
  isStringSingleQuote = true
208
197
  term += c
@@ -224,7 +213,7 @@ function parseJavaScript(text) {
224
213
  parsedElements.push(c)
225
214
  term = ""
226
215
  index += 1
227
- } else if (term == "import" || term == "new" || term == "async" || term == "await" || term == "for" || term == "while" || term == "of") {
216
+ } else if (term == "import" || term == "new" || term == "async" || term == "await" || term == "for" || term == "while" || term == "of" || term == "from") {
228
217
  parsedElements.push(Span({ class: "keyword" }, term))
229
218
  parsedElements.push(c)
230
219
  term = ""
@@ -235,20 +224,13 @@ function parseJavaScript(text) {
235
224
  parsedElements.push(c)
236
225
  term = ""
237
226
  index += 1
238
- } else if (/^\d+$/.test(term)) {
239
- parsedElements.push(Span({ class: "number" }, term))
240
- parsedElements.push(c)
241
- term = ""
242
- index += 1
243
- }
244
- else if (isFunctionDeclaration) {
227
+ } else if (isFunctionDeclaration) {
245
228
  isFunctionDeclaration = false
246
229
  parsedElements.push(Span({ class: "function-name" }, term))
247
230
  parsedElements.push(c)
248
231
  term = ""
249
232
  index += 1
250
- }
251
- else {
233
+ } else {
252
234
  if (term.length > 0) {
253
235
  index = pushWordTerm(parsedElements, term, index, text)
254
236
  c = text[index]
@@ -279,8 +261,7 @@ function parseJavaScript(text) {
279
261
  parsedElements.push(Span({ class: "spread-operator" }, term))
280
262
  }
281
263
  term = ""
282
- }
283
- else if (c === "(") {
264
+ } else if (c === "(") {
284
265
  if (term === "") {
285
266
  // skip
286
267
  } else if (term == "require" || term == "isNaN") {
@@ -345,6 +326,14 @@ function parseJavaScript(text) {
345
326
  if (term.length > 0) {
346
327
  if (isSingleLineComment) {
347
328
  parsedElements.push(Span({ class: "comment" }, term))
329
+ } else if (isNumber) {
330
+ if (term[term.length - 1] === "n") {
331
+ parsedElements.push(Span({ class: "bigint" }, term))
332
+ } else if (term.includes("n")) {
333
+ parsedElements.push(term)
334
+ } else {
335
+ parsedElements.push(Span({ class: "number" }, term))
336
+ }
348
337
  } else {
349
338
  pushWordTerm(parsedElements, term, index, text)
350
339
  }
@@ -6,12 +6,6 @@ function testOperatorSymbol(c) {
6
6
  return c === "+" || c === "-" || c === "*" || c === "/" || c === "=" || c === "&" || c === "|" || c === "<" || c === ">" || c === "~" || c === "^" || c === "!" || c === "?" || c === ":"
7
7
  }
8
8
 
9
- // testComment(term string) -> boolean
10
- function testComment(term) {
11
- return (term[0] === "/" && term[1] === "/")
12
- || (term[0] === "/" && term[1] === "*")
13
- }
14
-
15
9
  // pushWordTerm(parsedElements Array<object|string>, term string, index number, text string) -> ()
16
10
  function pushWordTerm(parsedElements, term, index, text) {
17
11
  if (term == "process" || term == "require" || term == "console" || term == "window" || term == "global" || term == "globalThis" || term == "isNaN") {
@@ -99,21 +93,21 @@ function parseJavaScript(text) {
99
93
  parsedElements.push(Span({ class: "operator" }, term))
100
94
  }
101
95
  term = ""
102
- } else if (isStringSingleQuote && c === "'") {
96
+ } else if (isStringSingleQuote && c === "'" && term[term.length - 1] !== "\\") {
103
97
  isStringSingleQuote = false
104
98
  term += c
105
99
  index += 1
106
100
  c = text[index]
107
101
  parsedElements.push(Span({ class: "string" }, term))
108
102
  term = ""
109
- } else if (isStringDoubleQuote && c === "\"") {
103
+ } else if (isStringDoubleQuote && c === "\"" && term[term.length - 1] !== "\\") {
110
104
  isStringDoubleQuote = false
111
105
  term += c
112
106
  index += 1
113
107
  c = text[index]
114
108
  parsedElements.push(Span({ class: "string" }, term))
115
109
  term = ""
116
- } else if (isTemplateLiteral && c === "`") {
110
+ } else if (isTemplateLiteral && c === "`" && term[term.length - 1] !== "\\") {
117
111
  isTemplateLiteral = false
118
112
  term += c
119
113
  index += 1
@@ -122,6 +116,10 @@ function parseJavaScript(text) {
122
116
  term = ""
123
117
  }
124
118
 
119
+ if (index == text.length) {
120
+ break
121
+ }
122
+
125
123
  if (isSingleLineComment) {
126
124
  term += c
127
125
  index += 1
@@ -157,6 +155,7 @@ function parseJavaScript(text) {
157
155
  term = ""
158
156
  index += 1
159
157
  } else {
158
+ term += templateVariable
160
159
  term += c
161
160
  index += 1
162
161
  }
@@ -187,16 +186,6 @@ function parseJavaScript(text) {
187
186
  isOperator = true
188
187
  term = c
189
188
  index += 1
190
- } else if (c === ":") {
191
- parsedElements.push(term)
192
- if (isTernaryOperator) {
193
- parsedElements.push(Span({ class: "operator" }, term))
194
- isTernaryOperator = false
195
- } else {
196
- parsedElements.push(Span({ class: "object-colon" }, c))
197
- }
198
- term = ""
199
- index += 1
200
189
  } else if (term.length == 0 && c === "'") {
201
190
  isStringSingleQuote = true
202
191
  term += c
@@ -218,7 +207,7 @@ function parseJavaScript(text) {
218
207
  parsedElements.push(c)
219
208
  term = ""
220
209
  index += 1
221
- } else if (term == "import" || term == "new" || term == "async" || term == "await" || term == "for" || term == "while" || term == "of") {
210
+ } else if (term == "import" || term == "new" || term == "async" || term == "await" || term == "for" || term == "while" || term == "of" || term == "from") {
222
211
  parsedElements.push(Span({ class: "keyword" }, term))
223
212
  parsedElements.push(c)
224
213
  term = ""
@@ -229,20 +218,13 @@ function parseJavaScript(text) {
229
218
  parsedElements.push(c)
230
219
  term = ""
231
220
  index += 1
232
- } else if (/^\d+$/.test(term)) {
233
- parsedElements.push(Span({ class: "number" }, term))
234
- parsedElements.push(c)
235
- term = ""
236
- index += 1
237
- }
238
- else if (isFunctionDeclaration) {
221
+ } else if (isFunctionDeclaration) {
239
222
  isFunctionDeclaration = false
240
223
  parsedElements.push(Span({ class: "function-name" }, term))
241
224
  parsedElements.push(c)
242
225
  term = ""
243
226
  index += 1
244
- }
245
- else {
227
+ } else {
246
228
  if (term.length > 0) {
247
229
  index = pushWordTerm(parsedElements, term, index, text)
248
230
  c = text[index]
@@ -273,8 +255,7 @@ function parseJavaScript(text) {
273
255
  parsedElements.push(Span({ class: "spread-operator" }, term))
274
256
  }
275
257
  term = ""
276
- }
277
- else if (c === "(") {
258
+ } else if (c === "(") {
278
259
  if (term === "") {
279
260
  // skip
280
261
  } else if (term == "require" || term == "isNaN") {
@@ -339,6 +320,14 @@ function parseJavaScript(text) {
339
320
  if (term.length > 0) {
340
321
  if (isSingleLineComment) {
341
322
  parsedElements.push(Span({ class: "comment" }, term))
323
+ } else if (isNumber) {
324
+ if (term[term.length - 1] === "n") {
325
+ parsedElements.push(Span({ class: "bigint" }, term))
326
+ } else if (term.includes("n")) {
327
+ parsedElements.push(term)
328
+ } else {
329
+ parsedElements.push(Span({ class: "number" }, term))
330
+ }
342
331
  } else {
343
332
  pushWordTerm(parsedElements, term, index, text)
344
333
  }
package/README.md CHANGED
@@ -1,6 +1,14 @@
1
1
  # ArcheHighlight
2
2
  Syntax highlighting for [vanilla microfrontends](https://arche.gallery/). Converts JavaScript code into a React Element or HTML.
3
3
 
4
+ Source code: [GitHub](https://github.com/richytong/ArcheHighlight) |
5
+ License: [CFOSS](https://cloutsworld.com/en-us/legal/license/cfoss)
6
+
7
+ ![Node.js CI](https://github.com/richytong/ArcheHighlight/workflows/Node.js%20CI/badge.svg)
8
+ [![codecov](https://codecov.io/gh/richytong/arche-highlight/graph/badge.svg?token=1IMQYQOMDM)](https://codecov.io/gh/richytong/arche-highlight)
9
+ [![npm version](https://img.shields.io/npm/v/arche-highlight.svg?style=flat)](https://www.npmjs.com/package/arche-highlight)
10
+
11
+
4
12
  ```javascript
5
13
  const ReactElement = Arche(React)
6
14
  window.Span = ReactElement.Span
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "arche-highlight",
3
- "version": "0.6.1",
3
+ "version": "0.6.3",
4
4
  "description": "Syntax highlighting for vanilla microfrontends",
5
5
  "author": "Richard Tong",
6
6
  "license": "CFOSS",