@typespec/prettier-plugin-typespec 0.56.0-dev.1 → 0.56.0-dev.3

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
@@ -9,7 +9,7 @@ function createSourceFile(text, path) {
9
9
  getLineAndCharacterOfPosition,
10
10
  };
11
11
  function getLineStarts() {
12
- return (lineStarts = lineStarts !== null && lineStarts !== void 0 ? lineStarts : scanLineStarts(text));
12
+ return (lineStarts = lineStarts ?? scanLineStarts(text));
13
13
  }
14
14
  function getLineAndCharacterOfPosition(position) {
15
15
  const starts = getLineStarts();
@@ -196,17 +196,6 @@ var ListenerFlow;
196
196
  ListenerFlow[ListenerFlow["NoRecursion"] = 1] = "NoRecursion";
197
197
  })(ListenerFlow || (ListenerFlow = {}));
198
198
 
199
- (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
200
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
201
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
202
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
203
- };
204
- (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
205
- if (kind === "m") throw new TypeError("Private method is not writable");
206
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
207
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
208
- return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
209
- };
210
199
  /**
211
200
  * A specially typed version of `Array.isArray` to work around [this issue](https://github.com/microsoft/TypeScript/issues/17002).
212
201
  */
@@ -236,7 +225,6 @@ function createDiagnosticCreator(diagnostics, libraryName) {
236
225
  ? `It must match one of the code defined in the library '${libraryName}'`
237
226
  : "It must match one of the code defined in the compiler.";
238
227
  function createDiagnostic(diagnostic) {
239
- var _a;
240
228
  const diagnosticDef = diagnostics[diagnostic.code];
241
229
  if (!diagnosticDef) {
242
230
  const codeStr = Object.keys(diagnostics)
@@ -245,7 +233,7 @@ function createDiagnosticCreator(diagnostics, libraryName) {
245
233
  const code = String(diagnostic.code);
246
234
  throw new Error(`Unexpected diagnostic code '${code}'. ${errorMessage}. Defined codes:\n${codeStr}`);
247
235
  }
248
- const message = diagnosticDef.messages[(_a = diagnostic.messageId) !== null && _a !== void 0 ? _a : "default"];
236
+ const message = diagnosticDef.messages[diagnostic.messageId ?? "default"];
249
237
  if (!message) {
250
238
  const codeStr = Object.keys(diagnosticDef.messages)
251
239
  .map((x) => ` - ${x}`)
@@ -3890,7 +3878,7 @@ function createScanner(source, diagnosticHandler) {
3890
3878
  function error(report, pos, end) {
3891
3879
  const diagnostic = createDiagnostic({
3892
3880
  ...report,
3893
- target: { file, pos: pos !== null && pos !== void 0 ? pos : tokenPosition, end: end !== null && end !== void 0 ? end : position },
3881
+ target: { file, pos: pos ?? tokenPosition, end: end ?? position },
3894
3882
  });
3895
3883
  diagnosticHandler(diagnostic);
3896
3884
  }
@@ -4548,9 +4536,8 @@ function addEmptyModelComment({ comment }) {
4548
4536
  return false;
4549
4537
  }
4550
4538
  function handleOnlyComments({ comment, ast, isLastComment }) {
4551
- var _a, _b;
4552
4539
  const { enclosingNode } = comment;
4553
- if (((_a = ast === null || ast === void 0 ? void 0 : ast.statements) === null || _a === void 0 ? void 0 : _a.length) === 0) {
4540
+ if (ast?.statements?.length === 0) {
4554
4541
  if (isLastComment) {
4555
4542
  util.addDanglingComment(ast, comment, undefined);
4556
4543
  }
@@ -4559,9 +4546,9 @@ function handleOnlyComments({ comment, ast, isLastComment }) {
4559
4546
  }
4560
4547
  return true;
4561
4548
  }
4562
- if ((enclosingNode === null || enclosingNode === void 0 ? void 0 : enclosingNode.kind) === SyntaxKind.TypeSpecScript &&
4549
+ if (enclosingNode?.kind === SyntaxKind.TypeSpecScript &&
4563
4550
  enclosingNode.statements.length === 0 &&
4564
- ((_b = enclosingNode.directives) === null || _b === void 0 ? void 0 : _b.length) === 0) {
4551
+ enclosingNode.directives?.length === 0) {
4565
4552
  if (isLastComment) {
4566
4553
  util.addDanglingComment(enclosingNode, comment, undefined);
4567
4554
  }
@@ -5209,14 +5196,13 @@ function printModelStatement(path, options, print) {
5209
5196
  ];
5210
5197
  }
5211
5198
  function printModelPropertiesBlock(path, options, print) {
5212
- var _a;
5213
5199
  const node = path.node;
5214
5200
  const hasProperties = node.properties && node.properties.length > 0;
5215
5201
  const nodeHasComments = hasComments(node, CommentCheckFlags.Dangling);
5216
5202
  if (!hasProperties && !nodeHasComments) {
5217
5203
  return "{}";
5218
5204
  }
5219
- const tryInline = ((_a = path.getParentNode()) === null || _a === void 0 ? void 0 : _a.kind) === SyntaxKind.TemplateParameterDeclaration;
5205
+ const tryInline = path.getParentNode()?.kind === SyntaxKind.TemplateParameterDeclaration;
5220
5206
  const lineDoc = tryInline ? softline : hardline;
5221
5207
  const seperator = isModelAValue(path) ? "," : ";";
5222
5208
  const body = [joinMembersInBlock(path, "properties", options, print, seperator, lineDoc)];
@@ -5267,7 +5253,6 @@ function joinMembersInBlock(path, member, options, print, separator, regularLine
5267
5253
  * - has leading comments
5268
5254
  */
5269
5255
  function shouldWrapMemberInNewLines(path, options) {
5270
- var _a;
5271
5256
  const node = path.node;
5272
5257
  return ((node.kind !== SyntaxKind.ModelSpreadProperty &&
5273
5258
  node.kind !== SyntaxKind.ProjectionModelSpreadProperty &&
@@ -5276,7 +5261,7 @@ function shouldWrapMemberInNewLines(path, options) {
5276
5261
  tryInline: DecoratorsTryInline.modelProperty,
5277
5262
  })) ||
5278
5263
  hasComments(node, CommentCheckFlags.Leading) ||
5279
- (node.docs && ((_a = node.docs) === null || _a === void 0 ? void 0 : _a.length) > 0));
5264
+ (node.docs && node.docs?.length > 0));
5280
5265
  }
5281
5266
  /**
5282
5267
  * Figure out if this model is being used as a definition or value.
@@ -5348,7 +5333,7 @@ function needBacktick(sv) {
5348
5333
  }
5349
5334
  function isModelExpressionInBlock(path) {
5350
5335
  const parent = path.getParentNode();
5351
- switch (parent === null || parent === void 0 ? void 0 : parent.kind) {
5336
+ switch (parent?.kind) {
5352
5337
  case SyntaxKind.OperationSignatureDeclaration:
5353
5338
  return parent.parameters !== path.getNode();
5354
5339
  default:
@@ -5374,7 +5359,7 @@ function printScalarStatement(path, options, print) {
5374
5359
  function printNamespaceStatement(path, options, print) {
5375
5360
  const names = path.map(print, "ids");
5376
5361
  const currentNode = path.getNode();
5377
- const suffix = (currentNode === null || currentNode === void 0 ? void 0 : currentNode.statements) === undefined
5362
+ const suffix = currentNode?.statements === undefined
5378
5363
  ? ";"
5379
5364
  : [
5380
5365
  " {",
@@ -5392,8 +5377,7 @@ function printOperationSignatureReference(path, options, print) {
5392
5377
  return [" is ", path.call(print, "baseOperation")];
5393
5378
  }
5394
5379
  function printOperationStatement(path, options, print) {
5395
- var _a;
5396
- const inInterface = ((_a = path.getParentNode()) === null || _a === void 0 ? void 0 : _a.kind) === SyntaxKind.InterfaceStatement;
5380
+ const inInterface = path.getParentNode()?.kind === SyntaxKind.InterfaceStatement;
5397
5381
  const templateParams = printTemplateParameters(path, options, print, "templateParameters");
5398
5382
  const { decorators } = printDecorators(path, options, print, {
5399
5383
  tryInline: true,
@@ -6977,15 +6961,14 @@ function createParser(code, options = {}) {
6977
6961
  };
6978
6962
  }
6979
6963
  function parseIdentifier(options) {
6980
- var _a;
6981
- if ((options === null || options === void 0 ? void 0 : options.recoverFromKeyword) !== false && isKeyword(token())) {
6964
+ if (options?.recoverFromKeyword !== false && isKeyword(token())) {
6982
6965
  error({ code: "reserved-identifier" });
6983
6966
  }
6984
6967
  else if (token() !== Token.Identifier &&
6985
- (!(options === null || options === void 0 ? void 0 : options.allowStringLiteral) || token() !== Token.StringLiteral)) {
6968
+ (!options?.allowStringLiteral || token() !== Token.StringLiteral)) {
6986
6969
  // Error recovery: when we fail to parse an identifier or expression,
6987
6970
  // we insert a synthesized identifier with a unique name.
6988
- error({ code: "token-expected", messageId: (_a = options === null || options === void 0 ? void 0 : options.message) !== null && _a !== void 0 ? _a : "identifier" });
6971
+ error({ code: "token-expected", messageId: options?.message ?? "identifier" });
6989
6972
  return createMissingIdentifier();
6990
6973
  }
6991
6974
  const pos = tokenPos();
@@ -8131,12 +8114,11 @@ function createParser(code, options = {}) {
8131
8114
  return { kind: SyntaxKind.InvalidStatement, decorators, ...finishNode(pos) };
8132
8115
  }
8133
8116
  function error(report) {
8134
- var _a, _b, _c, _d, _e, _f;
8135
8117
  parseErrorInNextFinishedNode = true;
8136
8118
  const location = {
8137
8119
  file: scanner.file,
8138
- pos: (_b = (_a = report.target) === null || _a === void 0 ? void 0 : _a.pos) !== null && _b !== void 0 ? _b : tokenPos(),
8139
- end: (_d = (_c = report.target) === null || _c === void 0 ? void 0 : _c.end) !== null && _d !== void 0 ? _d : tokenEnd(),
8120
+ pos: report.target?.pos ?? tokenPos(),
8121
+ end: report.target?.end ?? tokenEnd(),
8140
8122
  };
8141
8123
  if (!report.printable) {
8142
8124
  treePrintable = false;
@@ -8145,7 +8127,7 @@ function createParser(code, options = {}) {
8145
8127
  // position. The code path taken by error recovery after logging an error
8146
8128
  // can otherwise produce redundant and less decipherable errors, which this
8147
8129
  // suppresses.
8148
- const realPos = (_f = (_e = report.target) === null || _e === void 0 ? void 0 : _e.realPos) !== null && _f !== void 0 ? _f : location.pos;
8130
+ const realPos = report.target?.realPos ?? location.pos;
8149
8131
  if (realPositionOfLastError === realPos) {
8150
8132
  return;
8151
8133
  }
@@ -8158,11 +8140,10 @@ function createParser(code, options = {}) {
8158
8140
  parseDiagnostics.push(diagnostic);
8159
8141
  }
8160
8142
  function warning(report) {
8161
- var _a, _b, _c, _d;
8162
8143
  const location = {
8163
8144
  file: scanner.file,
8164
- pos: (_b = (_a = report.target) === null || _a === void 0 ? void 0 : _a.pos) !== null && _b !== void 0 ? _b : tokenPos(),
8165
- end: (_d = (_c = report.target) === null || _c === void 0 ? void 0 : _c.end) !== null && _d !== void 0 ? _d : tokenEnd(),
8145
+ pos: report.target?.pos ?? tokenPos(),
8146
+ end: report.target?.end ?? tokenEnd(),
8166
8147
  };
8167
8148
  const diagnostic = createDiagnostic({
8168
8149
  ...report,
@@ -8524,14 +8505,15 @@ function flattenNamespaces(base) {
8524
8505
  });
8525
8506
  }
8526
8507
  class PrettierParserError extends Error {
8508
+ error;
8509
+ loc;
8527
8510
  constructor(error) {
8528
- var _a, _b;
8529
8511
  super(error.message);
8530
8512
  this.error = error;
8531
8513
  const location = getSourceLocation(error.target);
8532
8514
  this.loc = {
8533
- start: (_a = location === null || location === void 0 ? void 0 : location.pos) !== null && _a !== void 0 ? _a : 0,
8534
- end: (_b = location === null || location === void 0 ? void 0 : location.end) !== null && _b !== void 0 ? _b : 0,
8515
+ start: location?.pos ?? 0,
8516
+ end: location?.end ?? 0,
8535
8517
  };
8536
8518
  }
8537
8519
  }