@typespec/prettier-plugin-typespec 0.47.0 → 0.48.0-dev.1

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.
package/dist/index.js CHANGED
@@ -90,6 +90,7 @@ var SyntaxKind;
90
90
  SyntaxKind[SyntaxKind["ProjectionStatement"] = 80] = "ProjectionStatement";
91
91
  SyntaxKind[SyntaxKind["ProjectionDecoratorReferenceExpression"] = 81] = "ProjectionDecoratorReferenceExpression";
92
92
  SyntaxKind[SyntaxKind["Return"] = 82] = "Return";
93
+ SyntaxKind[SyntaxKind["JsNamespaceDeclaration"] = 83] = "JsNamespaceDeclaration";
93
94
  })(SyntaxKind || (SyntaxKind = {}));
94
95
  var IdentifierKind;
95
96
  (function (IdentifierKind) {
@@ -100,6 +101,7 @@ var IdentifierKind;
100
101
  IdentifierKind[IdentifierKind["Declaration"] = 4] = "Declaration";
101
102
  IdentifierKind[IdentifierKind["Other"] = 5] = "Other";
102
103
  })(IdentifierKind || (IdentifierKind = {}));
104
+ /** Used to explicitly specify that a diagnostic has no target. */
103
105
  const NoTarget = Symbol.for("NoTarget");
104
106
  var ListenerFlow;
105
107
  (function (ListenerFlow) {
@@ -185,7 +187,7 @@ function createSourceFile(text, path) {
185
187
  };
186
188
  }
187
189
  }
188
- function getSourceLocation(target) {
190
+ function getSourceLocation(target, options = {}) {
189
191
  if (target === NoTarget || target === undefined) {
190
192
  return undefined;
191
193
  }
@@ -200,17 +202,17 @@ function getSourceLocation(target) {
200
202
  if (!target.declarations[0]) {
201
203
  return createSyntheticSourceLocation();
202
204
  }
203
- return getSourceLocationOfNode(target.declarations[0]);
205
+ return getSourceLocationOfNode(target.declarations[0], options);
204
206
  }
205
207
  else if (typeof target.kind === "number") {
206
208
  // node
207
- return getSourceLocationOfNode(target);
209
+ return getSourceLocationOfNode(target, options);
208
210
  }
209
211
  else {
210
212
  // type
211
213
  const targetNode = target.node;
212
214
  if (targetNode) {
213
- return getSourceLocationOfNode(targetNode);
215
+ return getSourceLocationOfNode(targetNode, options);
214
216
  }
215
217
  return createSyntheticSourceLocation();
216
218
  }
@@ -223,7 +225,7 @@ function createSyntheticSourceLocation(loc = "<unknown location>") {
223
225
  isSynthetic: true,
224
226
  };
225
227
  }
226
- function getSourceLocationOfNode(node) {
228
+ function getSourceLocationOfNode(node, options) {
227
229
  let root = node;
228
230
  while (root.parent !== undefined) {
229
231
  root = root.parent;
@@ -233,6 +235,9 @@ function getSourceLocationOfNode(node) {
233
235
  ? undefined
234
236
  : "<unknown location - cannot obtain source location of unbound node - file bug at https://github.com/microsoft/typespec>");
235
237
  }
238
+ if (options.locateId && "id" in node && node.id !== undefined) {
239
+ node = node.id;
240
+ }
236
241
  return {
237
242
  file: root.file,
238
243
  pos: node.pos,
@@ -1123,6 +1128,12 @@ const diagnostics = {
1123
1128
  default: paramMessage `Alias type '${"typeName"}' recursively references itself.`,
1124
1129
  },
1125
1130
  },
1131
+ "circular-prop": {
1132
+ severity: "error",
1133
+ messages: {
1134
+ default: paramMessage `Property '${"propName"}' recursively references itself.`,
1135
+ },
1136
+ },
1126
1137
  "conflict-marker": {
1127
1138
  severity: "error",
1128
1139
  messages: {
@@ -4617,6 +4628,7 @@ path, options, print) {
4617
4628
  case SyntaxKind.EmptyStatement:
4618
4629
  return "";
4619
4630
  case SyntaxKind.JsSourceFile:
4631
+ case SyntaxKind.JsNamespaceDeclaration:
4620
4632
  case SyntaxKind.InvalidStatement:
4621
4633
  return getRawText(node, options);
4622
4634
  default:
@@ -6388,6 +6400,7 @@ function createParser(code, options = {}) {
6388
6400
  ...finishNode(pos),
6389
6401
  };
6390
6402
  }
6403
+ parseExpected(Token.Semicolon);
6391
6404
  return {
6392
6405
  kind: SyntaxKind.AugmentDecoratorStatement,
6393
6406
  target,
@@ -7608,6 +7621,7 @@ function createParser(code, options = {}) {
7608
7621
  }
7609
7622
  const items = [];
7610
7623
  while (true) {
7624
+ const startingPos = tokenPos();
7611
7625
  const { pos, docs, directives, decorators } = parseAnnotations({
7612
7626
  skipParsingDocNodes: Boolean(kind.invalidAnnotationTarget),
7613
7627
  });
@@ -7682,7 +7696,7 @@ function createParser(code, options = {}) {
7682
7696
  // Example: `model M { a: B <missing semicolon> c: D }
7683
7697
  parseExpected(kind.delimiter);
7684
7698
  }
7685
- if (pos === tokenPos()) {
7699
+ if (startingPos === tokenPos()) {
7686
7700
  // Error recovery: we've inserted everything during this loop iteration
7687
7701
  // and haven't made any progress. Assume that the current token is a bad
7688
7702
  // representation of the end of the the list that we're trying to get
@@ -8059,6 +8073,7 @@ function visitChildren(node, cb) {
8059
8073
  case SyntaxKind.ExternKeyword:
8060
8074
  case SyntaxKind.UnknownKeyword:
8061
8075
  case SyntaxKind.JsSourceFile:
8076
+ case SyntaxKind.JsNamespaceDeclaration:
8062
8077
  case SyntaxKind.DocText:
8063
8078
  return;
8064
8079
  default: