Skip to content

Commit dd6c5c9

Browse files
committed
chore: split output comment printing
1 parent fbec997 commit dd6c5c9

File tree

5 files changed

+17
-13
lines changed

5 files changed

+17
-13
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@egoistdeveloper/twcss-to-sass",
3-
"version": "2.1.12",
3+
"version": "2.1.13",
44
"description": "HTML template to SASS converter for TailwindCSS",
55
"main": "dist/cjs/index.js",
66
"module": "dist/esm/index.js",

src/interfaces/tw-to-sass-options.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ import { IClassNameOptions } from './classname-options'
44
export interface ITwToSassOptions {
55
formatOutput: boolean
66
formatterOptions: CSSBeautifyOptions
7-
printComments: boolean
7+
printHtmlComments: boolean
8+
printSassComments: boolean
89
useCommentBlocksAsClassName: boolean
910
maxClassNameLength: number
1011
classNameOptions: IClassNameOptions

src/twcss-to-sass.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ const defaultOptions: ITwToSassOptions = {
3434
formatOutput: true,
3535
useCommentBlocksAsClassName: true,
3636
maxClassNameLength: 50,
37-
printComments: true,
37+
printHtmlComments: true,
38+
printSassComments: true,
3839
formatterOptions: formatterOptions,
3940
classNameOptions: {
4041
lowercase: true,
@@ -462,7 +463,7 @@ function getSassTree(nodeTree: IHtmlNode[]): string {
462463
}
463464

464465
if (treeString.length || subTreeString.length) {
465-
const classComment = _defaultOptions.printComments
466+
const classComment = _defaultOptions.printSassComments
466467
? `/* ${node.comment ? node.comment : node.tagName}${
467468
node.order ? ' -> ' + node.order : ''
468469
} */`
@@ -528,7 +529,7 @@ function getHtmlTree(nodeTree: IHtmlNode[]): string {
528529
const className = getClassName(node, node.order)
529530

530531
if (node.type == 'element' && node.tagName != 'style') {
531-
if (_defaultOptions.printComments) {
532+
if (_defaultOptions.printHtmlComments) {
532533
if (node.comment) {
533534
htmlTree += `\n<!-- ${node.comment.trim()} -->`
534535
}

test/twcss-to-html.test.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { ITwToSassOptions } from '../src/interfaces/tw-to-sass-options'
12
import { convertToSass } from '../src/twcss-to-sass'
23

34
test('convert to sass for html', () => {
@@ -19,9 +20,9 @@ test('convert to sass for html', () => {
1920
</div>
2021
</div>`
2122

22-
const converterConfigs = <any>{
23+
const converterConfigs = <ITwToSassOptions>{
2324
useCommentBlocksAsClassName: true,
24-
printComments: true,
25+
printSassComments: true,
2526
}
2627

2728
const converterResult = convertToSass(htmlCotnent, converterConfigs)
@@ -89,9 +90,9 @@ test('convert to sass for html with void elements', () => {
8990
9091
</html>`
9192

92-
const converterConfigs = <any>{
93+
const converterConfigs = <ITwToSassOptions>{
9394
useCommentBlocksAsClassName: true,
94-
printComments: true,
95+
printSassComments: true,
9596
}
9697

9798
const converterResult = convertToSass(htmlCotnent, converterConfigs)

test/twcss-to-sass.test.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { ITwToSassOptions } from '../src/interfaces/tw-to-sass-options'
12
import { convertToSass } from '../src/twcss-to-sass'
23

34
test('convert to sass', () => {
@@ -53,9 +54,9 @@ test('convert to sass with comments', () => {
5354
}
5455
}`
5556

56-
const converterConfigs = <any>{
57+
const converterConfigs = <ITwToSassOptions>{
5758
useCommentBlocksAsClassName: false,
58-
printComments: true,
59+
printSassComments: true,
5960
}
6061
const converterResult = convertToSass(htmlCotnent, converterConfigs)
6162

@@ -83,9 +84,9 @@ test('convert to sass with comments class names', () => {
8384
}
8485
}`
8586

86-
const converterConfigs = <any>{
87+
const converterConfigs = <ITwToSassOptions>{
8788
useCommentBlocksAsClassName: true,
88-
printComments: true,
89+
printSassComments: true,
8990
classNameOptions: {
9091
lowercase: true,
9192
replacement: '_',

0 commit comments

Comments
 (0)