1 line
23 KiB
Text
1 line
23 KiB
Text
|
{"version":3,"names":["_codeFrame","require","_index","_index2","_cache","_parser","_t","_helperHoistVariables","FUNCTION_TYPES","arrowFunctionExpression","assignmentExpression","awaitExpression","blockStatement","buildUndefinedNode","callExpression","cloneNode","conditionalExpression","expressionStatement","getBindingIdentifiers","identifier","inheritLeadingComments","inheritTrailingComments","inheritsComments","isBlockStatement","isEmptyStatement","isExpression","isExpressionStatement","isIfStatement","isProgram","isStatement","isVariableDeclaration","removeComments","returnStatement","sequenceExpression","validate","yieldExpression","replaceWithMultiple","nodes","_getCachedPaths","resync","_verifyNodeList","node","length","getCachedPaths","hub","parent","delete","container","key","paths","insertAfter","requeue","remove","replaceWithSourceString","replacement","ast","parse","err","loc","message","codeFrameColumns","start","line","column","code","expressionAST","program","body","expression","traverse","removeProperties","replaceWith","replacementPath","removed","Error","NodePath","Array","isArray","nodePath","isNodeType","canHaveVariableDeclarationOrExpression","canSwapBetweenExpressionAndStatement","parentPath","isExportDefaultDeclaration","replaceExpressionWithStatements","oldNode","_replaceWith","type","setScope","get","_getCachedPaths2","ReferenceError","inList","debug","set","declars","nodesAsSingleExpression","gatherSequenceExpressions","id","scope","push","functionParent","getFunctionParent","isParentAsync","is","isParentGenerator","callee","hoistVariables","completionRecords","getCompletionRecords","path","loop","findParent","isLoop","uid","getData","generateDeclaredUidIdentifier","pushContainer","setData","name","arrowFunctionToExpression","newCallee","needToAwaitFunction","hasType","needToYieldFunction","exprs","ensureLastUndefined","kind","declar","declarations","bindings","Object","keys","init","consequent","alternate","test","indexOf","replaceInline","_containerInsertAfter"],"sources":["../../src/path/replacement.ts"],"sourcesContent":["// This file contains methods responsible for replacing a node with another.\n\nimport { codeFrameColumns } from \"@babel/code-frame\";\nimport traverse from \"../index.ts\";\nimport NodePath from \"./index.ts\";\nimport { getCachedPaths } from \"../cache.ts\";\nimport { parse } from \"@babel/parser\";\nimport {\n FUNCTION_TYPES,\n arrowFunctionExpression,\n assignmentExpression,\n awaitExpression,\n blockStatement,\n buildUndefinedNode,\n callExpression,\n cloneNode,\n conditionalExpression,\n expressionStatement,\n getBindingIdentifiers,\n identifier,\n inheritLeadingComments,\n inheritTrailingComments,\n inheritsComments,\n isBlockStatement,\n isEmptyStatement,\n isExpression,\n isExpressionStatement,\n isIfStatement,\n isProgram,\n isStatement,\n isVariableDeclaration,\n removeComments,\n returnStatement,\n sequenceExpression,\n validate,\n yieldExpression,\n} from \"@babel/types\";\nimport type * as t from \"@babel/types\";\nimport hoistVariables from \"@babel/helper-hoist-variables\";\n\n/**\n * Replace a node with an array of multiple. This method performs the following steps:\n *\n * - Inherit the comments of first provided node with that of the current node.\n * - Insert the provided nodes after the current node.\n * - Remove the current node.\n */\n\nexport function replaceWithMultiple(\n this: NodePath,\n nodes: t.Node | t.Node[],\n): NodePath[] {\n this.resync();\n\n nodes = this._verifyNodeList(nodes);\n inheritLeadingComments(nodes[0], this.node);\n inheritTrailingComments(nodes[nodes.length - 1], this.node);\n getCachedPaths(this.hub, this.parent)?.delete(this.node);\n this.node =\n // @ts-expect-error this.key must present in this.container\n this.container[this.key] = null;\n const paths = this.insertAfter(nodes);\n\n if (this.node) {\n this.requeue();\n } else {\n this.remove();\n }\n return paths;\n}\n\n/**\n * Parse a string as an expression and replace the current node with the result.\n *\n * NOTE
|