How to use the cloneNode function from @babel/types
Find comprehensive JavaScript @babel/types.cloneNode code examples handpicked from public code repositorys.
29 30 31 32 33 34 35 36 37 38
}) break case 'CallExpression': references.forEach(reference => { const reference_node = reference.parentPath.node const replacement = t.cloneNode(body[0].argument) replacement.callee.object = reference_node.arguments[0] replacement.arguments = [reference_node.arguments[1]] reference.parentPath.replaceWith(replacement) })
5
19
2
+ 3 other calls in file
161 162 163 164 165 166 167 168 169 170
// TODO: decode switch statements inside for loops as they go in code const firstFunct2 = types.cloneNode(AST.program.body[0].expression.callee.body.body[1]); const secFunct2 = types.cloneNode(AST.program.body[0].expression.callee.body.body[3]); const evalScript = generate(firstFunct2).code + generate(secFunct2).code + generate(declarObj).code const context2 = {}; vm.runInNewContext(evalScript, context2);
2
0
0
+ 79 other calls in file
5 6 7 8 9 10 11 12 13 14 15 16 17
exports.default = populatePlaceholders; var t = require("@babel/types"); function populatePlaceholders(metadata, replacements) { const ast = t.cloneNode(metadata.ast); if (replacements) { metadata.placeholders.forEach(placeholder => { if (!Object.prototype.hasOwnProperty.call(replacements, placeholder.name)) {
0
1
1
+ 209 other calls in file
200 201 202 203 204 205 206 207 208 209
}); for (const path of imps) path.remove(); for (const path of impsBindingRefs) { const node = t.cloneNode(dependenciesRefs[path.node.name]); path.replaceWith(node); } path.stop();
0
1
1
+ 48 other calls in file
152 153 154 155 156 157 158 159 160 161
for (const localName of sourceMetadata.importsNamespace) { if (localName === sourceMetadata.name) continue; statements.push(_template.default.statement`var NAME = SOURCE;`({ NAME: localName, SOURCE: t.cloneNode(srcNamespace) })); } if (constantReexports) {
0
1
1
+ 87 other calls in file
339 340 341 342 343 344 345 346 347 348
generateDeclaredUidIdentifier(name) { const id = this.generateUidIdentifier(name); this.push({ id }); return t.cloneNode(id); } generateUidIdentifier(name) { return t.identifier(this.generateUid(name));
0
1
1
+ 33 other calls in file
136 137 138 139 140 141 142 143 144 145
if (t.isIdentifier(id) && !localBinding) { const binding = scope.parent.getBinding(id.name); if (binding && binding.constant && scope.getBinding(id.name) === binding) { node.id = t.cloneNode(id); node.id[t.NOT_LOCAL_BINDING] = true; return; } }
0
1
1
+ 8 other calls in file
18 19 20 21 22 23 24 25 26 27 28 29
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; } function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function getPrototypeOfExpression(objectRef, isStatic, file, isPrivateMethod) { objectRef = t.cloneNode(objectRef); const targetRef = isStatic || isPrivateMethod ? objectRef : t.memberExpression(objectRef, t.identifier("prototype")); return t.callExpression(file.addHelper("getPrototypeOf"), [targetRef]); }
0
1
0
+ 9 other calls in file
171 172 173 174 175 176 177 178 179
NAMESPACE: t.cloneNode(srcNamespace) })); } if (sourceMetadata.reexportAll) { const statement = buildNamespaceReexport(metadata, t.cloneNode(srcNamespace), loose); statement.loc = sourceMetadata.reexportAll.loc; statements.push(statement); }
0
0
1
+ 2 other calls in file
GitHub: john024x/TiendaAvocado
196 197 198 199 200 201 202 203 204 205
const namespace = metadata.lazy ? t.callExpression(t.identifier(metadata.name), []) : t.identifier(metadata.name); const templateForCurrentMode = getTemplateForReexport(loose); return Array.from(metadata.reexports, ([exportName, importName]) => templateForCurrentMode({ EXPORTS: meta.exportName, EXPORT_NAME: exportName, NAMESPACE: t.cloneNode(namespace), IMPORT_NAME: importName })); };
0
0
1
+ 43 other calls in file
GitHub: dcloudio/uni-app
432 433 434 435 436 437 438 439 440 441
let vIfNode let vForNode // TODO v-else if (t.isConditionalExpression(slotNode)) { // vIfCode = genCode(slotNode.test) vIfNode = t.cloneNode(slotNode, true) slotNode = slotNode.consequent } if (t.isCallExpression(slotNode)) { vForNode = t.cloneNode(slotNode, true)
0
0
502
+ 277 other calls in file
GitHub: duanemcguire/mcpiano
260 261 262 263 264 265 266 267 268 269
const ref = scope.generateUidIdentifierBasedOnNode(node); scope.push({ id: ref }); value.left = t.assignmentExpression("=", t.cloneNode(ref), value.left); parentPath.replaceWith(t.sequenceExpression([this.set(member, value), t.cloneNode(ref)])); } return; }
0
0
1
+ 34 other calls in file
83 84 85 86 87 88 89 90 91 92 93
STATE_NAME: dummyVar }); }; var _nestedUpdateExpTemplate = function _nestedUpdateExpTemplate(dummyVar, nestNode, higerStateName, trueVar, LONA, path) { var leftNodeOfNextAssignment = types.cloneNode(LONA); var isLeftMemberExp = types.isMemberExpression(trueVar); var isNextLeftMemberExp = types.isMemberExpression(leftNodeOfNextAssignment); var nextAssignLeft = leftNodeOfNextAssignment.name || getMemberExpStateName(leftNodeOfNextAssignment); var leftExpClone = types.cloneNode(trueVar);
0
0
1
+ 12 other calls in file
GitHub: OsmePhe/zeeat
112 113 114 115 116 117 118 119 120 121
})) { scope = scope.parent; } const temp = scope.generateDeclaredUidIdentifier(); nodes.unshift(t.expressionStatement(t.assignmentExpression("=", t.cloneNode(temp), this.node))); nodes.push(t.expressionStatement(t.cloneNode(temp))); } return this.replaceExpressionWithStatements(nodes);
0
0
0
212 213 214 215 216 217 218 219 220 221
loop.setData("expressionReplacementReturnUid", uid); } else { uid = t.identifier(uid.name); } path.get("expression").replaceWith(t.assignmentExpression("=", t.cloneNode(uid), path.node.expression)); } else { path.replaceWith(t.returnStatement(path.node.expression)); } }
0
0
0
@babel/types.identifier is the most popular function in @babel/types (20936 examples)