sugar-high 0.9.4 → 0.9.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.js +23 -4
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -678,9 +678,13 @@ function generate(tokens) {
|
|
|
678
678
|
}
|
|
679
679
|
/** @type {Array<[number, string]>} */
|
|
680
680
|
const lineTokens = []
|
|
681
|
+
let lastWasBreak = false
|
|
682
|
+
|
|
681
683
|
for (let i = 0; i < tokens.length; i++) {
|
|
682
684
|
const token = tokens[i]
|
|
683
685
|
const [type, value] = token
|
|
686
|
+
const isLastToken = i === tokens.length - 1
|
|
687
|
+
|
|
684
688
|
if (type !== T_BREAK) {
|
|
685
689
|
// Divide multi-line token into multi-line code
|
|
686
690
|
if (value.includes('\n')) {
|
|
@@ -695,15 +699,30 @@ function generate(tokens) {
|
|
|
695
699
|
} else {
|
|
696
700
|
lineTokens.push(token)
|
|
697
701
|
}
|
|
702
|
+
lastWasBreak = false
|
|
698
703
|
} else {
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
704
|
+
if (lastWasBreak) {
|
|
705
|
+
// Consecutive break - create empty line
|
|
706
|
+
flushLine([])
|
|
707
|
+
} else {
|
|
708
|
+
// First break after content - flush current line
|
|
709
|
+
flushLine(lineTokens)
|
|
710
|
+
lineTokens.length = 0
|
|
711
|
+
}
|
|
712
|
+
|
|
713
|
+
// If this is the last token and it's a break, create an empty line
|
|
714
|
+
if (isLastToken) {
|
|
715
|
+
flushLine([])
|
|
716
|
+
}
|
|
717
|
+
|
|
718
|
+
lastWasBreak = true
|
|
702
719
|
}
|
|
703
720
|
}
|
|
704
721
|
|
|
705
|
-
if
|
|
722
|
+
// Flush remaining tokens if any
|
|
723
|
+
if (lineTokens.length) {
|
|
706
724
|
flushLine(lineTokens)
|
|
725
|
+
}
|
|
707
726
|
|
|
708
727
|
return lines
|
|
709
728
|
}
|