Skip to content

Commit

Permalink
feature: comments: leading: improve
Browse files Browse the repository at this point in the history
  • Loading branch information
coderaiser committed Oct 25, 2023
1 parent 0906cf3 commit dbd6b5c
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 3 deletions.
5 changes: 5 additions & 0 deletions lib/tokenize/comment/comment.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ test('printer: comment: line', (t) => {
t.end();
});

test('printer: comment: line: after block', (t) => {
t.print(fixture.commentLineAfterBlock);
t.end();
});

test('printer: comment: line: innerComments', (t) => {
const ast = parse(fixture.commentLine, {
printer: 'putout',
Expand Down
10 changes: 10 additions & 0 deletions lib/tokenize/comment/fixture/comment-line-after-block.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const initialValue = 0;

{
for (const currentValue of array1) {}
}

// .reduceRight();
{
for (const a of x.slice(1)) {}
}
1 change: 0 additions & 1 deletion lib/tokenize/comment/parse-leading-comments.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ module.exports.parseLeadingComments = (path, {print, maybe, indent}, semantics)
const looksLikeDirective = path.isDirective();
const looksLikeProp = path.isObjectProperty();

// || path.isTSPropertySignature();
if (looksLikeProp)
print.breakline();

Expand Down
8 changes: 6 additions & 2 deletions lib/tokenize/comment/parse-trailing-comments.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
'use strict';

const {isDecorator} = require('@putout/babel').types;
const {isLast, isCoupleLines} = require('../is');
const {
isLast,
isCoupleLines,
isNext,
} = require('../is');

const hasBody = (path) => path.node.body;

Expand Down Expand Up @@ -30,7 +34,7 @@ module.exports.parseTrailingComments = (path, {write, maybe}, semantics) => {

if (hasBody(path)) {
write.breakline();
write.breakline();
maybe.write.breakline(!isNext(path));
}

write(`//${value}`);
Expand Down

0 comments on commit dbd6b5c

Please sign in to comment.