Skip to content

Commit 63387be

Browse files
committed
🐛 Comment out multiple-lines comment in verbose mode (fix #37)
1 parent f69b10d commit 63387be

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,7 @@ Given:
375375
// options.params.ENV === 'product'
376376

377377
// #!if ENV === 'develop'
378+
/** some comment */
378379
console.log("many doge");
379380
// #!else
380381
console.log("much wow");
@@ -385,6 +386,7 @@ If set to `true`, yields:
385386

386387
```javascript
387388
// #!if ENV === 'develop'
389+
// /** some comment */
388390
// console.log('many doge');
389391
// #!else
390392
console.log("much wow");

src/printer.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,12 @@ export function print(
4444
lastCommentClose = c_close || lastCommentClose;
4545

4646
segment = raw;
47+
} else if (isComment) {
48+
// comment may contain multiple lines
49+
const lines = raw.split("\n").filter((l) => l !== "");
50+
segment = lines
51+
.map((l) => verbosePrint(lastCommentOpen, lastCommentClose, l))
52+
.join("");
4753
} else {
4854
segment = verbosePrint(lastCommentOpen, lastCommentClose, raw);
4955
}

test/case.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,10 @@ const a = 1;
166166
/* #!debug */
167167
const b = 2;
168168
<!-- #!if foo === 1 -->
169-
/* NOT ME */
169+
/*
170+
NOT ME
171+
*/
172+
/* NOT ME EITHER */
170173
const c = 3;
171174
<!-- #!endif -->
172175
`;
@@ -177,7 +180,10 @@ module.exports.R_VERBOSE_MIXED = `
177180
/* #!debug */
178181
/* const b = 2;*/
179182
<!-- #!if foo === 1 -->
180-
/* NOT ME */
183+
<!-- /*-->
184+
<!-- NOT ME-->
185+
<!-- */-->
186+
<!-- /* NOT ME EITHER */-->
181187
<!-- const c = 3;-->
182188
<!-- #!endif -->
183189
`;

0 commit comments

Comments
 (0)