@typespec/prettier-plugin-typespec 0.61.0-dev.2 → 0.61.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 -227
- 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 ?? 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["DocPropTag"] = 55] = "DocPropTag";
|
|
142
|
+
SyntaxKind[SyntaxKind["DocReturnsTag"] = 56] = "DocReturnsTag";
|
|
143
|
+
SyntaxKind[SyntaxKind["DocErrorsTag"] = 57] = "DocErrorsTag";
|
|
144
|
+
SyntaxKind[SyntaxKind["DocTemplateTag"] = 58] = "DocTemplateTag";
|
|
145
|
+
SyntaxKind[SyntaxKind["DocUnknownTag"] = 59] = "DocUnknownTag";
|
|
146
|
+
SyntaxKind[SyntaxKind["Projection"] = 60] = "Projection";
|
|
147
|
+
SyntaxKind[SyntaxKind["ProjectionParameterDeclaration"] = 61] = "ProjectionParameterDeclaration";
|
|
148
|
+
SyntaxKind[SyntaxKind["ProjectionModelSelector"] = 62] = "ProjectionModelSelector";
|
|
149
|
+
SyntaxKind[SyntaxKind["ProjectionModelPropertySelector"] = 63] = "ProjectionModelPropertySelector";
|
|
150
|
+
SyntaxKind[SyntaxKind["ProjectionScalarSelector"] = 64] = "ProjectionScalarSelector";
|
|
151
|
+
SyntaxKind[SyntaxKind["ProjectionOperationSelector"] = 65] = "ProjectionOperationSelector";
|
|
152
|
+
SyntaxKind[SyntaxKind["ProjectionUnionSelector"] = 66] = "ProjectionUnionSelector";
|
|
153
|
+
SyntaxKind[SyntaxKind["ProjectionUnionVariantSelector"] = 67] = "ProjectionUnionVariantSelector";
|
|
154
|
+
SyntaxKind[SyntaxKind["ProjectionInterfaceSelector"] = 68] = "ProjectionInterfaceSelector";
|
|
155
|
+
SyntaxKind[SyntaxKind["ProjectionEnumSelector"] = 69] = "ProjectionEnumSelector";
|
|
156
|
+
SyntaxKind[SyntaxKind["ProjectionEnumMemberSelector"] = 70] = "ProjectionEnumMemberSelector";
|
|
157
|
+
SyntaxKind[SyntaxKind["ProjectionExpressionStatement"] = 71] = "ProjectionExpressionStatement";
|
|
158
|
+
SyntaxKind[SyntaxKind["ProjectionIfExpression"] = 72] = "ProjectionIfExpression";
|
|
159
|
+
SyntaxKind[SyntaxKind["ProjectionBlockExpression"] = 73] = "ProjectionBlockExpression";
|
|
160
|
+
SyntaxKind[SyntaxKind["ProjectionMemberExpression"] = 74] = "ProjectionMemberExpression";
|
|
161
|
+
SyntaxKind[SyntaxKind["ProjectionLogicalExpression"] = 75] = "ProjectionLogicalExpression";
|
|
162
|
+
SyntaxKind[SyntaxKind["ProjectionEqualityExpression"] = 76] = "ProjectionEqualityExpression";
|
|
163
|
+
SyntaxKind[SyntaxKind["ProjectionUnaryExpression"] = 77] = "ProjectionUnaryExpression";
|
|
164
|
+
SyntaxKind[SyntaxKind["ProjectionRelationalExpression"] = 78] = "ProjectionRelationalExpression";
|
|
165
|
+
SyntaxKind[SyntaxKind["ProjectionArithmeticExpression"] = 79] = "ProjectionArithmeticExpression";
|
|
166
|
+
SyntaxKind[SyntaxKind["ProjectionCallExpression"] = 80] = "ProjectionCallExpression";
|
|
167
|
+
SyntaxKind[SyntaxKind["ProjectionLambdaExpression"] = 81] = "ProjectionLambdaExpression";
|
|
168
|
+
SyntaxKind[SyntaxKind["ProjectionLambdaParameterDeclaration"] = 82] = "ProjectionLambdaParameterDeclaration";
|
|
169
|
+
SyntaxKind[SyntaxKind["ProjectionModelExpression"] = 83] = "ProjectionModelExpression";
|
|
170
|
+
SyntaxKind[SyntaxKind["ProjectionModelProperty"] = 84] = "ProjectionModelProperty";
|
|
171
|
+
SyntaxKind[SyntaxKind["ProjectionModelSpreadProperty"] = 85] = "ProjectionModelSpreadProperty";
|
|
172
|
+
SyntaxKind[SyntaxKind["ProjectionSpreadProperty"] = 86] = "ProjectionSpreadProperty";
|
|
173
|
+
SyntaxKind[SyntaxKind["ProjectionTupleExpression"] = 87] = "ProjectionTupleExpression";
|
|
174
|
+
SyntaxKind[SyntaxKind["ProjectionStatement"] = 88] = "ProjectionStatement";
|
|
175
|
+
SyntaxKind[SyntaxKind["ProjectionDecoratorReferenceExpression"] = 89] = "ProjectionDecoratorReferenceExpression";
|
|
176
|
+
SyntaxKind[SyntaxKind["Return"] = 90] = "Return";
|
|
177
|
+
SyntaxKind[SyntaxKind["JsNamespaceDeclaration"] = 91] = "JsNamespaceDeclaration";
|
|
178
|
+
SyntaxKind[SyntaxKind["TemplateArgument"] = 92] = "TemplateArgument";
|
|
179
|
+
SyntaxKind[SyntaxKind["TypeOfExpression"] = 93] = "TypeOfExpression";
|
|
180
|
+
SyntaxKind[SyntaxKind["ObjectLiteral"] = 94] = "ObjectLiteral";
|
|
181
|
+
SyntaxKind[SyntaxKind["ObjectLiteralProperty"] = 95] = "ObjectLiteralProperty";
|
|
182
|
+
SyntaxKind[SyntaxKind["ObjectLiteralSpreadProperty"] = 96] = "ObjectLiteralSpreadProperty";
|
|
183
|
+
SyntaxKind[SyntaxKind["ArrayLiteral"] = 97] = "ArrayLiteral";
|
|
184
|
+
SyntaxKind[SyntaxKind["ConstStatement"] = 98] = "ConstStatement";
|
|
185
|
+
SyntaxKind[SyntaxKind["CallExpression"] = 99] = "CallExpression";
|
|
186
|
+
SyntaxKind[SyntaxKind["ScalarConstructor"] = 100] = "ScalarConstructor";
|
|
187
|
+
})(SyntaxKind || (SyntaxKind = {}));
|
|
188
|
+
var IdentifierKind;
|
|
189
|
+
(function (IdentifierKind) {
|
|
190
|
+
IdentifierKind[IdentifierKind["TypeReference"] = 0] = "TypeReference";
|
|
191
|
+
IdentifierKind[IdentifierKind["TemplateArgument"] = 1] = "TemplateArgument";
|
|
192
|
+
IdentifierKind[IdentifierKind["Decorator"] = 2] = "Decorator";
|
|
193
|
+
IdentifierKind[IdentifierKind["Function"] = 3] = "Function";
|
|
194
|
+
IdentifierKind[IdentifierKind["Using"] = 4] = "Using";
|
|
195
|
+
IdentifierKind[IdentifierKind["Declaration"] = 5] = "Declaration";
|
|
196
|
+
IdentifierKind[IdentifierKind["ModelExpressionProperty"] = 6] = "ModelExpressionProperty";
|
|
197
|
+
IdentifierKind[IdentifierKind["ModelStatementProperty"] = 7] = "ModelStatementProperty";
|
|
198
|
+
IdentifierKind[IdentifierKind["ObjectLiteralProperty"] = 8] = "ObjectLiteralProperty";
|
|
199
|
+
IdentifierKind[IdentifierKind["Other"] = 9] = "Other";
|
|
200
|
+
})(IdentifierKind || (IdentifierKind = {}));
|
|
201
|
+
/** Used to explicitly specify that a diagnostic has no target. */
|
|
202
|
+
const NoTarget = Symbol.for("NoTarget");
|
|
203
|
+
var ListenerFlow;
|
|
204
|
+
(function (ListenerFlow) {
|
|
205
|
+
/**
|
|
206
|
+
* Do not navigate any containing or referenced type.
|
|
207
|
+
*/
|
|
208
|
+
ListenerFlow[ListenerFlow["NoRecursion"] = 1] = "NoRecursion";
|
|
209
|
+
})(ListenerFlow || (ListenerFlow = {}));
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* A specially typed version of `Array.isArray` to work around [this issue](https://github.com/microsoft/TypeScript/issues/17002).
|
|
213
|
+
*/
|
|
214
|
+
function isArray(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.
|
|
@@ -33,8 +257,11 @@ function createDiagnosticCreator(diagnostics, libraryName) {
|
|
|
33
257
|
message: messageStr,
|
|
34
258
|
target: diagnostic.target,
|
|
35
259
|
};
|
|
260
|
+
if (diagnosticDef.url) {
|
|
261
|
+
mutate(result).url = diagnosticDef.url;
|
|
262
|
+
}
|
|
36
263
|
if (diagnostic.codefixes) {
|
|
37
|
-
result.codefixes = diagnostic.codefixes;
|
|
264
|
+
mutate(result).codefixes = diagnostic.codefixes;
|
|
38
265
|
}
|
|
39
266
|
return result;
|
|
40
267
|
}
|
|
@@ -120,6 +347,8 @@ const diagnostics = {
|
|
|
120
347
|
},
|
|
121
348
|
"triple-quote-indent": {
|
|
122
349
|
severity: "error",
|
|
350
|
+
description: "Report when a triple-quoted string has lines with less indentation as the closing triple quotes.",
|
|
351
|
+
url: "https://typespec.io/docs/standard-library/diags/triple-quote-indent",
|
|
123
352
|
messages: {
|
|
124
353
|
default: "All lines in triple-quoted string lines must have the same indentation as closing triple quotes.",
|
|
125
354
|
},
|
|
@@ -657,6 +886,12 @@ const diagnostics = {
|
|
|
657
886
|
default: paramMessage `Path "${"path"}" cannot be relative. Use {cwd} or {project-root} to specify what the path should be relative to.`,
|
|
658
887
|
},
|
|
659
888
|
},
|
|
889
|
+
"config-invalid-name": {
|
|
890
|
+
severity: "error",
|
|
891
|
+
messages: {
|
|
892
|
+
default: paramMessage `The configuration name "${"name"}" is invalid because it contains a dot ("."). Using a dot will conflict with using nested configuration values.`,
|
|
893
|
+
},
|
|
894
|
+
},
|
|
660
895
|
"path-unix-style": {
|
|
661
896
|
severity: "warning",
|
|
662
897
|
messages: {
|
|
@@ -699,8 +934,7 @@ const diagnostics = {
|
|
|
699
934
|
"library-invalid": {
|
|
700
935
|
severity: "error",
|
|
701
936
|
messages: {
|
|
702
|
-
|
|
703
|
-
default: paramMessage `Library "${"path"}" has an invalid main file.`,
|
|
937
|
+
default: paramMessage `Library "${"path"}" is invalid: ${"message"}`,
|
|
704
938
|
},
|
|
705
939
|
},
|
|
706
940
|
"incompatible-library": {
|
|
@@ -1044,214 +1278,6 @@ const diagnostics = {
|
|
|
1044
1278
|
};
|
|
1045
1279
|
const { createDiagnostic, reportDiagnostic } = createDiagnosticCreator(diagnostics);
|
|
1046
1280
|
|
|
1047
|
-
function createSourceFile(text, path) {
|
|
1048
|
-
let lineStarts = undefined;
|
|
1049
|
-
return {
|
|
1050
|
-
text,
|
|
1051
|
-
path,
|
|
1052
|
-
getLineStarts,
|
|
1053
|
-
getLineAndCharacterOfPosition,
|
|
1054
|
-
};
|
|
1055
|
-
function getLineStarts() {
|
|
1056
|
-
return (lineStarts = lineStarts ?? scanLineStarts(text));
|
|
1057
|
-
}
|
|
1058
|
-
function getLineAndCharacterOfPosition(position) {
|
|
1059
|
-
const starts = getLineStarts();
|
|
1060
|
-
let line = binarySearch(starts, position);
|
|
1061
|
-
// When binarySearch returns < 0 indicating that the value was not found, it
|
|
1062
|
-
// returns the bitwise complement of the index where the value would need to
|
|
1063
|
-
// be inserted to keep the array sorted. So flipping the bits back to this
|
|
1064
|
-
// positive index tells us what the line number would be if we were to
|
|
1065
|
-
// create a new line starting at the given position, and subtracting 1 from
|
|
1066
|
-
// that therefore gives us the line number we're after.
|
|
1067
|
-
if (line < 0) {
|
|
1068
|
-
line = ~line - 1;
|
|
1069
|
-
}
|
|
1070
|
-
return {
|
|
1071
|
-
line,
|
|
1072
|
-
character: position - starts[line],
|
|
1073
|
-
};
|
|
1074
|
-
}
|
|
1075
|
-
}
|
|
1076
|
-
function scanLineStarts(text) {
|
|
1077
|
-
const starts = [];
|
|
1078
|
-
let start = 0;
|
|
1079
|
-
let pos = 0;
|
|
1080
|
-
while (pos < text.length) {
|
|
1081
|
-
const ch = text.charCodeAt(pos);
|
|
1082
|
-
pos++;
|
|
1083
|
-
switch (ch) {
|
|
1084
|
-
case 13 /* CharCode.CarriageReturn */:
|
|
1085
|
-
if (text.charCodeAt(pos) === 10 /* CharCode.LineFeed */) {
|
|
1086
|
-
pos++;
|
|
1087
|
-
}
|
|
1088
|
-
// fallthrough
|
|
1089
|
-
case 10 /* CharCode.LineFeed */:
|
|
1090
|
-
starts.push(start);
|
|
1091
|
-
start = pos;
|
|
1092
|
-
break;
|
|
1093
|
-
}
|
|
1094
|
-
}
|
|
1095
|
-
starts.push(start);
|
|
1096
|
-
return starts;
|
|
1097
|
-
}
|
|
1098
|
-
/**
|
|
1099
|
-
* Search sorted array of numbers for the given value. If found, return index
|
|
1100
|
-
* in array where value was found. If not found, return a negative number that
|
|
1101
|
-
* is the bitwise complement of the index where value would need to be inserted
|
|
1102
|
-
* to keep the array sorted.
|
|
1103
|
-
*/
|
|
1104
|
-
function binarySearch(array, value) {
|
|
1105
|
-
let low = 0;
|
|
1106
|
-
let high = array.length - 1;
|
|
1107
|
-
while (low <= high) {
|
|
1108
|
-
const middle = low + ((high - low) >> 1);
|
|
1109
|
-
const v = array[middle];
|
|
1110
|
-
if (v < value) {
|
|
1111
|
-
low = middle + 1;
|
|
1112
|
-
}
|
|
1113
|
-
else if (v > value) {
|
|
1114
|
-
high = middle - 1;
|
|
1115
|
-
}
|
|
1116
|
-
else {
|
|
1117
|
-
return middle;
|
|
1118
|
-
}
|
|
1119
|
-
}
|
|
1120
|
-
return ~low;
|
|
1121
|
-
}
|
|
1122
|
-
|
|
1123
|
-
/**
|
|
1124
|
-
* AST types
|
|
1125
|
-
*/
|
|
1126
|
-
var SyntaxKind;
|
|
1127
|
-
(function (SyntaxKind) {
|
|
1128
|
-
SyntaxKind[SyntaxKind["TypeSpecScript"] = 0] = "TypeSpecScript";
|
|
1129
|
-
/** @deprecated Use TypeSpecScript */
|
|
1130
|
-
SyntaxKind[SyntaxKind["CadlScript"] = 0] = "CadlScript";
|
|
1131
|
-
SyntaxKind[SyntaxKind["JsSourceFile"] = 1] = "JsSourceFile";
|
|
1132
|
-
SyntaxKind[SyntaxKind["ImportStatement"] = 2] = "ImportStatement";
|
|
1133
|
-
SyntaxKind[SyntaxKind["Identifier"] = 3] = "Identifier";
|
|
1134
|
-
SyntaxKind[SyntaxKind["AugmentDecoratorStatement"] = 4] = "AugmentDecoratorStatement";
|
|
1135
|
-
SyntaxKind[SyntaxKind["DecoratorExpression"] = 5] = "DecoratorExpression";
|
|
1136
|
-
SyntaxKind[SyntaxKind["DirectiveExpression"] = 6] = "DirectiveExpression";
|
|
1137
|
-
SyntaxKind[SyntaxKind["MemberExpression"] = 7] = "MemberExpression";
|
|
1138
|
-
SyntaxKind[SyntaxKind["NamespaceStatement"] = 8] = "NamespaceStatement";
|
|
1139
|
-
SyntaxKind[SyntaxKind["UsingStatement"] = 9] = "UsingStatement";
|
|
1140
|
-
SyntaxKind[SyntaxKind["OperationStatement"] = 10] = "OperationStatement";
|
|
1141
|
-
SyntaxKind[SyntaxKind["OperationSignatureDeclaration"] = 11] = "OperationSignatureDeclaration";
|
|
1142
|
-
SyntaxKind[SyntaxKind["OperationSignatureReference"] = 12] = "OperationSignatureReference";
|
|
1143
|
-
SyntaxKind[SyntaxKind["ModelStatement"] = 13] = "ModelStatement";
|
|
1144
|
-
SyntaxKind[SyntaxKind["ModelExpression"] = 14] = "ModelExpression";
|
|
1145
|
-
SyntaxKind[SyntaxKind["ModelProperty"] = 15] = "ModelProperty";
|
|
1146
|
-
SyntaxKind[SyntaxKind["ModelSpreadProperty"] = 16] = "ModelSpreadProperty";
|
|
1147
|
-
SyntaxKind[SyntaxKind["ScalarStatement"] = 17] = "ScalarStatement";
|
|
1148
|
-
SyntaxKind[SyntaxKind["InterfaceStatement"] = 18] = "InterfaceStatement";
|
|
1149
|
-
SyntaxKind[SyntaxKind["UnionStatement"] = 19] = "UnionStatement";
|
|
1150
|
-
SyntaxKind[SyntaxKind["UnionVariant"] = 20] = "UnionVariant";
|
|
1151
|
-
SyntaxKind[SyntaxKind["EnumStatement"] = 21] = "EnumStatement";
|
|
1152
|
-
SyntaxKind[SyntaxKind["EnumMember"] = 22] = "EnumMember";
|
|
1153
|
-
SyntaxKind[SyntaxKind["EnumSpreadMember"] = 23] = "EnumSpreadMember";
|
|
1154
|
-
SyntaxKind[SyntaxKind["AliasStatement"] = 24] = "AliasStatement";
|
|
1155
|
-
SyntaxKind[SyntaxKind["DecoratorDeclarationStatement"] = 25] = "DecoratorDeclarationStatement";
|
|
1156
|
-
SyntaxKind[SyntaxKind["FunctionDeclarationStatement"] = 26] = "FunctionDeclarationStatement";
|
|
1157
|
-
SyntaxKind[SyntaxKind["FunctionParameter"] = 27] = "FunctionParameter";
|
|
1158
|
-
SyntaxKind[SyntaxKind["UnionExpression"] = 28] = "UnionExpression";
|
|
1159
|
-
SyntaxKind[SyntaxKind["IntersectionExpression"] = 29] = "IntersectionExpression";
|
|
1160
|
-
SyntaxKind[SyntaxKind["TupleExpression"] = 30] = "TupleExpression";
|
|
1161
|
-
SyntaxKind[SyntaxKind["ArrayExpression"] = 31] = "ArrayExpression";
|
|
1162
|
-
SyntaxKind[SyntaxKind["StringLiteral"] = 32] = "StringLiteral";
|
|
1163
|
-
SyntaxKind[SyntaxKind["NumericLiteral"] = 33] = "NumericLiteral";
|
|
1164
|
-
SyntaxKind[SyntaxKind["BooleanLiteral"] = 34] = "BooleanLiteral";
|
|
1165
|
-
SyntaxKind[SyntaxKind["StringTemplateExpression"] = 35] = "StringTemplateExpression";
|
|
1166
|
-
SyntaxKind[SyntaxKind["StringTemplateHead"] = 36] = "StringTemplateHead";
|
|
1167
|
-
SyntaxKind[SyntaxKind["StringTemplateMiddle"] = 37] = "StringTemplateMiddle";
|
|
1168
|
-
SyntaxKind[SyntaxKind["StringTemplateTail"] = 38] = "StringTemplateTail";
|
|
1169
|
-
SyntaxKind[SyntaxKind["StringTemplateSpan"] = 39] = "StringTemplateSpan";
|
|
1170
|
-
SyntaxKind[SyntaxKind["ExternKeyword"] = 40] = "ExternKeyword";
|
|
1171
|
-
SyntaxKind[SyntaxKind["VoidKeyword"] = 41] = "VoidKeyword";
|
|
1172
|
-
SyntaxKind[SyntaxKind["NeverKeyword"] = 42] = "NeverKeyword";
|
|
1173
|
-
SyntaxKind[SyntaxKind["UnknownKeyword"] = 43] = "UnknownKeyword";
|
|
1174
|
-
SyntaxKind[SyntaxKind["ValueOfExpression"] = 44] = "ValueOfExpression";
|
|
1175
|
-
SyntaxKind[SyntaxKind["TypeReference"] = 45] = "TypeReference";
|
|
1176
|
-
SyntaxKind[SyntaxKind["ProjectionReference"] = 46] = "ProjectionReference";
|
|
1177
|
-
SyntaxKind[SyntaxKind["TemplateParameterDeclaration"] = 47] = "TemplateParameterDeclaration";
|
|
1178
|
-
SyntaxKind[SyntaxKind["EmptyStatement"] = 48] = "EmptyStatement";
|
|
1179
|
-
SyntaxKind[SyntaxKind["InvalidStatement"] = 49] = "InvalidStatement";
|
|
1180
|
-
SyntaxKind[SyntaxKind["LineComment"] = 50] = "LineComment";
|
|
1181
|
-
SyntaxKind[SyntaxKind["BlockComment"] = 51] = "BlockComment";
|
|
1182
|
-
SyntaxKind[SyntaxKind["Doc"] = 52] = "Doc";
|
|
1183
|
-
SyntaxKind[SyntaxKind["DocText"] = 53] = "DocText";
|
|
1184
|
-
SyntaxKind[SyntaxKind["DocParamTag"] = 54] = "DocParamTag";
|
|
1185
|
-
SyntaxKind[SyntaxKind["DocPropTag"] = 55] = "DocPropTag";
|
|
1186
|
-
SyntaxKind[SyntaxKind["DocReturnsTag"] = 56] = "DocReturnsTag";
|
|
1187
|
-
SyntaxKind[SyntaxKind["DocErrorsTag"] = 57] = "DocErrorsTag";
|
|
1188
|
-
SyntaxKind[SyntaxKind["DocTemplateTag"] = 58] = "DocTemplateTag";
|
|
1189
|
-
SyntaxKind[SyntaxKind["DocUnknownTag"] = 59] = "DocUnknownTag";
|
|
1190
|
-
SyntaxKind[SyntaxKind["Projection"] = 60] = "Projection";
|
|
1191
|
-
SyntaxKind[SyntaxKind["ProjectionParameterDeclaration"] = 61] = "ProjectionParameterDeclaration";
|
|
1192
|
-
SyntaxKind[SyntaxKind["ProjectionModelSelector"] = 62] = "ProjectionModelSelector";
|
|
1193
|
-
SyntaxKind[SyntaxKind["ProjectionModelPropertySelector"] = 63] = "ProjectionModelPropertySelector";
|
|
1194
|
-
SyntaxKind[SyntaxKind["ProjectionScalarSelector"] = 64] = "ProjectionScalarSelector";
|
|
1195
|
-
SyntaxKind[SyntaxKind["ProjectionOperationSelector"] = 65] = "ProjectionOperationSelector";
|
|
1196
|
-
SyntaxKind[SyntaxKind["ProjectionUnionSelector"] = 66] = "ProjectionUnionSelector";
|
|
1197
|
-
SyntaxKind[SyntaxKind["ProjectionUnionVariantSelector"] = 67] = "ProjectionUnionVariantSelector";
|
|
1198
|
-
SyntaxKind[SyntaxKind["ProjectionInterfaceSelector"] = 68] = "ProjectionInterfaceSelector";
|
|
1199
|
-
SyntaxKind[SyntaxKind["ProjectionEnumSelector"] = 69] = "ProjectionEnumSelector";
|
|
1200
|
-
SyntaxKind[SyntaxKind["ProjectionEnumMemberSelector"] = 70] = "ProjectionEnumMemberSelector";
|
|
1201
|
-
SyntaxKind[SyntaxKind["ProjectionExpressionStatement"] = 71] = "ProjectionExpressionStatement";
|
|
1202
|
-
SyntaxKind[SyntaxKind["ProjectionIfExpression"] = 72] = "ProjectionIfExpression";
|
|
1203
|
-
SyntaxKind[SyntaxKind["ProjectionBlockExpression"] = 73] = "ProjectionBlockExpression";
|
|
1204
|
-
SyntaxKind[SyntaxKind["ProjectionMemberExpression"] = 74] = "ProjectionMemberExpression";
|
|
1205
|
-
SyntaxKind[SyntaxKind["ProjectionLogicalExpression"] = 75] = "ProjectionLogicalExpression";
|
|
1206
|
-
SyntaxKind[SyntaxKind["ProjectionEqualityExpression"] = 76] = "ProjectionEqualityExpression";
|
|
1207
|
-
SyntaxKind[SyntaxKind["ProjectionUnaryExpression"] = 77] = "ProjectionUnaryExpression";
|
|
1208
|
-
SyntaxKind[SyntaxKind["ProjectionRelationalExpression"] = 78] = "ProjectionRelationalExpression";
|
|
1209
|
-
SyntaxKind[SyntaxKind["ProjectionArithmeticExpression"] = 79] = "ProjectionArithmeticExpression";
|
|
1210
|
-
SyntaxKind[SyntaxKind["ProjectionCallExpression"] = 80] = "ProjectionCallExpression";
|
|
1211
|
-
SyntaxKind[SyntaxKind["ProjectionLambdaExpression"] = 81] = "ProjectionLambdaExpression";
|
|
1212
|
-
SyntaxKind[SyntaxKind["ProjectionLambdaParameterDeclaration"] = 82] = "ProjectionLambdaParameterDeclaration";
|
|
1213
|
-
SyntaxKind[SyntaxKind["ProjectionModelExpression"] = 83] = "ProjectionModelExpression";
|
|
1214
|
-
SyntaxKind[SyntaxKind["ProjectionModelProperty"] = 84] = "ProjectionModelProperty";
|
|
1215
|
-
SyntaxKind[SyntaxKind["ProjectionModelSpreadProperty"] = 85] = "ProjectionModelSpreadProperty";
|
|
1216
|
-
SyntaxKind[SyntaxKind["ProjectionSpreadProperty"] = 86] = "ProjectionSpreadProperty";
|
|
1217
|
-
SyntaxKind[SyntaxKind["ProjectionTupleExpression"] = 87] = "ProjectionTupleExpression";
|
|
1218
|
-
SyntaxKind[SyntaxKind["ProjectionStatement"] = 88] = "ProjectionStatement";
|
|
1219
|
-
SyntaxKind[SyntaxKind["ProjectionDecoratorReferenceExpression"] = 89] = "ProjectionDecoratorReferenceExpression";
|
|
1220
|
-
SyntaxKind[SyntaxKind["Return"] = 90] = "Return";
|
|
1221
|
-
SyntaxKind[SyntaxKind["JsNamespaceDeclaration"] = 91] = "JsNamespaceDeclaration";
|
|
1222
|
-
SyntaxKind[SyntaxKind["TemplateArgument"] = 92] = "TemplateArgument";
|
|
1223
|
-
SyntaxKind[SyntaxKind["TypeOfExpression"] = 93] = "TypeOfExpression";
|
|
1224
|
-
SyntaxKind[SyntaxKind["ObjectLiteral"] = 94] = "ObjectLiteral";
|
|
1225
|
-
SyntaxKind[SyntaxKind["ObjectLiteralProperty"] = 95] = "ObjectLiteralProperty";
|
|
1226
|
-
SyntaxKind[SyntaxKind["ObjectLiteralSpreadProperty"] = 96] = "ObjectLiteralSpreadProperty";
|
|
1227
|
-
SyntaxKind[SyntaxKind["ArrayLiteral"] = 97] = "ArrayLiteral";
|
|
1228
|
-
SyntaxKind[SyntaxKind["ConstStatement"] = 98] = "ConstStatement";
|
|
1229
|
-
SyntaxKind[SyntaxKind["CallExpression"] = 99] = "CallExpression";
|
|
1230
|
-
SyntaxKind[SyntaxKind["ScalarConstructor"] = 100] = "ScalarConstructor";
|
|
1231
|
-
})(SyntaxKind || (SyntaxKind = {}));
|
|
1232
|
-
var IdentifierKind;
|
|
1233
|
-
(function (IdentifierKind) {
|
|
1234
|
-
IdentifierKind[IdentifierKind["TypeReference"] = 0] = "TypeReference";
|
|
1235
|
-
IdentifierKind[IdentifierKind["TemplateArgument"] = 1] = "TemplateArgument";
|
|
1236
|
-
IdentifierKind[IdentifierKind["Decorator"] = 2] = "Decorator";
|
|
1237
|
-
IdentifierKind[IdentifierKind["Function"] = 3] = "Function";
|
|
1238
|
-
IdentifierKind[IdentifierKind["Using"] = 4] = "Using";
|
|
1239
|
-
IdentifierKind[IdentifierKind["Declaration"] = 5] = "Declaration";
|
|
1240
|
-
IdentifierKind[IdentifierKind["ModelExpressionProperty"] = 6] = "ModelExpressionProperty";
|
|
1241
|
-
IdentifierKind[IdentifierKind["ModelStatementProperty"] = 7] = "ModelStatementProperty";
|
|
1242
|
-
IdentifierKind[IdentifierKind["ObjectLiteralProperty"] = 8] = "ObjectLiteralProperty";
|
|
1243
|
-
IdentifierKind[IdentifierKind["Other"] = 9] = "Other";
|
|
1244
|
-
})(IdentifierKind || (IdentifierKind = {}));
|
|
1245
|
-
/** Used to explicitly specify that a diagnostic has no target. */
|
|
1246
|
-
const NoTarget = Symbol.for("NoTarget");
|
|
1247
|
-
var ListenerFlow;
|
|
1248
|
-
(function (ListenerFlow) {
|
|
1249
|
-
/**
|
|
1250
|
-
* Do not navigate any containing or referenced type.
|
|
1251
|
-
*/
|
|
1252
|
-
ListenerFlow[ListenerFlow["NoRecursion"] = 1] = "NoRecursion";
|
|
1253
|
-
})(ListenerFlow || (ListenerFlow = {}));
|
|
1254
|
-
|
|
1255
1281
|
function getSourceLocation(target, options = {}) {
|
|
1256
1282
|
if (target === NoTarget || target === undefined) {
|
|
1257
1283
|
return undefined;
|
|
@@ -1341,22 +1367,6 @@ function compilerAssert(condition, message, target) {
|
|
|
1341
1367
|
throw new Error(message);
|
|
1342
1368
|
}
|
|
1343
1369
|
|
|
1344
|
-
/**
|
|
1345
|
-
* A specially typed version of `Array.isArray` to work around [this issue](https://github.com/microsoft/TypeScript/issues/17002).
|
|
1346
|
-
*/
|
|
1347
|
-
function isArray(arg) {
|
|
1348
|
-
return Array.isArray(arg);
|
|
1349
|
-
}
|
|
1350
|
-
/**
|
|
1351
|
-
* Casts away readonly typing.
|
|
1352
|
-
*
|
|
1353
|
-
* Use it like this when it is safe to override readonly typing:
|
|
1354
|
-
* mutate(item).prop = value;
|
|
1355
|
-
*/
|
|
1356
|
-
function mutate(value) {
|
|
1357
|
-
return value;
|
|
1358
|
-
}
|
|
1359
|
-
|
|
1360
1370
|
//
|
|
1361
1371
|
// Generated by scripts/regen-nonascii-map.js
|
|
1362
1372
|
// on node v18.16.0 with unicode 15.0.
|