Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
80713 views
1
var AST = {
2
Program: function(statements, blockParams, strip, locInfo) {
3
this.loc = locInfo;
4
this.type = 'Program';
5
this.body = statements;
6
7
this.blockParams = blockParams;
8
this.strip = strip;
9
},
10
11
MustacheStatement: function(path, params, hash, escaped, strip, locInfo) {
12
this.loc = locInfo;
13
this.type = 'MustacheStatement';
14
15
this.path = path;
16
this.params = params || [];
17
this.hash = hash;
18
this.escaped = escaped;
19
20
this.strip = strip;
21
},
22
23
BlockStatement: function(path, params, hash, program, inverse, openStrip, inverseStrip, closeStrip, locInfo) {
24
this.loc = locInfo;
25
this.type = 'BlockStatement';
26
27
this.path = path;
28
this.params = params || [];
29
this.hash = hash;
30
this.program = program;
31
this.inverse = inverse;
32
33
this.openStrip = openStrip;
34
this.inverseStrip = inverseStrip;
35
this.closeStrip = closeStrip;
36
},
37
38
PartialStatement: function(name, params, hash, strip, locInfo) {
39
this.loc = locInfo;
40
this.type = 'PartialStatement';
41
42
this.name = name;
43
this.params = params || [];
44
this.hash = hash;
45
46
this.indent = '';
47
this.strip = strip;
48
},
49
50
ContentStatement: function(string, locInfo) {
51
this.loc = locInfo;
52
this.type = 'ContentStatement';
53
this.original = this.value = string;
54
},
55
56
CommentStatement: function(comment, strip, locInfo) {
57
this.loc = locInfo;
58
this.type = 'CommentStatement';
59
this.value = comment;
60
61
this.strip = strip;
62
},
63
64
SubExpression: function(path, params, hash, locInfo) {
65
this.loc = locInfo;
66
67
this.type = 'SubExpression';
68
this.path = path;
69
this.params = params || [];
70
this.hash = hash;
71
},
72
73
PathExpression: function(data, depth, parts, original, locInfo) {
74
this.loc = locInfo;
75
this.type = 'PathExpression';
76
77
this.data = data;
78
this.original = original;
79
this.parts = parts;
80
this.depth = depth;
81
},
82
83
StringLiteral: function(string, locInfo) {
84
this.loc = locInfo;
85
this.type = 'StringLiteral';
86
this.original =
87
this.value = string;
88
},
89
90
NumberLiteral: function(number, locInfo) {
91
this.loc = locInfo;
92
this.type = 'NumberLiteral';
93
this.original =
94
this.value = Number(number);
95
},
96
97
BooleanLiteral: function(bool, locInfo) {
98
this.loc = locInfo;
99
this.type = 'BooleanLiteral';
100
this.original =
101
this.value = bool === 'true';
102
},
103
104
Hash: function(pairs, locInfo) {
105
this.loc = locInfo;
106
this.type = 'Hash';
107
this.pairs = pairs;
108
},
109
HashPair: function(key, value, locInfo) {
110
this.loc = locInfo;
111
this.type = 'HashPair';
112
this.key = key;
113
this.value = value;
114
},
115
116
// Public API used to evaluate derived attributes regarding AST nodes
117
helpers: {
118
// a mustache is definitely a helper if:
119
// * it is an eligible helper, and
120
// * it has at least one parameter or hash segment
121
// TODO: Make these public utility methods
122
helperExpression: function(node) {
123
return !!(node.type === 'SubExpression' || node.params.length || node.hash);
124
},
125
126
scopedId: function(path) {
127
return (/^\.|this\b/).test(path.original);
128
},
129
130
// an ID is simple if it only has one part, and that part is not
131
// `..` or `this`.
132
simpleId: function(path) {
133
return path.parts.length === 1 && !AST.helpers.scopedId(path) && !path.depth;
134
}
135
}
136
};
137
138
139
// Must be exported as an object rather than the root of the module as the jison lexer
140
// must modify the object to operate properly.
141
export default AST;
142
143