javascript - Why does this && not short-circuit? -


this code node module templatizer.

if (i === 3 && node.type === "expressionstatement" && node.expression.callee.object.name === "buf" &&        node.expression.arguments.length === 1 && node.expression.arguments[0].type === "literal") {         // save simple string        simplestring = node.expression.arguments[0].value;        cnt++;     } 

the value of node.type 'variabledeclaration' logical expression false , node.expression shouldn't evaluated appears so...

typeerror: cannot read property 'object' of undefined @ /node_modules/templatizer/lib/simplifytemplate.js:34:89 @ array.foreach (native)

it means 'object' in 'callee'. expression , callee both undefined. step on conditional node crashes.

edit

i think javascript works fine , perhaps async code resulting in strange results form debugger. if put console.log @ top of loop gives output makes sense...

/usr/local/bin/node bin/www count: 1 i:0 node.type: variabledeclaration expression: undefined node.expression.callee: undefined  count: 2 i:1 node.type: variabledeclaration expression: undefined node.expression.callee: undefined  count: 3 i:2 node.type: variabledeclaration expression: undefined node.expression.callee: undefined  count: 4 i:3 node.type: expressionstatement expression: [object object] node.expression.callee: [object object]  count: 5 i:4 node.type: returnstatement expression: undefined node.expression.callee: undefined  count: 6 i:0 node.type: variabledeclaration expression: undefined node.expression.callee: undefined  count: 7 i:1 node.type: variabledeclaration expression: undefined node.expression.callee: undefined  count: 8 i:2 node.type: variabledeclaration expression: undefined node.expression.callee: undefined  count: 9 i:3 node.type: expressionstatement expression: [object object] node.expression.callee: undefined   /users/me/webstormprojects/mysite/node_modules/templatizer/lib/simplifytemplate.js:41 = 3 && node.type === "expressionstatement" && node.expression.callee.object.na                                                                     ^ typeerror: cannot read property 'object' of undefined     @ /users/me/webstormprojects/mysite/node_modules/templatizer/lib/simplifytemplate.js:41:89     @ array.foreach (native)     @ module.exports (/users/me/webstormprojects/mysite/node_modules/templatizer/lib/simplifytemplate.js:15:18)     @ /users/me/webstormprojects/mysite/node_modules/templatizer/templatizer.js:111:20     @ array.foreach (native)     @ module.exports (/users/me/webstormprojects/mysite/node_modules/templatizer/templatizer.js:95:15)     @ object.<anonymous> (/users/me/webstormprojects/mysite/app.js:23:1)     @ module._compile (module.js:456:26)     @ object.module._extensions..js (module.js:474:10)     @ module.load (module.js:356:32)  process finished exit code 8 

so looks bug in module.

seems debugger showing values different part of execution 1 caused crash. surely must running things asynchronously somewhere. bug in module. temporary fix add check conditional.

if (i === 3 && node.type === "expressionstatement" && node.expression.callee && node.expression.callee.object.name === "buf" &&                 node.expression.arguments.length === 1 && node.expression.arguments[0].type === "literal")  

i opened issue.


Comments

Popular posts from this blog

c++ - QTextObjectInterface with Qml TextEdit (QQuickTextEdit) -

javascript - angular ng-required radio button not toggling required off in firefox 33, OK in chrome -

xcode - Swift Playground - Files are not readable -