rewrite-this.js 675 B

123456789101112131415161718192021222324252627282930
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = rewriteThis;
  6. var _helperEnvironmentVisitor = require("@babel/helper-environment-visitor");
  7. var _traverse = require("@babel/traverse");
  8. var _t = require("@babel/types");
  9. const {
  10. numericLiteral,
  11. unaryExpression
  12. } = _t;
  13. function rewriteThis(programPath) {
  14. (0, _traverse.default)(programPath.node, Object.assign({}, rewriteThisVisitor, {
  15. noScope: true
  16. }));
  17. }
  18. const rewriteThisVisitor = _traverse.default.visitors.merge([_helperEnvironmentVisitor.default, {
  19. ThisExpression(path) {
  20. path.replaceWith(unaryExpression("void", numericLiteral(0), true));
  21. }
  22. }]);