MCPcopy
hub / github.com/asm-js/validator / flattenAdditive

Function flattenAdditive

lib/validate.js:62–85  ·  view source on GitHub ↗
(left, right)

Source from the content-addressed store, hash-verified

60
61// (Expression, Expression) -> [Expression]
62function flattenAdditive(left, right) {
63 var result = [];
64
65 // Since .pop is faster than .shift we'll pop tasks from the end.
66 var todo = [right, left];
67 while (todo.length > 0) {
68 match(todo.pop(), function(when) {
69 when({
70 type: 'BinaryExpression',
71 operator: match.some('+', '-'),
72 left: match.var('left'),
73 right: match.var('right')
74 }, function(vars) {
75 todo.push(vars.right, vars.left);
76 });
77
78 when(match.var('operand'), function(vars) {
79 result.push(vars.operand);
80 });
81 });
82 }
83
84 return result;
85}
86
87// -----------------------------------------------------------------------------
88// main methods

Callers 1

validate.jsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected