sugar-high 0.4.3 → 0.4.6

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.
Files changed (3) hide show
  1. package/README.md +19 -1
  2. package/lib/index.mjs +14 -10
  3. package/package.json +5 -5
package/README.md CHANGED
@@ -1,9 +1,14 @@
1
1
  # Sugar High
2
+
3
+ [![Build][build-badge]][build]
4
+ [![Coverage][coverage-badge]][coverage]
5
+ [![Downloads][downloads-badge]][downloads]
6
+
2
7
  ### Introduction
3
8
 
4
9
  Super lightweight JSX syntax highlighter, around 1KB after minified and gzipped
5
10
 
6
- ![img](https://repository-images.githubusercontent.com/453236442/94994be5-72fa-479f-8b87-2dc14fe40329)
11
+ ![img](https://repository-images.githubusercontent.com/453236442/1d63a6ff-aa11-422c-a36c-ca16fc102f18)
7
12
 
8
13
  ### Usage
9
14
 
@@ -70,3 +75,16 @@ pre code {
70
75
 
71
76
  MIT
72
77
 
78
+ <!-- Definitions -->
79
+
80
+ [build-badge]: https://github.com/huozhi/sugar-high/workflows/Test/badge.svg
81
+
82
+ [build]: https://github.com/huozhi/sugar-high/actions
83
+
84
+ [coverage-badge]: https://badge.fury.io/js/sugar-high.svg
85
+
86
+ [coverage]: https://codecov.io/github/huozhi/sugar-high
87
+
88
+ [downloads-badge]: https://img.shields.io/npm/dm/sugar-high.svg
89
+
90
+ [downloads]: https://www.npmjs.com/package/sugar-high
package/lib/index.mjs CHANGED
@@ -3,6 +3,7 @@
3
3
  const jsxBrackets = new Set(['<', '>', '{', '}', '[', ']'])
4
4
  const keywords = new Set([
5
5
  'for',
6
+ 'do',
6
7
  'while',
7
8
  'if',
8
9
  'else',
@@ -52,7 +53,6 @@ const signs = new Set([
52
53
  '%',
53
54
  '=',
54
55
  '!',
55
- ...jsxBrackets,
56
56
  '&',
57
57
  '|',
58
58
  '^',
@@ -73,6 +73,7 @@ const signs = new Set([
73
73
  '#',
74
74
  '@',
75
75
  '\\',
76
+ ...jsxBrackets,
76
77
  ])
77
78
 
78
79
  export const types = [
@@ -126,7 +127,7 @@ function encode(str) {
126
127
  }
127
128
 
128
129
  function isWord(chr) {
129
- return /^[\w_]+$/.test(chr)
130
+ return /^[\w_]+$/.test(chr) || hasUnicode(chr)
130
131
  }
131
132
 
132
133
  function isCls(str) {
@@ -136,8 +137,12 @@ function isCls(str) {
136
137
  str === 'null'
137
138
  }
138
139
 
140
+ function hasUnicode(s) {
141
+ return /[^\u0000-\u007f]/.test(s);
142
+ }
143
+
139
144
  function isIdentifierChar(chr) {
140
- return /^[a-zA-Z_$]$/.test(chr)
145
+ return /^[a-zA-Z_$]$/.test(chr) || hasUnicode(chr)
141
146
  }
142
147
 
143
148
  function isIdentifier(str) {
@@ -259,27 +264,25 @@ export function tokenize(code) {
259
264
  continue
260
265
  }
261
266
 
262
-
263
267
  if (!inStrTemplateLiterals()) {
264
- if (prev !== '\\n' && curr === '`') {
268
+ if (prev !== '\\n' && isStrTemplateChr(curr)) {
265
269
  append()
266
- append(T_SIGN, curr)
270
+ append(T_STRING, curr)
267
271
  __strTemplateQuoteStack++
268
272
  continue
269
273
  }
270
274
  }
271
275
 
272
276
  if (inStrTemplateLiterals()) {
273
- if (prev !== '\\n' && curr === '`') {
277
+ if (prev !== '\\n' && isStrTemplateChr(curr)) {
274
278
  if (__strTemplateQuoteStack > 0) {
275
279
  append()
276
280
  __strTemplateQuoteStack--
277
- append(T_SIGN, curr)
281
+ append(T_STRING, curr)
278
282
  continue
279
283
  }
280
284
  }
281
285
 
282
-
283
286
  if (c_n === '${') {
284
287
  __strTemplateExprStack++
285
288
  append(T_STRING)
@@ -321,7 +324,8 @@ export function tokenize(code) {
321
324
  }
322
325
  if (__jsxTag) {
323
326
  // >: open tag close sign or closing tag closing sign
324
- if (curr === '>' && prev !== '/') {
327
+ // and it's not `=>` or `/>`
328
+ if (curr === '>' && !'/='.includes(prev)) {
325
329
  append()
326
330
  if (__jsxTag === 1) {
327
331
  __jsxTag = 0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sugar-high",
3
- "version": "0.4.3",
3
+ "version": "0.4.6",
4
4
  "type": "module",
5
5
  "exports": "./lib/index.mjs",
6
6
  "description": "Super lightweight JSX syntax highlighter",
@@ -17,10 +17,10 @@
17
17
  },
18
18
  "devDependencies": {
19
19
  "codice": "^0.0.10",
20
- "next": "12.1.6-canary.6",
21
- "react": "18.0.0",
22
- "react-dom": "18.0.0",
20
+ "next": "canary",
21
+ "react": "^18.1.0",
22
+ "react-dom": "^18.1.0",
23
23
  "sugar-high": "link:./",
24
- "vitest": "~0.6.0"
24
+ "vitest": "^0.13.1"
25
25
  }
26
26
  }