Blame view

天文台pc/tianwentai-ui/node_modules/@babel/generator/lib/node/index.js 2.13 KB
bc518174   王天杨   提交两个项目文件
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
  "use strict";
  
  Object.defineProperty(exports, "__esModule", {
    value: true
  });
  exports.TokenContext = void 0;
  exports.isLastChild = isLastChild;
  exports.parentNeedsParens = parentNeedsParens;
  var parens = require("./parentheses.js");
  var _t = require("@babel/types");
  var _nodes = require("../nodes.js");
  const {
    VISITOR_KEYS
  } = _t;
  const TokenContext = exports.TokenContext = {
    normal: 0,
    expressionStatement: 1,
    arrowBody: 2,
    exportDefault: 4,
    arrowFlowReturnType: 8,
    forInitHead: 16,
    forInHead: 32,
    forOfHead: 64,
    forInOrInitHeadAccumulate: 128,
    forInOrInitHeadAccumulatePassThroughMask: 128
  };
  for (const type of Object.keys(parens)) {
    const func = parens[type];
    if (_nodes.generatorInfosMap.has(type)) {
      _nodes.generatorInfosMap.get(type)[2] = func;
    }
  }
  function isOrHasCallExpression(node) {
    switch (node.type) {
      case "CallExpression":
        return true;
      case "MemberExpression":
        return isOrHasCallExpression(node.object);
    }
    return false;
  }
  function parentNeedsParens(node, parent, parentId) {
    switch (parentId) {
      case 112:
        if (parent.callee === node) {
          if (isOrHasCallExpression(node)) return true;
        }
        break;
      case 42:
        return !isDecoratorMemberExpression(node) && !(node.type === "CallExpression" && isDecoratorMemberExpression(node.callee)) && node.type !== "ParenthesizedExpression";
    }
    return false;
  }
  function isDecoratorMemberExpression(node) {
    switch (node.type) {
      case "Identifier":
        return true;
      case "MemberExpression":
        return !node.computed && node.property.type === "Identifier" && isDecoratorMemberExpression(node.object);
      default:
        return false;
    }
  }
  function isLastChild(parent, child) {
    const visitorKeys = VISITOR_KEYS[parent.type];
    for (let i = visitorKeys.length - 1; i >= 0; i--) {
      const val = parent[visitorKeys[i]];
      if (val === child) {
        return true;
      } else if (Array.isArray(val)) {
        let j = val.length - 1;
        while (j >= 0 && val[j] === null) j--;
        return j >= 0 && val[j] === child;
      } else if (val) {
        return false;
      }
    }
    return false;
  }
  
  //# sourceMappingURL=index.js.map