| 1 |
import gatherSequenceExpressions from "./gatherSequenceExpressions"; |
| 2 |
import type * as t from ".."; |
| 3 |
import type { DeclarationInfo } from "./gatherSequenceExpressions"; |
| 4 |
|
| 5 |
/** |
| 6 |
* Turn an array of statement `nodes` into a `SequenceExpression`. |
| 7 |
* |
| 8 |
* Variable declarations are turned into simple assignments and their |
| 9 |
* declarations hoisted to the top of the current scope. |
| 10 |
* |
| 11 |
* Expression statements are just resolved to their expression. |
| 12 |
*/ |
| 13 |
export default function toSequenceExpression( |
| 14 |
nodes: ReadonlyArray<t.Node>, |
| 15 |
scope: any, |
| 16 |
): t.SequenceExpression | undefined { |
| 17 |
if (!nodes?.length) return; |
| 18 |
|
| 19 |
const declars: DeclarationInfo[] = []; |
| 20 |
const result = gatherSequenceExpressions(nodes, scope, declars); |
| 21 |
if (!result) return; |
| 22 |
|
| 23 |
for (const declar of declars) { |
| 24 |
scope.push(declar); |
| 25 |
} |
| 26 |
|
| 27 |
// @ts-expect-error fixme: gatherSequenceExpressions will return an Expression when there are only one element |
| 28 |
return result; |
| 29 |
} |