How to use the cloneDeep function from @babel/types
Find comprehensive JavaScript @babel/types.cloneDeep code examples handpicked from public code repositorys.
37 38 39 40 41 42 43 44 45 46 47
/** * As above, but using the "extra" variant, which will reduce printing * after too many calls to prevent I/O flooding. */ function prettyPrintExtraStatement(variable) { return prettyPrintExtra({ ID: babelTypes.cloneDeep(variable) }); } /** * Mutator for suppressing known and/or unfixable issues.
46
35
0
+ 3 other calls in file
70 71 72 73 74 75 76 77 78
it('is not copying added state', () => { const source = helpers.loadTestData('mutate_expressions.js'); common.setSourceLoc(source, 5, 10); const noopNode = source.ast.program.body[0]; assert.equal(0.5, common.getSourceLoc(noopNode)); const cloned = babelTypes.cloneDeep(noopNode); assert.equal(undefined, common.getSourceLoc(cloned)); }); });
35
92
30
+ 23 other calls in file
519 520 521 522 523 524 525 526 527 528
// there will be duplicates so lets help ourselves out by // by just renaming the inner helper to an unique name // and then changing all its references to the new name because we // are hoisting this helper to our global scope const name = vdPath.node.declarations[0].id.name const vd = btypes.cloneDeep(vdPath.node) const declar = vd.declarations[0] const id = path.scope.generateUidIdentifierBasedOnNode(declar) declar.id = id vdPath.parentPath.scope.rename(name, id.name)
0
15
1
135 136 137 138 139 140 141 142 143 144
t.stringLiteral('o') ] element.properties.forEach(property => { objectExprElements.push(t.arrayExpression([ t.stringLiteral(property.key.name || property.key.value), t.cloneDeep(property.value) ])) }) element = t.arrayExpression(objectExprElements) }
0
1
1
+ 7 other calls in file
GitHub: iammadanlal/next-blog
340 341 342 343 344 345 346 347 348 349 350 351 352
if (Array.isArray(css)) { return t.arrayExpression(css); } return t.cloneDeep(css); }; exports.cssToBabelType = cssToBabelType;
0
1
0
66 67 68 69 70 71 72 73 74 75
const nodes = [ prepareTemplate({ ID: babelTypes.cloneDeep(path.node.callee), }).expression, babelTypes.cloneDeep(path.node), babelTypes.cloneDeep(path.node), optimizeTemplate({ ID: babelTypes.cloneDeep(path.node.callee), }).expression,
0
0
0
+ 11 other calls in file
28 29 30 31 32 33 34 35 36 37
} const probability = random.random(); if (probability < 0.7) { const repeated = babelTypes.cloneDeep(path.node); thisMutator.annotate(repeated, 'Repeated'); thisMutator.insertBeforeSkip(path, repeated); } else if (path.key > 0) { // Get a random previous sibling.
0
0
0
+ 3 other calls in file
87 88 89 90 91 92 93 94 95 96
const [a, b] = random.shuffle(getTwoRandomProperties()); if (common.isLargeNode(b.value)) { return; } annotate('Duplicate a property value'); a.value = babelTypes.cloneDeep(b.value); } } function insertRandomValue() {
0
0
0
+ 2 other calls in file
54 55 56 57 58 59 60 61 62 63
const element = random.single(elements); if (!element || common.isLargeNode(element)) { return; } annotate('Duplicate an element', replace); randomSplice(replace, babelTypes.cloneDeep(element)); } function insertRandomValue(replace) { annotate('Insert a random value', replace);
0
0
0
GitHub: dcloudio/uni-app
175 176 177 178 179 180 181 182 183 184
} function processMemberExpression (element, state) { // item['order']=>item.order if (t.isMemberExpression(element)) { element = t.cloneDeep(element) if (t.isStringLiteral(element.property)) { element.computed = false } // item[itemIndex[0]] = item[__$0__]
0
0
506
@babel/types.identifier is the most popular function in @babel/types (20936 examples)