diff --git a/.travis.yml b/.travis.yml index 6f3fad1b..a6e57f87 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,7 +11,6 @@ install: - npm install script: - npm run build - - export NODE_ENV=production && node_modules/mocha/bin/_mocha --ui exports --colors 'test/**/*.js' - npm test after_success: - npm run coverage \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 44aae625..b6410b9b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # CHANGELOG +## v4.8.1 + +1. 修复低版本 NodeJS 报错问题 + ## v4.8.0 1. 过滤器支持在运行时注入 [#4](https://github.com/aui/art-template-loader/issues/4) diff --git a/lib/compile/adapter/extend.js b/lib/compile/adapter/extend.js index ed73ef61..ce66521e 100644 --- a/lib/compile/adapter/extend.js +++ b/lib/compile/adapter/extend.js @@ -7,7 +7,7 @@ var toType = function toType(value) { }; /** - * 继承 + * 快速继承默认配置 * @param {Object} options * @param {?Object} defaults * @return {Object} @@ -24,7 +24,9 @@ var extend = function extend(target, defaults) { if (object) { for (var index in target) { - object[index] = extend(target[index], object[index]); + if (target.hasOwnProperty(index)) { + object[index] = extend(target[index], object[index]); + } } return object; } else { diff --git a/lib/template-web.js b/lib/template-web.js index fc8c431f..f8625577 100644 --- a/lib/template-web.js +++ b/lib/template-web.js @@ -1,3 +1,3 @@ -/*! art-template@4.8.0 | 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 i=n[r]={i:r,l:!1,exports:{}};return e[r].call(i.exports,i,i.exports,t),i.l=!0,i.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){(function(t){e.exports=!1;try{e.exports="[object process]"===Object.prototype.toString.call(t.process)}catch(n){}}).call(t,n(4))},function(e,t,n){"use strict";var r=n(18),i=n(2),o=n(21),s=function(e,t){t.onerror(e,t);var n=function(){return"{Template Error}"};return n.mappings=[],n.sourcesContent=[],n},c=function a(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{};"string"!=typeof e?t=e:t.source=e,t=i.$extend(t),e=t.source,t.debug&&(t.cache=!1,t.bail=!1,t.minimize=!1,t.compileDebug=!0),t.filename&&(t.filename=t.resolveFilename(t.filename,t));var n=t.filename,c=t.cache,u=t.caches;if(c&&n){var p=u.get(n);if(p)return p}if(!e)try{e=t.loader(n,t),t.source=e}catch(d){var l=new o({name:"CompileError",message:"template not found: "+d.message,stack:d.stack});if(t.bail)throw l;return s(l,t)}var f=void 0,h=new r(t);try{f=h.build()}catch(l){if(l=new o(l),t.bail)throw l;return s(l,t)}var m=function(e,n){try{return f(e,n)}catch(l){if(!t.compileDebug)return t.cache=!1,t.compileDebug=!0,a(t)(e,n);if(l=new o(l),t.bail)throw l;return s(l,t)()}};return m.mappings=f.mappings,m.toString=function(){return f.toString()},c&&n&&u.set(n,m),m};c.Compiler=r,e.exports=c},function(e,t,n){"use strict";var r=n(0),i=n(20),o=n(10),s=n(14),c=n(7),a=n(13),u=n(12),p=n(16),l=n(17),f=n(11),h=n(15),m={source:null,filename:null,rules:[l,p],escape:!0,debug:!!r&&"production"!==process.env.NODE_ENV,bail:!1,cache:!0,minimize:!0,compileDebug:!1,resolveFilename:h,htmlMinifier:f,htmlMinifierOptions:{collapseWhitespace:!0,minifyCSS:!0,minifyJS:!0,ignoreCustomFragments:[]},onerror:s,loader:a,caches:c,root:"/",extname:".art",ignore:[],imports:i};m.$extend=function(){var e=arguments.length>0&&arguments[0]!==undefined?arguments[0]:{};return o(e,m)},i.$include=u,e.exports=m},function(e,t){},function(e,t){var n;n=function(){return this}();try{n=n||Function("return this")()||(0,eval)("this")}catch(r){"object"==typeof window&&(n=window)}e.exports=n},function(e,t,n){"use strict";e.exports=n(2)},function(e,t,n){"use strict";var r=n(1),i=function(e,t,n){return r(e,n)(t)};e.exports=i},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]/,o=function(e){var t=""+e,n=i.exec(t);if(!n)return e;var r="",o=void 0,s=void 0,c=void 0;for(o=n.index,s=0;o>>","{{"+t+"}}","\n",s.filename||"")};switch("#"===t&&h("#value","@value"),f){case"set":i="var "+a.join("");break;case"if":i="if("+a.join("")+"){";break;case"else":var m=a.indexOf("if");m>-1?(a.splice(0,m+1),i="}else if("+a.join("")+"){"):i="}else{";break;case"/if":i="}";break;case"each":p=r._split(c),p.shift(),"as"===p[1]&&(h("each object as value index","each object value index"),p.splice(1,1));var d=p[0]||"$data",v=p[1]||"$value",g=p[2]||"$index";i="$each("+d+",function("+v+","+g+"){";break;case"/each":i="})";break;case"echo":f="print",h("echo value","value");case"print":case"include":case"extend":p=r._split(c),p.shift(),i=f+"("+p.join(",")+")";break;case"block":i="block("+a.join("")+",function(){";break;case"/block":i="})";break;default:if(-1!==a.indexOf("|")){for(var y=f,x=[],b=a.filter(function(e){return!/^\s+$/.test(e)});"|"!==b[0];)y+=b.shift();b.filter(function(e){return":"!==e}).forEach(function(e){"|"===e?x.push([]):x[x.length-1].push(e)}),x.reduce(function(e,t){var n=t.shift();return t.unshift(e),i="$imports."+n+"("+t.join(",")+")"},y)}else s.imports[f]?(h("filterName value","value | filterName"),p=r._split(c),p.shift(),i=f+"("+p.join(",")+")",l="raw"):i=""+f+a.join("");l||(l="escape")}return u.code=i,u.output=l,u},_split:function(e){for(var t=0,n=e.shift(),r=[[n]];t/,use:function(e,t,n,r){return n={"-":"raw","=":"escape","":!1,"==":"raw","=#":"raw"}[n],t&&(r="/*"+e+"*/",n=!1),{code:r,output:n}}};e.exports=r},function(e,t,n){"use strict";function r(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}var i=n(19),o=n(22),s="$data",c="$imports",a="print",u="include",p="extend",l="block",f="$$out",h="$$line",m="$$blocks",d="$$from",v="$$layout",g="$$options",y=function(e,t){return e.hasOwnProperty(t)},x=JSON.stringify,b=function(){function e(t){var n,i,y,x=this;r(this,e);var b=t.source,k=t.minimize,w=t.htmlMinifier;if(this.options=t,this.stacks=[],this.context=[],this.scripts=[],this.CONTEXT_MAP={},this.external=(n={},n[s]=!0,n[c]=!0,n[g]=!0,n),this.internal=(i={},i[f]="''",i[h]="[0,0,'']",i[m]="arguments[1]||{}",i[d]="null",i[v]="function(){return "+c+".$include("+d+","+s+","+m+","+g+")}",i[a]="function(){"+f+"+=''.concat.apply('',arguments)}",i[u]="function(src,data,block){"+f+"+="+c+".$include(src,data||"+s+",block,"+g+")}",i[p]="function(from){"+d+"=from}",i[l]="function(name,callback){if("+d+"){"+f+"='';callback();"+m+"[name]="+f+"}else{if(typeof "+m+"[name]==='string'){"+f+"+="+m+"[name]}else{callback()}}}",i),this.dependencies=(y={},y[a]=[f],y[u]=[f,c,s,g],y[p]=[d,v],y[l]=[d,f,m],y[v]=[c,d,s,m,g],y),this.importContext(f),t.compileDebug&&this.importContext(h),k)try{b=w(b,t)}catch(E){}this.source=b,this.getTplTokens(b,t.rules,this).forEach(function(e){e.type===o.TYPE_STRING?x.parseString(e):x.parseExpression(e)})}return e.prototype.getTplTokens=function(){return o.apply(undefined,arguments)},e.prototype.getEsTokens=function(e){return i(e)},e.prototype.getVariables=function(e){var t=!1;return e.filter(function(e){return"whitespace"!==e.type&&"comment"!==e.type}).filter(function(e){return"name"===e.type&&!t||(t="punctuator"===e.type&&"."===e.value,!1)}).map(function(e){return e.value})},e.prototype.importContext=function(e){var t=this,n="",r=this.internal,i=this.dependencies,o=this.external,a=this.context,u=this.options,p=u.ignore,l=u.imports,f=this.CONTEXT_MAP;!y(f,e)&&!y(o,e)&&p.indexOf(e)<0&&(y(r,e)?(n=r[e],y(i,e)&&i[e].forEach(function(e){return t.importContext(e)})):n=y(l,e)?c+"."+e:s+"."+e,f[e]=n,a.push({name:e,value:n}))},e.prototype.parseString=function(e){var t=e.value;if(t){var n=f+"+="+x(t);this.scripts.push({source:t,tplToken:e,code:n})}},e.prototype.parseExpression=function(e){var t=this,n=e.value,r=e.script,i=r.output,s=r.code;i&&(s=!1===escape||i===o.TYPE_RAW?f+"+="+r.code:f+"+=$escape("+r.code+")");var c=this.getEsTokens(s);this.getVariables(c).forEach(function(e){return t.importContext(e)}),this.scripts.push({source:n,tplToken:e,code:s})},e.prototype.checkExpression=function(e){for(var t=[[/^\s*}[\w\W]*?{?[\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,o=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},s=function(e){return e.match(i).map(function(e){return i.lastIndex=0,o(i.exec(e))}).map(function(e){return"name"===e.type&&r(e.value)&&(e.type="keyword"),e})};e.exports=s},function(e,t,n){"use strict";(function(t){/*! art-template@runtime | https://github.com/aui/art-template */ -var r=n(0),i=n(8),o=n(9),s=Object.create(r?t:window);s.$each=i,s.$escape=o,e.exports=s}).call(t,n(4))},function(e,t,n){"use strict";function r(e){var t=e.stack;delete e.stack,this.name="TemplateError",this.message=JSON.stringify(e,null,4),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}],i=0;i1&&arguments[1]!==undefined?arguments[1]:{};"string"!=typeof e?t=e:t.source=e,t=i.$extend(t),e=t.source,t.debug&&(t.cache=!1,t.bail=!1,t.minimize=!1,t.compileDebug=!0),t.filename&&(t.filename=t.resolveFilename(t.filename,t));var n=t.filename,a=t.cache,u=t.caches;if(a&&n){var p=u.get(n);if(p)return p}if(!e)try{e=t.loader(n,t),t.source=e}catch(d){var l=new o({name:"CompileError",message:"template not found: "+d.message,stack:d.stack});if(t.bail)throw l;return s(l,t)}var f=void 0,h=new r(t);try{f=h.build()}catch(l){if(l=new o(l),t.bail)throw l;return s(l,t)}var m=function(e,n){try{return f(e,n)}catch(l){if(!t.compileDebug)return t.cache=!1,t.compileDebug=!0,c(t)(e,n);if(l=new o(l),t.bail)throw l;return s(l,t)()}};return m.mappings=f.mappings,m.toString=function(){return f.toString()},a&&n&&u.set(n,m),m};a.Compiler=r,e.exports=a},function(e,t,n){"use strict";var r=n(0),i=n(20),o=n(10),s=n(14),a=n(7),c=n(13),u=n(12),p=n(16),l=n(17),f=n(11),h=n(15),m={source:null,filename:null,rules:[l,p],escape:!0,debug:!!r&&"production"!==process.env.NODE_ENV,bail:!1,cache:!0,minimize:!0,compileDebug:!1,resolveFilename:h,htmlMinifier:f,htmlMinifierOptions:{collapseWhitespace:!0,minifyCSS:!0,minifyJS:!0,ignoreCustomFragments:[]},onerror:s,loader:c,caches:a,root:"/",extname:".art",ignore:[],imports:i};m.$extend=function(){var e=arguments.length>0&&arguments[0]!==undefined?arguments[0]:{};return o(e,m)},i.$include=u,e.exports=m},function(e,t){},function(e,t){var n;n=function(){return this}();try{n=n||Function("return this")()||(0,eval)("this")}catch(r){"object"==typeof window&&(n=window)}e.exports=n},function(e,t,n){"use strict";e.exports=n(2)},function(e,t,n){"use strict";var r=n(1),i=function(e,t,n){return r(e,n)(t)};e.exports=i},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]/,o=function(e){var t=""+e,n=i.exec(t);if(!n)return e;var r="",o=void 0,s=void 0,a=void 0;for(o=n.index,s=0;o>>","{{"+t+"}}","\n",s.filename||"")};switch("#"===t&&h("#value","@value"),f){case"set":i="var "+c.join("");break;case"if":i="if("+c.join("")+"){";break;case"else":var m=c.indexOf("if");m>-1?(c.splice(0,m+1),i="}else if("+c.join("")+"){"):i="}else{";break;case"/if":i="}";break;case"each":p=r._split(a),p.shift(),"as"===p[1]&&(h("each object as value index","each object value index"),p.splice(1,1));var d=p[0]||"$data",v=p[1]||"$value",g=p[2]||"$index";i="$each("+d+",function("+v+","+g+"){";break;case"/each":i="})";break;case"echo":f="print",h("echo value","value");case"print":case"include":case"extend":p=r._split(a),p.shift(),i=f+"("+p.join(",")+")";break;case"block":i="block("+c.join("")+",function(){";break;case"/block":i="})";break;default:if(-1!==c.indexOf("|")){for(var y=f,x=[],b=c.filter(function(e){return!/^\s+$/.test(e)});"|"!==b[0];)y+=b.shift();b.filter(function(e){return":"!==e}).forEach(function(e){"|"===e?x.push([]):x[x.length-1].push(e)}),x.reduce(function(e,t){var n=t.shift();return t.unshift(e),i="$imports."+n+"("+t.join(",")+")"},y)}else s.imports[f]?(h("filterName value","value | filterName"),p=r._split(a),p.shift(),i=f+"("+p.join(",")+")",l="raw"):i=""+f+c.join("");l||(l="escape")}return u.code=i,u.output=l,u},_split:function(e){for(var t=0,n=e.shift(),r=[[n]];t/,use:function(e,t,n,r){return n={"-":"raw","=":"escape","":!1,"==":"raw","=#":"raw"}[n],t&&(r="/*"+e+"*/",n=!1),{code:r,output:n}}};e.exports=r},function(e,t,n){"use strict";function r(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}var i=n(19),o=n(22),s="$data",a="$imports",c="print",u="include",p="extend",l="block",f="$$out",h="$$line",m="$$blocks",d="$$from",v="$$layout",g="$$options",y=function(e,t){return e.hasOwnProperty(t)},x=JSON.stringify,b=function(){function e(t){var n,i,y,x=this;r(this,e);var b=t.source,k=t.minimize,w=t.htmlMinifier;if(this.options=t,this.stacks=[],this.context=[],this.scripts=[],this.CONTEXT_MAP={},this.external=(n={},n[s]=!0,n[a]=!0,n[g]=!0,n),this.internal=(i={},i[f]="''",i[h]="[0,0,'']",i[m]="arguments[1]||{}",i[d]="null",i[v]="function(){return "+a+".$include("+d+","+s+","+m+","+g+")}",i[c]="function(){"+f+"+=''.concat.apply('',arguments)}",i[u]="function(src,data,block){"+f+"+="+a+".$include(src,data||"+s+",block,"+g+")}",i[p]="function(from){"+d+"=from}",i[l]="function(name,callback){if("+d+"){"+f+"='';callback();"+m+"[name]="+f+"}else{if(typeof "+m+"[name]==='string'){"+f+"+="+m+"[name]}else{callback()}}}",i),this.dependencies=(y={},y[c]=[f],y[u]=[f,a,s,g],y[p]=[d,v],y[l]=[d,f,m],y[v]=[a,d,s,m,g],y),this.importContext(f),t.compileDebug&&this.importContext(h),k)try{b=w(b,t)}catch(E){}this.source=b,this.getTplTokens(b,t.rules,this).forEach(function(e){e.type===o.TYPE_STRING?x.parseString(e):x.parseExpression(e)})}return e.prototype.getTplTokens=function(){return o.apply(undefined,arguments)},e.prototype.getEsTokens=function(e){return i(e)},e.prototype.getVariables=function(e){var t=!1;return e.filter(function(e){return"whitespace"!==e.type&&"comment"!==e.type}).filter(function(e){return"name"===e.type&&!t||(t="punctuator"===e.type&&"."===e.value,!1)}).map(function(e){return e.value})},e.prototype.importContext=function(e){var t=this,n="",r=this.internal,i=this.dependencies,o=this.external,c=this.context,u=this.options,p=u.ignore,l=u.imports,f=this.CONTEXT_MAP;!y(f,e)&&!y(o,e)&&p.indexOf(e)<0&&(y(r,e)?(n=r[e],y(i,e)&&i[e].forEach(function(e){return t.importContext(e)})):n=y(l,e)?a+"."+e:s+"."+e,f[e]=n,c.push({name:e,value:n}))},e.prototype.parseString=function(e){var t=e.value;if(t){var n=f+"+="+x(t);this.scripts.push({source:t,tplToken:e,code:n})}},e.prototype.parseExpression=function(e){var t=this,n=e.value,r=e.script,i=r.output,s=r.code;i&&(s=!1===escape||i===o.TYPE_RAW?f+"+="+r.code:f+"+=$escape("+r.code+")");var a=this.getEsTokens(s);this.getVariables(a).forEach(function(e){return t.importContext(e)}),this.scripts.push({source:n,tplToken:e,code:s})},e.prototype.checkExpression=function(e){for(var t=[[/^\s*}[\w\W]*?{?[\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,o=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},s=function(e){return e.match(i).map(function(e){return i.lastIndex=0,o(i.exec(e))}).map(function(e){return"name"===e.type&&r(e.value)&&(e.type="keyword"),e})};e.exports=s},function(e,t,n){"use strict";(function(t){/*! art-template@runtime | https://github.com/aui/art-template */ +var r=n(0),i=n(8),o=n(9),s=Object.create(r?t:window);s.$each=i,s.$escape=o,e.exports=s}).call(t,n(4))},function(e,t,n){"use strict";function r(e){var t=e.stack;delete e.stack,this.name="TemplateError",this.message=JSON.stringify(e,null,4),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}],i=0;i { /** - * 继承 + * 快速继承默认配置 * @param {Object} options * @param {?Object} defaults * @return {Object} @@ -23,7 +23,9 @@ const extend = function (target, defaults) { if (object) { for (let index in target) { - object[index] = extend(target[index], object[index]); + if (target.hasOwnProperty(index)) { + object[index] = extend(target[index], object[index]); + } } return object; } else { @@ -31,5 +33,4 @@ const extend = function (target, defaults) { } }; - module.exports = extend; \ No newline at end of file diff --git a/test/compile/index.js b/test/compile/index.js index aaf97a16..4df389a2 100644 --- a/test/compile/index.js +++ b/test/compile/index.js @@ -237,6 +237,7 @@ module.exports = { test(`{{time * 1000 | dateFormat 'yyyy-MM-dd'}}`, { time: 1491566794 }, `2017-04-07`, options); + test(`{{3.14 | parseInt}}`, {}, `3`, options); test(`{{time | dateFormat:'yyyy-MM-dd'}}`, { time: 1491566794863 }, `2017-04-07`, options); // ... v3 compat ...