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