@tslite/parser 1.10.0 → 1.12.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.
Files changed (47) hide show
  1. package/LICENSE +55 -0
  2. package/NOTICE +14 -0
  3. package/dist/_namespaces/ts.d.ts +18 -0
  4. package/dist/_namespaces/ts.js +21 -0
  5. package/dist/_namespaces/ts.performance.d.ts +1 -0
  6. package/dist/_namespaces/ts.performance.js +2 -0
  7. package/dist/core.d.ts +450 -0
  8. package/dist/core.js +1394 -0
  9. package/dist/corePublic.d.ts +62 -0
  10. package/dist/corePublic.js +31 -0
  11. package/dist/debug.d.ts +74 -0
  12. package/dist/debug.js +326 -0
  13. package/dist/diagnosticInformationMap.generated.d.ts +1435 -0
  14. package/dist/diagnosticInformationMap.generated.js +1441 -0
  15. package/dist/factory.d.ts +78 -0
  16. package/dist/factory.js +622 -0
  17. package/dist/factoryPublic.d.ts +314 -0
  18. package/dist/factoryPublic.js +1796 -0
  19. package/dist/index.d.ts +1 -249
  20. package/dist/index.js +4 -6
  21. package/dist/parser.d.ts +59 -0
  22. package/dist/parser.js +5075 -0
  23. package/dist/path.d.ts +312 -0
  24. package/dist/path.js +475 -0
  25. package/dist/perfLogger.d.ts +4 -0
  26. package/dist/perfLogger.js +38 -0
  27. package/dist/performance.d.ts +20 -0
  28. package/dist/performance.js +49 -0
  29. package/dist/performanceTimestamp.d.ts +2 -0
  30. package/dist/performanceTimestamp.js +2 -0
  31. package/dist/scanner.d.ts +80 -0
  32. package/dist/scanner.js +1984 -0
  33. package/dist/shims/mapShim.d.ts +23 -0
  34. package/dist/shims/mapShim.js +156 -0
  35. package/dist/types.d.ts +2626 -0
  36. package/dist/types.js +1074 -0
  37. package/dist/utilities.d.ts +473 -0
  38. package/dist/utilities.js +2632 -0
  39. package/dist/utilitiesPublic.d.ts +274 -0
  40. package/dist/utilitiesPublic.js +1049 -0
  41. package/dist/visitor.d.ts +15 -0
  42. package/dist/visitor.js +64 -0
  43. package/dist/visitorPublic.d.ts +82 -0
  44. package/dist/visitorPublic.js +352 -0
  45. package/package.json +14 -42
  46. package/dist/index.cjs +0 -6
  47. package/dist/index.d.cts +0 -249
@@ -0,0 +1,622 @@
1
+ // Modificado de microsoft/TypeScript v3.9.10, src/compiler/factory.ts: o namespace virou módulo ES, com os imports explícitos.
2
+ import { Debug, compareValues, createArrayLiteral, createAssignment, createBlock, createLiteral, createNodeArray, createObjectLiteral, createParen, createParenthesizedType, createPropertyAccess, createPropertyAssignment, createReturn, createShorthandPropertyAssignment, createSpread, createSpreadAssignment, createStatement, getCommentRange, getExpressionAssociativity, getExpressionPrecedence, getMutableClone, getOperatorAssociativity, getOperatorPrecedence, getSourceMapRange, getSyntheticLeadingComments, getSyntheticTrailingComments, isArrayBindingPattern, isArrayLiteralExpression, isAssignmentExpression, isBinaryExpression, isBindingElement, isBindingPattern, isBlock, isCallExpression, isDeclarationBindingElement, isExpression, isFunctionTypeNode, isIdentifier, isLeftHandSideExpression, isLiteralKind, isObjectBindingPattern, isObjectLiteralElementLike, isObjectLiteralExpression, isPrologueDirective, isPropertyAssignment, isQualifiedName, isShorthandPropertyAssignment, isSpreadElement, isStringLiteral, isUnaryExpression, map, nodeIsSynthesized, noop, notImplemented, returnUndefined, sameMap, setOriginalNode, setStartsOnNewLine, setTextRange, skipPartiallyEmittedExpressions, some, updateAsExpression, updateParen, updatePartiallyEmittedExpression, } from "./_namespaces/ts.js";
3
+ export const nullTransformationContext = {
4
+ enableEmitNotification: noop,
5
+ enableSubstitution: noop,
6
+ endLexicalEnvironment: returnUndefined,
7
+ getCompilerOptions: () => ({}),
8
+ setLexicalEnvironmentFlags: noop,
9
+ getLexicalEnvironmentFlags: () => 0,
10
+ hoistVariableDeclaration: noop,
11
+ addInitializationStatement: noop,
12
+ isEmitNotificationEnabled: notImplemented,
13
+ isSubstitutionEnabled: notImplemented,
14
+ onEmitNode: noop,
15
+ onSubstituteNode: notImplemented,
16
+ readEmitHelpers: notImplemented,
17
+ requestEmitHelper: noop,
18
+ resumeLexicalEnvironment: noop,
19
+ startLexicalEnvironment: noop,
20
+ suspendLexicalEnvironment: noop,
21
+ addDiagnostic: noop,
22
+ };
23
+ // Helpers
24
+ // Utilities
25
+ export function createExpressionFromEntityName(node) {
26
+ if (isQualifiedName(node)) {
27
+ const left = createExpressionFromEntityName(node.left);
28
+ const right = getMutableClone(node.right);
29
+ return setTextRange(createPropertyAccess(left, right), node);
30
+ }
31
+ else {
32
+ return getMutableClone(node);
33
+ }
34
+ }
35
+ export function convertToFunctionBody(node, multiLine) {
36
+ return isBlock(node) ? node : setTextRange(createBlock([setTextRange(createReturn(node), node)], multiLine), node);
37
+ }
38
+ function isUseStrictPrologue(node) {
39
+ return isStringLiteral(node.expression) && node.expression.text === "use strict";
40
+ }
41
+ export function findUseStrictPrologue(statements) {
42
+ for (const statement of statements) {
43
+ if (isPrologueDirective(statement)) {
44
+ if (isUseStrictPrologue(statement)) {
45
+ return statement;
46
+ }
47
+ }
48
+ else {
49
+ break;
50
+ }
51
+ }
52
+ return undefined;
53
+ }
54
+ /**
55
+ * Ensures "use strict" directive is added
56
+ *
57
+ * @param statements An array of statements
58
+ */
59
+ export function ensureUseStrict(statements) {
60
+ const foundUseStrict = findUseStrictPrologue(statements);
61
+ if (!foundUseStrict) {
62
+ return setTextRange(createNodeArray([
63
+ startOnNewLine(createStatement(createLiteral("use strict"))),
64
+ ...statements
65
+ ]), statements);
66
+ }
67
+ return statements;
68
+ }
69
+ /**
70
+ * Wraps the operand to a BinaryExpression in parentheses if they are needed to preserve the intended
71
+ * order of operations.
72
+ *
73
+ * @param binaryOperator The operator for the BinaryExpression.
74
+ * @param operand The operand for the BinaryExpression.
75
+ * @param isLeftSideOfBinary A value indicating whether the operand is the left side of the
76
+ * BinaryExpression.
77
+ */
78
+ export function parenthesizeBinaryOperand(binaryOperator, operand, isLeftSideOfBinary, leftOperand) {
79
+ const skipped = skipPartiallyEmittedExpressions(operand);
80
+ // If the resulting expression is already parenthesized, we do not need to do any further processing.
81
+ if (skipped.kind === 200 /* SyntaxKind.ParenthesizedExpression */) {
82
+ return operand;
83
+ }
84
+ return binaryOperandNeedsParentheses(binaryOperator, operand, isLeftSideOfBinary, leftOperand)
85
+ ? createParen(operand)
86
+ : operand;
87
+ }
88
+ // O `??` misturado ao `||` ou ao `&&` sempre parenteseado: a correção do TypeScript 5.9.3 (PR #62311, CK-65).
89
+ function mixingBinaryOperatorsRequiresParentheses(a, b) {
90
+ if (a === 60 /* SyntaxKind.QuestionQuestionToken */) {
91
+ return b === 55 /* SyntaxKind.AmpersandAmpersandToken */ || b === 56 /* SyntaxKind.BarBarToken */;
92
+ }
93
+ if (b === 60 /* SyntaxKind.QuestionQuestionToken */) {
94
+ return a === 55 /* SyntaxKind.AmpersandAmpersandToken */ || a === 56 /* SyntaxKind.BarBarToken */;
95
+ }
96
+ return false;
97
+ }
98
+ /**
99
+ * Determines whether the operand to a BinaryExpression needs to be parenthesized.
100
+ *
101
+ * @param binaryOperator The operator for the BinaryExpression.
102
+ * @param operand The operand for the BinaryExpression.
103
+ * @param isLeftSideOfBinary A value indicating whether the operand is the left side of the
104
+ * BinaryExpression.
105
+ */
106
+ function binaryOperandNeedsParentheses(binaryOperator, operand, isLeftSideOfBinary, leftOperand) {
107
+ const emittedOperand = skipPartiallyEmittedExpressions(operand);
108
+ if (isBinaryExpression(emittedOperand) && mixingBinaryOperatorsRequiresParentheses(binaryOperator, emittedOperand.operatorToken.kind)) {
109
+ return true;
110
+ }
111
+ // If the operand has lower precedence, then it needs to be parenthesized to preserve the
112
+ // intent of the expression. For example, if the operand is `a + b` and the operator is
113
+ // `*`, then we need to parenthesize the operand to preserve the intended order of
114
+ // operations: `(a + b) * x`.
115
+ //
116
+ // If the operand has higher precedence, then it does not need to be parenthesized. For
117
+ // example, if the operand is `a * b` and the operator is `+`, then we do not need to
118
+ // parenthesize to preserve the intended order of operations: `a * b + x`.
119
+ //
120
+ // If the operand has the same precedence, then we need to check the associativity of
121
+ // the operator based on whether this is the left or right operand of the expression.
122
+ //
123
+ // For example, if `a / d` is on the right of operator `*`, we need to parenthesize
124
+ // to preserve the intended order of operations: `x * (a / d)`
125
+ //
126
+ // If `a ** d` is on the left of operator `**`, we need to parenthesize to preserve
127
+ // the intended order of operations: `(a ** b) ** c`
128
+ const binaryOperatorPrecedence = getOperatorPrecedence(209 /* SyntaxKind.BinaryExpression */, binaryOperator);
129
+ const binaryOperatorAssociativity = getOperatorAssociativity(209 /* SyntaxKind.BinaryExpression */, binaryOperator);
130
+ if (!isLeftSideOfBinary && operand.kind === 202 /* SyntaxKind.ArrowFunction */ && binaryOperatorPrecedence > 3) {
131
+ // We need to parenthesize arrow functions on the right side to avoid it being
132
+ // parsed as parenthesized expression: `a && (() => {})`
133
+ return true;
134
+ }
135
+ const operandPrecedence = getExpressionPrecedence(emittedOperand);
136
+ switch (compareValues(operandPrecedence, binaryOperatorPrecedence)) {
137
+ case -1 /* Comparison.LessThan */:
138
+ return true;
139
+ case 1 /* Comparison.GreaterThan */:
140
+ return false;
141
+ case 0 /* Comparison.EqualTo */:
142
+ if (isLeftSideOfBinary) {
143
+ // No need to parenthesize the left operand when the binary operator is
144
+ // left associative:
145
+ // (a*b)/x -> a*b/x
146
+ // (a**b)/x -> a**b/x
147
+ //
148
+ // Parentheses are needed for the left operand when the binary operator is
149
+ // right associative:
150
+ // (a/b)**x -> (a/b)**x
151
+ // (a**b)**x -> (a**b)**x
152
+ return binaryOperatorAssociativity === 1 /* Associativity.Right */;
153
+ }
154
+ else {
155
+ if (isBinaryExpression(emittedOperand)
156
+ && emittedOperand.operatorToken.kind === binaryOperator) {
157
+ // No need to parenthesize the right operand when the binary operator and
158
+ // operand are the same and one of the following:
159
+ // x*(a*b) => x*a*b
160
+ // x|(a|b) => x|a|b
161
+ // x&(a&b) => x&a&b
162
+ // x^(a^b) => x^a^b
163
+ if (operatorHasAssociativeProperty(binaryOperator)) {
164
+ return false;
165
+ }
166
+ // No need to parenthesize the right operand when the binary operator
167
+ // is plus (+) if both the left and right operands consist solely of either
168
+ // literals of the same kind or binary plus (+) expressions for literals of
169
+ // the same kind (recursively).
170
+ // "a"+(1+2) => "a"+(1+2)
171
+ // "a"+("b"+"c") => "a"+"b"+"c"
172
+ if (binaryOperator === 39 /* SyntaxKind.PlusToken */) {
173
+ const leftKind = leftOperand ? getLiteralKindOfBinaryPlusOperand(leftOperand) : 0 /* SyntaxKind.Unknown */;
174
+ if (isLiteralKind(leftKind) && leftKind === getLiteralKindOfBinaryPlusOperand(emittedOperand)) {
175
+ return false;
176
+ }
177
+ }
178
+ }
179
+ // No need to parenthesize the right operand when the operand is right
180
+ // associative:
181
+ // x/(a**b) -> x/a**b
182
+ // x**(a**b) -> x**a**b
183
+ //
184
+ // Parentheses are needed for the right operand when the operand is left
185
+ // associative:
186
+ // x/(a*b) -> x/(a*b)
187
+ // x**(a/b) -> x**(a/b)
188
+ const operandAssociativity = getExpressionAssociativity(emittedOperand);
189
+ return operandAssociativity === 0 /* Associativity.Left */;
190
+ }
191
+ }
192
+ }
193
+ /**
194
+ * Determines whether a binary operator is mathematically associative.
195
+ *
196
+ * @param binaryOperator The binary operator.
197
+ */
198
+ function operatorHasAssociativeProperty(binaryOperator) {
199
+ // The following operators are associative in JavaScript:
200
+ // (a*b)*c -> a*(b*c) -> a*b*c
201
+ // (a|b)|c -> a|(b|c) -> a|b|c
202
+ // (a&b)&c -> a&(b&c) -> a&b&c
203
+ // (a^b)^c -> a^(b^c) -> a^b^c
204
+ //
205
+ // While addition is associative in mathematics, JavaScript's `+` is not
206
+ // guaranteed to be associative as it is overloaded with string concatenation.
207
+ return binaryOperator === 41 /* SyntaxKind.AsteriskToken */
208
+ || binaryOperator === 51 /* SyntaxKind.BarToken */
209
+ || binaryOperator === 50 /* SyntaxKind.AmpersandToken */
210
+ || binaryOperator === 52 /* SyntaxKind.CaretToken */;
211
+ }
212
+ /**
213
+ * This function determines whether an expression consists of a homogeneous set of
214
+ * literal expressions or binary plus expressions that all share the same literal kind.
215
+ * It is used to determine whether the right-hand operand of a binary plus expression can be
216
+ * emitted without parentheses.
217
+ */
218
+ function getLiteralKindOfBinaryPlusOperand(node) {
219
+ node = skipPartiallyEmittedExpressions(node);
220
+ if (isLiteralKind(node.kind)) {
221
+ return node.kind;
222
+ }
223
+ if (node.kind === 209 /* SyntaxKind.BinaryExpression */ && node.operatorToken.kind === 39 /* SyntaxKind.PlusToken */) {
224
+ if (node.cachedLiteralKind !== undefined) {
225
+ return node.cachedLiteralKind;
226
+ }
227
+ const leftKind = getLiteralKindOfBinaryPlusOperand(node.left);
228
+ const literalKind = isLiteralKind(leftKind) && leftKind === getLiteralKindOfBinaryPlusOperand(node.right) ? leftKind :
229
+ 0 /* SyntaxKind.Unknown */;
230
+ node.cachedLiteralKind = literalKind;
231
+ return literalKind;
232
+ }
233
+ return 0 /* SyntaxKind.Unknown */;
234
+ }
235
+ export function parenthesizeForConditionalHead(condition) {
236
+ const conditionalPrecedence = getOperatorPrecedence(210 /* SyntaxKind.ConditionalExpression */, 57 /* SyntaxKind.QuestionToken */);
237
+ const emittedCondition = skipPartiallyEmittedExpressions(condition);
238
+ const conditionPrecedence = getExpressionPrecedence(emittedCondition);
239
+ if (compareValues(conditionPrecedence, conditionalPrecedence) !== 1 /* Comparison.GreaterThan */) {
240
+ return createParen(condition);
241
+ }
242
+ return condition;
243
+ }
244
+ export function parenthesizeSubexpressionOfConditionalExpression(e) {
245
+ // per ES grammar both 'whenTrue' and 'whenFalse' parts of conditional expression are assignment expressions
246
+ // so in case when comma expression is introduced as a part of previous transformations
247
+ // if should be wrapped in parens since comma operator has the lowest precedence
248
+ const emittedExpression = skipPartiallyEmittedExpressions(e);
249
+ return isCommaSequence(emittedExpression)
250
+ ? createParen(e)
251
+ : e;
252
+ }
253
+ /**
254
+ * O `export default` aceita uma AssignmentExpression: a sequência de vírgula, escrita ou sintética, vai entre
255
+ * parênteses.
256
+ */
257
+ export function parenthesizeDefaultExpression(e) {
258
+ const check = skipPartiallyEmittedExpressions(e);
259
+ return isCommaSequence(check) ? createParen(e) : e;
260
+ }
261
+ /**
262
+ * Wraps an expression in parentheses if it is needed in order to use the expression for
263
+ * property or element access.
264
+ *
265
+ * @param expr The expression node.
266
+ */
267
+ export function parenthesizeForAccess(expression) {
268
+ const emittedExpression = skipPartiallyEmittedExpressions(expression);
269
+ if (isLeftHandSideExpression(emittedExpression)) {
270
+ return expression;
271
+ }
272
+ return setTextRange(createParen(expression), expression);
273
+ }
274
+ export function parenthesizePostfixOperand(operand) {
275
+ return isLeftHandSideExpression(operand)
276
+ ? operand
277
+ : setTextRange(createParen(operand), operand);
278
+ }
279
+ export function parenthesizePrefixOperand(operand) {
280
+ return isUnaryExpression(operand)
281
+ ? operand
282
+ : setTextRange(createParen(operand), operand);
283
+ }
284
+ export function parenthesizeListElements(elements) {
285
+ let result;
286
+ for (let i = 0; i < elements.length; i++) {
287
+ const element = parenthesizeExpressionForList(elements[i]);
288
+ if (result !== undefined || element !== elements[i]) {
289
+ if (result === undefined) {
290
+ result = elements.slice(0, i);
291
+ }
292
+ result.push(element);
293
+ }
294
+ }
295
+ if (result !== undefined) {
296
+ return setTextRange(createNodeArray(result, elements.hasTrailingComma), elements);
297
+ }
298
+ return elements;
299
+ }
300
+ export function parenthesizeExpressionForList(expression) {
301
+ const emittedExpression = skipPartiallyEmittedExpressions(expression);
302
+ const expressionPrecedence = getExpressionPrecedence(emittedExpression);
303
+ const commaPrecedence = getOperatorPrecedence(209 /* SyntaxKind.BinaryExpression */, 27 /* SyntaxKind.CommaToken */);
304
+ return expressionPrecedence > commaPrecedence
305
+ ? expression
306
+ : setTextRange(createParen(expression), expression);
307
+ }
308
+ export function parenthesizeExpressionForExpressionStatement(expression) {
309
+ const emittedExpression = skipPartiallyEmittedExpressions(expression);
310
+ if (isCallExpression(emittedExpression)) {
311
+ const callee = emittedExpression.expression;
312
+ const kind = skipPartiallyEmittedExpressions(callee).kind;
313
+ if (kind === 202 /* SyntaxKind.ArrowFunction */) {
314
+ const mutableCall = getMutableClone(emittedExpression);
315
+ mutableCall.expression = setTextRange(createParen(callee), callee);
316
+ return recreateOuterExpressions(expression, mutableCall, 8 /* OuterExpressionKinds.PartiallyEmittedExpressions */);
317
+ }
318
+ }
319
+ const leftmostExpressionKind = getLeftmostExpression(emittedExpression).kind;
320
+ if (leftmostExpressionKind === 193 /* SyntaxKind.ObjectLiteralExpression */) {
321
+ return setTextRange(createParen(expression), expression);
322
+ }
323
+ return expression;
324
+ }
325
+ export function parenthesizeConditionalTypeMember(member) {
326
+ return member.kind === 180 /* SyntaxKind.ConditionalType */ ? createParenthesizedType(member) : member;
327
+ }
328
+ export function parenthesizeElementTypeMember(member) {
329
+ switch (member.kind) {
330
+ case 178 /* SyntaxKind.UnionType */:
331
+ case 179 /* SyntaxKind.IntersectionType */:
332
+ case 170 /* SyntaxKind.FunctionType */:
333
+ return createParenthesizedType(member);
334
+ }
335
+ return parenthesizeConditionalTypeMember(member);
336
+ }
337
+ export function parenthesizeArrayTypeMember(member) {
338
+ switch (member.kind) {
339
+ case 172 /* SyntaxKind.TypeQuery */:
340
+ case 184 /* SyntaxKind.TypeOperator */:
341
+ case 181 /* SyntaxKind.InferType */:
342
+ return createParenthesizedType(member);
343
+ }
344
+ return parenthesizeElementTypeMember(member);
345
+ }
346
+ export function parenthesizeElementTypeMembers(members) {
347
+ return createNodeArray(sameMap(members, parenthesizeElementTypeMember));
348
+ }
349
+ export function parenthesizeTypeParameters(typeParameters) {
350
+ if (some(typeParameters)) {
351
+ const params = [];
352
+ for (let i = 0; i < typeParameters.length; ++i) {
353
+ const entry = typeParameters[i];
354
+ params.push(i === 0 && isFunctionTypeNode(entry) && entry.typeParameters ?
355
+ createParenthesizedType(entry) :
356
+ entry);
357
+ }
358
+ return createNodeArray(params);
359
+ }
360
+ }
361
+ export function getLeftmostExpression(node) {
362
+ while (true) {
363
+ switch (node.kind) {
364
+ case 208 /* SyntaxKind.PostfixUnaryExpression */:
365
+ node = node.operand;
366
+ continue;
367
+ case 209 /* SyntaxKind.BinaryExpression */:
368
+ node = node.left;
369
+ continue;
370
+ case 210 /* SyntaxKind.ConditionalExpression */:
371
+ node = node.condition;
372
+ continue;
373
+ case 196 /* SyntaxKind.CallExpression */:
374
+ case 217 /* SyntaxKind.AsExpression */:
375
+ case 195 /* SyntaxKind.ElementAccessExpression */:
376
+ case 194 /* SyntaxKind.PropertyAccessExpression */:
377
+ case 326 /* SyntaxKind.PartiallyEmittedExpression */:
378
+ node = node.expression;
379
+ continue;
380
+ }
381
+ return node;
382
+ }
383
+ }
384
+ export function parenthesizeConciseBody(body) {
385
+ if (!isBlock(body) && (isCommaSequence(body) || getLeftmostExpression(body).kind === 193 /* SyntaxKind.ObjectLiteralExpression */)) {
386
+ return setTextRange(createParen(body), body);
387
+ }
388
+ return body;
389
+ }
390
+ export function isCommaSequence(node) {
391
+ return node.kind === 209 /* SyntaxKind.BinaryExpression */ && node.operatorToken.kind === 27 /* SyntaxKind.CommaToken */ ||
392
+ node.kind === 327 /* SyntaxKind.CommaListExpression */;
393
+ }
394
+ export var OuterExpressionKinds;
395
+ (function (OuterExpressionKinds) {
396
+ OuterExpressionKinds[OuterExpressionKinds["Parentheses"] = 1] = "Parentheses";
397
+ OuterExpressionKinds[OuterExpressionKinds["TypeAssertions"] = 2] = "TypeAssertions";
398
+ OuterExpressionKinds[OuterExpressionKinds["PartiallyEmittedExpressions"] = 8] = "PartiallyEmittedExpressions";
399
+ OuterExpressionKinds[OuterExpressionKinds["Assertions"] = 2] = "Assertions";
400
+ OuterExpressionKinds[OuterExpressionKinds["All"] = 11] = "All";
401
+ })(OuterExpressionKinds || (OuterExpressionKinds = {}));
402
+ export function isOuterExpression(node, kinds = 11 /* OuterExpressionKinds.All */) {
403
+ switch (node.kind) {
404
+ case 200 /* SyntaxKind.ParenthesizedExpression */:
405
+ return (kinds & 1 /* OuterExpressionKinds.Parentheses */) !== 0;
406
+ case 217 /* SyntaxKind.AsExpression */:
407
+ return (kinds & 2 /* OuterExpressionKinds.TypeAssertions */) !== 0;
408
+ case 326 /* SyntaxKind.PartiallyEmittedExpression */:
409
+ return (kinds & 8 /* OuterExpressionKinds.PartiallyEmittedExpressions */) !== 0;
410
+ }
411
+ return false;
412
+ }
413
+ export function skipOuterExpressions(node, kinds = 11 /* OuterExpressionKinds.All */) {
414
+ while (isOuterExpression(node, kinds)) {
415
+ node = node.expression;
416
+ }
417
+ return node;
418
+ }
419
+ function updateOuterExpression(outerExpression, expression) {
420
+ switch (outerExpression.kind) {
421
+ case 200 /* SyntaxKind.ParenthesizedExpression */: return updateParen(outerExpression, expression);
422
+ case 217 /* SyntaxKind.AsExpression */: return updateAsExpression(outerExpression, expression, outerExpression.type);
423
+ case 326 /* SyntaxKind.PartiallyEmittedExpression */: return updatePartiallyEmittedExpression(outerExpression, expression);
424
+ }
425
+ }
426
+ /**
427
+ * Determines whether a node is a parenthesized expression that can be ignored when recreating outer expressions.
428
+ *
429
+ * A parenthesized expression can be ignored when all of the following are true:
430
+ *
431
+ * - It's `pos` and `end` are not -1
432
+ * - It does not have a custom source map range
433
+ * - It does not have a custom comment range
434
+ * - It does not have synthetic leading or trailing comments
435
+ *
436
+ * If an outermost parenthesized expression is ignored, but the containing expression requires a parentheses around
437
+ * the expression to maintain precedence, a new parenthesized expression should be created automatically when
438
+ * the containing expression is created/updated.
439
+ */
440
+ function isIgnorableParen(node) {
441
+ return node.kind === 200 /* SyntaxKind.ParenthesizedExpression */
442
+ && nodeIsSynthesized(node)
443
+ && nodeIsSynthesized(getSourceMapRange(node))
444
+ && nodeIsSynthesized(getCommentRange(node))
445
+ && !some(getSyntheticLeadingComments(node))
446
+ && !some(getSyntheticTrailingComments(node));
447
+ }
448
+ export function recreateOuterExpressions(outerExpression, innerExpression, kinds = 11 /* OuterExpressionKinds.All */) {
449
+ if (outerExpression && isOuterExpression(outerExpression, kinds) && !isIgnorableParen(outerExpression)) {
450
+ return updateOuterExpression(outerExpression, recreateOuterExpressions(outerExpression.expression, innerExpression));
451
+ }
452
+ return innerExpression;
453
+ }
454
+ export function startOnNewLine(node) {
455
+ return setStartsOnNewLine(node, /*newLine*/ true);
456
+ }
457
+ /**
458
+ * Gets the initializer of an BindingOrAssignmentElement.
459
+ */
460
+ export function getInitializerOfBindingOrAssignmentElement(bindingElement) {
461
+ if (isDeclarationBindingElement(bindingElement)) {
462
+ // `1` in `let { a = 1 } = ...`
463
+ // `1` in `let { a: b = 1 } = ...`
464
+ // `1` in `let { a: {b} = 1 } = ...`
465
+ // `1` in `let { a: [b] = 1 } = ...`
466
+ // `1` in `let [a = 1] = ...`
467
+ // `1` in `let [{a} = 1] = ...`
468
+ // `1` in `let [[a] = 1] = ...`
469
+ return bindingElement.initializer;
470
+ }
471
+ if (isPropertyAssignment(bindingElement)) {
472
+ // `1` in `({ a: b = 1 } = ...)`
473
+ // `1` in `({ a: {b} = 1 } = ...)`
474
+ // `1` in `({ a: [b] = 1 } = ...)`
475
+ const initializer = bindingElement.initializer;
476
+ return isAssignmentExpression(initializer, /*excludeCompoundAssignment*/ true)
477
+ ? initializer.right
478
+ : undefined;
479
+ }
480
+ if (isShorthandPropertyAssignment(bindingElement)) {
481
+ // `1` in `({ a = 1 } = ...)`
482
+ return bindingElement.objectAssignmentInitializer;
483
+ }
484
+ if (isAssignmentExpression(bindingElement, /*excludeCompoundAssignment*/ true)) {
485
+ // `1` in `[a = 1] = ...`
486
+ // `1` in `[{a} = 1] = ...`
487
+ // `1` in `[[a] = 1] = ...`
488
+ return bindingElement.right;
489
+ }
490
+ if (isSpreadElement(bindingElement)) {
491
+ // Recovery consistent with existing emit.
492
+ return getInitializerOfBindingOrAssignmentElement(bindingElement.expression);
493
+ }
494
+ }
495
+ /**
496
+ * Gets the name of an BindingOrAssignmentElement.
497
+ */
498
+ export function getTargetOfBindingOrAssignmentElement(bindingElement) {
499
+ if (isDeclarationBindingElement(bindingElement)) {
500
+ // `a` in `let { a } = ...`
501
+ // `a` in `let { a = 1 } = ...`
502
+ // `b` in `let { a: b } = ...`
503
+ // `b` in `let { a: b = 1 } = ...`
504
+ // `a` in `let { ...a } = ...`
505
+ // `{b}` in `let { a: {b} } = ...`
506
+ // `{b}` in `let { a: {b} = 1 } = ...`
507
+ // `[b]` in `let { a: [b] } = ...`
508
+ // `[b]` in `let { a: [b] = 1 } = ...`
509
+ // `a` in `let [a] = ...`
510
+ // `a` in `let [a = 1] = ...`
511
+ // `a` in `let [...a] = ...`
512
+ // `{a}` in `let [{a}] = ...`
513
+ // `{a}` in `let [{a} = 1] = ...`
514
+ // `[a]` in `let [[a]] = ...`
515
+ // `[a]` in `let [[a] = 1] = ...`
516
+ return bindingElement.name;
517
+ }
518
+ if (isObjectLiteralElementLike(bindingElement)) {
519
+ switch (bindingElement.kind) {
520
+ case 281 /* SyntaxKind.PropertyAssignment */:
521
+ // `b` in `({ a: b } = ...)`
522
+ // `b` in `({ a: b = 1 } = ...)`
523
+ // `{b}` in `({ a: {b} } = ...)`
524
+ // `{b}` in `({ a: {b} = 1 } = ...)`
525
+ // `[b]` in `({ a: [b] } = ...)`
526
+ // `[b]` in `({ a: [b] = 1 } = ...)`
527
+ // `b.c` in `({ a: b.c } = ...)`
528
+ // `b.c` in `({ a: b.c = 1 } = ...)`
529
+ // `b[0]` in `({ a: b[0] } = ...)`
530
+ // `b[0]` in `({ a: b[0] = 1 } = ...)`
531
+ return getTargetOfBindingOrAssignmentElement(bindingElement.initializer);
532
+ case 282 /* SyntaxKind.ShorthandPropertyAssignment */:
533
+ // `a` in `({ a } = ...)`
534
+ // `a` in `({ a = 1 } = ...)`
535
+ return bindingElement.name;
536
+ case 283 /* SyntaxKind.SpreadAssignment */:
537
+ // `a` in `({ ...a } = ...)`
538
+ return getTargetOfBindingOrAssignmentElement(bindingElement.expression);
539
+ }
540
+ // no target
541
+ return undefined;
542
+ }
543
+ if (isAssignmentExpression(bindingElement, /*excludeCompoundAssignment*/ true)) {
544
+ // `a` in `[a = 1] = ...`
545
+ // `{a}` in `[{a} = 1] = ...`
546
+ // `[a]` in `[[a] = 1] = ...`
547
+ // `a.b` in `[a.b = 1] = ...`
548
+ // `a[0]` in `[a[0] = 1] = ...`
549
+ return getTargetOfBindingOrAssignmentElement(bindingElement.left);
550
+ }
551
+ if (isSpreadElement(bindingElement)) {
552
+ // `a` in `[...a] = ...`
553
+ return getTargetOfBindingOrAssignmentElement(bindingElement.expression);
554
+ }
555
+ // `a` in `[a] = ...`
556
+ // `{a}` in `[{a}] = ...`
557
+ // `[a]` in `[[a]] = ...`
558
+ // `a.b` in `[a.b] = ...`
559
+ // `a[0]` in `[a[0]] = ...`
560
+ return bindingElement;
561
+ }
562
+ export function convertToArrayAssignmentElement(element) {
563
+ if (isBindingElement(element)) {
564
+ if (element.dotDotDotToken) {
565
+ Debug.assertNode(element.name, isIdentifier);
566
+ return setOriginalNode(setTextRange(createSpread(element.name), element), element);
567
+ }
568
+ const expression = convertToAssignmentElementTarget(element.name);
569
+ return element.initializer
570
+ ? setOriginalNode(setTextRange(createAssignment(expression, element.initializer), element), element)
571
+ : expression;
572
+ }
573
+ Debug.assertNode(element, isExpression);
574
+ return element;
575
+ }
576
+ export function convertToObjectAssignmentElement(element) {
577
+ if (isBindingElement(element)) {
578
+ if (element.dotDotDotToken) {
579
+ Debug.assertNode(element.name, isIdentifier);
580
+ return setOriginalNode(setTextRange(createSpreadAssignment(element.name), element), element);
581
+ }
582
+ if (element.propertyName) {
583
+ const expression = convertToAssignmentElementTarget(element.name);
584
+ return setOriginalNode(setTextRange(createPropertyAssignment(element.propertyName, element.initializer ? createAssignment(expression, element.initializer) : expression), element), element);
585
+ }
586
+ Debug.assertNode(element.name, isIdentifier);
587
+ return setOriginalNode(setTextRange(createShorthandPropertyAssignment(element.name, element.initializer), element), element);
588
+ }
589
+ Debug.assertNode(element, isObjectLiteralElementLike);
590
+ return element;
591
+ }
592
+ export function convertToAssignmentPattern(node) {
593
+ switch (node.kind) {
594
+ case 190 /* SyntaxKind.ArrayBindingPattern */:
595
+ case 192 /* SyntaxKind.ArrayLiteralExpression */:
596
+ return convertToArrayAssignmentPattern(node);
597
+ case 189 /* SyntaxKind.ObjectBindingPattern */:
598
+ case 193 /* SyntaxKind.ObjectLiteralExpression */:
599
+ return convertToObjectAssignmentPattern(node);
600
+ }
601
+ }
602
+ export function convertToObjectAssignmentPattern(node) {
603
+ if (isObjectBindingPattern(node)) {
604
+ return setOriginalNode(setTextRange(createObjectLiteral(map(node.elements, convertToObjectAssignmentElement)), node), node);
605
+ }
606
+ Debug.assertNode(node, isObjectLiteralExpression);
607
+ return node;
608
+ }
609
+ export function convertToArrayAssignmentPattern(node) {
610
+ if (isArrayBindingPattern(node)) {
611
+ return setOriginalNode(setTextRange(createArrayLiteral(map(node.elements, convertToArrayAssignmentElement)), node), node);
612
+ }
613
+ Debug.assertNode(node, isArrayLiteralExpression);
614
+ return node;
615
+ }
616
+ export function convertToAssignmentElementTarget(node) {
617
+ if (isBindingPattern(node)) {
618
+ return convertToAssignmentPattern(node);
619
+ }
620
+ Debug.assertNode(node, isExpression);
621
+ return node;
622
+ }