-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhelpers.js
125 lines (101 loc) · 13.7 KB
/
helpers.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
'lang sweet.js';
const TypeCodes = {
Identifier: 0,
Keyword: 1,
Punctuator: 2,
NumericLiteral: 3,
StringLiteral: 4,
TemplateElement: 5,
Template: 6,
RegExp: 7
};
function check(obj, type) {
return obj && obj.type === 'RawSyntax' && obj.value.token.typeCode === type;
}
export function unwrap(obj) {
if (obj == null) return {};
if (obj.type === 'RawSyntax') {
if (obj.value.token.typeCode === TypeCodes.StringLiteral) {
return {
value: obj.value.token.str
};
} else if (obj.value.token.typeCode === TypeCodes.Template) {
return {
value: obj.value.token.items
};
} else {
return {
value: obj.value.token.value
};
}
} else if (obj.type === 'RawDelimiter') {
return {
value: obj.inner
};
}
return {};
}
export function isIdentifier(obj) {
return check(obj, TypeCodes.Identifier);
}
export function fromIdentifier(obj, x) {
return obj.value.fromIdentifier(x);
}
export function isKeyword(obj) {
return check(obj, TypeCodes.Keyword);
}
export function fromKeyword(obj, x) {
return obj.value.fromKeyword(x);
}
export function isPunctuator(obj) {
return check(obj, TypeCodes.Punctuator);
}
export function fromPunctuator(obj, x) {
return obj.value.fromPunctuator(x);
}
export function isNumericLiteral(obj) {
return check(obj, TypeCodes.NumericLiteral);
}
export function fromNumericLiteral(obj, x) {
return obj.value.fromNumber(x);
}
export function isStringLiteral(obj) {
return check(obj, TypeCodes.StringLiteral);
}
export function fromStringLiteral(obj, x) {
return obj.value.fromString(x);
}
export function isTemplateElement(obj) {
return check(obj, TypeCodes.TemplateElement);
}
export function isTemplate(obj) {
return check(obj, TypeCodes.Template);
}
export function isRegExp(obj) {
return check(obj, TypeCodes.RegExp);
}
export function isDelimiter(obj) {
return obj && obj.type === 'RawDelimiter';
}
export function isParens(obj) {
return obj && obj.type === 'RawDelimiter' && obj.kind === 'parens';
}
export function fromParens(obj, x) {
return obj.value.from('parens', x);
}
export function isBrackets(obj) {
return obj && obj.type === 'RawDelimiter' && obj.kind === 'brackets';
}
export function fromBrackets(obj, x) {
return obj.value.from('brackets', x);
}
export function isBraces(obj) {
return obj && obj.type === 'RawDelimiter' && obj.kind === 'braces';
}
export function fromBraces(obj, x) {
return obj.value.from('braces', x);
}
export function isSyntaxTemplate(obj) {
return obj && obj.type === 'RawDelimiter' && obj.kind === 'syntaxTemplate';
}
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInNyYy9oZWxwZXJzLmpzIl0sIm5hbWVzIjpbIlR5cGVDb2RlcyIsIklkZW50aWZpZXIiLCJLZXl3b3JkIiwiUHVuY3R1YXRvciIsIk51bWVyaWNMaXRlcmFsIiwiU3RyaW5nTGl0ZXJhbCIsIlRlbXBsYXRlRWxlbWVudCIsIlRlbXBsYXRlIiwiUmVnRXhwIiwiY2hlY2siLCJvYmoiLCJ0eXBlIiwidmFsdWUiLCJ0b2tlbiIsInR5cGVDb2RlIiwidW53cmFwIiwic3RyIiwiaXRlbXMiLCJpbm5lciIsImlzSWRlbnRpZmllciIsImZyb21JZGVudGlmaWVyIiwieCIsImlzS2V5d29yZCIsImZyb21LZXl3b3JkIiwiaXNQdW5jdHVhdG9yIiwiZnJvbVB1bmN0dWF0b3IiLCJpc051bWVyaWNMaXRlcmFsIiwiZnJvbU51bWVyaWNMaXRlcmFsIiwiZnJvbU51bWJlciIsImlzU3RyaW5nTGl0ZXJhbCIsImZyb21TdHJpbmdMaXRlcmFsIiwiZnJvbVN0cmluZyIsImlzVGV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