art-template 4.13.1 → 4.13.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +2 -2
- package/README.md +6 -12
- package/index.d.ts +109 -0
- package/lib/template-web.js +2 -2
- package/package.json +5 -4
- package/CHANGELOG.md +0 -212
- package/lib/compile/adapter/caches.js +0 -19
- package/lib/compile/adapter/extend.js +0 -37
- package/lib/compile/adapter/html-minifier.js +0 -29
- package/lib/compile/adapter/include.js +0 -21
- package/lib/compile/adapter/loader.js +0 -22
- package/lib/compile/adapter/onerror.js +0 -13
- package/lib/compile/adapter/resolve-filename.js +0 -36
- package/lib/compile/adapter/rule.art.js +0 -187
- package/lib/compile/adapter/rule.native.js +0 -34
- package/lib/compile/compiler.js +0 -470
- package/lib/compile/defaults.js +0 -95
- package/lib/compile/error.js +0 -60
- package/lib/compile/es-tokenizer.js +0 -26
- package/lib/compile/index.js +0 -136
- package/lib/compile/runtime.js +0 -98
- package/lib/compile/tpl-tokenizer.js +0 -98
- package/lib/defaults.js +0 -3
- package/lib/extension.js +0 -21
- package/lib/index.js +0 -26
- package/lib/precompile.js +0 -242
- package/lib/render.js +0 -16
- package/lib/runtime.js +0 -3
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var detectNode = typeof window === 'undefined';
|
|
4
|
-
var LOCAL_MODULE = /^\.+\//;
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* 获取模板的绝对路径
|
|
8
|
-
* @param {string} filename
|
|
9
|
-
* @param {Object} options
|
|
10
|
-
* @return {string}
|
|
11
|
-
*/
|
|
12
|
-
var resolveFilename = function resolveFilename(filename, options) {
|
|
13
|
-
/* istanbul ignore else */
|
|
14
|
-
if (detectNode) {
|
|
15
|
-
var path = require('path');
|
|
16
|
-
var root = options.root;
|
|
17
|
-
var extname = options.extname;
|
|
18
|
-
|
|
19
|
-
if (LOCAL_MODULE.test(filename)) {
|
|
20
|
-
var from = options.filename;
|
|
21
|
-
var self = !from || filename === from;
|
|
22
|
-
var base = self ? root : path.dirname(from);
|
|
23
|
-
filename = path.resolve(base, filename);
|
|
24
|
-
} else {
|
|
25
|
-
filename = path.resolve(root, filename);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
if (!path.extname(filename)) {
|
|
29
|
-
filename = filename + extname;
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
return filename;
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
module.exports = resolveFilename;
|
|
@@ -1,187 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* 简洁模板语法规则
|
|
5
|
-
*/
|
|
6
|
-
var artRule = {
|
|
7
|
-
test: /{{([@#]?)[ \t]*(\/?)([\w\W]*?)[ \t]*}}/,
|
|
8
|
-
use: function use(match, raw, close, code) {
|
|
9
|
-
var compiler = this;
|
|
10
|
-
var options = compiler.options;
|
|
11
|
-
var esTokens = compiler.getEsTokens(code);
|
|
12
|
-
var values = esTokens.map(function (token) {
|
|
13
|
-
return token.value;
|
|
14
|
-
});
|
|
15
|
-
var result = {};
|
|
16
|
-
|
|
17
|
-
var group = void 0;
|
|
18
|
-
var output = raw ? 'raw' : false;
|
|
19
|
-
var key = close + values.shift();
|
|
20
|
-
|
|
21
|
-
// 旧版语法升级提示
|
|
22
|
-
var warn = function warn(oldSyntax, newSyntax) {
|
|
23
|
-
console.warn((options.filename || 'anonymous') + ':' + (match.line + 1) + ':' + (match.start + 1) + '\n' + ('Template upgrade: {{' + oldSyntax + '}} -> {{' + newSyntax + '}}'));
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
// v3 compat: #value
|
|
27
|
-
if (raw === '#') {
|
|
28
|
-
warn('#value', '@value');
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
switch (key) {
|
|
32
|
-
case 'set':
|
|
33
|
-
code = 'var ' + values.join('').trim();
|
|
34
|
-
break;
|
|
35
|
-
|
|
36
|
-
case 'if':
|
|
37
|
-
code = 'if(' + values.join('').trim() + '){';
|
|
38
|
-
|
|
39
|
-
break;
|
|
40
|
-
|
|
41
|
-
case 'else':
|
|
42
|
-
var indexIf = values.indexOf('if');
|
|
43
|
-
|
|
44
|
-
if (~indexIf) {
|
|
45
|
-
values.splice(0, indexIf + 1);
|
|
46
|
-
code = '}else if(' + values.join('').trim() + '){';
|
|
47
|
-
} else {
|
|
48
|
-
code = '}else{';
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
break;
|
|
52
|
-
|
|
53
|
-
case '/if':
|
|
54
|
-
code = '}';
|
|
55
|
-
break;
|
|
56
|
-
|
|
57
|
-
case 'each':
|
|
58
|
-
group = artRule._split(esTokens);
|
|
59
|
-
group.shift();
|
|
60
|
-
|
|
61
|
-
if (group[1] === 'as') {
|
|
62
|
-
// ... v3 compat ...
|
|
63
|
-
warn('each object as value index', 'each object value index');
|
|
64
|
-
group.splice(1, 1);
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
var object = group[0] || '$data';
|
|
68
|
-
var value = group[1] || '$value';
|
|
69
|
-
var index = group[2] || '$index';
|
|
70
|
-
|
|
71
|
-
code = '$each(' + object + ',function(' + value + ',' + index + '){';
|
|
72
|
-
|
|
73
|
-
break;
|
|
74
|
-
|
|
75
|
-
case '/each':
|
|
76
|
-
code = '})';
|
|
77
|
-
break;
|
|
78
|
-
|
|
79
|
-
case 'block':
|
|
80
|
-
group = artRule._split(esTokens);
|
|
81
|
-
group.shift();
|
|
82
|
-
code = 'block(' + group.join(',').trim() + ',function(){';
|
|
83
|
-
break;
|
|
84
|
-
|
|
85
|
-
case '/block':
|
|
86
|
-
code = '})';
|
|
87
|
-
break;
|
|
88
|
-
|
|
89
|
-
case 'echo':
|
|
90
|
-
key = 'print';
|
|
91
|
-
warn('echo value', 'value');
|
|
92
|
-
case 'print':
|
|
93
|
-
case 'include':
|
|
94
|
-
case 'extend':
|
|
95
|
-
if (values.join('').trim().indexOf('(') !== 0) {
|
|
96
|
-
// 执行函数省略 `()` 与 `,`
|
|
97
|
-
group = artRule._split(esTokens);
|
|
98
|
-
group.shift();
|
|
99
|
-
code = key + '(' + group.join(',') + ')';
|
|
100
|
-
break;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
default:
|
|
104
|
-
if (~values.indexOf('|')) {
|
|
105
|
-
var v3split = ':'; // ... v3 compat ...
|
|
106
|
-
|
|
107
|
-
// 将过滤器解析成二维数组
|
|
108
|
-
var _group = esTokens.reduce(function (group, token) {
|
|
109
|
-
var value = token.value,
|
|
110
|
-
type = token.type;
|
|
111
|
-
|
|
112
|
-
if (value === '|') {
|
|
113
|
-
group.push([]);
|
|
114
|
-
} else if (type !== 'whitespace' && type !== 'comment') {
|
|
115
|
-
if (!group.length) {
|
|
116
|
-
group.push([]);
|
|
117
|
-
}
|
|
118
|
-
if (value === v3split && group[group.length - 1].length === 1) {
|
|
119
|
-
warn('value | filter: argv', 'value | filter argv');
|
|
120
|
-
} else {
|
|
121
|
-
group[group.length - 1].push(token);
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
return group;
|
|
125
|
-
}, []).map(function (g) {
|
|
126
|
-
return artRule._split(g);
|
|
127
|
-
});
|
|
128
|
-
|
|
129
|
-
// 将过滤器管道化
|
|
130
|
-
code = _group.reduce(function (accumulator, filter) {
|
|
131
|
-
var name = filter.shift();
|
|
132
|
-
filter.unshift(accumulator);
|
|
133
|
-
|
|
134
|
-
return '$imports.' + name + '(' + filter.join(',') + ')';
|
|
135
|
-
}, _group.shift().join(' ').trim());
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
output = output || 'escape';
|
|
139
|
-
|
|
140
|
-
break;
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
result.code = code;
|
|
144
|
-
result.output = output;
|
|
145
|
-
|
|
146
|
-
return result;
|
|
147
|
-
},
|
|
148
|
-
|
|
149
|
-
// 将多个 javascript 表达式拆分成组
|
|
150
|
-
// 支持基本运算、三元表达式、取值、运行函数,不支持 `typeof value` 操作
|
|
151
|
-
// 只支持 string、number、boolean、null、undefined 这几种类型声明,不支持 function、object、array
|
|
152
|
-
_split: function _split(esTokens) {
|
|
153
|
-
esTokens = esTokens.filter(function (_ref) {
|
|
154
|
-
var type = _ref.type;
|
|
155
|
-
|
|
156
|
-
return type !== 'whitespace' && type !== 'comment';
|
|
157
|
-
});
|
|
158
|
-
|
|
159
|
-
var current = 0;
|
|
160
|
-
var lastToken = esTokens.shift();
|
|
161
|
-
var punctuator = 'punctuator';
|
|
162
|
-
var close = /\]|\)/;
|
|
163
|
-
var group = [[lastToken]];
|
|
164
|
-
|
|
165
|
-
while (current < esTokens.length) {
|
|
166
|
-
var esToken = esTokens[current];
|
|
167
|
-
|
|
168
|
-
if (esToken.type === punctuator || lastToken.type === punctuator && !close.test(lastToken.value)) {
|
|
169
|
-
group[group.length - 1].push(esToken);
|
|
170
|
-
} else {
|
|
171
|
-
group.push([esToken]);
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
lastToken = esToken;
|
|
175
|
-
|
|
176
|
-
current++;
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
return group.map(function (g) {
|
|
180
|
-
return g.map(function (g) {
|
|
181
|
-
return g.value;
|
|
182
|
-
}).join('');
|
|
183
|
-
});
|
|
184
|
-
}
|
|
185
|
-
};
|
|
186
|
-
|
|
187
|
-
module.exports = artRule;
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* 原生模板语法规则
|
|
5
|
-
*/
|
|
6
|
-
var nativeRule = {
|
|
7
|
-
test: /<%(#?)((?:==|=#|[=-])?)[ \t]*([\w\W]*?)[ \t]*(-?)%>/,
|
|
8
|
-
use: function use(match, comment, output, code /*, trimMode*/) {
|
|
9
|
-
output = {
|
|
10
|
-
'-': 'raw',
|
|
11
|
-
'=': 'escape',
|
|
12
|
-
'': false,
|
|
13
|
-
// v3 compat: raw output
|
|
14
|
-
'==': 'raw',
|
|
15
|
-
'=#': 'raw'
|
|
16
|
-
}[output];
|
|
17
|
-
|
|
18
|
-
// ejs compat: comment tag
|
|
19
|
-
if (comment) {
|
|
20
|
-
code = '/*' + code + '*/';
|
|
21
|
-
output = false;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
// ejs compat: trims following newline
|
|
25
|
-
// if (trimMode) {}
|
|
26
|
-
|
|
27
|
-
return {
|
|
28
|
-
code: code,
|
|
29
|
-
output: output
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
module.exports = nativeRule;
|