schangxiang@126.com
2025-09-18 49a51c068d62084bc4c3e77c4be94a20de556c4a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
"use strict";
 
exports.__esModule = true;
 
var _getIterator2 = require("babel-runtime/core-js/get-iterator");
 
var _getIterator3 = _interopRequireDefault(_getIterator2);
 
exports.default = function (_ref) {
  var t = _ref.types;
 
  var FLOW_DIRECTIVE = "@flow";
 
  return {
    inherits: require("babel-plugin-syntax-flow"),
 
    visitor: {
      Program: function Program(path, _ref2) {
        var comments = _ref2.file.ast.comments;
 
        for (var _iterator = comments, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : (0, _getIterator3.default)(_iterator);;) {
          var _ref3;
 
          if (_isArray) {
            if (_i >= _iterator.length) break;
            _ref3 = _iterator[_i++];
          } else {
            _i = _iterator.next();
            if (_i.done) break;
            _ref3 = _i.value;
          }
 
          var comment = _ref3;
 
          if (comment.value.indexOf(FLOW_DIRECTIVE) >= 0) {
            comment.value = comment.value.replace(FLOW_DIRECTIVE, "");
 
            if (!comment.value.replace(/\*/g, "").trim()) comment.ignore = true;
          }
        }
      },
      Flow: function Flow(path) {
        path.remove();
      },
      ClassProperty: function ClassProperty(path) {
        path.node.variance = null;
        path.node.typeAnnotation = null;
        if (!path.node.value) path.remove();
      },
      Class: function Class(path) {
        path.node.implements = null;
 
        path.get("body.body").forEach(function (child) {
          if (child.isClassProperty()) {
            child.node.typeAnnotation = null;
            if (!child.node.value) child.remove();
          }
        });
      },
      AssignmentPattern: function AssignmentPattern(_ref4) {
        var node = _ref4.node;
 
        node.left.optional = false;
      },
      Function: function Function(_ref5) {
        var node = _ref5.node;
 
        for (var i = 0; i < node.params.length; i++) {
          var param = node.params[i];
          param.optional = false;
        }
      },
      TypeCastExpression: function TypeCastExpression(path) {
        var node = path.node;
 
        do {
          node = node.expression;
        } while (t.isTypeCastExpression(node));
        path.replaceWith(node);
      }
    }
  };
};
 
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
 
module.exports = exports["default"];