@typespec/prettier-plugin-typespec 0.41.0 → 0.43.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.
- package/dist/index.js +134 -70
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -874,30 +874,33 @@ var SyntaxKind;
|
|
|
874
874
|
SyntaxKind[SyntaxKind["Projection"] = 52] = "Projection";
|
|
875
875
|
SyntaxKind[SyntaxKind["ProjectionParameterDeclaration"] = 53] = "ProjectionParameterDeclaration";
|
|
876
876
|
SyntaxKind[SyntaxKind["ProjectionModelSelector"] = 54] = "ProjectionModelSelector";
|
|
877
|
-
SyntaxKind[SyntaxKind["
|
|
878
|
-
SyntaxKind[SyntaxKind["
|
|
879
|
-
SyntaxKind[SyntaxKind["
|
|
880
|
-
SyntaxKind[SyntaxKind["
|
|
881
|
-
SyntaxKind[SyntaxKind["
|
|
882
|
-
SyntaxKind[SyntaxKind["
|
|
883
|
-
SyntaxKind[SyntaxKind["
|
|
884
|
-
SyntaxKind[SyntaxKind["
|
|
885
|
-
SyntaxKind[SyntaxKind["
|
|
886
|
-
SyntaxKind[SyntaxKind["
|
|
887
|
-
SyntaxKind[SyntaxKind["
|
|
888
|
-
SyntaxKind[SyntaxKind["
|
|
889
|
-
SyntaxKind[SyntaxKind["
|
|
890
|
-
SyntaxKind[SyntaxKind["
|
|
891
|
-
SyntaxKind[SyntaxKind["
|
|
892
|
-
SyntaxKind[SyntaxKind["
|
|
893
|
-
SyntaxKind[SyntaxKind["
|
|
894
|
-
SyntaxKind[SyntaxKind["
|
|
895
|
-
SyntaxKind[SyntaxKind["
|
|
896
|
-
SyntaxKind[SyntaxKind["
|
|
897
|
-
SyntaxKind[SyntaxKind["
|
|
898
|
-
SyntaxKind[SyntaxKind["
|
|
899
|
-
SyntaxKind[SyntaxKind["
|
|
900
|
-
SyntaxKind[SyntaxKind["
|
|
877
|
+
SyntaxKind[SyntaxKind["ProjectionModelPropertySelector"] = 55] = "ProjectionModelPropertySelector";
|
|
878
|
+
SyntaxKind[SyntaxKind["ProjectionOperationSelector"] = 56] = "ProjectionOperationSelector";
|
|
879
|
+
SyntaxKind[SyntaxKind["ProjectionUnionSelector"] = 57] = "ProjectionUnionSelector";
|
|
880
|
+
SyntaxKind[SyntaxKind["ProjectionUnionVariantSelector"] = 58] = "ProjectionUnionVariantSelector";
|
|
881
|
+
SyntaxKind[SyntaxKind["ProjectionInterfaceSelector"] = 59] = "ProjectionInterfaceSelector";
|
|
882
|
+
SyntaxKind[SyntaxKind["ProjectionEnumSelector"] = 60] = "ProjectionEnumSelector";
|
|
883
|
+
SyntaxKind[SyntaxKind["ProjectionEnumMemberSelector"] = 61] = "ProjectionEnumMemberSelector";
|
|
884
|
+
SyntaxKind[SyntaxKind["ProjectionExpressionStatement"] = 62] = "ProjectionExpressionStatement";
|
|
885
|
+
SyntaxKind[SyntaxKind["ProjectionIfExpression"] = 63] = "ProjectionIfExpression";
|
|
886
|
+
SyntaxKind[SyntaxKind["ProjectionBlockExpression"] = 64] = "ProjectionBlockExpression";
|
|
887
|
+
SyntaxKind[SyntaxKind["ProjectionMemberExpression"] = 65] = "ProjectionMemberExpression";
|
|
888
|
+
SyntaxKind[SyntaxKind["ProjectionLogicalExpression"] = 66] = "ProjectionLogicalExpression";
|
|
889
|
+
SyntaxKind[SyntaxKind["ProjectionEqualityExpression"] = 67] = "ProjectionEqualityExpression";
|
|
890
|
+
SyntaxKind[SyntaxKind["ProjectionUnaryExpression"] = 68] = "ProjectionUnaryExpression";
|
|
891
|
+
SyntaxKind[SyntaxKind["ProjectionRelationalExpression"] = 69] = "ProjectionRelationalExpression";
|
|
892
|
+
SyntaxKind[SyntaxKind["ProjectionArithmeticExpression"] = 70] = "ProjectionArithmeticExpression";
|
|
893
|
+
SyntaxKind[SyntaxKind["ProjectionCallExpression"] = 71] = "ProjectionCallExpression";
|
|
894
|
+
SyntaxKind[SyntaxKind["ProjectionLambdaExpression"] = 72] = "ProjectionLambdaExpression";
|
|
895
|
+
SyntaxKind[SyntaxKind["ProjectionLambdaParameterDeclaration"] = 73] = "ProjectionLambdaParameterDeclaration";
|
|
896
|
+
SyntaxKind[SyntaxKind["ProjectionModelExpression"] = 74] = "ProjectionModelExpression";
|
|
897
|
+
SyntaxKind[SyntaxKind["ProjectionModelProperty"] = 75] = "ProjectionModelProperty";
|
|
898
|
+
SyntaxKind[SyntaxKind["ProjectionModelSpreadProperty"] = 76] = "ProjectionModelSpreadProperty";
|
|
899
|
+
SyntaxKind[SyntaxKind["ProjectionSpreadProperty"] = 77] = "ProjectionSpreadProperty";
|
|
900
|
+
SyntaxKind[SyntaxKind["ProjectionTupleExpression"] = 78] = "ProjectionTupleExpression";
|
|
901
|
+
SyntaxKind[SyntaxKind["ProjectionStatement"] = 79] = "ProjectionStatement";
|
|
902
|
+
SyntaxKind[SyntaxKind["ProjectionDecoratorReferenceExpression"] = 80] = "ProjectionDecoratorReferenceExpression";
|
|
903
|
+
SyntaxKind[SyntaxKind["Return"] = 81] = "Return";
|
|
901
904
|
})(SyntaxKind = SyntaxKind || (SyntaxKind = {}));
|
|
902
905
|
var IdentifierKind;
|
|
903
906
|
(function (IdentifierKind) {
|
|
@@ -1235,7 +1238,7 @@ const diagnostics = {
|
|
|
1235
1238
|
inDecorator: paramMessage `Cannot resolve ${"id"} in decorator`,
|
|
1236
1239
|
underNamespace: paramMessage `Namespace ${"namespace"} doesn't have member ${"id"}`,
|
|
1237
1240
|
underContainer: paramMessage `${"kind"} doesn't have member ${"id"}`,
|
|
1238
|
-
node: paramMessage `Cannot resolve '${"id"}' in
|
|
1241
|
+
node: paramMessage `Cannot resolve '${"id"}' in node ${"nodeName"} since it has no members. Did you mean to use "::" instead of "."?`,
|
|
1239
1242
|
},
|
|
1240
1243
|
},
|
|
1241
1244
|
"duplicate-property": {
|
|
@@ -1250,12 +1253,6 @@ const diagnostics = {
|
|
|
1250
1253
|
default: paramMessage `Model has an inherited property named ${"propName"} of type ${"propType"} which cannot override type ${"parentType"}`,
|
|
1251
1254
|
},
|
|
1252
1255
|
},
|
|
1253
|
-
"override-property-intrinsic": {
|
|
1254
|
-
severity: "error",
|
|
1255
|
-
messages: {
|
|
1256
|
-
default: paramMessage `Model has an inherited property named ${"propName"} of type ${"propType"} which can only override an intrinsic type on the parent property, not ${"parentType"}`,
|
|
1257
|
-
},
|
|
1258
|
-
},
|
|
1259
1256
|
"extend-scalar": {
|
|
1260
1257
|
severity: "error",
|
|
1261
1258
|
messages: {
|
|
@@ -1419,6 +1416,12 @@ const diagnostics = {
|
|
|
1419
1416
|
default: paramMessage `Path "${"path"}" cannot be relative. Use {cwd} or {project-root} to specify what the path should be relative to.`,
|
|
1420
1417
|
},
|
|
1421
1418
|
},
|
|
1419
|
+
"config-path-not-found": {
|
|
1420
|
+
severity: "error",
|
|
1421
|
+
messages: {
|
|
1422
|
+
default: paramMessage `No configuration file found at config path "${"path"}".`,
|
|
1423
|
+
},
|
|
1424
|
+
},
|
|
1422
1425
|
/**
|
|
1423
1426
|
* Program
|
|
1424
1427
|
*/
|
|
@@ -3124,14 +3127,20 @@ path, options, print) {
|
|
|
3124
3127
|
return printProjectionStatement(path, options, print);
|
|
3125
3128
|
case SyntaxKind.ProjectionModelSelector:
|
|
3126
3129
|
return "model";
|
|
3130
|
+
case SyntaxKind.ProjectionModelPropertySelector:
|
|
3131
|
+
return "modelproperty";
|
|
3127
3132
|
case SyntaxKind.ProjectionOperationSelector:
|
|
3128
3133
|
return "op";
|
|
3129
3134
|
case SyntaxKind.ProjectionUnionSelector:
|
|
3130
3135
|
return "union";
|
|
3136
|
+
case SyntaxKind.ProjectionUnionVariantSelector:
|
|
3137
|
+
return "unionvariant";
|
|
3131
3138
|
case SyntaxKind.ProjectionInterfaceSelector:
|
|
3132
3139
|
return "interface";
|
|
3133
3140
|
case SyntaxKind.ProjectionEnumSelector:
|
|
3134
3141
|
return "enum";
|
|
3142
|
+
case SyntaxKind.ProjectionEnumMemberSelector:
|
|
3143
|
+
return "enummember";
|
|
3135
3144
|
case SyntaxKind.Projection:
|
|
3136
3145
|
return printProjection(path, options, print);
|
|
3137
3146
|
case SyntaxKind.ProjectionParameterDeclaration:
|
|
@@ -3837,20 +3846,17 @@ function printBooleanLiteral(path, options) {
|
|
|
3837
3846
|
return node.value ? "true" : "false";
|
|
3838
3847
|
}
|
|
3839
3848
|
function printProjectionStatement(path, options, print) {
|
|
3840
|
-
const node = path.getValue();
|
|
3841
3849
|
const selector = path.call(print, "selector");
|
|
3842
3850
|
const id = path.call(print, "id");
|
|
3843
|
-
const
|
|
3844
|
-
const from = node.from ? [hardline, path.call(print, "from")] : "";
|
|
3845
|
-
const body = [to, from];
|
|
3851
|
+
const projections = path.map(print, "projections").flatMap((x) => [hardline, x]);
|
|
3846
3852
|
return [
|
|
3847
3853
|
"projection ",
|
|
3848
3854
|
selector,
|
|
3849
3855
|
"#",
|
|
3850
3856
|
id,
|
|
3851
3857
|
" {",
|
|
3852
|
-
indent(
|
|
3853
|
-
|
|
3858
|
+
indent(projections),
|
|
3859
|
+
projections.length > 0 ? hardline : "",
|
|
3854
3860
|
"}",
|
|
3855
3861
|
];
|
|
3856
3862
|
}
|
|
@@ -3858,7 +3864,15 @@ function printProjection(path, options, print) {
|
|
|
3858
3864
|
const node = path.getValue();
|
|
3859
3865
|
const params = printProjectionParameters(path, options, print);
|
|
3860
3866
|
const body = printProjectionExpressionStatements(path, options, print, "body");
|
|
3861
|
-
return [
|
|
3867
|
+
return [
|
|
3868
|
+
...node.modifierIds.flatMap((i) => [i.sv, " "]),
|
|
3869
|
+
node.directionId.sv,
|
|
3870
|
+
params,
|
|
3871
|
+
" {",
|
|
3872
|
+
indent(body),
|
|
3873
|
+
hardline,
|
|
3874
|
+
"}",
|
|
3875
|
+
];
|
|
3862
3876
|
}
|
|
3863
3877
|
function printProjectionParameters(path, options, print) {
|
|
3864
3878
|
const node = path.getValue();
|
|
@@ -4906,20 +4920,35 @@ function createParser(code, options = {}) {
|
|
|
4906
4920
|
message,
|
|
4907
4921
|
recoverFromKeyword,
|
|
4908
4922
|
});
|
|
4909
|
-
while (
|
|
4910
|
-
|
|
4911
|
-
|
|
4912
|
-
|
|
4913
|
-
|
|
4914
|
-
|
|
4915
|
-
|
|
4916
|
-
|
|
4917
|
-
|
|
4918
|
-
|
|
4919
|
-
|
|
4920
|
-
|
|
4921
|
-
|
|
4922
|
-
|
|
4923
|
+
while (token() !== Token.EndOfFile) {
|
|
4924
|
+
if (parseOptional(Token.Dot)) {
|
|
4925
|
+
base = {
|
|
4926
|
+
kind: SyntaxKind.MemberExpression,
|
|
4927
|
+
base,
|
|
4928
|
+
// Error recovery: false arg here means don't treat a keyword as an
|
|
4929
|
+
// identifier after `.` in member expression. Otherwise we will
|
|
4930
|
+
// parse `@Outer.<missing identifier> model M{}` as having decorator
|
|
4931
|
+
// `@Outer.model` applied to invalid statement `M {}` instead of
|
|
4932
|
+
// having incomplete decorator `@Outer.` applied to `model M {}`.
|
|
4933
|
+
id: parseIdentifier({
|
|
4934
|
+
recoverFromKeyword: false,
|
|
4935
|
+
}),
|
|
4936
|
+
selector: ".",
|
|
4937
|
+
...finishNode(pos),
|
|
4938
|
+
};
|
|
4939
|
+
}
|
|
4940
|
+
else if (parseOptional(Token.ColonColon)) {
|
|
4941
|
+
base = {
|
|
4942
|
+
kind: SyntaxKind.MemberExpression,
|
|
4943
|
+
base,
|
|
4944
|
+
id: parseIdentifier(),
|
|
4945
|
+
selector: "::",
|
|
4946
|
+
...finishNode(pos),
|
|
4947
|
+
};
|
|
4948
|
+
}
|
|
4949
|
+
else {
|
|
4950
|
+
break;
|
|
4951
|
+
}
|
|
4923
4952
|
}
|
|
4924
4953
|
return base;
|
|
4925
4954
|
}
|
|
@@ -5200,37 +5229,51 @@ function createParser(code, options = {}) {
|
|
|
5200
5229
|
parseExpected(Token.Hash);
|
|
5201
5230
|
const id = parseIdentifier();
|
|
5202
5231
|
parseExpected(Token.OpenBrace);
|
|
5203
|
-
|
|
5204
|
-
|
|
5205
|
-
|
|
5206
|
-
|
|
5207
|
-
if (
|
|
5208
|
-
|
|
5232
|
+
const projectionMap = new Map();
|
|
5233
|
+
const projections = [];
|
|
5234
|
+
while (token() === Token.Identifier) {
|
|
5235
|
+
const projection = parseProjection();
|
|
5236
|
+
if (projection.direction !== "<error>") {
|
|
5237
|
+
if (projectionMap.has(projection.direction)) {
|
|
5238
|
+
error({ code: "duplicate-symbol", target: projection, format: { name: "projection" } });
|
|
5239
|
+
}
|
|
5240
|
+
else {
|
|
5241
|
+
projectionMap.set(projection.direction, projection);
|
|
5242
|
+
}
|
|
5209
5243
|
}
|
|
5210
|
-
|
|
5211
|
-
|
|
5212
|
-
error({ code: "duplicate-symbol", target: proj2, format: { name: "projection" } });
|
|
5213
|
-
}
|
|
5214
|
-
else if (proj1) {
|
|
5215
|
-
[to, from] = proj1.direction === "to" ? [proj1, proj2] : [proj2, proj1];
|
|
5244
|
+
// NOTE: Don't drop projections with error in direction definition from the AST.
|
|
5245
|
+
projections.push(projection);
|
|
5216
5246
|
}
|
|
5217
5247
|
parseExpected(Token.CloseBrace);
|
|
5218
5248
|
return {
|
|
5219
5249
|
kind: SyntaxKind.ProjectionStatement,
|
|
5220
5250
|
selector,
|
|
5221
|
-
|
|
5222
|
-
|
|
5251
|
+
projections,
|
|
5252
|
+
preTo: projectionMap.get("pre_to"),
|
|
5253
|
+
preFrom: projectionMap.get("pre_from"),
|
|
5254
|
+
from: projectionMap.get("from"),
|
|
5255
|
+
to: projectionMap.get("to"),
|
|
5223
5256
|
id,
|
|
5224
5257
|
...finishNode(pos),
|
|
5225
5258
|
};
|
|
5226
5259
|
}
|
|
5227
5260
|
function parseProjection() {
|
|
5228
5261
|
const pos = tokenPos();
|
|
5229
|
-
|
|
5262
|
+
let directionId = parseIdentifier({ message: "projectionDirection" });
|
|
5230
5263
|
let direction;
|
|
5231
|
-
|
|
5264
|
+
const modifierIds = [];
|
|
5265
|
+
let isPre = false;
|
|
5266
|
+
if (directionId.sv === "pre") {
|
|
5267
|
+
isPre = true;
|
|
5268
|
+
modifierIds.push(directionId);
|
|
5269
|
+
directionId = parseIdentifier({ message: "projectionDirection" });
|
|
5270
|
+
}
|
|
5271
|
+
if (directionId.sv !== "to" && directionId.sv !== "from") {
|
|
5232
5272
|
error({ code: "token-expected", messageId: "projectionDirection" });
|
|
5233
|
-
direction = "
|
|
5273
|
+
direction = "<error>";
|
|
5274
|
+
}
|
|
5275
|
+
else if (isPre) {
|
|
5276
|
+
direction = directionId.sv === "to" ? "pre_to" : "pre_from";
|
|
5234
5277
|
}
|
|
5235
5278
|
else {
|
|
5236
5279
|
direction = directionId.sv;
|
|
@@ -5250,6 +5293,7 @@ function createParser(code, options = {}) {
|
|
|
5250
5293
|
body,
|
|
5251
5294
|
direction,
|
|
5252
5295
|
directionId,
|
|
5296
|
+
modifierIds,
|
|
5253
5297
|
parameters,
|
|
5254
5298
|
...finishNode(pos),
|
|
5255
5299
|
};
|
|
@@ -5681,7 +5725,27 @@ function createParser(code, options = {}) {
|
|
|
5681
5725
|
const selectorTok = expectTokenIsOneOf(Token.Identifier, Token.ModelKeyword, Token.OpKeyword, Token.InterfaceKeyword, Token.UnionKeyword, Token.EnumKeyword);
|
|
5682
5726
|
switch (selectorTok) {
|
|
5683
5727
|
case Token.Identifier:
|
|
5684
|
-
|
|
5728
|
+
const id = parseIdentifierOrMemberExpression(undefined, true);
|
|
5729
|
+
if (id.kind === SyntaxKind.Identifier) {
|
|
5730
|
+
switch (id.sv) {
|
|
5731
|
+
case "modelproperty":
|
|
5732
|
+
return {
|
|
5733
|
+
kind: SyntaxKind.ProjectionModelPropertySelector,
|
|
5734
|
+
...finishNode(pos),
|
|
5735
|
+
};
|
|
5736
|
+
case "unionvariant":
|
|
5737
|
+
return {
|
|
5738
|
+
kind: SyntaxKind.ProjectionUnionVariantSelector,
|
|
5739
|
+
...finishNode(pos),
|
|
5740
|
+
};
|
|
5741
|
+
case "enummember":
|
|
5742
|
+
return {
|
|
5743
|
+
kind: SyntaxKind.ProjectionEnumMemberSelector,
|
|
5744
|
+
...finishNode(pos),
|
|
5745
|
+
};
|
|
5746
|
+
}
|
|
5747
|
+
}
|
|
5748
|
+
return id;
|
|
5685
5749
|
case Token.ModelKeyword:
|
|
5686
5750
|
nextToken();
|
|
5687
5751
|
return {
|