@typespec/prettier-plugin-typespec 0.44.0 → 0.45.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 +101 -68
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -858,49 +858,50 @@ var SyntaxKind;
|
|
|
858
858
|
SyntaxKind[SyntaxKind["VoidKeyword"] = 36] = "VoidKeyword";
|
|
859
859
|
SyntaxKind[SyntaxKind["NeverKeyword"] = 37] = "NeverKeyword";
|
|
860
860
|
SyntaxKind[SyntaxKind["UnknownKeyword"] = 38] = "UnknownKeyword";
|
|
861
|
-
SyntaxKind[SyntaxKind["
|
|
862
|
-
SyntaxKind[SyntaxKind["
|
|
863
|
-
SyntaxKind[SyntaxKind["
|
|
864
|
-
SyntaxKind[SyntaxKind["
|
|
865
|
-
SyntaxKind[SyntaxKind["
|
|
866
|
-
SyntaxKind[SyntaxKind["
|
|
867
|
-
SyntaxKind[SyntaxKind["
|
|
868
|
-
SyntaxKind[SyntaxKind["
|
|
869
|
-
SyntaxKind[SyntaxKind["
|
|
870
|
-
SyntaxKind[SyntaxKind["
|
|
871
|
-
SyntaxKind[SyntaxKind["
|
|
872
|
-
SyntaxKind[SyntaxKind["
|
|
873
|
-
SyntaxKind[SyntaxKind["
|
|
874
|
-
SyntaxKind[SyntaxKind["
|
|
875
|
-
SyntaxKind[SyntaxKind["
|
|
876
|
-
SyntaxKind[SyntaxKind["
|
|
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["
|
|
901
|
-
SyntaxKind[SyntaxKind["
|
|
902
|
-
SyntaxKind[SyntaxKind["
|
|
903
|
-
SyntaxKind[SyntaxKind["
|
|
861
|
+
SyntaxKind[SyntaxKind["ValueOfExpression"] = 39] = "ValueOfExpression";
|
|
862
|
+
SyntaxKind[SyntaxKind["TypeReference"] = 40] = "TypeReference";
|
|
863
|
+
SyntaxKind[SyntaxKind["ProjectionReference"] = 41] = "ProjectionReference";
|
|
864
|
+
SyntaxKind[SyntaxKind["TemplateParameterDeclaration"] = 42] = "TemplateParameterDeclaration";
|
|
865
|
+
SyntaxKind[SyntaxKind["EmptyStatement"] = 43] = "EmptyStatement";
|
|
866
|
+
SyntaxKind[SyntaxKind["InvalidStatement"] = 44] = "InvalidStatement";
|
|
867
|
+
SyntaxKind[SyntaxKind["LineComment"] = 45] = "LineComment";
|
|
868
|
+
SyntaxKind[SyntaxKind["BlockComment"] = 46] = "BlockComment";
|
|
869
|
+
SyntaxKind[SyntaxKind["Doc"] = 47] = "Doc";
|
|
870
|
+
SyntaxKind[SyntaxKind["DocText"] = 48] = "DocText";
|
|
871
|
+
SyntaxKind[SyntaxKind["DocParamTag"] = 49] = "DocParamTag";
|
|
872
|
+
SyntaxKind[SyntaxKind["DocReturnsTag"] = 50] = "DocReturnsTag";
|
|
873
|
+
SyntaxKind[SyntaxKind["DocTemplateTag"] = 51] = "DocTemplateTag";
|
|
874
|
+
SyntaxKind[SyntaxKind["DocUnknownTag"] = 52] = "DocUnknownTag";
|
|
875
|
+
SyntaxKind[SyntaxKind["Projection"] = 53] = "Projection";
|
|
876
|
+
SyntaxKind[SyntaxKind["ProjectionParameterDeclaration"] = 54] = "ProjectionParameterDeclaration";
|
|
877
|
+
SyntaxKind[SyntaxKind["ProjectionModelSelector"] = 55] = "ProjectionModelSelector";
|
|
878
|
+
SyntaxKind[SyntaxKind["ProjectionModelPropertySelector"] = 56] = "ProjectionModelPropertySelector";
|
|
879
|
+
SyntaxKind[SyntaxKind["ProjectionOperationSelector"] = 57] = "ProjectionOperationSelector";
|
|
880
|
+
SyntaxKind[SyntaxKind["ProjectionUnionSelector"] = 58] = "ProjectionUnionSelector";
|
|
881
|
+
SyntaxKind[SyntaxKind["ProjectionUnionVariantSelector"] = 59] = "ProjectionUnionVariantSelector";
|
|
882
|
+
SyntaxKind[SyntaxKind["ProjectionInterfaceSelector"] = 60] = "ProjectionInterfaceSelector";
|
|
883
|
+
SyntaxKind[SyntaxKind["ProjectionEnumSelector"] = 61] = "ProjectionEnumSelector";
|
|
884
|
+
SyntaxKind[SyntaxKind["ProjectionEnumMemberSelector"] = 62] = "ProjectionEnumMemberSelector";
|
|
885
|
+
SyntaxKind[SyntaxKind["ProjectionExpressionStatement"] = 63] = "ProjectionExpressionStatement";
|
|
886
|
+
SyntaxKind[SyntaxKind["ProjectionIfExpression"] = 64] = "ProjectionIfExpression";
|
|
887
|
+
SyntaxKind[SyntaxKind["ProjectionBlockExpression"] = 65] = "ProjectionBlockExpression";
|
|
888
|
+
SyntaxKind[SyntaxKind["ProjectionMemberExpression"] = 66] = "ProjectionMemberExpression";
|
|
889
|
+
SyntaxKind[SyntaxKind["ProjectionLogicalExpression"] = 67] = "ProjectionLogicalExpression";
|
|
890
|
+
SyntaxKind[SyntaxKind["ProjectionEqualityExpression"] = 68] = "ProjectionEqualityExpression";
|
|
891
|
+
SyntaxKind[SyntaxKind["ProjectionUnaryExpression"] = 69] = "ProjectionUnaryExpression";
|
|
892
|
+
SyntaxKind[SyntaxKind["ProjectionRelationalExpression"] = 70] = "ProjectionRelationalExpression";
|
|
893
|
+
SyntaxKind[SyntaxKind["ProjectionArithmeticExpression"] = 71] = "ProjectionArithmeticExpression";
|
|
894
|
+
SyntaxKind[SyntaxKind["ProjectionCallExpression"] = 72] = "ProjectionCallExpression";
|
|
895
|
+
SyntaxKind[SyntaxKind["ProjectionLambdaExpression"] = 73] = "ProjectionLambdaExpression";
|
|
896
|
+
SyntaxKind[SyntaxKind["ProjectionLambdaParameterDeclaration"] = 74] = "ProjectionLambdaParameterDeclaration";
|
|
897
|
+
SyntaxKind[SyntaxKind["ProjectionModelExpression"] = 75] = "ProjectionModelExpression";
|
|
898
|
+
SyntaxKind[SyntaxKind["ProjectionModelProperty"] = 76] = "ProjectionModelProperty";
|
|
899
|
+
SyntaxKind[SyntaxKind["ProjectionModelSpreadProperty"] = 77] = "ProjectionModelSpreadProperty";
|
|
900
|
+
SyntaxKind[SyntaxKind["ProjectionSpreadProperty"] = 78] = "ProjectionSpreadProperty";
|
|
901
|
+
SyntaxKind[SyntaxKind["ProjectionTupleExpression"] = 79] = "ProjectionTupleExpression";
|
|
902
|
+
SyntaxKind[SyntaxKind["ProjectionStatement"] = 80] = "ProjectionStatement";
|
|
903
|
+
SyntaxKind[SyntaxKind["ProjectionDecoratorReferenceExpression"] = 81] = "ProjectionDecoratorReferenceExpression";
|
|
904
|
+
SyntaxKind[SyntaxKind["Return"] = 82] = "Return";
|
|
904
905
|
})(SyntaxKind = SyntaxKind || (SyntaxKind = {}));
|
|
905
906
|
var IdentifierKind;
|
|
906
907
|
(function (IdentifierKind) {
|
|
@@ -1020,6 +1021,21 @@ const diagnostics = {
|
|
|
1020
1021
|
default: paramMessage `${"message"}`,
|
|
1021
1022
|
},
|
|
1022
1023
|
},
|
|
1024
|
+
/**
|
|
1025
|
+
* Init templates
|
|
1026
|
+
*/
|
|
1027
|
+
"init-template-invalid-json": {
|
|
1028
|
+
severity: "error",
|
|
1029
|
+
messages: {
|
|
1030
|
+
default: paramMessage `Unable to parse ${"url"}: ${"message"}. Check that the template URL is correct.`,
|
|
1031
|
+
},
|
|
1032
|
+
},
|
|
1033
|
+
"init-template-download-failed": {
|
|
1034
|
+
severity: "error",
|
|
1035
|
+
messages: {
|
|
1036
|
+
default: paramMessage `Failed to download template from ${"url"}: ${"message"}. Check that the template URL is correct.`,
|
|
1037
|
+
},
|
|
1038
|
+
},
|
|
1023
1039
|
/**
|
|
1024
1040
|
* Parser errors.
|
|
1025
1041
|
*/
|
|
@@ -1511,12 +1527,6 @@ const diagnostics = {
|
|
|
1511
1527
|
default: paramMessage `Requested emitter package ${"emitterPackage"} does not provide an "onEmit" function.`,
|
|
1512
1528
|
},
|
|
1513
1529
|
},
|
|
1514
|
-
"emitter-not-found": {
|
|
1515
|
-
severity: "warning",
|
|
1516
|
-
messages: {
|
|
1517
|
-
default: paramMessage `Emitter with name ${"emitterName"} is not found.`,
|
|
1518
|
-
},
|
|
1519
|
-
},
|
|
1520
1530
|
"missing-import": {
|
|
1521
1531
|
severity: "error",
|
|
1522
1532
|
messages: {
|
|
@@ -1604,8 +1614,8 @@ const diagnostics = {
|
|
|
1604
1614
|
severity: "error",
|
|
1605
1615
|
messages: {
|
|
1606
1616
|
default: "Invalid encoding",
|
|
1607
|
-
wrongType: paramMessage `Encoding '${"encoding"}' cannot be used on type ${"type"}. Expected
|
|
1608
|
-
wrongEncodingType: paramMessage `Encoding '${"encoding"}'
|
|
1617
|
+
wrongType: paramMessage `Encoding '${"encoding"}' cannot be used on type '${"type"}'. Expected: ${"expected"}.`,
|
|
1618
|
+
wrongEncodingType: paramMessage `Encoding '${"encoding"}' on type '${"type"}' is expected to be serialized as '${"expected"}' but got '${"actual"}'.`,
|
|
1609
1619
|
},
|
|
1610
1620
|
},
|
|
1611
1621
|
/**
|
|
@@ -1987,27 +1997,28 @@ var Token;
|
|
|
1987
1997
|
Token[Token["IfKeyword"] = 60] = "IfKeyword";
|
|
1988
1998
|
Token[Token["DecKeyword"] = 61] = "DecKeyword";
|
|
1989
1999
|
Token[Token["FnKeyword"] = 62] = "FnKeyword";
|
|
2000
|
+
Token[Token["ValueOfKeyword"] = 63] = "ValueOfKeyword";
|
|
1990
2001
|
// Add new statement keyword above
|
|
1991
|
-
/** @internal */ Token[Token["__EndStatementKeyword"] =
|
|
2002
|
+
/** @internal */ Token[Token["__EndStatementKeyword"] = 64] = "__EndStatementKeyword";
|
|
1992
2003
|
///////////////////////////////////////////////////////////////
|
|
1993
2004
|
///////////////////////////////////////////////////////////////
|
|
1994
|
-
/** @internal */ Token[Token["__StartModifierKeyword"] =
|
|
1995
|
-
Token[Token["ExternKeyword"] =
|
|
1996
|
-
/** @internal */ Token[Token["__EndModifierKeyword"] =
|
|
2005
|
+
/** @internal */ Token[Token["__StartModifierKeyword"] = 64] = "__StartModifierKeyword";
|
|
2006
|
+
Token[Token["ExternKeyword"] = 64] = "ExternKeyword";
|
|
2007
|
+
/** @internal */ Token[Token["__EndModifierKeyword"] = 65] = "__EndModifierKeyword";
|
|
1997
2008
|
///////////////////////////////////////////////////////////////
|
|
1998
2009
|
///////////////////////////////////////////////////////////////
|
|
1999
2010
|
// Other keywords
|
|
2000
|
-
Token[Token["ExtendsKeyword"] =
|
|
2001
|
-
Token[Token["TrueKeyword"] =
|
|
2002
|
-
Token[Token["FalseKeyword"] =
|
|
2003
|
-
Token[Token["ReturnKeyword"] =
|
|
2004
|
-
Token[Token["VoidKeyword"] =
|
|
2005
|
-
Token[Token["NeverKeyword"] =
|
|
2006
|
-
Token[Token["UnknownKeyword"] =
|
|
2011
|
+
Token[Token["ExtendsKeyword"] = 65] = "ExtendsKeyword";
|
|
2012
|
+
Token[Token["TrueKeyword"] = 66] = "TrueKeyword";
|
|
2013
|
+
Token[Token["FalseKeyword"] = 67] = "FalseKeyword";
|
|
2014
|
+
Token[Token["ReturnKeyword"] = 68] = "ReturnKeyword";
|
|
2015
|
+
Token[Token["VoidKeyword"] = 69] = "VoidKeyword";
|
|
2016
|
+
Token[Token["NeverKeyword"] = 70] = "NeverKeyword";
|
|
2017
|
+
Token[Token["UnknownKeyword"] = 71] = "UnknownKeyword";
|
|
2007
2018
|
// Add new non-statement keyword above
|
|
2008
|
-
/** @internal */ Token[Token["__EndKeyword"] =
|
|
2019
|
+
/** @internal */ Token[Token["__EndKeyword"] = 72] = "__EndKeyword";
|
|
2009
2020
|
///////////////////////////////////////////////////////////////
|
|
2010
|
-
/** @internal */ Token[Token["__Count"] =
|
|
2021
|
+
/** @internal */ Token[Token["__Count"] = 72] = "__Count";
|
|
2011
2022
|
})(Token = Token || (Token = {}));
|
|
2012
2023
|
/** @internal */
|
|
2013
2024
|
const TokenDisplay = getTokenDisplayTable([
|
|
@@ -2074,6 +2085,7 @@ const TokenDisplay = getTokenDisplayTable([
|
|
|
2074
2085
|
[Token.IfKeyword, "'if'"],
|
|
2075
2086
|
[Token.DecKeyword, "'dec'"],
|
|
2076
2087
|
[Token.FnKeyword, "'fn'"],
|
|
2088
|
+
[Token.ValueOfKeyword, "'valueof'"],
|
|
2077
2089
|
[Token.ExtendsKeyword, "'extends'"],
|
|
2078
2090
|
[Token.TrueKeyword, "'true'"],
|
|
2079
2091
|
[Token.FalseKeyword, "'false'"],
|
|
@@ -2102,6 +2114,7 @@ const Keywords = new Map([
|
|
|
2102
2114
|
["alias", Token.AliasKeyword],
|
|
2103
2115
|
["dec", Token.DecKeyword],
|
|
2104
2116
|
["fn", Token.FnKeyword],
|
|
2117
|
+
["valueof", Token.ValueOfKeyword],
|
|
2105
2118
|
["true", Token.TrueKeyword],
|
|
2106
2119
|
["false", Token.FalseKeyword],
|
|
2107
2120
|
["return", Token.ReturnKeyword],
|
|
@@ -2948,6 +2961,7 @@ function addStatementDecoratorComment(comment) {
|
|
|
2948
2961
|
(enclosingNode.kind === SyntaxKind.NamespaceStatement ||
|
|
2949
2962
|
enclosingNode.kind === SyntaxKind.ModelStatement ||
|
|
2950
2963
|
enclosingNode.kind === SyntaxKind.EnumStatement ||
|
|
2964
|
+
enclosingNode.kind === SyntaxKind.OperationStatement ||
|
|
2951
2965
|
enclosingNode.kind === SyntaxKind.ModelProperty ||
|
|
2952
2966
|
enclosingNode.kind === SyntaxKind.EnumMember ||
|
|
2953
2967
|
enclosingNode.kind === SyntaxKind.UnionStatement)) {
|
|
@@ -3107,6 +3121,8 @@ path, options, print) {
|
|
|
3107
3121
|
return printUnionVariant(path, options, print);
|
|
3108
3122
|
case SyntaxKind.TypeReference:
|
|
3109
3123
|
return printTypeReference(path, options, print);
|
|
3124
|
+
case SyntaxKind.ValueOfExpression:
|
|
3125
|
+
return printValueOfExpression(path, options, print);
|
|
3110
3126
|
case SyntaxKind.TemplateParameterDeclaration:
|
|
3111
3127
|
return printTemplateParameterDeclaration(path, options, print);
|
|
3112
3128
|
case SyntaxKind.ModelSpreadProperty:
|
|
@@ -3780,6 +3796,10 @@ function printTypeReference(path, options, print) {
|
|
|
3780
3796
|
const template = printTemplateParameters(path, options, print, "arguments");
|
|
3781
3797
|
return [type, template];
|
|
3782
3798
|
}
|
|
3799
|
+
function printValueOfExpression(path, options, print) {
|
|
3800
|
+
const type = path.call(print, "target");
|
|
3801
|
+
return ["valueof ", type];
|
|
3802
|
+
}
|
|
3783
3803
|
function printTemplateParameterDeclaration(path, options, print) {
|
|
3784
3804
|
const node = path.getValue();
|
|
3785
3805
|
return [
|
|
@@ -4781,6 +4801,16 @@ function createParser(code, options = {}) {
|
|
|
4781
4801
|
}
|
|
4782
4802
|
return expr;
|
|
4783
4803
|
}
|
|
4804
|
+
function parseValueOfExpression() {
|
|
4805
|
+
const pos = tokenPos();
|
|
4806
|
+
parseExpected(Token.ValueOfKeyword);
|
|
4807
|
+
const target = parseExpression();
|
|
4808
|
+
return {
|
|
4809
|
+
kind: SyntaxKind.ValueOfExpression,
|
|
4810
|
+
target,
|
|
4811
|
+
...finishNode(pos),
|
|
4812
|
+
};
|
|
4813
|
+
}
|
|
4784
4814
|
function parseReferenceExpression(message) {
|
|
4785
4815
|
const pos = tokenPos();
|
|
4786
4816
|
const target = parseIdentifierOrMemberExpression(message);
|
|
@@ -4954,6 +4984,8 @@ function createParser(code, options = {}) {
|
|
|
4954
4984
|
function parsePrimaryExpression() {
|
|
4955
4985
|
while (true) {
|
|
4956
4986
|
switch (token()) {
|
|
4987
|
+
case Token.ValueOfKeyword:
|
|
4988
|
+
return parseValueOfExpression();
|
|
4957
4989
|
case Token.Identifier:
|
|
4958
4990
|
return parseReferenceExpression();
|
|
4959
4991
|
case Token.StringLiteral:
|
|
@@ -5057,12 +5089,13 @@ function createParser(code, options = {}) {
|
|
|
5057
5089
|
}
|
|
5058
5090
|
function parseNumericLiteral() {
|
|
5059
5091
|
const pos = tokenPos();
|
|
5060
|
-
const
|
|
5061
|
-
const value = Number(
|
|
5092
|
+
const valueAsString = tokenValue();
|
|
5093
|
+
const value = Number(valueAsString);
|
|
5062
5094
|
parseExpected(Token.NumericLiteral);
|
|
5063
5095
|
return {
|
|
5064
5096
|
kind: SyntaxKind.NumericLiteral,
|
|
5065
5097
|
value,
|
|
5098
|
+
valueAsString,
|
|
5066
5099
|
...finishNode(pos),
|
|
5067
5100
|
};
|
|
5068
5101
|
}
|
|
@@ -5797,7 +5830,7 @@ function createParser(code, options = {}) {
|
|
|
5797
5830
|
};
|
|
5798
5831
|
}
|
|
5799
5832
|
function parseDocList() {
|
|
5800
|
-
if (docRanges.length === 0 ||
|
|
5833
|
+
if (docRanges.length === 0 || options.docs === false) {
|
|
5801
5834
|
return [tokenPos(), []];
|
|
5802
5835
|
}
|
|
5803
5836
|
const docs = [];
|
|
@@ -6317,7 +6350,7 @@ function isBlocklessNamespace(node) {
|
|
|
6317
6350
|
}
|
|
6318
6351
|
|
|
6319
6352
|
function parse(text, parsers, opts) {
|
|
6320
|
-
const result = parse$1(text, { comments: true });
|
|
6353
|
+
const result = parse$1(text, { comments: true, docs: false });
|
|
6321
6354
|
const errors = result.parseDiagnostics.filter((x) => x.severity === "error");
|
|
6322
6355
|
if (errors.length > 0 && !result.printable) {
|
|
6323
6356
|
throw new PrettierParserError(errors[0]);
|