Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: parameter comment function attribute removal #2412

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/printer.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -1410,7 +1410,7 @@ function printFunction(path, options, print) {
const willBreakDeclaration = declaration.some(willBreak);

if (willBreakDeclaration) {
return [printedDeclaration, " ", printedBody];
return [...declAttrs, printedDeclaration, " ", printedBody];
}

return [
Expand Down
42 changes: 42 additions & 0 deletions tests/attributes/__snapshots__/jsfmt.spec.mjs.snap
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,28 @@ class Test
}

}

class ParamCommentFunctionAnnotation {

#[Foo]
function bar(
int $a, // parameter comment
int $b,
) {
return $a + $b;
}

#[Foo]
function bar2(
int $a,
int $middle, // parameter comment
int $b,
) {
return $a + $middle + $b;
}

}

=====================================output=====================================
<?php

Expand Down Expand Up @@ -206,5 +228,25 @@ class Test
}
}

class ParamCommentFunctionAnnotation
{
#[Foo]
function bar(
int $a, // parameter comment
int $b
) {
return $a + $b;
}

#[Foo]
function bar2(
int $a,
int $middle, // parameter comment
int $b
) {
return $a + $middle + $b;
}
}

================================================================================
`;
23 changes: 22 additions & 1 deletion tests/attributes/attributes.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,25 @@ public function withAttribute(string $foo): string
return $foo;
}

}
}

class ParamCommentFunctionAnnotation {

#[Foo]
function bar(
int $a, // parameter comment
int $b,
) {
return $a + $b;
}

#[Foo]
function bar2(
int $a,
int $middle, // parameter comment
int $b,
) {
return $a + $middle + $b;
}

}
Loading