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 formatter incorrectly formatting meta type accessor #2126

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
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@typespec/compiler",
"comment": "Fix: Formatter incorrectly formatting `::` to `.`",
"type": "none"
}
],
"packageName": "@typespec/compiler"
}
3 changes: 2 additions & 1 deletion packages/compiler/src/formatter/print/printer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -945,7 +945,8 @@ export function printMemberExpression(
print: PrettierChildPrint
): Doc {
const node = path.getValue();
return [node.base ? [path.call(print, "base"), "."] : "", path.call(print, "id")];

return [node.base ? [path.call(print, "base"), node.selector] : "", path.call(print, "id")];
}

export function printModelExpression(
Expand Down
13 changes: 13 additions & 0 deletions packages/compiler/test/formatter/formatter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2265,6 +2265,19 @@ model Foo {
});
});

describe("meta type accessor", () => {
it("format with ::", () => {
assertFormat({
code: `
@@doc(myOp :: parameters.foo, "")
`,
expected: `
@@doc(myOp::parameters.foo, "");
`,
});
});
});

describe("projections", () => {
it("format projections", () => {
assertFormat({
Expand Down
Loading