sugar-high 2.3.0 → 2.3.1

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
@@ -9,6 +9,32 @@ returns HTML without requiring a DOM.
9
9
 
10
10
  ![Sugar High preview](https://repository-images.githubusercontent.com/453236442/9aa2144a-3a4c-4a93-a87f-92ca6a37ded6)
11
11
 
12
+ ## Benchmarks
13
+
14
+ Sugar High, PrismJS, and highlight.js highlighting the same generated TypeScript files:
15
+
16
+ <!-- benchmark:start -->
17
+ Measured 2026-09-04 with Node v24.18.0, darwin arm64, Apple M4 Pro.
18
+
19
+ | TypeScript | Sugar High 2.2.2 | PrismJS 1.30.0 | highlight.js 11.12.0 |
20
+ | --- | ---: | ---: | ---: |
21
+ | Minified (KiB) | 9.90 | 14.63 | 29.54 |
22
+ | Gzip (KiB) | 4.35 | 5.47 | 11.12 |
23
+ | 11 KiB | 1.78 | 1.18 | 2.11 |
24
+ | 100 KiB | 18.02 | 15.25 | 23.05 |
25
+ | 500 KiB | 90.98 | 96.41 | 118.39 |
26
+
27
+ Median milliseconds per file; lower is better. 5 timed samples after warmup.
28
+ Sizes are TypeScript-only browser bundles, minified with Bun; gzip uses level 9. Theme CSS is excluded.
29
+ Loading and initialization are excluded. Each library highlights the same generated TypeScript
30
+ into HTML using an explicit language. Grammars and HTML output differ; this is not a measure
31
+ of highlighting quality or browser rendering speed. Results vary by machine and workload.
32
+ <!-- benchmark:end -->
33
+
34
+ Run `pnpm --filter sugar-high benchmark:large --write` to refresh this table and the
35
+ [website comparison](https://sugar-high.vercel.app/#benchmarks) from the same measurement.
36
+ See [benchmark methodology and options](../../docs/BENCHMARK.md).
37
+
12
38
  ## Install
13
39
 
14
40
  ```sh
package/lib/core.js CHANGED
@@ -110,6 +110,10 @@ function tokenize(code, options) {
110
110
  if (isWord(curr)) {
111
111
  const start = i++
112
112
  while (i < code.length && isWord(code[i])) i++
113
+ if (/^\d/.test(curr) && code[i] === '.' && /\d/.test(code[i + 1] || '')) {
114
+ i++
115
+ while (i < code.length && isWord(code[i])) i++
116
+ }
113
117
  const value = code.slice(start, i)
114
118
  const normalized = normalize(value)
115
119
  const type = typeKeywords.has(normalized)
@@ -283,6 +283,7 @@ function tokenize(code, options) {
283
283
  /** @type {0 | 1 | 2} 0 = none; 1 = inside `<open`; 2 = inside `</close` */
284
284
  let __jsxTag = 0
285
285
  let __jsxExpr = false
286
+ let __jsxTagExpr = 0
286
287
 
287
288
  /** Nested `<open>…</open>` depth (content between tags, including nested elements). */
288
289
  let __jsxStack = 0
@@ -323,6 +324,8 @@ function tokenize(code, options) {
323
324
  // classify jsx open tag
324
325
  if ((lastToken === '<' || lastToken === '</'))
325
326
  return T_ENTITY
327
+ if (!__jsxTagExpr && /^\s+$/.test(tokens[tokens.length - 1]?.[1] || ''))
328
+ return T_PROPERTY
326
329
  }
327
330
  }
328
331
  // Then determine if they're jsx literals
@@ -343,7 +346,7 @@ function tokenize(code, options) {
343
346
  } else if (token.split('').every(isSign)) {
344
347
  return T_SIGN
345
348
  } else if (isCls(token)) {
346
- return inJsxTag() ? T_IDENTIFIER : T_CLS_NUMBER
349
+ return inJsxTag() && !__jsxTagExpr ? T_IDENTIFIER : T_CLS_NUMBER
347
350
  } else {
348
351
  if (isIdentifier(token)) {
349
352
  const isLastPropDot = last[1] === '.' && isIdentifier(beforeLast[1])
@@ -372,6 +375,10 @@ function tokenize(code, options) {
372
375
  beforeLast = last
373
376
  last = pair
374
377
  }
378
+ if (inJsxTag() && type === T_SIGN) {
379
+ if (current === '{') __jsxTagExpr++
380
+ if (current === '}') __jsxTagExpr--
381
+ }
375
382
  tokens.push(pair)
376
383
  }
377
384
  current = ''
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sugar-high",
3
- "version": "2.3.0",
3
+ "version": "2.3.1",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/huozhi/sugar-high.git",