sugar-high 0.7.3 → 0.7.5

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/lib/index.d.ts CHANGED
@@ -1,3 +1,3 @@
1
1
  export function highlight(code: string): string
2
2
  export function tokenize(code: string): Array<[number, string]>
3
- export function generate(tokens: Array<[number, string]>): Array<[number, string]>
3
+ export function generate(tokens: Array<[number, string]>): Array<any>
package/lib/index.js CHANGED
@@ -220,9 +220,11 @@ function tokenize(code) {
220
220
 
221
221
  /** @type {string | null} */
222
222
  let __strQuote = null
223
+ let __regexQuoteStart = false
223
224
  let __strTemplateExprStack = 0
224
225
  let __strTemplateQuoteStack = 0
225
226
  const inStringQuotes = () => __strQuote !== null
227
+ const inRegexQuotes = () => __regexQuoteStart
226
228
  const inStrTemplateLiterals = () => (__strTemplateQuoteStack > __strTemplateExprStack)
227
229
  const inStrTemplateExpr = () => __strTemplateQuoteStack > 0 && (__strTemplateQuoteStack === __strTemplateExprStack)
228
230
  const inStringContent = () => inStringQuotes() || inStrTemplateLiterals()
@@ -275,12 +277,20 @@ function tokenize(code) {
275
277
  }
276
278
  }
277
279
 
278
- const append = (_type, _token) => {
279
- if (_token) {
280
- current = _token
280
+ /**
281
+ *
282
+ * @param {number} type_
283
+ * @param {string} token_
284
+ */
285
+ const append = (type_, token_) => {
286
+ if (type_ || token_) {
287
+ const nType = types[type_]
288
+ }
289
+ if (token_) {
290
+ current = token_
281
291
  }
282
292
  if (current) {
283
- type = _type || classify(current)
293
+ type = type_ || classify(current)
284
294
  /** @type [number, string] */
285
295
  const pair = [type, current]
286
296
  if (type !== T_SPACE && type !== T_BREAK) {
@@ -456,7 +466,13 @@ function tokenize(code) {
456
466
 
457
467
  // current and next char can form a jsx open or close tag
458
468
  if (curr === '<' && (next === '/' || isAlpha(next))) {
459
- __jsxEnter = true
469
+ if (
470
+ !inStringContent() &&
471
+ !inJsxLiterals() &&
472
+ !inRegexQuotes()
473
+ ) {
474
+ __jsxEnter = true
475
+ }
460
476
  }
461
477
  }
462
478
 
@@ -487,6 +503,7 @@ function tokenize(code) {
487
503
  continue
488
504
  }
489
505
 
506
+ __regexQuoteStart = true
490
507
  const start = i++
491
508
 
492
509
  // end of line of end of file
@@ -494,17 +511,20 @@ function tokenize(code) {
494
511
  const isEol = () => isEof() || code[i] === '\n'
495
512
 
496
513
  let foundClose = false
497
- // regex
514
+
515
+ // traverse to find closing regex slash
498
516
  for (; !isEol(); i++) {
499
517
  if (code[i] === '/' && code[i - 1] !== '\\') {
500
518
  foundClose = true
501
- // append regex flags
519
+ // end of regex, append regex flags
502
520
  while (start !== i && /^[a-z]$/.test(code[i + 1]) && !isEol()) {
503
521
  i++
504
522
  }
505
523
  break
506
524
  }
507
525
  }
526
+ __regexQuoteStart = false
527
+
508
528
  if (start !== i && foundClose) {
509
529
  // If current line is fully closed with string quotes or regex slashes,
510
530
  // add them to tokens
@@ -583,13 +603,13 @@ function tokenize(code) {
583
603
 
584
604
  /**
585
605
  * @param {Array<[number, string]>} tokens
586
- * @return {Array<[number, string]>}
606
+ * @return {Array<any>}
587
607
  */
588
608
  function generate(tokens) {
589
609
  const lines = []
590
610
  /**
591
611
  * @param {any} children
592
- *
612
+ * @return {{type: string, tagName: string, children: any[], properties: Record<string, string>}}
593
613
  */
594
614
  const createLine = (children) =>
595
615
  ({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sugar-high",
3
- "version": "0.7.3",
3
+ "version": "0.7.5",
4
4
  "type": "module",
5
5
  "types": "./lib/index.d.ts",
6
6
  "exports": {