@typespec/prettier-plugin-typespec 0.67.0-dev.2 → 0.67.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 +587 -1257
- package/dist/index.js.map +1 -1
- package/package.json +4 -5
package/dist/index.js
CHANGED
|
@@ -1,220 +1,5 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
function createSourceFile(text, path) {
|
|
4
|
-
let lineStarts = undefined;
|
|
5
|
-
return {
|
|
6
|
-
text,
|
|
7
|
-
path,
|
|
8
|
-
getLineStarts,
|
|
9
|
-
getLineAndCharacterOfPosition,
|
|
10
|
-
};
|
|
11
|
-
function getLineStarts() {
|
|
12
|
-
return (lineStarts = lineStarts ?? scanLineStarts(text));
|
|
13
|
-
}
|
|
14
|
-
function getLineAndCharacterOfPosition(position) {
|
|
15
|
-
const starts = getLineStarts();
|
|
16
|
-
let line = binarySearch(starts, position);
|
|
17
|
-
// When binarySearch returns < 0 indicating that the value was not found, it
|
|
18
|
-
// returns the bitwise complement of the index where the value would need to
|
|
19
|
-
// be inserted to keep the array sorted. So flipping the bits back to this
|
|
20
|
-
// positive index tells us what the line number would be if we were to
|
|
21
|
-
// create a new line starting at the given position, and subtracting 1 from
|
|
22
|
-
// that therefore gives us the line number we're after.
|
|
23
|
-
if (line < 0) {
|
|
24
|
-
line = ~line - 1;
|
|
25
|
-
}
|
|
26
|
-
return {
|
|
27
|
-
line,
|
|
28
|
-
character: position - starts[line],
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
function scanLineStarts(text) {
|
|
33
|
-
const starts = [];
|
|
34
|
-
let start = 0;
|
|
35
|
-
let pos = 0;
|
|
36
|
-
while (pos < text.length) {
|
|
37
|
-
const ch = text.charCodeAt(pos);
|
|
38
|
-
pos++;
|
|
39
|
-
switch (ch) {
|
|
40
|
-
case 13 /* CharCode.CarriageReturn */:
|
|
41
|
-
if (text.charCodeAt(pos) === 10 /* CharCode.LineFeed */) {
|
|
42
|
-
pos++;
|
|
43
|
-
}
|
|
44
|
-
// fallthrough
|
|
45
|
-
case 10 /* CharCode.LineFeed */:
|
|
46
|
-
starts.push(start);
|
|
47
|
-
start = pos;
|
|
48
|
-
break;
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
starts.push(start);
|
|
52
|
-
return starts;
|
|
53
|
-
}
|
|
54
|
-
/**
|
|
55
|
-
* Search sorted array of numbers for the given value. If found, return index
|
|
56
|
-
* in array where value was found. If not found, return a negative number that
|
|
57
|
-
* is the bitwise complement of the index where value would need to be inserted
|
|
58
|
-
* to keep the array sorted.
|
|
59
|
-
*/
|
|
60
|
-
function binarySearch(array, value) {
|
|
61
|
-
let low = 0;
|
|
62
|
-
let high = array.length - 1;
|
|
63
|
-
while (low <= high) {
|
|
64
|
-
const middle = low + ((high - low) >> 1);
|
|
65
|
-
const v = array[middle];
|
|
66
|
-
if (v < value) {
|
|
67
|
-
low = middle + 1;
|
|
68
|
-
}
|
|
69
|
-
else if (v > value) {
|
|
70
|
-
high = middle - 1;
|
|
71
|
-
}
|
|
72
|
-
else {
|
|
73
|
-
return middle;
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
return ~low;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
var ResolutionResultFlags;
|
|
80
|
-
(function (ResolutionResultFlags) {
|
|
81
|
-
ResolutionResultFlags[ResolutionResultFlags["None"] = 0] = "None";
|
|
82
|
-
ResolutionResultFlags[ResolutionResultFlags["Resolved"] = 2] = "Resolved";
|
|
83
|
-
ResolutionResultFlags[ResolutionResultFlags["Unknown"] = 4] = "Unknown";
|
|
84
|
-
ResolutionResultFlags[ResolutionResultFlags["Ambiguous"] = 8] = "Ambiguous";
|
|
85
|
-
ResolutionResultFlags[ResolutionResultFlags["NotFound"] = 16] = "NotFound";
|
|
86
|
-
ResolutionResultFlags[ResolutionResultFlags["ResolutionFailed"] = 28] = "ResolutionFailed";
|
|
87
|
-
})(ResolutionResultFlags || (ResolutionResultFlags = {}));
|
|
88
|
-
/**
|
|
89
|
-
* AST types
|
|
90
|
-
*/
|
|
91
|
-
var SyntaxKind;
|
|
92
|
-
(function (SyntaxKind) {
|
|
93
|
-
SyntaxKind[SyntaxKind["TypeSpecScript"] = 0] = "TypeSpecScript";
|
|
94
|
-
SyntaxKind[SyntaxKind["JsSourceFile"] = 1] = "JsSourceFile";
|
|
95
|
-
SyntaxKind[SyntaxKind["ImportStatement"] = 2] = "ImportStatement";
|
|
96
|
-
SyntaxKind[SyntaxKind["Identifier"] = 3] = "Identifier";
|
|
97
|
-
SyntaxKind[SyntaxKind["AugmentDecoratorStatement"] = 4] = "AugmentDecoratorStatement";
|
|
98
|
-
SyntaxKind[SyntaxKind["DecoratorExpression"] = 5] = "DecoratorExpression";
|
|
99
|
-
SyntaxKind[SyntaxKind["DirectiveExpression"] = 6] = "DirectiveExpression";
|
|
100
|
-
SyntaxKind[SyntaxKind["MemberExpression"] = 7] = "MemberExpression";
|
|
101
|
-
SyntaxKind[SyntaxKind["NamespaceStatement"] = 8] = "NamespaceStatement";
|
|
102
|
-
SyntaxKind[SyntaxKind["UsingStatement"] = 9] = "UsingStatement";
|
|
103
|
-
SyntaxKind[SyntaxKind["OperationStatement"] = 10] = "OperationStatement";
|
|
104
|
-
SyntaxKind[SyntaxKind["OperationSignatureDeclaration"] = 11] = "OperationSignatureDeclaration";
|
|
105
|
-
SyntaxKind[SyntaxKind["OperationSignatureReference"] = 12] = "OperationSignatureReference";
|
|
106
|
-
SyntaxKind[SyntaxKind["ModelStatement"] = 13] = "ModelStatement";
|
|
107
|
-
SyntaxKind[SyntaxKind["ModelExpression"] = 14] = "ModelExpression";
|
|
108
|
-
SyntaxKind[SyntaxKind["ModelProperty"] = 15] = "ModelProperty";
|
|
109
|
-
SyntaxKind[SyntaxKind["ModelSpreadProperty"] = 16] = "ModelSpreadProperty";
|
|
110
|
-
SyntaxKind[SyntaxKind["ScalarStatement"] = 17] = "ScalarStatement";
|
|
111
|
-
SyntaxKind[SyntaxKind["InterfaceStatement"] = 18] = "InterfaceStatement";
|
|
112
|
-
SyntaxKind[SyntaxKind["UnionStatement"] = 19] = "UnionStatement";
|
|
113
|
-
SyntaxKind[SyntaxKind["UnionVariant"] = 20] = "UnionVariant";
|
|
114
|
-
SyntaxKind[SyntaxKind["EnumStatement"] = 21] = "EnumStatement";
|
|
115
|
-
SyntaxKind[SyntaxKind["EnumMember"] = 22] = "EnumMember";
|
|
116
|
-
SyntaxKind[SyntaxKind["EnumSpreadMember"] = 23] = "EnumSpreadMember";
|
|
117
|
-
SyntaxKind[SyntaxKind["AliasStatement"] = 24] = "AliasStatement";
|
|
118
|
-
SyntaxKind[SyntaxKind["DecoratorDeclarationStatement"] = 25] = "DecoratorDeclarationStatement";
|
|
119
|
-
SyntaxKind[SyntaxKind["FunctionDeclarationStatement"] = 26] = "FunctionDeclarationStatement";
|
|
120
|
-
SyntaxKind[SyntaxKind["FunctionParameter"] = 27] = "FunctionParameter";
|
|
121
|
-
SyntaxKind[SyntaxKind["UnionExpression"] = 28] = "UnionExpression";
|
|
122
|
-
SyntaxKind[SyntaxKind["IntersectionExpression"] = 29] = "IntersectionExpression";
|
|
123
|
-
SyntaxKind[SyntaxKind["TupleExpression"] = 30] = "TupleExpression";
|
|
124
|
-
SyntaxKind[SyntaxKind["ArrayExpression"] = 31] = "ArrayExpression";
|
|
125
|
-
SyntaxKind[SyntaxKind["StringLiteral"] = 32] = "StringLiteral";
|
|
126
|
-
SyntaxKind[SyntaxKind["NumericLiteral"] = 33] = "NumericLiteral";
|
|
127
|
-
SyntaxKind[SyntaxKind["BooleanLiteral"] = 34] = "BooleanLiteral";
|
|
128
|
-
SyntaxKind[SyntaxKind["StringTemplateExpression"] = 35] = "StringTemplateExpression";
|
|
129
|
-
SyntaxKind[SyntaxKind["StringTemplateHead"] = 36] = "StringTemplateHead";
|
|
130
|
-
SyntaxKind[SyntaxKind["StringTemplateMiddle"] = 37] = "StringTemplateMiddle";
|
|
131
|
-
SyntaxKind[SyntaxKind["StringTemplateTail"] = 38] = "StringTemplateTail";
|
|
132
|
-
SyntaxKind[SyntaxKind["StringTemplateSpan"] = 39] = "StringTemplateSpan";
|
|
133
|
-
SyntaxKind[SyntaxKind["ExternKeyword"] = 40] = "ExternKeyword";
|
|
134
|
-
SyntaxKind[SyntaxKind["VoidKeyword"] = 41] = "VoidKeyword";
|
|
135
|
-
SyntaxKind[SyntaxKind["NeverKeyword"] = 42] = "NeverKeyword";
|
|
136
|
-
SyntaxKind[SyntaxKind["UnknownKeyword"] = 43] = "UnknownKeyword";
|
|
137
|
-
SyntaxKind[SyntaxKind["ValueOfExpression"] = 44] = "ValueOfExpression";
|
|
138
|
-
SyntaxKind[SyntaxKind["TypeReference"] = 45] = "TypeReference";
|
|
139
|
-
SyntaxKind[SyntaxKind["ProjectionReference"] = 46] = "ProjectionReference";
|
|
140
|
-
SyntaxKind[SyntaxKind["TemplateParameterDeclaration"] = 47] = "TemplateParameterDeclaration";
|
|
141
|
-
SyntaxKind[SyntaxKind["EmptyStatement"] = 48] = "EmptyStatement";
|
|
142
|
-
SyntaxKind[SyntaxKind["InvalidStatement"] = 49] = "InvalidStatement";
|
|
143
|
-
SyntaxKind[SyntaxKind["LineComment"] = 50] = "LineComment";
|
|
144
|
-
SyntaxKind[SyntaxKind["BlockComment"] = 51] = "BlockComment";
|
|
145
|
-
SyntaxKind[SyntaxKind["Doc"] = 52] = "Doc";
|
|
146
|
-
SyntaxKind[SyntaxKind["DocText"] = 53] = "DocText";
|
|
147
|
-
SyntaxKind[SyntaxKind["DocParamTag"] = 54] = "DocParamTag";
|
|
148
|
-
SyntaxKind[SyntaxKind["DocPropTag"] = 55] = "DocPropTag";
|
|
149
|
-
SyntaxKind[SyntaxKind["DocReturnsTag"] = 56] = "DocReturnsTag";
|
|
150
|
-
SyntaxKind[SyntaxKind["DocErrorsTag"] = 57] = "DocErrorsTag";
|
|
151
|
-
SyntaxKind[SyntaxKind["DocTemplateTag"] = 58] = "DocTemplateTag";
|
|
152
|
-
SyntaxKind[SyntaxKind["DocUnknownTag"] = 59] = "DocUnknownTag";
|
|
153
|
-
SyntaxKind[SyntaxKind["Projection"] = 60] = "Projection";
|
|
154
|
-
SyntaxKind[SyntaxKind["ProjectionParameterDeclaration"] = 61] = "ProjectionParameterDeclaration";
|
|
155
|
-
SyntaxKind[SyntaxKind["ProjectionModelSelector"] = 62] = "ProjectionModelSelector";
|
|
156
|
-
SyntaxKind[SyntaxKind["ProjectionModelPropertySelector"] = 63] = "ProjectionModelPropertySelector";
|
|
157
|
-
SyntaxKind[SyntaxKind["ProjectionScalarSelector"] = 64] = "ProjectionScalarSelector";
|
|
158
|
-
SyntaxKind[SyntaxKind["ProjectionOperationSelector"] = 65] = "ProjectionOperationSelector";
|
|
159
|
-
SyntaxKind[SyntaxKind["ProjectionUnionSelector"] = 66] = "ProjectionUnionSelector";
|
|
160
|
-
SyntaxKind[SyntaxKind["ProjectionUnionVariantSelector"] = 67] = "ProjectionUnionVariantSelector";
|
|
161
|
-
SyntaxKind[SyntaxKind["ProjectionInterfaceSelector"] = 68] = "ProjectionInterfaceSelector";
|
|
162
|
-
SyntaxKind[SyntaxKind["ProjectionEnumSelector"] = 69] = "ProjectionEnumSelector";
|
|
163
|
-
SyntaxKind[SyntaxKind["ProjectionEnumMemberSelector"] = 70] = "ProjectionEnumMemberSelector";
|
|
164
|
-
SyntaxKind[SyntaxKind["ProjectionExpressionStatement"] = 71] = "ProjectionExpressionStatement";
|
|
165
|
-
SyntaxKind[SyntaxKind["ProjectionIfExpression"] = 72] = "ProjectionIfExpression";
|
|
166
|
-
SyntaxKind[SyntaxKind["ProjectionBlockExpression"] = 73] = "ProjectionBlockExpression";
|
|
167
|
-
SyntaxKind[SyntaxKind["ProjectionMemberExpression"] = 74] = "ProjectionMemberExpression";
|
|
168
|
-
SyntaxKind[SyntaxKind["ProjectionLogicalExpression"] = 75] = "ProjectionLogicalExpression";
|
|
169
|
-
SyntaxKind[SyntaxKind["ProjectionEqualityExpression"] = 76] = "ProjectionEqualityExpression";
|
|
170
|
-
SyntaxKind[SyntaxKind["ProjectionUnaryExpression"] = 77] = "ProjectionUnaryExpression";
|
|
171
|
-
SyntaxKind[SyntaxKind["ProjectionRelationalExpression"] = 78] = "ProjectionRelationalExpression";
|
|
172
|
-
SyntaxKind[SyntaxKind["ProjectionArithmeticExpression"] = 79] = "ProjectionArithmeticExpression";
|
|
173
|
-
SyntaxKind[SyntaxKind["ProjectionCallExpression"] = 80] = "ProjectionCallExpression";
|
|
174
|
-
SyntaxKind[SyntaxKind["ProjectionLambdaExpression"] = 81] = "ProjectionLambdaExpression";
|
|
175
|
-
SyntaxKind[SyntaxKind["ProjectionLambdaParameterDeclaration"] = 82] = "ProjectionLambdaParameterDeclaration";
|
|
176
|
-
SyntaxKind[SyntaxKind["ProjectionModelExpression"] = 83] = "ProjectionModelExpression";
|
|
177
|
-
SyntaxKind[SyntaxKind["ProjectionModelProperty"] = 84] = "ProjectionModelProperty";
|
|
178
|
-
SyntaxKind[SyntaxKind["ProjectionModelSpreadProperty"] = 85] = "ProjectionModelSpreadProperty";
|
|
179
|
-
SyntaxKind[SyntaxKind["ProjectionSpreadProperty"] = 86] = "ProjectionSpreadProperty";
|
|
180
|
-
SyntaxKind[SyntaxKind["ProjectionTupleExpression"] = 87] = "ProjectionTupleExpression";
|
|
181
|
-
SyntaxKind[SyntaxKind["ProjectionStatement"] = 88] = "ProjectionStatement";
|
|
182
|
-
SyntaxKind[SyntaxKind["ProjectionDecoratorReferenceExpression"] = 89] = "ProjectionDecoratorReferenceExpression";
|
|
183
|
-
SyntaxKind[SyntaxKind["Return"] = 90] = "Return";
|
|
184
|
-
SyntaxKind[SyntaxKind["JsNamespaceDeclaration"] = 91] = "JsNamespaceDeclaration";
|
|
185
|
-
SyntaxKind[SyntaxKind["TemplateArgument"] = 92] = "TemplateArgument";
|
|
186
|
-
SyntaxKind[SyntaxKind["TypeOfExpression"] = 93] = "TypeOfExpression";
|
|
187
|
-
SyntaxKind[SyntaxKind["ObjectLiteral"] = 94] = "ObjectLiteral";
|
|
188
|
-
SyntaxKind[SyntaxKind["ObjectLiteralProperty"] = 95] = "ObjectLiteralProperty";
|
|
189
|
-
SyntaxKind[SyntaxKind["ObjectLiteralSpreadProperty"] = 96] = "ObjectLiteralSpreadProperty";
|
|
190
|
-
SyntaxKind[SyntaxKind["ArrayLiteral"] = 97] = "ArrayLiteral";
|
|
191
|
-
SyntaxKind[SyntaxKind["ConstStatement"] = 98] = "ConstStatement";
|
|
192
|
-
SyntaxKind[SyntaxKind["CallExpression"] = 99] = "CallExpression";
|
|
193
|
-
SyntaxKind[SyntaxKind["ScalarConstructor"] = 100] = "ScalarConstructor";
|
|
194
|
-
})(SyntaxKind || (SyntaxKind = {}));
|
|
195
|
-
var IdentifierKind;
|
|
196
|
-
(function (IdentifierKind) {
|
|
197
|
-
IdentifierKind[IdentifierKind["TypeReference"] = 0] = "TypeReference";
|
|
198
|
-
IdentifierKind[IdentifierKind["TemplateArgument"] = 1] = "TemplateArgument";
|
|
199
|
-
IdentifierKind[IdentifierKind["Decorator"] = 2] = "Decorator";
|
|
200
|
-
IdentifierKind[IdentifierKind["Function"] = 3] = "Function";
|
|
201
|
-
IdentifierKind[IdentifierKind["Using"] = 4] = "Using";
|
|
202
|
-
IdentifierKind[IdentifierKind["Declaration"] = 5] = "Declaration";
|
|
203
|
-
IdentifierKind[IdentifierKind["ModelExpressionProperty"] = 6] = "ModelExpressionProperty";
|
|
204
|
-
IdentifierKind[IdentifierKind["ModelStatementProperty"] = 7] = "ModelStatementProperty";
|
|
205
|
-
IdentifierKind[IdentifierKind["ObjectLiteralProperty"] = 8] = "ObjectLiteralProperty";
|
|
206
|
-
IdentifierKind[IdentifierKind["Other"] = 9] = "Other";
|
|
207
|
-
})(IdentifierKind || (IdentifierKind = {}));
|
|
208
|
-
/** Used to explicitly specify that a diagnostic has no target. */
|
|
209
|
-
const NoTarget = Symbol.for("NoTarget");
|
|
210
|
-
var ListenerFlow;
|
|
211
|
-
(function (ListenerFlow) {
|
|
212
|
-
/**
|
|
213
|
-
* Do not navigate any containing or referenced type.
|
|
214
|
-
*/
|
|
215
|
-
ListenerFlow[ListenerFlow["NoRecursion"] = 1] = "NoRecursion";
|
|
216
|
-
})(ListenerFlow || (ListenerFlow = {}));
|
|
217
|
-
|
|
218
3
|
/**
|
|
219
4
|
* A specially typed version of `Array.isArray` to work around [this issue](https://github.com/microsoft/TypeScript/issues/17002).
|
|
220
5
|
*/
|
|
@@ -426,7 +211,6 @@ const diagnostics = {
|
|
|
426
211
|
unexpected: paramMessage `Unexpected token ${"token"}`,
|
|
427
212
|
numericOrStringLiteral: "Expected numeric or string literal.",
|
|
428
213
|
identifier: "Identifier expected.",
|
|
429
|
-
projectionDirection: "from or to expected.",
|
|
430
214
|
expression: "Expression expected.",
|
|
431
215
|
statement: "Statement expected.",
|
|
432
216
|
property: "Property expected.",
|
|
@@ -465,6 +249,7 @@ const diagnostics = {
|
|
|
465
249
|
severity: "error",
|
|
466
250
|
messages: {
|
|
467
251
|
default: "Keyword cannot be used as identifier.",
|
|
252
|
+
future: paramMessage `${"name"} is a reserved keyword`,
|
|
468
253
|
},
|
|
469
254
|
},
|
|
470
255
|
"invalid-directive-location": {
|
|
@@ -479,15 +264,6 @@ const diagnostics = {
|
|
|
479
264
|
default: paramMessage `Cannot decorate ${"nodeName"}.`,
|
|
480
265
|
},
|
|
481
266
|
},
|
|
482
|
-
"invalid-projection": {
|
|
483
|
-
severity: "error",
|
|
484
|
-
messages: {
|
|
485
|
-
default: "Invalid projection",
|
|
486
|
-
wrongType: "Non-projection can't be used to project",
|
|
487
|
-
noTo: "Projection missing to projection",
|
|
488
|
-
projectionError: paramMessage `An error occurred when projecting this type: ${"message"}`,
|
|
489
|
-
},
|
|
490
|
-
},
|
|
491
267
|
"default-required": {
|
|
492
268
|
severity: "error",
|
|
493
269
|
messages: {
|
|
@@ -682,7 +458,8 @@ const diagnostics = {
|
|
|
682
458
|
messages: {
|
|
683
459
|
default: paramMessage `${"name"} refers to a type, but is being used as a value here.`,
|
|
684
460
|
model: paramMessage `${"name"} refers to a model type, but is being used as a value here. Use #{} to create an object value.`,
|
|
685
|
-
|
|
461
|
+
modelExpression: `Is a model expression type, but is being used as a value here. Use #{} to create an object value.`,
|
|
462
|
+
tuple: `Is a tuple type, but is being used as a value here. Use #[] to create an array value.`,
|
|
686
463
|
templateConstraint: paramMessage `${"name"} template parameter can be a type but is being used as a value here.`,
|
|
687
464
|
},
|
|
688
465
|
},
|
|
@@ -827,6 +604,12 @@ const diagnostics = {
|
|
|
827
604
|
default: "A function declaration must be prefixed with the 'extern' modifier.",
|
|
828
605
|
},
|
|
829
606
|
},
|
|
607
|
+
"function-unsupported": {
|
|
608
|
+
severity: "error",
|
|
609
|
+
messages: {
|
|
610
|
+
default: "Function are currently not supported.",
|
|
611
|
+
},
|
|
612
|
+
},
|
|
830
613
|
"missing-implementation": {
|
|
831
614
|
severity: "error",
|
|
832
615
|
messages: {
|
|
@@ -1328,56 +1111,240 @@ const diagnostics = {
|
|
|
1328
1111
|
};
|
|
1329
1112
|
const { createDiagnostic} = createDiagnosticCreator(diagnostics);
|
|
1330
1113
|
|
|
1331
|
-
function
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1114
|
+
function createSourceFile(text, path) {
|
|
1115
|
+
let lineStarts = undefined;
|
|
1116
|
+
return {
|
|
1117
|
+
text,
|
|
1118
|
+
path,
|
|
1119
|
+
getLineStarts,
|
|
1120
|
+
getLineAndCharacterOfPosition,
|
|
1121
|
+
};
|
|
1122
|
+
function getLineStarts() {
|
|
1123
|
+
return (lineStarts = lineStarts ?? scanLineStarts(text));
|
|
1337
1124
|
}
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
//
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
if (
|
|
1348
|
-
|
|
1125
|
+
function getLineAndCharacterOfPosition(position) {
|
|
1126
|
+
const starts = getLineStarts();
|
|
1127
|
+
let line = binarySearch(starts, position);
|
|
1128
|
+
// When binarySearch returns < 0 indicating that the value was not found, it
|
|
1129
|
+
// returns the bitwise complement of the index where the value would need to
|
|
1130
|
+
// be inserted to keep the array sorted. So flipping the bits back to this
|
|
1131
|
+
// positive index tells us what the line number would be if we were to
|
|
1132
|
+
// create a new line starting at the given position, and subtracting 1 from
|
|
1133
|
+
// that therefore gives us the line number we're after.
|
|
1134
|
+
if (line < 0) {
|
|
1135
|
+
line = ~line - 1;
|
|
1349
1136
|
}
|
|
1350
|
-
return
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
return getSourceLocationOfNode(target, options);
|
|
1137
|
+
return {
|
|
1138
|
+
line,
|
|
1139
|
+
character: position - starts[line],
|
|
1140
|
+
};
|
|
1355
1141
|
}
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1142
|
+
}
|
|
1143
|
+
function scanLineStarts(text) {
|
|
1144
|
+
const starts = [];
|
|
1145
|
+
let start = 0;
|
|
1146
|
+
let pos = 0;
|
|
1147
|
+
while (pos < text.length) {
|
|
1148
|
+
const ch = text.charCodeAt(pos);
|
|
1149
|
+
pos++;
|
|
1150
|
+
switch (ch) {
|
|
1151
|
+
case 13 /* CharCode.CarriageReturn */:
|
|
1152
|
+
if (text.charCodeAt(pos) === 10 /* CharCode.LineFeed */) {
|
|
1153
|
+
pos++;
|
|
1154
|
+
}
|
|
1155
|
+
// fallthrough
|
|
1156
|
+
case 10 /* CharCode.LineFeed */:
|
|
1157
|
+
starts.push(start);
|
|
1158
|
+
start = pos;
|
|
1159
|
+
break;
|
|
1361
1160
|
}
|
|
1362
|
-
return createSyntheticSourceLocation();
|
|
1363
1161
|
}
|
|
1162
|
+
starts.push(start);
|
|
1163
|
+
return starts;
|
|
1364
1164
|
}
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1165
|
+
/**
|
|
1166
|
+
* Search sorted array of numbers for the given value. If found, return index
|
|
1167
|
+
* in array where value was found. If not found, return a negative number that
|
|
1168
|
+
* is the bitwise complement of the index where value would need to be inserted
|
|
1169
|
+
* to keep the array sorted.
|
|
1170
|
+
*/
|
|
1171
|
+
function binarySearch(array, value) {
|
|
1172
|
+
let low = 0;
|
|
1173
|
+
let high = array.length - 1;
|
|
1174
|
+
while (low <= high) {
|
|
1175
|
+
const middle = low + ((high - low) >> 1);
|
|
1176
|
+
const v = array[middle];
|
|
1177
|
+
if (v < value) {
|
|
1178
|
+
low = middle + 1;
|
|
1179
|
+
}
|
|
1180
|
+
else if (v > value) {
|
|
1181
|
+
high = middle - 1;
|
|
1182
|
+
}
|
|
1183
|
+
else {
|
|
1184
|
+
return middle;
|
|
1185
|
+
}
|
|
1186
|
+
}
|
|
1187
|
+
return ~low;
|
|
1188
|
+
}
|
|
1189
|
+
|
|
1190
|
+
var ResolutionResultFlags;
|
|
1191
|
+
(function (ResolutionResultFlags) {
|
|
1192
|
+
ResolutionResultFlags[ResolutionResultFlags["None"] = 0] = "None";
|
|
1193
|
+
ResolutionResultFlags[ResolutionResultFlags["Resolved"] = 2] = "Resolved";
|
|
1194
|
+
ResolutionResultFlags[ResolutionResultFlags["Unknown"] = 4] = "Unknown";
|
|
1195
|
+
ResolutionResultFlags[ResolutionResultFlags["Ambiguous"] = 8] = "Ambiguous";
|
|
1196
|
+
ResolutionResultFlags[ResolutionResultFlags["NotFound"] = 16] = "NotFound";
|
|
1197
|
+
ResolutionResultFlags[ResolutionResultFlags["ResolutionFailed"] = 28] = "ResolutionFailed";
|
|
1198
|
+
})(ResolutionResultFlags || (ResolutionResultFlags = {}));
|
|
1199
|
+
/**
|
|
1200
|
+
* AST types
|
|
1201
|
+
*/
|
|
1202
|
+
var SyntaxKind;
|
|
1203
|
+
(function (SyntaxKind) {
|
|
1204
|
+
SyntaxKind[SyntaxKind["TypeSpecScript"] = 0] = "TypeSpecScript";
|
|
1205
|
+
SyntaxKind[SyntaxKind["JsSourceFile"] = 1] = "JsSourceFile";
|
|
1206
|
+
SyntaxKind[SyntaxKind["ImportStatement"] = 2] = "ImportStatement";
|
|
1207
|
+
SyntaxKind[SyntaxKind["Identifier"] = 3] = "Identifier";
|
|
1208
|
+
SyntaxKind[SyntaxKind["AugmentDecoratorStatement"] = 4] = "AugmentDecoratorStatement";
|
|
1209
|
+
SyntaxKind[SyntaxKind["DecoratorExpression"] = 5] = "DecoratorExpression";
|
|
1210
|
+
SyntaxKind[SyntaxKind["DirectiveExpression"] = 6] = "DirectiveExpression";
|
|
1211
|
+
SyntaxKind[SyntaxKind["MemberExpression"] = 7] = "MemberExpression";
|
|
1212
|
+
SyntaxKind[SyntaxKind["NamespaceStatement"] = 8] = "NamespaceStatement";
|
|
1213
|
+
SyntaxKind[SyntaxKind["UsingStatement"] = 9] = "UsingStatement";
|
|
1214
|
+
SyntaxKind[SyntaxKind["OperationStatement"] = 10] = "OperationStatement";
|
|
1215
|
+
SyntaxKind[SyntaxKind["OperationSignatureDeclaration"] = 11] = "OperationSignatureDeclaration";
|
|
1216
|
+
SyntaxKind[SyntaxKind["OperationSignatureReference"] = 12] = "OperationSignatureReference";
|
|
1217
|
+
SyntaxKind[SyntaxKind["ModelStatement"] = 13] = "ModelStatement";
|
|
1218
|
+
SyntaxKind[SyntaxKind["ModelExpression"] = 14] = "ModelExpression";
|
|
1219
|
+
SyntaxKind[SyntaxKind["ModelProperty"] = 15] = "ModelProperty";
|
|
1220
|
+
SyntaxKind[SyntaxKind["ModelSpreadProperty"] = 16] = "ModelSpreadProperty";
|
|
1221
|
+
SyntaxKind[SyntaxKind["ScalarStatement"] = 17] = "ScalarStatement";
|
|
1222
|
+
SyntaxKind[SyntaxKind["InterfaceStatement"] = 18] = "InterfaceStatement";
|
|
1223
|
+
SyntaxKind[SyntaxKind["UnionStatement"] = 19] = "UnionStatement";
|
|
1224
|
+
SyntaxKind[SyntaxKind["UnionVariant"] = 20] = "UnionVariant";
|
|
1225
|
+
SyntaxKind[SyntaxKind["EnumStatement"] = 21] = "EnumStatement";
|
|
1226
|
+
SyntaxKind[SyntaxKind["EnumMember"] = 22] = "EnumMember";
|
|
1227
|
+
SyntaxKind[SyntaxKind["EnumSpreadMember"] = 23] = "EnumSpreadMember";
|
|
1228
|
+
SyntaxKind[SyntaxKind["AliasStatement"] = 24] = "AliasStatement";
|
|
1229
|
+
SyntaxKind[SyntaxKind["DecoratorDeclarationStatement"] = 25] = "DecoratorDeclarationStatement";
|
|
1230
|
+
SyntaxKind[SyntaxKind["FunctionDeclarationStatement"] = 26] = "FunctionDeclarationStatement";
|
|
1231
|
+
SyntaxKind[SyntaxKind["FunctionParameter"] = 27] = "FunctionParameter";
|
|
1232
|
+
SyntaxKind[SyntaxKind["UnionExpression"] = 28] = "UnionExpression";
|
|
1233
|
+
SyntaxKind[SyntaxKind["IntersectionExpression"] = 29] = "IntersectionExpression";
|
|
1234
|
+
SyntaxKind[SyntaxKind["TupleExpression"] = 30] = "TupleExpression";
|
|
1235
|
+
SyntaxKind[SyntaxKind["ArrayExpression"] = 31] = "ArrayExpression";
|
|
1236
|
+
SyntaxKind[SyntaxKind["StringLiteral"] = 32] = "StringLiteral";
|
|
1237
|
+
SyntaxKind[SyntaxKind["NumericLiteral"] = 33] = "NumericLiteral";
|
|
1238
|
+
SyntaxKind[SyntaxKind["BooleanLiteral"] = 34] = "BooleanLiteral";
|
|
1239
|
+
SyntaxKind[SyntaxKind["StringTemplateExpression"] = 35] = "StringTemplateExpression";
|
|
1240
|
+
SyntaxKind[SyntaxKind["StringTemplateHead"] = 36] = "StringTemplateHead";
|
|
1241
|
+
SyntaxKind[SyntaxKind["StringTemplateMiddle"] = 37] = "StringTemplateMiddle";
|
|
1242
|
+
SyntaxKind[SyntaxKind["StringTemplateTail"] = 38] = "StringTemplateTail";
|
|
1243
|
+
SyntaxKind[SyntaxKind["StringTemplateSpan"] = 39] = "StringTemplateSpan";
|
|
1244
|
+
SyntaxKind[SyntaxKind["ExternKeyword"] = 40] = "ExternKeyword";
|
|
1245
|
+
SyntaxKind[SyntaxKind["VoidKeyword"] = 41] = "VoidKeyword";
|
|
1246
|
+
SyntaxKind[SyntaxKind["NeverKeyword"] = 42] = "NeverKeyword";
|
|
1247
|
+
SyntaxKind[SyntaxKind["UnknownKeyword"] = 43] = "UnknownKeyword";
|
|
1248
|
+
SyntaxKind[SyntaxKind["ValueOfExpression"] = 44] = "ValueOfExpression";
|
|
1249
|
+
SyntaxKind[SyntaxKind["TypeReference"] = 45] = "TypeReference";
|
|
1250
|
+
SyntaxKind[SyntaxKind["TemplateParameterDeclaration"] = 46] = "TemplateParameterDeclaration";
|
|
1251
|
+
SyntaxKind[SyntaxKind["EmptyStatement"] = 47] = "EmptyStatement";
|
|
1252
|
+
SyntaxKind[SyntaxKind["InvalidStatement"] = 48] = "InvalidStatement";
|
|
1253
|
+
SyntaxKind[SyntaxKind["LineComment"] = 49] = "LineComment";
|
|
1254
|
+
SyntaxKind[SyntaxKind["BlockComment"] = 50] = "BlockComment";
|
|
1255
|
+
SyntaxKind[SyntaxKind["Doc"] = 51] = "Doc";
|
|
1256
|
+
SyntaxKind[SyntaxKind["DocText"] = 52] = "DocText";
|
|
1257
|
+
SyntaxKind[SyntaxKind["DocParamTag"] = 53] = "DocParamTag";
|
|
1258
|
+
SyntaxKind[SyntaxKind["DocPropTag"] = 54] = "DocPropTag";
|
|
1259
|
+
SyntaxKind[SyntaxKind["DocReturnsTag"] = 55] = "DocReturnsTag";
|
|
1260
|
+
SyntaxKind[SyntaxKind["DocErrorsTag"] = 56] = "DocErrorsTag";
|
|
1261
|
+
SyntaxKind[SyntaxKind["DocTemplateTag"] = 57] = "DocTemplateTag";
|
|
1262
|
+
SyntaxKind[SyntaxKind["DocUnknownTag"] = 58] = "DocUnknownTag";
|
|
1263
|
+
SyntaxKind[SyntaxKind["Return"] = 59] = "Return";
|
|
1264
|
+
SyntaxKind[SyntaxKind["JsNamespaceDeclaration"] = 60] = "JsNamespaceDeclaration";
|
|
1265
|
+
SyntaxKind[SyntaxKind["TemplateArgument"] = 61] = "TemplateArgument";
|
|
1266
|
+
SyntaxKind[SyntaxKind["TypeOfExpression"] = 62] = "TypeOfExpression";
|
|
1267
|
+
SyntaxKind[SyntaxKind["ObjectLiteral"] = 63] = "ObjectLiteral";
|
|
1268
|
+
SyntaxKind[SyntaxKind["ObjectLiteralProperty"] = 64] = "ObjectLiteralProperty";
|
|
1269
|
+
SyntaxKind[SyntaxKind["ObjectLiteralSpreadProperty"] = 65] = "ObjectLiteralSpreadProperty";
|
|
1270
|
+
SyntaxKind[SyntaxKind["ArrayLiteral"] = 66] = "ArrayLiteral";
|
|
1271
|
+
SyntaxKind[SyntaxKind["ConstStatement"] = 67] = "ConstStatement";
|
|
1272
|
+
SyntaxKind[SyntaxKind["CallExpression"] = 68] = "CallExpression";
|
|
1273
|
+
SyntaxKind[SyntaxKind["ScalarConstructor"] = 69] = "ScalarConstructor";
|
|
1274
|
+
})(SyntaxKind || (SyntaxKind = {}));
|
|
1275
|
+
var IdentifierKind;
|
|
1276
|
+
(function (IdentifierKind) {
|
|
1277
|
+
IdentifierKind[IdentifierKind["TypeReference"] = 0] = "TypeReference";
|
|
1278
|
+
IdentifierKind[IdentifierKind["TemplateArgument"] = 1] = "TemplateArgument";
|
|
1279
|
+
IdentifierKind[IdentifierKind["Decorator"] = 2] = "Decorator";
|
|
1280
|
+
IdentifierKind[IdentifierKind["Function"] = 3] = "Function";
|
|
1281
|
+
IdentifierKind[IdentifierKind["Using"] = 4] = "Using";
|
|
1282
|
+
IdentifierKind[IdentifierKind["Declaration"] = 5] = "Declaration";
|
|
1283
|
+
IdentifierKind[IdentifierKind["ModelExpressionProperty"] = 6] = "ModelExpressionProperty";
|
|
1284
|
+
IdentifierKind[IdentifierKind["ModelStatementProperty"] = 7] = "ModelStatementProperty";
|
|
1285
|
+
IdentifierKind[IdentifierKind["ObjectLiteralProperty"] = 8] = "ObjectLiteralProperty";
|
|
1286
|
+
IdentifierKind[IdentifierKind["Other"] = 9] = "Other";
|
|
1287
|
+
})(IdentifierKind || (IdentifierKind = {}));
|
|
1288
|
+
/** Used to explicitly specify that a diagnostic has no target. */
|
|
1289
|
+
const NoTarget = Symbol.for("NoTarget");
|
|
1290
|
+
var ListenerFlow;
|
|
1291
|
+
(function (ListenerFlow) {
|
|
1292
|
+
/**
|
|
1293
|
+
* Do not navigate any containing or referenced type.
|
|
1294
|
+
*/
|
|
1295
|
+
ListenerFlow[ListenerFlow["NoRecursion"] = 1] = "NoRecursion";
|
|
1296
|
+
})(ListenerFlow || (ListenerFlow = {}));
|
|
1297
|
+
|
|
1298
|
+
function getSourceLocation(target, options = {}) {
|
|
1299
|
+
if (target === NoTarget || target === undefined) {
|
|
1300
|
+
return undefined;
|
|
1301
|
+
}
|
|
1302
|
+
if ("file" in target) {
|
|
1303
|
+
return target;
|
|
1304
|
+
}
|
|
1305
|
+
if (!("kind" in target) && !("entityKind" in target)) {
|
|
1306
|
+
// TemplateInstanceTarget
|
|
1307
|
+
if (!("declarations" in target)) {
|
|
1308
|
+
return getSourceLocationOfNode(target.node, options);
|
|
1309
|
+
}
|
|
1310
|
+
// symbol
|
|
1311
|
+
if (target.flags & 8192 /* SymbolFlags.Using */) {
|
|
1312
|
+
target = target.symbolSource;
|
|
1313
|
+
}
|
|
1314
|
+
if (!target.declarations[0]) {
|
|
1315
|
+
return createSyntheticSourceLocation();
|
|
1316
|
+
}
|
|
1317
|
+
return getSourceLocationOfNode(target.declarations[0], options);
|
|
1318
|
+
}
|
|
1319
|
+
else if ("kind" in target && typeof target.kind === "number") {
|
|
1320
|
+
// node
|
|
1321
|
+
return getSourceLocationOfNode(target, options);
|
|
1322
|
+
}
|
|
1323
|
+
else {
|
|
1324
|
+
// type
|
|
1325
|
+
const targetNode = target.node;
|
|
1326
|
+
if (targetNode) {
|
|
1327
|
+
return getSourceLocationOfNode(targetNode, options);
|
|
1328
|
+
}
|
|
1329
|
+
return createSyntheticSourceLocation();
|
|
1330
|
+
}
|
|
1331
|
+
}
|
|
1332
|
+
function createSyntheticSourceLocation(loc = "<unknown location>") {
|
|
1333
|
+
return {
|
|
1334
|
+
file: createSourceFile("", loc),
|
|
1335
|
+
pos: 0,
|
|
1336
|
+
end: 0,
|
|
1337
|
+
isSynthetic: true,
|
|
1338
|
+
};
|
|
1339
|
+
}
|
|
1340
|
+
function getSourceLocationOfNode(node, options) {
|
|
1341
|
+
let root = node;
|
|
1342
|
+
while (root.parent !== undefined) {
|
|
1343
|
+
root = root.parent;
|
|
1344
|
+
}
|
|
1345
|
+
if (root.kind !== SyntaxKind.TypeSpecScript && root.kind !== SyntaxKind.JsSourceFile) {
|
|
1346
|
+
return createSyntheticSourceLocation(node.flags & 8 /* NodeFlags.Synthetic */
|
|
1347
|
+
? undefined
|
|
1381
1348
|
: "<unknown location - cannot obtain source location of unbound node - file bug at https://github.com/microsoft/typespec>");
|
|
1382
1349
|
}
|
|
1383
1350
|
if (options.locateId && "id" in node && node.id !== undefined) {
|
|
@@ -2408,7 +2375,46 @@ var Token;
|
|
|
2408
2375
|
// Add new non-statement keyword above
|
|
2409
2376
|
/** @internal */ Token[Token["__EndKeyword"] = 80] = "__EndKeyword";
|
|
2410
2377
|
///////////////////////////////////////////////////////////////
|
|
2411
|
-
/** @internal */ Token[Token["
|
|
2378
|
+
/** @internal */ Token[Token["__StartReservedKeyword"] = 80] = "__StartReservedKeyword";
|
|
2379
|
+
///////////////////////////////////////////////////////////////
|
|
2380
|
+
// List of keywords that have special meaning in the language but are reserved for future use
|
|
2381
|
+
Token[Token["StatemachineKeyword"] = 80] = "StatemachineKeyword";
|
|
2382
|
+
Token[Token["MacroKeyword"] = 81] = "MacroKeyword";
|
|
2383
|
+
Token[Token["PackageKeyword"] = 82] = "PackageKeyword";
|
|
2384
|
+
Token[Token["MetadataKeyword"] = 83] = "MetadataKeyword";
|
|
2385
|
+
Token[Token["EnvKeyword"] = 84] = "EnvKeyword";
|
|
2386
|
+
Token[Token["ArgKeyword"] = 85] = "ArgKeyword";
|
|
2387
|
+
Token[Token["DeclareKeyword"] = 86] = "DeclareKeyword";
|
|
2388
|
+
Token[Token["ArrayKeyword"] = 87] = "ArrayKeyword";
|
|
2389
|
+
Token[Token["StructKeyword"] = 88] = "StructKeyword";
|
|
2390
|
+
Token[Token["RecordKeyword"] = 89] = "RecordKeyword";
|
|
2391
|
+
Token[Token["ModuleKeyword"] = 90] = "ModuleKeyword";
|
|
2392
|
+
Token[Token["ModKeyword"] = 91] = "ModKeyword";
|
|
2393
|
+
Token[Token["PubKeyword"] = 92] = "PubKeyword";
|
|
2394
|
+
Token[Token["SubKeyword"] = 93] = "SubKeyword";
|
|
2395
|
+
Token[Token["TypeRefKeyword"] = 94] = "TypeRefKeyword";
|
|
2396
|
+
Token[Token["TraitKeyword"] = 95] = "TraitKeyword";
|
|
2397
|
+
Token[Token["ThisKeyword"] = 96] = "ThisKeyword";
|
|
2398
|
+
Token[Token["SelfKeyword"] = 97] = "SelfKeyword";
|
|
2399
|
+
Token[Token["SuperKeyword"] = 98] = "SuperKeyword";
|
|
2400
|
+
Token[Token["KeyofKeyword"] = 99] = "KeyofKeyword";
|
|
2401
|
+
Token[Token["WithKeyword"] = 100] = "WithKeyword";
|
|
2402
|
+
Token[Token["ImplementsKeyword"] = 101] = "ImplementsKeyword";
|
|
2403
|
+
Token[Token["ImplKeyword"] = 102] = "ImplKeyword";
|
|
2404
|
+
Token[Token["SatisfiesKeyword"] = 103] = "SatisfiesKeyword";
|
|
2405
|
+
Token[Token["FlagKeyword"] = 104] = "FlagKeyword";
|
|
2406
|
+
Token[Token["AutoKeyword"] = 105] = "AutoKeyword";
|
|
2407
|
+
Token[Token["PartialKeyword"] = 106] = "PartialKeyword";
|
|
2408
|
+
Token[Token["PrivateKeyword"] = 107] = "PrivateKeyword";
|
|
2409
|
+
Token[Token["PublicKeyword"] = 108] = "PublicKeyword";
|
|
2410
|
+
Token[Token["ProtectedKeyword"] = 109] = "ProtectedKeyword";
|
|
2411
|
+
Token[Token["InternalKeyword"] = 110] = "InternalKeyword";
|
|
2412
|
+
Token[Token["SealedKeyword"] = 111] = "SealedKeyword";
|
|
2413
|
+
Token[Token["LocalKeyword"] = 112] = "LocalKeyword";
|
|
2414
|
+
Token[Token["AsyncKeyword"] = 113] = "AsyncKeyword";
|
|
2415
|
+
/** @internal */ Token[Token["__EndReservedKeyword"] = 114] = "__EndReservedKeyword";
|
|
2416
|
+
///////////////////////////////////////////////////////////////
|
|
2417
|
+
/** @internal */ Token[Token["__Count"] = 114] = "__Count";
|
|
2412
2418
|
})(Token || (Token = {}));
|
|
2413
2419
|
/** @internal */
|
|
2414
2420
|
const TokenDisplay = getTokenDisplayTable([
|
|
@@ -2492,6 +2498,41 @@ const TokenDisplay = getTokenDisplayTable([
|
|
|
2492
2498
|
[Token.NeverKeyword, "'never'"],
|
|
2493
2499
|
[Token.UnknownKeyword, "'unknown'"],
|
|
2494
2500
|
[Token.ExternKeyword, "'extern'"],
|
|
2501
|
+
// Reserved keywords
|
|
2502
|
+
[Token.StatemachineKeyword, "'statemachine'"],
|
|
2503
|
+
[Token.MacroKeyword, "'macro'"],
|
|
2504
|
+
[Token.PackageKeyword, "'package'"],
|
|
2505
|
+
[Token.MetadataKeyword, "'metadata'"],
|
|
2506
|
+
[Token.EnvKeyword, "'env'"],
|
|
2507
|
+
[Token.ArgKeyword, "'arg'"],
|
|
2508
|
+
[Token.DeclareKeyword, "'declare'"],
|
|
2509
|
+
[Token.ArrayKeyword, "'array'"],
|
|
2510
|
+
[Token.StructKeyword, "'struct'"],
|
|
2511
|
+
[Token.RecordKeyword, "'record'"],
|
|
2512
|
+
[Token.ModuleKeyword, "'module'"],
|
|
2513
|
+
[Token.ModKeyword, "'mod'"],
|
|
2514
|
+
[Token.PubKeyword, "'pub'"],
|
|
2515
|
+
[Token.SubKeyword, "'sub'"],
|
|
2516
|
+
[Token.TypeRefKeyword, "'typeref'"],
|
|
2517
|
+
[Token.TraitKeyword, "'trait'"],
|
|
2518
|
+
[Token.ThisKeyword, "'this'"],
|
|
2519
|
+
[Token.SelfKeyword, "'self'"],
|
|
2520
|
+
[Token.SuperKeyword, "'super'"],
|
|
2521
|
+
[Token.KeyofKeyword, "'keyof'"],
|
|
2522
|
+
[Token.WithKeyword, "'with'"],
|
|
2523
|
+
[Token.ImplementsKeyword, "'implements'"],
|
|
2524
|
+
[Token.ImplKeyword, "'impl'"],
|
|
2525
|
+
[Token.SatisfiesKeyword, "'satisfies'"],
|
|
2526
|
+
[Token.FlagKeyword, "'flag'"],
|
|
2527
|
+
[Token.AutoKeyword, "'auto'"],
|
|
2528
|
+
[Token.PartialKeyword, "'partial'"],
|
|
2529
|
+
[Token.PrivateKeyword, "'private'"],
|
|
2530
|
+
[Token.PublicKeyword, "'public'"],
|
|
2531
|
+
[Token.ProtectedKeyword, "'protected'"],
|
|
2532
|
+
[Token.InternalKeyword, "'internal'"],
|
|
2533
|
+
[Token.SealedKeyword, "'sealed'"],
|
|
2534
|
+
[Token.LocalKeyword, "'local'"],
|
|
2535
|
+
[Token.AsyncKeyword, "'async'"],
|
|
2495
2536
|
]);
|
|
2496
2537
|
/** @internal */
|
|
2497
2538
|
const Keywords = new Map([
|
|
@@ -2523,6 +2564,75 @@ const Keywords = new Map([
|
|
|
2523
2564
|
["never", Token.NeverKeyword],
|
|
2524
2565
|
["unknown", Token.UnknownKeyword],
|
|
2525
2566
|
["extern", Token.ExternKeyword],
|
|
2567
|
+
// Reserved keywords
|
|
2568
|
+
["statemachine", Token.StatemachineKeyword],
|
|
2569
|
+
["macro", Token.MacroKeyword],
|
|
2570
|
+
["package", Token.PackageKeyword],
|
|
2571
|
+
["metadata", Token.MetadataKeyword],
|
|
2572
|
+
["env", Token.EnvKeyword],
|
|
2573
|
+
["arg", Token.ArgKeyword],
|
|
2574
|
+
["declare", Token.DeclareKeyword],
|
|
2575
|
+
["array", Token.ArrayKeyword],
|
|
2576
|
+
["struct", Token.StructKeyword],
|
|
2577
|
+
["record", Token.RecordKeyword],
|
|
2578
|
+
["module", Token.ModuleKeyword],
|
|
2579
|
+
["mod", Token.ModKeyword],
|
|
2580
|
+
["pub", Token.PubKeyword],
|
|
2581
|
+
["sub", Token.SubKeyword],
|
|
2582
|
+
["typeref", Token.TypeRefKeyword],
|
|
2583
|
+
["trait", Token.TraitKeyword],
|
|
2584
|
+
["this", Token.ThisKeyword],
|
|
2585
|
+
["self", Token.SelfKeyword],
|
|
2586
|
+
["super", Token.SuperKeyword],
|
|
2587
|
+
["keyof", Token.KeyofKeyword],
|
|
2588
|
+
["with", Token.WithKeyword],
|
|
2589
|
+
["implements", Token.ImplementsKeyword],
|
|
2590
|
+
["impl", Token.ImplKeyword],
|
|
2591
|
+
["satisfies", Token.SatisfiesKeyword],
|
|
2592
|
+
["flag", Token.FlagKeyword],
|
|
2593
|
+
["auto", Token.AutoKeyword],
|
|
2594
|
+
["partial", Token.PartialKeyword],
|
|
2595
|
+
["private", Token.PrivateKeyword],
|
|
2596
|
+
["public", Token.PublicKeyword],
|
|
2597
|
+
["protected", Token.ProtectedKeyword],
|
|
2598
|
+
["internal", Token.InternalKeyword],
|
|
2599
|
+
["sealed", Token.SealedKeyword],
|
|
2600
|
+
["local", Token.LocalKeyword],
|
|
2601
|
+
["async", Token.AsyncKeyword],
|
|
2602
|
+
]);
|
|
2603
|
+
/** @internal */
|
|
2604
|
+
const ReservedKeywords = new Map([
|
|
2605
|
+
// Reserved keywords
|
|
2606
|
+
["statemachine", Token.StatemachineKeyword],
|
|
2607
|
+
["macro", Token.MacroKeyword],
|
|
2608
|
+
["package", Token.PackageKeyword],
|
|
2609
|
+
["metadata", Token.MetadataKeyword],
|
|
2610
|
+
["env", Token.EnvKeyword],
|
|
2611
|
+
["arg", Token.ArgKeyword],
|
|
2612
|
+
["declare", Token.DeclareKeyword],
|
|
2613
|
+
["array", Token.ArrayKeyword],
|
|
2614
|
+
["struct", Token.StructKeyword],
|
|
2615
|
+
["record", Token.RecordKeyword],
|
|
2616
|
+
["module", Token.ModuleKeyword],
|
|
2617
|
+
["trait", Token.TraitKeyword],
|
|
2618
|
+
["this", Token.ThisKeyword],
|
|
2619
|
+
["self", Token.SelfKeyword],
|
|
2620
|
+
["super", Token.SuperKeyword],
|
|
2621
|
+
["keyof", Token.KeyofKeyword],
|
|
2622
|
+
["with", Token.WithKeyword],
|
|
2623
|
+
["implements", Token.ImplementsKeyword],
|
|
2624
|
+
["impl", Token.ImplKeyword],
|
|
2625
|
+
["satisfies", Token.SatisfiesKeyword],
|
|
2626
|
+
["flag", Token.FlagKeyword],
|
|
2627
|
+
["auto", Token.AutoKeyword],
|
|
2628
|
+
["partial", Token.PartialKeyword],
|
|
2629
|
+
["private", Token.PrivateKeyword],
|
|
2630
|
+
["public", Token.PublicKeyword],
|
|
2631
|
+
["protected", Token.ProtectedKeyword],
|
|
2632
|
+
["internal", Token.InternalKeyword],
|
|
2633
|
+
["sealed", Token.SealedKeyword],
|
|
2634
|
+
["local", Token.LocalKeyword],
|
|
2635
|
+
["async", Token.AsyncKeyword],
|
|
2526
2636
|
]);
|
|
2527
2637
|
var TokenFlags;
|
|
2528
2638
|
(function (TokenFlags) {
|
|
@@ -2543,6 +2653,10 @@ function isComment(token) {
|
|
|
2543
2653
|
function isKeyword(token) {
|
|
2544
2654
|
return token >= Token.__StartKeyword && token < Token.__EndKeyword;
|
|
2545
2655
|
}
|
|
2656
|
+
/** If is a keyword with no actual use right now but will be in the future. */
|
|
2657
|
+
function isReservedKeyword(token) {
|
|
2658
|
+
return token >= Token.__StartReservedKeyword && token < Token.__EndReservedKeyword;
|
|
2659
|
+
}
|
|
2546
2660
|
function isPunctuation(token) {
|
|
2547
2661
|
return token >= Token.__StartPunctuation && token < Token.__EndPunctuation;
|
|
2548
2662
|
}
|
|
@@ -3294,7 +3408,7 @@ function createScanner(source, diagnosticHandler) {
|
|
|
3294
3408
|
break;
|
|
3295
3409
|
}
|
|
3296
3410
|
ch = input.charCodeAt(position);
|
|
3297
|
-
if (count <
|
|
3411
|
+
if (count < 12 /* KeywordLimit.MaxLength */ && isLowercaseAsciiLetter(ch)) {
|
|
3298
3412
|
continue;
|
|
3299
3413
|
}
|
|
3300
3414
|
if (isAsciiIdentifierContinue(ch)) {
|
|
@@ -3308,7 +3422,7 @@ function createScanner(source, diagnosticHandler) {
|
|
|
3308
3422
|
}
|
|
3309
3423
|
break;
|
|
3310
3424
|
}
|
|
3311
|
-
if (count >= 2 /* KeywordLimit.MinLength */ && count <=
|
|
3425
|
+
if (count >= 2 /* KeywordLimit.MinLength */ && count <= 12 /* KeywordLimit.MaxLength */) {
|
|
3312
3426
|
const keyword = Keywords.get(getTokenText());
|
|
3313
3427
|
if (keyword) {
|
|
3314
3428
|
return (token = keyword);
|
|
@@ -3452,8 +3566,9 @@ function getTokenDisplayTable(entries) {
|
|
|
3452
3566
|
* printIdentifier("foo bar") // `foo bar`
|
|
3453
3567
|
* ```
|
|
3454
3568
|
*/
|
|
3455
|
-
function printIdentifier$1(sv
|
|
3456
|
-
|
|
3569
|
+
function printIdentifier$1(sv,
|
|
3570
|
+
/** @internal */ context = "disallow-reserved") {
|
|
3571
|
+
if (needBacktick(sv, context)) {
|
|
3457
3572
|
const escapedString = sv
|
|
3458
3573
|
.replace(/\\/g, "\\\\")
|
|
3459
3574
|
.replace(/\n/g, "\\n")
|
|
@@ -3466,10 +3581,13 @@ function printIdentifier$1(sv) {
|
|
|
3466
3581
|
return sv;
|
|
3467
3582
|
}
|
|
3468
3583
|
}
|
|
3469
|
-
function needBacktick(sv) {
|
|
3584
|
+
function needBacktick(sv, context) {
|
|
3470
3585
|
if (sv.length === 0) {
|
|
3471
3586
|
return false;
|
|
3472
3587
|
}
|
|
3588
|
+
if (context === "allow-reserved" && ReservedKeywords.has(sv)) {
|
|
3589
|
+
return false;
|
|
3590
|
+
}
|
|
3473
3591
|
if (Keywords.has(sv)) {
|
|
3474
3592
|
return true;
|
|
3475
3593
|
}
|
|
@@ -3630,18 +3748,6 @@ var ListKind;
|
|
|
3630
3748
|
close: Token.CloseParen,
|
|
3631
3749
|
invalidAnnotationTarget: "expression",
|
|
3632
3750
|
};
|
|
3633
|
-
ListKind.ProjectionExpression = {
|
|
3634
|
-
...ExpresionsBase,
|
|
3635
|
-
allowEmpty: true,
|
|
3636
|
-
open: Token.OpenParen,
|
|
3637
|
-
close: Token.CloseParen,
|
|
3638
|
-
};
|
|
3639
|
-
ListKind.ProjectionParameter = {
|
|
3640
|
-
...ExpresionsBase,
|
|
3641
|
-
allowEmpty: true,
|
|
3642
|
-
open: Token.OpenParen,
|
|
3643
|
-
close: Token.CloseParen,
|
|
3644
|
-
};
|
|
3645
3751
|
})(ListKind || (ListKind = {}));
|
|
3646
3752
|
function parse$1(code, options = {}) {
|
|
3647
3753
|
const parser = createParser(code, options);
|
|
@@ -3769,10 +3875,6 @@ function createParser(code, options = {}) {
|
|
|
3769
3875
|
reportInvalidDecorators(decorators, "using statement");
|
|
3770
3876
|
item = parseUsingStatement(pos);
|
|
3771
3877
|
break;
|
|
3772
|
-
case Token.ProjectionKeyword:
|
|
3773
|
-
reportInvalidDecorators(decorators, "projection statement");
|
|
3774
|
-
item = parseProjectionStatement(pos);
|
|
3775
|
-
break;
|
|
3776
3878
|
case Token.Semicolon:
|
|
3777
3879
|
reportInvalidDecorators(decorators, "empty statement");
|
|
3778
3880
|
item = parseEmptyStatement(pos);
|
|
@@ -3873,10 +3975,6 @@ function createParser(code, options = {}) {
|
|
|
3873
3975
|
case Token.DecKeyword:
|
|
3874
3976
|
item = parseDeclaration(pos);
|
|
3875
3977
|
break;
|
|
3876
|
-
case Token.ProjectionKeyword:
|
|
3877
|
-
reportInvalidDecorators(decorators, "project statement");
|
|
3878
|
-
item = parseProjectionStatement(pos);
|
|
3879
|
-
break;
|
|
3880
3978
|
case Token.EndOfFile:
|
|
3881
3979
|
parseExpected(Token.CloseBrace);
|
|
3882
3980
|
return stmts;
|
|
@@ -4003,8 +4101,28 @@ function createParser(code, options = {}) {
|
|
|
4003
4101
|
...finishNode(pos),
|
|
4004
4102
|
};
|
|
4005
4103
|
}
|
|
4104
|
+
function parseIdOrValueForVariant() {
|
|
4105
|
+
const nextToken = token();
|
|
4106
|
+
let id;
|
|
4107
|
+
if (isReservedKeyword(nextToken)) {
|
|
4108
|
+
id = parseIdentifier({ allowReservedIdentifier: true });
|
|
4109
|
+
// If the next token is not a colon this means we tried to use the reserved keyword as a type reference
|
|
4110
|
+
if (token() !== Token.Colon) {
|
|
4111
|
+
error({ code: "reserved-identifier", messageId: "future", format: { name: id.sv } });
|
|
4112
|
+
}
|
|
4113
|
+
return {
|
|
4114
|
+
kind: SyntaxKind.TypeReference,
|
|
4115
|
+
target: id,
|
|
4116
|
+
arguments: [],
|
|
4117
|
+
...finishNode(id.pos),
|
|
4118
|
+
};
|
|
4119
|
+
}
|
|
4120
|
+
else {
|
|
4121
|
+
return parseExpression();
|
|
4122
|
+
}
|
|
4123
|
+
}
|
|
4006
4124
|
function parseUnionVariant(pos, decorators) {
|
|
4007
|
-
const idOrExpr =
|
|
4125
|
+
const idOrExpr = parseIdOrValueForVariant();
|
|
4008
4126
|
if (parseOptional(Token.Colon)) {
|
|
4009
4127
|
let id = undefined;
|
|
4010
4128
|
if (idOrExpr.kind !== SyntaxKind.TypeReference &&
|
|
@@ -4047,7 +4165,7 @@ function createParser(code, options = {}) {
|
|
|
4047
4165
|
}
|
|
4048
4166
|
function parseUsingStatement(pos) {
|
|
4049
4167
|
parseExpected(Token.UsingKeyword);
|
|
4050
|
-
const name = parseIdentifierOrMemberExpression(
|
|
4168
|
+
const name = parseIdentifierOrMemberExpression();
|
|
4051
4169
|
parseExpected(Token.Semicolon);
|
|
4052
4170
|
return {
|
|
4053
4171
|
kind: SyntaxKind.UsingStatement,
|
|
@@ -4227,6 +4345,7 @@ function createParser(code, options = {}) {
|
|
|
4227
4345
|
const id = parseIdentifier({
|
|
4228
4346
|
message: "property",
|
|
4229
4347
|
allowStringLiteral: true,
|
|
4348
|
+
allowReservedIdentifier: true,
|
|
4230
4349
|
});
|
|
4231
4350
|
const optional = parseOptional(Token.Question);
|
|
4232
4351
|
parseExpected(Token.Colon);
|
|
@@ -4262,6 +4381,7 @@ function createParser(code, options = {}) {
|
|
|
4262
4381
|
function parseObjectLiteralProperty(pos) {
|
|
4263
4382
|
const id = parseIdentifier({
|
|
4264
4383
|
message: "property",
|
|
4384
|
+
allowReservedIdentifier: true,
|
|
4265
4385
|
});
|
|
4266
4386
|
parseExpected(Token.Colon);
|
|
4267
4387
|
const value = parseExpression();
|
|
@@ -4348,6 +4468,7 @@ function createParser(code, options = {}) {
|
|
|
4348
4468
|
const id = parseIdentifier({
|
|
4349
4469
|
message: "enumMember",
|
|
4350
4470
|
allowStringLiteral: true,
|
|
4471
|
+
allowReservedIdentifier: true,
|
|
4351
4472
|
});
|
|
4352
4473
|
let value;
|
|
4353
4474
|
if (parseOptional(Token.Colon)) {
|
|
@@ -4515,12 +4636,18 @@ function createParser(code, options = {}) {
|
|
|
4515
4636
|
}
|
|
4516
4637
|
function parseReferenceExpression(message) {
|
|
4517
4638
|
const pos = tokenPos();
|
|
4518
|
-
const target = parseIdentifierOrMemberExpression(
|
|
4639
|
+
const target = parseIdentifierOrMemberExpression({
|
|
4640
|
+
message,
|
|
4641
|
+
allowReservedIdentifierInMember: true,
|
|
4642
|
+
});
|
|
4519
4643
|
return parseReferenceExpressionInternal(target, pos);
|
|
4520
4644
|
}
|
|
4521
4645
|
function parseCallOrReferenceExpression(message) {
|
|
4522
4646
|
const pos = tokenPos();
|
|
4523
|
-
const target = parseIdentifierOrMemberExpression(
|
|
4647
|
+
const target = parseIdentifierOrMemberExpression({
|
|
4648
|
+
message,
|
|
4649
|
+
allowReservedIdentifierInMember: true,
|
|
4650
|
+
});
|
|
4524
4651
|
if (token() === Token.OpenParen) {
|
|
4525
4652
|
const { items: args } = parseList(ListKind.FunctionArguments, parseExpression);
|
|
4526
4653
|
return {
|
|
@@ -4583,7 +4710,7 @@ function createParser(code, options = {}) {
|
|
|
4583
4710
|
// identifier. We want to parse `@ model Foo` as invalid decorator
|
|
4584
4711
|
// `@<missing identifier>` applied to `model Foo`, and not as `@model`
|
|
4585
4712
|
// applied to invalid statement `Foo`.
|
|
4586
|
-
const target = parseIdentifierOrMemberExpression(
|
|
4713
|
+
const target = parseIdentifierOrMemberExpression({ allowReservedIdentifierInMember: true });
|
|
4587
4714
|
const { items: args } = parseOptionalList(ListKind.DecoratorArguments, parseExpression);
|
|
4588
4715
|
if (args.length === 0) {
|
|
4589
4716
|
error({ code: "augment-decorator-target" });
|
|
@@ -4639,7 +4766,10 @@ function createParser(code, options = {}) {
|
|
|
4639
4766
|
// identifier. We want to parse `@ model Foo` as invalid decorator
|
|
4640
4767
|
// `@<missing identifier>` applied to `model Foo`, and not as `@model`
|
|
4641
4768
|
// applied to invalid statement `Foo`.
|
|
4642
|
-
const target = parseIdentifierOrMemberExpression(
|
|
4769
|
+
const target = parseIdentifierOrMemberExpression({
|
|
4770
|
+
allowReservedIdentifier: true,
|
|
4771
|
+
allowReservedIdentifierInMember: true,
|
|
4772
|
+
});
|
|
4643
4773
|
const { items: args } = parseOptionalList(ListKind.DecoratorArguments, parseExpression);
|
|
4644
4774
|
return {
|
|
4645
4775
|
kind: SyntaxKind.DecoratorExpression,
|
|
@@ -4700,11 +4830,11 @@ function createParser(code, options = {}) {
|
|
|
4700
4830
|
return undefined;
|
|
4701
4831
|
}
|
|
4702
4832
|
}
|
|
4703
|
-
function parseIdentifierOrMemberExpression(
|
|
4833
|
+
function parseIdentifierOrMemberExpression(options) {
|
|
4704
4834
|
const pos = tokenPos();
|
|
4705
4835
|
let base = parseIdentifier({
|
|
4706
|
-
message,
|
|
4707
|
-
|
|
4836
|
+
message: options?.message,
|
|
4837
|
+
allowReservedIdentifier: options?.allowReservedIdentifier,
|
|
4708
4838
|
});
|
|
4709
4839
|
while (token() !== Token.EndOfFile) {
|
|
4710
4840
|
if (parseOptional(Token.Dot)) {
|
|
@@ -4717,7 +4847,7 @@ function createParser(code, options = {}) {
|
|
|
4717
4847
|
// `@Outer.model` applied to invalid statement `M {}` instead of
|
|
4718
4848
|
// having incomplete decorator `@Outer.` applied to `model M {}`.
|
|
4719
4849
|
id: parseIdentifier({
|
|
4720
|
-
|
|
4850
|
+
allowReservedIdentifier: options?.allowReservedIdentifierInMember,
|
|
4721
4851
|
}),
|
|
4722
4852
|
selector: ".",
|
|
4723
4853
|
...finishNode(pos),
|
|
@@ -4960,731 +5090,173 @@ function createParser(code, options = {}) {
|
|
|
4960
5090
|
const value = Number(valueAsString);
|
|
4961
5091
|
parseExpected(Token.NumericLiteral);
|
|
4962
5092
|
return {
|
|
4963
|
-
kind: SyntaxKind.NumericLiteral,
|
|
4964
|
-
value,
|
|
4965
|
-
valueAsString,
|
|
4966
|
-
...finishNode(pos),
|
|
4967
|
-
};
|
|
4968
|
-
}
|
|
4969
|
-
function parseBooleanLiteral() {
|
|
4970
|
-
const pos = tokenPos();
|
|
4971
|
-
const token = parseExpectedOneOf(Token.TrueKeyword, Token.FalseKeyword);
|
|
4972
|
-
const value = token === Token.TrueKeyword;
|
|
4973
|
-
return {
|
|
4974
|
-
kind: SyntaxKind.BooleanLiteral,
|
|
4975
|
-
value,
|
|
4976
|
-
...finishNode(pos),
|
|
4977
|
-
};
|
|
4978
|
-
}
|
|
4979
|
-
function parseIdentifier(options) {
|
|
4980
|
-
if (options?.recoverFromKeyword !== false && isKeyword(token())) {
|
|
4981
|
-
error({ code: "reserved-identifier" });
|
|
4982
|
-
}
|
|
4983
|
-
else if (token() !== Token.Identifier &&
|
|
4984
|
-
(!options?.allowStringLiteral || token() !== Token.StringLiteral)) {
|
|
4985
|
-
// Error recovery: when we fail to parse an identifier or expression,
|
|
4986
|
-
// we insert a synthesized identifier with a unique name.
|
|
4987
|
-
error({ code: "token-expected", messageId: options?.message ?? "identifier" });
|
|
4988
|
-
return createMissingIdentifier();
|
|
4989
|
-
}
|
|
4990
|
-
const pos = tokenPos();
|
|
4991
|
-
const sv = tokenValue();
|
|
4992
|
-
nextToken();
|
|
4993
|
-
return {
|
|
4994
|
-
kind: SyntaxKind.Identifier,
|
|
4995
|
-
sv,
|
|
4996
|
-
...finishNode(pos),
|
|
4997
|
-
};
|
|
4998
|
-
}
|
|
4999
|
-
function parseDeclaration(pos) {
|
|
5000
|
-
const modifiers = parseModifiers();
|
|
5001
|
-
switch (token()) {
|
|
5002
|
-
case Token.DecKeyword:
|
|
5003
|
-
return parseDecoratorDeclarationStatement(pos, modifiers);
|
|
5004
|
-
case Token.FnKeyword:
|
|
5005
|
-
return parseFunctionDeclarationStatement(pos, modifiers);
|
|
5006
|
-
}
|
|
5007
|
-
return parseInvalidStatement(pos, []);
|
|
5008
|
-
}
|
|
5009
|
-
function parseModifiers() {
|
|
5010
|
-
const modifiers = [];
|
|
5011
|
-
let modifier;
|
|
5012
|
-
while ((modifier = parseModifier())) {
|
|
5013
|
-
modifiers.push(modifier);
|
|
5014
|
-
}
|
|
5015
|
-
return modifiers;
|
|
5016
|
-
}
|
|
5017
|
-
function parseModifier() {
|
|
5018
|
-
switch (token()) {
|
|
5019
|
-
case Token.ExternKeyword:
|
|
5020
|
-
return parseExternKeyword();
|
|
5021
|
-
default:
|
|
5022
|
-
return undefined;
|
|
5023
|
-
}
|
|
5024
|
-
}
|
|
5025
|
-
function parseDecoratorDeclarationStatement(pos, modifiers) {
|
|
5026
|
-
const modifierFlags = modifiersToFlags(modifiers);
|
|
5027
|
-
parseExpected(Token.DecKeyword);
|
|
5028
|
-
const id = parseIdentifier();
|
|
5029
|
-
const allParamListDetail = parseFunctionParameters();
|
|
5030
|
-
let [target, ...parameters] = allParamListDetail.items;
|
|
5031
|
-
if (target === undefined) {
|
|
5032
|
-
error({ code: "decorator-decl-target", target: { pos, end: previousTokenEnd } });
|
|
5033
|
-
target = {
|
|
5034
|
-
kind: SyntaxKind.FunctionParameter,
|
|
5035
|
-
id: createMissingIdentifier(),
|
|
5036
|
-
type: createMissingTypeReference(),
|
|
5037
|
-
optional: false,
|
|
5038
|
-
rest: false,
|
|
5039
|
-
...finishNode(pos),
|
|
5040
|
-
};
|
|
5041
|
-
}
|
|
5042
|
-
if (target.optional) {
|
|
5043
|
-
error({ code: "decorator-decl-target", messageId: "required" });
|
|
5044
|
-
}
|
|
5045
|
-
parseExpected(Token.Semicolon);
|
|
5046
|
-
return {
|
|
5047
|
-
kind: SyntaxKind.DecoratorDeclarationStatement,
|
|
5048
|
-
modifiers,
|
|
5049
|
-
modifierFlags,
|
|
5050
|
-
id,
|
|
5051
|
-
target,
|
|
5052
|
-
parameters,
|
|
5053
|
-
...finishNode(pos),
|
|
5054
|
-
};
|
|
5055
|
-
}
|
|
5056
|
-
function parseFunctionDeclarationStatement(pos, modifiers) {
|
|
5057
|
-
const modifierFlags = modifiersToFlags(modifiers);
|
|
5058
|
-
parseExpected(Token.FnKeyword);
|
|
5059
|
-
const id = parseIdentifier();
|
|
5060
|
-
const { items: parameters } = parseFunctionParameters();
|
|
5061
|
-
let returnType;
|
|
5062
|
-
if (parseOptional(Token.Colon)) {
|
|
5063
|
-
returnType = parseExpression();
|
|
5064
|
-
}
|
|
5065
|
-
parseExpected(Token.Semicolon);
|
|
5066
|
-
return {
|
|
5067
|
-
kind: SyntaxKind.FunctionDeclarationStatement,
|
|
5068
|
-
modifiers,
|
|
5069
|
-
modifierFlags,
|
|
5070
|
-
id,
|
|
5071
|
-
parameters,
|
|
5072
|
-
returnType,
|
|
5073
|
-
...finishNode(pos),
|
|
5074
|
-
};
|
|
5075
|
-
}
|
|
5076
|
-
function parseFunctionParameters() {
|
|
5077
|
-
const parameters = parseList(ListKind.FunctionParameters, parseFunctionParameter);
|
|
5078
|
-
let foundOptional = false;
|
|
5079
|
-
for (const [index, item] of parameters.items.entries()) {
|
|
5080
|
-
if (!item.optional && foundOptional) {
|
|
5081
|
-
error({ code: "required-parameter-first", target: item });
|
|
5082
|
-
continue;
|
|
5083
|
-
}
|
|
5084
|
-
if (item.optional) {
|
|
5085
|
-
foundOptional = true;
|
|
5086
|
-
}
|
|
5087
|
-
if (item.rest && item.optional) {
|
|
5088
|
-
error({ code: "rest-parameter-required", target: item });
|
|
5089
|
-
}
|
|
5090
|
-
if (item.rest && index !== parameters.items.length - 1) {
|
|
5091
|
-
error({ code: "rest-parameter-last", target: item });
|
|
5092
|
-
}
|
|
5093
|
-
}
|
|
5094
|
-
return parameters;
|
|
5095
|
-
}
|
|
5096
|
-
function parseFunctionParameter() {
|
|
5097
|
-
const pos = tokenPos();
|
|
5098
|
-
const rest = parseOptional(Token.Ellipsis);
|
|
5099
|
-
const id = parseIdentifier({ message: "property" });
|
|
5100
|
-
const optional = parseOptional(Token.Question);
|
|
5101
|
-
let type;
|
|
5102
|
-
if (parseOptional(Token.Colon)) {
|
|
5103
|
-
type = parseMixedParameterConstraint();
|
|
5104
|
-
}
|
|
5105
|
-
return {
|
|
5106
|
-
kind: SyntaxKind.FunctionParameter,
|
|
5107
|
-
id,
|
|
5108
|
-
type,
|
|
5109
|
-
optional,
|
|
5110
|
-
rest,
|
|
5111
|
-
...finishNode(pos),
|
|
5112
|
-
};
|
|
5113
|
-
}
|
|
5114
|
-
function modifiersToFlags(modifiers) {
|
|
5115
|
-
let flags = 0 /* ModifierFlags.None */;
|
|
5116
|
-
for (const modifier of modifiers) {
|
|
5117
|
-
switch (modifier.kind) {
|
|
5118
|
-
case SyntaxKind.ExternKeyword:
|
|
5119
|
-
flags |= 2 /* ModifierFlags.Extern */;
|
|
5120
|
-
break;
|
|
5121
|
-
}
|
|
5122
|
-
}
|
|
5123
|
-
return flags;
|
|
5124
|
-
}
|
|
5125
|
-
// eslint-disable-next-line @typescript-eslint/no-deprecated
|
|
5126
|
-
function parseProjectionStatement(pos) {
|
|
5127
|
-
parseExpected(Token.ProjectionKeyword);
|
|
5128
|
-
const selector = parseProjectionSelector();
|
|
5129
|
-
parseExpected(Token.Hash);
|
|
5130
|
-
const id = parseIdentifier();
|
|
5131
|
-
parseExpected(Token.OpenBrace);
|
|
5132
|
-
const projectionMap = new Map();
|
|
5133
|
-
const projections = [];
|
|
5134
|
-
while (token() === Token.Identifier) {
|
|
5135
|
-
const projection = parseProjection();
|
|
5136
|
-
if (projection.direction !== "<error>") {
|
|
5137
|
-
if (projectionMap.has(projection.direction)) {
|
|
5138
|
-
error({ code: "duplicate-symbol", target: projection, format: { name: "projection" } });
|
|
5139
|
-
}
|
|
5140
|
-
else {
|
|
5141
|
-
projectionMap.set(projection.direction, projection);
|
|
5142
|
-
}
|
|
5143
|
-
}
|
|
5144
|
-
// NOTE: Don't drop projections with error in direction definition from the AST.
|
|
5145
|
-
projections.push(projection);
|
|
5146
|
-
}
|
|
5147
|
-
parseExpected(Token.CloseBrace);
|
|
5148
|
-
return {
|
|
5149
|
-
kind: SyntaxKind.ProjectionStatement,
|
|
5150
|
-
selector,
|
|
5151
|
-
projections,
|
|
5152
|
-
preTo: projectionMap.get("pre_to"),
|
|
5153
|
-
preFrom: projectionMap.get("pre_from"),
|
|
5154
|
-
from: projectionMap.get("from"),
|
|
5155
|
-
to: projectionMap.get("to"),
|
|
5156
|
-
id,
|
|
5157
|
-
...finishNode(pos),
|
|
5158
|
-
};
|
|
5159
|
-
}
|
|
5160
|
-
function parseProjection() {
|
|
5161
|
-
const pos = tokenPos();
|
|
5162
|
-
let directionId = parseIdentifier({ message: "projectionDirection" });
|
|
5163
|
-
let direction;
|
|
5164
|
-
const modifierIds = [];
|
|
5165
|
-
let isPre = false;
|
|
5166
|
-
if (directionId.sv === "pre") {
|
|
5167
|
-
isPre = true;
|
|
5168
|
-
modifierIds.push(directionId);
|
|
5169
|
-
directionId = parseIdentifier({ message: "projectionDirection" });
|
|
5170
|
-
}
|
|
5171
|
-
if (directionId.sv !== "to" && directionId.sv !== "from") {
|
|
5172
|
-
error({ code: "token-expected", messageId: "projectionDirection" });
|
|
5173
|
-
direction = "<error>";
|
|
5174
|
-
}
|
|
5175
|
-
else if (isPre) {
|
|
5176
|
-
direction = directionId.sv === "to" ? "pre_to" : "pre_from";
|
|
5177
|
-
}
|
|
5178
|
-
else {
|
|
5179
|
-
direction = directionId.sv;
|
|
5180
|
-
}
|
|
5181
|
-
let parameters;
|
|
5182
|
-
if (token() === Token.OpenParen) {
|
|
5183
|
-
parameters = parseList(ListKind.ProjectionParameter, parseProjectionParameter).items;
|
|
5184
|
-
}
|
|
5185
|
-
else {
|
|
5186
|
-
parameters = [];
|
|
5187
|
-
}
|
|
5188
|
-
parseExpected(Token.OpenBrace);
|
|
5189
|
-
const body = parseProjectionStatementList();
|
|
5190
|
-
parseExpected(Token.CloseBrace);
|
|
5191
|
-
return {
|
|
5192
|
-
kind: SyntaxKind.Projection,
|
|
5193
|
-
body,
|
|
5194
|
-
direction,
|
|
5195
|
-
directionId,
|
|
5196
|
-
modifierIds,
|
|
5197
|
-
parameters,
|
|
5198
|
-
...finishNode(pos),
|
|
5199
|
-
};
|
|
5200
|
-
}
|
|
5201
|
-
function parseProjectionParameter() {
|
|
5202
|
-
const pos = tokenPos();
|
|
5203
|
-
const id = parseIdentifier();
|
|
5204
|
-
return {
|
|
5205
|
-
kind: SyntaxKind.ProjectionParameterDeclaration,
|
|
5206
|
-
id,
|
|
5207
|
-
...finishNode(pos),
|
|
5208
|
-
};
|
|
5209
|
-
}
|
|
5210
|
-
function parseProjectionStatementList() {
|
|
5211
|
-
const stmts = [];
|
|
5212
|
-
while (token() !== Token.CloseBrace) {
|
|
5213
|
-
const startPos = tokenPos();
|
|
5214
|
-
if (token() === Token.EndOfFile) {
|
|
5215
|
-
error({ code: "token-expected", messageId: "default", format: { token: "}" } });
|
|
5216
|
-
break;
|
|
5217
|
-
}
|
|
5218
|
-
const expr = parseProjectionExpressionStatement();
|
|
5219
|
-
stmts.push(expr);
|
|
5220
|
-
if (tokenPos() === startPos) {
|
|
5221
|
-
// we didn't manage to parse anything, so break out
|
|
5222
|
-
// and we'll report errors elsewhere.
|
|
5223
|
-
break;
|
|
5224
|
-
}
|
|
5225
|
-
}
|
|
5226
|
-
return stmts;
|
|
5227
|
-
}
|
|
5228
|
-
function parseProjectionExpressionStatement() {
|
|
5229
|
-
const pos = tokenPos();
|
|
5230
|
-
const expr = parseProjectionExpression();
|
|
5231
|
-
parseExpected(Token.Semicolon);
|
|
5232
|
-
return {
|
|
5233
|
-
kind: SyntaxKind.ProjectionExpressionStatement,
|
|
5234
|
-
expr,
|
|
5235
|
-
...finishNode(pos),
|
|
5236
|
-
};
|
|
5237
|
-
}
|
|
5238
|
-
function parseProjectionExpression() {
|
|
5239
|
-
return parseProjectionReturnExpressionOrHigher();
|
|
5240
|
-
}
|
|
5241
|
-
function parseProjectionReturnExpressionOrHigher() {
|
|
5242
|
-
if (token() === Token.ReturnKeyword) {
|
|
5243
|
-
const pos = tokenPos();
|
|
5244
|
-
parseExpected(Token.ReturnKeyword);
|
|
5245
|
-
return {
|
|
5246
|
-
kind: SyntaxKind.Return,
|
|
5247
|
-
value: parseProjectionExpression(),
|
|
5248
|
-
...finishNode(pos),
|
|
5249
|
-
};
|
|
5250
|
-
}
|
|
5251
|
-
return parseProjectionLogicalOrExpressionOrHigher();
|
|
5252
|
-
}
|
|
5253
|
-
function parseProjectionLogicalOrExpressionOrHigher() {
|
|
5254
|
-
let expr = parseProjectionLogicalAndExpressionOrHigher();
|
|
5255
|
-
while (token() !== Token.EndOfFile) {
|
|
5256
|
-
const pos = expr.pos;
|
|
5257
|
-
if (parseOptional(Token.BarBar)) {
|
|
5258
|
-
expr = {
|
|
5259
|
-
kind: SyntaxKind.ProjectionLogicalExpression,
|
|
5260
|
-
op: "||",
|
|
5261
|
-
left: expr,
|
|
5262
|
-
right: parseProjectionLogicalAndExpressionOrHigher(),
|
|
5263
|
-
...finishNode(pos),
|
|
5264
|
-
};
|
|
5265
|
-
}
|
|
5266
|
-
else {
|
|
5267
|
-
break;
|
|
5268
|
-
}
|
|
5269
|
-
}
|
|
5270
|
-
return expr;
|
|
5271
|
-
}
|
|
5272
|
-
function parseProjectionLogicalAndExpressionOrHigher() {
|
|
5273
|
-
let expr = parseProjectionEqualityExpressionOrHigher();
|
|
5274
|
-
while (token() !== Token.EndOfFile) {
|
|
5275
|
-
const pos = expr.pos;
|
|
5276
|
-
if (parseOptional(Token.AmpsersandAmpersand)) {
|
|
5277
|
-
expr = {
|
|
5278
|
-
kind: SyntaxKind.ProjectionLogicalExpression,
|
|
5279
|
-
op: "&&",
|
|
5280
|
-
left: expr,
|
|
5281
|
-
right: parseProjectionEqualityExpressionOrHigher(),
|
|
5282
|
-
...finishNode(pos),
|
|
5283
|
-
};
|
|
5284
|
-
}
|
|
5285
|
-
else {
|
|
5286
|
-
break;
|
|
5287
|
-
}
|
|
5288
|
-
}
|
|
5289
|
-
return expr;
|
|
5290
|
-
}
|
|
5291
|
-
function parseProjectionEqualityExpressionOrHigher() {
|
|
5292
|
-
let expr = parseProjectionRelationalExpressionOrHigher();
|
|
5293
|
-
while (token() !== Token.EndOfFile) {
|
|
5294
|
-
const pos = expr.pos;
|
|
5295
|
-
const tok = token();
|
|
5296
|
-
if (tok === Token.EqualsEquals || tok === Token.ExclamationEquals) {
|
|
5297
|
-
const op = tokenValue();
|
|
5298
|
-
nextToken();
|
|
5299
|
-
expr = {
|
|
5300
|
-
kind: SyntaxKind.ProjectionEqualityExpression,
|
|
5301
|
-
op,
|
|
5302
|
-
left: expr,
|
|
5303
|
-
right: parseProjectionRelationalExpressionOrHigher(),
|
|
5304
|
-
...finishNode(pos),
|
|
5305
|
-
};
|
|
5306
|
-
}
|
|
5307
|
-
else {
|
|
5308
|
-
break;
|
|
5309
|
-
}
|
|
5310
|
-
}
|
|
5311
|
-
return expr;
|
|
5312
|
-
}
|
|
5313
|
-
function parseProjectionRelationalExpressionOrHigher() {
|
|
5314
|
-
let expr = parseProjectionAdditiveExpressionOrHigher();
|
|
5315
|
-
while (token() !== Token.EndOfFile) {
|
|
5316
|
-
const pos = expr.pos;
|
|
5317
|
-
const tok = token();
|
|
5318
|
-
if (tok === Token.LessThan ||
|
|
5319
|
-
tok === Token.LessThanEquals ||
|
|
5320
|
-
tok === Token.GreaterThan ||
|
|
5321
|
-
tok === Token.GreaterThanEquals) {
|
|
5322
|
-
const op = tokenValue();
|
|
5323
|
-
nextToken();
|
|
5324
|
-
expr = {
|
|
5325
|
-
kind: SyntaxKind.ProjectionRelationalExpression,
|
|
5326
|
-
op,
|
|
5327
|
-
left: expr,
|
|
5328
|
-
right: parseProjectionAdditiveExpressionOrHigher(),
|
|
5329
|
-
...finishNode(pos),
|
|
5330
|
-
};
|
|
5331
|
-
}
|
|
5332
|
-
else {
|
|
5333
|
-
break;
|
|
5334
|
-
}
|
|
5335
|
-
}
|
|
5336
|
-
return expr;
|
|
5337
|
-
}
|
|
5338
|
-
function parseProjectionAdditiveExpressionOrHigher() {
|
|
5339
|
-
let expr = parseProjectionMultiplicativeExpressionOrHigher();
|
|
5340
|
-
while (token() !== Token.EndOfFile) {
|
|
5341
|
-
const pos = expr.pos;
|
|
5342
|
-
const tok = token();
|
|
5343
|
-
if (tok === Token.Plus || tok === Token.Hyphen) {
|
|
5344
|
-
const op = tokenValue();
|
|
5345
|
-
nextToken();
|
|
5346
|
-
expr = {
|
|
5347
|
-
kind: SyntaxKind.ProjectionArithmeticExpression,
|
|
5348
|
-
op,
|
|
5349
|
-
left: expr,
|
|
5350
|
-
right: parseProjectionMultiplicativeExpressionOrHigher(),
|
|
5351
|
-
...finishNode(pos),
|
|
5352
|
-
};
|
|
5353
|
-
}
|
|
5354
|
-
else {
|
|
5355
|
-
break;
|
|
5356
|
-
}
|
|
5357
|
-
}
|
|
5358
|
-
return expr;
|
|
5359
|
-
}
|
|
5360
|
-
function parseProjectionMultiplicativeExpressionOrHigher() {
|
|
5361
|
-
let expr = parseProjectionUnaryExpressionOrHigher();
|
|
5362
|
-
while (token() !== Token.EndOfFile) {
|
|
5363
|
-
const pos = expr.pos;
|
|
5364
|
-
const tok = token();
|
|
5365
|
-
if (tok === Token.ForwardSlash || tok === Token.Star) {
|
|
5366
|
-
const op = tokenValue();
|
|
5367
|
-
nextToken();
|
|
5368
|
-
expr = {
|
|
5369
|
-
kind: SyntaxKind.ProjectionArithmeticExpression,
|
|
5370
|
-
op,
|
|
5371
|
-
left: expr,
|
|
5372
|
-
right: parseProjectionUnaryExpressionOrHigher(),
|
|
5373
|
-
...finishNode(pos),
|
|
5374
|
-
};
|
|
5375
|
-
}
|
|
5376
|
-
else {
|
|
5377
|
-
break;
|
|
5378
|
-
}
|
|
5379
|
-
}
|
|
5380
|
-
return expr;
|
|
5381
|
-
}
|
|
5382
|
-
function parseProjectionUnaryExpressionOrHigher() {
|
|
5383
|
-
if (token() === Token.Exclamation) {
|
|
5384
|
-
const pos = tokenPos();
|
|
5385
|
-
nextToken();
|
|
5386
|
-
return {
|
|
5387
|
-
kind: SyntaxKind.ProjectionUnaryExpression,
|
|
5388
|
-
op: "!",
|
|
5389
|
-
target: parseProjectionUnaryExpressionOrHigher(),
|
|
5390
|
-
...finishNode(pos),
|
|
5391
|
-
};
|
|
5392
|
-
}
|
|
5393
|
-
return parseProjectionCallExpressionOrHigher();
|
|
5394
|
-
}
|
|
5395
|
-
function parseProjectionCallExpressionOrHigher() {
|
|
5396
|
-
let expr = parseProjectionDecoratorReferenceExpressionOrHigher();
|
|
5397
|
-
while (token() !== Token.EndOfFile) {
|
|
5398
|
-
const pos = expr.pos;
|
|
5399
|
-
expr = parseProjectionMemberExpressionRest(expr, pos);
|
|
5400
|
-
if (token() === Token.OpenParen) {
|
|
5401
|
-
expr = {
|
|
5402
|
-
kind: SyntaxKind.ProjectionCallExpression,
|
|
5403
|
-
callKind: "method",
|
|
5404
|
-
target: expr,
|
|
5405
|
-
arguments: parseList(ListKind.CallArguments, parseProjectionExpression).items,
|
|
5406
|
-
...finishNode(pos),
|
|
5407
|
-
};
|
|
5408
|
-
}
|
|
5409
|
-
else {
|
|
5410
|
-
break;
|
|
5411
|
-
}
|
|
5412
|
-
}
|
|
5413
|
-
return expr;
|
|
5414
|
-
}
|
|
5415
|
-
function parseProjectionDecoratorReferenceExpressionOrHigher() {
|
|
5416
|
-
if (token() === Token.At) {
|
|
5417
|
-
const pos = tokenPos();
|
|
5418
|
-
nextToken();
|
|
5419
|
-
return {
|
|
5420
|
-
kind: SyntaxKind.ProjectionDecoratorReferenceExpression,
|
|
5421
|
-
target: parseIdentifierOrMemberExpression(undefined, true),
|
|
5422
|
-
...finishNode(pos),
|
|
5423
|
-
};
|
|
5424
|
-
}
|
|
5425
|
-
return parseProjectionMemberExpressionOrHigher();
|
|
5426
|
-
}
|
|
5427
|
-
function parseProjectionMemberExpressionOrHigher() {
|
|
5428
|
-
const pos = tokenPos();
|
|
5429
|
-
let expr = parseProjectionPrimaryExpression();
|
|
5430
|
-
expr = parseProjectionMemberExpressionRest(expr, pos);
|
|
5431
|
-
return expr;
|
|
5432
|
-
}
|
|
5433
|
-
function parseProjectionMemberExpressionRest(expr, pos) {
|
|
5434
|
-
while (token() !== Token.EndOfFile) {
|
|
5435
|
-
if (parseOptional(Token.Dot)) {
|
|
5436
|
-
expr = {
|
|
5437
|
-
kind: SyntaxKind.ProjectionMemberExpression,
|
|
5438
|
-
base: expr,
|
|
5439
|
-
id: parseIdentifier(),
|
|
5440
|
-
selector: ".",
|
|
5441
|
-
...finishNode(pos),
|
|
5442
|
-
};
|
|
5443
|
-
}
|
|
5444
|
-
else if (parseOptional(Token.ColonColon)) {
|
|
5445
|
-
expr = {
|
|
5446
|
-
kind: SyntaxKind.ProjectionMemberExpression,
|
|
5447
|
-
base: expr,
|
|
5448
|
-
id: parseIdentifier(),
|
|
5449
|
-
selector: "::",
|
|
5450
|
-
...finishNode(pos),
|
|
5451
|
-
};
|
|
5452
|
-
}
|
|
5453
|
-
else {
|
|
5454
|
-
break;
|
|
5455
|
-
}
|
|
5456
|
-
}
|
|
5457
|
-
return expr;
|
|
5458
|
-
}
|
|
5459
|
-
function parseProjectionPrimaryExpression() {
|
|
5460
|
-
switch (token()) {
|
|
5461
|
-
case Token.IfKeyword:
|
|
5462
|
-
return parseProjectionIfExpression();
|
|
5463
|
-
case Token.NumericLiteral:
|
|
5464
|
-
return parseNumericLiteral();
|
|
5465
|
-
case Token.StringLiteral:
|
|
5466
|
-
return parseStringLiteral();
|
|
5467
|
-
case Token.TrueKeyword:
|
|
5468
|
-
case Token.FalseKeyword:
|
|
5469
|
-
return parseBooleanLiteral();
|
|
5470
|
-
case Token.OpenBracket:
|
|
5471
|
-
return parseProjectionTupleExpression();
|
|
5472
|
-
case Token.OpenBrace:
|
|
5473
|
-
return parseProjectionModelExpression();
|
|
5474
|
-
case Token.OpenParen:
|
|
5475
|
-
return parseProjectionLambdaOrParenthesizedExpression();
|
|
5476
|
-
case Token.VoidKeyword:
|
|
5477
|
-
return parseVoidKeyword();
|
|
5478
|
-
case Token.NeverKeyword:
|
|
5479
|
-
return parseNeverKeyword();
|
|
5480
|
-
case Token.UnknownKeyword:
|
|
5481
|
-
return parseUnknownKeyword();
|
|
5482
|
-
default:
|
|
5483
|
-
return parseIdentifier({ message: "expression" });
|
|
5484
|
-
}
|
|
5485
|
-
}
|
|
5486
|
-
function parseProjectionLambdaOrParenthesizedExpression() {
|
|
5487
|
-
const pos = tokenPos();
|
|
5488
|
-
const exprs = parseList(ListKind.ProjectionExpression, parseProjectionExpression).items;
|
|
5489
|
-
if (token() === Token.EqualsGreaterThan) {
|
|
5490
|
-
// unpack the exprs (which should be just identifiers) into a param list
|
|
5491
|
-
const params = [];
|
|
5492
|
-
for (const expr of exprs) {
|
|
5493
|
-
if (expr.kind === SyntaxKind.Identifier) {
|
|
5494
|
-
params.push(withSymbol({
|
|
5495
|
-
kind: SyntaxKind.ProjectionLambdaParameterDeclaration,
|
|
5496
|
-
id: expr,
|
|
5497
|
-
pos: expr.pos,
|
|
5498
|
-
end: expr.end,
|
|
5499
|
-
flags: 0 /* NodeFlags.None */,
|
|
5500
|
-
}));
|
|
5501
|
-
}
|
|
5502
|
-
else {
|
|
5503
|
-
error({ code: "token-expected", messageId: "identifier", target: expr });
|
|
5504
|
-
}
|
|
5505
|
-
}
|
|
5506
|
-
return parseProjectionLambdaExpressionRest(pos, params);
|
|
5507
|
-
}
|
|
5508
|
-
else {
|
|
5509
|
-
if (exprs.length === 0) {
|
|
5510
|
-
error({
|
|
5511
|
-
code: "token-expected",
|
|
5512
|
-
messageId: "expression",
|
|
5513
|
-
});
|
|
5514
|
-
}
|
|
5515
|
-
// verify we only have one entry
|
|
5516
|
-
for (let i = 1; i < exprs.length; i++) {
|
|
5517
|
-
error({
|
|
5518
|
-
code: "token-expected",
|
|
5519
|
-
messageId: "unexpected",
|
|
5520
|
-
format: { token: "expression" },
|
|
5521
|
-
target: exprs[i],
|
|
5522
|
-
});
|
|
5523
|
-
}
|
|
5524
|
-
return exprs[0];
|
|
5525
|
-
}
|
|
5093
|
+
kind: SyntaxKind.NumericLiteral,
|
|
5094
|
+
value,
|
|
5095
|
+
valueAsString,
|
|
5096
|
+
...finishNode(pos),
|
|
5097
|
+
};
|
|
5526
5098
|
}
|
|
5527
|
-
function
|
|
5528
|
-
|
|
5529
|
-
const
|
|
5099
|
+
function parseBooleanLiteral() {
|
|
5100
|
+
const pos = tokenPos();
|
|
5101
|
+
const token = parseExpectedOneOf(Token.TrueKeyword, Token.FalseKeyword);
|
|
5102
|
+
const value = token === Token.TrueKeyword;
|
|
5530
5103
|
return {
|
|
5531
|
-
kind: SyntaxKind.
|
|
5532
|
-
|
|
5533
|
-
body,
|
|
5104
|
+
kind: SyntaxKind.BooleanLiteral,
|
|
5105
|
+
value,
|
|
5534
5106
|
...finishNode(pos),
|
|
5535
5107
|
};
|
|
5536
5108
|
}
|
|
5537
|
-
function
|
|
5109
|
+
function parseIdentifier(options) {
|
|
5110
|
+
if (isKeyword(token())) {
|
|
5111
|
+
error({ code: "reserved-identifier" });
|
|
5112
|
+
return createMissingIdentifier();
|
|
5113
|
+
}
|
|
5114
|
+
else if (isReservedKeyword(token())) {
|
|
5115
|
+
if (!options?.allowReservedIdentifier) {
|
|
5116
|
+
error({ code: "reserved-identifier", messageId: "future", format: { name: tokenValue() } });
|
|
5117
|
+
}
|
|
5118
|
+
}
|
|
5119
|
+
else if (token() !== Token.Identifier &&
|
|
5120
|
+
(!options?.allowStringLiteral || token() !== Token.StringLiteral)) {
|
|
5121
|
+
// Error recovery: when we fail to parse an identifier or expression,
|
|
5122
|
+
// we insert a synthesized identifier with a unique name.
|
|
5123
|
+
error({ code: "token-expected", messageId: options?.message ?? "identifier" });
|
|
5124
|
+
return createMissingIdentifier();
|
|
5125
|
+
}
|
|
5538
5126
|
const pos = tokenPos();
|
|
5539
|
-
const
|
|
5127
|
+
const sv = tokenValue();
|
|
5128
|
+
nextToken();
|
|
5540
5129
|
return {
|
|
5541
|
-
kind: SyntaxKind.
|
|
5542
|
-
|
|
5130
|
+
kind: SyntaxKind.Identifier,
|
|
5131
|
+
sv,
|
|
5543
5132
|
...finishNode(pos),
|
|
5544
5133
|
};
|
|
5545
5134
|
}
|
|
5546
|
-
function
|
|
5547
|
-
|
|
5548
|
-
|
|
5549
|
-
:
|
|
5135
|
+
function parseDeclaration(pos) {
|
|
5136
|
+
const modifiers = parseModifiers();
|
|
5137
|
+
switch (token()) {
|
|
5138
|
+
case Token.DecKeyword:
|
|
5139
|
+
return parseDecoratorDeclarationStatement(pos, modifiers);
|
|
5140
|
+
case Token.FnKeyword:
|
|
5141
|
+
return parseFunctionDeclarationStatement(pos, modifiers);
|
|
5142
|
+
}
|
|
5143
|
+
return parseInvalidStatement(pos, []);
|
|
5550
5144
|
}
|
|
5551
|
-
function
|
|
5552
|
-
|
|
5553
|
-
|
|
5554
|
-
|
|
5145
|
+
function parseModifiers() {
|
|
5146
|
+
const modifiers = [];
|
|
5147
|
+
let modifier;
|
|
5148
|
+
while ((modifier = parseModifier())) {
|
|
5149
|
+
modifiers.push(modifier);
|
|
5150
|
+
}
|
|
5151
|
+
return modifiers;
|
|
5152
|
+
}
|
|
5153
|
+
function parseModifier() {
|
|
5154
|
+
switch (token()) {
|
|
5155
|
+
case Token.ExternKeyword:
|
|
5156
|
+
return parseExternKeyword();
|
|
5157
|
+
default:
|
|
5158
|
+
return undefined;
|
|
5159
|
+
}
|
|
5160
|
+
}
|
|
5161
|
+
function parseDecoratorDeclarationStatement(pos, modifiers) {
|
|
5162
|
+
const modifierFlags = modifiersToFlags(modifiers);
|
|
5163
|
+
parseExpected(Token.DecKeyword);
|
|
5164
|
+
const id = parseIdentifier();
|
|
5165
|
+
const allParamListDetail = parseFunctionParameters();
|
|
5166
|
+
let [target, ...parameters] = allParamListDetail.items;
|
|
5167
|
+
if (target === undefined) {
|
|
5168
|
+
error({ code: "decorator-decl-target", target: { pos, end: previousTokenEnd } });
|
|
5169
|
+
target = {
|
|
5170
|
+
kind: SyntaxKind.FunctionParameter,
|
|
5171
|
+
id: createMissingIdentifier(),
|
|
5172
|
+
type: createMissingTypeReference(),
|
|
5173
|
+
optional: false,
|
|
5174
|
+
rest: false,
|
|
5175
|
+
...finishNode(pos),
|
|
5176
|
+
};
|
|
5177
|
+
}
|
|
5178
|
+
if (target.optional) {
|
|
5179
|
+
error({ code: "decorator-decl-target", messageId: "required" });
|
|
5180
|
+
}
|
|
5181
|
+
parseExpected(Token.Semicolon);
|
|
5555
5182
|
return {
|
|
5556
|
-
kind: SyntaxKind.
|
|
5183
|
+
kind: SyntaxKind.DecoratorDeclarationStatement,
|
|
5184
|
+
modifiers,
|
|
5185
|
+
modifierFlags,
|
|
5186
|
+
id,
|
|
5557
5187
|
target,
|
|
5188
|
+
parameters,
|
|
5558
5189
|
...finishNode(pos),
|
|
5559
5190
|
};
|
|
5560
5191
|
}
|
|
5561
|
-
function
|
|
5562
|
-
const
|
|
5563
|
-
|
|
5564
|
-
|
|
5565
|
-
const
|
|
5566
|
-
|
|
5567
|
-
|
|
5192
|
+
function parseFunctionDeclarationStatement(pos, modifiers) {
|
|
5193
|
+
const modifierFlags = modifiersToFlags(modifiers);
|
|
5194
|
+
parseExpected(Token.FnKeyword);
|
|
5195
|
+
const id = parseIdentifier();
|
|
5196
|
+
const { items: parameters } = parseFunctionParameters();
|
|
5197
|
+
let returnType;
|
|
5198
|
+
if (parseOptional(Token.Colon)) {
|
|
5199
|
+
returnType = parseExpression();
|
|
5200
|
+
}
|
|
5201
|
+
parseExpected(Token.Semicolon);
|
|
5568
5202
|
return {
|
|
5569
|
-
kind: SyntaxKind.
|
|
5203
|
+
kind: SyntaxKind.FunctionDeclarationStatement,
|
|
5204
|
+
modifiers,
|
|
5205
|
+
modifierFlags,
|
|
5570
5206
|
id,
|
|
5571
|
-
|
|
5572
|
-
|
|
5573
|
-
optional,
|
|
5574
|
-
default: defaultValue,
|
|
5207
|
+
parameters,
|
|
5208
|
+
returnType,
|
|
5575
5209
|
...finishNode(pos),
|
|
5576
5210
|
};
|
|
5577
5211
|
}
|
|
5578
|
-
function
|
|
5579
|
-
const
|
|
5580
|
-
|
|
5581
|
-
const
|
|
5582
|
-
|
|
5583
|
-
|
|
5584
|
-
|
|
5585
|
-
if (token() === Token.IfKeyword) {
|
|
5586
|
-
alternate = parseProjectionIfExpression();
|
|
5212
|
+
function parseFunctionParameters() {
|
|
5213
|
+
const parameters = parseList(ListKind.FunctionParameters, parseFunctionParameter);
|
|
5214
|
+
let foundOptional = false;
|
|
5215
|
+
for (const [index, item] of parameters.items.entries()) {
|
|
5216
|
+
if (!item.optional && foundOptional) {
|
|
5217
|
+
error({ code: "required-parameter-first", target: item });
|
|
5218
|
+
continue;
|
|
5587
5219
|
}
|
|
5588
|
-
|
|
5589
|
-
|
|
5220
|
+
if (item.optional) {
|
|
5221
|
+
foundOptional = true;
|
|
5222
|
+
}
|
|
5223
|
+
if (item.rest && item.optional) {
|
|
5224
|
+
error({ code: "rest-parameter-required", target: item });
|
|
5225
|
+
}
|
|
5226
|
+
if (item.rest && index !== parameters.items.length - 1) {
|
|
5227
|
+
error({ code: "rest-parameter-last", target: item });
|
|
5590
5228
|
}
|
|
5591
5229
|
}
|
|
5592
|
-
return
|
|
5593
|
-
kind: SyntaxKind.ProjectionIfExpression,
|
|
5594
|
-
test,
|
|
5595
|
-
consequent,
|
|
5596
|
-
alternate,
|
|
5597
|
-
...finishNode(pos),
|
|
5598
|
-
};
|
|
5599
|
-
}
|
|
5600
|
-
function parseProjectionBlockExpression() {
|
|
5601
|
-
const pos = tokenPos();
|
|
5602
|
-
parseExpected(Token.OpenBrace);
|
|
5603
|
-
const statements = parseProjectionStatementList();
|
|
5604
|
-
parseExpected(Token.CloseBrace);
|
|
5605
|
-
return {
|
|
5606
|
-
kind: SyntaxKind.ProjectionBlockExpression,
|
|
5607
|
-
statements,
|
|
5608
|
-
...finishNode(pos),
|
|
5609
|
-
};
|
|
5230
|
+
return parameters;
|
|
5610
5231
|
}
|
|
5611
|
-
function
|
|
5232
|
+
function parseFunctionParameter() {
|
|
5612
5233
|
const pos = tokenPos();
|
|
5613
|
-
const
|
|
5234
|
+
const rest = parseOptional(Token.Ellipsis);
|
|
5235
|
+
const id = parseIdentifier({ message: "property" });
|
|
5236
|
+
const optional = parseOptional(Token.Question);
|
|
5237
|
+
let type;
|
|
5238
|
+
if (parseOptional(Token.Colon)) {
|
|
5239
|
+
type = parseMixedParameterConstraint();
|
|
5240
|
+
}
|
|
5614
5241
|
return {
|
|
5615
|
-
kind: SyntaxKind.
|
|
5616
|
-
|
|
5242
|
+
kind: SyntaxKind.FunctionParameter,
|
|
5243
|
+
id,
|
|
5244
|
+
type,
|
|
5245
|
+
optional,
|
|
5246
|
+
rest,
|
|
5617
5247
|
...finishNode(pos),
|
|
5618
5248
|
};
|
|
5619
5249
|
}
|
|
5620
|
-
function
|
|
5621
|
-
|
|
5622
|
-
|
|
5623
|
-
|
|
5624
|
-
|
|
5625
|
-
|
|
5626
|
-
|
|
5627
|
-
|
|
5628
|
-
case "modelproperty":
|
|
5629
|
-
return {
|
|
5630
|
-
kind: SyntaxKind.ProjectionModelPropertySelector,
|
|
5631
|
-
...finishNode(pos),
|
|
5632
|
-
};
|
|
5633
|
-
case "unionvariant":
|
|
5634
|
-
return {
|
|
5635
|
-
kind: SyntaxKind.ProjectionUnionVariantSelector,
|
|
5636
|
-
...finishNode(pos),
|
|
5637
|
-
};
|
|
5638
|
-
case "enummember":
|
|
5639
|
-
return {
|
|
5640
|
-
kind: SyntaxKind.ProjectionEnumMemberSelector,
|
|
5641
|
-
...finishNode(pos),
|
|
5642
|
-
};
|
|
5643
|
-
}
|
|
5644
|
-
}
|
|
5645
|
-
return id;
|
|
5646
|
-
case Token.ModelKeyword:
|
|
5647
|
-
nextToken();
|
|
5648
|
-
return {
|
|
5649
|
-
kind: SyntaxKind.ProjectionModelSelector,
|
|
5650
|
-
...finishNode(pos),
|
|
5651
|
-
};
|
|
5652
|
-
case Token.OpKeyword:
|
|
5653
|
-
nextToken();
|
|
5654
|
-
return {
|
|
5655
|
-
kind: SyntaxKind.ProjectionOperationSelector,
|
|
5656
|
-
...finishNode(pos),
|
|
5657
|
-
};
|
|
5658
|
-
case Token.InterfaceKeyword:
|
|
5659
|
-
nextToken();
|
|
5660
|
-
return {
|
|
5661
|
-
kind: SyntaxKind.ProjectionInterfaceSelector,
|
|
5662
|
-
...finishNode(pos),
|
|
5663
|
-
};
|
|
5664
|
-
case Token.UnionKeyword:
|
|
5665
|
-
nextToken();
|
|
5666
|
-
return {
|
|
5667
|
-
kind: SyntaxKind.ProjectionUnionSelector,
|
|
5668
|
-
...finishNode(pos),
|
|
5669
|
-
};
|
|
5670
|
-
case Token.EnumKeyword:
|
|
5671
|
-
nextToken();
|
|
5672
|
-
return {
|
|
5673
|
-
kind: SyntaxKind.ProjectionEnumSelector,
|
|
5674
|
-
...finishNode(pos),
|
|
5675
|
-
};
|
|
5676
|
-
case Token.ScalarKeyword:
|
|
5677
|
-
nextToken();
|
|
5678
|
-
return {
|
|
5679
|
-
kind: SyntaxKind.ProjectionScalarSelector,
|
|
5680
|
-
...finishNode(pos),
|
|
5681
|
-
};
|
|
5682
|
-
default:
|
|
5683
|
-
// recovery: return a missing identifier to use as the selector
|
|
5684
|
-
// we don't need to emit a diagnostic here as the `expectTokenOneOf` above
|
|
5685
|
-
// will have done so.
|
|
5686
|
-
return createMissingIdentifier();
|
|
5250
|
+
function modifiersToFlags(modifiers) {
|
|
5251
|
+
let flags = 0 /* ModifierFlags.None */;
|
|
5252
|
+
for (const modifier of modifiers) {
|
|
5253
|
+
switch (modifier.kind) {
|
|
5254
|
+
case SyntaxKind.ExternKeyword:
|
|
5255
|
+
flags |= 2 /* ModifierFlags.Extern */;
|
|
5256
|
+
break;
|
|
5257
|
+
}
|
|
5687
5258
|
}
|
|
5259
|
+
return flags;
|
|
5688
5260
|
}
|
|
5689
5261
|
function parseRange(mode, range, callback) {
|
|
5690
5262
|
const savedMode = currentMode;
|
|
@@ -6428,58 +6000,12 @@ function visitChildren(node, cb) {
|
|
|
6428
6000
|
return visitEach(cb, node.values);
|
|
6429
6001
|
case SyntaxKind.UnionExpression:
|
|
6430
6002
|
return visitEach(cb, node.options);
|
|
6431
|
-
case SyntaxKind.Projection:
|
|
6432
|
-
return (visitNode(cb, node.directionId) ||
|
|
6433
|
-
visitEach(cb, node.modifierIds) ||
|
|
6434
|
-
visitEach(cb, node.parameters) ||
|
|
6435
|
-
visitEach(cb, node.body));
|
|
6436
|
-
case SyntaxKind.ProjectionExpressionStatement:
|
|
6437
|
-
return visitNode(cb, node.expr);
|
|
6438
|
-
case SyntaxKind.ProjectionCallExpression:
|
|
6439
|
-
return visitNode(cb, node.target) || visitEach(cb, node.arguments);
|
|
6440
|
-
case SyntaxKind.ProjectionMemberExpression:
|
|
6441
|
-
return visitNode(cb, node.base) || visitNode(cb, node.id);
|
|
6442
|
-
// binops
|
|
6443
|
-
case SyntaxKind.ProjectionLogicalExpression:
|
|
6444
|
-
case SyntaxKind.ProjectionRelationalExpression:
|
|
6445
|
-
case SyntaxKind.ProjectionArithmeticExpression:
|
|
6446
|
-
case SyntaxKind.ProjectionEqualityExpression:
|
|
6447
|
-
return visitNode(cb, node.left) || visitNode(cb, node.right);
|
|
6448
|
-
case SyntaxKind.ProjectionUnaryExpression:
|
|
6449
|
-
return visitNode(cb, node.target);
|
|
6450
|
-
case SyntaxKind.ProjectionModelExpression:
|
|
6451
|
-
return visitEach(cb, node.properties);
|
|
6452
|
-
case SyntaxKind.ProjectionModelProperty:
|
|
6453
|
-
return (visitEach(cb, node.decorators) ||
|
|
6454
|
-
visitNode(cb, node.id) ||
|
|
6455
|
-
visitNode(cb, node.value) ||
|
|
6456
|
-
visitNode(cb, node.default));
|
|
6457
|
-
case SyntaxKind.ProjectionModelSpreadProperty:
|
|
6458
|
-
return visitNode(cb, node.target);
|
|
6459
|
-
case SyntaxKind.ProjectionTupleExpression:
|
|
6460
|
-
return visitEach(cb, node.values);
|
|
6461
|
-
case SyntaxKind.ProjectionBlockExpression:
|
|
6462
|
-
return visitEach(cb, node.statements);
|
|
6463
|
-
case SyntaxKind.ProjectionIfExpression:
|
|
6464
|
-
return (visitNode(cb, node.test) || visitNode(cb, node.consequent) || visitNode(cb, node.alternate));
|
|
6465
|
-
case SyntaxKind.ProjectionLambdaExpression:
|
|
6466
|
-
return visitEach(cb, node.parameters) || visitNode(cb, node.body);
|
|
6467
|
-
case SyntaxKind.ProjectionStatement:
|
|
6468
|
-
return (visitNode(cb, node.id) || visitNode(cb, node.selector) || visitEach(cb, node.projections));
|
|
6469
|
-
case SyntaxKind.ProjectionDecoratorReferenceExpression:
|
|
6470
|
-
return visitNode(cb, node.target);
|
|
6471
|
-
case SyntaxKind.Return:
|
|
6472
|
-
return visitNode(cb, node.value);
|
|
6473
6003
|
case SyntaxKind.InvalidStatement:
|
|
6474
6004
|
return visitEach(cb, node.decorators);
|
|
6475
6005
|
case SyntaxKind.TemplateParameterDeclaration:
|
|
6476
6006
|
return (visitNode(cb, node.id) || visitNode(cb, node.constraint) || visitNode(cb, node.default));
|
|
6477
6007
|
case SyntaxKind.TemplateArgument:
|
|
6478
6008
|
return (node.name && visitNode(cb, node.name)) || visitNode(cb, node.argument);
|
|
6479
|
-
case SyntaxKind.ProjectionLambdaParameterDeclaration:
|
|
6480
|
-
return visitNode(cb, node.id);
|
|
6481
|
-
case SyntaxKind.ProjectionParameterDeclaration:
|
|
6482
|
-
return visitNode(cb, node.id);
|
|
6483
6009
|
case SyntaxKind.Doc:
|
|
6484
6010
|
return visitEach(cb, node.content) || visitEach(cb, node.tags);
|
|
6485
6011
|
case SyntaxKind.DocParamTag:
|
|
@@ -6512,15 +6038,6 @@ function visitChildren(node, cb) {
|
|
|
6512
6038
|
case SyntaxKind.BooleanLiteral:
|
|
6513
6039
|
case SyntaxKind.Identifier:
|
|
6514
6040
|
case SyntaxKind.EmptyStatement:
|
|
6515
|
-
case SyntaxKind.ProjectionModelSelector:
|
|
6516
|
-
case SyntaxKind.ProjectionModelPropertySelector:
|
|
6517
|
-
case SyntaxKind.ProjectionScalarSelector:
|
|
6518
|
-
case SyntaxKind.ProjectionUnionSelector:
|
|
6519
|
-
case SyntaxKind.ProjectionUnionVariantSelector:
|
|
6520
|
-
case SyntaxKind.ProjectionInterfaceSelector:
|
|
6521
|
-
case SyntaxKind.ProjectionOperationSelector:
|
|
6522
|
-
case SyntaxKind.ProjectionEnumSelector:
|
|
6523
|
-
case SyntaxKind.ProjectionEnumMemberSelector:
|
|
6524
6041
|
case SyntaxKind.VoidKeyword:
|
|
6525
6042
|
case SyntaxKind.NeverKeyword:
|
|
6526
6043
|
case SyntaxKind.ExternKeyword:
|
|
@@ -7868,6 +7385,7 @@ function addCommentBetweenAnnotationsAndNode({ comment }) {
|
|
|
7868
7385
|
enclosingNode.kind === SyntaxKind.InterfaceStatement ||
|
|
7869
7386
|
enclosingNode.kind === SyntaxKind.ModelProperty ||
|
|
7870
7387
|
enclosingNode.kind === SyntaxKind.EnumMember ||
|
|
7388
|
+
enclosingNode.kind === SyntaxKind.UnionVariant ||
|
|
7871
7389
|
enclosingNode.kind === SyntaxKind.UnionStatement)) {
|
|
7872
7390
|
util.addTrailingComment(precedingNode, comment);
|
|
7873
7391
|
return true;
|
|
@@ -7964,10 +7482,6 @@ function needsParens(path, options) {
|
|
|
7964
7482
|
case SyntaxKind.UnionExpression:
|
|
7965
7483
|
return (parent.kind === SyntaxKind.IntersectionExpression ||
|
|
7966
7484
|
parent.kind === SyntaxKind.ArrayExpression);
|
|
7967
|
-
case SyntaxKind.ProjectionLogicalExpression:
|
|
7968
|
-
return parent.kind === SyntaxKind.ProjectionLogicalExpression;
|
|
7969
|
-
case SyntaxKind.ProjectionArithmeticExpression:
|
|
7970
|
-
return parent.kind === SyntaxKind.ProjectionArithmeticExpression;
|
|
7971
7485
|
default:
|
|
7972
7486
|
return false;
|
|
7973
7487
|
}
|
|
@@ -8107,63 +7621,6 @@ path, options, print) {
|
|
|
8107
7621
|
return "never";
|
|
8108
7622
|
case SyntaxKind.UnknownKeyword:
|
|
8109
7623
|
return "unknown";
|
|
8110
|
-
case SyntaxKind.ProjectionStatement:
|
|
8111
|
-
return printProjectionStatement(path, options, print);
|
|
8112
|
-
case SyntaxKind.ProjectionModelSelector:
|
|
8113
|
-
return "model";
|
|
8114
|
-
case SyntaxKind.ProjectionModelPropertySelector:
|
|
8115
|
-
return "modelproperty";
|
|
8116
|
-
case SyntaxKind.ProjectionScalarSelector:
|
|
8117
|
-
return "scalar";
|
|
8118
|
-
case SyntaxKind.ProjectionOperationSelector:
|
|
8119
|
-
return "op";
|
|
8120
|
-
case SyntaxKind.ProjectionUnionSelector:
|
|
8121
|
-
return "union";
|
|
8122
|
-
case SyntaxKind.ProjectionUnionVariantSelector:
|
|
8123
|
-
return "unionvariant";
|
|
8124
|
-
case SyntaxKind.ProjectionInterfaceSelector:
|
|
8125
|
-
return "interface";
|
|
8126
|
-
case SyntaxKind.ProjectionEnumSelector:
|
|
8127
|
-
return "enum";
|
|
8128
|
-
case SyntaxKind.ProjectionEnumMemberSelector:
|
|
8129
|
-
return "enummember";
|
|
8130
|
-
case SyntaxKind.Projection:
|
|
8131
|
-
return printProjection(path, options, print);
|
|
8132
|
-
case SyntaxKind.ProjectionParameterDeclaration:
|
|
8133
|
-
return printProjectionParameterDeclaration(path, options, print);
|
|
8134
|
-
case SyntaxKind.ProjectionExpressionStatement:
|
|
8135
|
-
return printProjectionExpressionStatement(path, options, print);
|
|
8136
|
-
case SyntaxKind.ProjectionIfExpression:
|
|
8137
|
-
return printProjectionIfExpressionNode(path, options, print);
|
|
8138
|
-
case SyntaxKind.ProjectionBlockExpression:
|
|
8139
|
-
return printProjectionBlockExpressionNode(path, options, print);
|
|
8140
|
-
case SyntaxKind.ProjectionMemberExpression:
|
|
8141
|
-
return printProjectionMemberExpression(path, options, print);
|
|
8142
|
-
case SyntaxKind.ProjectionLogicalExpression:
|
|
8143
|
-
case SyntaxKind.ProjectionEqualityExpression:
|
|
8144
|
-
case SyntaxKind.ProjectionRelationalExpression:
|
|
8145
|
-
case SyntaxKind.ProjectionArithmeticExpression:
|
|
8146
|
-
return printProjectionLeftRightExpression(path, options, print);
|
|
8147
|
-
case SyntaxKind.ProjectionUnaryExpression:
|
|
8148
|
-
return printProjectionUnaryExpression(path, options, print);
|
|
8149
|
-
case SyntaxKind.ProjectionCallExpression:
|
|
8150
|
-
return printProjectionCallExpression(path, options, print);
|
|
8151
|
-
case SyntaxKind.ProjectionLambdaExpression:
|
|
8152
|
-
return printProjectionLambdaExpression(path, options, print);
|
|
8153
|
-
case SyntaxKind.ProjectionLambdaParameterDeclaration:
|
|
8154
|
-
return printProjectionLambdaParameterDeclaration(path, options, print);
|
|
8155
|
-
case SyntaxKind.ProjectionModelExpression:
|
|
8156
|
-
return printModelExpression(path, options, print);
|
|
8157
|
-
case SyntaxKind.ProjectionModelProperty:
|
|
8158
|
-
return printModelProperty(path, options, print);
|
|
8159
|
-
case SyntaxKind.ProjectionModelSpreadProperty:
|
|
8160
|
-
return printModelSpread(path, options, print);
|
|
8161
|
-
case SyntaxKind.ProjectionTupleExpression:
|
|
8162
|
-
return printTuple(path, options, print);
|
|
8163
|
-
case SyntaxKind.ProjectionDecoratorReferenceExpression:
|
|
8164
|
-
return path.call(print, "target");
|
|
8165
|
-
case SyntaxKind.Return:
|
|
8166
|
-
return printReturnExpression(path, options, print);
|
|
8167
7624
|
case SyntaxKind.Doc:
|
|
8168
7625
|
return printDoc(path, options);
|
|
8169
7626
|
case SyntaxKind.DocText:
|
|
@@ -8329,7 +7786,11 @@ function hasNewlineBetweenOrAfterDecorators(node, options) {
|
|
|
8329
7786
|
}
|
|
8330
7787
|
function printDecorator(path, options, print) {
|
|
8331
7788
|
const args = printDecoratorArgs(path, options, print);
|
|
8332
|
-
|
|
7789
|
+
const node = path.node;
|
|
7790
|
+
const name = node.target.kind === SyntaxKind.Identifier
|
|
7791
|
+
? printIdentifier(node.target, "allow-reserved")
|
|
7792
|
+
: path.call(print, "target");
|
|
7793
|
+
return ["@", name, args];
|
|
8333
7794
|
}
|
|
8334
7795
|
function printAugmentDecorator(path, options, print) {
|
|
8335
7796
|
const args = printAugmentDecoratorArgs(path, options, print);
|
|
@@ -8425,7 +7886,7 @@ function printEnumBlock(path, options, print) {
|
|
|
8425
7886
|
}
|
|
8426
7887
|
function printEnumMember(path, options, print) {
|
|
8427
7888
|
const node = path.node;
|
|
8428
|
-
const id =
|
|
7889
|
+
const id = printIdentifier(node.id, "allow-reserved");
|
|
8429
7890
|
const value = node.value ? [": ", path.call(print, "value")] : "";
|
|
8430
7891
|
const { decorators } = printDecorators(path, options, print, {
|
|
8431
7892
|
tryInline: DecoratorsTryInline.enumMember,
|
|
@@ -8450,7 +7911,7 @@ function printUnionVariantsBlock(path, options, print) {
|
|
|
8450
7911
|
return group(["{", indent(body), hardline, "}"]);
|
|
8451
7912
|
}
|
|
8452
7913
|
function printUnionVariant(path, options, print) {
|
|
8453
|
-
const id = path.node.id === undefined ? "" : [path.
|
|
7914
|
+
const id = path.node.id === undefined ? "" : [printIdentifier(path.node.id, "allow-reserved"), ": "];
|
|
8454
7915
|
const { decorators } = printDecorators(path, options, print, {
|
|
8455
7916
|
tryInline: DecoratorsTryInline.unionVariant,
|
|
8456
7917
|
});
|
|
@@ -8576,7 +8037,8 @@ function printTuple(path, options, print) {
|
|
|
8576
8037
|
}
|
|
8577
8038
|
function printMemberExpression(path, options, print) {
|
|
8578
8039
|
const node = path.node;
|
|
8579
|
-
|
|
8040
|
+
const id = printIdentifier(node.id, "allow-reserved");
|
|
8041
|
+
return [node.base ? [path.call(print, "base"), node.selector] : "", id];
|
|
8580
8042
|
}
|
|
8581
8043
|
function printModelExpression(path, options, print) {
|
|
8582
8044
|
const inBlock = isModelExpressionInBlock(path);
|
|
@@ -8609,7 +8071,7 @@ function printObjectLiteral(path, options, print) {
|
|
|
8609
8071
|
}
|
|
8610
8072
|
function printObjectLiteralProperty(path, options, print) {
|
|
8611
8073
|
const node = path.node;
|
|
8612
|
-
const id = printIdentifier(node.id);
|
|
8074
|
+
const id = printIdentifier(node.id, "allow-reserved");
|
|
8613
8075
|
return [printDirectives(path, options, print), id, ": ", path.call(print, "value")];
|
|
8614
8076
|
}
|
|
8615
8077
|
function printObjectLiteralSpreadProperty(path, options, print) {
|
|
@@ -8703,7 +8165,6 @@ function joinMembersInBlock(path, member, options, print, separator, regularLine
|
|
|
8703
8165
|
function shouldWrapMemberInNewLines(path, options) {
|
|
8704
8166
|
const node = path.node;
|
|
8705
8167
|
return ((node.kind !== SyntaxKind.ModelSpreadProperty &&
|
|
8706
|
-
node.kind !== SyntaxKind.ProjectionModelSpreadProperty &&
|
|
8707
8168
|
node.kind !== SyntaxKind.EnumSpreadMember &&
|
|
8708
8169
|
node.kind !== SyntaxKind.ScalarConstructor &&
|
|
8709
8170
|
node.kind !== SyntaxKind.ObjectLiteralProperty &&
|
|
@@ -8738,7 +8199,7 @@ function printModelProperty(path, options, print) {
|
|
|
8738
8199
|
const { decorators } = printDecorators(path, options, print, {
|
|
8739
8200
|
tryInline: DecoratorsTryInline.modelProperty,
|
|
8740
8201
|
});
|
|
8741
|
-
const id = printIdentifier(node.id);
|
|
8202
|
+
const id = printIdentifier(node.id, "allow-reserved");
|
|
8742
8203
|
return [
|
|
8743
8204
|
printDirectives(path, options, print),
|
|
8744
8205
|
decorators,
|
|
@@ -8748,8 +8209,8 @@ function printModelProperty(path, options, print) {
|
|
|
8748
8209
|
node.default ? [" = ", path.call(print, "default")] : "",
|
|
8749
8210
|
];
|
|
8750
8211
|
}
|
|
8751
|
-
function printIdentifier(id,
|
|
8752
|
-
return printIdentifier$1(id.sv);
|
|
8212
|
+
function printIdentifier(id, context = "disallow-reserved") {
|
|
8213
|
+
return printIdentifier$1(id.sv, context);
|
|
8753
8214
|
}
|
|
8754
8215
|
function isModelExpressionInBlock(path) {
|
|
8755
8216
|
const parent = path.getParentNode();
|
|
@@ -8993,132 +8454,6 @@ function printBooleanLiteral(path, options) {
|
|
|
8993
8454
|
const node = path.node;
|
|
8994
8455
|
return node.value ? "true" : "false";
|
|
8995
8456
|
}
|
|
8996
|
-
function printProjectionStatement(path, options, print) {
|
|
8997
|
-
const selector = path.call(print, "selector");
|
|
8998
|
-
const id = path.call(print, "id");
|
|
8999
|
-
const projections = path.map(print, "projections").flatMap((x) => [hardline, x]);
|
|
9000
|
-
return [
|
|
9001
|
-
"projection ",
|
|
9002
|
-
selector,
|
|
9003
|
-
"#",
|
|
9004
|
-
id,
|
|
9005
|
-
" {",
|
|
9006
|
-
indent(projections),
|
|
9007
|
-
projections.length > 0 ? hardline : "",
|
|
9008
|
-
"}",
|
|
9009
|
-
];
|
|
9010
|
-
}
|
|
9011
|
-
function printProjection(path, options, print) {
|
|
9012
|
-
const node = path.node;
|
|
9013
|
-
const params = printProjectionParameters(path, options, print);
|
|
9014
|
-
const body = printProjectionExpressionStatements(path, options, print, "body");
|
|
9015
|
-
return [
|
|
9016
|
-
...node.modifierIds.flatMap((i) => [i.sv, " "]),
|
|
9017
|
-
node.directionId.sv,
|
|
9018
|
-
params,
|
|
9019
|
-
" {",
|
|
9020
|
-
indent(body),
|
|
9021
|
-
hardline,
|
|
9022
|
-
"}",
|
|
9023
|
-
];
|
|
9024
|
-
}
|
|
9025
|
-
function printProjectionParameters(path, options, print) {
|
|
9026
|
-
const node = path.node;
|
|
9027
|
-
const params = node.parameters;
|
|
9028
|
-
if (params.length === 0) {
|
|
9029
|
-
return "";
|
|
9030
|
-
}
|
|
9031
|
-
const shouldHug = params.length === 1;
|
|
9032
|
-
if (shouldHug) {
|
|
9033
|
-
return ["(", printItemList(path, options, print, "parameters"), ")"];
|
|
9034
|
-
}
|
|
9035
|
-
else {
|
|
9036
|
-
const body = indent([softline, join([", ", softline], path.map(print, "parameters"))]);
|
|
9037
|
-
return group(["(", body, softline, ")"]);
|
|
9038
|
-
}
|
|
9039
|
-
}
|
|
9040
|
-
function printProjectionExpressionStatements(path, options, print, key) {
|
|
9041
|
-
const parts = [hardline];
|
|
9042
|
-
const lastIndex = path.node[key].length - 1;
|
|
9043
|
-
path.each((statementPath, index) => {
|
|
9044
|
-
const node = path.node;
|
|
9045
|
-
if (node.kind === SyntaxKind.EmptyStatement) {
|
|
9046
|
-
return;
|
|
9047
|
-
}
|
|
9048
|
-
const printed = print(statementPath);
|
|
9049
|
-
parts.push(printed);
|
|
9050
|
-
parts.push(";");
|
|
9051
|
-
if (index < lastIndex) {
|
|
9052
|
-
parts.push(hardline);
|
|
9053
|
-
if (isNextLineEmpty(options.originalText, node, options.locEnd)) {
|
|
9054
|
-
parts.push(hardline);
|
|
9055
|
-
}
|
|
9056
|
-
}
|
|
9057
|
-
}, key);
|
|
9058
|
-
return parts;
|
|
9059
|
-
}
|
|
9060
|
-
function printProjectionParameterDeclaration(path, options, print) {
|
|
9061
|
-
return path.call(print, "id");
|
|
9062
|
-
}
|
|
9063
|
-
function printProjectionExpressionStatement(path, options, print) {
|
|
9064
|
-
return path.call(print, "expr");
|
|
9065
|
-
}
|
|
9066
|
-
function printProjectionIfExpressionNode(path, options, print) {
|
|
9067
|
-
const node = path.node;
|
|
9068
|
-
const test = path.call(print, "test");
|
|
9069
|
-
const consequent = path.call(print, "consequent");
|
|
9070
|
-
const alternate = node.alternate ? [" else ", path.call(print, "alternate")] : "";
|
|
9071
|
-
return ["if ", test, " ", consequent, alternate];
|
|
9072
|
-
}
|
|
9073
|
-
function printProjectionBlockExpressionNode(path, options, print) {
|
|
9074
|
-
const node = path.node;
|
|
9075
|
-
if (node.statements.length === 0) {
|
|
9076
|
-
return "{}";
|
|
9077
|
-
}
|
|
9078
|
-
return [
|
|
9079
|
-
"{",
|
|
9080
|
-
indent(printProjectionExpressionStatements(path, options, print, "statements")),
|
|
9081
|
-
hardline,
|
|
9082
|
-
"}",
|
|
9083
|
-
];
|
|
9084
|
-
}
|
|
9085
|
-
function printProjectionMemberExpression(path, options, print) {
|
|
9086
|
-
const node = path.node;
|
|
9087
|
-
return [path.call(print, "base"), node.selector, path.call(print, "id")];
|
|
9088
|
-
}
|
|
9089
|
-
function printProjectionLeftRightExpression(path, options, print) {
|
|
9090
|
-
const node = path.node;
|
|
9091
|
-
return [path.call(print, "left"), " ", node.op, " ", path.call(print, "right")];
|
|
9092
|
-
}
|
|
9093
|
-
function printProjectionUnaryExpression(path, options, print) {
|
|
9094
|
-
return ["!", path.call(print, "target")];
|
|
9095
|
-
}
|
|
9096
|
-
function printProjectionCallExpression(path, options, print) {
|
|
9097
|
-
const node = path.node;
|
|
9098
|
-
const target = path.call(print, "target");
|
|
9099
|
-
const params = printItemList(path, options, print, "arguments");
|
|
9100
|
-
if (node.callKind === "method") {
|
|
9101
|
-
return [target, "(", params, ")"];
|
|
9102
|
-
}
|
|
9103
|
-
else {
|
|
9104
|
-
return [target, "<", params, ">"];
|
|
9105
|
-
}
|
|
9106
|
-
}
|
|
9107
|
-
function printProjectionLambdaExpression(path, options, print) {
|
|
9108
|
-
return [
|
|
9109
|
-
"(",
|
|
9110
|
-
printItemList(path, options, print, "parameters"),
|
|
9111
|
-
")",
|
|
9112
|
-
" => ",
|
|
9113
|
-
path.call(print, "body"),
|
|
9114
|
-
];
|
|
9115
|
-
}
|
|
9116
|
-
function printProjectionLambdaParameterDeclaration(path, options, print) {
|
|
9117
|
-
return path.call(print, "id");
|
|
9118
|
-
}
|
|
9119
|
-
function printReturnExpression(path, options, print) {
|
|
9120
|
-
return ["return ", path.call(print, "value")];
|
|
9121
|
-
}
|
|
9122
8457
|
function printStringTemplateExpression(path, options, print) {
|
|
9123
8458
|
const node = path.node;
|
|
9124
8459
|
const multiline = isMultiline(node, options);
|
|
@@ -9164,9 +8499,6 @@ function trimMultilineString(lines, whitespaceIndent) {
|
|
|
9164
8499
|
}
|
|
9165
8500
|
return newLines;
|
|
9166
8501
|
}
|
|
9167
|
-
function printItemList(path, options, print, key) {
|
|
9168
|
-
return join(", ", path.map(print, key));
|
|
9169
|
-
}
|
|
9170
8502
|
/**
|
|
9171
8503
|
* @param node Node that has postition information.
|
|
9172
8504
|
* @param options Prettier options
|
|
@@ -9246,7 +8578,7 @@ const printers = {
|
|
|
9246
8578
|
"typespec-format": typespecPrinter,
|
|
9247
8579
|
};
|
|
9248
8580
|
|
|
9249
|
-
var
|
|
8581
|
+
var TypeSpecPrettierPlugin = /*#__PURE__*/Object.freeze({
|
|
9250
8582
|
__proto__: null,
|
|
9251
8583
|
defaultOptions: defaultOptions,
|
|
9252
8584
|
languages: languages,
|
|
@@ -9254,8 +8586,6 @@ var formatter = /*#__PURE__*/Object.freeze({
|
|
|
9254
8586
|
printers: printers
|
|
9255
8587
|
});
|
|
9256
8588
|
|
|
9257
|
-
const TypeSpecPrettierPlugin = formatter;
|
|
9258
|
-
|
|
9259
8589
|
/**
|
|
9260
8590
|
* Reexport the bare minimum for rollup to do the tree shaking.
|
|
9261
8591
|
*/
|