{"version":3,"names":["_getBindingIdentifiers","require","_index","_index2","_productions","_cloneNode","gatherSequenceExpressions","nodes","declars","exprs","ensureLastUndefined","node","isEmptyStatement","isExpression","push","isExpressionStatement","expression","isVariableDeclaration","kind","declar","declarations","bindings","getBindingIdentifiers","key","Object","keys","id","cloneNode","init","assignmentExpression","isIfStatement","consequent","buildUndefinedNode","alternate","conditionalExpression","test","isBlockStatement","body","indexOf","length","sequenceExpression"],"sources":["../../src/converters/gatherSequenceExpressions.ts"],"sourcesContent":["// TODO(Babel 8) Remove this file\nif (process.env.BABEL_8_BREAKING) {\n throw new Error(\n \"Internal Babel error: This file should only be loaded in Babel 7\",\n );\n}\n\nimport getBindingIdentifiers from \"../retrievers/getBindingIdentifiers.ts\";\nimport {\n isExpression,\n isExpressionStatement,\n isVariableDeclaration,\n isIfStatement,\n isBlockStatement,\n isEmptyStatement,\n} from \"../validators/generated/index.ts\";\nimport {\n sequenceExpression,\n assignmentExpression,\n conditionalExpression,\n} from \"../builders/generated/index.ts\";\nimport { buildUndefinedNode } from \"../builders/productions.ts\";\nimport cloneNode from \"../clone/cloneNode.ts\";\nimport type * as t from \"../index.ts\";\n\nexport type DeclarationInfo = {\n kind: t.VariableDeclaration[\"kind\"];\n id: t.Identifier;\n};\n\nexport default function gatherSequenceExpressions(\n nodes: ReadonlyArray,\n declars: Array,\n) {\n const exprs: t.Expression[] = [];\n let ensureLastUndefined = true;\n\n for (const node of nodes) {\n // if we encounter emptyStatement before a non-emptyStatement\n // we want to disregard that\n if (!isEmptyStatement(node)) {\n ensureLastUndefined = false;\n }\n\n if (isExpression(node)) {\n exprs.push(node);\n } else if (isExpressionStatement(node)) {\n exprs.push(node.expression);\n } else if (isVariableDeclaration(node)) {\n if (node.kind !== \"var\") return; // bailed\n\n for (const declar of node.declarations) {\n const bindings = getBindingIdentifiers(declar);\n for (const key of Object.keys(bindings)) {\n declars.push({\n kind: node.kind,\n id: cloneNode(bindings[key]),\n });\n }\n\n if (declar.init) {\n exprs.push(assignmentExpression(\"=\", declar.id, declar.init));\n }\n }\n\n ensureLastUndefined = true;\n } else if (isIfStatement(node)) {\n const consequent = node.consequent\n ? gatherSequenceExpressions([node.consequent], declars)\n : buildUndefinedNode();\n const alternate = node.alternate\n ? gatherSequenceExpressions([node.alternate], declars)\n : buildUndefinedNode();\n if (!consequent || !alternate) return; // bailed\n\n exprs.push(conditionalExpression(node.test, consequent, alternate));\n } else if (isBlockStatement(node)) {\n const body = gatherSequenceExpressions(node.body, declars);\n if (!body) return; // bailed\n\n exprs.push(body);\n } else if (isEmptyStatement(node)) {\n // empty statement so ensure the last item is undefined if we're last\n // checks if emptyStatement is first\n if (nodes.indexOf(node) === 0) {\n ensureLastUndefined = true;\n }\n } else {\n // bailed, we can't turn this statement into an expression\n return;\n }\n }\n\n if (ensureLastUndefined) {\n exprs.push(buildUndefinedNode());\n }\n\n if (exprs.length === 1) {\n return exprs[0];\n } else {\n return sequenceExpression(exprs);\n }\n}\n"],"mappings":";;;;;;AAOA,IAAAA,sBAAA,GAAAC,OAAA;AACA,IAAAC,MAAA,GAAAD,OAAA;AAQA,IAAAE,OAAA,GAAAF,OAAA;AAKA,IAAAG,YAAA,GAAAH,OAAA;AACA,IAAAI,UAAA,GAAAJ,OAAA;AAA8C;AAQ/B,SAASK,yBAAyBA,CAC/CC,KAA4B,EAC5BC,OAA+B,EAC/B;EACA,MAAMC,KAAqB,GAAG,EAAE;EAChC,IAAIC,mBAAmB,GAAG,IAAI;EAE9B,KAAK,MAAMC,IAAI,IAAIJ,KAAK,EAAE;IAGxB,IAAI,CAAC,IAAAK,uBAAgB,EAACD,IAAI,CAAC,EAAE;MAC3BD,mBAAmB,GAAG,KAAK;IAC7B;IAEA,IAAI,IAAAG,mBAAY,EAACF,IAAI,CAAC,EAAE;MACtBF,KAAK,CAACK,IAAI,CAACH,IAAI,CAAC;IAClB,CAAC,MAAM,IAAI,IAAAI,4BAAqB,EAACJ,IAAI,CAAC,EAAE;MACtCF,KAAK,CAACK,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