vite-plugin-simple-macro 0.0.9
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.d.ts +26 -0
- package/dist/index.js +5063 -0
- package/dist/index.mjs +5062 -0
- package/package.json +39 -0
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,5062 @@
|
|
|
1
|
+
import { parseAsync, traverse, types } from "@babel/core";
|
|
2
|
+
import * as _t from "@babel/types";
|
|
3
|
+
//#region \0rolldown/runtime.js
|
|
4
|
+
var __create = Object.create;
|
|
5
|
+
var __defProp = Object.defineProperty;
|
|
6
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
7
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
8
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
9
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
10
|
+
var __commonJSMin = (cb, mod) => () => (mod || (cb((mod = { exports: {} }).exports, mod), cb = null), mod.exports);
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
13
|
+
key = keys[i];
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
15
|
+
get: ((k) => from[k]).bind(null, key),
|
|
16
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
return to;
|
|
20
|
+
};
|
|
21
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
22
|
+
value: mod,
|
|
23
|
+
enumerable: true
|
|
24
|
+
}) : target, mod));
|
|
25
|
+
//#endregion
|
|
26
|
+
//#region node_modules/@rolldown/pluginutils/dist/filter-B_mD-HGz.mjs
|
|
27
|
+
var postfixRE = /[?#].*$/;
|
|
28
|
+
function cleanUrl(url) {
|
|
29
|
+
return url.replace(postfixRE, "");
|
|
30
|
+
}
|
|
31
|
+
function extractQueryWithoutFragment(url) {
|
|
32
|
+
const questionMarkIndex = url.indexOf("?");
|
|
33
|
+
if (questionMarkIndex === -1) return "";
|
|
34
|
+
const fragmentIndex = url.indexOf("#", questionMarkIndex);
|
|
35
|
+
if (fragmentIndex === -1) return url.substring(questionMarkIndex);
|
|
36
|
+
else return url.substring(questionMarkIndex, fragmentIndex);
|
|
37
|
+
}
|
|
38
|
+
var And = class {
|
|
39
|
+
kind;
|
|
40
|
+
args;
|
|
41
|
+
constructor(...args) {
|
|
42
|
+
if (args.length === 0) throw new Error("`And` expects at least one operand");
|
|
43
|
+
this.args = args;
|
|
44
|
+
this.kind = "and";
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
var Or = class {
|
|
48
|
+
kind;
|
|
49
|
+
args;
|
|
50
|
+
constructor(...args) {
|
|
51
|
+
if (args.length === 0) throw new Error("`Or` expects at least one operand");
|
|
52
|
+
this.args = args;
|
|
53
|
+
this.kind = "or";
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
var Id = class {
|
|
57
|
+
kind;
|
|
58
|
+
pattern;
|
|
59
|
+
params;
|
|
60
|
+
constructor(pattern, params) {
|
|
61
|
+
this.pattern = pattern;
|
|
62
|
+
this.kind = "id";
|
|
63
|
+
this.params = params ?? { cleanUrl: false };
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
var Include = class {
|
|
67
|
+
kind;
|
|
68
|
+
expr;
|
|
69
|
+
constructor(expr) {
|
|
70
|
+
this.expr = expr;
|
|
71
|
+
this.kind = "include";
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
function and(...args) {
|
|
75
|
+
return new And(...args);
|
|
76
|
+
}
|
|
77
|
+
function or(...args) {
|
|
78
|
+
return new Or(...args);
|
|
79
|
+
}
|
|
80
|
+
function id(pattern, params) {
|
|
81
|
+
return new Id(pattern, params);
|
|
82
|
+
}
|
|
83
|
+
function include(expr) {
|
|
84
|
+
return new Include(expr);
|
|
85
|
+
}
|
|
86
|
+
function exprInterpreter(expr, code, id, moduleType, importerId, ctx = {}) {
|
|
87
|
+
switch (expr.kind) {
|
|
88
|
+
case "and": return expr.args.every((e) => exprInterpreter(e, code, id, moduleType, importerId, ctx));
|
|
89
|
+
case "or": return expr.args.some((e) => exprInterpreter(e, code, id, moduleType, importerId, ctx));
|
|
90
|
+
case "not": return !exprInterpreter(expr.expr, code, id, moduleType, importerId, ctx);
|
|
91
|
+
case "id": {
|
|
92
|
+
if (id === void 0) throw new Error("`id` is required for `id` expression");
|
|
93
|
+
let idToMatch = id;
|
|
94
|
+
if (expr.params.cleanUrl) idToMatch = cleanUrl(idToMatch);
|
|
95
|
+
return typeof expr.pattern === "string" ? idToMatch === expr.pattern : expr.pattern.test(idToMatch);
|
|
96
|
+
}
|
|
97
|
+
case "importerId": {
|
|
98
|
+
if (importerId === void 0) return false;
|
|
99
|
+
let importerIdToMatch = importerId;
|
|
100
|
+
if (expr.params.cleanUrl) importerIdToMatch = cleanUrl(importerIdToMatch);
|
|
101
|
+
return typeof expr.pattern === "string" ? importerIdToMatch === expr.pattern : expr.pattern.test(importerIdToMatch);
|
|
102
|
+
}
|
|
103
|
+
case "moduleType":
|
|
104
|
+
if (moduleType === void 0) throw new Error("`moduleType` is required for `moduleType` expression");
|
|
105
|
+
return moduleType === expr.pattern;
|
|
106
|
+
case "code":
|
|
107
|
+
if (code === void 0) throw new Error("`code` is required for `code` expression");
|
|
108
|
+
return typeof expr.pattern === "string" ? code.includes(expr.pattern) : expr.pattern.test(code);
|
|
109
|
+
case "query": {
|
|
110
|
+
if (id === void 0) throw new Error("`id` is required for `Query` expression");
|
|
111
|
+
if (!ctx.urlSearchParamsCache) {
|
|
112
|
+
let queryString = extractQueryWithoutFragment(id);
|
|
113
|
+
ctx.urlSearchParamsCache = new URLSearchParams(queryString);
|
|
114
|
+
}
|
|
115
|
+
let urlParams = ctx.urlSearchParamsCache;
|
|
116
|
+
if (typeof expr.pattern === "boolean") if (expr.pattern) return urlParams.has(expr.key);
|
|
117
|
+
else return !urlParams.has(expr.key);
|
|
118
|
+
else if (typeof expr.pattern === "string") return urlParams.get(expr.key) === expr.pattern;
|
|
119
|
+
else return expr.pattern.test(urlParams.get(expr.key) ?? "");
|
|
120
|
+
}
|
|
121
|
+
default: throw new Error(`Expression ${JSON.stringify(expr)} is not expected.`);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
function makeIdFiltersToMatchWithQuery(input) {
|
|
125
|
+
if (!Array.isArray(input)) return makeIdFilterToMatchWithQuery(input);
|
|
126
|
+
return input.map((i) => makeIdFilterToMatchWithQuery(i));
|
|
127
|
+
}
|
|
128
|
+
function makeIdFilterToMatchWithQuery(input) {
|
|
129
|
+
if (typeof input === "string") return `${input}{?*,}`;
|
|
130
|
+
return makeRegexIdFilterToMatchWithQuery(input);
|
|
131
|
+
}
|
|
132
|
+
function makeRegexIdFilterToMatchWithQuery(input) {
|
|
133
|
+
return new RegExp(input.source.replace(/(?<!\\)\$/g, "(?:\\?.*)?$"), input.flags);
|
|
134
|
+
}
|
|
135
|
+
//#endregion
|
|
136
|
+
//#region node_modules/@jridgewell/sourcemap-codec/dist/sourcemap-codec.mjs
|
|
137
|
+
var comma = ",".charCodeAt(0);
|
|
138
|
+
var semicolon = ";".charCodeAt(0);
|
|
139
|
+
var chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
|
140
|
+
var intToChar = /* @__PURE__ */ new Uint8Array(64);
|
|
141
|
+
var charToInt = /* @__PURE__ */ new Uint8Array(128);
|
|
142
|
+
for (let i = 0; i < chars.length; i++) {
|
|
143
|
+
const c = chars.charCodeAt(i);
|
|
144
|
+
intToChar[i] = c;
|
|
145
|
+
charToInt[c] = i;
|
|
146
|
+
}
|
|
147
|
+
function decodeInteger(reader, relative) {
|
|
148
|
+
let value = 0;
|
|
149
|
+
let shift = 0;
|
|
150
|
+
let integer = 0;
|
|
151
|
+
do {
|
|
152
|
+
integer = charToInt[reader.next()];
|
|
153
|
+
value |= (integer & 31) << shift;
|
|
154
|
+
shift += 5;
|
|
155
|
+
} while (integer & 32);
|
|
156
|
+
const shouldNegate = value & 1;
|
|
157
|
+
value >>>= 1;
|
|
158
|
+
if (shouldNegate) value = -2147483648 | -value;
|
|
159
|
+
return relative + value;
|
|
160
|
+
}
|
|
161
|
+
function encodeInteger(builder, num, relative) {
|
|
162
|
+
let delta = num - relative;
|
|
163
|
+
delta = delta < 0 ? -delta << 1 | 1 : delta << 1;
|
|
164
|
+
do {
|
|
165
|
+
let clamped = delta & 31;
|
|
166
|
+
delta >>>= 5;
|
|
167
|
+
if (delta > 0) clamped |= 32;
|
|
168
|
+
builder.write(intToChar[clamped]);
|
|
169
|
+
} while (delta > 0);
|
|
170
|
+
return num;
|
|
171
|
+
}
|
|
172
|
+
function hasMoreVlq(reader, max) {
|
|
173
|
+
if (reader.pos >= max) return false;
|
|
174
|
+
return reader.peek() !== comma;
|
|
175
|
+
}
|
|
176
|
+
var bufLength = 1024 * 16;
|
|
177
|
+
var td = typeof TextDecoder !== "undefined" ? /* @__PURE__ */ new TextDecoder() : typeof Buffer !== "undefined" ? { decode(buf) {
|
|
178
|
+
return Buffer.from(buf.buffer, buf.byteOffset, buf.byteLength).toString();
|
|
179
|
+
} } : { decode(buf) {
|
|
180
|
+
let out = "";
|
|
181
|
+
for (let i = 0; i < buf.length; i++) out += String.fromCharCode(buf[i]);
|
|
182
|
+
return out;
|
|
183
|
+
} };
|
|
184
|
+
var StringWriter = class {
|
|
185
|
+
constructor() {
|
|
186
|
+
this.pos = 0;
|
|
187
|
+
this.out = "";
|
|
188
|
+
this.buffer = new Uint8Array(bufLength);
|
|
189
|
+
}
|
|
190
|
+
write(v) {
|
|
191
|
+
const { buffer } = this;
|
|
192
|
+
buffer[this.pos++] = v;
|
|
193
|
+
if (this.pos === bufLength) {
|
|
194
|
+
this.out += td.decode(buffer);
|
|
195
|
+
this.pos = 0;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
flush() {
|
|
199
|
+
const { buffer, out, pos } = this;
|
|
200
|
+
return pos > 0 ? out + td.decode(buffer.subarray(0, pos)) : out;
|
|
201
|
+
}
|
|
202
|
+
};
|
|
203
|
+
var StringReader = class {
|
|
204
|
+
constructor(buffer) {
|
|
205
|
+
this.pos = 0;
|
|
206
|
+
this.buffer = buffer;
|
|
207
|
+
}
|
|
208
|
+
next() {
|
|
209
|
+
return this.buffer.charCodeAt(this.pos++);
|
|
210
|
+
}
|
|
211
|
+
peek() {
|
|
212
|
+
return this.buffer.charCodeAt(this.pos);
|
|
213
|
+
}
|
|
214
|
+
indexOf(char) {
|
|
215
|
+
const { buffer, pos } = this;
|
|
216
|
+
const idx = buffer.indexOf(char, pos);
|
|
217
|
+
return idx === -1 ? buffer.length : idx;
|
|
218
|
+
}
|
|
219
|
+
};
|
|
220
|
+
function decode(mappings) {
|
|
221
|
+
const { length } = mappings;
|
|
222
|
+
const reader = new StringReader(mappings);
|
|
223
|
+
const decoded = [];
|
|
224
|
+
let genColumn = 0;
|
|
225
|
+
let sourcesIndex = 0;
|
|
226
|
+
let sourceLine = 0;
|
|
227
|
+
let sourceColumn = 0;
|
|
228
|
+
let namesIndex = 0;
|
|
229
|
+
do {
|
|
230
|
+
const semi = reader.indexOf(";");
|
|
231
|
+
const line = [];
|
|
232
|
+
let sorted = true;
|
|
233
|
+
let lastCol = 0;
|
|
234
|
+
genColumn = 0;
|
|
235
|
+
while (reader.pos < semi) {
|
|
236
|
+
let seg;
|
|
237
|
+
genColumn = decodeInteger(reader, genColumn);
|
|
238
|
+
if (genColumn < lastCol) sorted = false;
|
|
239
|
+
lastCol = genColumn;
|
|
240
|
+
if (hasMoreVlq(reader, semi)) {
|
|
241
|
+
sourcesIndex = decodeInteger(reader, sourcesIndex);
|
|
242
|
+
sourceLine = decodeInteger(reader, sourceLine);
|
|
243
|
+
sourceColumn = decodeInteger(reader, sourceColumn);
|
|
244
|
+
if (hasMoreVlq(reader, semi)) {
|
|
245
|
+
namesIndex = decodeInteger(reader, namesIndex);
|
|
246
|
+
seg = [
|
|
247
|
+
genColumn,
|
|
248
|
+
sourcesIndex,
|
|
249
|
+
sourceLine,
|
|
250
|
+
sourceColumn,
|
|
251
|
+
namesIndex
|
|
252
|
+
];
|
|
253
|
+
} else seg = [
|
|
254
|
+
genColumn,
|
|
255
|
+
sourcesIndex,
|
|
256
|
+
sourceLine,
|
|
257
|
+
sourceColumn
|
|
258
|
+
];
|
|
259
|
+
} else seg = [genColumn];
|
|
260
|
+
line.push(seg);
|
|
261
|
+
reader.pos++;
|
|
262
|
+
}
|
|
263
|
+
if (!sorted) sort(line);
|
|
264
|
+
decoded.push(line);
|
|
265
|
+
reader.pos = semi + 1;
|
|
266
|
+
} while (reader.pos <= length);
|
|
267
|
+
return decoded;
|
|
268
|
+
}
|
|
269
|
+
function sort(line) {
|
|
270
|
+
line.sort(sortComparator$1);
|
|
271
|
+
}
|
|
272
|
+
function sortComparator$1(a, b) {
|
|
273
|
+
return a[0] - b[0];
|
|
274
|
+
}
|
|
275
|
+
function encode(decoded) {
|
|
276
|
+
const writer = new StringWriter();
|
|
277
|
+
let sourcesIndex = 0;
|
|
278
|
+
let sourceLine = 0;
|
|
279
|
+
let sourceColumn = 0;
|
|
280
|
+
let namesIndex = 0;
|
|
281
|
+
for (let i = 0; i < decoded.length; i++) {
|
|
282
|
+
const line = decoded[i];
|
|
283
|
+
if (i > 0) writer.write(semicolon);
|
|
284
|
+
if (line.length === 0) continue;
|
|
285
|
+
let genColumn = 0;
|
|
286
|
+
for (let j = 0; j < line.length; j++) {
|
|
287
|
+
const segment = line[j];
|
|
288
|
+
if (j > 0) writer.write(comma);
|
|
289
|
+
genColumn = encodeInteger(writer, segment[0], genColumn);
|
|
290
|
+
if (segment.length === 1) continue;
|
|
291
|
+
sourcesIndex = encodeInteger(writer, segment[1], sourcesIndex);
|
|
292
|
+
sourceLine = encodeInteger(writer, segment[2], sourceLine);
|
|
293
|
+
sourceColumn = encodeInteger(writer, segment[3], sourceColumn);
|
|
294
|
+
if (segment.length === 4) continue;
|
|
295
|
+
namesIndex = encodeInteger(writer, segment[4], namesIndex);
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
return writer.flush();
|
|
299
|
+
}
|
|
300
|
+
//#endregion
|
|
301
|
+
//#region node_modules/@jridgewell/trace-mapping/dist/trace-mapping.mjs
|
|
302
|
+
var import_resolve_uri_umd = /* @__PURE__ */ __toESM((/* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
303
|
+
(function(global, factory) {
|
|
304
|
+
typeof exports === "object" && typeof module !== "undefined" ? module.exports = factory() : typeof define === "function" && define.amd ? define(factory) : (global = typeof globalThis !== "undefined" ? globalThis : global || self, global.resolveURI = factory());
|
|
305
|
+
})(exports, (function() {
|
|
306
|
+
"use strict";
|
|
307
|
+
const schemeRegex = /^[\w+.-]+:\/\//;
|
|
308
|
+
/**
|
|
309
|
+
* Matches the parts of a URL:
|
|
310
|
+
* 1. Scheme, including ":", guaranteed.
|
|
311
|
+
* 2. User/password, including "@", optional.
|
|
312
|
+
* 3. Host, guaranteed.
|
|
313
|
+
* 4. Port, including ":", optional.
|
|
314
|
+
* 5. Path, including "/", optional.
|
|
315
|
+
* 6. Query, including "?", optional.
|
|
316
|
+
* 7. Hash, including "#", optional.
|
|
317
|
+
*/
|
|
318
|
+
const urlRegex = /^([\w+.-]+:)\/\/([^@/#?]*@)?([^:/#?]*)(:\d+)?(\/[^#?]*)?(\?[^#]*)?(#.*)?/;
|
|
319
|
+
/**
|
|
320
|
+
* File URLs are weird. They dont' need the regular `//` in the scheme, they may or may not start
|
|
321
|
+
* with a leading `/`, they can have a domain (but only if they don't start with a Windows drive).
|
|
322
|
+
*
|
|
323
|
+
* 1. Host, optional.
|
|
324
|
+
* 2. Path, which may include "/", guaranteed.
|
|
325
|
+
* 3. Query, including "?", optional.
|
|
326
|
+
* 4. Hash, including "#", optional.
|
|
327
|
+
*/
|
|
328
|
+
const fileRegex = /^file:(?:\/\/((?![a-z]:)[^/#?]*)?)?(\/?[^#?]*)(\?[^#]*)?(#.*)?/i;
|
|
329
|
+
function isAbsoluteUrl(input) {
|
|
330
|
+
return schemeRegex.test(input);
|
|
331
|
+
}
|
|
332
|
+
function isSchemeRelativeUrl(input) {
|
|
333
|
+
return input.startsWith("//");
|
|
334
|
+
}
|
|
335
|
+
function isAbsolutePath(input) {
|
|
336
|
+
return input.startsWith("/");
|
|
337
|
+
}
|
|
338
|
+
function isFileUrl(input) {
|
|
339
|
+
return input.startsWith("file:");
|
|
340
|
+
}
|
|
341
|
+
function isRelative(input) {
|
|
342
|
+
return /^[.?#]/.test(input);
|
|
343
|
+
}
|
|
344
|
+
function parseAbsoluteUrl(input) {
|
|
345
|
+
const match = urlRegex.exec(input);
|
|
346
|
+
return makeUrl(match[1], match[2] || "", match[3], match[4] || "", match[5] || "/", match[6] || "", match[7] || "");
|
|
347
|
+
}
|
|
348
|
+
function parseFileUrl(input) {
|
|
349
|
+
const match = fileRegex.exec(input);
|
|
350
|
+
const path = match[2];
|
|
351
|
+
return makeUrl("file:", "", match[1] || "", "", isAbsolutePath(path) ? path : "/" + path, match[3] || "", match[4] || "");
|
|
352
|
+
}
|
|
353
|
+
function makeUrl(scheme, user, host, port, path, query, hash) {
|
|
354
|
+
return {
|
|
355
|
+
scheme,
|
|
356
|
+
user,
|
|
357
|
+
host,
|
|
358
|
+
port,
|
|
359
|
+
path,
|
|
360
|
+
query,
|
|
361
|
+
hash,
|
|
362
|
+
type: 7
|
|
363
|
+
};
|
|
364
|
+
}
|
|
365
|
+
function parseUrl(input) {
|
|
366
|
+
if (isSchemeRelativeUrl(input)) {
|
|
367
|
+
const url = parseAbsoluteUrl("http:" + input);
|
|
368
|
+
url.scheme = "";
|
|
369
|
+
url.type = 6;
|
|
370
|
+
return url;
|
|
371
|
+
}
|
|
372
|
+
if (isAbsolutePath(input)) {
|
|
373
|
+
const url = parseAbsoluteUrl("http://foo.com" + input);
|
|
374
|
+
url.scheme = "";
|
|
375
|
+
url.host = "";
|
|
376
|
+
url.type = 5;
|
|
377
|
+
return url;
|
|
378
|
+
}
|
|
379
|
+
if (isFileUrl(input)) return parseFileUrl(input);
|
|
380
|
+
if (isAbsoluteUrl(input)) return parseAbsoluteUrl(input);
|
|
381
|
+
const url = parseAbsoluteUrl("http://foo.com/" + input);
|
|
382
|
+
url.scheme = "";
|
|
383
|
+
url.host = "";
|
|
384
|
+
url.type = input ? input.startsWith("?") ? 3 : input.startsWith("#") ? 2 : 4 : 1;
|
|
385
|
+
return url;
|
|
386
|
+
}
|
|
387
|
+
function stripPathFilename(path) {
|
|
388
|
+
if (path.endsWith("/..")) return path;
|
|
389
|
+
const index = path.lastIndexOf("/");
|
|
390
|
+
return path.slice(0, index + 1);
|
|
391
|
+
}
|
|
392
|
+
function mergePaths(url, base) {
|
|
393
|
+
normalizePath(base, base.type);
|
|
394
|
+
if (url.path === "/") url.path = base.path;
|
|
395
|
+
else url.path = stripPathFilename(base.path) + url.path;
|
|
396
|
+
}
|
|
397
|
+
/**
|
|
398
|
+
* The path can have empty directories "//", unneeded parents "foo/..", or current directory
|
|
399
|
+
* "foo/.". We need to normalize to a standard representation.
|
|
400
|
+
*/
|
|
401
|
+
function normalizePath(url, type) {
|
|
402
|
+
const rel = type <= 4;
|
|
403
|
+
const pieces = url.path.split("/");
|
|
404
|
+
let pointer = 1;
|
|
405
|
+
let positive = 0;
|
|
406
|
+
let addTrailingSlash = false;
|
|
407
|
+
for (let i = 1; i < pieces.length; i++) {
|
|
408
|
+
const piece = pieces[i];
|
|
409
|
+
if (!piece) {
|
|
410
|
+
addTrailingSlash = true;
|
|
411
|
+
continue;
|
|
412
|
+
}
|
|
413
|
+
addTrailingSlash = false;
|
|
414
|
+
if (piece === ".") continue;
|
|
415
|
+
if (piece === "..") {
|
|
416
|
+
if (positive) {
|
|
417
|
+
addTrailingSlash = true;
|
|
418
|
+
positive--;
|
|
419
|
+
pointer--;
|
|
420
|
+
} else if (rel) pieces[pointer++] = piece;
|
|
421
|
+
continue;
|
|
422
|
+
}
|
|
423
|
+
pieces[pointer++] = piece;
|
|
424
|
+
positive++;
|
|
425
|
+
}
|
|
426
|
+
let path = "";
|
|
427
|
+
for (let i = 1; i < pointer; i++) path += "/" + pieces[i];
|
|
428
|
+
if (!path || addTrailingSlash && !path.endsWith("/..")) path += "/";
|
|
429
|
+
url.path = path;
|
|
430
|
+
}
|
|
431
|
+
/**
|
|
432
|
+
* Attempts to resolve `input` URL/path relative to `base`.
|
|
433
|
+
*/
|
|
434
|
+
function resolve(input, base) {
|
|
435
|
+
if (!input && !base) return "";
|
|
436
|
+
const url = parseUrl(input);
|
|
437
|
+
let inputType = url.type;
|
|
438
|
+
if (base && inputType !== 7) {
|
|
439
|
+
const baseUrl = parseUrl(base);
|
|
440
|
+
const baseType = baseUrl.type;
|
|
441
|
+
switch (inputType) {
|
|
442
|
+
case 1: url.hash = baseUrl.hash;
|
|
443
|
+
case 2: url.query = baseUrl.query;
|
|
444
|
+
case 3:
|
|
445
|
+
case 4: mergePaths(url, baseUrl);
|
|
446
|
+
case 5:
|
|
447
|
+
url.user = baseUrl.user;
|
|
448
|
+
url.host = baseUrl.host;
|
|
449
|
+
url.port = baseUrl.port;
|
|
450
|
+
case 6: url.scheme = baseUrl.scheme;
|
|
451
|
+
}
|
|
452
|
+
if (baseType > inputType) inputType = baseType;
|
|
453
|
+
}
|
|
454
|
+
normalizePath(url, inputType);
|
|
455
|
+
const queryHash = url.query + url.hash;
|
|
456
|
+
switch (inputType) {
|
|
457
|
+
case 2:
|
|
458
|
+
case 3: return queryHash;
|
|
459
|
+
case 4: {
|
|
460
|
+
const path = url.path.slice(1);
|
|
461
|
+
if (!path) return queryHash || ".";
|
|
462
|
+
if (isRelative(base || input) && !isRelative(path)) return "./" + path + queryHash;
|
|
463
|
+
return path + queryHash;
|
|
464
|
+
}
|
|
465
|
+
case 5: return url.path + queryHash;
|
|
466
|
+
default: return url.scheme + "//" + url.user + url.host + url.port + url.path + queryHash;
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
return resolve;
|
|
470
|
+
}));
|
|
471
|
+
})))(), 1);
|
|
472
|
+
function stripFilename(path) {
|
|
473
|
+
if (!path) return "";
|
|
474
|
+
const index = path.lastIndexOf("/");
|
|
475
|
+
return path.slice(0, index + 1);
|
|
476
|
+
}
|
|
477
|
+
function resolver(mapUrl, sourceRoot) {
|
|
478
|
+
const from = stripFilename(mapUrl);
|
|
479
|
+
const prefix = sourceRoot ? sourceRoot + "/" : "";
|
|
480
|
+
return (source) => (0, import_resolve_uri_umd.default)(prefix + (source || ""), from);
|
|
481
|
+
}
|
|
482
|
+
var COLUMN$1 = 0;
|
|
483
|
+
var SOURCES_INDEX$1 = 1;
|
|
484
|
+
var SOURCE_LINE$1 = 2;
|
|
485
|
+
var SOURCE_COLUMN$1 = 3;
|
|
486
|
+
var NAMES_INDEX$1 = 4;
|
|
487
|
+
function maybeSort(mappings, owned) {
|
|
488
|
+
const unsortedIndex = nextUnsortedSegmentLine(mappings, 0);
|
|
489
|
+
if (unsortedIndex === mappings.length) return mappings;
|
|
490
|
+
if (!owned) mappings = mappings.slice();
|
|
491
|
+
for (let i = unsortedIndex; i < mappings.length; i = nextUnsortedSegmentLine(mappings, i + 1)) mappings[i] = sortSegments(mappings[i], owned);
|
|
492
|
+
return mappings;
|
|
493
|
+
}
|
|
494
|
+
function nextUnsortedSegmentLine(mappings, start) {
|
|
495
|
+
for (let i = start; i < mappings.length; i++) if (!isSorted(mappings[i])) return i;
|
|
496
|
+
return mappings.length;
|
|
497
|
+
}
|
|
498
|
+
function isSorted(line) {
|
|
499
|
+
for (let j = 1; j < line.length; j++) if (line[j][COLUMN$1] < line[j - 1][COLUMN$1]) return false;
|
|
500
|
+
return true;
|
|
501
|
+
}
|
|
502
|
+
function sortSegments(line, owned) {
|
|
503
|
+
if (!owned) line = line.slice();
|
|
504
|
+
return line.sort(sortComparator);
|
|
505
|
+
}
|
|
506
|
+
function sortComparator(a, b) {
|
|
507
|
+
return a[COLUMN$1] - b[COLUMN$1];
|
|
508
|
+
}
|
|
509
|
+
var found = false;
|
|
510
|
+
function binarySearch(haystack, needle, low, high) {
|
|
511
|
+
while (low <= high) {
|
|
512
|
+
const mid = low + (high - low >> 1);
|
|
513
|
+
const cmp = haystack[mid][COLUMN$1] - needle;
|
|
514
|
+
if (cmp === 0) {
|
|
515
|
+
found = true;
|
|
516
|
+
return mid;
|
|
517
|
+
}
|
|
518
|
+
if (cmp < 0) low = mid + 1;
|
|
519
|
+
else high = mid - 1;
|
|
520
|
+
}
|
|
521
|
+
found = false;
|
|
522
|
+
return low - 1;
|
|
523
|
+
}
|
|
524
|
+
function upperBound(haystack, needle, index) {
|
|
525
|
+
for (let i = index + 1; i < haystack.length; index = i++) if (haystack[i][COLUMN$1] !== needle) break;
|
|
526
|
+
return index;
|
|
527
|
+
}
|
|
528
|
+
function lowerBound(haystack, needle, index) {
|
|
529
|
+
for (let i = index - 1; i >= 0; index = i--) if (haystack[i][COLUMN$1] !== needle) break;
|
|
530
|
+
return index;
|
|
531
|
+
}
|
|
532
|
+
function memoizedState() {
|
|
533
|
+
return {
|
|
534
|
+
lastKey: -1,
|
|
535
|
+
lastNeedle: -1,
|
|
536
|
+
lastIndex: -1
|
|
537
|
+
};
|
|
538
|
+
}
|
|
539
|
+
function memoizedBinarySearch(haystack, needle, state, key) {
|
|
540
|
+
const { lastKey, lastNeedle, lastIndex } = state;
|
|
541
|
+
let low = 0;
|
|
542
|
+
let high = haystack.length - 1;
|
|
543
|
+
if (key === lastKey) {
|
|
544
|
+
if (needle === lastNeedle) {
|
|
545
|
+
found = lastIndex !== -1 && haystack[lastIndex][COLUMN$1] === needle;
|
|
546
|
+
return lastIndex;
|
|
547
|
+
}
|
|
548
|
+
if (needle >= lastNeedle) low = lastIndex === -1 ? 0 : lastIndex;
|
|
549
|
+
else high = lastIndex;
|
|
550
|
+
}
|
|
551
|
+
state.lastKey = key;
|
|
552
|
+
state.lastNeedle = needle;
|
|
553
|
+
return state.lastIndex = binarySearch(haystack, needle, low, high);
|
|
554
|
+
}
|
|
555
|
+
function parse(map) {
|
|
556
|
+
return typeof map === "string" ? JSON.parse(map) : map;
|
|
557
|
+
}
|
|
558
|
+
var LINE_GTR_ZERO = "`line` must be greater than 0 (lines start at line 1)";
|
|
559
|
+
var COL_GTR_EQ_ZERO = "`column` must be greater than or equal to 0 (columns start at column 0)";
|
|
560
|
+
var TraceMap = class {
|
|
561
|
+
constructor(map, mapUrl) {
|
|
562
|
+
const isString = typeof map === "string";
|
|
563
|
+
if (!isString && map._decodedMemo) return map;
|
|
564
|
+
const parsed = parse(map);
|
|
565
|
+
const { version, file, names, sourceRoot, sources, sourcesContent } = parsed;
|
|
566
|
+
this.version = version;
|
|
567
|
+
this.file = file;
|
|
568
|
+
this.names = names || [];
|
|
569
|
+
this.sourceRoot = sourceRoot;
|
|
570
|
+
this.sources = sources;
|
|
571
|
+
this.sourcesContent = sourcesContent;
|
|
572
|
+
this.ignoreList = parsed.ignoreList || parsed.x_google_ignoreList || void 0;
|
|
573
|
+
const resolve = resolver(mapUrl, sourceRoot);
|
|
574
|
+
this.resolvedSources = sources.map(resolve);
|
|
575
|
+
const { mappings } = parsed;
|
|
576
|
+
if (typeof mappings === "string") {
|
|
577
|
+
this._encoded = mappings;
|
|
578
|
+
this._decoded = void 0;
|
|
579
|
+
} else if (Array.isArray(mappings)) {
|
|
580
|
+
this._encoded = void 0;
|
|
581
|
+
this._decoded = maybeSort(mappings, isString);
|
|
582
|
+
} else if (parsed.sections) throw new Error(`TraceMap passed sectioned source map, please use FlattenMap export instead`);
|
|
583
|
+
else throw new Error(`invalid source map: ${JSON.stringify(parsed)}`);
|
|
584
|
+
this._decodedMemo = memoizedState();
|
|
585
|
+
this._bySources = void 0;
|
|
586
|
+
this._bySourceMemos = void 0;
|
|
587
|
+
}
|
|
588
|
+
};
|
|
589
|
+
function cast$1(map) {
|
|
590
|
+
return map;
|
|
591
|
+
}
|
|
592
|
+
function decodedMappings(map) {
|
|
593
|
+
var _a;
|
|
594
|
+
return (_a = cast$1(map))._decoded || (_a._decoded = decode(cast$1(map)._encoded));
|
|
595
|
+
}
|
|
596
|
+
function originalPositionFor(map, needle) {
|
|
597
|
+
let { line, column, bias } = needle;
|
|
598
|
+
line--;
|
|
599
|
+
if (line < 0) throw new Error(LINE_GTR_ZERO);
|
|
600
|
+
if (column < 0) throw new Error(COL_GTR_EQ_ZERO);
|
|
601
|
+
const decoded = decodedMappings(map);
|
|
602
|
+
if (line >= decoded.length) return OMapping(null, null, null, null);
|
|
603
|
+
const segments = decoded[line];
|
|
604
|
+
const index = traceSegmentInternal(segments, cast$1(map)._decodedMemo, line, column, bias || 1);
|
|
605
|
+
if (index === -1) return OMapping(null, null, null, null);
|
|
606
|
+
const segment = segments[index];
|
|
607
|
+
if (segment.length === 1) return OMapping(null, null, null, null);
|
|
608
|
+
const { names, resolvedSources } = map;
|
|
609
|
+
return OMapping(resolvedSources[segment[SOURCES_INDEX$1]], segment[SOURCE_LINE$1] + 1, segment[SOURCE_COLUMN$1], segment.length === 5 ? names[segment[NAMES_INDEX$1]] : null);
|
|
610
|
+
}
|
|
611
|
+
function OMapping(source, line, column, name) {
|
|
612
|
+
return {
|
|
613
|
+
source,
|
|
614
|
+
line,
|
|
615
|
+
column,
|
|
616
|
+
name
|
|
617
|
+
};
|
|
618
|
+
}
|
|
619
|
+
function traceSegmentInternal(segments, memo, line, column, bias) {
|
|
620
|
+
let index = memoizedBinarySearch(segments, column, memo, line);
|
|
621
|
+
if (found) index = (bias === -1 ? upperBound : lowerBound)(segments, column, index);
|
|
622
|
+
else if (bias === -1) index++;
|
|
623
|
+
if (index === -1 || index === segments.length) return -1;
|
|
624
|
+
return index;
|
|
625
|
+
}
|
|
626
|
+
//#endregion
|
|
627
|
+
//#region node_modules/@jridgewell/gen-mapping/dist/gen-mapping.mjs
|
|
628
|
+
var SetArray = class {
|
|
629
|
+
constructor() {
|
|
630
|
+
this._indexes = { __proto__: null };
|
|
631
|
+
this.array = [];
|
|
632
|
+
}
|
|
633
|
+
};
|
|
634
|
+
function cast(set) {
|
|
635
|
+
return set;
|
|
636
|
+
}
|
|
637
|
+
function get(setarr, key) {
|
|
638
|
+
return cast(setarr)._indexes[key];
|
|
639
|
+
}
|
|
640
|
+
function put(setarr, key) {
|
|
641
|
+
const index = get(setarr, key);
|
|
642
|
+
if (index !== void 0) return index;
|
|
643
|
+
const { array, _indexes: indexes } = cast(setarr);
|
|
644
|
+
return indexes[key] = array.push(key) - 1;
|
|
645
|
+
}
|
|
646
|
+
var COLUMN = 0;
|
|
647
|
+
var SOURCES_INDEX = 1;
|
|
648
|
+
var SOURCE_LINE = 2;
|
|
649
|
+
var SOURCE_COLUMN = 3;
|
|
650
|
+
var NAMES_INDEX = 4;
|
|
651
|
+
var NO_NAME = -1;
|
|
652
|
+
var GenMapping = class {
|
|
653
|
+
constructor({ file, sourceRoot } = {}) {
|
|
654
|
+
this._names = new SetArray();
|
|
655
|
+
this._sources = new SetArray();
|
|
656
|
+
this._sourcesContent = [];
|
|
657
|
+
this._mappings = [];
|
|
658
|
+
this.file = file;
|
|
659
|
+
this.sourceRoot = sourceRoot;
|
|
660
|
+
this._ignoreList = new SetArray();
|
|
661
|
+
}
|
|
662
|
+
};
|
|
663
|
+
function cast2(map) {
|
|
664
|
+
return map;
|
|
665
|
+
}
|
|
666
|
+
var maybeAddMapping = (map, mapping) => {
|
|
667
|
+
return addMappingInternal(true, map, mapping);
|
|
668
|
+
};
|
|
669
|
+
function setSourceContent(map, source, content) {
|
|
670
|
+
const { _sources: sources, _sourcesContent: sourcesContent } = cast2(map);
|
|
671
|
+
const index = put(sources, source);
|
|
672
|
+
sourcesContent[index] = content;
|
|
673
|
+
}
|
|
674
|
+
function toDecodedMap(map) {
|
|
675
|
+
const { _mappings: mappings, _sources: sources, _sourcesContent: sourcesContent, _names: names, _ignoreList: ignoreList } = cast2(map);
|
|
676
|
+
removeEmptyFinalLines(mappings);
|
|
677
|
+
return {
|
|
678
|
+
version: 3,
|
|
679
|
+
file: map.file || void 0,
|
|
680
|
+
names: names.array,
|
|
681
|
+
sourceRoot: map.sourceRoot || void 0,
|
|
682
|
+
sources: sources.array,
|
|
683
|
+
sourcesContent,
|
|
684
|
+
mappings,
|
|
685
|
+
ignoreList: ignoreList.array
|
|
686
|
+
};
|
|
687
|
+
}
|
|
688
|
+
function toEncodedMap(map) {
|
|
689
|
+
const decoded = toDecodedMap(map);
|
|
690
|
+
return Object.assign({}, decoded, { mappings: encode(decoded.mappings) });
|
|
691
|
+
}
|
|
692
|
+
function allMappings(map) {
|
|
693
|
+
const out = [];
|
|
694
|
+
const { _mappings: mappings, _sources: sources, _names: names } = cast2(map);
|
|
695
|
+
for (let i = 0; i < mappings.length; i++) {
|
|
696
|
+
const line = mappings[i];
|
|
697
|
+
for (let j = 0; j < line.length; j++) {
|
|
698
|
+
const seg = line[j];
|
|
699
|
+
const generated = {
|
|
700
|
+
line: i + 1,
|
|
701
|
+
column: seg[COLUMN]
|
|
702
|
+
};
|
|
703
|
+
let source = void 0;
|
|
704
|
+
let original = void 0;
|
|
705
|
+
let name = void 0;
|
|
706
|
+
if (seg.length !== 1) {
|
|
707
|
+
source = sources.array[seg[SOURCES_INDEX]];
|
|
708
|
+
original = {
|
|
709
|
+
line: seg[SOURCE_LINE] + 1,
|
|
710
|
+
column: seg[SOURCE_COLUMN]
|
|
711
|
+
};
|
|
712
|
+
if (seg.length === 5) name = names.array[seg[NAMES_INDEX]];
|
|
713
|
+
}
|
|
714
|
+
out.push({
|
|
715
|
+
generated,
|
|
716
|
+
source,
|
|
717
|
+
original,
|
|
718
|
+
name
|
|
719
|
+
});
|
|
720
|
+
}
|
|
721
|
+
}
|
|
722
|
+
return out;
|
|
723
|
+
}
|
|
724
|
+
function addSegmentInternal(skipable, map, genLine, genColumn, source, sourceLine, sourceColumn, name, content) {
|
|
725
|
+
const { _mappings: mappings, _sources: sources, _sourcesContent: sourcesContent, _names: names } = cast2(map);
|
|
726
|
+
const line = getIndex(mappings, genLine);
|
|
727
|
+
const index = getColumnIndex(line, genColumn);
|
|
728
|
+
if (!source) {
|
|
729
|
+
if (skipable && skipSourceless(line, index)) return;
|
|
730
|
+
return insert(line, index, [genColumn]);
|
|
731
|
+
}
|
|
732
|
+
const sourcesIndex = put(sources, source);
|
|
733
|
+
const namesIndex = name ? put(names, name) : NO_NAME;
|
|
734
|
+
if (sourcesIndex === sourcesContent.length) sourcesContent[sourcesIndex] = content != null ? content : null;
|
|
735
|
+
if (skipable && skipSource(line, index, sourcesIndex, sourceLine, sourceColumn, namesIndex)) return;
|
|
736
|
+
return insert(line, index, name ? [
|
|
737
|
+
genColumn,
|
|
738
|
+
sourcesIndex,
|
|
739
|
+
sourceLine,
|
|
740
|
+
sourceColumn,
|
|
741
|
+
namesIndex
|
|
742
|
+
] : [
|
|
743
|
+
genColumn,
|
|
744
|
+
sourcesIndex,
|
|
745
|
+
sourceLine,
|
|
746
|
+
sourceColumn
|
|
747
|
+
]);
|
|
748
|
+
}
|
|
749
|
+
function getIndex(arr, index) {
|
|
750
|
+
for (let i = arr.length; i <= index; i++) arr[i] = [];
|
|
751
|
+
return arr[index];
|
|
752
|
+
}
|
|
753
|
+
function getColumnIndex(line, genColumn) {
|
|
754
|
+
let index = line.length;
|
|
755
|
+
for (let i = index - 1; i >= 0; index = i--) if (genColumn >= line[i][COLUMN]) break;
|
|
756
|
+
return index;
|
|
757
|
+
}
|
|
758
|
+
function insert(array, index, value) {
|
|
759
|
+
for (let i = array.length; i > index; i--) array[i] = array[i - 1];
|
|
760
|
+
array[index] = value;
|
|
761
|
+
}
|
|
762
|
+
function removeEmptyFinalLines(mappings) {
|
|
763
|
+
const { length } = mappings;
|
|
764
|
+
let len = length;
|
|
765
|
+
for (let i = len - 1; i >= 0; len = i, i--) if (mappings[i].length > 0) break;
|
|
766
|
+
if (len < length) mappings.length = len;
|
|
767
|
+
}
|
|
768
|
+
function skipSourceless(line, index) {
|
|
769
|
+
if (index === 0) return true;
|
|
770
|
+
return line[index - 1].length === 1;
|
|
771
|
+
}
|
|
772
|
+
function skipSource(line, index, sourcesIndex, sourceLine, sourceColumn, namesIndex) {
|
|
773
|
+
if (index === 0) return false;
|
|
774
|
+
const prev = line[index - 1];
|
|
775
|
+
if (prev.length === 1) return false;
|
|
776
|
+
return sourcesIndex === prev[SOURCES_INDEX] && sourceLine === prev[SOURCE_LINE] && sourceColumn === prev[SOURCE_COLUMN] && namesIndex === (prev.length === 5 ? prev[NAMES_INDEX] : NO_NAME);
|
|
777
|
+
}
|
|
778
|
+
function addMappingInternal(skipable, map, mapping) {
|
|
779
|
+
const { generated, source, original, name, content } = mapping;
|
|
780
|
+
if (!source) return addSegmentInternal(skipable, map, generated.line - 1, generated.column, null, null, null, null, null);
|
|
781
|
+
return addSegmentInternal(skipable, map, generated.line - 1, generated.column, source, original.line - 1, original.column, name, content);
|
|
782
|
+
}
|
|
783
|
+
//#endregion
|
|
784
|
+
//#region node_modules/@babel/generator/lib/index.js
|
|
785
|
+
var import_jsesc = /* @__PURE__ */ __toESM((/* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
786
|
+
var object = {};
|
|
787
|
+
var hasOwnProperty = object.hasOwnProperty;
|
|
788
|
+
var forOwn = (object, callback) => {
|
|
789
|
+
for (const key in object) if (hasOwnProperty.call(object, key)) callback(key, object[key]);
|
|
790
|
+
};
|
|
791
|
+
var extend = (destination, source) => {
|
|
792
|
+
if (!source) return destination;
|
|
793
|
+
forOwn(source, (key, value) => {
|
|
794
|
+
destination[key] = value;
|
|
795
|
+
});
|
|
796
|
+
return destination;
|
|
797
|
+
};
|
|
798
|
+
var forEach = (array, callback) => {
|
|
799
|
+
const length = array.length;
|
|
800
|
+
let index = -1;
|
|
801
|
+
while (++index < length) callback(array[index]);
|
|
802
|
+
};
|
|
803
|
+
var fourHexEscape = (hex) => {
|
|
804
|
+
return "\\u" + ("0000" + hex).slice(-4);
|
|
805
|
+
};
|
|
806
|
+
var hexadecimal = (code, lowercase) => {
|
|
807
|
+
let hexadecimal = code.toString(16);
|
|
808
|
+
if (lowercase) return hexadecimal;
|
|
809
|
+
return hexadecimal.toUpperCase();
|
|
810
|
+
};
|
|
811
|
+
var toString = object.toString;
|
|
812
|
+
var isArray = Array.isArray;
|
|
813
|
+
var isBuffer = (value) => {
|
|
814
|
+
return typeof Buffer === "function" && Buffer.isBuffer(value);
|
|
815
|
+
};
|
|
816
|
+
var isObject = (value) => {
|
|
817
|
+
return toString.call(value) == "[object Object]";
|
|
818
|
+
};
|
|
819
|
+
var isString = (value) => {
|
|
820
|
+
return typeof value == "string" || toString.call(value) == "[object String]";
|
|
821
|
+
};
|
|
822
|
+
var isNumber = (value) => {
|
|
823
|
+
return typeof value == "number" || toString.call(value) == "[object Number]";
|
|
824
|
+
};
|
|
825
|
+
var isBigInt = (value) => {
|
|
826
|
+
return typeof value == "bigint";
|
|
827
|
+
};
|
|
828
|
+
var isFunction = (value) => {
|
|
829
|
+
return typeof value == "function";
|
|
830
|
+
};
|
|
831
|
+
var isMap = (value) => {
|
|
832
|
+
return toString.call(value) == "[object Map]";
|
|
833
|
+
};
|
|
834
|
+
var isSet = (value) => {
|
|
835
|
+
return toString.call(value) == "[object Set]";
|
|
836
|
+
};
|
|
837
|
+
var singleEscapes = {
|
|
838
|
+
"\\": "\\\\",
|
|
839
|
+
"\b": "\\b",
|
|
840
|
+
"\f": "\\f",
|
|
841
|
+
"\n": "\\n",
|
|
842
|
+
"\r": "\\r",
|
|
843
|
+
" ": "\\t"
|
|
844
|
+
};
|
|
845
|
+
var regexSingleEscape = /[\\\b\f\n\r\t]/;
|
|
846
|
+
var regexDigit = /[0-9]/;
|
|
847
|
+
var regexWhitespace = /[\xA0\u1680\u2000-\u200A\u2028\u2029\u202F\u205F\u3000]/;
|
|
848
|
+
var escapeEverythingRegex = /([\uD800-\uDBFF][\uDC00-\uDFFF])|([\uD800-\uDFFF])|(['"`])|[^]/g;
|
|
849
|
+
var escapeNonAsciiRegex = /([\uD800-\uDBFF][\uDC00-\uDFFF])|([\uD800-\uDFFF])|(['"`])|[^ !#-&\(-\[\]-_a-~]/g;
|
|
850
|
+
var jsesc = (argument, options) => {
|
|
851
|
+
const increaseIndentation = () => {
|
|
852
|
+
oldIndent = indent;
|
|
853
|
+
++options.indentLevel;
|
|
854
|
+
indent = options.indent.repeat(options.indentLevel);
|
|
855
|
+
};
|
|
856
|
+
const defaults = {
|
|
857
|
+
"escapeEverything": false,
|
|
858
|
+
"minimal": false,
|
|
859
|
+
"isScriptContext": false,
|
|
860
|
+
"quotes": "single",
|
|
861
|
+
"wrap": false,
|
|
862
|
+
"es6": false,
|
|
863
|
+
"json": false,
|
|
864
|
+
"compact": true,
|
|
865
|
+
"lowercaseHex": false,
|
|
866
|
+
"numbers": "decimal",
|
|
867
|
+
"indent": " ",
|
|
868
|
+
"indentLevel": 0,
|
|
869
|
+
"__inline1__": false,
|
|
870
|
+
"__inline2__": false
|
|
871
|
+
};
|
|
872
|
+
const json = options && options.json;
|
|
873
|
+
if (json) {
|
|
874
|
+
defaults.quotes = "double";
|
|
875
|
+
defaults.wrap = true;
|
|
876
|
+
}
|
|
877
|
+
options = extend(defaults, options);
|
|
878
|
+
if (options.quotes != "single" && options.quotes != "double" && options.quotes != "backtick") options.quotes = "single";
|
|
879
|
+
const quote = options.quotes == "double" ? "\"" : options.quotes == "backtick" ? "`" : "'";
|
|
880
|
+
const compact = options.compact;
|
|
881
|
+
const lowercaseHex = options.lowercaseHex;
|
|
882
|
+
let indent = options.indent.repeat(options.indentLevel);
|
|
883
|
+
let oldIndent = "";
|
|
884
|
+
const inline1 = options.__inline1__;
|
|
885
|
+
const inline2 = options.__inline2__;
|
|
886
|
+
const newLine = compact ? "" : "\n";
|
|
887
|
+
let result;
|
|
888
|
+
let isEmpty = true;
|
|
889
|
+
const useBinNumbers = options.numbers == "binary";
|
|
890
|
+
const useOctNumbers = options.numbers == "octal";
|
|
891
|
+
const useDecNumbers = options.numbers == "decimal";
|
|
892
|
+
const useHexNumbers = options.numbers == "hexadecimal";
|
|
893
|
+
if (json && argument && isFunction(argument.toJSON)) argument = argument.toJSON();
|
|
894
|
+
if (!isString(argument)) {
|
|
895
|
+
if (isMap(argument)) {
|
|
896
|
+
if (argument.size == 0) return "new Map()";
|
|
897
|
+
if (!compact) {
|
|
898
|
+
options.__inline1__ = true;
|
|
899
|
+
options.__inline2__ = false;
|
|
900
|
+
}
|
|
901
|
+
return "new Map(" + jsesc(Array.from(argument), options) + ")";
|
|
902
|
+
}
|
|
903
|
+
if (isSet(argument)) {
|
|
904
|
+
if (argument.size == 0) return "new Set()";
|
|
905
|
+
return "new Set(" + jsesc(Array.from(argument), options) + ")";
|
|
906
|
+
}
|
|
907
|
+
if (isBuffer(argument)) {
|
|
908
|
+
if (argument.length == 0) return "Buffer.from([])";
|
|
909
|
+
return "Buffer.from(" + jsesc(Array.from(argument), options) + ")";
|
|
910
|
+
}
|
|
911
|
+
if (isArray(argument)) {
|
|
912
|
+
result = [];
|
|
913
|
+
options.wrap = true;
|
|
914
|
+
if (inline1) {
|
|
915
|
+
options.__inline1__ = false;
|
|
916
|
+
options.__inline2__ = true;
|
|
917
|
+
}
|
|
918
|
+
if (!inline2) increaseIndentation();
|
|
919
|
+
forEach(argument, (value) => {
|
|
920
|
+
isEmpty = false;
|
|
921
|
+
if (inline2) options.__inline2__ = false;
|
|
922
|
+
result.push((compact || inline2 ? "" : indent) + jsesc(value, options));
|
|
923
|
+
});
|
|
924
|
+
if (isEmpty) return "[]";
|
|
925
|
+
if (inline2) return "[" + result.join(", ") + "]";
|
|
926
|
+
return "[" + newLine + result.join("," + newLine) + newLine + (compact ? "" : oldIndent) + "]";
|
|
927
|
+
} else if (isNumber(argument) || isBigInt(argument)) {
|
|
928
|
+
if (json) return JSON.stringify(Number(argument));
|
|
929
|
+
let result;
|
|
930
|
+
if (useDecNumbers) result = String(argument);
|
|
931
|
+
else if (useHexNumbers) {
|
|
932
|
+
let hexadecimal = argument.toString(16);
|
|
933
|
+
if (!lowercaseHex) hexadecimal = hexadecimal.toUpperCase();
|
|
934
|
+
result = "0x" + hexadecimal;
|
|
935
|
+
} else if (useBinNumbers) result = "0b" + argument.toString(2);
|
|
936
|
+
else if (useOctNumbers) result = "0o" + argument.toString(8);
|
|
937
|
+
if (isBigInt(argument)) return result + "n";
|
|
938
|
+
return result;
|
|
939
|
+
} else if (isBigInt(argument)) {
|
|
940
|
+
if (json) return JSON.stringify(Number(argument));
|
|
941
|
+
return argument + "n";
|
|
942
|
+
} else if (!isObject(argument)) {
|
|
943
|
+
if (json) return JSON.stringify(argument) || "null";
|
|
944
|
+
return String(argument);
|
|
945
|
+
} else {
|
|
946
|
+
result = [];
|
|
947
|
+
options.wrap = true;
|
|
948
|
+
increaseIndentation();
|
|
949
|
+
forOwn(argument, (key, value) => {
|
|
950
|
+
isEmpty = false;
|
|
951
|
+
result.push((compact ? "" : indent) + jsesc(key, options) + ":" + (compact ? "" : " ") + jsesc(value, options));
|
|
952
|
+
});
|
|
953
|
+
if (isEmpty) return "{}";
|
|
954
|
+
return "{" + newLine + result.join("," + newLine) + newLine + (compact ? "" : oldIndent) + "}";
|
|
955
|
+
}
|
|
956
|
+
}
|
|
957
|
+
const regex = options.escapeEverything ? escapeEverythingRegex : escapeNonAsciiRegex;
|
|
958
|
+
result = argument.replace(regex, (char, pair, lone, quoteChar, index, string) => {
|
|
959
|
+
if (pair) {
|
|
960
|
+
if (options.minimal) return pair;
|
|
961
|
+
const first = pair.charCodeAt(0);
|
|
962
|
+
const second = pair.charCodeAt(1);
|
|
963
|
+
if (options.es6) return "\\u{" + hexadecimal((first - 55296) * 1024 + second - 56320 + 65536, lowercaseHex) + "}";
|
|
964
|
+
return fourHexEscape(hexadecimal(first, lowercaseHex)) + fourHexEscape(hexadecimal(second, lowercaseHex));
|
|
965
|
+
}
|
|
966
|
+
if (lone) return fourHexEscape(hexadecimal(lone.charCodeAt(0), lowercaseHex));
|
|
967
|
+
if (char == "\0" && !json && !regexDigit.test(string.charAt(index + 1))) return "\\0";
|
|
968
|
+
if (quoteChar) {
|
|
969
|
+
if (quoteChar == quote || options.escapeEverything) return "\\" + quoteChar;
|
|
970
|
+
return quoteChar;
|
|
971
|
+
}
|
|
972
|
+
if (regexSingleEscape.test(char)) return singleEscapes[char];
|
|
973
|
+
if (options.minimal && !regexWhitespace.test(char)) return char;
|
|
974
|
+
const hex = hexadecimal(char.charCodeAt(0), lowercaseHex);
|
|
975
|
+
if (json || hex.length > 2) return fourHexEscape(hex);
|
|
976
|
+
return "\\x" + ("00" + hex).slice(-2);
|
|
977
|
+
});
|
|
978
|
+
if (quote == "`") result = result.replace(/\$\{/g, "\\${");
|
|
979
|
+
if (options.isScriptContext) result = result.replace(/<\/(script|style)/gi, "<\\/$1").replace(/<!--/g, json ? "\\u003C!--" : "\\x3C!--");
|
|
980
|
+
if (options.wrap) result = quote + result + quote;
|
|
981
|
+
return result;
|
|
982
|
+
};
|
|
983
|
+
jsesc.version = "3.0.2";
|
|
984
|
+
module.exports = jsesc;
|
|
985
|
+
})))(), 1);
|
|
986
|
+
var SourceMap = class {
|
|
987
|
+
_map;
|
|
988
|
+
_rawMappings;
|
|
989
|
+
_sourceFileName;
|
|
990
|
+
_lastGenLine = 0;
|
|
991
|
+
_lastSourceLine = 0;
|
|
992
|
+
_lastSourceColumn = 0;
|
|
993
|
+
_inputMap = null;
|
|
994
|
+
constructor(opts, code) {
|
|
995
|
+
const map = this._map = new GenMapping({ sourceRoot: opts.sourceRoot });
|
|
996
|
+
this._sourceFileName = opts.sourceFileName?.replace(/\\/g, "/");
|
|
997
|
+
this._rawMappings = void 0;
|
|
998
|
+
if (opts.inputSourceMap) {
|
|
999
|
+
this._inputMap = new TraceMap(opts.inputSourceMap);
|
|
1000
|
+
const resolvedSources = this._inputMap.resolvedSources;
|
|
1001
|
+
if (resolvedSources.length) for (let i = 0; i < resolvedSources.length; i++) setSourceContent(map, resolvedSources[i], this._inputMap.sourcesContent?.[i]);
|
|
1002
|
+
}
|
|
1003
|
+
if (typeof code === "string" && !opts.inputSourceMap) setSourceContent(map, this._sourceFileName, code);
|
|
1004
|
+
else if (typeof code === "object") for (const sourceFileName of Object.keys(code)) setSourceContent(map, sourceFileName.replace(/\\/g, "/"), code[sourceFileName]);
|
|
1005
|
+
}
|
|
1006
|
+
get() {
|
|
1007
|
+
return toEncodedMap(this._map);
|
|
1008
|
+
}
|
|
1009
|
+
getDecoded() {
|
|
1010
|
+
return toDecodedMap(this._map);
|
|
1011
|
+
}
|
|
1012
|
+
getRawMappings() {
|
|
1013
|
+
return this._rawMappings ||= allMappings(this._map);
|
|
1014
|
+
}
|
|
1015
|
+
mark(generated, generatedIdentifierName, line, column, identifierName, identifierNamePos, filename) {
|
|
1016
|
+
this._rawMappings = void 0;
|
|
1017
|
+
let originalMapping;
|
|
1018
|
+
if (line != null) if (this._inputMap) {
|
|
1019
|
+
originalMapping = originalPositionFor(this._inputMap, {
|
|
1020
|
+
line,
|
|
1021
|
+
column
|
|
1022
|
+
});
|
|
1023
|
+
if (originalMapping.name && (identifierNamePos || identifierName != null && originalMapping.column === column)) identifierName = originalMapping.name;
|
|
1024
|
+
else if (identifierNamePos) {
|
|
1025
|
+
const originalIdentifierMapping = originalPositionFor(this._inputMap, identifierNamePos);
|
|
1026
|
+
if (originalIdentifierMapping.name) identifierName = originalIdentifierMapping.name;
|
|
1027
|
+
}
|
|
1028
|
+
} else originalMapping = {
|
|
1029
|
+
name: null,
|
|
1030
|
+
source: filename?.replace(/\\/g, "/") || this._sourceFileName,
|
|
1031
|
+
line,
|
|
1032
|
+
column
|
|
1033
|
+
};
|
|
1034
|
+
if (identifierName != null && identifierName === generatedIdentifierName) identifierName = null;
|
|
1035
|
+
maybeAddMapping(this._map, {
|
|
1036
|
+
name: identifierName,
|
|
1037
|
+
generated,
|
|
1038
|
+
source: originalMapping?.source,
|
|
1039
|
+
original: originalMapping
|
|
1040
|
+
});
|
|
1041
|
+
}
|
|
1042
|
+
};
|
|
1043
|
+
var spaceIndents = [];
|
|
1044
|
+
for (let i = 0; i < 32; i++) spaceIndents.push(" ".repeat(i * 2));
|
|
1045
|
+
var Buffer$1 = class {
|
|
1046
|
+
constructor(map, indentChar) {
|
|
1047
|
+
this._map = map;
|
|
1048
|
+
this._indentChar = indentChar;
|
|
1049
|
+
}
|
|
1050
|
+
_map = null;
|
|
1051
|
+
_buf = "";
|
|
1052
|
+
_str = "";
|
|
1053
|
+
_appendCount = 0;
|
|
1054
|
+
_last = 0;
|
|
1055
|
+
_canMarkIdName = true;
|
|
1056
|
+
_indentChar = "";
|
|
1057
|
+
_queuedChar = 0;
|
|
1058
|
+
_position = {
|
|
1059
|
+
line: 1,
|
|
1060
|
+
column: 0
|
|
1061
|
+
};
|
|
1062
|
+
_sourcePosition = {
|
|
1063
|
+
identifierName: void 0,
|
|
1064
|
+
identifierNamePos: void 0,
|
|
1065
|
+
line: void 0,
|
|
1066
|
+
column: void 0,
|
|
1067
|
+
filename: void 0
|
|
1068
|
+
};
|
|
1069
|
+
get() {
|
|
1070
|
+
const { _map, _last } = this;
|
|
1071
|
+
if (this._queuedChar !== 32) this._flush();
|
|
1072
|
+
const code = _last === 10 ? (this._buf + this._str).trimRight() : this._buf + this._str;
|
|
1073
|
+
if (_map === null) return {
|
|
1074
|
+
code,
|
|
1075
|
+
decodedMap: void 0,
|
|
1076
|
+
map: null,
|
|
1077
|
+
rawMappings: void 0
|
|
1078
|
+
};
|
|
1079
|
+
const result = {
|
|
1080
|
+
code,
|
|
1081
|
+
decodedMap: _map.getDecoded(),
|
|
1082
|
+
get map() {
|
|
1083
|
+
const resultMap = _map.get();
|
|
1084
|
+
result.map = resultMap;
|
|
1085
|
+
return resultMap;
|
|
1086
|
+
},
|
|
1087
|
+
set map(value) {
|
|
1088
|
+
Object.defineProperty(result, "map", {
|
|
1089
|
+
value,
|
|
1090
|
+
writable: true
|
|
1091
|
+
});
|
|
1092
|
+
},
|
|
1093
|
+
get rawMappings() {
|
|
1094
|
+
const mappings = _map.getRawMappings();
|
|
1095
|
+
result.rawMappings = mappings;
|
|
1096
|
+
return mappings;
|
|
1097
|
+
},
|
|
1098
|
+
set rawMappings(value) {
|
|
1099
|
+
Object.defineProperty(result, "rawMappings", {
|
|
1100
|
+
value,
|
|
1101
|
+
writable: true
|
|
1102
|
+
});
|
|
1103
|
+
}
|
|
1104
|
+
};
|
|
1105
|
+
return result;
|
|
1106
|
+
}
|
|
1107
|
+
append(str, maybeNewline, ignoreMapping = false) {
|
|
1108
|
+
this._flush();
|
|
1109
|
+
this._append(str, maybeNewline, ignoreMapping);
|
|
1110
|
+
}
|
|
1111
|
+
appendChar(char) {
|
|
1112
|
+
this._flush();
|
|
1113
|
+
this._appendChar(char, 1, true);
|
|
1114
|
+
}
|
|
1115
|
+
queue(char) {
|
|
1116
|
+
this._flush();
|
|
1117
|
+
this._queuedChar = char;
|
|
1118
|
+
}
|
|
1119
|
+
_flush() {
|
|
1120
|
+
const queuedChar = this._queuedChar;
|
|
1121
|
+
if (queuedChar !== 0) {
|
|
1122
|
+
this._appendChar(queuedChar, 1, true);
|
|
1123
|
+
this._queuedChar = 0;
|
|
1124
|
+
}
|
|
1125
|
+
}
|
|
1126
|
+
_appendChar(char, repeat, useSourcePos) {
|
|
1127
|
+
this._last = char;
|
|
1128
|
+
if (char === -1) {
|
|
1129
|
+
const indent = repeat >= 64 ? this._indentChar.repeat(repeat) : spaceIndents[repeat / 2];
|
|
1130
|
+
this._str += indent;
|
|
1131
|
+
} else this._str += repeat > 1 ? String.fromCharCode(char).repeat(repeat) : String.fromCharCode(char);
|
|
1132
|
+
const isSpace = char === 32;
|
|
1133
|
+
const position = this._position;
|
|
1134
|
+
if (char !== 10) {
|
|
1135
|
+
if (this._map) {
|
|
1136
|
+
const sourcePos = this._sourcePosition;
|
|
1137
|
+
if (useSourcePos && sourcePos) {
|
|
1138
|
+
this._map.mark(position, null, sourcePos.line, sourcePos.column, isSpace ? void 0 : sourcePos.identifierName, isSpace ? void 0 : sourcePos.identifierNamePos, sourcePos.filename);
|
|
1139
|
+
if (!isSpace && this._canMarkIdName) {
|
|
1140
|
+
sourcePos.identifierName = void 0;
|
|
1141
|
+
sourcePos.identifierNamePos = void 0;
|
|
1142
|
+
}
|
|
1143
|
+
} else this._map.mark(position, null);
|
|
1144
|
+
}
|
|
1145
|
+
position.column += repeat;
|
|
1146
|
+
} else {
|
|
1147
|
+
position.line++;
|
|
1148
|
+
position.column = 0;
|
|
1149
|
+
}
|
|
1150
|
+
}
|
|
1151
|
+
_append(str, maybeNewline, ignoreMapping) {
|
|
1152
|
+
const len = str.length;
|
|
1153
|
+
const position = this._position;
|
|
1154
|
+
const sourcePos = this._sourcePosition;
|
|
1155
|
+
this._last = -1;
|
|
1156
|
+
if (++this._appendCount > 4096) {
|
|
1157
|
+
+this._str;
|
|
1158
|
+
this._buf += this._str;
|
|
1159
|
+
this._str = str;
|
|
1160
|
+
this._appendCount = 0;
|
|
1161
|
+
} else this._str += str;
|
|
1162
|
+
const hasMap = !ignoreMapping && this._map !== null;
|
|
1163
|
+
if (!maybeNewline && !hasMap) {
|
|
1164
|
+
position.column += len;
|
|
1165
|
+
return;
|
|
1166
|
+
}
|
|
1167
|
+
const { column, identifierName, identifierNamePos, filename } = sourcePos;
|
|
1168
|
+
let line = sourcePos.line;
|
|
1169
|
+
if ((identifierName != null || identifierNamePos != null) && this._canMarkIdName) {
|
|
1170
|
+
sourcePos.identifierName = void 0;
|
|
1171
|
+
sourcePos.identifierNamePos = void 0;
|
|
1172
|
+
}
|
|
1173
|
+
let i = str.indexOf("\n");
|
|
1174
|
+
let last = 0;
|
|
1175
|
+
if (hasMap && i !== 0) this._map.mark(position, str, line, column, identifierName, identifierNamePos, filename);
|
|
1176
|
+
while (i !== -1) {
|
|
1177
|
+
position.line++;
|
|
1178
|
+
position.column = 0;
|
|
1179
|
+
last = i + 1;
|
|
1180
|
+
if (last < len && line !== void 0) {
|
|
1181
|
+
line++;
|
|
1182
|
+
if (hasMap) this._map.mark(position, str, line, 0, void 0, void 0, filename);
|
|
1183
|
+
}
|
|
1184
|
+
i = str.indexOf("\n", last);
|
|
1185
|
+
}
|
|
1186
|
+
position.column += len - last;
|
|
1187
|
+
}
|
|
1188
|
+
removeLastSemicolon() {
|
|
1189
|
+
if (this._queuedChar === 59) this._queuedChar = 0;
|
|
1190
|
+
}
|
|
1191
|
+
getLastChar(checkQueue) {
|
|
1192
|
+
if (!checkQueue) return this._last;
|
|
1193
|
+
const queuedChar = this._queuedChar;
|
|
1194
|
+
return queuedChar !== 0 ? queuedChar : this._last;
|
|
1195
|
+
}
|
|
1196
|
+
getNewlineCount() {
|
|
1197
|
+
return this._queuedChar === 0 && this._last === 10 ? 1 : 0;
|
|
1198
|
+
}
|
|
1199
|
+
hasContent() {
|
|
1200
|
+
return this._last !== 0;
|
|
1201
|
+
}
|
|
1202
|
+
exactSource(loc, cb) {
|
|
1203
|
+
if (!this._map) {
|
|
1204
|
+
cb();
|
|
1205
|
+
return;
|
|
1206
|
+
}
|
|
1207
|
+
this.source("start", loc);
|
|
1208
|
+
const identifierName = loc.identifierName;
|
|
1209
|
+
const sourcePos = this._sourcePosition;
|
|
1210
|
+
if (identifierName != null) {
|
|
1211
|
+
this._canMarkIdName = false;
|
|
1212
|
+
sourcePos.identifierName = identifierName;
|
|
1213
|
+
}
|
|
1214
|
+
cb();
|
|
1215
|
+
if (identifierName != null) {
|
|
1216
|
+
this._canMarkIdName = true;
|
|
1217
|
+
sourcePos.identifierName = void 0;
|
|
1218
|
+
sourcePos.identifierNamePos = void 0;
|
|
1219
|
+
}
|
|
1220
|
+
this.source("end", loc);
|
|
1221
|
+
}
|
|
1222
|
+
source(prop, loc) {
|
|
1223
|
+
if (!this._map) return;
|
|
1224
|
+
this._normalizePosition(prop, loc, 0);
|
|
1225
|
+
}
|
|
1226
|
+
sourceWithOffset(prop, loc, columnOffset) {
|
|
1227
|
+
if (!this._map) return;
|
|
1228
|
+
this._normalizePosition(prop, loc, columnOffset);
|
|
1229
|
+
}
|
|
1230
|
+
_normalizePosition(prop, loc, columnOffset) {
|
|
1231
|
+
this._flush();
|
|
1232
|
+
const pos = loc[prop];
|
|
1233
|
+
if (pos) {
|
|
1234
|
+
this.setSourcePosition(pos.line, Math.max(pos.column + columnOffset, 0));
|
|
1235
|
+
this._sourcePosition.filename = loc.filename;
|
|
1236
|
+
}
|
|
1237
|
+
}
|
|
1238
|
+
setSourcePosition(line, column) {
|
|
1239
|
+
const target = this._sourcePosition;
|
|
1240
|
+
target.line = line;
|
|
1241
|
+
target.column = column;
|
|
1242
|
+
}
|
|
1243
|
+
getCurrentColumn() {
|
|
1244
|
+
return this._position.column + (this._queuedChar ? 1 : 0);
|
|
1245
|
+
}
|
|
1246
|
+
getCurrentLine() {
|
|
1247
|
+
return this._position.line;
|
|
1248
|
+
}
|
|
1249
|
+
};
|
|
1250
|
+
var { isMemberExpression: isMemberExpression$1, isOptionalMemberExpression, isYieldExpression, isStatement: isStatement$4 } = _t;
|
|
1251
|
+
var PRECEDENCE = /* @__PURE__ */ new Map([
|
|
1252
|
+
["||", 0],
|
|
1253
|
+
["??", 1],
|
|
1254
|
+
["&&", 2],
|
|
1255
|
+
["|", 3],
|
|
1256
|
+
["^", 4],
|
|
1257
|
+
["&", 5],
|
|
1258
|
+
["==", 6],
|
|
1259
|
+
["===", 6],
|
|
1260
|
+
["!=", 6],
|
|
1261
|
+
["!==", 6],
|
|
1262
|
+
["<", 7],
|
|
1263
|
+
[">", 7],
|
|
1264
|
+
["<=", 7],
|
|
1265
|
+
[">=", 7],
|
|
1266
|
+
["in", 7],
|
|
1267
|
+
["instanceof", 7],
|
|
1268
|
+
[">>", 8],
|
|
1269
|
+
["<<", 8],
|
|
1270
|
+
[">>>", 8],
|
|
1271
|
+
["+", 9],
|
|
1272
|
+
["-", 9],
|
|
1273
|
+
["*", 10],
|
|
1274
|
+
["/", 10],
|
|
1275
|
+
["%", 10],
|
|
1276
|
+
["**", 11]
|
|
1277
|
+
]);
|
|
1278
|
+
function isTSTypeExpression(nodeId) {
|
|
1279
|
+
return nodeId === 154 || nodeId === 199 || nodeId === 207;
|
|
1280
|
+
}
|
|
1281
|
+
var isClassExtendsClause = (node, parent, parentId) => {
|
|
1282
|
+
return (parentId === 22 || parentId === 23) && parent.superClass === node;
|
|
1283
|
+
};
|
|
1284
|
+
var hasPostfixPart = (node, parent, parentId) => {
|
|
1285
|
+
switch (parentId) {
|
|
1286
|
+
case 109:
|
|
1287
|
+
case 133: return parent.object === node;
|
|
1288
|
+
case 18:
|
|
1289
|
+
case 131:
|
|
1290
|
+
case 113: return parent.callee === node;
|
|
1291
|
+
case 220: return parent.tag === node;
|
|
1292
|
+
case 189: return true;
|
|
1293
|
+
}
|
|
1294
|
+
return false;
|
|
1295
|
+
};
|
|
1296
|
+
function NullableTypeAnnotation$1(node, parent, parentId) {
|
|
1297
|
+
return parentId === 4;
|
|
1298
|
+
}
|
|
1299
|
+
function FunctionTypeAnnotation$1(node, parent, parentId, tokenContext) {
|
|
1300
|
+
return parentId === 237 || parentId === 91 || parentId === 4 || (tokenContext & 8) > 0;
|
|
1301
|
+
}
|
|
1302
|
+
function UpdateExpression$1(node, parent, parentId) {
|
|
1303
|
+
return hasPostfixPart(node, parent, parentId) || isClassExtendsClause(node, parent, parentId);
|
|
1304
|
+
}
|
|
1305
|
+
function needsParenBeforeExpressionBrace(tokenContext) {
|
|
1306
|
+
return (tokenContext & 3) > 0;
|
|
1307
|
+
}
|
|
1308
|
+
function ObjectExpression$1(node, parent, parentId, tokenContext) {
|
|
1309
|
+
return needsParenBeforeExpressionBrace(tokenContext);
|
|
1310
|
+
}
|
|
1311
|
+
function DoExpression$1(node, parent, parentId, tokenContext) {
|
|
1312
|
+
return (tokenContext & 1) > 0 && !node.async;
|
|
1313
|
+
}
|
|
1314
|
+
function BinaryLike(node, parent, parentId, nodeType) {
|
|
1315
|
+
if (isClassExtendsClause(node, parent, parentId)) return true;
|
|
1316
|
+
if (hasPostfixPart(node, parent, parentId) || parentId === 236 || parentId === 143 || parentId === 8) return true;
|
|
1317
|
+
let parentPos;
|
|
1318
|
+
switch (parentId) {
|
|
1319
|
+
case 11:
|
|
1320
|
+
case 108:
|
|
1321
|
+
parentPos = PRECEDENCE.get(parent.operator);
|
|
1322
|
+
break;
|
|
1323
|
+
case 154:
|
|
1324
|
+
case 199: parentPos = 7;
|
|
1325
|
+
}
|
|
1326
|
+
if (parentPos !== void 0) {
|
|
1327
|
+
const nodePos = nodeType === 2 ? 7 : PRECEDENCE.get(node.operator);
|
|
1328
|
+
if (parentPos > nodePos) return true;
|
|
1329
|
+
if (parentPos === nodePos && parentId === 11 && (nodePos === 11 ? parent.left === node : parent.right === node)) return true;
|
|
1330
|
+
if (nodeType === 1 && parentId === 108 && (nodePos === 1 && parentPos !== 1 || parentPos === 1 && nodePos !== 1)) return true;
|
|
1331
|
+
}
|
|
1332
|
+
return false;
|
|
1333
|
+
}
|
|
1334
|
+
function UnionTypeAnnotation$1(node, parent, parentId) {
|
|
1335
|
+
switch (parentId) {
|
|
1336
|
+
case 4:
|
|
1337
|
+
case 116:
|
|
1338
|
+
case 91:
|
|
1339
|
+
case 237: return true;
|
|
1340
|
+
}
|
|
1341
|
+
return false;
|
|
1342
|
+
}
|
|
1343
|
+
function OptionalIndexedAccessType$1(node, parent, parentId) {
|
|
1344
|
+
return parentId === 85 && parent.objectType === node;
|
|
1345
|
+
}
|
|
1346
|
+
function TSAsExpression$1(node, parent, parentId) {
|
|
1347
|
+
if ((parentId === 6 || parentId === 7) && parent.left === node) return true;
|
|
1348
|
+
if (parentId === 11 && (parent.operator === "|" || parent.operator === "&") && node === parent.left) return true;
|
|
1349
|
+
return BinaryLike(node, parent, parentId, 2);
|
|
1350
|
+
}
|
|
1351
|
+
function TSConditionalType$1(node, parent, parentId) {
|
|
1352
|
+
switch (parentId) {
|
|
1353
|
+
case 153:
|
|
1354
|
+
case 193:
|
|
1355
|
+
case 209:
|
|
1356
|
+
case 210:
|
|
1357
|
+
case 179:
|
|
1358
|
+
case 217: return true;
|
|
1359
|
+
case 173: return parent.objectType === node;
|
|
1360
|
+
case 159: return parent.checkType === node || parent.extendsType === node;
|
|
1361
|
+
}
|
|
1362
|
+
return false;
|
|
1363
|
+
}
|
|
1364
|
+
function TSUnionType$1(node, parent, parentId) {
|
|
1365
|
+
switch (parentId) {
|
|
1366
|
+
case 179:
|
|
1367
|
+
case 209:
|
|
1368
|
+
case 153:
|
|
1369
|
+
case 193: return true;
|
|
1370
|
+
case 173: return parent.objectType === node;
|
|
1371
|
+
}
|
|
1372
|
+
return false;
|
|
1373
|
+
}
|
|
1374
|
+
function TSIntersectionType$1(node, parent, parentId) {
|
|
1375
|
+
return parentId === 209 || TSTypeOperator$1(node, parent, parentId);
|
|
1376
|
+
}
|
|
1377
|
+
function TSInferType$1(node, parent, parentId) {
|
|
1378
|
+
if (TSTypeOperator$1(node, parent, parentId)) return true;
|
|
1379
|
+
if ((parentId === 179 || parentId === 217) && node.typeParameter.constraint != null) return true;
|
|
1380
|
+
return false;
|
|
1381
|
+
}
|
|
1382
|
+
function TSTypeOperator$1(node, parent, parentId) {
|
|
1383
|
+
switch (parentId) {
|
|
1384
|
+
case 153:
|
|
1385
|
+
case 193: return true;
|
|
1386
|
+
case 173: if (parent.objectType === node) return true;
|
|
1387
|
+
}
|
|
1388
|
+
return false;
|
|
1389
|
+
}
|
|
1390
|
+
function TSInstantiationExpression$1(node, parent, parentId) {
|
|
1391
|
+
switch (parentId) {
|
|
1392
|
+
case 18:
|
|
1393
|
+
case 131:
|
|
1394
|
+
case 113:
|
|
1395
|
+
case 175: return parent.typeArguments != null;
|
|
1396
|
+
}
|
|
1397
|
+
return false;
|
|
1398
|
+
}
|
|
1399
|
+
function TSFunctionType$1(node, parent, parentId) {
|
|
1400
|
+
if (TSUnionType$1(node, parent, parentId)) return true;
|
|
1401
|
+
return parentId === 217 || parentId === 159 && (parent.checkType === node || parent.extendsType === node);
|
|
1402
|
+
}
|
|
1403
|
+
function BinaryExpression$1(node, parent, parentId, tokenContext) {
|
|
1404
|
+
if (BinaryLike(node, parent, parentId, 0)) return true;
|
|
1405
|
+
return (tokenContext & 128) > 0 && node.operator === "in";
|
|
1406
|
+
}
|
|
1407
|
+
function LogicalExpression(node, parent, parentId) {
|
|
1408
|
+
return BinaryLike(node, parent, parentId, 1);
|
|
1409
|
+
}
|
|
1410
|
+
function SequenceExpression$1(node, parent, parentId) {
|
|
1411
|
+
if (parentId === 142 || parentId === 134 || parentId === 109 && parent.property === node || parentId === 133 && parent.property === node || parentId === 222) return false;
|
|
1412
|
+
if (parentId === 22) return true;
|
|
1413
|
+
if (parentId === 69) return parent.right === node;
|
|
1414
|
+
if (parentId === 61) return true;
|
|
1415
|
+
return !isStatement$4(parent);
|
|
1416
|
+
}
|
|
1417
|
+
function YieldExpression$1(node, parent, parentId) {
|
|
1418
|
+
return parentId === 11 || parentId === 108 || parentId === 236 || parentId === 143 || hasPostfixPart(node, parent, parentId) || parentId === 8 && isYieldExpression(node) || parentId === 29 && node === parent.test || isClassExtendsClause(node, parent, parentId) || isTSTypeExpression(parentId);
|
|
1419
|
+
}
|
|
1420
|
+
function ClassExpression(node, parent, parentId, tokenContext) {
|
|
1421
|
+
return (tokenContext & 5) > 0;
|
|
1422
|
+
}
|
|
1423
|
+
function UnaryLike(node, parent, parentId) {
|
|
1424
|
+
return hasPostfixPart(node, parent, parentId) || parentId === 11 && parent.operator === "**" && parent.left === node || isClassExtendsClause(node, parent, parentId);
|
|
1425
|
+
}
|
|
1426
|
+
function FunctionExpression$1(node, parent, parentId, tokenContext) {
|
|
1427
|
+
return (tokenContext & 5) > 0;
|
|
1428
|
+
}
|
|
1429
|
+
function ConditionalExpression$1(node, parent, parentId) {
|
|
1430
|
+
switch (parentId) {
|
|
1431
|
+
case 236:
|
|
1432
|
+
case 143:
|
|
1433
|
+
case 11:
|
|
1434
|
+
case 108:
|
|
1435
|
+
case 8: return true;
|
|
1436
|
+
case 29: if (parent.test === node) return true;
|
|
1437
|
+
}
|
|
1438
|
+
if (isTSTypeExpression(parentId)) return true;
|
|
1439
|
+
return UnaryLike(node, parent, parentId);
|
|
1440
|
+
}
|
|
1441
|
+
function OptionalMemberExpression$1(node, parent, parentId) {
|
|
1442
|
+
switch (parentId) {
|
|
1443
|
+
case 18: return parent.callee === node;
|
|
1444
|
+
case 109: return parent.object === node;
|
|
1445
|
+
}
|
|
1446
|
+
return false;
|
|
1447
|
+
}
|
|
1448
|
+
function AssignmentExpression$1(node, parent, parentId, tokenContext) {
|
|
1449
|
+
if (needsParenBeforeExpressionBrace(tokenContext) && node.left.type === "ObjectPattern") return true;
|
|
1450
|
+
return ConditionalExpression$1(node, parent, parentId);
|
|
1451
|
+
}
|
|
1452
|
+
function Identifier$1(node, parent, parentId, tokenContext, getRawIdentifier) {
|
|
1453
|
+
if (getRawIdentifier && getRawIdentifier(node) !== node.name) return false;
|
|
1454
|
+
if (parentId === 6 && node.extra?.parenthesized && parent.left === node) {
|
|
1455
|
+
const rightType = parent.right.type;
|
|
1456
|
+
if ((rightType === "FunctionExpression" || rightType === "ClassExpression") && parent.right.id == null) return true;
|
|
1457
|
+
}
|
|
1458
|
+
if (tokenContext & 64 || (parentId === 109 || parentId === 133) && tokenContext & 49) {
|
|
1459
|
+
if (node.name === "let") {
|
|
1460
|
+
if ((isMemberExpression$1(parent, {
|
|
1461
|
+
object: node,
|
|
1462
|
+
computed: true
|
|
1463
|
+
}) || isOptionalMemberExpression(parent, {
|
|
1464
|
+
object: node,
|
|
1465
|
+
computed: true,
|
|
1466
|
+
optional: false
|
|
1467
|
+
})) && tokenContext & 49) return true;
|
|
1468
|
+
return (tokenContext & 64) > 0;
|
|
1469
|
+
}
|
|
1470
|
+
}
|
|
1471
|
+
return parentId === 69 && parent.left === node && node.name === "async" && !parent.await;
|
|
1472
|
+
}
|
|
1473
|
+
var parens = /*#__PURE__*/ Object.defineProperty({
|
|
1474
|
+
__proto__: null,
|
|
1475
|
+
ArrowFunctionExpression: ConditionalExpression$1,
|
|
1476
|
+
AssignmentExpression: AssignmentExpression$1,
|
|
1477
|
+
AwaitExpression: YieldExpression$1,
|
|
1478
|
+
BinaryExpression: BinaryExpression$1,
|
|
1479
|
+
ClassExpression,
|
|
1480
|
+
ConditionalExpression: ConditionalExpression$1,
|
|
1481
|
+
DoExpression: DoExpression$1,
|
|
1482
|
+
FunctionExpression: FunctionExpression$1,
|
|
1483
|
+
FunctionTypeAnnotation: FunctionTypeAnnotation$1,
|
|
1484
|
+
Identifier: Identifier$1,
|
|
1485
|
+
IntersectionTypeAnnotation: UnionTypeAnnotation$1,
|
|
1486
|
+
LogicalExpression,
|
|
1487
|
+
NullableTypeAnnotation: NullableTypeAnnotation$1,
|
|
1488
|
+
ObjectExpression: ObjectExpression$1,
|
|
1489
|
+
OptionalCallExpression: OptionalMemberExpression$1,
|
|
1490
|
+
OptionalIndexedAccessType: OptionalIndexedAccessType$1,
|
|
1491
|
+
OptionalMemberExpression: OptionalMemberExpression$1,
|
|
1492
|
+
SequenceExpression: SequenceExpression$1,
|
|
1493
|
+
SpreadElement: UnaryLike,
|
|
1494
|
+
TSAsExpression: TSAsExpression$1,
|
|
1495
|
+
TSConditionalType: TSConditionalType$1,
|
|
1496
|
+
TSConstructorType: TSFunctionType$1,
|
|
1497
|
+
TSFunctionType: TSFunctionType$1,
|
|
1498
|
+
TSInferType: TSInferType$1,
|
|
1499
|
+
TSInstantiationExpression: TSInstantiationExpression$1,
|
|
1500
|
+
TSIntersectionType: TSIntersectionType$1,
|
|
1501
|
+
TSSatisfiesExpression: TSAsExpression$1,
|
|
1502
|
+
TSTypeAssertion: UnaryLike,
|
|
1503
|
+
TSTypeOperator: TSTypeOperator$1,
|
|
1504
|
+
TSUnionType: TSUnionType$1,
|
|
1505
|
+
UnaryExpression: UnaryLike,
|
|
1506
|
+
UnionTypeAnnotation: UnionTypeAnnotation$1,
|
|
1507
|
+
UpdateExpression: UpdateExpression$1,
|
|
1508
|
+
YieldExpression: YieldExpression$1
|
|
1509
|
+
}, Symbol.toStringTag, { value: "Module" });
|
|
1510
|
+
function TaggedTemplateExpression(node) {
|
|
1511
|
+
this.print(node.tag);
|
|
1512
|
+
this.print(node.typeArguments);
|
|
1513
|
+
this.print(node.quasi);
|
|
1514
|
+
}
|
|
1515
|
+
function TemplateElement() {
|
|
1516
|
+
throw new Error("TemplateElement printing is handled in TemplateLiteral");
|
|
1517
|
+
}
|
|
1518
|
+
function _printTemplate(node, substitutions) {
|
|
1519
|
+
const quasis = node.quasis;
|
|
1520
|
+
let partRaw = "`";
|
|
1521
|
+
for (let i = 0; i < quasis.length - 1; i++) {
|
|
1522
|
+
partRaw += quasis[i].value.raw;
|
|
1523
|
+
this.token(partRaw + "${", true);
|
|
1524
|
+
this.print(substitutions[i]);
|
|
1525
|
+
partRaw = "}";
|
|
1526
|
+
}
|
|
1527
|
+
partRaw += quasis[quasis.length - 1].value.raw;
|
|
1528
|
+
this.token(partRaw + "`", true);
|
|
1529
|
+
}
|
|
1530
|
+
function TemplateLiteral(node) {
|
|
1531
|
+
_printTemplate.call(this, node, node.expressions);
|
|
1532
|
+
}
|
|
1533
|
+
var { isCallExpression, isLiteral, isMemberExpression, isNewExpression, isPattern } = _t;
|
|
1534
|
+
function UnaryExpression(node) {
|
|
1535
|
+
const { operator } = node;
|
|
1536
|
+
const firstChar = operator.charCodeAt(0);
|
|
1537
|
+
if (firstChar >= 97 && firstChar <= 122) {
|
|
1538
|
+
this.word(operator);
|
|
1539
|
+
this.space();
|
|
1540
|
+
} else this.tokenChar(firstChar);
|
|
1541
|
+
this.print(node.argument);
|
|
1542
|
+
}
|
|
1543
|
+
function DoExpression(node) {
|
|
1544
|
+
if (node.async) {
|
|
1545
|
+
this.word("async", true);
|
|
1546
|
+
this.space();
|
|
1547
|
+
}
|
|
1548
|
+
this.word("do");
|
|
1549
|
+
this.space();
|
|
1550
|
+
this.print(node.body);
|
|
1551
|
+
}
|
|
1552
|
+
function ParenthesizedExpression(node) {
|
|
1553
|
+
this.tokenChar(40);
|
|
1554
|
+
const oldNoLineTerminatorAfterNode = this.enterDelimited();
|
|
1555
|
+
this.print(node.expression, void 0, true);
|
|
1556
|
+
this._noLineTerminatorAfterNode = oldNoLineTerminatorAfterNode;
|
|
1557
|
+
this.rightParens(node);
|
|
1558
|
+
}
|
|
1559
|
+
function UpdateExpression(node) {
|
|
1560
|
+
if (node.prefix) {
|
|
1561
|
+
this.token(node.operator, false, 0, true);
|
|
1562
|
+
this.print(node.argument);
|
|
1563
|
+
} else {
|
|
1564
|
+
this.print(node.argument, true);
|
|
1565
|
+
this.token(node.operator, false, 0, true);
|
|
1566
|
+
}
|
|
1567
|
+
}
|
|
1568
|
+
function ConditionalExpression(node) {
|
|
1569
|
+
this.print(node.test);
|
|
1570
|
+
this.space();
|
|
1571
|
+
this.tokenChar(63);
|
|
1572
|
+
this.space();
|
|
1573
|
+
this.print(node.consequent);
|
|
1574
|
+
this.space();
|
|
1575
|
+
this.tokenChar(58);
|
|
1576
|
+
this.space();
|
|
1577
|
+
this.print(node.alternate);
|
|
1578
|
+
}
|
|
1579
|
+
function _printExpressionArguments(node) {
|
|
1580
|
+
this.tokenChar(40);
|
|
1581
|
+
const oldNoLineTerminatorAfterNode = this.enterDelimited();
|
|
1582
|
+
this.printList(node.arguments, this.shouldPrintTrailingComma(")"), void 0, void 0, void 0, true);
|
|
1583
|
+
this._noLineTerminatorAfterNode = oldNoLineTerminatorAfterNode;
|
|
1584
|
+
this.rightParens(node);
|
|
1585
|
+
}
|
|
1586
|
+
function NewExpression(node, parent) {
|
|
1587
|
+
this.word("new");
|
|
1588
|
+
this.space();
|
|
1589
|
+
this.print(node.callee);
|
|
1590
|
+
if (this.format.minified && node.arguments.length === 0 && !isCallExpression(parent, { callee: node }) && !isMemberExpression(parent) && !isNewExpression(parent)) return;
|
|
1591
|
+
this.print(node.typeArguments);
|
|
1592
|
+
if (node.arguments.length === 0 && this.tokenMap && !this.tokenMap.endMatches(node, ")")) return;
|
|
1593
|
+
_printExpressionArguments.call(this, node);
|
|
1594
|
+
}
|
|
1595
|
+
function SequenceExpression(node) {
|
|
1596
|
+
this.printList(node.expressions);
|
|
1597
|
+
}
|
|
1598
|
+
function ThisExpression() {
|
|
1599
|
+
this.word("this");
|
|
1600
|
+
}
|
|
1601
|
+
function Super() {
|
|
1602
|
+
this.word("super");
|
|
1603
|
+
}
|
|
1604
|
+
function _shouldPrintDecoratorsBeforeExport(node) {
|
|
1605
|
+
return typeof node.start === "number" && node.start === node.declaration.start;
|
|
1606
|
+
}
|
|
1607
|
+
function Decorator(node) {
|
|
1608
|
+
this.tokenChar(64);
|
|
1609
|
+
const { expression } = node;
|
|
1610
|
+
this.print(expression);
|
|
1611
|
+
this.newline();
|
|
1612
|
+
}
|
|
1613
|
+
function OptionalMemberExpression(node) {
|
|
1614
|
+
let { computed } = node;
|
|
1615
|
+
const { optional, property } = node;
|
|
1616
|
+
this.print(node.object);
|
|
1617
|
+
if (!computed && isMemberExpression(property)) throw new TypeError("Got a MemberExpression for MemberExpression property");
|
|
1618
|
+
if (isLiteral(property) && typeof property.value === "number") computed = true;
|
|
1619
|
+
if (optional) this.token("?.");
|
|
1620
|
+
if (computed) {
|
|
1621
|
+
this.tokenChar(91);
|
|
1622
|
+
this.print(property);
|
|
1623
|
+
this.tokenChar(93);
|
|
1624
|
+
} else {
|
|
1625
|
+
if (!optional) this.tokenChar(46);
|
|
1626
|
+
this.print(property);
|
|
1627
|
+
}
|
|
1628
|
+
}
|
|
1629
|
+
function OptionalCallExpression(node) {
|
|
1630
|
+
this.print(node.callee);
|
|
1631
|
+
if (node.optional) this.token("?.");
|
|
1632
|
+
this.print(node.typeArguments);
|
|
1633
|
+
_printExpressionArguments.call(this, node);
|
|
1634
|
+
}
|
|
1635
|
+
function CallExpression(node) {
|
|
1636
|
+
this.print(node.callee);
|
|
1637
|
+
this.print(node.typeArguments);
|
|
1638
|
+
_printExpressionArguments.call(this, node);
|
|
1639
|
+
}
|
|
1640
|
+
function Import() {
|
|
1641
|
+
this.word("import");
|
|
1642
|
+
}
|
|
1643
|
+
function AwaitExpression(node) {
|
|
1644
|
+
this.word("await");
|
|
1645
|
+
this.space();
|
|
1646
|
+
this.print(node.argument);
|
|
1647
|
+
}
|
|
1648
|
+
function YieldExpression(node) {
|
|
1649
|
+
if (node.delegate) {
|
|
1650
|
+
this.word("yield", true);
|
|
1651
|
+
this.tokenChar(42);
|
|
1652
|
+
if (node.argument) {
|
|
1653
|
+
this.space();
|
|
1654
|
+
this.print(node.argument);
|
|
1655
|
+
}
|
|
1656
|
+
} else if (node.argument) {
|
|
1657
|
+
this.word("yield", true);
|
|
1658
|
+
this.space();
|
|
1659
|
+
this.print(node.argument);
|
|
1660
|
+
} else this.word("yield");
|
|
1661
|
+
}
|
|
1662
|
+
function EmptyStatement() {
|
|
1663
|
+
this.semicolon(true);
|
|
1664
|
+
}
|
|
1665
|
+
function ExpressionStatement(node) {
|
|
1666
|
+
this.tokenContext |= 1;
|
|
1667
|
+
this.print(node.expression);
|
|
1668
|
+
this.semicolon();
|
|
1669
|
+
}
|
|
1670
|
+
function AssignmentPattern(node) {
|
|
1671
|
+
this.print(node.left);
|
|
1672
|
+
if (node.left.type === "Identifier" || isPattern(node.left)) {
|
|
1673
|
+
if (node.left.optional) this.tokenChar(63);
|
|
1674
|
+
this.print(node.left.typeAnnotation);
|
|
1675
|
+
}
|
|
1676
|
+
this.space();
|
|
1677
|
+
this.tokenChar(61);
|
|
1678
|
+
this.space();
|
|
1679
|
+
this.print(node.right);
|
|
1680
|
+
}
|
|
1681
|
+
function AssignmentExpression(node) {
|
|
1682
|
+
this.print(node.left);
|
|
1683
|
+
this.space();
|
|
1684
|
+
this.token(node.operator, false, 0, true);
|
|
1685
|
+
this.space();
|
|
1686
|
+
this.print(node.right);
|
|
1687
|
+
}
|
|
1688
|
+
function BinaryExpression(node) {
|
|
1689
|
+
this.print(node.left);
|
|
1690
|
+
this.space();
|
|
1691
|
+
const { operator } = node;
|
|
1692
|
+
if (operator.charCodeAt(0) === 105) this.word(operator);
|
|
1693
|
+
else {
|
|
1694
|
+
this.token(operator, false, 0, true);
|
|
1695
|
+
this.setLastChar(operator.charCodeAt(operator.length - 1));
|
|
1696
|
+
}
|
|
1697
|
+
this.space();
|
|
1698
|
+
this.print(node.right);
|
|
1699
|
+
}
|
|
1700
|
+
function BindExpression(node) {
|
|
1701
|
+
this.print(node.object);
|
|
1702
|
+
this.token("::");
|
|
1703
|
+
this.print(node.callee);
|
|
1704
|
+
}
|
|
1705
|
+
function MemberExpression(node) {
|
|
1706
|
+
this.print(node.object);
|
|
1707
|
+
if (!node.computed && isMemberExpression(node.property)) throw new TypeError("Got a MemberExpression for MemberExpression property");
|
|
1708
|
+
let computed = node.computed;
|
|
1709
|
+
if (isLiteral(node.property) && typeof node.property.value === "number") computed = true;
|
|
1710
|
+
if (computed) {
|
|
1711
|
+
const oldNoLineTerminatorAfterNode = this.enterDelimited();
|
|
1712
|
+
this.tokenChar(91);
|
|
1713
|
+
this.print(node.property, void 0, true);
|
|
1714
|
+
this.tokenChar(93);
|
|
1715
|
+
this._noLineTerminatorAfterNode = oldNoLineTerminatorAfterNode;
|
|
1716
|
+
} else {
|
|
1717
|
+
this.tokenChar(46);
|
|
1718
|
+
this.print(node.property);
|
|
1719
|
+
}
|
|
1720
|
+
}
|
|
1721
|
+
function MetaProperty(node) {
|
|
1722
|
+
this.print(node.meta);
|
|
1723
|
+
this.tokenChar(46);
|
|
1724
|
+
this.print(node.property);
|
|
1725
|
+
}
|
|
1726
|
+
function PrivateName(node) {
|
|
1727
|
+
this.tokenChar(35);
|
|
1728
|
+
this.print(node.id);
|
|
1729
|
+
}
|
|
1730
|
+
function V8IntrinsicIdentifier(node) {
|
|
1731
|
+
this.tokenChar(37);
|
|
1732
|
+
this.word(node.name);
|
|
1733
|
+
}
|
|
1734
|
+
function ModuleExpression(node) {
|
|
1735
|
+
this.word("module", true);
|
|
1736
|
+
this.space();
|
|
1737
|
+
this.tokenChar(123);
|
|
1738
|
+
this.indent();
|
|
1739
|
+
const { body } = node;
|
|
1740
|
+
if (body.body.length || body.directives.length) this.newline();
|
|
1741
|
+
this.print(body);
|
|
1742
|
+
this.dedent();
|
|
1743
|
+
this.rightBrace(node);
|
|
1744
|
+
}
|
|
1745
|
+
var { isFor, isIfStatement, isStatement: isStatement$3, isVoidPattern } = _t;
|
|
1746
|
+
function WithStatement(node) {
|
|
1747
|
+
this.word("with");
|
|
1748
|
+
this.space();
|
|
1749
|
+
this.tokenChar(40);
|
|
1750
|
+
this.print(node.object);
|
|
1751
|
+
this.tokenChar(41);
|
|
1752
|
+
this.printBlock(node.body);
|
|
1753
|
+
}
|
|
1754
|
+
function IfStatement(node) {
|
|
1755
|
+
this.word("if");
|
|
1756
|
+
this.space();
|
|
1757
|
+
this.tokenChar(40);
|
|
1758
|
+
this.print(node.test);
|
|
1759
|
+
this.tokenChar(41);
|
|
1760
|
+
this.space();
|
|
1761
|
+
const needsBlock = node.alternate && isIfStatement(getLastStatement(node.consequent));
|
|
1762
|
+
if (needsBlock) {
|
|
1763
|
+
this.tokenChar(123);
|
|
1764
|
+
this.newline();
|
|
1765
|
+
this.indent();
|
|
1766
|
+
}
|
|
1767
|
+
this.printAndIndentOnComments(node.consequent);
|
|
1768
|
+
if (needsBlock) {
|
|
1769
|
+
this.dedent();
|
|
1770
|
+
this.newline();
|
|
1771
|
+
this.tokenChar(125);
|
|
1772
|
+
}
|
|
1773
|
+
if (node.alternate) {
|
|
1774
|
+
if (this.endsWith(125)) this.space();
|
|
1775
|
+
this.word("else");
|
|
1776
|
+
this.space();
|
|
1777
|
+
this.printAndIndentOnComments(node.alternate);
|
|
1778
|
+
}
|
|
1779
|
+
}
|
|
1780
|
+
function getLastStatement(statement) {
|
|
1781
|
+
const { body } = statement;
|
|
1782
|
+
if (isStatement$3(body) === false) return statement;
|
|
1783
|
+
return getLastStatement(body);
|
|
1784
|
+
}
|
|
1785
|
+
function ForStatement(node) {
|
|
1786
|
+
this.word("for");
|
|
1787
|
+
this.space();
|
|
1788
|
+
this.tokenChar(40);
|
|
1789
|
+
this.tokenContext |= 144;
|
|
1790
|
+
this.print(node.init);
|
|
1791
|
+
this.tokenContext = 0;
|
|
1792
|
+
this.tokenChar(59);
|
|
1793
|
+
if (node.test) {
|
|
1794
|
+
this.space();
|
|
1795
|
+
this.print(node.test);
|
|
1796
|
+
}
|
|
1797
|
+
this.tokenChar(59, 1);
|
|
1798
|
+
if (node.update) {
|
|
1799
|
+
this.space();
|
|
1800
|
+
this.print(node.update);
|
|
1801
|
+
}
|
|
1802
|
+
this.tokenChar(41);
|
|
1803
|
+
this.printBlock(node.body);
|
|
1804
|
+
}
|
|
1805
|
+
function WhileStatement(node) {
|
|
1806
|
+
this.word("while");
|
|
1807
|
+
this.space();
|
|
1808
|
+
this.tokenChar(40);
|
|
1809
|
+
this.print(node.test);
|
|
1810
|
+
this.tokenChar(41);
|
|
1811
|
+
this.printBlock(node.body);
|
|
1812
|
+
}
|
|
1813
|
+
function ForInStatement(node) {
|
|
1814
|
+
this.word("for");
|
|
1815
|
+
this.space();
|
|
1816
|
+
this.noIndentInnerCommentsHere();
|
|
1817
|
+
this.tokenChar(40);
|
|
1818
|
+
this.tokenContext |= 160;
|
|
1819
|
+
this.print(node.left);
|
|
1820
|
+
this.tokenContext = 0;
|
|
1821
|
+
this.space();
|
|
1822
|
+
this.word("in");
|
|
1823
|
+
this.space();
|
|
1824
|
+
this.print(node.right);
|
|
1825
|
+
this.tokenChar(41);
|
|
1826
|
+
this.printBlock(node.body);
|
|
1827
|
+
}
|
|
1828
|
+
function ForOfStatement(node) {
|
|
1829
|
+
this.word("for");
|
|
1830
|
+
this.space();
|
|
1831
|
+
if (node.await) {
|
|
1832
|
+
this.word("await");
|
|
1833
|
+
this.space();
|
|
1834
|
+
}
|
|
1835
|
+
this.noIndentInnerCommentsHere();
|
|
1836
|
+
this.tokenChar(40);
|
|
1837
|
+
this.tokenContext |= 64;
|
|
1838
|
+
this.print(node.left);
|
|
1839
|
+
this.space();
|
|
1840
|
+
this.word("of");
|
|
1841
|
+
this.space();
|
|
1842
|
+
this.print(node.right);
|
|
1843
|
+
this.tokenChar(41);
|
|
1844
|
+
this.printBlock(node.body);
|
|
1845
|
+
}
|
|
1846
|
+
function DoWhileStatement(node) {
|
|
1847
|
+
this.word("do");
|
|
1848
|
+
this.space();
|
|
1849
|
+
this.print(node.body);
|
|
1850
|
+
this.space();
|
|
1851
|
+
this.word("while");
|
|
1852
|
+
this.space();
|
|
1853
|
+
this.tokenChar(40);
|
|
1854
|
+
this.print(node.test);
|
|
1855
|
+
this.tokenChar(41);
|
|
1856
|
+
this.semicolon();
|
|
1857
|
+
}
|
|
1858
|
+
function printStatementAfterKeyword(printer, node) {
|
|
1859
|
+
if (node) {
|
|
1860
|
+
printer.space();
|
|
1861
|
+
printer.printTerminatorless(node);
|
|
1862
|
+
}
|
|
1863
|
+
printer.semicolon();
|
|
1864
|
+
}
|
|
1865
|
+
function BreakStatement(node) {
|
|
1866
|
+
this.word("break");
|
|
1867
|
+
printStatementAfterKeyword(this, node.label);
|
|
1868
|
+
}
|
|
1869
|
+
function ContinueStatement(node) {
|
|
1870
|
+
this.word("continue");
|
|
1871
|
+
printStatementAfterKeyword(this, node.label);
|
|
1872
|
+
}
|
|
1873
|
+
function ReturnStatement(node) {
|
|
1874
|
+
this.word("return");
|
|
1875
|
+
printStatementAfterKeyword(this, node.argument);
|
|
1876
|
+
}
|
|
1877
|
+
function ThrowStatement(node) {
|
|
1878
|
+
this.word("throw");
|
|
1879
|
+
printStatementAfterKeyword(this, node.argument);
|
|
1880
|
+
}
|
|
1881
|
+
function LabeledStatement(node) {
|
|
1882
|
+
this.print(node.label);
|
|
1883
|
+
this.tokenChar(58);
|
|
1884
|
+
this.space();
|
|
1885
|
+
this.print(node.body);
|
|
1886
|
+
}
|
|
1887
|
+
function TryStatement(node) {
|
|
1888
|
+
this.word("try");
|
|
1889
|
+
this.space();
|
|
1890
|
+
this.print(node.block);
|
|
1891
|
+
this.space();
|
|
1892
|
+
if (node.handlers) this.print(node.handlers[0]);
|
|
1893
|
+
else this.print(node.handler);
|
|
1894
|
+
if (node.finalizer) {
|
|
1895
|
+
this.space();
|
|
1896
|
+
this.word("finally");
|
|
1897
|
+
this.space();
|
|
1898
|
+
this.print(node.finalizer);
|
|
1899
|
+
}
|
|
1900
|
+
}
|
|
1901
|
+
function CatchClause(node) {
|
|
1902
|
+
this.word("catch");
|
|
1903
|
+
this.space();
|
|
1904
|
+
if (node.param) {
|
|
1905
|
+
this.tokenChar(40);
|
|
1906
|
+
this.print(node.param);
|
|
1907
|
+
this.print(node.param.typeAnnotation);
|
|
1908
|
+
this.tokenChar(41);
|
|
1909
|
+
this.space();
|
|
1910
|
+
}
|
|
1911
|
+
this.print(node.body);
|
|
1912
|
+
}
|
|
1913
|
+
function SwitchStatement(node) {
|
|
1914
|
+
this.word("switch");
|
|
1915
|
+
this.space();
|
|
1916
|
+
this.tokenChar(40);
|
|
1917
|
+
this.print(node.discriminant);
|
|
1918
|
+
this.tokenChar(41);
|
|
1919
|
+
this.space();
|
|
1920
|
+
this.tokenChar(123);
|
|
1921
|
+
this.printSequence(node.cases, true);
|
|
1922
|
+
this.rightBrace(node);
|
|
1923
|
+
}
|
|
1924
|
+
function SwitchCase(node) {
|
|
1925
|
+
if (node.test) {
|
|
1926
|
+
this.word("case");
|
|
1927
|
+
this.space();
|
|
1928
|
+
this.print(node.test);
|
|
1929
|
+
this.tokenChar(58);
|
|
1930
|
+
} else {
|
|
1931
|
+
this.word("default");
|
|
1932
|
+
this.tokenChar(58);
|
|
1933
|
+
}
|
|
1934
|
+
if (node.consequent.length) {
|
|
1935
|
+
this.newline();
|
|
1936
|
+
this.printSequence(node.consequent, true);
|
|
1937
|
+
}
|
|
1938
|
+
}
|
|
1939
|
+
function DebuggerStatement() {
|
|
1940
|
+
this.word("debugger");
|
|
1941
|
+
this.semicolon();
|
|
1942
|
+
}
|
|
1943
|
+
function commaSeparatorWithNewline(occurrenceCount) {
|
|
1944
|
+
this.tokenChar(44, occurrenceCount);
|
|
1945
|
+
this.newline();
|
|
1946
|
+
}
|
|
1947
|
+
function VariableDeclaration(node, parent) {
|
|
1948
|
+
if (node.declare) {
|
|
1949
|
+
this.word("declare");
|
|
1950
|
+
this.space();
|
|
1951
|
+
}
|
|
1952
|
+
const { kind } = node;
|
|
1953
|
+
switch (kind) {
|
|
1954
|
+
case "await using":
|
|
1955
|
+
this.word("await");
|
|
1956
|
+
this.space();
|
|
1957
|
+
case "using":
|
|
1958
|
+
this.word("using", true);
|
|
1959
|
+
break;
|
|
1960
|
+
default: this.word(kind);
|
|
1961
|
+
}
|
|
1962
|
+
this.space();
|
|
1963
|
+
let hasInits = false;
|
|
1964
|
+
if (!isFor(parent)) {
|
|
1965
|
+
for (const declar of node.declarations) if (declar.init) {
|
|
1966
|
+
hasInits = true;
|
|
1967
|
+
break;
|
|
1968
|
+
}
|
|
1969
|
+
}
|
|
1970
|
+
this.printList(node.declarations, void 0, void 0, node.declarations.length > 1, hasInits ? commaSeparatorWithNewline : void 0);
|
|
1971
|
+
if (parent != null) switch (parent.type) {
|
|
1972
|
+
case "ForStatement":
|
|
1973
|
+
if (parent.init === node) return;
|
|
1974
|
+
break;
|
|
1975
|
+
case "ForInStatement":
|
|
1976
|
+
case "ForOfStatement": if (parent.left === node) return;
|
|
1977
|
+
}
|
|
1978
|
+
this.semicolon();
|
|
1979
|
+
}
|
|
1980
|
+
function VariableDeclarator(node) {
|
|
1981
|
+
this.print(node.id);
|
|
1982
|
+
if (node.definite) this.tokenChar(33);
|
|
1983
|
+
if (!isVoidPattern(node.id)) this.print(node.id.typeAnnotation);
|
|
1984
|
+
if (node.init) {
|
|
1985
|
+
this.space();
|
|
1986
|
+
this.tokenChar(61);
|
|
1987
|
+
this.space();
|
|
1988
|
+
this.print(node.init);
|
|
1989
|
+
}
|
|
1990
|
+
}
|
|
1991
|
+
var { isIdentifier: isIdentifier$1 } = _t;
|
|
1992
|
+
function _params(node, noLineTerminator, idNode, parentNode) {
|
|
1993
|
+
this.print(node.typeParameters);
|
|
1994
|
+
if (idNode !== void 0 || parentNode !== void 0) {
|
|
1995
|
+
const nameInfo = _getFuncIdName.call(this, idNode, parentNode);
|
|
1996
|
+
if (nameInfo) this.sourceIdentifierName(nameInfo.name, nameInfo.pos);
|
|
1997
|
+
}
|
|
1998
|
+
this.tokenChar(40);
|
|
1999
|
+
_parameters.call(this, node.params, 41);
|
|
2000
|
+
this.print(node.returnType, noLineTerminator);
|
|
2001
|
+
this._noLineTerminator = noLineTerminator;
|
|
2002
|
+
}
|
|
2003
|
+
function _parameters(parameters, endToken) {
|
|
2004
|
+
const oldNoLineTerminatorAfterNode = this.enterDelimited();
|
|
2005
|
+
const trailingComma = this.shouldPrintTrailingComma(endToken);
|
|
2006
|
+
const paramLength = parameters.length;
|
|
2007
|
+
for (let i = 0; i < paramLength; i++) {
|
|
2008
|
+
_param.call(this, parameters[i]);
|
|
2009
|
+
if (trailingComma || i < paramLength - 1) {
|
|
2010
|
+
this.tokenChar(44, i);
|
|
2011
|
+
this.space();
|
|
2012
|
+
}
|
|
2013
|
+
}
|
|
2014
|
+
this.tokenChar(endToken);
|
|
2015
|
+
this._noLineTerminatorAfterNode = oldNoLineTerminatorAfterNode;
|
|
2016
|
+
}
|
|
2017
|
+
function _param(parameter) {
|
|
2018
|
+
this.printJoin(parameter.decorators, void 0, void 0, void 0, void 0, true);
|
|
2019
|
+
this.print(parameter, void 0, true);
|
|
2020
|
+
if (parameter.optional) this.tokenChar(63);
|
|
2021
|
+
this.print(parameter.typeAnnotation, void 0, true);
|
|
2022
|
+
}
|
|
2023
|
+
function _methodHead(node) {
|
|
2024
|
+
const kind = node.kind;
|
|
2025
|
+
const key = node.key;
|
|
2026
|
+
if (kind === "get" || kind === "set") {
|
|
2027
|
+
this.word(kind);
|
|
2028
|
+
this.space();
|
|
2029
|
+
}
|
|
2030
|
+
if (node.async) {
|
|
2031
|
+
this.word("async", true);
|
|
2032
|
+
this.space();
|
|
2033
|
+
}
|
|
2034
|
+
if (kind === "method" || kind === "init") {
|
|
2035
|
+
if (node.generator) this.tokenChar(42);
|
|
2036
|
+
}
|
|
2037
|
+
if (node.computed) {
|
|
2038
|
+
this.tokenChar(91);
|
|
2039
|
+
this.print(key);
|
|
2040
|
+
this.tokenChar(93);
|
|
2041
|
+
} else this.print(key);
|
|
2042
|
+
if (node.optional) this.tokenChar(63);
|
|
2043
|
+
if (this._buf._map) _params.call(this, node, false, node.computed && node.key.type !== "StringLiteral" ? void 0 : node.key);
|
|
2044
|
+
else _params.call(this, node, false);
|
|
2045
|
+
}
|
|
2046
|
+
function _predicate(node, noLineTerminatorAfter) {
|
|
2047
|
+
if (node.predicate) {
|
|
2048
|
+
if (!node.returnType) this.tokenChar(58);
|
|
2049
|
+
this.space();
|
|
2050
|
+
this.print(node.predicate, noLineTerminatorAfter);
|
|
2051
|
+
}
|
|
2052
|
+
}
|
|
2053
|
+
function _functionHead(node, parent, hasPredicate) {
|
|
2054
|
+
if (node.async) {
|
|
2055
|
+
this.word("async");
|
|
2056
|
+
if (!this.format.preserveFormat) this._innerCommentsState = 0;
|
|
2057
|
+
this.space();
|
|
2058
|
+
}
|
|
2059
|
+
this.word("function");
|
|
2060
|
+
if (node.generator) {
|
|
2061
|
+
if (!this.format.preserveFormat) this._innerCommentsState = 0;
|
|
2062
|
+
this.tokenChar(42);
|
|
2063
|
+
}
|
|
2064
|
+
this.space();
|
|
2065
|
+
if (node.id) this.print(node.id);
|
|
2066
|
+
if (this._buf._map) _params.call(this, node, false, node.id, parent);
|
|
2067
|
+
else _params.call(this, node, false);
|
|
2068
|
+
if (hasPredicate) _predicate.call(this, node);
|
|
2069
|
+
}
|
|
2070
|
+
function FunctionExpression(node, parent) {
|
|
2071
|
+
_functionHead.call(this, node, parent, true);
|
|
2072
|
+
this.space();
|
|
2073
|
+
this.print(node.body);
|
|
2074
|
+
}
|
|
2075
|
+
function ArrowFunctionExpression(node, parent) {
|
|
2076
|
+
if (node.async) {
|
|
2077
|
+
this.word("async", true);
|
|
2078
|
+
this.space();
|
|
2079
|
+
}
|
|
2080
|
+
if (_shouldPrintArrowParamsParens.call(this, node)) _params.call(this, node, true, void 0, this._buf._map ? parent : void 0);
|
|
2081
|
+
else this.print(node.params[0], true);
|
|
2082
|
+
_predicate.call(this, node, true);
|
|
2083
|
+
this.space();
|
|
2084
|
+
this.printInnerComments();
|
|
2085
|
+
this.token("=>");
|
|
2086
|
+
this.space();
|
|
2087
|
+
this.tokenContext |= 2;
|
|
2088
|
+
this.print(node.body);
|
|
2089
|
+
}
|
|
2090
|
+
function _shouldPrintArrowParamsParens(node) {
|
|
2091
|
+
if (node.params.length !== 1) return true;
|
|
2092
|
+
if (node.typeParameters || node.returnType || node.predicate) return true;
|
|
2093
|
+
const firstParam = node.params[0];
|
|
2094
|
+
if (!isIdentifier$1(firstParam) || firstParam.typeAnnotation || firstParam.optional || firstParam.leadingComments?.length || firstParam.trailingComments?.length) return true;
|
|
2095
|
+
if (this.tokenMap) {
|
|
2096
|
+
if (node.loc == null) return true;
|
|
2097
|
+
if (this.tokenMap.findMatching(node, "(") !== null) return true;
|
|
2098
|
+
const arrowToken = this.tokenMap.findMatching(node, "=>");
|
|
2099
|
+
if (arrowToken?.loc == null) return true;
|
|
2100
|
+
return arrowToken.loc.start.line !== node.loc.start.line;
|
|
2101
|
+
}
|
|
2102
|
+
if (this.format.retainLines) return true;
|
|
2103
|
+
return false;
|
|
2104
|
+
}
|
|
2105
|
+
function isRenamedIdentifier(id) {
|
|
2106
|
+
return !!id.loc?.identifierName && id.loc.identifierName !== id.name;
|
|
2107
|
+
}
|
|
2108
|
+
function _getFuncIdName(idNode, parent) {
|
|
2109
|
+
let id = idNode;
|
|
2110
|
+
if (!id && parent) {
|
|
2111
|
+
const parentType = parent.type;
|
|
2112
|
+
if (parentType === "VariableDeclarator") id = parent.id;
|
|
2113
|
+
else if (parentType === "AssignmentExpression" || parentType === "AssignmentPattern") id = parent.left;
|
|
2114
|
+
else if (parentType === "ObjectProperty" || parentType === "ClassProperty") {
|
|
2115
|
+
if (!parent.computed || parent.key.type === "StringLiteral") id = parent.key;
|
|
2116
|
+
} else if (parentType === "ClassPrivateProperty" || parentType === "ClassAccessorProperty") id = parent.key;
|
|
2117
|
+
}
|
|
2118
|
+
if (!id?.loc) return;
|
|
2119
|
+
let nameInfo;
|
|
2120
|
+
if (id.type === "Identifier") {
|
|
2121
|
+
if (!isRenamedIdentifier(id)) return;
|
|
2122
|
+
nameInfo = {
|
|
2123
|
+
pos: id.loc.start,
|
|
2124
|
+
name: id.loc.identifierName
|
|
2125
|
+
};
|
|
2126
|
+
} else if (id.type === "PrivateName") {
|
|
2127
|
+
if (!isRenamedIdentifier(id.id)) return;
|
|
2128
|
+
nameInfo = {
|
|
2129
|
+
pos: id.loc.start,
|
|
2130
|
+
name: "#" + id.id.loc.identifierName
|
|
2131
|
+
};
|
|
2132
|
+
} else if (id.type === "StringLiteral") nameInfo = {
|
|
2133
|
+
pos: id.loc.start,
|
|
2134
|
+
name: id.value
|
|
2135
|
+
};
|
|
2136
|
+
return nameInfo;
|
|
2137
|
+
}
|
|
2138
|
+
function TSTypeAnnotation(node, parent) {
|
|
2139
|
+
this.token((parent.type === "TSFunctionType" || parent.type === "TSConstructorType") && parent.returnType === node ? "=>" : ":");
|
|
2140
|
+
this.space();
|
|
2141
|
+
if (node.optional) this.tokenChar(63);
|
|
2142
|
+
this.print(node.typeAnnotation);
|
|
2143
|
+
}
|
|
2144
|
+
function TSTypeParameterInstantiation(node, parent) {
|
|
2145
|
+
this.tokenChar(60);
|
|
2146
|
+
let printTrailingSeparator = parent.type === "ArrowFunctionExpression" && node.params.length === 1;
|
|
2147
|
+
if (this.tokenMap && node.start != null && node.end != null) {
|
|
2148
|
+
printTrailingSeparator &&= !!this.tokenMap.find(node, (t) => this.tokenMap.matchesOriginal(t, ","));
|
|
2149
|
+
printTrailingSeparator ||= this.shouldPrintTrailingComma(">");
|
|
2150
|
+
}
|
|
2151
|
+
this.printList(node.params, printTrailingSeparator);
|
|
2152
|
+
this.tokenChar(62);
|
|
2153
|
+
}
|
|
2154
|
+
function TSTypeParameter(node) {
|
|
2155
|
+
if (node.const) {
|
|
2156
|
+
this.word("const");
|
|
2157
|
+
this.space();
|
|
2158
|
+
}
|
|
2159
|
+
if (node.in) {
|
|
2160
|
+
this.word("in");
|
|
2161
|
+
this.space();
|
|
2162
|
+
}
|
|
2163
|
+
if (node.out) {
|
|
2164
|
+
this.word("out");
|
|
2165
|
+
this.space();
|
|
2166
|
+
}
|
|
2167
|
+
this.word(node.name.name);
|
|
2168
|
+
if (node.constraint) {
|
|
2169
|
+
this.space();
|
|
2170
|
+
this.word("extends");
|
|
2171
|
+
this.space();
|
|
2172
|
+
this.print(node.constraint);
|
|
2173
|
+
}
|
|
2174
|
+
if (node.default) {
|
|
2175
|
+
this.space();
|
|
2176
|
+
this.tokenChar(61);
|
|
2177
|
+
this.space();
|
|
2178
|
+
this.print(node.default);
|
|
2179
|
+
}
|
|
2180
|
+
}
|
|
2181
|
+
function TSParameterProperty(node) {
|
|
2182
|
+
if (node.accessibility) {
|
|
2183
|
+
this.word(node.accessibility);
|
|
2184
|
+
this.space();
|
|
2185
|
+
}
|
|
2186
|
+
if (node.readonly) {
|
|
2187
|
+
this.word("readonly");
|
|
2188
|
+
this.space();
|
|
2189
|
+
}
|
|
2190
|
+
_param.call(this, node.parameter);
|
|
2191
|
+
}
|
|
2192
|
+
function TSDeclareFunction(node, parent) {
|
|
2193
|
+
if (node.declare) {
|
|
2194
|
+
this.word("declare");
|
|
2195
|
+
this.space();
|
|
2196
|
+
}
|
|
2197
|
+
_functionHead.call(this, node, parent, false);
|
|
2198
|
+
this.semicolon();
|
|
2199
|
+
}
|
|
2200
|
+
function TSDeclareMethod(node) {
|
|
2201
|
+
_classMethodHead.call(this, node, false);
|
|
2202
|
+
this.semicolon();
|
|
2203
|
+
}
|
|
2204
|
+
function TSQualifiedName(node) {
|
|
2205
|
+
this.print(node.left);
|
|
2206
|
+
this.tokenChar(46);
|
|
2207
|
+
this.print(node.right);
|
|
2208
|
+
}
|
|
2209
|
+
function TSCallSignatureDeclaration(node) {
|
|
2210
|
+
tsPrintSignatureDeclarationBase.call(this, node);
|
|
2211
|
+
maybePrintTrailingCommaOrSemicolon(this, node);
|
|
2212
|
+
}
|
|
2213
|
+
function maybePrintTrailingCommaOrSemicolon(printer, node) {
|
|
2214
|
+
if (!printer.tokenMap || !node.start || !node.end) {
|
|
2215
|
+
printer.semicolon();
|
|
2216
|
+
return;
|
|
2217
|
+
}
|
|
2218
|
+
if (printer.tokenMap.endMatches(node, ",")) printer.token(",");
|
|
2219
|
+
else if (printer.tokenMap.endMatches(node, ";")) printer.semicolon();
|
|
2220
|
+
}
|
|
2221
|
+
function TSConstructSignatureDeclaration(node) {
|
|
2222
|
+
this.word("new");
|
|
2223
|
+
this.space();
|
|
2224
|
+
tsPrintSignatureDeclarationBase.call(this, node);
|
|
2225
|
+
maybePrintTrailingCommaOrSemicolon(this, node);
|
|
2226
|
+
}
|
|
2227
|
+
function TSPropertySignature(node) {
|
|
2228
|
+
const { readonly } = node;
|
|
2229
|
+
if (readonly) {
|
|
2230
|
+
this.word("readonly");
|
|
2231
|
+
this.space();
|
|
2232
|
+
}
|
|
2233
|
+
tsPrintPropertyOrMethodName.call(this, node);
|
|
2234
|
+
this.print(node.typeAnnotation);
|
|
2235
|
+
maybePrintTrailingCommaOrSemicolon(this, node);
|
|
2236
|
+
}
|
|
2237
|
+
function tsPrintPropertyOrMethodName(node) {
|
|
2238
|
+
if (node.computed) this.tokenChar(91);
|
|
2239
|
+
this.print(node.key);
|
|
2240
|
+
if (node.computed) this.tokenChar(93);
|
|
2241
|
+
if (node.optional) this.tokenChar(63);
|
|
2242
|
+
}
|
|
2243
|
+
function TSMethodSignature(node) {
|
|
2244
|
+
const { kind } = node;
|
|
2245
|
+
if (kind === "set" || kind === "get") {
|
|
2246
|
+
this.word(kind);
|
|
2247
|
+
this.space();
|
|
2248
|
+
}
|
|
2249
|
+
tsPrintPropertyOrMethodName.call(this, node);
|
|
2250
|
+
tsPrintSignatureDeclarationBase.call(this, node);
|
|
2251
|
+
maybePrintTrailingCommaOrSemicolon(this, node);
|
|
2252
|
+
}
|
|
2253
|
+
function TSIndexSignature(node) {
|
|
2254
|
+
const { readonly, static: isStatic } = node;
|
|
2255
|
+
if (isStatic) {
|
|
2256
|
+
this.word("static");
|
|
2257
|
+
this.space();
|
|
2258
|
+
}
|
|
2259
|
+
if (readonly) {
|
|
2260
|
+
this.word("readonly");
|
|
2261
|
+
this.space();
|
|
2262
|
+
}
|
|
2263
|
+
this.tokenChar(91);
|
|
2264
|
+
_parameters.call(this, node.parameters, 93);
|
|
2265
|
+
this.print(node.typeAnnotation);
|
|
2266
|
+
maybePrintTrailingCommaOrSemicolon(this, node);
|
|
2267
|
+
}
|
|
2268
|
+
function TSAnyKeyword() {
|
|
2269
|
+
this.word("any");
|
|
2270
|
+
}
|
|
2271
|
+
function TSBigIntKeyword() {
|
|
2272
|
+
this.word("bigint");
|
|
2273
|
+
}
|
|
2274
|
+
function TSUnknownKeyword() {
|
|
2275
|
+
this.word("unknown");
|
|
2276
|
+
}
|
|
2277
|
+
function TSNumberKeyword() {
|
|
2278
|
+
this.word("number");
|
|
2279
|
+
}
|
|
2280
|
+
function TSObjectKeyword() {
|
|
2281
|
+
this.word("object");
|
|
2282
|
+
}
|
|
2283
|
+
function TSBooleanKeyword() {
|
|
2284
|
+
this.word("boolean");
|
|
2285
|
+
}
|
|
2286
|
+
function TSStringKeyword() {
|
|
2287
|
+
this.word("string");
|
|
2288
|
+
}
|
|
2289
|
+
function TSSymbolKeyword() {
|
|
2290
|
+
this.word("symbol");
|
|
2291
|
+
}
|
|
2292
|
+
function TSVoidKeyword() {
|
|
2293
|
+
this.word("void");
|
|
2294
|
+
}
|
|
2295
|
+
function TSUndefinedKeyword() {
|
|
2296
|
+
this.word("undefined");
|
|
2297
|
+
}
|
|
2298
|
+
function TSNullKeyword() {
|
|
2299
|
+
this.word("null");
|
|
2300
|
+
}
|
|
2301
|
+
function TSNeverKeyword() {
|
|
2302
|
+
this.word("never");
|
|
2303
|
+
}
|
|
2304
|
+
function TSIntrinsicKeyword() {
|
|
2305
|
+
this.word("intrinsic");
|
|
2306
|
+
}
|
|
2307
|
+
function TSThisType() {
|
|
2308
|
+
this.word("this");
|
|
2309
|
+
}
|
|
2310
|
+
function TSFunctionType(node) {
|
|
2311
|
+
tsPrintFunctionOrConstructorType.call(this, node);
|
|
2312
|
+
}
|
|
2313
|
+
function TSConstructorType(node) {
|
|
2314
|
+
if (node.abstract) {
|
|
2315
|
+
this.word("abstract");
|
|
2316
|
+
this.space();
|
|
2317
|
+
}
|
|
2318
|
+
this.word("new");
|
|
2319
|
+
this.space();
|
|
2320
|
+
tsPrintFunctionOrConstructorType.call(this, node);
|
|
2321
|
+
}
|
|
2322
|
+
function tsPrintFunctionOrConstructorType(node) {
|
|
2323
|
+
const { typeParameters } = node;
|
|
2324
|
+
const parameters = node.params;
|
|
2325
|
+
this.print(typeParameters);
|
|
2326
|
+
this.tokenChar(40);
|
|
2327
|
+
_parameters.call(this, parameters, 41);
|
|
2328
|
+
this.space();
|
|
2329
|
+
const returnType = node.returnType;
|
|
2330
|
+
this.print(returnType);
|
|
2331
|
+
}
|
|
2332
|
+
function TSTypeReference(node) {
|
|
2333
|
+
const typeArguments = node.typeArguments;
|
|
2334
|
+
this.print(node.typeName, !!typeArguments);
|
|
2335
|
+
this.print(typeArguments);
|
|
2336
|
+
}
|
|
2337
|
+
function TSTypePredicate(node) {
|
|
2338
|
+
if (node.asserts) {
|
|
2339
|
+
this.word("asserts");
|
|
2340
|
+
this.space();
|
|
2341
|
+
}
|
|
2342
|
+
this.print(node.parameterName);
|
|
2343
|
+
if (node.typeAnnotation) {
|
|
2344
|
+
this.space();
|
|
2345
|
+
this.word("is");
|
|
2346
|
+
this.space();
|
|
2347
|
+
this.print(node.typeAnnotation.typeAnnotation);
|
|
2348
|
+
}
|
|
2349
|
+
}
|
|
2350
|
+
function TSTypeQuery(node) {
|
|
2351
|
+
this.word("typeof");
|
|
2352
|
+
this.space();
|
|
2353
|
+
this.print(node.exprName);
|
|
2354
|
+
const typeArguments = node.typeArguments;
|
|
2355
|
+
if (typeArguments) this.print(typeArguments);
|
|
2356
|
+
}
|
|
2357
|
+
function TSTypeLiteral(node) {
|
|
2358
|
+
printBraced(this, node, () => this.printJoin(node.members, true, true, void 0, void 0, true));
|
|
2359
|
+
}
|
|
2360
|
+
function TSArrayType(node) {
|
|
2361
|
+
this.print(node.elementType, true);
|
|
2362
|
+
this.tokenChar(91);
|
|
2363
|
+
this.tokenChar(93);
|
|
2364
|
+
}
|
|
2365
|
+
function TSTupleType(node) {
|
|
2366
|
+
this.tokenChar(91);
|
|
2367
|
+
this.printList(node.elementTypes, this.shouldPrintTrailingComma("]"));
|
|
2368
|
+
this.tokenChar(93);
|
|
2369
|
+
}
|
|
2370
|
+
function TSOptionalType(node) {
|
|
2371
|
+
this.print(node.typeAnnotation);
|
|
2372
|
+
this.tokenChar(63);
|
|
2373
|
+
}
|
|
2374
|
+
function TSRestType(node) {
|
|
2375
|
+
this.token("...");
|
|
2376
|
+
this.print(node.typeAnnotation);
|
|
2377
|
+
}
|
|
2378
|
+
function TSNamedTupleMember(node) {
|
|
2379
|
+
this.print(node.label);
|
|
2380
|
+
if (node.optional) this.tokenChar(63);
|
|
2381
|
+
this.tokenChar(58);
|
|
2382
|
+
this.space();
|
|
2383
|
+
this.print(node.elementType);
|
|
2384
|
+
}
|
|
2385
|
+
function TSUnionType(node) {
|
|
2386
|
+
tsPrintUnionOrIntersectionType(this, node, "|");
|
|
2387
|
+
}
|
|
2388
|
+
function TSIntersectionType(node) {
|
|
2389
|
+
tsPrintUnionOrIntersectionType(this, node, "&");
|
|
2390
|
+
}
|
|
2391
|
+
function tsPrintUnionOrIntersectionType(printer, node, sep) {
|
|
2392
|
+
let hasLeadingToken = 0;
|
|
2393
|
+
if (printer.tokenMap?.startMatches(node, sep)) {
|
|
2394
|
+
hasLeadingToken = 1;
|
|
2395
|
+
printer.token(sep);
|
|
2396
|
+
}
|
|
2397
|
+
printer.printJoin(node.types, void 0, void 0, function(i) {
|
|
2398
|
+
this.space();
|
|
2399
|
+
this.token(sep, void 0, i + hasLeadingToken);
|
|
2400
|
+
this.space();
|
|
2401
|
+
});
|
|
2402
|
+
}
|
|
2403
|
+
function TSConditionalType(node) {
|
|
2404
|
+
this.print(node.checkType);
|
|
2405
|
+
this.space();
|
|
2406
|
+
this.word("extends");
|
|
2407
|
+
this.space();
|
|
2408
|
+
this.print(node.extendsType);
|
|
2409
|
+
this.space();
|
|
2410
|
+
this.tokenChar(63);
|
|
2411
|
+
this.space();
|
|
2412
|
+
this.print(node.trueType);
|
|
2413
|
+
this.space();
|
|
2414
|
+
this.tokenChar(58);
|
|
2415
|
+
this.space();
|
|
2416
|
+
this.print(node.falseType);
|
|
2417
|
+
}
|
|
2418
|
+
function TSInferType(node) {
|
|
2419
|
+
this.word("infer");
|
|
2420
|
+
this.print(node.typeParameter);
|
|
2421
|
+
}
|
|
2422
|
+
function TSParenthesizedType(node) {
|
|
2423
|
+
this.tokenChar(40);
|
|
2424
|
+
this.print(node.typeAnnotation);
|
|
2425
|
+
this.tokenChar(41);
|
|
2426
|
+
}
|
|
2427
|
+
function TSTypeOperator(node) {
|
|
2428
|
+
this.word(node.operator);
|
|
2429
|
+
this.space();
|
|
2430
|
+
this.print(node.typeAnnotation);
|
|
2431
|
+
}
|
|
2432
|
+
function TSIndexedAccessType(node) {
|
|
2433
|
+
this.print(node.objectType, true);
|
|
2434
|
+
this.tokenChar(91);
|
|
2435
|
+
this.print(node.indexType);
|
|
2436
|
+
this.tokenChar(93);
|
|
2437
|
+
}
|
|
2438
|
+
function TSMappedType(node) {
|
|
2439
|
+
const { nameType, optional, readonly, typeAnnotation } = node;
|
|
2440
|
+
this.tokenChar(123);
|
|
2441
|
+
const oldNoLineTerminatorAfterNode = this.enterDelimited();
|
|
2442
|
+
this.space();
|
|
2443
|
+
if (readonly) {
|
|
2444
|
+
tokenIfPlusMinus(this, readonly);
|
|
2445
|
+
this.word("readonly");
|
|
2446
|
+
this.space();
|
|
2447
|
+
}
|
|
2448
|
+
this.tokenChar(91);
|
|
2449
|
+
this.word(node.key.name);
|
|
2450
|
+
this.space();
|
|
2451
|
+
this.word("in");
|
|
2452
|
+
this.space();
|
|
2453
|
+
this.print(node.constraint);
|
|
2454
|
+
if (nameType) {
|
|
2455
|
+
this.space();
|
|
2456
|
+
this.word("as");
|
|
2457
|
+
this.space();
|
|
2458
|
+
this.print(nameType, void 0, true);
|
|
2459
|
+
}
|
|
2460
|
+
this.tokenChar(93);
|
|
2461
|
+
if (optional) {
|
|
2462
|
+
tokenIfPlusMinus(this, optional);
|
|
2463
|
+
this.tokenChar(63);
|
|
2464
|
+
}
|
|
2465
|
+
if (typeAnnotation) {
|
|
2466
|
+
this.tokenChar(58);
|
|
2467
|
+
this.space();
|
|
2468
|
+
this.print(typeAnnotation, void 0, true);
|
|
2469
|
+
}
|
|
2470
|
+
this.space();
|
|
2471
|
+
this._noLineTerminatorAfterNode = oldNoLineTerminatorAfterNode;
|
|
2472
|
+
this.tokenChar(125);
|
|
2473
|
+
}
|
|
2474
|
+
function tokenIfPlusMinus(self, tok) {
|
|
2475
|
+
if (tok !== true) self.token(tok);
|
|
2476
|
+
}
|
|
2477
|
+
function TSTemplateLiteralType(node) {
|
|
2478
|
+
_printTemplate.call(this, node, node.types);
|
|
2479
|
+
}
|
|
2480
|
+
function TSLiteralType(node) {
|
|
2481
|
+
this.print(node.literal);
|
|
2482
|
+
}
|
|
2483
|
+
function TSClassImplements(node) {
|
|
2484
|
+
this.print(node.expression);
|
|
2485
|
+
this.print(node.typeArguments);
|
|
2486
|
+
}
|
|
2487
|
+
function TSInterfaceDeclaration(node) {
|
|
2488
|
+
const { declare, id, typeParameters, extends: extendz, body } = node;
|
|
2489
|
+
if (declare) {
|
|
2490
|
+
this.word("declare");
|
|
2491
|
+
this.space();
|
|
2492
|
+
}
|
|
2493
|
+
this.word("interface");
|
|
2494
|
+
this.space();
|
|
2495
|
+
this.print(id);
|
|
2496
|
+
this.print(typeParameters);
|
|
2497
|
+
if (extendz?.length) {
|
|
2498
|
+
this.space();
|
|
2499
|
+
this.word("extends");
|
|
2500
|
+
this.space();
|
|
2501
|
+
this.printList(extendz);
|
|
2502
|
+
}
|
|
2503
|
+
this.space();
|
|
2504
|
+
this.print(body);
|
|
2505
|
+
}
|
|
2506
|
+
function TSInterfaceBody(node) {
|
|
2507
|
+
printBraced(this, node, () => this.printJoin(node.body, true, true, void 0, void 0, true));
|
|
2508
|
+
}
|
|
2509
|
+
function TSTypeAliasDeclaration(node) {
|
|
2510
|
+
const { declare, id, typeParameters, typeAnnotation } = node;
|
|
2511
|
+
if (declare) {
|
|
2512
|
+
this.word("declare");
|
|
2513
|
+
this.space();
|
|
2514
|
+
}
|
|
2515
|
+
this.word("type");
|
|
2516
|
+
this.space();
|
|
2517
|
+
this.print(id);
|
|
2518
|
+
this.print(typeParameters);
|
|
2519
|
+
this.space();
|
|
2520
|
+
this.tokenChar(61);
|
|
2521
|
+
this.space();
|
|
2522
|
+
this.print(typeAnnotation);
|
|
2523
|
+
this.semicolon();
|
|
2524
|
+
}
|
|
2525
|
+
function TSAsExpression(node) {
|
|
2526
|
+
const { expression, typeAnnotation } = node;
|
|
2527
|
+
this.print(expression, true);
|
|
2528
|
+
this.space();
|
|
2529
|
+
this.word("as");
|
|
2530
|
+
this.space();
|
|
2531
|
+
this.print(typeAnnotation);
|
|
2532
|
+
}
|
|
2533
|
+
function TSSatisfiesExpression(node) {
|
|
2534
|
+
const { expression, typeAnnotation } = node;
|
|
2535
|
+
this.print(expression, true);
|
|
2536
|
+
this.space();
|
|
2537
|
+
this.word("satisfies");
|
|
2538
|
+
this.space();
|
|
2539
|
+
this.print(typeAnnotation);
|
|
2540
|
+
}
|
|
2541
|
+
function TSTypeAssertion(node) {
|
|
2542
|
+
const { typeAnnotation, expression } = node;
|
|
2543
|
+
this.tokenChar(60);
|
|
2544
|
+
this.print(typeAnnotation);
|
|
2545
|
+
this.tokenChar(62);
|
|
2546
|
+
this.space();
|
|
2547
|
+
this.print(expression);
|
|
2548
|
+
}
|
|
2549
|
+
function TSInstantiationExpression(node) {
|
|
2550
|
+
this.print(node.expression);
|
|
2551
|
+
this.print(node.typeArguments);
|
|
2552
|
+
}
|
|
2553
|
+
function TSEnumDeclaration(node) {
|
|
2554
|
+
const { declare, const: isConst, id } = node;
|
|
2555
|
+
if (declare) {
|
|
2556
|
+
this.word("declare");
|
|
2557
|
+
this.space();
|
|
2558
|
+
}
|
|
2559
|
+
if (isConst) {
|
|
2560
|
+
this.word("const");
|
|
2561
|
+
this.space();
|
|
2562
|
+
}
|
|
2563
|
+
this.word("enum");
|
|
2564
|
+
this.space();
|
|
2565
|
+
this.print(id);
|
|
2566
|
+
this.space();
|
|
2567
|
+
this.print(node.body);
|
|
2568
|
+
}
|
|
2569
|
+
function TSEnumBody(node) {
|
|
2570
|
+
printBraced(this, node, () => this.printList(node.members, this.shouldPrintTrailingComma("}") ?? false, true, true, void 0, true));
|
|
2571
|
+
}
|
|
2572
|
+
function TSEnumMember(node) {
|
|
2573
|
+
const { id, initializer } = node;
|
|
2574
|
+
this.print(id);
|
|
2575
|
+
if (initializer) {
|
|
2576
|
+
this.space();
|
|
2577
|
+
this.tokenChar(61);
|
|
2578
|
+
this.space();
|
|
2579
|
+
this.print(initializer);
|
|
2580
|
+
}
|
|
2581
|
+
}
|
|
2582
|
+
function TSModuleDeclaration(node) {
|
|
2583
|
+
const { declare, kind } = node;
|
|
2584
|
+
if (declare) {
|
|
2585
|
+
this.word("declare");
|
|
2586
|
+
this.space();
|
|
2587
|
+
}
|
|
2588
|
+
if (kind !== "global") {
|
|
2589
|
+
this.word(kind);
|
|
2590
|
+
this.space();
|
|
2591
|
+
}
|
|
2592
|
+
this.print(node.id);
|
|
2593
|
+
if (!node.body) {
|
|
2594
|
+
this.semicolon();
|
|
2595
|
+
return;
|
|
2596
|
+
}
|
|
2597
|
+
this.space();
|
|
2598
|
+
this.print(node.body);
|
|
2599
|
+
}
|
|
2600
|
+
function TSModuleBlock(node) {
|
|
2601
|
+
printBraced(this, node, () => this.printSequence(node.body, true, true));
|
|
2602
|
+
}
|
|
2603
|
+
function TSImportType(node) {
|
|
2604
|
+
const { qualifier, options } = node;
|
|
2605
|
+
this.word("import");
|
|
2606
|
+
this.tokenChar(40);
|
|
2607
|
+
this.print(node.source);
|
|
2608
|
+
if (options) {
|
|
2609
|
+
this.tokenChar(44);
|
|
2610
|
+
this.print(options);
|
|
2611
|
+
}
|
|
2612
|
+
this.tokenChar(41);
|
|
2613
|
+
if (qualifier) {
|
|
2614
|
+
this.tokenChar(46);
|
|
2615
|
+
this.print(qualifier);
|
|
2616
|
+
}
|
|
2617
|
+
const typeArguments = node.typeArguments;
|
|
2618
|
+
if (typeArguments) this.print(typeArguments);
|
|
2619
|
+
}
|
|
2620
|
+
function TSImportEqualsDeclaration(node) {
|
|
2621
|
+
const { id, moduleReference } = node;
|
|
2622
|
+
this.word("import");
|
|
2623
|
+
this.space();
|
|
2624
|
+
this.print(id);
|
|
2625
|
+
this.space();
|
|
2626
|
+
this.tokenChar(61);
|
|
2627
|
+
this.space();
|
|
2628
|
+
this.print(moduleReference);
|
|
2629
|
+
this.semicolon();
|
|
2630
|
+
}
|
|
2631
|
+
function TSExternalModuleReference(node) {
|
|
2632
|
+
this.token("require(");
|
|
2633
|
+
this.print(node.expression);
|
|
2634
|
+
this.tokenChar(41);
|
|
2635
|
+
}
|
|
2636
|
+
function TSNonNullExpression(node) {
|
|
2637
|
+
this.print(node.expression);
|
|
2638
|
+
this.tokenChar(33);
|
|
2639
|
+
this.setLastChar(33);
|
|
2640
|
+
}
|
|
2641
|
+
function TSExportAssignment(node) {
|
|
2642
|
+
this.word("export");
|
|
2643
|
+
this.space();
|
|
2644
|
+
this.tokenChar(61);
|
|
2645
|
+
this.space();
|
|
2646
|
+
this.print(node.expression);
|
|
2647
|
+
this.semicolon();
|
|
2648
|
+
}
|
|
2649
|
+
function TSNamespaceExportDeclaration(node) {
|
|
2650
|
+
this.word("export");
|
|
2651
|
+
this.space();
|
|
2652
|
+
this.word("as");
|
|
2653
|
+
this.space();
|
|
2654
|
+
this.word("namespace");
|
|
2655
|
+
this.space();
|
|
2656
|
+
this.print(node.id);
|
|
2657
|
+
this.semicolon();
|
|
2658
|
+
}
|
|
2659
|
+
function tsPrintSignatureDeclarationBase(node) {
|
|
2660
|
+
const { typeParameters } = node;
|
|
2661
|
+
const parameters = node.params;
|
|
2662
|
+
this.print(typeParameters);
|
|
2663
|
+
this.tokenChar(40);
|
|
2664
|
+
_parameters.call(this, parameters, 41);
|
|
2665
|
+
this.print(node.returnType);
|
|
2666
|
+
}
|
|
2667
|
+
function _tsPrintClassMemberModifiers(node) {
|
|
2668
|
+
const isPrivateField = node.type === "ClassPrivateProperty";
|
|
2669
|
+
const isPublicField = node.type === "ClassAccessorProperty" || node.type === "ClassProperty";
|
|
2670
|
+
printModifiersList(this, node, [isPublicField && node.declare && "declare", !isPrivateField && node.accessibility]);
|
|
2671
|
+
if (node.static) {
|
|
2672
|
+
this.word("static");
|
|
2673
|
+
this.space();
|
|
2674
|
+
}
|
|
2675
|
+
printModifiersList(this, node, [
|
|
2676
|
+
!isPrivateField && node.abstract && "abstract",
|
|
2677
|
+
!isPrivateField && node.override && "override",
|
|
2678
|
+
(isPublicField || isPrivateField) && node.readonly && "readonly"
|
|
2679
|
+
]);
|
|
2680
|
+
}
|
|
2681
|
+
function printBraced(printer, node, cb) {
|
|
2682
|
+
printer.token("{");
|
|
2683
|
+
const oldNoLineTerminatorAfterNode = printer.enterDelimited();
|
|
2684
|
+
cb();
|
|
2685
|
+
printer._noLineTerminatorAfterNode = oldNoLineTerminatorAfterNode;
|
|
2686
|
+
printer.rightBrace(node);
|
|
2687
|
+
}
|
|
2688
|
+
function printModifiersList(printer, node, modifiers) {
|
|
2689
|
+
const modifiersSet = /* @__PURE__ */ new Set();
|
|
2690
|
+
for (const modifier of modifiers) if (modifier) modifiersSet.add(modifier);
|
|
2691
|
+
printer.tokenMap?.find(node, (tok) => {
|
|
2692
|
+
if (modifiersSet.has(tok.value)) {
|
|
2693
|
+
printer.token(tok.value);
|
|
2694
|
+
printer.space();
|
|
2695
|
+
modifiersSet.delete(tok.value);
|
|
2696
|
+
return modifiersSet.size === 0;
|
|
2697
|
+
}
|
|
2698
|
+
return false;
|
|
2699
|
+
});
|
|
2700
|
+
for (const modifier of modifiersSet) {
|
|
2701
|
+
printer.word(modifier);
|
|
2702
|
+
printer.space();
|
|
2703
|
+
}
|
|
2704
|
+
}
|
|
2705
|
+
var { isClassDeclaration, isExportDefaultSpecifier, isExportNamespaceSpecifier, isImportDefaultSpecifier, isImportNamespaceSpecifier, isStatement: isStatement$2 } = _t;
|
|
2706
|
+
function ImportSpecifier(node) {
|
|
2707
|
+
if (node.importKind === "type" || node.importKind === "typeof") {
|
|
2708
|
+
this.word(node.importKind);
|
|
2709
|
+
this.space();
|
|
2710
|
+
}
|
|
2711
|
+
this.print(node.imported);
|
|
2712
|
+
if (node.local && node.local.name !== node.imported.name) {
|
|
2713
|
+
this.space();
|
|
2714
|
+
this.word("as");
|
|
2715
|
+
this.space();
|
|
2716
|
+
this.print(node.local);
|
|
2717
|
+
}
|
|
2718
|
+
}
|
|
2719
|
+
function ImportDefaultSpecifier(node) {
|
|
2720
|
+
this.print(node.local);
|
|
2721
|
+
}
|
|
2722
|
+
function ExportDefaultSpecifier(node) {
|
|
2723
|
+
this.print(node.exported);
|
|
2724
|
+
}
|
|
2725
|
+
function ExportSpecifier(node) {
|
|
2726
|
+
if (node.exportKind === "type") {
|
|
2727
|
+
this.word("type");
|
|
2728
|
+
this.space();
|
|
2729
|
+
}
|
|
2730
|
+
this.print(node.local);
|
|
2731
|
+
if (node.exported && node.local.name !== node.exported.name) {
|
|
2732
|
+
this.space();
|
|
2733
|
+
this.word("as");
|
|
2734
|
+
this.space();
|
|
2735
|
+
this.print(node.exported);
|
|
2736
|
+
}
|
|
2737
|
+
}
|
|
2738
|
+
function ExportNamespaceSpecifier(node) {
|
|
2739
|
+
this.tokenChar(42);
|
|
2740
|
+
this.space();
|
|
2741
|
+
this.word("as");
|
|
2742
|
+
this.space();
|
|
2743
|
+
this.print(node.exported);
|
|
2744
|
+
}
|
|
2745
|
+
function _printAttributes(node, hasPreviousBrace) {
|
|
2746
|
+
const { attributes } = node;
|
|
2747
|
+
this.word("with");
|
|
2748
|
+
this.space();
|
|
2749
|
+
const occurrenceCount = hasPreviousBrace ? 1 : 0;
|
|
2750
|
+
this.token("{", void 0, occurrenceCount);
|
|
2751
|
+
this.space();
|
|
2752
|
+
this.printList(attributes, this.shouldPrintTrailingComma("}"));
|
|
2753
|
+
this.space();
|
|
2754
|
+
this.token("}", void 0, occurrenceCount);
|
|
2755
|
+
}
|
|
2756
|
+
function ExportAllDeclaration(node) {
|
|
2757
|
+
this.word("export");
|
|
2758
|
+
this.space();
|
|
2759
|
+
if (node.exportKind === "type") {
|
|
2760
|
+
this.word("type");
|
|
2761
|
+
this.space();
|
|
2762
|
+
}
|
|
2763
|
+
this.tokenChar(42);
|
|
2764
|
+
this.space();
|
|
2765
|
+
this.word("from");
|
|
2766
|
+
this.space();
|
|
2767
|
+
if (node.attributes?.length) {
|
|
2768
|
+
this.print(node.source, true);
|
|
2769
|
+
this.space();
|
|
2770
|
+
_printAttributes.call(this, node, false);
|
|
2771
|
+
} else this.print(node.source);
|
|
2772
|
+
this.semicolon();
|
|
2773
|
+
}
|
|
2774
|
+
function maybePrintDecoratorsBeforeExport(printer, node) {
|
|
2775
|
+
if (isClassDeclaration(node.declaration) && _shouldPrintDecoratorsBeforeExport.call(printer, node)) printer.printJoin(node.declaration.decorators);
|
|
2776
|
+
}
|
|
2777
|
+
function ExportNamedDeclaration(node) {
|
|
2778
|
+
maybePrintDecoratorsBeforeExport(this, node);
|
|
2779
|
+
this.word("export");
|
|
2780
|
+
this.space();
|
|
2781
|
+
if (node.declaration) {
|
|
2782
|
+
const declar = node.declaration;
|
|
2783
|
+
this.print(declar);
|
|
2784
|
+
if (!isStatement$2(declar)) this.semicolon();
|
|
2785
|
+
} else {
|
|
2786
|
+
if (node.exportKind === "type") {
|
|
2787
|
+
this.word("type");
|
|
2788
|
+
this.space();
|
|
2789
|
+
}
|
|
2790
|
+
const specifiers = node.specifiers.slice(0);
|
|
2791
|
+
let hasSpecial = false;
|
|
2792
|
+
for (;;) {
|
|
2793
|
+
const first = specifiers[0];
|
|
2794
|
+
if (isExportDefaultSpecifier(first) || isExportNamespaceSpecifier(first)) {
|
|
2795
|
+
hasSpecial = true;
|
|
2796
|
+
this.print(specifiers.shift());
|
|
2797
|
+
if (specifiers.length) {
|
|
2798
|
+
this.tokenChar(44);
|
|
2799
|
+
this.space();
|
|
2800
|
+
}
|
|
2801
|
+
} else break;
|
|
2802
|
+
}
|
|
2803
|
+
let hasBrace = false;
|
|
2804
|
+
if (specifiers.length || !specifiers.length && !hasSpecial) {
|
|
2805
|
+
hasBrace = true;
|
|
2806
|
+
this.tokenChar(123);
|
|
2807
|
+
if (specifiers.length) {
|
|
2808
|
+
this.space();
|
|
2809
|
+
this.printList(specifiers, this.shouldPrintTrailingComma("}"));
|
|
2810
|
+
this.space();
|
|
2811
|
+
}
|
|
2812
|
+
this.tokenChar(125);
|
|
2813
|
+
}
|
|
2814
|
+
if (node.source) {
|
|
2815
|
+
this.space();
|
|
2816
|
+
this.word("from");
|
|
2817
|
+
this.space();
|
|
2818
|
+
if (node.attributes?.length) {
|
|
2819
|
+
this.print(node.source, true);
|
|
2820
|
+
this.space();
|
|
2821
|
+
_printAttributes.call(this, node, hasBrace);
|
|
2822
|
+
} else this.print(node.source);
|
|
2823
|
+
}
|
|
2824
|
+
this.semicolon();
|
|
2825
|
+
}
|
|
2826
|
+
}
|
|
2827
|
+
function ExportDefaultDeclaration(node) {
|
|
2828
|
+
maybePrintDecoratorsBeforeExport(this, node);
|
|
2829
|
+
this.word("export");
|
|
2830
|
+
this.noIndentInnerCommentsHere();
|
|
2831
|
+
this.space();
|
|
2832
|
+
this.word("default");
|
|
2833
|
+
this.space();
|
|
2834
|
+
this.tokenContext |= 4;
|
|
2835
|
+
const declar = node.declaration;
|
|
2836
|
+
this.print(declar);
|
|
2837
|
+
if (!isStatement$2(declar)) this.semicolon();
|
|
2838
|
+
}
|
|
2839
|
+
function ImportDeclaration(node) {
|
|
2840
|
+
this.word("import");
|
|
2841
|
+
this.space();
|
|
2842
|
+
const isTypeKind = node.importKind === "type" || node.importKind === "typeof";
|
|
2843
|
+
if (isTypeKind) {
|
|
2844
|
+
this.noIndentInnerCommentsHere();
|
|
2845
|
+
this.word(node.importKind);
|
|
2846
|
+
this.space();
|
|
2847
|
+
} else if (node.module) {
|
|
2848
|
+
this.noIndentInnerCommentsHere();
|
|
2849
|
+
this.word("module");
|
|
2850
|
+
this.space();
|
|
2851
|
+
} else if (node.phase) {
|
|
2852
|
+
this.noIndentInnerCommentsHere();
|
|
2853
|
+
this.word(node.phase);
|
|
2854
|
+
this.space();
|
|
2855
|
+
}
|
|
2856
|
+
const specifiers = node.specifiers.slice(0);
|
|
2857
|
+
const hasSpecifiers = !!specifiers.length;
|
|
2858
|
+
while (hasSpecifiers) {
|
|
2859
|
+
const first = specifiers[0];
|
|
2860
|
+
if (isImportDefaultSpecifier(first) || isImportNamespaceSpecifier(first)) {
|
|
2861
|
+
this.print(specifiers.shift());
|
|
2862
|
+
if (specifiers.length) {
|
|
2863
|
+
this.tokenChar(44);
|
|
2864
|
+
this.space();
|
|
2865
|
+
}
|
|
2866
|
+
} else break;
|
|
2867
|
+
}
|
|
2868
|
+
let hasBrace = false;
|
|
2869
|
+
if (specifiers.length) {
|
|
2870
|
+
hasBrace = true;
|
|
2871
|
+
this.tokenChar(123);
|
|
2872
|
+
this.space();
|
|
2873
|
+
this.printList(specifiers, this.shouldPrintTrailingComma("}"));
|
|
2874
|
+
this.space();
|
|
2875
|
+
this.tokenChar(125);
|
|
2876
|
+
} else if (isTypeKind && !hasSpecifiers) {
|
|
2877
|
+
hasBrace = true;
|
|
2878
|
+
this.tokenChar(123);
|
|
2879
|
+
this.tokenChar(125);
|
|
2880
|
+
}
|
|
2881
|
+
if (hasSpecifiers || isTypeKind) {
|
|
2882
|
+
this.space();
|
|
2883
|
+
this.word("from");
|
|
2884
|
+
this.space();
|
|
2885
|
+
}
|
|
2886
|
+
if (node.attributes?.length) {
|
|
2887
|
+
this.print(node.source, true);
|
|
2888
|
+
this.space();
|
|
2889
|
+
_printAttributes.call(this, node, hasBrace);
|
|
2890
|
+
} else this.print(node.source);
|
|
2891
|
+
this.semicolon();
|
|
2892
|
+
}
|
|
2893
|
+
function ImportAttribute(node) {
|
|
2894
|
+
this.print(node.key);
|
|
2895
|
+
this.tokenChar(58);
|
|
2896
|
+
this.space();
|
|
2897
|
+
this.print(node.value);
|
|
2898
|
+
}
|
|
2899
|
+
function ImportNamespaceSpecifier(node) {
|
|
2900
|
+
this.tokenChar(42);
|
|
2901
|
+
this.space();
|
|
2902
|
+
this.word("as");
|
|
2903
|
+
this.space();
|
|
2904
|
+
this.print(node.local);
|
|
2905
|
+
}
|
|
2906
|
+
function ImportExpression(node) {
|
|
2907
|
+
this.word("import");
|
|
2908
|
+
if (node.phase) {
|
|
2909
|
+
this.tokenChar(46);
|
|
2910
|
+
this.word(node.phase);
|
|
2911
|
+
}
|
|
2912
|
+
this.tokenChar(40);
|
|
2913
|
+
const shouldPrintTrailingComma = this.shouldPrintTrailingComma(")");
|
|
2914
|
+
this.print(node.source);
|
|
2915
|
+
if (node.options != null) {
|
|
2916
|
+
this.tokenChar(44);
|
|
2917
|
+
this.space();
|
|
2918
|
+
this.print(node.options);
|
|
2919
|
+
}
|
|
2920
|
+
if (shouldPrintTrailingComma) this.tokenChar(44);
|
|
2921
|
+
this.rightParens(node);
|
|
2922
|
+
}
|
|
2923
|
+
var { isAssignmentPattern, isIdentifier } = _t;
|
|
2924
|
+
var lastRawIdentResult = "";
|
|
2925
|
+
function _getRawIdentifier(node) {
|
|
2926
|
+
const { name } = node;
|
|
2927
|
+
const token = this.tokenMap.find(node, (tok) => tok.value === name);
|
|
2928
|
+
if (token) {
|
|
2929
|
+
lastRawIdentResult = this._originalCode.slice(token.start, token.end);
|
|
2930
|
+
return lastRawIdentResult;
|
|
2931
|
+
}
|
|
2932
|
+
return lastRawIdentResult = node.name;
|
|
2933
|
+
}
|
|
2934
|
+
function Identifier(node) {
|
|
2935
|
+
if (this._buf._map && node.loc?.identifierName && node.loc.identifierName !== node.name) this.sourceIdentifierName(node.loc.identifierName);
|
|
2936
|
+
this.word(this.tokenMap ? lastRawIdentResult : node.name);
|
|
2937
|
+
}
|
|
2938
|
+
function ArgumentPlaceholder() {
|
|
2939
|
+
this.tokenChar(63);
|
|
2940
|
+
}
|
|
2941
|
+
function RestElement(node) {
|
|
2942
|
+
this.token("...");
|
|
2943
|
+
this.print(node.argument);
|
|
2944
|
+
}
|
|
2945
|
+
function ObjectExpression(node) {
|
|
2946
|
+
const props = node.properties;
|
|
2947
|
+
this.tokenChar(123);
|
|
2948
|
+
if (props.length) {
|
|
2949
|
+
const oldNoLineTerminatorAfterNode = this.enterDelimited();
|
|
2950
|
+
this.space();
|
|
2951
|
+
this.printList(props, this.shouldPrintTrailingComma("}"), true, true, void 0, true);
|
|
2952
|
+
this.space();
|
|
2953
|
+
this._noLineTerminatorAfterNode = oldNoLineTerminatorAfterNode;
|
|
2954
|
+
}
|
|
2955
|
+
this.rightBrace(node);
|
|
2956
|
+
}
|
|
2957
|
+
function ObjectMethod(node) {
|
|
2958
|
+
this.printJoin(node.decorators);
|
|
2959
|
+
_methodHead.call(this, node);
|
|
2960
|
+
this.space();
|
|
2961
|
+
this.print(node.body);
|
|
2962
|
+
}
|
|
2963
|
+
function ObjectProperty(node) {
|
|
2964
|
+
this.printJoin(node.decorators);
|
|
2965
|
+
if (node.computed) {
|
|
2966
|
+
this.tokenChar(91);
|
|
2967
|
+
this.print(node.key);
|
|
2968
|
+
this.tokenChar(93);
|
|
2969
|
+
} else {
|
|
2970
|
+
if (isAssignmentPattern(node.value) && isIdentifier(node.key) && node.key.name === node.value.left.name) {
|
|
2971
|
+
this.print(node.value);
|
|
2972
|
+
return;
|
|
2973
|
+
}
|
|
2974
|
+
this.print(node.key);
|
|
2975
|
+
if (node.shorthand && isIdentifier(node.key) && isIdentifier(node.value) && node.key.name === node.value.name) return;
|
|
2976
|
+
}
|
|
2977
|
+
this.tokenChar(58);
|
|
2978
|
+
this.space();
|
|
2979
|
+
this.print(node.value);
|
|
2980
|
+
}
|
|
2981
|
+
function ArrayExpression(node) {
|
|
2982
|
+
const elems = node.elements;
|
|
2983
|
+
const len = elems.length;
|
|
2984
|
+
this.tokenChar(91);
|
|
2985
|
+
const oldNoLineTerminatorAfterNode = this.enterDelimited();
|
|
2986
|
+
for (let i = 0; i < elems.length; i++) {
|
|
2987
|
+
const elem = elems[i];
|
|
2988
|
+
if (elem) {
|
|
2989
|
+
if (i > 0) this.space();
|
|
2990
|
+
this.print(elem, void 0, true);
|
|
2991
|
+
if (i < len - 1 || this.shouldPrintTrailingComma("]")) this.tokenChar(44, i);
|
|
2992
|
+
} else this.tokenChar(44, i);
|
|
2993
|
+
}
|
|
2994
|
+
this._noLineTerminatorAfterNode = oldNoLineTerminatorAfterNode;
|
|
2995
|
+
this.tokenChar(93);
|
|
2996
|
+
}
|
|
2997
|
+
function RegExpLiteral(node) {
|
|
2998
|
+
this.word(`/${node.pattern}/${node.flags}`, false);
|
|
2999
|
+
}
|
|
3000
|
+
function BooleanLiteral(node) {
|
|
3001
|
+
this.word(node.value ? "true" : "false");
|
|
3002
|
+
}
|
|
3003
|
+
function NullLiteral() {
|
|
3004
|
+
this.word("null");
|
|
3005
|
+
}
|
|
3006
|
+
function NumericLiteral(node) {
|
|
3007
|
+
const raw = this.getPossibleRaw(node);
|
|
3008
|
+
const opts = this.format.jsescOption;
|
|
3009
|
+
const value = node.value;
|
|
3010
|
+
const str = value + "";
|
|
3011
|
+
if (opts.numbers) this.number((0, import_jsesc.default)(value, opts), value);
|
|
3012
|
+
else if (raw == null) this.number(str, value);
|
|
3013
|
+
else if (this.format.minified) this.number(raw.length < str.length ? raw : str, value);
|
|
3014
|
+
else this.number(raw, value);
|
|
3015
|
+
}
|
|
3016
|
+
function StringLiteral(node) {
|
|
3017
|
+
const raw = this.getPossibleRaw(node);
|
|
3018
|
+
if (!this.format.minified && raw !== void 0) {
|
|
3019
|
+
this.token(raw);
|
|
3020
|
+
return;
|
|
3021
|
+
}
|
|
3022
|
+
const val = (0, import_jsesc.default)(node.value, this.format.jsescOption);
|
|
3023
|
+
this.token(val);
|
|
3024
|
+
}
|
|
3025
|
+
function BigIntLiteral(node) {
|
|
3026
|
+
const raw = this.getPossibleRaw(node);
|
|
3027
|
+
if (!this.format.minified && raw !== void 0) {
|
|
3028
|
+
this.word(raw);
|
|
3029
|
+
return;
|
|
3030
|
+
}
|
|
3031
|
+
this.word(node.value + "n");
|
|
3032
|
+
}
|
|
3033
|
+
var validTopicTokenSet = /* @__PURE__ */ new Set([
|
|
3034
|
+
"^^",
|
|
3035
|
+
"@@",
|
|
3036
|
+
"^",
|
|
3037
|
+
"%",
|
|
3038
|
+
"#"
|
|
3039
|
+
]);
|
|
3040
|
+
function TopicReference() {
|
|
3041
|
+
const { topicToken } = this.format;
|
|
3042
|
+
if (validTopicTokenSet.has(topicToken)) this.token(topicToken);
|
|
3043
|
+
else {
|
|
3044
|
+
const givenTopicTokenJSON = JSON.stringify(topicToken);
|
|
3045
|
+
const validTopics = Array.from(validTopicTokenSet, (v) => JSON.stringify(v));
|
|
3046
|
+
throw new Error(`The "topicToken" generator option must be one of ${validTopics.join(", ")} (${givenTopicTokenJSON} received instead).`);
|
|
3047
|
+
}
|
|
3048
|
+
}
|
|
3049
|
+
function VoidPattern() {
|
|
3050
|
+
this.word("void");
|
|
3051
|
+
}
|
|
3052
|
+
var { isDeclareExportDeclaration, isStatement: isStatement$1 } = _t;
|
|
3053
|
+
function AnyTypeAnnotation() {
|
|
3054
|
+
this.word("any");
|
|
3055
|
+
}
|
|
3056
|
+
function ArrayTypeAnnotation(node) {
|
|
3057
|
+
this.print(node.elementType, true);
|
|
3058
|
+
this.tokenChar(91);
|
|
3059
|
+
this.tokenChar(93);
|
|
3060
|
+
}
|
|
3061
|
+
function BooleanTypeAnnotation() {
|
|
3062
|
+
this.word("boolean");
|
|
3063
|
+
}
|
|
3064
|
+
function BooleanLiteralTypeAnnotation(node) {
|
|
3065
|
+
this.word(node.value ? "true" : "false");
|
|
3066
|
+
}
|
|
3067
|
+
function NullLiteralTypeAnnotation() {
|
|
3068
|
+
this.word("null");
|
|
3069
|
+
}
|
|
3070
|
+
function DeclareClass(node, parent) {
|
|
3071
|
+
if (!isDeclareExportDeclaration(parent)) {
|
|
3072
|
+
this.word("declare");
|
|
3073
|
+
this.space();
|
|
3074
|
+
}
|
|
3075
|
+
this.word("class");
|
|
3076
|
+
this.space();
|
|
3077
|
+
_interfaceish.call(this, node);
|
|
3078
|
+
}
|
|
3079
|
+
function DeclareFunction(node, parent) {
|
|
3080
|
+
if (!isDeclareExportDeclaration(parent)) {
|
|
3081
|
+
this.word("declare");
|
|
3082
|
+
this.space();
|
|
3083
|
+
}
|
|
3084
|
+
this.word("function");
|
|
3085
|
+
this.space();
|
|
3086
|
+
this.print(node.id);
|
|
3087
|
+
this.print(node.id.typeAnnotation?.typeAnnotation);
|
|
3088
|
+
if (node.predicate) {
|
|
3089
|
+
this.space();
|
|
3090
|
+
this.print(node.predicate);
|
|
3091
|
+
}
|
|
3092
|
+
this.semicolon();
|
|
3093
|
+
}
|
|
3094
|
+
function InferredPredicate() {
|
|
3095
|
+
this.tokenChar(37);
|
|
3096
|
+
this.word("checks");
|
|
3097
|
+
}
|
|
3098
|
+
function DeclaredPredicate(node) {
|
|
3099
|
+
this.tokenChar(37);
|
|
3100
|
+
this.word("checks");
|
|
3101
|
+
this.tokenChar(40);
|
|
3102
|
+
this.print(node.value);
|
|
3103
|
+
this.tokenChar(41);
|
|
3104
|
+
}
|
|
3105
|
+
function DeclareInterface(node) {
|
|
3106
|
+
this.word("declare");
|
|
3107
|
+
this.space();
|
|
3108
|
+
InterfaceDeclaration.call(this, node);
|
|
3109
|
+
}
|
|
3110
|
+
function DeclareModule(node) {
|
|
3111
|
+
this.word("declare");
|
|
3112
|
+
this.space();
|
|
3113
|
+
this.word("module");
|
|
3114
|
+
this.space();
|
|
3115
|
+
this.print(node.id);
|
|
3116
|
+
this.space();
|
|
3117
|
+
this.print(node.body);
|
|
3118
|
+
}
|
|
3119
|
+
function DeclareModuleExports(node) {
|
|
3120
|
+
this.word("declare");
|
|
3121
|
+
this.space();
|
|
3122
|
+
this.word("module");
|
|
3123
|
+
this.tokenChar(46);
|
|
3124
|
+
this.word("exports");
|
|
3125
|
+
this.print(node.typeAnnotation);
|
|
3126
|
+
}
|
|
3127
|
+
function DeclareTypeAlias(node) {
|
|
3128
|
+
this.word("declare");
|
|
3129
|
+
this.space();
|
|
3130
|
+
TypeAlias.call(this, node);
|
|
3131
|
+
}
|
|
3132
|
+
function DeclareOpaqueType(node, parent) {
|
|
3133
|
+
if (!isDeclareExportDeclaration(parent)) {
|
|
3134
|
+
this.word("declare");
|
|
3135
|
+
this.space();
|
|
3136
|
+
}
|
|
3137
|
+
OpaqueType.call(this, node);
|
|
3138
|
+
}
|
|
3139
|
+
function DeclareVariable(node, parent) {
|
|
3140
|
+
if (!isDeclareExportDeclaration(parent)) {
|
|
3141
|
+
this.word("declare");
|
|
3142
|
+
this.space();
|
|
3143
|
+
}
|
|
3144
|
+
this.word("var");
|
|
3145
|
+
this.space();
|
|
3146
|
+
this.print(node.id);
|
|
3147
|
+
this.print(node.id.typeAnnotation);
|
|
3148
|
+
this.semicolon();
|
|
3149
|
+
}
|
|
3150
|
+
function DeclareExportDeclaration(node) {
|
|
3151
|
+
this.word("declare");
|
|
3152
|
+
this.space();
|
|
3153
|
+
this.word("export");
|
|
3154
|
+
this.space();
|
|
3155
|
+
if (node.default) {
|
|
3156
|
+
this.word("default");
|
|
3157
|
+
this.space();
|
|
3158
|
+
}
|
|
3159
|
+
FlowExportDeclaration.call(this, node);
|
|
3160
|
+
}
|
|
3161
|
+
function DeclareExportAllDeclaration(node) {
|
|
3162
|
+
this.word("declare");
|
|
3163
|
+
this.space();
|
|
3164
|
+
ExportAllDeclaration.call(this, node);
|
|
3165
|
+
}
|
|
3166
|
+
function EnumDeclaration(node) {
|
|
3167
|
+
const { id, body } = node;
|
|
3168
|
+
this.word("enum");
|
|
3169
|
+
this.space();
|
|
3170
|
+
this.print(id);
|
|
3171
|
+
this.print(body);
|
|
3172
|
+
}
|
|
3173
|
+
function enumExplicitType(context, name, hasExplicitType) {
|
|
3174
|
+
if (hasExplicitType) {
|
|
3175
|
+
context.space();
|
|
3176
|
+
context.word("of");
|
|
3177
|
+
context.space();
|
|
3178
|
+
context.word(name);
|
|
3179
|
+
}
|
|
3180
|
+
context.space();
|
|
3181
|
+
}
|
|
3182
|
+
function enumBody(context, node) {
|
|
3183
|
+
const { members } = node;
|
|
3184
|
+
context.token("{");
|
|
3185
|
+
context.indent();
|
|
3186
|
+
context.newline();
|
|
3187
|
+
for (const member of members) {
|
|
3188
|
+
context.print(member);
|
|
3189
|
+
context.newline();
|
|
3190
|
+
}
|
|
3191
|
+
if (node.hasUnknownMembers) {
|
|
3192
|
+
context.token("...");
|
|
3193
|
+
context.newline();
|
|
3194
|
+
}
|
|
3195
|
+
context.dedent();
|
|
3196
|
+
context.token("}");
|
|
3197
|
+
}
|
|
3198
|
+
function EnumBooleanBody(node) {
|
|
3199
|
+
const { explicitType } = node;
|
|
3200
|
+
enumExplicitType(this, "boolean", explicitType);
|
|
3201
|
+
enumBody(this, node);
|
|
3202
|
+
}
|
|
3203
|
+
function EnumNumberBody(node) {
|
|
3204
|
+
const { explicitType } = node;
|
|
3205
|
+
enumExplicitType(this, "number", explicitType);
|
|
3206
|
+
enumBody(this, node);
|
|
3207
|
+
}
|
|
3208
|
+
function EnumStringBody(node) {
|
|
3209
|
+
const { explicitType } = node;
|
|
3210
|
+
enumExplicitType(this, "string", explicitType);
|
|
3211
|
+
enumBody(this, node);
|
|
3212
|
+
}
|
|
3213
|
+
function EnumSymbolBody(node) {
|
|
3214
|
+
enumExplicitType(this, "symbol", true);
|
|
3215
|
+
enumBody(this, node);
|
|
3216
|
+
}
|
|
3217
|
+
function EnumDefaultedMember(node) {
|
|
3218
|
+
const { id } = node;
|
|
3219
|
+
this.print(id);
|
|
3220
|
+
this.tokenChar(44);
|
|
3221
|
+
}
|
|
3222
|
+
function enumInitializedMember(context, node) {
|
|
3223
|
+
context.print(node.id);
|
|
3224
|
+
context.space();
|
|
3225
|
+
context.token("=");
|
|
3226
|
+
context.space();
|
|
3227
|
+
context.print(node.init);
|
|
3228
|
+
context.token(",");
|
|
3229
|
+
}
|
|
3230
|
+
function EnumBooleanMember(node) {
|
|
3231
|
+
enumInitializedMember(this, node);
|
|
3232
|
+
}
|
|
3233
|
+
function EnumNumberMember(node) {
|
|
3234
|
+
enumInitializedMember(this, node);
|
|
3235
|
+
}
|
|
3236
|
+
function EnumStringMember(node) {
|
|
3237
|
+
enumInitializedMember(this, node);
|
|
3238
|
+
}
|
|
3239
|
+
function FlowExportDeclaration(node) {
|
|
3240
|
+
if (node.declaration) {
|
|
3241
|
+
const declar = node.declaration;
|
|
3242
|
+
this.print(declar);
|
|
3243
|
+
if (!isStatement$1(declar)) this.semicolon();
|
|
3244
|
+
} else {
|
|
3245
|
+
this.tokenChar(123);
|
|
3246
|
+
if (node.specifiers.length) {
|
|
3247
|
+
this.space();
|
|
3248
|
+
this.printList(node.specifiers);
|
|
3249
|
+
this.space();
|
|
3250
|
+
}
|
|
3251
|
+
this.tokenChar(125);
|
|
3252
|
+
if (node.source) {
|
|
3253
|
+
this.space();
|
|
3254
|
+
this.word("from");
|
|
3255
|
+
this.space();
|
|
3256
|
+
this.print(node.source);
|
|
3257
|
+
}
|
|
3258
|
+
this.semicolon();
|
|
3259
|
+
}
|
|
3260
|
+
}
|
|
3261
|
+
function ExistsTypeAnnotation() {
|
|
3262
|
+
this.tokenChar(42);
|
|
3263
|
+
}
|
|
3264
|
+
function FunctionTypeAnnotation(node, parent) {
|
|
3265
|
+
this.print(node.typeParameters);
|
|
3266
|
+
this.tokenChar(40);
|
|
3267
|
+
if (node.this) {
|
|
3268
|
+
this.word("this");
|
|
3269
|
+
this.tokenChar(58);
|
|
3270
|
+
this.space();
|
|
3271
|
+
this.print(node.this.typeAnnotation);
|
|
3272
|
+
if (node.params.length || node.rest) {
|
|
3273
|
+
this.tokenChar(44);
|
|
3274
|
+
this.space();
|
|
3275
|
+
}
|
|
3276
|
+
}
|
|
3277
|
+
this.printList(node.params);
|
|
3278
|
+
if (node.rest) {
|
|
3279
|
+
if (node.params.length) {
|
|
3280
|
+
this.tokenChar(44);
|
|
3281
|
+
this.space();
|
|
3282
|
+
}
|
|
3283
|
+
this.token("...");
|
|
3284
|
+
this.print(node.rest);
|
|
3285
|
+
}
|
|
3286
|
+
this.tokenChar(41);
|
|
3287
|
+
const type = parent?.type;
|
|
3288
|
+
if (type != null && (type === "ObjectTypeCallProperty" || type === "ObjectTypeInternalSlot" || type === "DeclareFunction" || type === "ObjectTypeProperty" && parent.method)) this.tokenChar(58);
|
|
3289
|
+
else {
|
|
3290
|
+
this.space();
|
|
3291
|
+
this.token("=>");
|
|
3292
|
+
}
|
|
3293
|
+
this.space();
|
|
3294
|
+
this.print(node.returnType);
|
|
3295
|
+
}
|
|
3296
|
+
function FunctionTypeParam(node) {
|
|
3297
|
+
this.print(node.name);
|
|
3298
|
+
if (node.optional) this.tokenChar(63);
|
|
3299
|
+
if (node.name) {
|
|
3300
|
+
this.tokenChar(58);
|
|
3301
|
+
this.space();
|
|
3302
|
+
}
|
|
3303
|
+
this.print(node.typeAnnotation);
|
|
3304
|
+
}
|
|
3305
|
+
function InterfaceExtends(node) {
|
|
3306
|
+
this.print(node.id);
|
|
3307
|
+
this.print(node.typeParameters, true);
|
|
3308
|
+
}
|
|
3309
|
+
function _interfaceish(node) {
|
|
3310
|
+
this.print(node.id);
|
|
3311
|
+
this.print(node.typeParameters);
|
|
3312
|
+
if (node.extends?.length) {
|
|
3313
|
+
this.space();
|
|
3314
|
+
this.word("extends");
|
|
3315
|
+
this.space();
|
|
3316
|
+
this.printList(node.extends);
|
|
3317
|
+
}
|
|
3318
|
+
if (node.type === "DeclareClass") {
|
|
3319
|
+
if (node.mixins?.length) {
|
|
3320
|
+
this.space();
|
|
3321
|
+
this.word("mixins");
|
|
3322
|
+
this.space();
|
|
3323
|
+
this.printList(node.mixins);
|
|
3324
|
+
}
|
|
3325
|
+
if (node.implements?.length) {
|
|
3326
|
+
this.space();
|
|
3327
|
+
this.word("implements");
|
|
3328
|
+
this.space();
|
|
3329
|
+
this.printList(node.implements);
|
|
3330
|
+
}
|
|
3331
|
+
}
|
|
3332
|
+
this.space();
|
|
3333
|
+
this.print(node.body);
|
|
3334
|
+
}
|
|
3335
|
+
function _variance(node) {
|
|
3336
|
+
const kind = node.variance?.kind;
|
|
3337
|
+
if (kind != null) {
|
|
3338
|
+
if (kind === "plus") this.tokenChar(43);
|
|
3339
|
+
else if (kind === "minus") this.tokenChar(45);
|
|
3340
|
+
}
|
|
3341
|
+
}
|
|
3342
|
+
function InterfaceDeclaration(node) {
|
|
3343
|
+
this.word("interface");
|
|
3344
|
+
this.space();
|
|
3345
|
+
_interfaceish.call(this, node);
|
|
3346
|
+
}
|
|
3347
|
+
function andSeparator(occurrenceCount) {
|
|
3348
|
+
this.space();
|
|
3349
|
+
this.token("&", false, occurrenceCount);
|
|
3350
|
+
this.space();
|
|
3351
|
+
}
|
|
3352
|
+
function InterfaceTypeAnnotation(node) {
|
|
3353
|
+
this.word("interface");
|
|
3354
|
+
if (node.extends?.length) {
|
|
3355
|
+
this.space();
|
|
3356
|
+
this.word("extends");
|
|
3357
|
+
this.space();
|
|
3358
|
+
this.printList(node.extends);
|
|
3359
|
+
}
|
|
3360
|
+
this.space();
|
|
3361
|
+
this.print(node.body);
|
|
3362
|
+
}
|
|
3363
|
+
function IntersectionTypeAnnotation(node) {
|
|
3364
|
+
this.printJoin(node.types, void 0, void 0, andSeparator);
|
|
3365
|
+
}
|
|
3366
|
+
function MixedTypeAnnotation() {
|
|
3367
|
+
this.word("mixed");
|
|
3368
|
+
}
|
|
3369
|
+
function EmptyTypeAnnotation() {
|
|
3370
|
+
this.word("empty");
|
|
3371
|
+
}
|
|
3372
|
+
function NullableTypeAnnotation(node) {
|
|
3373
|
+
this.tokenChar(63);
|
|
3374
|
+
this.print(node.typeAnnotation);
|
|
3375
|
+
}
|
|
3376
|
+
function NumberTypeAnnotation() {
|
|
3377
|
+
this.word("number");
|
|
3378
|
+
}
|
|
3379
|
+
function StringTypeAnnotation() {
|
|
3380
|
+
this.word("string");
|
|
3381
|
+
}
|
|
3382
|
+
function ThisTypeAnnotation() {
|
|
3383
|
+
this.word("this");
|
|
3384
|
+
}
|
|
3385
|
+
function TupleTypeAnnotation(node) {
|
|
3386
|
+
this.tokenChar(91);
|
|
3387
|
+
this.printList(node.types);
|
|
3388
|
+
this.tokenChar(93);
|
|
3389
|
+
}
|
|
3390
|
+
function TypeofTypeAnnotation(node) {
|
|
3391
|
+
this.word("typeof");
|
|
3392
|
+
this.space();
|
|
3393
|
+
this.print(node.argument);
|
|
3394
|
+
}
|
|
3395
|
+
function TypeAlias(node) {
|
|
3396
|
+
this.word("type");
|
|
3397
|
+
this.space();
|
|
3398
|
+
this.print(node.id);
|
|
3399
|
+
this.print(node.typeParameters);
|
|
3400
|
+
this.space();
|
|
3401
|
+
this.tokenChar(61);
|
|
3402
|
+
this.space();
|
|
3403
|
+
this.print(node.right);
|
|
3404
|
+
this.semicolon();
|
|
3405
|
+
}
|
|
3406
|
+
function TypeAnnotation(node, parent) {
|
|
3407
|
+
this.tokenChar(58);
|
|
3408
|
+
this.space();
|
|
3409
|
+
if (parent.type === "ArrowFunctionExpression") this.tokenContext |= 8;
|
|
3410
|
+
else if (node.optional) this.tokenChar(63);
|
|
3411
|
+
this.print(node.typeAnnotation);
|
|
3412
|
+
}
|
|
3413
|
+
function TypeParameterInstantiation(node) {
|
|
3414
|
+
this.tokenChar(60);
|
|
3415
|
+
this.printList(node.params);
|
|
3416
|
+
this.tokenChar(62);
|
|
3417
|
+
}
|
|
3418
|
+
function TypeParameter(node) {
|
|
3419
|
+
_variance.call(this, node);
|
|
3420
|
+
this.word(node.name);
|
|
3421
|
+
if (node.bound) this.print(node.bound);
|
|
3422
|
+
if (node.default) {
|
|
3423
|
+
this.space();
|
|
3424
|
+
this.tokenChar(61);
|
|
3425
|
+
this.space();
|
|
3426
|
+
this.print(node.default);
|
|
3427
|
+
}
|
|
3428
|
+
}
|
|
3429
|
+
function OpaqueType(node) {
|
|
3430
|
+
this.word("opaque");
|
|
3431
|
+
this.space();
|
|
3432
|
+
this.word("type");
|
|
3433
|
+
this.space();
|
|
3434
|
+
this.print(node.id);
|
|
3435
|
+
this.print(node.typeParameters);
|
|
3436
|
+
if (node.supertype) {
|
|
3437
|
+
this.tokenChar(58);
|
|
3438
|
+
this.space();
|
|
3439
|
+
this.print(node.supertype);
|
|
3440
|
+
}
|
|
3441
|
+
if (node.impltype) {
|
|
3442
|
+
this.space();
|
|
3443
|
+
this.tokenChar(61);
|
|
3444
|
+
this.space();
|
|
3445
|
+
this.print(node.impltype);
|
|
3446
|
+
}
|
|
3447
|
+
this.semicolon();
|
|
3448
|
+
}
|
|
3449
|
+
function ObjectTypeAnnotation(node) {
|
|
3450
|
+
if (node.exact) this.token("{|");
|
|
3451
|
+
else this.tokenChar(123);
|
|
3452
|
+
const props = [
|
|
3453
|
+
...node.properties,
|
|
3454
|
+
...node.callProperties || [],
|
|
3455
|
+
...node.indexers || [],
|
|
3456
|
+
...node.internalSlots || []
|
|
3457
|
+
];
|
|
3458
|
+
if (props.length) {
|
|
3459
|
+
this.newline();
|
|
3460
|
+
this.space();
|
|
3461
|
+
this.printJoin(props, true, true, () => {
|
|
3462
|
+
if (props.length !== 1 || node.inexact) {
|
|
3463
|
+
this.tokenChar(44);
|
|
3464
|
+
this.space();
|
|
3465
|
+
}
|
|
3466
|
+
}, true);
|
|
3467
|
+
this.space();
|
|
3468
|
+
}
|
|
3469
|
+
if (node.inexact) {
|
|
3470
|
+
this.indent();
|
|
3471
|
+
this.token("...");
|
|
3472
|
+
if (props.length) this.newline();
|
|
3473
|
+
this.dedent();
|
|
3474
|
+
}
|
|
3475
|
+
if (node.exact) this.token("|}");
|
|
3476
|
+
else this.tokenChar(125);
|
|
3477
|
+
}
|
|
3478
|
+
function ObjectTypeInternalSlot(node) {
|
|
3479
|
+
if (node.static) {
|
|
3480
|
+
this.word("static");
|
|
3481
|
+
this.space();
|
|
3482
|
+
}
|
|
3483
|
+
this.tokenChar(91);
|
|
3484
|
+
this.tokenChar(91);
|
|
3485
|
+
this.print(node.id);
|
|
3486
|
+
this.tokenChar(93);
|
|
3487
|
+
this.tokenChar(93);
|
|
3488
|
+
if (node.optional) this.tokenChar(63);
|
|
3489
|
+
if (!node.method) {
|
|
3490
|
+
this.tokenChar(58);
|
|
3491
|
+
this.space();
|
|
3492
|
+
}
|
|
3493
|
+
this.print(node.value);
|
|
3494
|
+
}
|
|
3495
|
+
function ObjectTypeCallProperty(node) {
|
|
3496
|
+
if (node.static) {
|
|
3497
|
+
this.word("static");
|
|
3498
|
+
this.space();
|
|
3499
|
+
}
|
|
3500
|
+
this.print(node.value);
|
|
3501
|
+
}
|
|
3502
|
+
function ObjectTypeIndexer(node) {
|
|
3503
|
+
if (node.static) {
|
|
3504
|
+
this.word("static");
|
|
3505
|
+
this.space();
|
|
3506
|
+
}
|
|
3507
|
+
_variance.call(this, node);
|
|
3508
|
+
this.tokenChar(91);
|
|
3509
|
+
if (node.id) {
|
|
3510
|
+
this.print(node.id);
|
|
3511
|
+
this.tokenChar(58);
|
|
3512
|
+
this.space();
|
|
3513
|
+
}
|
|
3514
|
+
this.print(node.key);
|
|
3515
|
+
this.tokenChar(93);
|
|
3516
|
+
this.tokenChar(58);
|
|
3517
|
+
this.space();
|
|
3518
|
+
this.print(node.value);
|
|
3519
|
+
}
|
|
3520
|
+
function ObjectTypeProperty(node) {
|
|
3521
|
+
if (node.proto) {
|
|
3522
|
+
this.word("proto");
|
|
3523
|
+
this.space();
|
|
3524
|
+
}
|
|
3525
|
+
if (node.static) {
|
|
3526
|
+
this.word("static");
|
|
3527
|
+
this.space();
|
|
3528
|
+
}
|
|
3529
|
+
if (node.kind === "get" || node.kind === "set") {
|
|
3530
|
+
this.word(node.kind);
|
|
3531
|
+
this.space();
|
|
3532
|
+
}
|
|
3533
|
+
_variance.call(this, node);
|
|
3534
|
+
this.print(node.key);
|
|
3535
|
+
if (node.optional) this.tokenChar(63);
|
|
3536
|
+
if (!node.method) {
|
|
3537
|
+
this.tokenChar(58);
|
|
3538
|
+
this.space();
|
|
3539
|
+
}
|
|
3540
|
+
this.print(node.value);
|
|
3541
|
+
}
|
|
3542
|
+
function ObjectTypeSpreadProperty(node) {
|
|
3543
|
+
this.token("...");
|
|
3544
|
+
this.print(node.argument);
|
|
3545
|
+
}
|
|
3546
|
+
function QualifiedTypeIdentifier(node) {
|
|
3547
|
+
this.print(node.qualification);
|
|
3548
|
+
this.tokenChar(46);
|
|
3549
|
+
this.print(node.id);
|
|
3550
|
+
}
|
|
3551
|
+
function SymbolTypeAnnotation() {
|
|
3552
|
+
this.word("symbol");
|
|
3553
|
+
}
|
|
3554
|
+
function orSeparator(occurrenceCount) {
|
|
3555
|
+
this.space();
|
|
3556
|
+
this.token("|", false, occurrenceCount);
|
|
3557
|
+
this.space();
|
|
3558
|
+
}
|
|
3559
|
+
function UnionTypeAnnotation(node) {
|
|
3560
|
+
this.printJoin(node.types, void 0, void 0, orSeparator);
|
|
3561
|
+
}
|
|
3562
|
+
function TypeCastExpression(node) {
|
|
3563
|
+
this.tokenChar(40);
|
|
3564
|
+
this.print(node.expression);
|
|
3565
|
+
this.print(node.typeAnnotation);
|
|
3566
|
+
this.tokenChar(41);
|
|
3567
|
+
}
|
|
3568
|
+
function Variance(node) {
|
|
3569
|
+
if (node.kind === "plus") this.tokenChar(43);
|
|
3570
|
+
else this.tokenChar(45);
|
|
3571
|
+
}
|
|
3572
|
+
function VoidTypeAnnotation() {
|
|
3573
|
+
this.word("void");
|
|
3574
|
+
}
|
|
3575
|
+
function IndexedAccessType(node) {
|
|
3576
|
+
this.print(node.objectType, true);
|
|
3577
|
+
this.tokenChar(91);
|
|
3578
|
+
this.print(node.indexType);
|
|
3579
|
+
this.tokenChar(93);
|
|
3580
|
+
}
|
|
3581
|
+
function OptionalIndexedAccessType(node) {
|
|
3582
|
+
this.print(node.objectType);
|
|
3583
|
+
if (node.optional) this.token("?.");
|
|
3584
|
+
this.tokenChar(91);
|
|
3585
|
+
this.print(node.indexType);
|
|
3586
|
+
this.tokenChar(93);
|
|
3587
|
+
}
|
|
3588
|
+
var { isExportDefaultDeclaration, isExportNamedDeclaration } = _t;
|
|
3589
|
+
function ClassDeclaration(node, parent) {
|
|
3590
|
+
if (!(isExportDefaultDeclaration(parent) || isExportNamedDeclaration(parent)) || !_shouldPrintDecoratorsBeforeExport.call(this, parent)) this.printJoin(node.decorators);
|
|
3591
|
+
if (node.declare) {
|
|
3592
|
+
this.word("declare");
|
|
3593
|
+
this.space();
|
|
3594
|
+
}
|
|
3595
|
+
if (node.abstract) {
|
|
3596
|
+
this.word("abstract");
|
|
3597
|
+
this.space();
|
|
3598
|
+
}
|
|
3599
|
+
this.word("class");
|
|
3600
|
+
if (node.id) {
|
|
3601
|
+
this.space();
|
|
3602
|
+
this.print(node.id);
|
|
3603
|
+
}
|
|
3604
|
+
this.print(node.typeParameters);
|
|
3605
|
+
if (node.superClass) {
|
|
3606
|
+
this.space();
|
|
3607
|
+
this.word("extends");
|
|
3608
|
+
this.space();
|
|
3609
|
+
this.print(node.superClass);
|
|
3610
|
+
this.print(node.superTypeArguments);
|
|
3611
|
+
}
|
|
3612
|
+
if (node.implements) {
|
|
3613
|
+
this.space();
|
|
3614
|
+
this.word("implements");
|
|
3615
|
+
this.space();
|
|
3616
|
+
this.printList(node.implements);
|
|
3617
|
+
}
|
|
3618
|
+
this.space();
|
|
3619
|
+
this.print(node.body);
|
|
3620
|
+
}
|
|
3621
|
+
function ClassBody(node) {
|
|
3622
|
+
this.tokenChar(123);
|
|
3623
|
+
if (node.body.length === 0) this.tokenChar(125);
|
|
3624
|
+
else {
|
|
3625
|
+
const separator = classBodyEmptySemicolonsPrinter(this, node);
|
|
3626
|
+
separator?.(-1);
|
|
3627
|
+
const oldNoLineTerminatorAfterNode = this.enterDelimited();
|
|
3628
|
+
this.printJoin(node.body, true, true, separator, true, true);
|
|
3629
|
+
this._noLineTerminatorAfterNode = oldNoLineTerminatorAfterNode;
|
|
3630
|
+
if (!this.endsWith(10)) this.newline();
|
|
3631
|
+
this.rightBrace(node);
|
|
3632
|
+
}
|
|
3633
|
+
}
|
|
3634
|
+
function classBodyEmptySemicolonsPrinter(printer, node) {
|
|
3635
|
+
if (!printer.tokenMap || node.start == null || node.end == null) return null;
|
|
3636
|
+
const indexes = printer.tokenMap.getIndexes(node);
|
|
3637
|
+
if (!indexes) return null;
|
|
3638
|
+
let k = 1;
|
|
3639
|
+
let occurrenceCount = 0;
|
|
3640
|
+
let nextLocIndex = 0;
|
|
3641
|
+
const advanceNextLocIndex = () => {
|
|
3642
|
+
while (nextLocIndex < node.body.length && node.body[nextLocIndex].start == null) nextLocIndex++;
|
|
3643
|
+
};
|
|
3644
|
+
advanceNextLocIndex();
|
|
3645
|
+
return (i) => {
|
|
3646
|
+
if (nextLocIndex <= i) {
|
|
3647
|
+
nextLocIndex = i + 1;
|
|
3648
|
+
advanceNextLocIndex();
|
|
3649
|
+
}
|
|
3650
|
+
const end = nextLocIndex === node.body.length ? node.end : node.body[nextLocIndex].start;
|
|
3651
|
+
let tok;
|
|
3652
|
+
while (k < indexes.length && printer.tokenMap.matchesOriginal(tok = printer._tokens[indexes[k]], ";") && tok.start < end) {
|
|
3653
|
+
printer.tokenChar(59, occurrenceCount++);
|
|
3654
|
+
k++;
|
|
3655
|
+
}
|
|
3656
|
+
};
|
|
3657
|
+
}
|
|
3658
|
+
function ClassProperty(node) {
|
|
3659
|
+
this.printJoin(node.decorators);
|
|
3660
|
+
if (!node.static && !this.format.preserveFormat) {
|
|
3661
|
+
const endLine = node.key.loc?.end?.line;
|
|
3662
|
+
if (endLine) this.catchUp(endLine);
|
|
3663
|
+
}
|
|
3664
|
+
_tsPrintClassMemberModifiers.call(this, node);
|
|
3665
|
+
if (node.computed) {
|
|
3666
|
+
this.tokenChar(91);
|
|
3667
|
+
this.print(node.key);
|
|
3668
|
+
this.tokenChar(93);
|
|
3669
|
+
} else {
|
|
3670
|
+
_variance.call(this, node);
|
|
3671
|
+
this.print(node.key);
|
|
3672
|
+
}
|
|
3673
|
+
if (node.optional) this.tokenChar(63);
|
|
3674
|
+
if (node.definite) this.tokenChar(33);
|
|
3675
|
+
this.print(node.typeAnnotation);
|
|
3676
|
+
if (node.value) {
|
|
3677
|
+
this.space();
|
|
3678
|
+
this.tokenChar(61);
|
|
3679
|
+
this.space();
|
|
3680
|
+
this.print(node.value);
|
|
3681
|
+
}
|
|
3682
|
+
this.semicolon();
|
|
3683
|
+
}
|
|
3684
|
+
function ClassAccessorProperty(node) {
|
|
3685
|
+
this.printJoin(node.decorators);
|
|
3686
|
+
const endLine = node.key.loc?.end?.line;
|
|
3687
|
+
if (endLine) this.catchUp(endLine);
|
|
3688
|
+
_tsPrintClassMemberModifiers.call(this, node);
|
|
3689
|
+
this.word("accessor", true);
|
|
3690
|
+
this.space();
|
|
3691
|
+
if (node.computed) {
|
|
3692
|
+
this.tokenChar(91);
|
|
3693
|
+
this.print(node.key);
|
|
3694
|
+
this.tokenChar(93);
|
|
3695
|
+
} else {
|
|
3696
|
+
_variance.call(this, node);
|
|
3697
|
+
this.print(node.key);
|
|
3698
|
+
}
|
|
3699
|
+
if (node.optional) this.tokenChar(63);
|
|
3700
|
+
if (node.definite) this.tokenChar(33);
|
|
3701
|
+
this.print(node.typeAnnotation);
|
|
3702
|
+
if (node.value) {
|
|
3703
|
+
this.space();
|
|
3704
|
+
this.tokenChar(61);
|
|
3705
|
+
this.space();
|
|
3706
|
+
this.print(node.value);
|
|
3707
|
+
}
|
|
3708
|
+
this.semicolon();
|
|
3709
|
+
}
|
|
3710
|
+
function ClassPrivateProperty(node) {
|
|
3711
|
+
this.printJoin(node.decorators);
|
|
3712
|
+
_tsPrintClassMemberModifiers.call(this, node);
|
|
3713
|
+
this.print(node.key);
|
|
3714
|
+
if (node.optional) this.tokenChar(63);
|
|
3715
|
+
if (node.definite) this.tokenChar(33);
|
|
3716
|
+
this.print(node.typeAnnotation);
|
|
3717
|
+
if (node.value) {
|
|
3718
|
+
this.space();
|
|
3719
|
+
this.tokenChar(61);
|
|
3720
|
+
this.space();
|
|
3721
|
+
this.print(node.value);
|
|
3722
|
+
}
|
|
3723
|
+
this.semicolon();
|
|
3724
|
+
}
|
|
3725
|
+
function ClassMethod(node) {
|
|
3726
|
+
_classMethodHead.call(this, node);
|
|
3727
|
+
this.space();
|
|
3728
|
+
this.print(node.body);
|
|
3729
|
+
}
|
|
3730
|
+
function ClassPrivateMethod(node) {
|
|
3731
|
+
_classMethodHead.call(this, node);
|
|
3732
|
+
this.space();
|
|
3733
|
+
this.print(node.body);
|
|
3734
|
+
}
|
|
3735
|
+
function _classMethodHead(node, allowDecorators = true) {
|
|
3736
|
+
if (allowDecorators) this.printJoin(node.decorators);
|
|
3737
|
+
if (!this.format.preserveFormat) {
|
|
3738
|
+
const endLine = node.key.loc?.end?.line;
|
|
3739
|
+
if (endLine) this.catchUp(endLine);
|
|
3740
|
+
}
|
|
3741
|
+
_tsPrintClassMemberModifiers.call(this, node);
|
|
3742
|
+
_methodHead.call(this, node);
|
|
3743
|
+
}
|
|
3744
|
+
function StaticBlock(node) {
|
|
3745
|
+
this.word("static");
|
|
3746
|
+
this.space();
|
|
3747
|
+
this.tokenChar(123);
|
|
3748
|
+
if (node.body.length === 0) this.tokenChar(125);
|
|
3749
|
+
else {
|
|
3750
|
+
this.newline();
|
|
3751
|
+
this.printSequence(node.body, true);
|
|
3752
|
+
this.rightBrace(node);
|
|
3753
|
+
}
|
|
3754
|
+
}
|
|
3755
|
+
function File(node) {
|
|
3756
|
+
if (node.program) this.print(node.program.interpreter);
|
|
3757
|
+
this.print(node.program);
|
|
3758
|
+
}
|
|
3759
|
+
function Program(node) {
|
|
3760
|
+
this.printInnerComments(false);
|
|
3761
|
+
const directivesLen = node.directives?.length;
|
|
3762
|
+
if (directivesLen) {
|
|
3763
|
+
const newline = node.body.length ? 2 : 1;
|
|
3764
|
+
this.printSequence(node.directives, void 0, void 0, newline);
|
|
3765
|
+
if (!node.directives[directivesLen - 1].trailingComments?.length) this.newline(newline);
|
|
3766
|
+
}
|
|
3767
|
+
this.printSequence(node.body);
|
|
3768
|
+
}
|
|
3769
|
+
function BlockStatement(node) {
|
|
3770
|
+
this.tokenChar(123);
|
|
3771
|
+
const oldNoLineTerminatorAfterNode = this.enterDelimited();
|
|
3772
|
+
const directivesLen = node.directives?.length;
|
|
3773
|
+
if (directivesLen) {
|
|
3774
|
+
const newline = node.body.length ? 2 : 1;
|
|
3775
|
+
this.printSequence(node.directives, true, true, newline);
|
|
3776
|
+
if (!node.directives[directivesLen - 1].trailingComments?.length) this.newline(newline);
|
|
3777
|
+
}
|
|
3778
|
+
this.printSequence(node.body, true, true);
|
|
3779
|
+
this._noLineTerminatorAfterNode = oldNoLineTerminatorAfterNode;
|
|
3780
|
+
this.rightBrace(node);
|
|
3781
|
+
}
|
|
3782
|
+
function Directive(node) {
|
|
3783
|
+
this.print(node.value);
|
|
3784
|
+
this.semicolon();
|
|
3785
|
+
}
|
|
3786
|
+
var unescapedSingleQuoteRE = /(?:^|[^\\])(?:\\\\)*'/;
|
|
3787
|
+
var unescapedDoubleQuoteRE = /(?:^|[^\\])(?:\\\\)*"/;
|
|
3788
|
+
function DirectiveLiteral(node) {
|
|
3789
|
+
const raw = this.getPossibleRaw(node);
|
|
3790
|
+
if (!this.format.minified && raw !== void 0) {
|
|
3791
|
+
this.token(raw);
|
|
3792
|
+
return;
|
|
3793
|
+
}
|
|
3794
|
+
const { value } = node;
|
|
3795
|
+
if (!unescapedDoubleQuoteRE.test(value)) this.token(`"${value}"`);
|
|
3796
|
+
else if (!unescapedSingleQuoteRE.test(value)) this.token(`'${value}'`);
|
|
3797
|
+
else throw new Error("Malformed AST: it is not possible to print a directive containing both unescaped single and double quotes.");
|
|
3798
|
+
}
|
|
3799
|
+
function InterpreterDirective(node) {
|
|
3800
|
+
this.token(`#!${node.value}`);
|
|
3801
|
+
this._newline();
|
|
3802
|
+
}
|
|
3803
|
+
function Placeholder(node) {
|
|
3804
|
+
this.token("%%");
|
|
3805
|
+
this.print(node.name);
|
|
3806
|
+
this.token("%%");
|
|
3807
|
+
if (node.expectedNode === "Statement") this.semicolon();
|
|
3808
|
+
}
|
|
3809
|
+
function JSXAttribute(node) {
|
|
3810
|
+
this.print(node.name);
|
|
3811
|
+
if (node.value) {
|
|
3812
|
+
this.tokenChar(61);
|
|
3813
|
+
this.print(node.value);
|
|
3814
|
+
}
|
|
3815
|
+
}
|
|
3816
|
+
function JSXIdentifier(node) {
|
|
3817
|
+
this.word(node.name);
|
|
3818
|
+
}
|
|
3819
|
+
function JSXNamespacedName(node) {
|
|
3820
|
+
this.print(node.namespace);
|
|
3821
|
+
this.tokenChar(58);
|
|
3822
|
+
this.print(node.name);
|
|
3823
|
+
}
|
|
3824
|
+
function JSXMemberExpression(node) {
|
|
3825
|
+
this.print(node.object);
|
|
3826
|
+
this.tokenChar(46);
|
|
3827
|
+
this.print(node.property);
|
|
3828
|
+
}
|
|
3829
|
+
function JSXSpreadAttribute(node) {
|
|
3830
|
+
this.tokenChar(123);
|
|
3831
|
+
this.token("...");
|
|
3832
|
+
this.print(node.argument);
|
|
3833
|
+
this.rightBrace(node);
|
|
3834
|
+
}
|
|
3835
|
+
function JSXExpressionContainer(node) {
|
|
3836
|
+
this.tokenChar(123);
|
|
3837
|
+
this.print(node.expression);
|
|
3838
|
+
this.rightBrace(node);
|
|
3839
|
+
}
|
|
3840
|
+
function JSXSpreadChild(node) {
|
|
3841
|
+
this.tokenChar(123);
|
|
3842
|
+
this.token("...");
|
|
3843
|
+
this.print(node.expression);
|
|
3844
|
+
this.rightBrace(node);
|
|
3845
|
+
}
|
|
3846
|
+
function JSXText(node) {
|
|
3847
|
+
const raw = this.getPossibleRaw(node);
|
|
3848
|
+
if (raw !== void 0) this.token(raw, true);
|
|
3849
|
+
else this.token(node.value, true);
|
|
3850
|
+
}
|
|
3851
|
+
function JSXElement(node) {
|
|
3852
|
+
const open = node.openingElement;
|
|
3853
|
+
this.print(open);
|
|
3854
|
+
if (open.selfClosing) return;
|
|
3855
|
+
this.indent();
|
|
3856
|
+
for (const child of node.children) this.print(child);
|
|
3857
|
+
this.dedent();
|
|
3858
|
+
this.print(node.closingElement);
|
|
3859
|
+
}
|
|
3860
|
+
function spaceSeparator() {
|
|
3861
|
+
this.space();
|
|
3862
|
+
}
|
|
3863
|
+
function JSXOpeningElement(node) {
|
|
3864
|
+
this.tokenChar(60);
|
|
3865
|
+
this.print(node.name);
|
|
3866
|
+
this.print(node.typeArguments);
|
|
3867
|
+
if (node.attributes.length > 0) {
|
|
3868
|
+
this.space();
|
|
3869
|
+
this.printJoin(node.attributes, void 0, void 0, spaceSeparator);
|
|
3870
|
+
}
|
|
3871
|
+
if (node.selfClosing) {
|
|
3872
|
+
this.space();
|
|
3873
|
+
this.tokenChar(47);
|
|
3874
|
+
}
|
|
3875
|
+
this.tokenChar(62);
|
|
3876
|
+
}
|
|
3877
|
+
function JSXClosingElement(node) {
|
|
3878
|
+
this.tokenChar(60);
|
|
3879
|
+
this.tokenChar(47);
|
|
3880
|
+
this.print(node.name);
|
|
3881
|
+
this.tokenChar(62);
|
|
3882
|
+
}
|
|
3883
|
+
function JSXEmptyExpression() {
|
|
3884
|
+
this.printInnerComments();
|
|
3885
|
+
}
|
|
3886
|
+
function JSXFragment(node) {
|
|
3887
|
+
this.print(node.openingFragment);
|
|
3888
|
+
this.indent();
|
|
3889
|
+
for (const child of node.children) this.print(child);
|
|
3890
|
+
this.dedent();
|
|
3891
|
+
this.print(node.closingFragment);
|
|
3892
|
+
}
|
|
3893
|
+
function JSXOpeningFragment() {
|
|
3894
|
+
this.tokenChar(60);
|
|
3895
|
+
this.tokenChar(62);
|
|
3896
|
+
}
|
|
3897
|
+
function JSXClosingFragment() {
|
|
3898
|
+
this.token("</");
|
|
3899
|
+
this.tokenChar(62);
|
|
3900
|
+
}
|
|
3901
|
+
var generatorFunctions = /*#__PURE__*/ Object.defineProperty({
|
|
3902
|
+
__proto__: null,
|
|
3903
|
+
AnyTypeAnnotation,
|
|
3904
|
+
ArgumentPlaceholder,
|
|
3905
|
+
ArrayExpression,
|
|
3906
|
+
ArrayPattern: ArrayExpression,
|
|
3907
|
+
ArrayTypeAnnotation,
|
|
3908
|
+
ArrowFunctionExpression,
|
|
3909
|
+
AssignmentExpression,
|
|
3910
|
+
AssignmentPattern,
|
|
3911
|
+
AwaitExpression,
|
|
3912
|
+
BigIntLiteral,
|
|
3913
|
+
BigIntLiteralTypeAnnotation: BigIntLiteral,
|
|
3914
|
+
BinaryExpression,
|
|
3915
|
+
BindExpression,
|
|
3916
|
+
BlockStatement,
|
|
3917
|
+
BooleanLiteral,
|
|
3918
|
+
BooleanLiteralTypeAnnotation,
|
|
3919
|
+
BooleanTypeAnnotation,
|
|
3920
|
+
BreakStatement,
|
|
3921
|
+
CallExpression,
|
|
3922
|
+
CatchClause,
|
|
3923
|
+
ClassAccessorProperty,
|
|
3924
|
+
ClassBody,
|
|
3925
|
+
ClassDeclaration,
|
|
3926
|
+
ClassExpression: ClassDeclaration,
|
|
3927
|
+
ClassImplements: InterfaceExtends,
|
|
3928
|
+
ClassMethod,
|
|
3929
|
+
ClassPrivateMethod,
|
|
3930
|
+
ClassPrivateProperty,
|
|
3931
|
+
ClassProperty,
|
|
3932
|
+
ConditionalExpression,
|
|
3933
|
+
ContinueStatement,
|
|
3934
|
+
DebuggerStatement,
|
|
3935
|
+
DeclareClass,
|
|
3936
|
+
DeclareExportAllDeclaration,
|
|
3937
|
+
DeclareExportDeclaration,
|
|
3938
|
+
DeclareFunction,
|
|
3939
|
+
DeclareInterface,
|
|
3940
|
+
DeclareModule,
|
|
3941
|
+
DeclareModuleExports,
|
|
3942
|
+
DeclareOpaqueType,
|
|
3943
|
+
DeclareTypeAlias,
|
|
3944
|
+
DeclareVariable,
|
|
3945
|
+
DeclaredPredicate,
|
|
3946
|
+
Decorator,
|
|
3947
|
+
Directive,
|
|
3948
|
+
DirectiveLiteral,
|
|
3949
|
+
DoExpression,
|
|
3950
|
+
DoWhileStatement,
|
|
3951
|
+
EmptyStatement,
|
|
3952
|
+
EmptyTypeAnnotation,
|
|
3953
|
+
EnumBooleanBody,
|
|
3954
|
+
EnumBooleanMember,
|
|
3955
|
+
EnumDeclaration,
|
|
3956
|
+
EnumDefaultedMember,
|
|
3957
|
+
EnumNumberBody,
|
|
3958
|
+
EnumNumberMember,
|
|
3959
|
+
EnumStringBody,
|
|
3960
|
+
EnumStringMember,
|
|
3961
|
+
EnumSymbolBody,
|
|
3962
|
+
ExistsTypeAnnotation,
|
|
3963
|
+
ExportAllDeclaration,
|
|
3964
|
+
ExportDefaultDeclaration,
|
|
3965
|
+
ExportDefaultSpecifier,
|
|
3966
|
+
ExportNamedDeclaration,
|
|
3967
|
+
ExportNamespaceSpecifier,
|
|
3968
|
+
ExportSpecifier,
|
|
3969
|
+
ExpressionStatement,
|
|
3970
|
+
File,
|
|
3971
|
+
ForInStatement,
|
|
3972
|
+
ForOfStatement,
|
|
3973
|
+
ForStatement,
|
|
3974
|
+
FunctionDeclaration: FunctionExpression,
|
|
3975
|
+
FunctionExpression,
|
|
3976
|
+
FunctionTypeAnnotation,
|
|
3977
|
+
FunctionTypeParam,
|
|
3978
|
+
GenericTypeAnnotation: InterfaceExtends,
|
|
3979
|
+
Identifier,
|
|
3980
|
+
IfStatement,
|
|
3981
|
+
Import,
|
|
3982
|
+
ImportAttribute,
|
|
3983
|
+
ImportDeclaration,
|
|
3984
|
+
ImportDefaultSpecifier,
|
|
3985
|
+
ImportExpression,
|
|
3986
|
+
ImportNamespaceSpecifier,
|
|
3987
|
+
ImportSpecifier,
|
|
3988
|
+
IndexedAccessType,
|
|
3989
|
+
InferredPredicate,
|
|
3990
|
+
InterfaceDeclaration,
|
|
3991
|
+
InterfaceExtends,
|
|
3992
|
+
InterfaceTypeAnnotation,
|
|
3993
|
+
InterpreterDirective,
|
|
3994
|
+
IntersectionTypeAnnotation,
|
|
3995
|
+
JSXAttribute,
|
|
3996
|
+
JSXClosingElement,
|
|
3997
|
+
JSXClosingFragment,
|
|
3998
|
+
JSXElement,
|
|
3999
|
+
JSXEmptyExpression,
|
|
4000
|
+
JSXExpressionContainer,
|
|
4001
|
+
JSXFragment,
|
|
4002
|
+
JSXIdentifier,
|
|
4003
|
+
JSXMemberExpression,
|
|
4004
|
+
JSXNamespacedName,
|
|
4005
|
+
JSXOpeningElement,
|
|
4006
|
+
JSXOpeningFragment,
|
|
4007
|
+
JSXSpreadAttribute,
|
|
4008
|
+
JSXSpreadChild,
|
|
4009
|
+
JSXText,
|
|
4010
|
+
LabeledStatement,
|
|
4011
|
+
LogicalExpression: AssignmentExpression,
|
|
4012
|
+
MemberExpression,
|
|
4013
|
+
MetaProperty,
|
|
4014
|
+
MixedTypeAnnotation,
|
|
4015
|
+
ModuleExpression,
|
|
4016
|
+
NewExpression,
|
|
4017
|
+
NullLiteral,
|
|
4018
|
+
NullLiteralTypeAnnotation,
|
|
4019
|
+
NullableTypeAnnotation,
|
|
4020
|
+
NumberLiteralTypeAnnotation: NumericLiteral,
|
|
4021
|
+
NumberTypeAnnotation,
|
|
4022
|
+
NumericLiteral,
|
|
4023
|
+
ObjectExpression,
|
|
4024
|
+
ObjectMethod,
|
|
4025
|
+
ObjectPattern: ObjectExpression,
|
|
4026
|
+
ObjectProperty,
|
|
4027
|
+
ObjectTypeAnnotation,
|
|
4028
|
+
ObjectTypeCallProperty,
|
|
4029
|
+
ObjectTypeIndexer,
|
|
4030
|
+
ObjectTypeInternalSlot,
|
|
4031
|
+
ObjectTypeProperty,
|
|
4032
|
+
ObjectTypeSpreadProperty,
|
|
4033
|
+
OpaqueType,
|
|
4034
|
+
OptionalCallExpression,
|
|
4035
|
+
OptionalIndexedAccessType,
|
|
4036
|
+
OptionalMemberExpression,
|
|
4037
|
+
ParenthesizedExpression,
|
|
4038
|
+
Placeholder,
|
|
4039
|
+
PrivateName,
|
|
4040
|
+
Program,
|
|
4041
|
+
QualifiedTypeIdentifier,
|
|
4042
|
+
RegExpLiteral,
|
|
4043
|
+
RestElement,
|
|
4044
|
+
ReturnStatement,
|
|
4045
|
+
SequenceExpression,
|
|
4046
|
+
SpreadElement: RestElement,
|
|
4047
|
+
StaticBlock,
|
|
4048
|
+
StringLiteral,
|
|
4049
|
+
StringLiteralTypeAnnotation: StringLiteral,
|
|
4050
|
+
StringTypeAnnotation,
|
|
4051
|
+
Super,
|
|
4052
|
+
SwitchCase,
|
|
4053
|
+
SwitchStatement,
|
|
4054
|
+
SymbolTypeAnnotation,
|
|
4055
|
+
TSAnyKeyword,
|
|
4056
|
+
TSArrayType,
|
|
4057
|
+
TSAsExpression,
|
|
4058
|
+
TSBigIntKeyword,
|
|
4059
|
+
TSBooleanKeyword,
|
|
4060
|
+
TSCallSignatureDeclaration,
|
|
4061
|
+
TSClassImplements,
|
|
4062
|
+
TSConditionalType,
|
|
4063
|
+
TSConstructSignatureDeclaration,
|
|
4064
|
+
TSConstructorType,
|
|
4065
|
+
TSDeclareFunction,
|
|
4066
|
+
TSDeclareMethod,
|
|
4067
|
+
TSEnumBody,
|
|
4068
|
+
TSEnumDeclaration,
|
|
4069
|
+
TSEnumMember,
|
|
4070
|
+
TSExportAssignment,
|
|
4071
|
+
TSExternalModuleReference,
|
|
4072
|
+
TSFunctionType,
|
|
4073
|
+
TSImportEqualsDeclaration,
|
|
4074
|
+
TSImportType,
|
|
4075
|
+
TSIndexSignature,
|
|
4076
|
+
TSIndexedAccessType,
|
|
4077
|
+
TSInferType,
|
|
4078
|
+
TSInstantiationExpression,
|
|
4079
|
+
TSInterfaceBody,
|
|
4080
|
+
TSInterfaceDeclaration,
|
|
4081
|
+
TSInterfaceHeritage: TSClassImplements,
|
|
4082
|
+
TSIntersectionType,
|
|
4083
|
+
TSIntrinsicKeyword,
|
|
4084
|
+
TSLiteralType,
|
|
4085
|
+
TSMappedType,
|
|
4086
|
+
TSMethodSignature,
|
|
4087
|
+
TSModuleBlock,
|
|
4088
|
+
TSModuleDeclaration,
|
|
4089
|
+
TSNamedTupleMember,
|
|
4090
|
+
TSNamespaceExportDeclaration,
|
|
4091
|
+
TSNeverKeyword,
|
|
4092
|
+
TSNonNullExpression,
|
|
4093
|
+
TSNullKeyword,
|
|
4094
|
+
TSNumberKeyword,
|
|
4095
|
+
TSObjectKeyword,
|
|
4096
|
+
TSOptionalType,
|
|
4097
|
+
TSParameterProperty,
|
|
4098
|
+
TSParenthesizedType,
|
|
4099
|
+
TSPropertySignature,
|
|
4100
|
+
TSQualifiedName,
|
|
4101
|
+
TSRestType,
|
|
4102
|
+
TSSatisfiesExpression,
|
|
4103
|
+
TSStringKeyword,
|
|
4104
|
+
TSSymbolKeyword,
|
|
4105
|
+
TSTemplateLiteralType,
|
|
4106
|
+
TSThisType,
|
|
4107
|
+
TSTupleType,
|
|
4108
|
+
TSTypeAliasDeclaration,
|
|
4109
|
+
TSTypeAnnotation,
|
|
4110
|
+
TSTypeAssertion,
|
|
4111
|
+
TSTypeLiteral,
|
|
4112
|
+
TSTypeOperator,
|
|
4113
|
+
TSTypeParameter,
|
|
4114
|
+
TSTypeParameterDeclaration: TSTypeParameterInstantiation,
|
|
4115
|
+
TSTypeParameterInstantiation,
|
|
4116
|
+
TSTypePredicate,
|
|
4117
|
+
TSTypeQuery,
|
|
4118
|
+
TSTypeReference,
|
|
4119
|
+
TSUndefinedKeyword,
|
|
4120
|
+
TSUnionType,
|
|
4121
|
+
TSUnknownKeyword,
|
|
4122
|
+
TSVoidKeyword,
|
|
4123
|
+
TaggedTemplateExpression,
|
|
4124
|
+
TemplateElement,
|
|
4125
|
+
TemplateLiteral,
|
|
4126
|
+
ThisExpression,
|
|
4127
|
+
ThisTypeAnnotation,
|
|
4128
|
+
ThrowStatement,
|
|
4129
|
+
TopicReference,
|
|
4130
|
+
TryStatement,
|
|
4131
|
+
TupleTypeAnnotation,
|
|
4132
|
+
TypeAlias,
|
|
4133
|
+
TypeAnnotation,
|
|
4134
|
+
TypeCastExpression,
|
|
4135
|
+
TypeParameter,
|
|
4136
|
+
TypeParameterDeclaration: TypeParameterInstantiation,
|
|
4137
|
+
TypeParameterInstantiation,
|
|
4138
|
+
TypeofTypeAnnotation,
|
|
4139
|
+
UnaryExpression,
|
|
4140
|
+
UnionTypeAnnotation,
|
|
4141
|
+
UpdateExpression,
|
|
4142
|
+
V8IntrinsicIdentifier,
|
|
4143
|
+
VariableDeclaration,
|
|
4144
|
+
VariableDeclarator,
|
|
4145
|
+
Variance,
|
|
4146
|
+
VoidPattern,
|
|
4147
|
+
VoidTypeAnnotation,
|
|
4148
|
+
WhileStatement,
|
|
4149
|
+
WithStatement,
|
|
4150
|
+
YieldExpression,
|
|
4151
|
+
_classMethodHead,
|
|
4152
|
+
_functionHead,
|
|
4153
|
+
_getRawIdentifier,
|
|
4154
|
+
_interfaceish,
|
|
4155
|
+
_methodHead,
|
|
4156
|
+
_param,
|
|
4157
|
+
_parameters,
|
|
4158
|
+
_params,
|
|
4159
|
+
_predicate,
|
|
4160
|
+
_printAttributes,
|
|
4161
|
+
_printTemplate,
|
|
4162
|
+
_shouldPrintArrowParamsParens,
|
|
4163
|
+
_shouldPrintDecoratorsBeforeExport,
|
|
4164
|
+
_tsPrintClassMemberModifiers,
|
|
4165
|
+
_variance
|
|
4166
|
+
}, Symbol.toStringTag, { value: "Module" });
|
|
4167
|
+
var generatorInfosMap = /* @__PURE__ */ new Map();
|
|
4168
|
+
var index = 0;
|
|
4169
|
+
for (const key of Object.keys(generatorFunctions).sort()) {
|
|
4170
|
+
if (key.startsWith("_")) continue;
|
|
4171
|
+
generatorInfosMap.set(key, [
|
|
4172
|
+
generatorFunctions[key],
|
|
4173
|
+
index++,
|
|
4174
|
+
void 0
|
|
4175
|
+
]);
|
|
4176
|
+
}
|
|
4177
|
+
var { VISITOR_KEYS: VISITOR_KEYS$1 } = _t;
|
|
4178
|
+
for (const type of Object.keys(parens)) {
|
|
4179
|
+
const func = parens[type];
|
|
4180
|
+
if (generatorInfosMap.has(type)) generatorInfosMap.get(type)[2] = func;
|
|
4181
|
+
}
|
|
4182
|
+
function newCalleeNeedsParens(node) {
|
|
4183
|
+
let current = node;
|
|
4184
|
+
while (true) switch (current.type) {
|
|
4185
|
+
case "CallExpression":
|
|
4186
|
+
case "ImportExpression":
|
|
4187
|
+
case "OptionalCallExpression":
|
|
4188
|
+
case "OptionalMemberExpression": return true;
|
|
4189
|
+
case "MemberExpression":
|
|
4190
|
+
current = current.object;
|
|
4191
|
+
break;
|
|
4192
|
+
case "TaggedTemplateExpression":
|
|
4193
|
+
current = current.tag;
|
|
4194
|
+
break;
|
|
4195
|
+
case "TSNonNullExpression":
|
|
4196
|
+
current = current.expression;
|
|
4197
|
+
break;
|
|
4198
|
+
default: return false;
|
|
4199
|
+
}
|
|
4200
|
+
}
|
|
4201
|
+
function parentNeedsParens(node, parent, parentId) {
|
|
4202
|
+
switch (parentId) {
|
|
4203
|
+
case 113:
|
|
4204
|
+
if (parent.callee === node) return newCalleeNeedsParens(node);
|
|
4205
|
+
break;
|
|
4206
|
+
case 43: return !isDecoratorMemberExpression(node) && !(node.type === "CallExpression" && isDecoratorMemberExpression(node.callee)) && node.type !== "ParenthesizedExpression";
|
|
4207
|
+
}
|
|
4208
|
+
return false;
|
|
4209
|
+
}
|
|
4210
|
+
function isDecoratorMemberExpression(node) {
|
|
4211
|
+
switch (node.type) {
|
|
4212
|
+
case "Identifier": return true;
|
|
4213
|
+
case "MemberExpression": return !node.computed && node.property.type === "Identifier" && isDecoratorMemberExpression(node.object);
|
|
4214
|
+
default: return false;
|
|
4215
|
+
}
|
|
4216
|
+
}
|
|
4217
|
+
function isLastChild(parent, child) {
|
|
4218
|
+
const visitorKeys = VISITOR_KEYS$1[parent.type];
|
|
4219
|
+
for (let i = visitorKeys.length - 1; i >= 0; i--) {
|
|
4220
|
+
const val = parent[visitorKeys[i]];
|
|
4221
|
+
if (val === child) return true;
|
|
4222
|
+
else if (Array.isArray(val)) {
|
|
4223
|
+
let j = val.length - 1;
|
|
4224
|
+
while (j >= 0 && val[j] === null) j--;
|
|
4225
|
+
return j >= 0 && val[j] === child;
|
|
4226
|
+
} else if (val) return false;
|
|
4227
|
+
}
|
|
4228
|
+
return false;
|
|
4229
|
+
}
|
|
4230
|
+
var { traverseFast, VISITOR_KEYS } = _t;
|
|
4231
|
+
var TokenMap = class {
|
|
4232
|
+
_tokens;
|
|
4233
|
+
_source;
|
|
4234
|
+
_nodesToTokenIndexes = /* @__PURE__ */ new Map();
|
|
4235
|
+
_nodesOccurrencesCountCache = /* @__PURE__ */ new Map();
|
|
4236
|
+
_tokensCache = /* @__PURE__ */ new Map();
|
|
4237
|
+
constructor(ast, tokens, source) {
|
|
4238
|
+
this._tokens = tokens;
|
|
4239
|
+
this._source = source;
|
|
4240
|
+
traverseFast(ast, (node) => {
|
|
4241
|
+
const indexes = this._getTokensIndexesOfNode(node);
|
|
4242
|
+
if (indexes.length > 0) this._nodesToTokenIndexes.set(node, indexes);
|
|
4243
|
+
});
|
|
4244
|
+
this._tokensCache.clear();
|
|
4245
|
+
}
|
|
4246
|
+
has(node) {
|
|
4247
|
+
return this._nodesToTokenIndexes.has(node);
|
|
4248
|
+
}
|
|
4249
|
+
getIndexes(node) {
|
|
4250
|
+
return this._nodesToTokenIndexes.get(node);
|
|
4251
|
+
}
|
|
4252
|
+
find(node, condition) {
|
|
4253
|
+
const indexes = this._nodesToTokenIndexes.get(node);
|
|
4254
|
+
if (indexes) for (let k = 0; k < indexes.length; k++) {
|
|
4255
|
+
const index = indexes[k];
|
|
4256
|
+
const tok = this._tokens[index];
|
|
4257
|
+
if (condition(tok, index)) return tok;
|
|
4258
|
+
}
|
|
4259
|
+
return null;
|
|
4260
|
+
}
|
|
4261
|
+
findLastIndex(node, condition) {
|
|
4262
|
+
const indexes = this._nodesToTokenIndexes.get(node);
|
|
4263
|
+
if (indexes) for (let k = indexes.length - 1; k >= 0; k--) {
|
|
4264
|
+
const index = indexes[k];
|
|
4265
|
+
const tok = this._tokens[index];
|
|
4266
|
+
if (condition(tok, index)) return index;
|
|
4267
|
+
}
|
|
4268
|
+
return -1;
|
|
4269
|
+
}
|
|
4270
|
+
findMatching(node, test, occurrenceCount = 0) {
|
|
4271
|
+
const indexes = this._nodesToTokenIndexes.get(node);
|
|
4272
|
+
if (indexes) {
|
|
4273
|
+
if (typeof test === "number") test = String.fromCharCode(test);
|
|
4274
|
+
let i = 0;
|
|
4275
|
+
const count = occurrenceCount;
|
|
4276
|
+
if (count > 1) {
|
|
4277
|
+
const cache = this._nodesOccurrencesCountCache.get(node);
|
|
4278
|
+
if (cache?.test === test && cache.count < count) {
|
|
4279
|
+
i = cache.i + 1;
|
|
4280
|
+
occurrenceCount -= cache.count + 1;
|
|
4281
|
+
}
|
|
4282
|
+
}
|
|
4283
|
+
for (; i < indexes.length; i++) {
|
|
4284
|
+
const tok = this._tokens[indexes[i]];
|
|
4285
|
+
if (this.matchesOriginal(tok, test)) {
|
|
4286
|
+
if (occurrenceCount === 0) {
|
|
4287
|
+
if (count > 0) this._nodesOccurrencesCountCache.set(node, {
|
|
4288
|
+
test,
|
|
4289
|
+
count,
|
|
4290
|
+
i
|
|
4291
|
+
});
|
|
4292
|
+
return tok;
|
|
4293
|
+
}
|
|
4294
|
+
occurrenceCount--;
|
|
4295
|
+
}
|
|
4296
|
+
}
|
|
4297
|
+
}
|
|
4298
|
+
return null;
|
|
4299
|
+
}
|
|
4300
|
+
matchesOriginal(token, test) {
|
|
4301
|
+
if (token.end - token.start !== test.length) return false;
|
|
4302
|
+
if (token.value != null) return token.value === test;
|
|
4303
|
+
return this._source.startsWith(test, token.start);
|
|
4304
|
+
}
|
|
4305
|
+
startMatches(node, test) {
|
|
4306
|
+
const indexes = this._nodesToTokenIndexes.get(node);
|
|
4307
|
+
if (!indexes) return false;
|
|
4308
|
+
const tok = this._tokens[indexes[0]];
|
|
4309
|
+
if (tok.start !== node.start) return false;
|
|
4310
|
+
return this.matchesOriginal(tok, test);
|
|
4311
|
+
}
|
|
4312
|
+
endMatches(node, test) {
|
|
4313
|
+
const indexes = this._nodesToTokenIndexes.get(node);
|
|
4314
|
+
if (!indexes) return false;
|
|
4315
|
+
const tok = this._tokens[indexes[indexes.length - 1]];
|
|
4316
|
+
if (tok.end !== node.end) return false;
|
|
4317
|
+
return this.matchesOriginal(tok, test);
|
|
4318
|
+
}
|
|
4319
|
+
_getTokensIndexesOfNode(node) {
|
|
4320
|
+
if (node.start == null || node.end == null) return [];
|
|
4321
|
+
const { first, last } = this._findTokensOfNode(node, 0, this._tokens.length - 1);
|
|
4322
|
+
let low = first;
|
|
4323
|
+
const children = childrenIterator(node);
|
|
4324
|
+
if ((node.type === "ExportNamedDeclaration" || node.type === "ExportDefaultDeclaration") && node.declaration?.type === "ClassDeclaration") children.next();
|
|
4325
|
+
const indexes = [];
|
|
4326
|
+
for (const child of children) {
|
|
4327
|
+
if (child == null) continue;
|
|
4328
|
+
if (child.start == null || child.end == null) continue;
|
|
4329
|
+
const childTok = this._findTokensOfNode(child, low, last);
|
|
4330
|
+
const high = childTok.first;
|
|
4331
|
+
for (let k = low; k < high; k++) indexes.push(k);
|
|
4332
|
+
low = childTok.last + 1;
|
|
4333
|
+
}
|
|
4334
|
+
for (let k = low; k <= last; k++) indexes.push(k);
|
|
4335
|
+
return indexes;
|
|
4336
|
+
}
|
|
4337
|
+
_findTokensOfNode(node, low, high) {
|
|
4338
|
+
const cached = this._tokensCache.get(node);
|
|
4339
|
+
if (cached) return cached;
|
|
4340
|
+
const first = this._findFirstTokenOfNode(node.start, low, high);
|
|
4341
|
+
const last = this._findLastTokenOfNode(node.end, first, high);
|
|
4342
|
+
this._tokensCache.set(node, {
|
|
4343
|
+
first,
|
|
4344
|
+
last
|
|
4345
|
+
});
|
|
4346
|
+
return {
|
|
4347
|
+
first,
|
|
4348
|
+
last
|
|
4349
|
+
};
|
|
4350
|
+
}
|
|
4351
|
+
_findFirstTokenOfNode(start, low, high) {
|
|
4352
|
+
while (low <= high) {
|
|
4353
|
+
const mid = high + low >> 1;
|
|
4354
|
+
if (start < this._tokens[mid].start) high = mid - 1;
|
|
4355
|
+
else if (start > this._tokens[mid].start) low = mid + 1;
|
|
4356
|
+
else return mid;
|
|
4357
|
+
}
|
|
4358
|
+
return low;
|
|
4359
|
+
}
|
|
4360
|
+
_findLastTokenOfNode(end, low, high) {
|
|
4361
|
+
while (low <= high) {
|
|
4362
|
+
const mid = high + low >> 1;
|
|
4363
|
+
if (end < this._tokens[mid].end) high = mid - 1;
|
|
4364
|
+
else if (end > this._tokens[mid].end) low = mid + 1;
|
|
4365
|
+
else return mid;
|
|
4366
|
+
}
|
|
4367
|
+
return high;
|
|
4368
|
+
}
|
|
4369
|
+
};
|
|
4370
|
+
function* childrenIterator(node) {
|
|
4371
|
+
if (node.type === "TemplateLiteral") {
|
|
4372
|
+
yield node.quasis[0];
|
|
4373
|
+
for (let i = 1; i < node.quasis.length; i++) {
|
|
4374
|
+
yield node.expressions[i - 1];
|
|
4375
|
+
yield node.quasis[i];
|
|
4376
|
+
}
|
|
4377
|
+
return;
|
|
4378
|
+
}
|
|
4379
|
+
const keys = VISITOR_KEYS[node.type];
|
|
4380
|
+
for (const key of keys) {
|
|
4381
|
+
const child = node[key];
|
|
4382
|
+
if (!child) continue;
|
|
4383
|
+
if (Array.isArray(child)) yield* child;
|
|
4384
|
+
else yield child;
|
|
4385
|
+
}
|
|
4386
|
+
}
|
|
4387
|
+
var { isExpression, isFunction, isStatement, isClassBody, isTSInterfaceBody, isTSEnumMember } = _t;
|
|
4388
|
+
var SCIENTIFIC_NOTATION = /e/i;
|
|
4389
|
+
var ZERO_DECIMAL_INTEGER = /\.0+$/;
|
|
4390
|
+
var HAS_NEWLINE = /[\n\r\u2028\u2029]/;
|
|
4391
|
+
var HAS_NEWLINE_OR_BlOCK_COMMENT_END = /[\n\r\u2028\u2029]|\*\//;
|
|
4392
|
+
function commentIsNewline(c) {
|
|
4393
|
+
return c.type === "CommentLine" || HAS_NEWLINE.test(c.value);
|
|
4394
|
+
}
|
|
4395
|
+
var Printer = class {
|
|
4396
|
+
constructor(format, map, tokens = null, originalCode = null) {
|
|
4397
|
+
this.format = format;
|
|
4398
|
+
this._tokens = tokens;
|
|
4399
|
+
this._originalCode = originalCode;
|
|
4400
|
+
this._indentRepeat = format.indent.style.length;
|
|
4401
|
+
this._inputMap = map?._inputMap || null;
|
|
4402
|
+
this._buf = new Buffer$1(map, format.indent.style[0]);
|
|
4403
|
+
const { preserveFormat, compact, concise, retainLines, retainFunctionParens } = format;
|
|
4404
|
+
if (preserveFormat) this._flags |= 1;
|
|
4405
|
+
if (compact) this._flags |= 2;
|
|
4406
|
+
if (concise) this._flags |= 4;
|
|
4407
|
+
if (retainLines) this._flags |= 8;
|
|
4408
|
+
if (retainFunctionParens) this._flags |= 16;
|
|
4409
|
+
if (format.auxiliaryCommentBefore || format.auxiliaryCommentAfter) this._flags |= 32;
|
|
4410
|
+
}
|
|
4411
|
+
enterDelimited() {
|
|
4412
|
+
const oldNoLineTerminatorAfterNode = this._noLineTerminatorAfterNode;
|
|
4413
|
+
if (oldNoLineTerminatorAfterNode !== null) this._noLineTerminatorAfterNode = null;
|
|
4414
|
+
return oldNoLineTerminatorAfterNode;
|
|
4415
|
+
}
|
|
4416
|
+
tokenContext = 0;
|
|
4417
|
+
_tokens = null;
|
|
4418
|
+
_originalCode = null;
|
|
4419
|
+
_currentNode = null;
|
|
4420
|
+
_currentTypeId = null;
|
|
4421
|
+
_indent = 0;
|
|
4422
|
+
_indentRepeat = 0;
|
|
4423
|
+
_insideAux = false;
|
|
4424
|
+
_noLineTerminator = false;
|
|
4425
|
+
_noLineTerminatorAfterNode = null;
|
|
4426
|
+
_printAuxAfterOnNextUserNode = false;
|
|
4427
|
+
_printedComments = /* @__PURE__ */ new Set();
|
|
4428
|
+
_lastCommentLine = 0;
|
|
4429
|
+
_innerCommentsState = 0;
|
|
4430
|
+
_flags = 0;
|
|
4431
|
+
tokenMap = null;
|
|
4432
|
+
_boundGetRawIdentifier = null;
|
|
4433
|
+
generate(ast) {
|
|
4434
|
+
if (this.format.preserveFormat) {
|
|
4435
|
+
this.tokenMap = new TokenMap(ast, this._tokens, this._originalCode);
|
|
4436
|
+
this._boundGetRawIdentifier = _getRawIdentifier.bind(this);
|
|
4437
|
+
}
|
|
4438
|
+
this.print(ast);
|
|
4439
|
+
this._maybeAddAuxComment();
|
|
4440
|
+
return this._buf.get();
|
|
4441
|
+
}
|
|
4442
|
+
indent(flags = this._flags) {
|
|
4443
|
+
if (flags & 7) return;
|
|
4444
|
+
this._indent += this._indentRepeat;
|
|
4445
|
+
}
|
|
4446
|
+
dedent(flags = this._flags) {
|
|
4447
|
+
if (flags & 7) return;
|
|
4448
|
+
this._indent -= this._indentRepeat;
|
|
4449
|
+
}
|
|
4450
|
+
_printSemicolonBeforeNextNode = -1;
|
|
4451
|
+
_printSemicolonBeforeNextToken = -1;
|
|
4452
|
+
semicolon(force = false) {
|
|
4453
|
+
const flags = this._flags;
|
|
4454
|
+
if (flags & 32) this._maybeAddAuxComment();
|
|
4455
|
+
if (flags & 1) {
|
|
4456
|
+
const node = this._currentNode;
|
|
4457
|
+
if (node.start != null && node.end != null) {
|
|
4458
|
+
if (!this.tokenMap.endMatches(node, ";")) {
|
|
4459
|
+
this._printSemicolonBeforeNextNode = this._buf.getCurrentLine();
|
|
4460
|
+
return;
|
|
4461
|
+
}
|
|
4462
|
+
const indexes = this.tokenMap.getIndexes(this._currentNode);
|
|
4463
|
+
this._catchUpTo(this._tokens[indexes[indexes.length - 1]].loc.start);
|
|
4464
|
+
}
|
|
4465
|
+
}
|
|
4466
|
+
if (force) this._appendChar(59);
|
|
4467
|
+
else this._queue(59);
|
|
4468
|
+
this._noLineTerminator = false;
|
|
4469
|
+
}
|
|
4470
|
+
rightBrace(node) {
|
|
4471
|
+
if (this.format.minified) this._buf.removeLastSemicolon();
|
|
4472
|
+
this.sourceWithOffset("end", node.loc, -1);
|
|
4473
|
+
this.tokenChar(125);
|
|
4474
|
+
}
|
|
4475
|
+
rightParens(node) {
|
|
4476
|
+
this.sourceWithOffset("end", node.loc, -1);
|
|
4477
|
+
this.tokenChar(41);
|
|
4478
|
+
}
|
|
4479
|
+
space(force = false) {
|
|
4480
|
+
if (this._flags & 3) return;
|
|
4481
|
+
if (force) this._space();
|
|
4482
|
+
else {
|
|
4483
|
+
const lastCp = this.getLastChar(true);
|
|
4484
|
+
if (lastCp !== 0 && lastCp !== 32 && lastCp !== 10) this._space();
|
|
4485
|
+
}
|
|
4486
|
+
}
|
|
4487
|
+
word(str, noLineTerminatorAfter = false) {
|
|
4488
|
+
this.tokenContext &= 128;
|
|
4489
|
+
this._maybePrintInnerComments(str);
|
|
4490
|
+
const flags = this._flags;
|
|
4491
|
+
if (flags & 32) this._maybeAddAuxComment();
|
|
4492
|
+
if (flags & 1) this._catchUpToCurrentToken(str);
|
|
4493
|
+
const lastChar = this.getLastChar();
|
|
4494
|
+
if (lastChar === -2 || lastChar === -3 || lastChar === 47 && str.charCodeAt(0) === 47) this._space();
|
|
4495
|
+
this._append(str, false);
|
|
4496
|
+
this.setLastChar(-3);
|
|
4497
|
+
this._noLineTerminator = noLineTerminatorAfter;
|
|
4498
|
+
}
|
|
4499
|
+
number(str, number) {
|
|
4500
|
+
function isNonDecimalLiteral(str) {
|
|
4501
|
+
if (str.length > 2 && str.charCodeAt(0) === 48) {
|
|
4502
|
+
const secondChar = str.charCodeAt(1);
|
|
4503
|
+
return secondChar === 98 || secondChar === 111 || secondChar === 120;
|
|
4504
|
+
}
|
|
4505
|
+
return false;
|
|
4506
|
+
}
|
|
4507
|
+
this.word(str);
|
|
4508
|
+
if (Number.isInteger(number) && !isNonDecimalLiteral(str) && !SCIENTIFIC_NOTATION.test(str) && !ZERO_DECIMAL_INTEGER.test(str) && str.charCodeAt(str.length - 1) !== 46) this.setLastChar(-2);
|
|
4509
|
+
}
|
|
4510
|
+
token(str, maybeNewline = false, occurrenceCount = 0, mayNeedSpace = false) {
|
|
4511
|
+
this.tokenContext &= 128;
|
|
4512
|
+
this._maybePrintInnerComments(str, occurrenceCount);
|
|
4513
|
+
const flags = this._flags;
|
|
4514
|
+
if (flags & 32) this._maybeAddAuxComment();
|
|
4515
|
+
if (flags & 1) this._catchUpToCurrentToken(str, occurrenceCount);
|
|
4516
|
+
if (mayNeedSpace) {
|
|
4517
|
+
const strFirst = str.charCodeAt(0);
|
|
4518
|
+
if ((strFirst === 45 && str === "--" || strFirst === 61) && this.getLastChar() === 33 || strFirst === 43 && this.getLastChar() === 43 || strFirst === 45 && this.getLastChar() === 45 || strFirst === 46 && this.getLastChar() === -2) this._space();
|
|
4519
|
+
}
|
|
4520
|
+
this._append(str, maybeNewline);
|
|
4521
|
+
this._noLineTerminator = false;
|
|
4522
|
+
}
|
|
4523
|
+
tokenChar(char, occurrenceCount = 0) {
|
|
4524
|
+
this.tokenContext &= 128;
|
|
4525
|
+
this._maybePrintInnerComments(char, occurrenceCount);
|
|
4526
|
+
const flags = this._flags;
|
|
4527
|
+
if (flags & 32) this._maybeAddAuxComment();
|
|
4528
|
+
if (flags & 1) this._catchUpToCurrentToken(char, occurrenceCount);
|
|
4529
|
+
if (char === 43 && this.getLastChar() === 43 || char === 45 && this.getLastChar() === 45 || char === 46 && this.getLastChar() === -2) this._space();
|
|
4530
|
+
this._appendChar(char);
|
|
4531
|
+
this._noLineTerminator = false;
|
|
4532
|
+
}
|
|
4533
|
+
newline(i = 1, flags = this._flags) {
|
|
4534
|
+
if (i <= 0) return;
|
|
4535
|
+
if (flags & 10) return;
|
|
4536
|
+
if (flags & 4) {
|
|
4537
|
+
this.space();
|
|
4538
|
+
return;
|
|
4539
|
+
}
|
|
4540
|
+
if (i > 2) i = 2;
|
|
4541
|
+
i -= this._buf.getNewlineCount();
|
|
4542
|
+
for (let j = 0; j < i; j++) this._newline();
|
|
4543
|
+
}
|
|
4544
|
+
endsWith(char) {
|
|
4545
|
+
return this.getLastChar(true) === char;
|
|
4546
|
+
}
|
|
4547
|
+
getLastChar(checkQueue) {
|
|
4548
|
+
return this._buf.getLastChar(checkQueue);
|
|
4549
|
+
}
|
|
4550
|
+
setLastChar(char) {
|
|
4551
|
+
this._buf._last = char;
|
|
4552
|
+
}
|
|
4553
|
+
exactSource(loc, cb) {
|
|
4554
|
+
if (!loc) {
|
|
4555
|
+
cb();
|
|
4556
|
+
return;
|
|
4557
|
+
}
|
|
4558
|
+
this._catchUp("start", loc);
|
|
4559
|
+
this._buf.exactSource(loc, cb);
|
|
4560
|
+
}
|
|
4561
|
+
source(prop, loc) {
|
|
4562
|
+
if (!loc) return;
|
|
4563
|
+
this._catchUp(prop, loc);
|
|
4564
|
+
this._buf.source(prop, loc);
|
|
4565
|
+
}
|
|
4566
|
+
sourceWithOffset(prop, loc, columnOffset) {
|
|
4567
|
+
if (!loc || this.format.preserveFormat) return;
|
|
4568
|
+
this._catchUp(prop, loc);
|
|
4569
|
+
this._buf.sourceWithOffset(prop, loc, columnOffset);
|
|
4570
|
+
}
|
|
4571
|
+
sourceIdentifierName(identifierName, pos) {
|
|
4572
|
+
if (!this._buf._canMarkIdName) return;
|
|
4573
|
+
const sourcePosition = this._buf._sourcePosition;
|
|
4574
|
+
sourcePosition.identifierNamePos = pos;
|
|
4575
|
+
sourcePosition.identifierName = identifierName;
|
|
4576
|
+
}
|
|
4577
|
+
_space() {
|
|
4578
|
+
this._queue(32);
|
|
4579
|
+
}
|
|
4580
|
+
_newline() {
|
|
4581
|
+
if (this._buf._queuedChar === 32) this._buf._queuedChar = 0;
|
|
4582
|
+
this._appendChar(10, true);
|
|
4583
|
+
}
|
|
4584
|
+
_catchUpToCurrentToken(str, occurrenceCount = 0) {
|
|
4585
|
+
const token = this.tokenMap.findMatching(this._currentNode, str, occurrenceCount);
|
|
4586
|
+
if (token) this._catchUpTo(token.loc.start);
|
|
4587
|
+
if (this._printSemicolonBeforeNextToken !== -1 && this._printSemicolonBeforeNextToken === this._buf.getCurrentLine()) this._appendChar(59, true);
|
|
4588
|
+
this._printSemicolonBeforeNextToken = -1;
|
|
4589
|
+
this._printSemicolonBeforeNextNode = -1;
|
|
4590
|
+
}
|
|
4591
|
+
_append(str, maybeNewline) {
|
|
4592
|
+
this._maybeIndent();
|
|
4593
|
+
this._buf.append(str, maybeNewline);
|
|
4594
|
+
}
|
|
4595
|
+
_appendChar(char, noIndent) {
|
|
4596
|
+
if (!noIndent) this._maybeIndent();
|
|
4597
|
+
this._buf.appendChar(char);
|
|
4598
|
+
}
|
|
4599
|
+
_queue(char) {
|
|
4600
|
+
this._buf.queue(char);
|
|
4601
|
+
this.setLastChar(-1);
|
|
4602
|
+
}
|
|
4603
|
+
_maybeIndent() {
|
|
4604
|
+
const indent = this._shouldIndent();
|
|
4605
|
+
if (indent > 0) this._buf._appendChar(-1, indent, false);
|
|
4606
|
+
}
|
|
4607
|
+
_shouldIndent() {
|
|
4608
|
+
return this.endsWith(10) ? this._indent : 0;
|
|
4609
|
+
}
|
|
4610
|
+
catchUp(line) {
|
|
4611
|
+
if (!this.format.retainLines) return;
|
|
4612
|
+
const count = line - this._buf.getCurrentLine();
|
|
4613
|
+
for (let i = 0; i < count; i++) this._newline();
|
|
4614
|
+
}
|
|
4615
|
+
_catchUp(prop, loc) {
|
|
4616
|
+
const flags = this._flags;
|
|
4617
|
+
if ((flags & 1) === 0) {
|
|
4618
|
+
if (flags & 8 && loc?.[prop]) this.catchUp(loc[prop].line);
|
|
4619
|
+
return;
|
|
4620
|
+
}
|
|
4621
|
+
const pos = loc?.[prop];
|
|
4622
|
+
if (pos != null) this._catchUpTo(pos);
|
|
4623
|
+
}
|
|
4624
|
+
_catchUpTo({ line, column, index }) {
|
|
4625
|
+
const count = line - this._buf.getCurrentLine();
|
|
4626
|
+
if (count > 0 && this._noLineTerminator) return;
|
|
4627
|
+
for (let i = 0; i < count; i++) this._newline();
|
|
4628
|
+
const spacesCount = count > 0 ? column : column - this._buf.getCurrentColumn();
|
|
4629
|
+
if (spacesCount > 0) {
|
|
4630
|
+
const spaces = this._originalCode ? this._originalCode.slice(index - spacesCount, index).replace(/[^\t\v\f\uFEFF\p{Space_Separator}]/gu, " ") : " ".repeat(spacesCount);
|
|
4631
|
+
this._buf.append(spaces, false, true);
|
|
4632
|
+
this._buf.setSourcePosition(line, column);
|
|
4633
|
+
this.setLastChar(32);
|
|
4634
|
+
}
|
|
4635
|
+
}
|
|
4636
|
+
printTerminatorless(node) {
|
|
4637
|
+
this._noLineTerminator = true;
|
|
4638
|
+
this.print(node);
|
|
4639
|
+
}
|
|
4640
|
+
print(node, noLineTerminatorAfter = false, resetTokenContext = false, trailingCommentsLineOffset) {
|
|
4641
|
+
if (!node) return;
|
|
4642
|
+
this._innerCommentsState = 0;
|
|
4643
|
+
const { type, loc, extra } = node;
|
|
4644
|
+
const flags = this._flags;
|
|
4645
|
+
let changedFlags = false;
|
|
4646
|
+
if (node._compact) {
|
|
4647
|
+
this._flags |= 4;
|
|
4648
|
+
changedFlags = true;
|
|
4649
|
+
}
|
|
4650
|
+
const nodeInfo = generatorInfosMap.get(type);
|
|
4651
|
+
if (nodeInfo === void 0) throw new ReferenceError(`unknown node of type ${JSON.stringify(type)} with constructor ${JSON.stringify(node.constructor.name)}`);
|
|
4652
|
+
const [printMethod, nodeId, needsParens] = nodeInfo;
|
|
4653
|
+
const parent = this._currentNode;
|
|
4654
|
+
const parentId = this._currentTypeId;
|
|
4655
|
+
this._currentNode = node;
|
|
4656
|
+
this._currentTypeId = nodeId;
|
|
4657
|
+
if (flags & 1) this._printSemicolonBeforeNextToken = this._printSemicolonBeforeNextNode;
|
|
4658
|
+
let oldInAux;
|
|
4659
|
+
if (flags & 32) {
|
|
4660
|
+
oldInAux = this._insideAux;
|
|
4661
|
+
this._insideAux = loc == null;
|
|
4662
|
+
this._maybeAddAuxComment(this._insideAux && !oldInAux);
|
|
4663
|
+
}
|
|
4664
|
+
let oldTokenContext = 0;
|
|
4665
|
+
if (resetTokenContext) {
|
|
4666
|
+
oldTokenContext = this.tokenContext;
|
|
4667
|
+
if (oldTokenContext & 128) this.tokenContext = 0;
|
|
4668
|
+
else oldTokenContext = 0;
|
|
4669
|
+
}
|
|
4670
|
+
const parenthesized = extra != null && extra.parenthesized;
|
|
4671
|
+
let shouldPrintParens = parenthesized && flags & 1 || parenthesized && flags & 16 && nodeId === 72 || parent && (parentNeedsParens(node, parent, parentId) || needsParens != null && needsParens(node, parent, parentId, this.tokenContext, flags & 1 ? this._boundGetRawIdentifier : void 0));
|
|
4672
|
+
if (!shouldPrintParens && parenthesized && node.leadingComments?.length && node.leadingComments[0].type === "CommentBlock") switch (parentId) {
|
|
4673
|
+
case 66:
|
|
4674
|
+
case 241:
|
|
4675
|
+
case 6:
|
|
4676
|
+
case 141: break;
|
|
4677
|
+
case 18:
|
|
4678
|
+
case 131:
|
|
4679
|
+
case 113: if (parent.callee !== node) break;
|
|
4680
|
+
default: shouldPrintParens = true;
|
|
4681
|
+
}
|
|
4682
|
+
let indentParenthesized = false;
|
|
4683
|
+
if (!shouldPrintParens && this._noLineTerminator && (node.leadingComments?.some(commentIsNewline) || flags & 8 && loc && loc.start.line > this._buf.getCurrentLine())) {
|
|
4684
|
+
shouldPrintParens = true;
|
|
4685
|
+
indentParenthesized = true;
|
|
4686
|
+
}
|
|
4687
|
+
let oldNoLineTerminatorAfterNode;
|
|
4688
|
+
if (!shouldPrintParens) {
|
|
4689
|
+
noLineTerminatorAfter ||= !!parent && this._noLineTerminatorAfterNode === parent && isLastChild(parent, node);
|
|
4690
|
+
if (noLineTerminatorAfter) if (node.trailingComments?.some(commentIsNewline)) {
|
|
4691
|
+
if (isExpression(node)) shouldPrintParens = true;
|
|
4692
|
+
} else {
|
|
4693
|
+
oldNoLineTerminatorAfterNode = this._noLineTerminatorAfterNode;
|
|
4694
|
+
this._noLineTerminatorAfterNode = node;
|
|
4695
|
+
}
|
|
4696
|
+
}
|
|
4697
|
+
if (shouldPrintParens) {
|
|
4698
|
+
this.tokenChar(40);
|
|
4699
|
+
if (indentParenthesized) this.indent();
|
|
4700
|
+
this._innerCommentsState = 0;
|
|
4701
|
+
if (!resetTokenContext) oldTokenContext = this.tokenContext;
|
|
4702
|
+
if (oldTokenContext & 128) this.tokenContext = 0;
|
|
4703
|
+
oldNoLineTerminatorAfterNode = this._noLineTerminatorAfterNode;
|
|
4704
|
+
this._noLineTerminatorAfterNode = null;
|
|
4705
|
+
}
|
|
4706
|
+
this._printLeadingComments(node, parent);
|
|
4707
|
+
this.exactSource(nodeId === 137 || nodeId === 67 ? null : loc, printMethod.bind(this, node, parent));
|
|
4708
|
+
if (shouldPrintParens) {
|
|
4709
|
+
this._printTrailingComments(node, parent);
|
|
4710
|
+
if (indentParenthesized) {
|
|
4711
|
+
this.dedent();
|
|
4712
|
+
this.newline();
|
|
4713
|
+
}
|
|
4714
|
+
this.tokenChar(41);
|
|
4715
|
+
this._noLineTerminator = noLineTerminatorAfter;
|
|
4716
|
+
} else if (noLineTerminatorAfter && !this._noLineTerminator) {
|
|
4717
|
+
this._noLineTerminator = true;
|
|
4718
|
+
this._printTrailingComments(node, parent);
|
|
4719
|
+
} else this._printTrailingComments(node, parent, trailingCommentsLineOffset);
|
|
4720
|
+
if (oldTokenContext) this.tokenContext = oldTokenContext;
|
|
4721
|
+
this._currentNode = parent;
|
|
4722
|
+
this._currentTypeId = parentId;
|
|
4723
|
+
if (changedFlags) this._flags = flags;
|
|
4724
|
+
if (flags & 32) this._insideAux = oldInAux;
|
|
4725
|
+
if (oldNoLineTerminatorAfterNode != null) this._noLineTerminatorAfterNode = oldNoLineTerminatorAfterNode;
|
|
4726
|
+
this._innerCommentsState = 0;
|
|
4727
|
+
}
|
|
4728
|
+
_maybeAddAuxComment(enteredPositionlessNode) {
|
|
4729
|
+
if (enteredPositionlessNode) this._printAuxBeforeComment();
|
|
4730
|
+
if (!this._insideAux) this._printAuxAfterComment();
|
|
4731
|
+
}
|
|
4732
|
+
_printAuxBeforeComment() {
|
|
4733
|
+
if (this._printAuxAfterOnNextUserNode) return;
|
|
4734
|
+
this._printAuxAfterOnNextUserNode = true;
|
|
4735
|
+
const comment = this.format.auxiliaryCommentBefore;
|
|
4736
|
+
if (comment) this._printComment({
|
|
4737
|
+
type: "CommentBlock",
|
|
4738
|
+
value: comment
|
|
4739
|
+
}, 0);
|
|
4740
|
+
}
|
|
4741
|
+
_printAuxAfterComment() {
|
|
4742
|
+
if (!this._printAuxAfterOnNextUserNode) return;
|
|
4743
|
+
this._printAuxAfterOnNextUserNode = false;
|
|
4744
|
+
const comment = this.format.auxiliaryCommentAfter;
|
|
4745
|
+
if (comment) this._printComment({
|
|
4746
|
+
type: "CommentBlock",
|
|
4747
|
+
value: comment
|
|
4748
|
+
}, 0);
|
|
4749
|
+
}
|
|
4750
|
+
getPossibleRaw(node) {
|
|
4751
|
+
const extra = node.extra;
|
|
4752
|
+
if (extra?.raw != null && extra.rawValue != null && node.value === extra.rawValue) return extra.raw;
|
|
4753
|
+
}
|
|
4754
|
+
printJoin(nodes, statement, indent, separator, printTrailingSeparator, resetTokenContext, trailingCommentsLineOffset) {
|
|
4755
|
+
if (!nodes?.length) return;
|
|
4756
|
+
const flags = this._flags;
|
|
4757
|
+
if (indent == null && flags & 8) {
|
|
4758
|
+
const startLine = nodes[0].loc?.start.line;
|
|
4759
|
+
if (startLine != null && startLine !== this._buf.getCurrentLine()) indent = true;
|
|
4760
|
+
}
|
|
4761
|
+
if (indent) this.indent(flags);
|
|
4762
|
+
const len = nodes.length;
|
|
4763
|
+
for (let i = 0; i < len; i++) {
|
|
4764
|
+
const node = nodes[i];
|
|
4765
|
+
if (!node) continue;
|
|
4766
|
+
if (statement && i === 0 && this._buf.hasContent()) this.newline(1, flags);
|
|
4767
|
+
this.print(node, false, resetTokenContext, trailingCommentsLineOffset || 0);
|
|
4768
|
+
if (separator != null) {
|
|
4769
|
+
if (i < len - 1) separator.call(this, i, false);
|
|
4770
|
+
else if (printTrailingSeparator) separator.call(this, i, true);
|
|
4771
|
+
}
|
|
4772
|
+
if (statement) if (i + 1 === len) this.newline(1, flags);
|
|
4773
|
+
else {
|
|
4774
|
+
const lastCommentLine = this._lastCommentLine;
|
|
4775
|
+
if (lastCommentLine > 0) {
|
|
4776
|
+
const offset = (nodes[i + 1].loc?.start.line || 0) - lastCommentLine;
|
|
4777
|
+
if (offset >= 0) {
|
|
4778
|
+
this.newline(offset || 1, flags);
|
|
4779
|
+
continue;
|
|
4780
|
+
}
|
|
4781
|
+
}
|
|
4782
|
+
this.newline(1, flags);
|
|
4783
|
+
}
|
|
4784
|
+
}
|
|
4785
|
+
if (indent) this.dedent(flags);
|
|
4786
|
+
}
|
|
4787
|
+
printAndIndentOnComments(node) {
|
|
4788
|
+
const indent = node.leadingComments && node.leadingComments.length > 0;
|
|
4789
|
+
if (indent) this.indent();
|
|
4790
|
+
this.print(node);
|
|
4791
|
+
if (indent) this.dedent();
|
|
4792
|
+
}
|
|
4793
|
+
printBlock(body) {
|
|
4794
|
+
if (body.type !== "EmptyStatement") this.space();
|
|
4795
|
+
this.print(body);
|
|
4796
|
+
}
|
|
4797
|
+
_printTrailingComments(node, parent, lineOffset) {
|
|
4798
|
+
const { innerComments, trailingComments } = node;
|
|
4799
|
+
if (innerComments?.length) this._printComments(2, innerComments, node, parent, lineOffset);
|
|
4800
|
+
if (trailingComments?.length) this._printComments(2, trailingComments, node, parent, lineOffset);
|
|
4801
|
+
else this._lastCommentLine = 0;
|
|
4802
|
+
}
|
|
4803
|
+
_printLeadingComments(node, parent) {
|
|
4804
|
+
const comments = node.leadingComments;
|
|
4805
|
+
if (!comments?.length) return;
|
|
4806
|
+
this._printComments(0, comments, node, parent);
|
|
4807
|
+
}
|
|
4808
|
+
_maybePrintInnerComments(nextTokenStr, nextTokenOccurrenceCount) {
|
|
4809
|
+
const state = this._innerCommentsState;
|
|
4810
|
+
switch (state & 3) {
|
|
4811
|
+
case 0:
|
|
4812
|
+
this._innerCommentsState = 5;
|
|
4813
|
+
return;
|
|
4814
|
+
case 1: this.printInnerComments((state & 4) > 0, this.tokenMap?.findMatching(this._currentNode, nextTokenStr, nextTokenOccurrenceCount));
|
|
4815
|
+
}
|
|
4816
|
+
}
|
|
4817
|
+
printInnerComments(indent = true, nextToken) {
|
|
4818
|
+
const node = this._currentNode;
|
|
4819
|
+
const comments = node.innerComments;
|
|
4820
|
+
if (!comments?.length) {
|
|
4821
|
+
this._innerCommentsState = 2;
|
|
4822
|
+
return;
|
|
4823
|
+
}
|
|
4824
|
+
const hasSpace = this.endsWith(32);
|
|
4825
|
+
if (indent) this.indent();
|
|
4826
|
+
switch (this._printComments(1, comments, node, void 0, void 0, nextToken)) {
|
|
4827
|
+
case 2: this._innerCommentsState = 2;
|
|
4828
|
+
case 1: if (hasSpace) this.space();
|
|
4829
|
+
}
|
|
4830
|
+
if (indent) this.dedent();
|
|
4831
|
+
}
|
|
4832
|
+
noIndentInnerCommentsHere() {
|
|
4833
|
+
this._innerCommentsState &= -5;
|
|
4834
|
+
}
|
|
4835
|
+
printSequence(nodes, indent, resetTokenContext, trailingCommentsLineOffset) {
|
|
4836
|
+
this.printJoin(nodes, true, indent ?? false, void 0, void 0, resetTokenContext, trailingCommentsLineOffset);
|
|
4837
|
+
}
|
|
4838
|
+
printList(items, printTrailingSeparator, statement, indent, separator, resetTokenContext) {
|
|
4839
|
+
this.printJoin(items, statement, indent, separator ?? commaSeparator, printTrailingSeparator, resetTokenContext);
|
|
4840
|
+
}
|
|
4841
|
+
shouldPrintTrailingComma(listEnd) {
|
|
4842
|
+
if (!this.tokenMap) return null;
|
|
4843
|
+
const listEndIndex = this.tokenMap.findLastIndex(this._currentNode, (token) => this.tokenMap.matchesOriginal(token, typeof listEnd === "number" ? String.fromCharCode(listEnd) : listEnd));
|
|
4844
|
+
if (listEndIndex <= 0) return null;
|
|
4845
|
+
return this.tokenMap.matchesOriginal(this._tokens[listEndIndex - 1], ",");
|
|
4846
|
+
}
|
|
4847
|
+
_shouldPrintComment(comment, nextToken) {
|
|
4848
|
+
if (comment.ignore) return 0;
|
|
4849
|
+
if (this._printedComments.has(comment)) return 0;
|
|
4850
|
+
if (this._noLineTerminator && HAS_NEWLINE_OR_BlOCK_COMMENT_END.test(comment.value)) return 2;
|
|
4851
|
+
if (nextToken && this.tokenMap) {
|
|
4852
|
+
const commentTok = this.tokenMap.find(this._currentNode, (token) => token.value === comment.value);
|
|
4853
|
+
if (commentTok && commentTok.start > nextToken.start) return 2;
|
|
4854
|
+
}
|
|
4855
|
+
this._printedComments.add(comment);
|
|
4856
|
+
if (!this.format.shouldPrintComment(comment.value)) return 0;
|
|
4857
|
+
return 1;
|
|
4858
|
+
}
|
|
4859
|
+
_printComment(comment, skipNewLines) {
|
|
4860
|
+
const noLineTerminator = this._noLineTerminator;
|
|
4861
|
+
const isBlockComment = comment.type === "CommentBlock";
|
|
4862
|
+
const printNewLines = isBlockComment && skipNewLines !== 1 && !noLineTerminator;
|
|
4863
|
+
if (printNewLines && this._buf.hasContent() && skipNewLines !== 2) this.newline(1);
|
|
4864
|
+
switch (this.getLastChar(true)) {
|
|
4865
|
+
case 47: this._space();
|
|
4866
|
+
case 91:
|
|
4867
|
+
case 123:
|
|
4868
|
+
case 40: break;
|
|
4869
|
+
default: this.space();
|
|
4870
|
+
}
|
|
4871
|
+
let val;
|
|
4872
|
+
if (isBlockComment) {
|
|
4873
|
+
val = `/*${comment.value}*/`;
|
|
4874
|
+
if (this.format.indent.adjustMultilineComment) {
|
|
4875
|
+
const offset = comment.loc?.start.column;
|
|
4876
|
+
if (offset) {
|
|
4877
|
+
const newlineRegex = new RegExp("\\n\\s{1," + offset + "}", "g");
|
|
4878
|
+
val = val.replace(newlineRegex, "\n");
|
|
4879
|
+
}
|
|
4880
|
+
if (this._flags & 4) val = val.replace(/\n(?!$)/g, `\n`);
|
|
4881
|
+
else {
|
|
4882
|
+
let indentSize = this.format.retainLines ? 0 : this._buf.getCurrentColumn();
|
|
4883
|
+
if (this._shouldIndent() || this.format.retainLines) indentSize += this._indent;
|
|
4884
|
+
val = val.replace(/\n(?!$)/g, `\n${" ".repeat(indentSize)}`);
|
|
4885
|
+
}
|
|
4886
|
+
}
|
|
4887
|
+
} else if (!noLineTerminator) val = `//${comment.value}`;
|
|
4888
|
+
else val = `/*${comment.value}*/`;
|
|
4889
|
+
this.source("start", comment.loc);
|
|
4890
|
+
this._append(val, isBlockComment);
|
|
4891
|
+
if (!isBlockComment && !noLineTerminator) this._newline();
|
|
4892
|
+
if (printNewLines && skipNewLines !== 3) this.newline(1);
|
|
4893
|
+
}
|
|
4894
|
+
_printComments(type, comments, node, parent, lineOffset = 0, nextToken) {
|
|
4895
|
+
const nodeLoc = node.loc;
|
|
4896
|
+
const len = comments.length;
|
|
4897
|
+
let hasLoc = !!nodeLoc;
|
|
4898
|
+
const nodeStartLine = hasLoc ? nodeLoc.start.line : 0;
|
|
4899
|
+
const nodeEndLine = hasLoc ? nodeLoc.end.line : 0;
|
|
4900
|
+
let lastLine = 0;
|
|
4901
|
+
let leadingCommentNewline = 0;
|
|
4902
|
+
const { _noLineTerminator, _flags } = this;
|
|
4903
|
+
for (let i = 0; i < len; i++) {
|
|
4904
|
+
const comment = comments[i];
|
|
4905
|
+
const shouldPrint = this._shouldPrintComment(comment, nextToken);
|
|
4906
|
+
if (shouldPrint === 2) return i === 0 ? 0 : 1;
|
|
4907
|
+
if (hasLoc && comment.loc && shouldPrint === 1) {
|
|
4908
|
+
const commentStartLine = comment.loc.start.line;
|
|
4909
|
+
const commentEndLine = comment.loc.end.line;
|
|
4910
|
+
if (type === 0) {
|
|
4911
|
+
let offset = 0;
|
|
4912
|
+
if (i === 0) {
|
|
4913
|
+
if (this._buf.hasContent() && (comment.type === "CommentLine" || commentStartLine !== commentEndLine)) offset = leadingCommentNewline = 1;
|
|
4914
|
+
} else offset = commentStartLine - lastLine;
|
|
4915
|
+
lastLine = commentEndLine;
|
|
4916
|
+
if (offset > 0 && !_noLineTerminator) this.newline(offset, _flags);
|
|
4917
|
+
this._printComment(comment, 1);
|
|
4918
|
+
if (i + 1 === len) {
|
|
4919
|
+
const count = Math.max(nodeStartLine - lastLine, leadingCommentNewline);
|
|
4920
|
+
if (count > 0 && !_noLineTerminator) this.newline(count, _flags);
|
|
4921
|
+
lastLine = nodeStartLine;
|
|
4922
|
+
}
|
|
4923
|
+
} else if (type === 1) {
|
|
4924
|
+
const offset = commentStartLine - (i === 0 ? nodeStartLine : lastLine);
|
|
4925
|
+
lastLine = commentEndLine;
|
|
4926
|
+
if (offset > 0 && !_noLineTerminator) this.newline(offset, _flags);
|
|
4927
|
+
this._printComment(comment, 1);
|
|
4928
|
+
if (i + 1 === len) {
|
|
4929
|
+
const count = Math.min(1, nodeEndLine - lastLine);
|
|
4930
|
+
if (count > 0 && !_noLineTerminator) this.newline(count, _flags);
|
|
4931
|
+
lastLine = nodeEndLine;
|
|
4932
|
+
}
|
|
4933
|
+
} else {
|
|
4934
|
+
const offset = commentStartLine - (i === 0 ? nodeEndLine - lineOffset : lastLine);
|
|
4935
|
+
lastLine = commentEndLine;
|
|
4936
|
+
if (offset > 0 && !_noLineTerminator) this.newline(offset, _flags);
|
|
4937
|
+
this._printComment(comment, 1);
|
|
4938
|
+
}
|
|
4939
|
+
} else {
|
|
4940
|
+
hasLoc = false;
|
|
4941
|
+
if (shouldPrint !== 1) continue;
|
|
4942
|
+
if (len === 1) {
|
|
4943
|
+
const singleLine = comment.loc ? comment.loc.start.line === comment.loc.end.line : !HAS_NEWLINE.test(comment.value);
|
|
4944
|
+
const shouldSkipNewline = singleLine && !isStatement(node) && !isClassBody(parent) && !isTSInterfaceBody(parent) && !isTSEnumMember(node);
|
|
4945
|
+
if (type === 0) this._printComment(comment, shouldSkipNewline && node.type !== "ObjectExpression" || singleLine && isFunction(parent) && parent.body === node ? 1 : 0);
|
|
4946
|
+
else if (shouldSkipNewline && type === 2) this._printComment(comment, 1);
|
|
4947
|
+
else this._printComment(comment, 0);
|
|
4948
|
+
} else if (type === 1 && !(node.type === "ObjectExpression" && node.properties.length > 1) && node.type !== "ClassBody" && node.type !== "TSInterfaceBody") this._printComment(comment, i === 0 ? 2 : i === len - 1 ? 3 : 0);
|
|
4949
|
+
else this._printComment(comment, 0);
|
|
4950
|
+
}
|
|
4951
|
+
}
|
|
4952
|
+
if (type === 2 && hasLoc && lastLine) this._lastCommentLine = lastLine;
|
|
4953
|
+
return 2;
|
|
4954
|
+
}
|
|
4955
|
+
};
|
|
4956
|
+
function commaSeparator(occurrenceCount, last) {
|
|
4957
|
+
this.tokenChar(44, occurrenceCount);
|
|
4958
|
+
if (!last) this.space();
|
|
4959
|
+
}
|
|
4960
|
+
function normalizeOptions(code, opts, ast) {
|
|
4961
|
+
if (opts.experimental_preserveFormat) {
|
|
4962
|
+
if (typeof code !== "string") throw new Error("`experimental_preserveFormat` requires the original `code` to be passed to @babel/generator as a string");
|
|
4963
|
+
if (!opts.retainLines) throw new Error("`experimental_preserveFormat` requires `retainLines` to be set to `true`");
|
|
4964
|
+
if (opts.compact && opts.compact !== "auto") throw new Error("`experimental_preserveFormat` is not compatible with the `compact` option");
|
|
4965
|
+
if (opts.minified) throw new Error("`experimental_preserveFormat` is not compatible with the `minified` option");
|
|
4966
|
+
if (opts.jsescOption) throw new Error("`experimental_preserveFormat` is not compatible with the `jsescOption` option");
|
|
4967
|
+
if (!Array.isArray(ast.tokens)) throw new Error("`experimental_preserveFormat` requires the AST to have attached the token of the input code. Make sure to enable the `tokens: true` parser option.");
|
|
4968
|
+
}
|
|
4969
|
+
const format = {
|
|
4970
|
+
auxiliaryCommentBefore: opts.auxiliaryCommentBefore,
|
|
4971
|
+
auxiliaryCommentAfter: opts.auxiliaryCommentAfter,
|
|
4972
|
+
shouldPrintComment: opts.shouldPrintComment,
|
|
4973
|
+
preserveFormat: opts.experimental_preserveFormat,
|
|
4974
|
+
retainLines: opts.retainLines,
|
|
4975
|
+
retainFunctionParens: opts.retainFunctionParens,
|
|
4976
|
+
comments: opts.comments == null || opts.comments,
|
|
4977
|
+
compact: opts.compact,
|
|
4978
|
+
minified: opts.minified,
|
|
4979
|
+
concise: opts.concise,
|
|
4980
|
+
indent: {
|
|
4981
|
+
adjustMultilineComment: true,
|
|
4982
|
+
style: " "
|
|
4983
|
+
},
|
|
4984
|
+
jsescOption: {
|
|
4985
|
+
quotes: "double",
|
|
4986
|
+
wrap: true,
|
|
4987
|
+
minimal: true,
|
|
4988
|
+
...opts.jsescOption
|
|
4989
|
+
},
|
|
4990
|
+
topicToken: opts.topicToken
|
|
4991
|
+
};
|
|
4992
|
+
if (format.minified) {
|
|
4993
|
+
format.compact = true;
|
|
4994
|
+
format.shouldPrintComment = format.shouldPrintComment || (() => format.comments);
|
|
4995
|
+
} else format.shouldPrintComment = format.shouldPrintComment || ((value) => format.comments || value.includes("@license") || value.includes("@preserve"));
|
|
4996
|
+
if (format.compact === "auto") {
|
|
4997
|
+
format.compact = typeof code === "string" && code.length > 5e5;
|
|
4998
|
+
if (format.compact) console.error(`[BABEL] Note: The code generator has deoptimised the styling of ${opts.filename} as it exceeds the max of 500KB.`);
|
|
4999
|
+
}
|
|
5000
|
+
if (format.compact || format.preserveFormat) format.indent.adjustMultilineComment = false;
|
|
5001
|
+
const { auxiliaryCommentBefore, auxiliaryCommentAfter, shouldPrintComment } = format;
|
|
5002
|
+
if (auxiliaryCommentBefore && !shouldPrintComment(auxiliaryCommentBefore)) format.auxiliaryCommentBefore = void 0;
|
|
5003
|
+
if (auxiliaryCommentAfter && !shouldPrintComment(auxiliaryCommentAfter)) format.auxiliaryCommentAfter = void 0;
|
|
5004
|
+
return format;
|
|
5005
|
+
}
|
|
5006
|
+
function generate(ast, opts = {}, code) {
|
|
5007
|
+
return new Printer(normalizeOptions(code, opts, ast), opts.sourceMaps ? new SourceMap(opts, code) : null, ast.tokens, typeof code === "string" ? code : null).generate(ast);
|
|
5008
|
+
}
|
|
5009
|
+
//#endregion
|
|
5010
|
+
//#region src/index.ts
|
|
5011
|
+
var PREREQUISITE = id(makeIdFiltersToMatchWithQuery(/\.[mc]?[tj]sx?$/));
|
|
5012
|
+
var VISITOR = { CallExpression(path, ctx) {
|
|
5013
|
+
for (const macro of ctx.macro) {
|
|
5014
|
+
if (!macro.transform.call(ctx, path, ctx, types)) continue;
|
|
5015
|
+
ctx.changed++;
|
|
5016
|
+
break;
|
|
5017
|
+
}
|
|
5018
|
+
} };
|
|
5019
|
+
function macroPlugin(opts) {
|
|
5020
|
+
const { filter, macro } = opts;
|
|
5021
|
+
const inner = filter ? and(PREREQUISITE, filter) : PREREQUISITE;
|
|
5022
|
+
return {
|
|
5023
|
+
name: "vite-plugin-simple-macro",
|
|
5024
|
+
transform: {
|
|
5025
|
+
order: "pre",
|
|
5026
|
+
filter: [include(addSpecificFilter(macro, inner))],
|
|
5027
|
+
async handler(code, id, info) {
|
|
5028
|
+
if (!exprInterpreter(inner, code, id, info.moduleType)) return;
|
|
5029
|
+
const filtered = macro.filter(({ filter }) => !filter || exprInterpreter(filter, code, id, info.moduleType));
|
|
5030
|
+
if (!filtered.length) return;
|
|
5031
|
+
const ast = await parseAsync(code, {
|
|
5032
|
+
filename: id,
|
|
5033
|
+
plugins: [["@babel/plugin-syntax-typescript", { isTSX: true }]]
|
|
5034
|
+
});
|
|
5035
|
+
const ctx = {
|
|
5036
|
+
id,
|
|
5037
|
+
macro: filtered,
|
|
5038
|
+
changed: 0,
|
|
5039
|
+
...info
|
|
5040
|
+
};
|
|
5041
|
+
traverse(ast, VISITOR, void 0, ctx);
|
|
5042
|
+
if (!ctx.changed) return;
|
|
5043
|
+
const out = generate(ast, {
|
|
5044
|
+
sourceMaps: true,
|
|
5045
|
+
sourceFileName: id
|
|
5046
|
+
});
|
|
5047
|
+
return {
|
|
5048
|
+
code: out.code,
|
|
5049
|
+
map: out.map
|
|
5050
|
+
};
|
|
5051
|
+
}
|
|
5052
|
+
}
|
|
5053
|
+
};
|
|
5054
|
+
}
|
|
5055
|
+
function addSpecificFilter(macro, inner) {
|
|
5056
|
+
const out = [];
|
|
5057
|
+
for (const { filter } of macro) if (filter) out.push(filter);
|
|
5058
|
+
else return inner;
|
|
5059
|
+
return and(inner, or(...out));
|
|
5060
|
+
}
|
|
5061
|
+
//#endregion
|
|
5062
|
+
export { macroPlugin as default };
|