UNPKG

519 BJavaScriptView Raw
1/**
2 * 语法糖
3 *
4 * @param {string} content 文本内容
5 */
6module.exports = function processor(content) {
7 return content.replace( // 处理注释模板
8 /\/\*#\*\/\s*function\s*\(\s*\)\s*\{\s*\/\*\!?([^]*?)\*\/[\s;]*\}/g,
9 function(all, text) {
10 return JSON.stringify(text);
11 }
12 ).replace(/\/\*,\*\/\s*(function(?:\s+[\w$_]+)?\s*\(\s*([^()]+)\s*\))/g, // 处理参数自识别
13 function(all, func, params) {
14 return '[' + params.replace(/([^\s,]+)/g, "'$&'") + '], ' + func;
15 }
16 );
17};