mm_tpl 2.4.3 → 2.4.5

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/tpl_rule.js CHANGED
@@ -2,9 +2,19 @@
2
2
 
3
3
  /**
4
4
  * 原生模板语法规则
5
+ * @type {Object}
5
6
  */
6
7
  var nativeRule = {
7
8
  test: /[ \t\r\n]*<!--\[(#?)((?:==|=#|[=-])?)[ \t]*([\w\W]*?)[ \t]*(-?)\]-->/,
9
+
10
+ /**
11
+ * 处理原生模板语法
12
+ * @param {string} match - 匹配的字符串
13
+ * @param {string} comment - 注释标记
14
+ * @param {string} output - 输出类型
15
+ * @param {string} code - 代码内容
16
+ * @returns {Object} 处理结果
17
+ */
8
18
  use: function use(match, comment, output, code /*, trimMode*/ ) {
9
19
  output = {
10
20
  '-': 'raw',
@@ -33,9 +43,19 @@ var nativeRule = {
33
43
 
34
44
  /**
35
45
  * 简洁模板语法规则
46
+ * @type {Object}
36
47
  */
37
48
  var artRule = {
38
49
  test: /[ \t\r\n]*\$\{([@#]?)[ \t]*(\/?)([\w\W]*?)[ \t]*\}/,
50
+
51
+ /**
52
+ * 处理简洁模板语法
53
+ * @param {string} match - 匹配的字符串
54
+ * @param {string} raw - 原始输出标记
55
+ * @param {string} close - 闭合标记
56
+ * @param {string} code - 代码内容
57
+ * @returns {Object} 处理结果
58
+ */
39
59
  use: function use(match, raw, close, code) {
40
60
  var compiler = this;
41
61
  var options = compiler.options;
@@ -51,7 +71,7 @@ var artRule = {
51
71
 
52
72
  // 旧版语法升级提示
53
73
  var warn = function warn(oldSyntax, newSyntax) {
54
- console.warn((options.filename || 'anonymous') + ':' + (match.line + 1) + ':' + (match.start + 1) + '\n' + (
74
+ $.log.warn((options.filename || 'anonymous') + ':' + (match.line + 1) + ':' + (match.start + 1) + '\n' + (
55
75
  'Template upgrade: ${' + oldSyntax + '} -> ${' + newSyntax + '}'));
56
76
  };
57
77
 
@@ -179,9 +199,11 @@ var artRule = {
179
199
  return result;
180
200
  },
181
201
 
182
- // 将多个 javascript 表达式拆分成组
183
- // 支持基本运算、三元表达式、取值、运行函数,不支持 `typeof value` 操作
184
- // 只支持 string、number、boolean、null、undefined 这几种类型声明,不支持 function、object、array
202
+ /**
203
+ * 将多个javascript表达式拆分成组
204
+ * @param {Array} esTokens - ES令牌数组
205
+ * @returns {Array} 分组后的表达式数组
206
+ */
185
207
  _split: function _split(esTokens) {
186
208
  esTokens = esTokens.filter(function(_ref) {
187
209
  var type = _ref.type;
@@ -220,28 +242,32 @@ var artRule = {
220
242
  };
221
243
 
222
244
  /**
223
- * html注释模板语法规则
245
+ * HTML注释模板语法规则
246
+ * @type {Object}
224
247
  */
225
248
  var htmlRule = Object.assign({}, artRule, {
226
249
  test: /[ \t\r\n]*<!--\{([@#]?)[ \t]*(\/?)([\w\W]*?)[ \t]*\}-->/
227
250
  });
228
251
 
229
252
  /**
230
- * js注释模板语法规则
253
+ * JS注释模板语法规则
254
+ * @type {Object}
231
255
  */
232
256
  var jsRule = Object.assign({}, artRule, {
233
257
  test: /[ \t\r\n]*\/\*\[([@#]?)[ \t]*(\/?)([\w\W]*?)[ \t]*\]\*\//
234
258
  });
235
259
 
236
260
  /**
237
- * python注释模板语法规则
261
+ * Python注释模板语法规则
262
+ * @type {Object}
238
263
  */
239
264
  var pyRule = Object.assign({}, artRule, {
240
265
  test: /[ \t\r\n]*##([@#]?)[ \t]*(\/?)([\w\W]*?)[ \t]*##/
241
266
  });
242
267
 
243
268
  /**
244
- * python注释模板语法规则
269
+ * Python三引号注释模板语法规则
270
+ * @type {Object}
245
271
  */
246
272
  var pyRule2 = Object.assign({}, artRule, {
247
273
  test: /"""#([@#]?)[ \t]*(\/?)([\w\W]*?)[ \t]*#"""/
@@ -255,3 +281,7 @@ module.exports = {
255
281
  pyRule,
256
282
  pyRule2
257
283
  };
284
+
285
+
286
+
287
+