From 5bf2e299de6b4f6936bd7e88cb20a487d63e815f Mon Sep 17 00:00:00 2001 From: Timothee Guerin Date: Wed, 28 Jun 2023 07:54:02 -0700 Subject: [PATCH 1/2] Fix formatter incorrectly formatting meta type accessor --- packages/compiler/src/formatter/print/printer.ts | 3 ++- packages/compiler/test/formatter/formatter.test.ts | 13 +++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/packages/compiler/src/formatter/print/printer.ts b/packages/compiler/src/formatter/print/printer.ts index edb601102d..d74632b673 100644 --- a/packages/compiler/src/formatter/print/printer.ts +++ b/packages/compiler/src/formatter/print/printer.ts @@ -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( diff --git a/packages/compiler/test/formatter/formatter.test.ts b/packages/compiler/test/formatter/formatter.test.ts index 3511a45b0f..1e29fc83c4 100644 --- a/packages/compiler/test/formatter/formatter.test.ts +++ b/packages/compiler/test/formatter/formatter.test.ts @@ -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({ From 7a02678f529235e4bdf27ee65b1063c43c8c1555 Mon Sep 17 00:00:00 2001 From: Timothee Guerin Date: Wed, 28 Jun 2023 08:30:53 -0700 Subject: [PATCH 2/2] Changelog --- ...ormatter-format-meta-accessor_2023-06-28-15-30.json | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 common/changes/@typespec/compiler/fix-formatter-format-meta-accessor_2023-06-28-15-30.json diff --git a/common/changes/@typespec/compiler/fix-formatter-format-meta-accessor_2023-06-28-15-30.json b/common/changes/@typespec/compiler/fix-formatter-format-meta-accessor_2023-06-28-15-30.json new file mode 100644 index 0000000000..0309e97020 --- /dev/null +++ b/common/changes/@typespec/compiler/fix-formatter-format-meta-accessor_2023-06-28-15-30.json @@ -0,0 +1,10 @@ +{ + "changes": [ + { + "packageName": "@typespec/compiler", + "comment": "Fix: Formatter incorrectly formatting `::` to `.`", + "type": "none" + } + ], + "packageName": "@typespec/compiler" +} \ No newline at end of file