执行过npm install命令的vue-element-admin源码
康凯
2022-05-20 aa4c235a8ca67ea8b731f90c951a465e92c0a865
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
"use strict";
 
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
 
exports.__esModule = true;
exports.getIn = getIn;
exports.default = void 0;
 
var _propertyExpr = require("property-expr");
 
var _has = _interopRequireDefault(require("lodash/has"));
 
var trim = function trim(part) {
  return part.substr(0, part.length - 1).substr(1);
};
 
function getIn(schema, path, value, context) {
  var parent, lastPart, lastPartDebug; // if only one "value" arg then use it for both
 
  context = context || value;
  if (!path) return {
    parent: parent,
    parentPath: path,
    schema: schema.resolve({
      context: context,
      parent: parent,
      value: value
    })
  };
  (0, _propertyExpr.forEach)(path, function (_part, isBracket, isArray) {
    var part = isBracket ? trim(_part) : _part;
 
    if (isArray || (0, _has.default)(schema, '_subType')) {
      // we skipped an array: foo[].bar
      var idx = isArray ? parseInt(part, 10) : 0;
      schema = schema.resolve({
        context: context,
        parent: parent,
        value: value
      })._subType;
 
      if (value) {
        if (isArray && idx >= value.length) {
          throw new Error("Yup.reach cannot resolve an array item at index: " + _part + ", in the path: " + path + ". " + "because there is no value at that index. ");
        }
 
        value = value[idx];
      }
    }
 
    if (!isArray) {
      schema = schema.resolve({
        context: context,
        parent: parent,
        value: value
      });
      if (!(0, _has.default)(schema, 'fields') || !(0, _has.default)(schema.fields, part)) throw new Error("The schema does not contain the path: " + path + ". " + ("(failed at: " + lastPartDebug + " which is a type: \"" + schema._type + "\") "));
      schema = schema.fields[part];
      parent = value;
      value = value && value[part];
      lastPart = part;
      lastPartDebug = isBracket ? '[' + _part + ']' : '.' + _part;
    }
  });
 
  if (schema) {
    schema = schema.resolve({
      context: context,
      parent: parent,
      value: value
    });
  }
 
  return {
    schema: schema,
    parent: parent,
    parentPath: lastPart
  };
}
 
var reach = function reach(obj, path, value, context) {
  return getIn(obj, path, value, context).schema;
};
 
var _default = reach;
exports.default = _default;