Skip to content

Commit

Permalink
style: apply prettier formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
eventualbuddha committed May 12, 2023
1 parent 65a102d commit 1413bdf
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 25 deletions.
14 changes: 7 additions & 7 deletions lib/comments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,15 +228,15 @@ function breakTies(tiesToBreak: any[], lines: any) {
) {
++indexOfFirstLeadingComment;
}

if (indexOfFirstLeadingComment) {
const {enclosingNode} = tiesToBreak[indexOfFirstLeadingComment - 1];
if (enclosingNode?.type === 'CallExpression') {
--indexOfFirstLeadingComment;
}
const { enclosingNode } = tiesToBreak[indexOfFirstLeadingComment - 1];

if (enclosingNode?.type === "CallExpression") {
--indexOfFirstLeadingComment;
}
}

tiesToBreak.forEach(function (comment, i) {
if (i < indexOfFirstLeadingComment) {
addTrailingComment(pn, comment);
Expand Down
39 changes: 21 additions & 18 deletions test/comments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -833,31 +833,34 @@ function runTestsForParser(parserId: any) {
["// comment", ";(function() {})();"].join(eol),
);
});

pit("should preserve comments attached to CallExpression argument", function () {
const code = 'testFunc (/** @type {string} */ (a), b);';
const ast = recast.parse(code, { parser });
const args = ast.program.body[0].expression.arguments;

args.unshift(args[1]);
const expected = 'testFunc(b, /** @type {string} */ a, b);';

assert.strictEqual(recast.print(ast).code, expected);
});

pit(
"should preserve comments attached to CallExpression argument",
function () {
const code = "testFunc (/** @type {string} */ (a), b);";
const ast = recast.parse(code, { parser });
const args = ast.program.body[0].expression.arguments;

args.unshift(args[1]);
const expected = "testFunc(b, /** @type {string} */ a, b);";

assert.strictEqual(recast.print(ast).code, expected);
},
);

pit("should preserve comments attached: no enclosed", function () {
const code = [
'hello.world; // has computed value',
'hello["world"]; // has computed value',
"hello.world; // has computed value",
'hello["world"]; // has computed value',
].join(eol);

const ast = recast.parse(code, { parser });

const expected = [
'hello.world; // has computed value',
'hello["world"]; // has computed value',
"hello.world; // has computed value",
'hello["world"]; // has computed value',
].join(eol);

assert.strictEqual(recast.print(ast).code, expected);
});
}

0 comments on commit 1413bdf

Please sign in to comment.