@typespec/prettier-plugin-typespec 0.54.0-dev.1 → 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 +252 -234
- package/dist/index.js.map +1 -1
- package/package.json +4 -6
package/dist/index.js
CHANGED
|
@@ -1,5 +1,81 @@
|
|
|
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
|
+
|
|
3
79
|
/**
|
|
4
80
|
* AST types
|
|
5
81
|
*/
|
|
@@ -119,168 +195,33 @@ var ListenerFlow;
|
|
|
119
195
|
ListenerFlow[ListenerFlow["NoRecursion"] = 1] = "NoRecursion";
|
|
120
196
|
})(ListenerFlow || (ListenerFlow = {}));
|
|
121
197
|
|
|
122
|
-
function
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
function
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
function getLineAndCharacterOfPosition(position) {
|
|
134
|
-
const starts = getLineStarts();
|
|
135
|
-
let line = binarySearch(starts, position);
|
|
136
|
-
// When binarySearch returns < 0 indicating that the value was not found, it
|
|
137
|
-
// returns the bitwise complement of the index where the value would need to
|
|
138
|
-
// be inserted to keep the array sorted. So flipping the bits back to this
|
|
139
|
-
// positive index tells us what the line number would be if we were to
|
|
140
|
-
// create a new line starting at the given position, and subtracting 1 from
|
|
141
|
-
// that therefore gives us the line number we're after.
|
|
142
|
-
if (line < 0) {
|
|
143
|
-
line = ~line - 1;
|
|
144
|
-
}
|
|
145
|
-
return {
|
|
146
|
-
line,
|
|
147
|
-
character: position - starts[line],
|
|
148
|
-
};
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
function getSourceLocation(target, options = {}) {
|
|
152
|
-
if (target === NoTarget || target === undefined) {
|
|
153
|
-
return undefined;
|
|
154
|
-
}
|
|
155
|
-
if ("file" in target) {
|
|
156
|
-
return target;
|
|
157
|
-
}
|
|
158
|
-
if (!("kind" in target)) {
|
|
159
|
-
// symbol
|
|
160
|
-
if (target.flags & 524288 /* SymbolFlags.Using */) {
|
|
161
|
-
target = target.symbolSource;
|
|
162
|
-
}
|
|
163
|
-
if (!target.declarations[0]) {
|
|
164
|
-
return createSyntheticSourceLocation();
|
|
165
|
-
}
|
|
166
|
-
return getSourceLocationOfNode(target.declarations[0], options);
|
|
167
|
-
}
|
|
168
|
-
else if (typeof target.kind === "number") {
|
|
169
|
-
// node
|
|
170
|
-
return getSourceLocationOfNode(target, options);
|
|
171
|
-
}
|
|
172
|
-
else {
|
|
173
|
-
// type
|
|
174
|
-
const targetNode = target.node;
|
|
175
|
-
if (targetNode) {
|
|
176
|
-
return getSourceLocationOfNode(targetNode, options);
|
|
177
|
-
}
|
|
178
|
-
return createSyntheticSourceLocation();
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
function createSyntheticSourceLocation(loc = "<unknown location>") {
|
|
182
|
-
return {
|
|
183
|
-
file: createSourceFile("", loc),
|
|
184
|
-
pos: 0,
|
|
185
|
-
end: 0,
|
|
186
|
-
isSynthetic: true,
|
|
187
|
-
};
|
|
188
|
-
}
|
|
189
|
-
function getSourceLocationOfNode(node, options) {
|
|
190
|
-
let root = node;
|
|
191
|
-
while (root.parent !== undefined) {
|
|
192
|
-
root = root.parent;
|
|
193
|
-
}
|
|
194
|
-
if (root.kind !== SyntaxKind.TypeSpecScript && root.kind !== SyntaxKind.JsSourceFile) {
|
|
195
|
-
return createSyntheticSourceLocation(node.flags & 8 /* NodeFlags.Synthetic */
|
|
196
|
-
? undefined
|
|
197
|
-
: "<unknown location - cannot obtain source location of unbound node - file bug at https://github.com/microsoft/typespec>");
|
|
198
|
-
}
|
|
199
|
-
if (options.locateId && "id" in node && node.id !== undefined) {
|
|
200
|
-
node = node.id;
|
|
201
|
-
}
|
|
202
|
-
return {
|
|
203
|
-
file: root.file,
|
|
204
|
-
pos: node.pos,
|
|
205
|
-
end: node.end,
|
|
206
|
-
};
|
|
207
|
-
}
|
|
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
|
+
};
|
|
208
209
|
/**
|
|
209
|
-
*
|
|
210
|
-
* being compiled.
|
|
211
|
-
*
|
|
212
|
-
* @param condition Throw if this is not true.
|
|
213
|
-
*
|
|
214
|
-
* @param message Error message.
|
|
215
|
-
*
|
|
216
|
-
* @param target Optional location in source code that might give a clue about
|
|
217
|
-
* what got the compiler off track.
|
|
210
|
+
* A specially typed version of `Array.isArray` to work around [this issue](https://github.com/microsoft/TypeScript/issues/17002).
|
|
218
211
|
*/
|
|
219
|
-
function
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
if (target) {
|
|
224
|
-
let location;
|
|
225
|
-
try {
|
|
226
|
-
location = getSourceLocation(target);
|
|
227
|
-
}
|
|
228
|
-
catch (err) { }
|
|
229
|
-
if (location) {
|
|
230
|
-
const pos = location.file.getLineAndCharacterOfPosition(location.pos);
|
|
231
|
-
const file = location.file.path;
|
|
232
|
-
const line = pos.line + 1;
|
|
233
|
-
const col = pos.character + 1;
|
|
234
|
-
message += `\nOccurred while compiling code in ${file} near line ${line}, column ${col}`;
|
|
235
|
-
}
|
|
236
|
-
}
|
|
237
|
-
throw new Error(message);
|
|
238
|
-
}
|
|
239
|
-
function scanLineStarts(text) {
|
|
240
|
-
const starts = [];
|
|
241
|
-
let start = 0;
|
|
242
|
-
let pos = 0;
|
|
243
|
-
while (pos < text.length) {
|
|
244
|
-
const ch = text.charCodeAt(pos);
|
|
245
|
-
pos++;
|
|
246
|
-
switch (ch) {
|
|
247
|
-
case 13 /* CharCode.CarriageReturn */:
|
|
248
|
-
if (text.charCodeAt(pos) === 10 /* CharCode.LineFeed */) {
|
|
249
|
-
pos++;
|
|
250
|
-
}
|
|
251
|
-
// fallthrough
|
|
252
|
-
case 10 /* CharCode.LineFeed */:
|
|
253
|
-
starts.push(start);
|
|
254
|
-
start = pos;
|
|
255
|
-
break;
|
|
256
|
-
}
|
|
257
|
-
}
|
|
258
|
-
starts.push(start);
|
|
259
|
-
return starts;
|
|
212
|
+
function isArray(
|
|
213
|
+
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
214
|
+
arg) {
|
|
215
|
+
return Array.isArray(arg);
|
|
260
216
|
}
|
|
261
217
|
/**
|
|
262
|
-
*
|
|
263
|
-
*
|
|
264
|
-
*
|
|
265
|
-
*
|
|
218
|
+
* Casts away readonly typing.
|
|
219
|
+
*
|
|
220
|
+
* Use it like this when it is safe to override readonly typing:
|
|
221
|
+
* mutate(item).prop = value;
|
|
266
222
|
*/
|
|
267
|
-
function
|
|
268
|
-
|
|
269
|
-
let high = array.length - 1;
|
|
270
|
-
while (low <= high) {
|
|
271
|
-
const middle = low + ((high - low) >> 1);
|
|
272
|
-
const v = array[middle];
|
|
273
|
-
if (v < value) {
|
|
274
|
-
low = middle + 1;
|
|
275
|
-
}
|
|
276
|
-
else if (v > value) {
|
|
277
|
-
high = middle - 1;
|
|
278
|
-
}
|
|
279
|
-
else {
|
|
280
|
-
return middle;
|
|
281
|
-
}
|
|
282
|
-
}
|
|
283
|
-
return ~low;
|
|
223
|
+
function mutate(value) {
|
|
224
|
+
return value;
|
|
284
225
|
}
|
|
285
226
|
|
|
286
227
|
/**
|
|
@@ -313,12 +254,16 @@ function createDiagnosticCreator(diagnostics, libraryName) {
|
|
|
313
254
|
throw new Error(`Unexpected message id '${messageId}'. ${errorMessage} for code '${code}'. Defined codes:\n${codeStr}`);
|
|
314
255
|
}
|
|
315
256
|
const messageStr = typeof message === "string" ? message : message(diagnostic.format);
|
|
316
|
-
|
|
257
|
+
const result = {
|
|
317
258
|
code: libraryName ? `${libraryName}/${String(diagnostic.code)}` : diagnostic.code.toString(),
|
|
318
259
|
severity: diagnosticDef.severity,
|
|
319
260
|
message: messageStr,
|
|
320
261
|
target: diagnostic.target,
|
|
321
262
|
};
|
|
263
|
+
if (diagnostic.codefixes) {
|
|
264
|
+
mutate(result).codefixes = diagnostic.codefixes;
|
|
265
|
+
}
|
|
266
|
+
return result;
|
|
322
267
|
}
|
|
323
268
|
function reportDiagnostic(program, diagnostic) {
|
|
324
269
|
const diag = createDiagnostic(diagnostic);
|
|
@@ -629,6 +574,12 @@ const diagnostics = {
|
|
|
629
574
|
array: "Cannot intersect an array model.",
|
|
630
575
|
},
|
|
631
576
|
},
|
|
577
|
+
"incompatible-indexer": {
|
|
578
|
+
severity: "error",
|
|
579
|
+
messages: {
|
|
580
|
+
default: paramMessage `Property is incompatible with indexer:\n${"message"}`,
|
|
581
|
+
},
|
|
582
|
+
},
|
|
632
583
|
"no-array-properties": {
|
|
633
584
|
severity: "error",
|
|
634
585
|
messages: {
|
|
@@ -1173,6 +1124,12 @@ const diagnostics = {
|
|
|
1173
1124
|
default: paramMessage `Type '${"typeName"}' recursively references itself as a base type.`,
|
|
1174
1125
|
},
|
|
1175
1126
|
},
|
|
1127
|
+
"circular-constraint": {
|
|
1128
|
+
severity: "error",
|
|
1129
|
+
messages: {
|
|
1130
|
+
default: paramMessage `Type parameter '${"typeName"}' has a circular constraint.`,
|
|
1131
|
+
},
|
|
1132
|
+
},
|
|
1176
1133
|
"circular-op-signature": {
|
|
1177
1134
|
severity: "error",
|
|
1178
1135
|
messages: {
|
|
@@ -1221,33 +1178,93 @@ const diagnostics = {
|
|
|
1221
1178
|
};
|
|
1222
1179
|
const { createDiagnostic, reportDiagnostic } = createDiagnosticCreator(diagnostics);
|
|
1223
1180
|
|
|
1224
|
-
|
|
1225
|
-
if (
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
if (kind
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1181
|
+
function getSourceLocation(target, options = {}) {
|
|
1182
|
+
if (target === NoTarget || target === undefined) {
|
|
1183
|
+
return undefined;
|
|
1184
|
+
}
|
|
1185
|
+
if ("file" in target) {
|
|
1186
|
+
return target;
|
|
1187
|
+
}
|
|
1188
|
+
if (!("kind" in target)) {
|
|
1189
|
+
// symbol
|
|
1190
|
+
if (target.flags & 524288 /* SymbolFlags.Using */) {
|
|
1191
|
+
target = target.symbolSource;
|
|
1192
|
+
}
|
|
1193
|
+
if (!target.declarations[0]) {
|
|
1194
|
+
return createSyntheticSourceLocation();
|
|
1195
|
+
}
|
|
1196
|
+
return getSourceLocationOfNode(target.declarations[0], options);
|
|
1197
|
+
}
|
|
1198
|
+
else if (typeof target.kind === "number") {
|
|
1199
|
+
// node
|
|
1200
|
+
return getSourceLocationOfNode(target, options);
|
|
1201
|
+
}
|
|
1202
|
+
else {
|
|
1203
|
+
// type
|
|
1204
|
+
const targetNode = target.node;
|
|
1205
|
+
if (targetNode) {
|
|
1206
|
+
return getSourceLocationOfNode(targetNode, options);
|
|
1207
|
+
}
|
|
1208
|
+
return createSyntheticSourceLocation();
|
|
1209
|
+
}
|
|
1210
|
+
}
|
|
1211
|
+
function createSyntheticSourceLocation(loc = "<unknown location>") {
|
|
1212
|
+
return {
|
|
1213
|
+
file: createSourceFile("", loc),
|
|
1214
|
+
pos: 0,
|
|
1215
|
+
end: 0,
|
|
1216
|
+
isSynthetic: true,
|
|
1217
|
+
};
|
|
1218
|
+
}
|
|
1219
|
+
function getSourceLocationOfNode(node, options) {
|
|
1220
|
+
let root = node;
|
|
1221
|
+
while (root.parent !== undefined) {
|
|
1222
|
+
root = root.parent;
|
|
1223
|
+
}
|
|
1224
|
+
if (root.kind !== SyntaxKind.TypeSpecScript && root.kind !== SyntaxKind.JsSourceFile) {
|
|
1225
|
+
return createSyntheticSourceLocation(node.flags & 8 /* NodeFlags.Synthetic */
|
|
1226
|
+
? undefined
|
|
1227
|
+
: "<unknown location - cannot obtain source location of unbound node - file bug at https://github.com/microsoft/typespec>");
|
|
1228
|
+
}
|
|
1229
|
+
if (options.locateId && "id" in node && node.id !== undefined) {
|
|
1230
|
+
node = node.id;
|
|
1231
|
+
}
|
|
1232
|
+
return {
|
|
1233
|
+
file: root.file,
|
|
1234
|
+
pos: node.pos,
|
|
1235
|
+
end: node.end,
|
|
1236
|
+
};
|
|
1242
1237
|
}
|
|
1243
1238
|
/**
|
|
1244
|
-
*
|
|
1239
|
+
* Use this to report bugs in the compiler, and not errors in the source code
|
|
1240
|
+
* being compiled.
|
|
1245
1241
|
*
|
|
1246
|
-
*
|
|
1247
|
-
*
|
|
1242
|
+
* @param condition Throw if this is not true.
|
|
1243
|
+
*
|
|
1244
|
+
* @param message Error message.
|
|
1245
|
+
*
|
|
1246
|
+
* @param target Optional location in source code that might give a clue about
|
|
1247
|
+
* what got the compiler off track.
|
|
1248
1248
|
*/
|
|
1249
|
-
function
|
|
1250
|
-
|
|
1249
|
+
function compilerAssert(condition, message, target) {
|
|
1250
|
+
if (condition) {
|
|
1251
|
+
return;
|
|
1252
|
+
}
|
|
1253
|
+
if (target) {
|
|
1254
|
+
let location;
|
|
1255
|
+
try {
|
|
1256
|
+
location = getSourceLocation(target);
|
|
1257
|
+
}
|
|
1258
|
+
catch (err) { }
|
|
1259
|
+
if (location) {
|
|
1260
|
+
const pos = location.file.getLineAndCharacterOfPosition(location.pos);
|
|
1261
|
+
const file = location.file.path;
|
|
1262
|
+
const line = pos.line + 1;
|
|
1263
|
+
const col = pos.character + 1;
|
|
1264
|
+
message += `\nOccurred while compiling code in ${file} near line ${line}, column ${col}`;
|
|
1265
|
+
}
|
|
1266
|
+
}
|
|
1267
|
+
throw new Error(message);
|
|
1251
1268
|
}
|
|
1252
1269
|
|
|
1253
1270
|
var __defProp = Object.defineProperty;
|
|
@@ -4450,6 +4467,8 @@ const commentHandler = {
|
|
|
4450
4467
|
addCommentBetweenAnnotationsAndNode,
|
|
4451
4468
|
handleOnlyComments,
|
|
4452
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 })),
|
|
4453
4472
|
};
|
|
4454
4473
|
/**
|
|
4455
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.
|
|
@@ -4563,8 +4582,7 @@ function needsParens(path, options) {
|
|
|
4563
4582
|
if (!parent) {
|
|
4564
4583
|
return false;
|
|
4565
4584
|
}
|
|
4566
|
-
|
|
4567
|
-
const node = path.getValue();
|
|
4585
|
+
const node = path.node;
|
|
4568
4586
|
switch (node.kind) {
|
|
4569
4587
|
case SyntaxKind.ValueOfExpression:
|
|
4570
4588
|
return (parent.kind === SyntaxKind.UnionExpression ||
|
|
@@ -4604,7 +4622,7 @@ const typespecPrinter = {
|
|
|
4604
4622
|
function printTypeSpec(
|
|
4605
4623
|
// Path to the AST node to print
|
|
4606
4624
|
path, options, print) {
|
|
4607
|
-
const node = path.
|
|
4625
|
+
const node = path.node;
|
|
4608
4626
|
const docs = printDocComments(path, options, print);
|
|
4609
4627
|
const directives = shouldPrintDirective(node) ? printDirectives(path, options, print) : "";
|
|
4610
4628
|
const printedNode = printNode(path, options, print);
|
|
@@ -4625,7 +4643,7 @@ function shouldPrintDirective(node) {
|
|
|
4625
4643
|
function printNode(
|
|
4626
4644
|
// Path to the AST node to print
|
|
4627
4645
|
path, options, print) {
|
|
4628
|
-
const node = path.
|
|
4646
|
+
const node = path.node;
|
|
4629
4647
|
switch (node.kind) {
|
|
4630
4648
|
// Root
|
|
4631
4649
|
case SyntaxKind.TypeSpecScript:
|
|
@@ -4797,7 +4815,7 @@ path, options, print) {
|
|
|
4797
4815
|
}
|
|
4798
4816
|
}
|
|
4799
4817
|
function printTypeSpecScript(path, options, print) {
|
|
4800
|
-
const node = path.
|
|
4818
|
+
const node = path.node;
|
|
4801
4819
|
const nodeHasComments = hasComments(node, CommentCheckFlags.Dangling);
|
|
4802
4820
|
const body = [];
|
|
4803
4821
|
if (nodeHasComments) {
|
|
@@ -4812,7 +4830,7 @@ function printAliasStatement(path, options, print) {
|
|
|
4812
4830
|
return ["alias ", id, template, " = ", path.call(print, "value"), ";"];
|
|
4813
4831
|
}
|
|
4814
4832
|
function printTemplateParameters(path, options, print, propertyName) {
|
|
4815
|
-
const node = path.
|
|
4833
|
+
const node = path.node;
|
|
4816
4834
|
const args = node[propertyName];
|
|
4817
4835
|
if (args.length === 0) {
|
|
4818
4836
|
return "";
|
|
@@ -4840,7 +4858,7 @@ function canAttachComment(node) {
|
|
|
4840
4858
|
!(node.flags & 8 /* NodeFlags.Synthetic */));
|
|
4841
4859
|
}
|
|
4842
4860
|
function printComment(commentPath, options) {
|
|
4843
|
-
const comment = commentPath.
|
|
4861
|
+
const comment = commentPath.node;
|
|
4844
4862
|
comment.printed = true;
|
|
4845
4863
|
switch (comment.kind) {
|
|
4846
4864
|
case SyntaxKind.BlockComment:
|
|
@@ -4852,7 +4870,7 @@ function printComment(commentPath, options) {
|
|
|
4852
4870
|
}
|
|
4853
4871
|
}
|
|
4854
4872
|
function printBlockComment(commentPath, options) {
|
|
4855
|
-
const comment = commentPath.
|
|
4873
|
+
const comment = commentPath.node;
|
|
4856
4874
|
const rawComment = options.originalText.slice(comment.pos + 2, comment.end - 2);
|
|
4857
4875
|
const printed = isIndentableBlockComment(rawComment)
|
|
4858
4876
|
? printIndentableBlockCommentContent(rawComment)
|
|
@@ -4877,7 +4895,7 @@ function printIndentableBlockCommentContent(rawComment) {
|
|
|
4877
4895
|
}
|
|
4878
4896
|
/** Print a doc comment. */
|
|
4879
4897
|
function printDoc(path, options, print) {
|
|
4880
|
-
const node = path.
|
|
4898
|
+
const node = path.node;
|
|
4881
4899
|
const rawComment = options.originalText.slice(node.pos + 3, node.end - 2);
|
|
4882
4900
|
const printed = isIndentableBlockComment(rawComment)
|
|
4883
4901
|
? printIndentableBlockCommentContent(rawComment)
|
|
@@ -4887,7 +4905,7 @@ function printDoc(path, options, print) {
|
|
|
4887
4905
|
return ["/**", printed, "*/"];
|
|
4888
4906
|
}
|
|
4889
4907
|
function printDecorators(path, options, print, { tryInline }) {
|
|
4890
|
-
const node = path.
|
|
4908
|
+
const node = path.node;
|
|
4891
4909
|
if (node.decorators.length === 0) {
|
|
4892
4910
|
return { decorators: "", multiline: false };
|
|
4893
4911
|
}
|
|
@@ -4900,7 +4918,7 @@ function printDecorators(path, options, print, { tryInline }) {
|
|
|
4900
4918
|
}
|
|
4901
4919
|
/** Check if the decorators of the given node should be broken in sparate line */
|
|
4902
4920
|
function shouldDecoratorBreakLine(path, options, { tryInline }) {
|
|
4903
|
-
const node = path.
|
|
4921
|
+
const node = path.node;
|
|
4904
4922
|
return (!tryInline || node.decorators.length >= 3 || hasNewlineBetweenOrAfterDecorators(node, options));
|
|
4905
4923
|
}
|
|
4906
4924
|
/**
|
|
@@ -4931,7 +4949,7 @@ function printAugmentDecoratorArgs(path, options, print) {
|
|
|
4931
4949
|
];
|
|
4932
4950
|
}
|
|
4933
4951
|
function printDocComments(path, options, print) {
|
|
4934
|
-
const node = path.
|
|
4952
|
+
const node = path.node;
|
|
4935
4953
|
if (node.docs === undefined || node.docs.length === 0) {
|
|
4936
4954
|
return "";
|
|
4937
4955
|
}
|
|
@@ -4939,7 +4957,7 @@ function printDocComments(path, options, print) {
|
|
|
4939
4957
|
return group([...docs, breakParent]);
|
|
4940
4958
|
}
|
|
4941
4959
|
function printDirectives(path, options, print) {
|
|
4942
|
-
const node = path.
|
|
4960
|
+
const node = path.node;
|
|
4943
4961
|
if (node.directives === undefined || node.directives.length === 0) {
|
|
4944
4962
|
return "";
|
|
4945
4963
|
}
|
|
@@ -4951,7 +4969,7 @@ function printDirective(path, options, print) {
|
|
|
4951
4969
|
return ["#", path.call(print, "target"), " ", args];
|
|
4952
4970
|
}
|
|
4953
4971
|
function printDecoratorArgs(path, options, print) {
|
|
4954
|
-
const node = path.
|
|
4972
|
+
const node = path.node;
|
|
4955
4973
|
if (node.arguments.length === 0) {
|
|
4956
4974
|
return "";
|
|
4957
4975
|
}
|
|
@@ -4979,7 +4997,7 @@ function printDecoratorArgs(path, options, print) {
|
|
|
4979
4997
|
];
|
|
4980
4998
|
}
|
|
4981
4999
|
function printDirectiveArgs(path, options, print) {
|
|
4982
|
-
const node = path.
|
|
5000
|
+
const node = path.node;
|
|
4983
5001
|
if (node.arguments.length === 0) {
|
|
4984
5002
|
return "";
|
|
4985
5003
|
}
|
|
@@ -4991,7 +5009,7 @@ function printEnumStatement(path, options, print) {
|
|
|
4991
5009
|
return [decorators, "enum ", id, " ", printEnumBlock(path, options, print)];
|
|
4992
5010
|
}
|
|
4993
5011
|
function printEnumBlock(path, options, print) {
|
|
4994
|
-
const node = path.
|
|
5012
|
+
const node = path.node;
|
|
4995
5013
|
if (node.members.length === 0) {
|
|
4996
5014
|
return "{}";
|
|
4997
5015
|
}
|
|
@@ -4999,7 +5017,7 @@ function printEnumBlock(path, options, print) {
|
|
|
4999
5017
|
return group(["{", indent(body), hardline, "}"]);
|
|
5000
5018
|
}
|
|
5001
5019
|
function printEnumMember(path, options, print) {
|
|
5002
|
-
const node = path.
|
|
5020
|
+
const node = path.node;
|
|
5003
5021
|
const id = path.call(print, "id");
|
|
5004
5022
|
const value = node.value ? [": ", path.call(print, "value")] : "";
|
|
5005
5023
|
const { decorators } = printDecorators(path, options, print, {
|
|
@@ -5017,7 +5035,7 @@ function printUnionStatement(path, options, print) {
|
|
|
5017
5035
|
return [decorators, "union ", id, generic, " ", printUnionVariantsBlock(path, options, print)];
|
|
5018
5036
|
}
|
|
5019
5037
|
function printUnionVariantsBlock(path, options, print) {
|
|
5020
|
-
const node = path.
|
|
5038
|
+
const node = path.node;
|
|
5021
5039
|
if (node.options.length === 0) {
|
|
5022
5040
|
return "{}";
|
|
5023
5041
|
}
|
|
@@ -5047,7 +5065,7 @@ function printInterfaceStatement(path, options, print) {
|
|
|
5047
5065
|
];
|
|
5048
5066
|
}
|
|
5049
5067
|
function printInterfaceExtends(path, options, print) {
|
|
5050
|
-
const node = path.
|
|
5068
|
+
const node = path.node;
|
|
5051
5069
|
if (node.extends.length === 0) {
|
|
5052
5070
|
return "";
|
|
5053
5071
|
}
|
|
@@ -5055,7 +5073,7 @@ function printInterfaceExtends(path, options, print) {
|
|
|
5055
5073
|
return [group(indent([line, keyword, indent(join([",", line], path.map(print, "extends")))]))];
|
|
5056
5074
|
}
|
|
5057
5075
|
function printInterfaceMembers(path, options, print) {
|
|
5058
|
-
const node = path.
|
|
5076
|
+
const node = path.node;
|
|
5059
5077
|
const hasOperations = node.operations.length > 0;
|
|
5060
5078
|
const nodeHasComments = hasComments(node, CommentCheckFlags.Dangling);
|
|
5061
5079
|
if (!hasOperations && !nodeHasComments) {
|
|
@@ -5064,7 +5082,7 @@ function printInterfaceMembers(path, options, print) {
|
|
|
5064
5082
|
const lastOperation = node.operations[node.operations.length - 1];
|
|
5065
5083
|
const parts = [];
|
|
5066
5084
|
path.each((operationPath) => {
|
|
5067
|
-
const node = operationPath.
|
|
5085
|
+
const node = operationPath.node;
|
|
5068
5086
|
const printed = print(operationPath);
|
|
5069
5087
|
parts.push(printed);
|
|
5070
5088
|
if (node !== lastOperation) {
|
|
@@ -5081,13 +5099,13 @@ function printInterfaceMembers(path, options, print) {
|
|
|
5081
5099
|
return group(["{", indent(body), hardline, "}"]);
|
|
5082
5100
|
}
|
|
5083
5101
|
function printDanglingComments(path, options, { sameIndent }) {
|
|
5084
|
-
const node = path.
|
|
5102
|
+
const node = path.node;
|
|
5085
5103
|
const parts = [];
|
|
5086
5104
|
if (!node || !node.comments) {
|
|
5087
5105
|
return "";
|
|
5088
5106
|
}
|
|
5089
5107
|
path.each((commentPath) => {
|
|
5090
|
-
const comment = commentPath.
|
|
5108
|
+
const comment = commentPath.node;
|
|
5091
5109
|
if (!comment.leading && !comment.trailing) {
|
|
5092
5110
|
parts.push(printComment(path, options));
|
|
5093
5111
|
}
|
|
@@ -5110,7 +5128,7 @@ function printDanglingComments(path, options, { sameIndent }) {
|
|
|
5110
5128
|
* @returns Prettier document.
|
|
5111
5129
|
*/
|
|
5112
5130
|
function printIntersection(path, options, print) {
|
|
5113
|
-
const node = path.
|
|
5131
|
+
const node = path.node;
|
|
5114
5132
|
const types = path.map(print, "options");
|
|
5115
5133
|
const result = [];
|
|
5116
5134
|
let wasIndented = false;
|
|
@@ -5151,12 +5169,12 @@ function printTuple(path, options, print) {
|
|
|
5151
5169
|
]);
|
|
5152
5170
|
}
|
|
5153
5171
|
function printMemberExpression(path, options, print) {
|
|
5154
|
-
const node = path.
|
|
5172
|
+
const node = path.node;
|
|
5155
5173
|
return [node.base ? [path.call(print, "base"), node.selector] : "", path.call(print, "id")];
|
|
5156
5174
|
}
|
|
5157
5175
|
function printModelExpression(path, options, print) {
|
|
5158
5176
|
const inBlock = isModelExpressionInBlock(path);
|
|
5159
|
-
const node = path.
|
|
5177
|
+
const node = path.node;
|
|
5160
5178
|
if (inBlock) {
|
|
5161
5179
|
return group(printModelPropertiesBlock(path, options, print));
|
|
5162
5180
|
}
|
|
@@ -5168,7 +5186,7 @@ function printModelExpression(path, options, print) {
|
|
|
5168
5186
|
}
|
|
5169
5187
|
}
|
|
5170
5188
|
function printModelStatement(path, options, print) {
|
|
5171
|
-
const node = path.
|
|
5189
|
+
const node = path.node;
|
|
5172
5190
|
const id = path.call(print, "id");
|
|
5173
5191
|
const heritage = node.extends
|
|
5174
5192
|
? [ifBreak(line, " "), "extends ", path.call(print, "extends")]
|
|
@@ -5189,7 +5207,7 @@ function printModelStatement(path, options, print) {
|
|
|
5189
5207
|
}
|
|
5190
5208
|
function printModelPropertiesBlock(path, options, print) {
|
|
5191
5209
|
var _a;
|
|
5192
|
-
const node = path.
|
|
5210
|
+
const node = path.node;
|
|
5193
5211
|
const hasProperties = node.properties && node.properties.length > 0;
|
|
5194
5212
|
const nodeHasComments = hasComments(node, CommentCheckFlags.Dangling);
|
|
5195
5213
|
if (!hasProperties && !nodeHasComments) {
|
|
@@ -5215,7 +5233,7 @@ function printModelPropertiesBlock(path, options, print) {
|
|
|
5215
5233
|
*/
|
|
5216
5234
|
function joinMembersInBlock(path, member, options, print, separator, regularLine = hardline) {
|
|
5217
5235
|
const doc = [regularLine];
|
|
5218
|
-
const propertyContainerNode = path.
|
|
5236
|
+
const propertyContainerNode = path.node;
|
|
5219
5237
|
let newLineBeforeNextProp = false;
|
|
5220
5238
|
path.each((item, propertyIndex) => {
|
|
5221
5239
|
const isFirst = propertyIndex === 0;
|
|
@@ -5247,7 +5265,7 @@ function joinMembersInBlock(path, member, options, print, separator, regularLine
|
|
|
5247
5265
|
*/
|
|
5248
5266
|
function shouldWrapMemberInNewLines(path, options) {
|
|
5249
5267
|
var _a;
|
|
5250
|
-
const node = path.
|
|
5268
|
+
const node = path.node;
|
|
5251
5269
|
return ((node.kind !== SyntaxKind.ModelSpreadProperty &&
|
|
5252
5270
|
node.kind !== SyntaxKind.ProjectionModelSpreadProperty &&
|
|
5253
5271
|
node.kind !== SyntaxKind.EnumSpreadMember &&
|
|
@@ -5263,7 +5281,7 @@ function shouldWrapMemberInNewLines(path, options) {
|
|
|
5263
5281
|
*/
|
|
5264
5282
|
function isModelAValue(path) {
|
|
5265
5283
|
let count = 0;
|
|
5266
|
-
let node = path.
|
|
5284
|
+
let node = path.node;
|
|
5267
5285
|
do {
|
|
5268
5286
|
switch (node.kind) {
|
|
5269
5287
|
case SyntaxKind.ModelStatement:
|
|
@@ -5277,7 +5295,7 @@ function isModelAValue(path) {
|
|
|
5277
5295
|
return true;
|
|
5278
5296
|
}
|
|
5279
5297
|
function printModelProperty(path, options, print) {
|
|
5280
|
-
const node = path.
|
|
5298
|
+
const node = path.node;
|
|
5281
5299
|
const { decorators } = printDecorators(path, options, print, {
|
|
5282
5300
|
tryInline: DecoratorsTryInline.modelProperty,
|
|
5283
5301
|
});
|
|
@@ -5335,7 +5353,7 @@ function isModelExpressionInBlock(path) {
|
|
|
5335
5353
|
}
|
|
5336
5354
|
}
|
|
5337
5355
|
function printScalarStatement(path, options, print) {
|
|
5338
|
-
const node = path.
|
|
5356
|
+
const node = path.node;
|
|
5339
5357
|
const id = path.call(print, "id");
|
|
5340
5358
|
const template = printTemplateParameters(path, options, print, "templateParameters");
|
|
5341
5359
|
const heritage = node.extends
|
|
@@ -5387,11 +5405,11 @@ function printOperationStatement(path, options, print) {
|
|
|
5387
5405
|
];
|
|
5388
5406
|
}
|
|
5389
5407
|
function printStatementSequence(path, options, print, property) {
|
|
5390
|
-
const node = path.
|
|
5408
|
+
const node = path.node;
|
|
5391
5409
|
const parts = [];
|
|
5392
5410
|
const lastStatement = getLastStatement(node[property]);
|
|
5393
5411
|
path.each((statementPath) => {
|
|
5394
|
-
const node = path.
|
|
5412
|
+
const node = path.node;
|
|
5395
5413
|
if (node.kind === SyntaxKind.EmptyStatement) {
|
|
5396
5414
|
return;
|
|
5397
5415
|
}
|
|
@@ -5416,7 +5434,7 @@ function getLastStatement(statements) {
|
|
|
5416
5434
|
return undefined;
|
|
5417
5435
|
}
|
|
5418
5436
|
function printUnion(path, options, print) {
|
|
5419
|
-
const node = path.
|
|
5437
|
+
const node = path.node;
|
|
5420
5438
|
const shouldHug = shouldHugType(node);
|
|
5421
5439
|
const types = path.map((typePath) => {
|
|
5422
5440
|
let printedType = print(typePath);
|
|
@@ -5443,7 +5461,7 @@ function printTypeReference(path, options, print) {
|
|
|
5443
5461
|
return [type, template];
|
|
5444
5462
|
}
|
|
5445
5463
|
function printTemplateArgument(path, _options, print) {
|
|
5446
|
-
if (path.
|
|
5464
|
+
if (path.node.name !== undefined) {
|
|
5447
5465
|
const name = path.call(print, "name");
|
|
5448
5466
|
const argument = path.call(print, "argument");
|
|
5449
5467
|
return group([name, " = ", argument]);
|
|
@@ -5457,7 +5475,7 @@ function printValueOfExpression(path, options, print) {
|
|
|
5457
5475
|
return ["valueof ", type];
|
|
5458
5476
|
}
|
|
5459
5477
|
function printTemplateParameterDeclaration(path, options, print) {
|
|
5460
|
-
const node = path.
|
|
5478
|
+
const node = path.node;
|
|
5461
5479
|
return [
|
|
5462
5480
|
path.call(print, "id"),
|
|
5463
5481
|
node.constraint ? [" extends ", path.call(print, "constraint")] : "",
|
|
@@ -5481,7 +5499,7 @@ function printDecoratorDeclarationStatement(path, options, print) {
|
|
|
5481
5499
|
return [printModifiers(path, options, print), "dec ", id, "(", parameters, ")", ";"];
|
|
5482
5500
|
}
|
|
5483
5501
|
function printFunctionDeclarationStatement(path, options, print) {
|
|
5484
|
-
const node = path.
|
|
5502
|
+
const node = path.node;
|
|
5485
5503
|
const id = path.call(print, "id");
|
|
5486
5504
|
const parameters = [
|
|
5487
5505
|
group([
|
|
@@ -5493,7 +5511,7 @@ function printFunctionDeclarationStatement(path, options, print) {
|
|
|
5493
5511
|
return [printModifiers(path, options, print), "fn ", id, "(", parameters, ")", returnType, ";"];
|
|
5494
5512
|
}
|
|
5495
5513
|
function printFunctionParameterDeclaration(path, options, print) {
|
|
5496
|
-
const node = path.
|
|
5514
|
+
const node = path.node;
|
|
5497
5515
|
const id = path.call(print, "id");
|
|
5498
5516
|
const type = node.type ? [": ", path.call(print, "type")] : "";
|
|
5499
5517
|
return [
|
|
@@ -5505,22 +5523,22 @@ function printFunctionParameterDeclaration(path, options, print) {
|
|
|
5505
5523
|
];
|
|
5506
5524
|
}
|
|
5507
5525
|
function printModifiers(path, options, print) {
|
|
5508
|
-
const node = path.
|
|
5526
|
+
const node = path.node;
|
|
5509
5527
|
if (node.modifiers.length === 0) {
|
|
5510
5528
|
return "";
|
|
5511
5529
|
}
|
|
5512
5530
|
return path.map((x) => [print(x), " "], "modifiers");
|
|
5513
5531
|
}
|
|
5514
5532
|
function printStringLiteral(path, options) {
|
|
5515
|
-
const node = path.
|
|
5533
|
+
const node = path.node;
|
|
5516
5534
|
return getRawText(node, options);
|
|
5517
5535
|
}
|
|
5518
5536
|
function printNumberLiteral(path, options) {
|
|
5519
|
-
const node = path.
|
|
5537
|
+
const node = path.node;
|
|
5520
5538
|
return getRawText(node, options);
|
|
5521
5539
|
}
|
|
5522
5540
|
function printBooleanLiteral(path, options) {
|
|
5523
|
-
const node = path.
|
|
5541
|
+
const node = path.node;
|
|
5524
5542
|
return node.value ? "true" : "false";
|
|
5525
5543
|
}
|
|
5526
5544
|
function printProjectionStatement(path, options, print) {
|
|
@@ -5539,7 +5557,7 @@ function printProjectionStatement(path, options, print) {
|
|
|
5539
5557
|
];
|
|
5540
5558
|
}
|
|
5541
5559
|
function printProjection(path, options, print) {
|
|
5542
|
-
const node = path.
|
|
5560
|
+
const node = path.node;
|
|
5543
5561
|
const params = printProjectionParameters(path, options, print);
|
|
5544
5562
|
const body = printProjectionExpressionStatements(path, options, print, "body");
|
|
5545
5563
|
return [
|
|
@@ -5553,7 +5571,7 @@ function printProjection(path, options, print) {
|
|
|
5553
5571
|
];
|
|
5554
5572
|
}
|
|
5555
5573
|
function printProjectionParameters(path, options, print) {
|
|
5556
|
-
const node = path.
|
|
5574
|
+
const node = path.node;
|
|
5557
5575
|
const params = node.parameters;
|
|
5558
5576
|
if (params.length === 0) {
|
|
5559
5577
|
return "";
|
|
@@ -5569,9 +5587,9 @@ function printProjectionParameters(path, options, print) {
|
|
|
5569
5587
|
}
|
|
5570
5588
|
function printProjectionExpressionStatements(path, options, print, key) {
|
|
5571
5589
|
const parts = [hardline];
|
|
5572
|
-
const lastIndex = path.
|
|
5590
|
+
const lastIndex = path.node[key].length - 1;
|
|
5573
5591
|
path.each((statementPath, index) => {
|
|
5574
|
-
const node = path.
|
|
5592
|
+
const node = path.node;
|
|
5575
5593
|
if (node.kind === SyntaxKind.EmptyStatement) {
|
|
5576
5594
|
return;
|
|
5577
5595
|
}
|
|
@@ -5594,14 +5612,14 @@ function printProjectionExpressionStatement(path, options, print) {
|
|
|
5594
5612
|
return path.call(print, "expr");
|
|
5595
5613
|
}
|
|
5596
5614
|
function printProjectionIfExpressionNode(path, options, print) {
|
|
5597
|
-
const node = path.
|
|
5615
|
+
const node = path.node;
|
|
5598
5616
|
const test = path.call(print, "test");
|
|
5599
5617
|
const consequent = path.call(print, "consequent");
|
|
5600
5618
|
const alternate = node.alternate ? [" else ", path.call(print, "alternate")] : "";
|
|
5601
5619
|
return ["if ", test, " ", consequent, alternate];
|
|
5602
5620
|
}
|
|
5603
5621
|
function printProjectionBlockExpressionNode(path, options, print) {
|
|
5604
|
-
const node = path.
|
|
5622
|
+
const node = path.node;
|
|
5605
5623
|
if (node.statements.length === 0) {
|
|
5606
5624
|
return "{}";
|
|
5607
5625
|
}
|
|
@@ -5613,18 +5631,18 @@ function printProjectionBlockExpressionNode(path, options, print) {
|
|
|
5613
5631
|
];
|
|
5614
5632
|
}
|
|
5615
5633
|
function printProjectionMemberExpression(path, options, print) {
|
|
5616
|
-
const node = path.
|
|
5634
|
+
const node = path.node;
|
|
5617
5635
|
return [path.call(print, "base"), node.selector, path.call(print, "id")];
|
|
5618
5636
|
}
|
|
5619
5637
|
function printProjectionLeftRightExpression(path, options, print) {
|
|
5620
|
-
const node = path.
|
|
5638
|
+
const node = path.node;
|
|
5621
5639
|
return [path.call(print, "left"), " ", node.op, " ", path.call(print, "right")];
|
|
5622
5640
|
}
|
|
5623
5641
|
function printProjectionUnaryExpression(path, options, print) {
|
|
5624
5642
|
return ["!", path.call(print, "target")];
|
|
5625
5643
|
}
|
|
5626
5644
|
function printProjectionCallExpression(path, options, print) {
|
|
5627
|
-
const node = path.
|
|
5645
|
+
const node = path.node;
|
|
5628
5646
|
const target = path.call(print, "target");
|
|
5629
5647
|
const params = printItemList(path, options, print, "arguments");
|
|
5630
5648
|
if (node.callKind === "method") {
|