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 +1 -1
- package/lib/index.js +29 -9
- package/package.json +1 -1
package/lib/index.d.ts
CHANGED
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
|
-
|
|
279
|
-
|
|
280
|
-
|
|
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 =
|
|
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
|
-
|
|
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
|
-
|
|
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<
|
|
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
|
({
|