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