@typespec/compiler 0.46.0-dev.8 → 0.46.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (113) hide show
  1. package/dist/manifest.js +2 -2
  2. package/dist/src/config/config-loader.d.ts.map +1 -1
  3. package/dist/src/config/config-loader.js +1 -0
  4. package/dist/src/config/config-loader.js.map +1 -1
  5. package/dist/src/config/config-schema.d.ts.map +1 -1
  6. package/dist/src/config/config-schema.js +24 -0
  7. package/dist/src/config/config-schema.js.map +1 -1
  8. package/dist/src/config/types.d.ts +8 -1
  9. package/dist/src/config/types.d.ts.map +1 -1
  10. package/dist/src/core/checker.d.ts.map +1 -1
  11. package/dist/src/core/checker.js +13 -8
  12. package/dist/src/core/checker.js.map +1 -1
  13. package/dist/src/core/cli/args.d.ts.map +1 -1
  14. package/dist/src/core/cli/args.js +1 -0
  15. package/dist/src/core/cli/args.js.map +1 -1
  16. package/dist/src/core/helpers/index.d.ts +1 -0
  17. package/dist/src/core/helpers/index.d.ts.map +1 -1
  18. package/dist/src/core/helpers/index.js +1 -0
  19. package/dist/src/core/helpers/index.js.map +1 -1
  20. package/dist/src/core/helpers/location-context.d.ts +4 -0
  21. package/dist/src/core/helpers/location-context.d.ts.map +1 -0
  22. package/dist/src/core/helpers/location-context.js +9 -0
  23. package/dist/src/core/helpers/location-context.js.map +1 -0
  24. package/dist/src/core/helpers/type-name-utils.d.ts.map +1 -1
  25. package/dist/src/core/helpers/type-name-utils.js +8 -3
  26. package/dist/src/core/helpers/type-name-utils.js.map +1 -1
  27. package/dist/src/core/index.d.ts +1 -1
  28. package/dist/src/core/index.d.ts.map +1 -1
  29. package/dist/src/core/index.js +1 -1
  30. package/dist/src/core/index.js.map +1 -1
  31. package/dist/src/core/library.d.ts +3 -1
  32. package/dist/src/core/library.d.ts.map +1 -1
  33. package/dist/src/core/library.js +6 -1
  34. package/dist/src/core/library.js.map +1 -1
  35. package/dist/src/core/linter.d.ts +10 -0
  36. package/dist/src/core/linter.d.ts.map +1 -0
  37. package/dist/src/core/linter.js +166 -0
  38. package/dist/src/core/linter.js.map +1 -0
  39. package/dist/src/core/messages.d.ts +77 -2
  40. package/dist/src/core/messages.d.ts.map +1 -1
  41. package/dist/src/core/messages.js +27 -0
  42. package/dist/src/core/messages.js.map +1 -1
  43. package/dist/src/core/node-host.d.ts +3 -0
  44. package/dist/src/core/node-host.d.ts.map +1 -1
  45. package/dist/src/core/node-host.js +22 -1
  46. package/dist/src/core/node-host.js.map +1 -1
  47. package/dist/src/core/options.d.ts +3 -1
  48. package/dist/src/core/options.d.ts.map +1 -1
  49. package/dist/src/core/parser.d.ts.map +1 -1
  50. package/dist/src/core/parser.js +56 -29
  51. package/dist/src/core/parser.js.map +1 -1
  52. package/dist/src/core/program.d.ts +3 -17
  53. package/dist/src/core/program.d.ts.map +1 -1
  54. package/dist/src/core/program.js +90 -46
  55. package/dist/src/core/program.js.map +1 -1
  56. package/dist/src/core/schema-validator.d.ts +1 -0
  57. package/dist/src/core/schema-validator.d.ts.map +1 -1
  58. package/dist/src/core/schema-validator.js +2 -2
  59. package/dist/src/core/schema-validator.js.map +1 -1
  60. package/dist/src/core/types.d.ts +110 -11
  61. package/dist/src/core/types.d.ts.map +1 -1
  62. package/dist/src/core/types.js.map +1 -1
  63. package/dist/src/emitter-framework/asset-emitter.d.ts.map +1 -1
  64. package/dist/src/emitter-framework/asset-emitter.js +89 -45
  65. package/dist/src/emitter-framework/asset-emitter.js.map +1 -1
  66. package/dist/src/emitter-framework/type-emitter.d.ts +43 -22
  67. package/dist/src/emitter-framework/type-emitter.d.ts.map +1 -1
  68. package/dist/src/emitter-framework/type-emitter.js +90 -23
  69. package/dist/src/emitter-framework/type-emitter.js.map +1 -1
  70. package/dist/src/emitter-framework/types.d.ts +14 -4
  71. package/dist/src/emitter-framework/types.d.ts.map +1 -1
  72. package/dist/src/emitter-framework/types.js +1 -0
  73. package/dist/src/emitter-framework/types.js.map +1 -1
  74. package/dist/src/formatter/parser.d.ts.map +1 -1
  75. package/dist/src/formatter/parser.js +28 -2
  76. package/dist/src/formatter/parser.js.map +1 -1
  77. package/dist/src/formatter/print/comment-handler.d.ts +1 -1
  78. package/dist/src/formatter/print/comment-handler.d.ts.map +1 -1
  79. package/dist/src/formatter/print/comment-handler.js +37 -5
  80. package/dist/src/formatter/print/comment-handler.js.map +1 -1
  81. package/dist/src/formatter/print/needs-parens.d.ts +1 -1
  82. package/dist/src/formatter/print/needs-parens.js +1 -1
  83. package/dist/src/formatter/print/printer.d.ts +6 -3
  84. package/dist/src/formatter/print/printer.d.ts.map +1 -1
  85. package/dist/src/formatter/print/printer.js +130 -53
  86. package/dist/src/formatter/print/printer.js.map +1 -1
  87. package/dist/src/formatter/types.d.ts +9 -0
  88. package/dist/src/formatter/types.d.ts.map +1 -0
  89. package/dist/src/formatter/types.js +2 -0
  90. package/dist/src/formatter/types.js.map +1 -0
  91. package/dist/src/init/init-template.d.ts +3 -1
  92. package/dist/src/init/init-template.d.ts.map +1 -1
  93. package/dist/src/init/init-template.js +3 -6
  94. package/dist/src/init/init-template.js.map +1 -1
  95. package/dist/src/init/init.d.ts.map +1 -1
  96. package/dist/src/init/init.js +96 -16
  97. package/dist/src/init/init.js.map +1 -1
  98. package/dist/src/lib/decorators.d.ts +9 -0
  99. package/dist/src/lib/decorators.d.ts.map +1 -1
  100. package/dist/src/lib/decorators.js +9 -0
  101. package/dist/src/lib/decorators.js.map +1 -1
  102. package/dist/src/testing/index.d.ts +1 -0
  103. package/dist/src/testing/index.d.ts.map +1 -1
  104. package/dist/src/testing/index.js +1 -0
  105. package/dist/src/testing/index.js.map +1 -1
  106. package/dist/src/testing/rule-tester.d.ts +12 -0
  107. package/dist/src/testing/rule-tester.d.ts.map +1 -0
  108. package/dist/src/testing/rule-tester.js +34 -0
  109. package/dist/src/testing/rule-tester.js.map +1 -0
  110. package/entrypoints/cli.js +5 -0
  111. package/entrypoints/server.js +5 -0
  112. package/lib/decorators.tsp +8 -0
  113. package/package.json +12 -10
@@ -1,13 +1,39 @@
1
1
  import { getSourceLocation } from "../core/diagnostics.js";
2
- import { parse as typespecParse } from "../core/parser.js";
2
+ import { parse as typespecParse, visitChildren } from "../core/parser.js";
3
+ import { SyntaxKind } from "../core/types.js";
4
+ import { mutate } from "../core/util.js";
3
5
  export function parse(text, parsers, opts) {
4
- const result = typespecParse(text, { comments: true, docs: false });
6
+ const result = typespecParse(text, { comments: true, docs: true });
7
+ flattenNamespaces(result);
5
8
  const errors = result.parseDiagnostics.filter((x) => x.severity === "error");
6
9
  if (errors.length > 0 && !result.printable) {
7
10
  throw new PrettierParserError(errors[0]);
8
11
  }
12
+ // Remove doc comments as those are handled directly.
13
+ mutate(result).comments = result.comments.filter((x) => !(x.kind === SyntaxKind.BlockComment && x.parsedAsDocs));
9
14
  return result;
10
15
  }
16
+ /**
17
+ * We are patching the syntax tree to flatten the namespace nodes that are created from namespace Foo.Bar; which have the same pos, end
18
+ * This causes prettier to not know where comments belong.
19
+ * https://github.com/microsoft/typespec/pull/2061
20
+ */
21
+ function flattenNamespaces(base) {
22
+ visitChildren(base, (node) => {
23
+ if (node.kind === SyntaxKind.NamespaceStatement) {
24
+ let current = node;
25
+ const ids = [node.id];
26
+ while (current.statements && "kind" in current.statements) {
27
+ current = current.statements;
28
+ ids.push(current.id);
29
+ }
30
+ Object.assign(node, current, {
31
+ ids,
32
+ });
33
+ flattenNamespaces(current);
34
+ }
35
+ });
36
+ }
11
37
  export class PrettierParserError extends Error {
12
38
  constructor(error) {
13
39
  var _a, _b;
@@ -1 +1 @@
1
- {"version":3,"file":"parser.js","sourceRoot":"","sources":["../../../src/formatter/parser.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,EAAE,KAAK,IAAI,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAG3D,MAAM,UAAU,KAAK,CACnB,IAAY,EACZ,OAAyC,EACzC,IAA+C;IAE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GAAG;aACJ,CAAC,CAAC;YACH,iBAAiB,CAAC,OAAO,CAAC,CAAC;SAC5B;IACH,CAAC,CAAC,CAAC;AACL,CAAC;AAED,MAAM,OAAO,mBAAoB,SAAQ,KAAK;IAE5C,YAAmC,KAAiB;;QAClD,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;QADY,UAAK,GAAL,KAAK,CAAY;QAElD,MAAM,QAAQ,GAAG,iBAAiB,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;QACjD,IAAI,CAAC,GAAG,GAAG;YACT,KAAK,EAAE,MAAA,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,GAAG,mCAAI,CAAC;YACzB,GAAG,EAAE,MAAA,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,GAAG,mCAAI,CAAC;SACxB,CAAC;IACJ,CAAC;CACF"}
@@ -1,5 +1,5 @@
1
1
  import { Printer } from "prettier";
2
- import { Node } from "../../core/index.js";
2
+ import { Node } from "../../core/types.js";
3
3
  /**
4
4
  * Override the default behavior to attach comments to syntax node.
5
5
  */
@@ -1 +1 @@
1
- {"version":3,"file":"comment-handler.d.ts","sourceRoot":"","sources":["../../../../src/formatter/print/comment-handler.ts"],"names":[],"mappings":"AAAA,OAAiB,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AAC7C,OAAO,EAAE,IAAI,EAAc,MAAM,qBAAqB,CAAC;AASvD;;GAEG;AACH,eAAO,MAAM,cAAc,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC,gBAAgB,CAK1D,CAAC"}
1
+ {"version":3,"file":"comment-handler.d.ts","sourceRoot":"","sources":["../../../../src/formatter/print/comment-handler.ts"],"names":[],"mappings":"AAAA,OAAiB,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AAC7C,OAAO,EAAE,IAAI,EAAkC,MAAM,qBAAqB,CAAC;AAU3E;;GAEG;AACH,eAAO,MAAM,cAAc,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC,gBAAgB,CAQ1D,CAAC"}
@@ -1,11 +1,16 @@
1
1
  import prettier from "prettier";
2
- import { SyntaxKind } from "../../core/index.js";
2
+ import { SyntaxKind } from "../../core/types.js";
3
3
  const { util } = prettier;
4
4
  /**
5
5
  * Override the default behavior to attach comments to syntax node.
6
6
  */
7
7
  export const commentHandler = {
8
- ownLine: (comment) => [addEmptyInterfaceComment, addEmptyModelComment, addStatementDecoratorComment].some((x) => x(comment)),
8
+ ownLine: (comment, text, options, ast, isLastComment) => [
9
+ addEmptyInterfaceComment,
10
+ addEmptyModelComment,
11
+ addStatementDecoratorComment,
12
+ handleOnlyComments,
13
+ ].some((x) => x({ comment, text, options, ast: ast, isLastComment })),
9
14
  };
10
15
  /**
11
16
  * When a comment is on an empty interface make sure it gets added as a dangling comment on it and not on the identifier.
@@ -16,7 +21,7 @@ export const commentHandler = {
16
21
  * // My comment
17
22
  * }
18
23
  */
19
- function addEmptyInterfaceComment(comment) {
24
+ function addEmptyInterfaceComment({ comment }) {
20
25
  const { precedingNode, enclosingNode } = comment;
21
26
  if (enclosingNode &&
22
27
  enclosingNode.kind === SyntaxKind.InterfaceStatement &&
@@ -39,7 +44,7 @@ function addEmptyInterfaceComment(comment) {
39
44
  * model Foo {
40
45
  * }
41
46
  */
42
- function addStatementDecoratorComment(comment) {
47
+ function addStatementDecoratorComment({ comment }) {
43
48
  const { enclosingNode, precedingNode } = comment;
44
49
  if (precedingNode &&
45
50
  precedingNode.kind === SyntaxKind.DecoratorExpression &&
@@ -48,6 +53,8 @@ function addStatementDecoratorComment(comment) {
48
53
  enclosingNode.kind === SyntaxKind.ModelStatement ||
49
54
  enclosingNode.kind === SyntaxKind.EnumStatement ||
50
55
  enclosingNode.kind === SyntaxKind.OperationStatement ||
56
+ enclosingNode.kind === SyntaxKind.ScalarStatement ||
57
+ enclosingNode.kind === SyntaxKind.InterfaceStatement ||
51
58
  enclosingNode.kind === SyntaxKind.ModelProperty ||
52
59
  enclosingNode.kind === SyntaxKind.EnumMember ||
53
60
  enclosingNode.kind === SyntaxKind.UnionStatement)) {
@@ -65,7 +72,7 @@ function addStatementDecoratorComment(comment) {
65
72
  * // My comment
66
73
  * }
67
74
  */
68
- function addEmptyModelComment(comment) {
75
+ function addEmptyModelComment({ comment }) {
69
76
  const { precedingNode, enclosingNode } = comment;
70
77
  if (enclosingNode &&
71
78
  enclosingNode.kind === SyntaxKind.ModelStatement &&
@@ -79,4 +86,29 @@ function addEmptyModelComment(comment) {
79
86
  }
80
87
  return false;
81
88
  }
89
+ function handleOnlyComments({ comment, ast, isLastComment }) {
90
+ var _a, _b;
91
+ const { enclosingNode } = comment;
92
+ if (((_a = ast === null || ast === void 0 ? void 0 : ast.statements) === null || _a === void 0 ? void 0 : _a.length) === 0) {
93
+ if (isLastComment) {
94
+ util.addDanglingComment(ast, comment, undefined);
95
+ }
96
+ else {
97
+ util.addLeadingComment(ast, comment);
98
+ }
99
+ return true;
100
+ }
101
+ if ((enclosingNode === null || enclosingNode === void 0 ? void 0 : enclosingNode.kind) === SyntaxKind.TypeSpecScript &&
102
+ enclosingNode.statements.length === 0 &&
103
+ ((_b = enclosingNode.directives) === null || _b === void 0 ? void 0 : _b.length) === 0) {
104
+ if (isLastComment) {
105
+ util.addDanglingComment(enclosingNode, comment, undefined);
106
+ }
107
+ else {
108
+ util.addLeadingComment(enclosingNode, comment);
109
+ }
110
+ return true;
111
+ }
112
+ return false;
113
+ }
82
114
  //# sourceMappingURL=comment-handler.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"comment-handler.js","sourceRoot":"","sources":["../../../../src/formatter/print/comment-handler.ts"],"names":[],"mappings":"AAAA,OAAO,QAAqB,MAAM,UAAU,CAAC;AAC7C,OAAO,EAAQ,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAEvD,MAAM,EAAE,IAAI,EAAE,GAAG,QAAQ,CAAC;AAO1B;;GAEG;AACH,MAAM,CAAC,MAAM,cAAc,GAAoC;IAC7D,OAAO,EAAE,CAAC,OAAO,EA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IAAI,CAAC;KACb;IAED,OAAO,KAAK,CAAC;AACf,CAAC"}
@@ -1,5 +1,5 @@
1
1
  import { AstPath } from "prettier";
2
- import { Node } from "../../core/index.js";
2
+ import { Node } from "../../core/types.js";
3
3
  import { TypeSpecPrettierOptions } from "./types.js";
4
4
  /**
5
5
  * Check if the current path should be wrapped in parentheses
@@ -1,4 +1,4 @@
1
- import { SyntaxKind } from "../../core/index.js";
1
+ import { SyntaxKind } from "../../core/types.js";
2
2
  /**
3
3
  * Check if the current path should be wrapped in parentheses
4
4
  * @param path Prettier print path.
@@ -1,9 +1,11 @@
1
1
  import prettier, { AstPath, Doc, Printer } from "prettier";
2
- import { AliasStatementNode, ArrayExpressionNode, AugmentDecoratorStatementNode, Comment, DecoratorDeclarationStatementNode, DecoratorExpressionNode, DirectiveExpressionNode, EnumMemberNode, EnumStatementNode, FunctionDeclarationStatementNode, InterfaceStatementNode, IntersectionExpressionNode, MemberExpressionNode, ModelExpressionNode, ModelPropertyNode, ModelStatementNode, NamespaceStatementNode, Node, OperationSignatureDeclarationNode, OperationSignatureReferenceNode, OperationStatementNode, ProjectionArithmeticExpressionNode, ProjectionBlockExpressionNode, ProjectionCallExpressionNode, ProjectionEqualityExpressionNode, ProjectionLambdaExpressionNode, ProjectionLambdaParameterDeclarationNode, ProjectionLogicalExpressionNode, ProjectionMemberExpressionNode, ProjectionModelExpressionNode, ProjectionModelPropertyNode, ProjectionRelationalExpressionNode, ProjectionTupleExpressionNode, ProjectionUnaryExpressionNode, ReturnExpressionNode, ScalarStatementNode, TupleExpressionNode, TypeReferenceNode, UnionExpressionNode, UnionStatementNode, UnionVariantNode, ValueOfExpressionNode } from "../../core/types.js";
2
+ import { AliasStatementNode, ArrayExpressionNode, AugmentDecoratorStatementNode, Comment, DecoratorDeclarationStatementNode, DecoratorExpressionNode, DirectiveExpressionNode, EnumMemberNode, EnumStatementNode, FunctionDeclarationStatementNode, InterfaceStatementNode, IntersectionExpressionNode, MemberExpressionNode, ModelExpressionNode, ModelPropertyNode, ModelStatementNode, Node, OperationSignatureDeclarationNode, OperationSignatureReferenceNode, OperationStatementNode, ProjectionArithmeticExpressionNode, ProjectionBlockExpressionNode, ProjectionCallExpressionNode, ProjectionEqualityExpressionNode, ProjectionLambdaExpressionNode, ProjectionLambdaParameterDeclarationNode, ProjectionLogicalExpressionNode, ProjectionMemberExpressionNode, ProjectionModelExpressionNode, ProjectionModelPropertyNode, ProjectionRelationalExpressionNode, ProjectionTupleExpressionNode, ProjectionUnaryExpressionNode, ReturnExpressionNode, ScalarStatementNode, TupleExpressionNode, TypeReferenceNode, TypeSpecScriptNode, UnionExpressionNode, UnionStatementNode, UnionVariantNode, ValueOfExpressionNode } from "../../core/types.js";
3
+ import { FlattenedNamespaceStatementNode } from "../types.js";
3
4
  import { DecorableNode, PrettierChildPrint, TypeSpecPrettierOptions } from "./types.js";
4
5
  export declare const typespecPrinter: Printer<Node>;
5
6
  export declare function printTypeSpec(path: AstPath<Node>, options: TypeSpecPrettierOptions, print: PrettierChildPrint): prettier.Doc;
6
7
  export declare function printNode(path: AstPath<Node>, options: TypeSpecPrettierOptions, print: PrettierChildPrint): prettier.Doc;
8
+ export declare function printTypeSpecScript(path: AstPath<TypeSpecScriptNode>, options: TypeSpecPrettierOptions, print: PrettierChildPrint): Doc;
7
9
  export declare function printAliasStatement(path: AstPath<AliasStatementNode>, options: TypeSpecPrettierOptions, print: PrettierChildPrint): prettier.doc.builders.Doc[];
8
10
  export declare function canAttachComment(node: Node): boolean;
9
11
  export declare function printComment(commentPath: AstPath<Node | Comment>, options: TypeSpecPrettierOptions): Doc;
@@ -15,6 +17,7 @@ export declare function printDecorators(path: AstPath<DecorableNode>, options: o
15
17
  };
16
18
  export declare function printDecorator(path: AstPath<DecoratorExpressionNode>, options: TypeSpecPrettierOptions, print: PrettierChildPrint): prettier.doc.builders.Doc[];
17
19
  export declare function printAugmentDecorator(path: AstPath<AugmentDecoratorStatementNode>, options: TypeSpecPrettierOptions, print: PrettierChildPrint): prettier.doc.builders.Doc[];
20
+ export declare function printDocComments(path: AstPath<Node>, options: object, print: PrettierChildPrint): prettier.doc.builders.Group | "";
18
21
  export declare function printDirectives(path: AstPath<Node>, options: object, print: PrettierChildPrint): prettier.doc.builders.Group | "";
19
22
  export declare function printDirective(path: AstPath<DirectiveExpressionNode>, options: TypeSpecPrettierOptions, print: PrettierChildPrint): prettier.doc.builders.Doc[];
20
23
  export declare function printDirectiveArgs(path: AstPath<DirectiveExpressionNode>, options: object, print: PrettierChildPrint): prettier.doc.builders.Concat | "";
@@ -43,7 +46,7 @@ export declare function printModelStatement(path: AstPath<ModelStatementNode>, o
43
46
  export declare function printModelProperty(path: AstPath<ModelPropertyNode | ProjectionModelPropertyNode>, options: TypeSpecPrettierOptions, print: PrettierChildPrint): prettier.doc.builders.Doc[];
44
47
  export declare function printId(sv: string): string;
45
48
  export declare function printScalarStatement(path: AstPath<ScalarStatementNode>, options: TypeSpecPrettierOptions, print: PrettierChildPrint): prettier.doc.builders.Doc[];
46
- export declare function printNamespaceStatement(path: AstPath<NamespaceStatementNode>, options: TypeSpecPrettierOptions, print: PrettierChildPrint): prettier.doc.builders.Doc;
49
+ export declare function printNamespaceStatement(path: AstPath<FlattenedNamespaceStatementNode>, options: TypeSpecPrettierOptions, print: PrettierChildPrint): prettier.doc.builders.Doc[];
47
50
  export declare function printOperationSignatureDeclaration(path: AstPath<OperationSignatureDeclarationNode>, options: TypeSpecPrettierOptions, print: PrettierChildPrint): prettier.doc.builders.Doc[];
48
51
  export declare function printOperationSignatureReference(path: AstPath<OperationSignatureReferenceNode>, options: TypeSpecPrettierOptions, print: PrettierChildPrint): prettier.doc.builders.Doc[];
49
52
  export declare function printOperationStatement(path: AstPath<OperationStatementNode>, options: TypeSpecPrettierOptions, print: PrettierChildPrint): prettier.doc.builders.Doc[];
@@ -52,7 +55,7 @@ export declare function printUnion(path: AstPath<UnionExpressionNode>, options:
52
55
  export declare function printTypeReference(path: prettier.AstPath<TypeReferenceNode>, options: TypeSpecPrettierOptions, print: PrettierChildPrint): prettier.doc.builders.Doc;
53
56
  export declare function printValueOfExpression(path: prettier.AstPath<ValueOfExpressionNode>, options: TypeSpecPrettierOptions, print: PrettierChildPrint): prettier.doc.builders.Doc;
54
57
  export declare function printModifiers(path: AstPath<DecoratorDeclarationStatementNode | FunctionDeclarationStatementNode>, options: TypeSpecPrettierOptions, print: PrettierChildPrint): prettier.Doc;
55
- export declare function printProjectionBlockExpressionNode(path: AstPath<ProjectionBlockExpressionNode>, options: TypeSpecPrettierOptions, print: PrettierChildPrint): "{}" | (string | prettier.doc.builders.Concat | prettier.doc.builders.Indent)[];
58
+ export declare function printProjectionBlockExpressionNode(path: AstPath<ProjectionBlockExpressionNode>, options: TypeSpecPrettierOptions, print: PrettierChildPrint): (string | prettier.doc.builders.Concat | prettier.doc.builders.Indent)[] | "{}";
56
59
  export declare function printProjectionMemberExpression(path: AstPath<ProjectionMemberExpressionNode>, options: TypeSpecPrettierOptions, print: PrettierChildPrint): prettier.doc.builders.Doc[];
57
60
  export declare function printProjectionLeftRightExpression(path: AstPath<ProjectionLogicalExpressionNode | ProjectionRelationalExpressionNode | ProjectionEqualityExpressionNode | ProjectionArithmeticExpressionNode>, options: TypeSpecPrettierOptions, print: PrettierChildPrint): prettier.doc.builders.Doc[];
58
61
  export declare function printProjectionUnaryExpression(path: AstPath<ProjectionUnaryExpressionNode>, options: TypeSpecPrettierOptions, print: PrettierChildPrint): prettier.doc.builders.Doc[];
@@ -1 +1 @@
1
- {"version":3,"file":"printer.d.ts","sourceRoot":"","sources":["../../../../src/formatter/print/printer.ts"],"names":[],"mappings":"AAAA,OAAO,QAAQ,EAAE,EAAE,OAAO,EAAE,GAAG,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AAI3D,OAAO,EACL,kBAAkB,EAClB,mBAAmB,EACnB,6BAA6B,EAG7B,OAAO,EACP,iCAAiC,EACjC,uBAAuB,EACvB,uBAAuB,EACvB,cAAc,EAEd,iBAAiB,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EAAE,uBAAuB,EAChC,KAAK,EAAE,kBAAkB,+BAW1B;AAED,wBAAgB,+BAA+B,CAC7C,IAAI,EAAE,OAAO,CAAC,8BAA8B,CAAC,EAC7C,OAAO,EAAE,uBAAuB,EAChC,KAAK,EAAE,kBAAkB,+BAS1B;AAED,wBAAgB,yCAAyC,CACvD,IAAI,EAAE,OAAO,CAAC,wCAAwC,CAAC,EACvD,OAAO,EAAE,uBAAuB,EAChC,KAAK,EAAE,kBAAkB,6BAG1B;AAED,wBAAgB,qBAAqB,CACnC,IAAI,EAAE,OAAO,CAAC,oBAAoB,CAAC,EACnC,OAAO,EAAE,uBAAuB,EAChC,KAAK,EAAE,kBAAkB,+BAG1B"}
@@ -3,11 +3,18 @@ import { isIdentifierContinue, isIdentifierStart, utf16CodeUnits } from "../../c
3
3
  import { compilerAssert } from "../../core/diagnostics.js";
4
4
  import { Keywords } from "../../core/scanner.js";
5
5
  import { SyntaxKind, } from "../../core/types.js";
6
- import { isArray } from "../../core/util.js";
7
6
  import { commentHandler } from "./comment-handler.js";
8
7
  import { needsParens } from "./needs-parens.js";
9
8
  const { align, breakParent, group, hardline, ifBreak, indent, join, line, softline } = prettier.doc.builders;
10
9
  const { isNextLineEmpty } = prettier.util;
10
+ /**
11
+ * If the decorators for that node should try to be kept inline.
12
+ */
13
+ const DecoratorsTryInline = {
14
+ modelProperty: true,
15
+ enumMember: true,
16
+ unionVariant: true,
17
+ };
11
18
  export const typespecPrinter = {
12
19
  print: printTypeSpec,
13
20
  canAttachComment: canAttachComment,
@@ -18,10 +25,11 @@ export function printTypeSpec(
18
25
  // Path to the AST node to print
19
26
  path, options, print) {
20
27
  const node = path.getValue();
28
+ const docs = printDocComments(path, options, print);
21
29
  const directives = shouldPrintDirective(node) ? printDirectives(path, options, print) : "";
22
30
  const printedNode = printNode(path, options, print);
23
31
  const value = needsParens(path, options) ? ["(", printedNode, ")"] : printedNode;
24
- const parts = [directives, value];
32
+ const parts = [docs, directives, value];
25
33
  if (node.kind === SyntaxKind.TypeSpecScript) {
26
34
  // For TypeSpecScript(root of typespec document) we had a new line at the end.
27
35
  // This must be done here so the hardline entry can be the last item of the doc array returned by the printer
@@ -38,13 +46,10 @@ export function printNode(
38
46
  // Path to the AST node to print
39
47
  path, options, print) {
40
48
  const node = path.getValue();
41
- printDirectives(path, options, print);
42
49
  switch (node.kind) {
43
50
  // Root
44
51
  case SyntaxKind.TypeSpecScript:
45
- return [
46
- printStatementSequence(path, options, print, "statements"),
47
- ];
52
+ return printTypeSpecScript(path, options, print);
48
53
  // Statements
49
54
  case SyntaxKind.ImportStatement:
50
55
  return [`import "${node.path.value}";`];
@@ -183,6 +188,7 @@ path, options, print) {
183
188
  case SyntaxKind.Return:
184
189
  return printReturnExpression(path, options, print);
185
190
  case SyntaxKind.Doc:
191
+ return printDoc(path, options, print);
186
192
  case SyntaxKind.DocText:
187
193
  case SyntaxKind.DocParamTag:
188
194
  case SyntaxKind.DocTemplateTag:
@@ -191,8 +197,9 @@ path, options, print) {
191
197
  // https://github.com/microsoft/typespec/issues/1319 Tracks pretty-printing doc comments.
192
198
  compilerAssert(false, "Currently, doc comments are only handled as regular comments and we do not opt in to parsing them so we shouldn't reach here.");
193
199
  return "";
194
- case SyntaxKind.JsSourceFile:
195
200
  case SyntaxKind.EmptyStatement:
201
+ return "";
202
+ case SyntaxKind.JsSourceFile:
196
203
  case SyntaxKind.InvalidStatement:
197
204
  return getRawText(node, options);
198
205
  default:
@@ -203,6 +210,16 @@ path, options, print) {
203
210
  return getRawText(node, options);
204
211
  }
205
212
  }
213
+ export function printTypeSpecScript(path, options, print) {
214
+ const node = path.getValue();
215
+ const nodeHasComments = hasComments(node, CommentCheckFlags.Dangling);
216
+ const body = [];
217
+ if (nodeHasComments) {
218
+ body.push(printDanglingComments(path, options, { sameIndent: true }));
219
+ }
220
+ body.push(printStatementSequence(path, options, print, "statements"));
221
+ return body;
222
+ }
206
223
  export function printAliasStatement(path, options, print) {
207
224
  const id = path.call(print, "id");
208
225
  const template = printTemplateParameters(path, options, print, "templateParameters");
@@ -228,6 +245,13 @@ export function canAttachComment(node) {
228
245
  return Boolean(kind &&
229
246
  kind !== SyntaxKind.LineComment &&
230
247
  kind !== SyntaxKind.BlockComment &&
248
+ kind !== SyntaxKind.EmptyStatement &&
249
+ kind !== SyntaxKind.Doc &&
250
+ kind !== SyntaxKind.DocParamTag &&
251
+ kind !== SyntaxKind.DocReturnsTag &&
252
+ kind !== SyntaxKind.DocTemplateTag &&
253
+ kind !== SyntaxKind.DocText &&
254
+ kind !== SyntaxKind.DocUnknownTag &&
231
255
  !(node.flags & 8 /* NodeFlags.Synthetic */));
232
256
  }
233
257
  export function printComment(commentPath, options) {
@@ -245,11 +269,10 @@ export function printComment(commentPath, options) {
245
269
  function printBlockComment(commentPath, options) {
246
270
  const comment = commentPath.getValue();
247
271
  const rawComment = options.originalText.slice(comment.pos + 2, comment.end - 2);
248
- if (isIndentableBlockComment(rawComment)) {
249
- const printed = printIndentableBlockComment(rawComment);
250
- return printed;
251
- }
252
- return ["/*", rawComment, "*/"];
272
+ const printed = isIndentableBlockComment(rawComment)
273
+ ? printIndentableBlockCommentContent(rawComment)
274
+ : rawComment;
275
+ return ["/*", printed, "*/"];
253
276
  }
254
277
  function isIndentableBlockComment(rawComment) {
255
278
  // If the comment has multiple lines and every line starts with a star
@@ -259,28 +282,42 @@ function isIndentableBlockComment(rawComment) {
259
282
  const lines = `*${rawComment}*`.split("\n");
260
283
  return lines.length > 1 && lines.every((line) => line.trim()[0] === "*");
261
284
  }
262
- function printIndentableBlockComment(rawComment) {
285
+ function printIndentableBlockCommentContent(rawComment) {
263
286
  const lines = rawComment.split("\n");
264
287
  return [
265
- "/*",
266
288
  join(hardline, lines.map((line, index) => index === 0
267
289
  ? line.trimEnd()
268
290
  : " " + (index < lines.length - 1 ? line.trim() : line.trimStart()))),
269
- "*/",
270
291
  ];
271
292
  }
293
+ /** Print a doc comment. */
294
+ function printDoc(path, options, print) {
295
+ const node = path.getValue();
296
+ const rawComment = options.originalText.slice(node.pos + 3, node.end - 2);
297
+ const printed = isIndentableBlockComment(rawComment)
298
+ ? printIndentableBlockCommentContent(rawComment)
299
+ : rawComment.includes("\n")
300
+ ? rawComment
301
+ : ` ${rawComment.trim()} `;
302
+ return ["/**", printed, "*/"];
303
+ }
272
304
  export function printDecorators(path, options, print, { tryInline }) {
273
305
  const node = path.getValue();
274
306
  if (node.decorators.length === 0) {
275
307
  return { decorators: "", multiline: false };
276
308
  }
277
- const shouldBreak = !tryInline || node.decorators.length >= 3 || hasNewlineBetweenOrAfterDecorators(node, options);
309
+ const shouldBreak = shouldDecoratorBreakLine(path, options, { tryInline });
278
310
  const decorators = path.map((x) => [print(x), ifBreak(line, " ")], "decorators");
279
311
  return {
280
312
  decorators: group([shouldBreak ? breakParent : "", decorators]),
281
313
  multiline: shouldBreak,
282
314
  };
283
315
  }
316
+ /** Check if the decorators of the given node should be broken in sparate line */
317
+ function shouldDecoratorBreakLine(path, options, { tryInline }) {
318
+ const node = path.getValue();
319
+ return (!tryInline || node.decorators.length >= 3 || hasNewlineBetweenOrAfterDecorators(node, options));
320
+ }
284
321
  /**
285
322
  * Check if there is already new lines in between the decorators of the node.
286
323
  */
@@ -308,6 +345,14 @@ function printAugmentDecoratorArgs(path, options, print) {
308
345
  ")",
309
346
  ];
310
347
  }
348
+ export function printDocComments(path, options, print) {
349
+ const node = path.getValue();
350
+ if (node.docs === undefined || node.docs.length === 0) {
351
+ return "";
352
+ }
353
+ const docs = path.map((x) => [print(x), line], "docs");
354
+ return group([...docs, breakParent]);
355
+ }
311
356
  export function printDirectives(path, options, print) {
312
357
  const node = path.getValue();
313
358
  if (node.directives === undefined || node.directives.length === 0) {
@@ -379,7 +424,9 @@ export function printEnumMember(path, options, print) {
379
424
  const node = path.getValue();
380
425
  const id = path.call(print, "id");
381
426
  const value = node.value ? [": ", path.call(print, "value")] : "";
382
- const { decorators, multiline } = printDecorators(path, options, print, { tryInline: true });
427
+ const { decorators, multiline } = printDecorators(path, options, print, {
428
+ tryInline: DecoratorsTryInline.enumMember,
429
+ });
383
430
  const propertyIndex = path.stack[path.stack.length - 2];
384
431
  const isNotFirst = typeof propertyIndex === "number" && propertyIndex > 0;
385
432
  return [multiline && isNotFirst ? hardline : "", decorators, id, value];
@@ -411,7 +458,9 @@ export function printUnionVariantsBlock(path, options, print) {
411
458
  export function printUnionVariant(path, options, print) {
412
459
  const id = path.call(print, "id");
413
460
  const value = [": ", path.call(print, "value")];
414
- const { decorators } = printDecorators(path, options, print, { tryInline: true });
461
+ const { decorators } = printDecorators(path, options, print, {
462
+ tryInline: DecoratorsTryInline.unionVariant,
463
+ });
415
464
  return [decorators, id, value];
416
465
  }
417
466
  export function printInterfaceStatement(path, options, print) {
@@ -535,18 +584,19 @@ export function printTuple(path, options, print) {
535
584
  }
536
585
  export function printMemberExpression(path, options, print) {
537
586
  const node = path.getValue();
538
- return [node.base ? [path.call(print, "base"), "."] : "", path.call(print, "id")];
587
+ return [node.base ? [path.call(print, "base"), node.selector] : "", path.call(print, "id")];
539
588
  }
540
589
  export function printModelExpression(path, options, print) {
541
590
  const inBlock = isModelExpressionInBlock(path);
591
+ const node = path.getValue();
542
592
  if (inBlock) {
543
593
  return group(printModelPropertiesBlock(path, options, print));
544
594
  }
545
595
  else {
546
- return group([
547
- indent(join(", ", path.map((arg) => [softline, print(arg)], "properties"))),
548
- softline,
549
- ]);
596
+ const properties = node.properties.length === 0
597
+ ? ""
598
+ : indent(joinPropertiesInBlock(path, options, print, ifBreak(",", ", "), softline));
599
+ return group([properties, softline]);
550
600
  }
551
601
  }
552
602
  export function printModelStatement(path, options, print) {
@@ -580,16 +630,54 @@ function printModelPropertiesBlock(path, options, print) {
580
630
  const tryInline = ((_a = path.getParentNode()) === null || _a === void 0 ? void 0 : _a.kind) === SyntaxKind.TemplateParameterDeclaration;
581
631
  const lineDoc = tryInline ? softline : hardline;
582
632
  const seperator = isModelAValue(path) ? "," : ";";
583
- const body = [
584
- lineDoc,
585
- join([seperator, lineDoc], path.map((x) => [print(x)], "properties")),
586
- hasProperties ? ifBreak(seperator) : "",
587
- ];
633
+ const body = [joinPropertiesInBlock(path, options, print, seperator, lineDoc)];
588
634
  if (nodeHasComments) {
589
635
  body.push(printDanglingComments(path, options, { sameIndent: true }));
590
636
  }
591
637
  return group(["{", indent(body), lineDoc, "}"]);
592
638
  }
639
+ function joinPropertiesInBlock(path, options, print, separator, regularLine) {
640
+ const doc = [regularLine];
641
+ const propertyContainerNode = path.getValue();
642
+ let newLineBeforeNextProp = false;
643
+ path.each((item, propertyIndex) => {
644
+ const isFirst = propertyIndex === 0;
645
+ const isLast = propertyIndex === propertyContainerNode.properties.length - 1;
646
+ const shouldWrapInNewLines = shouldWrapPropertyInNewLines(item, options);
647
+ if ((newLineBeforeNextProp || shouldWrapInNewLines) && !isFirst) {
648
+ doc.push(hardline);
649
+ newLineBeforeNextProp = false;
650
+ }
651
+ doc.push(print(item));
652
+ if (isLast) {
653
+ doc.push(ifBreak(separator));
654
+ }
655
+ else {
656
+ doc.push(separator);
657
+ doc.push(regularLine);
658
+ if (shouldWrapInNewLines) {
659
+ newLineBeforeNextProp = true;
660
+ }
661
+ }
662
+ }, "properties");
663
+ return doc;
664
+ }
665
+ /**
666
+ * Check if property item (PropertyNode, SpreadProperty) should be wrapped in new lines.
667
+ * It can be wrapped for the following reasons:
668
+ * - has decorators on lines above
669
+ * - has leading comments
670
+ */
671
+ function shouldWrapPropertyInNewLines(path, options) {
672
+ var _a;
673
+ const node = path.getValue();
674
+ return (((node.kind === SyntaxKind.ModelProperty || node.kind === SyntaxKind.ProjectionModelProperty) &&
675
+ shouldDecoratorBreakLine(path, options, {
676
+ tryInline: DecoratorsTryInline.modelProperty,
677
+ })) ||
678
+ hasComments(node, CommentCheckFlags.Leading) ||
679
+ (node.docs && ((_a = node.docs) === null || _a === void 0 ? void 0 : _a.length) > 0));
680
+ }
593
681
  /**
594
682
  * Figure out if this model is being used as a definition or value.
595
683
  * @returns true if the model is used as a value(e.g. decorator value), false if it is used as a model definition.
@@ -611,14 +699,11 @@ function isModelAValue(path) {
611
699
  }
612
700
  export function printModelProperty(path, options, print) {
613
701
  const node = path.getValue();
614
- const propertyIndex = path.stack[path.stack.length - 2];
615
- const isNotFirst = typeof propertyIndex === "number" && propertyIndex > 0;
616
- const { decorators, multiline } = printDecorators(path, options, print, {
617
- tryInline: true,
702
+ const { decorators } = printDecorators(path, options, print, {
703
+ tryInline: DecoratorsTryInline.modelProperty,
618
704
  });
619
705
  const id = printIdentifier(node.id, options);
620
706
  return [
621
- multiline && isNotFirst ? hardline : "",
622
707
  printDirectives(path, options, print),
623
708
  decorators,
624
709
  id,
@@ -687,26 +772,18 @@ export function printScalarStatement(path, options, print) {
687
772
  ];
688
773
  }
689
774
  export function printNamespaceStatement(path, options, print) {
690
- const printNested = (currentPath, parentNames) => {
691
- var _a;
692
- const names = [...parentNames, currentPath.call(print, "id")];
693
- const currentNode = currentPath.getNode();
694
- if (!isArray(currentNode === null || currentNode === void 0 ? void 0 : currentNode.statements) &&
695
- ((_a = currentNode === null || currentNode === void 0 ? void 0 : currentNode.statements) === null || _a === void 0 ? void 0 : _a.kind) === SyntaxKind.NamespaceStatement) {
696
- return path.call((x) => printNested(x, names), "statements");
697
- }
698
- const suffix = (currentNode === null || currentNode === void 0 ? void 0 : currentNode.statements) === undefined
699
- ? ";"
700
- : [
701
- " {",
702
- indent([hardline, printStatementSequence(path, options, print, "statements")]),
703
- hardline,
704
- "}",
705
- ];
706
- const { decorators } = printDecorators(path, options, print, { tryInline: false });
707
- return [decorators, `namespace `, join(".", names), suffix];
708
- };
709
- return printNested(path, []);
775
+ const names = path.map(print, "ids");
776
+ const currentNode = path.getNode();
777
+ const suffix = (currentNode === null || currentNode === void 0 ? void 0 : currentNode.statements) === undefined
778
+ ? ";"
779
+ : [
780
+ " {",
781
+ indent([hardline, printStatementSequence(path, options, print, "statements")]),
782
+ hardline,
783
+ "}",
784
+ ];
785
+ const { decorators } = printDecorators(path, options, print, { tryInline: false });
786
+ return [decorators, `namespace `, join(".", names), suffix];
710
787
  }
711
788
  export function printOperationSignatureDeclaration(path, options, print) {
712
789
  return ["(", path.call(print, "parameters"), "): ", path.call(print, "returnType")];