Skip to content

Commit b8aa2de

Browse files
committed
feature: @putout/printer: AssignmentExpression inside ExpressionStatement: comments
1 parent 3c0bfcc commit b8aa2de

3 files changed

Lines changed: 35 additions & 0 deletions

File tree

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ test('printer: tokenizer: statement: expression: comment: same line', (t) => {
1212
t.end();
1313
});
1414

15+
test('printer: tokenizer: statement: expression: comment: line: assign', (t) => {
16+
t.print(fixture.expressionCommentLineAssign);
17+
t.end();
18+
});
19+
1520
test('printer: tokenizer: statement: expression: inside arrow: leading comment', (t) => {
1621
t.print(fixture.expressionInsideArrowLeadingComment);
1722
t.end();

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,23 @@ const isIndent = createTypeChecker([
4040
isNextToAssignmentCall,
4141
]);
4242

43+
function isSameLine(path) {
44+
const {node} = path;
45+
const [first] = path.node.trailingComments;
46+
47+
if (!node.loc)
48+
return false;
49+
50+
return node.loc.start.line === first.loc.start.line;
51+
}
52+
53+
const isCommentOnTheSameLine = createTypeChecker([
54+
['-: -> !', hasTrailingComment],
55+
['+', isSameLine],
56+
]);
57+
4358
export const isIndentAfter = createTypeChecker([
59+
['-', isCommentOnTheSameLine],
4460
['-: node.expression -> !AssignmentExpression'],
4561
['+', callWithNext(hasLeadingComment)],
4662
]);
@@ -81,3 +97,4 @@ export const ExpressionStatement = {
8197
export const isNewlineAfter = createTypeChecker([
8298
['+: -> !', hasTrailingComment],
8399
]);
100+
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
function printf() {
2+
if ([line] === 24) {
3+
[--line];
4+
5+
ax = 0x601; // Прокрутка вверх на одну строку
6+
bh = 0x02; // чорный фон, зеленые символы
7+
cx ^= cx; // от 00:00
8+
dx = 0x184f; // 24:79 (весь экран)
9+
int(0x10);
10+
}
11+
12+
eax = 1;
13+
}

0 commit comments

Comments
 (0)