sugar-high 0.5.1 → 0.5.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.
package/README.md CHANGED
@@ -2,7 +2,6 @@
2
2
 
3
3
  [![Build][build-badge]][build]
4
4
  [![Coverage][coverage-badge]][coverage]
5
- [![Downloads][downloads-badge]][downloads]
6
5
 
7
6
  ### Introduction
8
7
 
package/lib/index.mjs CHANGED
@@ -117,6 +117,10 @@ function isSpaces(str) {
117
117
  return /^[^\S\r\n]+$/g.test(str)
118
118
  }
119
119
 
120
+ function isSign(ch) {
121
+ return signs.has(ch)
122
+ }
123
+
120
124
  function encode(str) {
121
125
  return str
122
126
  .replace(/&/g, '&')
@@ -190,6 +194,7 @@ function tokenize(code) {
190
194
  let __jsxEnter = false
191
195
  /**
192
196
  * @type {0 | 1 | 2}
197
+ * @example
193
198
  * 0 for not in jsx;
194
199
  * 1 for open jsx tag;
195
200
  * 2 for closing jsx tag;
@@ -218,19 +223,26 @@ function tokenize(code) {
218
223
  */
219
224
  function classify(token) {
220
225
  const isLineBreak = token === '\n'
226
+ // First checking if they're attributes values
221
227
  if (inJsxTag() && inStringQuotes()) {
222
228
  return T_STRING
223
229
  }
230
+ // Then determine if they're jsx literals
224
231
  const isJsxLiterals = inJsxLiterals()
225
232
  if (isJsxLiterals) {
226
233
  return T_JSX_LITERALS
234
+
235
+ }
236
+ // Determine strings first before other types
237
+ if (inStringQuotes()) {
238
+ return T_STRING
227
239
  } else if (keywords.has(token)) {
228
240
  return last[1] === '.' ? T_IDENTIFIER : T_KEYWORD
229
241
  } else if (isLineBreak) {
230
242
  return T_BREAK
231
243
  } else if (isSpaces(token)) {
232
244
  return T_SPACE
233
- } else if (token.split('').every(ch => signs.has(ch))) {
245
+ } else if (token.split('').every(isSign)) {
234
246
  return T_SIGN
235
247
  } else if (isCls(token)) {
236
248
  return inJsxTag() ? T_IDENTIFIER : T_CLS_NUMBER
@@ -345,7 +357,8 @@ function tokenize(code) {
345
357
  if (__jsxTag) {
346
358
  // >: open tag close sign or closing tag closing sign
347
359
  // and it's not `=>` or `/>`
348
- if (curr === '>' && !'/='.includes(prev)) {
360
+ // `curr` could be `>` or `/`
361
+ if ((curr === '>' && !'/='.includes(prev))) {
349
362
  append()
350
363
  if (__jsxTag === 1) {
351
364
  __jsxTag = 0
@@ -361,15 +374,20 @@ function tokenize(code) {
361
374
  // >: tag self close sign or close tag sign
362
375
  if (c_n === '/>' || c_n === '</') {
363
376
  // if current token is not part of close tag sign, push it first
364
- if (current !== '<' || current !== '<') {
377
+ if (current !== '<' && current !== '/') {
365
378
  append()
366
379
  }
380
+
367
381
  if (c_n === '/>') {
368
382
  __jsxTag = 0
369
383
  } else {
370
384
  // is '</'
371
385
  __jsxStack--
372
386
  }
387
+
388
+ if (!__jsxStack)
389
+ __jsxEnter = false
390
+
373
391
  current = c_n
374
392
  i++
375
393
  append(T_SIGN)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sugar-high",
3
- "version": "0.5.1",
3
+ "version": "0.5.3",
4
4
  "type": "module",
5
5
  "exports": "./lib/index.mjs",
6
6
  "description": "Super lightweight JSX syntax highlighter",
@@ -16,8 +16,8 @@
16
16
  "build": "next build docs"
17
17
  },
18
18
  "devDependencies": {
19
- "codice": "^0.0.10",
20
- "next": "13.4.20-canary.23",
19
+ "codice": "^0.2.0",
20
+ "next": "13.4.20-canary.31",
21
21
  "react": "^18.2.0",
22
22
  "react-dom": "^18.2.0",
23
23
  "sugar-high": "link:./",