@stainless-api/playgrounds 0.0.1-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +15 -0
- package/README.md +23 -0
- package/eslint.config.js +2 -0
- package/package.json +69 -0
- package/src/Logs.tsx +216 -0
- package/src/Panel.tsx +21 -0
- package/src/PlaygroundPanelWrapper.tsx +5 -0
- package/src/build-py-types.ts +152 -0
- package/src/build-ts-types.ts +70 -0
- package/src/build.ts +97 -0
- package/src/codemirror/comlink.ts +698 -0
- package/src/codemirror/curl/curlconverter.vendor.js +7959 -0
- package/src/codemirror/curl.ts +108 -0
- package/src/codemirror/deps.ts +12 -0
- package/src/codemirror/fix-lsp-markdown.ts +50 -0
- package/src/codemirror/lsp.ts +87 -0
- package/src/codemirror/python/anser.ts +398 -0
- package/src/codemirror/python/pyodide.ts +180 -0
- package/src/codemirror/python.ts +160 -0
- package/src/codemirror/react.tsx +615 -0
- package/src/codemirror/sanitize-html.ts +12 -0
- package/src/codemirror/shiki.ts +65 -0
- package/src/codemirror/typescript/cdn-typescript.d.ts +1 -0
- package/src/codemirror/typescript/cdn-typescript.js +1 -0
- package/src/codemirror/typescript/console.ts +590 -0
- package/src/codemirror/typescript/get-signature.ts +94 -0
- package/src/codemirror/typescript/prettier-plugin-external-typescript.vendor.js +4968 -0
- package/src/codemirror/typescript/runner.ts +396 -0
- package/src/codemirror/typescript/special-info.ts +171 -0
- package/src/codemirror/typescript/worker.ts +292 -0
- package/src/codemirror/typescript.tsx +198 -0
- package/src/create.tsx +44 -0
- package/src/icon.tsx +21 -0
- package/src/index.ts +6 -0
- package/src/logs-context.ts +5 -0
- package/src/playground.css +359 -0
- package/src/sandbox-worker/in-frame.js +179 -0
- package/src/sandbox-worker/index.ts +202 -0
- package/src/use-storage.ts +54 -0
- package/src/util.ts +29 -0
- package/src/virtual-module.d.ts +45 -0
- package/src/vite-env.d.ts +1 -0
- package/test/get-signature.test.ts +73 -0
- package/test/use-storage.test.ts +60 -0
- package/tsconfig.json +11 -0
|
@@ -0,0 +1,4968 @@
|
|
|
1
|
+
/* eslint-disable */
|
|
2
|
+
/* @ts-nocheck */
|
|
3
|
+
import ts from './cdn-typescript';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* `prettier/plugins/typescript` uses a bundled version of typescript.
|
|
7
|
+
* this is a build patched to externalize it so our bundles are smaller.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
// scripts/build/shims/debug.js
|
|
11
|
+
var debug = () => () => {};
|
|
12
|
+
var debug_default = debug;
|
|
13
|
+
|
|
14
|
+
// scripts/build/shims/shared.js
|
|
15
|
+
var OPTIONAL_OBJECT = 1;
|
|
16
|
+
var createMethodShim =
|
|
17
|
+
(methodName, getImplementation) =>
|
|
18
|
+
(flags, object, ...arguments_) => {
|
|
19
|
+
if (flags | OPTIONAL_OBJECT && (object === void 0 || object === null)) {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
const implementation = getImplementation.call(object) ?? object[methodName];
|
|
23
|
+
return implementation.apply(object, arguments_);
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
// scripts/build/shims/method-replace-all.js
|
|
27
|
+
var stringReplaceAll =
|
|
28
|
+
String.prototype.replaceAll ??
|
|
29
|
+
function (pattern, replacement) {
|
|
30
|
+
if (pattern.global) {
|
|
31
|
+
return this.replace(pattern, replacement);
|
|
32
|
+
}
|
|
33
|
+
return this.split(pattern).join(replacement);
|
|
34
|
+
};
|
|
35
|
+
var replaceAll = createMethodShim('replaceAll', function () {
|
|
36
|
+
if (typeof this === 'string') {
|
|
37
|
+
return stringReplaceAll;
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
var method_replace_all_default = replaceAll;
|
|
41
|
+
|
|
42
|
+
// node_modules/@typescript-eslint/typescript-estree/dist/convert.js
|
|
43
|
+
|
|
44
|
+
// node_modules/@typescript-eslint/typescript-estree/dist/check-modifiers.js
|
|
45
|
+
|
|
46
|
+
// node_modules/@typescript-eslint/typescript-estree/dist/getModifiers.js
|
|
47
|
+
|
|
48
|
+
// node_modules/@typescript-eslint/typescript-estree/dist/version-check.js
|
|
49
|
+
var typescriptVersionIsAtLeast = new Proxy({}, { get: () => true });
|
|
50
|
+
|
|
51
|
+
// node_modules/@typescript-eslint/typescript-estree/dist/getModifiers.js
|
|
52
|
+
var isAtLeast48 = typescriptVersionIsAtLeast['4.8'];
|
|
53
|
+
function getModifiers2(node, includeIllegalModifiers = false) {
|
|
54
|
+
if (node == null) {
|
|
55
|
+
return void 0;
|
|
56
|
+
}
|
|
57
|
+
if (isAtLeast48) {
|
|
58
|
+
if (includeIllegalModifiers || ts.canHaveModifiers(node)) {
|
|
59
|
+
const modifiers = ts.getModifiers(node);
|
|
60
|
+
return modifiers ? [...modifiers] : void 0;
|
|
61
|
+
}
|
|
62
|
+
return void 0;
|
|
63
|
+
}
|
|
64
|
+
return (
|
|
65
|
+
// @ts-expect-error intentional fallback for older TS versions
|
|
66
|
+
node.modifiers?.filter((m) => !ts.isDecorator(m))
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
function getDecorators2(node, includeIllegalDecorators = false) {
|
|
70
|
+
if (node == null) {
|
|
71
|
+
return void 0;
|
|
72
|
+
}
|
|
73
|
+
if (isAtLeast48) {
|
|
74
|
+
if (includeIllegalDecorators || ts.canHaveDecorators(node)) {
|
|
75
|
+
const decorators = ts.getDecorators(node);
|
|
76
|
+
return decorators ? [...decorators] : void 0;
|
|
77
|
+
}
|
|
78
|
+
return void 0;
|
|
79
|
+
}
|
|
80
|
+
return (
|
|
81
|
+
// @ts-expect-error intentional fallback for older TS versions
|
|
82
|
+
node.decorators?.filter(ts.isDecorator)
|
|
83
|
+
);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// node_modules/@typescript-eslint/typescript-estree/dist/node-utils.js
|
|
87
|
+
|
|
88
|
+
// node_modules/@typescript-eslint/typescript-estree/dist/jsx/xhtml-entities.js
|
|
89
|
+
var xhtmlEntities = {};
|
|
90
|
+
|
|
91
|
+
// node_modules/@typescript-eslint/types/dist/generated/ast-spec.js
|
|
92
|
+
var TYPE_STORE = new Proxy({}, { get: (_, type) => type });
|
|
93
|
+
|
|
94
|
+
// node_modules/@typescript-eslint/types/dist/index.js
|
|
95
|
+
var AST_NODE_TYPES = TYPE_STORE;
|
|
96
|
+
var AST_TOKEN_TYPES = TYPE_STORE;
|
|
97
|
+
|
|
98
|
+
// node_modules/@typescript-eslint/typescript-estree/dist/ts-estree/index.js
|
|
99
|
+
var AST_NODE_TYPES2 = AST_NODE_TYPES;
|
|
100
|
+
var AST_TOKEN_TYPES2 = AST_TOKEN_TYPES;
|
|
101
|
+
|
|
102
|
+
// node_modules/@typescript-eslint/typescript-estree/dist/node-utils.js
|
|
103
|
+
var isAtLeast50 = typescriptVersionIsAtLeast['5.0'];
|
|
104
|
+
var SyntaxKind2 = ts.SyntaxKind;
|
|
105
|
+
var LOGICAL_OPERATORS = /* @__PURE__ */ new Set([
|
|
106
|
+
SyntaxKind2.AmpersandAmpersandToken,
|
|
107
|
+
SyntaxKind2.BarBarToken,
|
|
108
|
+
SyntaxKind2.QuestionQuestionToken,
|
|
109
|
+
]);
|
|
110
|
+
var ASSIGNMENT_OPERATORS = /* @__PURE__ */ new Set([
|
|
111
|
+
ts.SyntaxKind.AmpersandAmpersandEqualsToken,
|
|
112
|
+
ts.SyntaxKind.AmpersandEqualsToken,
|
|
113
|
+
ts.SyntaxKind.AsteriskAsteriskEqualsToken,
|
|
114
|
+
ts.SyntaxKind.AsteriskEqualsToken,
|
|
115
|
+
ts.SyntaxKind.BarBarEqualsToken,
|
|
116
|
+
ts.SyntaxKind.BarEqualsToken,
|
|
117
|
+
ts.SyntaxKind.CaretEqualsToken,
|
|
118
|
+
ts.SyntaxKind.EqualsToken,
|
|
119
|
+
ts.SyntaxKind.GreaterThanGreaterThanEqualsToken,
|
|
120
|
+
ts.SyntaxKind.GreaterThanGreaterThanGreaterThanEqualsToken,
|
|
121
|
+
ts.SyntaxKind.LessThanLessThanEqualsToken,
|
|
122
|
+
ts.SyntaxKind.MinusEqualsToken,
|
|
123
|
+
ts.SyntaxKind.PercentEqualsToken,
|
|
124
|
+
ts.SyntaxKind.PlusEqualsToken,
|
|
125
|
+
ts.SyntaxKind.QuestionQuestionEqualsToken,
|
|
126
|
+
ts.SyntaxKind.SlashEqualsToken,
|
|
127
|
+
]);
|
|
128
|
+
var BINARY_OPERATORS = /* @__PURE__ */ new Set([
|
|
129
|
+
SyntaxKind2.AmpersandAmpersandToken,
|
|
130
|
+
SyntaxKind2.AmpersandToken,
|
|
131
|
+
SyntaxKind2.AsteriskAsteriskToken,
|
|
132
|
+
SyntaxKind2.AsteriskToken,
|
|
133
|
+
SyntaxKind2.BarBarToken,
|
|
134
|
+
SyntaxKind2.BarToken,
|
|
135
|
+
SyntaxKind2.CaretToken,
|
|
136
|
+
SyntaxKind2.EqualsEqualsEqualsToken,
|
|
137
|
+
SyntaxKind2.EqualsEqualsToken,
|
|
138
|
+
SyntaxKind2.ExclamationEqualsEqualsToken,
|
|
139
|
+
SyntaxKind2.ExclamationEqualsToken,
|
|
140
|
+
SyntaxKind2.GreaterThanEqualsToken,
|
|
141
|
+
SyntaxKind2.GreaterThanGreaterThanGreaterThanToken,
|
|
142
|
+
SyntaxKind2.GreaterThanGreaterThanToken,
|
|
143
|
+
SyntaxKind2.GreaterThanToken,
|
|
144
|
+
SyntaxKind2.InKeyword,
|
|
145
|
+
SyntaxKind2.InstanceOfKeyword,
|
|
146
|
+
SyntaxKind2.LessThanEqualsToken,
|
|
147
|
+
SyntaxKind2.LessThanLessThanToken,
|
|
148
|
+
SyntaxKind2.LessThanToken,
|
|
149
|
+
SyntaxKind2.MinusToken,
|
|
150
|
+
SyntaxKind2.PercentToken,
|
|
151
|
+
SyntaxKind2.PlusToken,
|
|
152
|
+
SyntaxKind2.SlashToken,
|
|
153
|
+
]);
|
|
154
|
+
function isAssignmentOperator(operator) {
|
|
155
|
+
return ASSIGNMENT_OPERATORS.has(operator.kind);
|
|
156
|
+
}
|
|
157
|
+
function isLogicalOperator(operator) {
|
|
158
|
+
return LOGICAL_OPERATORS.has(operator.kind);
|
|
159
|
+
}
|
|
160
|
+
function isESTreeBinaryOperator(operator) {
|
|
161
|
+
return BINARY_OPERATORS.has(operator.kind);
|
|
162
|
+
}
|
|
163
|
+
function getTextForTokenKind(kind) {
|
|
164
|
+
return ts.tokenToString(kind);
|
|
165
|
+
}
|
|
166
|
+
function isESTreeClassMember(node) {
|
|
167
|
+
return node.kind !== SyntaxKind2.SemicolonClassElement;
|
|
168
|
+
}
|
|
169
|
+
function hasModifier(modifierKind, node) {
|
|
170
|
+
const modifiers = (0, getModifiers2)(node);
|
|
171
|
+
return modifiers?.some((modifier) => modifier.kind === modifierKind) === true;
|
|
172
|
+
}
|
|
173
|
+
function getLastModifier(node) {
|
|
174
|
+
const modifiers = (0, getModifiers2)(node);
|
|
175
|
+
if (modifiers == null) {
|
|
176
|
+
return null;
|
|
177
|
+
}
|
|
178
|
+
return modifiers[modifiers.length - 1] ?? null;
|
|
179
|
+
}
|
|
180
|
+
function isComma(token) {
|
|
181
|
+
return token.kind === SyntaxKind2.CommaToken;
|
|
182
|
+
}
|
|
183
|
+
function isComment(node) {
|
|
184
|
+
return (
|
|
185
|
+
node.kind === SyntaxKind2.SingleLineCommentTrivia || node.kind === SyntaxKind2.MultiLineCommentTrivia
|
|
186
|
+
);
|
|
187
|
+
}
|
|
188
|
+
function isJSDocComment(node) {
|
|
189
|
+
return node.kind === SyntaxKind2.JSDocComment;
|
|
190
|
+
}
|
|
191
|
+
function getBinaryExpressionType(operator) {
|
|
192
|
+
if (isAssignmentOperator(operator)) {
|
|
193
|
+
return {
|
|
194
|
+
type: AST_NODE_TYPES2.AssignmentExpression,
|
|
195
|
+
operator: getTextForTokenKind(operator.kind),
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
if (isLogicalOperator(operator)) {
|
|
199
|
+
return {
|
|
200
|
+
type: AST_NODE_TYPES2.LogicalExpression,
|
|
201
|
+
operator: getTextForTokenKind(operator.kind),
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
if (isESTreeBinaryOperator(operator)) {
|
|
205
|
+
return {
|
|
206
|
+
type: AST_NODE_TYPES2.BinaryExpression,
|
|
207
|
+
operator: getTextForTokenKind(operator.kind),
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
throw new Error(`Unexpected binary operator ${ts.tokenToString(operator.kind)}`);
|
|
211
|
+
}
|
|
212
|
+
function getLineAndCharacterFor(pos, ast) {
|
|
213
|
+
const loc = ast.getLineAndCharacterOfPosition(pos);
|
|
214
|
+
return {
|
|
215
|
+
column: loc.character,
|
|
216
|
+
line: loc.line + 1,
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
function getLocFor(range, ast) {
|
|
220
|
+
const [start, end] = range.map((pos) => getLineAndCharacterFor(pos, ast));
|
|
221
|
+
return {
|
|
222
|
+
end,
|
|
223
|
+
start,
|
|
224
|
+
};
|
|
225
|
+
}
|
|
226
|
+
function canContainDirective(node) {
|
|
227
|
+
if (node.kind === ts.SyntaxKind.Block) {
|
|
228
|
+
switch (node.parent.kind) {
|
|
229
|
+
case ts.SyntaxKind.Constructor:
|
|
230
|
+
case ts.SyntaxKind.GetAccessor:
|
|
231
|
+
case ts.SyntaxKind.SetAccessor:
|
|
232
|
+
case ts.SyntaxKind.ArrowFunction:
|
|
233
|
+
case ts.SyntaxKind.FunctionExpression:
|
|
234
|
+
case ts.SyntaxKind.FunctionDeclaration:
|
|
235
|
+
case ts.SyntaxKind.MethodDeclaration:
|
|
236
|
+
return true;
|
|
237
|
+
default:
|
|
238
|
+
return false;
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
return true;
|
|
242
|
+
}
|
|
243
|
+
function getRange(node, ast) {
|
|
244
|
+
return [node.getStart(ast), node.getEnd()];
|
|
245
|
+
}
|
|
246
|
+
function isToken2(node) {
|
|
247
|
+
return node.kind >= SyntaxKind2.FirstToken && node.kind <= SyntaxKind2.LastToken;
|
|
248
|
+
}
|
|
249
|
+
function isJSXToken(node) {
|
|
250
|
+
return node.kind >= SyntaxKind2.JsxElement && node.kind <= SyntaxKind2.JsxAttribute;
|
|
251
|
+
}
|
|
252
|
+
function getDeclarationKind(node) {
|
|
253
|
+
if (node.flags & ts.NodeFlags.Let) {
|
|
254
|
+
return 'let';
|
|
255
|
+
}
|
|
256
|
+
if ((node.flags & ts.NodeFlags.AwaitUsing) === ts.NodeFlags.AwaitUsing) {
|
|
257
|
+
return 'await using';
|
|
258
|
+
}
|
|
259
|
+
if (node.flags & ts.NodeFlags.Const) {
|
|
260
|
+
return 'const';
|
|
261
|
+
}
|
|
262
|
+
if (node.flags & ts.NodeFlags.Using) {
|
|
263
|
+
return 'using';
|
|
264
|
+
}
|
|
265
|
+
return 'var';
|
|
266
|
+
}
|
|
267
|
+
function getTSNodeAccessibility(node) {
|
|
268
|
+
const modifiers = (0, getModifiers2)(node);
|
|
269
|
+
if (modifiers == null) {
|
|
270
|
+
return void 0;
|
|
271
|
+
}
|
|
272
|
+
for (const modifier of modifiers) {
|
|
273
|
+
switch (modifier.kind) {
|
|
274
|
+
case SyntaxKind2.PublicKeyword:
|
|
275
|
+
return 'public';
|
|
276
|
+
case SyntaxKind2.ProtectedKeyword:
|
|
277
|
+
return 'protected';
|
|
278
|
+
case SyntaxKind2.PrivateKeyword:
|
|
279
|
+
return 'private';
|
|
280
|
+
default:
|
|
281
|
+
break;
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
return void 0;
|
|
285
|
+
}
|
|
286
|
+
function findNextToken(previousToken, parent, ast) {
|
|
287
|
+
return find(parent);
|
|
288
|
+
function find(n) {
|
|
289
|
+
if (ts.isToken(n) && n.pos === previousToken.end) {
|
|
290
|
+
return n;
|
|
291
|
+
}
|
|
292
|
+
return firstDefined(n.getChildren(ast), (child) => {
|
|
293
|
+
const shouldDiveInChildNode =
|
|
294
|
+
// previous token is enclosed somewhere in the child
|
|
295
|
+
(child.pos <= previousToken.pos && child.end > previousToken.end) || // previous token ends exactly at the beginning of child
|
|
296
|
+
child.pos === previousToken.end;
|
|
297
|
+
return shouldDiveInChildNode && nodeHasTokens(child, ast) ? find(child) : void 0;
|
|
298
|
+
});
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
function findFirstMatchingAncestor(node, predicate) {
|
|
302
|
+
let current = node;
|
|
303
|
+
while (current) {
|
|
304
|
+
if (predicate(current)) {
|
|
305
|
+
return current;
|
|
306
|
+
}
|
|
307
|
+
current = current.parent;
|
|
308
|
+
}
|
|
309
|
+
return void 0;
|
|
310
|
+
}
|
|
311
|
+
function hasJSXAncestor(node) {
|
|
312
|
+
return !!findFirstMatchingAncestor(node, isJSXToken);
|
|
313
|
+
}
|
|
314
|
+
function unescapeStringLiteralText(text) {
|
|
315
|
+
return method_replace_all_default(
|
|
316
|
+
/* OPTIONAL_OBJECT: false */
|
|
317
|
+
0,
|
|
318
|
+
text,
|
|
319
|
+
/&(?:#\d+|#x[\da-fA-F]+|[0-9a-zA-Z]+);/g,
|
|
320
|
+
(entity) => {
|
|
321
|
+
const item = entity.slice(1, -1);
|
|
322
|
+
if (item[0] === '#') {
|
|
323
|
+
const codePoint = item[1] === 'x' ? parseInt(item.slice(2), 16) : parseInt(item.slice(1), 10);
|
|
324
|
+
return codePoint > 1114111 ? entity : String.fromCodePoint(codePoint);
|
|
325
|
+
}
|
|
326
|
+
return xhtmlEntities[item] || entity;
|
|
327
|
+
},
|
|
328
|
+
);
|
|
329
|
+
}
|
|
330
|
+
function isComputedProperty(node) {
|
|
331
|
+
return node.kind === SyntaxKind2.ComputedPropertyName;
|
|
332
|
+
}
|
|
333
|
+
function isOptional(node) {
|
|
334
|
+
return !!node.questionToken;
|
|
335
|
+
}
|
|
336
|
+
function isChainExpression(node) {
|
|
337
|
+
return node.type === AST_NODE_TYPES2.ChainExpression;
|
|
338
|
+
}
|
|
339
|
+
function isChildUnwrappableOptionalChain(node, child) {
|
|
340
|
+
return (
|
|
341
|
+
isChainExpression(child) && // (x?.y).z is semantically different, and as such .z is no longer optional
|
|
342
|
+
node.expression.kind !== ts.SyntaxKind.ParenthesizedExpression
|
|
343
|
+
);
|
|
344
|
+
}
|
|
345
|
+
function getTokenType(token) {
|
|
346
|
+
if (token.kind === SyntaxKind2.NullKeyword) {
|
|
347
|
+
return AST_TOKEN_TYPES2.Null;
|
|
348
|
+
}
|
|
349
|
+
if (token.kind >= SyntaxKind2.FirstKeyword && token.kind <= SyntaxKind2.LastFutureReservedWord) {
|
|
350
|
+
if (token.kind === SyntaxKind2.FalseKeyword || token.kind === SyntaxKind2.TrueKeyword) {
|
|
351
|
+
return AST_TOKEN_TYPES2.Boolean;
|
|
352
|
+
}
|
|
353
|
+
return AST_TOKEN_TYPES2.Keyword;
|
|
354
|
+
}
|
|
355
|
+
if (token.kind >= SyntaxKind2.FirstPunctuation && token.kind <= SyntaxKind2.LastPunctuation) {
|
|
356
|
+
return AST_TOKEN_TYPES2.Punctuator;
|
|
357
|
+
}
|
|
358
|
+
if (token.kind >= SyntaxKind2.NoSubstitutionTemplateLiteral && token.kind <= SyntaxKind2.TemplateTail) {
|
|
359
|
+
return AST_TOKEN_TYPES2.Template;
|
|
360
|
+
}
|
|
361
|
+
switch (token.kind) {
|
|
362
|
+
case SyntaxKind2.NumericLiteral:
|
|
363
|
+
case SyntaxKind2.BigIntLiteral:
|
|
364
|
+
return AST_TOKEN_TYPES2.Numeric;
|
|
365
|
+
case SyntaxKind2.PrivateIdentifier:
|
|
366
|
+
return AST_TOKEN_TYPES2.PrivateIdentifier;
|
|
367
|
+
case SyntaxKind2.JsxText:
|
|
368
|
+
return AST_TOKEN_TYPES2.JSXText;
|
|
369
|
+
case SyntaxKind2.StringLiteral:
|
|
370
|
+
if (token.parent.kind === SyntaxKind2.JsxAttribute || token.parent.kind === SyntaxKind2.JsxElement) {
|
|
371
|
+
return AST_TOKEN_TYPES2.JSXText;
|
|
372
|
+
}
|
|
373
|
+
return AST_TOKEN_TYPES2.String;
|
|
374
|
+
case SyntaxKind2.RegularExpressionLiteral:
|
|
375
|
+
return AST_TOKEN_TYPES2.RegularExpression;
|
|
376
|
+
case SyntaxKind2.Identifier:
|
|
377
|
+
case SyntaxKind2.ConstructorKeyword:
|
|
378
|
+
case SyntaxKind2.GetKeyword:
|
|
379
|
+
case SyntaxKind2.SetKeyword:
|
|
380
|
+
// intentional fallthrough
|
|
381
|
+
default:
|
|
382
|
+
}
|
|
383
|
+
if (token.kind === SyntaxKind2.Identifier) {
|
|
384
|
+
if (isJSXToken(token.parent)) {
|
|
385
|
+
return AST_TOKEN_TYPES2.JSXIdentifier;
|
|
386
|
+
}
|
|
387
|
+
if (token.parent.kind === SyntaxKind2.PropertyAccessExpression && hasJSXAncestor(token)) {
|
|
388
|
+
return AST_TOKEN_TYPES2.JSXIdentifier;
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
return AST_TOKEN_TYPES2.Identifier;
|
|
392
|
+
}
|
|
393
|
+
function convertToken(token, ast) {
|
|
394
|
+
const start = token.kind === SyntaxKind2.JsxText ? token.getFullStart() : token.getStart(ast);
|
|
395
|
+
const end = token.getEnd();
|
|
396
|
+
const value = ast.text.slice(start, end);
|
|
397
|
+
const tokenType = getTokenType(token);
|
|
398
|
+
const range = [start, end];
|
|
399
|
+
const loc = getLocFor(range, ast);
|
|
400
|
+
if (tokenType === AST_TOKEN_TYPES2.RegularExpression) {
|
|
401
|
+
return {
|
|
402
|
+
type: tokenType,
|
|
403
|
+
loc,
|
|
404
|
+
range,
|
|
405
|
+
regex: {
|
|
406
|
+
flags: value.slice(value.lastIndexOf('/') + 1),
|
|
407
|
+
pattern: value.slice(1, value.lastIndexOf('/')),
|
|
408
|
+
},
|
|
409
|
+
value,
|
|
410
|
+
};
|
|
411
|
+
}
|
|
412
|
+
if (tokenType === AST_TOKEN_TYPES2.PrivateIdentifier) {
|
|
413
|
+
return {
|
|
414
|
+
type: tokenType,
|
|
415
|
+
loc,
|
|
416
|
+
range,
|
|
417
|
+
value: value.slice(1),
|
|
418
|
+
};
|
|
419
|
+
}
|
|
420
|
+
return {
|
|
421
|
+
type: tokenType,
|
|
422
|
+
loc,
|
|
423
|
+
range,
|
|
424
|
+
value,
|
|
425
|
+
};
|
|
426
|
+
}
|
|
427
|
+
function convertTokens(ast) {
|
|
428
|
+
const result = [];
|
|
429
|
+
function walk(node) {
|
|
430
|
+
if (isComment(node) || isJSDocComment(node)) {
|
|
431
|
+
return;
|
|
432
|
+
}
|
|
433
|
+
if (isToken2(node) && node.kind !== SyntaxKind2.EndOfFileToken) {
|
|
434
|
+
result.push(convertToken(node, ast));
|
|
435
|
+
} else {
|
|
436
|
+
node.getChildren(ast).forEach(walk);
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
walk(ast);
|
|
440
|
+
return result;
|
|
441
|
+
}
|
|
442
|
+
var TSError = class extends Error {
|
|
443
|
+
fileName;
|
|
444
|
+
location;
|
|
445
|
+
constructor(message, fileName, location) {
|
|
446
|
+
super(message);
|
|
447
|
+
this.fileName = fileName;
|
|
448
|
+
this.location = location;
|
|
449
|
+
Object.defineProperty(this, 'name', {
|
|
450
|
+
configurable: true,
|
|
451
|
+
enumerable: false,
|
|
452
|
+
value: new.target.name,
|
|
453
|
+
});
|
|
454
|
+
}
|
|
455
|
+
// For old version of ESLint https://github.com/typescript-eslint/typescript-eslint/pull/6556#discussion_r1123237311
|
|
456
|
+
get index() {
|
|
457
|
+
return this.location.start.offset;
|
|
458
|
+
}
|
|
459
|
+
// https://github.com/eslint/eslint/blob/b09a512107249a4eb19ef5a37b0bd672266eafdb/lib/linter/linter.js#L853
|
|
460
|
+
get lineNumber() {
|
|
461
|
+
return this.location.start.line;
|
|
462
|
+
}
|
|
463
|
+
// https://github.com/eslint/eslint/blob/b09a512107249a4eb19ef5a37b0bd672266eafdb/lib/linter/linter.js#L854
|
|
464
|
+
get column() {
|
|
465
|
+
return this.location.start.column;
|
|
466
|
+
}
|
|
467
|
+
};
|
|
468
|
+
function createError(message, ast, startIndex, endIndex = startIndex) {
|
|
469
|
+
const [start, end] = [startIndex, endIndex].map((offset) => {
|
|
470
|
+
const { character: column, line } = ast.getLineAndCharacterOfPosition(offset);
|
|
471
|
+
return {
|
|
472
|
+
column,
|
|
473
|
+
line: line + 1,
|
|
474
|
+
offset,
|
|
475
|
+
};
|
|
476
|
+
});
|
|
477
|
+
return new TSError(message, ast.fileName, {
|
|
478
|
+
end,
|
|
479
|
+
start,
|
|
480
|
+
});
|
|
481
|
+
}
|
|
482
|
+
function nodeHasTokens(n, ast) {
|
|
483
|
+
return n.kind === SyntaxKind2.EndOfFileToken ? !!n.jsDoc : n.getWidth(ast) !== 0;
|
|
484
|
+
}
|
|
485
|
+
function firstDefined(array, callback) {
|
|
486
|
+
if (array === void 0) {
|
|
487
|
+
return void 0;
|
|
488
|
+
}
|
|
489
|
+
for (let i = 0; i < array.length; i++) {
|
|
490
|
+
const result = callback(array[i], i);
|
|
491
|
+
if (result !== void 0) {
|
|
492
|
+
return result;
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
return void 0;
|
|
496
|
+
}
|
|
497
|
+
function identifierIsThisKeyword(id) {
|
|
498
|
+
return (
|
|
499
|
+
(isAtLeast50
|
|
500
|
+
? ts.identifierToKeywordKind(id)
|
|
501
|
+
: // @ts-expect-error -- intentional fallback for older TS versions <=4.9
|
|
502
|
+
id.originalKeywordKind) === SyntaxKind2.ThisKeyword
|
|
503
|
+
);
|
|
504
|
+
}
|
|
505
|
+
function isThisIdentifier(node) {
|
|
506
|
+
return !!node && node.kind === SyntaxKind2.Identifier && identifierIsThisKeyword(node);
|
|
507
|
+
}
|
|
508
|
+
function isThisInTypeQuery(node) {
|
|
509
|
+
if (!isThisIdentifier(node)) {
|
|
510
|
+
return false;
|
|
511
|
+
}
|
|
512
|
+
while (ts.isQualifiedName(node.parent) && node.parent.left === node) {
|
|
513
|
+
node = node.parent;
|
|
514
|
+
}
|
|
515
|
+
return node.parent.kind === SyntaxKind2.TypeQuery;
|
|
516
|
+
}
|
|
517
|
+
function isValidAssignmentTarget(node) {
|
|
518
|
+
switch (node.kind) {
|
|
519
|
+
case SyntaxKind2.Identifier:
|
|
520
|
+
return true;
|
|
521
|
+
case SyntaxKind2.PropertyAccessExpression:
|
|
522
|
+
case SyntaxKind2.ElementAccessExpression:
|
|
523
|
+
if (node.flags & ts.NodeFlags.OptionalChain) {
|
|
524
|
+
return false;
|
|
525
|
+
}
|
|
526
|
+
return true;
|
|
527
|
+
case SyntaxKind2.ParenthesizedExpression:
|
|
528
|
+
case SyntaxKind2.TypeAssertionExpression:
|
|
529
|
+
case SyntaxKind2.AsExpression:
|
|
530
|
+
case SyntaxKind2.SatisfiesExpression:
|
|
531
|
+
case SyntaxKind2.ExpressionWithTypeArguments:
|
|
532
|
+
case SyntaxKind2.NonNullExpression:
|
|
533
|
+
return isValidAssignmentTarget(node.expression);
|
|
534
|
+
default:
|
|
535
|
+
return false;
|
|
536
|
+
}
|
|
537
|
+
}
|
|
538
|
+
function getNamespaceModifiers(node) {
|
|
539
|
+
let modifiers = (0, getModifiers2)(node);
|
|
540
|
+
let moduleDeclaration = node;
|
|
541
|
+
while ((!modifiers || modifiers.length === 0) && ts.isModuleDeclaration(moduleDeclaration.parent)) {
|
|
542
|
+
const parentModifiers = (0, getModifiers2)(moduleDeclaration.parent);
|
|
543
|
+
if (parentModifiers?.length) {
|
|
544
|
+
modifiers = parentModifiers;
|
|
545
|
+
}
|
|
546
|
+
moduleDeclaration = moduleDeclaration.parent;
|
|
547
|
+
}
|
|
548
|
+
return modifiers;
|
|
549
|
+
}
|
|
550
|
+
function declarationNameToString(name, ast) {
|
|
551
|
+
const text = ast.text.slice(name.pos, name.end).trimStart();
|
|
552
|
+
return text || '(Missing)';
|
|
553
|
+
}
|
|
554
|
+
|
|
555
|
+
// node_modules/@typescript-eslint/typescript-estree/dist/check-modifiers.js
|
|
556
|
+
var SyntaxKind4 = ts.SyntaxKind;
|
|
557
|
+
function nodeIsMissing(node) {
|
|
558
|
+
if (node == null) {
|
|
559
|
+
return true;
|
|
560
|
+
}
|
|
561
|
+
return node.pos === node.end && node.pos >= 0 && node.kind !== SyntaxKind4.EndOfFileToken;
|
|
562
|
+
}
|
|
563
|
+
function nodeIsPresent(node) {
|
|
564
|
+
return !nodeIsMissing(node);
|
|
565
|
+
}
|
|
566
|
+
function hasAbstractModifier(node) {
|
|
567
|
+
return (0, hasModifier)(SyntaxKind4.AbstractKeyword, node);
|
|
568
|
+
}
|
|
569
|
+
function getThisParameter(signature) {
|
|
570
|
+
if (signature.parameters.length && !ts.isJSDocSignature(signature)) {
|
|
571
|
+
const thisParameter = signature.parameters[0];
|
|
572
|
+
if (parameterIsThisKeyword(thisParameter)) {
|
|
573
|
+
return thisParameter;
|
|
574
|
+
}
|
|
575
|
+
}
|
|
576
|
+
return null;
|
|
577
|
+
}
|
|
578
|
+
function parameterIsThisKeyword(parameter) {
|
|
579
|
+
return (0, isThisIdentifier)(parameter.name);
|
|
580
|
+
}
|
|
581
|
+
function getContainingFunction(node) {
|
|
582
|
+
return ts.findAncestor(node.parent, ts.isFunctionLike);
|
|
583
|
+
}
|
|
584
|
+
function nodeCanBeDecorated(node) {
|
|
585
|
+
switch (node.kind) {
|
|
586
|
+
case SyntaxKind4.ClassDeclaration:
|
|
587
|
+
return true;
|
|
588
|
+
case SyntaxKind4.ClassExpression:
|
|
589
|
+
return true;
|
|
590
|
+
case SyntaxKind4.PropertyDeclaration: {
|
|
591
|
+
const { parent } = node;
|
|
592
|
+
if (ts.isClassDeclaration(parent)) {
|
|
593
|
+
return true;
|
|
594
|
+
}
|
|
595
|
+
if (ts.isClassLike(parent) && !hasAbstractModifier(node)) {
|
|
596
|
+
return true;
|
|
597
|
+
}
|
|
598
|
+
return false;
|
|
599
|
+
}
|
|
600
|
+
case SyntaxKind4.GetAccessor:
|
|
601
|
+
case SyntaxKind4.SetAccessor:
|
|
602
|
+
case SyntaxKind4.MethodDeclaration: {
|
|
603
|
+
const { parent } = node;
|
|
604
|
+
return Boolean(node.body) && (ts.isClassDeclaration(parent) || ts.isClassLike(parent));
|
|
605
|
+
}
|
|
606
|
+
case SyntaxKind4.Parameter: {
|
|
607
|
+
const { parent } = node;
|
|
608
|
+
const grandparent = parent.parent;
|
|
609
|
+
return (
|
|
610
|
+
Boolean(parent) &&
|
|
611
|
+
'body' in parent &&
|
|
612
|
+
Boolean(parent.body) &&
|
|
613
|
+
(parent.kind === SyntaxKind4.Constructor ||
|
|
614
|
+
parent.kind === SyntaxKind4.MethodDeclaration ||
|
|
615
|
+
parent.kind === SyntaxKind4.SetAccessor) &&
|
|
616
|
+
getThisParameter(parent) !== node &&
|
|
617
|
+
Boolean(grandparent) &&
|
|
618
|
+
grandparent.kind === SyntaxKind4.ClassDeclaration
|
|
619
|
+
);
|
|
620
|
+
}
|
|
621
|
+
}
|
|
622
|
+
return false;
|
|
623
|
+
}
|
|
624
|
+
function nodeHasIllegalDecorators(node) {
|
|
625
|
+
return !!('illegalDecorators' in node && node.illegalDecorators?.length);
|
|
626
|
+
}
|
|
627
|
+
function throwError(node, message) {
|
|
628
|
+
const ast = node.getSourceFile();
|
|
629
|
+
const start = node.getStart(ast);
|
|
630
|
+
const end = node.getEnd();
|
|
631
|
+
throw (0, createError)(message, ast, start, end);
|
|
632
|
+
}
|
|
633
|
+
function checkModifiers(node) {
|
|
634
|
+
if (nodeHasIllegalDecorators(node)) {
|
|
635
|
+
throwError(node.illegalDecorators[0], 'Decorators are not valid here.');
|
|
636
|
+
}
|
|
637
|
+
for (const decorator of (0, getDecorators2)(
|
|
638
|
+
node,
|
|
639
|
+
/* includeIllegalDecorators */
|
|
640
|
+
true,
|
|
641
|
+
) ?? []) {
|
|
642
|
+
if (!nodeCanBeDecorated(node)) {
|
|
643
|
+
if (ts.isMethodDeclaration(node) && !nodeIsPresent(node.body)) {
|
|
644
|
+
throwError(decorator, 'A decorator can only decorate a method implementation, not an overload.');
|
|
645
|
+
} else {
|
|
646
|
+
throwError(decorator, 'Decorators are not valid here.');
|
|
647
|
+
}
|
|
648
|
+
}
|
|
649
|
+
}
|
|
650
|
+
for (const modifier of (0, getModifiers2)(
|
|
651
|
+
node,
|
|
652
|
+
/* includeIllegalModifiers */
|
|
653
|
+
true,
|
|
654
|
+
) ?? []) {
|
|
655
|
+
if (modifier.kind !== SyntaxKind4.ReadonlyKeyword) {
|
|
656
|
+
if (node.kind === SyntaxKind4.PropertySignature || node.kind === SyntaxKind4.MethodSignature) {
|
|
657
|
+
throwError(modifier, `'${ts.tokenToString(modifier.kind)}' modifier cannot appear on a type member`);
|
|
658
|
+
}
|
|
659
|
+
if (
|
|
660
|
+
node.kind === SyntaxKind4.IndexSignature &&
|
|
661
|
+
(modifier.kind !== SyntaxKind4.StaticKeyword || !ts.isClassLike(node.parent))
|
|
662
|
+
) {
|
|
663
|
+
throwError(
|
|
664
|
+
modifier,
|
|
665
|
+
`'${ts.tokenToString(modifier.kind)}' modifier cannot appear on an index signature`,
|
|
666
|
+
);
|
|
667
|
+
}
|
|
668
|
+
}
|
|
669
|
+
if (
|
|
670
|
+
modifier.kind !== SyntaxKind4.InKeyword &&
|
|
671
|
+
modifier.kind !== SyntaxKind4.OutKeyword &&
|
|
672
|
+
modifier.kind !== SyntaxKind4.ConstKeyword &&
|
|
673
|
+
node.kind === SyntaxKind4.TypeParameter
|
|
674
|
+
) {
|
|
675
|
+
throwError(modifier, `'${ts.tokenToString(modifier.kind)}' modifier cannot appear on a type parameter`);
|
|
676
|
+
}
|
|
677
|
+
if (
|
|
678
|
+
(modifier.kind === SyntaxKind4.InKeyword || modifier.kind === SyntaxKind4.OutKeyword) &&
|
|
679
|
+
(node.kind !== SyntaxKind4.TypeParameter ||
|
|
680
|
+
!(
|
|
681
|
+
ts.isInterfaceDeclaration(node.parent) ||
|
|
682
|
+
ts.isClassLike(node.parent) ||
|
|
683
|
+
ts.isTypeAliasDeclaration(node.parent)
|
|
684
|
+
))
|
|
685
|
+
) {
|
|
686
|
+
throwError(
|
|
687
|
+
modifier,
|
|
688
|
+
`'${ts.tokenToString(modifier.kind)}' modifier can only appear on a type parameter of a class, interface or type alias`,
|
|
689
|
+
);
|
|
690
|
+
}
|
|
691
|
+
if (
|
|
692
|
+
modifier.kind === SyntaxKind4.ReadonlyKeyword &&
|
|
693
|
+
node.kind !== SyntaxKind4.PropertyDeclaration &&
|
|
694
|
+
node.kind !== SyntaxKind4.PropertySignature &&
|
|
695
|
+
node.kind !== SyntaxKind4.IndexSignature &&
|
|
696
|
+
node.kind !== SyntaxKind4.Parameter
|
|
697
|
+
) {
|
|
698
|
+
throwError(
|
|
699
|
+
modifier,
|
|
700
|
+
"'readonly' modifier can only appear on a property declaration or index signature.",
|
|
701
|
+
);
|
|
702
|
+
}
|
|
703
|
+
if (
|
|
704
|
+
modifier.kind === SyntaxKind4.DeclareKeyword &&
|
|
705
|
+
ts.isClassLike(node.parent) &&
|
|
706
|
+
!ts.isPropertyDeclaration(node)
|
|
707
|
+
) {
|
|
708
|
+
throwError(
|
|
709
|
+
modifier,
|
|
710
|
+
`'${ts.tokenToString(modifier.kind)}' modifier cannot appear on class elements of this kind.`,
|
|
711
|
+
);
|
|
712
|
+
}
|
|
713
|
+
if (modifier.kind === SyntaxKind4.DeclareKeyword && ts.isVariableStatement(node)) {
|
|
714
|
+
const declarationKind = (0, getDeclarationKind)(node.declarationList);
|
|
715
|
+
if (declarationKind === 'using' || declarationKind === 'await using') {
|
|
716
|
+
throwError(modifier, `'declare' modifier cannot appear on a '${declarationKind}' declaration.`);
|
|
717
|
+
}
|
|
718
|
+
}
|
|
719
|
+
if (
|
|
720
|
+
modifier.kind === SyntaxKind4.AbstractKeyword &&
|
|
721
|
+
node.kind !== SyntaxKind4.ClassDeclaration &&
|
|
722
|
+
node.kind !== SyntaxKind4.ConstructorType &&
|
|
723
|
+
node.kind !== SyntaxKind4.MethodDeclaration &&
|
|
724
|
+
node.kind !== SyntaxKind4.PropertyDeclaration &&
|
|
725
|
+
node.kind !== SyntaxKind4.GetAccessor &&
|
|
726
|
+
node.kind !== SyntaxKind4.SetAccessor
|
|
727
|
+
) {
|
|
728
|
+
throwError(
|
|
729
|
+
modifier,
|
|
730
|
+
`'${ts.tokenToString(modifier.kind)}' modifier can only appear on a class, method, or property declaration.`,
|
|
731
|
+
);
|
|
732
|
+
}
|
|
733
|
+
if (
|
|
734
|
+
(modifier.kind === SyntaxKind4.StaticKeyword ||
|
|
735
|
+
modifier.kind === SyntaxKind4.PublicKeyword ||
|
|
736
|
+
modifier.kind === SyntaxKind4.ProtectedKeyword ||
|
|
737
|
+
modifier.kind === SyntaxKind4.PrivateKeyword) &&
|
|
738
|
+
(node.parent.kind === SyntaxKind4.ModuleBlock || node.parent.kind === SyntaxKind4.SourceFile)
|
|
739
|
+
) {
|
|
740
|
+
throwError(
|
|
741
|
+
modifier,
|
|
742
|
+
`'${ts.tokenToString(modifier.kind)}' modifier cannot appear on a module or namespace element.`,
|
|
743
|
+
);
|
|
744
|
+
}
|
|
745
|
+
if (modifier.kind === SyntaxKind4.AccessorKeyword && node.kind !== SyntaxKind4.PropertyDeclaration) {
|
|
746
|
+
throwError(modifier, "'accessor' modifier can only appear on a property declaration.");
|
|
747
|
+
}
|
|
748
|
+
if (
|
|
749
|
+
modifier.kind === SyntaxKind4.AsyncKeyword &&
|
|
750
|
+
node.kind !== SyntaxKind4.MethodDeclaration &&
|
|
751
|
+
node.kind !== SyntaxKind4.FunctionDeclaration &&
|
|
752
|
+
node.kind !== SyntaxKind4.FunctionExpression &&
|
|
753
|
+
node.kind !== SyntaxKind4.ArrowFunction
|
|
754
|
+
) {
|
|
755
|
+
throwError(modifier, "'async' modifier cannot be used here.");
|
|
756
|
+
}
|
|
757
|
+
if (
|
|
758
|
+
node.kind === SyntaxKind4.Parameter &&
|
|
759
|
+
(modifier.kind === SyntaxKind4.StaticKeyword ||
|
|
760
|
+
modifier.kind === SyntaxKind4.ExportKeyword ||
|
|
761
|
+
modifier.kind === SyntaxKind4.DeclareKeyword ||
|
|
762
|
+
modifier.kind === SyntaxKind4.AsyncKeyword)
|
|
763
|
+
) {
|
|
764
|
+
throwError(modifier, `'${ts.tokenToString(modifier.kind)}' modifier cannot appear on a parameter.`);
|
|
765
|
+
}
|
|
766
|
+
if (
|
|
767
|
+
modifier.kind === SyntaxKind4.PublicKeyword ||
|
|
768
|
+
modifier.kind === SyntaxKind4.ProtectedKeyword ||
|
|
769
|
+
modifier.kind === SyntaxKind4.PrivateKeyword
|
|
770
|
+
) {
|
|
771
|
+
for (const anotherModifier of (0, getModifiers2)(node) ?? []) {
|
|
772
|
+
if (
|
|
773
|
+
anotherModifier !== modifier &&
|
|
774
|
+
(anotherModifier.kind === SyntaxKind4.PublicKeyword ||
|
|
775
|
+
anotherModifier.kind === SyntaxKind4.ProtectedKeyword ||
|
|
776
|
+
anotherModifier.kind === SyntaxKind4.PrivateKeyword)
|
|
777
|
+
) {
|
|
778
|
+
throwError(anotherModifier, `Accessibility modifier already seen.`);
|
|
779
|
+
}
|
|
780
|
+
}
|
|
781
|
+
}
|
|
782
|
+
if (
|
|
783
|
+
node.kind === SyntaxKind4.Parameter && // In `typescript` package, it's `ts.hasSyntacticModifier(node, ts.ModifierFlags.ParameterPropertyModifier)`
|
|
784
|
+
// https://github.com/typescript-eslint/typescript-eslint/pull/6615#discussion_r1136489935
|
|
785
|
+
(modifier.kind === SyntaxKind4.PublicKeyword ||
|
|
786
|
+
modifier.kind === SyntaxKind4.PrivateKeyword ||
|
|
787
|
+
modifier.kind === SyntaxKind4.ProtectedKeyword ||
|
|
788
|
+
modifier.kind === SyntaxKind4.ReadonlyKeyword ||
|
|
789
|
+
modifier.kind === SyntaxKind4.OverrideKeyword)
|
|
790
|
+
) {
|
|
791
|
+
const func = getContainingFunction(node);
|
|
792
|
+
if (!(func?.kind === SyntaxKind4.Constructor && nodeIsPresent(func.body))) {
|
|
793
|
+
throwError(modifier, 'A parameter property is only allowed in a constructor implementation.');
|
|
794
|
+
}
|
|
795
|
+
}
|
|
796
|
+
if (
|
|
797
|
+
modifier.kind !== SyntaxKind4.AsyncKeyword &&
|
|
798
|
+
node.kind === SyntaxKind4.MethodDeclaration &&
|
|
799
|
+
node.parent.kind === SyntaxKind4.ObjectLiteralExpression
|
|
800
|
+
) {
|
|
801
|
+
throwError(modifier, `'${ts.tokenToString(modifier.kind)}' modifier cannot be used here.`);
|
|
802
|
+
}
|
|
803
|
+
}
|
|
804
|
+
}
|
|
805
|
+
|
|
806
|
+
// node_modules/@typescript-eslint/typescript-estree/dist/convert.js
|
|
807
|
+
var SyntaxKind6 = ts.SyntaxKind;
|
|
808
|
+
function convertError(error) {
|
|
809
|
+
return (0, createError)(
|
|
810
|
+
('message' in error && error.message) || error.messageText,
|
|
811
|
+
error.file,
|
|
812
|
+
error.start,
|
|
813
|
+
);
|
|
814
|
+
}
|
|
815
|
+
function isPropertyAccessEntityNameExpression(node) {
|
|
816
|
+
return (
|
|
817
|
+
ts.isPropertyAccessExpression(node) &&
|
|
818
|
+
ts.isIdentifier(node.name) &&
|
|
819
|
+
isEntityNameExpression(node.expression)
|
|
820
|
+
);
|
|
821
|
+
}
|
|
822
|
+
function isEntityNameExpression(node) {
|
|
823
|
+
return node.kind === SyntaxKind6.Identifier || isPropertyAccessEntityNameExpression(node);
|
|
824
|
+
}
|
|
825
|
+
var Converter = class {
|
|
826
|
+
allowPattern = false;
|
|
827
|
+
ast;
|
|
828
|
+
esTreeNodeToTSNodeMap = /* @__PURE__ */ new WeakMap();
|
|
829
|
+
options;
|
|
830
|
+
tsNodeToESTreeNodeMap = /* @__PURE__ */ new WeakMap();
|
|
831
|
+
/**
|
|
832
|
+
* Converts a TypeScript node into an ESTree node
|
|
833
|
+
* @param ast the full TypeScript AST
|
|
834
|
+
* @param options additional options for the conversion
|
|
835
|
+
* @returns the converted ESTreeNode
|
|
836
|
+
*/
|
|
837
|
+
constructor(ast, options) {
|
|
838
|
+
this.ast = ast;
|
|
839
|
+
this.options = {
|
|
840
|
+
...options,
|
|
841
|
+
};
|
|
842
|
+
}
|
|
843
|
+
#checkForStatementDeclaration(initializer, kind) {
|
|
844
|
+
const loop = kind === ts.SyntaxKind.ForInStatement ? 'for...in' : 'for...of';
|
|
845
|
+
if (ts.isVariableDeclarationList(initializer)) {
|
|
846
|
+
if (initializer.declarations.length !== 1) {
|
|
847
|
+
this.#throwError(
|
|
848
|
+
initializer,
|
|
849
|
+
`Only a single variable declaration is allowed in a '${loop}' statement.`,
|
|
850
|
+
);
|
|
851
|
+
}
|
|
852
|
+
const declaration = initializer.declarations[0];
|
|
853
|
+
if (declaration.initializer) {
|
|
854
|
+
this.#throwError(
|
|
855
|
+
declaration,
|
|
856
|
+
`The variable declaration of a '${loop}' statement cannot have an initializer.`,
|
|
857
|
+
);
|
|
858
|
+
} else if (declaration.type) {
|
|
859
|
+
this.#throwError(
|
|
860
|
+
declaration,
|
|
861
|
+
`The variable declaration of a '${loop}' statement cannot have a type annotation.`,
|
|
862
|
+
);
|
|
863
|
+
}
|
|
864
|
+
if (kind === ts.SyntaxKind.ForInStatement && initializer.flags & ts.NodeFlags.Using) {
|
|
865
|
+
this.#throwError(
|
|
866
|
+
initializer,
|
|
867
|
+
"The left-hand side of a 'for...in' statement cannot be a 'using' declaration.",
|
|
868
|
+
);
|
|
869
|
+
}
|
|
870
|
+
} else if (
|
|
871
|
+
!(0, isValidAssignmentTarget)(initializer) &&
|
|
872
|
+
initializer.kind !== ts.SyntaxKind.ObjectLiteralExpression &&
|
|
873
|
+
initializer.kind !== ts.SyntaxKind.ArrayLiteralExpression
|
|
874
|
+
) {
|
|
875
|
+
this.#throwError(
|
|
876
|
+
initializer,
|
|
877
|
+
`The left-hand side of a '${loop}' statement must be a variable or a property access.`,
|
|
878
|
+
);
|
|
879
|
+
}
|
|
880
|
+
}
|
|
881
|
+
#checkModifiers(node) {
|
|
882
|
+
if (this.options.allowInvalidAST) {
|
|
883
|
+
return;
|
|
884
|
+
}
|
|
885
|
+
(0, checkModifiers)(node);
|
|
886
|
+
}
|
|
887
|
+
#throwError(node, message) {
|
|
888
|
+
let start;
|
|
889
|
+
let end;
|
|
890
|
+
if (Array.isArray(node)) {
|
|
891
|
+
[start, end] = node;
|
|
892
|
+
} else if (typeof node === 'number') {
|
|
893
|
+
start = end = node;
|
|
894
|
+
} else {
|
|
895
|
+
start = node.getStart(this.ast);
|
|
896
|
+
end = node.getEnd();
|
|
897
|
+
}
|
|
898
|
+
throw (0, createError)(message, this.ast, start, end);
|
|
899
|
+
}
|
|
900
|
+
#throwUnlessAllowInvalidAST(node, message) {
|
|
901
|
+
if (!this.options.allowInvalidAST) {
|
|
902
|
+
this.#throwError(node, message);
|
|
903
|
+
}
|
|
904
|
+
}
|
|
905
|
+
/**
|
|
906
|
+
* Creates a getter for a property under aliasKey that returns the value under
|
|
907
|
+
* valueKey. If suppressDeprecatedPropertyWarnings is not enabled, the
|
|
908
|
+
* getter also console warns about the deprecation.
|
|
909
|
+
*
|
|
910
|
+
* @see https://github.com/typescript-eslint/typescript-eslint/issues/6469
|
|
911
|
+
*/
|
|
912
|
+
#withDeprecatedAliasGetter(node, aliasKey, valueKey, suppressWarnings = false) {
|
|
913
|
+
let warned = suppressWarnings;
|
|
914
|
+
Object.defineProperty(node, aliasKey, {
|
|
915
|
+
configurable: true,
|
|
916
|
+
get: this.options.suppressDeprecatedPropertyWarnings
|
|
917
|
+
? () => node[valueKey]
|
|
918
|
+
: () => {
|
|
919
|
+
if (!warned) {
|
|
920
|
+
(void 0)(
|
|
921
|
+
`The '${aliasKey}' property is deprecated on ${node.type} nodes. Use '${valueKey}' instead. See https://typescript-eslint.io/troubleshooting/faqs/general#the-key-property-is-deprecated-on-type-nodes-use-key-instead-warnings.`,
|
|
922
|
+
'DeprecationWarning',
|
|
923
|
+
);
|
|
924
|
+
warned = true;
|
|
925
|
+
}
|
|
926
|
+
return node[valueKey];
|
|
927
|
+
},
|
|
928
|
+
set(value) {
|
|
929
|
+
Object.defineProperty(node, aliasKey, {
|
|
930
|
+
enumerable: true,
|
|
931
|
+
value,
|
|
932
|
+
writable: true,
|
|
933
|
+
});
|
|
934
|
+
},
|
|
935
|
+
});
|
|
936
|
+
return node;
|
|
937
|
+
}
|
|
938
|
+
#withDeprecatedGetter(node, deprecatedKey, preferredKey, value) {
|
|
939
|
+
let warned = false;
|
|
940
|
+
Object.defineProperty(node, deprecatedKey, {
|
|
941
|
+
configurable: true,
|
|
942
|
+
get: this.options.suppressDeprecatedPropertyWarnings
|
|
943
|
+
? () => value
|
|
944
|
+
: () => {
|
|
945
|
+
if (!warned) {
|
|
946
|
+
let message = `The '${deprecatedKey}' property is deprecated on ${node.type} nodes.`;
|
|
947
|
+
if (preferredKey) {
|
|
948
|
+
message += ` Use ${preferredKey} instead.`;
|
|
949
|
+
}
|
|
950
|
+
message +=
|
|
951
|
+
' See https://typescript-eslint.io/troubleshooting/faqs/general#the-key-property-is-deprecated-on-type-nodes-use-key-instead-warnings.';
|
|
952
|
+
(void 0)(message, 'DeprecationWarning');
|
|
953
|
+
warned = true;
|
|
954
|
+
}
|
|
955
|
+
return value;
|
|
956
|
+
},
|
|
957
|
+
set(value2) {
|
|
958
|
+
Object.defineProperty(node, deprecatedKey, {
|
|
959
|
+
enumerable: true,
|
|
960
|
+
value: value2,
|
|
961
|
+
writable: true,
|
|
962
|
+
});
|
|
963
|
+
},
|
|
964
|
+
});
|
|
965
|
+
return node;
|
|
966
|
+
}
|
|
967
|
+
assertModuleSpecifier(node, allowNull) {
|
|
968
|
+
if (!allowNull && node.moduleSpecifier == null) {
|
|
969
|
+
this.#throwUnlessAllowInvalidAST(node, 'Module specifier must be a string literal.');
|
|
970
|
+
}
|
|
971
|
+
if (node.moduleSpecifier && node.moduleSpecifier?.kind !== SyntaxKind6.StringLiteral) {
|
|
972
|
+
this.#throwUnlessAllowInvalidAST(node.moduleSpecifier, 'Module specifier must be a string literal.');
|
|
973
|
+
}
|
|
974
|
+
}
|
|
975
|
+
convertBindingNameWithTypeAnnotation(name, tsType, parent) {
|
|
976
|
+
const id = this.convertPattern(name);
|
|
977
|
+
if (tsType) {
|
|
978
|
+
id.typeAnnotation = this.convertTypeAnnotation(tsType, parent);
|
|
979
|
+
this.fixParentLocation(id, id.typeAnnotation.range);
|
|
980
|
+
}
|
|
981
|
+
return id;
|
|
982
|
+
}
|
|
983
|
+
/**
|
|
984
|
+
* Coverts body Nodes and add a directive field to StringLiterals
|
|
985
|
+
* @param nodes of ts.Node
|
|
986
|
+
* @param parent parentNode
|
|
987
|
+
* @returns Array of body statements
|
|
988
|
+
*/
|
|
989
|
+
convertBodyExpressions(nodes, parent) {
|
|
990
|
+
let allowDirectives = (0, canContainDirective)(parent);
|
|
991
|
+
return nodes
|
|
992
|
+
.map((statement) => {
|
|
993
|
+
const child = this.convertChild(statement);
|
|
994
|
+
if (allowDirectives) {
|
|
995
|
+
if (
|
|
996
|
+
child?.expression &&
|
|
997
|
+
ts.isExpressionStatement(statement) &&
|
|
998
|
+
ts.isStringLiteral(statement.expression)
|
|
999
|
+
) {
|
|
1000
|
+
const raw = child.expression.raw;
|
|
1001
|
+
child.directive = raw.slice(1, -1);
|
|
1002
|
+
return child;
|
|
1003
|
+
}
|
|
1004
|
+
allowDirectives = false;
|
|
1005
|
+
}
|
|
1006
|
+
return child;
|
|
1007
|
+
})
|
|
1008
|
+
.filter((statement) => statement);
|
|
1009
|
+
}
|
|
1010
|
+
convertChainExpression(node, tsNode) {
|
|
1011
|
+
const { child, isOptional: isOptional2 } = (() => {
|
|
1012
|
+
if (node.type === AST_NODE_TYPES2.MemberExpression) {
|
|
1013
|
+
return {
|
|
1014
|
+
child: node.object,
|
|
1015
|
+
isOptional: node.optional,
|
|
1016
|
+
};
|
|
1017
|
+
}
|
|
1018
|
+
if (node.type === AST_NODE_TYPES2.CallExpression) {
|
|
1019
|
+
return {
|
|
1020
|
+
child: node.callee,
|
|
1021
|
+
isOptional: node.optional,
|
|
1022
|
+
};
|
|
1023
|
+
}
|
|
1024
|
+
return {
|
|
1025
|
+
child: node.expression,
|
|
1026
|
+
isOptional: false,
|
|
1027
|
+
};
|
|
1028
|
+
})();
|
|
1029
|
+
const isChildUnwrappable = (0, isChildUnwrappableOptionalChain)(tsNode, child);
|
|
1030
|
+
if (!isChildUnwrappable && !isOptional2) {
|
|
1031
|
+
return node;
|
|
1032
|
+
}
|
|
1033
|
+
if (isChildUnwrappable && (0, isChainExpression)(child)) {
|
|
1034
|
+
const newChild = child.expression;
|
|
1035
|
+
if (node.type === AST_NODE_TYPES2.MemberExpression) {
|
|
1036
|
+
node.object = newChild;
|
|
1037
|
+
} else if (node.type === AST_NODE_TYPES2.CallExpression) {
|
|
1038
|
+
node.callee = newChild;
|
|
1039
|
+
} else {
|
|
1040
|
+
node.expression = newChild;
|
|
1041
|
+
}
|
|
1042
|
+
}
|
|
1043
|
+
return this.createNode(tsNode, {
|
|
1044
|
+
type: AST_NODE_TYPES2.ChainExpression,
|
|
1045
|
+
expression: node,
|
|
1046
|
+
});
|
|
1047
|
+
}
|
|
1048
|
+
/**
|
|
1049
|
+
* Converts a TypeScript node into an ESTree node.
|
|
1050
|
+
* @param child the child ts.Node
|
|
1051
|
+
* @param parent parentNode
|
|
1052
|
+
* @returns the converted ESTree node
|
|
1053
|
+
*/
|
|
1054
|
+
convertChild(child, parent) {
|
|
1055
|
+
return this.converter(child, parent, false);
|
|
1056
|
+
}
|
|
1057
|
+
/**
|
|
1058
|
+
* Converts TypeScript node array into an ESTree node list.
|
|
1059
|
+
* @param children the child `ts.NodeArray` or `ts.Node[]`
|
|
1060
|
+
* @param parent parentNode
|
|
1061
|
+
* @returns the converted ESTree node list
|
|
1062
|
+
*/
|
|
1063
|
+
convertChildren(children, parent) {
|
|
1064
|
+
return children.map((child) => this.converter(child, parent, false));
|
|
1065
|
+
}
|
|
1066
|
+
/**
|
|
1067
|
+
* Converts a TypeScript node into an ESTree node.
|
|
1068
|
+
* @param child the child ts.Node
|
|
1069
|
+
* @param parent parentNode
|
|
1070
|
+
* @returns the converted ESTree node
|
|
1071
|
+
*/
|
|
1072
|
+
convertPattern(child, parent) {
|
|
1073
|
+
return this.converter(child, parent, true);
|
|
1074
|
+
}
|
|
1075
|
+
/**
|
|
1076
|
+
* Converts a child into a type annotation. This creates an intermediary
|
|
1077
|
+
* TypeAnnotation node to match what Flow does.
|
|
1078
|
+
* @param child The TypeScript AST node to convert.
|
|
1079
|
+
* @param parent parentNode
|
|
1080
|
+
* @returns The type annotation node.
|
|
1081
|
+
*/
|
|
1082
|
+
convertTypeAnnotation(child, parent) {
|
|
1083
|
+
const offset =
|
|
1084
|
+
parent?.kind === SyntaxKind6.FunctionType || parent?.kind === SyntaxKind6.ConstructorType ? 2 : 1;
|
|
1085
|
+
const annotationStartCol = child.getFullStart() - offset;
|
|
1086
|
+
const range = [annotationStartCol, child.end];
|
|
1087
|
+
const loc = (0, getLocFor)(range, this.ast);
|
|
1088
|
+
return {
|
|
1089
|
+
type: AST_NODE_TYPES2.TSTypeAnnotation,
|
|
1090
|
+
loc,
|
|
1091
|
+
range,
|
|
1092
|
+
typeAnnotation: this.convertChild(child),
|
|
1093
|
+
};
|
|
1094
|
+
}
|
|
1095
|
+
/**
|
|
1096
|
+
* Converts a ts.Node's typeArguments to TSTypeParameterInstantiation node
|
|
1097
|
+
* @param typeArguments ts.NodeArray typeArguments
|
|
1098
|
+
* @param node parent used to create this node
|
|
1099
|
+
* @returns TypeParameterInstantiation node
|
|
1100
|
+
*/
|
|
1101
|
+
convertTypeArgumentsToTypeParameterInstantiation(typeArguments, node) {
|
|
1102
|
+
const greaterThanToken = (0, findNextToken)(typeArguments, this.ast, this.ast);
|
|
1103
|
+
const range = [typeArguments.pos - 1, greaterThanToken.end];
|
|
1104
|
+
if (typeArguments.length === 0) {
|
|
1105
|
+
this.#throwError(range, 'Type argument list cannot be empty.');
|
|
1106
|
+
}
|
|
1107
|
+
return this.createNode(node, {
|
|
1108
|
+
type: AST_NODE_TYPES2.TSTypeParameterInstantiation,
|
|
1109
|
+
range,
|
|
1110
|
+
params: this.convertChildren(typeArguments),
|
|
1111
|
+
});
|
|
1112
|
+
}
|
|
1113
|
+
/**
|
|
1114
|
+
* Converts a ts.Node's typeParameters to TSTypeParameterDeclaration node
|
|
1115
|
+
* @param typeParameters ts.Node typeParameters
|
|
1116
|
+
* @returns TypeParameterDeclaration node
|
|
1117
|
+
*/
|
|
1118
|
+
convertTSTypeParametersToTypeParametersDeclaration(typeParameters) {
|
|
1119
|
+
const greaterThanToken = (0, findNextToken)(typeParameters, this.ast, this.ast);
|
|
1120
|
+
const range = [typeParameters.pos - 1, greaterThanToken.end];
|
|
1121
|
+
if (typeParameters.length === 0) {
|
|
1122
|
+
this.#throwError(range, 'Type parameter list cannot be empty.');
|
|
1123
|
+
}
|
|
1124
|
+
return {
|
|
1125
|
+
type: AST_NODE_TYPES2.TSTypeParameterDeclaration,
|
|
1126
|
+
loc: (0, getLocFor)(range, this.ast),
|
|
1127
|
+
range,
|
|
1128
|
+
params: this.convertChildren(typeParameters),
|
|
1129
|
+
};
|
|
1130
|
+
}
|
|
1131
|
+
/**
|
|
1132
|
+
* Converts an array of ts.Node parameters into an array of ESTreeNode params
|
|
1133
|
+
* @param parameters An array of ts.Node params to be converted
|
|
1134
|
+
* @returns an array of converted ESTreeNode params
|
|
1135
|
+
*/
|
|
1136
|
+
convertParameters(parameters) {
|
|
1137
|
+
if (!parameters?.length) {
|
|
1138
|
+
return [];
|
|
1139
|
+
}
|
|
1140
|
+
return parameters.map((param) => {
|
|
1141
|
+
const convertedParam = this.convertChild(param);
|
|
1142
|
+
convertedParam.decorators = this.convertChildren((0, getDecorators2)(param) ?? []);
|
|
1143
|
+
return convertedParam;
|
|
1144
|
+
});
|
|
1145
|
+
}
|
|
1146
|
+
/**
|
|
1147
|
+
* Converts a TypeScript node into an ESTree node.
|
|
1148
|
+
* @param node the child ts.Node
|
|
1149
|
+
* @param parent parentNode
|
|
1150
|
+
* @param allowPattern flag to determine if patterns are allowed
|
|
1151
|
+
* @returns the converted ESTree node
|
|
1152
|
+
*/
|
|
1153
|
+
converter(node, parent, allowPattern) {
|
|
1154
|
+
if (!node) {
|
|
1155
|
+
return null;
|
|
1156
|
+
}
|
|
1157
|
+
this.#checkModifiers(node);
|
|
1158
|
+
const pattern = this.allowPattern;
|
|
1159
|
+
if (allowPattern != null) {
|
|
1160
|
+
this.allowPattern = allowPattern;
|
|
1161
|
+
}
|
|
1162
|
+
const result = this.convertNode(node, parent ?? node.parent);
|
|
1163
|
+
this.registerTSNodeInNodeMap(node, result);
|
|
1164
|
+
this.allowPattern = pattern;
|
|
1165
|
+
return result;
|
|
1166
|
+
}
|
|
1167
|
+
convertImportAttributes(node) {
|
|
1168
|
+
const attributes = node.attributes ?? node.assertClause;
|
|
1169
|
+
return this.convertChildren(attributes?.elements ?? []);
|
|
1170
|
+
}
|
|
1171
|
+
convertJSXIdentifier(node) {
|
|
1172
|
+
const result = this.createNode(node, {
|
|
1173
|
+
type: AST_NODE_TYPES2.JSXIdentifier,
|
|
1174
|
+
name: node.getText(),
|
|
1175
|
+
});
|
|
1176
|
+
this.registerTSNodeInNodeMap(node, result);
|
|
1177
|
+
return result;
|
|
1178
|
+
}
|
|
1179
|
+
convertJSXNamespaceOrIdentifier(node) {
|
|
1180
|
+
if (node.kind === ts.SyntaxKind.JsxNamespacedName) {
|
|
1181
|
+
const result = this.createNode(node, {
|
|
1182
|
+
type: AST_NODE_TYPES2.JSXNamespacedName,
|
|
1183
|
+
name: this.createNode(node.name, {
|
|
1184
|
+
type: AST_NODE_TYPES2.JSXIdentifier,
|
|
1185
|
+
name: node.name.text,
|
|
1186
|
+
}),
|
|
1187
|
+
namespace: this.createNode(node.namespace, {
|
|
1188
|
+
type: AST_NODE_TYPES2.JSXIdentifier,
|
|
1189
|
+
name: node.namespace.text,
|
|
1190
|
+
}),
|
|
1191
|
+
});
|
|
1192
|
+
this.registerTSNodeInNodeMap(node, result);
|
|
1193
|
+
return result;
|
|
1194
|
+
}
|
|
1195
|
+
const text = node.getText();
|
|
1196
|
+
const colonIndex = text.indexOf(':');
|
|
1197
|
+
if (colonIndex > 0) {
|
|
1198
|
+
const range = (0, getRange)(node, this.ast);
|
|
1199
|
+
const result = this.createNode(node, {
|
|
1200
|
+
type: AST_NODE_TYPES2.JSXNamespacedName,
|
|
1201
|
+
range,
|
|
1202
|
+
name: this.createNode(node, {
|
|
1203
|
+
type: AST_NODE_TYPES2.JSXIdentifier,
|
|
1204
|
+
range: [range[0] + colonIndex + 1, range[1]],
|
|
1205
|
+
name: text.slice(colonIndex + 1),
|
|
1206
|
+
}),
|
|
1207
|
+
namespace: this.createNode(node, {
|
|
1208
|
+
type: AST_NODE_TYPES2.JSXIdentifier,
|
|
1209
|
+
range: [range[0], range[0] + colonIndex],
|
|
1210
|
+
name: text.slice(0, colonIndex),
|
|
1211
|
+
}),
|
|
1212
|
+
});
|
|
1213
|
+
this.registerTSNodeInNodeMap(node, result);
|
|
1214
|
+
return result;
|
|
1215
|
+
}
|
|
1216
|
+
return this.convertJSXIdentifier(node);
|
|
1217
|
+
}
|
|
1218
|
+
/**
|
|
1219
|
+
* Converts a TypeScript JSX node.tagName into an ESTree node.name
|
|
1220
|
+
* @param node the tagName object from a JSX ts.Node
|
|
1221
|
+
* @returns the converted ESTree name object
|
|
1222
|
+
*/
|
|
1223
|
+
convertJSXTagName(node, parent) {
|
|
1224
|
+
let result;
|
|
1225
|
+
switch (node.kind) {
|
|
1226
|
+
case SyntaxKind6.PropertyAccessExpression:
|
|
1227
|
+
if (node.name.kind === SyntaxKind6.PrivateIdentifier) {
|
|
1228
|
+
this.#throwError(node.name, 'Non-private identifier expected.');
|
|
1229
|
+
}
|
|
1230
|
+
result = this.createNode(node, {
|
|
1231
|
+
type: AST_NODE_TYPES2.JSXMemberExpression,
|
|
1232
|
+
object: this.convertJSXTagName(node.expression, parent),
|
|
1233
|
+
property: this.convertJSXIdentifier(node.name),
|
|
1234
|
+
});
|
|
1235
|
+
break;
|
|
1236
|
+
case SyntaxKind6.ThisKeyword:
|
|
1237
|
+
case SyntaxKind6.Identifier:
|
|
1238
|
+
default:
|
|
1239
|
+
return this.convertJSXNamespaceOrIdentifier(node);
|
|
1240
|
+
}
|
|
1241
|
+
this.registerTSNodeInNodeMap(node, result);
|
|
1242
|
+
return result;
|
|
1243
|
+
}
|
|
1244
|
+
convertMethodSignature(node) {
|
|
1245
|
+
return this.createNode(node, {
|
|
1246
|
+
type: AST_NODE_TYPES2.TSMethodSignature,
|
|
1247
|
+
accessibility: (0, getTSNodeAccessibility)(node),
|
|
1248
|
+
computed: (0, isComputedProperty)(node.name),
|
|
1249
|
+
key: this.convertChild(node.name),
|
|
1250
|
+
kind: (() => {
|
|
1251
|
+
switch (node.kind) {
|
|
1252
|
+
case SyntaxKind6.GetAccessor:
|
|
1253
|
+
return 'get';
|
|
1254
|
+
case SyntaxKind6.SetAccessor:
|
|
1255
|
+
return 'set';
|
|
1256
|
+
case SyntaxKind6.MethodSignature:
|
|
1257
|
+
return 'method';
|
|
1258
|
+
}
|
|
1259
|
+
})(),
|
|
1260
|
+
optional: (0, isOptional)(node),
|
|
1261
|
+
params: this.convertParameters(node.parameters),
|
|
1262
|
+
readonly: (0, hasModifier)(SyntaxKind6.ReadonlyKeyword, node),
|
|
1263
|
+
returnType: node.type && this.convertTypeAnnotation(node.type, node),
|
|
1264
|
+
static: (0, hasModifier)(SyntaxKind6.StaticKeyword, node),
|
|
1265
|
+
typeParameters:
|
|
1266
|
+
node.typeParameters && this.convertTSTypeParametersToTypeParametersDeclaration(node.typeParameters),
|
|
1267
|
+
});
|
|
1268
|
+
}
|
|
1269
|
+
/**
|
|
1270
|
+
* Uses the provided range location to adjust the location data of the given Node
|
|
1271
|
+
* @param result The node that will have its location data mutated
|
|
1272
|
+
* @param childRange The child node range used to expand location
|
|
1273
|
+
*/
|
|
1274
|
+
fixParentLocation(result, childRange) {
|
|
1275
|
+
if (childRange[0] < result.range[0]) {
|
|
1276
|
+
result.range[0] = childRange[0];
|
|
1277
|
+
result.loc.start = (0, getLineAndCharacterFor)(result.range[0], this.ast);
|
|
1278
|
+
}
|
|
1279
|
+
if (childRange[1] > result.range[1]) {
|
|
1280
|
+
result.range[1] = childRange[1];
|
|
1281
|
+
result.loc.end = (0, getLineAndCharacterFor)(result.range[1], this.ast);
|
|
1282
|
+
}
|
|
1283
|
+
}
|
|
1284
|
+
/**
|
|
1285
|
+
* Converts a TypeScript node into an ESTree node.
|
|
1286
|
+
* The core of the conversion logic:
|
|
1287
|
+
* Identify and convert each relevant TypeScript SyntaxKind
|
|
1288
|
+
* @returns the converted ESTree node
|
|
1289
|
+
*/
|
|
1290
|
+
convertNode(node, parent) {
|
|
1291
|
+
switch (node.kind) {
|
|
1292
|
+
case SyntaxKind6.SourceFile: {
|
|
1293
|
+
return this.createNode(node, {
|
|
1294
|
+
type: AST_NODE_TYPES2.Program,
|
|
1295
|
+
range: [node.getStart(this.ast), node.endOfFileToken.end],
|
|
1296
|
+
body: this.convertBodyExpressions(node.statements, node),
|
|
1297
|
+
comments: void 0,
|
|
1298
|
+
sourceType: node.externalModuleIndicator ? 'module' : 'script',
|
|
1299
|
+
tokens: void 0,
|
|
1300
|
+
});
|
|
1301
|
+
}
|
|
1302
|
+
case SyntaxKind6.Block: {
|
|
1303
|
+
return this.createNode(node, {
|
|
1304
|
+
type: AST_NODE_TYPES2.BlockStatement,
|
|
1305
|
+
body: this.convertBodyExpressions(node.statements, node),
|
|
1306
|
+
});
|
|
1307
|
+
}
|
|
1308
|
+
case SyntaxKind6.Identifier: {
|
|
1309
|
+
if ((0, isThisInTypeQuery)(node)) {
|
|
1310
|
+
return this.createNode(node, {
|
|
1311
|
+
type: AST_NODE_TYPES2.ThisExpression,
|
|
1312
|
+
});
|
|
1313
|
+
}
|
|
1314
|
+
return this.createNode(node, {
|
|
1315
|
+
type: AST_NODE_TYPES2.Identifier,
|
|
1316
|
+
decorators: [],
|
|
1317
|
+
name: node.text,
|
|
1318
|
+
optional: false,
|
|
1319
|
+
typeAnnotation: void 0,
|
|
1320
|
+
});
|
|
1321
|
+
}
|
|
1322
|
+
case SyntaxKind6.PrivateIdentifier: {
|
|
1323
|
+
return this.createNode(node, {
|
|
1324
|
+
type: AST_NODE_TYPES2.PrivateIdentifier,
|
|
1325
|
+
// typescript includes the `#` in the text
|
|
1326
|
+
name: node.text.slice(1),
|
|
1327
|
+
});
|
|
1328
|
+
}
|
|
1329
|
+
case SyntaxKind6.WithStatement:
|
|
1330
|
+
return this.createNode(node, {
|
|
1331
|
+
type: AST_NODE_TYPES2.WithStatement,
|
|
1332
|
+
body: this.convertChild(node.statement),
|
|
1333
|
+
object: this.convertChild(node.expression),
|
|
1334
|
+
});
|
|
1335
|
+
// Control Flow
|
|
1336
|
+
case SyntaxKind6.ReturnStatement:
|
|
1337
|
+
return this.createNode(node, {
|
|
1338
|
+
type: AST_NODE_TYPES2.ReturnStatement,
|
|
1339
|
+
argument: this.convertChild(node.expression),
|
|
1340
|
+
});
|
|
1341
|
+
case SyntaxKind6.LabeledStatement:
|
|
1342
|
+
return this.createNode(node, {
|
|
1343
|
+
type: AST_NODE_TYPES2.LabeledStatement,
|
|
1344
|
+
body: this.convertChild(node.statement),
|
|
1345
|
+
label: this.convertChild(node.label),
|
|
1346
|
+
});
|
|
1347
|
+
case SyntaxKind6.ContinueStatement:
|
|
1348
|
+
return this.createNode(node, {
|
|
1349
|
+
type: AST_NODE_TYPES2.ContinueStatement,
|
|
1350
|
+
label: this.convertChild(node.label),
|
|
1351
|
+
});
|
|
1352
|
+
case SyntaxKind6.BreakStatement:
|
|
1353
|
+
return this.createNode(node, {
|
|
1354
|
+
type: AST_NODE_TYPES2.BreakStatement,
|
|
1355
|
+
label: this.convertChild(node.label),
|
|
1356
|
+
});
|
|
1357
|
+
// Choice
|
|
1358
|
+
case SyntaxKind6.IfStatement:
|
|
1359
|
+
return this.createNode(node, {
|
|
1360
|
+
type: AST_NODE_TYPES2.IfStatement,
|
|
1361
|
+
alternate: this.convertChild(node.elseStatement),
|
|
1362
|
+
consequent: this.convertChild(node.thenStatement),
|
|
1363
|
+
test: this.convertChild(node.expression),
|
|
1364
|
+
});
|
|
1365
|
+
case SyntaxKind6.SwitchStatement:
|
|
1366
|
+
if (
|
|
1367
|
+
node.caseBlock.clauses.filter((switchCase) => switchCase.kind === SyntaxKind6.DefaultClause)
|
|
1368
|
+
.length > 1
|
|
1369
|
+
) {
|
|
1370
|
+
this.#throwError(node, "A 'default' clause cannot appear more than once in a 'switch' statement.");
|
|
1371
|
+
}
|
|
1372
|
+
return this.createNode(node, {
|
|
1373
|
+
type: AST_NODE_TYPES2.SwitchStatement,
|
|
1374
|
+
cases: this.convertChildren(node.caseBlock.clauses),
|
|
1375
|
+
discriminant: this.convertChild(node.expression),
|
|
1376
|
+
});
|
|
1377
|
+
case SyntaxKind6.CaseClause:
|
|
1378
|
+
case SyntaxKind6.DefaultClause:
|
|
1379
|
+
return this.createNode(node, {
|
|
1380
|
+
type: AST_NODE_TYPES2.SwitchCase,
|
|
1381
|
+
// expression is present in case only
|
|
1382
|
+
consequent: this.convertChildren(node.statements),
|
|
1383
|
+
test: node.kind === SyntaxKind6.CaseClause ? this.convertChild(node.expression) : null,
|
|
1384
|
+
});
|
|
1385
|
+
// Exceptions
|
|
1386
|
+
case SyntaxKind6.ThrowStatement:
|
|
1387
|
+
if (node.expression.end === node.expression.pos) {
|
|
1388
|
+
this.#throwUnlessAllowInvalidAST(node, 'A throw statement must throw an expression.');
|
|
1389
|
+
}
|
|
1390
|
+
return this.createNode(node, {
|
|
1391
|
+
type: AST_NODE_TYPES2.ThrowStatement,
|
|
1392
|
+
argument: this.convertChild(node.expression),
|
|
1393
|
+
});
|
|
1394
|
+
case SyntaxKind6.TryStatement:
|
|
1395
|
+
return this.createNode(node, {
|
|
1396
|
+
type: AST_NODE_TYPES2.TryStatement,
|
|
1397
|
+
block: this.convertChild(node.tryBlock),
|
|
1398
|
+
finalizer: this.convertChild(node.finallyBlock),
|
|
1399
|
+
handler: this.convertChild(node.catchClause),
|
|
1400
|
+
});
|
|
1401
|
+
case SyntaxKind6.CatchClause:
|
|
1402
|
+
if (node.variableDeclaration?.initializer) {
|
|
1403
|
+
this.#throwError(
|
|
1404
|
+
node.variableDeclaration.initializer,
|
|
1405
|
+
'Catch clause variable cannot have an initializer.',
|
|
1406
|
+
);
|
|
1407
|
+
}
|
|
1408
|
+
return this.createNode(node, {
|
|
1409
|
+
type: AST_NODE_TYPES2.CatchClause,
|
|
1410
|
+
body: this.convertChild(node.block),
|
|
1411
|
+
param: node.variableDeclaration
|
|
1412
|
+
? this.convertBindingNameWithTypeAnnotation(
|
|
1413
|
+
node.variableDeclaration.name,
|
|
1414
|
+
node.variableDeclaration.type,
|
|
1415
|
+
)
|
|
1416
|
+
: null,
|
|
1417
|
+
});
|
|
1418
|
+
// Loops
|
|
1419
|
+
case SyntaxKind6.WhileStatement:
|
|
1420
|
+
return this.createNode(node, {
|
|
1421
|
+
type: AST_NODE_TYPES2.WhileStatement,
|
|
1422
|
+
body: this.convertChild(node.statement),
|
|
1423
|
+
test: this.convertChild(node.expression),
|
|
1424
|
+
});
|
|
1425
|
+
/**
|
|
1426
|
+
* Unlike other parsers, TypeScript calls a "DoWhileStatement"
|
|
1427
|
+
* a "DoStatement"
|
|
1428
|
+
*/
|
|
1429
|
+
case SyntaxKind6.DoStatement:
|
|
1430
|
+
return this.createNode(node, {
|
|
1431
|
+
type: AST_NODE_TYPES2.DoWhileStatement,
|
|
1432
|
+
body: this.convertChild(node.statement),
|
|
1433
|
+
test: this.convertChild(node.expression),
|
|
1434
|
+
});
|
|
1435
|
+
case SyntaxKind6.ForStatement:
|
|
1436
|
+
return this.createNode(node, {
|
|
1437
|
+
type: AST_NODE_TYPES2.ForStatement,
|
|
1438
|
+
body: this.convertChild(node.statement),
|
|
1439
|
+
init: this.convertChild(node.initializer),
|
|
1440
|
+
test: this.convertChild(node.condition),
|
|
1441
|
+
update: this.convertChild(node.incrementor),
|
|
1442
|
+
});
|
|
1443
|
+
case SyntaxKind6.ForInStatement:
|
|
1444
|
+
this.#checkForStatementDeclaration(node.initializer, node.kind);
|
|
1445
|
+
return this.createNode(node, {
|
|
1446
|
+
type: AST_NODE_TYPES2.ForInStatement,
|
|
1447
|
+
body: this.convertChild(node.statement),
|
|
1448
|
+
left: this.convertPattern(node.initializer),
|
|
1449
|
+
right: this.convertChild(node.expression),
|
|
1450
|
+
});
|
|
1451
|
+
case SyntaxKind6.ForOfStatement: {
|
|
1452
|
+
this.#checkForStatementDeclaration(node.initializer, node.kind);
|
|
1453
|
+
return this.createNode(node, {
|
|
1454
|
+
type: AST_NODE_TYPES2.ForOfStatement,
|
|
1455
|
+
await: Boolean(node.awaitModifier && node.awaitModifier.kind === SyntaxKind6.AwaitKeyword),
|
|
1456
|
+
body: this.convertChild(node.statement),
|
|
1457
|
+
left: this.convertPattern(node.initializer),
|
|
1458
|
+
right: this.convertChild(node.expression),
|
|
1459
|
+
});
|
|
1460
|
+
}
|
|
1461
|
+
// Declarations
|
|
1462
|
+
case SyntaxKind6.FunctionDeclaration: {
|
|
1463
|
+
const isDeclare = (0, hasModifier)(SyntaxKind6.DeclareKeyword, node);
|
|
1464
|
+
const isAsync = (0, hasModifier)(SyntaxKind6.AsyncKeyword, node);
|
|
1465
|
+
const isGenerator = !!node.asteriskToken;
|
|
1466
|
+
if (isDeclare) {
|
|
1467
|
+
if (node.body) {
|
|
1468
|
+
this.#throwError(node, 'An implementation cannot be declared in ambient contexts.');
|
|
1469
|
+
} else if (isAsync) {
|
|
1470
|
+
this.#throwError(node, "'async' modifier cannot be used in an ambient context.");
|
|
1471
|
+
} else if (isGenerator) {
|
|
1472
|
+
this.#throwError(node, 'Generators are not allowed in an ambient context.');
|
|
1473
|
+
}
|
|
1474
|
+
} else if (!node.body && isGenerator) {
|
|
1475
|
+
this.#throwError(node, 'A function signature cannot be declared as a generator.');
|
|
1476
|
+
}
|
|
1477
|
+
const result = this.createNode(node, {
|
|
1478
|
+
// declare implies no body due to the invariant above
|
|
1479
|
+
type: !node.body ? AST_NODE_TYPES2.TSDeclareFunction : AST_NODE_TYPES2.FunctionDeclaration,
|
|
1480
|
+
async: isAsync,
|
|
1481
|
+
body: this.convertChild(node.body) || void 0,
|
|
1482
|
+
declare: isDeclare,
|
|
1483
|
+
expression: false,
|
|
1484
|
+
generator: isGenerator,
|
|
1485
|
+
id: this.convertChild(node.name),
|
|
1486
|
+
params: this.convertParameters(node.parameters),
|
|
1487
|
+
returnType: node.type && this.convertTypeAnnotation(node.type, node),
|
|
1488
|
+
typeParameters:
|
|
1489
|
+
node.typeParameters &&
|
|
1490
|
+
this.convertTSTypeParametersToTypeParametersDeclaration(node.typeParameters),
|
|
1491
|
+
});
|
|
1492
|
+
return this.fixExports(node, result);
|
|
1493
|
+
}
|
|
1494
|
+
case SyntaxKind6.VariableDeclaration: {
|
|
1495
|
+
const definite = !!node.exclamationToken;
|
|
1496
|
+
const init = this.convertChild(node.initializer);
|
|
1497
|
+
const id = this.convertBindingNameWithTypeAnnotation(node.name, node.type, node);
|
|
1498
|
+
if (definite) {
|
|
1499
|
+
if (init) {
|
|
1500
|
+
this.#throwError(
|
|
1501
|
+
node,
|
|
1502
|
+
'Declarations with initializers cannot also have definite assignment assertions.',
|
|
1503
|
+
);
|
|
1504
|
+
} else if (id.type !== AST_NODE_TYPES2.Identifier || !id.typeAnnotation) {
|
|
1505
|
+
this.#throwError(
|
|
1506
|
+
node,
|
|
1507
|
+
'Declarations with definite assignment assertions must also have type annotations.',
|
|
1508
|
+
);
|
|
1509
|
+
}
|
|
1510
|
+
}
|
|
1511
|
+
return this.createNode(node, {
|
|
1512
|
+
type: AST_NODE_TYPES2.VariableDeclarator,
|
|
1513
|
+
definite,
|
|
1514
|
+
id,
|
|
1515
|
+
init,
|
|
1516
|
+
});
|
|
1517
|
+
}
|
|
1518
|
+
case SyntaxKind6.VariableStatement: {
|
|
1519
|
+
const result = this.createNode(node, {
|
|
1520
|
+
type: AST_NODE_TYPES2.VariableDeclaration,
|
|
1521
|
+
declarations: this.convertChildren(node.declarationList.declarations),
|
|
1522
|
+
declare: (0, hasModifier)(SyntaxKind6.DeclareKeyword, node),
|
|
1523
|
+
kind: (0, getDeclarationKind)(node.declarationList),
|
|
1524
|
+
});
|
|
1525
|
+
if (!result.declarations.length) {
|
|
1526
|
+
this.#throwUnlessAllowInvalidAST(
|
|
1527
|
+
node,
|
|
1528
|
+
'A variable declaration list must have at least one variable declarator.',
|
|
1529
|
+
);
|
|
1530
|
+
}
|
|
1531
|
+
if (result.kind === 'using' || result.kind === 'await using') {
|
|
1532
|
+
node.declarationList.declarations.forEach((declaration, i) => {
|
|
1533
|
+
if (result.declarations[i].init == null) {
|
|
1534
|
+
this.#throwError(declaration, `'${result.kind}' declarations must be initialized.`);
|
|
1535
|
+
}
|
|
1536
|
+
if (result.declarations[i].id.type !== AST_NODE_TYPES2.Identifier) {
|
|
1537
|
+
this.#throwError(
|
|
1538
|
+
declaration.name,
|
|
1539
|
+
`'${result.kind}' declarations may not have binding patterns.`,
|
|
1540
|
+
);
|
|
1541
|
+
}
|
|
1542
|
+
});
|
|
1543
|
+
}
|
|
1544
|
+
if (result.declare || ['await using', 'const', 'using'].includes(result.kind)) {
|
|
1545
|
+
node.declarationList.declarations.forEach((declaration, i) => {
|
|
1546
|
+
if (result.declarations[i].definite) {
|
|
1547
|
+
this.#throwError(
|
|
1548
|
+
declaration,
|
|
1549
|
+
`A definite assignment assertion '!' is not permitted in this context.`,
|
|
1550
|
+
);
|
|
1551
|
+
}
|
|
1552
|
+
});
|
|
1553
|
+
}
|
|
1554
|
+
if (result.declare) {
|
|
1555
|
+
node.declarationList.declarations.forEach((declaration, i) => {
|
|
1556
|
+
if (
|
|
1557
|
+
result.declarations[i].init &&
|
|
1558
|
+
(['let', 'var'].includes(result.kind) || result.declarations[i].id.typeAnnotation)
|
|
1559
|
+
) {
|
|
1560
|
+
this.#throwError(declaration, `Initializers are not permitted in ambient contexts.`);
|
|
1561
|
+
}
|
|
1562
|
+
});
|
|
1563
|
+
}
|
|
1564
|
+
return this.fixExports(node, result);
|
|
1565
|
+
}
|
|
1566
|
+
// mostly for for-of, for-in
|
|
1567
|
+
case SyntaxKind6.VariableDeclarationList: {
|
|
1568
|
+
const result = this.createNode(node, {
|
|
1569
|
+
type: AST_NODE_TYPES2.VariableDeclaration,
|
|
1570
|
+
declarations: this.convertChildren(node.declarations),
|
|
1571
|
+
declare: false,
|
|
1572
|
+
kind: (0, getDeclarationKind)(node),
|
|
1573
|
+
});
|
|
1574
|
+
if (result.kind === 'using' || result.kind === 'await using') {
|
|
1575
|
+
node.declarations.forEach((declaration, i) => {
|
|
1576
|
+
if (result.declarations[i].init != null) {
|
|
1577
|
+
this.#throwError(
|
|
1578
|
+
declaration,
|
|
1579
|
+
`'${result.kind}' declarations may not be initialized in for statement.`,
|
|
1580
|
+
);
|
|
1581
|
+
}
|
|
1582
|
+
if (result.declarations[i].id.type !== AST_NODE_TYPES2.Identifier) {
|
|
1583
|
+
this.#throwError(
|
|
1584
|
+
declaration.name,
|
|
1585
|
+
`'${result.kind}' declarations may not have binding patterns.`,
|
|
1586
|
+
);
|
|
1587
|
+
}
|
|
1588
|
+
});
|
|
1589
|
+
}
|
|
1590
|
+
return result;
|
|
1591
|
+
}
|
|
1592
|
+
// Expressions
|
|
1593
|
+
case SyntaxKind6.ExpressionStatement:
|
|
1594
|
+
return this.createNode(node, {
|
|
1595
|
+
type: AST_NODE_TYPES2.ExpressionStatement,
|
|
1596
|
+
directive: void 0,
|
|
1597
|
+
expression: this.convertChild(node.expression),
|
|
1598
|
+
});
|
|
1599
|
+
case SyntaxKind6.ThisKeyword:
|
|
1600
|
+
return this.createNode(node, {
|
|
1601
|
+
type: AST_NODE_TYPES2.ThisExpression,
|
|
1602
|
+
});
|
|
1603
|
+
case SyntaxKind6.ArrayLiteralExpression: {
|
|
1604
|
+
if (this.allowPattern) {
|
|
1605
|
+
return this.createNode(node, {
|
|
1606
|
+
type: AST_NODE_TYPES2.ArrayPattern,
|
|
1607
|
+
decorators: [],
|
|
1608
|
+
elements: node.elements.map((el) => this.convertPattern(el)),
|
|
1609
|
+
optional: false,
|
|
1610
|
+
typeAnnotation: void 0,
|
|
1611
|
+
});
|
|
1612
|
+
}
|
|
1613
|
+
return this.createNode(node, {
|
|
1614
|
+
type: AST_NODE_TYPES2.ArrayExpression,
|
|
1615
|
+
elements: this.convertChildren(node.elements),
|
|
1616
|
+
});
|
|
1617
|
+
}
|
|
1618
|
+
case SyntaxKind6.ObjectLiteralExpression: {
|
|
1619
|
+
if (this.allowPattern) {
|
|
1620
|
+
return this.createNode(node, {
|
|
1621
|
+
type: AST_NODE_TYPES2.ObjectPattern,
|
|
1622
|
+
decorators: [],
|
|
1623
|
+
optional: false,
|
|
1624
|
+
properties: node.properties.map((el) => this.convertPattern(el)),
|
|
1625
|
+
typeAnnotation: void 0,
|
|
1626
|
+
});
|
|
1627
|
+
}
|
|
1628
|
+
const properties = [];
|
|
1629
|
+
for (const property of node.properties) {
|
|
1630
|
+
if (
|
|
1631
|
+
(property.kind === SyntaxKind6.GetAccessor ||
|
|
1632
|
+
property.kind === SyntaxKind6.SetAccessor ||
|
|
1633
|
+
property.kind === SyntaxKind6.MethodDeclaration) &&
|
|
1634
|
+
!property.body
|
|
1635
|
+
) {
|
|
1636
|
+
this.#throwUnlessAllowInvalidAST(property.end - 1, "'{' expected.");
|
|
1637
|
+
}
|
|
1638
|
+
properties.push(this.convertChild(property));
|
|
1639
|
+
}
|
|
1640
|
+
return this.createNode(node, {
|
|
1641
|
+
type: AST_NODE_TYPES2.ObjectExpression,
|
|
1642
|
+
properties,
|
|
1643
|
+
});
|
|
1644
|
+
}
|
|
1645
|
+
case SyntaxKind6.PropertyAssignment: {
|
|
1646
|
+
const { exclamationToken, questionToken } = node;
|
|
1647
|
+
if (questionToken) {
|
|
1648
|
+
this.#throwError(questionToken, 'A property assignment cannot have a question token.');
|
|
1649
|
+
}
|
|
1650
|
+
if (exclamationToken) {
|
|
1651
|
+
this.#throwError(exclamationToken, 'A property assignment cannot have an exclamation token.');
|
|
1652
|
+
}
|
|
1653
|
+
return this.createNode(node, {
|
|
1654
|
+
type: AST_NODE_TYPES2.Property,
|
|
1655
|
+
computed: (0, isComputedProperty)(node.name),
|
|
1656
|
+
key: this.convertChild(node.name),
|
|
1657
|
+
kind: 'init',
|
|
1658
|
+
method: false,
|
|
1659
|
+
optional: false,
|
|
1660
|
+
shorthand: false,
|
|
1661
|
+
value: this.converter(node.initializer, node, this.allowPattern),
|
|
1662
|
+
});
|
|
1663
|
+
}
|
|
1664
|
+
case SyntaxKind6.ShorthandPropertyAssignment: {
|
|
1665
|
+
const { exclamationToken, modifiers, questionToken } = node;
|
|
1666
|
+
if (modifiers) {
|
|
1667
|
+
this.#throwError(modifiers[0], 'A shorthand property assignment cannot have modifiers.');
|
|
1668
|
+
}
|
|
1669
|
+
if (questionToken) {
|
|
1670
|
+
this.#throwError(questionToken, 'A shorthand property assignment cannot have a question token.');
|
|
1671
|
+
}
|
|
1672
|
+
if (exclamationToken) {
|
|
1673
|
+
this.#throwError(
|
|
1674
|
+
exclamationToken,
|
|
1675
|
+
'A shorthand property assignment cannot have an exclamation token.',
|
|
1676
|
+
);
|
|
1677
|
+
}
|
|
1678
|
+
if (node.objectAssignmentInitializer) {
|
|
1679
|
+
return this.createNode(node, {
|
|
1680
|
+
type: AST_NODE_TYPES2.Property,
|
|
1681
|
+
computed: false,
|
|
1682
|
+
key: this.convertChild(node.name),
|
|
1683
|
+
kind: 'init',
|
|
1684
|
+
method: false,
|
|
1685
|
+
optional: false,
|
|
1686
|
+
shorthand: true,
|
|
1687
|
+
value: this.createNode(node, {
|
|
1688
|
+
type: AST_NODE_TYPES2.AssignmentPattern,
|
|
1689
|
+
decorators: [],
|
|
1690
|
+
left: this.convertPattern(node.name),
|
|
1691
|
+
optional: false,
|
|
1692
|
+
right: this.convertChild(node.objectAssignmentInitializer),
|
|
1693
|
+
typeAnnotation: void 0,
|
|
1694
|
+
}),
|
|
1695
|
+
});
|
|
1696
|
+
}
|
|
1697
|
+
return this.createNode(node, {
|
|
1698
|
+
type: AST_NODE_TYPES2.Property,
|
|
1699
|
+
computed: false,
|
|
1700
|
+
key: this.convertChild(node.name),
|
|
1701
|
+
kind: 'init',
|
|
1702
|
+
method: false,
|
|
1703
|
+
optional: false,
|
|
1704
|
+
shorthand: true,
|
|
1705
|
+
value: this.convertChild(node.name),
|
|
1706
|
+
});
|
|
1707
|
+
}
|
|
1708
|
+
case SyntaxKind6.ComputedPropertyName:
|
|
1709
|
+
return this.convertChild(node.expression);
|
|
1710
|
+
case SyntaxKind6.PropertyDeclaration: {
|
|
1711
|
+
const isAbstract = (0, hasModifier)(SyntaxKind6.AbstractKeyword, node);
|
|
1712
|
+
if (isAbstract && node.initializer) {
|
|
1713
|
+
this.#throwError(node.initializer, `Abstract property cannot have an initializer.`);
|
|
1714
|
+
}
|
|
1715
|
+
if (node.name.kind === SyntaxKind6.StringLiteral && node.name.text === 'constructor') {
|
|
1716
|
+
this.#throwError(node.name, "Classes may not have a field named 'constructor'.");
|
|
1717
|
+
}
|
|
1718
|
+
const isAccessor = (0, hasModifier)(SyntaxKind6.AccessorKeyword, node);
|
|
1719
|
+
const type = (() => {
|
|
1720
|
+
if (isAccessor) {
|
|
1721
|
+
if (isAbstract) {
|
|
1722
|
+
return AST_NODE_TYPES2.TSAbstractAccessorProperty;
|
|
1723
|
+
}
|
|
1724
|
+
return AST_NODE_TYPES2.AccessorProperty;
|
|
1725
|
+
}
|
|
1726
|
+
if (isAbstract) {
|
|
1727
|
+
return AST_NODE_TYPES2.TSAbstractPropertyDefinition;
|
|
1728
|
+
}
|
|
1729
|
+
return AST_NODE_TYPES2.PropertyDefinition;
|
|
1730
|
+
})();
|
|
1731
|
+
const key = this.convertChild(node.name);
|
|
1732
|
+
return this.createNode(node, {
|
|
1733
|
+
type,
|
|
1734
|
+
accessibility: (0, getTSNodeAccessibility)(node),
|
|
1735
|
+
computed: (0, isComputedProperty)(node.name),
|
|
1736
|
+
declare: (0, hasModifier)(SyntaxKind6.DeclareKeyword, node),
|
|
1737
|
+
decorators: this.convertChildren((0, getDecorators2)(node) ?? []),
|
|
1738
|
+
definite: !!node.exclamationToken,
|
|
1739
|
+
key,
|
|
1740
|
+
optional:
|
|
1741
|
+
(key.type === AST_NODE_TYPES2.Literal ||
|
|
1742
|
+
node.name.kind === SyntaxKind6.Identifier ||
|
|
1743
|
+
node.name.kind === SyntaxKind6.ComputedPropertyName ||
|
|
1744
|
+
node.name.kind === SyntaxKind6.PrivateIdentifier) &&
|
|
1745
|
+
!!node.questionToken,
|
|
1746
|
+
override: (0, hasModifier)(SyntaxKind6.OverrideKeyword, node),
|
|
1747
|
+
readonly: (0, hasModifier)(SyntaxKind6.ReadonlyKeyword, node),
|
|
1748
|
+
static: (0, hasModifier)(SyntaxKind6.StaticKeyword, node),
|
|
1749
|
+
typeAnnotation: node.type && this.convertTypeAnnotation(node.type, node),
|
|
1750
|
+
value: isAbstract ? null : this.convertChild(node.initializer),
|
|
1751
|
+
});
|
|
1752
|
+
}
|
|
1753
|
+
case SyntaxKind6.GetAccessor:
|
|
1754
|
+
case SyntaxKind6.SetAccessor: {
|
|
1755
|
+
if (
|
|
1756
|
+
node.parent.kind === SyntaxKind6.InterfaceDeclaration ||
|
|
1757
|
+
node.parent.kind === SyntaxKind6.TypeLiteral
|
|
1758
|
+
) {
|
|
1759
|
+
return this.convertMethodSignature(node);
|
|
1760
|
+
}
|
|
1761
|
+
}
|
|
1762
|
+
// otherwise, it is a non-type accessor - intentional fallthrough
|
|
1763
|
+
case SyntaxKind6.MethodDeclaration: {
|
|
1764
|
+
const isAbstract = (0, hasModifier)(SyntaxKind6.AbstractKeyword, node);
|
|
1765
|
+
if (isAbstract && node.body) {
|
|
1766
|
+
this.#throwError(
|
|
1767
|
+
node.name,
|
|
1768
|
+
node.kind === SyntaxKind6.GetAccessor || node.kind === SyntaxKind6.SetAccessor
|
|
1769
|
+
? 'An abstract accessor cannot have an implementation.'
|
|
1770
|
+
: `Method '${(0, declarationNameToString)(node.name, this.ast)}' cannot have an implementation because it is marked abstract.`,
|
|
1771
|
+
);
|
|
1772
|
+
}
|
|
1773
|
+
const method = this.createNode(node, {
|
|
1774
|
+
type: !node.body
|
|
1775
|
+
? AST_NODE_TYPES2.TSEmptyBodyFunctionExpression
|
|
1776
|
+
: AST_NODE_TYPES2.FunctionExpression,
|
|
1777
|
+
range: [node.parameters.pos - 1, node.end],
|
|
1778
|
+
async: (0, hasModifier)(SyntaxKind6.AsyncKeyword, node),
|
|
1779
|
+
body: this.convertChild(node.body),
|
|
1780
|
+
declare: false,
|
|
1781
|
+
expression: false,
|
|
1782
|
+
// ESTreeNode as ESTreeNode here
|
|
1783
|
+
generator: !!node.asteriskToken,
|
|
1784
|
+
id: null,
|
|
1785
|
+
params: [],
|
|
1786
|
+
returnType: node.type && this.convertTypeAnnotation(node.type, node),
|
|
1787
|
+
typeParameters:
|
|
1788
|
+
node.typeParameters &&
|
|
1789
|
+
this.convertTSTypeParametersToTypeParametersDeclaration(node.typeParameters),
|
|
1790
|
+
});
|
|
1791
|
+
if (method.typeParameters) {
|
|
1792
|
+
this.fixParentLocation(method, method.typeParameters.range);
|
|
1793
|
+
}
|
|
1794
|
+
let result;
|
|
1795
|
+
if (parent.kind === SyntaxKind6.ObjectLiteralExpression) {
|
|
1796
|
+
method.params = this.convertChildren(node.parameters);
|
|
1797
|
+
result = this.createNode(node, {
|
|
1798
|
+
type: AST_NODE_TYPES2.Property,
|
|
1799
|
+
computed: (0, isComputedProperty)(node.name),
|
|
1800
|
+
key: this.convertChild(node.name),
|
|
1801
|
+
kind: 'init',
|
|
1802
|
+
method: node.kind === SyntaxKind6.MethodDeclaration,
|
|
1803
|
+
optional: !!node.questionToken,
|
|
1804
|
+
shorthand: false,
|
|
1805
|
+
value: method,
|
|
1806
|
+
});
|
|
1807
|
+
} else {
|
|
1808
|
+
method.params = this.convertParameters(node.parameters);
|
|
1809
|
+
const methodDefinitionType = isAbstract
|
|
1810
|
+
? AST_NODE_TYPES2.TSAbstractMethodDefinition
|
|
1811
|
+
: AST_NODE_TYPES2.MethodDefinition;
|
|
1812
|
+
result = this.createNode(node, {
|
|
1813
|
+
type: methodDefinitionType,
|
|
1814
|
+
accessibility: (0, getTSNodeAccessibility)(node),
|
|
1815
|
+
computed: (0, isComputedProperty)(node.name),
|
|
1816
|
+
decorators: this.convertChildren((0, getDecorators2)(node) ?? []),
|
|
1817
|
+
key: this.convertChild(node.name),
|
|
1818
|
+
kind: 'method',
|
|
1819
|
+
optional: !!node.questionToken,
|
|
1820
|
+
override: (0, hasModifier)(SyntaxKind6.OverrideKeyword, node),
|
|
1821
|
+
static: (0, hasModifier)(SyntaxKind6.StaticKeyword, node),
|
|
1822
|
+
value: method,
|
|
1823
|
+
});
|
|
1824
|
+
}
|
|
1825
|
+
if (node.kind === SyntaxKind6.GetAccessor) {
|
|
1826
|
+
result.kind = 'get';
|
|
1827
|
+
} else if (node.kind === SyntaxKind6.SetAccessor) {
|
|
1828
|
+
result.kind = 'set';
|
|
1829
|
+
} else if (
|
|
1830
|
+
!result.static &&
|
|
1831
|
+
node.name.kind === SyntaxKind6.StringLiteral &&
|
|
1832
|
+
node.name.text === 'constructor' &&
|
|
1833
|
+
result.type !== AST_NODE_TYPES2.Property
|
|
1834
|
+
) {
|
|
1835
|
+
result.kind = 'constructor';
|
|
1836
|
+
}
|
|
1837
|
+
return result;
|
|
1838
|
+
}
|
|
1839
|
+
// TypeScript uses this even for static methods named "constructor"
|
|
1840
|
+
case SyntaxKind6.Constructor: {
|
|
1841
|
+
const lastModifier = (0, getLastModifier)(node);
|
|
1842
|
+
const constructorToken =
|
|
1843
|
+
(lastModifier && (0, findNextToken)(lastModifier, node, this.ast)) ?? node.getFirstToken();
|
|
1844
|
+
const constructor = this.createNode(node, {
|
|
1845
|
+
type: !node.body
|
|
1846
|
+
? AST_NODE_TYPES2.TSEmptyBodyFunctionExpression
|
|
1847
|
+
: AST_NODE_TYPES2.FunctionExpression,
|
|
1848
|
+
range: [node.parameters.pos - 1, node.end],
|
|
1849
|
+
async: false,
|
|
1850
|
+
body: this.convertChild(node.body),
|
|
1851
|
+
declare: false,
|
|
1852
|
+
expression: false,
|
|
1853
|
+
// is not present in ESTreeNode
|
|
1854
|
+
generator: false,
|
|
1855
|
+
id: null,
|
|
1856
|
+
params: this.convertParameters(node.parameters),
|
|
1857
|
+
returnType: node.type && this.convertTypeAnnotation(node.type, node),
|
|
1858
|
+
typeParameters:
|
|
1859
|
+
node.typeParameters &&
|
|
1860
|
+
this.convertTSTypeParametersToTypeParametersDeclaration(node.typeParameters),
|
|
1861
|
+
});
|
|
1862
|
+
if (constructor.typeParameters) {
|
|
1863
|
+
this.fixParentLocation(constructor, constructor.typeParameters.range);
|
|
1864
|
+
}
|
|
1865
|
+
const constructorKey =
|
|
1866
|
+
constructorToken.kind === SyntaxKind6.StringLiteral
|
|
1867
|
+
? this.createNode(constructorToken, {
|
|
1868
|
+
type: AST_NODE_TYPES2.Literal,
|
|
1869
|
+
raw: constructorToken.getText(),
|
|
1870
|
+
value: 'constructor',
|
|
1871
|
+
})
|
|
1872
|
+
: this.createNode(node, {
|
|
1873
|
+
type: AST_NODE_TYPES2.Identifier,
|
|
1874
|
+
range: [constructorToken.getStart(this.ast), constructorToken.end],
|
|
1875
|
+
decorators: [],
|
|
1876
|
+
name: 'constructor',
|
|
1877
|
+
optional: false,
|
|
1878
|
+
typeAnnotation: void 0,
|
|
1879
|
+
});
|
|
1880
|
+
const isStatic = (0, hasModifier)(SyntaxKind6.StaticKeyword, node);
|
|
1881
|
+
return this.createNode(node, {
|
|
1882
|
+
type: (0, hasModifier)(SyntaxKind6.AbstractKeyword, node)
|
|
1883
|
+
? AST_NODE_TYPES2.TSAbstractMethodDefinition
|
|
1884
|
+
: AST_NODE_TYPES2.MethodDefinition,
|
|
1885
|
+
accessibility: (0, getTSNodeAccessibility)(node),
|
|
1886
|
+
computed: false,
|
|
1887
|
+
decorators: [],
|
|
1888
|
+
key: constructorKey,
|
|
1889
|
+
kind: isStatic ? 'method' : 'constructor',
|
|
1890
|
+
optional: false,
|
|
1891
|
+
override: false,
|
|
1892
|
+
static: isStatic,
|
|
1893
|
+
value: constructor,
|
|
1894
|
+
});
|
|
1895
|
+
}
|
|
1896
|
+
case SyntaxKind6.FunctionExpression: {
|
|
1897
|
+
return this.createNode(node, {
|
|
1898
|
+
type: AST_NODE_TYPES2.FunctionExpression,
|
|
1899
|
+
async: (0, hasModifier)(SyntaxKind6.AsyncKeyword, node),
|
|
1900
|
+
body: this.convertChild(node.body),
|
|
1901
|
+
declare: false,
|
|
1902
|
+
expression: false,
|
|
1903
|
+
generator: !!node.asteriskToken,
|
|
1904
|
+
id: this.convertChild(node.name),
|
|
1905
|
+
params: this.convertParameters(node.parameters),
|
|
1906
|
+
returnType: node.type && this.convertTypeAnnotation(node.type, node),
|
|
1907
|
+
typeParameters:
|
|
1908
|
+
node.typeParameters &&
|
|
1909
|
+
this.convertTSTypeParametersToTypeParametersDeclaration(node.typeParameters),
|
|
1910
|
+
});
|
|
1911
|
+
}
|
|
1912
|
+
case SyntaxKind6.SuperKeyword:
|
|
1913
|
+
return this.createNode(node, {
|
|
1914
|
+
type: AST_NODE_TYPES2.Super,
|
|
1915
|
+
});
|
|
1916
|
+
case SyntaxKind6.ArrayBindingPattern:
|
|
1917
|
+
return this.createNode(node, {
|
|
1918
|
+
type: AST_NODE_TYPES2.ArrayPattern,
|
|
1919
|
+
decorators: [],
|
|
1920
|
+
elements: node.elements.map((el) => this.convertPattern(el)),
|
|
1921
|
+
optional: false,
|
|
1922
|
+
typeAnnotation: void 0,
|
|
1923
|
+
});
|
|
1924
|
+
// occurs with missing array elements like [,]
|
|
1925
|
+
case SyntaxKind6.OmittedExpression:
|
|
1926
|
+
return null;
|
|
1927
|
+
case SyntaxKind6.ObjectBindingPattern:
|
|
1928
|
+
return this.createNode(node, {
|
|
1929
|
+
type: AST_NODE_TYPES2.ObjectPattern,
|
|
1930
|
+
decorators: [],
|
|
1931
|
+
optional: false,
|
|
1932
|
+
properties: node.elements.map((el) => this.convertPattern(el)),
|
|
1933
|
+
typeAnnotation: void 0,
|
|
1934
|
+
});
|
|
1935
|
+
case SyntaxKind6.BindingElement: {
|
|
1936
|
+
if (parent.kind === SyntaxKind6.ArrayBindingPattern) {
|
|
1937
|
+
const arrayItem = this.convertChild(node.name, parent);
|
|
1938
|
+
if (node.initializer) {
|
|
1939
|
+
return this.createNode(node, {
|
|
1940
|
+
type: AST_NODE_TYPES2.AssignmentPattern,
|
|
1941
|
+
decorators: [],
|
|
1942
|
+
left: arrayItem,
|
|
1943
|
+
optional: false,
|
|
1944
|
+
right: this.convertChild(node.initializer),
|
|
1945
|
+
typeAnnotation: void 0,
|
|
1946
|
+
});
|
|
1947
|
+
}
|
|
1948
|
+
if (node.dotDotDotToken) {
|
|
1949
|
+
return this.createNode(node, {
|
|
1950
|
+
type: AST_NODE_TYPES2.RestElement,
|
|
1951
|
+
argument: arrayItem,
|
|
1952
|
+
decorators: [],
|
|
1953
|
+
optional: false,
|
|
1954
|
+
typeAnnotation: void 0,
|
|
1955
|
+
value: void 0,
|
|
1956
|
+
});
|
|
1957
|
+
}
|
|
1958
|
+
return arrayItem;
|
|
1959
|
+
}
|
|
1960
|
+
let result;
|
|
1961
|
+
if (node.dotDotDotToken) {
|
|
1962
|
+
result = this.createNode(node, {
|
|
1963
|
+
type: AST_NODE_TYPES2.RestElement,
|
|
1964
|
+
argument: this.convertChild(node.propertyName ?? node.name),
|
|
1965
|
+
decorators: [],
|
|
1966
|
+
optional: false,
|
|
1967
|
+
typeAnnotation: void 0,
|
|
1968
|
+
value: void 0,
|
|
1969
|
+
});
|
|
1970
|
+
} else {
|
|
1971
|
+
result = this.createNode(node, {
|
|
1972
|
+
type: AST_NODE_TYPES2.Property,
|
|
1973
|
+
computed: Boolean(
|
|
1974
|
+
node.propertyName && node.propertyName.kind === SyntaxKind6.ComputedPropertyName,
|
|
1975
|
+
),
|
|
1976
|
+
key: this.convertChild(node.propertyName ?? node.name),
|
|
1977
|
+
kind: 'init',
|
|
1978
|
+
method: false,
|
|
1979
|
+
optional: false,
|
|
1980
|
+
shorthand: !node.propertyName,
|
|
1981
|
+
value: this.convertChild(node.name),
|
|
1982
|
+
});
|
|
1983
|
+
}
|
|
1984
|
+
if (node.initializer) {
|
|
1985
|
+
result.value = this.createNode(node, {
|
|
1986
|
+
type: AST_NODE_TYPES2.AssignmentPattern,
|
|
1987
|
+
range: [node.name.getStart(this.ast), node.initializer.end],
|
|
1988
|
+
decorators: [],
|
|
1989
|
+
left: this.convertChild(node.name),
|
|
1990
|
+
optional: false,
|
|
1991
|
+
right: this.convertChild(node.initializer),
|
|
1992
|
+
typeAnnotation: void 0,
|
|
1993
|
+
});
|
|
1994
|
+
}
|
|
1995
|
+
return result;
|
|
1996
|
+
}
|
|
1997
|
+
case SyntaxKind6.ArrowFunction: {
|
|
1998
|
+
return this.createNode(node, {
|
|
1999
|
+
type: AST_NODE_TYPES2.ArrowFunctionExpression,
|
|
2000
|
+
async: (0, hasModifier)(SyntaxKind6.AsyncKeyword, node),
|
|
2001
|
+
body: this.convertChild(node.body),
|
|
2002
|
+
expression: node.body.kind !== SyntaxKind6.Block,
|
|
2003
|
+
generator: false,
|
|
2004
|
+
id: null,
|
|
2005
|
+
params: this.convertParameters(node.parameters),
|
|
2006
|
+
returnType: node.type && this.convertTypeAnnotation(node.type, node),
|
|
2007
|
+
typeParameters:
|
|
2008
|
+
node.typeParameters &&
|
|
2009
|
+
this.convertTSTypeParametersToTypeParametersDeclaration(node.typeParameters),
|
|
2010
|
+
});
|
|
2011
|
+
}
|
|
2012
|
+
case SyntaxKind6.YieldExpression:
|
|
2013
|
+
return this.createNode(node, {
|
|
2014
|
+
type: AST_NODE_TYPES2.YieldExpression,
|
|
2015
|
+
argument: this.convertChild(node.expression),
|
|
2016
|
+
delegate: !!node.asteriskToken,
|
|
2017
|
+
});
|
|
2018
|
+
case SyntaxKind6.AwaitExpression:
|
|
2019
|
+
return this.createNode(node, {
|
|
2020
|
+
type: AST_NODE_TYPES2.AwaitExpression,
|
|
2021
|
+
argument: this.convertChild(node.expression),
|
|
2022
|
+
});
|
|
2023
|
+
// Template Literals
|
|
2024
|
+
case SyntaxKind6.NoSubstitutionTemplateLiteral:
|
|
2025
|
+
return this.createNode(node, {
|
|
2026
|
+
type: AST_NODE_TYPES2.TemplateLiteral,
|
|
2027
|
+
expressions: [],
|
|
2028
|
+
quasis: [
|
|
2029
|
+
this.createNode(node, {
|
|
2030
|
+
type: AST_NODE_TYPES2.TemplateElement,
|
|
2031
|
+
tail: true,
|
|
2032
|
+
value: {
|
|
2033
|
+
cooked: node.text,
|
|
2034
|
+
raw: this.ast.text.slice(node.getStart(this.ast) + 1, node.end - 1),
|
|
2035
|
+
},
|
|
2036
|
+
}),
|
|
2037
|
+
],
|
|
2038
|
+
});
|
|
2039
|
+
case SyntaxKind6.TemplateExpression: {
|
|
2040
|
+
const result = this.createNode(node, {
|
|
2041
|
+
type: AST_NODE_TYPES2.TemplateLiteral,
|
|
2042
|
+
expressions: [],
|
|
2043
|
+
quasis: [this.convertChild(node.head)],
|
|
2044
|
+
});
|
|
2045
|
+
node.templateSpans.forEach((templateSpan) => {
|
|
2046
|
+
result.expressions.push(this.convertChild(templateSpan.expression));
|
|
2047
|
+
result.quasis.push(this.convertChild(templateSpan.literal));
|
|
2048
|
+
});
|
|
2049
|
+
return result;
|
|
2050
|
+
}
|
|
2051
|
+
case SyntaxKind6.TaggedTemplateExpression: {
|
|
2052
|
+
if (node.tag.flags & ts.NodeFlags.OptionalChain) {
|
|
2053
|
+
this.#throwError(node, 'Tagged template expressions are not permitted in an optional chain.');
|
|
2054
|
+
}
|
|
2055
|
+
return this.createNode(node, {
|
|
2056
|
+
type: AST_NODE_TYPES2.TaggedTemplateExpression,
|
|
2057
|
+
quasi: this.convertChild(node.template),
|
|
2058
|
+
tag: this.convertChild(node.tag),
|
|
2059
|
+
typeArguments:
|
|
2060
|
+
node.typeArguments &&
|
|
2061
|
+
this.convertTypeArgumentsToTypeParameterInstantiation(node.typeArguments, node),
|
|
2062
|
+
});
|
|
2063
|
+
}
|
|
2064
|
+
case SyntaxKind6.TemplateHead:
|
|
2065
|
+
case SyntaxKind6.TemplateMiddle:
|
|
2066
|
+
case SyntaxKind6.TemplateTail: {
|
|
2067
|
+
const tail = node.kind === SyntaxKind6.TemplateTail;
|
|
2068
|
+
return this.createNode(node, {
|
|
2069
|
+
type: AST_NODE_TYPES2.TemplateElement,
|
|
2070
|
+
tail,
|
|
2071
|
+
value: {
|
|
2072
|
+
cooked: node.text,
|
|
2073
|
+
raw: this.ast.text.slice(node.getStart(this.ast) + 1, node.end - (tail ? 1 : 2)),
|
|
2074
|
+
},
|
|
2075
|
+
});
|
|
2076
|
+
}
|
|
2077
|
+
// Patterns
|
|
2078
|
+
case SyntaxKind6.SpreadAssignment:
|
|
2079
|
+
case SyntaxKind6.SpreadElement: {
|
|
2080
|
+
if (this.allowPattern) {
|
|
2081
|
+
return this.createNode(node, {
|
|
2082
|
+
type: AST_NODE_TYPES2.RestElement,
|
|
2083
|
+
argument: this.convertPattern(node.expression),
|
|
2084
|
+
decorators: [],
|
|
2085
|
+
optional: false,
|
|
2086
|
+
typeAnnotation: void 0,
|
|
2087
|
+
value: void 0,
|
|
2088
|
+
});
|
|
2089
|
+
}
|
|
2090
|
+
return this.createNode(node, {
|
|
2091
|
+
type: AST_NODE_TYPES2.SpreadElement,
|
|
2092
|
+
argument: this.convertChild(node.expression),
|
|
2093
|
+
});
|
|
2094
|
+
}
|
|
2095
|
+
case SyntaxKind6.Parameter: {
|
|
2096
|
+
let parameter;
|
|
2097
|
+
let result;
|
|
2098
|
+
if (node.dotDotDotToken) {
|
|
2099
|
+
parameter = result = this.createNode(node, {
|
|
2100
|
+
type: AST_NODE_TYPES2.RestElement,
|
|
2101
|
+
argument: this.convertChild(node.name),
|
|
2102
|
+
decorators: [],
|
|
2103
|
+
optional: false,
|
|
2104
|
+
typeAnnotation: void 0,
|
|
2105
|
+
value: void 0,
|
|
2106
|
+
});
|
|
2107
|
+
} else if (node.initializer) {
|
|
2108
|
+
parameter = this.convertChild(node.name);
|
|
2109
|
+
result = this.createNode(node, {
|
|
2110
|
+
type: AST_NODE_TYPES2.AssignmentPattern,
|
|
2111
|
+
range: [node.name.getStart(this.ast), node.initializer.end],
|
|
2112
|
+
decorators: [],
|
|
2113
|
+
left: parameter,
|
|
2114
|
+
optional: false,
|
|
2115
|
+
right: this.convertChild(node.initializer),
|
|
2116
|
+
typeAnnotation: void 0,
|
|
2117
|
+
});
|
|
2118
|
+
const modifiers2 = (0, getModifiers2)(node);
|
|
2119
|
+
if (modifiers2) {
|
|
2120
|
+
result.range[0] = parameter.range[0];
|
|
2121
|
+
result.loc = (0, getLocFor)(result.range, this.ast);
|
|
2122
|
+
}
|
|
2123
|
+
} else {
|
|
2124
|
+
parameter = result = this.convertChild(node.name, parent);
|
|
2125
|
+
}
|
|
2126
|
+
if (node.type) {
|
|
2127
|
+
parameter.typeAnnotation = this.convertTypeAnnotation(node.type, node);
|
|
2128
|
+
this.fixParentLocation(parameter, parameter.typeAnnotation.range);
|
|
2129
|
+
}
|
|
2130
|
+
if (node.questionToken) {
|
|
2131
|
+
if (node.questionToken.end > parameter.range[1]) {
|
|
2132
|
+
parameter.range[1] = node.questionToken.end;
|
|
2133
|
+
parameter.loc.end = (0, getLineAndCharacterFor)(parameter.range[1], this.ast);
|
|
2134
|
+
}
|
|
2135
|
+
parameter.optional = true;
|
|
2136
|
+
}
|
|
2137
|
+
const modifiers = (0, getModifiers2)(node);
|
|
2138
|
+
if (modifiers) {
|
|
2139
|
+
return this.createNode(node, {
|
|
2140
|
+
type: AST_NODE_TYPES2.TSParameterProperty,
|
|
2141
|
+
accessibility: (0, getTSNodeAccessibility)(node),
|
|
2142
|
+
decorators: [],
|
|
2143
|
+
override: (0, hasModifier)(SyntaxKind6.OverrideKeyword, node),
|
|
2144
|
+
parameter: result,
|
|
2145
|
+
readonly: (0, hasModifier)(SyntaxKind6.ReadonlyKeyword, node),
|
|
2146
|
+
static: (0, hasModifier)(SyntaxKind6.StaticKeyword, node),
|
|
2147
|
+
});
|
|
2148
|
+
}
|
|
2149
|
+
return result;
|
|
2150
|
+
}
|
|
2151
|
+
// Classes
|
|
2152
|
+
case SyntaxKind6.ClassDeclaration:
|
|
2153
|
+
if (
|
|
2154
|
+
!node.name &&
|
|
2155
|
+
(!(0, hasModifier)(ts.SyntaxKind.ExportKeyword, node) ||
|
|
2156
|
+
!(0, hasModifier)(ts.SyntaxKind.DefaultKeyword, node))
|
|
2157
|
+
) {
|
|
2158
|
+
this.#throwUnlessAllowInvalidAST(
|
|
2159
|
+
node,
|
|
2160
|
+
"A class declaration without the 'default' modifier must have a name.",
|
|
2161
|
+
);
|
|
2162
|
+
}
|
|
2163
|
+
/* intentional fallthrough */
|
|
2164
|
+
case SyntaxKind6.ClassExpression: {
|
|
2165
|
+
const heritageClauses = node.heritageClauses ?? [];
|
|
2166
|
+
const classNodeType =
|
|
2167
|
+
node.kind === SyntaxKind6.ClassDeclaration
|
|
2168
|
+
? AST_NODE_TYPES2.ClassDeclaration
|
|
2169
|
+
: AST_NODE_TYPES2.ClassExpression;
|
|
2170
|
+
let extendsClause;
|
|
2171
|
+
let implementsClause;
|
|
2172
|
+
for (const heritageClause of heritageClauses) {
|
|
2173
|
+
const { token, types } = heritageClause;
|
|
2174
|
+
if (types.length === 0) {
|
|
2175
|
+
this.#throwUnlessAllowInvalidAST(
|
|
2176
|
+
heritageClause,
|
|
2177
|
+
`'${ts.tokenToString(token)}' list cannot be empty.`,
|
|
2178
|
+
);
|
|
2179
|
+
}
|
|
2180
|
+
if (token === SyntaxKind6.ExtendsKeyword) {
|
|
2181
|
+
if (extendsClause) {
|
|
2182
|
+
this.#throwUnlessAllowInvalidAST(heritageClause, "'extends' clause already seen.");
|
|
2183
|
+
}
|
|
2184
|
+
if (implementsClause) {
|
|
2185
|
+
this.#throwUnlessAllowInvalidAST(
|
|
2186
|
+
heritageClause,
|
|
2187
|
+
"'extends' clause must precede 'implements' clause.",
|
|
2188
|
+
);
|
|
2189
|
+
}
|
|
2190
|
+
if (types.length > 1) {
|
|
2191
|
+
this.#throwUnlessAllowInvalidAST(types[1], 'Classes can only extend a single class.');
|
|
2192
|
+
}
|
|
2193
|
+
extendsClause ?? (extendsClause = heritageClause);
|
|
2194
|
+
} else if (token === SyntaxKind6.ImplementsKeyword) {
|
|
2195
|
+
if (implementsClause) {
|
|
2196
|
+
this.#throwUnlessAllowInvalidAST(heritageClause, "'implements' clause already seen.");
|
|
2197
|
+
}
|
|
2198
|
+
implementsClause ?? (implementsClause = heritageClause);
|
|
2199
|
+
}
|
|
2200
|
+
}
|
|
2201
|
+
const result = this.createNode(node, {
|
|
2202
|
+
type: classNodeType,
|
|
2203
|
+
abstract: (0, hasModifier)(SyntaxKind6.AbstractKeyword, node),
|
|
2204
|
+
body: this.createNode(node, {
|
|
2205
|
+
type: AST_NODE_TYPES2.ClassBody,
|
|
2206
|
+
range: [node.members.pos - 1, node.end],
|
|
2207
|
+
body: this.convertChildren(node.members.filter(isESTreeClassMember)),
|
|
2208
|
+
}),
|
|
2209
|
+
declare: (0, hasModifier)(SyntaxKind6.DeclareKeyword, node),
|
|
2210
|
+
decorators: this.convertChildren((0, getDecorators2)(node) ?? []),
|
|
2211
|
+
id: this.convertChild(node.name),
|
|
2212
|
+
implements: this.convertChildren(implementsClause?.types ?? []),
|
|
2213
|
+
superClass: extendsClause?.types[0] ? this.convertChild(extendsClause.types[0].expression) : null,
|
|
2214
|
+
superTypeArguments: void 0,
|
|
2215
|
+
typeParameters:
|
|
2216
|
+
node.typeParameters &&
|
|
2217
|
+
this.convertTSTypeParametersToTypeParametersDeclaration(node.typeParameters),
|
|
2218
|
+
});
|
|
2219
|
+
if (extendsClause?.types[0]?.typeArguments) {
|
|
2220
|
+
result.superTypeArguments = this.convertTypeArgumentsToTypeParameterInstantiation(
|
|
2221
|
+
extendsClause.types[0].typeArguments,
|
|
2222
|
+
extendsClause.types[0],
|
|
2223
|
+
);
|
|
2224
|
+
}
|
|
2225
|
+
return this.fixExports(node, result);
|
|
2226
|
+
}
|
|
2227
|
+
// Modules
|
|
2228
|
+
case SyntaxKind6.ModuleBlock:
|
|
2229
|
+
return this.createNode(node, {
|
|
2230
|
+
type: AST_NODE_TYPES2.TSModuleBlock,
|
|
2231
|
+
body: this.convertBodyExpressions(node.statements, node),
|
|
2232
|
+
});
|
|
2233
|
+
case SyntaxKind6.ImportDeclaration: {
|
|
2234
|
+
this.assertModuleSpecifier(node, false);
|
|
2235
|
+
const result = this.createNode(
|
|
2236
|
+
node,
|
|
2237
|
+
this.#withDeprecatedAliasGetter(
|
|
2238
|
+
{
|
|
2239
|
+
type: AST_NODE_TYPES2.ImportDeclaration,
|
|
2240
|
+
attributes: this.convertImportAttributes(node),
|
|
2241
|
+
importKind: 'value',
|
|
2242
|
+
source: this.convertChild(node.moduleSpecifier),
|
|
2243
|
+
specifiers: [],
|
|
2244
|
+
},
|
|
2245
|
+
'assertions',
|
|
2246
|
+
'attributes',
|
|
2247
|
+
true,
|
|
2248
|
+
),
|
|
2249
|
+
);
|
|
2250
|
+
if (node.importClause) {
|
|
2251
|
+
if (node.importClause.isTypeOnly) {
|
|
2252
|
+
result.importKind = 'type';
|
|
2253
|
+
}
|
|
2254
|
+
if (node.importClause.name) {
|
|
2255
|
+
result.specifiers.push(this.convertChild(node.importClause));
|
|
2256
|
+
}
|
|
2257
|
+
if (node.importClause.namedBindings) {
|
|
2258
|
+
switch (node.importClause.namedBindings.kind) {
|
|
2259
|
+
case SyntaxKind6.NamespaceImport:
|
|
2260
|
+
result.specifiers.push(this.convertChild(node.importClause.namedBindings));
|
|
2261
|
+
break;
|
|
2262
|
+
case SyntaxKind6.NamedImports:
|
|
2263
|
+
result.specifiers.push(...this.convertChildren(node.importClause.namedBindings.elements));
|
|
2264
|
+
break;
|
|
2265
|
+
}
|
|
2266
|
+
}
|
|
2267
|
+
}
|
|
2268
|
+
return result;
|
|
2269
|
+
}
|
|
2270
|
+
case SyntaxKind6.NamespaceImport:
|
|
2271
|
+
return this.createNode(node, {
|
|
2272
|
+
type: AST_NODE_TYPES2.ImportNamespaceSpecifier,
|
|
2273
|
+
local: this.convertChild(node.name),
|
|
2274
|
+
});
|
|
2275
|
+
case SyntaxKind6.ImportSpecifier:
|
|
2276
|
+
return this.createNode(node, {
|
|
2277
|
+
type: AST_NODE_TYPES2.ImportSpecifier,
|
|
2278
|
+
imported: this.convertChild(node.propertyName ?? node.name),
|
|
2279
|
+
importKind: node.isTypeOnly ? 'type' : 'value',
|
|
2280
|
+
local: this.convertChild(node.name),
|
|
2281
|
+
});
|
|
2282
|
+
case SyntaxKind6.ImportClause: {
|
|
2283
|
+
const local = this.convertChild(node.name);
|
|
2284
|
+
return this.createNode(node, {
|
|
2285
|
+
type: AST_NODE_TYPES2.ImportDefaultSpecifier,
|
|
2286
|
+
range: local.range,
|
|
2287
|
+
local,
|
|
2288
|
+
});
|
|
2289
|
+
}
|
|
2290
|
+
case SyntaxKind6.ExportDeclaration: {
|
|
2291
|
+
if (node.exportClause?.kind === SyntaxKind6.NamedExports) {
|
|
2292
|
+
this.assertModuleSpecifier(node, true);
|
|
2293
|
+
return this.createNode(
|
|
2294
|
+
node,
|
|
2295
|
+
this.#withDeprecatedAliasGetter(
|
|
2296
|
+
{
|
|
2297
|
+
type: AST_NODE_TYPES2.ExportNamedDeclaration,
|
|
2298
|
+
attributes: this.convertImportAttributes(node),
|
|
2299
|
+
declaration: null,
|
|
2300
|
+
exportKind: node.isTypeOnly ? 'type' : 'value',
|
|
2301
|
+
source: this.convertChild(node.moduleSpecifier),
|
|
2302
|
+
specifiers: this.convertChildren(node.exportClause.elements, node),
|
|
2303
|
+
},
|
|
2304
|
+
'assertions',
|
|
2305
|
+
'attributes',
|
|
2306
|
+
true,
|
|
2307
|
+
),
|
|
2308
|
+
);
|
|
2309
|
+
}
|
|
2310
|
+
this.assertModuleSpecifier(node, false);
|
|
2311
|
+
return this.createNode(
|
|
2312
|
+
node,
|
|
2313
|
+
this.#withDeprecatedAliasGetter(
|
|
2314
|
+
{
|
|
2315
|
+
type: AST_NODE_TYPES2.ExportAllDeclaration,
|
|
2316
|
+
attributes: this.convertImportAttributes(node),
|
|
2317
|
+
exported:
|
|
2318
|
+
node.exportClause?.kind === SyntaxKind6.NamespaceExport
|
|
2319
|
+
? this.convertChild(node.exportClause.name)
|
|
2320
|
+
: null,
|
|
2321
|
+
exportKind: node.isTypeOnly ? 'type' : 'value',
|
|
2322
|
+
source: this.convertChild(node.moduleSpecifier),
|
|
2323
|
+
},
|
|
2324
|
+
'assertions',
|
|
2325
|
+
'attributes',
|
|
2326
|
+
true,
|
|
2327
|
+
),
|
|
2328
|
+
);
|
|
2329
|
+
}
|
|
2330
|
+
case SyntaxKind6.ExportSpecifier: {
|
|
2331
|
+
const local = node.propertyName ?? node.name;
|
|
2332
|
+
if (
|
|
2333
|
+
local.kind === SyntaxKind6.StringLiteral &&
|
|
2334
|
+
parent.kind === SyntaxKind6.ExportDeclaration &&
|
|
2335
|
+
parent.moduleSpecifier?.kind !== SyntaxKind6.StringLiteral
|
|
2336
|
+
) {
|
|
2337
|
+
this.#throwError(
|
|
2338
|
+
local,
|
|
2339
|
+
'A string literal cannot be used as a local exported binding without `from`.',
|
|
2340
|
+
);
|
|
2341
|
+
}
|
|
2342
|
+
return this.createNode(node, {
|
|
2343
|
+
type: AST_NODE_TYPES2.ExportSpecifier,
|
|
2344
|
+
exported: this.convertChild(node.name),
|
|
2345
|
+
exportKind: node.isTypeOnly ? 'type' : 'value',
|
|
2346
|
+
local: this.convertChild(local),
|
|
2347
|
+
});
|
|
2348
|
+
}
|
|
2349
|
+
case SyntaxKind6.ExportAssignment:
|
|
2350
|
+
if (node.isExportEquals) {
|
|
2351
|
+
return this.createNode(node, {
|
|
2352
|
+
type: AST_NODE_TYPES2.TSExportAssignment,
|
|
2353
|
+
expression: this.convertChild(node.expression),
|
|
2354
|
+
});
|
|
2355
|
+
}
|
|
2356
|
+
return this.createNode(node, {
|
|
2357
|
+
type: AST_NODE_TYPES2.ExportDefaultDeclaration,
|
|
2358
|
+
declaration: this.convertChild(node.expression),
|
|
2359
|
+
exportKind: 'value',
|
|
2360
|
+
});
|
|
2361
|
+
// Unary Operations
|
|
2362
|
+
case SyntaxKind6.PrefixUnaryExpression:
|
|
2363
|
+
case SyntaxKind6.PostfixUnaryExpression: {
|
|
2364
|
+
const operator = (0, getTextForTokenKind)(node.operator);
|
|
2365
|
+
if (operator === '++' || operator === '--') {
|
|
2366
|
+
if (!(0, isValidAssignmentTarget)(node.operand)) {
|
|
2367
|
+
this.#throwUnlessAllowInvalidAST(
|
|
2368
|
+
node.operand,
|
|
2369
|
+
'Invalid left-hand side expression in unary operation',
|
|
2370
|
+
);
|
|
2371
|
+
}
|
|
2372
|
+
return this.createNode(node, {
|
|
2373
|
+
type: AST_NODE_TYPES2.UpdateExpression,
|
|
2374
|
+
argument: this.convertChild(node.operand),
|
|
2375
|
+
operator,
|
|
2376
|
+
prefix: node.kind === SyntaxKind6.PrefixUnaryExpression,
|
|
2377
|
+
});
|
|
2378
|
+
}
|
|
2379
|
+
return this.createNode(node, {
|
|
2380
|
+
type: AST_NODE_TYPES2.UnaryExpression,
|
|
2381
|
+
argument: this.convertChild(node.operand),
|
|
2382
|
+
operator,
|
|
2383
|
+
prefix: node.kind === SyntaxKind6.PrefixUnaryExpression,
|
|
2384
|
+
});
|
|
2385
|
+
}
|
|
2386
|
+
case SyntaxKind6.DeleteExpression:
|
|
2387
|
+
return this.createNode(node, {
|
|
2388
|
+
type: AST_NODE_TYPES2.UnaryExpression,
|
|
2389
|
+
argument: this.convertChild(node.expression),
|
|
2390
|
+
operator: 'delete',
|
|
2391
|
+
prefix: true,
|
|
2392
|
+
});
|
|
2393
|
+
case SyntaxKind6.VoidExpression:
|
|
2394
|
+
return this.createNode(node, {
|
|
2395
|
+
type: AST_NODE_TYPES2.UnaryExpression,
|
|
2396
|
+
argument: this.convertChild(node.expression),
|
|
2397
|
+
operator: 'void',
|
|
2398
|
+
prefix: true,
|
|
2399
|
+
});
|
|
2400
|
+
case SyntaxKind6.TypeOfExpression:
|
|
2401
|
+
return this.createNode(node, {
|
|
2402
|
+
type: AST_NODE_TYPES2.UnaryExpression,
|
|
2403
|
+
argument: this.convertChild(node.expression),
|
|
2404
|
+
operator: 'typeof',
|
|
2405
|
+
prefix: true,
|
|
2406
|
+
});
|
|
2407
|
+
case SyntaxKind6.TypeOperator:
|
|
2408
|
+
return this.createNode(node, {
|
|
2409
|
+
type: AST_NODE_TYPES2.TSTypeOperator,
|
|
2410
|
+
operator: (0, getTextForTokenKind)(node.operator),
|
|
2411
|
+
typeAnnotation: this.convertChild(node.type),
|
|
2412
|
+
});
|
|
2413
|
+
// Binary Operations
|
|
2414
|
+
case SyntaxKind6.BinaryExpression: {
|
|
2415
|
+
if (
|
|
2416
|
+
node.operatorToken.kind !== SyntaxKind6.InKeyword &&
|
|
2417
|
+
node.left.kind === SyntaxKind6.PrivateIdentifier
|
|
2418
|
+
) {
|
|
2419
|
+
this.#throwError(
|
|
2420
|
+
node.left,
|
|
2421
|
+
"Private identifiers cannot appear on the right-hand-side of an 'in' expression.",
|
|
2422
|
+
);
|
|
2423
|
+
} else if (node.right.kind === SyntaxKind6.PrivateIdentifier) {
|
|
2424
|
+
this.#throwError(
|
|
2425
|
+
node.right,
|
|
2426
|
+
"Private identifiers are only allowed on the left-hand-side of an 'in' expression.",
|
|
2427
|
+
);
|
|
2428
|
+
}
|
|
2429
|
+
if ((0, isComma)(node.operatorToken)) {
|
|
2430
|
+
const result = this.createNode(node, {
|
|
2431
|
+
type: AST_NODE_TYPES2.SequenceExpression,
|
|
2432
|
+
expressions: [],
|
|
2433
|
+
});
|
|
2434
|
+
const left = this.convertChild(node.left);
|
|
2435
|
+
if (
|
|
2436
|
+
left.type === AST_NODE_TYPES2.SequenceExpression &&
|
|
2437
|
+
node.left.kind !== SyntaxKind6.ParenthesizedExpression
|
|
2438
|
+
) {
|
|
2439
|
+
result.expressions.push(...left.expressions);
|
|
2440
|
+
} else {
|
|
2441
|
+
result.expressions.push(left);
|
|
2442
|
+
}
|
|
2443
|
+
result.expressions.push(this.convertChild(node.right));
|
|
2444
|
+
return result;
|
|
2445
|
+
}
|
|
2446
|
+
const expressionType = (0, getBinaryExpressionType)(node.operatorToken);
|
|
2447
|
+
if (this.allowPattern && expressionType.type === AST_NODE_TYPES2.AssignmentExpression) {
|
|
2448
|
+
return this.createNode(node, {
|
|
2449
|
+
type: AST_NODE_TYPES2.AssignmentPattern,
|
|
2450
|
+
decorators: [],
|
|
2451
|
+
left: this.convertPattern(node.left, node),
|
|
2452
|
+
optional: false,
|
|
2453
|
+
right: this.convertChild(node.right),
|
|
2454
|
+
typeAnnotation: void 0,
|
|
2455
|
+
});
|
|
2456
|
+
}
|
|
2457
|
+
return this.createNode(node, {
|
|
2458
|
+
...expressionType,
|
|
2459
|
+
left: this.converter(node.left, node, expressionType.type === AST_NODE_TYPES2.AssignmentExpression),
|
|
2460
|
+
right: this.convertChild(node.right),
|
|
2461
|
+
});
|
|
2462
|
+
}
|
|
2463
|
+
case SyntaxKind6.PropertyAccessExpression: {
|
|
2464
|
+
const object = this.convertChild(node.expression);
|
|
2465
|
+
const property = this.convertChild(node.name);
|
|
2466
|
+
const computed = false;
|
|
2467
|
+
const result = this.createNode(node, {
|
|
2468
|
+
type: AST_NODE_TYPES2.MemberExpression,
|
|
2469
|
+
computed,
|
|
2470
|
+
object,
|
|
2471
|
+
optional: node.questionDotToken != null,
|
|
2472
|
+
property,
|
|
2473
|
+
});
|
|
2474
|
+
return this.convertChainExpression(result, node);
|
|
2475
|
+
}
|
|
2476
|
+
case SyntaxKind6.ElementAccessExpression: {
|
|
2477
|
+
const object = this.convertChild(node.expression);
|
|
2478
|
+
const property = this.convertChild(node.argumentExpression);
|
|
2479
|
+
const computed = true;
|
|
2480
|
+
const result = this.createNode(node, {
|
|
2481
|
+
type: AST_NODE_TYPES2.MemberExpression,
|
|
2482
|
+
computed,
|
|
2483
|
+
object,
|
|
2484
|
+
optional: node.questionDotToken != null,
|
|
2485
|
+
property,
|
|
2486
|
+
});
|
|
2487
|
+
return this.convertChainExpression(result, node);
|
|
2488
|
+
}
|
|
2489
|
+
case SyntaxKind6.CallExpression: {
|
|
2490
|
+
if (node.expression.kind === SyntaxKind6.ImportKeyword) {
|
|
2491
|
+
if (node.arguments.length !== 1 && node.arguments.length !== 2) {
|
|
2492
|
+
this.#throwUnlessAllowInvalidAST(
|
|
2493
|
+
node.arguments[2] ?? node,
|
|
2494
|
+
'Dynamic import requires exactly one or two arguments.',
|
|
2495
|
+
);
|
|
2496
|
+
}
|
|
2497
|
+
return this.createNode(
|
|
2498
|
+
node,
|
|
2499
|
+
this.#withDeprecatedAliasGetter(
|
|
2500
|
+
{
|
|
2501
|
+
type: AST_NODE_TYPES2.ImportExpression,
|
|
2502
|
+
options: node.arguments[1] ? this.convertChild(node.arguments[1]) : null,
|
|
2503
|
+
source: this.convertChild(node.arguments[0]),
|
|
2504
|
+
},
|
|
2505
|
+
'attributes',
|
|
2506
|
+
'options',
|
|
2507
|
+
true,
|
|
2508
|
+
),
|
|
2509
|
+
);
|
|
2510
|
+
}
|
|
2511
|
+
const callee = this.convertChild(node.expression);
|
|
2512
|
+
const args = this.convertChildren(node.arguments);
|
|
2513
|
+
const typeArguments =
|
|
2514
|
+
node.typeArguments &&
|
|
2515
|
+
this.convertTypeArgumentsToTypeParameterInstantiation(node.typeArguments, node);
|
|
2516
|
+
const result = this.createNode(node, {
|
|
2517
|
+
type: AST_NODE_TYPES2.CallExpression,
|
|
2518
|
+
arguments: args,
|
|
2519
|
+
callee,
|
|
2520
|
+
optional: node.questionDotToken != null,
|
|
2521
|
+
typeArguments,
|
|
2522
|
+
});
|
|
2523
|
+
return this.convertChainExpression(result, node);
|
|
2524
|
+
}
|
|
2525
|
+
case SyntaxKind6.NewExpression: {
|
|
2526
|
+
const typeArguments =
|
|
2527
|
+
node.typeArguments &&
|
|
2528
|
+
this.convertTypeArgumentsToTypeParameterInstantiation(node.typeArguments, node);
|
|
2529
|
+
return this.createNode(node, {
|
|
2530
|
+
type: AST_NODE_TYPES2.NewExpression,
|
|
2531
|
+
arguments: this.convertChildren(node.arguments ?? []),
|
|
2532
|
+
callee: this.convertChild(node.expression),
|
|
2533
|
+
typeArguments,
|
|
2534
|
+
});
|
|
2535
|
+
}
|
|
2536
|
+
case SyntaxKind6.ConditionalExpression:
|
|
2537
|
+
return this.createNode(node, {
|
|
2538
|
+
type: AST_NODE_TYPES2.ConditionalExpression,
|
|
2539
|
+
alternate: this.convertChild(node.whenFalse),
|
|
2540
|
+
consequent: this.convertChild(node.whenTrue),
|
|
2541
|
+
test: this.convertChild(node.condition),
|
|
2542
|
+
});
|
|
2543
|
+
case SyntaxKind6.MetaProperty: {
|
|
2544
|
+
return this.createNode(node, {
|
|
2545
|
+
type: AST_NODE_TYPES2.MetaProperty,
|
|
2546
|
+
meta: this.createNode(
|
|
2547
|
+
// TODO: do we really want to convert it to Token?
|
|
2548
|
+
node.getFirstToken(),
|
|
2549
|
+
{
|
|
2550
|
+
type: AST_NODE_TYPES2.Identifier,
|
|
2551
|
+
decorators: [],
|
|
2552
|
+
name: (0, getTextForTokenKind)(node.keywordToken),
|
|
2553
|
+
optional: false,
|
|
2554
|
+
typeAnnotation: void 0,
|
|
2555
|
+
},
|
|
2556
|
+
),
|
|
2557
|
+
property: this.convertChild(node.name),
|
|
2558
|
+
});
|
|
2559
|
+
}
|
|
2560
|
+
case SyntaxKind6.Decorator: {
|
|
2561
|
+
return this.createNode(node, {
|
|
2562
|
+
type: AST_NODE_TYPES2.Decorator,
|
|
2563
|
+
expression: this.convertChild(node.expression),
|
|
2564
|
+
});
|
|
2565
|
+
}
|
|
2566
|
+
// Literals
|
|
2567
|
+
case SyntaxKind6.StringLiteral: {
|
|
2568
|
+
return this.createNode(node, {
|
|
2569
|
+
type: AST_NODE_TYPES2.Literal,
|
|
2570
|
+
raw: node.getText(),
|
|
2571
|
+
value:
|
|
2572
|
+
parent.kind === SyntaxKind6.JsxAttribute ? (0, unescapeStringLiteralText)(node.text) : node.text,
|
|
2573
|
+
});
|
|
2574
|
+
}
|
|
2575
|
+
case SyntaxKind6.NumericLiteral: {
|
|
2576
|
+
return this.createNode(node, {
|
|
2577
|
+
type: AST_NODE_TYPES2.Literal,
|
|
2578
|
+
raw: node.getText(),
|
|
2579
|
+
value: Number(node.text),
|
|
2580
|
+
});
|
|
2581
|
+
}
|
|
2582
|
+
case SyntaxKind6.BigIntLiteral: {
|
|
2583
|
+
const range = (0, getRange)(node, this.ast);
|
|
2584
|
+
const rawValue = this.ast.text.slice(range[0], range[1]);
|
|
2585
|
+
const bigint = method_replace_all_default(
|
|
2586
|
+
/* OPTIONAL_OBJECT: false */
|
|
2587
|
+
0,
|
|
2588
|
+
rawValue.slice(0, -1),
|
|
2589
|
+
'_',
|
|
2590
|
+
'',
|
|
2591
|
+
);
|
|
2592
|
+
const value = typeof BigInt !== 'undefined' ? BigInt(bigint) : null;
|
|
2593
|
+
return this.createNode(node, {
|
|
2594
|
+
type: AST_NODE_TYPES2.Literal,
|
|
2595
|
+
range,
|
|
2596
|
+
bigint: value == null ? bigint : String(value),
|
|
2597
|
+
raw: rawValue,
|
|
2598
|
+
value,
|
|
2599
|
+
});
|
|
2600
|
+
}
|
|
2601
|
+
case SyntaxKind6.RegularExpressionLiteral: {
|
|
2602
|
+
const pattern = node.text.slice(1, node.text.lastIndexOf('/'));
|
|
2603
|
+
const flags = node.text.slice(node.text.lastIndexOf('/') + 1);
|
|
2604
|
+
let regex = null;
|
|
2605
|
+
try {
|
|
2606
|
+
regex = new RegExp(pattern, flags);
|
|
2607
|
+
} catch {}
|
|
2608
|
+
return this.createNode(node, {
|
|
2609
|
+
type: AST_NODE_TYPES2.Literal,
|
|
2610
|
+
raw: node.text,
|
|
2611
|
+
regex: {
|
|
2612
|
+
flags,
|
|
2613
|
+
pattern,
|
|
2614
|
+
},
|
|
2615
|
+
value: regex,
|
|
2616
|
+
});
|
|
2617
|
+
}
|
|
2618
|
+
case SyntaxKind6.TrueKeyword:
|
|
2619
|
+
return this.createNode(node, {
|
|
2620
|
+
type: AST_NODE_TYPES2.Literal,
|
|
2621
|
+
raw: 'true',
|
|
2622
|
+
value: true,
|
|
2623
|
+
});
|
|
2624
|
+
case SyntaxKind6.FalseKeyword:
|
|
2625
|
+
return this.createNode(node, {
|
|
2626
|
+
type: AST_NODE_TYPES2.Literal,
|
|
2627
|
+
raw: 'false',
|
|
2628
|
+
value: false,
|
|
2629
|
+
});
|
|
2630
|
+
case SyntaxKind6.NullKeyword: {
|
|
2631
|
+
return this.createNode(node, {
|
|
2632
|
+
type: AST_NODE_TYPES2.Literal,
|
|
2633
|
+
raw: 'null',
|
|
2634
|
+
value: null,
|
|
2635
|
+
});
|
|
2636
|
+
}
|
|
2637
|
+
case SyntaxKind6.EmptyStatement:
|
|
2638
|
+
return this.createNode(node, {
|
|
2639
|
+
type: AST_NODE_TYPES2.EmptyStatement,
|
|
2640
|
+
});
|
|
2641
|
+
case SyntaxKind6.DebuggerStatement:
|
|
2642
|
+
return this.createNode(node, {
|
|
2643
|
+
type: AST_NODE_TYPES2.DebuggerStatement,
|
|
2644
|
+
});
|
|
2645
|
+
// JSX
|
|
2646
|
+
case SyntaxKind6.JsxElement:
|
|
2647
|
+
return this.createNode(node, {
|
|
2648
|
+
type: AST_NODE_TYPES2.JSXElement,
|
|
2649
|
+
children: this.convertChildren(node.children),
|
|
2650
|
+
closingElement: this.convertChild(node.closingElement),
|
|
2651
|
+
openingElement: this.convertChild(node.openingElement),
|
|
2652
|
+
});
|
|
2653
|
+
case SyntaxKind6.JsxFragment:
|
|
2654
|
+
return this.createNode(node, {
|
|
2655
|
+
type: AST_NODE_TYPES2.JSXFragment,
|
|
2656
|
+
children: this.convertChildren(node.children),
|
|
2657
|
+
closingFragment: this.convertChild(node.closingFragment),
|
|
2658
|
+
openingFragment: this.convertChild(node.openingFragment),
|
|
2659
|
+
});
|
|
2660
|
+
case SyntaxKind6.JsxSelfClosingElement: {
|
|
2661
|
+
return this.createNode(node, {
|
|
2662
|
+
type: AST_NODE_TYPES2.JSXElement,
|
|
2663
|
+
/**
|
|
2664
|
+
* Convert SyntaxKind.JsxSelfClosingElement to SyntaxKind.JsxOpeningElement,
|
|
2665
|
+
* TypeScript does not seem to have the idea of openingElement when tag is self-closing
|
|
2666
|
+
*/
|
|
2667
|
+
children: [],
|
|
2668
|
+
closingElement: null,
|
|
2669
|
+
openingElement: this.createNode(node, {
|
|
2670
|
+
type: AST_NODE_TYPES2.JSXOpeningElement,
|
|
2671
|
+
range: (0, getRange)(node, this.ast),
|
|
2672
|
+
attributes: this.convertChildren(node.attributes.properties),
|
|
2673
|
+
name: this.convertJSXTagName(node.tagName, node),
|
|
2674
|
+
selfClosing: true,
|
|
2675
|
+
typeArguments: node.typeArguments
|
|
2676
|
+
? this.convertTypeArgumentsToTypeParameterInstantiation(node.typeArguments, node)
|
|
2677
|
+
: void 0,
|
|
2678
|
+
}),
|
|
2679
|
+
});
|
|
2680
|
+
}
|
|
2681
|
+
case SyntaxKind6.JsxOpeningElement: {
|
|
2682
|
+
return this.createNode(node, {
|
|
2683
|
+
type: AST_NODE_TYPES2.JSXOpeningElement,
|
|
2684
|
+
attributes: this.convertChildren(node.attributes.properties),
|
|
2685
|
+
name: this.convertJSXTagName(node.tagName, node),
|
|
2686
|
+
selfClosing: false,
|
|
2687
|
+
typeArguments:
|
|
2688
|
+
node.typeArguments &&
|
|
2689
|
+
this.convertTypeArgumentsToTypeParameterInstantiation(node.typeArguments, node),
|
|
2690
|
+
});
|
|
2691
|
+
}
|
|
2692
|
+
case SyntaxKind6.JsxClosingElement:
|
|
2693
|
+
return this.createNode(node, {
|
|
2694
|
+
type: AST_NODE_TYPES2.JSXClosingElement,
|
|
2695
|
+
name: this.convertJSXTagName(node.tagName, node),
|
|
2696
|
+
});
|
|
2697
|
+
case SyntaxKind6.JsxOpeningFragment:
|
|
2698
|
+
return this.createNode(node, {
|
|
2699
|
+
type: AST_NODE_TYPES2.JSXOpeningFragment,
|
|
2700
|
+
});
|
|
2701
|
+
case SyntaxKind6.JsxClosingFragment:
|
|
2702
|
+
return this.createNode(node, {
|
|
2703
|
+
type: AST_NODE_TYPES2.JSXClosingFragment,
|
|
2704
|
+
});
|
|
2705
|
+
case SyntaxKind6.JsxExpression: {
|
|
2706
|
+
const expression = node.expression
|
|
2707
|
+
? this.convertChild(node.expression)
|
|
2708
|
+
: this.createNode(node, {
|
|
2709
|
+
type: AST_NODE_TYPES2.JSXEmptyExpression,
|
|
2710
|
+
range: [node.getStart(this.ast) + 1, node.getEnd() - 1],
|
|
2711
|
+
});
|
|
2712
|
+
if (node.dotDotDotToken) {
|
|
2713
|
+
return this.createNode(node, {
|
|
2714
|
+
type: AST_NODE_TYPES2.JSXSpreadChild,
|
|
2715
|
+
expression,
|
|
2716
|
+
});
|
|
2717
|
+
}
|
|
2718
|
+
return this.createNode(node, {
|
|
2719
|
+
type: AST_NODE_TYPES2.JSXExpressionContainer,
|
|
2720
|
+
expression,
|
|
2721
|
+
});
|
|
2722
|
+
}
|
|
2723
|
+
case SyntaxKind6.JsxAttribute: {
|
|
2724
|
+
return this.createNode(node, {
|
|
2725
|
+
type: AST_NODE_TYPES2.JSXAttribute,
|
|
2726
|
+
name: this.convertJSXNamespaceOrIdentifier(node.name),
|
|
2727
|
+
value: this.convertChild(node.initializer),
|
|
2728
|
+
});
|
|
2729
|
+
}
|
|
2730
|
+
case SyntaxKind6.JsxText: {
|
|
2731
|
+
const start = node.getFullStart();
|
|
2732
|
+
const end = node.getEnd();
|
|
2733
|
+
const text = this.ast.text.slice(start, end);
|
|
2734
|
+
return this.createNode(node, {
|
|
2735
|
+
type: AST_NODE_TYPES2.JSXText,
|
|
2736
|
+
range: [start, end],
|
|
2737
|
+
raw: text,
|
|
2738
|
+
value: (0, unescapeStringLiteralText)(text),
|
|
2739
|
+
});
|
|
2740
|
+
}
|
|
2741
|
+
case SyntaxKind6.JsxSpreadAttribute:
|
|
2742
|
+
return this.createNode(node, {
|
|
2743
|
+
type: AST_NODE_TYPES2.JSXSpreadAttribute,
|
|
2744
|
+
argument: this.convertChild(node.expression),
|
|
2745
|
+
});
|
|
2746
|
+
case SyntaxKind6.QualifiedName: {
|
|
2747
|
+
return this.createNode(node, {
|
|
2748
|
+
type: AST_NODE_TYPES2.TSQualifiedName,
|
|
2749
|
+
left: this.convertChild(node.left),
|
|
2750
|
+
right: this.convertChild(node.right),
|
|
2751
|
+
});
|
|
2752
|
+
}
|
|
2753
|
+
// TypeScript specific
|
|
2754
|
+
case SyntaxKind6.TypeReference:
|
|
2755
|
+
return this.createNode(node, {
|
|
2756
|
+
type: AST_NODE_TYPES2.TSTypeReference,
|
|
2757
|
+
typeArguments:
|
|
2758
|
+
node.typeArguments &&
|
|
2759
|
+
this.convertTypeArgumentsToTypeParameterInstantiation(node.typeArguments, node),
|
|
2760
|
+
typeName: this.convertChild(node.typeName),
|
|
2761
|
+
});
|
|
2762
|
+
case SyntaxKind6.TypeParameter: {
|
|
2763
|
+
return this.createNode(node, {
|
|
2764
|
+
type: AST_NODE_TYPES2.TSTypeParameter,
|
|
2765
|
+
const: (0, hasModifier)(SyntaxKind6.ConstKeyword, node),
|
|
2766
|
+
constraint: node.constraint && this.convertChild(node.constraint),
|
|
2767
|
+
default: node.default ? this.convertChild(node.default) : void 0,
|
|
2768
|
+
in: (0, hasModifier)(SyntaxKind6.InKeyword, node),
|
|
2769
|
+
name: this.convertChild(node.name),
|
|
2770
|
+
out: (0, hasModifier)(SyntaxKind6.OutKeyword, node),
|
|
2771
|
+
});
|
|
2772
|
+
}
|
|
2773
|
+
case SyntaxKind6.ThisType:
|
|
2774
|
+
return this.createNode(node, {
|
|
2775
|
+
type: AST_NODE_TYPES2.TSThisType,
|
|
2776
|
+
});
|
|
2777
|
+
case SyntaxKind6.AnyKeyword:
|
|
2778
|
+
case SyntaxKind6.BigIntKeyword:
|
|
2779
|
+
case SyntaxKind6.BooleanKeyword:
|
|
2780
|
+
case SyntaxKind6.NeverKeyword:
|
|
2781
|
+
case SyntaxKind6.NumberKeyword:
|
|
2782
|
+
case SyntaxKind6.ObjectKeyword:
|
|
2783
|
+
case SyntaxKind6.StringKeyword:
|
|
2784
|
+
case SyntaxKind6.SymbolKeyword:
|
|
2785
|
+
case SyntaxKind6.UnknownKeyword:
|
|
2786
|
+
case SyntaxKind6.VoidKeyword:
|
|
2787
|
+
case SyntaxKind6.UndefinedKeyword:
|
|
2788
|
+
case SyntaxKind6.IntrinsicKeyword: {
|
|
2789
|
+
return this.createNode(node, {
|
|
2790
|
+
type: AST_NODE_TYPES2[`TS${SyntaxKind6[node.kind]}`],
|
|
2791
|
+
});
|
|
2792
|
+
}
|
|
2793
|
+
case SyntaxKind6.NonNullExpression: {
|
|
2794
|
+
const nnExpr = this.createNode(node, {
|
|
2795
|
+
type: AST_NODE_TYPES2.TSNonNullExpression,
|
|
2796
|
+
expression: this.convertChild(node.expression),
|
|
2797
|
+
});
|
|
2798
|
+
return this.convertChainExpression(nnExpr, node);
|
|
2799
|
+
}
|
|
2800
|
+
case SyntaxKind6.TypeLiteral: {
|
|
2801
|
+
return this.createNode(node, {
|
|
2802
|
+
type: AST_NODE_TYPES2.TSTypeLiteral,
|
|
2803
|
+
members: this.convertChildren(node.members),
|
|
2804
|
+
});
|
|
2805
|
+
}
|
|
2806
|
+
case SyntaxKind6.ArrayType: {
|
|
2807
|
+
return this.createNode(node, {
|
|
2808
|
+
type: AST_NODE_TYPES2.TSArrayType,
|
|
2809
|
+
elementType: this.convertChild(node.elementType),
|
|
2810
|
+
});
|
|
2811
|
+
}
|
|
2812
|
+
case SyntaxKind6.IndexedAccessType: {
|
|
2813
|
+
return this.createNode(node, {
|
|
2814
|
+
type: AST_NODE_TYPES2.TSIndexedAccessType,
|
|
2815
|
+
indexType: this.convertChild(node.indexType),
|
|
2816
|
+
objectType: this.convertChild(node.objectType),
|
|
2817
|
+
});
|
|
2818
|
+
}
|
|
2819
|
+
case SyntaxKind6.ConditionalType: {
|
|
2820
|
+
return this.createNode(node, {
|
|
2821
|
+
type: AST_NODE_TYPES2.TSConditionalType,
|
|
2822
|
+
checkType: this.convertChild(node.checkType),
|
|
2823
|
+
extendsType: this.convertChild(node.extendsType),
|
|
2824
|
+
falseType: this.convertChild(node.falseType),
|
|
2825
|
+
trueType: this.convertChild(node.trueType),
|
|
2826
|
+
});
|
|
2827
|
+
}
|
|
2828
|
+
case SyntaxKind6.TypeQuery:
|
|
2829
|
+
return this.createNode(node, {
|
|
2830
|
+
type: AST_NODE_TYPES2.TSTypeQuery,
|
|
2831
|
+
exprName: this.convertChild(node.exprName),
|
|
2832
|
+
typeArguments:
|
|
2833
|
+
node.typeArguments &&
|
|
2834
|
+
this.convertTypeArgumentsToTypeParameterInstantiation(node.typeArguments, node),
|
|
2835
|
+
});
|
|
2836
|
+
case SyntaxKind6.MappedType: {
|
|
2837
|
+
if (node.members && node.members.length > 0) {
|
|
2838
|
+
this.#throwUnlessAllowInvalidAST(
|
|
2839
|
+
node.members[0],
|
|
2840
|
+
'A mapped type may not declare properties or methods.',
|
|
2841
|
+
);
|
|
2842
|
+
}
|
|
2843
|
+
return this.createNode(
|
|
2844
|
+
node,
|
|
2845
|
+
this.#withDeprecatedGetter(
|
|
2846
|
+
{
|
|
2847
|
+
type: AST_NODE_TYPES2.TSMappedType,
|
|
2848
|
+
constraint: this.convertChild(node.typeParameter.constraint),
|
|
2849
|
+
key: this.convertChild(node.typeParameter.name),
|
|
2850
|
+
nameType: this.convertChild(node.nameType) ?? null,
|
|
2851
|
+
optional: node.questionToken
|
|
2852
|
+
? node.questionToken.kind === SyntaxKind6.QuestionToken ||
|
|
2853
|
+
(0, getTextForTokenKind)(node.questionToken.kind)
|
|
2854
|
+
: false,
|
|
2855
|
+
readonly: node.readonlyToken
|
|
2856
|
+
? node.readonlyToken.kind === SyntaxKind6.ReadonlyKeyword ||
|
|
2857
|
+
(0, getTextForTokenKind)(node.readonlyToken.kind)
|
|
2858
|
+
: void 0,
|
|
2859
|
+
typeAnnotation: node.type && this.convertChild(node.type),
|
|
2860
|
+
},
|
|
2861
|
+
'typeParameter',
|
|
2862
|
+
"'constraint' and 'key'",
|
|
2863
|
+
this.convertChild(node.typeParameter),
|
|
2864
|
+
),
|
|
2865
|
+
);
|
|
2866
|
+
}
|
|
2867
|
+
case SyntaxKind6.ParenthesizedExpression:
|
|
2868
|
+
return this.convertChild(node.expression, parent);
|
|
2869
|
+
case SyntaxKind6.TypeAliasDeclaration: {
|
|
2870
|
+
const result = this.createNode(node, {
|
|
2871
|
+
type: AST_NODE_TYPES2.TSTypeAliasDeclaration,
|
|
2872
|
+
declare: (0, hasModifier)(SyntaxKind6.DeclareKeyword, node),
|
|
2873
|
+
id: this.convertChild(node.name),
|
|
2874
|
+
typeAnnotation: this.convertChild(node.type),
|
|
2875
|
+
typeParameters:
|
|
2876
|
+
node.typeParameters &&
|
|
2877
|
+
this.convertTSTypeParametersToTypeParametersDeclaration(node.typeParameters),
|
|
2878
|
+
});
|
|
2879
|
+
return this.fixExports(node, result);
|
|
2880
|
+
}
|
|
2881
|
+
case SyntaxKind6.MethodSignature: {
|
|
2882
|
+
return this.convertMethodSignature(node);
|
|
2883
|
+
}
|
|
2884
|
+
case SyntaxKind6.PropertySignature: {
|
|
2885
|
+
const { initializer } = node;
|
|
2886
|
+
if (initializer) {
|
|
2887
|
+
this.#throwError(initializer, 'A property signature cannot have an initializer.');
|
|
2888
|
+
}
|
|
2889
|
+
return this.createNode(node, {
|
|
2890
|
+
type: AST_NODE_TYPES2.TSPropertySignature,
|
|
2891
|
+
accessibility: (0, getTSNodeAccessibility)(node),
|
|
2892
|
+
computed: (0, isComputedProperty)(node.name),
|
|
2893
|
+
key: this.convertChild(node.name),
|
|
2894
|
+
optional: (0, isOptional)(node),
|
|
2895
|
+
readonly: (0, hasModifier)(SyntaxKind6.ReadonlyKeyword, node),
|
|
2896
|
+
static: (0, hasModifier)(SyntaxKind6.StaticKeyword, node),
|
|
2897
|
+
typeAnnotation: node.type && this.convertTypeAnnotation(node.type, node),
|
|
2898
|
+
});
|
|
2899
|
+
}
|
|
2900
|
+
case SyntaxKind6.IndexSignature: {
|
|
2901
|
+
return this.createNode(node, {
|
|
2902
|
+
type: AST_NODE_TYPES2.TSIndexSignature,
|
|
2903
|
+
accessibility: (0, getTSNodeAccessibility)(node),
|
|
2904
|
+
parameters: this.convertChildren(node.parameters),
|
|
2905
|
+
readonly: (0, hasModifier)(SyntaxKind6.ReadonlyKeyword, node),
|
|
2906
|
+
static: (0, hasModifier)(SyntaxKind6.StaticKeyword, node),
|
|
2907
|
+
typeAnnotation: node.type && this.convertTypeAnnotation(node.type, node),
|
|
2908
|
+
});
|
|
2909
|
+
}
|
|
2910
|
+
case SyntaxKind6.ConstructorType: {
|
|
2911
|
+
return this.createNode(node, {
|
|
2912
|
+
type: AST_NODE_TYPES2.TSConstructorType,
|
|
2913
|
+
abstract: (0, hasModifier)(SyntaxKind6.AbstractKeyword, node),
|
|
2914
|
+
params: this.convertParameters(node.parameters),
|
|
2915
|
+
returnType: node.type && this.convertTypeAnnotation(node.type, node),
|
|
2916
|
+
typeParameters:
|
|
2917
|
+
node.typeParameters &&
|
|
2918
|
+
this.convertTSTypeParametersToTypeParametersDeclaration(node.typeParameters),
|
|
2919
|
+
});
|
|
2920
|
+
}
|
|
2921
|
+
case SyntaxKind6.FunctionType: {
|
|
2922
|
+
const { modifiers } = node;
|
|
2923
|
+
if (modifiers) {
|
|
2924
|
+
this.#throwError(modifiers[0], 'A function type cannot have modifiers.');
|
|
2925
|
+
}
|
|
2926
|
+
}
|
|
2927
|
+
// intentional fallthrough
|
|
2928
|
+
case SyntaxKind6.ConstructSignature:
|
|
2929
|
+
case SyntaxKind6.CallSignature: {
|
|
2930
|
+
const type =
|
|
2931
|
+
node.kind === SyntaxKind6.ConstructSignature
|
|
2932
|
+
? AST_NODE_TYPES2.TSConstructSignatureDeclaration
|
|
2933
|
+
: node.kind === SyntaxKind6.CallSignature
|
|
2934
|
+
? AST_NODE_TYPES2.TSCallSignatureDeclaration
|
|
2935
|
+
: AST_NODE_TYPES2.TSFunctionType;
|
|
2936
|
+
return this.createNode(node, {
|
|
2937
|
+
type,
|
|
2938
|
+
params: this.convertParameters(node.parameters),
|
|
2939
|
+
returnType: node.type && this.convertTypeAnnotation(node.type, node),
|
|
2940
|
+
typeParameters:
|
|
2941
|
+
node.typeParameters &&
|
|
2942
|
+
this.convertTSTypeParametersToTypeParametersDeclaration(node.typeParameters),
|
|
2943
|
+
});
|
|
2944
|
+
}
|
|
2945
|
+
case SyntaxKind6.ExpressionWithTypeArguments: {
|
|
2946
|
+
const parentKind = parent.kind;
|
|
2947
|
+
const type =
|
|
2948
|
+
parentKind === SyntaxKind6.InterfaceDeclaration
|
|
2949
|
+
? AST_NODE_TYPES2.TSInterfaceHeritage
|
|
2950
|
+
: parentKind === SyntaxKind6.HeritageClause
|
|
2951
|
+
? AST_NODE_TYPES2.TSClassImplements
|
|
2952
|
+
: AST_NODE_TYPES2.TSInstantiationExpression;
|
|
2953
|
+
return this.createNode(node, {
|
|
2954
|
+
type,
|
|
2955
|
+
expression: this.convertChild(node.expression),
|
|
2956
|
+
typeArguments:
|
|
2957
|
+
node.typeArguments &&
|
|
2958
|
+
this.convertTypeArgumentsToTypeParameterInstantiation(node.typeArguments, node),
|
|
2959
|
+
});
|
|
2960
|
+
}
|
|
2961
|
+
case SyntaxKind6.InterfaceDeclaration: {
|
|
2962
|
+
const interfaceHeritageClauses = node.heritageClauses ?? [];
|
|
2963
|
+
const interfaceExtends = [];
|
|
2964
|
+
let seenExtendsClause = false;
|
|
2965
|
+
for (const heritageClause of interfaceHeritageClauses) {
|
|
2966
|
+
if (heritageClause.token !== SyntaxKind6.ExtendsKeyword) {
|
|
2967
|
+
this.#throwError(
|
|
2968
|
+
heritageClause,
|
|
2969
|
+
heritageClause.token === SyntaxKind6.ImplementsKeyword
|
|
2970
|
+
? "Interface declaration cannot have 'implements' clause."
|
|
2971
|
+
: 'Unexpected token.',
|
|
2972
|
+
);
|
|
2973
|
+
}
|
|
2974
|
+
if (seenExtendsClause) {
|
|
2975
|
+
this.#throwError(heritageClause, "'extends' clause already seen.");
|
|
2976
|
+
}
|
|
2977
|
+
seenExtendsClause = true;
|
|
2978
|
+
for (const heritageType of heritageClause.types) {
|
|
2979
|
+
if (
|
|
2980
|
+
!isEntityNameExpression(heritageType.expression) ||
|
|
2981
|
+
ts.isOptionalChain(heritageType.expression)
|
|
2982
|
+
) {
|
|
2983
|
+
this.#throwError(
|
|
2984
|
+
heritageType,
|
|
2985
|
+
'Interface declaration can only extend an identifier/qualified name with optional type arguments.',
|
|
2986
|
+
);
|
|
2987
|
+
}
|
|
2988
|
+
interfaceExtends.push(this.convertChild(heritageType, node));
|
|
2989
|
+
}
|
|
2990
|
+
}
|
|
2991
|
+
const result = this.createNode(node, {
|
|
2992
|
+
type: AST_NODE_TYPES2.TSInterfaceDeclaration,
|
|
2993
|
+
body: this.createNode(node, {
|
|
2994
|
+
type: AST_NODE_TYPES2.TSInterfaceBody,
|
|
2995
|
+
range: [node.members.pos - 1, node.end],
|
|
2996
|
+
body: this.convertChildren(node.members),
|
|
2997
|
+
}),
|
|
2998
|
+
declare: (0, hasModifier)(SyntaxKind6.DeclareKeyword, node),
|
|
2999
|
+
extends: interfaceExtends,
|
|
3000
|
+
id: this.convertChild(node.name),
|
|
3001
|
+
typeParameters:
|
|
3002
|
+
node.typeParameters &&
|
|
3003
|
+
this.convertTSTypeParametersToTypeParametersDeclaration(node.typeParameters),
|
|
3004
|
+
});
|
|
3005
|
+
return this.fixExports(node, result);
|
|
3006
|
+
}
|
|
3007
|
+
case SyntaxKind6.TypePredicate: {
|
|
3008
|
+
const result = this.createNode(node, {
|
|
3009
|
+
type: AST_NODE_TYPES2.TSTypePredicate,
|
|
3010
|
+
asserts: node.assertsModifier != null,
|
|
3011
|
+
parameterName: this.convertChild(node.parameterName),
|
|
3012
|
+
typeAnnotation: null,
|
|
3013
|
+
});
|
|
3014
|
+
if (node.type) {
|
|
3015
|
+
result.typeAnnotation = this.convertTypeAnnotation(node.type, node);
|
|
3016
|
+
result.typeAnnotation.loc = result.typeAnnotation.typeAnnotation.loc;
|
|
3017
|
+
result.typeAnnotation.range = result.typeAnnotation.typeAnnotation.range;
|
|
3018
|
+
}
|
|
3019
|
+
return result;
|
|
3020
|
+
}
|
|
3021
|
+
case SyntaxKind6.ImportType: {
|
|
3022
|
+
const range = (0, getRange)(node, this.ast);
|
|
3023
|
+
if (node.isTypeOf) {
|
|
3024
|
+
const token = (0, findNextToken)(node.getFirstToken(), node, this.ast);
|
|
3025
|
+
range[0] = token.getStart(this.ast);
|
|
3026
|
+
}
|
|
3027
|
+
let options = null;
|
|
3028
|
+
if (node.attributes) {
|
|
3029
|
+
const value = this.createNode(node.attributes, {
|
|
3030
|
+
type: AST_NODE_TYPES2.ObjectExpression,
|
|
3031
|
+
properties: node.attributes.elements.map((importAttribute) =>
|
|
3032
|
+
this.createNode(importAttribute, {
|
|
3033
|
+
type: AST_NODE_TYPES2.Property,
|
|
3034
|
+
computed: false,
|
|
3035
|
+
key: this.convertChild(importAttribute.name),
|
|
3036
|
+
kind: 'init',
|
|
3037
|
+
method: false,
|
|
3038
|
+
optional: false,
|
|
3039
|
+
shorthand: false,
|
|
3040
|
+
value: this.convertChild(importAttribute.value),
|
|
3041
|
+
}),
|
|
3042
|
+
),
|
|
3043
|
+
});
|
|
3044
|
+
const commaToken = (0, findNextToken)(node.argument, node, this.ast);
|
|
3045
|
+
const openBraceToken = (0, findNextToken)(commaToken, node, this.ast);
|
|
3046
|
+
const tokenAfterAttributes = (0, findNextToken)(node.attributes, node, this.ast);
|
|
3047
|
+
const closeBraceToken =
|
|
3048
|
+
tokenAfterAttributes.kind === ts.SyntaxKind.CommaToken
|
|
3049
|
+
? (0, findNextToken)(tokenAfterAttributes, node, this.ast)
|
|
3050
|
+
: tokenAfterAttributes;
|
|
3051
|
+
const withOrAssertToken = (0, findNextToken)(openBraceToken, node, this.ast);
|
|
3052
|
+
const withOrAssertTokenRange = (0, getRange)(withOrAssertToken, this.ast);
|
|
3053
|
+
const withOrAssertName = withOrAssertToken.kind === ts.SyntaxKind.AssertKeyword ? 'assert' : 'with';
|
|
3054
|
+
options = this.createNode(node, {
|
|
3055
|
+
type: AST_NODE_TYPES2.ObjectExpression,
|
|
3056
|
+
range: [openBraceToken.getStart(this.ast), closeBraceToken.end],
|
|
3057
|
+
properties: [
|
|
3058
|
+
this.createNode(node, {
|
|
3059
|
+
type: AST_NODE_TYPES2.Property,
|
|
3060
|
+
range: [withOrAssertTokenRange[0], node.attributes.end],
|
|
3061
|
+
computed: false,
|
|
3062
|
+
key: this.createNode(node, {
|
|
3063
|
+
type: AST_NODE_TYPES2.Identifier,
|
|
3064
|
+
range: withOrAssertTokenRange,
|
|
3065
|
+
decorators: [],
|
|
3066
|
+
name: withOrAssertName,
|
|
3067
|
+
optional: false,
|
|
3068
|
+
typeAnnotation: void 0,
|
|
3069
|
+
}),
|
|
3070
|
+
kind: 'init',
|
|
3071
|
+
method: false,
|
|
3072
|
+
optional: false,
|
|
3073
|
+
shorthand: false,
|
|
3074
|
+
value,
|
|
3075
|
+
}),
|
|
3076
|
+
],
|
|
3077
|
+
});
|
|
3078
|
+
}
|
|
3079
|
+
const result = this.createNode(node, {
|
|
3080
|
+
type: AST_NODE_TYPES2.TSImportType,
|
|
3081
|
+
range,
|
|
3082
|
+
argument: this.convertChild(node.argument),
|
|
3083
|
+
options,
|
|
3084
|
+
qualifier: this.convertChild(node.qualifier),
|
|
3085
|
+
typeArguments: node.typeArguments
|
|
3086
|
+
? this.convertTypeArgumentsToTypeParameterInstantiation(node.typeArguments, node)
|
|
3087
|
+
: null,
|
|
3088
|
+
});
|
|
3089
|
+
if (node.isTypeOf) {
|
|
3090
|
+
return this.createNode(node, {
|
|
3091
|
+
type: AST_NODE_TYPES2.TSTypeQuery,
|
|
3092
|
+
exprName: result,
|
|
3093
|
+
typeArguments: void 0,
|
|
3094
|
+
});
|
|
3095
|
+
}
|
|
3096
|
+
return result;
|
|
3097
|
+
}
|
|
3098
|
+
case SyntaxKind6.EnumDeclaration: {
|
|
3099
|
+
const members = this.convertChildren(node.members);
|
|
3100
|
+
const result = this.createNode(
|
|
3101
|
+
node,
|
|
3102
|
+
this.#withDeprecatedGetter(
|
|
3103
|
+
{
|
|
3104
|
+
type: AST_NODE_TYPES2.TSEnumDeclaration,
|
|
3105
|
+
body: this.createNode(node, {
|
|
3106
|
+
type: AST_NODE_TYPES2.TSEnumBody,
|
|
3107
|
+
range: [node.members.pos - 1, node.end],
|
|
3108
|
+
members,
|
|
3109
|
+
}),
|
|
3110
|
+
const: (0, hasModifier)(SyntaxKind6.ConstKeyword, node),
|
|
3111
|
+
declare: (0, hasModifier)(SyntaxKind6.DeclareKeyword, node),
|
|
3112
|
+
id: this.convertChild(node.name),
|
|
3113
|
+
},
|
|
3114
|
+
'members',
|
|
3115
|
+
`'body.members'`,
|
|
3116
|
+
this.convertChildren(node.members),
|
|
3117
|
+
),
|
|
3118
|
+
);
|
|
3119
|
+
return this.fixExports(node, result);
|
|
3120
|
+
}
|
|
3121
|
+
case SyntaxKind6.EnumMember: {
|
|
3122
|
+
const computed = node.name.kind === ts.SyntaxKind.ComputedPropertyName;
|
|
3123
|
+
if (computed) {
|
|
3124
|
+
this.#throwUnlessAllowInvalidAST(node.name, 'Computed property names are not allowed in enums.');
|
|
3125
|
+
}
|
|
3126
|
+
if (node.name.kind === SyntaxKind6.NumericLiteral || node.name.kind === SyntaxKind6.BigIntLiteral) {
|
|
3127
|
+
this.#throwUnlessAllowInvalidAST(node.name, 'An enum member cannot have a numeric name.');
|
|
3128
|
+
}
|
|
3129
|
+
return this.createNode(
|
|
3130
|
+
node,
|
|
3131
|
+
this.#withDeprecatedGetter(
|
|
3132
|
+
{
|
|
3133
|
+
type: AST_NODE_TYPES2.TSEnumMember,
|
|
3134
|
+
id: this.convertChild(node.name),
|
|
3135
|
+
initializer: node.initializer && this.convertChild(node.initializer),
|
|
3136
|
+
},
|
|
3137
|
+
'computed',
|
|
3138
|
+
void 0,
|
|
3139
|
+
computed,
|
|
3140
|
+
),
|
|
3141
|
+
);
|
|
3142
|
+
}
|
|
3143
|
+
case SyntaxKind6.ModuleDeclaration: {
|
|
3144
|
+
let isDeclare = (0, hasModifier)(SyntaxKind6.DeclareKeyword, node);
|
|
3145
|
+
const result = this.createNode(node, {
|
|
3146
|
+
type: AST_NODE_TYPES2.TSModuleDeclaration,
|
|
3147
|
+
...(() => {
|
|
3148
|
+
if (node.flags & ts.NodeFlags.GlobalAugmentation) {
|
|
3149
|
+
const id = this.convertChild(node.name);
|
|
3150
|
+
const body = this.convertChild(node.body);
|
|
3151
|
+
if (body == null || body.type === AST_NODE_TYPES2.TSModuleDeclaration) {
|
|
3152
|
+
this.#throwUnlessAllowInvalidAST(node.body ?? node, 'Expected a valid module body');
|
|
3153
|
+
}
|
|
3154
|
+
if (id.type !== AST_NODE_TYPES2.Identifier) {
|
|
3155
|
+
this.#throwUnlessAllowInvalidAST(
|
|
3156
|
+
node.name,
|
|
3157
|
+
'global module augmentation must have an Identifier id',
|
|
3158
|
+
);
|
|
3159
|
+
}
|
|
3160
|
+
return {
|
|
3161
|
+
body,
|
|
3162
|
+
declare: false,
|
|
3163
|
+
global: false,
|
|
3164
|
+
id,
|
|
3165
|
+
kind: 'global',
|
|
3166
|
+
};
|
|
3167
|
+
}
|
|
3168
|
+
if (ts.isStringLiteral(node.name)) {
|
|
3169
|
+
const body = this.convertChild(node.body);
|
|
3170
|
+
return {
|
|
3171
|
+
kind: 'module',
|
|
3172
|
+
...(body != null
|
|
3173
|
+
? {
|
|
3174
|
+
body,
|
|
3175
|
+
}
|
|
3176
|
+
: {}),
|
|
3177
|
+
declare: false,
|
|
3178
|
+
global: false,
|
|
3179
|
+
id: this.convertChild(node.name),
|
|
3180
|
+
};
|
|
3181
|
+
}
|
|
3182
|
+
if (node.body == null) {
|
|
3183
|
+
this.#throwUnlessAllowInvalidAST(node, 'Expected a module body');
|
|
3184
|
+
}
|
|
3185
|
+
if (node.name.kind !== ts.SyntaxKind.Identifier) {
|
|
3186
|
+
this.#throwUnlessAllowInvalidAST(node.name, '`namespace`s must have an Identifier id');
|
|
3187
|
+
}
|
|
3188
|
+
let name = this.createNode(node.name, {
|
|
3189
|
+
type: AST_NODE_TYPES2.Identifier,
|
|
3190
|
+
range: [node.name.getStart(this.ast), node.name.getEnd()],
|
|
3191
|
+
decorators: [],
|
|
3192
|
+
name: node.name.text,
|
|
3193
|
+
optional: false,
|
|
3194
|
+
typeAnnotation: void 0,
|
|
3195
|
+
});
|
|
3196
|
+
while (node.body && ts.isModuleDeclaration(node.body) && node.body.name) {
|
|
3197
|
+
node = node.body;
|
|
3198
|
+
isDeclare || (isDeclare = (0, hasModifier)(SyntaxKind6.DeclareKeyword, node));
|
|
3199
|
+
const nextName = node.name;
|
|
3200
|
+
const right = this.createNode(nextName, {
|
|
3201
|
+
type: AST_NODE_TYPES2.Identifier,
|
|
3202
|
+
range: [nextName.getStart(this.ast), nextName.getEnd()],
|
|
3203
|
+
decorators: [],
|
|
3204
|
+
name: nextName.text,
|
|
3205
|
+
optional: false,
|
|
3206
|
+
typeAnnotation: void 0,
|
|
3207
|
+
});
|
|
3208
|
+
name = this.createNode(nextName, {
|
|
3209
|
+
type: AST_NODE_TYPES2.TSQualifiedName,
|
|
3210
|
+
range: [name.range[0], right.range[1]],
|
|
3211
|
+
left: name,
|
|
3212
|
+
right,
|
|
3213
|
+
});
|
|
3214
|
+
}
|
|
3215
|
+
return {
|
|
3216
|
+
body: this.convertChild(node.body),
|
|
3217
|
+
declare: false,
|
|
3218
|
+
global: false,
|
|
3219
|
+
id: name,
|
|
3220
|
+
kind: node.flags & ts.NodeFlags.Namespace ? 'namespace' : 'module',
|
|
3221
|
+
};
|
|
3222
|
+
})(),
|
|
3223
|
+
});
|
|
3224
|
+
result.declare = isDeclare;
|
|
3225
|
+
if (node.flags & ts.NodeFlags.GlobalAugmentation) {
|
|
3226
|
+
result.global = true;
|
|
3227
|
+
}
|
|
3228
|
+
return this.fixExports(node, result);
|
|
3229
|
+
}
|
|
3230
|
+
// TypeScript specific types
|
|
3231
|
+
case SyntaxKind6.ParenthesizedType: {
|
|
3232
|
+
return this.convertChild(node.type);
|
|
3233
|
+
}
|
|
3234
|
+
case SyntaxKind6.UnionType: {
|
|
3235
|
+
return this.createNode(node, {
|
|
3236
|
+
type: AST_NODE_TYPES2.TSUnionType,
|
|
3237
|
+
types: this.convertChildren(node.types),
|
|
3238
|
+
});
|
|
3239
|
+
}
|
|
3240
|
+
case SyntaxKind6.IntersectionType: {
|
|
3241
|
+
return this.createNode(node, {
|
|
3242
|
+
type: AST_NODE_TYPES2.TSIntersectionType,
|
|
3243
|
+
types: this.convertChildren(node.types),
|
|
3244
|
+
});
|
|
3245
|
+
}
|
|
3246
|
+
case SyntaxKind6.AsExpression: {
|
|
3247
|
+
return this.createNode(node, {
|
|
3248
|
+
type: AST_NODE_TYPES2.TSAsExpression,
|
|
3249
|
+
expression: this.convertChild(node.expression),
|
|
3250
|
+
typeAnnotation: this.convertChild(node.type),
|
|
3251
|
+
});
|
|
3252
|
+
}
|
|
3253
|
+
case SyntaxKind6.InferType: {
|
|
3254
|
+
return this.createNode(node, {
|
|
3255
|
+
type: AST_NODE_TYPES2.TSInferType,
|
|
3256
|
+
typeParameter: this.convertChild(node.typeParameter),
|
|
3257
|
+
});
|
|
3258
|
+
}
|
|
3259
|
+
case SyntaxKind6.LiteralType: {
|
|
3260
|
+
if (node.literal.kind === SyntaxKind6.NullKeyword) {
|
|
3261
|
+
return this.createNode(node.literal, {
|
|
3262
|
+
type: AST_NODE_TYPES2.TSNullKeyword,
|
|
3263
|
+
});
|
|
3264
|
+
}
|
|
3265
|
+
return this.createNode(node, {
|
|
3266
|
+
type: AST_NODE_TYPES2.TSLiteralType,
|
|
3267
|
+
literal: this.convertChild(node.literal),
|
|
3268
|
+
});
|
|
3269
|
+
}
|
|
3270
|
+
case SyntaxKind6.TypeAssertionExpression: {
|
|
3271
|
+
return this.createNode(node, {
|
|
3272
|
+
type: AST_NODE_TYPES2.TSTypeAssertion,
|
|
3273
|
+
expression: this.convertChild(node.expression),
|
|
3274
|
+
typeAnnotation: this.convertChild(node.type),
|
|
3275
|
+
});
|
|
3276
|
+
}
|
|
3277
|
+
case SyntaxKind6.ImportEqualsDeclaration: {
|
|
3278
|
+
return this.fixExports(
|
|
3279
|
+
node,
|
|
3280
|
+
this.createNode(node, {
|
|
3281
|
+
type: AST_NODE_TYPES2.TSImportEqualsDeclaration,
|
|
3282
|
+
id: this.convertChild(node.name),
|
|
3283
|
+
importKind: node.isTypeOnly ? 'type' : 'value',
|
|
3284
|
+
moduleReference: this.convertChild(node.moduleReference),
|
|
3285
|
+
}),
|
|
3286
|
+
);
|
|
3287
|
+
}
|
|
3288
|
+
case SyntaxKind6.ExternalModuleReference: {
|
|
3289
|
+
if (node.expression.kind !== SyntaxKind6.StringLiteral) {
|
|
3290
|
+
this.#throwError(node.expression, 'String literal expected.');
|
|
3291
|
+
}
|
|
3292
|
+
return this.createNode(node, {
|
|
3293
|
+
type: AST_NODE_TYPES2.TSExternalModuleReference,
|
|
3294
|
+
expression: this.convertChild(node.expression),
|
|
3295
|
+
});
|
|
3296
|
+
}
|
|
3297
|
+
case SyntaxKind6.NamespaceExportDeclaration: {
|
|
3298
|
+
return this.createNode(node, {
|
|
3299
|
+
type: AST_NODE_TYPES2.TSNamespaceExportDeclaration,
|
|
3300
|
+
id: this.convertChild(node.name),
|
|
3301
|
+
});
|
|
3302
|
+
}
|
|
3303
|
+
case SyntaxKind6.AbstractKeyword: {
|
|
3304
|
+
return this.createNode(node, {
|
|
3305
|
+
type: AST_NODE_TYPES2.TSAbstractKeyword,
|
|
3306
|
+
});
|
|
3307
|
+
}
|
|
3308
|
+
// Tuple
|
|
3309
|
+
case SyntaxKind6.TupleType: {
|
|
3310
|
+
const elementTypes = this.convertChildren(node.elements);
|
|
3311
|
+
return this.createNode(node, {
|
|
3312
|
+
type: AST_NODE_TYPES2.TSTupleType,
|
|
3313
|
+
elementTypes,
|
|
3314
|
+
});
|
|
3315
|
+
}
|
|
3316
|
+
case SyntaxKind6.NamedTupleMember: {
|
|
3317
|
+
const member = this.createNode(node, {
|
|
3318
|
+
type: AST_NODE_TYPES2.TSNamedTupleMember,
|
|
3319
|
+
elementType: this.convertChild(node.type, node),
|
|
3320
|
+
label: this.convertChild(node.name, node),
|
|
3321
|
+
optional: node.questionToken != null,
|
|
3322
|
+
});
|
|
3323
|
+
if (node.dotDotDotToken) {
|
|
3324
|
+
member.range[0] = member.label.range[0];
|
|
3325
|
+
member.loc.start = member.label.loc.start;
|
|
3326
|
+
return this.createNode(node, {
|
|
3327
|
+
type: AST_NODE_TYPES2.TSRestType,
|
|
3328
|
+
typeAnnotation: member,
|
|
3329
|
+
});
|
|
3330
|
+
}
|
|
3331
|
+
return member;
|
|
3332
|
+
}
|
|
3333
|
+
case SyntaxKind6.OptionalType: {
|
|
3334
|
+
return this.createNode(node, {
|
|
3335
|
+
type: AST_NODE_TYPES2.TSOptionalType,
|
|
3336
|
+
typeAnnotation: this.convertChild(node.type),
|
|
3337
|
+
});
|
|
3338
|
+
}
|
|
3339
|
+
case SyntaxKind6.RestType: {
|
|
3340
|
+
return this.createNode(node, {
|
|
3341
|
+
type: AST_NODE_TYPES2.TSRestType,
|
|
3342
|
+
typeAnnotation: this.convertChild(node.type),
|
|
3343
|
+
});
|
|
3344
|
+
}
|
|
3345
|
+
// Template Literal Types
|
|
3346
|
+
case SyntaxKind6.TemplateLiteralType: {
|
|
3347
|
+
const result = this.createNode(node, {
|
|
3348
|
+
type: AST_NODE_TYPES2.TSTemplateLiteralType,
|
|
3349
|
+
quasis: [this.convertChild(node.head)],
|
|
3350
|
+
types: [],
|
|
3351
|
+
});
|
|
3352
|
+
node.templateSpans.forEach((templateSpan) => {
|
|
3353
|
+
result.types.push(this.convertChild(templateSpan.type));
|
|
3354
|
+
result.quasis.push(this.convertChild(templateSpan.literal));
|
|
3355
|
+
});
|
|
3356
|
+
return result;
|
|
3357
|
+
}
|
|
3358
|
+
case SyntaxKind6.ClassStaticBlockDeclaration: {
|
|
3359
|
+
return this.createNode(node, {
|
|
3360
|
+
type: AST_NODE_TYPES2.StaticBlock,
|
|
3361
|
+
body: this.convertBodyExpressions(node.body.statements, node),
|
|
3362
|
+
});
|
|
3363
|
+
}
|
|
3364
|
+
case SyntaxKind6.AssertEntry:
|
|
3365
|
+
case SyntaxKind6.ImportAttribute: {
|
|
3366
|
+
return this.createNode(node, {
|
|
3367
|
+
type: AST_NODE_TYPES2.ImportAttribute,
|
|
3368
|
+
key: this.convertChild(node.name),
|
|
3369
|
+
value: this.convertChild(node.value),
|
|
3370
|
+
});
|
|
3371
|
+
}
|
|
3372
|
+
case SyntaxKind6.SatisfiesExpression: {
|
|
3373
|
+
return this.createNode(node, {
|
|
3374
|
+
type: AST_NODE_TYPES2.TSSatisfiesExpression,
|
|
3375
|
+
expression: this.convertChild(node.expression),
|
|
3376
|
+
typeAnnotation: this.convertChild(node.type),
|
|
3377
|
+
});
|
|
3378
|
+
}
|
|
3379
|
+
default:
|
|
3380
|
+
return this.deeplyCopy(node);
|
|
3381
|
+
}
|
|
3382
|
+
}
|
|
3383
|
+
createNode(node, data) {
|
|
3384
|
+
const result = data;
|
|
3385
|
+
result.range ?? (result.range = (0, getRange)(node, this.ast));
|
|
3386
|
+
result.loc ?? (result.loc = (0, getLocFor)(result.range, this.ast));
|
|
3387
|
+
if (result && this.options.shouldPreserveNodeMaps) {
|
|
3388
|
+
this.esTreeNodeToTSNodeMap.set(result, node);
|
|
3389
|
+
}
|
|
3390
|
+
return result;
|
|
3391
|
+
}
|
|
3392
|
+
convertProgram() {
|
|
3393
|
+
return this.converter(this.ast);
|
|
3394
|
+
}
|
|
3395
|
+
/**
|
|
3396
|
+
* For nodes that are copied directly from the TypeScript AST into
|
|
3397
|
+
* ESTree mostly as-is. The only difference is the addition of a type
|
|
3398
|
+
* property instead of a kind property. Recursively copies all children.
|
|
3399
|
+
*/
|
|
3400
|
+
deeplyCopy(node) {
|
|
3401
|
+
if (node.kind === ts.SyntaxKind.JSDocFunctionType) {
|
|
3402
|
+
this.#throwError(node, 'JSDoc types can only be used inside documentation comments.');
|
|
3403
|
+
}
|
|
3404
|
+
const customType = `TS${SyntaxKind6[node.kind]}`;
|
|
3405
|
+
if (this.options.errorOnUnknownASTType && !AST_NODE_TYPES2[customType]) {
|
|
3406
|
+
throw new Error(`Unknown AST_NODE_TYPE: "${customType}"`);
|
|
3407
|
+
}
|
|
3408
|
+
const result = this.createNode(node, {
|
|
3409
|
+
type: customType,
|
|
3410
|
+
});
|
|
3411
|
+
if ('type' in node) {
|
|
3412
|
+
result.typeAnnotation =
|
|
3413
|
+
node.type && 'kind' in node.type && ts.isTypeNode(node.type)
|
|
3414
|
+
? this.convertTypeAnnotation(node.type, node)
|
|
3415
|
+
: null;
|
|
3416
|
+
}
|
|
3417
|
+
if ('typeArguments' in node) {
|
|
3418
|
+
result.typeArguments =
|
|
3419
|
+
node.typeArguments && 'pos' in node.typeArguments
|
|
3420
|
+
? this.convertTypeArgumentsToTypeParameterInstantiation(node.typeArguments, node)
|
|
3421
|
+
: null;
|
|
3422
|
+
}
|
|
3423
|
+
if ('typeParameters' in node) {
|
|
3424
|
+
result.typeParameters =
|
|
3425
|
+
node.typeParameters && 'pos' in node.typeParameters
|
|
3426
|
+
? this.convertTSTypeParametersToTypeParametersDeclaration(node.typeParameters)
|
|
3427
|
+
: null;
|
|
3428
|
+
}
|
|
3429
|
+
const decorators = (0, getDecorators2)(node);
|
|
3430
|
+
if (decorators?.length) {
|
|
3431
|
+
result.decorators = this.convertChildren(decorators);
|
|
3432
|
+
}
|
|
3433
|
+
const KEYS_TO_NOT_COPY = /* @__PURE__ */ new Set([
|
|
3434
|
+
'_children',
|
|
3435
|
+
'decorators',
|
|
3436
|
+
'end',
|
|
3437
|
+
'flags',
|
|
3438
|
+
'heritageClauses',
|
|
3439
|
+
'illegalDecorators',
|
|
3440
|
+
'jsDoc',
|
|
3441
|
+
'kind',
|
|
3442
|
+
'locals',
|
|
3443
|
+
'localSymbol',
|
|
3444
|
+
'modifierFlagsCache',
|
|
3445
|
+
'modifiers',
|
|
3446
|
+
'nextContainer',
|
|
3447
|
+
'parent',
|
|
3448
|
+
'pos',
|
|
3449
|
+
'symbol',
|
|
3450
|
+
'transformFlags',
|
|
3451
|
+
'type',
|
|
3452
|
+
'typeArguments',
|
|
3453
|
+
'typeParameters',
|
|
3454
|
+
]);
|
|
3455
|
+
Object.entries(node)
|
|
3456
|
+
.filter(([key]) => !KEYS_TO_NOT_COPY.has(key))
|
|
3457
|
+
.forEach(([key, value]) => {
|
|
3458
|
+
if (Array.isArray(value)) {
|
|
3459
|
+
result[key] = this.convertChildren(value);
|
|
3460
|
+
} else if (value && typeof value === 'object' && value.kind) {
|
|
3461
|
+
result[key] = this.convertChild(value);
|
|
3462
|
+
} else {
|
|
3463
|
+
result[key] = value;
|
|
3464
|
+
}
|
|
3465
|
+
});
|
|
3466
|
+
return result;
|
|
3467
|
+
}
|
|
3468
|
+
/**
|
|
3469
|
+
* Fixes the exports of the given ts.Node
|
|
3470
|
+
* @returns the ESTreeNode with fixed exports
|
|
3471
|
+
*/
|
|
3472
|
+
fixExports(node, result) {
|
|
3473
|
+
const isNamespaceNode = ts.isModuleDeclaration(node) && !ts.isStringLiteral(node.name);
|
|
3474
|
+
const modifiers = isNamespaceNode ? (0, getNamespaceModifiers)(node) : (0, getModifiers2)(node);
|
|
3475
|
+
if (modifiers?.[0].kind === SyntaxKind6.ExportKeyword) {
|
|
3476
|
+
this.registerTSNodeInNodeMap(node, result);
|
|
3477
|
+
const exportKeyword = modifiers[0];
|
|
3478
|
+
const nextModifier = modifiers[1];
|
|
3479
|
+
const declarationIsDefault = nextModifier?.kind === SyntaxKind6.DefaultKeyword;
|
|
3480
|
+
const varToken = declarationIsDefault
|
|
3481
|
+
? (0, findNextToken)(nextModifier, this.ast, this.ast)
|
|
3482
|
+
: (0, findNextToken)(exportKeyword, this.ast, this.ast);
|
|
3483
|
+
result.range[0] = varToken.getStart(this.ast);
|
|
3484
|
+
result.loc = (0, getLocFor)(result.range, this.ast);
|
|
3485
|
+
if (declarationIsDefault) {
|
|
3486
|
+
return this.createNode(node, {
|
|
3487
|
+
type: AST_NODE_TYPES2.ExportDefaultDeclaration,
|
|
3488
|
+
range: [exportKeyword.getStart(this.ast), result.range[1]],
|
|
3489
|
+
declaration: result,
|
|
3490
|
+
exportKind: 'value',
|
|
3491
|
+
});
|
|
3492
|
+
}
|
|
3493
|
+
const isType =
|
|
3494
|
+
result.type === AST_NODE_TYPES2.TSInterfaceDeclaration ||
|
|
3495
|
+
result.type === AST_NODE_TYPES2.TSTypeAliasDeclaration;
|
|
3496
|
+
const isDeclare = 'declare' in result && result.declare;
|
|
3497
|
+
return this.createNode(
|
|
3498
|
+
node,
|
|
3499
|
+
// @ts-expect-error - TODO, narrow the types here
|
|
3500
|
+
this.#withDeprecatedAliasGetter(
|
|
3501
|
+
{
|
|
3502
|
+
type: AST_NODE_TYPES2.ExportNamedDeclaration,
|
|
3503
|
+
range: [exportKeyword.getStart(this.ast), result.range[1]],
|
|
3504
|
+
attributes: [],
|
|
3505
|
+
declaration: result,
|
|
3506
|
+
exportKind: isType || isDeclare ? 'type' : 'value',
|
|
3507
|
+
source: null,
|
|
3508
|
+
specifiers: [],
|
|
3509
|
+
},
|
|
3510
|
+
'assertions',
|
|
3511
|
+
'attributes',
|
|
3512
|
+
true,
|
|
3513
|
+
),
|
|
3514
|
+
);
|
|
3515
|
+
}
|
|
3516
|
+
return result;
|
|
3517
|
+
}
|
|
3518
|
+
getASTMaps() {
|
|
3519
|
+
return {
|
|
3520
|
+
esTreeNodeToTSNodeMap: this.esTreeNodeToTSNodeMap,
|
|
3521
|
+
tsNodeToESTreeNodeMap: this.tsNodeToESTreeNodeMap,
|
|
3522
|
+
};
|
|
3523
|
+
}
|
|
3524
|
+
/**
|
|
3525
|
+
* Register specific TypeScript node into map with first ESTree node provided
|
|
3526
|
+
*/
|
|
3527
|
+
registerTSNodeInNodeMap(node, result) {
|
|
3528
|
+
if (result && this.options.shouldPreserveNodeMaps && !this.tsNodeToESTreeNodeMap.has(node)) {
|
|
3529
|
+
this.tsNodeToESTreeNodeMap.set(node, result);
|
|
3530
|
+
}
|
|
3531
|
+
}
|
|
3532
|
+
};
|
|
3533
|
+
|
|
3534
|
+
// node_modules/ts-api-utils/lib/index.js
|
|
3535
|
+
function forEachToken(node, callback, sourceFile = node.getSourceFile()) {
|
|
3536
|
+
const queue = [];
|
|
3537
|
+
while (true) {
|
|
3538
|
+
if (ts.isTokenKind(node.kind)) {
|
|
3539
|
+
callback(node);
|
|
3540
|
+
} else {
|
|
3541
|
+
const children = node.getChildren(sourceFile);
|
|
3542
|
+
if (children.length === 1) {
|
|
3543
|
+
node = children[0];
|
|
3544
|
+
continue;
|
|
3545
|
+
}
|
|
3546
|
+
for (let i = children.length - 1; i >= 0; --i) {
|
|
3547
|
+
queue.push(children[i]);
|
|
3548
|
+
}
|
|
3549
|
+
}
|
|
3550
|
+
if (queue.length === 0) {
|
|
3551
|
+
break;
|
|
3552
|
+
}
|
|
3553
|
+
node = queue.pop();
|
|
3554
|
+
}
|
|
3555
|
+
}
|
|
3556
|
+
function forEachComment(node, callback, sourceFile = node.getSourceFile()) {
|
|
3557
|
+
const fullText = sourceFile.text;
|
|
3558
|
+
const notJsx = sourceFile.languageVariant !== ts.LanguageVariant.JSX;
|
|
3559
|
+
return forEachToken(
|
|
3560
|
+
node,
|
|
3561
|
+
(token) => {
|
|
3562
|
+
if (token.pos === token.end) {
|
|
3563
|
+
return;
|
|
3564
|
+
}
|
|
3565
|
+
if (token.kind !== ts.SyntaxKind.JsxText) {
|
|
3566
|
+
ts.forEachLeadingCommentRange(
|
|
3567
|
+
fullText,
|
|
3568
|
+
// skip shebang at position 0
|
|
3569
|
+
token.pos === 0 ? (ts.getShebang(fullText) ?? '').length : token.pos,
|
|
3570
|
+
commentCallback,
|
|
3571
|
+
);
|
|
3572
|
+
}
|
|
3573
|
+
if (notJsx || canHaveTrailingTrivia(token)) {
|
|
3574
|
+
return ts.forEachTrailingCommentRange(fullText, token.end, commentCallback);
|
|
3575
|
+
}
|
|
3576
|
+
},
|
|
3577
|
+
sourceFile,
|
|
3578
|
+
);
|
|
3579
|
+
function commentCallback(pos, end, kind) {
|
|
3580
|
+
callback(fullText, { end, kind, pos });
|
|
3581
|
+
}
|
|
3582
|
+
}
|
|
3583
|
+
function canHaveTrailingTrivia(token) {
|
|
3584
|
+
switch (token.kind) {
|
|
3585
|
+
case ts.SyntaxKind.CloseBraceToken:
|
|
3586
|
+
return (
|
|
3587
|
+
token.parent.kind !== ts.SyntaxKind.JsxExpression || !isJsxElementOrFragment(token.parent.parent)
|
|
3588
|
+
);
|
|
3589
|
+
case ts.SyntaxKind.GreaterThanToken:
|
|
3590
|
+
switch (token.parent.kind) {
|
|
3591
|
+
case ts.SyntaxKind.JsxClosingElement:
|
|
3592
|
+
case ts.SyntaxKind.JsxClosingFragment:
|
|
3593
|
+
return !isJsxElementOrFragment(token.parent.parent.parent);
|
|
3594
|
+
case ts.SyntaxKind.JsxOpeningElement:
|
|
3595
|
+
return token.end !== token.parent.end;
|
|
3596
|
+
case ts.SyntaxKind.JsxOpeningFragment:
|
|
3597
|
+
return false;
|
|
3598
|
+
// would be inside the fragment
|
|
3599
|
+
case ts.SyntaxKind.JsxSelfClosingElement:
|
|
3600
|
+
return (
|
|
3601
|
+
token.end !== token.parent.end || // if end is not equal, this is part of the type arguments list
|
|
3602
|
+
!isJsxElementOrFragment(token.parent.parent)
|
|
3603
|
+
);
|
|
3604
|
+
}
|
|
3605
|
+
}
|
|
3606
|
+
return true;
|
|
3607
|
+
}
|
|
3608
|
+
function isJsxElementOrFragment(node) {
|
|
3609
|
+
return node.kind === ts.SyntaxKind.JsxElement || node.kind === ts.SyntaxKind.JsxFragment;
|
|
3610
|
+
}
|
|
3611
|
+
var [tsMajor, tsMinor] = ts.versionMajorMinor.split('.').map((raw) => Number.parseInt(raw, 10));
|
|
3612
|
+
var IntrinsicTypeFlags =
|
|
3613
|
+
ts.TypeFlags.Intrinsic ??
|
|
3614
|
+
ts.TypeFlags.Any |
|
|
3615
|
+
ts.TypeFlags.Unknown |
|
|
3616
|
+
ts.TypeFlags.String |
|
|
3617
|
+
ts.TypeFlags.Number |
|
|
3618
|
+
ts.TypeFlags.BigInt |
|
|
3619
|
+
ts.TypeFlags.Boolean |
|
|
3620
|
+
ts.TypeFlags.BooleanLiteral |
|
|
3621
|
+
ts.TypeFlags.ESSymbol |
|
|
3622
|
+
ts.TypeFlags.Void |
|
|
3623
|
+
ts.TypeFlags.Undefined |
|
|
3624
|
+
ts.TypeFlags.Null |
|
|
3625
|
+
ts.TypeFlags.Never |
|
|
3626
|
+
ts.TypeFlags.NonPrimitive;
|
|
3627
|
+
|
|
3628
|
+
// node_modules/@typescript-eslint/typescript-estree/dist/convert-comments.js
|
|
3629
|
+
function convertComments(ast, code) {
|
|
3630
|
+
const comments = [];
|
|
3631
|
+
forEachComment(
|
|
3632
|
+
ast,
|
|
3633
|
+
(_, comment) => {
|
|
3634
|
+
const type =
|
|
3635
|
+
comment.kind === ts.SyntaxKind.SingleLineCommentTrivia
|
|
3636
|
+
? AST_TOKEN_TYPES2.Line
|
|
3637
|
+
: AST_TOKEN_TYPES2.Block;
|
|
3638
|
+
const range = [comment.pos, comment.end];
|
|
3639
|
+
const loc = (0, getLocFor)(range, ast);
|
|
3640
|
+
const textStart = range[0] + 2;
|
|
3641
|
+
const textEnd =
|
|
3642
|
+
comment.kind === ts.SyntaxKind.SingleLineCommentTrivia
|
|
3643
|
+
? // single line comments end at the end
|
|
3644
|
+
range[1]
|
|
3645
|
+
: // multiline comments end 2 characters early
|
|
3646
|
+
range[1] - 2;
|
|
3647
|
+
comments.push({
|
|
3648
|
+
type,
|
|
3649
|
+
loc,
|
|
3650
|
+
range,
|
|
3651
|
+
value: code.slice(textStart, textEnd),
|
|
3652
|
+
});
|
|
3653
|
+
},
|
|
3654
|
+
ast,
|
|
3655
|
+
);
|
|
3656
|
+
return comments;
|
|
3657
|
+
}
|
|
3658
|
+
|
|
3659
|
+
// node_modules/@typescript-eslint/typescript-estree/dist/simple-traverse.js
|
|
3660
|
+
var simpleTraverse = () => {};
|
|
3661
|
+
|
|
3662
|
+
// node_modules/@typescript-eslint/typescript-estree/dist/ast-converter.js
|
|
3663
|
+
function astConverter(ast, parseSettings, shouldPreserveNodeMaps) {
|
|
3664
|
+
const { parseDiagnostics } = ast;
|
|
3665
|
+
if (parseDiagnostics.length) {
|
|
3666
|
+
throw (0, convertError)(parseDiagnostics[0]);
|
|
3667
|
+
}
|
|
3668
|
+
const instance = new Converter(ast, {
|
|
3669
|
+
allowInvalidAST: parseSettings.allowInvalidAST,
|
|
3670
|
+
errorOnUnknownASTType: parseSettings.errorOnUnknownASTType,
|
|
3671
|
+
shouldPreserveNodeMaps,
|
|
3672
|
+
suppressDeprecatedPropertyWarnings: parseSettings.suppressDeprecatedPropertyWarnings,
|
|
3673
|
+
});
|
|
3674
|
+
const estree = instance.convertProgram();
|
|
3675
|
+
if (!parseSettings.range || !parseSettings.loc) {
|
|
3676
|
+
(0, simpleTraverse)(estree, {
|
|
3677
|
+
enter: (node) => {
|
|
3678
|
+
if (!parseSettings.range) {
|
|
3679
|
+
delete node.range;
|
|
3680
|
+
}
|
|
3681
|
+
if (!parseSettings.loc) {
|
|
3682
|
+
delete node.loc;
|
|
3683
|
+
}
|
|
3684
|
+
},
|
|
3685
|
+
});
|
|
3686
|
+
}
|
|
3687
|
+
if (parseSettings.tokens) {
|
|
3688
|
+
estree.tokens = (0, convertTokens)(ast);
|
|
3689
|
+
}
|
|
3690
|
+
if (parseSettings.comment) {
|
|
3691
|
+
estree.comments = (0, convertComments)(ast, parseSettings.codeFullText);
|
|
3692
|
+
}
|
|
3693
|
+
const astMaps = instance.getASTMaps();
|
|
3694
|
+
return { astMaps, estree };
|
|
3695
|
+
}
|
|
3696
|
+
|
|
3697
|
+
// node_modules/@typescript-eslint/typescript-estree/dist/create-program/createSourceFile.js
|
|
3698
|
+
|
|
3699
|
+
// node_modules/@typescript-eslint/typescript-estree/dist/source-files.js
|
|
3700
|
+
function isSourceFile2(code) {
|
|
3701
|
+
if (typeof code !== 'object' || code == null) {
|
|
3702
|
+
return false;
|
|
3703
|
+
}
|
|
3704
|
+
const maybeSourceFile = code;
|
|
3705
|
+
return (
|
|
3706
|
+
maybeSourceFile.kind === ts.SyntaxKind.SourceFile && typeof maybeSourceFile.getFullText === 'function'
|
|
3707
|
+
);
|
|
3708
|
+
}
|
|
3709
|
+
|
|
3710
|
+
// node_modules/@typescript-eslint/typescript-estree/dist/create-program/getScriptKind.js
|
|
3711
|
+
var __importDefault = function (mod) {
|
|
3712
|
+
return mod && mod.__esModule ? mod : { default: mod };
|
|
3713
|
+
};
|
|
3714
|
+
var node_path_1 = __importDefault({
|
|
3715
|
+
extname: (file) => '.' + file.split('.').pop(),
|
|
3716
|
+
});
|
|
3717
|
+
function getScriptKind(filePath, jsx) {
|
|
3718
|
+
const extension = node_path_1.default.extname(filePath).toLowerCase();
|
|
3719
|
+
switch (extension) {
|
|
3720
|
+
case ts.Extension.Cjs:
|
|
3721
|
+
case ts.Extension.Js:
|
|
3722
|
+
case ts.Extension.Mjs:
|
|
3723
|
+
return ts.ScriptKind.JS;
|
|
3724
|
+
case ts.Extension.Cts:
|
|
3725
|
+
case ts.Extension.Mts:
|
|
3726
|
+
case ts.Extension.Ts:
|
|
3727
|
+
return ts.ScriptKind.TS;
|
|
3728
|
+
case ts.Extension.Json:
|
|
3729
|
+
return ts.ScriptKind.JSON;
|
|
3730
|
+
case ts.Extension.Jsx:
|
|
3731
|
+
return ts.ScriptKind.JSX;
|
|
3732
|
+
case ts.Extension.Tsx:
|
|
3733
|
+
return ts.ScriptKind.TSX;
|
|
3734
|
+
default:
|
|
3735
|
+
return jsx ? ts.ScriptKind.TSX : ts.ScriptKind.TS;
|
|
3736
|
+
}
|
|
3737
|
+
}
|
|
3738
|
+
|
|
3739
|
+
// node_modules/@typescript-eslint/typescript-estree/dist/create-program/createSourceFile.js
|
|
3740
|
+
var debug_1 = { default: debug_default };
|
|
3741
|
+
var log = (0, debug_1.default)('typescript-eslint:typescript-estree:create-program:createSourceFile');
|
|
3742
|
+
function createSourceFile2(parseSettings) {
|
|
3743
|
+
log(
|
|
3744
|
+
'Getting AST without type information in %s mode for: %s',
|
|
3745
|
+
parseSettings.jsx ? 'TSX' : 'TS',
|
|
3746
|
+
parseSettings.filePath,
|
|
3747
|
+
);
|
|
3748
|
+
return (0, isSourceFile2)(parseSettings.code)
|
|
3749
|
+
? parseSettings.code
|
|
3750
|
+
: ts.createSourceFile(
|
|
3751
|
+
parseSettings.filePath,
|
|
3752
|
+
parseSettings.codeFullText,
|
|
3753
|
+
{
|
|
3754
|
+
jsDocParsingMode: parseSettings.jsDocParsingMode,
|
|
3755
|
+
languageVersion: ts.ScriptTarget.Latest,
|
|
3756
|
+
setExternalModuleIndicator: parseSettings.setExternalModuleIndicator,
|
|
3757
|
+
},
|
|
3758
|
+
/* setParentNodes */
|
|
3759
|
+
true,
|
|
3760
|
+
(0, getScriptKind)(parseSettings.filePath, parseSettings.jsx),
|
|
3761
|
+
);
|
|
3762
|
+
}
|
|
3763
|
+
|
|
3764
|
+
// node_modules/@typescript-eslint/typescript-estree/dist/parseSettings/createParseSettings.js
|
|
3765
|
+
|
|
3766
|
+
// node_modules/@typescript-eslint/typescript-estree/dist/create-program/shared.js
|
|
3767
|
+
var ensureAbsolutePath = (path) => path;
|
|
3768
|
+
|
|
3769
|
+
// node_modules/@typescript-eslint/typescript-estree/dist/create-program/validateDefaultProjectForFilesGlob.js
|
|
3770
|
+
var validateDefaultProjectForFilesGlob = () => {};
|
|
3771
|
+
|
|
3772
|
+
// node_modules/@typescript-eslint/typescript-estree/dist/parseSettings/ExpiringCache.js
|
|
3773
|
+
var DEFAULT_TSCONFIG_CACHE_DURATION_SECONDS = void 0;
|
|
3774
|
+
var ExpiringCache = class {};
|
|
3775
|
+
|
|
3776
|
+
// node_modules/@typescript-eslint/typescript-estree/dist/parseSettings/inferSingleRun.js
|
|
3777
|
+
var inferSingleRun = () => false;
|
|
3778
|
+
|
|
3779
|
+
// node_modules/@typescript-eslint/typescript-estree/dist/parseSettings/warnAboutTSVersion.js
|
|
3780
|
+
var warnAboutTSVersion = () => {};
|
|
3781
|
+
|
|
3782
|
+
// node_modules/@typescript-eslint/typescript-estree/dist/parseSettings/createParseSettings.js
|
|
3783
|
+
var __importDefault2 = function (mod) {
|
|
3784
|
+
return mod && mod.__esModule ? mod : { default: mod };
|
|
3785
|
+
};
|
|
3786
|
+
var project_service_1 = {};
|
|
3787
|
+
var debug_12 = { default: debug_default };
|
|
3788
|
+
var node_path_12 = __importDefault2({
|
|
3789
|
+
extname: (file) => '.' + file.split('.').pop(),
|
|
3790
|
+
});
|
|
3791
|
+
var log2 = (0, debug_12.default)('typescript-eslint:typescript-estree:parseSettings:createParseSettings');
|
|
3792
|
+
var TSCONFIG_MATCH_CACHE;
|
|
3793
|
+
var TSSERVER_PROJECT_SERVICE = null;
|
|
3794
|
+
var JSDocParsingMode2 = {
|
|
3795
|
+
ParseAll: ts.JSDocParsingMode?.ParseAll,
|
|
3796
|
+
ParseForTypeErrors: ts.JSDocParsingMode?.ParseForTypeErrors,
|
|
3797
|
+
ParseForTypeInfo: ts.JSDocParsingMode?.ParseForTypeInfo,
|
|
3798
|
+
ParseNone: ts.JSDocParsingMode?.ParseNone,
|
|
3799
|
+
};
|
|
3800
|
+
function createParseSettings(code, tsestreeOptions = {}) {
|
|
3801
|
+
const codeFullText = enforceCodeString(code);
|
|
3802
|
+
const singleRun = (0, inferSingleRun)(tsestreeOptions);
|
|
3803
|
+
const tsconfigRootDir = void 0;
|
|
3804
|
+
const passedLoggerFn = typeof tsestreeOptions.loggerFn === 'function';
|
|
3805
|
+
const filePath = (0, ensureAbsolutePath)(
|
|
3806
|
+
typeof tsestreeOptions.filePath === 'string' && tsestreeOptions.filePath !== '<input>'
|
|
3807
|
+
? tsestreeOptions.filePath
|
|
3808
|
+
: getFileName(tsestreeOptions.jsx),
|
|
3809
|
+
tsconfigRootDir,
|
|
3810
|
+
);
|
|
3811
|
+
const extension = node_path_12.default.extname(filePath).toLowerCase();
|
|
3812
|
+
const jsDocParsingMode = (() => {
|
|
3813
|
+
switch (tsestreeOptions.jsDocParsingMode) {
|
|
3814
|
+
case 'all':
|
|
3815
|
+
return JSDocParsingMode2.ParseAll;
|
|
3816
|
+
case 'none':
|
|
3817
|
+
return JSDocParsingMode2.ParseNone;
|
|
3818
|
+
case 'type-info':
|
|
3819
|
+
return JSDocParsingMode2.ParseForTypeInfo;
|
|
3820
|
+
default:
|
|
3821
|
+
return JSDocParsingMode2.ParseAll;
|
|
3822
|
+
}
|
|
3823
|
+
})();
|
|
3824
|
+
const parseSettings = {
|
|
3825
|
+
loc: tsestreeOptions.loc === true,
|
|
3826
|
+
range: tsestreeOptions.range === true,
|
|
3827
|
+
allowInvalidAST: tsestreeOptions.allowInvalidAST === true,
|
|
3828
|
+
code,
|
|
3829
|
+
codeFullText,
|
|
3830
|
+
comment: tsestreeOptions.comment === true,
|
|
3831
|
+
comments: [],
|
|
3832
|
+
debugLevel:
|
|
3833
|
+
tsestreeOptions.debugLevel === true
|
|
3834
|
+
? /* @__PURE__ */ new Set(['typescript-eslint'])
|
|
3835
|
+
: Array.isArray(tsestreeOptions.debugLevel)
|
|
3836
|
+
? new Set(tsestreeOptions.debugLevel)
|
|
3837
|
+
: /* @__PURE__ */ new Set(),
|
|
3838
|
+
errorOnTypeScriptSyntacticAndSemanticIssues: false,
|
|
3839
|
+
errorOnUnknownASTType: tsestreeOptions.errorOnUnknownASTType === true,
|
|
3840
|
+
extraFileExtensions:
|
|
3841
|
+
Array.isArray(tsestreeOptions.extraFileExtensions) &&
|
|
3842
|
+
tsestreeOptions.extraFileExtensions.every((ext) => typeof ext === 'string')
|
|
3843
|
+
? tsestreeOptions.extraFileExtensions
|
|
3844
|
+
: [],
|
|
3845
|
+
filePath,
|
|
3846
|
+
jsDocParsingMode,
|
|
3847
|
+
jsx: tsestreeOptions.jsx === true,
|
|
3848
|
+
log:
|
|
3849
|
+
typeof tsestreeOptions.loggerFn === 'function'
|
|
3850
|
+
? tsestreeOptions.loggerFn
|
|
3851
|
+
: tsestreeOptions.loggerFn === false
|
|
3852
|
+
? () => {}
|
|
3853
|
+
: console.log,
|
|
3854
|
+
preserveNodeMaps: tsestreeOptions.preserveNodeMaps !== false,
|
|
3855
|
+
programs: Array.isArray(tsestreeOptions.programs) ? tsestreeOptions.programs : null,
|
|
3856
|
+
projects: /* @__PURE__ */ new Map(),
|
|
3857
|
+
projectService:
|
|
3858
|
+
tsestreeOptions.projectService ||
|
|
3859
|
+
(tsestreeOptions.project &&
|
|
3860
|
+
tsestreeOptions.projectService !== false &&
|
|
3861
|
+
(void 0).env.TYPESCRIPT_ESLINT_PROJECT_SERVICE === 'true')
|
|
3862
|
+
? populateProjectService(tsestreeOptions.projectService, {
|
|
3863
|
+
jsDocParsingMode,
|
|
3864
|
+
tsconfigRootDir,
|
|
3865
|
+
})
|
|
3866
|
+
: void 0,
|
|
3867
|
+
setExternalModuleIndicator:
|
|
3868
|
+
tsestreeOptions.sourceType === 'module' ||
|
|
3869
|
+
(tsestreeOptions.sourceType == null && extension === ts.Extension.Mjs) ||
|
|
3870
|
+
(tsestreeOptions.sourceType == null && extension === ts.Extension.Mts)
|
|
3871
|
+
? (file) => {
|
|
3872
|
+
file.externalModuleIndicator = true;
|
|
3873
|
+
}
|
|
3874
|
+
: void 0,
|
|
3875
|
+
singleRun,
|
|
3876
|
+
suppressDeprecatedPropertyWarnings: tsestreeOptions.suppressDeprecatedPropertyWarnings ?? true,
|
|
3877
|
+
tokens: tsestreeOptions.tokens === true ? [] : null,
|
|
3878
|
+
tsconfigMatchCache:
|
|
3879
|
+
TSCONFIG_MATCH_CACHE ??
|
|
3880
|
+
(TSCONFIG_MATCH_CACHE = new ExpiringCache(
|
|
3881
|
+
singleRun
|
|
3882
|
+
? 'Infinity'
|
|
3883
|
+
: (tsestreeOptions.cacheLifetime?.glob ?? DEFAULT_TSCONFIG_CACHE_DURATION_SECONDS),
|
|
3884
|
+
)),
|
|
3885
|
+
tsconfigRootDir,
|
|
3886
|
+
};
|
|
3887
|
+
if (parseSettings.debugLevel.size > 0) {
|
|
3888
|
+
const namespaces = [];
|
|
3889
|
+
if (parseSettings.debugLevel.has('typescript-eslint')) {
|
|
3890
|
+
namespaces.push('typescript-eslint:*');
|
|
3891
|
+
}
|
|
3892
|
+
if (
|
|
3893
|
+
parseSettings.debugLevel.has('eslint') || // make sure we don't turn off the eslint debug if it was enabled via --debug
|
|
3894
|
+
debug_12.default.enabled('eslint:*,-eslint:code-path')
|
|
3895
|
+
) {
|
|
3896
|
+
namespaces.push('eslint:*,-eslint:code-path');
|
|
3897
|
+
}
|
|
3898
|
+
debug_12.default.enable(namespaces.join(','));
|
|
3899
|
+
}
|
|
3900
|
+
if (Array.isArray(tsestreeOptions.programs)) {
|
|
3901
|
+
if (!tsestreeOptions.programs.length) {
|
|
3902
|
+
throw new Error(
|
|
3903
|
+
`You have set parserOptions.programs to an empty array. This will cause all files to not be found in existing programs. Either provide one or more existing TypeScript Program instances in the array, or remove the parserOptions.programs setting.`,
|
|
3904
|
+
);
|
|
3905
|
+
}
|
|
3906
|
+
log2('parserOptions.programs was provided, so parserOptions.project will be ignored.');
|
|
3907
|
+
}
|
|
3908
|
+
if (!parseSettings.programs && !parseSettings.projectService) {
|
|
3909
|
+
parseSettings.projects = true
|
|
3910
|
+
? /* @__PURE__ */ new Map()
|
|
3911
|
+
: (0, resolveProjectList)({
|
|
3912
|
+
cacheLifetime: tsestreeOptions.cacheLifetime,
|
|
3913
|
+
project: (0, void 0)(parseSettings, tsestreeOptions.project),
|
|
3914
|
+
projectFolderIgnoreList: tsestreeOptions.projectFolderIgnoreList,
|
|
3915
|
+
singleRun: parseSettings.singleRun,
|
|
3916
|
+
tsconfigRootDir,
|
|
3917
|
+
});
|
|
3918
|
+
}
|
|
3919
|
+
if (
|
|
3920
|
+
tsestreeOptions.jsDocParsingMode == null &&
|
|
3921
|
+
parseSettings.projects.size === 0 &&
|
|
3922
|
+
parseSettings.programs == null &&
|
|
3923
|
+
parseSettings.projectService == null
|
|
3924
|
+
) {
|
|
3925
|
+
parseSettings.jsDocParsingMode = JSDocParsingMode2.ParseNone;
|
|
3926
|
+
}
|
|
3927
|
+
(0, warnAboutTSVersion)(parseSettings, passedLoggerFn);
|
|
3928
|
+
return parseSettings;
|
|
3929
|
+
}
|
|
3930
|
+
function enforceCodeString(code) {
|
|
3931
|
+
return (0, isSourceFile2)(code) ? code.getFullText(code) : typeof code === 'string' ? code : String(code);
|
|
3932
|
+
}
|
|
3933
|
+
function getFileName(jsx) {
|
|
3934
|
+
return jsx ? 'estree.tsx' : 'estree.ts';
|
|
3935
|
+
}
|
|
3936
|
+
function populateProjectService(optionsRaw, settings) {
|
|
3937
|
+
const options = typeof optionsRaw === 'object' ? optionsRaw : {};
|
|
3938
|
+
(0, validateDefaultProjectForFilesGlob)(options.allowDefaultProject);
|
|
3939
|
+
TSSERVER_PROJECT_SERVICE ??
|
|
3940
|
+
(TSSERVER_PROJECT_SERVICE = (0, project_service_1.createProjectService)({
|
|
3941
|
+
options,
|
|
3942
|
+
...settings,
|
|
3943
|
+
}));
|
|
3944
|
+
return TSSERVER_PROJECT_SERVICE;
|
|
3945
|
+
}
|
|
3946
|
+
|
|
3947
|
+
// node_modules/@typescript-eslint/typescript-estree/dist/parser.js
|
|
3948
|
+
var debug_13 = { default: debug_default };
|
|
3949
|
+
var log3 = (0, debug_13.default)('typescript-eslint:typescript-estree:parser');
|
|
3950
|
+
function parse(code, options) {
|
|
3951
|
+
const { ast } = parseWithNodeMapsInternal(code, options, false);
|
|
3952
|
+
return ast;
|
|
3953
|
+
}
|
|
3954
|
+
function parseWithNodeMapsInternal(code, options, shouldPreserveNodeMaps) {
|
|
3955
|
+
const parseSettings = (0, createParseSettings)(code, options);
|
|
3956
|
+
if (options?.errorOnTypeScriptSyntacticAndSemanticIssues) {
|
|
3957
|
+
throw new Error(
|
|
3958
|
+
`"errorOnTypeScriptSyntacticAndSemanticIssues" is only supported for parseAndGenerateServices()`,
|
|
3959
|
+
);
|
|
3960
|
+
}
|
|
3961
|
+
const ast = (0, createSourceFile2)(parseSettings);
|
|
3962
|
+
const { astMaps, estree } = (0, astConverter)(ast, parseSettings, shouldPreserveNodeMaps);
|
|
3963
|
+
return {
|
|
3964
|
+
ast: estree,
|
|
3965
|
+
esTreeNodeToTSNodeMap: astMaps.esTreeNodeToTSNodeMap,
|
|
3966
|
+
tsNodeToESTreeNodeMap: astMaps.tsNodeToESTreeNodeMap,
|
|
3967
|
+
};
|
|
3968
|
+
}
|
|
3969
|
+
|
|
3970
|
+
// src/common/parser-create-error.js
|
|
3971
|
+
function createError2(message, options) {
|
|
3972
|
+
const error = new SyntaxError(
|
|
3973
|
+
message + ' (' + options.loc.start.line + ':' + options.loc.start.column + ')',
|
|
3974
|
+
);
|
|
3975
|
+
return Object.assign(error, options);
|
|
3976
|
+
}
|
|
3977
|
+
var parser_create_error_default = createError2;
|
|
3978
|
+
|
|
3979
|
+
// src/utils/try-combinations.js
|
|
3980
|
+
function tryCombinations(combinations) {
|
|
3981
|
+
const errors = [];
|
|
3982
|
+
for (const fn of combinations) {
|
|
3983
|
+
try {
|
|
3984
|
+
return fn();
|
|
3985
|
+
} catch (error) {
|
|
3986
|
+
errors.push(error);
|
|
3987
|
+
}
|
|
3988
|
+
}
|
|
3989
|
+
throw Object.assign(new Error('All combinations failed'), { errors });
|
|
3990
|
+
}
|
|
3991
|
+
var try_combinations_default = tryCombinations;
|
|
3992
|
+
|
|
3993
|
+
// scripts/build/shims/method-find-last.js
|
|
3994
|
+
var arrayFindLast =
|
|
3995
|
+
Array.prototype.findLast ??
|
|
3996
|
+
function (callback) {
|
|
3997
|
+
for (let index = this.length - 1; index >= 0; index--) {
|
|
3998
|
+
const element = this[index];
|
|
3999
|
+
if (callback(element, index, this)) {
|
|
4000
|
+
return element;
|
|
4001
|
+
}
|
|
4002
|
+
}
|
|
4003
|
+
};
|
|
4004
|
+
var findLast = createMethodShim('findLast', function () {
|
|
4005
|
+
if (Array.isArray(this)) {
|
|
4006
|
+
return arrayFindLast;
|
|
4007
|
+
}
|
|
4008
|
+
});
|
|
4009
|
+
var method_find_last_default = findLast;
|
|
4010
|
+
|
|
4011
|
+
// scripts/build/shims/method-at.js
|
|
4012
|
+
function stringOrArrayAt(index) {
|
|
4013
|
+
return this[index < 0 ? this.length + index : index];
|
|
4014
|
+
}
|
|
4015
|
+
var at = createMethodShim('at', function () {
|
|
4016
|
+
if (Array.isArray(this) || typeof this === 'string') {
|
|
4017
|
+
return stringOrArrayAt;
|
|
4018
|
+
}
|
|
4019
|
+
});
|
|
4020
|
+
var method_at_default = at;
|
|
4021
|
+
|
|
4022
|
+
// src/language-js/loc.js
|
|
4023
|
+
function locStart(node) {
|
|
4024
|
+
const start = node.range?.[0] ?? node.start;
|
|
4025
|
+
if (false) {
|
|
4026
|
+
throw new TypeError("Can't not locate node.");
|
|
4027
|
+
}
|
|
4028
|
+
const firstDecorator = (node.declaration?.decorators ?? node.decorators)?.[0];
|
|
4029
|
+
if (firstDecorator) {
|
|
4030
|
+
return Math.min(locStart(firstDecorator), start);
|
|
4031
|
+
}
|
|
4032
|
+
return start;
|
|
4033
|
+
}
|
|
4034
|
+
function locEnd(node) {
|
|
4035
|
+
const end = node.range?.[1] ?? node.end;
|
|
4036
|
+
if (false) {
|
|
4037
|
+
throw new TypeError("Can't not locate node.");
|
|
4038
|
+
}
|
|
4039
|
+
return end;
|
|
4040
|
+
}
|
|
4041
|
+
|
|
4042
|
+
// src/language-js/utils/create-type-check-function.js
|
|
4043
|
+
function createTypeCheckFunction(typesArray) {
|
|
4044
|
+
const types = new Set(typesArray);
|
|
4045
|
+
if (false) {
|
|
4046
|
+
noop_default(typesArray.length, types.size, "'typesArray' should be unique.");
|
|
4047
|
+
}
|
|
4048
|
+
return (node) => types.has(node?.type);
|
|
4049
|
+
}
|
|
4050
|
+
var create_type_check_function_default = createTypeCheckFunction;
|
|
4051
|
+
|
|
4052
|
+
// src/language-js/utils/is-block-comment.js
|
|
4053
|
+
var isBlockComment = create_type_check_function_default([
|
|
4054
|
+
'Block',
|
|
4055
|
+
'CommentBlock',
|
|
4056
|
+
// `meriyah`
|
|
4057
|
+
'MultiLine',
|
|
4058
|
+
]);
|
|
4059
|
+
var is_block_comment_default = isBlockComment;
|
|
4060
|
+
|
|
4061
|
+
// src/language-js/utils/is-line-comment.js
|
|
4062
|
+
var isLineComment = create_type_check_function_default([
|
|
4063
|
+
'Line',
|
|
4064
|
+
'CommentLine',
|
|
4065
|
+
// `meriyah` has `SingleLine`, `HashbangComment`, `HTMLOpen`, and `HTMLClose`
|
|
4066
|
+
'SingleLine',
|
|
4067
|
+
'HashbangComment',
|
|
4068
|
+
'HTMLOpen',
|
|
4069
|
+
'HTMLClose',
|
|
4070
|
+
// `espree`, and `oxc`(with `{astType: 'ts'}`)
|
|
4071
|
+
'Hashbang',
|
|
4072
|
+
// `babel` and `flow` hashbang
|
|
4073
|
+
'InterpreterDirective',
|
|
4074
|
+
]);
|
|
4075
|
+
var is_line_comment_default = isLineComment;
|
|
4076
|
+
|
|
4077
|
+
// src/language-js/utils/is-type-cast-comment.js
|
|
4078
|
+
var cache = /* @__PURE__ */ new WeakMap();
|
|
4079
|
+
function isTypeCastComment(comment) {
|
|
4080
|
+
if (!cache.has(comment)) {
|
|
4081
|
+
cache.set(
|
|
4082
|
+
comment,
|
|
4083
|
+
is_block_comment_default(comment) &&
|
|
4084
|
+
comment.value[0] === '*' && // TypeScript expects the type to be enclosed in curly brackets, however
|
|
4085
|
+
// Closure Compiler accepts types in parens and even without any delimiters at all.
|
|
4086
|
+
// That's why we just search for "@type" and "@satisfies".
|
|
4087
|
+
/@(?:type|satisfies)\b/u.test(comment.value),
|
|
4088
|
+
);
|
|
4089
|
+
}
|
|
4090
|
+
return cache.get(comment);
|
|
4091
|
+
}
|
|
4092
|
+
var is_type_cast_comment_default = isTypeCastComment;
|
|
4093
|
+
|
|
4094
|
+
// src/language-js/utils/is-indentable-block-comment.js
|
|
4095
|
+
function isIndentableBlockCommentInternal(comment) {
|
|
4096
|
+
if (!is_block_comment_default(comment)) {
|
|
4097
|
+
return false;
|
|
4098
|
+
}
|
|
4099
|
+
const lines = `*${comment.value}*`.split('\n');
|
|
4100
|
+
return lines.length > 1 && lines.every((line) => line.trimStart()[0] === '*');
|
|
4101
|
+
}
|
|
4102
|
+
var cache2 = /* @__PURE__ */ new WeakMap();
|
|
4103
|
+
function isIndentableBlockComment(comment) {
|
|
4104
|
+
if (!cache2.has(comment)) {
|
|
4105
|
+
cache2.set(comment, isIndentableBlockCommentInternal(comment));
|
|
4106
|
+
}
|
|
4107
|
+
return cache2.get(comment);
|
|
4108
|
+
}
|
|
4109
|
+
var is_indentable_block_comment_default = isIndentableBlockComment;
|
|
4110
|
+
|
|
4111
|
+
// src/language-js/parse/postprocess/merge-nestled-jsdoc-comments.js
|
|
4112
|
+
function mergeNestledJsdocComments(comments) {
|
|
4113
|
+
if (comments.length < 2) {
|
|
4114
|
+
return;
|
|
4115
|
+
}
|
|
4116
|
+
let followingComment;
|
|
4117
|
+
for (let i = comments.length - 1; i >= 0; i--) {
|
|
4118
|
+
const comment = comments[i];
|
|
4119
|
+
if (
|
|
4120
|
+
followingComment &&
|
|
4121
|
+
locEnd(comment) === locStart(followingComment) &&
|
|
4122
|
+
is_indentable_block_comment_default(comment) &&
|
|
4123
|
+
is_indentable_block_comment_default(followingComment)
|
|
4124
|
+
) {
|
|
4125
|
+
comments.splice(i + 1, 1);
|
|
4126
|
+
comment.value += '*//*' + followingComment.value;
|
|
4127
|
+
comment.range = [locStart(comment), locEnd(followingComment)];
|
|
4128
|
+
}
|
|
4129
|
+
if (!is_line_comment_default(comment) && !is_block_comment_default(comment)) {
|
|
4130
|
+
throw new TypeError(`Unknown comment type: "${comment.type}".`);
|
|
4131
|
+
}
|
|
4132
|
+
followingComment = comment;
|
|
4133
|
+
}
|
|
4134
|
+
}
|
|
4135
|
+
var merge_nestled_jsdoc_comments_default = mergeNestledJsdocComments;
|
|
4136
|
+
|
|
4137
|
+
// node_modules/to-fast-properties/index.js
|
|
4138
|
+
var fastProto = null;
|
|
4139
|
+
function FastObject(object) {
|
|
4140
|
+
if (fastProto !== null && typeof fastProto.property) {
|
|
4141
|
+
const result = fastProto;
|
|
4142
|
+
fastProto = FastObject.prototype = null;
|
|
4143
|
+
return result;
|
|
4144
|
+
}
|
|
4145
|
+
fastProto = FastObject.prototype = object == null ? /* @__PURE__ */ Object.create(null) : object;
|
|
4146
|
+
return new FastObject();
|
|
4147
|
+
}
|
|
4148
|
+
var inlineCacheCutoff = 10;
|
|
4149
|
+
for (let index = 0; index <= inlineCacheCutoff; index++) {
|
|
4150
|
+
FastObject();
|
|
4151
|
+
}
|
|
4152
|
+
function toFastproperties(object) {
|
|
4153
|
+
return FastObject(object);
|
|
4154
|
+
}
|
|
4155
|
+
|
|
4156
|
+
// src/utils/create-get-visitor-keys.js
|
|
4157
|
+
function createGetVisitorKeys(visitorKeys, typeProperty = 'type') {
|
|
4158
|
+
toFastproperties(visitorKeys);
|
|
4159
|
+
function getVisitorKeys2(node) {
|
|
4160
|
+
const type = node[typeProperty];
|
|
4161
|
+
if (false) {
|
|
4162
|
+
throw new Error(`Can't get node type, you must pass the wrong typeProperty '${typeProperty}'`);
|
|
4163
|
+
}
|
|
4164
|
+
const keys = visitorKeys[type];
|
|
4165
|
+
if (!Array.isArray(keys)) {
|
|
4166
|
+
throw Object.assign(new Error(`Missing visitor keys for '${type}'.`), {
|
|
4167
|
+
node,
|
|
4168
|
+
});
|
|
4169
|
+
}
|
|
4170
|
+
return keys;
|
|
4171
|
+
}
|
|
4172
|
+
return getVisitorKeys2;
|
|
4173
|
+
}
|
|
4174
|
+
var create_get_visitor_keys_default = createGetVisitorKeys;
|
|
4175
|
+
|
|
4176
|
+
// src/language-js/traverse/visitor-keys.evaluate.js
|
|
4177
|
+
var visitor_keys_evaluate_default = {
|
|
4178
|
+
AccessorProperty: ['decorators', 'key', 'typeAnnotation', 'value'],
|
|
4179
|
+
AnyTypeAnnotation: [],
|
|
4180
|
+
ArgumentPlaceholder: [],
|
|
4181
|
+
ArrayExpression: ['elements'],
|
|
4182
|
+
ArrayPattern: ['elements', 'typeAnnotation', 'decorators'],
|
|
4183
|
+
ArrayTypeAnnotation: ['elementType'],
|
|
4184
|
+
ArrowFunctionExpression: ['typeParameters', 'params', 'predicate', 'returnType', 'body'],
|
|
4185
|
+
AsConstExpression: ['expression'],
|
|
4186
|
+
AsExpression: ['expression', 'typeAnnotation'],
|
|
4187
|
+
AssignmentExpression: ['left', 'right'],
|
|
4188
|
+
AssignmentPattern: ['left', 'right', 'decorators', 'typeAnnotation'],
|
|
4189
|
+
AwaitExpression: ['argument'],
|
|
4190
|
+
BigIntLiteral: [],
|
|
4191
|
+
BigIntLiteralTypeAnnotation: [],
|
|
4192
|
+
BigIntTypeAnnotation: [],
|
|
4193
|
+
BinaryExpression: ['left', 'right'],
|
|
4194
|
+
BindExpression: ['object', 'callee'],
|
|
4195
|
+
BlockStatement: ['directives', 'body'],
|
|
4196
|
+
BooleanLiteral: [],
|
|
4197
|
+
BooleanLiteralTypeAnnotation: [],
|
|
4198
|
+
BooleanTypeAnnotation: [],
|
|
4199
|
+
BreakStatement: ['label'],
|
|
4200
|
+
CallExpression: ['callee', 'typeArguments', 'arguments'],
|
|
4201
|
+
CatchClause: ['param', 'body'],
|
|
4202
|
+
ChainExpression: ['expression'],
|
|
4203
|
+
ClassAccessorProperty: ['decorators', 'key', 'typeAnnotation', 'value'],
|
|
4204
|
+
ClassBody: ['body'],
|
|
4205
|
+
ClassDeclaration: [
|
|
4206
|
+
'decorators',
|
|
4207
|
+
'id',
|
|
4208
|
+
'typeParameters',
|
|
4209
|
+
'superClass',
|
|
4210
|
+
'superTypeArguments',
|
|
4211
|
+
'mixins',
|
|
4212
|
+
'implements',
|
|
4213
|
+
'body',
|
|
4214
|
+
'superTypeParameters',
|
|
4215
|
+
],
|
|
4216
|
+
ClassExpression: [
|
|
4217
|
+
'decorators',
|
|
4218
|
+
'id',
|
|
4219
|
+
'typeParameters',
|
|
4220
|
+
'superClass',
|
|
4221
|
+
'superTypeArguments',
|
|
4222
|
+
'mixins',
|
|
4223
|
+
'implements',
|
|
4224
|
+
'body',
|
|
4225
|
+
'superTypeParameters',
|
|
4226
|
+
],
|
|
4227
|
+
ClassImplements: ['id', 'typeParameters'],
|
|
4228
|
+
ClassMethod: ['decorators', 'key', 'typeParameters', 'params', 'returnType', 'body'],
|
|
4229
|
+
ClassPrivateMethod: ['decorators', 'key', 'typeParameters', 'params', 'returnType', 'body'],
|
|
4230
|
+
ClassPrivateProperty: ['decorators', 'variance', 'key', 'typeAnnotation', 'value'],
|
|
4231
|
+
ClassProperty: ['decorators', 'variance', 'key', 'typeAnnotation', 'value'],
|
|
4232
|
+
ComponentDeclaration: ['id', 'params', 'body', 'typeParameters', 'rendersType'],
|
|
4233
|
+
ComponentParameter: ['name', 'local'],
|
|
4234
|
+
ComponentTypeAnnotation: ['params', 'rest', 'typeParameters', 'rendersType'],
|
|
4235
|
+
ComponentTypeParameter: ['name', 'typeAnnotation'],
|
|
4236
|
+
ConditionalExpression: ['test', 'consequent', 'alternate'],
|
|
4237
|
+
ConditionalTypeAnnotation: ['checkType', 'extendsType', 'trueType', 'falseType'],
|
|
4238
|
+
ContinueStatement: ['label'],
|
|
4239
|
+
DebuggerStatement: [],
|
|
4240
|
+
DeclareClass: ['id', 'typeParameters', 'extends', 'mixins', 'implements', 'body'],
|
|
4241
|
+
DeclareComponent: ['id', 'params', 'rest', 'typeParameters', 'rendersType'],
|
|
4242
|
+
DeclaredPredicate: ['value'],
|
|
4243
|
+
DeclareEnum: ['id', 'body'],
|
|
4244
|
+
DeclareExportAllDeclaration: ['source', 'attributes'],
|
|
4245
|
+
DeclareExportDeclaration: ['declaration', 'specifiers', 'source', 'attributes'],
|
|
4246
|
+
DeclareFunction: ['id', 'predicate'],
|
|
4247
|
+
DeclareHook: ['id'],
|
|
4248
|
+
DeclareInterface: ['id', 'typeParameters', 'extends', 'body'],
|
|
4249
|
+
DeclareModule: ['id', 'body'],
|
|
4250
|
+
DeclareModuleExports: ['typeAnnotation'],
|
|
4251
|
+
DeclareNamespace: ['id', 'body'],
|
|
4252
|
+
DeclareOpaqueType: ['id', 'typeParameters', 'supertype', 'lowerBound', 'upperBound'],
|
|
4253
|
+
DeclareTypeAlias: ['id', 'typeParameters', 'right'],
|
|
4254
|
+
DeclareVariable: ['id'],
|
|
4255
|
+
Decorator: ['expression'],
|
|
4256
|
+
Directive: ['value'],
|
|
4257
|
+
DirectiveLiteral: [],
|
|
4258
|
+
DoExpression: ['body'],
|
|
4259
|
+
DoWhileStatement: ['body', 'test'],
|
|
4260
|
+
EmptyStatement: [],
|
|
4261
|
+
EmptyTypeAnnotation: [],
|
|
4262
|
+
EnumBigIntBody: ['members'],
|
|
4263
|
+
EnumBigIntMember: ['id', 'init'],
|
|
4264
|
+
EnumBooleanBody: ['members'],
|
|
4265
|
+
EnumBooleanMember: ['id', 'init'],
|
|
4266
|
+
EnumDeclaration: ['id', 'body'],
|
|
4267
|
+
EnumDefaultedMember: ['id'],
|
|
4268
|
+
EnumNumberBody: ['members'],
|
|
4269
|
+
EnumNumberMember: ['id', 'init'],
|
|
4270
|
+
EnumStringBody: ['members'],
|
|
4271
|
+
EnumStringMember: ['id', 'init'],
|
|
4272
|
+
EnumSymbolBody: ['members'],
|
|
4273
|
+
ExistsTypeAnnotation: [],
|
|
4274
|
+
ExperimentalRestProperty: ['argument'],
|
|
4275
|
+
ExperimentalSpreadProperty: ['argument'],
|
|
4276
|
+
ExportAllDeclaration: ['source', 'attributes', 'exported'],
|
|
4277
|
+
ExportDefaultDeclaration: ['declaration'],
|
|
4278
|
+
ExportDefaultSpecifier: ['exported'],
|
|
4279
|
+
ExportNamedDeclaration: ['declaration', 'specifiers', 'source', 'attributes'],
|
|
4280
|
+
ExportNamespaceSpecifier: ['exported'],
|
|
4281
|
+
ExportSpecifier: ['local', 'exported'],
|
|
4282
|
+
ExpressionStatement: ['expression'],
|
|
4283
|
+
File: ['program'],
|
|
4284
|
+
ForInStatement: ['left', 'right', 'body'],
|
|
4285
|
+
ForOfStatement: ['left', 'right', 'body'],
|
|
4286
|
+
ForStatement: ['init', 'test', 'update', 'body'],
|
|
4287
|
+
FunctionDeclaration: ['id', 'typeParameters', 'params', 'predicate', 'returnType', 'body'],
|
|
4288
|
+
FunctionExpression: ['id', 'typeParameters', 'params', 'predicate', 'returnType', 'body'],
|
|
4289
|
+
FunctionTypeAnnotation: ['typeParameters', 'this', 'params', 'rest', 'returnType'],
|
|
4290
|
+
FunctionTypeParam: ['name', 'typeAnnotation'],
|
|
4291
|
+
GenericTypeAnnotation: ['id', 'typeParameters'],
|
|
4292
|
+
HookDeclaration: ['id', 'params', 'body', 'typeParameters', 'returnType'],
|
|
4293
|
+
HookTypeAnnotation: ['params', 'returnType', 'rest', 'typeParameters'],
|
|
4294
|
+
Identifier: ['typeAnnotation', 'decorators'],
|
|
4295
|
+
IfStatement: ['test', 'consequent', 'alternate'],
|
|
4296
|
+
ImportAttribute: ['key', 'value'],
|
|
4297
|
+
ImportDeclaration: ['specifiers', 'source', 'attributes'],
|
|
4298
|
+
ImportDefaultSpecifier: ['local'],
|
|
4299
|
+
ImportExpression: ['source', 'options'],
|
|
4300
|
+
ImportNamespaceSpecifier: ['local'],
|
|
4301
|
+
ImportSpecifier: ['imported', 'local'],
|
|
4302
|
+
IndexedAccessType: ['objectType', 'indexType'],
|
|
4303
|
+
InferredPredicate: [],
|
|
4304
|
+
InferTypeAnnotation: ['typeParameter'],
|
|
4305
|
+
InterfaceDeclaration: ['id', 'typeParameters', 'extends', 'body'],
|
|
4306
|
+
InterfaceExtends: ['id', 'typeParameters'],
|
|
4307
|
+
InterfaceTypeAnnotation: ['extends', 'body'],
|
|
4308
|
+
InterpreterDirective: [],
|
|
4309
|
+
IntersectionTypeAnnotation: ['types'],
|
|
4310
|
+
JsExpressionRoot: ['node'],
|
|
4311
|
+
JsonRoot: ['node'],
|
|
4312
|
+
JSXAttribute: ['name', 'value'],
|
|
4313
|
+
JSXClosingElement: ['name'],
|
|
4314
|
+
JSXClosingFragment: [],
|
|
4315
|
+
JSXElement: ['openingElement', 'children', 'closingElement'],
|
|
4316
|
+
JSXEmptyExpression: [],
|
|
4317
|
+
JSXExpressionContainer: ['expression'],
|
|
4318
|
+
JSXFragment: ['openingFragment', 'children', 'closingFragment'],
|
|
4319
|
+
JSXIdentifier: [],
|
|
4320
|
+
JSXMemberExpression: ['object', 'property'],
|
|
4321
|
+
JSXNamespacedName: ['namespace', 'name'],
|
|
4322
|
+
JSXOpeningElement: ['name', 'typeArguments', 'attributes'],
|
|
4323
|
+
JSXOpeningFragment: [],
|
|
4324
|
+
JSXSpreadAttribute: ['argument'],
|
|
4325
|
+
JSXSpreadChild: ['expression'],
|
|
4326
|
+
JSXText: [],
|
|
4327
|
+
KeyofTypeAnnotation: ['argument'],
|
|
4328
|
+
LabeledStatement: ['label', 'body'],
|
|
4329
|
+
Literal: [],
|
|
4330
|
+
LogicalExpression: ['left', 'right'],
|
|
4331
|
+
MatchArrayPattern: ['elements', 'rest'],
|
|
4332
|
+
MatchAsPattern: ['pattern', 'target'],
|
|
4333
|
+
MatchBindingPattern: ['id'],
|
|
4334
|
+
MatchExpression: ['argument', 'cases'],
|
|
4335
|
+
MatchExpressionCase: ['pattern', 'body', 'guard'],
|
|
4336
|
+
MatchIdentifierPattern: ['id'],
|
|
4337
|
+
MatchLiteralPattern: ['literal'],
|
|
4338
|
+
MatchMemberPattern: ['base', 'property'],
|
|
4339
|
+
MatchObjectPattern: ['properties', 'rest'],
|
|
4340
|
+
MatchObjectPatternProperty: ['key', 'pattern'],
|
|
4341
|
+
MatchOrPattern: ['patterns'],
|
|
4342
|
+
MatchRestPattern: ['argument'],
|
|
4343
|
+
MatchStatement: ['argument', 'cases'],
|
|
4344
|
+
MatchStatementCase: ['pattern', 'body', 'guard'],
|
|
4345
|
+
MatchUnaryPattern: ['argument'],
|
|
4346
|
+
MatchWildcardPattern: [],
|
|
4347
|
+
MemberExpression: ['object', 'property'],
|
|
4348
|
+
MetaProperty: ['meta', 'property'],
|
|
4349
|
+
MethodDefinition: ['decorators', 'key', 'value'],
|
|
4350
|
+
MixedTypeAnnotation: [],
|
|
4351
|
+
ModuleExpression: ['body'],
|
|
4352
|
+
NeverTypeAnnotation: [],
|
|
4353
|
+
NewExpression: ['callee', 'typeArguments', 'arguments'],
|
|
4354
|
+
NGChainedExpression: ['expressions'],
|
|
4355
|
+
NGEmptyExpression: [],
|
|
4356
|
+
NGMicrosyntax: ['body'],
|
|
4357
|
+
NGMicrosyntaxAs: ['key', 'alias'],
|
|
4358
|
+
NGMicrosyntaxExpression: ['expression', 'alias'],
|
|
4359
|
+
NGMicrosyntaxKey: [],
|
|
4360
|
+
NGMicrosyntaxKeyedExpression: ['key', 'expression'],
|
|
4361
|
+
NGMicrosyntaxLet: ['key', 'value'],
|
|
4362
|
+
NGPipeExpression: ['left', 'right', 'arguments'],
|
|
4363
|
+
NGRoot: ['node'],
|
|
4364
|
+
NullableTypeAnnotation: ['typeAnnotation'],
|
|
4365
|
+
NullLiteral: [],
|
|
4366
|
+
NullLiteralTypeAnnotation: [],
|
|
4367
|
+
NumberLiteralTypeAnnotation: [],
|
|
4368
|
+
NumberTypeAnnotation: [],
|
|
4369
|
+
NumericLiteral: [],
|
|
4370
|
+
ObjectExpression: ['properties'],
|
|
4371
|
+
ObjectMethod: ['decorators', 'key', 'typeParameters', 'params', 'returnType', 'body'],
|
|
4372
|
+
ObjectPattern: ['decorators', 'properties', 'typeAnnotation'],
|
|
4373
|
+
ObjectProperty: ['decorators', 'key', 'value'],
|
|
4374
|
+
ObjectTypeAnnotation: ['properties', 'indexers', 'callProperties', 'internalSlots'],
|
|
4375
|
+
ObjectTypeCallProperty: ['value'],
|
|
4376
|
+
ObjectTypeIndexer: ['variance', 'id', 'key', 'value'],
|
|
4377
|
+
ObjectTypeInternalSlot: ['id', 'value'],
|
|
4378
|
+
ObjectTypeMappedTypeProperty: ['keyTparam', 'propType', 'sourceType', 'variance'],
|
|
4379
|
+
ObjectTypeProperty: ['key', 'value', 'variance'],
|
|
4380
|
+
ObjectTypeSpreadProperty: ['argument'],
|
|
4381
|
+
OpaqueType: ['id', 'typeParameters', 'supertype', 'impltype', 'lowerBound', 'upperBound'],
|
|
4382
|
+
OptionalCallExpression: ['callee', 'typeArguments', 'arguments'],
|
|
4383
|
+
OptionalIndexedAccessType: ['objectType', 'indexType'],
|
|
4384
|
+
OptionalMemberExpression: ['object', 'property'],
|
|
4385
|
+
ParenthesizedExpression: ['expression'],
|
|
4386
|
+
PipelineBareFunction: ['callee'],
|
|
4387
|
+
PipelinePrimaryTopicReference: [],
|
|
4388
|
+
PipelineTopicExpression: ['expression'],
|
|
4389
|
+
Placeholder: [],
|
|
4390
|
+
PrivateIdentifier: [],
|
|
4391
|
+
PrivateName: ['id'],
|
|
4392
|
+
Program: ['directives', 'body'],
|
|
4393
|
+
Property: ['key', 'value'],
|
|
4394
|
+
PropertyDefinition: ['decorators', 'key', 'typeAnnotation', 'value', 'variance'],
|
|
4395
|
+
QualifiedTypeIdentifier: ['qualification', 'id'],
|
|
4396
|
+
QualifiedTypeofIdentifier: ['qualification', 'id'],
|
|
4397
|
+
RegExpLiteral: [],
|
|
4398
|
+
RestElement: ['argument', 'typeAnnotation', 'decorators'],
|
|
4399
|
+
ReturnStatement: ['argument'],
|
|
4400
|
+
SatisfiesExpression: ['expression', 'typeAnnotation'],
|
|
4401
|
+
SequenceExpression: ['expressions'],
|
|
4402
|
+
SpreadElement: ['argument'],
|
|
4403
|
+
StaticBlock: ['body'],
|
|
4404
|
+
StringLiteral: [],
|
|
4405
|
+
StringLiteralTypeAnnotation: [],
|
|
4406
|
+
StringTypeAnnotation: [],
|
|
4407
|
+
Super: [],
|
|
4408
|
+
SwitchCase: ['test', 'consequent'],
|
|
4409
|
+
SwitchStatement: ['discriminant', 'cases'],
|
|
4410
|
+
SymbolTypeAnnotation: [],
|
|
4411
|
+
TaggedTemplateExpression: ['tag', 'typeArguments', 'quasi'],
|
|
4412
|
+
TemplateElement: [],
|
|
4413
|
+
TemplateLiteral: ['quasis', 'expressions'],
|
|
4414
|
+
ThisExpression: [],
|
|
4415
|
+
ThisTypeAnnotation: [],
|
|
4416
|
+
ThrowStatement: ['argument'],
|
|
4417
|
+
TopicReference: [],
|
|
4418
|
+
TryStatement: ['block', 'handler', 'finalizer'],
|
|
4419
|
+
TSAbstractAccessorProperty: ['decorators', 'key', 'typeAnnotation'],
|
|
4420
|
+
TSAbstractKeyword: [],
|
|
4421
|
+
TSAbstractMethodDefinition: ['key', 'value'],
|
|
4422
|
+
TSAbstractPropertyDefinition: ['decorators', 'key', 'typeAnnotation'],
|
|
4423
|
+
TSAnyKeyword: [],
|
|
4424
|
+
TSArrayType: ['elementType'],
|
|
4425
|
+
TSAsExpression: ['expression', 'typeAnnotation'],
|
|
4426
|
+
TSAsyncKeyword: [],
|
|
4427
|
+
TSBigIntKeyword: [],
|
|
4428
|
+
TSBooleanKeyword: [],
|
|
4429
|
+
TSCallSignatureDeclaration: ['typeParameters', 'params', 'returnType'],
|
|
4430
|
+
TSClassImplements: ['expression', 'typeArguments'],
|
|
4431
|
+
TSConditionalType: ['checkType', 'extendsType', 'trueType', 'falseType'],
|
|
4432
|
+
TSConstructorType: ['typeParameters', 'params', 'returnType'],
|
|
4433
|
+
TSConstructSignatureDeclaration: ['typeParameters', 'params', 'returnType'],
|
|
4434
|
+
TSDeclareFunction: ['id', 'typeParameters', 'params', 'returnType', 'body'],
|
|
4435
|
+
TSDeclareKeyword: [],
|
|
4436
|
+
TSDeclareMethod: ['decorators', 'key', 'typeParameters', 'params', 'returnType'],
|
|
4437
|
+
TSEmptyBodyFunctionExpression: ['id', 'typeParameters', 'params', 'returnType'],
|
|
4438
|
+
TSEnumBody: ['members'],
|
|
4439
|
+
TSEnumDeclaration: ['id', 'body'],
|
|
4440
|
+
TSEnumMember: ['id', 'initializer'],
|
|
4441
|
+
TSExportAssignment: ['expression'],
|
|
4442
|
+
TSExportKeyword: [],
|
|
4443
|
+
TSExternalModuleReference: ['expression'],
|
|
4444
|
+
TSFunctionType: ['typeParameters', 'params', 'returnType'],
|
|
4445
|
+
TSImportEqualsDeclaration: ['id', 'moduleReference'],
|
|
4446
|
+
TSImportType: ['argument', 'options', 'qualifier', 'typeArguments'],
|
|
4447
|
+
TSIndexedAccessType: ['objectType', 'indexType'],
|
|
4448
|
+
TSIndexSignature: ['parameters', 'typeAnnotation'],
|
|
4449
|
+
TSInferType: ['typeParameter'],
|
|
4450
|
+
TSInstantiationExpression: ['expression', 'typeArguments'],
|
|
4451
|
+
TSInterfaceBody: ['body'],
|
|
4452
|
+
TSInterfaceDeclaration: ['id', 'typeParameters', 'extends', 'body'],
|
|
4453
|
+
TSInterfaceHeritage: ['expression', 'typeArguments'],
|
|
4454
|
+
TSIntersectionType: ['types'],
|
|
4455
|
+
TSIntrinsicKeyword: [],
|
|
4456
|
+
TSJSDocAllType: [],
|
|
4457
|
+
TSJSDocNonNullableType: ['typeAnnotation'],
|
|
4458
|
+
TSJSDocNullableType: ['typeAnnotation'],
|
|
4459
|
+
TSJSDocUnknownType: [],
|
|
4460
|
+
TSLiteralType: ['literal'],
|
|
4461
|
+
TSMappedType: ['key', 'constraint', 'nameType', 'typeAnnotation'],
|
|
4462
|
+
TSMethodSignature: ['key', 'typeParameters', 'params', 'returnType'],
|
|
4463
|
+
TSModuleBlock: ['body'],
|
|
4464
|
+
TSModuleDeclaration: ['id', 'body'],
|
|
4465
|
+
TSNamedTupleMember: ['label', 'elementType'],
|
|
4466
|
+
TSNamespaceExportDeclaration: ['id'],
|
|
4467
|
+
TSNeverKeyword: [],
|
|
4468
|
+
TSNonNullExpression: ['expression'],
|
|
4469
|
+
TSNullKeyword: [],
|
|
4470
|
+
TSNumberKeyword: [],
|
|
4471
|
+
TSObjectKeyword: [],
|
|
4472
|
+
TSOptionalType: ['typeAnnotation'],
|
|
4473
|
+
TSParameterProperty: ['parameter', 'decorators'],
|
|
4474
|
+
TSParenthesizedType: ['typeAnnotation'],
|
|
4475
|
+
TSPrivateKeyword: [],
|
|
4476
|
+
TSPropertySignature: ['key', 'typeAnnotation'],
|
|
4477
|
+
TSProtectedKeyword: [],
|
|
4478
|
+
TSPublicKeyword: [],
|
|
4479
|
+
TSQualifiedName: ['left', 'right'],
|
|
4480
|
+
TSReadonlyKeyword: [],
|
|
4481
|
+
TSRestType: ['typeAnnotation'],
|
|
4482
|
+
TSSatisfiesExpression: ['expression', 'typeAnnotation'],
|
|
4483
|
+
TSStaticKeyword: [],
|
|
4484
|
+
TSStringKeyword: [],
|
|
4485
|
+
TSSymbolKeyword: [],
|
|
4486
|
+
TSTemplateLiteralType: ['quasis', 'types'],
|
|
4487
|
+
TSThisType: [],
|
|
4488
|
+
TSTupleType: ['elementTypes'],
|
|
4489
|
+
TSTypeAliasDeclaration: ['id', 'typeParameters', 'typeAnnotation'],
|
|
4490
|
+
TSTypeAnnotation: ['typeAnnotation'],
|
|
4491
|
+
TSTypeAssertion: ['typeAnnotation', 'expression'],
|
|
4492
|
+
TSTypeLiteral: ['members'],
|
|
4493
|
+
TSTypeOperator: ['typeAnnotation'],
|
|
4494
|
+
TSTypeParameter: ['name', 'constraint', 'default'],
|
|
4495
|
+
TSTypeParameterDeclaration: ['params'],
|
|
4496
|
+
TSTypeParameterInstantiation: ['params'],
|
|
4497
|
+
TSTypePredicate: ['parameterName', 'typeAnnotation'],
|
|
4498
|
+
TSTypeQuery: ['exprName', 'typeArguments'],
|
|
4499
|
+
TSTypeReference: ['typeName', 'typeArguments'],
|
|
4500
|
+
TSUndefinedKeyword: [],
|
|
4501
|
+
TSUnionType: ['types'],
|
|
4502
|
+
TSUnknownKeyword: [],
|
|
4503
|
+
TSVoidKeyword: [],
|
|
4504
|
+
TupleTypeAnnotation: ['types', 'elementTypes'],
|
|
4505
|
+
TupleTypeLabeledElement: ['label', 'elementType', 'variance'],
|
|
4506
|
+
TupleTypeSpreadElement: ['label', 'typeAnnotation'],
|
|
4507
|
+
TypeAlias: ['id', 'typeParameters', 'right'],
|
|
4508
|
+
TypeAnnotation: ['typeAnnotation'],
|
|
4509
|
+
TypeCastExpression: ['expression', 'typeAnnotation'],
|
|
4510
|
+
TypeofTypeAnnotation: ['argument', 'typeArguments'],
|
|
4511
|
+
TypeOperator: ['typeAnnotation'],
|
|
4512
|
+
TypeParameter: ['bound', 'default', 'variance'],
|
|
4513
|
+
TypeParameterDeclaration: ['params'],
|
|
4514
|
+
TypeParameterInstantiation: ['params'],
|
|
4515
|
+
TypePredicate: ['parameterName', 'typeAnnotation'],
|
|
4516
|
+
UnaryExpression: ['argument'],
|
|
4517
|
+
UndefinedTypeAnnotation: [],
|
|
4518
|
+
UnionTypeAnnotation: ['types'],
|
|
4519
|
+
UnknownTypeAnnotation: [],
|
|
4520
|
+
UpdateExpression: ['argument'],
|
|
4521
|
+
V8IntrinsicIdentifier: [],
|
|
4522
|
+
VariableDeclaration: ['declarations'],
|
|
4523
|
+
VariableDeclarator: ['id', 'init'],
|
|
4524
|
+
Variance: [],
|
|
4525
|
+
VoidPattern: [],
|
|
4526
|
+
VoidTypeAnnotation: [],
|
|
4527
|
+
WhileStatement: ['test', 'body'],
|
|
4528
|
+
WithStatement: ['object', 'body'],
|
|
4529
|
+
YieldExpression: ['argument'],
|
|
4530
|
+
};
|
|
4531
|
+
|
|
4532
|
+
// src/language-js/traverse/get-visitor-keys.js
|
|
4533
|
+
var getVisitorKeys = create_get_visitor_keys_default(visitor_keys_evaluate_default);
|
|
4534
|
+
var get_visitor_keys_default = getVisitorKeys;
|
|
4535
|
+
|
|
4536
|
+
// src/language-js/parse/postprocess/visit-node.js
|
|
4537
|
+
function visitNode(node, options) {
|
|
4538
|
+
if (!(node !== null && typeof node === 'object')) {
|
|
4539
|
+
return node;
|
|
4540
|
+
}
|
|
4541
|
+
if (Array.isArray(node)) {
|
|
4542
|
+
for (let i = 0; i < node.length; i++) {
|
|
4543
|
+
node[i] = visitNode(node[i], options);
|
|
4544
|
+
}
|
|
4545
|
+
return node;
|
|
4546
|
+
}
|
|
4547
|
+
if (options.onEnter) {
|
|
4548
|
+
node = options.onEnter(node) || node;
|
|
4549
|
+
}
|
|
4550
|
+
const keys = get_visitor_keys_default(node);
|
|
4551
|
+
for (let i = 0; i < keys.length; i++) {
|
|
4552
|
+
node[keys[i]] = visitNode(node[keys[i]], options);
|
|
4553
|
+
}
|
|
4554
|
+
return options.onLeave(node) || node;
|
|
4555
|
+
}
|
|
4556
|
+
var visit_node_default = visitNode;
|
|
4557
|
+
|
|
4558
|
+
// src/language-js/parse/postprocess/index.js
|
|
4559
|
+
var isNodeWithRaw = create_type_check_function_default([
|
|
4560
|
+
// Babel
|
|
4561
|
+
'RegExpLiteral',
|
|
4562
|
+
'BigIntLiteral',
|
|
4563
|
+
'NumericLiteral',
|
|
4564
|
+
'StringLiteral',
|
|
4565
|
+
// "NullLiteral",
|
|
4566
|
+
// "BooleanLiteral",
|
|
4567
|
+
'DirectiveLiteral',
|
|
4568
|
+
// ESTree
|
|
4569
|
+
'Literal',
|
|
4570
|
+
'JSXText',
|
|
4571
|
+
'TemplateElement',
|
|
4572
|
+
// Flow
|
|
4573
|
+
'StringLiteralTypeAnnotation',
|
|
4574
|
+
'NumberLiteralTypeAnnotation',
|
|
4575
|
+
'BigIntLiteralTypeAnnotation',
|
|
4576
|
+
]);
|
|
4577
|
+
function postprocess(ast, options) {
|
|
4578
|
+
const { parser, text } = options;
|
|
4579
|
+
const { comments } = ast;
|
|
4580
|
+
const isOxcTs = parser === 'oxc' && options.oxcAstType === 'ts';
|
|
4581
|
+
merge_nestled_jsdoc_comments_default(comments);
|
|
4582
|
+
let typeCastCommentsEnds;
|
|
4583
|
+
ast = visit_node_default(ast, {
|
|
4584
|
+
onLeave(node) {
|
|
4585
|
+
switch (node.type) {
|
|
4586
|
+
case 'ParenthesizedExpression': {
|
|
4587
|
+
const { expression } = node;
|
|
4588
|
+
const start = locStart(node);
|
|
4589
|
+
if (expression.type === 'TypeCastExpression') {
|
|
4590
|
+
expression.range = [start, locEnd(node)];
|
|
4591
|
+
return expression;
|
|
4592
|
+
}
|
|
4593
|
+
let keepTypeCast = false;
|
|
4594
|
+
if (!isOxcTs) {
|
|
4595
|
+
if (!typeCastCommentsEnds) {
|
|
4596
|
+
typeCastCommentsEnds = [];
|
|
4597
|
+
for (const comment of comments) {
|
|
4598
|
+
if (is_type_cast_comment_default(comment)) {
|
|
4599
|
+
typeCastCommentsEnds.push(locEnd(comment));
|
|
4600
|
+
}
|
|
4601
|
+
}
|
|
4602
|
+
}
|
|
4603
|
+
const previousCommentEnd = method_find_last_default(
|
|
4604
|
+
/* OPTIONAL_OBJECT: false */
|
|
4605
|
+
0,
|
|
4606
|
+
typeCastCommentsEnds,
|
|
4607
|
+
(end) => end <= start,
|
|
4608
|
+
);
|
|
4609
|
+
keepTypeCast =
|
|
4610
|
+
previousCommentEnd && // check that there are only white spaces between the comment and the parenthesis
|
|
4611
|
+
text.slice(previousCommentEnd, start).trim().length === 0;
|
|
4612
|
+
}
|
|
4613
|
+
if (!keepTypeCast) {
|
|
4614
|
+
expression.extra = {
|
|
4615
|
+
...expression.extra,
|
|
4616
|
+
parenthesized: true,
|
|
4617
|
+
};
|
|
4618
|
+
return expression;
|
|
4619
|
+
}
|
|
4620
|
+
break;
|
|
4621
|
+
}
|
|
4622
|
+
case 'LogicalExpression':
|
|
4623
|
+
if (isUnbalancedLogicalTree(node)) {
|
|
4624
|
+
return rebalanceLogicalTree(node);
|
|
4625
|
+
}
|
|
4626
|
+
break;
|
|
4627
|
+
// This happens when use `oxc-parser` to parse `` `${foo satisfies bar}`; ``
|
|
4628
|
+
// https://github.com/oxc-project/oxc/issues/11313
|
|
4629
|
+
case 'TemplateLiteral':
|
|
4630
|
+
if (node.expressions.length !== node.quasis.length - 1) {
|
|
4631
|
+
throw new Error('Malformed template literal.');
|
|
4632
|
+
}
|
|
4633
|
+
break;
|
|
4634
|
+
case 'TemplateElement':
|
|
4635
|
+
if (
|
|
4636
|
+
parser === 'flow' ||
|
|
4637
|
+
parser === 'hermes' ||
|
|
4638
|
+
parser === 'espree' ||
|
|
4639
|
+
parser === 'typescript' ||
|
|
4640
|
+
isOxcTs
|
|
4641
|
+
) {
|
|
4642
|
+
const start = locStart(node) + 1;
|
|
4643
|
+
const end = locEnd(node) - (node.tail ? 1 : 2);
|
|
4644
|
+
node.range = [start, end];
|
|
4645
|
+
}
|
|
4646
|
+
break;
|
|
4647
|
+
// fix unexpected locEnd caused by --no-semi style
|
|
4648
|
+
case 'VariableDeclaration': {
|
|
4649
|
+
const lastDeclaration = method_at_default(
|
|
4650
|
+
/* OPTIONAL_OBJECT: false */
|
|
4651
|
+
0,
|
|
4652
|
+
node.declarations,
|
|
4653
|
+
-1,
|
|
4654
|
+
);
|
|
4655
|
+
if (lastDeclaration?.init && text[locEnd(lastDeclaration)] !== ';') {
|
|
4656
|
+
node.range = [locStart(node), locEnd(lastDeclaration)];
|
|
4657
|
+
}
|
|
4658
|
+
break;
|
|
4659
|
+
}
|
|
4660
|
+
// remove redundant TypeScript nodes
|
|
4661
|
+
case 'TSParenthesizedType':
|
|
4662
|
+
return node.typeAnnotation;
|
|
4663
|
+
// For hack-style pipeline
|
|
4664
|
+
case 'TopicReference':
|
|
4665
|
+
ast.extra = {
|
|
4666
|
+
...ast.extra,
|
|
4667
|
+
__isUsingHackPipeline: true,
|
|
4668
|
+
};
|
|
4669
|
+
break;
|
|
4670
|
+
// In Flow parser, it doesn't generate union/intersection types for single type
|
|
4671
|
+
case 'TSUnionType':
|
|
4672
|
+
case 'TSIntersectionType':
|
|
4673
|
+
if (node.types.length === 1) {
|
|
4674
|
+
return node.types[0];
|
|
4675
|
+
}
|
|
4676
|
+
break;
|
|
4677
|
+
// https://github.com/facebook/hermes/issues/1712
|
|
4678
|
+
case 'ImportExpression':
|
|
4679
|
+
if (parser === 'hermes' && node.attributes && !node.options) {
|
|
4680
|
+
node.options = node.attributes;
|
|
4681
|
+
}
|
|
4682
|
+
break;
|
|
4683
|
+
}
|
|
4684
|
+
if (false) {
|
|
4685
|
+
assertRaw(node, text);
|
|
4686
|
+
}
|
|
4687
|
+
},
|
|
4688
|
+
});
|
|
4689
|
+
const program = ast.type === 'File' ? ast.program : ast;
|
|
4690
|
+
if (program.interpreter) {
|
|
4691
|
+
comments.unshift(program.interpreter);
|
|
4692
|
+
delete program.interpreter;
|
|
4693
|
+
}
|
|
4694
|
+
if (isOxcTs && ast.hashbang) {
|
|
4695
|
+
comments.unshift(ast.hashbang);
|
|
4696
|
+
delete ast.hashbang;
|
|
4697
|
+
}
|
|
4698
|
+
if (false) {
|
|
4699
|
+
assertComments(comments, text);
|
|
4700
|
+
}
|
|
4701
|
+
if (ast.type === 'Program') {
|
|
4702
|
+
ast.range = [0, text.length];
|
|
4703
|
+
}
|
|
4704
|
+
return ast;
|
|
4705
|
+
}
|
|
4706
|
+
function isUnbalancedLogicalTree(node) {
|
|
4707
|
+
return (
|
|
4708
|
+
node.type === 'LogicalExpression' &&
|
|
4709
|
+
node.right.type === 'LogicalExpression' &&
|
|
4710
|
+
node.operator === node.right.operator
|
|
4711
|
+
);
|
|
4712
|
+
}
|
|
4713
|
+
function rebalanceLogicalTree(node) {
|
|
4714
|
+
if (!isUnbalancedLogicalTree(node)) {
|
|
4715
|
+
return node;
|
|
4716
|
+
}
|
|
4717
|
+
return rebalanceLogicalTree({
|
|
4718
|
+
type: 'LogicalExpression',
|
|
4719
|
+
operator: node.operator,
|
|
4720
|
+
left: rebalanceLogicalTree({
|
|
4721
|
+
type: 'LogicalExpression',
|
|
4722
|
+
operator: node.operator,
|
|
4723
|
+
left: node.left,
|
|
4724
|
+
right: node.right.left,
|
|
4725
|
+
range: [locStart(node.left), locEnd(node.right.left)],
|
|
4726
|
+
}),
|
|
4727
|
+
right: node.right.right,
|
|
4728
|
+
range: [locStart(node), locEnd(node)],
|
|
4729
|
+
});
|
|
4730
|
+
}
|
|
4731
|
+
var postprocess_default = postprocess;
|
|
4732
|
+
|
|
4733
|
+
// node_modules/jest-docblock/build/index.js
|
|
4734
|
+
var commentEndRe = /\*\/$/;
|
|
4735
|
+
var commentStartRe = /^\/\*\*?/;
|
|
4736
|
+
var docblockRe = /^\s*(\/\*\*?(.|\r?\n)*?\*\/)/;
|
|
4737
|
+
var lineCommentRe = /(^|\s+)\/\/([^\n\r]*)/g;
|
|
4738
|
+
var ltrimNewlineRe = /^(\r?\n)+/;
|
|
4739
|
+
var multilineRe = /(?:^|\r?\n) *(@[^\n\r]*?) *\r?\n *(?![^\n\r@]*\/\/[^]*)([^\s@][^\n\r@]+?) *\r?\n/g;
|
|
4740
|
+
var propertyRe = /(?:^|\r?\n) *@(\S+) *([^\n\r]*)/g;
|
|
4741
|
+
var stringStartRe = /(\r?\n|^) *\* ?/g;
|
|
4742
|
+
var STRING_ARRAY = [];
|
|
4743
|
+
function extract(contents) {
|
|
4744
|
+
const match = contents.match(docblockRe);
|
|
4745
|
+
return match ? match[0].trimStart() : '';
|
|
4746
|
+
}
|
|
4747
|
+
function parseWithComments(docblock) {
|
|
4748
|
+
const line = '\n';
|
|
4749
|
+
docblock = method_replace_all_default(
|
|
4750
|
+
/* OPTIONAL_OBJECT: false */
|
|
4751
|
+
0,
|
|
4752
|
+
docblock.replace(commentStartRe, '').replace(commentEndRe, ''),
|
|
4753
|
+
stringStartRe,
|
|
4754
|
+
'$1',
|
|
4755
|
+
);
|
|
4756
|
+
let prev = '';
|
|
4757
|
+
while (prev !== docblock) {
|
|
4758
|
+
prev = docblock;
|
|
4759
|
+
docblock = method_replace_all_default(
|
|
4760
|
+
/* OPTIONAL_OBJECT: false */
|
|
4761
|
+
0,
|
|
4762
|
+
docblock,
|
|
4763
|
+
multilineRe,
|
|
4764
|
+
`${line}$1 $2${line}`,
|
|
4765
|
+
);
|
|
4766
|
+
}
|
|
4767
|
+
docblock = docblock.replace(ltrimNewlineRe, '').trimEnd();
|
|
4768
|
+
const result = /* @__PURE__ */ Object.create(null);
|
|
4769
|
+
const comments = method_replace_all_default(
|
|
4770
|
+
/* OPTIONAL_OBJECT: false */
|
|
4771
|
+
0,
|
|
4772
|
+
docblock,
|
|
4773
|
+
propertyRe,
|
|
4774
|
+
'',
|
|
4775
|
+
)
|
|
4776
|
+
.replace(ltrimNewlineRe, '')
|
|
4777
|
+
.trimEnd();
|
|
4778
|
+
let match;
|
|
4779
|
+
while ((match = propertyRe.exec(docblock))) {
|
|
4780
|
+
const nextPragma = method_replace_all_default(
|
|
4781
|
+
/* OPTIONAL_OBJECT: false */
|
|
4782
|
+
0,
|
|
4783
|
+
match[2],
|
|
4784
|
+
lineCommentRe,
|
|
4785
|
+
'',
|
|
4786
|
+
);
|
|
4787
|
+
if (typeof result[match[1]] === 'string' || Array.isArray(result[match[1]])) {
|
|
4788
|
+
const resultElement = result[match[1]];
|
|
4789
|
+
result[match[1]] = [
|
|
4790
|
+
...STRING_ARRAY,
|
|
4791
|
+
...(Array.isArray(resultElement) ? resultElement : [resultElement]),
|
|
4792
|
+
nextPragma,
|
|
4793
|
+
];
|
|
4794
|
+
} else {
|
|
4795
|
+
result[match[1]] = nextPragma;
|
|
4796
|
+
}
|
|
4797
|
+
}
|
|
4798
|
+
return {
|
|
4799
|
+
comments,
|
|
4800
|
+
pragmas: result,
|
|
4801
|
+
};
|
|
4802
|
+
}
|
|
4803
|
+
|
|
4804
|
+
// src/utils/pragma/pragma.evaluate.js
|
|
4805
|
+
var FORMAT_IGNORE_PRAGMAS = ['noformat', 'noprettier'];
|
|
4806
|
+
var FORMAT_PRAGMAS = ['format', 'prettier'];
|
|
4807
|
+
|
|
4808
|
+
// src/language-js/utils/get-shebang.js
|
|
4809
|
+
function getShebang2(text) {
|
|
4810
|
+
if (!text.startsWith('#!')) {
|
|
4811
|
+
return '';
|
|
4812
|
+
}
|
|
4813
|
+
const index = text.indexOf('\n');
|
|
4814
|
+
if (index === -1) {
|
|
4815
|
+
return text;
|
|
4816
|
+
}
|
|
4817
|
+
return text.slice(0, index);
|
|
4818
|
+
}
|
|
4819
|
+
var get_shebang_default = getShebang2;
|
|
4820
|
+
|
|
4821
|
+
// src/language-js/pragma.js
|
|
4822
|
+
function parseDocBlock(text) {
|
|
4823
|
+
const shebang = get_shebang_default(text);
|
|
4824
|
+
if (shebang) {
|
|
4825
|
+
text = text.slice(shebang.length + 1);
|
|
4826
|
+
}
|
|
4827
|
+
const docBlock = extract(text);
|
|
4828
|
+
const { pragmas, comments } = parseWithComments(docBlock);
|
|
4829
|
+
return {
|
|
4830
|
+
shebang,
|
|
4831
|
+
text,
|
|
4832
|
+
pragmas,
|
|
4833
|
+
comments,
|
|
4834
|
+
};
|
|
4835
|
+
}
|
|
4836
|
+
function hasPragma(text) {
|
|
4837
|
+
const { pragmas } = parseDocBlock(text);
|
|
4838
|
+
return FORMAT_PRAGMAS.some((pragma) => Object.prototype.hasOwnProperty.call(pragmas, pragma));
|
|
4839
|
+
}
|
|
4840
|
+
function hasIgnorePragma(text) {
|
|
4841
|
+
const { pragmas } = parseDocBlock(text);
|
|
4842
|
+
return FORMAT_IGNORE_PRAGMAS.some((pragma) => Object.prototype.hasOwnProperty.call(pragmas, pragma));
|
|
4843
|
+
}
|
|
4844
|
+
|
|
4845
|
+
// src/language-js/parse/utils/create-parser.js
|
|
4846
|
+
function createParser(options) {
|
|
4847
|
+
options = typeof options === 'function' ? { parse: options } : options;
|
|
4848
|
+
return {
|
|
4849
|
+
astFormat: 'estree',
|
|
4850
|
+
hasPragma,
|
|
4851
|
+
hasIgnorePragma,
|
|
4852
|
+
locStart,
|
|
4853
|
+
locEnd,
|
|
4854
|
+
...options,
|
|
4855
|
+
};
|
|
4856
|
+
}
|
|
4857
|
+
var create_parser_default = createParser;
|
|
4858
|
+
|
|
4859
|
+
// src/language-js/parse/utils/jsx-regexp.evaluate.js
|
|
4860
|
+
var jsx_regexp_evaluate_default = /^[^"'`]*<\/|^[^/]{2}.*\/>/mu;
|
|
4861
|
+
|
|
4862
|
+
// src/language-js/parse/utils/replace-hashbang.js
|
|
4863
|
+
function replaceHashbang(text) {
|
|
4864
|
+
if (text.charAt(0) === '#' && text.charAt(1) === '!') {
|
|
4865
|
+
return '//' + text.slice(2);
|
|
4866
|
+
}
|
|
4867
|
+
return text;
|
|
4868
|
+
}
|
|
4869
|
+
var replace_hashbang_default = replaceHashbang;
|
|
4870
|
+
|
|
4871
|
+
// src/language-js/parse/utils/source-types.js
|
|
4872
|
+
var SOURCE_TYPE_MODULE = 'module';
|
|
4873
|
+
var SOURCE_TYPE_SCRIPT = 'script';
|
|
4874
|
+
var SOURCE_TYPE_COMBINATIONS = [SOURCE_TYPE_MODULE, SOURCE_TYPE_SCRIPT];
|
|
4875
|
+
function getSourceType(filepath) {
|
|
4876
|
+
if (typeof filepath !== 'string') {
|
|
4877
|
+
return;
|
|
4878
|
+
}
|
|
4879
|
+
filepath = filepath.toLowerCase();
|
|
4880
|
+
if (/\.(?:mjs|mts)$/iu.test(filepath)) {
|
|
4881
|
+
return SOURCE_TYPE_MODULE;
|
|
4882
|
+
}
|
|
4883
|
+
if (/\.(?:cjs|cts)$/iu.test(filepath)) {
|
|
4884
|
+
return SOURCE_TYPE_SCRIPT;
|
|
4885
|
+
}
|
|
4886
|
+
}
|
|
4887
|
+
|
|
4888
|
+
// src/language-js/parse/typescript.js
|
|
4889
|
+
var baseParseOptions = {
|
|
4890
|
+
// `jest@<=26.4.2` rely on `loc`
|
|
4891
|
+
// https://github.com/facebook/jest/issues/10444
|
|
4892
|
+
// Set `loc` and `range` to `true` also prevent AST traverse
|
|
4893
|
+
// https://github.com/typescript-eslint/typescript-eslint/blob/733b3598c17d3a712cf6f043115587f724dbe3ef/packages/typescript-estree/src/ast-converter.ts#L38
|
|
4894
|
+
loc: true,
|
|
4895
|
+
range: true,
|
|
4896
|
+
comment: true,
|
|
4897
|
+
tokens: false,
|
|
4898
|
+
loggerFn: false,
|
|
4899
|
+
project: false,
|
|
4900
|
+
jsDocParsingMode: 'none',
|
|
4901
|
+
// TODO: Use new properties when update printer
|
|
4902
|
+
suppressDeprecatedPropertyWarnings: true,
|
|
4903
|
+
};
|
|
4904
|
+
function createParseError(error) {
|
|
4905
|
+
const { message, location } = error;
|
|
4906
|
+
if (!location) {
|
|
4907
|
+
return error;
|
|
4908
|
+
}
|
|
4909
|
+
const { start, end } = location;
|
|
4910
|
+
return parser_create_error_default(message, {
|
|
4911
|
+
loc: {
|
|
4912
|
+
start: { line: start.line, column: start.column + 1 },
|
|
4913
|
+
end: { line: end.line, column: end.column + 1 },
|
|
4914
|
+
},
|
|
4915
|
+
cause: error,
|
|
4916
|
+
});
|
|
4917
|
+
}
|
|
4918
|
+
var isKnownFileType = (filepath) => filepath && /\.(?:js|mjs|cjs|jsx|ts|mts|cts|tsx)$/iu.test(filepath);
|
|
4919
|
+
function getParseOptionsCombinations(text, filepath) {
|
|
4920
|
+
let combinations = [{ ...baseParseOptions, filePath: filepath }];
|
|
4921
|
+
const sourceType = getSourceType(filepath);
|
|
4922
|
+
if (sourceType) {
|
|
4923
|
+
combinations = combinations.map((parseOptions) => ({
|
|
4924
|
+
...parseOptions,
|
|
4925
|
+
sourceType,
|
|
4926
|
+
}));
|
|
4927
|
+
} else {
|
|
4928
|
+
combinations = SOURCE_TYPE_COMBINATIONS.flatMap((sourceType2) =>
|
|
4929
|
+
combinations.map((parseOptions) => ({
|
|
4930
|
+
...parseOptions,
|
|
4931
|
+
sourceType: sourceType2,
|
|
4932
|
+
})),
|
|
4933
|
+
);
|
|
4934
|
+
}
|
|
4935
|
+
if (isKnownFileType(filepath)) {
|
|
4936
|
+
return combinations;
|
|
4937
|
+
}
|
|
4938
|
+
const shouldEnableJsx = jsx_regexp_evaluate_default.test(text);
|
|
4939
|
+
return [shouldEnableJsx, !shouldEnableJsx].flatMap((jsx) =>
|
|
4940
|
+
combinations.map((parseOptions) => ({ ...parseOptions, jsx })),
|
|
4941
|
+
);
|
|
4942
|
+
}
|
|
4943
|
+
function parse2(text, options) {
|
|
4944
|
+
let filepath = options?.filepath;
|
|
4945
|
+
if (typeof filepath !== 'string') {
|
|
4946
|
+
filepath = void 0;
|
|
4947
|
+
}
|
|
4948
|
+
const textToParse = replace_hashbang_default(text);
|
|
4949
|
+
const parseOptionsCombinations = getParseOptionsCombinations(text, filepath);
|
|
4950
|
+
let ast;
|
|
4951
|
+
try {
|
|
4952
|
+
ast = try_combinations_default(
|
|
4953
|
+
parseOptionsCombinations.map((parseOptions) => () => parse(textToParse, parseOptions)),
|
|
4954
|
+
);
|
|
4955
|
+
} catch ({
|
|
4956
|
+
// @ts-expect-error -- expected
|
|
4957
|
+
errors: [
|
|
4958
|
+
// Suppose our guess is correct, throw the first error
|
|
4959
|
+
error,
|
|
4960
|
+
],
|
|
4961
|
+
}) {
|
|
4962
|
+
throw createParseError(error);
|
|
4963
|
+
}
|
|
4964
|
+
return postprocess_default(ast, { parser: 'typescript', text });
|
|
4965
|
+
}
|
|
4966
|
+
|
|
4967
|
+
var typescript = create_parser_default(parse2);
|
|
4968
|
+
export const parsers = { typescript };
|