@tslite/parser 1.10.0 → 1.13.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/LICENSE +55 -0
- package/NOTICE +14 -0
- package/dist/_namespaces/ts.d.ts +18 -0
- package/dist/_namespaces/ts.js +21 -0
- package/dist/_namespaces/ts.performance.d.ts +1 -0
- package/dist/_namespaces/ts.performance.js +2 -0
- package/dist/core.d.ts +450 -0
- package/dist/core.js +1394 -0
- package/dist/corePublic.d.ts +62 -0
- package/dist/corePublic.js +31 -0
- package/dist/debug.d.ts +74 -0
- package/dist/debug.js +326 -0
- package/dist/diagnosticInformationMap.generated.d.ts +1435 -0
- package/dist/diagnosticInformationMap.generated.js +1441 -0
- package/dist/factory.d.ts +78 -0
- package/dist/factory.js +622 -0
- package/dist/factoryPublic.d.ts +314 -0
- package/dist/factoryPublic.js +1796 -0
- package/dist/index.d.ts +1 -249
- package/dist/index.js +4 -6
- package/dist/parser.d.ts +59 -0
- package/dist/parser.js +5075 -0
- package/dist/path.d.ts +312 -0
- package/dist/path.js +475 -0
- package/dist/perfLogger.d.ts +4 -0
- package/dist/perfLogger.js +38 -0
- package/dist/performance.d.ts +20 -0
- package/dist/performance.js +49 -0
- package/dist/performanceTimestamp.d.ts +2 -0
- package/dist/performanceTimestamp.js +2 -0
- package/dist/scanner.d.ts +80 -0
- package/dist/scanner.js +1984 -0
- package/dist/shims/mapShim.d.ts +23 -0
- package/dist/shims/mapShim.js +156 -0
- package/dist/types.d.ts +2626 -0
- package/dist/types.js +1074 -0
- package/dist/utilities.d.ts +473 -0
- package/dist/utilities.js +2632 -0
- package/dist/utilitiesPublic.d.ts +274 -0
- package/dist/utilitiesPublic.js +1049 -0
- package/dist/visitor.d.ts +15 -0
- package/dist/visitor.js +64 -0
- package/dist/visitorPublic.d.ts +82 -0
- package/dist/visitorPublic.js +352 -0
- package/package.json +14 -42
- package/dist/index.cjs +0 -6
- package/dist/index.d.cts +0 -249
|
@@ -0,0 +1,1049 @@
|
|
|
1
|
+
// Modificado de microsoft/TypeScript v3.9.10, src/compiler/utilitiesPublic.ts: o namespace virou módulo ES, com os imports explícitos.
|
|
2
|
+
import { compareDiagnostics, emptyArray, every, getAssignmentDeclarationKind, getElementOrPropertyAccessArgumentExpressionOrName, getModifierFlags, isBindableStaticElementAccessExpression, isFunctionBlock, isRootedDiskPath, isTypeNodeKind, pathIsRelative, skipOuterExpressions, some, sortAndDeduplicate, } from "./_namespaces/ts.js";
|
|
3
|
+
export function isExternalModuleNameRelative(moduleName) {
|
|
4
|
+
// TypeScript 1.0 spec (April 2014): 11.2.1
|
|
5
|
+
// An external module name is "relative" if the first term is "." or "..".
|
|
6
|
+
// Update: We also consider a path like `C:\foo.ts` "relative" because we do not search for it in `node_modules` or treat it as an ambient module.
|
|
7
|
+
return pathIsRelative(moduleName) || isRootedDiskPath(moduleName);
|
|
8
|
+
}
|
|
9
|
+
export function sortAndDeduplicateDiagnostics(diagnostics) {
|
|
10
|
+
return sortAndDeduplicate(diagnostics, compareDiagnostics);
|
|
11
|
+
}
|
|
12
|
+
export function getDefaultLibFileName(options) {
|
|
13
|
+
switch (options.target) {
|
|
14
|
+
case 99 /* ScriptTarget.ESNext */:
|
|
15
|
+
return "lib.esnext.full.d.ts";
|
|
16
|
+
case 7 /* ScriptTarget.ES2020 */:
|
|
17
|
+
return "lib.es2020.full.d.ts";
|
|
18
|
+
case 6 /* ScriptTarget.ES2019 */:
|
|
19
|
+
return "lib.es2019.full.d.ts";
|
|
20
|
+
case 5 /* ScriptTarget.ES2018 */:
|
|
21
|
+
return "lib.es2018.full.d.ts";
|
|
22
|
+
case 4 /* ScriptTarget.ES2017 */:
|
|
23
|
+
return "lib.es2017.full.d.ts";
|
|
24
|
+
case 3 /* ScriptTarget.ES2016 */:
|
|
25
|
+
return "lib.es2016.full.d.ts";
|
|
26
|
+
case 2 /* ScriptTarget.ES2015 */:
|
|
27
|
+
return "lib.es6.d.ts"; // We don't use lib.es2015.full.d.ts due to breaking change.
|
|
28
|
+
default:
|
|
29
|
+
return "lib.d.ts";
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
export function textSpanEnd(span) {
|
|
33
|
+
return span.start + span.length;
|
|
34
|
+
}
|
|
35
|
+
export function textSpanIsEmpty(span) {
|
|
36
|
+
return span.length === 0;
|
|
37
|
+
}
|
|
38
|
+
export function textSpanContainsPosition(span, position) {
|
|
39
|
+
return position >= span.start && position < textSpanEnd(span);
|
|
40
|
+
}
|
|
41
|
+
export function textSpanIntersectsWith(span, start, length) {
|
|
42
|
+
return decodedTextSpanIntersectsWith(span.start, span.length, start, length);
|
|
43
|
+
}
|
|
44
|
+
export function decodedTextSpanIntersectsWith(start1, length1, start2, length2) {
|
|
45
|
+
const end1 = start1 + length1;
|
|
46
|
+
const end2 = start2 + length2;
|
|
47
|
+
return start2 <= end1 && end2 >= start1;
|
|
48
|
+
}
|
|
49
|
+
export function textSpanIntersectsWithPosition(span, position) {
|
|
50
|
+
return position <= textSpanEnd(span) && position >= span.start;
|
|
51
|
+
}
|
|
52
|
+
export function createTextSpan(start, length) {
|
|
53
|
+
if (start < 0) {
|
|
54
|
+
throw new Error("start < 0");
|
|
55
|
+
}
|
|
56
|
+
if (length < 0) {
|
|
57
|
+
throw new Error("length < 0");
|
|
58
|
+
}
|
|
59
|
+
return { start, length };
|
|
60
|
+
}
|
|
61
|
+
export function createTextSpanFromBounds(start, end) {
|
|
62
|
+
return createTextSpan(start, end - start);
|
|
63
|
+
}
|
|
64
|
+
export function textChangeRangeNewSpan(range) {
|
|
65
|
+
return createTextSpan(range.span.start, range.newLength);
|
|
66
|
+
}
|
|
67
|
+
export function textChangeRangeIsUnchanged(range) {
|
|
68
|
+
return textSpanIsEmpty(range.span) && range.newLength === 0;
|
|
69
|
+
}
|
|
70
|
+
export function createTextChangeRange(span, newLength) {
|
|
71
|
+
if (newLength < 0) {
|
|
72
|
+
throw new Error("newLength < 0");
|
|
73
|
+
}
|
|
74
|
+
return { span, newLength };
|
|
75
|
+
}
|
|
76
|
+
export function isEmptyBindingPattern(node) {
|
|
77
|
+
if (isBindingPattern(node)) {
|
|
78
|
+
return every(node.elements, isEmptyBindingElement);
|
|
79
|
+
}
|
|
80
|
+
return false;
|
|
81
|
+
}
|
|
82
|
+
export function isEmptyBindingElement(node) {
|
|
83
|
+
if (isOmittedExpression(node)) {
|
|
84
|
+
return true;
|
|
85
|
+
}
|
|
86
|
+
return isEmptyBindingPattern(node.name);
|
|
87
|
+
}
|
|
88
|
+
export function walkUpBindingElementsAndPatterns(binding) {
|
|
89
|
+
let node = binding.parent;
|
|
90
|
+
while (isBindingElement(node.parent)) {
|
|
91
|
+
node = node.parent.parent;
|
|
92
|
+
}
|
|
93
|
+
return node.parent;
|
|
94
|
+
}
|
|
95
|
+
function getCombinedFlags(node, getFlags) {
|
|
96
|
+
if (isBindingElement(node)) {
|
|
97
|
+
node = walkUpBindingElementsAndPatterns(node);
|
|
98
|
+
}
|
|
99
|
+
let flags = getFlags(node);
|
|
100
|
+
if (node.kind === 242 /* SyntaxKind.VariableDeclaration */) {
|
|
101
|
+
node = node.parent;
|
|
102
|
+
}
|
|
103
|
+
if (node && node.kind === 243 /* SyntaxKind.VariableDeclarationList */) {
|
|
104
|
+
flags |= getFlags(node);
|
|
105
|
+
node = node.parent;
|
|
106
|
+
}
|
|
107
|
+
if (node && node.kind === 225 /* SyntaxKind.VariableStatement */) {
|
|
108
|
+
flags |= getFlags(node);
|
|
109
|
+
}
|
|
110
|
+
return flags;
|
|
111
|
+
}
|
|
112
|
+
export function getCombinedModifierFlags(node) {
|
|
113
|
+
return getCombinedFlags(node, getModifierFlags);
|
|
114
|
+
}
|
|
115
|
+
// Returns the node flags for this node and all relevant parent nodes. This is done so that
|
|
116
|
+
// nodes like variable declarations and binding elements can returned a view of their flags
|
|
117
|
+
// that includes the modifiers from their container. i.e. flags like export/declare aren't
|
|
118
|
+
// stored on the variable declaration directly, but on the containing variable statement
|
|
119
|
+
// (if it has one). Similarly, flags for let/const are store on the variable declaration
|
|
120
|
+
// list. By calling this function, all those flags are combined so that the client can treat
|
|
121
|
+
// the node as if it actually had those flags.
|
|
122
|
+
export function getCombinedNodeFlags(node) {
|
|
123
|
+
return getCombinedFlags(node, n => n.flags);
|
|
124
|
+
}
|
|
125
|
+
export function getOriginalNode(node, nodeTest) {
|
|
126
|
+
if (node) {
|
|
127
|
+
while (node.original !== undefined) {
|
|
128
|
+
node = node.original;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
// O teste recebe o nó como a tag o passa, mesmo `undefined`; o tipo é o do TypeScript 5.
|
|
132
|
+
return !nodeTest || nodeTest(node) ? node : undefined;
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Gets a value indicating whether a node originated in the parse tree.
|
|
136
|
+
*
|
|
137
|
+
* @param node The node to test.
|
|
138
|
+
*/
|
|
139
|
+
export function isParseTreeNode(node) {
|
|
140
|
+
return (node.flags & 8 /* NodeFlags.Synthesized */) === 0;
|
|
141
|
+
}
|
|
142
|
+
export function getParseTreeNode(node, nodeTest) {
|
|
143
|
+
if (node === undefined || isParseTreeNode(node)) {
|
|
144
|
+
return node;
|
|
145
|
+
}
|
|
146
|
+
node = getOriginalNode(node);
|
|
147
|
+
if (isParseTreeNode(node) && (!nodeTest || nodeTest(node))) {
|
|
148
|
+
return node;
|
|
149
|
+
}
|
|
150
|
+
return undefined;
|
|
151
|
+
}
|
|
152
|
+
/** Add an extra underscore to identifiers that start with two underscores to avoid issues with magic names like '__proto__' */
|
|
153
|
+
export function escapeLeadingUnderscores(identifier) {
|
|
154
|
+
return (identifier.length >= 2 && identifier.charCodeAt(0) === 95 /* CharacterCodes._ */ && identifier.charCodeAt(1) === 95 /* CharacterCodes._ */ ? "_" + identifier : identifier);
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Remove extra underscore from escaped identifier text content.
|
|
158
|
+
*
|
|
159
|
+
* @param identifier The escaped identifier text.
|
|
160
|
+
* @returns The unescaped identifier text.
|
|
161
|
+
*/
|
|
162
|
+
export function unescapeLeadingUnderscores(identifier) {
|
|
163
|
+
const id = identifier;
|
|
164
|
+
return id.length >= 3 && id.charCodeAt(0) === 95 /* CharacterCodes._ */ && id.charCodeAt(1) === 95 /* CharacterCodes._ */ && id.charCodeAt(2) === 95 /* CharacterCodes._ */ ? id.substr(1) : id;
|
|
165
|
+
}
|
|
166
|
+
export function idText(identifierOrPrivateName) {
|
|
167
|
+
return unescapeLeadingUnderscores(identifierOrPrivateName.escapedText);
|
|
168
|
+
}
|
|
169
|
+
export function symbolName(symbol) {
|
|
170
|
+
return unescapeLeadingUnderscores(symbol.escapedName);
|
|
171
|
+
}
|
|
172
|
+
export function nodeHasName(statement, name) {
|
|
173
|
+
if (isNamedDeclaration(statement) && isIdentifier(statement.name) && idText(statement.name) === idText(name)) {
|
|
174
|
+
return true;
|
|
175
|
+
}
|
|
176
|
+
if (isVariableStatement(statement) && some(statement.declarationList.declarations, d => nodeHasName(d, name))) {
|
|
177
|
+
return true;
|
|
178
|
+
}
|
|
179
|
+
return false;
|
|
180
|
+
}
|
|
181
|
+
export function isNamedDeclaration(node) {
|
|
182
|
+
return !!node.name; // A 'name' property should always be a DeclarationName.
|
|
183
|
+
}
|
|
184
|
+
export function getNonAssignedNameOfDeclaration(declaration) {
|
|
185
|
+
switch (declaration.kind) {
|
|
186
|
+
case 75 /* SyntaxKind.Identifier */:
|
|
187
|
+
return declaration;
|
|
188
|
+
case 196 /* SyntaxKind.CallExpression */:
|
|
189
|
+
case 209 /* SyntaxKind.BinaryExpression */: {
|
|
190
|
+
const expr = declaration;
|
|
191
|
+
switch (getAssignmentDeclarationKind(expr)) {
|
|
192
|
+
case 1 /* AssignmentDeclarationKind.ExportsProperty */:
|
|
193
|
+
case 4 /* AssignmentDeclarationKind.Property */:
|
|
194
|
+
case 3 /* AssignmentDeclarationKind.PrototypeProperty */:
|
|
195
|
+
return getElementOrPropertyAccessArgumentExpressionOrName(expr.left);
|
|
196
|
+
case 6 /* AssignmentDeclarationKind.ObjectDefinePropertyValue */:
|
|
197
|
+
case 7 /* AssignmentDeclarationKind.ObjectDefinePropertyExports */:
|
|
198
|
+
case 8 /* AssignmentDeclarationKind.ObjectDefinePrototypeProperty */:
|
|
199
|
+
return expr.arguments[1];
|
|
200
|
+
default:
|
|
201
|
+
return undefined;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
case 259 /* SyntaxKind.ExportAssignment */: {
|
|
205
|
+
const { expression } = declaration;
|
|
206
|
+
return isIdentifier(expression) ? expression : undefined;
|
|
207
|
+
}
|
|
208
|
+
case 195 /* SyntaxKind.ElementAccessExpression */:
|
|
209
|
+
const expr = declaration;
|
|
210
|
+
if (isBindableStaticElementAccessExpression(expr)) {
|
|
211
|
+
return expr.argumentExpression;
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
return declaration.name;
|
|
215
|
+
}
|
|
216
|
+
export function getNameOfDeclaration(declaration) {
|
|
217
|
+
if (declaration === undefined)
|
|
218
|
+
return undefined;
|
|
219
|
+
return getNonAssignedNameOfDeclaration(declaration);
|
|
220
|
+
}
|
|
221
|
+
/** Os parâmetros de tipo que a declaração escreve. */
|
|
222
|
+
export function getEffectiveTypeParameterDeclarations(node) {
|
|
223
|
+
return node.typeParameters || emptyArray;
|
|
224
|
+
}
|
|
225
|
+
/** A constraint que o parâmetro de tipo escreve. */
|
|
226
|
+
export function getEffectiveConstraintOfTypeParameter(node) {
|
|
227
|
+
return node.constraint;
|
|
228
|
+
}
|
|
229
|
+
// #region
|
|
230
|
+
// Simple node tests of the form `node.kind === SyntaxKind.Foo`.
|
|
231
|
+
// Literals
|
|
232
|
+
export function isNumericLiteral(node) {
|
|
233
|
+
return node.kind === 8 /* SyntaxKind.NumericLiteral */;
|
|
234
|
+
}
|
|
235
|
+
export function isBigIntLiteral(node) {
|
|
236
|
+
return node.kind === 9 /* SyntaxKind.BigIntLiteral */;
|
|
237
|
+
}
|
|
238
|
+
export function isStringLiteral(node) {
|
|
239
|
+
return node.kind === 10 /* SyntaxKind.StringLiteral */;
|
|
240
|
+
}
|
|
241
|
+
export function isJsxText(node) {
|
|
242
|
+
return node.kind === 11 /* SyntaxKind.JsxText */;
|
|
243
|
+
}
|
|
244
|
+
// Pseudo-literals
|
|
245
|
+
export function isTemplateHead(node) {
|
|
246
|
+
return node.kind === 15 /* SyntaxKind.TemplateHead */;
|
|
247
|
+
}
|
|
248
|
+
export function isTemplateTail(node) {
|
|
249
|
+
return node.kind === 17 /* SyntaxKind.TemplateTail */;
|
|
250
|
+
}
|
|
251
|
+
export function isIdentifier(node) {
|
|
252
|
+
return node.kind === 75 /* SyntaxKind.Identifier */;
|
|
253
|
+
}
|
|
254
|
+
// Names
|
|
255
|
+
export function isQualifiedName(node) {
|
|
256
|
+
return node.kind === 153 /* SyntaxKind.QualifiedName */;
|
|
257
|
+
}
|
|
258
|
+
export function isComputedPropertyName(node) {
|
|
259
|
+
return node.kind === 154 /* SyntaxKind.ComputedPropertyName */;
|
|
260
|
+
}
|
|
261
|
+
// Signature elements
|
|
262
|
+
export function isTypeParameterDeclaration(node) {
|
|
263
|
+
return node.kind === 155 /* SyntaxKind.TypeParameter */;
|
|
264
|
+
}
|
|
265
|
+
export function isParameter(node) {
|
|
266
|
+
return node.kind === 156 /* SyntaxKind.Parameter */;
|
|
267
|
+
}
|
|
268
|
+
// TypeMember
|
|
269
|
+
export function isPropertySignature(node) {
|
|
270
|
+
return node.kind === 158 /* SyntaxKind.PropertySignature */;
|
|
271
|
+
}
|
|
272
|
+
export function isMethodSignature(node) {
|
|
273
|
+
return node.kind === 160 /* SyntaxKind.MethodSignature */;
|
|
274
|
+
}
|
|
275
|
+
export function isCallSignatureDeclaration(node) {
|
|
276
|
+
return node.kind === 165 /* SyntaxKind.CallSignature */;
|
|
277
|
+
}
|
|
278
|
+
export function isIndexSignatureDeclaration(node) {
|
|
279
|
+
return node.kind === 167 /* SyntaxKind.IndexSignature */;
|
|
280
|
+
}
|
|
281
|
+
// Type
|
|
282
|
+
export function isTypePredicateNode(node) {
|
|
283
|
+
return node.kind === 168 /* SyntaxKind.TypePredicate */;
|
|
284
|
+
}
|
|
285
|
+
export function isTypeReferenceNode(node) {
|
|
286
|
+
return node.kind === 169 /* SyntaxKind.TypeReference */;
|
|
287
|
+
}
|
|
288
|
+
export function isFunctionTypeNode(node) {
|
|
289
|
+
return node.kind === 170 /* SyntaxKind.FunctionType */;
|
|
290
|
+
}
|
|
291
|
+
export function isTypeQueryNode(node) {
|
|
292
|
+
return node.kind === 172 /* SyntaxKind.TypeQuery */;
|
|
293
|
+
}
|
|
294
|
+
export function isTypeLiteralNode(node) {
|
|
295
|
+
return node.kind === 173 /* SyntaxKind.TypeLiteral */;
|
|
296
|
+
}
|
|
297
|
+
export function isArrayTypeNode(node) {
|
|
298
|
+
return node.kind === 174 /* SyntaxKind.ArrayType */;
|
|
299
|
+
}
|
|
300
|
+
export function isUnionTypeNode(node) {
|
|
301
|
+
return node.kind === 178 /* SyntaxKind.UnionType */;
|
|
302
|
+
}
|
|
303
|
+
export function isConditionalTypeNode(node) {
|
|
304
|
+
return node.kind === 180 /* SyntaxKind.ConditionalType */;
|
|
305
|
+
}
|
|
306
|
+
export function isInferTypeNode(node) {
|
|
307
|
+
return node.kind === 181 /* SyntaxKind.InferType */;
|
|
308
|
+
}
|
|
309
|
+
export function isParenthesizedTypeNode(node) {
|
|
310
|
+
return node.kind === 182 /* SyntaxKind.ParenthesizedType */;
|
|
311
|
+
}
|
|
312
|
+
export function isTypeOperatorNode(node) {
|
|
313
|
+
return node.kind === 184 /* SyntaxKind.TypeOperator */;
|
|
314
|
+
}
|
|
315
|
+
export function isIndexedAccessTypeNode(node) {
|
|
316
|
+
return node.kind === 185 /* SyntaxKind.IndexedAccessType */;
|
|
317
|
+
}
|
|
318
|
+
export function isMappedTypeNode(node) {
|
|
319
|
+
return node.kind === 186 /* SyntaxKind.MappedType */;
|
|
320
|
+
}
|
|
321
|
+
export function isLiteralTypeNode(node) {
|
|
322
|
+
return node.kind === 187 /* SyntaxKind.LiteralType */;
|
|
323
|
+
}
|
|
324
|
+
export function isImportTypeNode(node) {
|
|
325
|
+
return node.kind === 188 /* SyntaxKind.ImportType */;
|
|
326
|
+
}
|
|
327
|
+
// Binding patterns
|
|
328
|
+
export function isObjectBindingPattern(node) {
|
|
329
|
+
return node.kind === 189 /* SyntaxKind.ObjectBindingPattern */;
|
|
330
|
+
}
|
|
331
|
+
export function isArrayBindingPattern(node) {
|
|
332
|
+
return node.kind === 190 /* SyntaxKind.ArrayBindingPattern */;
|
|
333
|
+
}
|
|
334
|
+
export function isBindingElement(node) {
|
|
335
|
+
return node.kind === 191 /* SyntaxKind.BindingElement */;
|
|
336
|
+
}
|
|
337
|
+
// Expression
|
|
338
|
+
export function isArrayLiteralExpression(node) {
|
|
339
|
+
return node.kind === 192 /* SyntaxKind.ArrayLiteralExpression */;
|
|
340
|
+
}
|
|
341
|
+
export function isObjectLiteralExpression(node) {
|
|
342
|
+
return node.kind === 193 /* SyntaxKind.ObjectLiteralExpression */;
|
|
343
|
+
}
|
|
344
|
+
export function isPropertyAccessExpression(node) {
|
|
345
|
+
return node.kind === 194 /* SyntaxKind.PropertyAccessExpression */;
|
|
346
|
+
}
|
|
347
|
+
export function isPropertyAccessChain(node) {
|
|
348
|
+
return isPropertyAccessExpression(node) && !!(node.flags & 32 /* NodeFlags.OptionalChain */);
|
|
349
|
+
}
|
|
350
|
+
export function isElementAccessExpression(node) {
|
|
351
|
+
return node.kind === 195 /* SyntaxKind.ElementAccessExpression */;
|
|
352
|
+
}
|
|
353
|
+
export function isCallExpression(node) {
|
|
354
|
+
return node.kind === 196 /* SyntaxKind.CallExpression */;
|
|
355
|
+
}
|
|
356
|
+
export function isCallChain(node) {
|
|
357
|
+
return isCallExpression(node) && !!(node.flags & 32 /* NodeFlags.OptionalChain */);
|
|
358
|
+
}
|
|
359
|
+
export function isOptionalChain(node) {
|
|
360
|
+
const kind = node.kind;
|
|
361
|
+
return !!(node.flags & 32 /* NodeFlags.OptionalChain */) &&
|
|
362
|
+
(kind === 194 /* SyntaxKind.PropertyAccessExpression */
|
|
363
|
+
|| kind === 195 /* SyntaxKind.ElementAccessExpression */
|
|
364
|
+
|| kind === 196 /* SyntaxKind.CallExpression */);
|
|
365
|
+
}
|
|
366
|
+
export function isOptionalChainRoot(node) {
|
|
367
|
+
return isOptionalChain(node) && !!node.questionDotToken;
|
|
368
|
+
}
|
|
369
|
+
/**
|
|
370
|
+
* Determines whether a node is the expression preceding an optional chain (i.e. `a` in `a?.b`).
|
|
371
|
+
*/
|
|
372
|
+
export function isExpressionOfOptionalChainRoot(node) {
|
|
373
|
+
return isOptionalChainRoot(node.parent) && node.parent.expression === node;
|
|
374
|
+
}
|
|
375
|
+
/**
|
|
376
|
+
* Determines whether a node is the outermost `OptionalChain` in an ECMAScript `OptionalExpression`:
|
|
377
|
+
*
|
|
378
|
+
* 1. For `a?.b.c`, the outermost chain is `a?.b.c` (`c` is the end of the chain starting at `a?.`)
|
|
379
|
+
* 2. For `a?.b!`, the outermost chain is `a?.b` (`b` is the end of the chain starting at `a?.`)
|
|
380
|
+
* 3. For `(a?.b.c).d`, the outermost chain is `a?.b.c` (`c` is the end of the chain starting at `a?.` since parens end the chain)
|
|
381
|
+
* 4. For `a?.b.c?.d`, both `a?.b.c` and `a?.b.c?.d` are outermost (`c` is the end of the chain starting at `a?.`, and `d` is
|
|
382
|
+
* the end of the chain starting at `c?.`)
|
|
383
|
+
* 5. For `a?.(b?.c).d`, both `b?.c` and `a?.(b?.c)d` are outermost (`c` is the end of the chain starting at `b`, and `d` is
|
|
384
|
+
* the end of the chain starting at `a?.`)
|
|
385
|
+
*/
|
|
386
|
+
export function isOutermostOptionalChain(node) {
|
|
387
|
+
return !isOptionalChain(node.parent) // cases 1, 2, and 3
|
|
388
|
+
|| isOptionalChainRoot(node.parent) // case 4
|
|
389
|
+
|| node !== node.parent.expression; // case 5
|
|
390
|
+
}
|
|
391
|
+
export function isNullishCoalesce(node) {
|
|
392
|
+
return node.kind === 209 /* SyntaxKind.BinaryExpression */ && node.operatorToken.kind === 60 /* SyntaxKind.QuestionQuestionToken */;
|
|
393
|
+
}
|
|
394
|
+
export function isParenthesizedExpression(node) {
|
|
395
|
+
return node.kind === 200 /* SyntaxKind.ParenthesizedExpression */;
|
|
396
|
+
}
|
|
397
|
+
export function skipPartiallyEmittedExpressions(node) {
|
|
398
|
+
return skipOuterExpressions(node, 8 /* OuterExpressionKinds.PartiallyEmittedExpressions */);
|
|
399
|
+
}
|
|
400
|
+
export function isArrowFunction(node) {
|
|
401
|
+
return node.kind === 202 /* SyntaxKind.ArrowFunction */;
|
|
402
|
+
}
|
|
403
|
+
export function isDeleteExpression(node) {
|
|
404
|
+
return node.kind === 203 /* SyntaxKind.DeleteExpression */;
|
|
405
|
+
}
|
|
406
|
+
export function isTypeOfExpression(node) {
|
|
407
|
+
return node.kind === 204 /* SyntaxKind.TypeOfExpression */;
|
|
408
|
+
}
|
|
409
|
+
export function isAwaitExpression(node) {
|
|
410
|
+
return node.kind === 206 /* SyntaxKind.AwaitExpression */;
|
|
411
|
+
}
|
|
412
|
+
export function isPrefixUnaryExpression(node) {
|
|
413
|
+
return node.kind === 207 /* SyntaxKind.PrefixUnaryExpression */;
|
|
414
|
+
}
|
|
415
|
+
export function isBinaryExpression(node) {
|
|
416
|
+
return node.kind === 209 /* SyntaxKind.BinaryExpression */;
|
|
417
|
+
}
|
|
418
|
+
export function isSpreadElement(node) {
|
|
419
|
+
return node.kind === 213 /* SyntaxKind.SpreadElement */;
|
|
420
|
+
}
|
|
421
|
+
export function isOmittedExpression(node) {
|
|
422
|
+
return node.kind === 215 /* SyntaxKind.OmittedExpression */;
|
|
423
|
+
}
|
|
424
|
+
export function isAsExpression(node) {
|
|
425
|
+
return node.kind === 217 /* SyntaxKind.AsExpression */;
|
|
426
|
+
}
|
|
427
|
+
export function isMetaProperty(node) {
|
|
428
|
+
return node.kind === 219 /* SyntaxKind.MetaProperty */;
|
|
429
|
+
}
|
|
430
|
+
// Misc
|
|
431
|
+
export function isTemplateSpan(node) {
|
|
432
|
+
return node.kind === 221 /* SyntaxKind.TemplateSpan */;
|
|
433
|
+
}
|
|
434
|
+
// Block
|
|
435
|
+
export function isBlock(node) {
|
|
436
|
+
return node.kind === 223 /* SyntaxKind.Block */;
|
|
437
|
+
}
|
|
438
|
+
export function isVariableStatement(node) {
|
|
439
|
+
return node.kind === 225 /* SyntaxKind.VariableStatement */;
|
|
440
|
+
}
|
|
441
|
+
export function isEmptyStatement(node) {
|
|
442
|
+
return node.kind === 224 /* SyntaxKind.EmptyStatement */;
|
|
443
|
+
}
|
|
444
|
+
export function isExpressionStatement(node) {
|
|
445
|
+
return node.kind === 226 /* SyntaxKind.ExpressionStatement */;
|
|
446
|
+
}
|
|
447
|
+
export function isIfStatement(node) {
|
|
448
|
+
return node.kind === 227 /* SyntaxKind.IfStatement */;
|
|
449
|
+
}
|
|
450
|
+
export function isForInStatement(node) {
|
|
451
|
+
return node.kind === 231 /* SyntaxKind.ForInStatement */;
|
|
452
|
+
}
|
|
453
|
+
export function isForOfStatement(node) {
|
|
454
|
+
return node.kind === 232 /* SyntaxKind.ForOfStatement */;
|
|
455
|
+
}
|
|
456
|
+
export function isBreakOrContinueStatement(node) {
|
|
457
|
+
return node.kind === 234 /* SyntaxKind.BreakStatement */ || node.kind === 233 /* SyntaxKind.ContinueStatement */;
|
|
458
|
+
}
|
|
459
|
+
export function isReturnStatement(node) {
|
|
460
|
+
return node.kind === 235 /* SyntaxKind.ReturnStatement */;
|
|
461
|
+
}
|
|
462
|
+
export function isSwitchStatement(node) {
|
|
463
|
+
return node.kind === 237 /* SyntaxKind.SwitchStatement */;
|
|
464
|
+
}
|
|
465
|
+
export function isThrowStatement(node) {
|
|
466
|
+
return node.kind === 239 /* SyntaxKind.ThrowStatement */;
|
|
467
|
+
}
|
|
468
|
+
export function isTryStatement(node) {
|
|
469
|
+
return node.kind === 240 /* SyntaxKind.TryStatement */;
|
|
470
|
+
}
|
|
471
|
+
export function isVariableDeclaration(node) {
|
|
472
|
+
return node.kind === 242 /* SyntaxKind.VariableDeclaration */;
|
|
473
|
+
}
|
|
474
|
+
export function isVariableDeclarationList(node) {
|
|
475
|
+
return node.kind === 243 /* SyntaxKind.VariableDeclarationList */;
|
|
476
|
+
}
|
|
477
|
+
export function isTypeAliasDeclaration(node) {
|
|
478
|
+
return node.kind === 247 /* SyntaxKind.TypeAliasDeclaration */;
|
|
479
|
+
}
|
|
480
|
+
export function isModuleDeclaration(node) {
|
|
481
|
+
return node.kind === 249 /* SyntaxKind.ModuleDeclaration */;
|
|
482
|
+
}
|
|
483
|
+
export function isModuleBlock(node) {
|
|
484
|
+
return node.kind === 250 /* SyntaxKind.ModuleBlock */;
|
|
485
|
+
}
|
|
486
|
+
export function isCaseBlock(node) {
|
|
487
|
+
return node.kind === 251 /* SyntaxKind.CaseBlock */;
|
|
488
|
+
}
|
|
489
|
+
export function isImportDeclaration(node) {
|
|
490
|
+
return node.kind === 254 /* SyntaxKind.ImportDeclaration */;
|
|
491
|
+
}
|
|
492
|
+
export function isImportClause(node) {
|
|
493
|
+
return node.kind === 255 /* SyntaxKind.ImportClause */;
|
|
494
|
+
}
|
|
495
|
+
export function isNamespaceImport(node) {
|
|
496
|
+
return node.kind === 256 /* SyntaxKind.NamespaceImport */;
|
|
497
|
+
}
|
|
498
|
+
export function isNamespaceExport(node) {
|
|
499
|
+
return node.kind === 262 /* SyntaxKind.NamespaceExport */;
|
|
500
|
+
}
|
|
501
|
+
export function isNamedExportBindings(node) {
|
|
502
|
+
return node.kind === 262 /* SyntaxKind.NamespaceExport */ || node.kind === 261 /* SyntaxKind.NamedExports */;
|
|
503
|
+
}
|
|
504
|
+
export function isNamedImports(node) {
|
|
505
|
+
return node.kind === 257 /* SyntaxKind.NamedImports */;
|
|
506
|
+
}
|
|
507
|
+
export function isImportSpecifier(node) {
|
|
508
|
+
return node.kind === 258 /* SyntaxKind.ImportSpecifier */;
|
|
509
|
+
}
|
|
510
|
+
export function isExportAssignment(node) {
|
|
511
|
+
return node.kind === 259 /* SyntaxKind.ExportAssignment */;
|
|
512
|
+
}
|
|
513
|
+
export function isExportDeclaration(node) {
|
|
514
|
+
return node.kind === 260 /* SyntaxKind.ExportDeclaration */;
|
|
515
|
+
}
|
|
516
|
+
export function isNamedExports(node) {
|
|
517
|
+
return node.kind === 261 /* SyntaxKind.NamedExports */;
|
|
518
|
+
}
|
|
519
|
+
export function isExportSpecifier(node) {
|
|
520
|
+
return node.kind === 263 /* SyntaxKind.ExportSpecifier */;
|
|
521
|
+
}
|
|
522
|
+
// JSX
|
|
523
|
+
export function isJsxElement(node) {
|
|
524
|
+
return node.kind === 266 /* SyntaxKind.JsxElement */;
|
|
525
|
+
}
|
|
526
|
+
export function isJsxSelfClosingElement(node) {
|
|
527
|
+
return node.kind === 267 /* SyntaxKind.JsxSelfClosingElement */;
|
|
528
|
+
}
|
|
529
|
+
export function isJsxOpeningElement(node) {
|
|
530
|
+
return node.kind === 268 /* SyntaxKind.JsxOpeningElement */;
|
|
531
|
+
}
|
|
532
|
+
export function isJsxClosingElement(node) {
|
|
533
|
+
return node.kind === 269 /* SyntaxKind.JsxClosingElement */;
|
|
534
|
+
}
|
|
535
|
+
export function isJsxOpeningFragment(node) {
|
|
536
|
+
return node.kind === 271 /* SyntaxKind.JsxOpeningFragment */;
|
|
537
|
+
}
|
|
538
|
+
export function isJsxClosingFragment(node) {
|
|
539
|
+
return node.kind === 272 /* SyntaxKind.JsxClosingFragment */;
|
|
540
|
+
}
|
|
541
|
+
export function isJsxAttribute(node) {
|
|
542
|
+
return node.kind === 273 /* SyntaxKind.JsxAttribute */;
|
|
543
|
+
}
|
|
544
|
+
export function isJsxAttributes(node) {
|
|
545
|
+
return node.kind === 274 /* SyntaxKind.JsxAttributes */;
|
|
546
|
+
}
|
|
547
|
+
export function isJsxSpreadAttribute(node) {
|
|
548
|
+
return node.kind === 275 /* SyntaxKind.JsxSpreadAttribute */;
|
|
549
|
+
}
|
|
550
|
+
export function isJsxExpression(node) {
|
|
551
|
+
return node.kind === 276 /* SyntaxKind.JsxExpression */;
|
|
552
|
+
}
|
|
553
|
+
// Clauses
|
|
554
|
+
export function isCaseClause(node) {
|
|
555
|
+
return node.kind === 277 /* SyntaxKind.CaseClause */;
|
|
556
|
+
}
|
|
557
|
+
export function isDefaultClause(node) {
|
|
558
|
+
return node.kind === 278 /* SyntaxKind.DefaultClause */;
|
|
559
|
+
}
|
|
560
|
+
export function isCatchClause(node) {
|
|
561
|
+
return node.kind === 280 /* SyntaxKind.CatchClause */;
|
|
562
|
+
}
|
|
563
|
+
// Property assignments
|
|
564
|
+
export function isPropertyAssignment(node) {
|
|
565
|
+
return node.kind === 281 /* SyntaxKind.PropertyAssignment */;
|
|
566
|
+
}
|
|
567
|
+
export function isShorthandPropertyAssignment(node) {
|
|
568
|
+
return node.kind === 282 /* SyntaxKind.ShorthandPropertyAssignment */;
|
|
569
|
+
}
|
|
570
|
+
export function isSpreadAssignment(node) {
|
|
571
|
+
return node.kind === 283 /* SyntaxKind.SpreadAssignment */;
|
|
572
|
+
}
|
|
573
|
+
// Top-level nodes
|
|
574
|
+
export function isSourceFile(node) {
|
|
575
|
+
return node.kind === 290 /* SyntaxKind.SourceFile */;
|
|
576
|
+
}
|
|
577
|
+
export function isUnparsedSource(node) {
|
|
578
|
+
return node.kind === 292 /* SyntaxKind.UnparsedSource */;
|
|
579
|
+
}
|
|
580
|
+
export function isUnparsedPrepend(node) {
|
|
581
|
+
return node.kind === 286 /* SyntaxKind.UnparsedPrepend */;
|
|
582
|
+
}
|
|
583
|
+
export function isUnparsedTextLike(node) {
|
|
584
|
+
switch (node.kind) {
|
|
585
|
+
case 287 /* SyntaxKind.UnparsedText */:
|
|
586
|
+
case 288 /* SyntaxKind.UnparsedInternalText */:
|
|
587
|
+
return true;
|
|
588
|
+
default:
|
|
589
|
+
return false;
|
|
590
|
+
}
|
|
591
|
+
}
|
|
592
|
+
export function isUnparsedNode(node) {
|
|
593
|
+
return isUnparsedTextLike(node) ||
|
|
594
|
+
node.kind === 285 /* SyntaxKind.UnparsedPrologue */ ||
|
|
595
|
+
node.kind === 289 /* SyntaxKind.UnparsedSyntheticReference */;
|
|
596
|
+
}
|
|
597
|
+
// #endregion
|
|
598
|
+
// #region
|
|
599
|
+
// Node tests
|
|
600
|
+
//
|
|
601
|
+
// All node tests in the following list should *not* reference parent pointers so that
|
|
602
|
+
// they may be used with transformations.
|
|
603
|
+
export function isSyntaxList(n) {
|
|
604
|
+
return n.kind === 324 /* SyntaxKind.SyntaxList */;
|
|
605
|
+
}
|
|
606
|
+
export function isNodeKind(kind) {
|
|
607
|
+
return kind >= 153 /* SyntaxKind.FirstNode */;
|
|
608
|
+
}
|
|
609
|
+
/**
|
|
610
|
+
* True if node is of some token syntax kind.
|
|
611
|
+
* For example, this is true for an IfKeyword but not for an IfStatement.
|
|
612
|
+
* Literals are considered tokens, except TemplateLiteral, but does include TemplateHead/Middle/Tail.
|
|
613
|
+
*/
|
|
614
|
+
export function isToken(n) {
|
|
615
|
+
return n.kind >= 0 /* SyntaxKind.FirstToken */ && n.kind <= 152 /* SyntaxKind.LastToken */;
|
|
616
|
+
}
|
|
617
|
+
// Node Arrays
|
|
618
|
+
export function isNodeArray(array) {
|
|
619
|
+
return array.hasOwnProperty("pos") && array.hasOwnProperty("end");
|
|
620
|
+
}
|
|
621
|
+
// Literals
|
|
622
|
+
export function isLiteralKind(kind) {
|
|
623
|
+
return 8 /* SyntaxKind.FirstLiteralToken */ <= kind && kind <= 14 /* SyntaxKind.LastLiteralToken */;
|
|
624
|
+
}
|
|
625
|
+
export function isLiteralExpression(node) {
|
|
626
|
+
return isLiteralKind(node.kind);
|
|
627
|
+
}
|
|
628
|
+
// Pseudo-literals
|
|
629
|
+
export function isTemplateLiteralKind(kind) {
|
|
630
|
+
return 14 /* SyntaxKind.FirstTemplateToken */ <= kind && kind <= 17 /* SyntaxKind.LastTemplateToken */;
|
|
631
|
+
}
|
|
632
|
+
export function isTemplateMiddleOrTemplateTail(node) {
|
|
633
|
+
const kind = node.kind;
|
|
634
|
+
return kind === 16 /* SyntaxKind.TemplateMiddle */
|
|
635
|
+
|| kind === 17 /* SyntaxKind.TemplateTail */;
|
|
636
|
+
}
|
|
637
|
+
export function isImportOrExportSpecifier(node) {
|
|
638
|
+
return isImportSpecifier(node) || isExportSpecifier(node);
|
|
639
|
+
}
|
|
640
|
+
export function isTypeOnlyImportOrExportDeclaration(node) {
|
|
641
|
+
switch (node.kind) {
|
|
642
|
+
case 258 /* SyntaxKind.ImportSpecifier */:
|
|
643
|
+
case 263 /* SyntaxKind.ExportSpecifier */:
|
|
644
|
+
return node.parent.parent.isTypeOnly;
|
|
645
|
+
case 256 /* SyntaxKind.NamespaceImport */:
|
|
646
|
+
return node.parent.isTypeOnly;
|
|
647
|
+
case 255 /* SyntaxKind.ImportClause */:
|
|
648
|
+
return node.isTypeOnly;
|
|
649
|
+
default:
|
|
650
|
+
return false;
|
|
651
|
+
}
|
|
652
|
+
}
|
|
653
|
+
export function isStringTextContainingNode(node) {
|
|
654
|
+
return node.kind === 10 /* SyntaxKind.StringLiteral */ || isTemplateLiteralKind(node.kind);
|
|
655
|
+
}
|
|
656
|
+
// Identifiers
|
|
657
|
+
export function isGeneratedIdentifier(node) {
|
|
658
|
+
return isIdentifier(node) && (node.autoGenerateFlags & 7 /* GeneratedIdentifierFlags.KindMask */) > 0 /* GeneratedIdentifierFlags.None */;
|
|
659
|
+
}
|
|
660
|
+
// Keywords
|
|
661
|
+
export function isModifierKind(token) {
|
|
662
|
+
switch (token) {
|
|
663
|
+
case 126 /* SyntaxKind.AsyncKeyword */:
|
|
664
|
+
case 130 /* SyntaxKind.DeclareKeyword */:
|
|
665
|
+
case 89 /* SyntaxKind.ExportKeyword */:
|
|
666
|
+
case 138 /* SyntaxKind.ReadonlyKeyword */:
|
|
667
|
+
return true;
|
|
668
|
+
}
|
|
669
|
+
return false;
|
|
670
|
+
}
|
|
671
|
+
export function isModifier(node) {
|
|
672
|
+
return isModifierKind(node.kind);
|
|
673
|
+
}
|
|
674
|
+
export function isEntityName(node) {
|
|
675
|
+
const kind = node.kind;
|
|
676
|
+
return kind === 153 /* SyntaxKind.QualifiedName */
|
|
677
|
+
|| kind === 75 /* SyntaxKind.Identifier */;
|
|
678
|
+
}
|
|
679
|
+
export function isPropertyName(node) {
|
|
680
|
+
const kind = node.kind;
|
|
681
|
+
return kind === 75 /* SyntaxKind.Identifier */
|
|
682
|
+
|| kind === 10 /* SyntaxKind.StringLiteral */
|
|
683
|
+
|| kind === 8 /* SyntaxKind.NumericLiteral */
|
|
684
|
+
|| kind === 154 /* SyntaxKind.ComputedPropertyName */;
|
|
685
|
+
}
|
|
686
|
+
export function isBindingName(node) {
|
|
687
|
+
const kind = node.kind;
|
|
688
|
+
return kind === 75 /* SyntaxKind.Identifier */
|
|
689
|
+
|| kind === 189 /* SyntaxKind.ObjectBindingPattern */
|
|
690
|
+
|| kind === 190 /* SyntaxKind.ArrayBindingPattern */;
|
|
691
|
+
}
|
|
692
|
+
// Functions
|
|
693
|
+
export function isFunctionLike(node) {
|
|
694
|
+
return node && isFunctionLikeKind(node.kind);
|
|
695
|
+
}
|
|
696
|
+
export function isFunctionLikeDeclaration(node) {
|
|
697
|
+
return node && isFunctionLikeDeclarationKind(node.kind);
|
|
698
|
+
}
|
|
699
|
+
function isFunctionLikeDeclarationKind(kind) {
|
|
700
|
+
switch (kind) {
|
|
701
|
+
case 202 /* SyntaxKind.ArrowFunction */:
|
|
702
|
+
return true;
|
|
703
|
+
default:
|
|
704
|
+
return false;
|
|
705
|
+
}
|
|
706
|
+
}
|
|
707
|
+
export function isFunctionLikeKind(kind) {
|
|
708
|
+
switch (kind) {
|
|
709
|
+
case 160 /* SyntaxKind.MethodSignature */:
|
|
710
|
+
case 165 /* SyntaxKind.CallSignature */:
|
|
711
|
+
case 167 /* SyntaxKind.IndexSignature */:
|
|
712
|
+
case 170 /* SyntaxKind.FunctionType */:
|
|
713
|
+
return true;
|
|
714
|
+
default:
|
|
715
|
+
return isFunctionLikeDeclarationKind(kind);
|
|
716
|
+
}
|
|
717
|
+
}
|
|
718
|
+
export function isFunctionOrModuleBlock(node) {
|
|
719
|
+
return isSourceFile(node) || isModuleBlock(node) || isBlock(node) && isFunctionLike(node.parent);
|
|
720
|
+
}
|
|
721
|
+
// Type members
|
|
722
|
+
export function isTypeElement(node) {
|
|
723
|
+
const kind = node.kind;
|
|
724
|
+
return kind === 165 /* SyntaxKind.CallSignature */
|
|
725
|
+
|| kind === 158 /* SyntaxKind.PropertySignature */
|
|
726
|
+
|| kind === 160 /* SyntaxKind.MethodSignature */
|
|
727
|
+
|| kind === 167 /* SyntaxKind.IndexSignature */;
|
|
728
|
+
}
|
|
729
|
+
export function isObjectLiteralElementLike(node) {
|
|
730
|
+
const kind = node.kind;
|
|
731
|
+
return kind === 281 /* SyntaxKind.PropertyAssignment */
|
|
732
|
+
|| kind === 282 /* SyntaxKind.ShorthandPropertyAssignment */
|
|
733
|
+
|| kind === 283 /* SyntaxKind.SpreadAssignment */;
|
|
734
|
+
}
|
|
735
|
+
// Type
|
|
736
|
+
/**
|
|
737
|
+
* Node test that determines whether a node is a valid type node.
|
|
738
|
+
* This differs from the `isPartOfTypeNode` function which determines whether a node is *part*
|
|
739
|
+
* of a TypeNode.
|
|
740
|
+
*/
|
|
741
|
+
export function isTypeNode(node) {
|
|
742
|
+
return isTypeNodeKind(node.kind);
|
|
743
|
+
}
|
|
744
|
+
// Binding patterns
|
|
745
|
+
export function isBindingPattern(node) {
|
|
746
|
+
if (node) {
|
|
747
|
+
const kind = node.kind;
|
|
748
|
+
return kind === 190 /* SyntaxKind.ArrayBindingPattern */
|
|
749
|
+
|| kind === 189 /* SyntaxKind.ObjectBindingPattern */;
|
|
750
|
+
}
|
|
751
|
+
return false;
|
|
752
|
+
}
|
|
753
|
+
export function isAssignmentPattern(node) {
|
|
754
|
+
const kind = node.kind;
|
|
755
|
+
return kind === 192 /* SyntaxKind.ArrayLiteralExpression */
|
|
756
|
+
|| kind === 193 /* SyntaxKind.ObjectLiteralExpression */;
|
|
757
|
+
}
|
|
758
|
+
export function isArrayBindingElement(node) {
|
|
759
|
+
const kind = node.kind;
|
|
760
|
+
return kind === 191 /* SyntaxKind.BindingElement */
|
|
761
|
+
|| kind === 215 /* SyntaxKind.OmittedExpression */;
|
|
762
|
+
}
|
|
763
|
+
/**
|
|
764
|
+
* Determines whether the BindingOrAssignmentElement is a BindingElement-like declaration
|
|
765
|
+
*/
|
|
766
|
+
export function isDeclarationBindingElement(bindingElement) {
|
|
767
|
+
switch (bindingElement.kind) {
|
|
768
|
+
case 242 /* SyntaxKind.VariableDeclaration */:
|
|
769
|
+
case 156 /* SyntaxKind.Parameter */:
|
|
770
|
+
case 191 /* SyntaxKind.BindingElement */:
|
|
771
|
+
return true;
|
|
772
|
+
}
|
|
773
|
+
return false;
|
|
774
|
+
}
|
|
775
|
+
export function isPropertyAccessOrQualifiedNameOrImportTypeNode(node) {
|
|
776
|
+
const kind = node.kind;
|
|
777
|
+
return kind === 194 /* SyntaxKind.PropertyAccessExpression */
|
|
778
|
+
|| kind === 153 /* SyntaxKind.QualifiedName */
|
|
779
|
+
|| kind === 188 /* SyntaxKind.ImportType */;
|
|
780
|
+
}
|
|
781
|
+
// Expression
|
|
782
|
+
export function isPropertyAccessOrQualifiedName(node) {
|
|
783
|
+
const kind = node.kind;
|
|
784
|
+
return kind === 194 /* SyntaxKind.PropertyAccessExpression */
|
|
785
|
+
|| kind === 153 /* SyntaxKind.QualifiedName */;
|
|
786
|
+
}
|
|
787
|
+
export function isCallLikeExpression(node) {
|
|
788
|
+
switch (node.kind) {
|
|
789
|
+
case 268 /* SyntaxKind.JsxOpeningElement */:
|
|
790
|
+
case 267 /* SyntaxKind.JsxSelfClosingElement */:
|
|
791
|
+
case 196 /* SyntaxKind.CallExpression */:
|
|
792
|
+
return true;
|
|
793
|
+
default:
|
|
794
|
+
return false;
|
|
795
|
+
}
|
|
796
|
+
}
|
|
797
|
+
/** A chamada. Na tag, também o `new` (CK-02). */
|
|
798
|
+
export function isCallOrNewExpression(node) {
|
|
799
|
+
return node.kind === 196 /* SyntaxKind.CallExpression */;
|
|
800
|
+
}
|
|
801
|
+
export function isTemplateLiteral(node) {
|
|
802
|
+
const kind = node.kind;
|
|
803
|
+
return kind === 211 /* SyntaxKind.TemplateExpression */
|
|
804
|
+
|| kind === 14 /* SyntaxKind.NoSubstitutionTemplateLiteral */;
|
|
805
|
+
}
|
|
806
|
+
export function isLeftHandSideExpression(node) {
|
|
807
|
+
return isLeftHandSideExpressionKind(skipPartiallyEmittedExpressions(node).kind);
|
|
808
|
+
}
|
|
809
|
+
function isLeftHandSideExpressionKind(kind) {
|
|
810
|
+
switch (kind) {
|
|
811
|
+
case 194 /* SyntaxKind.PropertyAccessExpression */:
|
|
812
|
+
case 195 /* SyntaxKind.ElementAccessExpression */:
|
|
813
|
+
case 196 /* SyntaxKind.CallExpression */:
|
|
814
|
+
case 266 /* SyntaxKind.JsxElement */:
|
|
815
|
+
case 267 /* SyntaxKind.JsxSelfClosingElement */:
|
|
816
|
+
case 270 /* SyntaxKind.JsxFragment */:
|
|
817
|
+
case 192 /* SyntaxKind.ArrayLiteralExpression */:
|
|
818
|
+
case 200 /* SyntaxKind.ParenthesizedExpression */:
|
|
819
|
+
case 193 /* SyntaxKind.ObjectLiteralExpression */:
|
|
820
|
+
case 75 /* SyntaxKind.Identifier */:
|
|
821
|
+
case 8 /* SyntaxKind.NumericLiteral */:
|
|
822
|
+
case 9 /* SyntaxKind.BigIntLiteral */:
|
|
823
|
+
case 10 /* SyntaxKind.StringLiteral */:
|
|
824
|
+
case 14 /* SyntaxKind.NoSubstitutionTemplateLiteral */:
|
|
825
|
+
case 211 /* SyntaxKind.TemplateExpression */:
|
|
826
|
+
case 91 /* SyntaxKind.FalseKeyword */:
|
|
827
|
+
case 100 /* SyntaxKind.NullKeyword */:
|
|
828
|
+
case 106 /* SyntaxKind.TrueKeyword */:
|
|
829
|
+
case 219 /* SyntaxKind.MetaProperty */:
|
|
830
|
+
case 96 /* SyntaxKind.ImportKeyword */: // technically this is only an Expression if it's in a CallExpression
|
|
831
|
+
return true;
|
|
832
|
+
default:
|
|
833
|
+
return false;
|
|
834
|
+
}
|
|
835
|
+
}
|
|
836
|
+
export function isUnaryExpression(node) {
|
|
837
|
+
return isUnaryExpressionKind(skipPartiallyEmittedExpressions(node).kind);
|
|
838
|
+
}
|
|
839
|
+
function isUnaryExpressionKind(kind) {
|
|
840
|
+
switch (kind) {
|
|
841
|
+
case 207 /* SyntaxKind.PrefixUnaryExpression */:
|
|
842
|
+
case 208 /* SyntaxKind.PostfixUnaryExpression */:
|
|
843
|
+
case 203 /* SyntaxKind.DeleteExpression */:
|
|
844
|
+
case 204 /* SyntaxKind.TypeOfExpression */:
|
|
845
|
+
case 206 /* SyntaxKind.AwaitExpression */:
|
|
846
|
+
return true;
|
|
847
|
+
default:
|
|
848
|
+
return isLeftHandSideExpressionKind(kind);
|
|
849
|
+
}
|
|
850
|
+
}
|
|
851
|
+
export function isUnaryExpressionWithWrite(expr) {
|
|
852
|
+
switch (expr.kind) {
|
|
853
|
+
case 208 /* SyntaxKind.PostfixUnaryExpression */:
|
|
854
|
+
return true;
|
|
855
|
+
case 207 /* SyntaxKind.PrefixUnaryExpression */:
|
|
856
|
+
return expr.operator === 45 /* SyntaxKind.PlusPlusToken */ ||
|
|
857
|
+
expr.operator === 46 /* SyntaxKind.MinusMinusToken */;
|
|
858
|
+
default:
|
|
859
|
+
return false;
|
|
860
|
+
}
|
|
861
|
+
}
|
|
862
|
+
/**
|
|
863
|
+
* Determines whether a node is an expression based only on its kind.
|
|
864
|
+
* Use `isExpressionNode` if not in transforms.
|
|
865
|
+
*/
|
|
866
|
+
export function isExpression(node) {
|
|
867
|
+
return isExpressionKind(skipPartiallyEmittedExpressions(node).kind);
|
|
868
|
+
}
|
|
869
|
+
function isExpressionKind(kind) {
|
|
870
|
+
switch (kind) {
|
|
871
|
+
case 210 /* SyntaxKind.ConditionalExpression */:
|
|
872
|
+
case 202 /* SyntaxKind.ArrowFunction */:
|
|
873
|
+
case 209 /* SyntaxKind.BinaryExpression */:
|
|
874
|
+
case 213 /* SyntaxKind.SpreadElement */:
|
|
875
|
+
case 217 /* SyntaxKind.AsExpression */:
|
|
876
|
+
case 215 /* SyntaxKind.OmittedExpression */:
|
|
877
|
+
case 327 /* SyntaxKind.CommaListExpression */:
|
|
878
|
+
case 326 /* SyntaxKind.PartiallyEmittedExpression */:
|
|
879
|
+
return true;
|
|
880
|
+
default:
|
|
881
|
+
return isUnaryExpressionKind(kind);
|
|
882
|
+
}
|
|
883
|
+
}
|
|
884
|
+
export function isAssertionExpression(node) {
|
|
885
|
+
const kind = node.kind;
|
|
886
|
+
return kind === 217 /* SyntaxKind.AsExpression */;
|
|
887
|
+
}
|
|
888
|
+
export function isNotEmittedStatement(node) {
|
|
889
|
+
return node.kind === 325 /* SyntaxKind.NotEmittedStatement */;
|
|
890
|
+
}
|
|
891
|
+
// Statement
|
|
892
|
+
export function isIterationStatement(node) {
|
|
893
|
+
switch (node.kind) {
|
|
894
|
+
case 230 /* SyntaxKind.ForStatement */:
|
|
895
|
+
case 231 /* SyntaxKind.ForInStatement */:
|
|
896
|
+
case 232 /* SyntaxKind.ForOfStatement */:
|
|
897
|
+
case 228 /* SyntaxKind.DoStatement */:
|
|
898
|
+
case 229 /* SyntaxKind.WhileStatement */:
|
|
899
|
+
return true;
|
|
900
|
+
}
|
|
901
|
+
return false;
|
|
902
|
+
}
|
|
903
|
+
export function isForInOrOfStatement(node) {
|
|
904
|
+
return node.kind === 231 /* SyntaxKind.ForInStatement */ || node.kind === 232 /* SyntaxKind.ForOfStatement */;
|
|
905
|
+
}
|
|
906
|
+
// Element
|
|
907
|
+
export function isConciseBody(node) {
|
|
908
|
+
return isBlock(node)
|
|
909
|
+
|| isExpression(node);
|
|
910
|
+
}
|
|
911
|
+
export function isForInitializer(node) {
|
|
912
|
+
return isVariableDeclarationList(node)
|
|
913
|
+
|| isExpression(node);
|
|
914
|
+
}
|
|
915
|
+
export function isModuleBody(node) {
|
|
916
|
+
const kind = node.kind;
|
|
917
|
+
return kind === 250 /* SyntaxKind.ModuleBlock */
|
|
918
|
+
|| kind === 249 /* SyntaxKind.ModuleDeclaration */
|
|
919
|
+
|| kind === 75 /* SyntaxKind.Identifier */;
|
|
920
|
+
}
|
|
921
|
+
export function isNamedImportBindings(node) {
|
|
922
|
+
const kind = node.kind;
|
|
923
|
+
return kind === 257 /* SyntaxKind.NamedImports */
|
|
924
|
+
|| kind === 256 /* SyntaxKind.NamespaceImport */;
|
|
925
|
+
}
|
|
926
|
+
function isDeclarationKind(kind) {
|
|
927
|
+
return kind === 202 /* SyntaxKind.ArrowFunction */
|
|
928
|
+
|| kind === 191 /* SyntaxKind.BindingElement */
|
|
929
|
+
|| kind === 263 /* SyntaxKind.ExportSpecifier */
|
|
930
|
+
|| kind === 255 /* SyntaxKind.ImportClause */
|
|
931
|
+
|| kind === 258 /* SyntaxKind.ImportSpecifier */
|
|
932
|
+
|| kind === 273 /* SyntaxKind.JsxAttribute */
|
|
933
|
+
|| kind === 249 /* SyntaxKind.ModuleDeclaration */
|
|
934
|
+
|| kind === 256 /* SyntaxKind.NamespaceImport */
|
|
935
|
+
|| kind === 262 /* SyntaxKind.NamespaceExport */
|
|
936
|
+
|| kind === 156 /* SyntaxKind.Parameter */
|
|
937
|
+
|| kind === 281 /* SyntaxKind.PropertyAssignment */
|
|
938
|
+
|| kind === 158 /* SyntaxKind.PropertySignature */
|
|
939
|
+
|| kind === 282 /* SyntaxKind.ShorthandPropertyAssignment */
|
|
940
|
+
|| kind === 247 /* SyntaxKind.TypeAliasDeclaration */
|
|
941
|
+
|| kind === 155 /* SyntaxKind.TypeParameter */
|
|
942
|
+
|| kind === 242 /* SyntaxKind.VariableDeclaration */;
|
|
943
|
+
}
|
|
944
|
+
function isDeclarationStatementKind(kind) {
|
|
945
|
+
return kind === 264 /* SyntaxKind.MissingDeclaration */
|
|
946
|
+
|| kind === 247 /* SyntaxKind.TypeAliasDeclaration */
|
|
947
|
+
|| kind === 249 /* SyntaxKind.ModuleDeclaration */
|
|
948
|
+
|| kind === 254 /* SyntaxKind.ImportDeclaration */
|
|
949
|
+
|| kind === 260 /* SyntaxKind.ExportDeclaration */
|
|
950
|
+
|| kind === 259 /* SyntaxKind.ExportAssignment */;
|
|
951
|
+
}
|
|
952
|
+
function isStatementKindButNotDeclarationKind(kind) {
|
|
953
|
+
return kind === 234 /* SyntaxKind.BreakStatement */
|
|
954
|
+
|| kind === 233 /* SyntaxKind.ContinueStatement */
|
|
955
|
+
|| kind === 228 /* SyntaxKind.DoStatement */
|
|
956
|
+
|| kind === 226 /* SyntaxKind.ExpressionStatement */
|
|
957
|
+
|| kind === 224 /* SyntaxKind.EmptyStatement */
|
|
958
|
+
|| kind === 231 /* SyntaxKind.ForInStatement */
|
|
959
|
+
|| kind === 232 /* SyntaxKind.ForOfStatement */
|
|
960
|
+
|| kind === 230 /* SyntaxKind.ForStatement */
|
|
961
|
+
|| kind === 227 /* SyntaxKind.IfStatement */
|
|
962
|
+
|| kind === 235 /* SyntaxKind.ReturnStatement */
|
|
963
|
+
|| kind === 237 /* SyntaxKind.SwitchStatement */
|
|
964
|
+
|| kind === 239 /* SyntaxKind.ThrowStatement */
|
|
965
|
+
|| kind === 240 /* SyntaxKind.TryStatement */
|
|
966
|
+
|| kind === 225 /* SyntaxKind.VariableStatement */
|
|
967
|
+
|| kind === 229 /* SyntaxKind.WhileStatement */
|
|
968
|
+
|| kind === 325 /* SyntaxKind.NotEmittedStatement */
|
|
969
|
+
|| kind === 329 /* SyntaxKind.EndOfDeclarationMarker */
|
|
970
|
+
|| kind === 328 /* SyntaxKind.MergeDeclarationMarker */;
|
|
971
|
+
}
|
|
972
|
+
export function isDeclaration(node) {
|
|
973
|
+
if (node.kind === 155 /* SyntaxKind.TypeParameter */) {
|
|
974
|
+
return !!node.parent;
|
|
975
|
+
}
|
|
976
|
+
return isDeclarationKind(node.kind);
|
|
977
|
+
}
|
|
978
|
+
/**
|
|
979
|
+
* Determines whether the node is a statement that is not also a declaration
|
|
980
|
+
*/
|
|
981
|
+
export function isStatementButNotDeclaration(node) {
|
|
982
|
+
return isStatementKindButNotDeclarationKind(node.kind);
|
|
983
|
+
}
|
|
984
|
+
export function isStatement(node) {
|
|
985
|
+
const kind = node.kind;
|
|
986
|
+
return isStatementKindButNotDeclarationKind(kind)
|
|
987
|
+
|| isDeclarationStatementKind(kind)
|
|
988
|
+
|| isBlockStatement(node);
|
|
989
|
+
}
|
|
990
|
+
function isBlockStatement(node) {
|
|
991
|
+
if (node.kind !== 223 /* SyntaxKind.Block */)
|
|
992
|
+
return false;
|
|
993
|
+
if (node.parent !== undefined) {
|
|
994
|
+
if (node.parent.kind === 240 /* SyntaxKind.TryStatement */ || node.parent.kind === 280 /* SyntaxKind.CatchClause */) {
|
|
995
|
+
return false;
|
|
996
|
+
}
|
|
997
|
+
}
|
|
998
|
+
return !isFunctionBlock(node);
|
|
999
|
+
}
|
|
1000
|
+
// JSX
|
|
1001
|
+
export function isJsxTagNameExpression(node) {
|
|
1002
|
+
const kind = node.kind;
|
|
1003
|
+
return kind === 75 /* SyntaxKind.Identifier */
|
|
1004
|
+
|| kind === 194 /* SyntaxKind.PropertyAccessExpression */;
|
|
1005
|
+
}
|
|
1006
|
+
export function isJsxChild(node) {
|
|
1007
|
+
const kind = node.kind;
|
|
1008
|
+
return kind === 266 /* SyntaxKind.JsxElement */
|
|
1009
|
+
|| kind === 276 /* SyntaxKind.JsxExpression */
|
|
1010
|
+
|| kind === 267 /* SyntaxKind.JsxSelfClosingElement */
|
|
1011
|
+
|| kind === 11 /* SyntaxKind.JsxText */
|
|
1012
|
+
|| kind === 270 /* SyntaxKind.JsxFragment */;
|
|
1013
|
+
}
|
|
1014
|
+
export function isJsxAttributeLike(node) {
|
|
1015
|
+
const kind = node.kind;
|
|
1016
|
+
return kind === 273 /* SyntaxKind.JsxAttribute */
|
|
1017
|
+
|| kind === 275 /* SyntaxKind.JsxSpreadAttribute */;
|
|
1018
|
+
}
|
|
1019
|
+
export function isStringLiteralOrJsxExpression(node) {
|
|
1020
|
+
const kind = node.kind;
|
|
1021
|
+
return kind === 10 /* SyntaxKind.StringLiteral */
|
|
1022
|
+
|| kind === 276 /* SyntaxKind.JsxExpression */;
|
|
1023
|
+
}
|
|
1024
|
+
export function isJsxOpeningLikeElement(node) {
|
|
1025
|
+
const kind = node.kind;
|
|
1026
|
+
return kind === 268 /* SyntaxKind.JsxOpeningElement */
|
|
1027
|
+
|| kind === 267 /* SyntaxKind.JsxSelfClosingElement */;
|
|
1028
|
+
}
|
|
1029
|
+
// Clauses
|
|
1030
|
+
export function isCaseOrDefaultClause(node) {
|
|
1031
|
+
const kind = node.kind;
|
|
1032
|
+
return kind === 277 /* SyntaxKind.CaseClause */
|
|
1033
|
+
|| kind === 278 /* SyntaxKind.DefaultClause */;
|
|
1034
|
+
}
|
|
1035
|
+
/** True if has type node attached to it. */
|
|
1036
|
+
export function hasType(node) {
|
|
1037
|
+
return !!node.type;
|
|
1038
|
+
}
|
|
1039
|
+
/** True if has initializer node attached to it. */
|
|
1040
|
+
export function hasInitializer(node) {
|
|
1041
|
+
return !!node.initializer;
|
|
1042
|
+
}
|
|
1043
|
+
export function isObjectLiteralElement(node) {
|
|
1044
|
+
return node.kind === 273 /* SyntaxKind.JsxAttribute */ || node.kind === 275 /* SyntaxKind.JsxSpreadAttribute */ || isObjectLiteralElementLike(node);
|
|
1045
|
+
}
|
|
1046
|
+
export function isStringLiteralLike(node) {
|
|
1047
|
+
return node.kind === 10 /* SyntaxKind.StringLiteral */ || node.kind === 14 /* SyntaxKind.NoSubstitutionTemplateLiteral */;
|
|
1048
|
+
}
|
|
1049
|
+
// #endregion
|