mirror of https://github.com/jkjoy/sunpeiwen.git
1 line
16 KiB
Plaintext
1 line
16 KiB
Plaintext
|
{"version":3,"names":["buildLoopBody","path","declar","newBody","block","bodyPath","get","body","node","t","isBlockStatement","Object","keys","getBindingIdentifiers","some","id","scope","hasOwnBinding","blockStatement","toBlock","unshift","declare","api","options","assertVersion","assumeArray","allowArrayLike","loose","Error","test","version","iterableIsArray","assumption","arrayLikeIsIterable","skipIteratorClosing","name","visitor","ForOfStatement","left","right","await","isAwait","i","generateUidIdentifier","array","maybeGenerateMemoised","inits","variableDeclarator","numericLiteral","push","item","memberExpression","cloneNode","assignment","isVariableDeclaration","declarations","init","expressionStatement","assignmentExpression","replaceWith","forStatement","variableDeclaration","binaryExpression","identifier","updateExpression","buildForOfArray","template","buildForOfNoIteratorClosing","statements","buildForOf","builder","build","helper","getContainer","nodes","_ForOfStatementArray","generateUidIdentifierBasedOnNode","iterationKey","loop","BODY","KEY","NAME","ARR","inherits","iterationValue","state","isArrayExpression","isGenericType","isArrayTypeAnnotation","getTypeAnnotation","availableHelper","transformWithoutHelper","parent","stepKey","generateUid","stepValue","kind","CREATE_ITERATOR_HELPER","addHelper","ITERATOR_HELPER","ARRAY_LIKE_IS_ITERABLE","booleanLiteral","STEP_KEY","OBJECT","container","isLabeledStatement","labeledStatement","label","parentPath","replaceWithMultiple","skip"],"sources":["../src/index.ts"],"sourcesContent":["import { declare } from \"@babel/helper-plugin-utils\";\nimport { template, types as t } from \"@babel/core\";\nimport type { NodePath } from \"@babel/traverse\";\n\nimport transformWithoutHelper from \"./no-helper-implementation\";\n\nexport interface Options {\n allowArrayLike?: boolean;\n assumeArray?: boolean;\n loose?: boolean;\n}\n\nfunction buildLoopBody(\n path: NodePath<t.ForXStatement>,\n declar: t.Statement,\n newBody?: t.Statement | t.Expression,\n) {\n let block;\n const bodyPath = path.get(\"body\");\n const body = newBody ?? bodyPath.node;\n if (\n t.isBlockStatement(body) &&\n Object.keys(path.getBindingIdentifiers()).some(id =>\n bodyPath.scope.hasOwnBinding(id),\n )\n ) {\n block = t.blockStatement([declar, body]);\n } else {\n block = t.toBlock(body);\n block.body.unshift(declar);\n }\n return block;\n}\n\nexport default declare((api, options: Options) => {\n api.assertVersion(7);\n\n {\n const { assumeArray, allowArrayLike, loose } = options;\n\n if (loose === true && assumeArray === true) {\n throw new Error(\n `The loose and assumeArray options cannot be used together in @babel/plugin-transform-for-of`,\n );\n }\n\n if (assumeArray === true && allowArrayLike === true) {\n throw new Error(\n `The assumeArray and allowArrayLike options cannot be used together in @babel/plugin-transform-for-of`,\n );\n }\n\n // TODO: Remove in Babel 8\n if (allowArrayLike && /^7\\.\\d\\./.test(api.version)) {\n throw new Error(\n `The allowArrayLike is only supported when using @babel/core@^7.10.0`,\n );\n }\n }\n\n const iterableIsArray =\n options.assumeArray ??\n // Loose mode is not compatible with 'assumeArray', so we shouldn't read\n // 'iterableIsArray' if 'loose' is true.\n (!options.loose && api.assumption(\"iterableIsArray\"));\n\n const arrayLikeIsIterable =\n options.allowArrayLike ?? api.assumption(\"arrayLikeIsIterable\");\n\n const skipIteratorClosing =\n api.assumption(\"skipForOfIteratorClosing\") ?? options.loose;\n\n if (iterableIsArray && arrayLikeIsIterable) {\n throw new Error(\n `The \"iterableIsArray\" and \"arrayLikeIsIterable\" assumptions are not compatible.`,\n );\n }\n\n if (iterableIsArray) {\n return {\n name: \"transform-for-of\",\n\n visitor: {\n ForOfStatement(path) {\n const { scope } = path;\n const { left, right, await: isAwait } = path.node;\n if (isAwa
|