We wonder if we can read the federated wiki codebase and infer from it sufficient dynamic information to guild further refactoring.
We start with one file, the recently decaffeinated refresh.js, and parse to JSON AST with acorn, as recommended by Brian. explore
pages/static-aspects
We set as our first challenge to find "handleDrop" which appears twice. We tried writing a general iteration of the AST. This failed. So we tried recursing cautiously and found more variation than easily interpreted. github
Third try. We've found each "handleDrop". We did this by defining functions for each AST node between the root and the two references. Output from console.log. run github
Defined
PARSING VariableDeclaration PARSING VariableDeclarator PARSING Identifier 1995 'handleDrop'
Used
PARSING IfStatement PARSING UnaryExpression FAIL UnaryExpression 6667 PARSING BlockStatement PARSING ExpressionStatement PARSING CallExpression PARSING Identifier 6685 'handleDrop'
Rules written as functions match AST node types that they then interpret. The node is the only parameter but we de-structure this into the fields as needed. A function named parse gets this started and is often called recursively as we look deeper into the tree.
IfStatement({test,consequent}) {parse(test); parse(consequent)}
A CallExpression has two fields of interest: the callee and the arguments to be passed on the call. We use an unusual syntax to retrieve this second field because "arguments" is a reserved word in strict javascript.
CallExpression({callee}) {parse(callee); arguments[0]['arguments'].map(parse)}
After this small success, we let the chosen test file guide the creation of more rules based on the most frequent fails.
Most new rules expose the need for even more rules. We repeat this process until 33 rules traverse the full AST. We then tally identifiers and find 262 uniques name, some with double digit use counts.
http://ward.dojo.fed.wiki/assets/pages/static-aspects/match.html
I now recognize what I have coded is called a "tree walker". The acorn package comes with such code with some convenient interfaces. They include 80 rules, more than double my own. This suggests the test file uses less than half of the javascript features. github
After exploring various parsers and their associated implementation details I chose instead to implement an interactive interface as a deno web server from my localhost development workspace. deno github
As we developed our skills navigating we have found various presentations useful. Choose an identifier then proceed from context to details.
digraph { rankdir=LR context -> formula -> detail formula -> example -> detail node [color=green penwidth=3] edge [color=green penwidth=3] formula -> context detail -> similar -> formula }
Marc often reminds me how much he liked my way of browsing the New Relic graph database. In this a query makes a diagram where node clicks lead to another node specific query. matrix
Live State Translating Diagrams related?
npm start
http://localhost:1954/index HEIGHT 300
We observe that wiki-client exercised 47 distinct production rules. Will this number grow or shrink as we modernize? Nick's pure functional game-of-life source came in at 7 once we focused exclusively on the computation. github