{"version":3,"sources":["https://lively-kernel.org/lively4S2/swd21-event-sourcing/src/client/reactive/babel-plugin-databindings/index.js"],"names":["babel","types","t","template","transformFromAst","traverse","name","visitor","Program","enter","ppath","state","LabeledStatement","path","node","label","variableDeclaration","body","declarations","replaceWith","kind","map","varDecl","variableDeclarator","id","reverse","expression","init","AEIdentifier","identifier","loc","AECall","callExpression","arrowFunctionExpression","assignment","assignmentExpression","assignmentFunction","onChangeCall","memberExpression","AEexpreesion","expressionStatement","insertAfter"],"mappings":";;;;;;;;;yBAAe,UAAUA,KAAV,EAAiB;AAC9B,cAAM,EAAEC,OAAOC,CAAT,EAAYC,QAAZ,EAAsBC,gBAAtB,EAAwCC,QAAxC,KAAqDL,KAA3D;;AAEA,eAAO;AACLM,gBAAM,cADD;AAELC,mBAAS;AACPC,qBAAS;AACPC,oBAAMC,KAAN,EAAaC,KAAb,EAAoB;AAClBD,sBAAML,QAAN,CAAe;AACbO,mCAAiBC,IAAjB,EAAuB;AACrB,0BAAMC,OAAOD,KAAKC,IAAlB;AACA,wBAAIA,KAAKC,KAAL,CAAWT,IAAX,KAAoB,QAAxB,EAAkC;AAClC,0BAAMU,sBAAsBF,KAAKG,IAAL,CAAUC,YAAV,CAAuB,CAAvB,CAA5B;AACAL,yBAAKM,WAAL,CAAiBjB,EAAEc,mBAAF,CAAsBF,KAAKG,IAAL,CAAUG,IAAhC,EAAsCN,KAAKG,IAAL,CAAUC,YAAV,CAAuBG,GAAvB,CAA2BC,WAAWpB,EAAEqB,kBAAF,CAAqBD,QAAQE,EAA7B,CAAtC,CAAtC,CAAjB;;AAEA,yBAAK,MAAMR,mBAAX,IAAkCF,KAAKG,IAAL,CAAUC,YAAV,CAAuBO,OAAvB,EAAlC,EAAoE;AAClE,4BAAMC,aAAaV,oBAAoBW,IAAvC;AACA,4BAAMC,eAAe1B,EAAE2B,UAAF,CAAa,OAAb,CAArB;AACA;AACAD,mCAAaE,GAAb,GAAmBhB,KAAKgB,GAAxB;AACA,4BAAMC,SAAS7B,EAAE8B,cAAF,CAAiBJ,YAAjB,EAA+B,CAAC1B,EAAE+B,uBAAF,CAA0B,EAA1B,EAA8BP,UAA9B,CAAD,CAA/B,CAAf;AACA,4BAAMQ,aAAahC,EAAEiC,oBAAF,CAAuB,GAAvB,EAA4BnB,oBAAoBQ,EAAhD,EAAoDtB,EAAE2B,UAAF,CAAa,OAAb,CAApD,CAAnB;AACA;AACAK,iCAAWJ,GAAX,GAAiBhB,KAAKgB,GAAtB;AACA,4BAAMM,qBAAqBlC,EAAE+B,uBAAF,CAA0B,CAAC/B,EAAE2B,UAAF,CAAa,OAAb,CAAD,CAA1B,EAAmDK,UAAnD,CAA3B;AACA,4BAAMG,eAAenC,EAAE8B,cAAF,CAAiB9B,EAAEoC,gBAAF,CAAmBP,MAAnB,EAA2B7B,EAAE2B,UAAF,CAAa,UAAb,CAA3B,CAAjB,EAAuE,CAACO,kBAAD,CAAvE,CAArB;AACA,4BAAMG,eAAerC,EAAEsC,mBAAF,CAAsBH,YAAtB,CAArB;;AAEAxB,2BAAK4B,WAAL,CAAiBF,YAAjB;AACD;AACF;AAtBY,iBAAf;AAwBD;AA1BM;AADF;AAFJ,SAAP;AAiCD,O","file":"index.js","sourcesContent":["export default function (babel) {\n  const { types: t, template, transformFromAst, traverse } = babel;\n\n  return {\n    name: \"data-binding\",\n    visitor: {\n      Program: {\n        enter(ppath, state) {\n          ppath.traverse({\n            LabeledStatement(path) {\n              const node = path.node;\n              if (node.label.name !== \"always\") return;\n              const variableDeclaration = node.body.declarations[0];\n              path.replaceWith(t.variableDeclaration(node.body.kind, node.body.declarations.map(varDecl => t.variableDeclarator(varDecl.id))));\n\n              for (const variableDeclaration of node.body.declarations.reverse()) {\n                const expression = variableDeclaration.init;\n                const AEIdentifier = t.identifier(\"aexpr\");\n                // When registering the AE, we want to know the code that generated it, which is this entire LabeledStatement\n                AEIdentifier.loc = node.loc;\n                const AECall = t.callExpression(AEIdentifier, [t.arrowFunctionExpression([], expression)]);\n                const assignment = t.assignmentExpression(\"=\", variableDeclaration.id, t.identifier(\"value\"));\n                // Also add the location info for the assignment\n                assignment.loc = node.loc;\n                const assignmentFunction = t.arrowFunctionExpression([t.identifier(\"value\")], assignment);\n                const onChangeCall = t.callExpression(t.memberExpression(AECall, t.identifier(\"dataflow\")), [assignmentFunction]);\n                const AEexpreesion = t.expressionStatement(onChangeCall);\n\n                path.insertAfter(AEexpreesion);\n              }\n            }\n          });\n        }\n      }\n    }\n  };\n}"]}