(a, b)
| 2 | const { javascriptGenerator } = require('blockly/javascript') |
| 3 | |
| 4 | function fuzzyMatch (a, b) { |
| 5 | if (a.type !== b.type) return false |
| 6 | switch (a.type) { |
| 7 | case 'Identifier': |
| 8 | return a.name === b.name |
| 9 | case 'CallExpression': |
| 10 | if (!fuzzyMatch(a.callee, b.callee)) return false |
| 11 | return true |
| 12 | case 'MemberExpression': |
| 13 | return fuzzyMatch(a.object, b.object) && fuzzyMatch(a.property, b.property) && a.computed === b.computed |
| 14 | case 'NumericLiteral': |
| 15 | case 'StringLiteral': |
| 16 | case 'BooleanLiteral': |
| 17 | return true |
| 18 | case 'ArrayExpression': |
| 19 | return (a.elements.length === 0) === (b.elements.length === 0) |
| 20 | case 'BreakStatement': |
| 21 | case 'ContinueStatement': |
| 22 | return true |
| 23 | case 'WhileStatement': |
| 24 | case 'ForStatement': |
| 25 | case 'ConditionalExpression': |
| 26 | return true |
| 27 | case 'IfStatement': |
| 28 | return true |
| 29 | default: |
| 30 | throw new Error(`Don't know how to fuzzy compare ${a.type}`) |
| 31 | } |
| 32 | } |
| 33 | |
| 34 | function findOne (array, pred, why = 'Expected exactly one match') { |
| 35 | const matches = array.filter(pred) |
no outgoing calls
no test coverage detected