How to use the unaryExpression function from @babel/types
Find comprehensive JavaScript @babel/types.unaryExpression code examples handpicked from public code repositorys.
GitHub: raxjs/miniapp
![raxjs profile picture](/raxjs.png?size=40)
112 113 114 115 116 117 118 119 120 121
throw new CodeError(code, path.node, path.node.loc, 'Logical operator only support && or ||'); } } else if (rightIsJSX || hasJSX(rightPath)) { let test; if (operator === '||') { test = t.unaryExpression('!', left); } else if (operator === '&&') { test = left; } else { throw new CodeError(code, path.node, path.node.loc, 'Logical operator only support && or ||');
+ 11 other calls in file
GitHub: egoist/styled-vue
![egoist profile picture](/egoist.png?size=40)
92 93 94 95 96 97 98 99 100 101
: mustNotBeFunction ? getValue(false) : t.conditionalExpression( t.binaryExpression( '===', t.unaryExpression('typeof', id), t.stringLiteral('function') ), getValue(true), getValue(false)
+ 15 other calls in file
321 322 323 324 325 326 327 328 329 330
} else if (operator === "||") { //TODO:好像不需要转换!!!!! // 转换前: "" == str || /\d/.test(num) || global.log(); // 转换后: if(!("" == str || /\d/.test(num))) global.log(); // 判断条件需取反 // var unaryExpression = t.unaryExpression("!", exp.left) // var alternateBlockStatement = t.blockStatement([t.expressionStatement(exp.right)], []) // var ifStatement = t.ifStatement(unaryExpression, alternateBlockStatement) // try { // path.replaceWith(ifStatement)
72 73 74 75 76 77 78 79 80 81
//let let dispenser = t.variableDeclaration('let', [varArray, varIndex]); //拼装switch (+_array[_index++]) let uptExp = t.updateExpression('++', index); let memExp = t.memberExpression(array, uptExp, true); let discriminant = t.unaryExpression('+', memExp); let switchSta = t.switchStatement(discriminant, cases); //拼装while (!![]) let unaExp = t.unaryExpression('!', t.arrayExpression()); unaExp = t.unaryExpression('!', unaExp);
+ 11 other calls in file
GitHub: N0taN3rd/Emu
![N0taN3rd profile picture](/N0taN3rd.png?size=40)
114 115 116 117 118 119 120 121 122 123
static ifTypeOfXEqWhat (prop, body, type) { return btypes.ifStatement( btypes.binaryExpression( '===', btypes.unaryExpression('typeof', EH.makeIdentifier(prop)), EH.makeStringLiteral(type) ), EH.ensureBlockStatement(body) )
+ 11 other calls in file
545 546 547 548 549 550 551 552 553 554
this.registerBinding("unknown", path); } } buildUndefinedNode() { return t.unaryExpression("void", t.numericLiteral(0), true); } registerConstantViolation(path) { const ids = path.getBindingIdentifiers();
+ 16 other calls in file
303 304 305 306 307 308 309 310 311 312
babelTypes.identifier('undefined'), babelTypes.conditionalExpression( babelTypes.binaryExpression( '===', babelTypes.stringLiteral('number'), babelTypes.unaryExpression( 'typeof', babelTypes.identifier(tmpVar), true )
+ 10 other calls in file
42 43 44 45 46 47 48 49 50 51
let varIndex = t.variableDeclarator(index, t.numericLiteral(0)); let dispenser = t.variableDeclaration('let',[varArray, varIndex]); //生成switch中的表达式 +_array[_index++] let updExp = t.updateExpression('++', index); let memExp = t.memberExpression(array, updExp, true); let discriminant = t.unaryExpression("+", memExp); //构建整个switch语句 let switchSta = t.switchStatement(discriminant, cases); //生成while循环中的条件 !![] let unaExp = t.unaryExpression("!", t.arrayExpression());
+ 14 other calls in file
GitHub: redexp/adv-parser
![redexp profile picture](/redexp.png?size=40)
25 26 27 28 29 30 31 32 33 34
function asPure(root) { if (!t.isObjectExpression(root)) { throw new Error(`Invalid argument type: ${JSON.stringify(root && root.type)}, ObjectExpression expected`); } return t.unaryExpression('!', t.unaryExpression('!', root)); } function getProp(obj, name) { if (!Array.isArray(obj.properties)) {
+ 5 other calls in file
GitHub: dcloudio/uni-app
![dcloudio profile picture](/dcloudio.png?size=40)
97 98 99 100 101 102 103 104 105 106
} } }) test = test.elements[0] if (path.key === 'alternate') { test = t.unaryExpression('!', test) } tests = tests ? t.logicalExpression('&&', test, tests) : test } path = path.parentPath
@babel/types.identifier is the most popular function in @babel/types (20936 examples)