Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
80728 views
1
"use strict";
2
var Exception = require("../exception")["default"];
3
4
function SourceLocation(source, locInfo) {
5
this.source = source;
6
this.start = {
7
line: locInfo.first_line,
8
column: locInfo.first_column
9
};
10
this.end = {
11
line: locInfo.last_line,
12
column: locInfo.last_column
13
};
14
}
15
16
exports.SourceLocation = SourceLocation;function stripFlags(open, close) {
17
return {
18
open: open.charAt(2) === '~',
19
close: close.charAt(close.length-3) === '~'
20
};
21
}
22
23
exports.stripFlags = stripFlags;function stripComment(comment) {
24
return comment.replace(/^\{\{~?\!-?-?/, '')
25
.replace(/-?-?~?\}\}$/, '');
26
}
27
28
exports.stripComment = stripComment;function preparePath(data, parts, locInfo) {
29
/*jshint -W040 */
30
locInfo = this.locInfo(locInfo);
31
32
var original = data ? '@' : '',
33
dig = [],
34
depth = 0,
35
depthString = '';
36
37
for(var i=0,l=parts.length; i<l; i++) {
38
var part = parts[i].part;
39
original += (parts[i].separator || '') + part;
40
41
if (part === '..' || part === '.' || part === 'this') {
42
if (dig.length > 0) {
43
throw new Exception('Invalid path: ' + original, {loc: locInfo});
44
} else if (part === '..') {
45
depth++;
46
depthString += '../';
47
}
48
} else {
49
dig.push(part);
50
}
51
}
52
53
return new this.PathExpression(data, depth, dig, original, locInfo);
54
}
55
56
exports.preparePath = preparePath;function prepareMustache(path, params, hash, open, strip, locInfo) {
57
/*jshint -W040 */
58
// Must use charAt to support IE pre-10
59
var escapeFlag = open.charAt(3) || open.charAt(2),
60
escaped = escapeFlag !== '{' && escapeFlag !== '&';
61
62
return new this.MustacheStatement(path, params, hash, escaped, strip, this.locInfo(locInfo));
63
}
64
65
exports.prepareMustache = prepareMustache;function prepareRawBlock(openRawBlock, content, close, locInfo) {
66
/*jshint -W040 */
67
if (openRawBlock.path.original !== close) {
68
var errorNode = {loc: openRawBlock.path.loc};
69
70
throw new Exception(openRawBlock.path.original + " doesn't match " + close, errorNode);
71
}
72
73
locInfo = this.locInfo(locInfo);
74
var program = new this.Program([content], null, {}, locInfo);
75
76
return new this.BlockStatement(
77
openRawBlock.path, openRawBlock.params, openRawBlock.hash,
78
program, undefined,
79
{}, {}, {},
80
locInfo);
81
}
82
83
exports.prepareRawBlock = prepareRawBlock;function prepareBlock(openBlock, program, inverseAndProgram, close, inverted, locInfo) {
84
/*jshint -W040 */
85
// When we are chaining inverse calls, we will not have a close path
86
if (close && close.path && openBlock.path.original !== close.path.original) {
87
var errorNode = {loc: openBlock.path.loc};
88
89
throw new Exception(openBlock.path.original + ' doesn\'t match ' + close.path.original, errorNode);
90
}
91
92
program.blockParams = openBlock.blockParams;
93
94
var inverse,
95
inverseStrip;
96
97
if (inverseAndProgram) {
98
if (inverseAndProgram.chain) {
99
inverseAndProgram.program.body[0].closeStrip = close.strip;
100
}
101
102
inverseStrip = inverseAndProgram.strip;
103
inverse = inverseAndProgram.program;
104
}
105
106
if (inverted) {
107
inverted = inverse;
108
inverse = program;
109
program = inverted;
110
}
111
112
return new this.BlockStatement(
113
openBlock.path, openBlock.params, openBlock.hash,
114
program, inverse,
115
openBlock.strip, inverseStrip, close && close.strip,
116
this.locInfo(locInfo));
117
}
118
119
exports.prepareBlock = prepareBlock;
120