Skip to content

Instantly share code, notes, and snippets.

@erikpukinskis
Last active October 29, 2017 07:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save erikpukinskis/e2fbe5e6ff5d0bdf60baaaf1b942fabc to your computer and use it in GitHub Desktop.
Save erikpukinskis/e2fbe5e6ff5d0bdf60baaaf1b942fabc to your computer and use it in GitHub Desktop.
javascript-to-ezjs$ node demo
===
NEW LOG for demo-module
function (anExpression) {
anExpression.tree("tree8d")
// begin
}
===
Original JavaScript:
function housePanel(issueBond, sellBond) {
var bond = issueBond(
"floor panel",{
"rateOfReturn": "10%",
"termLength": "60 days"})
bond.addTasks([
"cut studs to length",
"cut track to length",
"crimp",
"add sheathing",
"flipsulate",
"add sheathing",])
bond.addExpense(
"labor",
"$100")
bond.addExpense(
"steel studs",
"$20")
bond.addExpense(
"plywood",
"$10")
return function(bridge) {
sellBond.prepareSite(bridge.getSite())
sellBond(bridge, bond)
bridge.send(
"hallooo")}
}
* function literal start! function housePanel(issueBond, sellBond) {
!!! no parent to add to
function literal
--> adding assigning to var bond (explflu) to function literal
* assignment! var bond = issueBond(
* function call start! issueBond(
◯ popped variable assignment
--> adding calling issueBond (explflv) to assigning to var bond
--> adding "floor panel" (explflw) to calling issueBond as argument
+ Adding string literal << explflw >> at 3
* string literal! "floor panel",{
+ Adding object literal << explflx >> at 4
--> adding object with keys undefined (explflx) to calling issueBond as argument
↖ push ← object literal
--> adding "10%" (explfly) to object with keys undefined
+ Adding string literal << explfly >> at 5
* string literal! "10%",
* argument string! ,
Set valueId of explflz to explflz
--> adding "60 days" (explfm0) to object with keys undefined
+ Adding string literal << explfm0 >> at 6
* string literal! "60 days"}
◯ popped object literal
* object literal end! }
Set valueId of explfm1 to explfm1
◯ popped function call
+ Adding function call << explflv >> at 2
+ PARENT explflu
+ Add LINE variable assignment << explflu >> LINE at 1 to explflt
+ PARENT explflt
+ Adding function literal << explflt >> at 0
* call end! "termLength": "60 days"})
* function call start! bond.addTasks([
function literal
--> adding calling bond.addTasks (explfm2) to function literal
* array literal! [
--> adding array (explfm3) to calling bond.addTasks as argument
--> adding "cut studs to length" (explfm4) to array
+ Adding string literal << explfm4 >> at 9
* string literal! "cut studs to length",
* argument string! ,
--> adding "cut track to length" (explfm5) to array
+ Adding string literal << explfm5 >> at 10
* string literal! "cut track to length",
* argument string! ,
--> adding "crimp" (explfm6) to array
+ Adding string literal << explfm6 >> at 11
* string literal! "crimp",
* argument string! ,
--> adding "add sheathing" (explfm7) to array
+ Adding string literal << explfm7 >> at 12
* string literal! "add sheathing",
* argument string! ,
--> adding "flipsulate" (explfm8) to array
+ Adding string literal << explfm8 >> at 13
* string literal! "flipsulate",
* argument string! ,
--> adding "add sheathing" (explfm9) to array
+ Adding string literal << explfm9 >> at 14
* string literal! "add sheathing",]
* argument string! ,
◯ popped array literal
+ Adding array literal << explfm3 >> at 8
* array end! ,]
◯ popped function call
+ Add LINE function call << explfm2 >> LINE at 7 to explflt
* call end! "add sheathing",])
* function call start! bond.addExpense(
function literal
--> adding calling bond.addExpense (explfma) to function literal
--> adding "labor" (explfmb) to calling bond.addExpense as argument
+ Adding string literal << explfmb >> at 16
* string literal! "labor",
* argument string! ,
--> adding "$100" (explfmc) to calling bond.addExpense as argument
+ Adding string literal << explfmc >> at 17
* string literal! "$100"
◯ popped function call
+ Add LINE function call << explfma >> LINE at 15 to explflt
* call end! "$100")
* function call start! bond.addExpense(
function literal
--> adding calling bond.addExpense (explfmd) to function literal
--> adding "steel studs" (explfme) to calling bond.addExpense as argument
+ Adding string literal << explfme >> at 19
* string literal! "steel studs",
* argument string! ,
--> adding "$20" (explfmf) to calling bond.addExpense as argument
+ Adding string literal << explfmf >> at 20
* string literal! "$20"
◯ popped function call
+ Add LINE function call << explfmd >> LINE at 18 to explflt
* call end! "$20")
* function call start! bond.addExpense(
function literal
--> adding calling bond.addExpense (explfmg) to function literal
--> adding "plywood" (explfmh) to calling bond.addExpense as argument
+ Adding string literal << explfmh >> at 22
* string literal! "plywood",
* argument string! ,
--> adding "$10" (explfmi) to calling bond.addExpense as argument
+ Adding string literal << explfmi >> at 23
* string literal! "$10"
◯ popped function call
+ Add LINE function call << explfmg >> LINE at 21 to explflt
* call end! "$10")
--> adding returning undefined (explfmj) to function literal
* return statement! return function(bridge) {
* function literal start! function(bridge) {
◯ popped return statement
--> adding function literal (explfmk) to returning undefined
* function call start! sellBond.prepareSite(bridge.getSite())
function literal
--> adding calling sellBond.prepareSite (explfml) to function literal
* function call start! bridge.getSite())
--> adding calling bridge.getSite (explfmm) to calling sellBond.prepareSite as argument
◯ popped function call
* function call end! ))
* function call start! sellBond(bridge, bond)
--> adding calling sellBond (explfmn) to calling sellBond.prepareSite as argument
* argument string! bridge, bond
* reference! bridge
--> adding reference to var bridge (explfmo) to calling sellBond as argument
+ Adding variable reference << explfmo >> at 29
* reference! bond
--> adding reference to var bond (explfmp) to calling sellBond as argument
+ Adding variable reference << explfmp >> at 30
◯ popped function call
+ Adding function call << explfmn >> at 28
* call end! bridge, bond)
* function call start! bridge.send(
--> adding calling bridge.send (explfmq) to calling sellBond.prepareSite as argument
--> adding "hallooo" (explfmr) to calling bridge.send as argument
+ Adding string literal << explfmr >> at 32
* string literal! "hallooo")}
◯ popped function call
* function call end! )}
◯ popped function call
* function call end! }
root is { kind: 'function literal',
id: 'explfmk',
index: 25,
argumentNames: [ 'bridge' ],
body: [],
parentToAdd:
{ kind: 'return statement',
id: 'explfmj',
index: 24,
lineIn:
{ kind: 'function literal',
id: 'explflt',
functionName: 'housePanel',
argumentNames: [Object],
body: [] },
expression: 'explfmk' } }
function literal
--> adding function literal (explflt) to function literal
Finished expression. Root is explflt
function (anExpression) {
anExpression.tree("tree8d")
anExpression.addToTree("tree8d", 3, {"kind":"string literal","id":"explflw","string":"floor panel"})
anExpression.addToTree("tree8d", 4, {"kind":"object literal","valueIdsByKey":{},"id":"explflx"})
anExpression.addToTree("tree8d", 5, {"kind":"string literal","id":"explfly","string":"10%"})
anExpression.addKeyValuePair("tree8d", "explflx", "rateOfReturn", "explfly", undefined)
anExpression.addToTree("tree8d", 6, {"kind":"string literal","id":"explfm0","string":"60 days"})
anExpression.addKeyValuePair("tree8d", "explflx", "termLength", "explfm0", undefined)
anExpression.addToTree("tree8d", 2, {"kind":"function call","id":"explflv","functionName":"issueBond","arguments":["explflw","explflx"]})
anExpression.setAttribute("tree8d", "parentId", "explflw", "explflv")
anExpression.setAttribute("tree8d", "role", "explflw", "call argument")
anExpression.setAttribute("tree8d", "parentId", "explflx", "explflv")
anExpression.setAttribute("tree8d", "role", "explflx", "call argument")
anExpression.lineIn("explflt", "tree8d", 1, {"kind":"variable assignment","id":"explflu","variableName":"bond ","isDeclaration":true,"expression":"explflv"})
anExpression.setAttribute("tree8d", "parentId", "explflu", "explflt")
anExpression.setAttribute("tree8d", "role", "explflu", "function literal line")
anExpression.addToTree("tree8d", 0, {"kind":"function literal","id":"explflt","functionName":"housePanel","argumentNames":["issueBond","sellBond"],"body":[]})
anExpression.addToTree("tree8d", 9, {"kind":"string literal","id":"explfm4","string":"cut studs to length"})
anExpression.addToTree("tree8d", 10, {"kind":"string literal","id":"explfm5","string":"cut track to length"})
anExpression.addToTree("tree8d", 11, {"kind":"string literal","id":"explfm6","string":"crimp"})
anExpression.addToTree("tree8d", 12, {"kind":"string literal","id":"explfm7","string":"add sheathing"})
anExpression.addToTree("tree8d", 13, {"kind":"string literal","id":"explfm8","string":"flipsulate"})
anExpression.addToTree("tree8d", 14, {"kind":"string literal","id":"explfm9","string":"add sheathing"})
anExpression.addToTree("tree8d", 8, {"kind":"array literal","id":"explfm3","items":["explfm4","explfm5","explfm6","explfm7","explfm8","explfm9"]})
anExpression.setAttribute("tree8d", "parentId", "explfm4", "explfm3")
anExpression.setAttribute("tree8d", "role", "explfm4", "array item")
anExpression.setAttribute("tree8d", "parentId", "explfm5", "explfm3")
anExpression.setAttribute("tree8d", "role", "explfm5", "array item")
anExpression.setAttribute("tree8d", "parentId", "explfm6", "explfm3")
anExpression.setAttribute("tree8d", "role", "explfm6", "array item")
anExpression.setAttribute("tree8d", "parentId", "explfm7", "explfm3")
anExpression.setAttribute("tree8d", "role", "explfm7", "array item")
anExpression.setAttribute("tree8d", "parentId", "explfm8", "explfm3")
anExpression.setAttribute("tree8d", "role", "explfm8", "array item")
anExpression.setAttribute("tree8d", "parentId", "explfm9", "explfm3")
anExpression.setAttribute("tree8d", "role", "explfm9", "array item")
anExpression.setAttribute("tree8d", "parentId", "explfm3", "explfm2")
anExpression.setAttribute("tree8d", "role", "explfm3", "call argument")
anExpression.lineIn("explflt", "tree8d", 7, {"kind":"function call","id":"explfm2","functionName":"bond.addTasks","arguments":["explfm3"]})
anExpression.setAttribute("tree8d", "parentId", "explfm2", "explflt")
anExpression.setAttribute("tree8d", "role", "explfm2", "function literal line")
anExpression.addToTree("tree8d", 16, {"kind":"string literal","id":"explfmb","string":"labor"})
anExpression.addToTree("tree8d", 17, {"kind":"string literal","id":"explfmc","string":"$100"})
anExpression.setAttribute("tree8d", "parentId", "explfmb", "explfma")
anExpression.setAttribute("tree8d", "role", "explfmb", "call argument")
anExpression.setAttribute("tree8d", "parentId", "explfmc", "explfma")
anExpression.setAttribute("tree8d", "role", "explfmc", "call argument")
anExpression.lineIn("explflt", "tree8d", 15, {"kind":"function call","id":"explfma","functionName":"bond.addExpense","arguments":["explfmb","explfmc"]})
anExpression.setAttribute("tree8d", "parentId", "explfma", "explflt")
anExpression.setAttribute("tree8d", "role", "explfma", "function literal line")
anExpression.addToTree("tree8d", 19, {"kind":"string literal","id":"explfme","string":"steel studs"})
anExpression.addToTree("tree8d", 20, {"kind":"string literal","id":"explfmf","string":"$20"})
anExpression.setAttribute("tree8d", "parentId", "explfme", "explfmd")
anExpression.setAttribute("tree8d", "role", "explfme", "call argument")
anExpression.setAttribute("tree8d", "parentId", "explfmf", "explfmd")
anExpression.setAttribute("tree8d", "role", "explfmf", "call argument")
anExpression.lineIn("explflt", "tree8d", 18, {"kind":"function call","id":"explfmd","functionName":"bond.addExpense","arguments":["explfme","explfmf"]})
anExpression.setAttribute("tree8d", "parentId", "explfmd", "explflt")
anExpression.setAttribute("tree8d", "role", "explfmd", "function literal line")
anExpression.addToTree("tree8d", 22, {"kind":"string literal","id":"explfmh","string":"plywood"})
anExpression.addToTree("tree8d", 23, {"kind":"string literal","id":"explfmi","string":"$10"})
anExpression.setAttribute("tree8d", "parentId", "explfmh", "explfmg")
anExpression.setAttribute("tree8d", "role", "explfmh", "call argument")
anExpression.setAttribute("tree8d", "parentId", "explfmi", "explfmg")
anExpression.setAttribute("tree8d", "role", "explfmi", "call argument")
anExpression.lineIn("explflt", "tree8d", 21, {"kind":"function call","id":"explfmg","functionName":"bond.addExpense","arguments":["explfmh","explfmi"]})
anExpression.setAttribute("tree8d", "parentId", "explfmg", "explflt")
anExpression.setAttribute("tree8d", "role", "explfmg", "function literal line")
anExpression.addToTree("tree8d", 29, {"kind":"variable reference","id":"explfmo","variableName":"bridge"})
anExpression.addToTree("tree8d", 30, {"kind":"variable reference","id":"explfmp","variableName":"bond"})
anExpression.addToTree("tree8d", 28, {"kind":"function call","id":"explfmn","functionName":"sellBond","arguments":["explfmo","explfmp"]})
anExpression.setAttribute("tree8d", "parentId", "explfmo", "explfmn")
anExpression.setAttribute("tree8d", "role", "explfmo", "call argument")
anExpression.setAttribute("tree8d", "parentId", "explfmp", "explfmn")
anExpression.setAttribute("tree8d", "role", "explfmp", "call argument")
anExpression.addToTree("tree8d", 32, {"kind":"string literal","id":"explfmr","string":"hallooo"})
// begin
}
Root id is explflt
initial tree tree8d :
forgot trees. tree8d = undefined
Set valueId of explfms to explfms
Set valueId of explfmt to explfmt
now tree tree8d is:
===
ORIGINAL JAVASCRIPT
function housePanel(issueBond, sellBond) {
var bond = issueBond(
"floor panel",{
"rateOfReturn": "10%",
"termLength": "60 days"})
bond.addTasks([
"cut studs to length",
"cut track to length",
"crimp",
"add sheathing",
"flipsulate",
"add sheathing",])
bond.addExpense(
"labor",
"$100")
bond.addExpense(
"steel studs",
"$20")
bond.addExpense(
"plywood",
"$10")
return function(bridge) {
sellBond.prepareSite(bridge.getSite())
sellBond(bridge, bond)
bridge.send(
"hallooo")}
}
===
===
RECONSTRUCTURED SOURCE
function housePanel(issueBond, sellBond) {
var bond = issueBond(
"floor panel",
{
"rateOfReturn": "10%",
"termLength": "60 days"
})
bond.addTasks(
[
"cut studs to length",
"cut track to length",
"crimp",
"add sheathing",
"flipsulate",
"add sheathing"
])
bond.addExpense(
"labor",
"$100")
bond.addExpense(
"steel studs",
"$20")
bond.addExpense(
"plywood",
"$10")
}
===
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment