Skip to content

Commit 51d4eaf

Browse files
committed
Do not reformat block comments
1 parent 3344c2f commit 51d4eaf

File tree

2 files changed

+19
-11
lines changed

2 files changed

+19
-11
lines changed

src/astring.js

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -156,14 +156,15 @@ function reindent(state, text, indent, lineEnd) {
156156
/*
157157
Writes into `state` the `text` string reindented with the provided `indent`.
158158
*/
159-
const trimmedText = text.trim()
160-
if (trimmedText === '') {
161-
return
162-
}
163-
const lines = text.trim().split('\n')
164-
const { length } = lines
165-
for (let i = 0; i < length; i++) {
166-
state.write(indent + lines[i].trim() + lineEnd)
159+
const lines = text.split('\n')
160+
const end = lines.length - 1
161+
state.write(lines[0].trim())
162+
if (end > 0) {
163+
state.write(lineEnd)
164+
for (let i = 1; i < end; i++) {
165+
state.write(indent + lines[i].trim() + lineEnd)
166+
}
167+
state.write(indent + lines[end].trim())
167168
}
168169
}
169170

@@ -182,9 +183,9 @@ function formatComments(state, comments, indent, lineEnd) {
182183
state.write('// ' + comment.value.trim() + '\n')
183184
} else {
184185
// Block comment
185-
state.write('/*' + lineEnd)
186+
state.write('/*')
186187
reindent(state, comment.value, indent, lineEnd)
187-
state.write(indent + '*/' + lineEnd)
188+
state.write('*/' + lineEnd)
188189
}
189190
}
190191
}

test/comment/block.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,17 @@ Block comment for this script file.
55
Block comment for function f.
66
*/
77
function f() {}
8+
/**
9+
* JSDoc block comment.
10+
* @param {string} a - Some string to test
11+
*/
12+
function g(a) {
13+
return a;
14+
}
815
/*
916
Block comment for function g.
1017
*/
11-
function g() {
18+
function h() {
1219
/*
1320
Block comment inside of function g.
1421
*/

0 commit comments

Comments
 (0)