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