diff --git a/lib/template-node.js b/lib/template-node.js index 5eb32016..6b8e4c6d 100644 --- a/lib/template-node.js +++ b/lib/template-node.js @@ -249,11 +249,22 @@ function extend(options) { var copy = Object.create(this); for (var name in options) { + + var object = void 0; var value = options[name]; var type = toType(value); - if (type === 'Array' || type === 'Object') { - copy[name] = extend.call(copy[name], value); + if (type === 'Object') { + object = Object.create(copy[name]); + } else if (type === 'Array') { + object = [].concat(copy[name]); + } + + if (object) { + for (var index in value) { + object[index] = value[index]; + } + copy[name] = object; } else { copy[name] = value; } diff --git a/lib/template-web.js b/lib/template-web.js index 62502984..215a2641 100644 --- a/lib/template-web.js +++ b/lib/template-web.js @@ -1,2 +1,2 @@ /*! art-template@4.5.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 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(n){}}).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),s=n(21),c=function(e,t){t.onerror(e,t);var n=function(){return"{Template Error}"};return n.mappings=[],n},u=function a(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{};"object"===(void 0===e?"undefined":r(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,u=t.cache,l=t.caches;if(u&&n){var p=l.get(n);if(p)return p}if(!e)try{e=t.loader(n,t),t.source=e}catch(d){var f=new s({name:"CompileError",message:"template not found: "+d.message,stack:d.stack});if(t.bail)throw f;return c(f,t)}var m=void 0,h=new o(t);try{m=h.build()}catch(f){if(f=new s(f),t.bail)throw f;return c(f,t)}var y=function(e,n){try{return m(e,n)}catch(f){if(!t.compileDebug)return t.cache=!1,t.compileDebug=!0,a(t)(e,n);if(f=new s(f),t.bail)throw f;return c(f,t)()}};return y.mappings=m.mappings,y.toString=function(){return m.toString()},u&&n&&l.set(n,y),y};u.Compiler=o,e.exports=u},function(e,t,n){"use strict";function r(e){var t=Object.create(this);for(var n in e){var o=e[n],i=d(o);t[n]="Array"===i||"Object"===i?r.call(t[n],o):o}return t}var o=n(0),i=n(15),s=n(9),c=n(11),u=n(14),a=n(13),l=n(10),p=n(17),f=n(18),m=n(12),h=n(16),y=Object.prototype.toString,d=function(e){return null===e?"Null":y.call(e).slice(8,-1)},v={source:null,filename:null,rules:[f,p],escape:!0,debug:!!o&&"production"!==process.env.NODE_ENV,bail:!1,cache:!0,minimize:!0,compileDebug:!1,resolveFilename:h,htmlMinifier:m,onerror:i,loader:u,caches:s,root:"/",extname:".art",imports:{$each:l,$escape:c,$include:a}};v.$extend=r,e.exports=v},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(i){"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 n(e){return"string"!=typeof e&&(e="function"==typeof e?n(e.call(e)):null===e?"":JSON.stringify(e)||""),e}(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),s=t.root,c=t.extname;if(o.test(e)){var u=t.filename,a=!u||e===u,l=a?s:i.dirname(u);e=i.resolve(l,e)}else e=i.resolve(s,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,s=i.options,c=i.getEsTokens(r.trim()),u=c.map(function(e){return e.value}),a={},l=void 0,p=!!t&&"raw",f=n+u.shift(),m=function(e,t){console.warn("Template upgrade:","{{"+e+"}}",">>>","{{"+t+"}}","\n",s.filename||"")};switch("#"===t&&m("#value","@value"),f){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":f="print",m("echo value","value");case"print":case"include":case"extend":l=o(c),l.shift(),r=f+"("+l.join(",")+")";break;case"block":r="block("+u.join("")+",function(){";break;case"/block":r="})";break;default:if(-1!==u.indexOf("|")){for(var b=f,g=[],x=u.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 s.imports[f]?(m("filterName value","value | filterName"),l=o(c),l.shift(),r=f+"("+l.join(",")+")",p="raw"):r=""+f+u.join("");p||(p="escape")}return a.code=r,a.output=p,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,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}var o=n(20),i=n(22),s="$data",c="$imports",u="print",a="include",l="extend",p="block",f="$$out",m="$$line",h="$$blocks",y="$$from",d="$$layout",v="$$options",b=function(e,t){return e.hasOwnProperty(t)},g=JSON.stringify,x=function(){function e(t){var n,o,b,g=this;r(this,e);var x=t.source,w=t.minimize,S=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[v]=!0,n),this.internal=(o={},o[f]="''",o[m]="[0,0,'']",o[h]="arguments[1]||{}",o[y]="null",o[d]="function(){return "+c+".$include("+y+","+s+","+h+","+v+")}",o[u]="function(){"+f+"+=''.concat.apply('',arguments)}",o[a]="function(src,data,block){"+f+"+="+c+".$include(src,data||"+s+",block,"+v+")}",o[l]="function(from){"+y+"=from}",o[p]="function(name,callback){if("+y+"){"+f+"='';callback();"+h+"[name]="+f+"}else{if(typeof "+h+"[name]==='string'){"+f+"+="+h+"[name]}else{callback()}}}",o),this.dependencies=(b={},b[u]=[f],b[a]=[f,c,s,v],b[l]=[y,d],b[p]=[y,f,h],b[d]=[c,y,s,h,v],b),this.importContext(f),t.compileDebug&&this.importContext(m),w)try{x=S(x,t)}catch(k){}this.getTplTokens(x,t.rules,this).forEach(function(e){e.type===i.TYPE_STRING?g.parseString(e):g.parseExpression(e)})}return e.prototype.getTplTokens=function(){return i.apply(undefined,arguments)},e.prototype.getEsTokens=function(e){return o(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,o=this.dependencies,i=this.external,u=this.context,a=this.options,l=a.imports,p=this.CONTEXT_MAP;b(p,e)||b(i,e)||(b(r,e)?(n=r[e],b(o,e)&&o[e].forEach(function(e){return t.importContext(e)})):n=b(l,e)?c+"."+e:s+"."+e,p[e]=n,u.push({name:e,value:n}))},e.prototype.parseString=function(e){var t=e.value;if(t){var n=f+"+="+g(t);this.scripts.push({source:t,tplToken:e,code:n})}},e.prototype.parseExpression=function(e){var t=this,n=e.value,r=e.script,o=r.output,s=r.code;o&&(s=!1===escape||o===i.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*?}.*?{?[\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(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(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=s},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}],o=0;o1&&arguments[1]!==undefined?arguments[1]:{};"object"===(void 0===e?"undefined":r(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,u=t.cache,l=t.caches;if(u&&n){var p=l.get(n);if(p)return p}if(!e)try{e=t.loader(n,t),t.source=e}catch(d){var f=new c({name:"CompileError",message:"template not found: "+d.message,stack:d.stack});if(t.bail)throw f;return s(f,t)}var m=void 0,h=new o(t);try{m=h.build()}catch(f){if(f=new c(f),t.bail)throw f;return s(f,t)}var y=function(e,n){try{return m(e,n)}catch(f){if(!t.compileDebug)return t.cache=!1,t.compileDebug=!0,a(t)(e,n);if(f=new c(f),t.bail)throw f;return s(f,t)()}};return y.mappings=m.mappings,y.toString=function(){return m.toString()},u&&n&&l.set(n,y),y};u.Compiler=o,e.exports=u},function(e,t,n){"use strict";function r(e){var t=Object.create(this);for(var n in e){var r=void 0,o=e[n],i=d(o);if("Object"===i?r=Object.create(t[n]):"Array"===i&&(r=[].concat(t[n])),r){for(var c in o)r[c]=o[c];t[n]=r}else t[n]=o}return t}var o=n(0),i=n(15),c=n(9),s=n(11),u=n(14),a=n(13),l=n(10),p=n(17),f=n(18),m=n(12),h=n(16),y=Object.prototype.toString,d=function(e){return null===e?"Null":y.call(e).slice(8,-1)},v={source:null,filename:null,rules:[f,p],escape:!0,debug:!!o&&"production"!==process.env.NODE_ENV,bail:!1,cache:!0,minimize:!0,compileDebug:!1,resolveFilename:h,htmlMinifier:m,onerror:i,loader:u,caches:c,root:"/",extname:".art",imports:{$each:l,$escape:s,$include:a}};v.$extend=r,e.exports=v},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(i){"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 n(e){return"string"!=typeof e&&(e="function"==typeof e?n(e.call(e)):null===e?"":JSON.stringify(e)||""),e}(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),c=t.root,s=t.extname;if(o.test(e)){var u=t.filename,a=!u||e===u,l=a?c:i.dirname(u);e=i.resolve(l,e)}else e=i.resolve(c,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,c=i.options,s=i.getEsTokens(r.trim()),u=s.map(function(e){return e.value}),a={},l=void 0,p=!!t&&"raw",f=n+u.shift(),m=function(e,t){console.warn("Template upgrade:","{{"+e+"}}",">>>","{{"+t+"}}","\n",c.filename||"")};switch("#"===t&&m("#value","@value"),f){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(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":f="print",m("echo value","value");case"print":case"include":case"extend":l=o(s),l.shift(),r=f+"("+l.join(",")+")";break;case"block":r="block("+u.join("")+",function(){";break;case"/block":r="})";break;default:if(-1!==u.indexOf("|")){for(var b=f,g=[],x=u.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 c.imports[f]?(m("filterName value","value | filterName"),l=o(s),l.shift(),r=f+"("+l.join(",")+")",p="raw"):r=""+f+u.join("");p||(p="escape")}return a.code=r,a.output=p,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,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}var o=n(20),i=n(22),c="$data",s="$imports",u="print",a="include",l="extend",p="block",f="$$out",m="$$line",h="$$blocks",y="$$from",d="$$layout",v="$$options",b=function(e,t){return e.hasOwnProperty(t)},g=JSON.stringify,x=function(){function e(t){var n,o,b,g=this;r(this,e);var x=t.source,w=t.minimize,S=t.htmlMinifier;if(this.options=t,this.stacks=[],this.context=[],this.scripts=[],this.CONTEXT_MAP={},this.external=(n={},n[c]=!0,n[s]=!0,n[v]=!0,n),this.internal=(o={},o[f]="''",o[m]="[0,0,'']",o[h]="arguments[1]||{}",o[y]="null",o[d]="function(){return "+s+".$include("+y+","+c+","+h+","+v+")}",o[u]="function(){"+f+"+=''.concat.apply('',arguments)}",o[a]="function(src,data,block){"+f+"+="+s+".$include(src,data||"+c+",block,"+v+")}",o[l]="function(from){"+y+"=from}",o[p]="function(name,callback){if("+y+"){"+f+"='';callback();"+h+"[name]="+f+"}else{if(typeof "+h+"[name]==='string'){"+f+"+="+h+"[name]}else{callback()}}}",o),this.dependencies=(b={},b[u]=[f],b[a]=[f,s,c,v],b[l]=[y,d],b[p]=[y,f,h],b[d]=[s,y,c,h,v],b),this.importContext(f),t.compileDebug&&this.importContext(m),w)try{x=S(x,t)}catch(k){}this.getTplTokens(x,t.rules,this).forEach(function(e){e.type===i.TYPE_STRING?g.parseString(e):g.parseExpression(e)})}return e.prototype.getTplTokens=function(){return i.apply(undefined,arguments)},e.prototype.getEsTokens=function(e){return o(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,o=this.dependencies,i=this.external,u=this.context,a=this.options,l=a.imports,p=this.CONTEXT_MAP;b(p,e)||b(i,e)||(b(r,e)?(n=r[e],b(o,e)&&o[e].forEach(function(e){return t.importContext(e)})):n=b(l,e)?s+"."+e:c+"."+e,p[e]=n,u.push({name:e,value:n}))},e.prototype.parseString=function(e){var t=e.value;if(t){var n=f+"+="+g(t);this.scripts.push({source:t,tplToken:e,code:n})}},e.prototype.parseExpression=function(e){var t=this,n=e.value,r=e.script,o=r.output,c=r.code;o&&(c=!1===escape||o===i.TYPE_RAW?f+"+="+r.code:f+"+=$escape("+r.code+")");var s=this.getEsTokens(c);this.getVariables(s).forEach(function(e){return t.importContext(e)}),this.scripts.push({source:n,tplToken:e,code:c})},e.prototype.checkExpression=function(e){for(var t=[[/^\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(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},c=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=c},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}],o=0;o { * @return {Object} */ function extend(options) { - const copy = Object.create(this); + let copy = Object.create(this); for (let name in options) { + + let object; const value = options[name]; const type = toType(value); - if (type === 'Array' || type === 'Object') { - copy[name] = extend.call(copy[name], value); + if (type === 'Object') { + object = Object.create(copy[name]); + } else if (type === 'Array') { + object = [].concat(copy[name]); + } + + if (object) { + for (let index in value) { + object[index] = value[index]; + } + copy[name] = object; } else { copy[name] = value; } diff --git a/test/compile/defaults.js b/test/compile/defaults.js index 2e78f491..c73f2710 100644 --- a/test/compile/defaults.js +++ b/test/compile/defaults.js @@ -30,15 +30,6 @@ module.exports = { assert.deepEqual(null, options.rules[0]); assert.deepEqual(rules[1], options.rules[1]); assert.deepEqual(length, rules.length); - - // const rules = defaults.rules; - // const length = rules.length; - // const options = defaults.$extend({ - // rules: [] - // }); - - // assert.deepEqual(0, options.rules.length); - // assert.deepEqual(length, rules.length); } } }; \ No newline at end of file