UNPKG

1.45 kBSource Map (JSON)View Raw
1{"version":3,"names":["numericLiteral","unaryExpression","rewriteThis","programPath","traverse","node","rewriteThisVisitor","noScope","visitors","merge","environmentVisitor","ThisExpression","path","replaceWith"],"sources":["../src/rewrite-this.ts"],"sourcesContent":["import environmentVisitor from \"@babel/helper-environment-visitor\";\nimport traverse from \"@babel/traverse\";\nimport { numericLiteral, unaryExpression } from \"@babel/types\";\n\nimport type { NodePath, Visitor } from \"@babel/traverse\";\nexport default function rewriteThis(programPath: NodePath) {\n // Rewrite \"this\" to be \"undefined\".\n traverse(programPath.node, { ...rewriteThisVisitor, noScope: true });\n}\n\n/**\n * A visitor to walk the tree, rewriting all `this` references in the top-level scope to be\n * `void 0` (undefined).\n */\nconst rewriteThisVisitor: Visitor = traverse.visitors.merge([\n environmentVisitor,\n {\n ThisExpression(path) {\n path.replaceWith(unaryExpression(\"void\", numericLiteral(0), true));\n },\n },\n]);\n"],"mappings":";;;;;;;AAAA;;AACA;;AACA;;;EAASA,c;EAAgBC;;;AAGV,SAASC,WAAT,CAAqBC,WAArB,EAA4C;EAEzD,IAAAC,iBAAA,EAASD,WAAW,CAACE,IAArB,oBAAgCC,kBAAhC;IAAoDC,OAAO,EAAE;EAA7D;AACD;;AAMD,MAAMD,kBAA2B,GAAGF,iBAAA,CAASI,QAAT,CAAkBC,KAAlB,CAAwB,CAC1DC,iCAD0D,EAE1D;EACEC,cAAc,CAACC,IAAD,EAAO;IACnBA,IAAI,CAACC,WAAL,CAAiBZ,eAAe,CAAC,MAAD,EAASD,cAAc,CAAC,CAAD,CAAvB,EAA4B,IAA5B,CAAhC;EACD;;AAHH,CAF0D,CAAxB,CAApC"}
\No newline at end of file