arche-highlight 0.6.0 → 0.6.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.
@@ -337,7 +337,11 @@ function parseJavaScript(text) {
337
337
  }
338
338
 
339
339
  if (term.length > 0) {
340
- pushWordTerm(parsedElements, term, index, text)
340
+ if (isSingleLineComment) {
341
+ parsedElements.push(Span({ class: "comment" }, term))
342
+ } else {
343
+ pushWordTerm(parsedElements, term, index, text)
344
+ }
341
345
  }
342
346
 
343
347
  return parsedElements
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
@@ -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") {
@@ -343,7 +324,19 @@ function parseJavaScript(text) {
343
324
  }
344
325
 
345
326
  if (term.length > 0) {
346
- pushWordTerm(parsedElements, term, index, text)
327
+ if (isSingleLineComment) {
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
+ }
337
+ } else {
338
+ pushWordTerm(parsedElements, term, index, text)
339
+ }
347
340
  }
348
341
 
349
342
  return parsedElements
@@ -337,7 +337,11 @@ function parseJavaScript(text) {
337
337
  }
338
338
 
339
339
  if (term.length > 0) {
340
- pushWordTerm(parsedElements, term, index, text)
340
+ if (isSingleLineComment) {
341
+ parsedElements.push(Span({ class: "comment" }, term))
342
+ } else {
343
+ pushWordTerm(parsedElements, term, index, text)
344
+ }
341
345
  }
342
346
 
343
347
  return parsedElements
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "arche-highlight",
3
- "version": "0.6.0",
3
+ "version": "0.6.2",
4
4
  "description": "Syntax highlighting for vanilla microfrontends",
5
5
  "author": "Richard Tong",
6
6
  "license": "CFOSS",