-
-
Notifications
You must be signed in to change notification settings - Fork 487
/
ReferencesCollector.js
80 lines (72 loc) · 1.88 KB
/
ReferencesCollector.js
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
import { TrySplitVariableId } from '../../Resources/Util.js'
/**
* Visit property on actions and feedbacks, and collect any references used
*/
export class VisitorReferencesCollector {
/**
* Referenced instance labels
* @type {Set<string>}
* @access public
* @readonly
*/
connecionLabels
/**
* Referenced instance ids
* @type {Set<string>}
* @access public
* @readonly
*/
connectionIds
/**
* @param {Set<string> | undefined} foundConnectionIds
* @param {Set<string> | undefined} foundConnectionLabels
*/
constructor(foundConnectionIds, foundConnectionLabels) {
this.connecionLabels = foundConnectionLabels || new Set()
this.connectionIds = foundConnectionIds || new Set()
}
/**
* Visit an instance id property
* @param {Record<string, any>} obj
* @param {string} propName
* @param {string=} _feedbackId
*/
visitInstanceId(obj, propName, _feedbackId) {
this.connectionIds.add(obj[propName])
}
/**
* Visit an instance id array property
* @param {Record<string, any>} obj
* @param {string} propName
* @param {string=} _feedbackId
*/
visitInstanceIdArray(obj, propName, _feedbackId) {
for (const id of obj[propName]) {
this.connectionIds.add(id)
}
}
/**
* Visit a property containing variables
* @param {Record<string, any>} obj
* @param {string} propName
*/
visitString(obj, propName) {
const rawStr = obj[propName]
if (typeof rawStr !== 'string') return
// Everybody stand back. I know regular expressions. - xckd #208 /ck/kc/
const reg = /\$\(([^:$)]+):/g
const matches = rawStr.matchAll(reg)
for (const match of matches) {
this.connecionLabels.add(match[1])
}
}
/**
* Visit a variable name property
* @param {Record<string, any>} obj
* @param {string} propName
*/
visitVariableName(obj, propName) {
const label = TrySplitVariableId(obj[propName])
if (label) this.connecionLabels.add(label[0])
}
}