|
6 | 6 | IterableExtensionKind,
|
7 | 7 | } from "../../utils/language-extensions";
|
8 | 8 | import { TransformationContext } from "../../context";
|
9 |
| -import { findFirstNodeAbove } from "../../utils/typescript"; |
| 9 | +import { findFirstNodeAbove, findFirstNonOuterParent } from "../../utils/typescript"; |
10 | 10 |
|
11 | 11 | const multiReturnExtensionName = "__tstlMultiReturn";
|
12 | 12 | export function isMultiReturnType(type: ts.Type): boolean {
|
@@ -58,46 +58,48 @@ export function shouldMultiReturnCallBeWrapped(context: TransformationContext, n
|
58 | 58 | return false;
|
59 | 59 | }
|
60 | 60 |
|
| 61 | + const parent = findFirstNonOuterParent(node); |
| 62 | + |
61 | 63 | // Variable declaration with destructuring
|
62 |
| - if (ts.isVariableDeclaration(node.parent) && ts.isArrayBindingPattern(node.parent.name)) { |
| 64 | + if (ts.isVariableDeclaration(parent) && ts.isArrayBindingPattern(parent.name)) { |
63 | 65 | return false;
|
64 | 66 | }
|
65 | 67 |
|
66 | 68 | // Variable assignment with destructuring
|
67 | 69 | if (
|
68 |
| - ts.isBinaryExpression(node.parent) && |
69 |
| - node.parent.operatorToken.kind === ts.SyntaxKind.EqualsToken && |
70 |
| - ts.isArrayLiteralExpression(node.parent.left) |
| 70 | + ts.isBinaryExpression(parent) && |
| 71 | + parent.operatorToken.kind === ts.SyntaxKind.EqualsToken && |
| 72 | + ts.isArrayLiteralExpression(parent.left) |
71 | 73 | ) {
|
72 | 74 | return false;
|
73 | 75 | }
|
74 | 76 |
|
75 | 77 | // Spread operator
|
76 |
| - if (ts.isSpreadElement(node.parent)) { |
| 78 | + if (ts.isSpreadElement(parent)) { |
77 | 79 | return false;
|
78 | 80 | }
|
79 | 81 |
|
80 | 82 | // Stand-alone expression
|
81 |
| - if (ts.isExpressionStatement(node.parent)) { |
| 83 | + if (ts.isExpressionStatement(parent)) { |
82 | 84 | return false;
|
83 | 85 | }
|
84 | 86 |
|
85 | 87 | // Forwarded multi-return call
|
86 | 88 | if (
|
87 |
| - (ts.isReturnStatement(node.parent) || ts.isArrowFunction(node.parent)) && // Body-less arrow func |
| 89 | + (ts.isReturnStatement(parent) || ts.isArrowFunction(parent)) && // Body-less arrow func |
88 | 90 | isInMultiReturnFunction(context, node)
|
89 | 91 | ) {
|
90 | 92 | return false;
|
91 | 93 | }
|
92 | 94 |
|
93 | 95 | // Element access expression 'foo()[0]' will be optimized using 'select'
|
94 |
| - if (ts.isElementAccessExpression(node.parent)) { |
| 96 | + if (ts.isElementAccessExpression(parent)) { |
95 | 97 | return false;
|
96 | 98 | }
|
97 | 99 |
|
98 | 100 | // LuaIterable in for...of
|
99 | 101 | if (
|
100 |
| - ts.isForOfStatement(node.parent) && |
| 102 | + ts.isForOfStatement(parent) && |
101 | 103 | getIterableExtensionKindForNode(context, node) === IterableExtensionKind.Iterable
|
102 | 104 | ) {
|
103 | 105 | return false;
|
|
0 commit comments