Skip to content

Commit 70d59ab

Browse files
committed
feature: @putout/printer: isNextSimpleWithLeadingComments: type checker
1 parent 72ea26a commit 70d59ab

2 files changed

Lines changed: 10 additions & 31 deletions

File tree

lib/tokenize/statements/expression-statement/after-if.js

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,8 @@ import {
1515
const {
1616
isCallExpression,
1717
isAssignmentExpression,
18-
isArrayExpression,
19-
isStringLiteral,
20-
isTemplateLiteral,
2118
isExpressionStatement,
2219
isStatement,
23-
isBooleanLiteral,
2420
} = types;
2521

2622
function isNotLastOrParentLast(path) {
@@ -76,29 +72,6 @@ const isNextCallWithLeadingComments = (path) => {
7672
return isCallExpression(nextExpression);
7773
};
7874

79-
export function isNextSimpleWithLeadingComments(path) {
80-
const next = path.getNextSibling();
81-
82-
if (!hasTrailingComment(path))
83-
return false;
84-
85-
if (!isExpressionStatement(next))
86-
return false;
87-
88-
const {expression} = next.node;
89-
90-
if (isBooleanLiteral(expression))
91-
return true;
92-
93-
if (isStringLiteral(expression))
94-
return true;
95-
96-
if (isTemplateLiteral(expression))
97-
return true;
98-
99-
return isArrayExpression(next.node.expression);
100-
}
101-
10275
function isAssignWithTrailingComments(path) {
10376
const {expression} = path.node;
10477

lib/tokenize/statements/expression-statement/expression-statement.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,7 @@ import {
1212
printLeadingCommentLine,
1313
printLeadingCommentBlock,
1414
} from './comments.js';
15-
import {
16-
afterIf,
17-
isNextSimpleWithLeadingComments,
18-
} from './after-if.js';
15+
import {afterIf} from './after-if.js';
1916
import {beforeIf} from './before-if.js';
2017

2118
const {isIfStatement} = types;
@@ -82,3 +79,12 @@ export const ExpressionStatement = {
8279
maybe.markAfter(store(), path);
8380
},
8481
};
82+
83+
export const isNextSimpleWithLeadingComments = callWithNext(createTypeChecker([
84+
['-: -> !', hasLeadingComment],
85+
['-: -> !ExpressionStatement'],
86+
['+: node.expression -> TemplateLiteral'],
87+
['+: node.expression -> ArrayExpression'],
88+
['+: node.expression -> BooleanLiteral'],
89+
['+: node.expression -> StringLiteral'],
90+
]));

0 commit comments

Comments
 (0)