art-template 4.12.1 → 4.13.2
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/CHANGELOG.md +17 -0
- package/README.md +18 -20
- package/index.d.ts +109 -0
- package/index.js +1 -1
- package/lib/compile/adapter/extend.js +1 -1
- package/lib/compile/adapter/html-minifier.js +5 -3
- package/lib/compile/adapter/loader.js +1 -1
- package/lib/compile/adapter/resolve-filename.js +3 -4
- package/lib/compile/adapter/rule.art.js +0 -14
- package/lib/compile/adapter/rule.native.js +0 -1
- package/lib/compile/compiler.js +284 -277
- package/lib/compile/defaults.js +3 -4
- package/lib/compile/error.js +1 -4
- package/lib/compile/index.js +0 -5
- package/lib/compile/runtime.js +7 -7
- package/lib/compile/tpl-tokenizer.js +53 -68
- package/lib/extension.js +2 -2
- package/lib/precompile.js +41 -48
- package/lib/template-web.js +3 -3
- package/package.json +11 -10
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,22 @@
|
|
|
1
1
|
# CHANGELOG
|
|
2
2
|
|
|
3
|
+
## v4.13.2
|
|
4
|
+
|
|
5
|
+
1. 修复 npm 包 index.d.ts 丢失的问题
|
|
6
|
+
|
|
7
|
+
## v4.13.1
|
|
8
|
+
|
|
9
|
+
1. 修复在某些情况 runtime 提示 window 未定义的问题 [#553](https://github.com/aui/art-template/issues/553)
|
|
10
|
+
|
|
11
|
+
## v4.13.0
|
|
12
|
+
|
|
13
|
+
1. 修复超大模板编译性能问题 [#539](https://github.com/aui/art-template/issues/539)、[#4](https://github.com/aui/express-art-template/issues/4)
|
|
14
|
+
2. 支持嵌套 block [#468](https://github.com/aui/art-template/issues/468)
|
|
15
|
+
|
|
16
|
+
## v4.12.2
|
|
17
|
+
|
|
18
|
+
1. 修复 [#483](https://github.com/aui/art-template/issues/483)
|
|
19
|
+
|
|
3
20
|
## v4.12.1
|
|
4
21
|
|
|
5
22
|
1. 修复过滤器不能使用包含空的格字符串参数的问题
|
package/README.md
CHANGED
|
@@ -6,34 +6,32 @@
|
|
|
6
6
|
[](https://travis-ci.org/aui/art-template)
|
|
7
7
|
[](https://coveralls.io/github/aui/art-template?branch=master)
|
|
8
8
|
|
|
9
|
-
art-template
|
|
9
|
+
[English document](https://aui.github.io/art-template/) | [中文文档](https://aui.github.io/art-template/zh-cn/index.html)
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
art-template is a simple and superfast templating engine that optimizes template rendering speed by scope pre-declared technique, hence achieving runtime performance which is close to the limits of JavaScript. At the same time, it supports both NodeJS and browser. [speed test online](https://aui.github.io/art-template/rendering-test/).
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
art-template 是一个简约、超快的模板引擎。它采用作用域预声明的技术来优化模板渲染速度,从而获得接近 JavaScript 极限的运行性能,并且同时支持 NodeJS 和浏览器。[在线速度测试](https://aui.github.io/art-template/rendering-test/)。
|
|
14
14
|
|
|
15
15
|
[](https://aui.github.io/art-template/rendering-test/)
|
|
16
16
|
|
|
17
|
+
## Feature
|
|
17
18
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
* 兼容 [EJS](http://ejs.co)、[Underscore](http://underscorejs.org/#template)、[LoDash](https://lodash.com/docs/#template) 模板语法
|
|
24
|
-
* 模板编译后的代码支持在严格模式下运行
|
|
25
|
-
* 支持 JavaScript 语句与模板语法混合书写
|
|
26
|
-
* 支持自定义模板的语法解析规则
|
|
27
|
-
* 浏览器版本仅 6KB 大小
|
|
28
|
-
|
|
29
|
-
[art-template@4 新特性介绍](https://github.com/aui/art-template/issues/369)
|
|
19
|
+
1. performance is close to the JavaScript rendering limits
|
|
20
|
+
2. debugging friendly. Syntax errors or runtime errors will be positioned accurately at which line of template. Support setting breakpoint in templating files (Webpack Loader)
|
|
21
|
+
3. support Express, Koa, Webpack
|
|
22
|
+
4. support template inheritance and sub template
|
|
23
|
+
5. browser version is only 6KB
|
|
30
24
|
|
|
31
|
-
##
|
|
25
|
+
## 特性
|
|
32
26
|
|
|
33
|
-
|
|
27
|
+
1. 拥有接近 JavaScript 渲染极限的的性能
|
|
28
|
+
2. 调试友好:语法、运行时错误日志精确到模板所在行;支持在模板文件上打断点(Webpack Loader)
|
|
29
|
+
5. 支持 Express、Koa、Webpack
|
|
30
|
+
6. 支持模板继承与子模板
|
|
31
|
+
7. 浏览器版本仅 6KB 大小
|
|
34
32
|
|
|
35
|
-
|
|
33
|
+
-----------------
|
|
36
34
|
|
|
37
|
-
|
|
35
|
+
[捐助我](https://cloud.githubusercontent.com/assets/1791748/25561320/09c9d6d0-2d9c-11e7-8689-1109f3f88f41.png)(微信支付)
|
|
38
36
|
|
|
39
|
-
|
|
37
|
+
[\[AD\] 前端招聘:在海边写代码](https://juejin.im/post/5a2651d06fb9a0451c3a40ad)
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
declare type artTemplateDefaults = {
|
|
2
|
+
/**
|
|
3
|
+
* template name
|
|
4
|
+
*/
|
|
5
|
+
filename?: string;
|
|
6
|
+
/**
|
|
7
|
+
* an array of rules of template syntax
|
|
8
|
+
*/
|
|
9
|
+
rules: any[];
|
|
10
|
+
/**
|
|
11
|
+
* whether to automatically encode output statements of template. Setting false will close that functionality
|
|
12
|
+
* escape can prevent XSS attacks
|
|
13
|
+
*/
|
|
14
|
+
excape: boolean;
|
|
15
|
+
/**
|
|
16
|
+
* enable debug mode. If true: {cache:false, minimize:false, compileDebug:true}
|
|
17
|
+
*/
|
|
18
|
+
debug: boolean;
|
|
19
|
+
/**
|
|
20
|
+
* if bail is set true, compilation errors and runtime errors will throw exception
|
|
21
|
+
*/
|
|
22
|
+
bail: boolean;
|
|
23
|
+
/**
|
|
24
|
+
* whether to enable caching
|
|
25
|
+
*/
|
|
26
|
+
cache: boolean;
|
|
27
|
+
/**
|
|
28
|
+
* whether to enable minimization. It will execute htmlMinifier and minimize HTML, CSS, JS
|
|
29
|
+
* if template contains unclosing tags, please don't open minimize. Otherwise unclosing tags will be restored or filtered
|
|
30
|
+
*/
|
|
31
|
+
minimize: boolean;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* whether to compile in debug mode
|
|
35
|
+
*/
|
|
36
|
+
compileDebug: boolean;
|
|
37
|
+
/**
|
|
38
|
+
* resolve template path
|
|
39
|
+
*/
|
|
40
|
+
resolveFilename: any;
|
|
41
|
+
/**
|
|
42
|
+
* sub template compilation adapter
|
|
43
|
+
*/
|
|
44
|
+
include: any,
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* HTML minifier. Work only in NodeJS environment
|
|
48
|
+
*/
|
|
49
|
+
htmlMinifier: any;
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* HTML minifier configuration. Refer to: https://github.com/kangax/html-minifier
|
|
53
|
+
*/
|
|
54
|
+
htmlMinifierOptions: {
|
|
55
|
+
collapseWhitespace: boolean,
|
|
56
|
+
minifyCSS: boolean,
|
|
57
|
+
minifyJS: boolean,
|
|
58
|
+
// automatically merged at runtime: rules.map(rule => rule.test)
|
|
59
|
+
ignoreCustomFragments: any[]
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* error events. Work only if bail is false
|
|
64
|
+
*/
|
|
65
|
+
onerror: any,
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* template file loader
|
|
69
|
+
*/
|
|
70
|
+
loader: any,
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* cache center adapter (depend on filename field)
|
|
74
|
+
*/
|
|
75
|
+
caches: any,
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* root directory of template. If filename field is not a local path, template will be found in root directory
|
|
79
|
+
* @default '/'
|
|
80
|
+
*/
|
|
81
|
+
root: string;
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* @default '.art'
|
|
85
|
+
* default extension. If no extensions, extname will be automatically added
|
|
86
|
+
*/
|
|
87
|
+
extname: string,
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* ignored variables. An array of template variables ignored by template compiler
|
|
91
|
+
*/
|
|
92
|
+
ignore: any[],
|
|
93
|
+
|
|
94
|
+
// imported template variables
|
|
95
|
+
imports: { [key: string]: Function }
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
*
|
|
99
|
+
* @param filenameOrTemplateId [ for bowser ] id of template [ for Node ] fileName of template
|
|
100
|
+
* @param content [ if is Object ] return compile result , [ if is string ] return compile Funtion
|
|
101
|
+
*/
|
|
102
|
+
declare function artTemplate(filenameOrTemplateId: string, content?: string | Object): any;
|
|
103
|
+
declare namespace artTemplate {
|
|
104
|
+
export const defaults: artTemplateDefaults;
|
|
105
|
+
export const extension: { [key: string]: Function };
|
|
106
|
+
function render(source: string, data: any, options?: any): string;
|
|
107
|
+
function compile(source: string, options?: any): (data: any) => string;
|
|
108
|
+
}
|
|
109
|
+
export = artTemplate;
|
package/index.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
|
|
4
|
+
|
|
5
|
+
var detectNode = typeof window === 'undefined';
|
|
4
6
|
|
|
5
7
|
/**
|
|
6
|
-
* HTML 压缩器
|
|
8
|
+
* HTML 压缩器
|
|
7
9
|
* @param {string} source
|
|
8
10
|
* @param {Object} options
|
|
9
11
|
* @return {string}
|
|
@@ -17,7 +19,7 @@ var htmlMinifier = function htmlMinifier(source, options) {
|
|
|
17
19
|
var ignoreCustomFragments = options.rules.map(function (rule) {
|
|
18
20
|
return rule.test;
|
|
19
21
|
});
|
|
20
|
-
(_htmlMinifierOptions$ = htmlMinifierOptions.ignoreCustomFragments).push.apply(_htmlMinifierOptions$, ignoreCustomFragments);
|
|
22
|
+
(_htmlMinifierOptions$ = htmlMinifierOptions.ignoreCustomFragments).push.apply(_htmlMinifierOptions$, _toConsumableArray(ignoreCustomFragments));
|
|
21
23
|
source = _htmlMinifier(source, htmlMinifierOptions);
|
|
22
24
|
}
|
|
23
25
|
|
|
@@ -1,16 +1,15 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var detectNode =
|
|
3
|
+
var detectNode = typeof window === 'undefined';
|
|
4
4
|
var LOCAL_MODULE = /^\.+\//;
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* 获取模板的绝对路径
|
|
8
|
-
* @param {string} filename
|
|
9
|
-
* @param {Object} options
|
|
8
|
+
* @param {string} filename
|
|
9
|
+
* @param {Object} options
|
|
10
10
|
* @return {string}
|
|
11
11
|
*/
|
|
12
12
|
var resolveFilename = function resolveFilename(filename, options) {
|
|
13
|
-
|
|
14
13
|
/* istanbul ignore else */
|
|
15
14
|
if (detectNode) {
|
|
16
15
|
var path = require('path');
|
|
@@ -6,7 +6,6 @@
|
|
|
6
6
|
var artRule = {
|
|
7
7
|
test: /{{([@#]?)[ \t]*(\/?)([\w\W]*?)[ \t]*}}/,
|
|
8
8
|
use: function use(match, raw, close, code) {
|
|
9
|
-
|
|
10
9
|
var compiler = this;
|
|
11
10
|
var options = compiler.options;
|
|
12
11
|
var esTokens = compiler.getEsTokens(code);
|
|
@@ -30,20 +29,16 @@ var artRule = {
|
|
|
30
29
|
}
|
|
31
30
|
|
|
32
31
|
switch (key) {
|
|
33
|
-
|
|
34
32
|
case 'set':
|
|
35
|
-
|
|
36
33
|
code = 'var ' + values.join('').trim();
|
|
37
34
|
break;
|
|
38
35
|
|
|
39
36
|
case 'if':
|
|
40
|
-
|
|
41
37
|
code = 'if(' + values.join('').trim() + '){';
|
|
42
38
|
|
|
43
39
|
break;
|
|
44
40
|
|
|
45
41
|
case 'else':
|
|
46
|
-
|
|
47
42
|
var indexIf = values.indexOf('if');
|
|
48
43
|
|
|
49
44
|
if (~indexIf) {
|
|
@@ -56,12 +51,10 @@ var artRule = {
|
|
|
56
51
|
break;
|
|
57
52
|
|
|
58
53
|
case '/if':
|
|
59
|
-
|
|
60
54
|
code = '}';
|
|
61
55
|
break;
|
|
62
56
|
|
|
63
57
|
case 'each':
|
|
64
|
-
|
|
65
58
|
group = artRule._split(esTokens);
|
|
66
59
|
group.shift();
|
|
67
60
|
|
|
@@ -80,19 +73,16 @@ var artRule = {
|
|
|
80
73
|
break;
|
|
81
74
|
|
|
82
75
|
case '/each':
|
|
83
|
-
|
|
84
76
|
code = '})';
|
|
85
77
|
break;
|
|
86
78
|
|
|
87
79
|
case 'block':
|
|
88
|
-
|
|
89
80
|
group = artRule._split(esTokens);
|
|
90
81
|
group.shift();
|
|
91
82
|
code = 'block(' + group.join(',').trim() + ',function(){';
|
|
92
83
|
break;
|
|
93
84
|
|
|
94
85
|
case '/block':
|
|
95
|
-
|
|
96
86
|
code = '})';
|
|
97
87
|
break;
|
|
98
88
|
|
|
@@ -102,7 +92,6 @@ var artRule = {
|
|
|
102
92
|
case 'print':
|
|
103
93
|
case 'include':
|
|
104
94
|
case 'extend':
|
|
105
|
-
|
|
106
95
|
if (values.join('').trim().indexOf('(') !== 0) {
|
|
107
96
|
// 执行函数省略 `()` 与 `,`
|
|
108
97
|
group = artRule._split(esTokens);
|
|
@@ -112,9 +101,7 @@ var artRule = {
|
|
|
112
101
|
}
|
|
113
102
|
|
|
114
103
|
default:
|
|
115
|
-
|
|
116
104
|
if (~values.indexOf('|')) {
|
|
117
|
-
|
|
118
105
|
var v3split = ':'; // ... v3 compat ...
|
|
119
106
|
|
|
120
107
|
// 将过滤器解析成二维数组
|
|
@@ -163,7 +150,6 @@ var artRule = {
|
|
|
163
150
|
// 支持基本运算、三元表达式、取值、运行函数,不支持 `typeof value` 操作
|
|
164
151
|
// 只支持 string、number、boolean、null、undefined 这几种类型声明,不支持 function、object、array
|
|
165
152
|
_split: function _split(esTokens) {
|
|
166
|
-
|
|
167
153
|
esTokens = esTokens.filter(function (_ref) {
|
|
168
154
|
var type = _ref.type;
|
|
169
155
|
|