sugar-high 0.5.2 → 0.5.4

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;
@@ -237,7 +242,7 @@ function tokenize(code) {
237
242
  return T_BREAK
238
243
  } else if (isSpaces(token)) {
239
244
  return T_SPACE
240
- } else if (token.split('').every(ch => signs.has(ch))) {
245
+ } else if (token.split('').every(isSign)) {
241
246
  return T_SIGN
242
247
  } else if (isCls(token)) {
243
248
  return inJsxTag() ? T_IDENTIFIER : T_CLS_NUMBER
@@ -352,7 +357,8 @@ function tokenize(code) {
352
357
  if (__jsxTag) {
353
358
  // >: open tag close sign or closing tag closing sign
354
359
  // and it's not `=>` or `/>`
355
- if (curr === '>' && !'/='.includes(prev)) {
360
+ // `curr` could be `>` or `/`
361
+ if ((curr === '>' && !'/='.includes(prev))) {
356
362
  append()
357
363
  if (__jsxTag === 1) {
358
364
  __jsxTag = 0
@@ -368,15 +374,20 @@ function tokenize(code) {
368
374
  // >: tag self close sign or close tag sign
369
375
  if (c_n === '/>' || c_n === '</') {
370
376
  // if current token is not part of close tag sign, push it first
371
- if (current !== '<' || current !== '<') {
377
+ if (current !== '<' && current !== '/') {
372
378
  append()
373
379
  }
380
+
374
381
  if (c_n === '/>') {
375
382
  __jsxTag = 0
376
383
  } else {
377
384
  // is '</'
378
385
  __jsxStack--
379
386
  }
387
+
388
+ if (!__jsxStack)
389
+ __jsxEnter = false
390
+
380
391
  current = c_n
381
392
  i++
382
393
  append(T_SIGN)
package/package.json CHANGED
@@ -1,8 +1,9 @@
1
1
  {
2
2
  "name": "sugar-high",
3
- "version": "0.5.2",
3
+ "version": "0.5.4",
4
4
  "type": "module",
5
5
  "exports": "./lib/index.mjs",
6
+ "types": "./index.d.ts",
6
7
  "description": "Super lightweight JSX syntax highlighter",
7
8
  "files": [
8
9
  "lib",
@@ -16,8 +17,8 @@
16
17
  "build": "next build docs"
17
18
  },
18
19
  "devDependencies": {
19
- "codice": "^0.0.10",
20
- "next": "13.4.20-canary.23",
20
+ "codice": "^0.2.0",
21
+ "next": "13.4.20-canary.31",
21
22
  "react": "^18.2.0",
22
23
  "react-dom": "^18.2.0",
23
24
  "sugar-high": "link:./",