How to use the types function from @babel/core
Find comprehensive JavaScript @babel/core.types code examples handpicked from public code repositorys.
93 94 95 96 97 98 99 100 101 102
node.arguments[2].properties[1].value.body.type === 'BlockStatement' && node.arguments[2].properties[1].value.body.body.length === 1 && node.arguments[2].properties[1].value.body.body[0].type === 'ReturnStatement' && node.arguments[2].properties[1].value.body.body[0].argument.type === 'MemberExpression' ) { const newNode = babel.types.assignmentExpression( '=', babel.types.memberExpression( node.arguments[0], babel.types.Identifier(node.arguments[1].value),
21
227
6
+ 13 other calls in file
379 380 381 382 383 384 385 386 387 388
MODULE_NAME: moduleName, SETTERS: _core.types.arrayExpression(setters), EXECUTE: _core.types.functionExpression(null, [], _core.types.blockStatement(path.node.body), false, hasTLA), SOURCES: _core.types.arrayExpression(sources), EXPORT_IDENTIFIER: _core.types.identifier(exportIdent), CONTEXT_IDENTIFIER: _core.types.identifier(contextIdent) })]; } } }
3
26
2
+ 30 other calls in file
61 62 63 64 65 66 67 68 69 70
const statements = [] if (!exportStarTarget) { if (exportNames.length === 1) { statements.push( _core.types.expressionStatement( _core.types.callExpression(exportIdent, [ _core.types.stringLiteral(exportNames[0]), exportValues[0], ]), ),
3
26
2
+ 84 other calls in file
42 43 44 45 46 47 48 49 50 51
var nullable_1 = require("../../helpers/nullable"); var create_mitosis_node_1 = require("../../helpers/create-mitosis-node"); var function_1 = require("fp-ts/lib/function"); var helpers_1 = require("./helpers"); var bindings_1 = require("../../helpers/bindings"); var types = babel.types; var getForArguments = function (params) { var _a = params .filter(function (param) { return types.isIdentifier(param); }) .map(function (param) { return param.name; })
1
4
4
28 29 30 31 32 33 34 35 36 37
node, parent } = path; if (node.operator !== "typeof") return; if (path.parentPath.isBinaryExpression() && _core.types.EQUALITY_BINARY_OPERATORS.indexOf(parent.operator) >= 0) { const opposite = path.getOpposite(); if (opposite.isLiteral() && opposite.node.value !== "symbol" && opposite.node.value !== "object") { return;
0
2
1
+ 3 other calls in file
18 19 20 21 22 23 24 25 26 27
if (mutableTemplateObject) helperName += "Loose"; function buildConcatCallExpressions(items) { let avail = true; return items.reduce(function (left, right) { let canBeInserted = _core.types.isLiteral(right); if (!canBeInserted && avail) { canBeInserted = true; avail = false;
0
2
1
+ 6 other calls in file
20 21 22 23 24 25 26 27 28 29 30 31
return hasOwnDecorators(node) || node.body.body.some(hasOwnDecorators); } function prop(key, value) { if (!value) return null; return _core.types.objectProperty(_core.types.identifier(key), value); } function method(key, body) { return _core.types.objectMethod("method", _core.types.identifier(key), [], _core.types.blockStatement(body));
0
2
1
+ 11 other calls in file
123 124 125 126 127 128 129 130 131 132
const right = param.get("right"); const undefinedNode = scope.buildUndefinedNode(); if (left.isIdentifier()) { body.push(buildLooseDefaultParam({ ASSIGNMENT_IDENTIFIER: _core.types.cloneNode(left.node), DEFAULT_VALUE: right.node, UNDEFINED: undefinedNode })); param.replaceWith(left.node);
0
2
1
+ 6 other calls in file
172 173 174 175 176 177 178 179 180 181
{ console.warn(MISSING_PLUGIN_WARNING); } } path.replaceWith(_core.types.callExpression(_core.types.memberExpression(_core.types.identifier(state.contextIdent), _core.types.identifier("import")), [(0, _utils.getImportSource)(_core.types, path.node)])); } }, MetaProperty(path, state) {
0
2
0
+ 29 other calls in file
373 374 375 376 377 378 379 380 381
} const newId = generateClassPrivateUid(); const newFieldInitId = element.scope.parent.generateDeclaredUidIdentifier(`init_${name}`); const newValue = _core.types.callExpression(_core.types.cloneNode(newFieldInitId), params); const newField = generateClassProperty(newId, newValue, isStatic); const [newPath] = element.replaceWith(newField);
0
1
1
+ 41 other calls in file
8 9 10 11 12 13 14 15 16 17 18
/** * @param {babel.NodePath<babel.types.CallExpression>} path * @returns {null | { * type: typeof STANDARD_COMPONENT | typeof FUNCTIONAL_COMPONENT, * node: undefined | babel.types.Expression * }} */ module.exports = function parseComponent(path) { if (!t.isMemberExpression(path.parentPath.node)) {
0
1
1
+ 5 other calls in file
8 9 10 11 12 13 14 15 16 17 18 19 20
const helperIDs = new WeakMap(); function addCreateSuperHelper(file) { if (helperIDs.has(file)) { return (_core.types.cloneNode || _core.types.clone)(helperIDs.get(file)); } try { return file.addHelper("createSuper");
0
1
1
+ 5 other calls in file
74 75 76 77 78 79 80 81 82
objectRef: classRef, superRef, file, refToPreserve: classRef }).replace(); const properties = [prop("kind", _core.types.stringLiteral(_core.types.isClassMethod(node) ? node.kind : "field")), prop("decorators", takeDecorators(node)), prop("static", node.static && _core.types.booleanLiteral(true)), prop("key", getKey(node))].filter(Boolean); if (_core.types.isClassMethod(node)) { const id = node.computed ? null : node.key;
0
1
1
+ 35 other calls in file
GitHub: Shkabarnia/As-is_network
186 187 188 189 190 191 192 193 194 195
if (instanceNodes.length > 0) { (0, _misc.injectInitialization)(path, constructor, instanceNodes, (referenceVisitor, state) => { if (isDecorated) return; for (const prop of props) { if (_core.types.isStaticBlock != null && _core.types.isStaticBlock(prop.node) || prop.node.static) continue; prop.traverse(referenceVisitor, state); } }); }
0
0
1
+ 7 other calls in file
62 63 64 65 66 67 68 69 70 71
getId, setId } = value; const isAccessor = getId || setId; const id = _core.types.cloneNode(value.id); let init; if (privateFieldsAsProperties) {
0
0
1
+ 127 other calls in file
GitHub: ra265/node
34 35 36 37 38 39 40 41 42 43
let ref; let assignment; if (scope.isStatic(node.left)) { ref = node.left; assignment = _core.types.cloneNode(node.left); } else if (scope.path.isPattern()) { path.replaceWith(_core.template.statement.ast`(() => ${path.node})()`); return; } else {
0
0
1
+ 3 other calls in file
GitHub: ra265/node
64 65 66 67 68 69 70 71 72 73
if (globalName) { initAssignments = []; const members = globalName.split("."); globalToAssign = members.slice(1).reduce((accum, curr) => { initAssignments.push(buildPrerequisiteAssignment({ GLOBAL_REFERENCE: _core.types.cloneNode(accum) })); return _core.types.memberExpression(accum, _core.types.identifier(curr)); }, _core.types.memberExpression(_core.types.identifier("global"), _core.types.identifier(members[0]))); }
0
0
1
+ 12 other calls in file
GitHub: fitrianihamenda/fitri22
52 53 54 55 56 57 58 59 60 61
if (_core.types.isMethod(node)) { path.replaceWith(scope.buildUndefinedNode()); return; } const constructor = _core.types.memberExpression(_core.types.thisExpression(), _core.types.identifier("constructor")); if (func.isClass()) { path.replaceWith(constructor); return;
0
0
1
83 84 85 86 87 88 89 90 91 92
const properties = [prop("kind", _core.types.stringLiteral(_core.types.isClassMethod(node) ? node.kind : "field")), prop("decorators", takeDecorators(node)), prop("static", node.static && _core.types.booleanLiteral(true)), prop("key", getKey(node))].filter(Boolean); if (_core.types.isClassMethod(node)) { const id = node.computed ? null : node.key; const transformed = _core.types.toExpression(node); properties.push(prop("value", (0, _helperFunctionName.default)({ node: transformed, id,
0
0
1
+ 11 other calls in file
@babel/core.types is the most popular function in @babel/core (2111 examples)