You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
1 line
11 KiB
1 line
11 KiB
1 month ago
|
{"version":3,"names":["_core","require","transformWithoutHelper","loose","path","state","pushComputedProps","pushComputedPropsLoose","pushComputedPropsSpec","node","build","declar","loop","block","body","ensureBlock","push","t","inherits","replaceParent","parentPath","replaceWithMultiple","remove","buildForOfLoose","template","statement","buildForOf","statements","scope","parent","left","id","intermediate","isIdentifier","isPattern","isMemberExpression","isVariableDeclaration","generateUidIdentifier","variableDeclaration","kind","variableDeclarator","declarations","identifier","name","buildCodeFrameError","type","iteratorKey","isArrayKey","LOOP_OBJECT","IS_ARRAY","OBJECT","right","INDEX","ID","INTERMEDIATE","isLabeledParent","isLabeledStatement","labeled","labeledStatement","label","stepKey","generateUid","stepValue","memberExpression","expressionStatement","assignmentExpression","ITERATOR_HAD_ERROR_KEY","ITERATOR_COMPLETION","ITERATOR_ERROR_KEY","ITERATOR_KEY","STEP_KEY","tryBody"],"sources":["../src/no-helper-implementation.ts"],"sourcesContent":["import { template, types as t } from \"@babel/core\";\nimport type { PluginPass, NodePath } from \"@babel/core\";\n\n// This is the legacy implementation, which inlines all the code.\n// It must be kept for compatibility reasons.\n// TODO(Babel 8): Remove this file.\n\nexport default function transformWithoutHelper(\n loose: boolean | void,\n path: NodePath<t.ForOfStatement>,\n state: PluginPass,\n) {\n const pushComputedProps = loose\n ? pushComputedPropsLoose\n : pushComputedPropsSpec;\n\n const { node } = path;\n const build = pushComputedProps(path, state);\n const declar = build.declar;\n const loop = build.loop;\n const block = loop.body as t.BlockStatement;\n\n // ensure that it's a block so we can take all its statements\n path.ensureBlock();\n\n // add the value declaration to the new loop body\n if (declar) {\n block.body.push(declar);\n }\n\n // push the rest of the original loop body onto our new body\n block.body.push(...(node.body as t.BlockStatement).body);\n\n t.inherits(loop, node);\n t.inherits(loop.body, node.body);\n\n if (build.replaceParent) {\n path.parentPath.replaceWithMultiple(build.node);\n path.remove();\n } else {\n path.replaceWithMultiple(build.node);\n }\n}\n\nconst buildForOfLoose = template.statement(`\n for (var LOOP_OBJECT = OBJECT,\n IS_ARRAY = Array.isArray(LOOP_OBJECT),\n INDEX = 0,\n LOOP_OBJECT = IS_ARRAY ? LOOP_OBJECT : LOOP_OBJECT[Symbol.iterator]();;) {\n INTERMEDIATE;\n if (IS_ARRAY) {\n if (INDEX >= LOOP_OBJECT.length) break;\n ID = LOOP_OBJECT[INDEX++];\n } else {\n INDEX = LOOP_OBJECT.next();\n if (INDEX.done) break;\n ID = INDEX.value;\n }\n }\n`);\n\nconst buildForOf = template.statements(`\n var ITERATOR_COMPLETION = true;\n var ITERATOR_HAD_ERROR_KEY = false;\n var ITERATOR_ERROR_KEY = undefined;\n try {\n for (\n var ITERATOR_KEY = OBJECT[Symbol.iterator](), STEP_KEY;\n !(ITERATOR_COMPLETION = (STEP_KEY = ITERATOR_KEY.next()).done);\n ITERATOR_COMPLETION = true\n ) {}\n } catch (err) {\n ITERATOR_HAD_ERROR_KEY = true;\n ITERATOR_ERROR_KEY = err;\n } finally {\n try {\n if (!ITERATOR_COMPLETION && ITERATOR_KEY.return != null) {\n ITERATOR_KEY.return();\n }\n } finally {\n if (ITERATOR_HAD_ERROR_KEY) {\n throw ITERATOR_ERROR_KEY;\n }\n }\n }\n`);\n\nfunction pushComputedPropsLoose(\n path: NodePath<t.ForOfStatement>,\n state: PluginPass,\n) {\n const { node, scope, parent } = path;\n const { left } = node;\n let declar, id, intermediate;\n\n if (t.isIdentifier(left) || t.isPattern(left) || t.isMemberExpression(left)) {\n // for (i of test), for ({ i } of test)\n id = left;\n intermediate = null;\n } else if (t.isVariableDeclaration(left)) {\n // for (let i of test)\n id = scope.generateUidIdentifier(\"ref\");\n declar = t.variableDeclaration(left.kind, [\n t.variableDeclarator(left.declarations[0].id, t.identifier(id
|