Every line of 'node js if statement' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.
9 export function compileIf(compiler: Compiler, node: typescript.IfStatement): binaryen.Statement { 10 const op = compiler.module; 11 12 return op.if( 13 compiler.compileExpression(node.expression, reflection.intType, reflection.intType, true), 14 compiler.compileStatement(node.thenStatement), 15 node.elseStatement ? compiler.compileStatement(node.elseStatement) : undefined 16 ); 17 }
Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code
17 export function ElseifClause(node) { 18 this.word('elseif'); 19 this.space(); 20 this.print(node.condition, node); 21 this.space(); 22 this.word('then'); 23 this.printBlock(node); 24 this.removeTrailingNewline(); 25 if (this.format.minified) this._buf.removeLastSemicolon(); 26 }
559 IfStatement(node, path) { 560 var old = this.text 561 this.text += 'if(' 562 563 var test = node.test 564 this[test.type](test,path+'if') 565 566 this.text += ')' 567 var cq = node.consequent 568 var alt = node.alternate 569 570 this[cq.type](cq,path+'cons') 571 572 if(alt) { 573 var old = this.text 574 this.text += '\nelse ' 575 this[alt.type](alt,path+'alt') 576 } 577 }
32 function IfStatement(node) { 33 this.word("if"); 34 this.space(); 35 this.token("("); 36 this.print(node.test, node); 37 this.token(")"); 38 this.space(); 39 var needsBlock = node.alternate && t.isIfStatement(getLastStatement(node.consequent)); 40 41 if (needsBlock) { 42 this.token("{"); 43 this.newline(); 44 this.indent(); 45 } 46 47 this.printAndIndentOnComments(node.consequent, node); 48 49 if (needsBlock) { 50 this.dedent(); 51 this.newline(); 52 this.token("}"); 53 } 54 55 if (node.alternate) { 56 if (this.endsWith("}")) this.space(); 57 this.word("else"); 58 this.space(); 59 this.printAndIndentOnComments(node.alternate, node); 60 } 61 }
60 get if() { 61 const ifNode = new Node(); 62 ifNode.parent = this._current; 63 this._current.set(keyword.IF, ifNode); 64 this._current = ifNode; 65 return this; 66 }
1 export function macroIfBlock(node: any) { 2 if (node.params.length !== 1) { 3 throw new Error(`macroIf (block form) requires one arguments, you passed ${node.params.length}`); 4 } 5 6 let result = evaluate(node.params[0]); 7 if (!result.confident) { 8 throw new Error(`first argument to macroIf must be statically analyzable`); 9 } 10 11 if (result.value) { 12 return node.program.body; 13 } else { 14 if (node.inverse) { 15 return node.inverse.body; 16 } else { 17 return []; 18 } 19 } 20 }
33 statementTransformers['IfStatement'] = function transformIfStatement(node) { 34 node.update(template.ifElseStatement({ 35 test: node.test.source(), 36 consequent: removeBraces(node.consequent.source()), 37 alternate: node.alternate ? removeBraces(node.alternate.source()) : '', 38 consequentStep: stepID++, 39 alternateStep: stepID++, 40 continueStep: stepID++ 41 })); 42 };
800 export function isForOfStatement(node) { 801 return node.type === 'ForOfStatement'; 802 }
281 function isForOfStatement(node) { 282 return node.kind === ts.SyntaxKind.ForOfStatement; 283 }
87 export function IfStatement(path: NodePath, node: Node) { 88 const t = []; 89 const test = path.get('test'); 90 const conq = path.get('consequent'); 91 t.push(...test.srcElBefore()); 92 t.push({element: 'Punctuator', value: '('}); 93 94 // TODO: preserve inner paren spacing 95 96 t.push(test.srcEl()); 97 this.print(path, 'test'); 98 99 // TODO: move this to a reusable spot, use whenever `then` could occur 100 if (ty.isBlock(node.consequent)) { 101 // TODO: preserve spacing after close paren 102 // if nothing to preserve, use the spacing seen `()_here_->` 103 t.push({element: 'Punctuator', value: ')'}); 104 t.push(...test.srcElUntil(conq)); 105 } else { 106 t.push(...keywordToPunc(test.srcElUntil(conq))); 107 } 108 109 t.push(conq.srcEl()); 110 this.print(path, 'consequent'); 111 112 if (node.alternate) { 113 const alt = path.get('alternate'); 114 t.push(...conq.srcElUntil(alt), alt.srcEl()) 115 this.print(path, 'alternate'); 116 t.push(...alt.srcElAfter()); 117 } else { 118 t.push(...conq.srcElAfter()); 119 } 120 121 node[this.key] = t; 122 }