cnhis-design-vue 3.1.14-beta.14 → 3.1.14-beta.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/es/node_modules/@formily/path/esm/contexts.js +22 -0
- package/es/node_modules/@formily/path/esm/destructor.js +124 -0
- package/es/node_modules/@formily/path/esm/index.js +579 -0
- package/es/node_modules/@formily/path/esm/matcher.js +199 -0
- package/es/node_modules/@formily/path/esm/parser.js +402 -0
- package/es/node_modules/@formily/path/esm/shared.js +73 -0
- package/es/node_modules/@formily/path/esm/tokenizer.js +287 -0
- package/es/node_modules/@formily/path/esm/tokens.js +240 -0
- package/es/node_modules/@formily/path/esm/types.js +17 -0
- package/es/packages/form-render/src/components/renderer/combination.d.ts +6 -0
- package/es/packages/form-render/src/components/renderer/combination.js +53 -16
- package/es/packages/form-render/src/components/renderer/select.js +1 -2
- package/es/packages/form-render/src/components/renderer/simpleComponent.d.ts +1 -0
- package/es/packages/form-render/src/components/renderer/simpleComponent.js +4 -3
- package/es/packages/form-render/src/hooks/useFieldListAdaptor.js +1 -0
- package/es/packages/form-render/src/types/fieldItem.d.ts +1 -0
- package/es/packages/shortcut-provider/src/types/index.d.ts +11 -9
- package/es/packages/shortcut-provider/src/utils/index.js +5 -5
- package/es/packages/shortcut-setter/index.d.ts +3248 -1486
- package/es/packages/shortcut-setter/src/ShortcutSetter.js +9 -5
- package/es/packages/shortcut-setter/src/ShortcutSetter.vue.d.ts +3248 -1486
- package/es/packages/shortcut-setter/src/ShortcutSetterItem.js +24 -11
- package/es/packages/shortcut-setter/src/ShortcutSetterItem.vue.d.ts +1700 -1661
- package/global.d.ts +8 -8
- package/package.json +1 -1
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
import { isWildcardOperator, isExpandOperator, isDotOperator, isIdentifier, isIgnoreExpression, isDestructorExpression, isGroupExpression, isRangeExpression } from './types.js';
|
|
2
|
+
import { isEqual, toArr, isSegmentEqual } from './shared.js';
|
|
3
|
+
|
|
4
|
+
var Matcher = /** @class */ (function () {
|
|
5
|
+
function Matcher(tree, record) {
|
|
6
|
+
this.tree = tree;
|
|
7
|
+
this.stack = [];
|
|
8
|
+
this.excluding = false;
|
|
9
|
+
this.wildcards = [];
|
|
10
|
+
this.record = record;
|
|
11
|
+
}
|
|
12
|
+
Matcher.prototype.next = function (node, pos) {
|
|
13
|
+
var isLastToken = pos === this.path.length - 1;
|
|
14
|
+
// const isOverToken = pos > this.path.length
|
|
15
|
+
if (node.after) {
|
|
16
|
+
// if (isOverToken) {
|
|
17
|
+
// return false
|
|
18
|
+
// }
|
|
19
|
+
return this.matchNode(node.after, pos);
|
|
20
|
+
}
|
|
21
|
+
if (isWildcardOperator(node) && !node.filter) {
|
|
22
|
+
if (this.excluding) {
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
if (pos === 0 || node.optional)
|
|
27
|
+
return true;
|
|
28
|
+
return !!this.take(pos);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
if (isLastToken) {
|
|
32
|
+
return !!this.take(pos);
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
var wildcard = this.wildcards.pop();
|
|
36
|
+
if (wildcard && wildcard.after) {
|
|
37
|
+
return this.next(wildcard, pos);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return false;
|
|
41
|
+
};
|
|
42
|
+
Matcher.prototype.shot = function () {
|
|
43
|
+
var _a;
|
|
44
|
+
if (((_a = this.record) === null || _a === void 0 ? void 0 : _a.score) >= 0) {
|
|
45
|
+
this.record.score++;
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
Matcher.prototype.take = function (pos) {
|
|
49
|
+
var _a;
|
|
50
|
+
return String((_a = this.path[pos]) !== null && _a !== void 0 ? _a : '');
|
|
51
|
+
};
|
|
52
|
+
Matcher.prototype.matchExcludeIdentifier = function (matched, node, pos) {
|
|
53
|
+
var isLastToken = pos === this.path.length - 1;
|
|
54
|
+
var isContainToken = pos < this.path.length;
|
|
55
|
+
if (!node.after) {
|
|
56
|
+
this.excluding = false;
|
|
57
|
+
}
|
|
58
|
+
if (matched) {
|
|
59
|
+
if (node.after) {
|
|
60
|
+
return this.next(node, pos);
|
|
61
|
+
}
|
|
62
|
+
if (isLastToken) {
|
|
63
|
+
return false;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
if (isLastToken) {
|
|
67
|
+
return true;
|
|
68
|
+
}
|
|
69
|
+
return isContainToken;
|
|
70
|
+
};
|
|
71
|
+
Matcher.prototype.matchIdentifier = function (node, pos) {
|
|
72
|
+
var current = this.take(pos);
|
|
73
|
+
var matched = false;
|
|
74
|
+
if (isExpandOperator(node.after)) {
|
|
75
|
+
if (current.indexOf(node.value) === 0) {
|
|
76
|
+
this.shot();
|
|
77
|
+
matched = true;
|
|
78
|
+
}
|
|
79
|
+
if (this.excluding) {
|
|
80
|
+
return this.matchExcludeIdentifier(matched, node.after, pos);
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
return matched && this.next(node.after, pos);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
else if (current === node.value) {
|
|
87
|
+
this.shot();
|
|
88
|
+
matched = true;
|
|
89
|
+
}
|
|
90
|
+
if (this.excluding) {
|
|
91
|
+
return this.matchExcludeIdentifier(matched, node, pos);
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
return matched && this.next(node, pos);
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
Matcher.prototype.matchIgnoreExpression = function (node, pos) {
|
|
98
|
+
return isEqual(node.value, this.take(pos)) && this.next(node, pos);
|
|
99
|
+
};
|
|
100
|
+
Matcher.prototype.matchDestructorExpression = function (node, pos) {
|
|
101
|
+
return isEqual(node.source, this.take(pos)) && this.next(node, pos);
|
|
102
|
+
};
|
|
103
|
+
Matcher.prototype.matchExpandOperator = function (node, pos) {
|
|
104
|
+
return this.next(node, pos);
|
|
105
|
+
};
|
|
106
|
+
Matcher.prototype.matchWildcardOperator = function (node, pos) {
|
|
107
|
+
var matched = false;
|
|
108
|
+
if (node.filter) {
|
|
109
|
+
this.stack.push(node);
|
|
110
|
+
matched = this.matchNode(node.filter, pos);
|
|
111
|
+
this.stack.pop();
|
|
112
|
+
}
|
|
113
|
+
else {
|
|
114
|
+
matched = this.next(node, pos);
|
|
115
|
+
}
|
|
116
|
+
return matched;
|
|
117
|
+
};
|
|
118
|
+
Matcher.prototype.matchGroupExpression = function (node, pos) {
|
|
119
|
+
var _this = this;
|
|
120
|
+
var excluding = false;
|
|
121
|
+
if (node.isExclude) {
|
|
122
|
+
excluding = !this.excluding;
|
|
123
|
+
}
|
|
124
|
+
return toArr(node.value)[excluding ? 'every' : 'some'](function (item) {
|
|
125
|
+
_this.wildcards = _this.stack.slice();
|
|
126
|
+
_this.excluding = excluding;
|
|
127
|
+
return _this.matchNode(item, pos);
|
|
128
|
+
});
|
|
129
|
+
};
|
|
130
|
+
Matcher.prototype.matchRangeExpression = function (node, pos) {
|
|
131
|
+
var current = Number(this.take(pos));
|
|
132
|
+
if (node.start) {
|
|
133
|
+
if (node.end) {
|
|
134
|
+
return (current >= Number(node.start.value) &&
|
|
135
|
+
current <= Number(node.end.value));
|
|
136
|
+
}
|
|
137
|
+
else {
|
|
138
|
+
return current >= Number(node.start.value);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
else {
|
|
142
|
+
if (node.end) {
|
|
143
|
+
return current <= Number(node.end.value);
|
|
144
|
+
}
|
|
145
|
+
else {
|
|
146
|
+
this.wildcards = this.stack.slice();
|
|
147
|
+
return this.next(node, pos);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
};
|
|
151
|
+
Matcher.prototype.matchNode = function (node, pos) {
|
|
152
|
+
if (pos === void 0) { pos = 0; }
|
|
153
|
+
if (isDotOperator(node)) {
|
|
154
|
+
return this.next(node, pos + 1);
|
|
155
|
+
}
|
|
156
|
+
else if (isIdentifier(node)) {
|
|
157
|
+
return this.matchIdentifier(node, pos);
|
|
158
|
+
}
|
|
159
|
+
else if (isIgnoreExpression(node)) {
|
|
160
|
+
return this.matchIgnoreExpression(node, pos);
|
|
161
|
+
}
|
|
162
|
+
else if (isDestructorExpression(node)) {
|
|
163
|
+
return this.matchDestructorExpression(node, pos);
|
|
164
|
+
}
|
|
165
|
+
else if (isExpandOperator(node)) {
|
|
166
|
+
return this.matchExpandOperator(node, pos);
|
|
167
|
+
}
|
|
168
|
+
else if (isWildcardOperator(node)) {
|
|
169
|
+
return this.matchWildcardOperator(node, pos);
|
|
170
|
+
}
|
|
171
|
+
else if (isGroupExpression(node)) {
|
|
172
|
+
return this.matchGroupExpression(node, pos);
|
|
173
|
+
}
|
|
174
|
+
else if (isRangeExpression(node)) {
|
|
175
|
+
return this.matchRangeExpression(node, pos);
|
|
176
|
+
}
|
|
177
|
+
return false;
|
|
178
|
+
};
|
|
179
|
+
Matcher.prototype.match = function (path) {
|
|
180
|
+
this.path = path;
|
|
181
|
+
return { matched: this.matchNode(this.tree), record: this.record };
|
|
182
|
+
};
|
|
183
|
+
Matcher.matchSegments = function (source, target, record) {
|
|
184
|
+
if (source.length !== target.length)
|
|
185
|
+
return { matched: false, record: record };
|
|
186
|
+
var match = function (pos) {
|
|
187
|
+
if (pos === void 0) { pos = 0; }
|
|
188
|
+
var current = isSegmentEqual(source[pos], target[pos]);
|
|
189
|
+
if ((record === null || record === void 0 ? void 0 : record.score) >= 0) {
|
|
190
|
+
record.score++;
|
|
191
|
+
}
|
|
192
|
+
return current && (pos < source.length - 1 ? match(pos + 1) : true);
|
|
193
|
+
};
|
|
194
|
+
return { matched: match(), record: record };
|
|
195
|
+
};
|
|
196
|
+
return Matcher;
|
|
197
|
+
}());
|
|
198
|
+
|
|
199
|
+
export { Matcher };
|
|
@@ -0,0 +1,402 @@
|
|
|
1
|
+
import { Tokenizer } from './tokenizer.js';
|
|
2
|
+
import { eofTok, dotTok, bracketDLTok, starTok, dbStarTok, expandTok, nameTok, bracketLTok, braceLTok, bracketRTok, parenLTok, braceRTok, colonTok, parenRTok, bangTok, commaTok } from './tokens.js';
|
|
3
|
+
import { destructorContext, bracketArrayContext } from './contexts.js';
|
|
4
|
+
import { setDestructor, parseDestructorRules } from './destructor.js';
|
|
5
|
+
import { isNumberLike } from './shared.js';
|
|
6
|
+
|
|
7
|
+
var __extends = (undefined && undefined.__extends) || (function () {
|
|
8
|
+
var extendStatics = function (d, b) {
|
|
9
|
+
extendStatics = Object.setPrototypeOf ||
|
|
10
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
11
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
12
|
+
return extendStatics(d, b);
|
|
13
|
+
};
|
|
14
|
+
return function (d, b) {
|
|
15
|
+
if (typeof b !== "function" && b !== null)
|
|
16
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
17
|
+
extendStatics(d, b);
|
|
18
|
+
function __() { this.constructor = d; }
|
|
19
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
20
|
+
};
|
|
21
|
+
})();
|
|
22
|
+
var createTreeBySegments = function (segments, afterNode) {
|
|
23
|
+
if (segments === void 0) { segments = []; }
|
|
24
|
+
var segLen = segments.length;
|
|
25
|
+
var build = function (start) {
|
|
26
|
+
if (start === void 0) { start = 0; }
|
|
27
|
+
var after = start < segLen - 1 ? build(start + 1) : afterNode;
|
|
28
|
+
var dot = after && {
|
|
29
|
+
type: 'DotOperator',
|
|
30
|
+
after: after,
|
|
31
|
+
};
|
|
32
|
+
return {
|
|
33
|
+
type: 'Identifier',
|
|
34
|
+
value: segments[start],
|
|
35
|
+
after: dot,
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
return build();
|
|
39
|
+
};
|
|
40
|
+
var calculate = function (a, b, operator) {
|
|
41
|
+
if (isNumberLike(a) && isNumberLike(b)) {
|
|
42
|
+
if (operator === '+')
|
|
43
|
+
return String(Number(a) + Number(b));
|
|
44
|
+
if (operator === '-')
|
|
45
|
+
return String(Number(a) - Number(b));
|
|
46
|
+
if (operator === '*')
|
|
47
|
+
return String(Number(a) * Number(b));
|
|
48
|
+
if (operator === '/')
|
|
49
|
+
return String(Number(a) / Number(b));
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
if (operator === '+')
|
|
53
|
+
return String(a) + String(b);
|
|
54
|
+
if (operator === '-')
|
|
55
|
+
return 'NaN';
|
|
56
|
+
if (operator === '*')
|
|
57
|
+
return 'NaN';
|
|
58
|
+
if (operator === '/')
|
|
59
|
+
return 'NaN';
|
|
60
|
+
}
|
|
61
|
+
return String(Number(b));
|
|
62
|
+
};
|
|
63
|
+
var Parser = /** @class */ (function (_super) {
|
|
64
|
+
__extends(Parser, _super);
|
|
65
|
+
function Parser(input, base) {
|
|
66
|
+
var _this = _super.call(this, input) || this;
|
|
67
|
+
_this.isMatchPattern = false;
|
|
68
|
+
_this.isWildMatchPattern = false;
|
|
69
|
+
_this.haveExcludePattern = false;
|
|
70
|
+
_this.haveRelativePattern = false;
|
|
71
|
+
_this.base = base;
|
|
72
|
+
return _this;
|
|
73
|
+
}
|
|
74
|
+
Parser.prototype.parse = function () {
|
|
75
|
+
var node;
|
|
76
|
+
this.data = {
|
|
77
|
+
segments: [],
|
|
78
|
+
};
|
|
79
|
+
if (!this.eat(eofTok)) {
|
|
80
|
+
this.next();
|
|
81
|
+
node = this.parseAtom(this.state.type);
|
|
82
|
+
}
|
|
83
|
+
this.data.tree = node;
|
|
84
|
+
return node;
|
|
85
|
+
};
|
|
86
|
+
Parser.prototype.append = function (parent, node) {
|
|
87
|
+
if (parent && node) {
|
|
88
|
+
parent.after = node;
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
Parser.prototype.parseAtom = function (type) {
|
|
92
|
+
switch (type) {
|
|
93
|
+
case braceLTok:
|
|
94
|
+
case bracketLTok:
|
|
95
|
+
if (this.includesContext(destructorContext)) {
|
|
96
|
+
if (type === braceLTok) {
|
|
97
|
+
return this.parseObjectPattern();
|
|
98
|
+
}
|
|
99
|
+
else {
|
|
100
|
+
return this.parseArrayPattern();
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
return this.parseDestructorExpression();
|
|
104
|
+
case nameTok:
|
|
105
|
+
return this.parseIdentifier();
|
|
106
|
+
case expandTok:
|
|
107
|
+
return this.parseExpandOperator();
|
|
108
|
+
case dbStarTok:
|
|
109
|
+
case starTok:
|
|
110
|
+
return this.parseWildcardOperator();
|
|
111
|
+
case bracketDLTok:
|
|
112
|
+
return this.parseIgnoreExpression();
|
|
113
|
+
case dotTok:
|
|
114
|
+
return this.parseDotOperator();
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
Parser.prototype.pushSegments = function (key) {
|
|
118
|
+
this.data.segments.push(key);
|
|
119
|
+
};
|
|
120
|
+
Parser.prototype.parseIdentifier = function () {
|
|
121
|
+
var node = {
|
|
122
|
+
type: 'Identifier',
|
|
123
|
+
value: this.state.value,
|
|
124
|
+
};
|
|
125
|
+
var hasNotInDestructor = !this.includesContext(destructorContext) &&
|
|
126
|
+
!this.isMatchPattern &&
|
|
127
|
+
!this.isWildMatchPattern;
|
|
128
|
+
this.next();
|
|
129
|
+
if (this.includesContext(bracketArrayContext)) {
|
|
130
|
+
if (this.state.type !== bracketRTok) {
|
|
131
|
+
throw this.unexpect();
|
|
132
|
+
}
|
|
133
|
+
else {
|
|
134
|
+
this.state.context.pop();
|
|
135
|
+
this.next();
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
else if (hasNotInDestructor) {
|
|
139
|
+
this.pushSegments(node.value);
|
|
140
|
+
}
|
|
141
|
+
if (this.state.type === bracketLTok) {
|
|
142
|
+
this.next();
|
|
143
|
+
if (this.state.type !== nameTok) {
|
|
144
|
+
throw this.unexpect();
|
|
145
|
+
}
|
|
146
|
+
this.state.context.push(bracketArrayContext);
|
|
147
|
+
var isNumberKey = false;
|
|
148
|
+
if (/^\d+$/.test(this.state.value)) {
|
|
149
|
+
isNumberKey = true;
|
|
150
|
+
}
|
|
151
|
+
var value = this.state.value;
|
|
152
|
+
this.pushSegments(isNumberKey ? Number(value) : value);
|
|
153
|
+
var after = this.parseAtom(this.state.type);
|
|
154
|
+
if (isNumberKey) {
|
|
155
|
+
after.arrayIndex = true;
|
|
156
|
+
}
|
|
157
|
+
this.append(node, after);
|
|
158
|
+
}
|
|
159
|
+
else {
|
|
160
|
+
this.append(node, this.parseAtom(this.state.type));
|
|
161
|
+
}
|
|
162
|
+
return node;
|
|
163
|
+
};
|
|
164
|
+
Parser.prototype.parseExpandOperator = function () {
|
|
165
|
+
var node = {
|
|
166
|
+
type: 'ExpandOperator',
|
|
167
|
+
};
|
|
168
|
+
this.isMatchPattern = true;
|
|
169
|
+
this.isWildMatchPattern = true;
|
|
170
|
+
this.data.segments = [];
|
|
171
|
+
this.next();
|
|
172
|
+
this.append(node, this.parseAtom(this.state.type));
|
|
173
|
+
return node;
|
|
174
|
+
};
|
|
175
|
+
Parser.prototype.parseWildcardOperator = function () {
|
|
176
|
+
var node = {
|
|
177
|
+
type: 'WildcardOperator',
|
|
178
|
+
};
|
|
179
|
+
if (this.state.type === dbStarTok) {
|
|
180
|
+
node.optional = true;
|
|
181
|
+
}
|
|
182
|
+
this.isMatchPattern = true;
|
|
183
|
+
this.isWildMatchPattern = true;
|
|
184
|
+
this.data.segments = [];
|
|
185
|
+
this.next();
|
|
186
|
+
if (this.state.type === parenLTok) {
|
|
187
|
+
node.filter = this.parseGroupExpression(node);
|
|
188
|
+
}
|
|
189
|
+
else if (this.state.type === bracketLTok) {
|
|
190
|
+
node.filter = this.parseRangeExpression(node);
|
|
191
|
+
}
|
|
192
|
+
this.append(node, this.parseAtom(this.state.type));
|
|
193
|
+
return node;
|
|
194
|
+
};
|
|
195
|
+
Parser.prototype.parseDestructorExpression = function () {
|
|
196
|
+
var _this = this;
|
|
197
|
+
var node = {
|
|
198
|
+
type: 'DestructorExpression',
|
|
199
|
+
};
|
|
200
|
+
this.state.context.push(destructorContext);
|
|
201
|
+
var startPos = this.state.pos - 1;
|
|
202
|
+
node.value =
|
|
203
|
+
this.state.type === braceLTok
|
|
204
|
+
? this.parseObjectPattern()
|
|
205
|
+
: this.parseArrayPattern();
|
|
206
|
+
var endPos = this.state.pos;
|
|
207
|
+
this.state.context.pop();
|
|
208
|
+
node.source = this.input
|
|
209
|
+
.substring(startPos, endPos)
|
|
210
|
+
.replace(/\[\s*([\+\-\*\/])?\s*([^,\]\s]*)\s*\]/, function (match, operator, target) {
|
|
211
|
+
if (_this.relative !== undefined) {
|
|
212
|
+
if (operator) {
|
|
213
|
+
if (target) {
|
|
214
|
+
return calculate(_this.relative, target, operator);
|
|
215
|
+
}
|
|
216
|
+
else {
|
|
217
|
+
return calculate(_this.relative, 1, operator);
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
else {
|
|
221
|
+
if (target) {
|
|
222
|
+
return calculate(_this.relative, target, '+');
|
|
223
|
+
}
|
|
224
|
+
else {
|
|
225
|
+
return String(_this.relative);
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
return match;
|
|
230
|
+
})
|
|
231
|
+
.replace(/\s*\.\s*/g, '')
|
|
232
|
+
.replace(/\s*/g, '');
|
|
233
|
+
if (this.relative === undefined) {
|
|
234
|
+
setDestructor(node.source, parseDestructorRules(node));
|
|
235
|
+
}
|
|
236
|
+
this.relative = undefined;
|
|
237
|
+
this.pushSegments(node.source);
|
|
238
|
+
this.next();
|
|
239
|
+
this.append(node, this.parseAtom(this.state.type));
|
|
240
|
+
return node;
|
|
241
|
+
};
|
|
242
|
+
Parser.prototype.parseArrayPattern = function () {
|
|
243
|
+
var node = {
|
|
244
|
+
type: 'ArrayPattern',
|
|
245
|
+
elements: [],
|
|
246
|
+
};
|
|
247
|
+
this.next();
|
|
248
|
+
node.elements = this.parseArrayPatternElements();
|
|
249
|
+
return node;
|
|
250
|
+
};
|
|
251
|
+
Parser.prototype.parseArrayPatternElements = function () {
|
|
252
|
+
var nodes = [];
|
|
253
|
+
while (this.state.type !== bracketRTok && this.state.type !== eofTok) {
|
|
254
|
+
nodes.push(this.parseAtom(this.state.type));
|
|
255
|
+
if (this.state.type === bracketRTok) {
|
|
256
|
+
if (this.includesContext(destructorContext)) {
|
|
257
|
+
this.next();
|
|
258
|
+
}
|
|
259
|
+
return nodes;
|
|
260
|
+
}
|
|
261
|
+
this.next();
|
|
262
|
+
}
|
|
263
|
+
return nodes;
|
|
264
|
+
};
|
|
265
|
+
Parser.prototype.parseObjectPattern = function () {
|
|
266
|
+
var node = {
|
|
267
|
+
type: 'ObjectPattern',
|
|
268
|
+
properties: [],
|
|
269
|
+
};
|
|
270
|
+
this.next();
|
|
271
|
+
node.properties = this.parseObjectProperties();
|
|
272
|
+
return node;
|
|
273
|
+
};
|
|
274
|
+
Parser.prototype.parseObjectProperties = function () {
|
|
275
|
+
var nodes = [];
|
|
276
|
+
while (this.state.type !== braceRTok && this.state.type !== eofTok) {
|
|
277
|
+
var node = {
|
|
278
|
+
type: 'ObjectPatternProperty',
|
|
279
|
+
key: this.parseAtom(this.state.type),
|
|
280
|
+
};
|
|
281
|
+
nodes.push(node);
|
|
282
|
+
if (this.state.type === colonTok) {
|
|
283
|
+
this.next();
|
|
284
|
+
node.value = this.parseAtom(this.state.type);
|
|
285
|
+
}
|
|
286
|
+
if (this.state.type === braceRTok) {
|
|
287
|
+
if (this.includesContext(destructorContext)) {
|
|
288
|
+
this.next();
|
|
289
|
+
}
|
|
290
|
+
return nodes;
|
|
291
|
+
}
|
|
292
|
+
this.next();
|
|
293
|
+
}
|
|
294
|
+
return nodes;
|
|
295
|
+
};
|
|
296
|
+
Parser.prototype.parseDotOperator = function () {
|
|
297
|
+
var node = {
|
|
298
|
+
type: 'DotOperator',
|
|
299
|
+
};
|
|
300
|
+
var prevToken = this.type_;
|
|
301
|
+
if (!prevToken && this.base) {
|
|
302
|
+
if (this.base.isMatchPattern) {
|
|
303
|
+
throw new Error('Base path must be an absolute path.');
|
|
304
|
+
}
|
|
305
|
+
this.data.segments = this.base.toArr();
|
|
306
|
+
while (this.state.type === dotTok) {
|
|
307
|
+
this.relative = this.data.segments.pop();
|
|
308
|
+
this.haveRelativePattern = true;
|
|
309
|
+
this.next();
|
|
310
|
+
}
|
|
311
|
+
return createTreeBySegments(this.data.segments.slice(), this.parseAtom(this.state.type));
|
|
312
|
+
}
|
|
313
|
+
else {
|
|
314
|
+
this.next();
|
|
315
|
+
}
|
|
316
|
+
this.append(node, this.parseAtom(this.state.type));
|
|
317
|
+
return node;
|
|
318
|
+
};
|
|
319
|
+
Parser.prototype.parseIgnoreExpression = function () {
|
|
320
|
+
this.next();
|
|
321
|
+
var value = String(this.state.value).replace(/\s*/g, '');
|
|
322
|
+
var node = {
|
|
323
|
+
type: 'IgnoreExpression',
|
|
324
|
+
value: value,
|
|
325
|
+
};
|
|
326
|
+
this.pushSegments(value);
|
|
327
|
+
this.next();
|
|
328
|
+
this.append(node, this.parseAtom(this.state.type));
|
|
329
|
+
this.next();
|
|
330
|
+
return node;
|
|
331
|
+
};
|
|
332
|
+
Parser.prototype.parseGroupExpression = function (parent) {
|
|
333
|
+
var node = {
|
|
334
|
+
type: 'GroupExpression',
|
|
335
|
+
value: [],
|
|
336
|
+
};
|
|
337
|
+
this.isMatchPattern = true;
|
|
338
|
+
this.data.segments = [];
|
|
339
|
+
this.next();
|
|
340
|
+
loop: while (true) {
|
|
341
|
+
switch (this.state.type) {
|
|
342
|
+
case commaTok:
|
|
343
|
+
this.next();
|
|
344
|
+
break;
|
|
345
|
+
case bangTok:
|
|
346
|
+
node.isExclude = true;
|
|
347
|
+
this.haveExcludePattern = true;
|
|
348
|
+
this.next();
|
|
349
|
+
break;
|
|
350
|
+
case eofTok:
|
|
351
|
+
break loop;
|
|
352
|
+
case parenRTok:
|
|
353
|
+
break loop;
|
|
354
|
+
default:
|
|
355
|
+
node.value.push(this.parseAtom(this.state.type));
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
this.next();
|
|
359
|
+
this.append(parent, this.parseAtom(this.state.type));
|
|
360
|
+
return node;
|
|
361
|
+
};
|
|
362
|
+
Parser.prototype.parseRangeExpression = function (parent) {
|
|
363
|
+
var node = {
|
|
364
|
+
type: 'RangeExpression',
|
|
365
|
+
};
|
|
366
|
+
this.next();
|
|
367
|
+
this.isMatchPattern = true;
|
|
368
|
+
this.data.segments = [];
|
|
369
|
+
var start = false, hasColon = false;
|
|
370
|
+
loop: while (true) {
|
|
371
|
+
switch (this.state.type) {
|
|
372
|
+
case colonTok:
|
|
373
|
+
hasColon = true;
|
|
374
|
+
start = true;
|
|
375
|
+
this.next();
|
|
376
|
+
break;
|
|
377
|
+
case bracketRTok:
|
|
378
|
+
if (!hasColon && !node.end) {
|
|
379
|
+
node.end = node.start;
|
|
380
|
+
}
|
|
381
|
+
break loop;
|
|
382
|
+
case commaTok:
|
|
383
|
+
throw this.unexpect();
|
|
384
|
+
case eofTok:
|
|
385
|
+
break loop;
|
|
386
|
+
default:
|
|
387
|
+
if (!start) {
|
|
388
|
+
node.start = this.parseAtom(this.state.type);
|
|
389
|
+
}
|
|
390
|
+
else {
|
|
391
|
+
node.end = this.parseAtom(this.state.type);
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
this.next();
|
|
396
|
+
this.append(parent, this.parseAtom(this.state.type));
|
|
397
|
+
return node;
|
|
398
|
+
};
|
|
399
|
+
return Parser;
|
|
400
|
+
}(Tokenizer));
|
|
401
|
+
|
|
402
|
+
export { Parser };
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
var toString = Object.prototype.toString;
|
|
2
|
+
var isType = function (type) {
|
|
3
|
+
return function (obj) {
|
|
4
|
+
return toString.call(obj) === "[object ".concat(type, "]");
|
|
5
|
+
};
|
|
6
|
+
};
|
|
7
|
+
var isFn = isType('Function');
|
|
8
|
+
var isArr = Array.isArray || isType('Array');
|
|
9
|
+
var isStr = isType('String');
|
|
10
|
+
var isNum = isType('Number');
|
|
11
|
+
var isObj = function (val) { return typeof val === 'object'; };
|
|
12
|
+
var isRegExp = isType('RegExp');
|
|
13
|
+
var isNumberLike = function (t) {
|
|
14
|
+
return isNum(t) || /^(\d+)(\.\d+)?$/.test(t);
|
|
15
|
+
};
|
|
16
|
+
var isArray = isArr;
|
|
17
|
+
var keyList = Object.keys;
|
|
18
|
+
var hasProp = Object.prototype.hasOwnProperty;
|
|
19
|
+
var toArr = function (val) {
|
|
20
|
+
return Array.isArray(val) ? val : val !== undefined ? [val] : [];
|
|
21
|
+
};
|
|
22
|
+
var isEqual = function (a, b) {
|
|
23
|
+
if (a === b) {
|
|
24
|
+
return true;
|
|
25
|
+
}
|
|
26
|
+
if (a && b && typeof a === 'object' && typeof b === 'object') {
|
|
27
|
+
var arrA = isArray(a);
|
|
28
|
+
var arrB = isArray(b);
|
|
29
|
+
var i = void 0;
|
|
30
|
+
var length = void 0;
|
|
31
|
+
var key = void 0;
|
|
32
|
+
if (arrA && arrB) {
|
|
33
|
+
length = a.length;
|
|
34
|
+
if (length !== b.length) {
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
for (i = length; i-- !== 0;) {
|
|
38
|
+
if (!isEqual(a[i], b[i])) {
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return true;
|
|
43
|
+
}
|
|
44
|
+
if (arrA !== arrB) {
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
var keys = keyList(a);
|
|
48
|
+
length = keys.length;
|
|
49
|
+
if (length !== keyList(b).length) {
|
|
50
|
+
return false;
|
|
51
|
+
}
|
|
52
|
+
for (i = length; i-- !== 0;) {
|
|
53
|
+
if (!hasProp.call(b, keys[i])) {
|
|
54
|
+
return false;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
for (i = length; i-- !== 0;) {
|
|
58
|
+
key = keys[i];
|
|
59
|
+
if (!isEqual(a[key], b[key])) {
|
|
60
|
+
return false;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return true;
|
|
64
|
+
}
|
|
65
|
+
return a !== a && b !== b;
|
|
66
|
+
};
|
|
67
|
+
var isSegmentEqual = function (a, b) {
|
|
68
|
+
a = typeof a === 'symbol' ? a : "".concat(a);
|
|
69
|
+
b = typeof b === 'symbol' ? b : "".concat(b);
|
|
70
|
+
return a === b;
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
export { isArr, isEqual, isFn, isNum, isNumberLike, isObj, isRegExp, isSegmentEqual, isStr, toArr };
|