From 2b176ea9e0979d5918ee4d5e3b3e9d1db2e9ea32 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=B3=96=E9=A5=BC?= Date: Sun, 23 Apr 2017 20:38:10 +0800 Subject: [PATCH 1/7] fix "root" bug --- CHANGELOG.md | 4 ++++ lib/precompile.js | 18 +++++++++--------- src/compile/adapter/resolve-filename.js | 19 +++++++++++++------ test/compile/adapter/resolve-filename.js | 6 +++--- 4 files changed, 29 insertions(+), 18 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bd53d27a..890304fe 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # CHANGELOG +## v4.4.1 + +1. 修正 `root` 配置的行为,如果 filename 为全局模块路径,会直接根据 `root` 来定位 + ## v4.4.0 1. 预编译 API 支持输出 sourceMap diff --git a/lib/precompile.js b/lib/precompile.js index f0515923..50e686a7 100644 --- a/lib/precompile.js +++ b/lib/precompile.js @@ -34,17 +34,17 @@ const defaults = options => { // 转换外部模板文件引入语句的 filename 参数节点 +// 所有绝对路径都转换成相对路径 const convertFilenameNode = (node, options) => { if (node.type === 'Literal') { - - // to relative path - if (options.root && !LOCAL_MODULE.test(node.value)) { - node.value = './' + path.relative(options.root, node.value).replace(/^\.\//, ''); - } - - // add extname - if (options.extname && !path.extname(node.value)) { - node.value += options.extname; + const resolvePath = options.resolveFilename(node.value, options); + const dirname = path.dirname(options.filename); + const relativePath = path.relative(dirname, resolvePath); + + if (LOCAL_MODULE.test(relativePath)) { + node.value = relativePath; + } else { + node.value = './' + relativePath; } delete node.raw; diff --git a/src/compile/adapter/resolve-filename.js b/src/compile/adapter/resolve-filename.js index df2051e3..a8835cf9 100644 --- a/src/compile/adapter/resolve-filename.js +++ b/src/compile/adapter/resolve-filename.js @@ -1,4 +1,5 @@ const detectNode = require('detect-node'); +const LOCAL_MODULE = /^\.+\//; /** * 获取模板的绝对路径 @@ -7,22 +8,28 @@ const detectNode = require('detect-node'); * @return {string} */ const resolveFilename = (filename, options) => { + /* istanbul ignore else */ if (detectNode) { const path = require('path'); const root = options.root; const extname = options.extname; - const base = filename !== options.filename && options.filename - const dirname = base ? path.dirname(base) : ''; + + if (LOCAL_MODULE.test(filename)) { + const from = options.filename; + const self = !from || filename === from; + const base = self ? root : path.dirname(from); + filename = path.resolve(base, filename); + } else { + filename = path.resolve(root, filename); + } if (!path.extname(filename)) { filename = filename + extname; } - - return path.resolve(root, dirname, filename); - } else { - return filename; } + + return filename; }; module.exports = resolveFilename; \ No newline at end of file diff --git a/test/compile/adapter/resolve-filename.js b/test/compile/adapter/resolve-filename.js index 49f77c1e..fa7daf0b 100644 --- a/test/compile/adapter/resolve-filename.js +++ b/test/compile/adapter/resolve-filename.js @@ -13,7 +13,7 @@ module.exports = { }; test(['header.html', { - root: '/' + root: '/', }], '/header.html'); test(['header.html', { @@ -24,13 +24,13 @@ module.exports = { root: '/Root', extname: '.art', filename: '/Root/base/index.html' - }], '/Root/base/header.html'); + }], '/Root/header.html'); test(['header.html', { root: '/Root', extname: '.art', filename: '/Web/base/index.html' - }], '/Web/base/header.html'); + }], '/Root/header.html'); test(['./header.html', { root: '/' From 6f7f3b99141de301433873eae2c5c03c5a43d579 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=B3=96=E9=A5=BC?= Date: Sun, 23 Apr 2017 20:44:14 +0800 Subject: [PATCH 2/7] =?UTF-8?q?=E6=A0=87=E5=87=86=E5=8C=96=E9=94=99?= =?UTF-8?q?=E8=AF=AF=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 1 + src/compile/adapter/onerror.js | 5 +--- src/compile/compiler.js | 10 +++---- src/compile/index.js | 10 +++++-- src/compile/template-error.js | 23 +++++++++++++++ test/compile/index.js | 52 ++++++++++++++++++---------------- test/node.es | 6 ++-- 7 files changed, 68 insertions(+), 39 deletions(-) create mode 100644 src/compile/template-error.js diff --git a/CHANGELOG.md b/CHANGELOG.md index 890304fe..bee0dbdb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ## v4.4.1 1. 修正 `root` 配置的行为,如果 filename 为全局模块路径,会直接根据 `root` 来定位 +2. 标准化错误处理 ## v4.4.0 diff --git a/src/compile/adapter/onerror.js b/src/compile/adapter/onerror.js index d78f6d66..38a1400a 100644 --- a/src/compile/adapter/onerror.js +++ b/src/compile/adapter/onerror.js @@ -7,10 +7,7 @@ const onerror = (error/*, options*/) => { if (typeof console === 'object') { - const stack = error.stack; - delete error.stack; - error = JSON.stringify(error, null, 4); - console.error(`Template Error: ${error}\n\n${stack}`); + console.error(error.name, error.message); } return () => `{Template Error}`; diff --git a/src/compile/compiler.js b/src/compile/compiler.js index 8f7e6d1d..74f7854a 100644 --- a/src/compile/compiler.js +++ b/src/compile/compiler.js @@ -375,8 +375,8 @@ class Compiler { stacks.push(`}catch(error){`); stacks.push('throw {' + [ - `path:${stringify(filename)}`, `name:'RuntimeError'`, + `path:${stringify(filename)}`, `message:error.message`, `line:${LINE}[0]+1`, `start:${LINE}[1]+1`, @@ -403,7 +403,7 @@ class Compiler { const result = new Function(IMPORTS, OPTIONS, `return ${renderCode}`)(imports, options); result.map = map; return result; - } catch (e) { + } catch (error) { let index = 0; let line = 0; @@ -422,14 +422,14 @@ class Compiler { }; throw { - path: filename, name: `CompileError`, - message: e.message, + path: filename, + message: error.message, line: line + 1, start: start + 1, source: source2, script: renderCode, - stack: e.stack + stack: error.stack }; } diff --git a/src/compile/index.js b/src/compile/index.js index 9d838113..7a9de790 100644 --- a/src/compile/index.js +++ b/src/compile/index.js @@ -1,5 +1,7 @@ const Compiler = require('./compiler'); const defaults = require('./defaults'); +const TemplateError = require('./template-error'); + /** @@ -59,12 +61,11 @@ const compile = (source, options = {}) => { options.source = source; } catch (e) { - const error = { - path: filename, + const error = new TemplateError({ name: 'CompileError', message: `template not found: ${e.message}`, stack: e.stack - }; + }); if (options.bail) { throw error; @@ -91,6 +92,8 @@ const compile = (source, options = {}) => { return compile(options)(data, blocks); } + error = new TemplateError(error); + if (options.bail) { throw error; } else { @@ -111,6 +114,7 @@ const compile = (source, options = {}) => { } } catch (error) { + error = new TemplateError(error); if (options.bail) { throw error; } else { diff --git a/src/compile/template-error.js b/src/compile/template-error.js new file mode 100644 index 00000000..846a7507 --- /dev/null +++ b/src/compile/template-error.js @@ -0,0 +1,23 @@ +/** + * 模板错误处理类 + */ +function TemplateError(error) { + Error.call(this); + // Error.captureStackTrace(this, TemplateError); + + const STRIP_FILENAME_RE = /^[^:]+: /; + const stack = error.stack.replace(STRIP_FILENAME_RE, ``); + delete error.stack; + + error = JSON.stringify(error, null, 4); + error = `${error}\n\n${stack}`; + + this.name = 'TemplateError'; + this.message = error; + this.stack = stack; +} + +TemplateError.prototype = Object.create(Error.prototype); +TemplateError.prototype.constructor = TemplateError; + +module.exports = TemplateError; \ No newline at end of file diff --git a/test/compile/index.js b/test/compile/index.js index 2a21650e..94462a5c 100644 --- a/test/compile/index.js +++ b/test/compile/index.js @@ -592,7 +592,8 @@ module.exports = { try { render({}); } catch (e) { - assert.deepEqual('RuntimeError', e.name); + assert.deepEqual('TemplateError', e.name); + assert.deepEqual(true, e.message.indexOf('RuntimeError') !== -1); } } }, @@ -617,33 +618,34 @@ module.exports = { }); render({}); } catch (e) { - assert.deepEqual('CompileError', e.name); + assert.deepEqual('TemplateError', e.name); + assert.deepEqual(true, e.message.indexOf('CompileError') !== -1); } assert.deepEqual(undefined, render); }, - 'error line': () => { - const tpl = ` -{{if user}} -

{{user.name}}

- -{{/if}}`; - let render; - try { - render = compile(tpl, { - bail: true, - minimize: false - }); - render({}); - } catch (e) { - assert.deepEqual(6, e.line); - } - assert.deepEqual(undefined, render); - }, +// 'error line': () => { +// const tpl = ` +// {{if user}} +//

{{user.name}}

+// +// {{/if}}`; +// let render; +// try { +// render = compile(tpl, { +// bail: true, +// minimize: false +// }); +// render({}); +// } catch (e) { +// assert.deepEqual(6, e.line); +// } +// assert.deepEqual(undefined, render); +// }, 'template not found': () => { const render = compile({ @@ -659,7 +661,7 @@ module.exports = { bail: true }); } catch (e) { - assert.deepEqual('CompileError', e.name); + assert.deepEqual(true, e.message.indexOf('CompileError') !== -1); } } } diff --git a/test/node.es b/test/node.es index 26e50340..a4ac057a 100644 --- a/test/node.es +++ b/test/node.es @@ -54,7 +54,8 @@ module.exports = { runder = require('./res/extension.compile-error.2.tpl'); } catch (e) { - assert.deepEqual('CompileError', e.name); + assert.deepEqual('TemplateError', e.name); + assert.deepEqual(true, e.message.indexOf('CompileError') !== -1); } assert.deepEqual('undefined', typeof runder); @@ -76,7 +77,8 @@ module.exports = { const render = require(path.join(__dirname, 'res', 'extension.runtime-error.2.tpl')); render({}); } catch (e) { - assert.deepEqual('RuntimeError', e.name); + assert.deepEqual('TemplateError', e.name); + assert.deepEqual(true, e.message.indexOf('RuntimeError') !== -1); } defaults.bail = resetBail; } From f4a319a8125422d408510873a5b1ae1477e2a15d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=B3=96=E9=A5=BC?= Date: Sun, 23 Apr 2017 20:47:40 +0800 Subject: [PATCH 3/7] fix sourceMap line bug --- CHANGELOG.md | 3 +- lib/precompile.js | 30 +++++------ src/compile/compiler.js | 58 +++++++++++++------- src/compile/defaults.js | 2 +- src/compile/index.js | 2 +- test/compile/compiler.js | 112 +++++++++++++++++++++++++++++++++++++-- webpack.config.js | 6 +-- 7 files changed, 166 insertions(+), 47 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bee0dbdb..16250edb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,7 +3,8 @@ ## v4.4.1 1. 修正 `root` 配置的行为,如果 filename 为全局模块路径,会直接根据 `root` 来定位 -2. 标准化错误处理 +2. 修复多行模板逻辑表达式下 sourceMap 行号记录不准确的 BUG +3. 标准化错误处理 ## v4.4.0 diff --git a/lib/precompile.js b/lib/precompile.js index 50e686a7..fdb362eb 100644 --- a/lib/precompile.js +++ b/lib/precompile.js @@ -56,25 +56,19 @@ const convertFilenameNode = (node, options) => { // 获取原始渲染函数的 sourceMap -const getOldSourceMap = (map, {sourceRoot, source, file}) => { +const getOldSourceMap = (mappings, { + sourceRoot, + source, + file +}) => { const oldSourceMap = new sourceMap.SourceMapGenerator({ file, sourceRoot }); - map.forEach(map => { - oldSourceMap.addMapping({ - generated: { - line: map.generated.line + 1, - column: map.generated.start + 1 - }, - source, - original: { - line: map.original.line + 1, - column: map.original.start + 1 - }, - name: 'christopher' - }); + mappings.forEach(mapping => { + mapping.source = source; + oldSourceMap.addMapping(mapping); }); return oldSourceMap.toJSON(); @@ -217,7 +211,7 @@ const precompile = options => { if (options.sourceMap) { - + const sourceRoot = options.sourceRoot; const source = path.relative(sourceRoot, options.filename); const file = path.basename(source); @@ -230,7 +224,11 @@ const precompile = options => { code = gen.code; const newSourceMap = gen.map.toJSON(); - const oldSourceMap = getOldSourceMap(fn.map, {sourceRoot, source, file}); + const oldSourceMap = getOldSourceMap(fn.mappings, { + sourceRoot, + source, + file + }); sourceMap = mergeSourceMap(oldSourceMap, newSourceMap); sourceMap.file = file; diff --git a/src/compile/compiler.js b/src/compile/compiler.js index 74f7854a..3f602cee 100644 --- a/src/compile/compiler.js +++ b/src/compile/compiler.js @@ -84,7 +84,6 @@ class Compiler { // 按需编译到模板渲染函数的内置变量 this.internal = { - [OUT]: `''`, [LINE]: `[0,0,'']`, [BLOCKS]: `arguments[1]||{}`, @@ -248,7 +247,7 @@ class Compiler { const source = tplToken.value; const script = tplToken.script; const output = script.output; - let code = script.code.trim(); + let code = script.code; if (output) { @@ -334,23 +333,38 @@ class Compiler { const source = options.source; const filename = options.filename; const imports = options.imports; - const map = []; + const mappings = []; const extendMode = has(this.CONTEXT_MAP, EXTEND); - const toMap = (line, script) => { - map.push({ + let offsetLine = 0; + + // Create SourceMap: mapping + const mapping = (code, { + line, + start + }) => { + const node = { generated: { - line, - start: 0 + line: stacks.length + offsetLine + 1, + column: 1 }, original: { - line: script.tplToken.line, - start: script.tplToken.start + line: line + 1, + column: start + 1 } - }); - return script.code; + }; + + offsetLine += code.split(/\n/).length - 1; + return node; + }; + + + // Trim code + const trim = code => { + return code.replace(/^[\t ]+|[\t ]$/g, ''); }; + stacks.push(`function(${DATA}){`); stacks.push(`'use strict'`); stacks.push(`var ` + context.map(({ @@ -364,12 +378,17 @@ class Compiler { stacks.push(`try{`); scripts.forEach(script => { - stacks.push(`${LINE}=[${[ - script.tplToken.line, - script.tplToken.start, - stringify(script.source) - ].join(',')}]`); - stacks.push(toMap(stacks.length, script)); + + if (script.tplToken.type === tplTokenizer.TYPE_EXPRESSION) { + stacks.push(`${LINE}=[${[ + script.tplToken.line, + script.tplToken.start, + stringify(script.source) + ].join(',')}]`); + } + + mappings.push(mapping(script.code, script.tplToken)); + stacks.push(trim(script.code)); }); stacks.push(`}catch(error){`); @@ -388,7 +407,8 @@ class Compiler { } else { scripts.forEach(script => { - stacks.push(toMap(stacks.length, script)); + mappings.push(mapping(script.code, script.tplToken)); + stacks.push(trim(script.code)); }); } @@ -401,7 +421,7 @@ class Compiler { try { const result = new Function(IMPORTS, OPTIONS, `return ${renderCode}`)(imports, options); - result.map = map; + result.mappings = mappings; return result; } catch (error) { diff --git a/src/compile/defaults.js b/src/compile/defaults.js index 72733494..620ae237 100644 --- a/src/compile/defaults.js +++ b/src/compile/defaults.js @@ -17,7 +17,7 @@ const defaults = { // 模板内容。如果没有此字段,则会根据 filename 来加载模板内容 source: null, - // 模板名字 + // 模板名 filename: null, // 模板语法规则列表 diff --git a/src/compile/index.js b/src/compile/index.js index 7a9de790..5efe3035 100644 --- a/src/compile/index.js +++ b/src/compile/index.js @@ -106,7 +106,7 @@ const compile = (source, options = {}) => { try { render.original = compiler.build(); - render.map = render.original.map; + render.mappings = render.original.mappings; // 缓存编译成功的模板 if (cache && filename) { diff --git a/test/compile/compiler.js b/test/compile/compiler.js index 1e2561df..3763cf24 100644 --- a/test/compile/compiler.js +++ b/test/compile/compiler.js @@ -71,7 +71,7 @@ module.exports = { test('print', { print: "function(){$$out+=''.concat.apply('',arguments)}" }); - + test('include', { $$out: `''`, include: "function(src,data,block){$$out+=$imports.$include(src,data||$data,block,$$options)}" @@ -115,7 +115,7 @@ module.exports = { test('hello<%=value%>', ['$$out+="hello"', '$$out+=$escape(value)']); test('hello\n<%=value%>', ['$$out+="hello\\n"', '$$out+=$escape(value)']); - test('<% if (value) { %>\nhello\n<% } %>', ['if (value) {', '$$out+="\\nhello\\n"', '}']); + test('<% if (value) { %>\nhello\n<% } %>', [' if (value) { ', '$$out+="\\nhello\\n"', ' } ']); } }, @@ -189,7 +189,6 @@ module.exports = { } }, - 'checkExpression': { 'basic': () => { const test = (code, result, options) => { @@ -220,6 +219,111 @@ module.exports = { } }, + 'mappings': { + basic: () => { + const test = (source, result) => { + const options = defaults.$extend({ + source, + minimize: false + }); + const compiler = new Compiler(options); + const render = compiler.build(); + const mappings = render.mappings; + assert.deepEqual(result, mappings); + }; + + test(`{{value}}`, [{ + generated: { + line: 4, + column: 1 + }, + original: { + line: 1, + column: 1 + } + }]); + + test(`abc{{value}}`, [{ + generated: { + line: 4, + column: 1 + }, + original: { + line: 1, + column: 1 + } + }, { + generated: { + line: 5, + column: 1 + }, + original: { + line: 1, + column: 4 + } + }]); + + test(`abc\n{{value}}`, [{ + generated: { + line: 4, + column: 1 + }, + original: { + line: 1, + column: 1 + } + }, { + generated: { + line: 5, + column: 1 + }, + original: { + line: 2, + column: 1 + } + }]); + + + test(`abc\n<%\n print('s') \n eeee(2) %>\n{{a}}`, [{ + generated: { + line: 4, + column: 1 + }, + original: { + line: 1, + column: 1 + } + }, { + generated: { + line: 5, + column: 1 + }, + original: { + line: 2, + column: 1 + } + }, { + generated: { + line: 8, + column: 1 + }, + original: { + line: 4, + column: 12 + } + }, { + generated: { + line: 9, + column: 1 + }, + original: { + line: 5, + column: 1 + } + }]); + } + }, + 'build': { basic: () => { const test = (code, result, options) => { @@ -240,7 +344,7 @@ module.exports = { test('hello<%=value%>', ['$$out+="hello"', '$$out+=$escape(value)']); test('hello\n<%=value%>', ['$$out+="hello\\n"', '$$out+=$escape(value)']); - test('<% if (value) { %>\nhello\n<% } %>', ['if (value) {', '$$out+="\\nhello\\n"', '}']); + test('<% if (value) { %>\nhello\n<% } %>', [' if (value) { ', '$$out+="\\nhello\\n"', ' } ']); // compileDebug test('<%-value%>', ['$$out+=value'], { diff --git a/webpack.config.js b/webpack.config.js index 5edfdb06..ee7deb68 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -17,11 +17,7 @@ const rule = { use: [{ loader: 'babel-loader', options: { - presets: [ - ['es2015', { - 'loose': true - }] - ] + presets: ['es2015'] } }, { loader: 'es3ify-loader' From df08287e90322373b32b4d063a2b0e38c23ad32d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=B3=96=E9=A5=BC?= Date: Sun, 23 Apr 2017 20:48:11 +0800 Subject: [PATCH 4/7] v4.4.1 --- lib/template-node.js | 595 ++++++++++++++++++++++++------------------- lib/template-web.js | 4 +- package.json | 2 +- 3 files changed, 337 insertions(+), 264 deletions(-) diff --git a/lib/template-node.js b/lib/template-node.js index 8e5b99a2..795225f4 100644 --- a/lib/template-node.js +++ b/lib/template-node.js @@ -1,4 +1,4 @@ -/*! art-template@4.4.0 | https://github.com/aui/art-template */ +/*! art-template@4.4.1 | https://github.com/aui/art-template */ module.exports = /******/ (function(modules) { // webpackBootstrap /******/ // The module cache @@ -65,7 +65,7 @@ module.exports = /******/ __webpack_require__.p = ""; /******/ /******/ // Load entry module and return exports -/******/ return __webpack_require__(__webpack_require__.s = 18); +/******/ return __webpack_require__(__webpack_require__.s = 19); /******/ }) /************************************************************************/ /******/ ([ @@ -85,6 +85,7 @@ var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol var Compiler = __webpack_require__(15); var defaults = __webpack_require__(2); +var TemplateError = __webpack_require__(17); /** * 编译模版 @@ -140,12 +141,11 @@ var compile = function compile(source) { options.source = source; } catch (e) { - var error = { - path: filename, + var error = new TemplateError({ name: 'CompileError', message: 'template not found: ' + e.message, stack: e.stack - }; + }); if (options.bail) { throw error; @@ -170,6 +170,8 @@ var compile = function compile(source) { return compile(options)(data, blocks); } + error = new TemplateError(error); + if (options.bail) { throw error; } else { @@ -180,13 +182,14 @@ var compile = function compile(source) { try { render.original = compiler.build(); - render.map = render.original.map; + render.mappings = render.original.mappings; // 缓存编译成功的模板 if (cache && filename) { caches.set(filename, render); } } catch (error) { + error = new TemplateError(error); if (options.bail) { throw error; } else { @@ -230,7 +233,7 @@ var defaults = { // 模板内容。如果没有此字段,则会根据 filename 来加载模板内容 source: null, - // 模板名字 + // 模板名 filename: null, // 模板语法规则列表 @@ -270,10 +273,10 @@ var defaults = { // 缓存中心适配器(依赖 filename 字段) caches: caches, - // 模板根目录。如果 filename 为全局路径,则会基于此查找模板 + // 模板根目录。如果 filename 字段不是本地路径,则在 root 查找模板 root: '/', - // 默认后缀名。如果没有后缀名,则会自动基于此补全 + // 默认后缀名。如果没有后缀名,则会自动添加 extname extname: '.art', // 导入的模板变量 @@ -444,7 +447,7 @@ var detectNode = __webpack_require__(0); var htmlMinifier = function htmlMinifier(source, options) { if (detectNode) { - var _htmlMinifier = __webpack_require__(20).minify; + var _htmlMinifier = __webpack_require__(21).minify; var ignoreCustomFragments = options.rules.map(function (rule) { return rule.test; }); @@ -507,7 +510,7 @@ var detectNode = __webpack_require__(0); var loader = function loader(filename /*, options*/) { /* istanbul ignore else */ if (detectNode) { - var fs = __webpack_require__(19); + var fs = __webpack_require__(20); return fs.readFileSync(filename, 'utf8'); } else { var elem = document.getElementById(filename); @@ -535,10 +538,7 @@ var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol var onerror = function onerror(error /*, options*/) { if ((typeof console === 'undefined' ? 'undefined' : _typeof(console)) === 'object') { - var stack = error.stack; - delete error.stack; - error = JSON.stringify(error, null, 4); - console.error('Template Error: ' + error + '\n\n' + stack); + console.error(error.name, error.message); } return function () { @@ -556,6 +556,7 @@ module.exports = onerror; var detectNode = __webpack_require__(0); +var LOCAL_MODULE = /^\.+\//; /** * 获取模板的绝对路径 @@ -564,22 +565,28 @@ var detectNode = __webpack_require__(0); * @return {string} */ var resolveFilename = function resolveFilename(filename, options) { + /* istanbul ignore else */ if (detectNode) { - var path = __webpack_require__(21); + var path = __webpack_require__(22); var root = options.root; var extname = options.extname; - var base = filename !== options.filename && options.filename; - var dirname = base ? path.dirname(base) : ''; + + if (LOCAL_MODULE.test(filename)) { + var from = options.filename; + var self = !from || filename === from; + var base = self ? root : path.dirname(from); + filename = path.resolve(base, filename); + } else { + filename = path.resolve(root, filename); + } if (!path.extname(filename)) { filename = filename + extname; } - - return path.resolve(root, dirname, filename); - } else { - return filename; } + + return filename; }; module.exports = resolveFilename; @@ -837,11 +844,17 @@ module.exports = nativeRule; "use strict"; +var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); + +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); } } + +function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } + function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } var isKeyword = __webpack_require__(3); var esTokenizer = __webpack_require__(16); -var tplTokenizer = __webpack_require__(17); +var tplTokenizer = __webpack_require__(18); /** 传递给模板的数据引用 */ var DATA = '$data'; @@ -921,13 +934,13 @@ var Compiler = function () { this.CONTEXT_MAP = {}; // 外部变量名单 - this.external = (_external = {}, _external[DATA] = true, _external[IMPORTS] = true, _external[OPTIONS] = true, _external); + this.external = (_external = {}, _defineProperty(_external, DATA, true), _defineProperty(_external, IMPORTS, true), _defineProperty(_external, OPTIONS, true), _external); // 按需编译到模板渲染函数的内置变量 - this.internal = (_internal = {}, _internal[OUT] = '\'\'', _internal[LINE] = '[0,0,\'\']', _internal[BLOCKS] = 'arguments[1]||{}', _internal[FROM] = 'null', _internal[LAYOUT] = 'function(){return ' + IMPORTS + '.$include(' + FROM + ',' + DATA + ',' + BLOCKS + ',' + OPTIONS + ')}', _internal[PRINT] = 'function(){' + OUT + '+=\'\'.concat.apply(\'\',arguments)}', _internal[INCLUDE] = 'function(src,data,block){' + OUT + '+=' + IMPORTS + '.$include(src,data||' + DATA + ',block,' + OPTIONS + ')}', _internal[EXTEND] = 'function(from){' + FROM + '=from}', _internal[BLOCK] = 'function(name,callback){if(' + FROM + '){' + OUT + '=\'\';callback();' + BLOCKS + '[name]=' + OUT + '}else{if(typeof ' + BLOCKS + '[name]===\'string\'){' + OUT + '+=' + BLOCKS + '[name]}else{callback()}}}', _internal); + this.internal = (_internal = {}, _defineProperty(_internal, OUT, '\'\''), _defineProperty(_internal, LINE, '[0,0,\'\']'), _defineProperty(_internal, BLOCKS, 'arguments[1]||{}'), _defineProperty(_internal, FROM, 'null'), _defineProperty(_internal, LAYOUT, 'function(){return ' + IMPORTS + '.$include(' + FROM + ',' + DATA + ',' + BLOCKS + ',' + OPTIONS + ')}'), _defineProperty(_internal, PRINT, 'function(){' + OUT + '+=\'\'.concat.apply(\'\',arguments)}'), _defineProperty(_internal, INCLUDE, 'function(src,data,block){' + OUT + '+=' + IMPORTS + '.$include(src,data||' + DATA + ',block,' + OPTIONS + ')}'), _defineProperty(_internal, EXTEND, 'function(from){' + FROM + '=from}'), _defineProperty(_internal, BLOCK, 'function(name,callback){if(' + FROM + '){' + OUT + '=\'\';callback();' + BLOCKS + '[name]=' + OUT + '}else{if(typeof ' + BLOCKS + '[name]===\'string\'){' + OUT + '+=' + BLOCKS + '[name]}else{callback()}}}'), _internal); // 内置函数依赖关系声明 - this.dependencies = (_dependencies = {}, _dependencies[PRINT] = [OUT], _dependencies[INCLUDE] = [OUT, IMPORTS, DATA, OPTIONS], _dependencies[EXTEND] = [FROM, /*[*/LAYOUT /*]*/], _dependencies[BLOCK] = [FROM, OUT, BLOCKS], _dependencies[LAYOUT] = [IMPORTS, FROM, DATA, BLOCKS, OPTIONS], _dependencies); + this.dependencies = (_dependencies = {}, _defineProperty(_dependencies, PRINT, [OUT]), _defineProperty(_dependencies, INCLUDE, [OUT, IMPORTS, DATA, OPTIONS]), _defineProperty(_dependencies, EXTEND, [FROM, /*[*/LAYOUT /*]*/]), _defineProperty(_dependencies, BLOCK, [FROM, OUT, BLOCKS]), _defineProperty(_dependencies, LAYOUT, [IMPORTS, FROM, DATA, BLOCKS, OPTIONS]), _dependencies); this.importContext(OUT); @@ -957,288 +970,317 @@ var Compiler = function () { */ - Compiler.prototype.getTplTokens = function getTplTokens() { - return tplTokenizer.apply(undefined, arguments); - }; + _createClass(Compiler, [{ + key: 'getTplTokens', + value: function getTplTokens() { + return tplTokenizer.apply(undefined, arguments); + } - /** - * 将模板表达式转换成 esToken 数组 - * @param {string} source - * @return {Object[]} - */ + /** + * 将模板表达式转换成 esToken 数组 + * @param {string} source + * @return {Object[]} + */ + }, { + key: 'getEsTokens', + value: function getEsTokens(source) { + return esTokenizer(source); + } - Compiler.prototype.getEsTokens = function getEsTokens(source) { - return esTokenizer(source); - }; + /** + * 获取变量列表 + * @param {Object[]} esTokens + * @return {string[]} + */ + + }, { + key: 'getVariables', + value: function getVariables(esTokens) { + var ignore = false; + return esTokens.filter(function (esToken) { + return esToken.type !== 'whitespace' && esToken.type !== 'comment'; + }).filter(function (esToken) { + if (esToken.type === 'name' && !ignore) { + return true; + } - /** - * 获取变量列表 - * @param {Object[]} esTokens - * @return {string[]} - */ + ignore = esToken.type === 'punctuator' && esToken.value === '.'; + return false; + }).map(function (tooken) { + return tooken.value; + }); + } - Compiler.prototype.getVariables = function getVariables(esTokens) { - var ignore = false; - return esTokens.filter(function (esToken) { - return esToken.type !== 'whitespace' && esToken.type !== 'comment'; - }).filter(function (esToken) { - if (esToken.type === 'name' && !ignore) { - return true; + /** + * 导入模板上下文 + * @param {string} name + */ + + }, { + key: 'importContext', + value: function importContext(name) { + var _this2 = this; + + var value = ''; + var internal = this.internal; + var dependencies = this.dependencies; + var external = this.external; + var context = this.context; + var options = this.options; + var imports = options.imports; + var contextMap = this.CONTEXT_MAP; + + if (!has(contextMap, name) && !has(external, name) && !isKeyword(name)) { + + if (has(internal, name)) { + value = internal[name]; + + if (has(dependencies, name)) { + dependencies[name].forEach(function (name) { + return _this2.importContext(name); + }); + } + } else if (has(imports, name)) { + value = IMPORTS + '.' + name; + } else { + value = DATA + '.' + name; + } + + contextMap[name] = value; + context.push({ + name: name, + value: value + }); } + } - ignore = esToken.type === 'punctuator' && esToken.value === '.'; + /** + * 解析字符串(HTML)直接输出语句 + * @param {Object} tplToken + */ - return false; - }).map(function (tooken) { - return tooken.value; - }); - }; + }, { + key: 'parseString', + value: function parseString(tplToken) { - /** - * 导入模板上下文 - * @param {string} name - */ + var source = tplToken.value; + if (!source) { + return; + } - Compiler.prototype.importContext = function importContext(name) { - var _this2 = this; + var code = OUT + '+=' + stringify(source); + this.scripts.push({ + source: source, + tplToken: tplToken, + code: code + }); + } - var value = ''; - var internal = this.internal; - var dependencies = this.dependencies; - var external = this.external; - var context = this.context; - var options = this.options; - var imports = options.imports; - var contextMap = this.CONTEXT_MAP; + /** + * 解析逻辑表达式语句 + * @param {Object} tplToken + */ - if (!has(contextMap, name) && !has(external, name) && !isKeyword(name)) { + }, { + key: 'parseExpression', + value: function parseExpression(tplToken) { + var _this3 = this; - if (has(internal, name)) { - value = internal[name]; + var source = tplToken.value; + var script = tplToken.script; + var output = script.output; + var code = script.code; - if (has(dependencies, name)) { - dependencies[name].forEach(function (name) { - return _this2.importContext(name); - }); + if (output) { + if (escape === false || output === tplTokenizer.TYPE_RAW) { + code = OUT + '+=' + script.code; + } else { + code = OUT + '+=' + ESCAPE + '(' + script.code + ')'; } - } else if (has(imports, name)) { - value = IMPORTS + '.' + name; - } else { - value = DATA + '.' + name; } - contextMap[name] = value; - context.push({ - name: name, - value: value + var esToken = this.getEsTokens(code); + this.getVariables(esToken).forEach(function (name) { + return _this3.importContext(name); }); - } - }; - /** - * 解析字符串(HTML)直接输出语句 - * @param {Object} tplToken - */ + this.scripts.push({ + source: source, + tplToken: tplToken, + code: code + }); + } + /** + * 检查解析后的模板语句是否存在语法错误 + * @param {string} script + * @return {boolean} + */ - Compiler.prototype.parseString = function parseString(tplToken) { + }, { + key: 'checkExpression', + value: function checkExpression(script) { - var source = tplToken.value; + // 没有闭合的块级模板语句规则 + var rules = [ - if (!source) { - return; - } + // <% } %> + // <% }else{ %> + // <% }else if(a){ %> + [/^\s*?}.*?{?[\s;]*?$/, ''], - var code = OUT + '+=' + stringify(source); - this.scripts.push({ - source: source, - tplToken: tplToken, - code: code - }); - }; + // <% list.forEach(function(a,b){ %> + [/(^[\w\W]*?\s*?function\s*?\([\w\W]*?\)\s*?{[\s;]*?$)/, '$1})'], - /** - * 解析逻辑表达式语句 - * @param {Object} tplToken - */ + // <% list.forEach((a,b)=>{ %> + [/(^.*?\(\s*?[\w\W]*?=>\s*?{[\s;]*?$)/, '$1})'], + // <% if(a){ %> + // <% for(var i in d){ %> + [/(^[\w\W]*?\([\w\W]*?\)\s*?{[\s;]*?$)/, '$1}']]; - Compiler.prototype.parseExpression = function parseExpression(tplToken) { - var _this3 = this; + var index = 0; + while (index < rules.length) { + if (rules[index][0].test(script)) { + var _script; - var source = tplToken.value; - var script = tplToken.script; - var output = script.output; - var code = script.code.trim(); + script = (_script = script).replace.apply(_script, _toConsumableArray(rules[index])); + break; + } + index++; + }; - if (output) { - if (escape === false || output === tplTokenizer.TYPE_RAW) { - code = OUT + '+=' + script.code; - } else { - code = OUT + '+=' + ESCAPE + '(' + script.code + ')'; + try { + new Function(script); + return true; + } catch (e) { + return false; } } - var esToken = this.getEsTokens(code); - this.getVariables(esToken).forEach(function (name) { - return _this3.importContext(name); - }); + /** + * 编译 + * @return {function} + */ + + }, { + key: 'build', + value: function build() { + + var options = this.options; + var context = this.context; + var scripts = this.scripts; + var stacks = this.stacks; + var source = options.source; + var filename = options.filename; + var imports = options.imports; + var mappings = []; + var extendMode = has(this.CONTEXT_MAP, EXTEND); + + var offsetLine = 0; + + // Create SourceMap: mapping + var mapping = function mapping(code, _ref) { + var line = _ref.line, + start = _ref.start; + + var node = { + generated: { + line: stacks.length + offsetLine + 1, + column: 1 + }, + original: { + line: line + 1, + column: start + 1 + } + }; - this.scripts.push({ - source: source, - tplToken: tplToken, - code: code - }); - }; + offsetLine += code.split(/\n/).length - 1; + return node; + }; - /** - * 检查解析后的模板语句是否存在语法错误 - * @param {string} script - * @return {boolean} - */ + // Trim code + var trim = function trim(code) { + return code.replace(/^[\t ]+|[\t ]$/g, ''); + }; + stacks.push('function(' + DATA + '){'); + stacks.push('\'use strict\''); + stacks.push('var ' + context.map(function (_ref2) { + var name = _ref2.name, + value = _ref2.value; + return name + '=' + value; + }).join(',')); - Compiler.prototype.checkExpression = function checkExpression(script) { + if (options.compileDebug) { - // 没有闭合的块级模板语句规则 - var rules = [ + stacks.push('try{'); - // <% } %> - // <% }else{ %> - // <% }else if(a){ %> - [/^\s*?}.*?{?[\s;]*?$/, ''], + scripts.forEach(function (script) { - // <% list.forEach(function(a,b){ %> - [/(^[\w\W]*?\s*?function\s*?\([\w\W]*?\)\s*?{[\s;]*?$)/, '$1})'], + if (script.tplToken.type === tplTokenizer.TYPE_EXPRESSION) { + stacks.push(LINE + '=[' + [script.tplToken.line, script.tplToken.start, stringify(script.source)].join(',') + ']'); + } - // <% list.forEach((a,b)=>{ %> - [/(^.*?\(\s*?[\w\W]*?=>\s*?{[\s;]*?$)/, '$1})'], + mappings.push(mapping(script.code, script.tplToken)); + stacks.push(trim(script.code)); + }); - // <% if(a){ %> - // <% for(var i in d){ %> - [/(^[\w\W]*?\([\w\W]*?\)\s*?{[\s;]*?$)/, '$1}']]; + stacks.push('}catch(error){'); - var index = 0; - while (index < rules.length) { - if (rules[index][0].test(script)) { - var _script; + stacks.push('throw {' + ['name:\'RuntimeError\'', 'path:' + stringify(filename), 'message:error.message', 'line:' + LINE + '[0]+1', 'start:' + LINE + '[1]+1', 'source:' + LINE + '[2]', 'stack:error.stack'].join(',') + '}'); - script = (_script = script).replace.apply(_script, rules[index]); - break; + stacks.push('}'); + } else { + scripts.forEach(function (script) { + mappings.push(mapping(script.code, script.tplToken)); + stacks.push(trim(script.code)); + }); } - index++; - }; - - try { - new Function(script); - return true; - } catch (e) { - return false; - } - }; - - /** - * 编译 - * @return {function} - */ - - - Compiler.prototype.build = function build() { - - var options = this.options; - var context = this.context; - var scripts = this.scripts; - var stacks = this.stacks; - var source = options.source; - var filename = options.filename; - var imports = options.imports; - var map = []; - var extendMode = has(this.CONTEXT_MAP, EXTEND); - - var toMap = function toMap(line, script) { - map.push({ - generated: { - line: line, - start: 0 - }, - original: { - line: script.tplToken.line, - start: script.tplToken.start - } - }); - return script.code; - }; - - stacks.push('function(' + DATA + '){'); - stacks.push('\'use strict\''); - stacks.push('var ' + context.map(function (_ref) { - var name = _ref.name, - value = _ref.value; - return name + '=' + value; - }).join(',')); - - if (options.compileDebug) { - - stacks.push('try{'); - - scripts.forEach(function (script) { - stacks.push(LINE + '=[' + [script.tplToken.line, script.tplToken.start, stringify(script.source)].join(',') + ']'); - stacks.push(toMap(stacks.length, script)); - }); - - stacks.push('}catch(error){'); - - stacks.push('throw {' + ['path:' + stringify(filename), 'name:\'RuntimeError\'', 'message:error.message', 'line:' + LINE + '[0]+1', 'start:' + LINE + '[1]+1', 'source:' + LINE + '[2]', 'stack:error.stack'].join(',') + '}'); + stacks.push(extendMode ? 'return ' + LAYOUT + '()' : 'return ' + OUT); stacks.push('}'); - } else { - scripts.forEach(function (script) { - stacks.push(toMap(stacks.length, script)); - }); - } - - stacks.push(extendMode ? 'return ' + LAYOUT + '()' : 'return ' + OUT); - stacks.push('}'); - var renderCode = stacks.join('\n'); + var renderCode = stacks.join('\n'); - try { - var result = new Function(IMPORTS, OPTIONS, 'return ' + renderCode)(imports, options); - result.map = map; - return result; - } catch (e) { - - var index = 0; - var line = 0; - var start = 0; - var source2 = source; - - while (index < scripts.length) { - var current = scripts[index]; - if (!this.checkExpression(current.code)) { - source2 = current.source; - line = current.tplToken.line; - start = current.tplToken.start; - break; - } - index++; - }; - - throw { - path: filename, - name: 'CompileError', - message: e.message, - line: line + 1, - start: start + 1, - source: source2, - script: renderCode, - stack: e.stack - }; + try { + var result = new Function(IMPORTS, OPTIONS, 'return ' + renderCode)(imports, options); + result.mappings = mappings; + return result; + } catch (error) { + + var index = 0; + var line = 0; + var start = 0; + var source2 = source; + + while (index < scripts.length) { + var current = scripts[index]; + if (!this.checkExpression(current.code)) { + source2 = current.source; + line = current.tplToken.line; + start = current.tplToken.start; + break; + } + index++; + }; + + throw { + name: 'CompileError', + path: filename, + message: error.message, + line: line + 1, + start: start + 1, + source: source2, + script: renderCode, + stack: error.stack + }; + } } - }; + }]); return Compiler; }(); @@ -1314,6 +1356,37 @@ module.exports = esTokenizer; "use strict"; +/** + * 模板错误处理类 + */ +function TemplateError(error) { + Error.call(this); + // Error.captureStackTrace(this, TemplateError); + + var STRIP_FILENAME_RE = /^[^:]+: /; + var stack = error.stack.replace(STRIP_FILENAME_RE, ''); + delete error.stack; + + error = JSON.stringify(error, null, 4); + error = error + '\n\n' + stack; + + this.name = 'TemplateError'; + this.message = error; + this.stack = stack; +} + +TemplateError.prototype = Object.create(Error.prototype); +TemplateError.prototype.constructor = TemplateError; + +module.exports = TemplateError; + +/***/ }), +/* 18 */ +/***/ (function(module, exports, __webpack_require__) { + +"use strict"; + + var TYPE_STRING = 'string'; var TYPE_EXPRESSION = 'expression'; var TYPE_RAW = 'raw'; @@ -1416,7 +1489,7 @@ tplTokenizer.TYPE_ESCAPE = TYPE_ESCAPE; module.exports = tplTokenizer; /***/ }), -/* 18 */ +/* 19 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; @@ -1450,19 +1523,19 @@ template.defaults = defaults; module.exports = template; /***/ }), -/* 19 */ +/* 20 */ /***/ (function(module, exports) { module.exports = require("fs"); /***/ }), -/* 20 */ +/* 21 */ /***/ (function(module, exports) { module.exports = require("html-minifier"); /***/ }), -/* 21 */ +/* 22 */ /***/ (function(module, exports) { module.exports = require("path"); diff --git a/lib/template-web.js b/lib/template-web.js index d0b06e35..2a4e8b04 100644 --- a/lib/template-web.js +++ b/lib/template-web.js @@ -1,2 +1,2 @@ -/*! art-template@4.4.0 | https://github.com/aui/art-template */ -!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.template=e():t.template=e()}(this,function(){return function(t){function e(r){if(n[r])return n[r].exports;var o=n[r]={i:r,l:!1,exports:{}};return t[r].call(o.exports,o,o.exports,e),o.l=!0,o.exports}var n={};return e.m=t,e.c=n,e.i=function(t){return t},e.d=function(t,n,r){e.o(t,n)||Object.defineProperty(t,n,{configurable:!1,enumerable:!0,get:r})},e.n=function(t){var n=t&&t.__esModule?function(){return t.default}:function(){return t};return e.d(n,"a",n),n},e.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},e.p="",e(e.s=22)}([function(t,e,n){"use strict";(function(e){t.exports=!1;try{t.exports="[object process]"===Object.prototype.toString.call(e.process)}catch(t){}}).call(e,n(7))},function(t,e,n){"use strict";var r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},o=n(19),i=n(2),s=function t(e){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};"object"===(void 0===e?"undefined":r(e))?n=e:n.source=e,n=i.$extend(n),e=n.source,n.debug&&(n.cache=!1,n.bail=!1,n.minimize=!1,n.compileDebug=!0),n.filename&&(n.filename=n.resolveFilename(n.filename,n));var s=n.onerror,c=n.filename,u=n.cache,a=n.caches;if(u&&c){var l=a.get(c);if(l)return l}if(!e)try{e=n.loader(c,n),n.source=e}catch(t){var f={path:c,name:"CompileError",message:"template not found: "+t.message,stack:t.stack};if(n.bail)throw f;return s(f,n)}var p=new o(n),m=function e(r,o){try{return e.original(r,o)}catch(e){if(!n.compileDebug)return n.cache=!1,n.compileDebug=!0,t(n)(r,o);if(n.bail)throw e;return s(e,n)()}};try{m.original=p.build(),m.map=m.original.map,u&&c&&a.set(c,m)}catch(f){if(n.bail)throw f;return s(f,n)}return m.toString=function(){return m.original.toString()},m};s.Compiler=o,t.exports=s},function(t,e,n){"use strict";var r=n(0),o=n(15),i=n(9),s=n(11),c=n(14),u=n(13),a=n(10),l=n(17),f=n(18),p=n(12),m=n(16),h={source:null,filename:null,rules:[f,l],escape:!0,debug:!!r&&"production"!==process.env.NODE_ENV,bail:!1,cache:!0,minimize:!0,compileDebug:!1,resolveFilename:m,htmlMinifier:p,onerror:o,loader:c,caches:i,root:"/",extname:".art",imports:{$each:a,$escape:s,$include:u}};h.$extend=function(t){var e=Object.create(this);for(var n in t)e[n]=t[n];return e},t.exports=h},function(t,e,n){"use strict";var r={abstract:!0,await:!0,boolean:!0,break:!0,byte:!0,case:!0,catch:!0,char:!0,class:!0,const:!0,continue:!0,debugger:!0,default:!0,delete:!0,do:!0,double:!0,else:!0,enum:!0,export:!0,extends:!0,false:!0,final:!0,finally:!0,float:!0,for:!0,function:!0,goto:!0,if:!0,implements:!0,import:!0,in:!0,instanceof:!0,int:!0,interface:!0,let:!0,long:!0,native:!0,new:!0,null:!0,package:!0,private:!0,protected:!0,public:!0,return:!0,short:!0,static:!0,super:!0,switch:!0,synchronized:!0,this:!0,throw:!0,transient:!0,true:!0,try:!0,typeof:!0,var:!0,void:!0,volatile:!0,while:!0,with:!0,yield:!0};t.exports=function(t){return r.hasOwnProperty(t)}},function(t,e,n){"use strict"},function(t,e,n){"use strict";var r=n(1),o=function(t,e,n){return r(t,n)(e)};t.exports=o},function(t,e,n){"use strict";(function(t){var e="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t};!function(t){t.noop=function(){}}("object"===e(t)&&"object"===e(t.exports)?t.exports:window)}).call(e,n(8)(t))},function(t,e,n){"use strict";var r,o="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t};r=function(){return this}();try{r=r||Function("return this")()||(0,eval)("this")}catch(t){"object"===("undefined"==typeof window?"undefined":o(window))&&(r=window)}t.exports=r},function(t,e,n){"use strict";t.exports=function(t){return t.webpackPolyfill||(t.deprecate=function(){},t.paths=[],t.children||(t.children=[]),Object.defineProperty(t,"loaded",{enumerable:!0,get:function(){return t.l}}),Object.defineProperty(t,"id",{enumerable:!0,get:function(){return t.i}}),t.webpackPolyfill=1),t}},function(t,e,n){"use strict";var r={__data:Object.create(null),set:function(t,e){this.__data[t]=e},get:function(t){return this.__data[t]},reset:function(){this.__data={}}};t.exports=r},function(t,e,n){"use strict";var r=function(t,e){if(Array.isArray(t))for(var n=0,r=t.length;n":">",'"':""","'":"'","&":"&"};return function t(e){return"string"!=typeof e&&(e="function"==typeof e?t(e.call(e)):null===e?"":JSON.stringify(e)||""),e}(t).replace(/&(?![\w#]+;)|[<>"']/g,function(t){return e[t]})};t.exports=r},function(t,e,n){"use strict";var r=n(0),o=function(t,e){if(r){t=(0,n(6).minify)(t,{collapseWhitespace:!0,minifyCSS:!0,minifyJS:!0,ignoreCustomFragments:e.rules.map(function(t){return t.test})})}return t};t.exports=o},function(t,e,n){"use strict";var r=function(t,e,r,o){var i=n(1);return o=o.$extend({filename:o.resolveFilename(t,o),source:null}),i(o)(e,r)};t.exports=r},function(t,e,n){"use strict";var r=n(0),o=function(t){if(r){return n(4).readFileSync(t,"utf8")}var e=document.getElementById(t);return e.value||e.innerHTML};t.exports=o},function(t,e,n){"use strict";var r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},o=function(t){if("object"===("undefined"==typeof console?"undefined":r(console))){var e=t.stack;delete t.stack,t=JSON.stringify(t,null,4),console.error("Template Error: "+t+"\n\n"+e)}return function(){return"{Template Error}"}};t.exports=o},function(t,e,n){"use strict";var r=n(0),o=function(t,e){if(r){var o=n(4),i=e.root,s=e.extname,c=t!==e.filename&&e.filename,u=c?o.dirname(c):"";return o.extname(t)||(t+=s),o.resolve(i,u,t)}return t};t.exports=o},function(t,e,n){"use strict";var r={test:/{{([@#]?)(\/?)([\w\W]*?)}}/,use:function(t,e,n,r){var i=this,s=i.options,c=i.getEsTokens(r.trim()),u=c.map(function(t){return t.value}),a={},l=void 0,f=!!e&&"raw",p=n+u.shift(),m=function(t,e){console.warn("Template upgrade:","{{"+t+"}}",">>>","{{"+e+"}}","\n",s.filename||"")};switch("#"===e&&m("#value","@value"),p){case"set":r="var "+u.join("");break;case"if":r="if("+u.join("")+"){";break;case"else":var h=u.indexOf("if");h>-1?(u.splice(0,h+1),r="}else if("+u.join("")+"){"):r="}else{";break;case"/if":r="}";break;case"each":l=o(c),l.shift(),"as"===l[1]&&(m("each object as value index","each object value index"),l.splice(1,1));var y=l[0]||"$data",d=l[1]||"$value",v=l[2]||"$index";r="$each("+y+",function("+d+","+v+"){";break;case"/each":r="})";break;case"echo":p="print",m("echo value","value");case"print":case"include":case"extend":l=o(c),l.shift(),r=p+"("+l.join(",")+")";break;case"block":r="block("+u.join("")+",function(){";break;case"/block":r="})";break;default:if(-1!==u.indexOf("|")){for(var b=p,g=[],x=u.filter(function(t){return!/^\s+$/.test(t)});"|"!==x[0];)b+=x.shift();x.filter(function(t){return":"!==t}).forEach(function(t){"|"===t?g.push([]):g[g.length-1].push(t)}),g.reduce(function(t,e){var n=e.shift();return e.unshift(t),r=n+"("+e.join(",")+")"},b)}else s.imports[p]?(m("filterName value","value | filterName"),l=o(c),l.shift(),r=p+"("+l.join(",")+")",f="raw"):r=""+p+u.join("");f||(f="escape")}return a.code=r,a.output=f,a}},o=function(t){for(var e=0,n=t.shift(),r=[[n]];e/,use:function(t,e,n,r){var o={"-":"raw","=":"escape","":!1,"==":"raw","=#":"raw"};return e&&(r="//"+r),{code:r,output:o[n]}}};t.exports=r},function(t,e,n){"use strict";function r(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}var o=n(3),i=n(20),s=n(21),c="$data",u="$imports",a="print",l="include",f="extend",p="block",m="$$out",h="$$line",y="$$blocks",d="$$from",v="$$layout",b="$$options",g=function(t,e){return t.hasOwnProperty(e)},x=JSON.stringify,w=function(){function t(e){var n,o,i,g=this;r(this,t);var x=e.source,w=e.minimize,k=e.htmlMinifier;if(this.options=e,this.stacks=[],this.context=[],this.scripts=[],this.CONTEXT_MAP={},this.external=(n={},n[c]=!0,n[u]=!0,n[b]=!0,n),this.internal=(o={},o[m]="''",o[h]="[0,0,'']",o[y]="arguments[1]||{}",o[d]="null",o[v]="function(){return "+u+".$include("+d+","+c+","+y+","+b+")}",o[a]="function(){"+m+"+=''.concat.apply('',arguments)}",o[l]="function(src,data,block){"+m+"+="+u+".$include(src,data||"+c+",block,"+b+")}",o[f]="function(from){"+d+"=from}",o[p]="function(name,callback){if("+d+"){"+m+"='';callback();"+y+"[name]="+m+"}else{if(typeof "+y+"[name]==='string'){"+m+"+="+y+"[name]}else{callback()}}}",o),this.dependencies=(i={},i[a]=[m],i[l]=[m,u,c,b],i[f]=[d,v],i[p]=[d,m,y],i[v]=[u,d,c,y,b],i),this.importContext(m),e.compileDebug&&this.importContext(h),w)try{x=k(x,e)}catch(t){}this.getTplTokens(x,e.rules,this).forEach(function(t){t.type===s.TYPE_STRING?g.parseString(t):g.parseExpression(t)})}return t.prototype.getTplTokens=function(){return s.apply(void 0,arguments)},t.prototype.getEsTokens=function(t){return i(t)},t.prototype.getVariables=function(t){var e=!1;return t.filter(function(t){return"whitespace"!==t.type&&"comment"!==t.type}).filter(function(t){return"name"===t.type&&!e||(e="punctuator"===t.type&&"."===t.value,!1)}).map(function(t){return t.value})},t.prototype.importContext=function(t){var e=this,n="",r=this.internal,i=this.dependencies,s=this.external,a=this.context,l=this.options,f=l.imports,p=this.CONTEXT_MAP;g(p,t)||g(s,t)||o(t)||(g(r,t)?(n=r[t],g(i,t)&&i[t].forEach(function(t){return e.importContext(t)})):n=g(f,t)?u+"."+t:c+"."+t,p[t]=n,a.push({name:t,value:n}))},t.prototype.parseString=function(t){var e=t.value;if(e){var n=m+"+="+x(e);this.scripts.push({source:e,tplToken:t,code:n})}},t.prototype.parseExpression=function(t){var e=this,n=t.value,r=t.script,o=r.output,i=r.code.trim();o&&(i=!1===escape||o===s.TYPE_RAW?m+"+="+r.code:m+"+=$escape("+r.code+")");var c=this.getEsTokens(i);this.getVariables(c).forEach(function(t){return e.importContext(t)}),this.scripts.push({source:n,tplToken:t,code:i})},t.prototype.checkExpression=function(t){for(var e=[[/^\s*?}.*?{?[\s;]*?$/,""],[/(^[\w\W]*?\s*?function\s*?\([\w\W]*?\)\s*?{[\s;]*?$)/,"$1})"],[/(^.*?\(\s*?[\w\W]*?=>\s*?{[\s;]*?$)/,"$1})"],[/(^[\w\W]*?\([\w\W]*?\)\s*?{[\s;]*?$)/,"$1}"]],n=0;n!=?({]|\/(?![\/*])))))|(0[xX][\da-fA-F]+|0[oO][0-7]+|0[bB][01]+|(?:\d*\.\d+|\d+\.?)(?:[eE][+-]?\d+)?)|((?!\d)(?:(?!\s)[$\w\u0080-\uFFFF]|\\u[\da-fA-F]{4}|\\u\{[\da-fA-F]+\})+)|(--|\+\+|&&|\|\||=>|\.{3}|(?:[+\-\/%&|^]|\*{1,2}|<{1,2}|>{1,3}|!=?|={1,2})=?|[?~.,:;[\](){}])|(\s+)|(^$|[\s\S])/g,i=function(t){var e={type:"invalid",value:t[0]};return t[1]?(e.type="string",e.closed=!(!t[3]&&!t[4])):t[5]?e.type="comment":t[6]?(e.type="comment",e.closed=!!t[7]):t[8]?e.type="regex":t[9]?e.type="number":t[10]?e.type="name":t[11]?e.type="punctuator":t[12]&&(e.type="whitespace"),e},s=function(t){return t.match(o).map(function(t){return o.lastIndex=0,i(o.exec(t))}).map(function(t){return"name"===t.type&&r(t.value)&&(t.type="keyword"),t})};t.exports=s},function(t,e,n){"use strict";var r=function(t,e,n){for(var r=[{type:"string",value:t,line:0,start:0,end:t.length}],o=0;o1&&void 0!==arguments[1]?arguments[1]:{};"object"===(void 0===t?"undefined":r(t))?n=t:n.source=t,n=i.$extend(n),t=n.source,n.debug&&(n.cache=!1,n.bail=!1,n.minimize=!1,n.compileDebug=!0),n.filename&&(n.filename=n.resolveFilename(n.filename,n));var s=n.onerror,c=n.filename,a=n.cache,l=n.caches;if(a&&c){var f=l.get(c);if(f)return f}if(!t)try{t=n.loader(c,n),n.source=t}catch(e){var p=new u({name:"CompileError",message:"template not found: "+e.message,stack:e.stack});if(n.bail)throw p;return s(p,n)}var m=new o(n),h=function t(r,o){try{return t.original(r,o)}catch(t){if(!n.compileDebug)return n.cache=!1,n.compileDebug=!0,e(n)(r,o);if(t=new u(t),n.bail)throw t;return s(t,n)()}};try{h.original=m.build(),h.mappings=h.original.mappings,a&&c&&l.set(c,h)}catch(p){if(p=new u(p),n.bail)throw p;return s(p,n)}return h.toString=function(){return h.original.toString()},h};s.Compiler=o,e.exports=s},function(e,t,n){"use strict";var r=n(0),o=n(15),i=n(9),u=n(11),s=n(14),c=n(13),a=n(10),l=n(17),f=n(18),p=n(12),m=n(16),h={source:null,filename:null,rules:[f,l],escape:!0,debug:!!r&&"production"!==process.env.NODE_ENV,bail:!1,cache:!0,minimize:!0,compileDebug:!1,resolveFilename:m,htmlMinifier:p,onerror:o,loader:s,caches:i,root:"/",extname:".art",imports:{$each:a,$escape:u,$include:c}};h.$extend=function(e){var t=Object.create(this);for(var n in e)t[n]=e[n];return t},e.exports=h},function(e,t,n){"use strict";var r={abstract:!0,await:!0,boolean:!0,break:!0,byte:!0,case:!0,catch:!0,char:!0,class:!0,const:!0,continue:!0,debugger:!0,default:!0,delete:!0,do:!0,double:!0,else:!0,enum:!0,export:!0,extends:!0,false:!0,final:!0,finally:!0,float:!0,for:!0,function:!0,goto:!0,if:!0,implements:!0,import:!0,in:!0,instanceof:!0,int:!0,interface:!0,let:!0,long:!0,native:!0,new:!0,null:!0,package:!0,private:!0,protected:!0,public:!0,return:!0,short:!0,static:!0,super:!0,switch:!0,synchronized:!0,this:!0,throw:!0,transient:!0,true:!0,try:!0,typeof:!0,var:!0,void:!0,volatile:!0,while:!0,with:!0,yield:!0};e.exports=function(e){return r.hasOwnProperty(e)}},function(e,t,n){"use strict"},function(e,t,n){"use strict";var r=n(1),o=function(e,t,n){return r(e,n)(t)};e.exports=o},function(e,t,n){"use strict";(function(e){var t="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e};!function(e){e.noop=function(){}}("object"===t(e)&&"object"===t(e.exports)?e.exports:window)}).call(t,n(8)(e))},function(e,t,n){"use strict";var r,o="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e};r=function(){return this}();try{r=r||Function("return this")()||(0,eval)("this")}catch(e){"object"===("undefined"==typeof window?"undefined":o(window))&&(r=window)}e.exports=r},function(e,t,n){"use strict";e.exports=function(e){return e.webpackPolyfill||(e.deprecate=function(){},e.paths=[],e.children||(e.children=[]),Object.defineProperty(e,"loaded",{enumerable:!0,get:function(){return e.l}}),Object.defineProperty(e,"id",{enumerable:!0,get:function(){return e.i}}),e.webpackPolyfill=1),e}},function(e,t,n){"use strict";var r={__data:Object.create(null),set:function(e,t){this.__data[e]=t},get:function(e){return this.__data[e]},reset:function(){this.__data={}}};e.exports=r},function(e,t,n){"use strict";var r=function(e,t){if(Array.isArray(e))for(var n=0,r=e.length;n":">",'"':""","'":"'","&":"&"};return function e(t){return"string"!=typeof t&&(t="function"==typeof t?e(t.call(t)):null===t?"":JSON.stringify(t)||""),t}(e).replace(/&(?![\w#]+;)|[<>"']/g,function(e){return t[e]})};e.exports=r},function(e,t,n){"use strict";var r=n(0),o=function(e,t){if(r){e=(0,n(6).minify)(e,{collapseWhitespace:!0,minifyCSS:!0,minifyJS:!0,ignoreCustomFragments:t.rules.map(function(e){return e.test})})}return e};e.exports=o},function(e,t,n){"use strict";var r=function(e,t,r,o){var i=n(1);return o=o.$extend({filename:o.resolveFilename(e,o),source:null}),i(o)(t,r)};e.exports=r},function(e,t,n){"use strict";var r=n(0),o=function(e){if(r){return n(4).readFileSync(e,"utf8")}var t=document.getElementById(e);return t.value||t.innerHTML};e.exports=o},function(e,t,n){"use strict";var r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},o=function(e){return"object"===("undefined"==typeof console?"undefined":r(console))&&console.error(e.name,e.message),function(){return"{Template Error}"}};e.exports=o},function(e,t,n){"use strict";var r=n(0),o=/^\.+\//,i=function(e,t){if(r){var i=n(4),u=t.root,s=t.extname;if(o.test(e)){var c=t.filename,a=!c||e===c,l=a?u:i.dirname(c);e=i.resolve(l,e)}else e=i.resolve(u,e);i.extname(e)||(e+=s)}return e};e.exports=i},function(e,t,n){"use strict";var r={test:/{{([@#]?)(\/?)([\w\W]*?)}}/,use:function(e,t,n,r){var i=this,u=i.options,s=i.getEsTokens(r.trim()),c=s.map(function(e){return e.value}),a={},l=void 0,f=!!t&&"raw",p=n+c.shift(),m=function(e,t){console.warn("Template upgrade:","{{"+e+"}}",">>>","{{"+t+"}}","\n",u.filename||"")};switch("#"===t&&m("#value","@value"),p){case"set":r="var "+c.join("");break;case"if":r="if("+c.join("")+"){";break;case"else":var h=c.indexOf("if");h>-1?(c.splice(0,h+1),r="}else if("+c.join("")+"){"):r="}else{";break;case"/if":r="}";break;case"each":l=o(s),l.shift(),"as"===l[1]&&(m("each object as value index","each object value index"),l.splice(1,1));var y=l[0]||"$data",d=l[1]||"$value",v=l[2]||"$index";r="$each("+y+",function("+d+","+v+"){";break;case"/each":r="})";break;case"echo":p="print",m("echo value","value");case"print":case"include":case"extend":l=o(s),l.shift(),r=p+"("+l.join(",")+")";break;case"block":r="block("+c.join("")+",function(){";break;case"/block":r="})";break;default:if(-1!==c.indexOf("|")){for(var b=p,g=[],x=c.filter(function(e){return!/^\s+$/.test(e)});"|"!==x[0];)b+=x.shift();x.filter(function(e){return":"!==e}).forEach(function(e){"|"===e?g.push([]):g[g.length-1].push(e)}),g.reduce(function(e,t){var n=t.shift();return t.unshift(e),r=n+"("+t.join(",")+")"},b)}else u.imports[p]?(m("filterName value","value | filterName"),l=o(s),l.shift(),r=p+"("+l.join(",")+")",f="raw"):r=""+p+c.join("");f||(f="escape")}return a.code=r,a.output=f,a}},o=function(e){for(var t=0,n=e.shift(),r=[[n]];t/,use:function(e,t,n,r){var o={"-":"raw","=":"escape","":!1,"==":"raw","=#":"raw"};return t&&(r="//"+r),{code:r,output:o[n]}}};e.exports=r},function(e,t,n){"use strict";function r(e){if(Array.isArray(e)){for(var t=0,n=Array(e.length);t\s*?{[\s;]*?$)/,"$1})"],[/(^[\w\W]*?\([\w\W]*?\)\s*?{[\s;]*?$)/,"$1}"]],n=0;n!=?({]|\/(?![\/*])))))|(0[xX][\da-fA-F]+|0[oO][0-7]+|0[bB][01]+|(?:\d*\.\d+|\d+\.?)(?:[eE][+-]?\d+)?)|((?!\d)(?:(?!\s)[$\w\u0080-\uFFFF]|\\u[\da-fA-F]{4}|\\u\{[\da-fA-F]+\})+)|(--|\+\+|&&|\|\||=>|\.{3}|(?:[+\-\/%&|^]|\*{1,2}|<{1,2}|>{1,3}|!=?|={1,2})=?|[?~.,:;[\](){}])|(\s+)|(^$|[\s\S])/g,i=function(e){var t={type:"invalid",value:e[0]};return e[1]?(t.type="string",t.closed=!(!e[3]&&!e[4])):e[5]?t.type="comment":e[6]?(t.type="comment",t.closed=!!e[7]):e[8]?t.type="regex":e[9]?t.type="number":e[10]?t.type="name":e[11]?t.type="punctuator":e[12]&&(t.type="whitespace"),t},u=function(e){return e.match(o).map(function(e){return o.lastIndex=0,i(o.exec(e))}).map(function(e){return"name"===e.type&&r(e.value)&&(e.type="keyword"),e})};e.exports=u},function(e,t,n){"use strict";function r(e){Error.call(this);var t=e.stack.replace(/^[^:]+: /,"");delete e.stack,e=JSON.stringify(e,null,4),e=e+"\n\n"+t,this.name="TemplateError",this.message=e,this.stack=t}r.prototype=Object.create(Error.prototype),r.prototype.constructor=r,e.exports=r},function(e,t,n){"use strict";var r=function(e,t,n){for(var r=[{type:"string",value:e,line:0,start:0,end:e.length}],o=0;o Date: Sun, 23 Apr 2017 22:18:09 +0800 Subject: [PATCH 5/7] =?UTF-8?q?=E4=BC=98=E5=8C=96=E9=94=99=E8=AF=AF?= =?UTF-8?q?=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/template-node.js | 31 +++++++++++++++---------------- lib/template-web.js | 2 +- src/compile/adapter/onerror.js | 5 +---- src/compile/compiler.js | 4 ++-- src/compile/index.js | 18 ++++++++++++------ src/compile/template-error.js | 4 ---- test/compile/adapter/include.js | 9 --------- test/compile/adapter/onerror.js | 17 ----------------- test/res/index/index.html | 4 ++-- 9 files changed, 33 insertions(+), 61 deletions(-) delete mode 100644 test/compile/adapter/onerror.js diff --git a/lib/template-node.js b/lib/template-node.js index 795225f4..0dac2fdf 100644 --- a/lib/template-node.js +++ b/lib/template-node.js @@ -87,6 +87,15 @@ var Compiler = __webpack_require__(15); var defaults = __webpack_require__(2); var TemplateError = __webpack_require__(17); +var debugRender = function debugRender(error, options) { + options.onerror(error, options); + var render = function render() { + return '{Template Error}'; + }; + render.mappings = []; + return render; +}; + /** * 编译模版 * @param {string|Object} source 模板内容 @@ -120,7 +129,6 @@ var compile = function compile(source) { options.filename = options.resolveFilename(options.filename, options); } - var onerror = options.onerror; var filename = options.filename; var cache = options.cache; var caches = options.caches; @@ -150,7 +158,7 @@ var compile = function compile(source) { if (options.bail) { throw error; } else { - return onerror(error, options); + return debugRender(error, options); } } } @@ -175,7 +183,7 @@ var compile = function compile(source) { if (options.bail) { throw error; } else { - return onerror(error, options)(); + return debugRender(error, options)(); } } }; @@ -193,7 +201,7 @@ var compile = function compile(source) { if (options.bail) { throw error; } else { - return onerror(error, options); + return debugRender(error, options); } } @@ -533,17 +541,12 @@ var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol * 调试器 * @param {Object} error * @param {?Object} options - * @return {function} + * @return {string} */ var onerror = function onerror(error /*, options*/) { - if ((typeof console === 'undefined' ? 'undefined' : _typeof(console)) === 'object') { console.error(error.name, error.message); } - - return function () { - return '{Template Error}'; - }; }; module.exports = onerror; @@ -1231,7 +1234,7 @@ var Compiler = function () { stacks.push('}catch(error){'); - stacks.push('throw {' + ['name:\'RuntimeError\'', 'path:' + stringify(filename), 'message:error.message', 'line:' + LINE + '[0]+1', 'start:' + LINE + '[1]+1', 'source:' + LINE + '[2]', 'stack:error.stack'].join(',') + '}'); + stacks.push('throw {' + ['name:\'RuntimeError\'', 'path:' + stringify(filename), 'message:error.message', 'line:' + LINE + '[0]+1', 'column:' + LINE + '[1]+1', 'source:' + LINE + '[2]', 'stack:error.stack'].join(',') + '}'); stacks.push('}'); } else { @@ -1273,7 +1276,7 @@ var Compiler = function () { path: filename, message: error.message, line: line + 1, - start: start + 1, + column: start + 1, source: source2, script: renderCode, stack: error.stack @@ -1360,15 +1363,11 @@ module.exports = esTokenizer; * 模板错误处理类 */ function TemplateError(error) { - Error.call(this); - // Error.captureStackTrace(this, TemplateError); - var STRIP_FILENAME_RE = /^[^:]+: /; var stack = error.stack.replace(STRIP_FILENAME_RE, ''); delete error.stack; error = JSON.stringify(error, null, 4); - error = error + '\n\n' + stack; this.name = 'TemplateError'; this.message = error; diff --git a/lib/template-web.js b/lib/template-web.js index 2a4e8b04..ad2aca2b 100644 --- a/lib/template-web.js +++ b/lib/template-web.js @@ -1,2 +1,2 @@ /*! art-template@4.4.1 | https://github.com/aui/art-template */ -!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.template=t():e.template=t()}(this,function(){return function(e){function t(r){if(n[r])return n[r].exports;var o=n[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,t),o.l=!0,o.exports}var n={};return t.m=e,t.c=n,t.i=function(e){return e},t.d=function(e,n,r){t.o(e,n)||Object.defineProperty(e,n,{configurable:!1,enumerable:!0,get:r})},t.n=function(e){var n=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(n,"a",n),n},t.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},t.p="",t(t.s=23)}([function(e,t,n){"use strict";(function(t){e.exports=!1;try{e.exports="[object process]"===Object.prototype.toString.call(t.process)}catch(e){}}).call(t,n(7))},function(e,t,n){"use strict";var r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},o=n(19),i=n(2),u=n(21),s=function e(t){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};"object"===(void 0===t?"undefined":r(t))?n=t:n.source=t,n=i.$extend(n),t=n.source,n.debug&&(n.cache=!1,n.bail=!1,n.minimize=!1,n.compileDebug=!0),n.filename&&(n.filename=n.resolveFilename(n.filename,n));var s=n.onerror,c=n.filename,a=n.cache,l=n.caches;if(a&&c){var f=l.get(c);if(f)return f}if(!t)try{t=n.loader(c,n),n.source=t}catch(e){var p=new u({name:"CompileError",message:"template not found: "+e.message,stack:e.stack});if(n.bail)throw p;return s(p,n)}var m=new o(n),h=function t(r,o){try{return t.original(r,o)}catch(t){if(!n.compileDebug)return n.cache=!1,n.compileDebug=!0,e(n)(r,o);if(t=new u(t),n.bail)throw t;return s(t,n)()}};try{h.original=m.build(),h.mappings=h.original.mappings,a&&c&&l.set(c,h)}catch(p){if(p=new u(p),n.bail)throw p;return s(p,n)}return h.toString=function(){return h.original.toString()},h};s.Compiler=o,e.exports=s},function(e,t,n){"use strict";var r=n(0),o=n(15),i=n(9),u=n(11),s=n(14),c=n(13),a=n(10),l=n(17),f=n(18),p=n(12),m=n(16),h={source:null,filename:null,rules:[f,l],escape:!0,debug:!!r&&"production"!==process.env.NODE_ENV,bail:!1,cache:!0,minimize:!0,compileDebug:!1,resolveFilename:m,htmlMinifier:p,onerror:o,loader:s,caches:i,root:"/",extname:".art",imports:{$each:a,$escape:u,$include:c}};h.$extend=function(e){var t=Object.create(this);for(var n in e)t[n]=e[n];return t},e.exports=h},function(e,t,n){"use strict";var r={abstract:!0,await:!0,boolean:!0,break:!0,byte:!0,case:!0,catch:!0,char:!0,class:!0,const:!0,continue:!0,debugger:!0,default:!0,delete:!0,do:!0,double:!0,else:!0,enum:!0,export:!0,extends:!0,false:!0,final:!0,finally:!0,float:!0,for:!0,function:!0,goto:!0,if:!0,implements:!0,import:!0,in:!0,instanceof:!0,int:!0,interface:!0,let:!0,long:!0,native:!0,new:!0,null:!0,package:!0,private:!0,protected:!0,public:!0,return:!0,short:!0,static:!0,super:!0,switch:!0,synchronized:!0,this:!0,throw:!0,transient:!0,true:!0,try:!0,typeof:!0,var:!0,void:!0,volatile:!0,while:!0,with:!0,yield:!0};e.exports=function(e){return r.hasOwnProperty(e)}},function(e,t,n){"use strict"},function(e,t,n){"use strict";var r=n(1),o=function(e,t,n){return r(e,n)(t)};e.exports=o},function(e,t,n){"use strict";(function(e){var t="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e};!function(e){e.noop=function(){}}("object"===t(e)&&"object"===t(e.exports)?e.exports:window)}).call(t,n(8)(e))},function(e,t,n){"use strict";var r,o="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e};r=function(){return this}();try{r=r||Function("return this")()||(0,eval)("this")}catch(e){"object"===("undefined"==typeof window?"undefined":o(window))&&(r=window)}e.exports=r},function(e,t,n){"use strict";e.exports=function(e){return e.webpackPolyfill||(e.deprecate=function(){},e.paths=[],e.children||(e.children=[]),Object.defineProperty(e,"loaded",{enumerable:!0,get:function(){return e.l}}),Object.defineProperty(e,"id",{enumerable:!0,get:function(){return e.i}}),e.webpackPolyfill=1),e}},function(e,t,n){"use strict";var r={__data:Object.create(null),set:function(e,t){this.__data[e]=t},get:function(e){return this.__data[e]},reset:function(){this.__data={}}};e.exports=r},function(e,t,n){"use strict";var r=function(e,t){if(Array.isArray(e))for(var n=0,r=e.length;n":">",'"':""","'":"'","&":"&"};return function e(t){return"string"!=typeof t&&(t="function"==typeof t?e(t.call(t)):null===t?"":JSON.stringify(t)||""),t}(e).replace(/&(?![\w#]+;)|[<>"']/g,function(e){return t[e]})};e.exports=r},function(e,t,n){"use strict";var r=n(0),o=function(e,t){if(r){e=(0,n(6).minify)(e,{collapseWhitespace:!0,minifyCSS:!0,minifyJS:!0,ignoreCustomFragments:t.rules.map(function(e){return e.test})})}return e};e.exports=o},function(e,t,n){"use strict";var r=function(e,t,r,o){var i=n(1);return o=o.$extend({filename:o.resolveFilename(e,o),source:null}),i(o)(t,r)};e.exports=r},function(e,t,n){"use strict";var r=n(0),o=function(e){if(r){return n(4).readFileSync(e,"utf8")}var t=document.getElementById(e);return t.value||t.innerHTML};e.exports=o},function(e,t,n){"use strict";var r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},o=function(e){return"object"===("undefined"==typeof console?"undefined":r(console))&&console.error(e.name,e.message),function(){return"{Template Error}"}};e.exports=o},function(e,t,n){"use strict";var r=n(0),o=/^\.+\//,i=function(e,t){if(r){var i=n(4),u=t.root,s=t.extname;if(o.test(e)){var c=t.filename,a=!c||e===c,l=a?u:i.dirname(c);e=i.resolve(l,e)}else e=i.resolve(u,e);i.extname(e)||(e+=s)}return e};e.exports=i},function(e,t,n){"use strict";var r={test:/{{([@#]?)(\/?)([\w\W]*?)}}/,use:function(e,t,n,r){var i=this,u=i.options,s=i.getEsTokens(r.trim()),c=s.map(function(e){return e.value}),a={},l=void 0,f=!!t&&"raw",p=n+c.shift(),m=function(e,t){console.warn("Template upgrade:","{{"+e+"}}",">>>","{{"+t+"}}","\n",u.filename||"")};switch("#"===t&&m("#value","@value"),p){case"set":r="var "+c.join("");break;case"if":r="if("+c.join("")+"){";break;case"else":var h=c.indexOf("if");h>-1?(c.splice(0,h+1),r="}else if("+c.join("")+"){"):r="}else{";break;case"/if":r="}";break;case"each":l=o(s),l.shift(),"as"===l[1]&&(m("each object as value index","each object value index"),l.splice(1,1));var y=l[0]||"$data",d=l[1]||"$value",v=l[2]||"$index";r="$each("+y+",function("+d+","+v+"){";break;case"/each":r="})";break;case"echo":p="print",m("echo value","value");case"print":case"include":case"extend":l=o(s),l.shift(),r=p+"("+l.join(",")+")";break;case"block":r="block("+c.join("")+",function(){";break;case"/block":r="})";break;default:if(-1!==c.indexOf("|")){for(var b=p,g=[],x=c.filter(function(e){return!/^\s+$/.test(e)});"|"!==x[0];)b+=x.shift();x.filter(function(e){return":"!==e}).forEach(function(e){"|"===e?g.push([]):g[g.length-1].push(e)}),g.reduce(function(e,t){var n=t.shift();return t.unshift(e),r=n+"("+t.join(",")+")"},b)}else u.imports[p]?(m("filterName value","value | filterName"),l=o(s),l.shift(),r=p+"("+l.join(",")+")",f="raw"):r=""+p+c.join("");f||(f="escape")}return a.code=r,a.output=f,a}},o=function(e){for(var t=0,n=e.shift(),r=[[n]];t/,use:function(e,t,n,r){var o={"-":"raw","=":"escape","":!1,"==":"raw","=#":"raw"};return t&&(r="//"+r),{code:r,output:o[n]}}};e.exports=r},function(e,t,n){"use strict";function r(e){if(Array.isArray(e)){for(var t=0,n=Array(e.length);t\s*?{[\s;]*?$)/,"$1})"],[/(^[\w\W]*?\([\w\W]*?\)\s*?{[\s;]*?$)/,"$1}"]],n=0;n!=?({]|\/(?![\/*])))))|(0[xX][\da-fA-F]+|0[oO][0-7]+|0[bB][01]+|(?:\d*\.\d+|\d+\.?)(?:[eE][+-]?\d+)?)|((?!\d)(?:(?!\s)[$\w\u0080-\uFFFF]|\\u[\da-fA-F]{4}|\\u\{[\da-fA-F]+\})+)|(--|\+\+|&&|\|\||=>|\.{3}|(?:[+\-\/%&|^]|\*{1,2}|<{1,2}|>{1,3}|!=?|={1,2})=?|[?~.,:;[\](){}])|(\s+)|(^$|[\s\S])/g,i=function(e){var t={type:"invalid",value:e[0]};return e[1]?(t.type="string",t.closed=!(!e[3]&&!e[4])):e[5]?t.type="comment":e[6]?(t.type="comment",t.closed=!!e[7]):e[8]?t.type="regex":e[9]?t.type="number":e[10]?t.type="name":e[11]?t.type="punctuator":e[12]&&(t.type="whitespace"),t},u=function(e){return e.match(o).map(function(e){return o.lastIndex=0,i(o.exec(e))}).map(function(e){return"name"===e.type&&r(e.value)&&(e.type="keyword"),e})};e.exports=u},function(e,t,n){"use strict";function r(e){Error.call(this);var t=e.stack.replace(/^[^:]+: /,"");delete e.stack,e=JSON.stringify(e,null,4),e=e+"\n\n"+t,this.name="TemplateError",this.message=e,this.stack=t}r.prototype=Object.create(Error.prototype),r.prototype.constructor=r,e.exports=r},function(e,t,n){"use strict";var r=function(e,t,n){for(var r=[{type:"string",value:e,line:0,start:0,end:e.length}],o=0;o1&&void 0!==arguments[1]?arguments[1]:{};"object"===(void 0===t?"undefined":r(t))?n=t:n.source=t,n=i.$extend(n),t=n.source,n.debug&&(n.cache=!1,n.bail=!1,n.minimize=!1,n.compileDebug=!0),n.filename&&(n.filename=n.resolveFilename(n.filename,n));var s=n.filename,a=n.cache,l=n.caches;if(a&&s){var f=l.get(s);if(f)return f}if(!t)try{t=n.loader(s,n),n.source=t}catch(e){var p=new u({name:"CompileError",message:"template not found: "+e.message,stack:e.stack});if(n.bail)throw p;return c(p,n)}var m=new o(n),h=function t(r,o){try{return t.original(r,o)}catch(t){if(!n.compileDebug)return n.cache=!1,n.compileDebug=!0,e(n)(r,o);if(t=new u(t),n.bail)throw t;return c(t,n)()}};try{h.original=m.build(),h.mappings=h.original.mappings,a&&s&&l.set(s,h)}catch(p){if(p=new u(p),n.bail)throw p;return c(p,n)}return h.toString=function(){return h.original.toString()},h};s.Compiler=o,e.exports=s},function(e,t,n){"use strict";var r=n(0),o=n(15),i=n(9),u=n(11),c=n(14),s=n(13),a=n(10),l=n(17),f=n(18),p=n(12),m=n(16),h={source:null,filename:null,rules:[f,l],escape:!0,debug:!!r&&"production"!==process.env.NODE_ENV,bail:!1,cache:!0,minimize:!0,compileDebug:!1,resolveFilename:m,htmlMinifier:p,onerror:o,loader:c,caches:i,root:"/",extname:".art",imports:{$each:a,$escape:u,$include:s}};h.$extend=function(e){var t=Object.create(this);for(var n in e)t[n]=e[n];return t},e.exports=h},function(e,t,n){"use strict";var r={abstract:!0,await:!0,boolean:!0,break:!0,byte:!0,case:!0,catch:!0,char:!0,class:!0,const:!0,continue:!0,debugger:!0,default:!0,delete:!0,do:!0,double:!0,else:!0,enum:!0,export:!0,extends:!0,false:!0,final:!0,finally:!0,float:!0,for:!0,function:!0,goto:!0,if:!0,implements:!0,import:!0,in:!0,instanceof:!0,int:!0,interface:!0,let:!0,long:!0,native:!0,new:!0,null:!0,package:!0,private:!0,protected:!0,public:!0,return:!0,short:!0,static:!0,super:!0,switch:!0,synchronized:!0,this:!0,throw:!0,transient:!0,true:!0,try:!0,typeof:!0,var:!0,void:!0,volatile:!0,while:!0,with:!0,yield:!0};e.exports=function(e){return r.hasOwnProperty(e)}},function(e,t,n){"use strict"},function(e,t,n){"use strict";var r=n(1),o=function(e,t,n){return r(e,n)(t)};e.exports=o},function(e,t,n){"use strict";(function(e){var t="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e};!function(e){e.noop=function(){}}("object"===t(e)&&"object"===t(e.exports)?e.exports:window)}).call(t,n(8)(e))},function(e,t,n){"use strict";var r,o="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e};r=function(){return this}();try{r=r||Function("return this")()||(0,eval)("this")}catch(e){"object"===("undefined"==typeof window?"undefined":o(window))&&(r=window)}e.exports=r},function(e,t,n){"use strict";e.exports=function(e){return e.webpackPolyfill||(e.deprecate=function(){},e.paths=[],e.children||(e.children=[]),Object.defineProperty(e,"loaded",{enumerable:!0,get:function(){return e.l}}),Object.defineProperty(e,"id",{enumerable:!0,get:function(){return e.i}}),e.webpackPolyfill=1),e}},function(e,t,n){"use strict";var r={__data:Object.create(null),set:function(e,t){this.__data[e]=t},get:function(e){return this.__data[e]},reset:function(){this.__data={}}};e.exports=r},function(e,t,n){"use strict";var r=function(e,t){if(Array.isArray(e))for(var n=0,r=e.length;n":">",'"':""","'":"'","&":"&"};return function e(t){return"string"!=typeof t&&(t="function"==typeof t?e(t.call(t)):null===t?"":JSON.stringify(t)||""),t}(e).replace(/&(?![\w#]+;)|[<>"']/g,function(e){return t[e]})};e.exports=r},function(e,t,n){"use strict";var r=n(0),o=function(e,t){if(r){e=(0,n(6).minify)(e,{collapseWhitespace:!0,minifyCSS:!0,minifyJS:!0,ignoreCustomFragments:t.rules.map(function(e){return e.test})})}return e};e.exports=o},function(e,t,n){"use strict";var r=function(e,t,r,o){var i=n(1);return o=o.$extend({filename:o.resolveFilename(e,o),source:null}),i(o)(t,r)};e.exports=r},function(e,t,n){"use strict";var r=n(0),o=function(e){if(r){return n(4).readFileSync(e,"utf8")}var t=document.getElementById(e);return t.value||t.innerHTML};e.exports=o},function(e,t,n){"use strict";var r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},o=function(e){"object"===("undefined"==typeof console?"undefined":r(console))&&console.error(e.name,e.message)};e.exports=o},function(e,t,n){"use strict";var r=n(0),o=/^\.+\//,i=function(e,t){if(r){var i=n(4),u=t.root,c=t.extname;if(o.test(e)){var s=t.filename,a=!s||e===s,l=a?u:i.dirname(s);e=i.resolve(l,e)}else e=i.resolve(u,e);i.extname(e)||(e+=c)}return e};e.exports=i},function(e,t,n){"use strict";var r={test:/{{([@#]?)(\/?)([\w\W]*?)}}/,use:function(e,t,n,r){var i=this,u=i.options,c=i.getEsTokens(r.trim()),s=c.map(function(e){return e.value}),a={},l=void 0,f=!!t&&"raw",p=n+s.shift(),m=function(e,t){console.warn("Template upgrade:","{{"+e+"}}",">>>","{{"+t+"}}","\n",u.filename||"")};switch("#"===t&&m("#value","@value"),p){case"set":r="var "+s.join("");break;case"if":r="if("+s.join("")+"){";break;case"else":var h=s.indexOf("if");h>-1?(s.splice(0,h+1),r="}else if("+s.join("")+"){"):r="}else{";break;case"/if":r="}";break;case"each":l=o(c),l.shift(),"as"===l[1]&&(m("each object as value index","each object value index"),l.splice(1,1));var y=l[0]||"$data",d=l[1]||"$value",v=l[2]||"$index";r="$each("+y+",function("+d+","+v+"){";break;case"/each":r="})";break;case"echo":p="print",m("echo value","value");case"print":case"include":case"extend":l=o(c),l.shift(),r=p+"("+l.join(",")+")";break;case"block":r="block("+s.join("")+",function(){";break;case"/block":r="})";break;default:if(-1!==s.indexOf("|")){for(var b=p,g=[],x=s.filter(function(e){return!/^\s+$/.test(e)});"|"!==x[0];)b+=x.shift();x.filter(function(e){return":"!==e}).forEach(function(e){"|"===e?g.push([]):g[g.length-1].push(e)}),g.reduce(function(e,t){var n=t.shift();return t.unshift(e),r=n+"("+t.join(",")+")"},b)}else u.imports[p]?(m("filterName value","value | filterName"),l=o(c),l.shift(),r=p+"("+l.join(",")+")",f="raw"):r=""+p+s.join("");f||(f="escape")}return a.code=r,a.output=f,a}},o=function(e){for(var t=0,n=e.shift(),r=[[n]];t/,use:function(e,t,n,r){var o={"-":"raw","=":"escape","":!1,"==":"raw","=#":"raw"};return t&&(r="//"+r),{code:r,output:o[n]}}};e.exports=r},function(e,t,n){"use strict";function r(e){if(Array.isArray(e)){for(var t=0,n=Array(e.length);t\s*?{[\s;]*?$)/,"$1})"],[/(^[\w\W]*?\([\w\W]*?\)\s*?{[\s;]*?$)/,"$1}"]],n=0;n!=?({]|\/(?![\/*])))))|(0[xX][\da-fA-F]+|0[oO][0-7]+|0[bB][01]+|(?:\d*\.\d+|\d+\.?)(?:[eE][+-]?\d+)?)|((?!\d)(?:(?!\s)[$\w\u0080-\uFFFF]|\\u[\da-fA-F]{4}|\\u\{[\da-fA-F]+\})+)|(--|\+\+|&&|\|\||=>|\.{3}|(?:[+\-\/%&|^]|\*{1,2}|<{1,2}|>{1,3}|!=?|={1,2})=?|[?~.,:;[\](){}])|(\s+)|(^$|[\s\S])/g,i=function(e){var t={type:"invalid",value:e[0]};return e[1]?(t.type="string",t.closed=!(!e[3]&&!e[4])):e[5]?t.type="comment":e[6]?(t.type="comment",t.closed=!!e[7]):e[8]?t.type="regex":e[9]?t.type="number":e[10]?t.type="name":e[11]?t.type="punctuator":e[12]&&(t.type="whitespace"),t},u=function(e){return e.match(o).map(function(e){return o.lastIndex=0,i(o.exec(e))}).map(function(e){return"name"===e.type&&r(e.value)&&(e.type="keyword"),e})};e.exports=u},function(e,t,n){"use strict";function r(e){var t=e.stack.replace(/^[^:]+: /,"");delete e.stack,e=JSON.stringify(e,null,4),this.name="TemplateError",this.message=e,this.stack=t}r.prototype=Object.create(Error.prototype),r.prototype.constructor=r,e.exports=r},function(e,t,n){"use strict";var r=function(e,t,n){for(var r=[{type:"string",value:e,line:0,start:0,end:e.length}],o=0;o { - if (typeof console === 'object') { console.error(error.name, error.message); } - - return () => `{Template Error}`; }; module.exports = onerror; \ No newline at end of file diff --git a/src/compile/compiler.js b/src/compile/compiler.js index 3f602cee..31d476c3 100644 --- a/src/compile/compiler.js +++ b/src/compile/compiler.js @@ -398,7 +398,7 @@ class Compiler { `path:${stringify(filename)}`, `message:error.message`, `line:${LINE}[0]+1`, - `start:${LINE}[1]+1`, + `column:${LINE}[1]+1`, `source:${LINE}[2]`, `stack:error.stack` ].join(`,`) + '}'); @@ -446,7 +446,7 @@ class Compiler { path: filename, message: error.message, line: line + 1, - start: start + 1, + column: start + 1, source: source2, script: renderCode, stack: error.stack diff --git a/src/compile/index.js b/src/compile/index.js index 5efe3035..c03e07dd 100644 --- a/src/compile/index.js +++ b/src/compile/index.js @@ -3,6 +3,13 @@ const defaults = require('./defaults'); const TemplateError = require('./template-error'); +const debugRender = (error, options) => { + options.onerror(error, options); + const render = () => `{Template Error}`; + render.mappings = []; + return render; +}; + /** * 编译模版 @@ -38,7 +45,6 @@ const compile = (source, options = {}) => { } - const onerror = options.onerror; const filename = options.filename; const cache = options.cache; const caches = options.caches; @@ -55,7 +61,7 @@ const compile = (source, options = {}) => { // 加载外部模板 if (!source) { - + try { source = options.loader(filename, options); options.source = source; @@ -70,7 +76,7 @@ const compile = (source, options = {}) => { if (options.bail) { throw error; } else { - return onerror(error, options); + return debugRender(error, options); } } @@ -97,7 +103,7 @@ const compile = (source, options = {}) => { if (options.bail) { throw error; } else { - return onerror(error, options)(); + return debugRender(error, options)(); } } @@ -118,12 +124,12 @@ const compile = (source, options = {}) => { if (options.bail) { throw error; } else { - return onerror(error, options); + return debugRender(error, options); } } - render.toString = function() { + render.toString = function () { return render.original.toString(); }; diff --git a/src/compile/template-error.js b/src/compile/template-error.js index 846a7507..303b5959 100644 --- a/src/compile/template-error.js +++ b/src/compile/template-error.js @@ -2,15 +2,11 @@ * 模板错误处理类 */ function TemplateError(error) { - Error.call(this); - // Error.captureStackTrace(this, TemplateError); - const STRIP_FILENAME_RE = /^[^:]+: /; const stack = error.stack.replace(STRIP_FILENAME_RE, ``); delete error.stack; error = JSON.stringify(error, null, 4); - error = `${error}\n\n${stack}`; this.name = 'TemplateError'; this.message = error; diff --git a/test/compile/adapter/include.js b/test/compile/adapter/include.js index 8f8f88b0..ca3ebf17 100644 --- a/test/compile/adapter/include.js +++ b/test/compile/adapter/include.js @@ -24,15 +24,6 @@ module.exports = { root }))); - assert.deepEqual('hello world', include('file.html', data, null, defaults.$extend({ - filename: base, - root: '/' - }))); - - assert.deepEqual('hello world', include('file.html', data, null, defaults.$extend({ - filename: base, - root - }))); } } }; \ No newline at end of file diff --git a/test/compile/adapter/onerror.js b/test/compile/adapter/onerror.js deleted file mode 100644 index fbd55295..00000000 --- a/test/compile/adapter/onerror.js +++ /dev/null @@ -1,17 +0,0 @@ -const assert = require('assert'); -const onerror = require('../../../src/compile/adapter/onerror'); - -module.exports = { - before: () => { - console.log('#compile/adapter/onerror'); - }, - 'onerror': { - 'return function': () => { - assert.deepEqual('function', typeof onerror({})); - }, - - 'run function': () => { - assert.deepEqual('{Template Error}', onerror({})()); - } - } -}; \ No newline at end of file diff --git a/test/res/index/index.html b/test/res/index/index.html index ab5c039d..5a8b8c7b 100644 --- a/test/res/index/index.html +++ b/test/res/index/index.html @@ -1,2 +1,2 @@ -{{include 'include.html'}} -<% include('include.html', {name: '糖饼'}) %> \ No newline at end of file +{{include './include.html'}} +<% include('./include.html', {name: '糖饼'}) %> \ No newline at end of file From 9845ffd637c724e493d6a78253f11336c8882e22 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=B3=96=E9=A5=BC?= Date: Sun, 23 Apr 2017 22:25:41 +0800 Subject: [PATCH 6/7] remove isKeyword() --- src/compile/compiler.js | 3 +-- test/compile/compiler.js | 4 ++-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/compile/compiler.js b/src/compile/compiler.js index 31d476c3..d554e929 100644 --- a/src/compile/compiler.js +++ b/src/compile/compiler.js @@ -1,4 +1,3 @@ -const isKeyword = require('is-keyword-js'); const esTokenizer = require('./es-tokenizer'); const tplTokenizer = require('./tpl-tokenizer'); @@ -190,7 +189,7 @@ class Compiler { const imports = options.imports; const contextMap = this.CONTEXT_MAP; - if (!has(contextMap, name) && !has(external, name) && !isKeyword(name)) { + if (!has(contextMap, name) && !has(external, name)) { if (has(internal, name)) { value = internal[name]; diff --git a/test/compile/compiler.js b/test/compile/compiler.js index 3763cf24..3781514e 100644 --- a/test/compile/compiler.js +++ b/test/compile/compiler.js @@ -63,8 +63,8 @@ module.exports = { value: '$data.value' }); - test('if', {}); - test('for', {}); + //test('if', {}); + //test('for', {}); test('$data', {}); test('$imports', {}); From 4fc42f12bc8ed27f0d6a42c15971826420bb6a61 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=B3=96=E9=A5=BC?= Date: Sun, 23 Apr 2017 22:25:58 +0800 Subject: [PATCH 7/7] rebuild --- lib/template-node.js | 87 ++++++++++++++++++++++---------------------- lib/template-web.js | 2 +- 2 files changed, 44 insertions(+), 45 deletions(-) diff --git a/lib/template-node.js b/lib/template-node.js index 0dac2fdf..68a9f3f8 100644 --- a/lib/template-node.js +++ b/lib/template-node.js @@ -65,7 +65,7 @@ module.exports = /******/ __webpack_require__.p = ""; /******/ /******/ // Load entry module and return exports -/******/ return __webpack_require__(__webpack_require__.s = 19); +/******/ return __webpack_require__(__webpack_require__.s = 18); /******/ }) /************************************************************************/ /******/ ([ @@ -83,9 +83,9 @@ module.exports = require("detect-node"); var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; -var Compiler = __webpack_require__(15); +var Compiler = __webpack_require__(14); var defaults = __webpack_require__(2); -var TemplateError = __webpack_require__(17); +var TemplateError = __webpack_require__(16); var debugRender = function debugRender(error, options) { options.onerror(error, options); @@ -224,16 +224,16 @@ module.exports = compile; var detectNode = __webpack_require__(0); -var onerror = __webpack_require__(11); -var caches = __webpack_require__(5); -var escape = __webpack_require__(7); -var loader = __webpack_require__(10); -var include = __webpack_require__(9); -var each = __webpack_require__(6); -var artRule = __webpack_require__(13); -var nativeRule = __webpack_require__(14); -var htmlMinifier = __webpack_require__(8); -var resolveFilename = __webpack_require__(12); +var onerror = __webpack_require__(10); +var caches = __webpack_require__(4); +var escape = __webpack_require__(6); +var loader = __webpack_require__(9); +var include = __webpack_require__(8); +var each = __webpack_require__(5); +var artRule = __webpack_require__(12); +var nativeRule = __webpack_require__(13); +var htmlMinifier = __webpack_require__(7); +var resolveFilename = __webpack_require__(11); /** 模板编译器默认配置 */ var defaults = { @@ -315,12 +315,6 @@ module.exports = defaults; /***/ }), /* 3 */ -/***/ (function(module, exports) { - -module.exports = require("is-keyword-js"); - -/***/ }), -/* 4 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; @@ -342,7 +336,7 @@ var render = function render(source, data, options) { module.exports = render; /***/ }), -/* 5 */ +/* 4 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; @@ -367,7 +361,7 @@ var caches = { module.exports = caches; /***/ }), -/* 6 */ +/* 5 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; @@ -393,7 +387,7 @@ var each = function each(data, callback) { module.exports = each; /***/ }), -/* 7 */ +/* 6 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; @@ -438,7 +432,7 @@ var escape = function escape(content) { module.exports = escape; /***/ }), -/* 8 */ +/* 7 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; @@ -455,7 +449,7 @@ var detectNode = __webpack_require__(0); var htmlMinifier = function htmlMinifier(source, options) { if (detectNode) { - var _htmlMinifier = __webpack_require__(21).minify; + var _htmlMinifier = __webpack_require__(20).minify; var ignoreCustomFragments = options.rules.map(function (rule) { return rule.test; }); @@ -475,7 +469,7 @@ var htmlMinifier = function htmlMinifier(source, options) { module.exports = htmlMinifier; /***/ }), -/* 9 */ +/* 8 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; @@ -501,7 +495,7 @@ var include = function include(filename, data, blocks, options) { module.exports = include; /***/ }), -/* 10 */ +/* 9 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; @@ -518,7 +512,7 @@ var detectNode = __webpack_require__(0); var loader = function loader(filename /*, options*/) { /* istanbul ignore else */ if (detectNode) { - var fs = __webpack_require__(20); + var fs = __webpack_require__(19); return fs.readFileSync(filename, 'utf8'); } else { var elem = document.getElementById(filename); @@ -529,7 +523,7 @@ var loader = function loader(filename /*, options*/) { module.exports = loader; /***/ }), -/* 11 */ +/* 10 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; @@ -552,7 +546,7 @@ var onerror = function onerror(error /*, options*/) { module.exports = onerror; /***/ }), -/* 12 */ +/* 11 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; @@ -595,7 +589,7 @@ var resolveFilename = function resolveFilename(filename, options) { module.exports = resolveFilename; /***/ }), -/* 13 */ +/* 12 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; @@ -804,7 +798,7 @@ nativeRule._split = split; module.exports = nativeRule; /***/ }), -/* 14 */ +/* 13 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; @@ -841,7 +835,7 @@ var nativeRule = { module.exports = nativeRule; /***/ }), -/* 15 */ +/* 14 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; @@ -855,9 +849,8 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } -var isKeyword = __webpack_require__(3); -var esTokenizer = __webpack_require__(16); -var tplTokenizer = __webpack_require__(18); +var esTokenizer = __webpack_require__(15); +var tplTokenizer = __webpack_require__(17); /** 传递给模板的数据引用 */ var DATA = '$data'; @@ -1035,7 +1028,7 @@ var Compiler = function () { var imports = options.imports; var contextMap = this.CONTEXT_MAP; - if (!has(contextMap, name) && !has(external, name) && !isKeyword(name)) { + if (!has(contextMap, name) && !has(external, name)) { if (has(internal, name)) { value = internal[name]; @@ -1312,13 +1305,13 @@ Compiler.CONSTS = { module.exports = Compiler; /***/ }), -/* 16 */ +/* 15 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; -var isKeyword = __webpack_require__(3); +var isKeyword = __webpack_require__(21); // js-tokens@3.0.1 // Copyright 2014, 2015, 2016, 2017 Simon Lydell @@ -1353,7 +1346,7 @@ var esTokenizer = function esTokenizer(code) { module.exports = esTokenizer; /***/ }), -/* 17 */ +/* 16 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; @@ -1380,7 +1373,7 @@ TemplateError.prototype.constructor = TemplateError; module.exports = TemplateError; /***/ }), -/* 18 */ +/* 17 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; @@ -1488,7 +1481,7 @@ tplTokenizer.TYPE_ESCAPE = TYPE_ESCAPE; module.exports = tplTokenizer; /***/ }), -/* 19 */ +/* 18 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; @@ -1496,7 +1489,7 @@ module.exports = tplTokenizer; var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; -var render = __webpack_require__(4); +var render = __webpack_require__(3); var compile = __webpack_require__(1); var defaults = __webpack_require__(2); @@ -1522,17 +1515,23 @@ template.defaults = defaults; module.exports = template; /***/ }), -/* 20 */ +/* 19 */ /***/ (function(module, exports) { module.exports = require("fs"); /***/ }), -/* 21 */ +/* 20 */ /***/ (function(module, exports) { module.exports = require("html-minifier"); +/***/ }), +/* 21 */ +/***/ (function(module, exports) { + +module.exports = require("is-keyword-js"); + /***/ }), /* 22 */ /***/ (function(module, exports) { diff --git a/lib/template-web.js b/lib/template-web.js index ad2aca2b..2a3d883a 100644 --- a/lib/template-web.js +++ b/lib/template-web.js @@ -1,2 +1,2 @@ /*! art-template@4.4.1 | https://github.com/aui/art-template */ -!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.template=t():e.template=t()}(this,function(){return function(e){function t(r){if(n[r])return n[r].exports;var o=n[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,t),o.l=!0,o.exports}var n={};return t.m=e,t.c=n,t.i=function(e){return e},t.d=function(e,n,r){t.o(e,n)||Object.defineProperty(e,n,{configurable:!1,enumerable:!0,get:r})},t.n=function(e){var n=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(n,"a",n),n},t.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},t.p="",t(t.s=23)}([function(e,t,n){"use strict";(function(t){e.exports=!1;try{e.exports="[object process]"===Object.prototype.toString.call(t.process)}catch(e){}}).call(t,n(7))},function(e,t,n){"use strict";var r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},o=n(19),i=n(2),u=n(21),c=function(e,t){t.onerror(e,t);var n=function(){return"{Template Error}"};return n.mappings=[],n},s=function e(t){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};"object"===(void 0===t?"undefined":r(t))?n=t:n.source=t,n=i.$extend(n),t=n.source,n.debug&&(n.cache=!1,n.bail=!1,n.minimize=!1,n.compileDebug=!0),n.filename&&(n.filename=n.resolveFilename(n.filename,n));var s=n.filename,a=n.cache,l=n.caches;if(a&&s){var f=l.get(s);if(f)return f}if(!t)try{t=n.loader(s,n),n.source=t}catch(e){var p=new u({name:"CompileError",message:"template not found: "+e.message,stack:e.stack});if(n.bail)throw p;return c(p,n)}var m=new o(n),h=function t(r,o){try{return t.original(r,o)}catch(t){if(!n.compileDebug)return n.cache=!1,n.compileDebug=!0,e(n)(r,o);if(t=new u(t),n.bail)throw t;return c(t,n)()}};try{h.original=m.build(),h.mappings=h.original.mappings,a&&s&&l.set(s,h)}catch(p){if(p=new u(p),n.bail)throw p;return c(p,n)}return h.toString=function(){return h.original.toString()},h};s.Compiler=o,e.exports=s},function(e,t,n){"use strict";var r=n(0),o=n(15),i=n(9),u=n(11),c=n(14),s=n(13),a=n(10),l=n(17),f=n(18),p=n(12),m=n(16),h={source:null,filename:null,rules:[f,l],escape:!0,debug:!!r&&"production"!==process.env.NODE_ENV,bail:!1,cache:!0,minimize:!0,compileDebug:!1,resolveFilename:m,htmlMinifier:p,onerror:o,loader:c,caches:i,root:"/",extname:".art",imports:{$each:a,$escape:u,$include:s}};h.$extend=function(e){var t=Object.create(this);for(var n in e)t[n]=e[n];return t},e.exports=h},function(e,t,n){"use strict";var r={abstract:!0,await:!0,boolean:!0,break:!0,byte:!0,case:!0,catch:!0,char:!0,class:!0,const:!0,continue:!0,debugger:!0,default:!0,delete:!0,do:!0,double:!0,else:!0,enum:!0,export:!0,extends:!0,false:!0,final:!0,finally:!0,float:!0,for:!0,function:!0,goto:!0,if:!0,implements:!0,import:!0,in:!0,instanceof:!0,int:!0,interface:!0,let:!0,long:!0,native:!0,new:!0,null:!0,package:!0,private:!0,protected:!0,public:!0,return:!0,short:!0,static:!0,super:!0,switch:!0,synchronized:!0,this:!0,throw:!0,transient:!0,true:!0,try:!0,typeof:!0,var:!0,void:!0,volatile:!0,while:!0,with:!0,yield:!0};e.exports=function(e){return r.hasOwnProperty(e)}},function(e,t,n){"use strict"},function(e,t,n){"use strict";var r=n(1),o=function(e,t,n){return r(e,n)(t)};e.exports=o},function(e,t,n){"use strict";(function(e){var t="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e};!function(e){e.noop=function(){}}("object"===t(e)&&"object"===t(e.exports)?e.exports:window)}).call(t,n(8)(e))},function(e,t,n){"use strict";var r,o="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e};r=function(){return this}();try{r=r||Function("return this")()||(0,eval)("this")}catch(e){"object"===("undefined"==typeof window?"undefined":o(window))&&(r=window)}e.exports=r},function(e,t,n){"use strict";e.exports=function(e){return e.webpackPolyfill||(e.deprecate=function(){},e.paths=[],e.children||(e.children=[]),Object.defineProperty(e,"loaded",{enumerable:!0,get:function(){return e.l}}),Object.defineProperty(e,"id",{enumerable:!0,get:function(){return e.i}}),e.webpackPolyfill=1),e}},function(e,t,n){"use strict";var r={__data:Object.create(null),set:function(e,t){this.__data[e]=t},get:function(e){return this.__data[e]},reset:function(){this.__data={}}};e.exports=r},function(e,t,n){"use strict";var r=function(e,t){if(Array.isArray(e))for(var n=0,r=e.length;n":">",'"':""","'":"'","&":"&"};return function e(t){return"string"!=typeof t&&(t="function"==typeof t?e(t.call(t)):null===t?"":JSON.stringify(t)||""),t}(e).replace(/&(?![\w#]+;)|[<>"']/g,function(e){return t[e]})};e.exports=r},function(e,t,n){"use strict";var r=n(0),o=function(e,t){if(r){e=(0,n(6).minify)(e,{collapseWhitespace:!0,minifyCSS:!0,minifyJS:!0,ignoreCustomFragments:t.rules.map(function(e){return e.test})})}return e};e.exports=o},function(e,t,n){"use strict";var r=function(e,t,r,o){var i=n(1);return o=o.$extend({filename:o.resolveFilename(e,o),source:null}),i(o)(t,r)};e.exports=r},function(e,t,n){"use strict";var r=n(0),o=function(e){if(r){return n(4).readFileSync(e,"utf8")}var t=document.getElementById(e);return t.value||t.innerHTML};e.exports=o},function(e,t,n){"use strict";var r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},o=function(e){"object"===("undefined"==typeof console?"undefined":r(console))&&console.error(e.name,e.message)};e.exports=o},function(e,t,n){"use strict";var r=n(0),o=/^\.+\//,i=function(e,t){if(r){var i=n(4),u=t.root,c=t.extname;if(o.test(e)){var s=t.filename,a=!s||e===s,l=a?u:i.dirname(s);e=i.resolve(l,e)}else e=i.resolve(u,e);i.extname(e)||(e+=c)}return e};e.exports=i},function(e,t,n){"use strict";var r={test:/{{([@#]?)(\/?)([\w\W]*?)}}/,use:function(e,t,n,r){var i=this,u=i.options,c=i.getEsTokens(r.trim()),s=c.map(function(e){return e.value}),a={},l=void 0,f=!!t&&"raw",p=n+s.shift(),m=function(e,t){console.warn("Template upgrade:","{{"+e+"}}",">>>","{{"+t+"}}","\n",u.filename||"")};switch("#"===t&&m("#value","@value"),p){case"set":r="var "+s.join("");break;case"if":r="if("+s.join("")+"){";break;case"else":var h=s.indexOf("if");h>-1?(s.splice(0,h+1),r="}else if("+s.join("")+"){"):r="}else{";break;case"/if":r="}";break;case"each":l=o(c),l.shift(),"as"===l[1]&&(m("each object as value index","each object value index"),l.splice(1,1));var y=l[0]||"$data",d=l[1]||"$value",v=l[2]||"$index";r="$each("+y+",function("+d+","+v+"){";break;case"/each":r="})";break;case"echo":p="print",m("echo value","value");case"print":case"include":case"extend":l=o(c),l.shift(),r=p+"("+l.join(",")+")";break;case"block":r="block("+s.join("")+",function(){";break;case"/block":r="})";break;default:if(-1!==s.indexOf("|")){for(var b=p,g=[],x=s.filter(function(e){return!/^\s+$/.test(e)});"|"!==x[0];)b+=x.shift();x.filter(function(e){return":"!==e}).forEach(function(e){"|"===e?g.push([]):g[g.length-1].push(e)}),g.reduce(function(e,t){var n=t.shift();return t.unshift(e),r=n+"("+t.join(",")+")"},b)}else u.imports[p]?(m("filterName value","value | filterName"),l=o(c),l.shift(),r=p+"("+l.join(",")+")",f="raw"):r=""+p+s.join("");f||(f="escape")}return a.code=r,a.output=f,a}},o=function(e){for(var t=0,n=e.shift(),r=[[n]];t/,use:function(e,t,n,r){var o={"-":"raw","=":"escape","":!1,"==":"raw","=#":"raw"};return t&&(r="//"+r),{code:r,output:o[n]}}};e.exports=r},function(e,t,n){"use strict";function r(e){if(Array.isArray(e)){for(var t=0,n=Array(e.length);t\s*?{[\s;]*?$)/,"$1})"],[/(^[\w\W]*?\([\w\W]*?\)\s*?{[\s;]*?$)/,"$1}"]],n=0;n!=?({]|\/(?![\/*])))))|(0[xX][\da-fA-F]+|0[oO][0-7]+|0[bB][01]+|(?:\d*\.\d+|\d+\.?)(?:[eE][+-]?\d+)?)|((?!\d)(?:(?!\s)[$\w\u0080-\uFFFF]|\\u[\da-fA-F]{4}|\\u\{[\da-fA-F]+\})+)|(--|\+\+|&&|\|\||=>|\.{3}|(?:[+\-\/%&|^]|\*{1,2}|<{1,2}|>{1,3}|!=?|={1,2})=?|[?~.,:;[\](){}])|(\s+)|(^$|[\s\S])/g,i=function(e){var t={type:"invalid",value:e[0]};return e[1]?(t.type="string",t.closed=!(!e[3]&&!e[4])):e[5]?t.type="comment":e[6]?(t.type="comment",t.closed=!!e[7]):e[8]?t.type="regex":e[9]?t.type="number":e[10]?t.type="name":e[11]?t.type="punctuator":e[12]&&(t.type="whitespace"),t},u=function(e){return e.match(o).map(function(e){return o.lastIndex=0,i(o.exec(e))}).map(function(e){return"name"===e.type&&r(e.value)&&(e.type="keyword"),e})};e.exports=u},function(e,t,n){"use strict";function r(e){var t=e.stack.replace(/^[^:]+: /,"");delete e.stack,e=JSON.stringify(e,null,4),this.name="TemplateError",this.message=e,this.stack=t}r.prototype=Object.create(Error.prototype),r.prototype.constructor=r,e.exports=r},function(e,t,n){"use strict";var r=function(e,t,n){for(var r=[{type:"string",value:e,line:0,start:0,end:e.length}],o=0;o1&&void 0!==arguments[1]?arguments[1]:{};"object"===(void 0===t?"undefined":r(t))?n=t:n.source=t,n=i.$extend(n),t=n.source,n.debug&&(n.cache=!1,n.bail=!1,n.minimize=!1,n.compileDebug=!0),n.filename&&(n.filename=n.resolveFilename(n.filename,n));var s=n.filename,a=n.cache,l=n.caches;if(a&&s){var f=l.get(s);if(f)return f}if(!t)try{t=n.loader(s,n),n.source=t}catch(e){var p=new u({name:"CompileError",message:"template not found: "+e.message,stack:e.stack});if(n.bail)throw p;return c(p,n)}var m=new o(n),h=function t(r,o){try{return t.original(r,o)}catch(t){if(!n.compileDebug)return n.cache=!1,n.compileDebug=!0,e(n)(r,o);if(t=new u(t),n.bail)throw t;return c(t,n)()}};try{h.original=m.build(),h.mappings=h.original.mappings,a&&s&&l.set(s,h)}catch(p){if(p=new u(p),n.bail)throw p;return c(p,n)}return h.toString=function(){return h.original.toString()},h};s.Compiler=o,e.exports=s},function(e,t,n){"use strict";var r=n(0),o=n(15),i=n(9),u=n(11),c=n(14),s=n(13),a=n(10),l=n(17),f=n(18),p=n(12),m=n(16),h={source:null,filename:null,rules:[f,l],escape:!0,debug:!!r&&"production"!==process.env.NODE_ENV,bail:!1,cache:!0,minimize:!0,compileDebug:!1,resolveFilename:m,htmlMinifier:p,onerror:o,loader:c,caches:i,root:"/",extname:".art",imports:{$each:a,$escape:u,$include:s}};h.$extend=function(e){var t=Object.create(this);for(var n in e)t[n]=e[n];return t},e.exports=h},function(e,t,n){"use strict"},function(e,t,n){"use strict";var r=n(1),o=function(e,t,n){return r(e,n)(t)};e.exports=o},function(e,t,n){"use strict";(function(e){var t="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e};!function(e){e.noop=function(){}}("object"===t(e)&&"object"===t(e.exports)?e.exports:window)}).call(t,n(8)(e))},function(e,t,n){"use strict";var r={abstract:!0,await:!0,boolean:!0,break:!0,byte:!0,case:!0,catch:!0,char:!0,class:!0,const:!0,continue:!0,debugger:!0,default:!0,delete:!0,do:!0,double:!0,else:!0,enum:!0,export:!0,extends:!0,false:!0,final:!0,finally:!0,float:!0,for:!0,function:!0,goto:!0,if:!0,implements:!0,import:!0,in:!0,instanceof:!0,int:!0,interface:!0,let:!0,long:!0,native:!0,new:!0,null:!0,package:!0,private:!0,protected:!0,public:!0,return:!0,short:!0,static:!0,super:!0,switch:!0,synchronized:!0,this:!0,throw:!0,transient:!0,true:!0,try:!0,typeof:!0,var:!0,void:!0,volatile:!0,while:!0,with:!0,yield:!0};e.exports=function(e){return r.hasOwnProperty(e)}},function(e,t,n){"use strict";var r,o="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e};r=function(){return this}();try{r=r||Function("return this")()||(0,eval)("this")}catch(e){"object"===("undefined"==typeof window?"undefined":o(window))&&(r=window)}e.exports=r},function(e,t,n){"use strict";e.exports=function(e){return e.webpackPolyfill||(e.deprecate=function(){},e.paths=[],e.children||(e.children=[]),Object.defineProperty(e,"loaded",{enumerable:!0,get:function(){return e.l}}),Object.defineProperty(e,"id",{enumerable:!0,get:function(){return e.i}}),e.webpackPolyfill=1),e}},function(e,t,n){"use strict";var r={__data:Object.create(null),set:function(e,t){this.__data[e]=t},get:function(e){return this.__data[e]},reset:function(){this.__data={}}};e.exports=r},function(e,t,n){"use strict";var r=function(e,t){if(Array.isArray(e))for(var n=0,r=e.length;n":">",'"':""","'":"'","&":"&"};return function e(t){return"string"!=typeof t&&(t="function"==typeof t?e(t.call(t)):null===t?"":JSON.stringify(t)||""),t}(e).replace(/&(?![\w#]+;)|[<>"']/g,function(e){return t[e]})};e.exports=r},function(e,t,n){"use strict";var r=n(0),o=function(e,t){if(r){e=(0,n(5).minify)(e,{collapseWhitespace:!0,minifyCSS:!0,minifyJS:!0,ignoreCustomFragments:t.rules.map(function(e){return e.test})})}return e};e.exports=o},function(e,t,n){"use strict";var r=function(e,t,r,o){var i=n(1);return o=o.$extend({filename:o.resolveFilename(e,o),source:null}),i(o)(t,r)};e.exports=r},function(e,t,n){"use strict";var r=n(0),o=function(e){if(r){return n(3).readFileSync(e,"utf8")}var t=document.getElementById(e);return t.value||t.innerHTML};e.exports=o},function(e,t,n){"use strict";var r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},o=function(e){"object"===("undefined"==typeof console?"undefined":r(console))&&console.error(e.name,e.message)};e.exports=o},function(e,t,n){"use strict";var r=n(0),o=/^\.+\//,i=function(e,t){if(r){var i=n(3),u=t.root,c=t.extname;if(o.test(e)){var s=t.filename,a=!s||e===s,l=a?u:i.dirname(s);e=i.resolve(l,e)}else e=i.resolve(u,e);i.extname(e)||(e+=c)}return e};e.exports=i},function(e,t,n){"use strict";var r={test:/{{([@#]?)(\/?)([\w\W]*?)}}/,use:function(e,t,n,r){var i=this,u=i.options,c=i.getEsTokens(r.trim()),s=c.map(function(e){return e.value}),a={},l=void 0,f=!!t&&"raw",p=n+s.shift(),m=function(e,t){console.warn("Template upgrade:","{{"+e+"}}",">>>","{{"+t+"}}","\n",u.filename||"")};switch("#"===t&&m("#value","@value"),p){case"set":r="var "+s.join("");break;case"if":r="if("+s.join("")+"){";break;case"else":var h=s.indexOf("if");h>-1?(s.splice(0,h+1),r="}else if("+s.join("")+"){"):r="}else{";break;case"/if":r="}";break;case"each":l=o(c),l.shift(),"as"===l[1]&&(m("each object as value index","each object value index"),l.splice(1,1));var y=l[0]||"$data",d=l[1]||"$value",v=l[2]||"$index";r="$each("+y+",function("+d+","+v+"){";break;case"/each":r="})";break;case"echo":p="print",m("echo value","value");case"print":case"include":case"extend":l=o(c),l.shift(),r=p+"("+l.join(",")+")";break;case"block":r="block("+s.join("")+",function(){";break;case"/block":r="})";break;default:if(-1!==s.indexOf("|")){for(var b=p,g=[],x=s.filter(function(e){return!/^\s+$/.test(e)});"|"!==x[0];)b+=x.shift();x.filter(function(e){return":"!==e}).forEach(function(e){"|"===e?g.push([]):g[g.length-1].push(e)}),g.reduce(function(e,t){var n=t.shift();return t.unshift(e),r=n+"("+t.join(",")+")"},b)}else u.imports[p]?(m("filterName value","value | filterName"),l=o(c),l.shift(),r=p+"("+l.join(",")+")",f="raw"):r=""+p+s.join("");f||(f="escape")}return a.code=r,a.output=f,a}},o=function(e){for(var t=0,n=e.shift(),r=[[n]];t/,use:function(e,t,n,r){var o={"-":"raw","=":"escape","":!1,"==":"raw","=#":"raw"};return t&&(r="//"+r),{code:r,output:o[n]}}};e.exports=r},function(e,t,n){"use strict";function r(e){if(Array.isArray(e)){for(var t=0,n=Array(e.length);t\s*?{[\s;]*?$)/,"$1})"],[/(^[\w\W]*?\([\w\W]*?\)\s*?{[\s;]*?$)/,"$1}"]],n=0;n!=?({]|\/(?![\/*])))))|(0[xX][\da-fA-F]+|0[oO][0-7]+|0[bB][01]+|(?:\d*\.\d+|\d+\.?)(?:[eE][+-]?\d+)?)|((?!\d)(?:(?!\s)[$\w\u0080-\uFFFF]|\\u[\da-fA-F]{4}|\\u\{[\da-fA-F]+\})+)|(--|\+\+|&&|\|\||=>|\.{3}|(?:[+\-\/%&|^]|\*{1,2}|<{1,2}|>{1,3}|!=?|={1,2})=?|[?~.,:;[\](){}])|(\s+)|(^$|[\s\S])/g,i=function(e){var t={type:"invalid",value:e[0]};return e[1]?(t.type="string",t.closed=!(!e[3]&&!e[4])):e[5]?t.type="comment":e[6]?(t.type="comment",t.closed=!!e[7]):e[8]?t.type="regex":e[9]?t.type="number":e[10]?t.type="name":e[11]?t.type="punctuator":e[12]&&(t.type="whitespace"),t},u=function(e){return e.match(o).map(function(e){return o.lastIndex=0,i(o.exec(e))}).map(function(e){return"name"===e.type&&r(e.value)&&(e.type="keyword"),e})};e.exports=u},function(e,t,n){"use strict";function r(e){var t=e.stack.replace(/^[^:]+: /,"");delete e.stack,e=JSON.stringify(e,null,4),this.name="TemplateError",this.message=e,this.stack=t}r.prototype=Object.create(Error.prototype),r.prototype.constructor=r,e.exports=r},function(e,t,n){"use strict";var r=function(e,t,n){for(var r=[{type:"string",value:e,line:0,start:0,end:e.length}],o=0;o