I'm looking into how the AST can be used to extract interesting stuff about Javascript, and discovered that the nodes to leaves ratio is on average 1.65 ± 0.05. This number, being so consistent (a standard deviation of 3%) over a lot of node.js code, makes me curious. The
% node tree-stats.js ~/dev/ast/others/esprima/esprima.js
filename: /Users/emil/dev/ast/others/esprima/esprima.js
nLeaves: 22590
nNodes: 36260
nNodes/nLeaves: 1.61
% node tree-stats.js simple-nested.js
nLeaves: 67
nNodes: 114
nNodes/nLeaves: 1.70
# Hmm, suspicious?
% for f in $(find node_modules -name "*.js" | head -n 100); do node tree-stats.js $f; done 2>/dev/null | grep 'nLeaves/' | awk '{print $2}' | node statistics.js
samples: 75
mean: 1.65
stdev: 0.05