{"version":3,"sources":["https://lively-kernel.org/lively4/lively4-markus/src/client/reactive/babel-plugin-polymorphic-identifiers/polymorphic-identifiers.js"],"names":["SHARED_FLAG_GENERATED_IMPORT_IDENTIFIER","types","t","template","name","visitor","Program","enter","path","state","addCustomTemplate","file","declar","declarations","identifier","addImport","hasDirective","foundDirective","traverse","Directive","get","node","value","shouldTransform","opts","executedIn","TaggedTemplateExpression","visitedByPI","tagTemplate","tagPath","replaceWith","MAKE_REF","TAG_NODE","memberExpression","parentPath","isBinaryExpression","parentKey","operator","right","preStatementAncestor","find","p","parent","isStatement","isArrowFunctionExpression","assignmentExpression"],"mappings":";;;;;;;;;AACA,YAAMA,0CAA0C,yCAAhD;;;;;;;;;;;;;;;;yBAEe,UAAU,EAAEC,OAAOC,CAAT,EAAYC,QAAZ,EAAV,EAAkC;AAC/C,eAAO;AACLC,gBAAM,yBADD;AAELC,mBAAS;AACPC,qBAAS;AACPC,oBAAMC,IAAN,EAAYC,KAAZ,EAAmB;AACjB,yBAASC,iBAAT,CAA2BC,IAA3B,EAAiCP,IAAjC,EAAuC;AACrC,wBAAMQ,SAASD,KAAKE,YAAL,CAAkBT,IAAlB,CAAf;AACA,sBAAIQ,MAAJ,EAAY;AACV,2BAAOA,MAAP;AACD;;AAED,wBAAME,aAAaH,KAAKE,YAAL,CAAkBT,IAAlB,IAA0BO,KAAKI,SAAL,CAAe,yBAAf,EAA0CX,IAA1C,EAAgDA,IAAhD,CAA7C;AACAU,6BAAWd,uCAAX,IAAsD,IAAtD;AACA,yBAAOc,UAAP;AACD;;AAED,yBAASE,YAAT,CAAsBR,IAAtB,EAA4BJ,IAA5B,EAAkC;AAChC,sBAAIa,iBAAiB,KAArB;AACAT,uBAAKU,QAAL,CAAc;AACZC,8BAAUX,IAAV,EAAgB;AACd,0BAAIA,KAAKY,GAAL,CAAS,OAAT,EAAkBC,IAAlB,CAAuBC,KAAvB,KAAiClB,IAArC,EAA2C;AACzCa,yCAAiB,IAAjB;AACD;AACF;AAL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rC,KAAKa,IAAjC,EAAuCkB,qBAAqBlB,IAA5D,CAAjC;AACD;AACF;AA9BW,iBAAd;AAgCD;AA9DM;AADF;AAFJ,SAAP;AAqED,O","file":"polymorphic-identifiers.js","sourcesContent":["\nconst SHARED_FLAG_GENERATED_IMPORT_IDENTIFIER = 'SHARED_FLAG_GENERATED_IMPORT_IDENTIFIER';\n\nexport default function ({ types: t, template }) {\n  return {\n    name: 'polymorphic-identifiers',\n    visitor: {\n      Program: {\n        enter(path, state) {\n          function addCustomTemplate(file, name) {\n            const declar = file.declarations[name];\n            if (declar) {\n              return declar;\n            }\n\n            const identifier = file.declarations[name] = file.addImport(\"polymorphic-identifiers\", name, name);\n            identifier[SHARED_FLAG_GENERATED_IMPORT_IDENTIFIER] = true;\n            return identifier;\n          }\n\n          function hasDirective(path, name) {\n            let foundDirective = false;\n            path.traverse({\n              Directive(path) {\n                if (path.get(\"value\").node.value === name) {\n                  foundDirective = true;\n                }\n              }\n            });\n            return foundDirective;\n          }\n\n          const shouldTransform = state.opts.executedIn === 'workspace' || hasDirective(path, \"pi\");\n          if (!shouldTransform) {\n            return;\n          }\n\n          path.traverse({\n            TaggedTemplateExpression(path) {\n              if (path.node.visitedByPI) {\n                return;\n              }\n              path.node.visitedByPI = true;\n\n              const tagTemplate = template(`MAKE_REF(TAG_NODE, {\n                thisReference: this,\n                evalFunction: str => eval(str)\n              })`);\n              const tagPath = path.get('tag');\n              tagPath.replaceWith(tagTemplate({\n                MAKE_REF: addCustomTemplate(state.file, 'makeRef'),\n                TAG_NODE: tagPath.node\n              }));\n              \n              path.replaceWith(t.memberExpression(path.node, t.identifier('access')));\n              \n              const parentPath = path.parentPath;\n              if (parentPath.isBinaryExpression() && path.parentKey === 'left' && parentPath.node.operator === \"<<\") {\n                parentPath.replaceWith(parentPath.node.right);\n                \n                // find something we can embed an assignment expression in\n                const preStatementAncestor = parentPath.find(p => {\n                  const parent = p.parentPath;\n                  return parent && (parent.isStatement() || (parent.isArrowFunctionExpression() && p.parentKey === \"body\"))\n                });\n                preStatementAncestor.replaceWith(t.assignmentExpression('=', path.node, preStatementAncestor.node));\n              }\n            }\n          });\n        }\n      }\n    }\n  };\n}"]}