@typespec/prettier-plugin-typespec 0.54.0-dev.2 → 0.54.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +237 -225
- package/dist/index.js.map +1 -1
- package/package.json +4 -5
package/dist/index.js
CHANGED
|
@@ -1,5 +1,229 @@
|
|
|
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 !== null && lineStarts !== void 0 ? 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
|
+
/**
|
|
80
|
+
* AST types
|
|
81
|
+
*/
|
|
82
|
+
var SyntaxKind;
|
|
83
|
+
(function (SyntaxKind) {
|
|
84
|
+
SyntaxKind[SyntaxKind["TypeSpecScript"] = 0] = "TypeSpecScript";
|
|
85
|
+
/** @deprecated Use TypeSpecScript */
|
|
86
|
+
SyntaxKind[SyntaxKind["CadlScript"] = 0] = "CadlScript";
|
|
87
|
+
SyntaxKind[SyntaxKind["JsSourceFile"] = 1] = "JsSourceFile";
|
|
88
|
+
SyntaxKind[SyntaxKind["ImportStatement"] = 2] = "ImportStatement";
|
|
89
|
+
SyntaxKind[SyntaxKind["Identifier"] = 3] = "Identifier";
|
|
90
|
+
SyntaxKind[SyntaxKind["AugmentDecoratorStatement"] = 4] = "AugmentDecoratorStatement";
|
|
91
|
+
SyntaxKind[SyntaxKind["DecoratorExpression"] = 5] = "DecoratorExpression";
|
|
92
|
+
SyntaxKind[SyntaxKind["DirectiveExpression"] = 6] = "DirectiveExpression";
|
|
93
|
+
SyntaxKind[SyntaxKind["MemberExpression"] = 7] = "MemberExpression";
|
|
94
|
+
SyntaxKind[SyntaxKind["NamespaceStatement"] = 8] = "NamespaceStatement";
|
|
95
|
+
SyntaxKind[SyntaxKind["UsingStatement"] = 9] = "UsingStatement";
|
|
96
|
+
SyntaxKind[SyntaxKind["OperationStatement"] = 10] = "OperationStatement";
|
|
97
|
+
SyntaxKind[SyntaxKind["OperationSignatureDeclaration"] = 11] = "OperationSignatureDeclaration";
|
|
98
|
+
SyntaxKind[SyntaxKind["OperationSignatureReference"] = 12] = "OperationSignatureReference";
|
|
99
|
+
SyntaxKind[SyntaxKind["ModelStatement"] = 13] = "ModelStatement";
|
|
100
|
+
SyntaxKind[SyntaxKind["ModelExpression"] = 14] = "ModelExpression";
|
|
101
|
+
SyntaxKind[SyntaxKind["ModelProperty"] = 15] = "ModelProperty";
|
|
102
|
+
SyntaxKind[SyntaxKind["ModelSpreadProperty"] = 16] = "ModelSpreadProperty";
|
|
103
|
+
SyntaxKind[SyntaxKind["ScalarStatement"] = 17] = "ScalarStatement";
|
|
104
|
+
SyntaxKind[SyntaxKind["InterfaceStatement"] = 18] = "InterfaceStatement";
|
|
105
|
+
SyntaxKind[SyntaxKind["UnionStatement"] = 19] = "UnionStatement";
|
|
106
|
+
SyntaxKind[SyntaxKind["UnionVariant"] = 20] = "UnionVariant";
|
|
107
|
+
SyntaxKind[SyntaxKind["EnumStatement"] = 21] = "EnumStatement";
|
|
108
|
+
SyntaxKind[SyntaxKind["EnumMember"] = 22] = "EnumMember";
|
|
109
|
+
SyntaxKind[SyntaxKind["EnumSpreadMember"] = 23] = "EnumSpreadMember";
|
|
110
|
+
SyntaxKind[SyntaxKind["AliasStatement"] = 24] = "AliasStatement";
|
|
111
|
+
SyntaxKind[SyntaxKind["DecoratorDeclarationStatement"] = 25] = "DecoratorDeclarationStatement";
|
|
112
|
+
SyntaxKind[SyntaxKind["FunctionDeclarationStatement"] = 26] = "FunctionDeclarationStatement";
|
|
113
|
+
SyntaxKind[SyntaxKind["FunctionParameter"] = 27] = "FunctionParameter";
|
|
114
|
+
SyntaxKind[SyntaxKind["UnionExpression"] = 28] = "UnionExpression";
|
|
115
|
+
SyntaxKind[SyntaxKind["IntersectionExpression"] = 29] = "IntersectionExpression";
|
|
116
|
+
SyntaxKind[SyntaxKind["TupleExpression"] = 30] = "TupleExpression";
|
|
117
|
+
SyntaxKind[SyntaxKind["ArrayExpression"] = 31] = "ArrayExpression";
|
|
118
|
+
SyntaxKind[SyntaxKind["StringLiteral"] = 32] = "StringLiteral";
|
|
119
|
+
SyntaxKind[SyntaxKind["NumericLiteral"] = 33] = "NumericLiteral";
|
|
120
|
+
SyntaxKind[SyntaxKind["BooleanLiteral"] = 34] = "BooleanLiteral";
|
|
121
|
+
SyntaxKind[SyntaxKind["StringTemplateExpression"] = 35] = "StringTemplateExpression";
|
|
122
|
+
SyntaxKind[SyntaxKind["StringTemplateHead"] = 36] = "StringTemplateHead";
|
|
123
|
+
SyntaxKind[SyntaxKind["StringTemplateMiddle"] = 37] = "StringTemplateMiddle";
|
|
124
|
+
SyntaxKind[SyntaxKind["StringTemplateTail"] = 38] = "StringTemplateTail";
|
|
125
|
+
SyntaxKind[SyntaxKind["StringTemplateSpan"] = 39] = "StringTemplateSpan";
|
|
126
|
+
SyntaxKind[SyntaxKind["ExternKeyword"] = 40] = "ExternKeyword";
|
|
127
|
+
SyntaxKind[SyntaxKind["VoidKeyword"] = 41] = "VoidKeyword";
|
|
128
|
+
SyntaxKind[SyntaxKind["NeverKeyword"] = 42] = "NeverKeyword";
|
|
129
|
+
SyntaxKind[SyntaxKind["UnknownKeyword"] = 43] = "UnknownKeyword";
|
|
130
|
+
SyntaxKind[SyntaxKind["ValueOfExpression"] = 44] = "ValueOfExpression";
|
|
131
|
+
SyntaxKind[SyntaxKind["TypeReference"] = 45] = "TypeReference";
|
|
132
|
+
SyntaxKind[SyntaxKind["ProjectionReference"] = 46] = "ProjectionReference";
|
|
133
|
+
SyntaxKind[SyntaxKind["TemplateParameterDeclaration"] = 47] = "TemplateParameterDeclaration";
|
|
134
|
+
SyntaxKind[SyntaxKind["EmptyStatement"] = 48] = "EmptyStatement";
|
|
135
|
+
SyntaxKind[SyntaxKind["InvalidStatement"] = 49] = "InvalidStatement";
|
|
136
|
+
SyntaxKind[SyntaxKind["LineComment"] = 50] = "LineComment";
|
|
137
|
+
SyntaxKind[SyntaxKind["BlockComment"] = 51] = "BlockComment";
|
|
138
|
+
SyntaxKind[SyntaxKind["Doc"] = 52] = "Doc";
|
|
139
|
+
SyntaxKind[SyntaxKind["DocText"] = 53] = "DocText";
|
|
140
|
+
SyntaxKind[SyntaxKind["DocParamTag"] = 54] = "DocParamTag";
|
|
141
|
+
SyntaxKind[SyntaxKind["DocReturnsTag"] = 55] = "DocReturnsTag";
|
|
142
|
+
SyntaxKind[SyntaxKind["DocErrorsTag"] = 56] = "DocErrorsTag";
|
|
143
|
+
SyntaxKind[SyntaxKind["DocTemplateTag"] = 57] = "DocTemplateTag";
|
|
144
|
+
SyntaxKind[SyntaxKind["DocUnknownTag"] = 58] = "DocUnknownTag";
|
|
145
|
+
SyntaxKind[SyntaxKind["Projection"] = 59] = "Projection";
|
|
146
|
+
SyntaxKind[SyntaxKind["ProjectionParameterDeclaration"] = 60] = "ProjectionParameterDeclaration";
|
|
147
|
+
SyntaxKind[SyntaxKind["ProjectionModelSelector"] = 61] = "ProjectionModelSelector";
|
|
148
|
+
SyntaxKind[SyntaxKind["ProjectionModelPropertySelector"] = 62] = "ProjectionModelPropertySelector";
|
|
149
|
+
SyntaxKind[SyntaxKind["ProjectionOperationSelector"] = 63] = "ProjectionOperationSelector";
|
|
150
|
+
SyntaxKind[SyntaxKind["ProjectionUnionSelector"] = 64] = "ProjectionUnionSelector";
|
|
151
|
+
SyntaxKind[SyntaxKind["ProjectionUnionVariantSelector"] = 65] = "ProjectionUnionVariantSelector";
|
|
152
|
+
SyntaxKind[SyntaxKind["ProjectionInterfaceSelector"] = 66] = "ProjectionInterfaceSelector";
|
|
153
|
+
SyntaxKind[SyntaxKind["ProjectionEnumSelector"] = 67] = "ProjectionEnumSelector";
|
|
154
|
+
SyntaxKind[SyntaxKind["ProjectionEnumMemberSelector"] = 68] = "ProjectionEnumMemberSelector";
|
|
155
|
+
SyntaxKind[SyntaxKind["ProjectionExpressionStatement"] = 69] = "ProjectionExpressionStatement";
|
|
156
|
+
SyntaxKind[SyntaxKind["ProjectionIfExpression"] = 70] = "ProjectionIfExpression";
|
|
157
|
+
SyntaxKind[SyntaxKind["ProjectionBlockExpression"] = 71] = "ProjectionBlockExpression";
|
|
158
|
+
SyntaxKind[SyntaxKind["ProjectionMemberExpression"] = 72] = "ProjectionMemberExpression";
|
|
159
|
+
SyntaxKind[SyntaxKind["ProjectionLogicalExpression"] = 73] = "ProjectionLogicalExpression";
|
|
160
|
+
SyntaxKind[SyntaxKind["ProjectionEqualityExpression"] = 74] = "ProjectionEqualityExpression";
|
|
161
|
+
SyntaxKind[SyntaxKind["ProjectionUnaryExpression"] = 75] = "ProjectionUnaryExpression";
|
|
162
|
+
SyntaxKind[SyntaxKind["ProjectionRelationalExpression"] = 76] = "ProjectionRelationalExpression";
|
|
163
|
+
SyntaxKind[SyntaxKind["ProjectionArithmeticExpression"] = 77] = "ProjectionArithmeticExpression";
|
|
164
|
+
SyntaxKind[SyntaxKind["ProjectionCallExpression"] = 78] = "ProjectionCallExpression";
|
|
165
|
+
SyntaxKind[SyntaxKind["ProjectionLambdaExpression"] = 79] = "ProjectionLambdaExpression";
|
|
166
|
+
SyntaxKind[SyntaxKind["ProjectionLambdaParameterDeclaration"] = 80] = "ProjectionLambdaParameterDeclaration";
|
|
167
|
+
SyntaxKind[SyntaxKind["ProjectionModelExpression"] = 81] = "ProjectionModelExpression";
|
|
168
|
+
SyntaxKind[SyntaxKind["ProjectionModelProperty"] = 82] = "ProjectionModelProperty";
|
|
169
|
+
SyntaxKind[SyntaxKind["ProjectionModelSpreadProperty"] = 83] = "ProjectionModelSpreadProperty";
|
|
170
|
+
SyntaxKind[SyntaxKind["ProjectionSpreadProperty"] = 84] = "ProjectionSpreadProperty";
|
|
171
|
+
SyntaxKind[SyntaxKind["ProjectionTupleExpression"] = 85] = "ProjectionTupleExpression";
|
|
172
|
+
SyntaxKind[SyntaxKind["ProjectionStatement"] = 86] = "ProjectionStatement";
|
|
173
|
+
SyntaxKind[SyntaxKind["ProjectionDecoratorReferenceExpression"] = 87] = "ProjectionDecoratorReferenceExpression";
|
|
174
|
+
SyntaxKind[SyntaxKind["Return"] = 88] = "Return";
|
|
175
|
+
SyntaxKind[SyntaxKind["JsNamespaceDeclaration"] = 89] = "JsNamespaceDeclaration";
|
|
176
|
+
SyntaxKind[SyntaxKind["TemplateArgument"] = 90] = "TemplateArgument";
|
|
177
|
+
})(SyntaxKind || (SyntaxKind = {}));
|
|
178
|
+
var IdentifierKind;
|
|
179
|
+
(function (IdentifierKind) {
|
|
180
|
+
IdentifierKind[IdentifierKind["TypeReference"] = 0] = "TypeReference";
|
|
181
|
+
IdentifierKind[IdentifierKind["TemplateArgument"] = 1] = "TemplateArgument";
|
|
182
|
+
IdentifierKind[IdentifierKind["Decorator"] = 2] = "Decorator";
|
|
183
|
+
IdentifierKind[IdentifierKind["Function"] = 3] = "Function";
|
|
184
|
+
IdentifierKind[IdentifierKind["Using"] = 4] = "Using";
|
|
185
|
+
IdentifierKind[IdentifierKind["Declaration"] = 5] = "Declaration";
|
|
186
|
+
IdentifierKind[IdentifierKind["Other"] = 6] = "Other";
|
|
187
|
+
})(IdentifierKind || (IdentifierKind = {}));
|
|
188
|
+
/** Used to explicitly specify that a diagnostic has no target. */
|
|
189
|
+
const NoTarget = Symbol.for("NoTarget");
|
|
190
|
+
var ListenerFlow;
|
|
191
|
+
(function (ListenerFlow) {
|
|
192
|
+
/**
|
|
193
|
+
* Do not navigate any containing or referenced type.
|
|
194
|
+
*/
|
|
195
|
+
ListenerFlow[ListenerFlow["NoRecursion"] = 1] = "NoRecursion";
|
|
196
|
+
})(ListenerFlow || (ListenerFlow = {}));
|
|
197
|
+
|
|
198
|
+
(this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
199
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
200
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
201
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
202
|
+
};
|
|
203
|
+
(this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
204
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
205
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
206
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
207
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
208
|
+
};
|
|
209
|
+
/**
|
|
210
|
+
* A specially typed version of `Array.isArray` to work around [this issue](https://github.com/microsoft/TypeScript/issues/17002).
|
|
211
|
+
*/
|
|
212
|
+
function isArray(
|
|
213
|
+
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
214
|
+
arg) {
|
|
215
|
+
return Array.isArray(arg);
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* Casts away readonly typing.
|
|
219
|
+
*
|
|
220
|
+
* Use it like this when it is safe to override readonly typing:
|
|
221
|
+
* mutate(item).prop = value;
|
|
222
|
+
*/
|
|
223
|
+
function mutate(value) {
|
|
224
|
+
return value;
|
|
225
|
+
}
|
|
226
|
+
|
|
3
227
|
/**
|
|
4
228
|
* Create a new diagnostics creator.
|
|
5
229
|
* @param diagnostics Map of the potential diagnostics.
|
|
@@ -30,12 +254,16 @@ function createDiagnosticCreator(diagnostics, libraryName) {
|
|
|
30
254
|
throw new Error(`Unexpected message id '${messageId}'. ${errorMessage} for code '${code}'. Defined codes:\n${codeStr}`);
|
|
31
255
|
}
|
|
32
256
|
const messageStr = typeof message === "string" ? message : message(diagnostic.format);
|
|
33
|
-
|
|
257
|
+
const result = {
|
|
34
258
|
code: libraryName ? `${libraryName}/${String(diagnostic.code)}` : diagnostic.code.toString(),
|
|
35
259
|
severity: diagnosticDef.severity,
|
|
36
260
|
message: messageStr,
|
|
37
261
|
target: diagnostic.target,
|
|
38
262
|
};
|
|
263
|
+
if (diagnostic.codefixes) {
|
|
264
|
+
mutate(result).codefixes = diagnostic.codefixes;
|
|
265
|
+
}
|
|
266
|
+
return result;
|
|
39
267
|
}
|
|
40
268
|
function reportDiagnostic(program, diagnostic) {
|
|
41
269
|
const diag = createDiagnostic(diagnostic);
|
|
@@ -346,6 +574,12 @@ const diagnostics = {
|
|
|
346
574
|
array: "Cannot intersect an array model.",
|
|
347
575
|
},
|
|
348
576
|
},
|
|
577
|
+
"incompatible-indexer": {
|
|
578
|
+
severity: "error",
|
|
579
|
+
messages: {
|
|
580
|
+
default: paramMessage `Property is incompatible with indexer:\n${"message"}`,
|
|
581
|
+
},
|
|
582
|
+
},
|
|
349
583
|
"no-array-properties": {
|
|
350
584
|
severity: "error",
|
|
351
585
|
messages: {
|
|
@@ -944,201 +1178,6 @@ const diagnostics = {
|
|
|
944
1178
|
};
|
|
945
1179
|
const { createDiagnostic, reportDiagnostic } = createDiagnosticCreator(diagnostics);
|
|
946
1180
|
|
|
947
|
-
function createSourceFile(text, path) {
|
|
948
|
-
let lineStarts = undefined;
|
|
949
|
-
return {
|
|
950
|
-
text,
|
|
951
|
-
path,
|
|
952
|
-
getLineStarts,
|
|
953
|
-
getLineAndCharacterOfPosition,
|
|
954
|
-
};
|
|
955
|
-
function getLineStarts() {
|
|
956
|
-
return (lineStarts = lineStarts !== null && lineStarts !== void 0 ? lineStarts : scanLineStarts(text));
|
|
957
|
-
}
|
|
958
|
-
function getLineAndCharacterOfPosition(position) {
|
|
959
|
-
const starts = getLineStarts();
|
|
960
|
-
let line = binarySearch(starts, position);
|
|
961
|
-
// When binarySearch returns < 0 indicating that the value was not found, it
|
|
962
|
-
// returns the bitwise complement of the index where the value would need to
|
|
963
|
-
// be inserted to keep the array sorted. So flipping the bits back to this
|
|
964
|
-
// positive index tells us what the line number would be if we were to
|
|
965
|
-
// create a new line starting at the given position, and subtracting 1 from
|
|
966
|
-
// that therefore gives us the line number we're after.
|
|
967
|
-
if (line < 0) {
|
|
968
|
-
line = ~line - 1;
|
|
969
|
-
}
|
|
970
|
-
return {
|
|
971
|
-
line,
|
|
972
|
-
character: position - starts[line],
|
|
973
|
-
};
|
|
974
|
-
}
|
|
975
|
-
}
|
|
976
|
-
function scanLineStarts(text) {
|
|
977
|
-
const starts = [];
|
|
978
|
-
let start = 0;
|
|
979
|
-
let pos = 0;
|
|
980
|
-
while (pos < text.length) {
|
|
981
|
-
const ch = text.charCodeAt(pos);
|
|
982
|
-
pos++;
|
|
983
|
-
switch (ch) {
|
|
984
|
-
case 13 /* CharCode.CarriageReturn */:
|
|
985
|
-
if (text.charCodeAt(pos) === 10 /* CharCode.LineFeed */) {
|
|
986
|
-
pos++;
|
|
987
|
-
}
|
|
988
|
-
// fallthrough
|
|
989
|
-
case 10 /* CharCode.LineFeed */:
|
|
990
|
-
starts.push(start);
|
|
991
|
-
start = pos;
|
|
992
|
-
break;
|
|
993
|
-
}
|
|
994
|
-
}
|
|
995
|
-
starts.push(start);
|
|
996
|
-
return starts;
|
|
997
|
-
}
|
|
998
|
-
/**
|
|
999
|
-
* Search sorted array of numbers for the given value. If found, return index
|
|
1000
|
-
* in array where value was found. If not found, return a negative number that
|
|
1001
|
-
* is the bitwise complement of the index where value would need to be inserted
|
|
1002
|
-
* to keep the array sorted.
|
|
1003
|
-
*/
|
|
1004
|
-
function binarySearch(array, value) {
|
|
1005
|
-
let low = 0;
|
|
1006
|
-
let high = array.length - 1;
|
|
1007
|
-
while (low <= high) {
|
|
1008
|
-
const middle = low + ((high - low) >> 1);
|
|
1009
|
-
const v = array[middle];
|
|
1010
|
-
if (v < value) {
|
|
1011
|
-
low = middle + 1;
|
|
1012
|
-
}
|
|
1013
|
-
else if (v > value) {
|
|
1014
|
-
high = middle - 1;
|
|
1015
|
-
}
|
|
1016
|
-
else {
|
|
1017
|
-
return middle;
|
|
1018
|
-
}
|
|
1019
|
-
}
|
|
1020
|
-
return ~low;
|
|
1021
|
-
}
|
|
1022
|
-
|
|
1023
|
-
/**
|
|
1024
|
-
* AST types
|
|
1025
|
-
*/
|
|
1026
|
-
var SyntaxKind;
|
|
1027
|
-
(function (SyntaxKind) {
|
|
1028
|
-
SyntaxKind[SyntaxKind["TypeSpecScript"] = 0] = "TypeSpecScript";
|
|
1029
|
-
/** @deprecated Use TypeSpecScript */
|
|
1030
|
-
SyntaxKind[SyntaxKind["CadlScript"] = 0] = "CadlScript";
|
|
1031
|
-
SyntaxKind[SyntaxKind["JsSourceFile"] = 1] = "JsSourceFile";
|
|
1032
|
-
SyntaxKind[SyntaxKind["ImportStatement"] = 2] = "ImportStatement";
|
|
1033
|
-
SyntaxKind[SyntaxKind["Identifier"] = 3] = "Identifier";
|
|
1034
|
-
SyntaxKind[SyntaxKind["AugmentDecoratorStatement"] = 4] = "AugmentDecoratorStatement";
|
|
1035
|
-
SyntaxKind[SyntaxKind["DecoratorExpression"] = 5] = "DecoratorExpression";
|
|
1036
|
-
SyntaxKind[SyntaxKind["DirectiveExpression"] = 6] = "DirectiveExpression";
|
|
1037
|
-
SyntaxKind[SyntaxKind["MemberExpression"] = 7] = "MemberExpression";
|
|
1038
|
-
SyntaxKind[SyntaxKind["NamespaceStatement"] = 8] = "NamespaceStatement";
|
|
1039
|
-
SyntaxKind[SyntaxKind["UsingStatement"] = 9] = "UsingStatement";
|
|
1040
|
-
SyntaxKind[SyntaxKind["OperationStatement"] = 10] = "OperationStatement";
|
|
1041
|
-
SyntaxKind[SyntaxKind["OperationSignatureDeclaration"] = 11] = "OperationSignatureDeclaration";
|
|
1042
|
-
SyntaxKind[SyntaxKind["OperationSignatureReference"] = 12] = "OperationSignatureReference";
|
|
1043
|
-
SyntaxKind[SyntaxKind["ModelStatement"] = 13] = "ModelStatement";
|
|
1044
|
-
SyntaxKind[SyntaxKind["ModelExpression"] = 14] = "ModelExpression";
|
|
1045
|
-
SyntaxKind[SyntaxKind["ModelProperty"] = 15] = "ModelProperty";
|
|
1046
|
-
SyntaxKind[SyntaxKind["ModelSpreadProperty"] = 16] = "ModelSpreadProperty";
|
|
1047
|
-
SyntaxKind[SyntaxKind["ScalarStatement"] = 17] = "ScalarStatement";
|
|
1048
|
-
SyntaxKind[SyntaxKind["InterfaceStatement"] = 18] = "InterfaceStatement";
|
|
1049
|
-
SyntaxKind[SyntaxKind["UnionStatement"] = 19] = "UnionStatement";
|
|
1050
|
-
SyntaxKind[SyntaxKind["UnionVariant"] = 20] = "UnionVariant";
|
|
1051
|
-
SyntaxKind[SyntaxKind["EnumStatement"] = 21] = "EnumStatement";
|
|
1052
|
-
SyntaxKind[SyntaxKind["EnumMember"] = 22] = "EnumMember";
|
|
1053
|
-
SyntaxKind[SyntaxKind["EnumSpreadMember"] = 23] = "EnumSpreadMember";
|
|
1054
|
-
SyntaxKind[SyntaxKind["AliasStatement"] = 24] = "AliasStatement";
|
|
1055
|
-
SyntaxKind[SyntaxKind["DecoratorDeclarationStatement"] = 25] = "DecoratorDeclarationStatement";
|
|
1056
|
-
SyntaxKind[SyntaxKind["FunctionDeclarationStatement"] = 26] = "FunctionDeclarationStatement";
|
|
1057
|
-
SyntaxKind[SyntaxKind["FunctionParameter"] = 27] = "FunctionParameter";
|
|
1058
|
-
SyntaxKind[SyntaxKind["UnionExpression"] = 28] = "UnionExpression";
|
|
1059
|
-
SyntaxKind[SyntaxKind["IntersectionExpression"] = 29] = "IntersectionExpression";
|
|
1060
|
-
SyntaxKind[SyntaxKind["TupleExpression"] = 30] = "TupleExpression";
|
|
1061
|
-
SyntaxKind[SyntaxKind["ArrayExpression"] = 31] = "ArrayExpression";
|
|
1062
|
-
SyntaxKind[SyntaxKind["StringLiteral"] = 32] = "StringLiteral";
|
|
1063
|
-
SyntaxKind[SyntaxKind["NumericLiteral"] = 33] = "NumericLiteral";
|
|
1064
|
-
SyntaxKind[SyntaxKind["BooleanLiteral"] = 34] = "BooleanLiteral";
|
|
1065
|
-
SyntaxKind[SyntaxKind["StringTemplateExpression"] = 35] = "StringTemplateExpression";
|
|
1066
|
-
SyntaxKind[SyntaxKind["StringTemplateHead"] = 36] = "StringTemplateHead";
|
|
1067
|
-
SyntaxKind[SyntaxKind["StringTemplateMiddle"] = 37] = "StringTemplateMiddle";
|
|
1068
|
-
SyntaxKind[SyntaxKind["StringTemplateTail"] = 38] = "StringTemplateTail";
|
|
1069
|
-
SyntaxKind[SyntaxKind["StringTemplateSpan"] = 39] = "StringTemplateSpan";
|
|
1070
|
-
SyntaxKind[SyntaxKind["ExternKeyword"] = 40] = "ExternKeyword";
|
|
1071
|
-
SyntaxKind[SyntaxKind["VoidKeyword"] = 41] = "VoidKeyword";
|
|
1072
|
-
SyntaxKind[SyntaxKind["NeverKeyword"] = 42] = "NeverKeyword";
|
|
1073
|
-
SyntaxKind[SyntaxKind["UnknownKeyword"] = 43] = "UnknownKeyword";
|
|
1074
|
-
SyntaxKind[SyntaxKind["ValueOfExpression"] = 44] = "ValueOfExpression";
|
|
1075
|
-
SyntaxKind[SyntaxKind["TypeReference"] = 45] = "TypeReference";
|
|
1076
|
-
SyntaxKind[SyntaxKind["ProjectionReference"] = 46] = "ProjectionReference";
|
|
1077
|
-
SyntaxKind[SyntaxKind["TemplateParameterDeclaration"] = 47] = "TemplateParameterDeclaration";
|
|
1078
|
-
SyntaxKind[SyntaxKind["EmptyStatement"] = 48] = "EmptyStatement";
|
|
1079
|
-
SyntaxKind[SyntaxKind["InvalidStatement"] = 49] = "InvalidStatement";
|
|
1080
|
-
SyntaxKind[SyntaxKind["LineComment"] = 50] = "LineComment";
|
|
1081
|
-
SyntaxKind[SyntaxKind["BlockComment"] = 51] = "BlockComment";
|
|
1082
|
-
SyntaxKind[SyntaxKind["Doc"] = 52] = "Doc";
|
|
1083
|
-
SyntaxKind[SyntaxKind["DocText"] = 53] = "DocText";
|
|
1084
|
-
SyntaxKind[SyntaxKind["DocParamTag"] = 54] = "DocParamTag";
|
|
1085
|
-
SyntaxKind[SyntaxKind["DocReturnsTag"] = 55] = "DocReturnsTag";
|
|
1086
|
-
SyntaxKind[SyntaxKind["DocErrorsTag"] = 56] = "DocErrorsTag";
|
|
1087
|
-
SyntaxKind[SyntaxKind["DocTemplateTag"] = 57] = "DocTemplateTag";
|
|
1088
|
-
SyntaxKind[SyntaxKind["DocUnknownTag"] = 58] = "DocUnknownTag";
|
|
1089
|
-
SyntaxKind[SyntaxKind["Projection"] = 59] = "Projection";
|
|
1090
|
-
SyntaxKind[SyntaxKind["ProjectionParameterDeclaration"] = 60] = "ProjectionParameterDeclaration";
|
|
1091
|
-
SyntaxKind[SyntaxKind["ProjectionModelSelector"] = 61] = "ProjectionModelSelector";
|
|
1092
|
-
SyntaxKind[SyntaxKind["ProjectionModelPropertySelector"] = 62] = "ProjectionModelPropertySelector";
|
|
1093
|
-
SyntaxKind[SyntaxKind["ProjectionOperationSelector"] = 63] = "ProjectionOperationSelector";
|
|
1094
|
-
SyntaxKind[SyntaxKind["ProjectionUnionSelector"] = 64] = "ProjectionUnionSelector";
|
|
1095
|
-
SyntaxKind[SyntaxKind["ProjectionUnionVariantSelector"] = 65] = "ProjectionUnionVariantSelector";
|
|
1096
|
-
SyntaxKind[SyntaxKind["ProjectionInterfaceSelector"] = 66] = "ProjectionInterfaceSelector";
|
|
1097
|
-
SyntaxKind[SyntaxKind["ProjectionEnumSelector"] = 67] = "ProjectionEnumSelector";
|
|
1098
|
-
SyntaxKind[SyntaxKind["ProjectionEnumMemberSelector"] = 68] = "ProjectionEnumMemberSelector";
|
|
1099
|
-
SyntaxKind[SyntaxKind["ProjectionExpressionStatement"] = 69] = "ProjectionExpressionStatement";
|
|
1100
|
-
SyntaxKind[SyntaxKind["ProjectionIfExpression"] = 70] = "ProjectionIfExpression";
|
|
1101
|
-
SyntaxKind[SyntaxKind["ProjectionBlockExpression"] = 71] = "ProjectionBlockExpression";
|
|
1102
|
-
SyntaxKind[SyntaxKind["ProjectionMemberExpression"] = 72] = "ProjectionMemberExpression";
|
|
1103
|
-
SyntaxKind[SyntaxKind["ProjectionLogicalExpression"] = 73] = "ProjectionLogicalExpression";
|
|
1104
|
-
SyntaxKind[SyntaxKind["ProjectionEqualityExpression"] = 74] = "ProjectionEqualityExpression";
|
|
1105
|
-
SyntaxKind[SyntaxKind["ProjectionUnaryExpression"] = 75] = "ProjectionUnaryExpression";
|
|
1106
|
-
SyntaxKind[SyntaxKind["ProjectionRelationalExpression"] = 76] = "ProjectionRelationalExpression";
|
|
1107
|
-
SyntaxKind[SyntaxKind["ProjectionArithmeticExpression"] = 77] = "ProjectionArithmeticExpression";
|
|
1108
|
-
SyntaxKind[SyntaxKind["ProjectionCallExpression"] = 78] = "ProjectionCallExpression";
|
|
1109
|
-
SyntaxKind[SyntaxKind["ProjectionLambdaExpression"] = 79] = "ProjectionLambdaExpression";
|
|
1110
|
-
SyntaxKind[SyntaxKind["ProjectionLambdaParameterDeclaration"] = 80] = "ProjectionLambdaParameterDeclaration";
|
|
1111
|
-
SyntaxKind[SyntaxKind["ProjectionModelExpression"] = 81] = "ProjectionModelExpression";
|
|
1112
|
-
SyntaxKind[SyntaxKind["ProjectionModelProperty"] = 82] = "ProjectionModelProperty";
|
|
1113
|
-
SyntaxKind[SyntaxKind["ProjectionModelSpreadProperty"] = 83] = "ProjectionModelSpreadProperty";
|
|
1114
|
-
SyntaxKind[SyntaxKind["ProjectionSpreadProperty"] = 84] = "ProjectionSpreadProperty";
|
|
1115
|
-
SyntaxKind[SyntaxKind["ProjectionTupleExpression"] = 85] = "ProjectionTupleExpression";
|
|
1116
|
-
SyntaxKind[SyntaxKind["ProjectionStatement"] = 86] = "ProjectionStatement";
|
|
1117
|
-
SyntaxKind[SyntaxKind["ProjectionDecoratorReferenceExpression"] = 87] = "ProjectionDecoratorReferenceExpression";
|
|
1118
|
-
SyntaxKind[SyntaxKind["Return"] = 88] = "Return";
|
|
1119
|
-
SyntaxKind[SyntaxKind["JsNamespaceDeclaration"] = 89] = "JsNamespaceDeclaration";
|
|
1120
|
-
SyntaxKind[SyntaxKind["TemplateArgument"] = 90] = "TemplateArgument";
|
|
1121
|
-
})(SyntaxKind || (SyntaxKind = {}));
|
|
1122
|
-
var IdentifierKind;
|
|
1123
|
-
(function (IdentifierKind) {
|
|
1124
|
-
IdentifierKind[IdentifierKind["TypeReference"] = 0] = "TypeReference";
|
|
1125
|
-
IdentifierKind[IdentifierKind["TemplateArgument"] = 1] = "TemplateArgument";
|
|
1126
|
-
IdentifierKind[IdentifierKind["Decorator"] = 2] = "Decorator";
|
|
1127
|
-
IdentifierKind[IdentifierKind["Function"] = 3] = "Function";
|
|
1128
|
-
IdentifierKind[IdentifierKind["Using"] = 4] = "Using";
|
|
1129
|
-
IdentifierKind[IdentifierKind["Declaration"] = 5] = "Declaration";
|
|
1130
|
-
IdentifierKind[IdentifierKind["Other"] = 6] = "Other";
|
|
1131
|
-
})(IdentifierKind || (IdentifierKind = {}));
|
|
1132
|
-
/** Used to explicitly specify that a diagnostic has no target. */
|
|
1133
|
-
const NoTarget = Symbol.for("NoTarget");
|
|
1134
|
-
var ListenerFlow;
|
|
1135
|
-
(function (ListenerFlow) {
|
|
1136
|
-
/**
|
|
1137
|
-
* Do not navigate any containing or referenced type.
|
|
1138
|
-
*/
|
|
1139
|
-
ListenerFlow[ListenerFlow["NoRecursion"] = 1] = "NoRecursion";
|
|
1140
|
-
})(ListenerFlow || (ListenerFlow = {}));
|
|
1141
|
-
|
|
1142
1181
|
function getSourceLocation(target, options = {}) {
|
|
1143
1182
|
if (target === NoTarget || target === undefined) {
|
|
1144
1183
|
return undefined;
|
|
@@ -1228,35 +1267,6 @@ function compilerAssert(condition, message, target) {
|
|
|
1228
1267
|
throw new Error(message);
|
|
1229
1268
|
}
|
|
1230
1269
|
|
|
1231
|
-
(this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
1232
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
1233
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
1234
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
1235
|
-
};
|
|
1236
|
-
(this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
1237
|
-
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
1238
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
1239
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
1240
|
-
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
1241
|
-
};
|
|
1242
|
-
/**
|
|
1243
|
-
* A specially typed version of `Array.isArray` to work around [this issue](https://github.com/microsoft/TypeScript/issues/17002).
|
|
1244
|
-
*/
|
|
1245
|
-
function isArray(
|
|
1246
|
-
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
1247
|
-
arg) {
|
|
1248
|
-
return Array.isArray(arg);
|
|
1249
|
-
}
|
|
1250
|
-
/**
|
|
1251
|
-
* Casts away readonly typing.
|
|
1252
|
-
*
|
|
1253
|
-
* Use it like this when it is safe to override readonly typing:
|
|
1254
|
-
* mutate(item).prop = value;
|
|
1255
|
-
*/
|
|
1256
|
-
function mutate(value) {
|
|
1257
|
-
return value;
|
|
1258
|
-
}
|
|
1259
|
-
|
|
1260
1270
|
var __defProp = Object.defineProperty;
|
|
1261
1271
|
var __export = (target, all) => {
|
|
1262
1272
|
for (var name in all)
|
|
@@ -4457,6 +4467,8 @@ const commentHandler = {
|
|
|
4457
4467
|
addCommentBetweenAnnotationsAndNode,
|
|
4458
4468
|
handleOnlyComments,
|
|
4459
4469
|
].some((x) => x({ comment, text, options, ast: ast, isLastComment })),
|
|
4470
|
+
remaining: (comment, text, options, ast, isLastComment) => [handleOnlyComments].some((x) => x({ comment, text, options, ast: ast, isLastComment })),
|
|
4471
|
+
endOfLine: (comment, text, options, ast, isLastComment) => [handleOnlyComments].some((x) => x({ comment, text, options, ast: ast, isLastComment })),
|
|
4460
4472
|
};
|
|
4461
4473
|
/**
|
|
4462
4474
|
* When a comment is on an empty interface make sure it gets added as a dangling comment on it and not on the identifier.
|