compiler.common.js 94 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768
  1. 'use strict';
  2. var entities = require('entities');
  3. /**
  4. * Convert a value to a string that is actually rendered.
  5. *
  6. * @param {*} val
  7. * @return {String}
  8. */
  9. function renderString(val) {
  10. return val == null ? '' : typeof val === 'object' ? JSON.stringify(val, null, 2) : String(val);
  11. }
  12. /**
  13. * Make a map and return a function for checking if a key
  14. * is in that map.
  15. *
  16. * @param {String} str
  17. * @param {Boolean} expectsLowerCase
  18. * @return {Function}
  19. */
  20. function makeMap(str, expectsLowerCase) {
  21. var map = Object.create(null);
  22. var list = str.split(',');
  23. for (var i = 0; i < list.length; i++) {
  24. map[list[i]] = true;
  25. }
  26. return expectsLowerCase ? function (val) {
  27. return map[val.toLowerCase()];
  28. } : function (val) {
  29. return map[val];
  30. };
  31. }
  32. /**
  33. * Check if a tag is a built-in tag.
  34. */
  35. var isBuiltInTag = makeMap('slot,component,render,transition', true);
  36. /**
  37. * Remove an item from an array
  38. *
  39. * @param {Array} arr
  40. * @param {*} item
  41. */
  42. function remove(arr, item) {
  43. if (arr.length) {
  44. var index = arr.indexOf(item);
  45. if (index > -1) {
  46. return arr.splice(index, 1);
  47. }
  48. }
  49. }
  50. /**
  51. * Check whether the object has the property.
  52. *
  53. * @param {Object} obj
  54. * @param {String} key
  55. * @return {Boolean}
  56. */
  57. var hasOwnProperty = Object.prototype.hasOwnProperty;
  58. function hasOwn(obj, key) {
  59. return hasOwnProperty.call(obj, key);
  60. }
  61. /**
  62. * Check if value is primitive
  63. *
  64. * @param {*} value
  65. * @return {Boolean}
  66. */
  67. function isPrimitive(value) {
  68. return typeof value === 'string' || typeof value === 'number';
  69. }
  70. /**
  71. * Create a cached version of a pure function.
  72. *
  73. * @param {Function} fn
  74. * @return {Function}
  75. */
  76. function cached(fn) {
  77. var cache = Object.create(null);
  78. return function cachedFn(str) {
  79. var hit = cache[str];
  80. return hit || (cache[str] = fn(str));
  81. };
  82. }
  83. /**
  84. * Camelize a hyphen-delmited string.
  85. *
  86. * @param {String} str
  87. * @return {String}
  88. */
  89. var camelizeRE = /-(\w)/g;
  90. var camelize = cached(function (str) {
  91. return str.replace(camelizeRE, toUpper);
  92. });
  93. function toUpper(_, c) {
  94. return c ? c.toUpperCase() : '';
  95. }
  96. /**
  97. * Hyphenate a camelCase string.
  98. *
  99. * @param {String} str
  100. * @return {String}
  101. */
  102. var hyphenateRE = /([a-z\d])([A-Z])/g;
  103. var hyphenate = cached(function (str) {
  104. return str.replace(hyphenateRE, '$1-$2').toLowerCase();
  105. });
  106. /**
  107. * Simple bind, faster than native
  108. *
  109. * @param {Function} fn
  110. * @param {Object} ctx
  111. * @return {Function}
  112. */
  113. function bind(fn, ctx) {
  114. return function (a) {
  115. var l = arguments.length;
  116. return l ? l > 1 ? fn.apply(ctx, arguments) : fn.call(ctx, a) : fn.call(ctx);
  117. };
  118. }
  119. /**
  120. * Convert an Array-like object to a real Array.
  121. *
  122. * @param {Array-like} list
  123. * @param {Number} [start] - start index
  124. * @return {Array}
  125. */
  126. function toArray(list, start) {
  127. start = start || 0;
  128. var i = list.length - start;
  129. var ret = new Array(i);
  130. while (i--) {
  131. ret[i] = list[i + start];
  132. }
  133. return ret;
  134. }
  135. /**
  136. * Mix properties into target object.
  137. *
  138. * @param {Object} to
  139. * @param {Object} from
  140. */
  141. function extend(to, from) {
  142. for (var key in from) {
  143. to[key] = from[key];
  144. }
  145. return to;
  146. }
  147. /**
  148. * Quick object check - this is primarily used to tell
  149. * Objects from primitive values when we know the value
  150. * is a JSON-compliant type.
  151. *
  152. * @param {*} obj
  153. * @return {Boolean}
  154. */
  155. function isObject(obj) {
  156. return obj !== null && typeof obj === 'object';
  157. }
  158. /**
  159. * Strict object type check. Only returns true
  160. * for plain JavaScript objects.
  161. *
  162. * @param {*} obj
  163. * @return {Boolean}
  164. */
  165. var toString = Object.prototype.toString;
  166. var OBJECT_STRING = '[object Object]';
  167. function isPlainObject(obj) {
  168. return toString.call(obj) === OBJECT_STRING;
  169. }
  170. /**
  171. * Array type check.
  172. *
  173. * @param {*} obj
  174. * @return {Boolean}
  175. */
  176. var isArray = Array.isArray;
  177. /**
  178. * Check if a string starts with $ or _
  179. *
  180. * @param {String} str
  181. * @return {Boolean}
  182. */
  183. function isReserved(str) {
  184. var c = (str + '').charCodeAt(0);
  185. return c === 0x24 || c === 0x5F;
  186. }
  187. /**
  188. * Define a property.
  189. *
  190. * @param {Object} obj
  191. * @param {String} key
  192. * @param {*} val
  193. * @param {Boolean} [enumerable]
  194. */
  195. function def(obj, key, val, enumerable) {
  196. Object.defineProperty(obj, key, {
  197. value: val,
  198. enumerable: !!enumerable,
  199. writable: true,
  200. configurable: true
  201. });
  202. }
  203. /**
  204. * Parse simple path.
  205. */
  206. var bailRE = /[^\w\.]/;
  207. function parsePath(path) {
  208. if (bailRE.test(path)) {
  209. return;
  210. } else {
  211. path = path.split('.');
  212. return function (obj) {
  213. for (var i = 0; i < path.length; i++) {
  214. if (!obj) return;
  215. obj = obj[path[i]];
  216. }
  217. return obj;
  218. };
  219. }
  220. }
  221. /* global MutationObserver */
  222. // can we use __proto__?
  223. var hasProto = '__proto__' in {};
  224. // Browser environment sniffing
  225. var inBrowser = typeof window !== 'undefined' && Object.prototype.toString.call(window) !== '[object Object]';
  226. // UA sniffing for working around browser-specific quirks
  227. var UA$1 = inBrowser && window.navigator.userAgent.toLowerCase();
  228. var isIos = UA$1 && /(iphone|ipad|ipod|ios)/i.test(UA$1);
  229. var isWechat = UA$1 && UA$1.indexOf('micromessenger') > 0;
  230. /**
  231. * Defer a task to execute it asynchronously. Ideally this
  232. * should be executed as a microtask, so we leverage
  233. * MutationObserver if it's available, and fallback to
  234. * setTimeout(0).
  235. *
  236. * @param {Function} cb
  237. * @param {Object} ctx
  238. */
  239. var nextTick = function () {
  240. var callbacks = [];
  241. var pending = false;
  242. var timerFunc;
  243. function nextTickHandler() {
  244. pending = false;
  245. var copies = callbacks.slice(0);
  246. callbacks = [];
  247. for (var i = 0; i < copies.length; i++) {
  248. copies[i]();
  249. }
  250. }
  251. /* istanbul ignore if */
  252. if (typeof MutationObserver !== 'undefined' && !(isWechat && isIos)) {
  253. var counter = 1;
  254. var observer = new MutationObserver(nextTickHandler);
  255. var textNode = document.createTextNode(counter);
  256. observer.observe(textNode, {
  257. characterData: true
  258. });
  259. timerFunc = function timerFunc() {
  260. counter = (counter + 1) % 2;
  261. textNode.data = counter;
  262. };
  263. } else {
  264. // webpack attempts to inject a shim for setImmediate
  265. // if it is used as a global, so we have to work around that to
  266. // avoid bundling unnecessary code.
  267. var context = inBrowser ? window : typeof global !== 'undefined' ? global : {};
  268. timerFunc = context.setImmediate || setTimeout;
  269. }
  270. return function (cb, ctx) {
  271. var func = ctx ? function () {
  272. cb.call(ctx);
  273. } : cb;
  274. callbacks.push(func);
  275. if (pending) return;
  276. pending = true;
  277. timerFunc(nextTickHandler, 0);
  278. };
  279. }();
  280. var Set$1 = void 0;
  281. /* istanbul ignore if */
  282. if (typeof Set !== 'undefined' && Set.toString().match(/native code/)) {
  283. // use native Set when available.
  284. Set$1 = Set;
  285. } else {
  286. // a non-standard Set polyfill that only works with primitive keys.
  287. Set$1 = function _Set() {
  288. this.set = Object.create(null);
  289. };
  290. Set$1.prototype.has = function (key) {
  291. return this.set[key] !== undefined;
  292. };
  293. Set$1.prototype.add = function (key) {
  294. this.set[key] = 1;
  295. };
  296. Set$1.prototype.clear = function () {
  297. this.set = Object.create(null);
  298. };
  299. }
  300. var hasProxy = void 0;
  301. var proxyHandlers = void 0;
  302. var initProxy = void 0;
  303. if (process.env.NODE_ENV !== 'production') {
  304. (function () {
  305. var allowedGlobals = makeMap('Infinity,undefined,NaN,isFinite,isNaN,' + 'parseFloat,parseInt,decodeURI,decodeURIComponent,encodeURI,encodeURIComponent,' + 'Math,Number,Date,Array,Object,Boolean,String,RegExp,Map,Set,JSON,Intl');
  306. hasProxy = typeof Proxy !== 'undefined' && Proxy.toString().match(/native code/);
  307. proxyHandlers = {
  308. has: function has(target, key) {
  309. var has = key in target;
  310. var isAllowedGlobal = allowedGlobals(key);
  311. if (!has && !isAllowedGlobal) {
  312. warn$1('Trying to access non-existent property "' + key + '" while rendering.', target);
  313. }
  314. return !isAllowedGlobal;
  315. }
  316. };
  317. initProxy = function initProxy(vm) {
  318. if (hasProxy) {
  319. vm._renderProxy = new Proxy(vm, proxyHandlers);
  320. } else {
  321. vm._renderProxy = vm;
  322. }
  323. };
  324. })();
  325. }
  326. var uid$2 = 0;
  327. /**
  328. * A dep is an observable that can have multiple
  329. * directives subscribing to it.
  330. *
  331. * @constructor
  332. */
  333. function Dep() {
  334. this.id = uid$2++;
  335. this.subs = [];
  336. }
  337. // the current target watcher being evaluated.
  338. // this is globally unique because there could be only one
  339. // watcher being evaluated at any time.
  340. Dep.target = null;
  341. /**
  342. * Add a directive subscriber.
  343. *
  344. * @param {Directive} sub
  345. */
  346. Dep.prototype.addSub = function (sub) {
  347. this.subs.push(sub);
  348. };
  349. /**
  350. * Remove a directive subscriber.
  351. *
  352. * @param {Directive} sub
  353. */
  354. Dep.prototype.removeSub = function (sub) {
  355. remove(this.subs, sub);
  356. };
  357. /**
  358. * Add self as a dependency to the target watcher.
  359. */
  360. Dep.prototype.depend = function () {
  361. Dep.target.addDep(this);
  362. };
  363. /**
  364. * Notify all subscribers of a new value.
  365. */
  366. Dep.prototype.notify = function () {
  367. // stablize the subscriber list first
  368. var subs = this.subs.slice();
  369. for (var i = 0, l = subs.length; i < l; i++) {
  370. subs[i].update();
  371. }
  372. };
  373. var config = {
  374. /**
  375. * Preserve whitespaces between elements.
  376. */
  377. preserveWhitespace: true,
  378. /**
  379. * Whether to suppress warnings.
  380. *
  381. * @type {Boolean}
  382. */
  383. silent: false,
  384. /**
  385. * Check if a tag is reserved so that it cannot be registered as a
  386. * component. This is platform-dependent and may be overwritten.
  387. */
  388. isReservedTag: function isReservedTag() {
  389. return false;
  390. },
  391. /**
  392. * Check if a tag is an unknown element.
  393. * Platform-dependent.
  394. */
  395. isUnknownElement: function isUnknownElement() {
  396. return false;
  397. },
  398. /**
  399. * List of asset types that a component can own.
  400. *
  401. * @type {Array}
  402. */
  403. _assetTypes: ['component', 'directive', 'transition'],
  404. /**
  405. * List of lifecycle hooks.
  406. *
  407. * @type {Array}
  408. */
  409. _lifecycleHooks: ['init', 'created', 'beforeMount', 'mounted', 'ready', 'beforeUpdate', 'updated', 'beforeDestroy', 'destroyed'],
  410. /**
  411. * Max circular updates allowed in a batcher flush cycle.
  412. */
  413. _maxUpdateCount: 100
  414. };
  415. // we have two separate queues: one for directive updates
  416. // and one for user watcher registered via $watch().
  417. // we want to guarantee directive updates to be called
  418. // before user watchers so that when user watchers are
  419. // triggered, the DOM would have already been in updated
  420. // state.
  421. var queueIndex;
  422. var queue = [];
  423. var userQueue = [];
  424. var has = {};
  425. var circular = {};
  426. var waiting = false;
  427. var internalQueueDepleted = false;
  428. /**
  429. * Reset the batcher's state.
  430. */
  431. function resetBatcherState() {
  432. queue = [];
  433. userQueue = [];
  434. has = {};
  435. circular = {};
  436. waiting = internalQueueDepleted = false;
  437. }
  438. /**
  439. * Flush both queues and run the watchers.
  440. */
  441. function flushBatcherQueue() {
  442. queue.sort(queueSorter);
  443. runBatcherQueue(queue);
  444. internalQueueDepleted = true;
  445. runBatcherQueue(userQueue);
  446. resetBatcherState();
  447. }
  448. /**
  449. * Sort queue before flush.
  450. * This ensures components are updated from parent to child
  451. * so there will be no duplicate updates, e.g. a child was
  452. * pushed into the queue first and then its parent's props
  453. * changed.
  454. */
  455. function queueSorter(a, b) {
  456. return a.id - b.id;
  457. }
  458. /**
  459. * Run the watchers in a single queue.
  460. *
  461. * @param {Array} queue
  462. */
  463. function runBatcherQueue(queue) {
  464. // do not cache length because more watchers might be pushed
  465. // as we run existing watchers
  466. for (queueIndex = 0; queueIndex < queue.length; queueIndex++) {
  467. var watcher = queue[queueIndex];
  468. var id = watcher.id;
  469. has[id] = null;
  470. watcher.run();
  471. // in dev build, check and stop circular updates.
  472. if (process.env.NODE_ENV !== 'production' && has[id] != null) {
  473. circular[id] = (circular[id] || 0) + 1;
  474. if (circular[id] > config._maxUpdateCount) {
  475. warn$1('You may have an infinite update loop for watcher ' + 'with expression "' + watcher.expression + '"', watcher.vm);
  476. break;
  477. }
  478. }
  479. }
  480. }
  481. /**
  482. * Push a watcher into the watcher queue.
  483. * Jobs with duplicate IDs will be skipped unless it's
  484. * pushed when the queue is being flushed.
  485. *
  486. * @param {Watcher} watcher
  487. * properties:
  488. * - {Number} id
  489. * - {Function} run
  490. */
  491. function pushWatcher(watcher) {
  492. var id = watcher.id;
  493. if (has[id] == null) {
  494. if (internalQueueDepleted && !watcher.user) {
  495. // an internal watcher triggered by a user watcher...
  496. // let's run it immediately after current user watcher is done.
  497. userQueue.splice(queueIndex + 1, 0, watcher);
  498. } else {
  499. // push watcher into appropriate queue
  500. var q = watcher.user ? userQueue : queue;
  501. has[id] = q.length;
  502. q.push(watcher);
  503. // queue the flush
  504. if (!waiting) {
  505. waiting = true;
  506. nextTick(flushBatcherQueue);
  507. }
  508. }
  509. }
  510. }
  511. var uid$1 = 0;
  512. var prevTarget = void 0;
  513. /**
  514. * A watcher parses an expression, collects dependencies,
  515. * and fires callback when the expression value changes.
  516. * This is used for both the $watch() api and directives.
  517. *
  518. * @param {Vue} vm
  519. * @param {String|Function} expOrFn
  520. * @param {Function} cb
  521. * @param {Object} options
  522. * - {Array} filters
  523. * - {Boolean} twoWay
  524. * - {Boolean} deep
  525. * - {Boolean} user
  526. * - {Boolean} sync
  527. * - {Boolean} lazy
  528. * - {Function} [preProcess]
  529. * - {Function} [postProcess]
  530. * @constructor
  531. */
  532. function Watcher(vm, expOrFn, cb, options) {
  533. // mix in options
  534. if (options) {
  535. extend(this, options);
  536. }
  537. var isFn = typeof expOrFn === 'function';
  538. this.vm = vm;
  539. vm._watchers.push(this);
  540. this.expression = expOrFn;
  541. this.cb = cb;
  542. this.id = ++uid$1; // uid for batching
  543. this.active = true;
  544. this.dirty = this.lazy; // for lazy watchers
  545. this.deps = [];
  546. this.newDeps = [];
  547. this.depIds = new Set$1();
  548. this.newDepIds = new Set$1();
  549. // parse expression for getter
  550. if (isFn) {
  551. this.getter = expOrFn;
  552. } else {
  553. this.getter = parsePath(expOrFn);
  554. if (!this.getter) {
  555. this.getter = function () {};
  556. process.env.NODE_ENV !== 'production' && warn$1('Failed watching path: ' + expOrFn + 'Watcher only accepts simple dot-delimited paths. ' + 'For full control, use a function instead.', vm);
  557. }
  558. }
  559. this.value = this.lazy ? undefined : this.get();
  560. // state for avoiding false triggers for deep and Array
  561. // watchers during vm._digest()
  562. this.queued = this.shallow = false;
  563. }
  564. /**
  565. * Evaluate the getter, and re-collect dependencies.
  566. */
  567. Watcher.prototype.get = function () {
  568. this.beforeGet();
  569. var value = this.getter.call(this.vm, this.vm);
  570. // "touch" every property so they are all tracked as
  571. // dependencies for deep watching
  572. if (this.deep) {
  573. traverse(value);
  574. }
  575. this.afterGet();
  576. return value;
  577. };
  578. /**
  579. * Prepare for dependency collection.
  580. */
  581. Watcher.prototype.beforeGet = function () {
  582. prevTarget = Dep.target;
  583. Dep.target = this;
  584. };
  585. /**
  586. * Add a dependency to this directive.
  587. *
  588. * @param {Dep} dep
  589. */
  590. Watcher.prototype.addDep = function (dep) {
  591. var id = dep.id;
  592. if (!this.newDepIds.has(id)) {
  593. this.newDepIds.add(id);
  594. this.newDeps.push(dep);
  595. if (!this.depIds.has(id)) {
  596. dep.addSub(this);
  597. }
  598. }
  599. };
  600. /**
  601. * Clean up for dependency collection.
  602. */
  603. Watcher.prototype.afterGet = function () {
  604. Dep.target = prevTarget;
  605. var i = this.deps.length;
  606. while (i--) {
  607. var dep = this.deps[i];
  608. if (!this.newDepIds.has(dep.id)) {
  609. dep.removeSub(this);
  610. }
  611. }
  612. var tmp = this.depIds;
  613. this.depIds = this.newDepIds;
  614. this.newDepIds = tmp;
  615. this.newDepIds.clear();
  616. tmp = this.deps;
  617. this.deps = this.newDeps;
  618. this.newDeps = tmp;
  619. this.newDeps.length = 0;
  620. };
  621. /**
  622. * Subscriber interface.
  623. * Will be called when a dependency changes.
  624. *
  625. * @param {Boolean} shallow
  626. */
  627. Watcher.prototype.update = function (shallow) {
  628. if (this.lazy) {
  629. this.dirty = true;
  630. } else if (this.sync) {
  631. this.run();
  632. } else {
  633. // if queued, only overwrite shallow with non-shallow,
  634. // but not the other way around.
  635. this.shallow = this.queued ? shallow ? this.shallow : false : !!shallow;
  636. this.queued = true;
  637. pushWatcher(this);
  638. }
  639. };
  640. /**
  641. * Batcher job interface.
  642. * Will be called by the batcher.
  643. */
  644. Watcher.prototype.run = function () {
  645. if (this.active) {
  646. var value = this.get();
  647. if (value !== this.value ||
  648. // Deep watchers and watchers on Object/Arrays should fire even
  649. // when the value is the same, because the value may
  650. // have mutated; but only do so if this is a
  651. // non-shallow update (caused by a vm digest).
  652. (isObject(value) || this.deep) && !this.shallow) {
  653. // set new value
  654. var oldValue = this.value;
  655. this.value = value;
  656. this.cb.call(this.vm, value, oldValue);
  657. }
  658. this.queued = this.shallow = false;
  659. }
  660. };
  661. /**
  662. * Evaluate the value of the watcher.
  663. * This only gets called for lazy watchers.
  664. */
  665. Watcher.prototype.evaluate = function () {
  666. // avoid overwriting another watcher that is being
  667. // collected.
  668. var current = Dep.target;
  669. this.value = this.get();
  670. this.dirty = false;
  671. Dep.target = current;
  672. };
  673. /**
  674. * Depend on all deps collected by this watcher.
  675. */
  676. Watcher.prototype.depend = function () {
  677. var i = this.deps.length;
  678. while (i--) {
  679. this.deps[i].depend();
  680. }
  681. };
  682. /**
  683. * Remove self from all dependencies' subcriber list.
  684. */
  685. Watcher.prototype.teardown = function () {
  686. if (this.active) {
  687. // remove self from vm's watcher list
  688. // this is a somewhat expensive operation so we skip it
  689. // if the vm is being destroyed or is performing a v-for
  690. // re-render (the watcher list is then filtered by v-for).
  691. if (!this.vm._isBeingDestroyed && !this.vm._vForRemoving) {
  692. remove(this.vm._watchers, this);
  693. }
  694. var i = this.deps.length;
  695. while (i--) {
  696. this.deps[i].removeSub(this);
  697. }
  698. this.active = false;
  699. this.vm = this.cb = this.value = null;
  700. }
  701. };
  702. /**
  703. * Recrusively traverse an object to evoke all converted
  704. * getters, so that every nested property inside the object
  705. * is collected as a "deep" dependency.
  706. *
  707. * @param {*} val
  708. * @param {Set} seen
  709. */
  710. var seenObjects = new Set$1();
  711. function traverse(val, seen) {
  712. var i = void 0,
  713. keys = void 0,
  714. isA = void 0,
  715. isO = void 0;
  716. if (!seen) {
  717. seen = seenObjects;
  718. seen.clear();
  719. }
  720. isA = isArray(val);
  721. isO = isObject(val);
  722. if (isA || isO) {
  723. if (val.__ob__) {
  724. var depId = val.__ob__.dep.id;
  725. if (seen.has(depId)) {
  726. return;
  727. } else {
  728. seen.add(depId);
  729. }
  730. }
  731. if (isA) {
  732. i = val.length;
  733. while (i--) {
  734. traverse(val[i], seen);
  735. }
  736. } else if (isO) {
  737. keys = Object.keys(val);
  738. i = keys.length;
  739. while (i--) {
  740. traverse(val[keys[i]], seen);
  741. }
  742. }
  743. }
  744. }
  745. var arrayProto = Array.prototype;
  746. var arrayMethods = Object.create(arrayProto)
  747. /**
  748. * Intercept mutating methods and emit events
  749. */
  750. ;['push', 'pop', 'shift', 'unshift', 'splice', 'sort', 'reverse'].forEach(function (method) {
  751. // cache original method
  752. var original = arrayProto[method];
  753. def(arrayMethods, method, function mutator() {
  754. // avoid leaking arguments:
  755. // http://jsperf.com/closure-with-arguments
  756. var i = arguments.length;
  757. var args = new Array(i);
  758. while (i--) {
  759. args[i] = arguments[i];
  760. }
  761. var result = original.apply(this, args);
  762. var ob = this.__ob__;
  763. var inserted;
  764. switch (method) {
  765. case 'push':
  766. inserted = args;
  767. break;
  768. case 'unshift':
  769. inserted = args;
  770. break;
  771. case 'splice':
  772. inserted = args.slice(2);
  773. break;
  774. }
  775. if (inserted) ob.observeArray(inserted);
  776. // notify change
  777. ob.dep.notify();
  778. return result;
  779. });
  780. });
  781. var arrayKeys = Object.getOwnPropertyNames(arrayMethods);
  782. /**
  783. * By default, when a reactive property is set, the new value is
  784. * also converted to become reactive. However when passing down props,
  785. * we don't want to force conversion because the value may be a nested value
  786. * under a frozen data structure. Converting it would defeat the optimization.
  787. */
  788. var observerState = {
  789. shouldConvert: true
  790. };
  791. /**
  792. * Observer class that are attached to each observed
  793. * object. Once attached, the observer converts target
  794. * object's property keys into getter/setters that
  795. * collect dependencies and dispatches updates.
  796. *
  797. * @param {Array|Object} value
  798. * @constructor
  799. */
  800. function Observer(value) {
  801. this.value = value;
  802. this.dep = new Dep();
  803. def(value, '__ob__', this);
  804. if (isArray(value)) {
  805. var augment = hasProto ? protoAugment : copyAugment;
  806. augment(value, arrayMethods, arrayKeys);
  807. this.observeArray(value);
  808. } else {
  809. this.walk(value);
  810. }
  811. }
  812. // Instance methods
  813. /**
  814. * Walk through each property and convert them into
  815. * getter/setters. This method should only be called when
  816. * value type is Object.
  817. *
  818. * @param {Object} obj
  819. */
  820. Observer.prototype.walk = function (obj) {
  821. for (var key in obj) {
  822. this.convert(key, obj[key]);
  823. }
  824. };
  825. /**
  826. * Observe a list of Array items.
  827. *
  828. * @param {Array} items
  829. */
  830. Observer.prototype.observeArray = function (items) {
  831. for (var i = 0, l = items.length; i < l; i++) {
  832. observe(items[i]);
  833. }
  834. };
  835. /**
  836. * Convert a property into getter/setter so we can emit
  837. * the events when the property is accessed/changed.
  838. *
  839. * @param {String} key
  840. * @param {*} val
  841. */
  842. Observer.prototype.convert = function (key, val) {
  843. defineReactive(this.value, key, val);
  844. };
  845. /**
  846. * Add an owner vm, so that when $set/$delete mutations
  847. * happen we can notify owner vms to proxy the keys and
  848. * digest the watchers. This is only called when the object
  849. * is observed as an instance's root $data.
  850. *
  851. * @param {Vue} vm
  852. */
  853. Observer.prototype.addVm = function (vm) {
  854. (this.vms || (this.vms = [])).push(vm);
  855. };
  856. /**
  857. * Remove an owner vm. This is called when the object is
  858. * swapped out as an instance's $data object.
  859. *
  860. * @param {Vue} vm
  861. */
  862. Observer.prototype.removeVm = function (vm) {
  863. remove(this.vms, vm);
  864. };
  865. // helpers
  866. /**
  867. * Augment an target Object or Array by intercepting
  868. * the prototype chain using __proto__
  869. *
  870. * @param {Object|Array} target
  871. * @param {Object} src
  872. */
  873. function protoAugment(target, src) {
  874. /* eslint-disable no-proto */
  875. target.__proto__ = src;
  876. /* eslint-enable no-proto */
  877. }
  878. /**
  879. * Augment an target Object or Array by defining
  880. * hidden properties.
  881. *
  882. * @param {Object|Array} target
  883. * @param {Object} proto
  884. */
  885. function copyAugment(target, src, keys) {
  886. for (var i = 0, l = keys.length; i < l; i++) {
  887. var key = keys[i];
  888. def(target, key, src[key]);
  889. }
  890. }
  891. /**
  892. * Attempt to create an observer instance for a value,
  893. * returns the new observer if successfully observed,
  894. * or the existing observer if the value already has one.
  895. *
  896. * @param {*} value
  897. * @param {Vue} [vm]
  898. * @return {Observer|undefined}
  899. * @static
  900. */
  901. function observe(value, vm) {
  902. if (!isObject(value)) {
  903. return;
  904. }
  905. var ob;
  906. if (hasOwn(value, '__ob__') && value.__ob__ instanceof Observer) {
  907. ob = value.__ob__;
  908. } else if (observerState.shouldConvert && (isArray(value) || isPlainObject(value)) && Object.isExtensible(value) && !value._isVue) {
  909. ob = new Observer(value);
  910. }
  911. if (ob && vm) {
  912. ob.addVm(vm);
  913. }
  914. return ob;
  915. }
  916. /**
  917. * Define a reactive property on an Object.
  918. *
  919. * @param {Object} obj
  920. * @param {String} key
  921. * @param {*} val
  922. */
  923. function defineReactive(obj, key, val) {
  924. var dep = new Dep();
  925. var property = Object.getOwnPropertyDescriptor(obj, key);
  926. if (property && property.configurable === false) {
  927. return;
  928. }
  929. // cater for pre-defined getter/setters
  930. var getter = property && property.get;
  931. var setter = property && property.set;
  932. var childOb = observe(val);
  933. Object.defineProperty(obj, key, {
  934. enumerable: true,
  935. configurable: true,
  936. get: function reactiveGetter() {
  937. var value = getter ? getter.call(obj) : val;
  938. if (Dep.target) {
  939. dep.depend();
  940. if (childOb) {
  941. childOb.dep.depend();
  942. }
  943. if (isArray(value)) {
  944. for (var e, i = 0, l = value.length; i < l; i++) {
  945. e = value[i];
  946. e && e.__ob__ && e.__ob__.dep.depend();
  947. }
  948. }
  949. }
  950. return value;
  951. },
  952. set: function reactiveSetter(newVal) {
  953. var value = getter ? getter.call(obj) : val;
  954. if (newVal === value) {
  955. return;
  956. }
  957. if (setter) {
  958. setter.call(obj, newVal);
  959. } else {
  960. val = newVal;
  961. }
  962. childOb = observe(newVal);
  963. dep.notify();
  964. }
  965. });
  966. }
  967. /**
  968. * Set a property on an object. Adds the new property and
  969. * triggers change notification if the property doesn't
  970. * already exist.
  971. *
  972. * @param {Object} obj
  973. * @param {String} key
  974. * @param {*} val
  975. * @public
  976. */
  977. function set(obj, key, val) {
  978. if (isArray(obj)) {
  979. return obj.splice(key, 1, val);
  980. }
  981. if (hasOwn(obj, key)) {
  982. obj[key] = val;
  983. return;
  984. }
  985. if (obj._isVue) {
  986. set(obj._data, key, val);
  987. return;
  988. }
  989. var ob = obj.__ob__;
  990. if (!ob) {
  991. obj[key] = val;
  992. return;
  993. }
  994. ob.convert(key, val);
  995. ob.dep.notify();
  996. if (ob.vms) {
  997. var i = ob.vms.length;
  998. while (i--) {
  999. var vm = ob.vms[i];
  1000. proxy(vm, key);
  1001. vm.$forceUpdate();
  1002. }
  1003. }
  1004. return val;
  1005. }
  1006. function proxy(vm, key) {
  1007. if (!isReserved(key)) {
  1008. Object.defineProperty(vm, key, {
  1009. configurable: true,
  1010. enumerable: true,
  1011. get: function proxyGetter() {
  1012. return vm._data[key];
  1013. },
  1014. set: function proxySetter(val) {
  1015. vm._data[key] = val;
  1016. }
  1017. });
  1018. }
  1019. }
  1020. function unproxy(vm, key) {
  1021. if (!isReserved(key)) {
  1022. delete vm[key];
  1023. }
  1024. }
  1025. function initState(vm) {
  1026. vm._watchers = [];
  1027. initProps(vm);
  1028. initData(vm);
  1029. initComputed(vm);
  1030. initMethods(vm);
  1031. initWatch(vm);
  1032. }
  1033. function initProps(vm) {
  1034. var props = vm.$options.props;
  1035. var propsData = vm.$options.propsData;
  1036. if (props) {
  1037. var keys = vm.$options.propKeys = Object.keys(props);
  1038. var isRoot = !vm.$parent;
  1039. // root instance props should be converted
  1040. observerState.shouldConvert = isRoot;
  1041. for (var i = 0; i < keys.length; i++) {
  1042. var key = keys[i];
  1043. defineReactive(vm, key, validateProp(vm, key, propsData));
  1044. }
  1045. observerState.shouldConvert = true;
  1046. }
  1047. }
  1048. function initData(vm) {
  1049. var data = vm.$options.data;
  1050. data = vm._data = typeof data === 'function' ? data() : data || {};
  1051. if (!isPlainObject(data)) {
  1052. data = {};
  1053. process.env.NODE_ENV !== 'production' && warn$1('data functions should return an object.', vm);
  1054. }
  1055. // proxy data on instance
  1056. var keys = Object.keys(data);
  1057. var i = keys.length;
  1058. while (i--) {
  1059. proxy(vm, keys[i]);
  1060. }
  1061. // observe data
  1062. observe(data, vm);
  1063. }
  1064. function noop() {}
  1065. function initComputed(vm) {
  1066. var computed = vm.$options.computed;
  1067. if (computed) {
  1068. for (var key in computed) {
  1069. var userDef = computed[key];
  1070. var def = {
  1071. enumerable: true,
  1072. configurable: true
  1073. };
  1074. if (typeof userDef === 'function') {
  1075. def.get = makeComputedGetter(userDef, vm);
  1076. def.set = noop;
  1077. } else {
  1078. def.get = userDef.get ? userDef.cache !== false ? makeComputedGetter(userDef.get, vm) : bind(userDef.get, vm) : noop;
  1079. def.set = userDef.set ? bind(userDef.set, vm) : noop;
  1080. }
  1081. Object.defineProperty(vm, key, def);
  1082. }
  1083. }
  1084. }
  1085. function makeComputedGetter(getter, owner) {
  1086. var watcher = new Watcher(owner, getter, null, {
  1087. lazy: true
  1088. });
  1089. return function computedGetter() {
  1090. if (watcher.dirty) {
  1091. watcher.evaluate();
  1092. }
  1093. if (Dep.target) {
  1094. watcher.depend();
  1095. }
  1096. return watcher.value;
  1097. };
  1098. }
  1099. function initMethods(vm) {
  1100. var methods = vm.$options.methods;
  1101. if (methods) {
  1102. for (var key in methods) {
  1103. vm[key] = bind(methods[key], vm);
  1104. }
  1105. }
  1106. }
  1107. function initWatch(vm) {
  1108. var watch = vm.$options.watch;
  1109. if (watch) {
  1110. for (var key in watch) {
  1111. var handler = watch[key];
  1112. if (isArray(handler)) {
  1113. for (var i = 0; i < handler.length; i++) {
  1114. createWatcher(vm, key, handler[i]);
  1115. }
  1116. } else {
  1117. createWatcher(vm, key, handler);
  1118. }
  1119. }
  1120. }
  1121. }
  1122. function createWatcher(vm, key, handler) {
  1123. var options = void 0;
  1124. if (isPlainObject(handler)) {
  1125. options = handler;
  1126. handler = handler.handler;
  1127. }
  1128. if (typeof handler === 'string') {
  1129. handler = vm[handler];
  1130. }
  1131. vm.$watch(key, handler, options);
  1132. }
  1133. function stateMixin(Vue) {
  1134. Object.defineProperty(Vue.prototype, '$data', {
  1135. get: function get() {
  1136. return this._data;
  1137. },
  1138. set: function set(newData) {
  1139. if (newData !== this._data) {
  1140. setData(this, newData);
  1141. }
  1142. }
  1143. });
  1144. Vue.prototype.$watch = function (fn, cb, options) {
  1145. options = options || {};
  1146. options.user = true;
  1147. var watcher = new Watcher(this, fn, cb, options);
  1148. if (options.immediate) {
  1149. cb.call(this, watcher.value);
  1150. }
  1151. return function unwatchFn() {
  1152. watcher.teardown();
  1153. };
  1154. };
  1155. }
  1156. function setData(vm, newData) {
  1157. newData = newData || {};
  1158. var oldData = vm._data;
  1159. vm._data = newData;
  1160. var keys, key, i;
  1161. // unproxy keys not present in new data
  1162. keys = Object.keys(oldData);
  1163. i = keys.length;
  1164. while (i--) {
  1165. key = keys[i];
  1166. if (!(key in newData)) {
  1167. unproxy(vm, key);
  1168. }
  1169. }
  1170. // proxy keys not already proxied,
  1171. // and trigger change for changed values
  1172. keys = Object.keys(newData);
  1173. i = keys.length;
  1174. while (i--) {
  1175. key = keys[i];
  1176. if (!hasOwn(vm, key)) {
  1177. // new property
  1178. proxy(vm, key);
  1179. }
  1180. }
  1181. oldData.__ob__.removeVm(vm);
  1182. observe(newData, vm);
  1183. vm.$forceUpdate();
  1184. }
  1185. function VNode(tag, data, children, text, elm, ns, context) {
  1186. return {
  1187. tag: tag,
  1188. data: data,
  1189. children: children,
  1190. text: text,
  1191. elm: elm,
  1192. ns: ns,
  1193. context: context,
  1194. key: data && data.key
  1195. };
  1196. }
  1197. function flatten(children) {
  1198. if (typeof children === 'string') {
  1199. return [VNode(undefined, undefined, undefined, children)];
  1200. }
  1201. if (isArray(children)) {
  1202. var res = [];
  1203. for (var i = 0, l = children.length; i < l; i++) {
  1204. var c = children[i];
  1205. // flatten nested
  1206. if (isArray(c)) {
  1207. res.push.apply(res, flatten(c));
  1208. } else if (isPrimitive(c)) {
  1209. // convert primitive to vnode
  1210. res.push(VNode(undefined, undefined, undefined, c));
  1211. } else if (c) {
  1212. res.push(c);
  1213. }
  1214. }
  1215. return res;
  1216. }
  1217. }
  1218. function updateListeners(on, oldOn, add) {
  1219. var name = void 0,
  1220. cur = void 0,
  1221. old = void 0,
  1222. event = void 0,
  1223. capture = void 0;
  1224. for (name in on) {
  1225. cur = on[name];
  1226. old = oldOn[name];
  1227. if (old === undefined) {
  1228. capture = name.charAt(0) === '!';
  1229. event = capture ? name.slice(1) : name;
  1230. if (isArray(cur)) {
  1231. add(event, arrInvoker(cur), capture);
  1232. } else {
  1233. cur = { fn: cur };
  1234. on[name] = cur;
  1235. add(event, fnInvoker(cur), capture);
  1236. }
  1237. } else if (isArray(old)) {
  1238. old.length = cur.length;
  1239. for (var i = 0; i < old.length; i++) {
  1240. old[i] = cur[i];
  1241. }on[name] = old;
  1242. } else {
  1243. old.fn = cur;
  1244. on[name] = old;
  1245. }
  1246. }
  1247. }
  1248. function arrInvoker(arr) {
  1249. return function (ev) {
  1250. for (var i = 0; i < arr.length; i++) {
  1251. arr[i](ev);
  1252. }
  1253. };
  1254. }
  1255. function fnInvoker(o) {
  1256. return function (ev) {
  1257. o.fn(ev);
  1258. };
  1259. }
  1260. function initLifecycle(vm) {
  1261. var options = vm.$options;
  1262. vm.$parent = options.parent;
  1263. vm.$root = vm.$parent ? vm.$parent.$root : vm;
  1264. if (vm.$parent) {
  1265. vm.$parent.$children.push(vm);
  1266. }
  1267. vm.$children = [];
  1268. vm.$refs = {};
  1269. vm._isDestroyed = false;
  1270. vm._isBeingDestroyed = false;
  1271. }
  1272. function lifecycleMixin(Vue) {
  1273. Vue.prototype._mount = function () {
  1274. var _this = this;
  1275. if (!this.$options.render) {
  1276. this.$options.render = function () {
  1277. return _this.$createElement('div');
  1278. };
  1279. if (process.env.NODE_ENV !== 'production') {
  1280. if (this.$options.template) {
  1281. warn$1('You are using the runtime-only build of Vue where the template ' + 'option is not available. Either pre-compile the templates into ' + 'render functions, or use the compiler-included build.', this);
  1282. } else {
  1283. warn$1('Failed to mount component: template or render function not defined.', this);
  1284. }
  1285. }
  1286. }
  1287. // render static sub-trees for once on mount
  1288. var staticRenderFns = this.$options.staticRenderFns;
  1289. if (staticRenderFns) {
  1290. this._staticTrees = new Array(staticRenderFns.length);
  1291. for (var i = 0; i < staticRenderFns.length; i++) {
  1292. this._staticTrees[i] = staticRenderFns[i].call(this._renderProxy);
  1293. }
  1294. }
  1295. this._watcher = new Watcher(this, this._render, this._update);
  1296. this._update(this._watcher.value);
  1297. this._mounted = true;
  1298. // root instance, call ready on self
  1299. if (this.$root === this) {
  1300. callHook(this, 'ready');
  1301. }
  1302. return this;
  1303. };
  1304. Vue.prototype._update = function (vnode) {
  1305. if (this._mounted) {
  1306. callHook(this, 'beforeUpdate');
  1307. }
  1308. var parentNode = this.$options._parentVnode;
  1309. // set vnode parent before patch
  1310. vnode.parent = parentNode;
  1311. if (!this._vnode) {
  1312. // Vue.prototype.__patch__ is injected in entry points
  1313. // based on the rendering backend used.
  1314. this.$el = this.__patch__(this.$el, vnode);
  1315. } else {
  1316. this.$el = this.__patch__(this._vnode, vnode);
  1317. }
  1318. this._vnode = vnode;
  1319. // set parent vnode element after patch
  1320. if (parentNode) {
  1321. parentNode.elm = this.$el;
  1322. }
  1323. if (this._mounted) {
  1324. callHook(this, 'updated');
  1325. }
  1326. };
  1327. Vue.prototype._updateFromParent = function (propsData, listeners, parentVnode, children) {
  1328. var _this2 = this;
  1329. this.$options._parentVnode = parentVnode;
  1330. this.$options._renderChildren = children;
  1331. // update props
  1332. if (propsData && this.$options.props) {
  1333. observerState.shouldConvert = false;
  1334. var propKeys = this.$options.propKeys;
  1335. for (var i = 0; i < propKeys.length; i++) {
  1336. var key = propKeys[i];
  1337. this[key] = validateProp(this, key, propsData);
  1338. }
  1339. observerState.shouldConvert = true;
  1340. }
  1341. // update listeners
  1342. if (listeners) {
  1343. var oldListeners = this.$options._parentListeners;
  1344. this.$options._parentListeners = listeners;
  1345. updateListeners(listeners, oldListeners || {}, function (event, handler) {
  1346. _this2.$on(event, handler);
  1347. });
  1348. }
  1349. };
  1350. Vue.prototype.$forceUpdate = function () {
  1351. this._watcher.update();
  1352. };
  1353. Vue.prototype.$destroy = function () {
  1354. if (this._isDestroyed) {
  1355. return;
  1356. }
  1357. callHook(this, 'beforeDestroy');
  1358. this._isBeingDestroyed = true;
  1359. // remove self from parent
  1360. var parent = this.$parent;
  1361. if (parent && !parent._isBeingDestroyed) {
  1362. remove(parent.$children, this);
  1363. }
  1364. // unregister ref
  1365. if (this._ref) {
  1366. this._context.$refs[this._ref] = undefined;
  1367. }
  1368. // teardown watchers
  1369. var i = this._watchers.length;
  1370. while (i--) {
  1371. this._watchers[i].teardown();
  1372. }
  1373. // remove reference from data ob
  1374. // frozen object may not have observer.
  1375. if (this._data.__ob__) {
  1376. this._data.__ob__.removeVm(this);
  1377. }
  1378. // call the last hook...
  1379. this._isDestroyed = true;
  1380. callHook(this, 'destroyed');
  1381. // turn off all instance listeners.
  1382. this.$off();
  1383. };
  1384. }
  1385. function callHook(vm, hook) {
  1386. vm.$emit('pre-hook:' + hook);
  1387. var handlers = vm.$options[hook];
  1388. if (handlers) {
  1389. for (var i = 0, j = handlers.length; i < j; i++) {
  1390. handlers[i].call(vm);
  1391. }
  1392. }
  1393. vm.$emit('hook:' + hook);
  1394. }
  1395. var hooks = { init: init, prepatch: prepatch, insert: insert, destroy: destroy };
  1396. var hooksToMerge = Object.keys(hooks);
  1397. function createComponent(Ctor, data, parent, children, context) {
  1398. if (process.env.NODE_ENV !== 'production' && children && typeof children !== 'function') {
  1399. warn$1('A component\'s children should be a function that returns the ' + 'children array. This allows the component to track the children ' + 'dependencies and optimizes re-rendering.');
  1400. }
  1401. if (!Ctor) {
  1402. return;
  1403. }
  1404. if (isObject(Ctor)) {
  1405. Ctor = Vue.extend(Ctor);
  1406. }
  1407. if (process.env.NODE_ENV !== 'production' && typeof Ctor !== 'function') {
  1408. warn$1('Invalid Component definition: ' + Ctor, parent);
  1409. return;
  1410. }
  1411. // async component
  1412. if (!Ctor.cid) {
  1413. if (Ctor.resolved) {
  1414. Ctor = Ctor.resolved;
  1415. } else {
  1416. resolveAsyncComponent(Ctor, function () {
  1417. // it's ok to queue this on every render because
  1418. // $forceUpdate is buffered.
  1419. parent.$forceUpdate();
  1420. });
  1421. return;
  1422. }
  1423. }
  1424. data = data || {};
  1425. // merge component management hooks onto the placeholder node
  1426. mergeHooks(data);
  1427. // extract props
  1428. var propsData = extractProps(data, Ctor);
  1429. // extract listeners, since these needs to be treated as
  1430. // child component listeners instead of DOM listeners
  1431. var listeners = data.on;
  1432. if (listeners) {
  1433. data.on = null;
  1434. }
  1435. // return a placeholder vnode
  1436. var name = Ctor.options.name ? '-' + Ctor.options.name : '';
  1437. var vnode = VNode('vue-component-' + Ctor.cid + name, data, undefined, undefined, undefined, undefined, context);
  1438. vnode.componentOptions = { Ctor: Ctor, propsData: propsData, listeners: listeners, parent: parent, children: children };
  1439. return vnode;
  1440. }
  1441. function init(vnode) {
  1442. var _vnode$componentOptio = vnode.componentOptions;
  1443. var Ctor = _vnode$componentOptio.Ctor;
  1444. var propsData = _vnode$componentOptio.propsData;
  1445. var listeners = _vnode$componentOptio.listeners;
  1446. var parent = _vnode$componentOptio.parent;
  1447. var children = _vnode$componentOptio.children;
  1448. var child = new Ctor({
  1449. parent: parent,
  1450. propsData: propsData,
  1451. _parentVnode: vnode,
  1452. _parentListeners: listeners,
  1453. _renderChildren: children
  1454. });
  1455. // if this is a server-rendered mount,
  1456. // the vnode would already have an element.
  1457. // otherwise the child sets the parent vnode's elm when mounted
  1458. // and when updated.
  1459. child.$mount(vnode.elm);
  1460. vnode.child = child;
  1461. }
  1462. function prepatch(oldVnode, vnode) {
  1463. var _vnode$componentOptio2 = vnode.componentOptions;
  1464. var listeners = _vnode$componentOptio2.listeners;
  1465. var propsData = _vnode$componentOptio2.propsData;
  1466. var children = _vnode$componentOptio2.children;
  1467. vnode.child = oldVnode.child;
  1468. vnode.child._updateFromParent(propsData, // updated props
  1469. listeners, // updated listeners
  1470. vnode, // new parent vnode
  1471. children // new children
  1472. );
  1473. }
  1474. function insert(vnode) {
  1475. callHook(vnode.child, 'ready');
  1476. }
  1477. function destroy(vnode) {
  1478. vnode.child.$destroy();
  1479. }
  1480. function resolveAsyncComponent(factory, cb) {
  1481. if (factory.resolved) {
  1482. // cached
  1483. cb(factory.resolved);
  1484. } else if (factory.requested) {
  1485. // pool callbacks
  1486. factory.pendingCallbacks.push(cb);
  1487. } else {
  1488. (function () {
  1489. factory.requested = true;
  1490. var cbs = factory.pendingCallbacks = [cb];
  1491. factory(function resolve(res) {
  1492. if (isObject(res)) {
  1493. res = Vue.extend(res);
  1494. }
  1495. // cache resolved
  1496. factory.resolved = res;
  1497. // invoke callbacks
  1498. for (var i = 0, l = cbs.length; i < l; i++) {
  1499. cbs[i](res);
  1500. }
  1501. }, function reject(reason) {
  1502. process.env.NODE_ENV !== 'production' && warn$1('Failed to resolve async component: ' + factory + (reason ? '\nReason: ' + reason : ''));
  1503. });
  1504. })();
  1505. }
  1506. }
  1507. function extractProps(data, Ctor) {
  1508. // we are only extrating raw values here.
  1509. // validation and default values are handled in the child
  1510. // component itself.
  1511. var propOptions = Ctor.options.props;
  1512. if (!propOptions) {
  1513. return;
  1514. }
  1515. var res = {};
  1516. var attrs = data.attrs;
  1517. var props = data.props;
  1518. var staticAttrs = data.staticAttrs;
  1519. if (!attrs && !props) {
  1520. return res;
  1521. }
  1522. for (var key in propOptions) {
  1523. var altKey = hyphenate(key);
  1524. checkProp(res, attrs, key, altKey) || checkProp(res, props, key, altKey) || checkProp(res, staticAttrs, key, altKey);
  1525. }
  1526. return res;
  1527. }
  1528. function checkProp(res, hash, key, altKey) {
  1529. if (hash) {
  1530. if (hasOwn(hash, key)) {
  1531. res[key] = hash[key];
  1532. delete hash[key];
  1533. return true;
  1534. } else if (hasOwn(hash, altKey)) {
  1535. res[key] = hash[altKey];
  1536. delete hash[altKey];
  1537. return true;
  1538. }
  1539. }
  1540. }
  1541. function mergeHooks(data) {
  1542. if (data.hook) {
  1543. for (var i = 0; i < hooksToMerge.length; i++) {
  1544. var key = hooksToMerge[i];
  1545. var fromParent = data.hook[key];
  1546. var ours = hooks[key];
  1547. data.hook[key] = fromParent ? mergeHook$1(ours, fromParent) : ours;
  1548. }
  1549. } else {
  1550. data.hook = hooks;
  1551. }
  1552. }
  1553. function mergeHook$1(a, b) {
  1554. // since all hooks have at most two args, use fixed args
  1555. // to avoid having to use fn.apply().
  1556. return function (_, __) {
  1557. a(_, __);
  1558. b(_, __);
  1559. };
  1560. }
  1561. function createElement(tag, data, children, namespace) {
  1562. var context = this;
  1563. var parent = renderState.activeInstance;
  1564. if (typeof tag === 'string') {
  1565. var Ctor = void 0;
  1566. if (config.isReservedTag(tag)) {
  1567. return VNode(tag, data, flatten(children), undefined, undefined, namespace, context);
  1568. } else if (Ctor = resolveAsset(context.$options, 'components', tag)) {
  1569. return createComponent(Ctor, data, parent, children, context);
  1570. } else {
  1571. if (process.env.NODE_ENV !== 'production') {
  1572. if (!namespace && config.isUnknownElement(tag)) {
  1573. warn$1('Unknown custom element: <' + tag + '> - did you ' + 'register the component correctly? For recursive components, ' + 'make sure to provide the "name" option.');
  1574. }
  1575. }
  1576. return VNode(tag, data, flatten(children && children()), undefined, undefined, namespace, context);
  1577. }
  1578. } else {
  1579. return createComponent(tag, data, parent, children, context);
  1580. }
  1581. }
  1582. var renderState = {
  1583. activeInstance: null
  1584. };
  1585. function initRender(vm) {
  1586. vm._vnode = null;
  1587. vm._mounted = false;
  1588. vm._staticTrees = null;
  1589. vm.$slots = {};
  1590. // bind the public createElement fn to this instance
  1591. // so that we get proper render context inside it.
  1592. vm.$createElement = bind(createElement, vm);
  1593. if (vm.$options.el) {
  1594. vm.$mount(vm.$options.el);
  1595. }
  1596. }
  1597. function renderMixin(Vue) {
  1598. Vue.prototype._render = function () {
  1599. var prev = renderState.activeInstance;
  1600. renderState.activeInstance = this;
  1601. var _$options = this.$options;
  1602. var render = _$options.render;
  1603. var _renderChildren = _$options._renderChildren;
  1604. // resolve slots. becaues slots are rendered in parent scope,
  1605. // we set the activeInstance to parent.
  1606. if (_renderChildren) {
  1607. resolveSlots(this, _renderChildren);
  1608. }
  1609. // render self
  1610. var vnode = render.call(this._renderProxy);
  1611. // restore render state
  1612. renderState.activeInstance = prev;
  1613. return vnode;
  1614. };
  1615. // shorthands used in render functions
  1616. Vue.prototype.__h__ = createElement;
  1617. // toString for mustaches
  1618. Vue.prototype.__toString__ = renderString;
  1619. // render v-for
  1620. Vue.prototype.__renderList__ = function (val, render) {
  1621. var ret = void 0,
  1622. i = void 0,
  1623. l = void 0,
  1624. keys = void 0,
  1625. key = void 0;
  1626. if (isArray(val)) {
  1627. ret = new Array(val.length);
  1628. for (i = 0, l = val.length; i < l; i++) {
  1629. ret[i] = render(val[i], i, i);
  1630. }
  1631. } else if (typeof val === 'number') {
  1632. ret = new Array(val);
  1633. for (i = 0; i < val; i++) {
  1634. ret[i] = render(i + 1, i, i);
  1635. }
  1636. } else if (isObject(val)) {
  1637. keys = Object.keys(val);
  1638. ret = new Array(keys.length);
  1639. for (i = 0, l = keys.length; i < l; i++) {
  1640. key = keys[i];
  1641. ret[i] = render(val[key], i, key);
  1642. }
  1643. }
  1644. return ret;
  1645. };
  1646. // register ref
  1647. Vue.prototype.__registerRef__ = function (key, ref, vFor, remove) {
  1648. var refs = this.$refs;
  1649. if (remove) {
  1650. if (vFor) {
  1651. remove(refs[key], ref);
  1652. } else {
  1653. refs[key] = undefined;
  1654. }
  1655. } else {
  1656. if (vFor) {
  1657. if (refs[key]) {
  1658. refs[key].push(ref);
  1659. } else {
  1660. refs[key] = [ref];
  1661. }
  1662. } else {
  1663. refs[key] = ref;
  1664. }
  1665. }
  1666. };
  1667. }
  1668. function resolveSlots(vm, children) {
  1669. if (children) {
  1670. children = flatten(isArray(children) ? children : children());
  1671. var slots = { default: children };
  1672. var i = children.length;
  1673. var name = void 0,
  1674. child = void 0;
  1675. while (i--) {
  1676. child = children[i];
  1677. if (name = child.data && child.data.slot) {
  1678. var slot = slots[name] || (slots[name] = []);
  1679. if (child.tag === 'template') {
  1680. slot.push.apply(slot, child.children);
  1681. } else {
  1682. slot.push(child);
  1683. }
  1684. children.splice(i, 1);
  1685. }
  1686. }
  1687. vm.$slots = slots;
  1688. }
  1689. }
  1690. function initEvents(vm) {
  1691. vm._events = Object.create(null);
  1692. // init parent attached events
  1693. var listeners = vm.$options._parentListeners;
  1694. if (listeners) {
  1695. updateListeners(listeners, {}, function (event, handler) {
  1696. vm.$on(event, handler);
  1697. });
  1698. }
  1699. }
  1700. function eventsMixin(Vue) {
  1701. Vue.prototype.$on = function (event, fn) {
  1702. (this._events[event] || (this._events[event] = [])).push(fn);
  1703. return this;
  1704. };
  1705. /**
  1706. * Adds an `event` listener that will be invoked a single
  1707. * time then automatically removed.
  1708. *
  1709. * @param {String} event
  1710. * @param {Function} fn
  1711. */
  1712. Vue.prototype.$once = function (event, fn) {
  1713. var self = this;
  1714. function on() {
  1715. self.$off(event, on);
  1716. fn.apply(this, arguments);
  1717. }
  1718. on.fn = fn;
  1719. this.$on(event, on);
  1720. return this;
  1721. };
  1722. /**
  1723. * Remove the given callback for `event` or all
  1724. * registered callbacks.
  1725. *
  1726. * @param {String} event
  1727. * @param {Function} fn
  1728. */
  1729. Vue.prototype.$off = function (event, fn) {
  1730. var cbs;
  1731. // all
  1732. if (!arguments.length) {
  1733. this._events = Object.create(null);
  1734. return this;
  1735. }
  1736. // specific event
  1737. cbs = this._events[event];
  1738. if (!cbs) {
  1739. return this;
  1740. }
  1741. if (arguments.length === 1) {
  1742. this._events[event] = null;
  1743. return this;
  1744. }
  1745. // specific handler
  1746. var cb;
  1747. var i = cbs.length;
  1748. while (i--) {
  1749. cb = cbs[i];
  1750. if (cb === fn || cb.fn === fn) {
  1751. cbs.splice(i, 1);
  1752. break;
  1753. }
  1754. }
  1755. return this;
  1756. };
  1757. /**
  1758. * Trigger an event on self.
  1759. *
  1760. * @param {String} event
  1761. */
  1762. Vue.prototype.$emit = function (event) {
  1763. var cbs = this._events[event];
  1764. if (cbs) {
  1765. cbs = cbs.length > 1 ? toArray(cbs) : cbs;
  1766. var args = toArray(arguments, 1);
  1767. for (var i = 0, l = cbs.length; i < l; i++) {
  1768. cbs[i].apply(this, args);
  1769. }
  1770. }
  1771. };
  1772. }
  1773. var uid = 0;
  1774. function Vue(options) {
  1775. this._init(options);
  1776. }
  1777. Vue.prototype._init = function (options) {
  1778. // a uid
  1779. this._uid = uid++;
  1780. // a flag to avoid this being observed
  1781. this._isVue = true;
  1782. // merge options
  1783. this.$options = mergeOptions(this.constructor.options, options || {}, this);
  1784. if (process.env.NODE_ENV !== 'production') {
  1785. initProxy(this);
  1786. } else {
  1787. this._renderProxy = this;
  1788. }
  1789. initLifecycle(this);
  1790. initEvents(this);
  1791. callHook(this, 'init');
  1792. initState(this);
  1793. callHook(this, 'created');
  1794. initRender(this);
  1795. };
  1796. Vue.prototype.$nextTick = function (fn) {
  1797. nextTick(fn, this);
  1798. };
  1799. stateMixin(Vue);
  1800. eventsMixin(Vue);
  1801. lifecycleMixin(Vue);
  1802. renderMixin(Vue);
  1803. var warn$1 = void 0;
  1804. var formatComponentName = void 0;
  1805. if (process.env.NODE_ENV !== 'production') {
  1806. (function () {
  1807. var hasConsole = typeof console !== 'undefined';
  1808. warn$1 = function warn(msg, vm) {
  1809. if (hasConsole && !config.silent) {
  1810. console.error('[Vue warn]: ' + msg + (vm ? formatComponentName(vm) : ''));
  1811. }
  1812. };
  1813. formatComponentName = function formatComponentName(vm) {
  1814. var name = vm._isVue ? vm.$options.name : vm.name;
  1815. return name ? ' (found in component: <' + hyphenate(name) + '>)' : '';
  1816. };
  1817. })();
  1818. }
  1819. /**
  1820. * Option overwriting strategies are functions that handle
  1821. * how to merge a parent option value and a child option
  1822. * value into the final value.
  1823. *
  1824. * All strategy functions follow the same signature:
  1825. *
  1826. * @param {*} parentVal
  1827. * @param {*} childVal
  1828. * @param {Vue} [vm]
  1829. */
  1830. var strats = config.optionMergeStrategies = Object.create(null);
  1831. /**
  1832. * Helper that recursively merges two data objects together.
  1833. */
  1834. function mergeData(to, from) {
  1835. var key, toVal, fromVal;
  1836. for (key in from) {
  1837. toVal = to[key];
  1838. fromVal = from[key];
  1839. if (!hasOwn(to, key)) {
  1840. set(to, key, fromVal);
  1841. } else if (isObject(toVal) && isObject(fromVal)) {
  1842. mergeData(toVal, fromVal);
  1843. }
  1844. }
  1845. return to;
  1846. }
  1847. /**
  1848. * Data
  1849. */
  1850. strats.data = function (parentVal, childVal, vm) {
  1851. if (!vm) {
  1852. // in a Vue.extend merge, both should be functions
  1853. if (!childVal) {
  1854. return parentVal;
  1855. }
  1856. if (typeof childVal !== 'function') {
  1857. process.env.NODE_ENV !== 'production' && warn$1('The "data" option should be a function ' + 'that returns a per-instance value in component ' + 'definitions.', vm);
  1858. return parentVal;
  1859. }
  1860. if (!parentVal) {
  1861. return childVal;
  1862. }
  1863. // when parentVal & childVal are both present,
  1864. // we need to return a function that returns the
  1865. // merged result of both functions... no need to
  1866. // check if parentVal is a function here because
  1867. // it has to be a function to pass previous merges.
  1868. return function mergedDataFn() {
  1869. return mergeData(childVal.call(this), parentVal.call(this));
  1870. };
  1871. } else if (parentVal || childVal) {
  1872. return function mergedInstanceDataFn() {
  1873. // instance merge
  1874. var instanceData = typeof childVal === 'function' ? childVal.call(vm) : childVal;
  1875. var defaultData = typeof parentVal === 'function' ? parentVal.call(vm) : undefined;
  1876. if (instanceData) {
  1877. return mergeData(instanceData, defaultData);
  1878. } else {
  1879. return defaultData;
  1880. }
  1881. };
  1882. }
  1883. };
  1884. /**
  1885. * El
  1886. */
  1887. strats.el = function (parentVal, childVal, vm) {
  1888. if (!vm && childVal && typeof childVal !== 'function') {
  1889. process.env.NODE_ENV !== 'production' && warn$1('The "el" option should be a function ' + 'that returns a per-instance value in component ' + 'definitions.', vm);
  1890. return;
  1891. }
  1892. var ret = childVal || parentVal;
  1893. // invoke the element factory if this is instance merge
  1894. return vm && typeof ret === 'function' ? ret.call(vm) : ret;
  1895. };
  1896. /**
  1897. * Hooks and param attributes are merged as arrays.
  1898. */
  1899. function mergeHook(parentVal, childVal) {
  1900. return childVal ? parentVal ? parentVal.concat(childVal) : isArray(childVal) ? childVal : [childVal] : parentVal;
  1901. }
  1902. config._lifecycleHooks.forEach(function (hook) {
  1903. strats[hook] = mergeHook;
  1904. });
  1905. /**
  1906. * Assets
  1907. *
  1908. * When a vm is present (instance creation), we need to do
  1909. * a three-way merge between constructor options, instance
  1910. * options and parent options.
  1911. */
  1912. function mergeAssets(parentVal, childVal) {
  1913. var res = Object.create(parentVal);
  1914. return childVal ? extend(res, childVal) : res;
  1915. }
  1916. config._assetTypes.forEach(function (type) {
  1917. strats[type + 's'] = mergeAssets;
  1918. });
  1919. /**
  1920. * Watchers.
  1921. *
  1922. * Watchers hashes should not overwrite one
  1923. * another, so we merge them as arrays.
  1924. */
  1925. strats.watch = function (parentVal, childVal) {
  1926. if (!childVal) return parentVal;
  1927. if (!parentVal) return childVal;
  1928. var ret = {};
  1929. extend(ret, parentVal);
  1930. for (var key in childVal) {
  1931. var parent = ret[key];
  1932. var child = childVal[key];
  1933. if (parent && !isArray(parent)) {
  1934. parent = [parent];
  1935. }
  1936. ret[key] = parent ? parent.concat(child) : [child];
  1937. }
  1938. return ret;
  1939. };
  1940. /**
  1941. * Other object hashes.
  1942. */
  1943. strats.props = strats.methods = strats.computed = function (parentVal, childVal) {
  1944. if (!childVal) return parentVal;
  1945. if (!parentVal) return childVal;
  1946. var ret = Object.create(null);
  1947. extend(ret, parentVal);
  1948. extend(ret, childVal);
  1949. return ret;
  1950. };
  1951. /**
  1952. * Default strategy.
  1953. */
  1954. var defaultStrat = function defaultStrat(parentVal, childVal) {
  1955. return childVal === undefined ? parentVal : childVal;
  1956. };
  1957. /**
  1958. * Make sure component options get converted to actual
  1959. * constructors.
  1960. *
  1961. * @param {Object} options
  1962. */
  1963. function guardComponents(options) {
  1964. if (options.components) {
  1965. var components = options.components;
  1966. var def;
  1967. for (var key in components) {
  1968. if (isBuiltInTag(key) || config.isReservedTag(key)) {
  1969. process.env.NODE_ENV !== 'production' && warn$1('Do not use built-in or reserved HTML elements as component ' + 'id: ' + key);
  1970. continue;
  1971. }
  1972. def = components[key];
  1973. if (isPlainObject(def)) {
  1974. components[key] = Vue.extend(def);
  1975. }
  1976. }
  1977. }
  1978. }
  1979. /**
  1980. * Ensure all props option syntax are normalized into the
  1981. * Object-based format.
  1982. *
  1983. * @param {Object} options
  1984. */
  1985. function guardProps(options) {
  1986. var props = options.props;
  1987. if (!props) return;
  1988. var res = {};
  1989. var i = void 0,
  1990. val = void 0,
  1991. name = void 0;
  1992. if (isArray(props)) {
  1993. i = props.length;
  1994. while (i--) {
  1995. val = props[i];
  1996. if (typeof val === 'string') {
  1997. name = camelize(val);
  1998. res[name] = { type: null };
  1999. } else if (process.env.NODE_ENV !== 'production') {
  2000. warn$1('props must be strings when using array syntax.');
  2001. }
  2002. }
  2003. } else if (isPlainObject(props)) {
  2004. for (var key in props) {
  2005. val = props[key];
  2006. name = camelize(key);
  2007. res[name] = isPlainObject(val) ? val : { type: val };
  2008. }
  2009. }
  2010. options.props = res;
  2011. }
  2012. function guardDirectives(options) {
  2013. var dirs = options.directives;
  2014. if (dirs) {
  2015. for (var key in dirs) {
  2016. if (typeof dirs[key] === 'function') {
  2017. dirs[key] = { update: dirs[key] };
  2018. }
  2019. }
  2020. }
  2021. }
  2022. /**
  2023. * Merge two option objects into a new one.
  2024. * Core utility used in both instantiation and inheritance.
  2025. *
  2026. * @param {Object} parent
  2027. * @param {Object} child
  2028. * @param {Vue} [vm] - if vm is present, indicates this is
  2029. * an instantiation merge.
  2030. */
  2031. function mergeOptions(parent, child, vm) {
  2032. guardComponents(child);
  2033. guardProps(child);
  2034. guardDirectives(child);
  2035. if (process.env.NODE_ENV !== 'production') {
  2036. if (child.propsData && !vm) {
  2037. warn$1('propsData can only be used as an instantiation option.');
  2038. }
  2039. }
  2040. var options = {};
  2041. var key;
  2042. if (child.mixins) {
  2043. for (var i = 0, l = child.mixins.length; i < l; i++) {
  2044. parent = mergeOptions(parent, child.mixins[i], vm);
  2045. }
  2046. }
  2047. for (key in parent) {
  2048. mergeField(key);
  2049. }
  2050. for (key in child) {
  2051. if (!hasOwn(parent, key)) {
  2052. mergeField(key);
  2053. }
  2054. }
  2055. function mergeField(key) {
  2056. var strat = strats[key] || defaultStrat;
  2057. options[key] = strat(parent[key], child[key], vm, key);
  2058. }
  2059. return options;
  2060. }
  2061. /**
  2062. * Resolve an asset.
  2063. * This function is used because child instances need access
  2064. * to assets defined in its ancestor chain.
  2065. *
  2066. * @param {Object} options
  2067. * @param {String} type
  2068. * @param {String} id
  2069. * @param {Boolean} warnMissing
  2070. * @return {Object|Function}
  2071. */
  2072. function resolveAsset(options, type, id, warnMissing) {
  2073. /* istanbul ignore if */
  2074. if (typeof id !== 'string') {
  2075. return;
  2076. }
  2077. var assets = options[type];
  2078. var camelizedId;
  2079. var res = assets[id] ||
  2080. // camelCase ID
  2081. assets[camelizedId = camelize(id)] ||
  2082. // Pascal Case ID
  2083. assets[camelizedId.charAt(0).toUpperCase() + camelizedId.slice(1)];
  2084. if (process.env.NODE_ENV !== 'production' && warnMissing && !res) {
  2085. warn$1('Failed to resolve ' + type.slice(0, -1) + ': ' + id, options);
  2086. }
  2087. return res;
  2088. }
  2089. function validateProp(vm, key, propsData) {
  2090. if (!propsData) return;
  2091. var prop = vm.$options.props[key];
  2092. var absent = hasOwn(propsData, key);
  2093. var value = propsData[key];
  2094. // check default value
  2095. if (value === undefined) {
  2096. value = getPropDefaultValue(vm, prop, key);
  2097. // since the default value is a fresh copy,
  2098. // make sure to observe it.
  2099. observerState.shouldConvert = true;
  2100. observe(value);
  2101. observerState.shouldConvert = false;
  2102. }
  2103. if (process.env.NODE_ENV !== 'production') {
  2104. assertProp(prop, key, value, vm, absent);
  2105. }
  2106. return value;
  2107. }
  2108. /**
  2109. * Get the default value of a prop.
  2110. *
  2111. * @param {Vue} vm
  2112. * @param {Object} prop
  2113. * @return {*}
  2114. */
  2115. function getPropDefaultValue(vm, prop, name) {
  2116. // no default, return undefined
  2117. if (!hasOwn(prop, 'default')) {
  2118. // absent boolean value defaults to false
  2119. return prop.type === Boolean ? false : undefined;
  2120. }
  2121. var def = prop.default;
  2122. // warn against non-factory defaults for Object & Array
  2123. if (isObject(def)) {
  2124. process.env.NODE_ENV !== 'production' && warn$1('Invalid default value for prop "' + name + '": ' + 'Props with type Object/Array must use a factory function ' + 'to return the default value.', vm);
  2125. }
  2126. // call factory function for non-Function types
  2127. return typeof def === 'function' && prop.type !== Function ? def.call(vm) : def;
  2128. }
  2129. /**
  2130. * Assert whether a prop is valid.
  2131. *
  2132. * @param {Object} prop
  2133. * @param {String} name
  2134. * @param {*} value
  2135. * @param {Vue} vm
  2136. * @param {Boolean} absent
  2137. */
  2138. function assertProp(prop, name, value, vm, absent) {
  2139. if (prop.required && absent) {
  2140. process.env.NODE_ENV !== 'production' && warn$1('Missing required prop: "' + name + '"', vm);
  2141. return false;
  2142. }
  2143. if (value == null) {
  2144. return true;
  2145. }
  2146. var type = prop.type;
  2147. var valid = !type;
  2148. var expectedTypes = [];
  2149. if (type) {
  2150. if (!isArray(type)) {
  2151. type = [type];
  2152. }
  2153. for (var i = 0; i < type.length && !valid; i++) {
  2154. var assertedType = assertType(value, type[i]);
  2155. expectedTypes.push(assertedType.expectedType);
  2156. valid = assertedType.valid;
  2157. }
  2158. }
  2159. if (!valid) {
  2160. if (process.env.NODE_ENV !== 'production') {
  2161. warn$1('Invalid prop: type check failed for prop "' + name + '".' + ' Expected ' + expectedTypes.map(formatType).join(', ') + ', got ' + formatValue(value) + '.', vm);
  2162. }
  2163. return false;
  2164. }
  2165. var validator = prop.validator;
  2166. if (validator) {
  2167. if (!validator(value)) {
  2168. process.env.NODE_ENV !== 'production' && warn$1('Invalid prop: custom validator check failed for prop "' + name + '".', vm);
  2169. return false;
  2170. }
  2171. }
  2172. return true;
  2173. }
  2174. /**
  2175. * Assert the type of a value
  2176. *
  2177. * @param {*} value
  2178. * @param {Function} type
  2179. * @return {Object}
  2180. */
  2181. function assertType(value, type) {
  2182. var valid;
  2183. var expectedType;
  2184. if (type === String) {
  2185. expectedType = 'string';
  2186. valid = typeof value === expectedType;
  2187. } else if (type === Number) {
  2188. expectedType = 'number';
  2189. valid = typeof value === expectedType;
  2190. } else if (type === Boolean) {
  2191. expectedType = 'boolean';
  2192. valid = typeof value === expectedType;
  2193. } else if (type === Function) {
  2194. expectedType = 'function';
  2195. valid = typeof value === expectedType;
  2196. } else if (type === Object) {
  2197. expectedType = 'object';
  2198. valid = isPlainObject(value);
  2199. } else if (type === Array) {
  2200. expectedType = 'array';
  2201. valid = isArray(value);
  2202. } else {
  2203. valid = value instanceof type;
  2204. }
  2205. return {
  2206. valid: valid,
  2207. expectedType: expectedType
  2208. };
  2209. }
  2210. /**
  2211. * Format type for output
  2212. *
  2213. * @param {String} type
  2214. * @return {String}
  2215. */
  2216. function formatType(type) {
  2217. return type ? type.charAt(0).toUpperCase() + type.slice(1) : 'custom type';
  2218. }
  2219. /**
  2220. * Format value
  2221. *
  2222. * @param {*} value
  2223. * @return {String}
  2224. */
  2225. function formatValue(val) {
  2226. return Object.prototype.toString.call(val).slice(8, -1);
  2227. }
  2228. // attributes that should be using props for binding
  2229. var mustUseProp = makeMap('value,selected,checked,muted');
  2230. var isEnumeratedAttr = makeMap('contenteditable,draggable,spellcheck');
  2231. var isBooleanAttr = makeMap('allowfullscreen,async,autofocus,autoplay,checked,compact,controls,declare,' + 'default,defaultchecked,defaultmuted,defaultselected,defer,disabled,' + 'enabled,formnovalidate,hidden,indeterminate,inert,ismap,itemscope,loop,multiple,' + 'muted,nohref,noresize,noshade,novalidate,nowrap,open,pauseonexit,readonly,' + 'required,reversed,scoped,seamless,selected,sortable,translate,' + 'truespeed,typemustmatch,visible');
  2232. var isReservedTag = makeMap('html,base,head,link,meta,style,title,' + 'address,article,footer,header,h1,h2,h3,h4,h5,h6,hgroup,nav,section,' + 'div,dd,dl,dt,figcaption,figure,hr,li,main,ol,p,pre,ul,' + 'a,b,abbr,bdi,bdo,br,cite,code,data,dfn,em,i,kbd,mark,q,rp,rt,rtc,ruby,' + 's,samp,small,span,strong,sub,sup,time,u,var,wbr,area,audio,map,track,video,' + 'embed,object,param,source,canvas,script,noscript,del,ins,' + 'caption,col,colgroup,table,thead,tbody,td,th,tr,' + 'button,datalist,fieldset,form,input,label,legend,meter,optgroup,option,' + 'output,progress,select,textarea,' + 'details,dialog,menu,menuitem,summary,' + 'content,element,shadow,template');
  2233. var isUnaryTag = makeMap('area,base,br,col,embed,frame,hr,img,input,isindex,keygen,' + 'link,meta,param,source,track,wbr', true);
  2234. // Elements that you can, intentionally, leave open
  2235. // (and which close themselves)
  2236. var canBeLeftOpenTag = makeMap('colgroup,dd,dt,li,options,p,td,tfoot,th,thead,tr,source', true);
  2237. // HTML5 tags https://html.spec.whatwg.org/multipage/indices.html#elements-3
  2238. // Phrasing Content https://html.spec.whatwg.org/multipage/dom.html#phrasing-content
  2239. var isNonPhrasingTag = makeMap('address,article,aside,base,blockquote,body,caption,col,colgroup,dd,' + 'details,dialog,div,dl,dt,fieldset,figcaption,figure,footer,form,' + 'h1,h2,h3,h4,h5,h6,head,header,hgroup,hr,html,legend,li,menuitem,meta,' + 'optgroup,option,param,rp,rt,source,style,summary,tbody,td,tfoot,th,thead,' + 'title,tr,track', true);
  2240. // this map covers namespace elements that can appear as template root nodes
  2241. var isSVG = makeMap('svg,g,defs,symbol,use,image,text,circle,ellipse,' + 'line,path,polygon,polyline,rect', true);
  2242. function getTagNamespace(tag) {
  2243. if (isSVG(tag)) {
  2244. return 'svg';
  2245. }
  2246. // basic support for MathML
  2247. // note it doesn't support other MathML elements being component roots
  2248. if (tag === 'math') {
  2249. return 'math';
  2250. }
  2251. }
  2252. var UA = inBrowser && window.navigator.userAgent.toLowerCase();
  2253. var isIE9 = UA && UA.indexOf('msie 9.0') > 0;
  2254. var isAndroid = UA && UA.indexOf('android') > 0;
  2255. // Regular Expressions for parsing tags and attributes
  2256. var singleAttrIdentifier = /([^\s"'<>\/=]+)/;
  2257. var singleAttrAssign = /=/;
  2258. var singleAttrAssigns = [singleAttrAssign];
  2259. var singleAttrValues = [
  2260. // attr value double quotes
  2261. /"([^"]*)"+/.source,
  2262. // attr value, single quotes
  2263. /'([^']*)'+/.source,
  2264. // attr value, no quotes
  2265. /([^\s"'=<>`]+)/.source];
  2266. // could use https://www.w3.org/TR/1999/REC-xml-names-19990114/#NT-QName
  2267. // but for Vue templates we can enforce a simple charset
  2268. var ncname = '[a-zA-Z_][\\w\\-\\.]*';
  2269. var qnameCapture = '((?:' + ncname + '\\:)?' + ncname + ')';
  2270. var startTagOpen = new RegExp('^<' + qnameCapture);
  2271. var startTagClose = /^\s*(\/?)>/;
  2272. var endTag = new RegExp('^<\\/' + qnameCapture + '[^>]*>');
  2273. var doctype = /^<!DOCTYPE [^>]+>/i;
  2274. var IS_REGEX_CAPTURING_BROKEN = false;
  2275. 'x'.replace(/x(.)?/g, function (m, g) {
  2276. IS_REGEX_CAPTURING_BROKEN = g === '';
  2277. });
  2278. // Special Elements (can contain anything)
  2279. var special = makeMap('script,style', true);
  2280. var reCache = {};
  2281. function attrForHandler(handler) {
  2282. var pattern = singleAttrIdentifier.source + '(?:\\s*(' + joinSingleAttrAssigns(handler) + ')' + '\\s*(?:' + singleAttrValues.join('|') + '))?';
  2283. return new RegExp('^\\s*' + pattern);
  2284. }
  2285. function joinSingleAttrAssigns(handler) {
  2286. return singleAttrAssigns.map(function (assign) {
  2287. return '(?:' + assign.source + ')';
  2288. }).join('|');
  2289. }
  2290. function parseHTML(html, handler) {
  2291. var stack = [];
  2292. var attribute = attrForHandler(handler);
  2293. var expectHTML = handler.expectHTML;
  2294. var isUnaryTag = handler.isUnaryTag || function () {
  2295. return false;
  2296. };
  2297. var last = void 0,
  2298. prevTag = void 0,
  2299. nextTag = void 0,
  2300. lastTag = void 0;
  2301. while (html) {
  2302. last = html;
  2303. // Make sure we're not in a script or style element
  2304. if (!lastTag || !special(lastTag)) {
  2305. var textEnd = html.indexOf('<');
  2306. if (textEnd === 0) {
  2307. // Comment:
  2308. if (/^<!--/.test(html)) {
  2309. var commentEnd = html.indexOf('-->');
  2310. if (commentEnd >= 0) {
  2311. html = html.substring(commentEnd + 3);
  2312. prevTag = '';
  2313. continue;
  2314. }
  2315. }
  2316. // http://en.wikipedia.org/wiki/Conditional_comment#Downlevel-revealed_conditional_comment
  2317. if (/^<!\[/.test(html)) {
  2318. var conditionalEnd = html.indexOf(']>');
  2319. if (conditionalEnd >= 0) {
  2320. html = html.substring(conditionalEnd + 2);
  2321. prevTag = '';
  2322. continue;
  2323. }
  2324. }
  2325. // Doctype:
  2326. var doctypeMatch = html.match(doctype);
  2327. if (doctypeMatch) {
  2328. if (handler.doctype) {
  2329. handler.doctype(doctypeMatch[0]);
  2330. }
  2331. html = html.substring(doctypeMatch[0].length);
  2332. prevTag = '';
  2333. continue;
  2334. }
  2335. // End tag:
  2336. var endTagMatch = html.match(endTag);
  2337. if (endTagMatch) {
  2338. html = html.substring(endTagMatch[0].length);
  2339. endTagMatch[0].replace(endTag, parseEndTag);
  2340. prevTag = '/' + endTagMatch[1].toLowerCase();
  2341. continue;
  2342. }
  2343. // Start tag:
  2344. var startTagMatch = parseStartTag(html);
  2345. if (startTagMatch) {
  2346. html = startTagMatch.rest;
  2347. handleStartTag(startTagMatch);
  2348. prevTag = startTagMatch.tagName.toLowerCase();
  2349. continue;
  2350. }
  2351. }
  2352. var text;
  2353. if (textEnd >= 0) {
  2354. text = html.substring(0, textEnd);
  2355. html = html.substring(textEnd);
  2356. } else {
  2357. text = html;
  2358. html = '';
  2359. }
  2360. // next tag
  2361. var nextTagMatch = parseStartTag(html);
  2362. if (nextTagMatch) {
  2363. nextTag = nextTagMatch.tagName;
  2364. } else {
  2365. nextTagMatch = html.match(endTag);
  2366. if (nextTagMatch) {
  2367. nextTag = '/' + nextTagMatch[1];
  2368. } else {
  2369. nextTag = '';
  2370. }
  2371. }
  2372. if (handler.chars) {
  2373. handler.chars(text, prevTag, nextTag);
  2374. }
  2375. prevTag = '';
  2376. } else {
  2377. var stackedTag = lastTag.toLowerCase();
  2378. var reStackedTag = reCache[stackedTag] || (reCache[stackedTag] = new RegExp('([\\s\\S]*?)</' + stackedTag + '[^>]*>', 'i'));
  2379. html = html.replace(reStackedTag, function (all, text) {
  2380. if (stackedTag !== 'script' && stackedTag !== 'style' && stackedTag !== 'noscript') {
  2381. text = text.replace(/<!--([\s\S]*?)-->/g, '$1').replace(/<!\[CDATA\[([\s\S]*?)\]\]>/g, '$1');
  2382. }
  2383. if (handler.chars) {
  2384. handler.chars(text);
  2385. }
  2386. return '';
  2387. });
  2388. parseEndTag('</' + stackedTag + '>', stackedTag);
  2389. }
  2390. if (html === last) {
  2391. throw new Error('Error parsing template:\n\n' + html);
  2392. }
  2393. }
  2394. if (!handler.partialMarkup) {
  2395. // Clean up any remaining tags
  2396. parseEndTag();
  2397. }
  2398. function parseStartTag(input) {
  2399. var start = input.match(startTagOpen);
  2400. if (start) {
  2401. var match = {
  2402. tagName: start[1],
  2403. attrs: []
  2404. };
  2405. input = input.slice(start[0].length);
  2406. var end, attr;
  2407. while (!(end = input.match(startTagClose)) && (attr = input.match(attribute))) {
  2408. input = input.slice(attr[0].length);
  2409. match.attrs.push(attr);
  2410. }
  2411. if (end) {
  2412. match.unarySlash = end[1];
  2413. match.rest = input.slice(end[0].length);
  2414. return match;
  2415. }
  2416. }
  2417. }
  2418. function handleStartTag(match) {
  2419. var tagName = match.tagName;
  2420. var unarySlash = match.unarySlash;
  2421. if (expectHTML) {
  2422. if (lastTag === 'p' && isNonPhrasingTag(tagName)) {
  2423. parseEndTag('', lastTag);
  2424. }
  2425. if (canBeLeftOpenTag(tagName) && lastTag === tagName) {
  2426. parseEndTag('', tagName);
  2427. }
  2428. }
  2429. var unary = isUnaryTag(tagName) || tagName === 'html' && lastTag === 'head' || !!unarySlash;
  2430. var attrs = match.attrs.map(function (args) {
  2431. // hackish work around FF bug https://bugzilla.mozilla.org/show_bug.cgi?id=369778
  2432. if (IS_REGEX_CAPTURING_BROKEN && args[0].indexOf('""') === -1) {
  2433. if (args[3] === '') {
  2434. delete args[3];
  2435. }
  2436. if (args[4] === '') {
  2437. delete args[4];
  2438. }
  2439. if (args[5] === '') {
  2440. delete args[5];
  2441. }
  2442. }
  2443. return {
  2444. name: args[1],
  2445. value: entities.decodeHTML(args[3] || args[4] || args[5] || '')
  2446. };
  2447. });
  2448. if (!unary) {
  2449. stack.push({ tag: tagName, attrs: attrs });
  2450. lastTag = tagName;
  2451. unarySlash = '';
  2452. }
  2453. if (handler.start) {
  2454. handler.start(tagName, attrs, unary, unarySlash);
  2455. }
  2456. }
  2457. function parseEndTag(tag, tagName) {
  2458. var pos;
  2459. // Find the closest opened tag of the same type
  2460. if (tagName) {
  2461. var needle = tagName.toLowerCase();
  2462. for (pos = stack.length - 1; pos >= 0; pos--) {
  2463. if (stack[pos].tag.toLowerCase() === needle) {
  2464. break;
  2465. }
  2466. }
  2467. } else {
  2468. // If no tag name is provided, clean shop
  2469. pos = 0;
  2470. }
  2471. if (pos >= 0) {
  2472. // Close all the open elements, up the stack
  2473. for (var i = stack.length - 1; i >= pos; i--) {
  2474. if (handler.end) {
  2475. handler.end(stack[i].tag, stack[i].attrs, i > pos || !tag);
  2476. }
  2477. }
  2478. // Remove the open elements from the stack
  2479. stack.length = pos;
  2480. lastTag = pos && stack[pos - 1].tag;
  2481. } else if (tagName.toLowerCase() === 'br') {
  2482. if (handler.start) {
  2483. handler.start(tagName, [], true, '');
  2484. }
  2485. } else if (tagName.toLowerCase() === 'p') {
  2486. if (handler.start) {
  2487. handler.start(tagName, [], false, '', true);
  2488. }
  2489. if (handler.end) {
  2490. handler.end(tagName, []);
  2491. }
  2492. }
  2493. }
  2494. }
  2495. var tagRE = /\{\{((?:.|\\n)+?)\}\}/g;
  2496. function parseText(text) {
  2497. if (!tagRE.test(text)) {
  2498. return null;
  2499. }
  2500. var tokens = [];
  2501. var lastIndex = tagRE.lastIndex = 0;
  2502. var match, index;
  2503. while (match = tagRE.exec(text)) {
  2504. index = match.index;
  2505. // push text token
  2506. if (index > lastIndex) {
  2507. tokens.push(JSON.stringify(text.slice(lastIndex, index)));
  2508. }
  2509. // tag token
  2510. var exp = match[1].trim();
  2511. tokens.push('__toString__(' + exp + ')');
  2512. lastIndex = index + match[0].length;
  2513. }
  2514. if (lastIndex < text.length) {
  2515. tokens.push(JSON.stringify(text.slice(lastIndex)));
  2516. }
  2517. return tokens.join('+');
  2518. }
  2519. function addProp(el, name, value) {
  2520. (el.props || (el.props = [])).push({ name: name, value: value });
  2521. }
  2522. function addAttr(el, name, value) {
  2523. (el.attrs || (el.attrs = [])).push({ name: name, value: value });
  2524. }
  2525. function addStaticAttr(el, name, value) {
  2526. (el.staticAttrs || (el.staticAttrs = [])).push({ name: name, value: value });
  2527. }
  2528. function addDirective(el, name, value, arg, modifiers) {
  2529. (el.directives || (el.directives = [])).push({ name: name, value: value, arg: arg, modifiers: modifiers });
  2530. }
  2531. function addHook(el, name, code) {
  2532. var hooks = el.hooks || (el.hooks = {});
  2533. var hook = hooks[name];
  2534. if (hook) {
  2535. hook.push(code);
  2536. } else {
  2537. hooks[name] = [code];
  2538. }
  2539. }
  2540. function addHandler(el, name, value, modifiers) {
  2541. var events = el.events || (el.events = {});
  2542. // check capture modifier
  2543. if (modifiers && modifiers.capture) {
  2544. delete modifiers.capture;
  2545. name = '!' + name; // mark the event as captured
  2546. }
  2547. var newHandler = { value: value, modifiers: modifiers };
  2548. var handlers = events[name];
  2549. if (isArray(handlers)) {
  2550. handlers.push(newHandler);
  2551. } else if (handlers) {
  2552. events[name] = [handlers, newHandler];
  2553. } else {
  2554. events[name] = newHandler;
  2555. }
  2556. }
  2557. function getBindingAttr(el, name, getStatic) {
  2558. var staticValue = getStatic !== false && getAndRemoveAttr(el, name);
  2559. return staticValue || staticValue === '' ? JSON.stringify(staticValue) : getAndRemoveAttr(el, ':' + name) || getAndRemoveAttr(el, 'v-bind:' + name);
  2560. }
  2561. function getAndRemoveAttr(el, name) {
  2562. var val = void 0;
  2563. if ((val = el.attrsMap[name]) != null) {
  2564. el.attrsMap[name] = null;
  2565. var list = el.attrsList;
  2566. for (var i = 0, l = list.length; i < l; i++) {
  2567. if (list[i].name === name) {
  2568. list.splice(i, 1);
  2569. break;
  2570. }
  2571. }
  2572. }
  2573. return val;
  2574. }
  2575. var dirRE = /^v-|^@|^:/;
  2576. var bindRE = /^:|^v-bind:/;
  2577. var onRE = /^@|^v-on:/;
  2578. var argRE = /:(.*)$/;
  2579. var modifierRE = /\.[^\.]+/g;
  2580. var forAliasRE = /(.*)\s+(?:in|of)\s+(.*)/;
  2581. var forIteratorRE = /\((.*),(.*)\)/;
  2582. var camelRE = /[a-z\d][A-Z]/;
  2583. var decodeHTMLCached = cached(entities.decodeHTML);
  2584. // make warning customizable depending on environment.
  2585. var warn = void 0;
  2586. var baseWarn = function baseWarn(msg) {
  2587. return console.error('[Vue parser]: ' + msg);
  2588. };
  2589. // platform-injected util functions
  2590. var platformGetTagNamespace = void 0;
  2591. var platformMustUseProp = void 0;
  2592. /**
  2593. * Convert HTML string to AST.
  2594. *
  2595. * @param {String} template
  2596. * @param {Object} options
  2597. * @return {Object}
  2598. */
  2599. function parse(template, options) {
  2600. warn = options.warn || baseWarn;
  2601. platformGetTagNamespace = options.getTagNamespace || function () {
  2602. return null;
  2603. };
  2604. platformMustUseProp = options.mustUseProp || function () {
  2605. return false;
  2606. };
  2607. var stack = [];
  2608. var root = void 0;
  2609. var currentParent = void 0;
  2610. var inPre = false;
  2611. var warned = false;
  2612. parseHTML(template, {
  2613. expectHTML: options.expectHTML,
  2614. isUnaryTag: options.isUnaryTag,
  2615. start: function start(tag, attrs, unary) {
  2616. // check camelCase tag
  2617. if (camelRE.test(tag)) {
  2618. process.env.NODE_ENV !== 'production' && warn('Found camelCase tag in template: <' + tag + '>. ' + ('I\'ve converted it to <' + hyphenate(tag) + '> for you.'));
  2619. tag = hyphenate(tag);
  2620. }
  2621. tag = tag.toLowerCase();
  2622. var element = {
  2623. tag: tag,
  2624. attrsList: attrs,
  2625. attrsMap: makeAttrsMap(attrs),
  2626. parent: currentParent,
  2627. children: []
  2628. };
  2629. // check namespace.
  2630. // inherit parent ns if there is one
  2631. var ns = void 0;
  2632. if ((ns = currentParent && currentParent.ns) || (ns = platformGetTagNamespace(tag))) {
  2633. element.ns = ns;
  2634. }
  2635. if (!inPre) {
  2636. processPre(element);
  2637. if (element.pre) {
  2638. inPre = true;
  2639. }
  2640. }
  2641. if (inPre) {
  2642. processRawAttrs(element);
  2643. } else {
  2644. processFor(element);
  2645. processIf(element);
  2646. processOnce(element);
  2647. // determine whether this is a plain element after
  2648. // removing if/for/once attributes
  2649. element.plain = !attrs.length;
  2650. processRender(element);
  2651. processSlot(element);
  2652. processComponent(element);
  2653. processClassBinding(element);
  2654. processStyleBinding(element);
  2655. processTransition(element);
  2656. processAttrs(element);
  2657. }
  2658. // tree management
  2659. if (!root) {
  2660. root = element;
  2661. } else if (process.env.NODE_ENV !== 'production' && !stack.length && !warned) {
  2662. warned = true;
  2663. warn('Component template should contain exactly one root element:\n\n' + template);
  2664. }
  2665. if (currentParent) {
  2666. if (element.else) {
  2667. processElse(element, currentParent);
  2668. } else {
  2669. currentParent.children.push(element);
  2670. element.parent = currentParent;
  2671. }
  2672. }
  2673. if (!unary) {
  2674. currentParent = element;
  2675. stack.push(element);
  2676. }
  2677. },
  2678. end: function end(tag) {
  2679. // remove trailing whitespace
  2680. var element = stack[stack.length - 1];
  2681. var lastNode = element.children[element.children.length - 1];
  2682. if (lastNode && lastNode.text === ' ') element.children.pop();
  2683. // pop stack
  2684. stack.length -= 1;
  2685. currentParent = stack[stack.length - 1];
  2686. // check pre state
  2687. if (element.pre) {
  2688. inPre = false;
  2689. }
  2690. },
  2691. chars: function chars(text) {
  2692. if (!currentParent) {
  2693. if (process.env.NODE_ENV !== 'production' && !warned) {
  2694. warned = true;
  2695. warn('Component template should contain exactly one root element:\n\n' + template);
  2696. }
  2697. return;
  2698. }
  2699. text = currentParent.tag === 'pre' || text.trim() ? decodeHTMLCached(text)
  2700. // only preserve whitespace if its not right after a starting tag
  2701. : options.preserveWhitespace && currentParent.children.length ? ' ' : null;
  2702. if (text) {
  2703. var expression = void 0;
  2704. if (!inPre && text !== ' ' && (expression = parseText(text))) {
  2705. currentParent.children.push({ expression: expression });
  2706. } else {
  2707. currentParent.children.push({ text: text });
  2708. }
  2709. }
  2710. }
  2711. });
  2712. return root;
  2713. }
  2714. function processPre(el) {
  2715. if (getAndRemoveAttr(el, 'v-pre') != null) {
  2716. el.pre = true;
  2717. }
  2718. }
  2719. function processRawAttrs(el) {
  2720. var l = el.attrsList.length;
  2721. if (l) {
  2722. el.attrs = new Array(l);
  2723. for (var i = 0; i < l; i++) {
  2724. el.attrs[i] = {
  2725. name: el.attrsList[i].name,
  2726. value: JSON.stringify(el.attrsList[i].value)
  2727. };
  2728. }
  2729. }
  2730. }
  2731. function processFor(el) {
  2732. var exp = void 0;
  2733. if (exp = getAndRemoveAttr(el, 'v-for')) {
  2734. var inMatch = exp.match(forAliasRE);
  2735. if (!inMatch) {
  2736. process.env.NODE_ENV !== 'production' && warn('Invalid v-for expression: ' + exp);
  2737. return;
  2738. }
  2739. el.for = inMatch[2].trim();
  2740. var alias = inMatch[1].trim();
  2741. var iteratorMatch = alias.match(forIteratorRE);
  2742. if (iteratorMatch) {
  2743. el.iterator = iteratorMatch[1].trim();
  2744. el.alias = iteratorMatch[2].trim();
  2745. } else {
  2746. el.alias = alias;
  2747. }
  2748. if (exp = getAndRemoveAttr(el, 'track-by')) {
  2749. el.key = exp === '$index' ? exp : el.alias + '["' + exp + '"]';
  2750. }
  2751. }
  2752. }
  2753. function processIf(el) {
  2754. var exp = getAndRemoveAttr(el, 'v-if');
  2755. if (exp) {
  2756. el.if = exp;
  2757. }
  2758. if (getAndRemoveAttr(el, 'v-else') != null) {
  2759. el.else = true;
  2760. }
  2761. }
  2762. function processElse(el, parent) {
  2763. var prev = findPrevElement(parent.children);
  2764. if (prev && (prev.if || prev.attrsMap['v-show'])) {
  2765. if (prev.if) {
  2766. // v-if
  2767. prev.elseBlock = el;
  2768. } else {
  2769. // v-show: simply add a v-show with reversed value
  2770. addDirective(el, 'show', '!(' + prev.attrsMap['v-show'] + ')');
  2771. // also copy its transition
  2772. el.transition = prev.transition;
  2773. // als set show to true
  2774. el.show = true;
  2775. parent.children.push(el);
  2776. }
  2777. } else if (process.env.NODE_ENV !== 'production') {
  2778. warn('v-else used on element <' + el.tag + '> without corresponding v-if/v-show.');
  2779. }
  2780. }
  2781. function processOnce(el) {
  2782. var once = getAndRemoveAttr(el, 'v-once');
  2783. if (once != null) {
  2784. el.once = true;
  2785. }
  2786. }
  2787. function processRender(el) {
  2788. if (el.tag === 'render') {
  2789. el.render = true;
  2790. el.renderMethod = el.attrsMap.method;
  2791. el.renderArgs = el.attrsMap[':args'] || el.attrsMap['v-bind:args'];
  2792. if (process.env.NODE_ENV !== 'production') {
  2793. if (!el.renderMethod) {
  2794. warn('method attribute is required on <render>.');
  2795. }
  2796. if (el.attrsMap.args) {
  2797. warn('<render> args should use a dynamic binding, e.g. `:args="..."`.');
  2798. }
  2799. }
  2800. }
  2801. }
  2802. function processSlot(el) {
  2803. if (el.tag === 'slot') {
  2804. el.slotName = getBindingAttr(el, 'name');
  2805. } else {
  2806. var slotTarget = getBindingAttr(el, 'slot');
  2807. if (slotTarget) {
  2808. el.slotTarget = slotTarget;
  2809. }
  2810. }
  2811. }
  2812. function processComponent(el) {
  2813. if (el.tag === 'component') {
  2814. el.component = getBindingAttr(el, 'is');
  2815. }
  2816. }
  2817. function processClassBinding(el) {
  2818. var staticClass = getAndRemoveAttr(el, 'class');
  2819. el.staticClass = parseText(staticClass) || JSON.stringify(staticClass);
  2820. var classBinding = getBindingAttr(el, 'class', false /* getStatic */);
  2821. if (classBinding) {
  2822. el.classBinding = classBinding;
  2823. }
  2824. }
  2825. function processStyleBinding(el) {
  2826. var styleBinding = getBindingAttr(el, 'style', false /* getStatic */);
  2827. if (styleBinding) {
  2828. el.styleBinding = styleBinding;
  2829. }
  2830. }
  2831. function processTransition(el) {
  2832. var transition = getBindingAttr(el, 'transition');
  2833. if (transition === '""') {
  2834. transition = true;
  2835. }
  2836. if (transition) {
  2837. el.transition = transition;
  2838. el.transitionOnAppear = getBindingAttr(el, 'transition-on-appear') != null;
  2839. }
  2840. }
  2841. function processAttrs(el) {
  2842. var list = el.attrsList;
  2843. var i = void 0,
  2844. l = void 0,
  2845. name = void 0,
  2846. value = void 0,
  2847. arg = void 0,
  2848. modifiers = void 0;
  2849. for (i = 0, l = list.length; i < l; i++) {
  2850. name = list[i].name;
  2851. value = list[i].value;
  2852. if (dirRE.test(name)) {
  2853. // modifiers
  2854. modifiers = parseModifiers(name);
  2855. if (modifiers) {
  2856. name = name.replace(modifierRE, '');
  2857. }
  2858. if (bindRE.test(name)) {
  2859. // v-bind
  2860. name = name.replace(bindRE, '');
  2861. if (platformMustUseProp(name)) {
  2862. addProp(el, name, value);
  2863. } else {
  2864. addAttr(el, name, value);
  2865. }
  2866. } else if (onRE.test(name)) {
  2867. // v-on
  2868. name = name.replace(onRE, '');
  2869. addHandler(el, name, value, modifiers);
  2870. } else {
  2871. // normal directives
  2872. name = name.replace(dirRE, '');
  2873. // parse arg
  2874. if ((arg = name.match(argRE)) && (arg = arg[1])) {
  2875. name = name.slice(0, -(arg.length + 1));
  2876. }
  2877. addDirective(el, name, value, arg, modifiers);
  2878. }
  2879. } else {
  2880. // literal attribute
  2881. var expression = parseText(value);
  2882. if (expression) {
  2883. warn('Interpolation inside attributes has been deprecated. ' + 'Use v-bind or the colon shorthand instead.');
  2884. } else {
  2885. addStaticAttr(el, name, JSON.stringify(value));
  2886. }
  2887. }
  2888. }
  2889. }
  2890. function parseModifiers(name) {
  2891. var match = name.match(modifierRE);
  2892. if (match) {
  2893. var _ret = function () {
  2894. var ret = {};
  2895. match.forEach(function (m) {
  2896. ret[m.slice(1)] = true;
  2897. });
  2898. return {
  2899. v: ret
  2900. };
  2901. }();
  2902. if (typeof _ret === "object") return _ret.v;
  2903. }
  2904. }
  2905. function makeAttrsMap(attrs) {
  2906. var map = {};
  2907. for (var i = 0, l = attrs.length; i < l; i++) {
  2908. if (process.env.NODE_ENV !== 'production' && map[attrs[i].name]) {
  2909. warn('duplicate attribute: ' + attrs[i].name);
  2910. }
  2911. map[attrs[i].name] = attrs[i].value;
  2912. }
  2913. return map;
  2914. }
  2915. function findPrevElement(children) {
  2916. var i = children.length;
  2917. while (i--) {
  2918. if (children[i].tag) return children[i];
  2919. }
  2920. }
  2921. var isPlatformReservedTag = void 0;
  2922. /**
  2923. * Goal of the optimizier: walk the generated template AST tree
  2924. * and detect sub-trees that are purely static, i.e. parts of
  2925. * the DOM that never needs to change.
  2926. *
  2927. * Once we detect these sub-trees, we can:
  2928. *
  2929. * 1. Hoist them into constants, so that we no longer need to
  2930. * create fresh nodes for them on each re-render;
  2931. * 2. Completely skip them in the patching process.
  2932. */
  2933. function optimize(root, options) {
  2934. isPlatformReservedTag = options.isReservedTag || function () {
  2935. return false;
  2936. };
  2937. // first pass: mark all non-static nodes.
  2938. markStatic(root);
  2939. // second pass: mark static roots.
  2940. markStaticRoots(root);
  2941. }
  2942. function markStatic(node) {
  2943. node.static = isStatic(node);
  2944. if (node.children) {
  2945. for (var i = 0, l = node.children.length; i < l; i++) {
  2946. var child = node.children[i];
  2947. markStatic(child);
  2948. if (!child.static) {
  2949. node.static = false;
  2950. }
  2951. }
  2952. }
  2953. }
  2954. function markStaticRoots(node) {
  2955. if (node.tag && (node.once || node.static)) {
  2956. node.staticRoot = true;
  2957. return;
  2958. }
  2959. if (node.children) {
  2960. for (var i = 0, l = node.children.length; i < l; i++) {
  2961. markStaticRoots(node.children[i]);
  2962. }
  2963. }
  2964. }
  2965. var isStaticKey = makeMap('tag,attrsList,attrsMap,plain,parent,children,' + 'staticAttrs,staticClass');
  2966. function isStatic(node) {
  2967. return !!(node.text || node.pre || !node.expression && // not text with interpolation
  2968. !node.if && !node.for && ( // not v-if or v-for or v-else
  2969. !node.tag || isPlatformReservedTag(node.tag)) && // not a component
  2970. !isBuiltInTag(node.tag) && ( // not a built-in
  2971. node.plain || Object.keys(node).every(isStaticKey)) // no dynamic bindings
  2972. );
  2973. }
  2974. var simplePathRE = /^[A-Za-z_$][\w$]*(?:\.[A-Za-z_$][\w$]*|\['.*?'\]|\[".*?"\]|\[\d+\]|\[[A-Za-z_$][\w$]*\])*$/;
  2975. // keyCode aliases
  2976. var keyCodes = {
  2977. esc: 27,
  2978. tab: 9,
  2979. enter: 13,
  2980. space: 32,
  2981. up: 38,
  2982. left: 37,
  2983. right: 39,
  2984. down: 40,
  2985. 'delete': [8, 46]
  2986. };
  2987. var modifierCode = {
  2988. stop: '$event.stopPropagation();',
  2989. prevent: '$event.preventDefault();',
  2990. self: 'if($event.target !== $event.currentTarget)return;'
  2991. };
  2992. function genHandlers(events) {
  2993. var res = 'on:{';
  2994. for (var name in events) {
  2995. res += '"' + name + '":' + genHandler(events[name]) + ',';
  2996. }
  2997. return res.slice(0, -1) + '}';
  2998. }
  2999. function genHandler(handler) {
  3000. if (!handler) {
  3001. return 'function(){}';
  3002. } else if (isArray(handler)) {
  3003. return '[' + handler.map(genHandler).join(',') + ']';
  3004. } else if (!handler.modifiers) {
  3005. return simplePathRE.test(handler.value) ? handler.value : 'function($event){' + handler.value + '}';
  3006. } else {
  3007. var code = 'function($event){';
  3008. for (var key in handler.modifiers) {
  3009. code += modifierCode[key] || genKeyFilter(key);
  3010. }
  3011. var handlerCode = simplePathRE.test(handler.value) ? handler.value + '($event)' : handler.value;
  3012. return code + handlerCode + '}';
  3013. }
  3014. }
  3015. function genKeyFilter(key) {
  3016. var code = keyCodes[key];
  3017. if (isArray(code)) {
  3018. return 'if(' + code.map(function (c) {
  3019. return '$event.keyCode!==' + c;
  3020. }).join('&&') + ')return;';
  3021. } else {
  3022. return 'if($event.keyCode!==' + code + ')return;';
  3023. }
  3024. }
  3025. function ref(el, dir) {
  3026. // go up and check if this node is inside a v-for
  3027. var isFor = false;
  3028. var parent = el;
  3029. while (parent) {
  3030. if (parent.for !== undefined) {
  3031. isFor = true;
  3032. }
  3033. parent = parent.parent;
  3034. }
  3035. // __registerRef__(name, ref, vFor?, remove?)
  3036. var code = '__registerRef__("' + dir.arg + '", n1.child || n1.elm, ' + (isFor ? 'true' : 'false');
  3037. addHook(el, 'insert', code + ')');
  3038. addHook(el, 'destroy', code + ', true)');
  3039. }
  3040. var baseDirectives = {
  3041. ref: ref,
  3042. cloak: function cloak() {} // noop
  3043. };
  3044. // platform-injected utils
  3045. var platformDirectives = void 0;
  3046. var isPlatformReservedTag$1 = void 0;
  3047. // reset on each call
  3048. var staticRenderFns = void 0;
  3049. function generate(ast, options) {
  3050. staticRenderFns = [];
  3051. platformDirectives = options.directives || {};
  3052. isPlatformReservedTag$1 = options.isReservedTag || function () {
  3053. return false;
  3054. };
  3055. var code = ast ? genElement(ast) : '__h__("div")';
  3056. return {
  3057. render: 'with (this) { return ' + code + '}',
  3058. staticRenderFns: staticRenderFns
  3059. };
  3060. }
  3061. function genElement(el) {
  3062. if (el.for) {
  3063. return genFor(el);
  3064. } else if (el.if) {
  3065. return genIf(el);
  3066. } else if (el.tag === 'template' && !el.slotTarget) {
  3067. return genChildren(el);
  3068. } else if (el.tag === 'render') {
  3069. return genRender(el);
  3070. } else if (el.tag === 'slot') {
  3071. return genSlot(el);
  3072. } else if (el.tag === 'component') {
  3073. return genComponent(el);
  3074. } else {
  3075. // if the element is potentially a component,
  3076. // wrap its children as a thunk.
  3077. var children = genChildren(el, !isPlatformReservedTag$1(el.tag) /* asThunk */);
  3078. var code = '__h__(\'' + el.tag + '\', ' + genData(el) + ', ' + children + ', \'' + (el.ns || '') + '\')';
  3079. if (el.staticRoot) {
  3080. // hoist static sub-trees out
  3081. staticRenderFns.push('with(this){return ' + code + '}');
  3082. return '_staticTrees[' + (staticRenderFns.length - 1) + ']';
  3083. } else {
  3084. return code;
  3085. }
  3086. }
  3087. }
  3088. function genIf(el) {
  3089. var exp = el.if;
  3090. el.if = false; // avoid recursion
  3091. return '(' + exp + ') ? ' + genElement(el) + ' : ' + genElse(el);
  3092. }
  3093. function genElse(el) {
  3094. return el.elseBlock ? genElement(el.elseBlock) : 'null';
  3095. }
  3096. function genFor(el) {
  3097. var exp = el.for;
  3098. var alias = el.alias;
  3099. var iterator = el.iterator;
  3100. el.for = false; // avoid recursion
  3101. return '(' + exp + ')&&__renderList__((' + exp + '), ' + ('function(' + alias + ',$index' + (iterator ? ',' + iterator : '') + '){') + ('return ' + genElement(el)) + '})';
  3102. }
  3103. function genData(el) {
  3104. if (el.plain) {
  3105. return 'undefined';
  3106. }
  3107. var data = '{';
  3108. // directives first.
  3109. // directives may mutate the el's other properties before they are generated.
  3110. if (el.directives) {
  3111. var dirs = genDirectives(el);
  3112. if (dirs) data += dirs + ',';
  3113. }
  3114. // pre
  3115. if (el.pre) {
  3116. data += 'pre:true,';
  3117. }
  3118. // key
  3119. if (el.key) {
  3120. data += 'key:' + el.key + ',';
  3121. }
  3122. // slot target
  3123. if (el.slotTarget) {
  3124. data += 'slot:' + el.slotTarget + ',';
  3125. }
  3126. // class
  3127. if (el.staticClass) {
  3128. data += 'staticClass:' + el.staticClass + ',';
  3129. }
  3130. if (el.classBinding) {
  3131. data += 'class:' + el.classBinding + ',';
  3132. }
  3133. // style
  3134. if (el.styleBinding) {
  3135. data += 'style:' + el.styleBinding + ',';
  3136. }
  3137. // transition
  3138. if (el.transition) {
  3139. data += 'transition:{definition:(' + el.transition + '),appear:' + el.transitionOnAppear + '},';
  3140. }
  3141. // v-show, used to avoid transition being applied
  3142. // since v-show takes it over
  3143. if (el.attrsMap['v-show'] || el.show) {
  3144. data += 'show:true,';
  3145. }
  3146. // props
  3147. if (el.props) {
  3148. data += 'props:{' + genProps(el.props) + '},';
  3149. }
  3150. // attributes
  3151. if (el.attrs) {
  3152. data += 'attrs:{' + genProps(el.attrs) + '},';
  3153. }
  3154. // static attributes
  3155. if (el.staticAttrs) {
  3156. data += 'staticAttrs:{' + genProps(el.staticAttrs) + '},';
  3157. }
  3158. // hooks
  3159. if (el.hooks) {
  3160. data += 'hook:{' + genHooks(el.hooks) + '},';
  3161. }
  3162. // event handlers
  3163. if (el.events) {
  3164. data += genHandlers(el.events);
  3165. }
  3166. return data.replace(/,$/, '') + '}';
  3167. }
  3168. function genDirectives(el) {
  3169. var dirs = el.directives;
  3170. var res = 'directives:[';
  3171. var hasRuntime = false;
  3172. var i = void 0,
  3173. l = void 0,
  3174. dir = void 0,
  3175. needRuntime = void 0;
  3176. for (i = 0, l = dirs.length; i < l; i++) {
  3177. dir = dirs[i];
  3178. needRuntime = true;
  3179. var gen = platformDirectives[dir.name] || baseDirectives[dir.name];
  3180. if (gen) {
  3181. // compile-time directive that manipulates AST.
  3182. // returns true if it also needs a runtime counterpart.
  3183. needRuntime = !!gen(el, dir);
  3184. }
  3185. if (needRuntime) {
  3186. hasRuntime = true;
  3187. res += '{name:"' + dir.name + '"' + (dir.value ? ',value:(' + dir.value + ')' : '') + (dir.arg ? ',arg:"' + dir.arg + '"' : '') + (dir.modifiers ? ',modifiers:' + JSON.stringify(dir.modifiers) : '') + '},';
  3188. }
  3189. }
  3190. if (hasRuntime) {
  3191. return res.slice(0, -1) + ']';
  3192. }
  3193. }
  3194. function genChildren(el, asThunk) {
  3195. if (!el.children.length) {
  3196. return 'undefined';
  3197. }
  3198. var code = '[' + el.children.map(genNode).join(',') + ']';
  3199. return asThunk ? 'function(){return ' + code + '}' : code;
  3200. }
  3201. function genNode(node) {
  3202. if (node.tag) {
  3203. return genElement(node);
  3204. } else {
  3205. return genText(node);
  3206. }
  3207. }
  3208. function genText(text) {
  3209. return text.expression ? '(' + text.expression + ')' : JSON.stringify(text.text);
  3210. }
  3211. function genRender(el) {
  3212. return el.renderMethod + '(' + (el.renderArgs || 'null') + ',' + genChildren(el) + ')';
  3213. }
  3214. function genSlot(el) {
  3215. var name = el.slotName || '"default"';
  3216. return '($slots[' + name + '] || ' + genChildren(el) + ')';
  3217. }
  3218. function genComponent(el) {
  3219. return '__h__(' + el.component + ', ' + genData(el) + ', ' + genChildren(el, true) + ')';
  3220. }
  3221. function genProps(props) {
  3222. var res = '';
  3223. for (var i = 0; i < props.length; i++) {
  3224. var prop = props[i];
  3225. res += '"' + prop.name + '":' + prop.value + ',';
  3226. }
  3227. return res.slice(0, -1);
  3228. }
  3229. function genHooks(hooks) {
  3230. var res = '';
  3231. for (var key in hooks) {
  3232. res += '"' + key + '":function(n1,n2){' + hooks[key].join(';') + '},';
  3233. }
  3234. return res.slice(0, -1);
  3235. }
  3236. /**
  3237. * Compile a template.
  3238. *
  3239. * @param {String} template
  3240. * @param {Object} options
  3241. * - warn
  3242. * - directives
  3243. * - isReservedTag
  3244. * - mustUseProp
  3245. * - getTagNamespace
  3246. */
  3247. function compile$1(template, options) {
  3248. var ast = parse(template.trim(), options);
  3249. optimize(ast, options);
  3250. return generate(ast, options);
  3251. }
  3252. function model(el, dir) {
  3253. var value = dir.value;
  3254. var modifiers = dir.modifiers;
  3255. if (el.tag === 'select') {
  3256. if (el.attrsMap.multiple != null) {
  3257. genMultiSelect(el, value);
  3258. } else {
  3259. genSelect(el, value);
  3260. }
  3261. } else {
  3262. switch (el.attrsMap.type) {
  3263. case 'checkbox':
  3264. genCheckboxModel(el, value);
  3265. break;
  3266. case 'radio':
  3267. genRadioModel(el, value);
  3268. break;
  3269. default:
  3270. return genDefaultModel(el, value, modifiers);
  3271. }
  3272. }
  3273. }
  3274. function genCheckboxModel(el, value) {
  3275. var valueBinding = getBindingAttr(el, 'value');
  3276. addProp(el, 'checked', 'Array.isArray(' + value + ')' + ('?(' + value + ').indexOf(' + valueBinding + ')>-1') + (':!!(' + value + ')'));
  3277. addHandler(el, 'change', 'var $$a=' + value + ',' + '$$el=$event.target,' + '$$c=$$el.checked;' + 'if(Array.isArray($$a)){' + ('var $$v=' + valueBinding + ',') + '$$i=$$a.indexOf($$v);' + 'if($$c){$$i<0&&$$a.push($$v)}' + 'else{$$i>-1&&$$a.splice($$i,1)}' + ('}else{' + value + '=$$c}'));
  3278. }
  3279. function genRadioModel(el, value) {
  3280. var valueBinding = getBindingAttr(el, 'value');
  3281. addProp(el, 'checked', '(' + value + '==' + valueBinding + ')');
  3282. addHandler(el, 'change', value + '=' + valueBinding);
  3283. }
  3284. function genDefaultModel(el, value, modifiers) {
  3285. var type = el.attrsMap.type;
  3286. var _ref = modifiers || {};
  3287. var lazy = _ref.lazy;
  3288. var number = _ref.number;
  3289. var trim = _ref.trim;
  3290. var event = lazy ? 'change' : 'input';
  3291. var needCompositionGuard = !lazy && type !== 'range';
  3292. var valueExpression = '$event.target.value' + (trim ? '.trim()' : '');
  3293. var code = number || type === 'number' ? value + '=Number(' + valueExpression + ')' : value + '=' + valueExpression;
  3294. if (needCompositionGuard) {
  3295. code = 'if($event.target.composing)return;' + code;
  3296. }
  3297. addProp(el, 'value', '(' + value + ')');
  3298. addHandler(el, event, code);
  3299. if (needCompositionGuard) {
  3300. // need runtime directive code to help with composition events
  3301. return true;
  3302. }
  3303. }
  3304. var getSelectedValueCode = 'Array.prototype.filter' + '.call($event.target.options,function(o){return o.selected})' + '.map(function(o){return "_value" in o ? o._value : o.value})';
  3305. function patchChildOptions(el, fn) {
  3306. for (var i = 0; i < el.children.length; i++) {
  3307. var c = el.children[i];
  3308. if (c.tag === 'option') {
  3309. addProp(c, 'selected', fn(getBindingAttr(c, 'value')));
  3310. }
  3311. }
  3312. }
  3313. function genSelect(el, value) {
  3314. addHandler(el, 'change', value + '=' + getSelectedValueCode + '[0]');
  3315. patchChildOptions(el, function (valueBinding) {
  3316. return '$(' + value + ')===(' + valueBinding + ')';
  3317. });
  3318. }
  3319. function genMultiSelect(el, value) {
  3320. addHandler(el, 'change', value + '=' + getSelectedValueCode);
  3321. patchChildOptions(el, function (valueBinding) {
  3322. return '$(' + value + ').indexOf(' + valueBinding + ')>-1';
  3323. });
  3324. }
  3325. function text(el, dir) {
  3326. if (!dir.value) return;
  3327. addProp(el, 'textContent', '__toString__(' + dir.value + ')');
  3328. }
  3329. function html(el, dir) {
  3330. if (!dir.value) return;
  3331. addProp(el, 'innerHTML', '__toString__(' + dir.value + ')');
  3332. }
  3333. var directives = {
  3334. model: model,
  3335. text: text,
  3336. html: html
  3337. };
  3338. var cache1 = Object.create(null);
  3339. var cache2 = Object.create(null);
  3340. var baseOptions = {
  3341. expectHTML: true,
  3342. directives: directives,
  3343. isReservedTag: isReservedTag,
  3344. isUnaryTag: isUnaryTag,
  3345. mustUseProp: mustUseProp,
  3346. getTagNamespace: getTagNamespace
  3347. };
  3348. function compile(template, options) {
  3349. options = options ? extend(extend({}, baseOptions), options) : baseOptions;
  3350. return compile$1(template, options);
  3351. }
  3352. function compileToFunctions(template) {
  3353. var options = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1];
  3354. var preserveWhitespace = options.preserveWhitespace !== false;
  3355. var cache = preserveWhitespace ? cache1 : cache2;
  3356. if (cache[template]) {
  3357. return cache[template];
  3358. }
  3359. var res = {};
  3360. var compiled = compile(template, { preserveWhitespace: preserveWhitespace });
  3361. res.render = new Function(compiled.render);
  3362. var l = compiled.staticRenderFns.length;
  3363. if (l) {
  3364. res.staticRenderFns = new Array(l);
  3365. for (var i = 0; i < l; i++) {
  3366. res.staticRenderFns[i] = new Function(compiled.staticRenderFns[i]);
  3367. }
  3368. }
  3369. return cache[template] = res;
  3370. }
  3371. exports.compile = compile;
  3372. exports.compileToFunctions = compileToFunctions;