build.js 120 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697
  1. 'use strict';
  2. Object.defineProperty(exports, '__esModule', { value: true });
  3. function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
  4. var deindent = _interopDefault(require('de-indent'));
  5. var he = _interopDefault(require('he'));
  6. /* */
  7. // these helpers produces better vm code in JS engines due to their
  8. // explicitness and function inlining
  9. /**
  10. * Check if value is primitive
  11. */
  12. /**
  13. * Quick object check - this is primarily used to tell
  14. * Objects from primitive values when we know the value
  15. * is a JSON-compliant type.
  16. */
  17. function isObject (obj) {
  18. return obj !== null && typeof obj === 'object'
  19. }
  20. /**
  21. * Get the raw type string of a value e.g. [object Object]
  22. */
  23. var _toString = Object.prototype.toString;
  24. function toRawType (value) {
  25. return _toString.call(value).slice(8, -1)
  26. }
  27. /**
  28. * Strict object type check. Only returns true
  29. * for plain JavaScript objects.
  30. */
  31. function isPlainObject (obj) {
  32. return _toString.call(obj) === '[object Object]'
  33. }
  34. /**
  35. * Check if val is a valid array index.
  36. */
  37. function isValidArrayIndex (val) {
  38. var n = parseFloat(String(val));
  39. return n >= 0 && Math.floor(n) === n && isFinite(val)
  40. }
  41. /**
  42. * Convert a value to a string that is actually rendered.
  43. */
  44. /**
  45. * Convert a input value to a number for persistence.
  46. * If the conversion fails, return original string.
  47. */
  48. /**
  49. * Make a map and return a function for checking if a key
  50. * is in that map.
  51. */
  52. function makeMap (
  53. str,
  54. expectsLowerCase
  55. ) {
  56. var map = Object.create(null);
  57. var list = str.split(',');
  58. for (var i = 0; i < list.length; i++) {
  59. map[list[i]] = true;
  60. }
  61. return expectsLowerCase
  62. ? function (val) { return map[val.toLowerCase()]; }
  63. : function (val) { return map[val]; }
  64. }
  65. /**
  66. * Check if a tag is a built-in tag.
  67. */
  68. var isBuiltInTag = makeMap('slot,component', true);
  69. /**
  70. * Check if a attribute is a reserved attribute.
  71. */
  72. var isReservedAttribute = makeMap('key,ref,slot,slot-scope,is');
  73. /**
  74. * Remove an item from an array
  75. */
  76. function remove (arr, item) {
  77. if (arr.length) {
  78. var index = arr.indexOf(item);
  79. if (index > -1) {
  80. return arr.splice(index, 1)
  81. }
  82. }
  83. }
  84. /**
  85. * Check whether the object has the property.
  86. */
  87. var hasOwnProperty = Object.prototype.hasOwnProperty;
  88. function hasOwn (obj, key) {
  89. return hasOwnProperty.call(obj, key)
  90. }
  91. /**
  92. * Create a cached version of a pure function.
  93. */
  94. function cached (fn) {
  95. var cache = Object.create(null);
  96. return (function cachedFn (str) {
  97. var hit = cache[str];
  98. return hit || (cache[str] = fn(str))
  99. })
  100. }
  101. /**
  102. * Camelize a hyphen-delimited string.
  103. */
  104. var camelizeRE = /-(\w)/g;
  105. var camelize = cached(function (str) {
  106. return str.replace(camelizeRE, function (_, c) { return c ? c.toUpperCase() : ''; })
  107. });
  108. /**
  109. * Capitalize a string.
  110. */
  111. var capitalize = cached(function (str) {
  112. return str.charAt(0).toUpperCase() + str.slice(1)
  113. });
  114. /**
  115. * Hyphenate a camelCase string.
  116. */
  117. var hyphenateRE = /\B([A-Z])/g;
  118. var hyphenate = cached(function (str) {
  119. return str.replace(hyphenateRE, '-$1').toLowerCase()
  120. });
  121. /**
  122. * Simple bind, faster than native
  123. */
  124. /**
  125. * Convert an Array-like object to a real Array.
  126. */
  127. /**
  128. * Mix properties into target object.
  129. */
  130. function extend (to, _from) {
  131. for (var key in _from) {
  132. to[key] = _from[key];
  133. }
  134. return to
  135. }
  136. /**
  137. * Merge an Array of Objects into a single Object.
  138. */
  139. /**
  140. * Perform no operation.
  141. * Stubbing args to make Flow happy without leaving useless transpiled code
  142. * with ...rest (https://flow.org/blog/2017/05/07/Strict-Function-Call-Arity/)
  143. */
  144. function noop (a, b, c) {}
  145. /**
  146. * Always return false.
  147. */
  148. var no = function (a, b, c) { return false; };
  149. /**
  150. * Return same value
  151. */
  152. var identity = function (_) { return _; };
  153. /**
  154. * Generate a static keys string from compiler modules.
  155. */
  156. function genStaticKeys (modules) {
  157. return modules.reduce(function (keys, m) {
  158. return keys.concat(m.staticKeys || [])
  159. }, []).join(',')
  160. }
  161. /**
  162. * Check if two values are loosely equal - that is,
  163. * if they are plain objects, do they have the same shape?
  164. */
  165. /**
  166. * Ensure a function is called only once.
  167. */
  168. /* */
  169. var isUnaryTag = makeMap(
  170. 'area,base,br,col,embed,frame,hr,img,input,isindex,keygen,' +
  171. 'link,meta,param,source,track,wbr'
  172. );
  173. // Elements that you can, intentionally, leave open
  174. // (and which close themselves)
  175. var canBeLeftOpenTag = makeMap(
  176. 'colgroup,dd,dt,li,options,p,td,tfoot,th,thead,tr,source'
  177. );
  178. // HTML5 tags https://html.spec.whatwg.org/multipage/indices.html#elements-3
  179. // Phrasing Content https://html.spec.whatwg.org/multipage/dom.html#phrasing-content
  180. var isNonPhrasingTag = makeMap(
  181. 'address,article,aside,base,blockquote,body,caption,col,colgroup,dd,' +
  182. 'details,dialog,div,dl,dt,fieldset,figcaption,figure,footer,form,' +
  183. 'h1,h2,h3,h4,h5,h6,head,header,hgroup,hr,html,legend,li,menuitem,meta,' +
  184. 'optgroup,option,param,rp,rt,source,style,summary,tbody,td,tfoot,th,thead,' +
  185. 'title,tr,track'
  186. );
  187. /**
  188. * Not type-checking this file because it's mostly vendor code.
  189. */
  190. /*!
  191. * HTML Parser By John Resig (ejohn.org)
  192. * Modified by Juriy "kangax" Zaytsev
  193. * Original code by Erik Arvidsson, Mozilla Public License
  194. * http://erik.eae.net/simplehtmlparser/simplehtmlparser.js
  195. */
  196. // Regular Expressions for parsing tags and attributes
  197. var attribute = /^\s*([^\s"'<>\/=]+)(?:\s*(=)\s*(?:"([^"]*)"+|'([^']*)'+|([^\s"'=<>`]+)))?/;
  198. // could use https://www.w3.org/TR/1999/REC-xml-names-19990114/#NT-QName
  199. // but for Vue templates we can enforce a simple charset
  200. var ncname = '[a-zA-Z_][\\w\\-\\.]*';
  201. var qnameCapture = "((?:" + ncname + "\\:)?" + ncname + ")";
  202. var startTagOpen = new RegExp(("^<" + qnameCapture));
  203. var startTagClose = /^\s*(\/?)>/;
  204. var endTag = new RegExp(("^<\\/" + qnameCapture + "[^>]*>"));
  205. var doctype = /^<!DOCTYPE [^>]+>/i;
  206. var comment = /^<!--/;
  207. var conditionalComment = /^<!\[/;
  208. var IS_REGEX_CAPTURING_BROKEN = false;
  209. 'x'.replace(/x(.)?/g, function (m, g) {
  210. IS_REGEX_CAPTURING_BROKEN = g === '';
  211. });
  212. // Special Elements (can contain anything)
  213. var isPlainTextElement = makeMap('script,style,textarea', true);
  214. var reCache = {};
  215. var decodingMap = {
  216. '&lt;': '<',
  217. '&gt;': '>',
  218. '&quot;': '"',
  219. '&amp;': '&',
  220. '&#10;': '\n',
  221. '&#9;': '\t'
  222. };
  223. var encodedAttr = /&(?:lt|gt|quot|amp);/g;
  224. var encodedAttrWithNewLines = /&(?:lt|gt|quot|amp|#10|#9);/g;
  225. // #5992
  226. var isIgnoreNewlineTag = makeMap('pre,textarea', true);
  227. var shouldIgnoreFirstNewline = function (tag, html) { return tag && isIgnoreNewlineTag(tag) && html[0] === '\n'; };
  228. function decodeAttr (value, shouldDecodeNewlines) {
  229. var re = shouldDecodeNewlines ? encodedAttrWithNewLines : encodedAttr;
  230. return value.replace(re, function (match) { return decodingMap[match]; })
  231. }
  232. function parseHTML (html, options) {
  233. var stack = [];
  234. var expectHTML = options.expectHTML;
  235. var isUnaryTag$$1 = options.isUnaryTag || no;
  236. var canBeLeftOpenTag$$1 = options.canBeLeftOpenTag || no;
  237. var index = 0;
  238. var last, lastTag;
  239. while (html) {
  240. last = html;
  241. // Make sure we're not in a plaintext content element like script/style
  242. if (!lastTag || !isPlainTextElement(lastTag)) {
  243. var textEnd = html.indexOf('<');
  244. if (textEnd === 0) {
  245. // Comment:
  246. if (comment.test(html)) {
  247. var commentEnd = html.indexOf('-->');
  248. if (commentEnd >= 0) {
  249. if (options.shouldKeepComment) {
  250. options.comment(html.substring(4, commentEnd));
  251. }
  252. advance(commentEnd + 3);
  253. continue
  254. }
  255. }
  256. // http://en.wikipedia.org/wiki/Conditional_comment#Downlevel-revealed_conditional_comment
  257. if (conditionalComment.test(html)) {
  258. var conditionalEnd = html.indexOf(']>');
  259. if (conditionalEnd >= 0) {
  260. advance(conditionalEnd + 2);
  261. continue
  262. }
  263. }
  264. // Doctype:
  265. var doctypeMatch = html.match(doctype);
  266. if (doctypeMatch) {
  267. advance(doctypeMatch[0].length);
  268. continue
  269. }
  270. // End tag:
  271. var endTagMatch = html.match(endTag);
  272. if (endTagMatch) {
  273. var curIndex = index;
  274. advance(endTagMatch[0].length);
  275. parseEndTag(endTagMatch[1], curIndex, index);
  276. continue
  277. }
  278. // Start tag:
  279. var startTagMatch = parseStartTag();
  280. if (startTagMatch) {
  281. handleStartTag(startTagMatch);
  282. if (shouldIgnoreFirstNewline(lastTag, html)) {
  283. advance(1);
  284. }
  285. continue
  286. }
  287. }
  288. var text = (void 0), rest = (void 0), next = (void 0);
  289. if (textEnd >= 0) {
  290. rest = html.slice(textEnd);
  291. while (
  292. !endTag.test(rest) &&
  293. !startTagOpen.test(rest) &&
  294. !comment.test(rest) &&
  295. !conditionalComment.test(rest)
  296. ) {
  297. // < in plain text, be forgiving and treat it as text
  298. next = rest.indexOf('<', 1);
  299. if (next < 0) { break }
  300. textEnd += next;
  301. rest = html.slice(textEnd);
  302. }
  303. text = html.substring(0, textEnd);
  304. advance(textEnd);
  305. }
  306. if (textEnd < 0) {
  307. text = html;
  308. html = '';
  309. }
  310. if (options.chars && text) {
  311. options.chars(text);
  312. }
  313. } else {
  314. var endTagLength = 0;
  315. var stackedTag = lastTag.toLowerCase();
  316. var reStackedTag = reCache[stackedTag] || (reCache[stackedTag] = new RegExp('([\\s\\S]*?)(</' + stackedTag + '[^>]*>)', 'i'));
  317. var rest$1 = html.replace(reStackedTag, function (all, text, endTag) {
  318. endTagLength = endTag.length;
  319. if (!isPlainTextElement(stackedTag) && stackedTag !== 'noscript') {
  320. text = text
  321. .replace(/<!--([\s\S]*?)-->/g, '$1')
  322. .replace(/<!\[CDATA\[([\s\S]*?)]]>/g, '$1');
  323. }
  324. if (shouldIgnoreFirstNewline(stackedTag, text)) {
  325. text = text.slice(1);
  326. }
  327. if (options.chars) {
  328. options.chars(text);
  329. }
  330. return ''
  331. });
  332. index += html.length - rest$1.length;
  333. html = rest$1;
  334. parseEndTag(stackedTag, index - endTagLength, index);
  335. }
  336. if (html === last) {
  337. options.chars && options.chars(html);
  338. if (process.env.NODE_ENV !== 'production' && !stack.length && options.warn) {
  339. options.warn(("Mal-formatted tag at end of template: \"" + html + "\""));
  340. }
  341. break
  342. }
  343. }
  344. // Clean up any remaining tags
  345. parseEndTag();
  346. function advance (n) {
  347. index += n;
  348. html = html.substring(n);
  349. }
  350. function parseStartTag () {
  351. var start = html.match(startTagOpen);
  352. if (start) {
  353. var match = {
  354. tagName: start[1],
  355. attrs: [],
  356. start: index
  357. };
  358. advance(start[0].length);
  359. var end, attr;
  360. while (!(end = html.match(startTagClose)) && (attr = html.match(attribute))) {
  361. advance(attr[0].length);
  362. match.attrs.push(attr);
  363. }
  364. if (end) {
  365. match.unarySlash = end[1];
  366. advance(end[0].length);
  367. match.end = index;
  368. return match
  369. }
  370. }
  371. }
  372. function handleStartTag (match) {
  373. var tagName = match.tagName;
  374. var unarySlash = match.unarySlash;
  375. if (expectHTML) {
  376. if (lastTag === 'p' && isNonPhrasingTag(tagName)) {
  377. parseEndTag(lastTag);
  378. }
  379. if (canBeLeftOpenTag$$1(tagName) && lastTag === tagName) {
  380. parseEndTag(tagName);
  381. }
  382. }
  383. var unary = isUnaryTag$$1(tagName) || !!unarySlash;
  384. var l = match.attrs.length;
  385. var attrs = new Array(l);
  386. for (var i = 0; i < l; i++) {
  387. var args = match.attrs[i];
  388. // hackish work around FF bug https://bugzilla.mozilla.org/show_bug.cgi?id=369778
  389. if (IS_REGEX_CAPTURING_BROKEN && args[0].indexOf('""') === -1) {
  390. if (args[3] === '') { delete args[3]; }
  391. if (args[4] === '') { delete args[4]; }
  392. if (args[5] === '') { delete args[5]; }
  393. }
  394. var value = args[3] || args[4] || args[5] || '';
  395. var shouldDecodeNewlines = tagName === 'a' && args[1] === 'href'
  396. ? options.shouldDecodeNewlinesForHref
  397. : options.shouldDecodeNewlines;
  398. attrs[i] = {
  399. name: args[1],
  400. value: decodeAttr(value, shouldDecodeNewlines)
  401. };
  402. }
  403. if (!unary) {
  404. stack.push({ tag: tagName, lowerCasedTag: tagName.toLowerCase(), attrs: attrs });
  405. lastTag = tagName;
  406. }
  407. if (options.start) {
  408. options.start(tagName, attrs, unary, match.start, match.end);
  409. }
  410. }
  411. function parseEndTag (tagName, start, end) {
  412. var pos, lowerCasedTagName;
  413. if (start == null) { start = index; }
  414. if (end == null) { end = index; }
  415. if (tagName) {
  416. lowerCasedTagName = tagName.toLowerCase();
  417. }
  418. // Find the closest opened tag of the same type
  419. if (tagName) {
  420. for (pos = stack.length - 1; pos >= 0; pos--) {
  421. if (stack[pos].lowerCasedTag === lowerCasedTagName) {
  422. break
  423. }
  424. }
  425. } else {
  426. // If no tag name is provided, clean shop
  427. pos = 0;
  428. }
  429. if (pos >= 0) {
  430. // Close all the open elements, up the stack
  431. for (var i = stack.length - 1; i >= pos; i--) {
  432. if (process.env.NODE_ENV !== 'production' &&
  433. (i > pos || !tagName) &&
  434. options.warn
  435. ) {
  436. options.warn(
  437. ("tag <" + (stack[i].tag) + "> has no matching end tag.")
  438. );
  439. }
  440. if (options.end) {
  441. options.end(stack[i].tag, start, end);
  442. }
  443. }
  444. // Remove the open elements from the stack
  445. stack.length = pos;
  446. lastTag = pos && stack[pos - 1].tag;
  447. } else if (lowerCasedTagName === 'br') {
  448. if (options.start) {
  449. options.start(tagName, [], true, start, end);
  450. }
  451. } else if (lowerCasedTagName === 'p') {
  452. if (options.start) {
  453. options.start(tagName, [], false, start, end);
  454. }
  455. if (options.end) {
  456. options.end(tagName, start, end);
  457. }
  458. }
  459. }
  460. }
  461. /* */
  462. var splitRE = /\r?\n/g;
  463. var replaceRE = /./g;
  464. var isSpecialTag = makeMap('script,style,template', true);
  465. /**
  466. * Parse a single-file component (*.vue) file into an SFC Descriptor Object.
  467. */
  468. function parseComponent (
  469. content,
  470. options
  471. ) {
  472. if ( options === void 0 ) options = {};
  473. var sfc = {
  474. template: null,
  475. script: null,
  476. styles: [],
  477. customBlocks: []
  478. };
  479. var depth = 0;
  480. var currentBlock = null;
  481. function start (
  482. tag,
  483. attrs,
  484. unary,
  485. start,
  486. end
  487. ) {
  488. if (depth === 0) {
  489. currentBlock = {
  490. type: tag,
  491. content: '',
  492. start: end,
  493. attrs: attrs.reduce(function (cumulated, ref) {
  494. var name = ref.name;
  495. var value = ref.value;
  496. cumulated[name] = value || true;
  497. return cumulated
  498. }, Object.create(null))
  499. };
  500. if (isSpecialTag(tag)) {
  501. checkAttrs(currentBlock, attrs);
  502. if (tag === 'style') {
  503. sfc.styles.push(currentBlock);
  504. } else {
  505. sfc[tag] = currentBlock;
  506. }
  507. } else { // custom blocks
  508. sfc.customBlocks.push(currentBlock);
  509. }
  510. }
  511. if (!unary) {
  512. depth++;
  513. }
  514. }
  515. function checkAttrs (block, attrs) {
  516. for (var i = 0; i < attrs.length; i++) {
  517. var attr = attrs[i];
  518. if (attr.name === 'lang') {
  519. block.lang = attr.value;
  520. }
  521. if (attr.name === 'scoped') {
  522. block.scoped = true;
  523. }
  524. if (attr.name === 'module') {
  525. block.module = attr.value || true;
  526. }
  527. if (attr.name === 'src') {
  528. block.src = attr.value;
  529. }
  530. }
  531. }
  532. function end (tag, start, end) {
  533. if (depth === 1 && currentBlock) {
  534. currentBlock.end = start;
  535. var text = deindent(content.slice(currentBlock.start, currentBlock.end));
  536. // pad content so that linters and pre-processors can output correct
  537. // line numbers in errors and warnings
  538. if (currentBlock.type !== 'template' && options.pad) {
  539. text = padContent(currentBlock, options.pad) + text;
  540. }
  541. currentBlock.content = text;
  542. currentBlock = null;
  543. }
  544. depth--;
  545. }
  546. function padContent (block, pad) {
  547. if (pad === 'space') {
  548. return content.slice(0, block.start).replace(replaceRE, ' ')
  549. } else {
  550. var offset = content.slice(0, block.start).split(splitRE).length;
  551. var padChar = block.type === 'script' && !block.lang
  552. ? '//\n'
  553. : '\n';
  554. return Array(offset).join(padChar)
  555. }
  556. }
  557. parseHTML(content, {
  558. start: start,
  559. end: end
  560. });
  561. return sfc
  562. }
  563. /* */
  564. var emptyObject = Object.freeze({});
  565. /**
  566. * Check if a string starts with $ or _
  567. */
  568. /**
  569. * Define a property.
  570. */
  571. function def (obj, key, val, enumerable) {
  572. Object.defineProperty(obj, key, {
  573. value: val,
  574. enumerable: !!enumerable,
  575. writable: true,
  576. configurable: true
  577. });
  578. }
  579. /* */
  580. // can we use __proto__?
  581. var hasProto = '__proto__' in {};
  582. // Browser environment sniffing
  583. var inBrowser = typeof window !== 'undefined';
  584. var UA = inBrowser && window.navigator.userAgent.toLowerCase();
  585. var isIE = UA && /msie|trident/.test(UA);
  586. var isIE9 = UA && UA.indexOf('msie 9.0') > 0;
  587. var isEdge = UA && UA.indexOf('edge/') > 0;
  588. var isAndroid = UA && UA.indexOf('android') > 0;
  589. var isIOS = UA && /iphone|ipad|ipod|ios/.test(UA);
  590. var isChrome = UA && /chrome\/\d+/.test(UA) && !isEdge;
  591. // Firefox has a "watch" function on Object.prototype...
  592. var nativeWatch = ({}).watch;
  593. if (inBrowser) {
  594. try {
  595. var opts = {};
  596. Object.defineProperty(opts, 'passive', ({
  597. get: function get () {
  598. /* istanbul ignore next */
  599. }
  600. })); // https://github.com/facebook/flow/issues/285
  601. window.addEventListener('test-passive', null, opts);
  602. } catch (e) {}
  603. }
  604. // this needs to be lazy-evaled because vue may be required before
  605. // vue-server-renderer can set VUE_ENV
  606. var _isServer;
  607. var isServerRendering = function () {
  608. if (_isServer === undefined) {
  609. /* istanbul ignore if */
  610. if (!inBrowser && typeof global !== 'undefined') {
  611. // detect presence of vue-server-renderer and avoid
  612. // Webpack shimming the process
  613. _isServer = global['process'].env.VUE_ENV === 'server';
  614. } else {
  615. _isServer = false;
  616. }
  617. }
  618. return _isServer
  619. };
  620. // detect devtools
  621. /* istanbul ignore next */
  622. function isNative (Ctor) {
  623. return typeof Ctor === 'function' && /native code/.test(Ctor.toString())
  624. }
  625. var hasSymbol =
  626. typeof Symbol !== 'undefined' && isNative(Symbol) &&
  627. typeof Reflect !== 'undefined' && isNative(Reflect.ownKeys);
  628. var _Set;
  629. /* istanbul ignore if */ // $flow-disable-line
  630. if (typeof Set !== 'undefined' && isNative(Set)) {
  631. // use native Set when available.
  632. _Set = Set;
  633. } else {
  634. // a non-standard Set polyfill that only works with primitive keys.
  635. _Set = (function () {
  636. function Set () {
  637. this.set = Object.create(null);
  638. }
  639. Set.prototype.has = function has (key) {
  640. return this.set[key] === true
  641. };
  642. Set.prototype.add = function add (key) {
  643. this.set[key] = true;
  644. };
  645. Set.prototype.clear = function clear () {
  646. this.set = Object.create(null);
  647. };
  648. return Set;
  649. }());
  650. }
  651. var ASSET_TYPES = [
  652. 'component',
  653. 'directive',
  654. 'filter'
  655. ];
  656. var LIFECYCLE_HOOKS = [
  657. 'beforeCreate',
  658. 'created',
  659. 'beforeMount',
  660. 'mounted',
  661. 'beforeUpdate',
  662. 'updated',
  663. 'beforeDestroy',
  664. 'destroyed',
  665. 'activated',
  666. 'deactivated',
  667. 'errorCaptured'
  668. ];
  669. /* */
  670. var config = ({
  671. /**
  672. * Option merge strategies (used in core/util/options)
  673. */
  674. optionMergeStrategies: Object.create(null),
  675. /**
  676. * Whether to suppress warnings.
  677. */
  678. silent: false,
  679. /**
  680. * Show production mode tip message on boot?
  681. */
  682. productionTip: process.env.NODE_ENV !== 'production',
  683. /**
  684. * Whether to enable devtools
  685. */
  686. devtools: process.env.NODE_ENV !== 'production',
  687. /**
  688. * Whether to record perf
  689. */
  690. performance: false,
  691. /**
  692. * Error handler for watcher errors
  693. */
  694. errorHandler: null,
  695. /**
  696. * Warn handler for watcher warns
  697. */
  698. warnHandler: null,
  699. /**
  700. * Ignore certain custom elements
  701. */
  702. ignoredElements: [],
  703. /**
  704. * Custom user key aliases for v-on
  705. */
  706. keyCodes: Object.create(null),
  707. /**
  708. * Check if a tag is reserved so that it cannot be registered as a
  709. * component. This is platform-dependent and may be overwritten.
  710. */
  711. isReservedTag: no,
  712. /**
  713. * Check if an attribute is reserved so that it cannot be used as a component
  714. * prop. This is platform-dependent and may be overwritten.
  715. */
  716. isReservedAttr: no,
  717. /**
  718. * Check if a tag is an unknown element.
  719. * Platform-dependent.
  720. */
  721. isUnknownElement: no,
  722. /**
  723. * Get the namespace of an element
  724. */
  725. getTagNamespace: noop,
  726. /**
  727. * Parse the real tag name for the specific platform.
  728. */
  729. parsePlatformTagName: identity,
  730. /**
  731. * Check if an attribute must be bound using property, e.g. value
  732. * Platform-dependent.
  733. */
  734. mustUseProp: no,
  735. /**
  736. * Exposed for legacy reasons
  737. */
  738. _lifecycleHooks: LIFECYCLE_HOOKS
  739. });
  740. /* */
  741. var warn = noop;
  742. var tip = noop;
  743. var generateComponentTrace = (noop); // work around flow check
  744. var formatComponentName = (noop);
  745. if (process.env.NODE_ENV !== 'production') {
  746. var hasConsole = typeof console !== 'undefined';
  747. var classifyRE = /(?:^|[-_])(\w)/g;
  748. var classify = function (str) { return str
  749. .replace(classifyRE, function (c) { return c.toUpperCase(); })
  750. .replace(/[-_]/g, ''); };
  751. warn = function (msg, vm) {
  752. var trace = vm ? generateComponentTrace(vm) : '';
  753. if (config.warnHandler) {
  754. config.warnHandler.call(null, msg, vm, trace);
  755. } else if (hasConsole && (!config.silent)) {
  756. console.error(("[Vue warn]: " + msg + trace));
  757. }
  758. };
  759. tip = function (msg, vm) {
  760. if (hasConsole && (!config.silent)) {
  761. console.warn("[Vue tip]: " + msg + (
  762. vm ? generateComponentTrace(vm) : ''
  763. ));
  764. }
  765. };
  766. formatComponentName = function (vm, includeFile) {
  767. if (vm.$root === vm) {
  768. return '<Root>'
  769. }
  770. var options = typeof vm === 'function' && vm.cid != null
  771. ? vm.options
  772. : vm._isVue
  773. ? vm.$options || vm.constructor.options
  774. : vm || {};
  775. var name = options.name || options._componentTag;
  776. var file = options.__file;
  777. if (!name && file) {
  778. var match = file.match(/([^/\\]+)\.vue$/);
  779. name = match && match[1];
  780. }
  781. return (
  782. (name ? ("<" + (classify(name)) + ">") : "<Anonymous>") +
  783. (file && includeFile !== false ? (" at " + file) : '')
  784. )
  785. };
  786. var repeat = function (str, n) {
  787. var res = '';
  788. while (n) {
  789. if (n % 2 === 1) { res += str; }
  790. if (n > 1) { str += str; }
  791. n >>= 1;
  792. }
  793. return res
  794. };
  795. generateComponentTrace = function (vm) {
  796. if (vm._isVue && vm.$parent) {
  797. var tree = [];
  798. var currentRecursiveSequence = 0;
  799. while (vm) {
  800. if (tree.length > 0) {
  801. var last = tree[tree.length - 1];
  802. if (last.constructor === vm.constructor) {
  803. currentRecursiveSequence++;
  804. vm = vm.$parent;
  805. continue
  806. } else if (currentRecursiveSequence > 0) {
  807. tree[tree.length - 1] = [last, currentRecursiveSequence];
  808. currentRecursiveSequence = 0;
  809. }
  810. }
  811. tree.push(vm);
  812. vm = vm.$parent;
  813. }
  814. return '\n\nfound in\n\n' + tree
  815. .map(function (vm, i) { return ("" + (i === 0 ? '---> ' : repeat(' ', 5 + i * 2)) + (Array.isArray(vm)
  816. ? ((formatComponentName(vm[0])) + "... (" + (vm[1]) + " recursive calls)")
  817. : formatComponentName(vm))); })
  818. .join('\n')
  819. } else {
  820. return ("\n\n(found in " + (formatComponentName(vm)) + ")")
  821. }
  822. };
  823. }
  824. /* */
  825. var uid = 0;
  826. /**
  827. * A dep is an observable that can have multiple
  828. * directives subscribing to it.
  829. */
  830. var Dep = function Dep () {
  831. this.id = uid++;
  832. this.subs = [];
  833. };
  834. Dep.prototype.addSub = function addSub (sub) {
  835. this.subs.push(sub);
  836. };
  837. Dep.prototype.removeSub = function removeSub (sub) {
  838. remove(this.subs, sub);
  839. };
  840. Dep.prototype.depend = function depend () {
  841. if (Dep.target) {
  842. Dep.target.addDep(this);
  843. }
  844. };
  845. Dep.prototype.notify = function notify () {
  846. // stabilize the subscriber list first
  847. var subs = this.subs.slice();
  848. for (var i = 0, l = subs.length; i < l; i++) {
  849. subs[i].update();
  850. }
  851. };
  852. // the current target watcher being evaluated.
  853. // this is globally unique because there could be only one
  854. // watcher being evaluated at any time.
  855. Dep.target = null;
  856. /* */
  857. var VNode = function VNode (
  858. tag,
  859. data,
  860. children,
  861. text,
  862. elm,
  863. context,
  864. componentOptions,
  865. asyncFactory
  866. ) {
  867. this.tag = tag;
  868. this.data = data;
  869. this.children = children;
  870. this.text = text;
  871. this.elm = elm;
  872. this.ns = undefined;
  873. this.context = context;
  874. this.functionalContext = undefined;
  875. this.functionalOptions = undefined;
  876. this.functionalScopeId = undefined;
  877. this.key = data && data.key;
  878. this.componentOptions = componentOptions;
  879. this.componentInstance = undefined;
  880. this.parent = undefined;
  881. this.raw = false;
  882. this.isStatic = false;
  883. this.isRootInsert = true;
  884. this.isComment = false;
  885. this.isCloned = false;
  886. this.isOnce = false;
  887. this.asyncFactory = asyncFactory;
  888. this.asyncMeta = undefined;
  889. this.isAsyncPlaceholder = false;
  890. };
  891. var prototypeAccessors = { child: { configurable: true } };
  892. // DEPRECATED: alias for componentInstance for backwards compat.
  893. /* istanbul ignore next */
  894. prototypeAccessors.child.get = function () {
  895. return this.componentInstance
  896. };
  897. Object.defineProperties( VNode.prototype, prototypeAccessors );
  898. // optimized shallow clone
  899. // used for static nodes and slot nodes because they may be reused across
  900. // multiple renders, cloning them avoids errors when DOM manipulations rely
  901. // on their elm reference.
  902. /*
  903. * not type checking this file because flow doesn't play well with
  904. * dynamically accessing methods on Array prototype
  905. */
  906. var arrayProto = Array.prototype;
  907. var arrayMethods = Object.create(arrayProto);[
  908. 'push',
  909. 'pop',
  910. 'shift',
  911. 'unshift',
  912. 'splice',
  913. 'sort',
  914. 'reverse'
  915. ]
  916. .forEach(function (method) {
  917. // cache original method
  918. var original = arrayProto[method];
  919. def(arrayMethods, method, function mutator () {
  920. var args = [], len = arguments.length;
  921. while ( len-- ) args[ len ] = arguments[ len ];
  922. var result = original.apply(this, args);
  923. var ob = this.__ob__;
  924. var inserted;
  925. switch (method) {
  926. case 'push':
  927. case 'unshift':
  928. inserted = args;
  929. break
  930. case 'splice':
  931. inserted = args.slice(2);
  932. break
  933. }
  934. if (inserted) { ob.observeArray(inserted); }
  935. // notify change
  936. ob.dep.notify();
  937. return result
  938. });
  939. });
  940. /* */
  941. var arrayKeys = Object.getOwnPropertyNames(arrayMethods);
  942. /**
  943. * By default, when a reactive property is set, the new value is
  944. * also converted to become reactive. However when passing down props,
  945. * we don't want to force conversion because the value may be a nested value
  946. * under a frozen data structure. Converting it would defeat the optimization.
  947. */
  948. var observerState = {
  949. shouldConvert: true
  950. };
  951. /**
  952. * Observer class that are attached to each observed
  953. * object. Once attached, the observer converts target
  954. * object's property keys into getter/setters that
  955. * collect dependencies and dispatches updates.
  956. */
  957. var Observer = function Observer (value) {
  958. this.value = value;
  959. this.dep = new Dep();
  960. this.vmCount = 0;
  961. def(value, '__ob__', this);
  962. if (Array.isArray(value)) {
  963. var augment = hasProto
  964. ? protoAugment
  965. : copyAugment;
  966. augment(value, arrayMethods, arrayKeys);
  967. this.observeArray(value);
  968. } else {
  969. this.walk(value);
  970. }
  971. };
  972. /**
  973. * Walk through each property and convert them into
  974. * getter/setters. This method should only be called when
  975. * value type is Object.
  976. */
  977. Observer.prototype.walk = function walk (obj) {
  978. var keys = Object.keys(obj);
  979. for (var i = 0; i < keys.length; i++) {
  980. defineReactive(obj, keys[i], obj[keys[i]]);
  981. }
  982. };
  983. /**
  984. * Observe a list of Array items.
  985. */
  986. Observer.prototype.observeArray = function observeArray (items) {
  987. for (var i = 0, l = items.length; i < l; i++) {
  988. observe(items[i]);
  989. }
  990. };
  991. // helpers
  992. /**
  993. * Augment an target Object or Array by intercepting
  994. * the prototype chain using __proto__
  995. */
  996. function protoAugment (target, src, keys) {
  997. /* eslint-disable no-proto */
  998. target.__proto__ = src;
  999. /* eslint-enable no-proto */
  1000. }
  1001. /**
  1002. * Augment an target Object or Array by defining
  1003. * hidden properties.
  1004. */
  1005. /* istanbul ignore next */
  1006. function copyAugment (target, src, keys) {
  1007. for (var i = 0, l = keys.length; i < l; i++) {
  1008. var key = keys[i];
  1009. def(target, key, src[key]);
  1010. }
  1011. }
  1012. /**
  1013. * Attempt to create an observer instance for a value,
  1014. * returns the new observer if successfully observed,
  1015. * or the existing observer if the value already has one.
  1016. */
  1017. function observe (value, asRootData) {
  1018. if (!isObject(value) || value instanceof VNode) {
  1019. return
  1020. }
  1021. var ob;
  1022. if (hasOwn(value, '__ob__') && value.__ob__ instanceof Observer) {
  1023. ob = value.__ob__;
  1024. } else if (
  1025. observerState.shouldConvert &&
  1026. !isServerRendering() &&
  1027. (Array.isArray(value) || isPlainObject(value)) &&
  1028. Object.isExtensible(value) &&
  1029. !value._isVue
  1030. ) {
  1031. ob = new Observer(value);
  1032. }
  1033. if (asRootData && ob) {
  1034. ob.vmCount++;
  1035. }
  1036. return ob
  1037. }
  1038. /**
  1039. * Define a reactive property on an Object.
  1040. */
  1041. function defineReactive (
  1042. obj,
  1043. key,
  1044. val,
  1045. customSetter,
  1046. shallow
  1047. ) {
  1048. var dep = new Dep();
  1049. var property = Object.getOwnPropertyDescriptor(obj, key);
  1050. if (property && property.configurable === false) {
  1051. return
  1052. }
  1053. // cater for pre-defined getter/setters
  1054. var getter = property && property.get;
  1055. var setter = property && property.set;
  1056. var childOb = !shallow && observe(val);
  1057. Object.defineProperty(obj, key, {
  1058. enumerable: true,
  1059. configurable: true,
  1060. get: function reactiveGetter () {
  1061. var value = getter ? getter.call(obj) : val;
  1062. if (Dep.target) {
  1063. dep.depend();
  1064. if (childOb) {
  1065. childOb.dep.depend();
  1066. if (Array.isArray(value)) {
  1067. dependArray(value);
  1068. }
  1069. }
  1070. }
  1071. return value
  1072. },
  1073. set: function reactiveSetter (newVal) {
  1074. var value = getter ? getter.call(obj) : val;
  1075. /* eslint-disable no-self-compare */
  1076. if (newVal === value || (newVal !== newVal && value !== value)) {
  1077. return
  1078. }
  1079. /* eslint-enable no-self-compare */
  1080. if (process.env.NODE_ENV !== 'production' && customSetter) {
  1081. customSetter();
  1082. }
  1083. if (setter) {
  1084. setter.call(obj, newVal);
  1085. } else {
  1086. val = newVal;
  1087. }
  1088. childOb = !shallow && observe(newVal);
  1089. dep.notify();
  1090. }
  1091. });
  1092. }
  1093. /**
  1094. * Set a property on an object. Adds the new property and
  1095. * triggers change notification if the property doesn't
  1096. * already exist.
  1097. */
  1098. function set (target, key, val) {
  1099. if (Array.isArray(target) && isValidArrayIndex(key)) {
  1100. target.length = Math.max(target.length, key);
  1101. target.splice(key, 1, val);
  1102. return val
  1103. }
  1104. if (key in target && !(key in Object.prototype)) {
  1105. target[key] = val;
  1106. return val
  1107. }
  1108. var ob = (target).__ob__;
  1109. if (target._isVue || (ob && ob.vmCount)) {
  1110. process.env.NODE_ENV !== 'production' && warn(
  1111. 'Avoid adding reactive properties to a Vue instance or its root $data ' +
  1112. 'at runtime - declare it upfront in the data option.'
  1113. );
  1114. return val
  1115. }
  1116. if (!ob) {
  1117. target[key] = val;
  1118. return val
  1119. }
  1120. defineReactive(ob.value, key, val);
  1121. ob.dep.notify();
  1122. return val
  1123. }
  1124. /**
  1125. * Delete a property and trigger change if necessary.
  1126. */
  1127. /**
  1128. * Collect dependencies on array elements when the array is touched, since
  1129. * we cannot intercept array element access like property getters.
  1130. */
  1131. function dependArray (value) {
  1132. for (var e = (void 0), i = 0, l = value.length; i < l; i++) {
  1133. e = value[i];
  1134. e && e.__ob__ && e.__ob__.dep.depend();
  1135. if (Array.isArray(e)) {
  1136. dependArray(e);
  1137. }
  1138. }
  1139. }
  1140. /* */
  1141. /**
  1142. * Option overwriting strategies are functions that handle
  1143. * how to merge a parent option value and a child option
  1144. * value into the final value.
  1145. */
  1146. var strats = config.optionMergeStrategies;
  1147. /**
  1148. * Options with restrictions
  1149. */
  1150. if (process.env.NODE_ENV !== 'production') {
  1151. strats.el = strats.propsData = function (parent, child, vm, key) {
  1152. if (!vm) {
  1153. warn(
  1154. "option \"" + key + "\" can only be used during instance " +
  1155. 'creation with the `new` keyword.'
  1156. );
  1157. }
  1158. return defaultStrat(parent, child)
  1159. };
  1160. }
  1161. /**
  1162. * Helper that recursively merges two data objects together.
  1163. */
  1164. function mergeData (to, from) {
  1165. if (!from) { return to }
  1166. var key, toVal, fromVal;
  1167. var keys = Object.keys(from);
  1168. for (var i = 0; i < keys.length; i++) {
  1169. key = keys[i];
  1170. toVal = to[key];
  1171. fromVal = from[key];
  1172. if (!hasOwn(to, key)) {
  1173. set(to, key, fromVal);
  1174. } else if (isPlainObject(toVal) && isPlainObject(fromVal)) {
  1175. mergeData(toVal, fromVal);
  1176. }
  1177. }
  1178. return to
  1179. }
  1180. /**
  1181. * Data
  1182. */
  1183. function mergeDataOrFn (
  1184. parentVal,
  1185. childVal,
  1186. vm
  1187. ) {
  1188. if (!vm) {
  1189. // in a Vue.extend merge, both should be functions
  1190. if (!childVal) {
  1191. return parentVal
  1192. }
  1193. if (!parentVal) {
  1194. return childVal
  1195. }
  1196. // when parentVal & childVal are both present,
  1197. // we need to return a function that returns the
  1198. // merged result of both functions... no need to
  1199. // check if parentVal is a function here because
  1200. // it has to be a function to pass previous merges.
  1201. return function mergedDataFn () {
  1202. return mergeData(
  1203. typeof childVal === 'function' ? childVal.call(this) : childVal,
  1204. typeof parentVal === 'function' ? parentVal.call(this) : parentVal
  1205. )
  1206. }
  1207. } else {
  1208. return function mergedInstanceDataFn () {
  1209. // instance merge
  1210. var instanceData = typeof childVal === 'function'
  1211. ? childVal.call(vm)
  1212. : childVal;
  1213. var defaultData = typeof parentVal === 'function'
  1214. ? parentVal.call(vm)
  1215. : parentVal;
  1216. if (instanceData) {
  1217. return mergeData(instanceData, defaultData)
  1218. } else {
  1219. return defaultData
  1220. }
  1221. }
  1222. }
  1223. }
  1224. strats.data = function (
  1225. parentVal,
  1226. childVal,
  1227. vm
  1228. ) {
  1229. if (!vm) {
  1230. if (childVal && typeof childVal !== 'function') {
  1231. process.env.NODE_ENV !== 'production' && warn(
  1232. 'The "data" option should be a function ' +
  1233. 'that returns a per-instance value in component ' +
  1234. 'definitions.',
  1235. vm
  1236. );
  1237. return parentVal
  1238. }
  1239. return mergeDataOrFn(parentVal, childVal)
  1240. }
  1241. return mergeDataOrFn(parentVal, childVal, vm)
  1242. };
  1243. /**
  1244. * Hooks and props are merged as arrays.
  1245. */
  1246. function mergeHook (
  1247. parentVal,
  1248. childVal
  1249. ) {
  1250. return childVal
  1251. ? parentVal
  1252. ? parentVal.concat(childVal)
  1253. : Array.isArray(childVal)
  1254. ? childVal
  1255. : [childVal]
  1256. : parentVal
  1257. }
  1258. LIFECYCLE_HOOKS.forEach(function (hook) {
  1259. strats[hook] = mergeHook;
  1260. });
  1261. /**
  1262. * Assets
  1263. *
  1264. * When a vm is present (instance creation), we need to do
  1265. * a three-way merge between constructor options, instance
  1266. * options and parent options.
  1267. */
  1268. function mergeAssets (
  1269. parentVal,
  1270. childVal,
  1271. vm,
  1272. key
  1273. ) {
  1274. var res = Object.create(parentVal || null);
  1275. if (childVal) {
  1276. process.env.NODE_ENV !== 'production' && assertObjectType(key, childVal, vm);
  1277. return extend(res, childVal)
  1278. } else {
  1279. return res
  1280. }
  1281. }
  1282. ASSET_TYPES.forEach(function (type) {
  1283. strats[type + 's'] = mergeAssets;
  1284. });
  1285. /**
  1286. * Watchers.
  1287. *
  1288. * Watchers hashes should not overwrite one
  1289. * another, so we merge them as arrays.
  1290. */
  1291. strats.watch = function (
  1292. parentVal,
  1293. childVal,
  1294. vm,
  1295. key
  1296. ) {
  1297. // work around Firefox's Object.prototype.watch...
  1298. if (parentVal === nativeWatch) { parentVal = undefined; }
  1299. if (childVal === nativeWatch) { childVal = undefined; }
  1300. /* istanbul ignore if */
  1301. if (!childVal) { return Object.create(parentVal || null) }
  1302. if (process.env.NODE_ENV !== 'production') {
  1303. assertObjectType(key, childVal, vm);
  1304. }
  1305. if (!parentVal) { return childVal }
  1306. var ret = {};
  1307. extend(ret, parentVal);
  1308. for (var key$1 in childVal) {
  1309. var parent = ret[key$1];
  1310. var child = childVal[key$1];
  1311. if (parent && !Array.isArray(parent)) {
  1312. parent = [parent];
  1313. }
  1314. ret[key$1] = parent
  1315. ? parent.concat(child)
  1316. : Array.isArray(child) ? child : [child];
  1317. }
  1318. return ret
  1319. };
  1320. /**
  1321. * Other object hashes.
  1322. */
  1323. strats.props =
  1324. strats.methods =
  1325. strats.inject =
  1326. strats.computed = function (
  1327. parentVal,
  1328. childVal,
  1329. vm,
  1330. key
  1331. ) {
  1332. if (childVal && process.env.NODE_ENV !== 'production') {
  1333. assertObjectType(key, childVal, vm);
  1334. }
  1335. if (!parentVal) { return childVal }
  1336. var ret = Object.create(null);
  1337. extend(ret, parentVal);
  1338. if (childVal) { extend(ret, childVal); }
  1339. return ret
  1340. };
  1341. strats.provide = mergeDataOrFn;
  1342. /**
  1343. * Default strategy.
  1344. */
  1345. var defaultStrat = function (parentVal, childVal) {
  1346. return childVal === undefined
  1347. ? parentVal
  1348. : childVal
  1349. };
  1350. function assertObjectType (name, value, vm) {
  1351. if (!isPlainObject(value)) {
  1352. warn(
  1353. "Invalid value for option \"" + name + "\": expected an Object, " +
  1354. "but got " + (toRawType(value)) + ".",
  1355. vm
  1356. );
  1357. }
  1358. }
  1359. /**
  1360. * Merge two option objects into a new one.
  1361. * Core utility used in both instantiation and inheritance.
  1362. */
  1363. /**
  1364. * Resolve an asset.
  1365. * This function is used because child instances need access
  1366. * to assets defined in its ancestor chain.
  1367. */
  1368. /* */
  1369. /* */
  1370. /* */
  1371. /* globals MessageChannel */
  1372. var callbacks = [];
  1373. function flushCallbacks () {
  1374. var copies = callbacks.slice(0);
  1375. callbacks.length = 0;
  1376. for (var i = 0; i < copies.length; i++) {
  1377. copies[i]();
  1378. }
  1379. }
  1380. // Determine (macro) Task defer implementation.
  1381. // Technically setImmediate should be the ideal choice, but it's only available
  1382. // in IE. The only polyfill that consistently queues the callback after all DOM
  1383. // events triggered in the same loop is by using MessageChannel.
  1384. /* istanbul ignore if */
  1385. if (typeof setImmediate !== 'undefined' && isNative(setImmediate)) {
  1386. } else if (typeof MessageChannel !== 'undefined' && (
  1387. isNative(MessageChannel) ||
  1388. // PhantomJS
  1389. MessageChannel.toString() === '[object MessageChannelConstructor]'
  1390. )) {
  1391. var channel = new MessageChannel();
  1392. channel.port1.onmessage = flushCallbacks;
  1393. } else {
  1394. /* istanbul ignore next */
  1395. }
  1396. // Determine MicroTask defer implementation.
  1397. /* istanbul ignore next, $flow-disable-line */
  1398. if (typeof Promise !== 'undefined' && isNative(Promise)) {
  1399. } else {
  1400. // fallback to macro
  1401. }
  1402. /**
  1403. * Wrap a function so that if any code inside triggers state change,
  1404. * the changes are queued using a Task instead of a MicroTask.
  1405. */
  1406. /* */
  1407. /* */
  1408. // these are reserved for web because they are directly compiled away
  1409. // during template compilation
  1410. var isReservedAttr = makeMap('style,class');
  1411. // attributes that should be using props for binding
  1412. var acceptValue = makeMap('input,textarea,option,select,progress');
  1413. var mustUseProp = function (tag, type, attr) {
  1414. return (
  1415. (attr === 'value' && acceptValue(tag)) && type !== 'button' ||
  1416. (attr === 'selected' && tag === 'option') ||
  1417. (attr === 'checked' && tag === 'input') ||
  1418. (attr === 'muted' && tag === 'video')
  1419. )
  1420. };
  1421. var isEnumeratedAttr = makeMap('contenteditable,draggable,spellcheck');
  1422. var isBooleanAttr = makeMap(
  1423. 'allowfullscreen,async,autofocus,autoplay,checked,compact,controls,declare,' +
  1424. 'default,defaultchecked,defaultmuted,defaultselected,defer,disabled,' +
  1425. 'enabled,formnovalidate,hidden,indeterminate,inert,ismap,itemscope,loop,multiple,' +
  1426. 'muted,nohref,noresize,noshade,novalidate,nowrap,open,pauseonexit,readonly,' +
  1427. 'required,reversed,scoped,seamless,selected,sortable,translate,' +
  1428. 'truespeed,typemustmatch,visible'
  1429. );
  1430. /* */
  1431. /* */
  1432. var isHTMLTag = makeMap(
  1433. 'html,body,base,head,link,meta,style,title,' +
  1434. 'address,article,aside,footer,header,h1,h2,h3,h4,h5,h6,hgroup,nav,section,' +
  1435. 'div,dd,dl,dt,figcaption,figure,picture,hr,img,li,main,ol,p,pre,ul,' +
  1436. 'a,b,abbr,bdi,bdo,br,cite,code,data,dfn,em,i,kbd,mark,q,rp,rt,rtc,ruby,' +
  1437. 's,samp,small,span,strong,sub,sup,time,u,var,wbr,area,audio,map,track,video,' +
  1438. 'embed,object,param,source,canvas,script,noscript,del,ins,' +
  1439. 'caption,col,colgroup,table,thead,tbody,td,th,tr,' +
  1440. 'button,datalist,fieldset,form,input,label,legend,meter,optgroup,option,' +
  1441. 'output,progress,select,textarea,' +
  1442. 'details,dialog,menu,menuitem,summary,' +
  1443. 'content,element,shadow,template,blockquote,iframe,tfoot'
  1444. );
  1445. // this map is intentionally selective, only covering SVG elements that may
  1446. // contain child elements.
  1447. var isSVG = makeMap(
  1448. 'svg,animate,circle,clippath,cursor,defs,desc,ellipse,filter,font-face,' +
  1449. 'foreignObject,g,glyph,image,line,marker,mask,missing-glyph,path,pattern,' +
  1450. 'polygon,polyline,rect,switch,symbol,text,textpath,tspan,use,view',
  1451. true
  1452. );
  1453. var isPreTag = function (tag) { return tag === 'pre'; };
  1454. var isReservedTag = function (tag) {
  1455. return isHTMLTag(tag) || isSVG(tag)
  1456. };
  1457. function getTagNamespace (tag) {
  1458. if (isSVG(tag)) {
  1459. return 'svg'
  1460. }
  1461. // basic support for MathML
  1462. // note it doesn't support other MathML elements being component roots
  1463. if (tag === 'math') {
  1464. return 'math'
  1465. }
  1466. }
  1467. var isTextInputType = makeMap('text,number,password,search,email,tel,url');
  1468. /* */
  1469. /**
  1470. * Query an element selector if it's not an element already.
  1471. */
  1472. /* */
  1473. var validDivisionCharRE = /[\w).+\-_$\]]/;
  1474. function parseFilters (exp) {
  1475. var inSingle = false;
  1476. var inDouble = false;
  1477. var inTemplateString = false;
  1478. var inRegex = false;
  1479. var curly = 0;
  1480. var square = 0;
  1481. var paren = 0;
  1482. var lastFilterIndex = 0;
  1483. var c, prev, i, expression, filters;
  1484. for (i = 0; i < exp.length; i++) {
  1485. prev = c;
  1486. c = exp.charCodeAt(i);
  1487. if (inSingle) {
  1488. if (c === 0x27 && prev !== 0x5C) { inSingle = false; }
  1489. } else if (inDouble) {
  1490. if (c === 0x22 && prev !== 0x5C) { inDouble = false; }
  1491. } else if (inTemplateString) {
  1492. if (c === 0x60 && prev !== 0x5C) { inTemplateString = false; }
  1493. } else if (inRegex) {
  1494. if (c === 0x2f && prev !== 0x5C) { inRegex = false; }
  1495. } else if (
  1496. c === 0x7C && // pipe
  1497. exp.charCodeAt(i + 1) !== 0x7C &&
  1498. exp.charCodeAt(i - 1) !== 0x7C &&
  1499. !curly && !square && !paren
  1500. ) {
  1501. if (expression === undefined) {
  1502. // first filter, end of expression
  1503. lastFilterIndex = i + 1;
  1504. expression = exp.slice(0, i).trim();
  1505. } else {
  1506. pushFilter();
  1507. }
  1508. } else {
  1509. switch (c) {
  1510. case 0x22: inDouble = true; break // "
  1511. case 0x27: inSingle = true; break // '
  1512. case 0x60: inTemplateString = true; break // `
  1513. case 0x28: paren++; break // (
  1514. case 0x29: paren--; break // )
  1515. case 0x5B: square++; break // [
  1516. case 0x5D: square--; break // ]
  1517. case 0x7B: curly++; break // {
  1518. case 0x7D: curly--; break // }
  1519. }
  1520. if (c === 0x2f) { // /
  1521. var j = i - 1;
  1522. var p = (void 0);
  1523. // find first non-whitespace prev char
  1524. for (; j >= 0; j--) {
  1525. p = exp.charAt(j);
  1526. if (p !== ' ') { break }
  1527. }
  1528. if (!p || !validDivisionCharRE.test(p)) {
  1529. inRegex = true;
  1530. }
  1531. }
  1532. }
  1533. }
  1534. if (expression === undefined) {
  1535. expression = exp.slice(0, i).trim();
  1536. } else if (lastFilterIndex !== 0) {
  1537. pushFilter();
  1538. }
  1539. function pushFilter () {
  1540. (filters || (filters = [])).push(exp.slice(lastFilterIndex, i).trim());
  1541. lastFilterIndex = i + 1;
  1542. }
  1543. if (filters) {
  1544. for (i = 0; i < filters.length; i++) {
  1545. expression = wrapFilter(expression, filters[i]);
  1546. }
  1547. }
  1548. return expression
  1549. }
  1550. function wrapFilter (exp, filter) {
  1551. var i = filter.indexOf('(');
  1552. if (i < 0) {
  1553. // _f: resolveFilter
  1554. return ("_f(\"" + filter + "\")(" + exp + ")")
  1555. } else {
  1556. var name = filter.slice(0, i);
  1557. var args = filter.slice(i + 1);
  1558. return ("_f(\"" + name + "\")(" + exp + "," + args)
  1559. }
  1560. }
  1561. /* */
  1562. var defaultTagRE = /\{\{((?:.|\n)+?)\}\}/g;
  1563. var regexEscapeRE = /[-.*+?^${}()|[\]\/\\]/g;
  1564. var buildRegex = cached(function (delimiters) {
  1565. var open = delimiters[0].replace(regexEscapeRE, '\\$&');
  1566. var close = delimiters[1].replace(regexEscapeRE, '\\$&');
  1567. return new RegExp(open + '((?:.|\\n)+?)' + close, 'g')
  1568. });
  1569. function parseText (
  1570. text,
  1571. delimiters
  1572. ) {
  1573. var tagRE = delimiters ? buildRegex(delimiters) : defaultTagRE;
  1574. if (!tagRE.test(text)) {
  1575. return
  1576. }
  1577. var tokens = [];
  1578. var lastIndex = tagRE.lastIndex = 0;
  1579. var match, index;
  1580. while ((match = tagRE.exec(text))) {
  1581. index = match.index;
  1582. // push text token
  1583. if (index > lastIndex) {
  1584. tokens.push(JSON.stringify(text.slice(lastIndex, index)));
  1585. }
  1586. // tag token
  1587. var exp = parseFilters(match[1].trim());
  1588. tokens.push(("_s(" + exp + ")"));
  1589. lastIndex = index + match[0].length;
  1590. }
  1591. if (lastIndex < text.length) {
  1592. tokens.push(JSON.stringify(text.slice(lastIndex)));
  1593. }
  1594. return tokens.join('+')
  1595. }
  1596. /* */
  1597. function baseWarn (msg) {
  1598. console.error(("[Vue compiler]: " + msg));
  1599. }
  1600. function pluckModuleFunction (
  1601. modules,
  1602. key
  1603. ) {
  1604. return modules
  1605. ? modules.map(function (m) { return m[key]; }).filter(function (_) { return _; })
  1606. : []
  1607. }
  1608. function addProp (el, name, value) {
  1609. (el.props || (el.props = [])).push({ name: name, value: value });
  1610. }
  1611. function addAttr (el, name, value) {
  1612. (el.attrs || (el.attrs = [])).push({ name: name, value: value });
  1613. }
  1614. function addDirective (
  1615. el,
  1616. name,
  1617. rawName,
  1618. value,
  1619. arg,
  1620. modifiers
  1621. ) {
  1622. (el.directives || (el.directives = [])).push({ name: name, rawName: rawName, value: value, arg: arg, modifiers: modifiers });
  1623. }
  1624. function addHandler (
  1625. el,
  1626. name,
  1627. value,
  1628. modifiers,
  1629. important,
  1630. warn
  1631. ) {
  1632. // warn prevent and passive modifier
  1633. /* istanbul ignore if */
  1634. if (
  1635. process.env.NODE_ENV !== 'production' && warn &&
  1636. modifiers && modifiers.prevent && modifiers.passive
  1637. ) {
  1638. warn(
  1639. 'passive and prevent can\'t be used together. ' +
  1640. 'Passive handler can\'t prevent default event.'
  1641. );
  1642. }
  1643. // check capture modifier
  1644. if (modifiers && modifiers.capture) {
  1645. delete modifiers.capture;
  1646. name = '!' + name; // mark the event as captured
  1647. }
  1648. if (modifiers && modifiers.once) {
  1649. delete modifiers.once;
  1650. name = '~' + name; // mark the event as once
  1651. }
  1652. /* istanbul ignore if */
  1653. if (modifiers && modifiers.passive) {
  1654. delete modifiers.passive;
  1655. name = '&' + name; // mark the event as passive
  1656. }
  1657. var events;
  1658. if (modifiers && modifiers.native) {
  1659. delete modifiers.native;
  1660. events = el.nativeEvents || (el.nativeEvents = {});
  1661. } else {
  1662. events = el.events || (el.events = {});
  1663. }
  1664. var newHandler = { value: value, modifiers: modifiers };
  1665. var handlers = events[name];
  1666. /* istanbul ignore if */
  1667. if (Array.isArray(handlers)) {
  1668. important ? handlers.unshift(newHandler) : handlers.push(newHandler);
  1669. } else if (handlers) {
  1670. events[name] = important ? [newHandler, handlers] : [handlers, newHandler];
  1671. } else {
  1672. events[name] = newHandler;
  1673. }
  1674. }
  1675. function getBindingAttr (
  1676. el,
  1677. name,
  1678. getStatic
  1679. ) {
  1680. var dynamicValue =
  1681. getAndRemoveAttr(el, ':' + name) ||
  1682. getAndRemoveAttr(el, 'v-bind:' + name);
  1683. if (dynamicValue != null) {
  1684. return parseFilters(dynamicValue)
  1685. } else if (getStatic !== false) {
  1686. var staticValue = getAndRemoveAttr(el, name);
  1687. if (staticValue != null) {
  1688. return JSON.stringify(staticValue)
  1689. }
  1690. }
  1691. }
  1692. // note: this only removes the attr from the Array (attrsList) so that it
  1693. // doesn't get processed by processAttrs.
  1694. // By default it does NOT remove it from the map (attrsMap) because the map is
  1695. // needed during codegen.
  1696. function getAndRemoveAttr (
  1697. el,
  1698. name,
  1699. removeFromMap
  1700. ) {
  1701. var val;
  1702. if ((val = el.attrsMap[name]) != null) {
  1703. var list = el.attrsList;
  1704. for (var i = 0, l = list.length; i < l; i++) {
  1705. if (list[i].name === name) {
  1706. list.splice(i, 1);
  1707. break
  1708. }
  1709. }
  1710. }
  1711. if (removeFromMap) {
  1712. delete el.attrsMap[name];
  1713. }
  1714. return val
  1715. }
  1716. /* */
  1717. function transformNode (el, options) {
  1718. var warn = options.warn || baseWarn;
  1719. var staticClass = getAndRemoveAttr(el, 'class');
  1720. if (process.env.NODE_ENV !== 'production' && staticClass) {
  1721. var expression = parseText(staticClass, options.delimiters);
  1722. if (expression) {
  1723. warn(
  1724. "class=\"" + staticClass + "\": " +
  1725. 'Interpolation inside attributes has been removed. ' +
  1726. 'Use v-bind or the colon shorthand instead. For example, ' +
  1727. 'instead of <div class="{{ val }}">, use <div :class="val">.'
  1728. );
  1729. }
  1730. }
  1731. if (staticClass) {
  1732. el.staticClass = JSON.stringify(staticClass);
  1733. }
  1734. var classBinding = getBindingAttr(el, 'class', false /* getStatic */);
  1735. if (classBinding) {
  1736. el.classBinding = classBinding;
  1737. }
  1738. }
  1739. function genData (el) {
  1740. var data = '';
  1741. if (el.staticClass) {
  1742. data += "staticClass:" + (el.staticClass) + ",";
  1743. }
  1744. if (el.classBinding) {
  1745. data += "class:" + (el.classBinding) + ",";
  1746. }
  1747. return data
  1748. }
  1749. var klass = {
  1750. staticKeys: ['staticClass'],
  1751. transformNode: transformNode,
  1752. genData: genData
  1753. };
  1754. /* */
  1755. var parseStyleText = cached(function (cssText) {
  1756. var res = {};
  1757. var listDelimiter = /;(?![^(]*\))/g;
  1758. var propertyDelimiter = /:(.+)/;
  1759. cssText.split(listDelimiter).forEach(function (item) {
  1760. if (item) {
  1761. var tmp = item.split(propertyDelimiter);
  1762. tmp.length > 1 && (res[tmp[0].trim()] = tmp[1].trim());
  1763. }
  1764. });
  1765. return res
  1766. });
  1767. // normalize possible array / string values into Object
  1768. /**
  1769. * parent component style should be after child's
  1770. * so that parent component's style could override it
  1771. */
  1772. /* */
  1773. function transformNode$1 (el, options) {
  1774. var warn = options.warn || baseWarn;
  1775. var staticStyle = getAndRemoveAttr(el, 'style');
  1776. if (staticStyle) {
  1777. /* istanbul ignore if */
  1778. if (process.env.NODE_ENV !== 'production') {
  1779. var expression = parseText(staticStyle, options.delimiters);
  1780. if (expression) {
  1781. warn(
  1782. "style=\"" + staticStyle + "\": " +
  1783. 'Interpolation inside attributes has been removed. ' +
  1784. 'Use v-bind or the colon shorthand instead. For example, ' +
  1785. 'instead of <div style="{{ val }}">, use <div :style="val">.'
  1786. );
  1787. }
  1788. }
  1789. el.staticStyle = JSON.stringify(parseStyleText(staticStyle));
  1790. }
  1791. var styleBinding = getBindingAttr(el, 'style', false /* getStatic */);
  1792. if (styleBinding) {
  1793. el.styleBinding = styleBinding;
  1794. }
  1795. }
  1796. function genData$1 (el) {
  1797. var data = '';
  1798. if (el.staticStyle) {
  1799. data += "staticStyle:" + (el.staticStyle) + ",";
  1800. }
  1801. if (el.styleBinding) {
  1802. data += "style:(" + (el.styleBinding) + "),";
  1803. }
  1804. return data
  1805. }
  1806. var style = {
  1807. staticKeys: ['staticStyle'],
  1808. transformNode: transformNode$1,
  1809. genData: genData$1
  1810. };
  1811. /* */
  1812. /**
  1813. * Cross-platform code generation for component v-model
  1814. */
  1815. function genComponentModel (
  1816. el,
  1817. value,
  1818. modifiers
  1819. ) {
  1820. var ref = modifiers || {};
  1821. var number = ref.number;
  1822. var trim = ref.trim;
  1823. var baseValueExpression = '$$v';
  1824. var valueExpression = baseValueExpression;
  1825. if (trim) {
  1826. valueExpression =
  1827. "(typeof " + baseValueExpression + " === 'string'" +
  1828. "? " + baseValueExpression + ".trim()" +
  1829. ": " + baseValueExpression + ")";
  1830. }
  1831. if (number) {
  1832. valueExpression = "_n(" + valueExpression + ")";
  1833. }
  1834. var assignment = genAssignmentCode(value, valueExpression);
  1835. el.model = {
  1836. value: ("(" + value + ")"),
  1837. expression: ("\"" + value + "\""),
  1838. callback: ("function (" + baseValueExpression + ") {" + assignment + "}")
  1839. };
  1840. }
  1841. /**
  1842. * Cross-platform codegen helper for generating v-model value assignment code.
  1843. */
  1844. function genAssignmentCode (
  1845. value,
  1846. assignment
  1847. ) {
  1848. var res = parseModel(value);
  1849. if (res.key === null) {
  1850. return (value + "=" + assignment)
  1851. } else {
  1852. return ("$set(" + (res.exp) + ", " + (res.key) + ", " + assignment + ")")
  1853. }
  1854. }
  1855. /**
  1856. * Parse a v-model expression into a base path and a final key segment.
  1857. * Handles both dot-path and possible square brackets.
  1858. *
  1859. * Possible cases:
  1860. *
  1861. * - test
  1862. * - test[key]
  1863. * - test[test1[key]]
  1864. * - test["a"][key]
  1865. * - xxx.test[a[a].test1[key]]
  1866. * - test.xxx.a["asa"][test1[key]]
  1867. *
  1868. */
  1869. var len;
  1870. var str;
  1871. var chr;
  1872. var index;
  1873. var expressionPos;
  1874. var expressionEndPos;
  1875. function parseModel (val) {
  1876. len = val.length;
  1877. if (val.indexOf('[') < 0 || val.lastIndexOf(']') < len - 1) {
  1878. index = val.lastIndexOf('.');
  1879. if (index > -1) {
  1880. return {
  1881. exp: val.slice(0, index),
  1882. key: '"' + val.slice(index + 1) + '"'
  1883. }
  1884. } else {
  1885. return {
  1886. exp: val,
  1887. key: null
  1888. }
  1889. }
  1890. }
  1891. str = val;
  1892. index = expressionPos = expressionEndPos = 0;
  1893. while (!eof()) {
  1894. chr = next();
  1895. /* istanbul ignore if */
  1896. if (isStringStart(chr)) {
  1897. parseString(chr);
  1898. } else if (chr === 0x5B) {
  1899. parseBracket(chr);
  1900. }
  1901. }
  1902. return {
  1903. exp: val.slice(0, expressionPos),
  1904. key: val.slice(expressionPos + 1, expressionEndPos)
  1905. }
  1906. }
  1907. function next () {
  1908. return str.charCodeAt(++index)
  1909. }
  1910. function eof () {
  1911. return index >= len
  1912. }
  1913. function isStringStart (chr) {
  1914. return chr === 0x22 || chr === 0x27
  1915. }
  1916. function parseBracket (chr) {
  1917. var inBracket = 1;
  1918. expressionPos = index;
  1919. while (!eof()) {
  1920. chr = next();
  1921. if (isStringStart(chr)) {
  1922. parseString(chr);
  1923. continue
  1924. }
  1925. if (chr === 0x5B) { inBracket++; }
  1926. if (chr === 0x5D) { inBracket--; }
  1927. if (inBracket === 0) {
  1928. expressionEndPos = index;
  1929. break
  1930. }
  1931. }
  1932. }
  1933. function parseString (chr) {
  1934. var stringQuote = chr;
  1935. while (!eof()) {
  1936. chr = next();
  1937. if (chr === stringQuote) {
  1938. break
  1939. }
  1940. }
  1941. }
  1942. /* */
  1943. var onRE = /^@|^v-on:/;
  1944. var dirRE = /^v-|^@|^:/;
  1945. var forAliasRE = /(.*?)\s+(?:in|of)\s+(.*)/;
  1946. var forIteratorRE = /\((\{[^}]*\}|[^,]*),([^,]*)(?:,([^,]*))?\)/;
  1947. var argRE = /:(.*)$/;
  1948. var bindRE = /^:|^v-bind:/;
  1949. var modifierRE = /\.[^.]+/g;
  1950. var decodeHTMLCached = cached(he.decode);
  1951. // configurable state
  1952. var warn$1;
  1953. var delimiters;
  1954. var transforms;
  1955. var preTransforms;
  1956. var postTransforms;
  1957. var platformIsPreTag;
  1958. var platformMustUseProp;
  1959. var platformGetTagNamespace;
  1960. function createASTElement (
  1961. tag,
  1962. attrs,
  1963. parent
  1964. ) {
  1965. return {
  1966. type: 1,
  1967. tag: tag,
  1968. attrsList: attrs,
  1969. attrsMap: makeAttrsMap(attrs),
  1970. parent: parent,
  1971. children: []
  1972. }
  1973. }
  1974. /**
  1975. * Convert HTML string to AST.
  1976. */
  1977. function parse (
  1978. template,
  1979. options
  1980. ) {
  1981. warn$1 = options.warn || baseWarn;
  1982. platformIsPreTag = options.isPreTag || no;
  1983. platformMustUseProp = options.mustUseProp || no;
  1984. platformGetTagNamespace = options.getTagNamespace || no;
  1985. transforms = pluckModuleFunction(options.modules, 'transformNode');
  1986. preTransforms = pluckModuleFunction(options.modules, 'preTransformNode');
  1987. postTransforms = pluckModuleFunction(options.modules, 'postTransformNode');
  1988. delimiters = options.delimiters;
  1989. var stack = [];
  1990. var preserveWhitespace = options.preserveWhitespace !== false;
  1991. var root;
  1992. var currentParent;
  1993. var inVPre = false;
  1994. var inPre = false;
  1995. var warned = false;
  1996. function warnOnce (msg) {
  1997. if (!warned) {
  1998. warned = true;
  1999. warn$1(msg);
  2000. }
  2001. }
  2002. function endPre (element) {
  2003. // check pre state
  2004. if (element.pre) {
  2005. inVPre = false;
  2006. }
  2007. if (platformIsPreTag(element.tag)) {
  2008. inPre = false;
  2009. }
  2010. }
  2011. parseHTML(template, {
  2012. warn: warn$1,
  2013. expectHTML: options.expectHTML,
  2014. isUnaryTag: options.isUnaryTag,
  2015. canBeLeftOpenTag: options.canBeLeftOpenTag,
  2016. shouldDecodeNewlines: options.shouldDecodeNewlines,
  2017. shouldDecodeNewlinesForHref: options.shouldDecodeNewlinesForHref,
  2018. shouldKeepComment: options.comments,
  2019. start: function start (tag, attrs, unary) {
  2020. // check namespace.
  2021. // inherit parent ns if there is one
  2022. var ns = (currentParent && currentParent.ns) || platformGetTagNamespace(tag);
  2023. // handle IE svg bug
  2024. /* istanbul ignore if */
  2025. if (isIE && ns === 'svg') {
  2026. attrs = guardIESVGBug(attrs);
  2027. }
  2028. var element = createASTElement(tag, attrs, currentParent);
  2029. if (ns) {
  2030. element.ns = ns;
  2031. }
  2032. if (isForbiddenTag(element) && !isServerRendering()) {
  2033. element.forbidden = true;
  2034. process.env.NODE_ENV !== 'production' && warn$1(
  2035. 'Templates should only be responsible for mapping the state to the ' +
  2036. 'UI. Avoid placing tags with side-effects in your templates, such as ' +
  2037. "<" + tag + ">" + ', as they will not be parsed.'
  2038. );
  2039. }
  2040. // apply pre-transforms
  2041. for (var i = 0; i < preTransforms.length; i++) {
  2042. element = preTransforms[i](element, options) || element;
  2043. }
  2044. if (!inVPre) {
  2045. processPre(element);
  2046. if (element.pre) {
  2047. inVPre = true;
  2048. }
  2049. }
  2050. if (platformIsPreTag(element.tag)) {
  2051. inPre = true;
  2052. }
  2053. if (inVPre) {
  2054. processRawAttrs(element);
  2055. } else if (!element.processed) {
  2056. // structural directives
  2057. processFor(element);
  2058. processIf(element);
  2059. processOnce(element);
  2060. // element-scope stuff
  2061. processElement(element, options);
  2062. }
  2063. function checkRootConstraints (el) {
  2064. if (process.env.NODE_ENV !== 'production') {
  2065. if (el.tag === 'slot' || el.tag === 'template') {
  2066. warnOnce(
  2067. "Cannot use <" + (el.tag) + "> as component root element because it may " +
  2068. 'contain multiple nodes.'
  2069. );
  2070. }
  2071. if (el.attrsMap.hasOwnProperty('v-for')) {
  2072. warnOnce(
  2073. 'Cannot use v-for on stateful component root element because ' +
  2074. 'it renders multiple elements.'
  2075. );
  2076. }
  2077. }
  2078. }
  2079. // tree management
  2080. if (!root) {
  2081. root = element;
  2082. checkRootConstraints(root);
  2083. } else if (!stack.length) {
  2084. // allow root elements with v-if, v-else-if and v-else
  2085. if (root.if && (element.elseif || element.else)) {
  2086. checkRootConstraints(element);
  2087. addIfCondition(root, {
  2088. exp: element.elseif,
  2089. block: element
  2090. });
  2091. } else if (process.env.NODE_ENV !== 'production') {
  2092. warnOnce(
  2093. "Component template should contain exactly one root element. " +
  2094. "If you are using v-if on multiple elements, " +
  2095. "use v-else-if to chain them instead."
  2096. );
  2097. }
  2098. }
  2099. if (currentParent && !element.forbidden) {
  2100. if (element.elseif || element.else) {
  2101. processIfConditions(element, currentParent);
  2102. } else if (element.slotScope) { // scoped slot
  2103. currentParent.plain = false;
  2104. var name = element.slotTarget || '"default"';(currentParent.scopedSlots || (currentParent.scopedSlots = {}))[name] = element;
  2105. } else {
  2106. currentParent.children.push(element);
  2107. element.parent = currentParent;
  2108. }
  2109. }
  2110. if (!unary) {
  2111. currentParent = element;
  2112. stack.push(element);
  2113. } else {
  2114. endPre(element);
  2115. }
  2116. // apply post-transforms
  2117. for (var i$1 = 0; i$1 < postTransforms.length; i$1++) {
  2118. postTransforms[i$1](element, options);
  2119. }
  2120. },
  2121. end: function end () {
  2122. // remove trailing whitespace
  2123. var element = stack[stack.length - 1];
  2124. var lastNode = element.children[element.children.length - 1];
  2125. if (lastNode && lastNode.type === 3 && lastNode.text === ' ' && !inPre) {
  2126. element.children.pop();
  2127. }
  2128. // pop stack
  2129. stack.length -= 1;
  2130. currentParent = stack[stack.length - 1];
  2131. endPre(element);
  2132. },
  2133. chars: function chars (text) {
  2134. if (!currentParent) {
  2135. if (process.env.NODE_ENV !== 'production') {
  2136. if (text === template) {
  2137. warnOnce(
  2138. 'Component template requires a root element, rather than just text.'
  2139. );
  2140. } else if ((text = text.trim())) {
  2141. warnOnce(
  2142. ("text \"" + text + "\" outside root element will be ignored.")
  2143. );
  2144. }
  2145. }
  2146. return
  2147. }
  2148. // IE textarea placeholder bug
  2149. /* istanbul ignore if */
  2150. if (isIE &&
  2151. currentParent.tag === 'textarea' &&
  2152. currentParent.attrsMap.placeholder === text
  2153. ) {
  2154. return
  2155. }
  2156. var children = currentParent.children;
  2157. text = inPre || text.trim()
  2158. ? isTextTag(currentParent) ? text : decodeHTMLCached(text)
  2159. // only preserve whitespace if its not right after a starting tag
  2160. : preserveWhitespace && children.length ? ' ' : '';
  2161. if (text) {
  2162. var expression;
  2163. if (!inVPre && text !== ' ' && (expression = parseText(text, delimiters))) {
  2164. children.push({
  2165. type: 2,
  2166. expression: expression,
  2167. text: text
  2168. });
  2169. } else if (text !== ' ' || !children.length || children[children.length - 1].text !== ' ') {
  2170. children.push({
  2171. type: 3,
  2172. text: text
  2173. });
  2174. }
  2175. }
  2176. },
  2177. comment: function comment (text) {
  2178. currentParent.children.push({
  2179. type: 3,
  2180. text: text,
  2181. isComment: true
  2182. });
  2183. }
  2184. });
  2185. return root
  2186. }
  2187. function processPre (el) {
  2188. if (getAndRemoveAttr(el, 'v-pre') != null) {
  2189. el.pre = true;
  2190. }
  2191. }
  2192. function processRawAttrs (el) {
  2193. var l = el.attrsList.length;
  2194. if (l) {
  2195. var attrs = el.attrs = new Array(l);
  2196. for (var i = 0; i < l; i++) {
  2197. attrs[i] = {
  2198. name: el.attrsList[i].name,
  2199. value: JSON.stringify(el.attrsList[i].value)
  2200. };
  2201. }
  2202. } else if (!el.pre) {
  2203. // non root node in pre blocks with no attributes
  2204. el.plain = true;
  2205. }
  2206. }
  2207. function processElement (element, options) {
  2208. processKey(element);
  2209. // determine whether this is a plain element after
  2210. // removing structural attributes
  2211. element.plain = !element.key && !element.attrsList.length;
  2212. processRef(element);
  2213. processSlot(element);
  2214. processComponent(element);
  2215. for (var i = 0; i < transforms.length; i++) {
  2216. element = transforms[i](element, options) || element;
  2217. }
  2218. processAttrs(element);
  2219. }
  2220. function processKey (el) {
  2221. var exp = getBindingAttr(el, 'key');
  2222. if (exp) {
  2223. if (process.env.NODE_ENV !== 'production' && el.tag === 'template') {
  2224. warn$1("<template> cannot be keyed. Place the key on real elements instead.");
  2225. }
  2226. el.key = exp;
  2227. }
  2228. }
  2229. function processRef (el) {
  2230. var ref = getBindingAttr(el, 'ref');
  2231. if (ref) {
  2232. el.ref = ref;
  2233. el.refInFor = checkInFor(el);
  2234. }
  2235. }
  2236. function processFor (el) {
  2237. var exp;
  2238. if ((exp = getAndRemoveAttr(el, 'v-for'))) {
  2239. var inMatch = exp.match(forAliasRE);
  2240. if (!inMatch) {
  2241. process.env.NODE_ENV !== 'production' && warn$1(
  2242. ("Invalid v-for expression: " + exp)
  2243. );
  2244. return
  2245. }
  2246. el.for = inMatch[2].trim();
  2247. var alias = inMatch[1].trim();
  2248. var iteratorMatch = alias.match(forIteratorRE);
  2249. if (iteratorMatch) {
  2250. el.alias = iteratorMatch[1].trim();
  2251. el.iterator1 = iteratorMatch[2].trim();
  2252. if (iteratorMatch[3]) {
  2253. el.iterator2 = iteratorMatch[3].trim();
  2254. }
  2255. } else {
  2256. el.alias = alias;
  2257. }
  2258. }
  2259. }
  2260. function processIf (el) {
  2261. var exp = getAndRemoveAttr(el, 'v-if');
  2262. if (exp) {
  2263. el.if = exp;
  2264. addIfCondition(el, {
  2265. exp: exp,
  2266. block: el
  2267. });
  2268. } else {
  2269. if (getAndRemoveAttr(el, 'v-else') != null) {
  2270. el.else = true;
  2271. }
  2272. var elseif = getAndRemoveAttr(el, 'v-else-if');
  2273. if (elseif) {
  2274. el.elseif = elseif;
  2275. }
  2276. }
  2277. }
  2278. function processIfConditions (el, parent) {
  2279. var prev = findPrevElement(parent.children);
  2280. if (prev && prev.if) {
  2281. addIfCondition(prev, {
  2282. exp: el.elseif,
  2283. block: el
  2284. });
  2285. } else if (process.env.NODE_ENV !== 'production') {
  2286. warn$1(
  2287. "v-" + (el.elseif ? ('else-if="' + el.elseif + '"') : 'else') + " " +
  2288. "used on element <" + (el.tag) + "> without corresponding v-if."
  2289. );
  2290. }
  2291. }
  2292. function findPrevElement (children) {
  2293. var i = children.length;
  2294. while (i--) {
  2295. if (children[i].type === 1) {
  2296. return children[i]
  2297. } else {
  2298. if (process.env.NODE_ENV !== 'production' && children[i].text !== ' ') {
  2299. warn$1(
  2300. "text \"" + (children[i].text.trim()) + "\" between v-if and v-else(-if) " +
  2301. "will be ignored."
  2302. );
  2303. }
  2304. children.pop();
  2305. }
  2306. }
  2307. }
  2308. function addIfCondition (el, condition) {
  2309. if (!el.ifConditions) {
  2310. el.ifConditions = [];
  2311. }
  2312. el.ifConditions.push(condition);
  2313. }
  2314. function processOnce (el) {
  2315. var once$$1 = getAndRemoveAttr(el, 'v-once');
  2316. if (once$$1 != null) {
  2317. el.once = true;
  2318. }
  2319. }
  2320. function processSlot (el) {
  2321. if (el.tag === 'slot') {
  2322. el.slotName = getBindingAttr(el, 'name');
  2323. if (process.env.NODE_ENV !== 'production' && el.key) {
  2324. warn$1(
  2325. "`key` does not work on <slot> because slots are abstract outlets " +
  2326. "and can possibly expand into multiple elements. " +
  2327. "Use the key on a wrapping element instead."
  2328. );
  2329. }
  2330. } else {
  2331. var slotScope;
  2332. if (el.tag === 'template') {
  2333. slotScope = getAndRemoveAttr(el, 'scope');
  2334. /* istanbul ignore if */
  2335. if (process.env.NODE_ENV !== 'production' && slotScope) {
  2336. warn$1(
  2337. "the \"scope\" attribute for scoped slots have been deprecated and " +
  2338. "replaced by \"slot-scope\" since 2.5. The new \"slot-scope\" attribute " +
  2339. "can also be used on plain elements in addition to <template> to " +
  2340. "denote scoped slots.",
  2341. true
  2342. );
  2343. }
  2344. el.slotScope = slotScope || getAndRemoveAttr(el, 'slot-scope');
  2345. } else if ((slotScope = getAndRemoveAttr(el, 'slot-scope'))) {
  2346. el.slotScope = slotScope;
  2347. }
  2348. var slotTarget = getBindingAttr(el, 'slot');
  2349. if (slotTarget) {
  2350. el.slotTarget = slotTarget === '""' ? '"default"' : slotTarget;
  2351. // preserve slot as an attribute for native shadow DOM compat
  2352. // only for non-scoped slots.
  2353. if (el.tag !== 'template' && !el.slotScope) {
  2354. addAttr(el, 'slot', slotTarget);
  2355. }
  2356. }
  2357. }
  2358. }
  2359. function processComponent (el) {
  2360. var binding;
  2361. if ((binding = getBindingAttr(el, 'is'))) {
  2362. el.component = binding;
  2363. }
  2364. if (getAndRemoveAttr(el, 'inline-template') != null) {
  2365. el.inlineTemplate = true;
  2366. }
  2367. }
  2368. function processAttrs (el) {
  2369. var list = el.attrsList;
  2370. var i, l, name, rawName, value, modifiers, isProp;
  2371. for (i = 0, l = list.length; i < l; i++) {
  2372. name = rawName = list[i].name;
  2373. value = list[i].value;
  2374. if (dirRE.test(name)) {
  2375. // mark element as dynamic
  2376. el.hasBindings = true;
  2377. // modifiers
  2378. modifiers = parseModifiers(name);
  2379. if (modifiers) {
  2380. name = name.replace(modifierRE, '');
  2381. }
  2382. if (bindRE.test(name)) { // v-bind
  2383. name = name.replace(bindRE, '');
  2384. value = parseFilters(value);
  2385. isProp = false;
  2386. if (modifiers) {
  2387. if (modifiers.prop) {
  2388. isProp = true;
  2389. name = camelize(name);
  2390. if (name === 'innerHtml') { name = 'innerHTML'; }
  2391. }
  2392. if (modifiers.camel) {
  2393. name = camelize(name);
  2394. }
  2395. if (modifiers.sync) {
  2396. addHandler(
  2397. el,
  2398. ("update:" + (camelize(name))),
  2399. genAssignmentCode(value, "$event")
  2400. );
  2401. }
  2402. }
  2403. if (isProp || (
  2404. !el.component && platformMustUseProp(el.tag, el.attrsMap.type, name)
  2405. )) {
  2406. addProp(el, name, value);
  2407. } else {
  2408. addAttr(el, name, value);
  2409. }
  2410. } else if (onRE.test(name)) { // v-on
  2411. name = name.replace(onRE, '');
  2412. addHandler(el, name, value, modifiers, false, warn$1);
  2413. } else { // normal directives
  2414. name = name.replace(dirRE, '');
  2415. // parse arg
  2416. var argMatch = name.match(argRE);
  2417. var arg = argMatch && argMatch[1];
  2418. if (arg) {
  2419. name = name.slice(0, -(arg.length + 1));
  2420. }
  2421. addDirective(el, name, rawName, value, arg, modifiers);
  2422. if (process.env.NODE_ENV !== 'production' && name === 'model') {
  2423. checkForAliasModel(el, value);
  2424. }
  2425. }
  2426. } else {
  2427. // literal attribute
  2428. if (process.env.NODE_ENV !== 'production') {
  2429. var expression = parseText(value, delimiters);
  2430. if (expression) {
  2431. warn$1(
  2432. name + "=\"" + value + "\": " +
  2433. 'Interpolation inside attributes has been removed. ' +
  2434. 'Use v-bind or the colon shorthand instead. For example, ' +
  2435. 'instead of <div id="{{ val }}">, use <div :id="val">.'
  2436. );
  2437. }
  2438. }
  2439. addAttr(el, name, JSON.stringify(value));
  2440. // #6887 firefox doesn't update muted state if set via attribute
  2441. // even immediately after element creation
  2442. if (!el.component &&
  2443. name === 'muted' &&
  2444. platformMustUseProp(el.tag, el.attrsMap.type, name)) {
  2445. addProp(el, name, 'true');
  2446. }
  2447. }
  2448. }
  2449. }
  2450. function checkInFor (el) {
  2451. var parent = el;
  2452. while (parent) {
  2453. if (parent.for !== undefined) {
  2454. return true
  2455. }
  2456. parent = parent.parent;
  2457. }
  2458. return false
  2459. }
  2460. function parseModifiers (name) {
  2461. var match = name.match(modifierRE);
  2462. if (match) {
  2463. var ret = {};
  2464. match.forEach(function (m) { ret[m.slice(1)] = true; });
  2465. return ret
  2466. }
  2467. }
  2468. function makeAttrsMap (attrs) {
  2469. var map = {};
  2470. for (var i = 0, l = attrs.length; i < l; i++) {
  2471. if (
  2472. process.env.NODE_ENV !== 'production' &&
  2473. map[attrs[i].name] && !isIE && !isEdge
  2474. ) {
  2475. warn$1('duplicate attribute: ' + attrs[i].name);
  2476. }
  2477. map[attrs[i].name] = attrs[i].value;
  2478. }
  2479. return map
  2480. }
  2481. // for script (e.g. type="x/template") or style, do not decode content
  2482. function isTextTag (el) {
  2483. return el.tag === 'script' || el.tag === 'style'
  2484. }
  2485. function isForbiddenTag (el) {
  2486. return (
  2487. el.tag === 'style' ||
  2488. (el.tag === 'script' && (
  2489. !el.attrsMap.type ||
  2490. el.attrsMap.type === 'text/javascript'
  2491. ))
  2492. )
  2493. }
  2494. var ieNSBug = /^xmlns:NS\d+/;
  2495. var ieNSPrefix = /^NS\d+:/;
  2496. /* istanbul ignore next */
  2497. function guardIESVGBug (attrs) {
  2498. var res = [];
  2499. for (var i = 0; i < attrs.length; i++) {
  2500. var attr = attrs[i];
  2501. if (!ieNSBug.test(attr.name)) {
  2502. attr.name = attr.name.replace(ieNSPrefix, '');
  2503. res.push(attr);
  2504. }
  2505. }
  2506. return res
  2507. }
  2508. function checkForAliasModel (el, value) {
  2509. var _el = el;
  2510. while (_el) {
  2511. if (_el.for && _el.alias === value) {
  2512. warn$1(
  2513. "<" + (el.tag) + " v-model=\"" + value + "\">: " +
  2514. "You are binding v-model directly to a v-for iteration alias. " +
  2515. "This will not be able to modify the v-for source array because " +
  2516. "writing to the alias is like modifying a function local variable. " +
  2517. "Consider using an array of objects and use v-model on an object property instead."
  2518. );
  2519. }
  2520. _el = _el.parent;
  2521. }
  2522. }
  2523. /* */
  2524. /**
  2525. * Expand input[v-model] with dyanmic type bindings into v-if-else chains
  2526. * Turn this:
  2527. * <input v-model="data[type]" :type="type">
  2528. * into this:
  2529. * <input v-if="type === 'checkbox'" type="checkbox" v-model="data[type]">
  2530. * <input v-else-if="type === 'radio'" type="radio" v-model="data[type]">
  2531. * <input v-else :type="type" v-model="data[type]">
  2532. */
  2533. function preTransformNode (el, options) {
  2534. if (el.tag === 'input') {
  2535. var map = el.attrsMap;
  2536. if (map['v-model'] && (map['v-bind:type'] || map[':type'])) {
  2537. var typeBinding = getBindingAttr(el, 'type');
  2538. var ifCondition = getAndRemoveAttr(el, 'v-if', true);
  2539. var ifConditionExtra = ifCondition ? ("&&(" + ifCondition + ")") : "";
  2540. var hasElse = getAndRemoveAttr(el, 'v-else', true) != null;
  2541. var elseIfCondition = getAndRemoveAttr(el, 'v-else-if', true);
  2542. // 1. checkbox
  2543. var branch0 = cloneASTElement(el);
  2544. // process for on the main node
  2545. processFor(branch0);
  2546. addRawAttr(branch0, 'type', 'checkbox');
  2547. processElement(branch0, options);
  2548. branch0.processed = true; // prevent it from double-processed
  2549. branch0.if = "(" + typeBinding + ")==='checkbox'" + ifConditionExtra;
  2550. addIfCondition(branch0, {
  2551. exp: branch0.if,
  2552. block: branch0
  2553. });
  2554. // 2. add radio else-if condition
  2555. var branch1 = cloneASTElement(el);
  2556. getAndRemoveAttr(branch1, 'v-for', true);
  2557. addRawAttr(branch1, 'type', 'radio');
  2558. processElement(branch1, options);
  2559. addIfCondition(branch0, {
  2560. exp: "(" + typeBinding + ")==='radio'" + ifConditionExtra,
  2561. block: branch1
  2562. });
  2563. // 3. other
  2564. var branch2 = cloneASTElement(el);
  2565. getAndRemoveAttr(branch2, 'v-for', true);
  2566. addRawAttr(branch2, ':type', typeBinding);
  2567. processElement(branch2, options);
  2568. addIfCondition(branch0, {
  2569. exp: ifCondition,
  2570. block: branch2
  2571. });
  2572. if (hasElse) {
  2573. branch0.else = true;
  2574. } else if (elseIfCondition) {
  2575. branch0.elseif = elseIfCondition;
  2576. }
  2577. return branch0
  2578. }
  2579. }
  2580. }
  2581. function cloneASTElement (el) {
  2582. return createASTElement(el.tag, el.attrsList.slice(), el.parent)
  2583. }
  2584. function addRawAttr (el, name, value) {
  2585. el.attrsMap[name] = value;
  2586. el.attrsList.push({ name: name, value: value });
  2587. }
  2588. var model = {
  2589. preTransformNode: preTransformNode
  2590. };
  2591. var modules = [
  2592. klass,
  2593. style,
  2594. model
  2595. ];
  2596. /* */
  2597. var warn$2;
  2598. // in some cases, the event used has to be determined at runtime
  2599. // so we used some reserved tokens during compile.
  2600. var RANGE_TOKEN = '__r';
  2601. function model$1 (
  2602. el,
  2603. dir,
  2604. _warn
  2605. ) {
  2606. warn$2 = _warn;
  2607. var value = dir.value;
  2608. var modifiers = dir.modifiers;
  2609. var tag = el.tag;
  2610. var type = el.attrsMap.type;
  2611. if (process.env.NODE_ENV !== 'production') {
  2612. // inputs with type="file" are read only and setting the input's
  2613. // value will throw an error.
  2614. if (tag === 'input' && type === 'file') {
  2615. warn$2(
  2616. "<" + (el.tag) + " v-model=\"" + value + "\" type=\"file\">:\n" +
  2617. "File inputs are read only. Use a v-on:change listener instead."
  2618. );
  2619. }
  2620. }
  2621. if (el.component) {
  2622. genComponentModel(el, value, modifiers);
  2623. // component v-model doesn't need extra runtime
  2624. return false
  2625. } else if (tag === 'select') {
  2626. genSelect(el, value, modifiers);
  2627. } else if (tag === 'input' && type === 'checkbox') {
  2628. genCheckboxModel(el, value, modifiers);
  2629. } else if (tag === 'input' && type === 'radio') {
  2630. genRadioModel(el, value, modifiers);
  2631. } else if (tag === 'input' || tag === 'textarea') {
  2632. genDefaultModel(el, value, modifiers);
  2633. } else if (!config.isReservedTag(tag)) {
  2634. genComponentModel(el, value, modifiers);
  2635. // component v-model doesn't need extra runtime
  2636. return false
  2637. } else if (process.env.NODE_ENV !== 'production') {
  2638. warn$2(
  2639. "<" + (el.tag) + " v-model=\"" + value + "\">: " +
  2640. "v-model is not supported on this element type. " +
  2641. 'If you are working with contenteditable, it\'s recommended to ' +
  2642. 'wrap a library dedicated for that purpose inside a custom component.'
  2643. );
  2644. }
  2645. // ensure runtime directive metadata
  2646. return true
  2647. }
  2648. function genCheckboxModel (
  2649. el,
  2650. value,
  2651. modifiers
  2652. ) {
  2653. var number = modifiers && modifiers.number;
  2654. var valueBinding = getBindingAttr(el, 'value') || 'null';
  2655. var trueValueBinding = getBindingAttr(el, 'true-value') || 'true';
  2656. var falseValueBinding = getBindingAttr(el, 'false-value') || 'false';
  2657. addProp(el, 'checked',
  2658. "Array.isArray(" + value + ")" +
  2659. "?_i(" + value + "," + valueBinding + ")>-1" + (
  2660. trueValueBinding === 'true'
  2661. ? (":(" + value + ")")
  2662. : (":_q(" + value + "," + trueValueBinding + ")")
  2663. )
  2664. );
  2665. addHandler(el, 'change',
  2666. "var $$a=" + value + "," +
  2667. '$$el=$event.target,' +
  2668. "$$c=$$el.checked?(" + trueValueBinding + "):(" + falseValueBinding + ");" +
  2669. 'if(Array.isArray($$a)){' +
  2670. "var $$v=" + (number ? '_n(' + valueBinding + ')' : valueBinding) + "," +
  2671. '$$i=_i($$a,$$v);' +
  2672. "if($$el.checked){$$i<0&&(" + value + "=$$a.concat([$$v]))}" +
  2673. "else{$$i>-1&&(" + value + "=$$a.slice(0,$$i).concat($$a.slice($$i+1)))}" +
  2674. "}else{" + (genAssignmentCode(value, '$$c')) + "}",
  2675. null, true
  2676. );
  2677. }
  2678. function genRadioModel (
  2679. el,
  2680. value,
  2681. modifiers
  2682. ) {
  2683. var number = modifiers && modifiers.number;
  2684. var valueBinding = getBindingAttr(el, 'value') || 'null';
  2685. valueBinding = number ? ("_n(" + valueBinding + ")") : valueBinding;
  2686. addProp(el, 'checked', ("_q(" + value + "," + valueBinding + ")"));
  2687. addHandler(el, 'change', genAssignmentCode(value, valueBinding), null, true);
  2688. }
  2689. function genSelect (
  2690. el,
  2691. value,
  2692. modifiers
  2693. ) {
  2694. var number = modifiers && modifiers.number;
  2695. var selectedVal = "Array.prototype.filter" +
  2696. ".call($event.target.options,function(o){return o.selected})" +
  2697. ".map(function(o){var val = \"_value\" in o ? o._value : o.value;" +
  2698. "return " + (number ? '_n(val)' : 'val') + "})";
  2699. var assignment = '$event.target.multiple ? $$selectedVal : $$selectedVal[0]';
  2700. var code = "var $$selectedVal = " + selectedVal + ";";
  2701. code = code + " " + (genAssignmentCode(value, assignment));
  2702. addHandler(el, 'change', code, null, true);
  2703. }
  2704. function genDefaultModel (
  2705. el,
  2706. value,
  2707. modifiers
  2708. ) {
  2709. var type = el.attrsMap.type;
  2710. var ref = modifiers || {};
  2711. var lazy = ref.lazy;
  2712. var number = ref.number;
  2713. var trim = ref.trim;
  2714. var needCompositionGuard = !lazy && type !== 'range';
  2715. var event = lazy
  2716. ? 'change'
  2717. : type === 'range'
  2718. ? RANGE_TOKEN
  2719. : 'input';
  2720. var valueExpression = '$event.target.value';
  2721. if (trim) {
  2722. valueExpression = "$event.target.value.trim()";
  2723. }
  2724. if (number) {
  2725. valueExpression = "_n(" + valueExpression + ")";
  2726. }
  2727. var code = genAssignmentCode(value, valueExpression);
  2728. if (needCompositionGuard) {
  2729. code = "if($event.target.composing)return;" + code;
  2730. }
  2731. addProp(el, 'value', ("(" + value + ")"));
  2732. addHandler(el, event, code, null, true);
  2733. if (trim || number) {
  2734. addHandler(el, 'blur', '$forceUpdate()');
  2735. }
  2736. }
  2737. /* */
  2738. function text (el, dir) {
  2739. if (dir.value) {
  2740. addProp(el, 'textContent', ("_s(" + (dir.value) + ")"));
  2741. }
  2742. }
  2743. /* */
  2744. function html (el, dir) {
  2745. if (dir.value) {
  2746. addProp(el, 'innerHTML', ("_s(" + (dir.value) + ")"));
  2747. }
  2748. }
  2749. var directives = {
  2750. model: model$1,
  2751. text: text,
  2752. html: html
  2753. };
  2754. /* */
  2755. var baseOptions = {
  2756. expectHTML: true,
  2757. modules: modules,
  2758. directives: directives,
  2759. isPreTag: isPreTag,
  2760. isUnaryTag: isUnaryTag,
  2761. mustUseProp: mustUseProp,
  2762. canBeLeftOpenTag: canBeLeftOpenTag,
  2763. isReservedTag: isReservedTag,
  2764. getTagNamespace: getTagNamespace,
  2765. staticKeys: genStaticKeys(modules)
  2766. };
  2767. /* */
  2768. var isStaticKey;
  2769. var isPlatformReservedTag;
  2770. var genStaticKeysCached = cached(genStaticKeys$1);
  2771. /**
  2772. * Goal of the optimizer: walk the generated template AST tree
  2773. * and detect sub-trees that are purely static, i.e. parts of
  2774. * the DOM that never needs to change.
  2775. *
  2776. * Once we detect these sub-trees, we can:
  2777. *
  2778. * 1. Hoist them into constants, so that we no longer need to
  2779. * create fresh nodes for them on each re-render;
  2780. * 2. Completely skip them in the patching process.
  2781. */
  2782. function optimize (root, options) {
  2783. if (!root) { return }
  2784. isStaticKey = genStaticKeysCached(options.staticKeys || '');
  2785. isPlatformReservedTag = options.isReservedTag || no;
  2786. // first pass: mark all non-static nodes.
  2787. markStatic(root);
  2788. // second pass: mark static roots.
  2789. markStaticRoots(root, false);
  2790. }
  2791. function genStaticKeys$1 (keys) {
  2792. return makeMap(
  2793. 'type,tag,attrsList,attrsMap,plain,parent,children,attrs' +
  2794. (keys ? ',' + keys : '')
  2795. )
  2796. }
  2797. function markStatic (node) {
  2798. node.static = isStatic(node);
  2799. if (node.type === 1) {
  2800. // do not make component slot content static. this avoids
  2801. // 1. components not able to mutate slot nodes
  2802. // 2. static slot content fails for hot-reloading
  2803. if (
  2804. !isPlatformReservedTag(node.tag) &&
  2805. node.tag !== 'slot' &&
  2806. node.attrsMap['inline-template'] == null
  2807. ) {
  2808. return
  2809. }
  2810. for (var i = 0, l = node.children.length; i < l; i++) {
  2811. var child = node.children[i];
  2812. markStatic(child);
  2813. if (!child.static) {
  2814. node.static = false;
  2815. }
  2816. }
  2817. if (node.ifConditions) {
  2818. for (var i$1 = 1, l$1 = node.ifConditions.length; i$1 < l$1; i$1++) {
  2819. var block = node.ifConditions[i$1].block;
  2820. markStatic(block);
  2821. if (!block.static) {
  2822. node.static = false;
  2823. }
  2824. }
  2825. }
  2826. }
  2827. }
  2828. function markStaticRoots (node, isInFor) {
  2829. if (node.type === 1) {
  2830. if (node.static || node.once) {
  2831. node.staticInFor = isInFor;
  2832. }
  2833. // For a node to qualify as a static root, it should have children that
  2834. // are not just static text. Otherwise the cost of hoisting out will
  2835. // outweigh the benefits and it's better off to just always render it fresh.
  2836. if (node.static && node.children.length && !(
  2837. node.children.length === 1 &&
  2838. node.children[0].type === 3
  2839. )) {
  2840. node.staticRoot = true;
  2841. return
  2842. } else {
  2843. node.staticRoot = false;
  2844. }
  2845. if (node.children) {
  2846. for (var i = 0, l = node.children.length; i < l; i++) {
  2847. markStaticRoots(node.children[i], isInFor || !!node.for);
  2848. }
  2849. }
  2850. if (node.ifConditions) {
  2851. for (var i$1 = 1, l$1 = node.ifConditions.length; i$1 < l$1; i$1++) {
  2852. markStaticRoots(node.ifConditions[i$1].block, isInFor);
  2853. }
  2854. }
  2855. }
  2856. }
  2857. function isStatic (node) {
  2858. if (node.type === 2) { // expression
  2859. return false
  2860. }
  2861. if (node.type === 3) { // text
  2862. return true
  2863. }
  2864. return !!(node.pre || (
  2865. !node.hasBindings && // no dynamic bindings
  2866. !node.if && !node.for && // not v-if or v-for or v-else
  2867. !isBuiltInTag(node.tag) && // not a built-in
  2868. isPlatformReservedTag(node.tag) && // not a component
  2869. !isDirectChildOfTemplateFor(node) &&
  2870. Object.keys(node).every(isStaticKey)
  2871. ))
  2872. }
  2873. function isDirectChildOfTemplateFor (node) {
  2874. while (node.parent) {
  2875. node = node.parent;
  2876. if (node.tag !== 'template') {
  2877. return false
  2878. }
  2879. if (node.for) {
  2880. return true
  2881. }
  2882. }
  2883. return false
  2884. }
  2885. /* */
  2886. var fnExpRE = /^\s*([\w$_]+|\([^)]*?\))\s*=>|^function\s*\(/;
  2887. var simplePathRE = /^\s*[A-Za-z_$][\w$]*(?:\.[A-Za-z_$][\w$]*|\['.*?']|\[".*?"]|\[\d+]|\[[A-Za-z_$][\w$]*])*\s*$/;
  2888. // keyCode aliases
  2889. var keyCodes = {
  2890. esc: 27,
  2891. tab: 9,
  2892. enter: 13,
  2893. space: 32,
  2894. up: 38,
  2895. left: 37,
  2896. right: 39,
  2897. down: 40,
  2898. 'delete': [8, 46]
  2899. };
  2900. // #4868: modifiers that prevent the execution of the listener
  2901. // need to explicitly return null so that we can determine whether to remove
  2902. // the listener for .once
  2903. var genGuard = function (condition) { return ("if(" + condition + ")return null;"); };
  2904. var modifierCode = {
  2905. stop: '$event.stopPropagation();',
  2906. prevent: '$event.preventDefault();',
  2907. self: genGuard("$event.target !== $event.currentTarget"),
  2908. ctrl: genGuard("!$event.ctrlKey"),
  2909. shift: genGuard("!$event.shiftKey"),
  2910. alt: genGuard("!$event.altKey"),
  2911. meta: genGuard("!$event.metaKey"),
  2912. left: genGuard("'button' in $event && $event.button !== 0"),
  2913. middle: genGuard("'button' in $event && $event.button !== 1"),
  2914. right: genGuard("'button' in $event && $event.button !== 2")
  2915. };
  2916. function genHandlers (
  2917. events,
  2918. isNative,
  2919. warn
  2920. ) {
  2921. var res = isNative ? 'nativeOn:{' : 'on:{';
  2922. for (var name in events) {
  2923. var handler = events[name];
  2924. // #5330: warn click.right, since right clicks do not actually fire click events.
  2925. if (process.env.NODE_ENV !== 'production' &&
  2926. name === 'click' &&
  2927. handler && handler.modifiers && handler.modifiers.right
  2928. ) {
  2929. warn(
  2930. "Use \"contextmenu\" instead of \"click.right\" since right clicks " +
  2931. "do not actually fire \"click\" events."
  2932. );
  2933. }
  2934. res += "\"" + name + "\":" + (genHandler(name, handler)) + ",";
  2935. }
  2936. return res.slice(0, -1) + '}'
  2937. }
  2938. function genHandler (
  2939. name,
  2940. handler
  2941. ) {
  2942. if (!handler) {
  2943. return 'function(){}'
  2944. }
  2945. if (Array.isArray(handler)) {
  2946. return ("[" + (handler.map(function (handler) { return genHandler(name, handler); }).join(',')) + "]")
  2947. }
  2948. var isMethodPath = simplePathRE.test(handler.value);
  2949. var isFunctionExpression = fnExpRE.test(handler.value);
  2950. if (!handler.modifiers) {
  2951. return isMethodPath || isFunctionExpression
  2952. ? handler.value
  2953. : ("function($event){" + (handler.value) + "}") // inline statement
  2954. } else {
  2955. var code = '';
  2956. var genModifierCode = '';
  2957. var keys = [];
  2958. for (var key in handler.modifiers) {
  2959. if (modifierCode[key]) {
  2960. genModifierCode += modifierCode[key];
  2961. // left/right
  2962. if (keyCodes[key]) {
  2963. keys.push(key);
  2964. }
  2965. } else if (key === 'exact') {
  2966. var modifiers = (handler.modifiers);
  2967. genModifierCode += genGuard(
  2968. ['ctrl', 'shift', 'alt', 'meta']
  2969. .filter(function (keyModifier) { return !modifiers[keyModifier]; })
  2970. .map(function (keyModifier) { return ("$event." + keyModifier + "Key"); })
  2971. .join('||')
  2972. );
  2973. } else {
  2974. keys.push(key);
  2975. }
  2976. }
  2977. if (keys.length) {
  2978. code += genKeyFilter(keys);
  2979. }
  2980. // Make sure modifiers like prevent and stop get executed after key filtering
  2981. if (genModifierCode) {
  2982. code += genModifierCode;
  2983. }
  2984. var handlerCode = isMethodPath
  2985. ? handler.value + '($event)'
  2986. : isFunctionExpression
  2987. ? ("(" + (handler.value) + ")($event)")
  2988. : handler.value;
  2989. return ("function($event){" + code + handlerCode + "}")
  2990. }
  2991. }
  2992. function genKeyFilter (keys) {
  2993. return ("if(!('button' in $event)&&" + (keys.map(genFilterCode).join('&&')) + ")return null;")
  2994. }
  2995. function genFilterCode (key) {
  2996. var keyVal = parseInt(key, 10);
  2997. if (keyVal) {
  2998. return ("$event.keyCode!==" + keyVal)
  2999. }
  3000. var code = keyCodes[key];
  3001. return (
  3002. "_k($event.keyCode," +
  3003. (JSON.stringify(key)) + "," +
  3004. (JSON.stringify(code)) + "," +
  3005. "$event.key)"
  3006. )
  3007. }
  3008. /* */
  3009. function on (el, dir) {
  3010. if (process.env.NODE_ENV !== 'production' && dir.modifiers) {
  3011. warn("v-on without argument does not support modifiers.");
  3012. }
  3013. el.wrapListeners = function (code) { return ("_g(" + code + "," + (dir.value) + ")"); };
  3014. }
  3015. /* */
  3016. function bind$1 (el, dir) {
  3017. el.wrapData = function (code) {
  3018. return ("_b(" + code + ",'" + (el.tag) + "'," + (dir.value) + "," + (dir.modifiers && dir.modifiers.prop ? 'true' : 'false') + (dir.modifiers && dir.modifiers.sync ? ',true' : '') + ")")
  3019. };
  3020. }
  3021. /* */
  3022. var baseDirectives = {
  3023. on: on,
  3024. bind: bind$1,
  3025. cloak: noop
  3026. };
  3027. /* */
  3028. var CodegenState = function CodegenState (options) {
  3029. this.options = options;
  3030. this.warn = options.warn || baseWarn;
  3031. this.transforms = pluckModuleFunction(options.modules, 'transformCode');
  3032. this.dataGenFns = pluckModuleFunction(options.modules, 'genData');
  3033. this.directives = extend(extend({}, baseDirectives), options.directives);
  3034. var isReservedTag = options.isReservedTag || no;
  3035. this.maybeComponent = function (el) { return !isReservedTag(el.tag); };
  3036. this.onceId = 0;
  3037. this.staticRenderFns = [];
  3038. };
  3039. function generate (
  3040. ast,
  3041. options
  3042. ) {
  3043. var state = new CodegenState(options);
  3044. var code = ast ? genElement(ast, state) : '_c("div")';
  3045. return {
  3046. render: ("with(this){return " + code + "}"),
  3047. staticRenderFns: state.staticRenderFns
  3048. }
  3049. }
  3050. function genElement (el, state) {
  3051. if (el.staticRoot && !el.staticProcessed) {
  3052. return genStatic(el, state)
  3053. } else if (el.once && !el.onceProcessed) {
  3054. return genOnce(el, state)
  3055. } else if (el.for && !el.forProcessed) {
  3056. return genFor(el, state)
  3057. } else if (el.if && !el.ifProcessed) {
  3058. return genIf(el, state)
  3059. } else if (el.tag === 'template' && !el.slotTarget) {
  3060. return genChildren(el, state) || 'void 0'
  3061. } else if (el.tag === 'slot') {
  3062. return genSlot(el, state)
  3063. } else {
  3064. // component or element
  3065. var code;
  3066. if (el.component) {
  3067. code = genComponent(el.component, el, state);
  3068. } else {
  3069. var data = el.plain ? undefined : genData$2(el, state);
  3070. var children = el.inlineTemplate ? null : genChildren(el, state, true);
  3071. code = "_c('" + (el.tag) + "'" + (data ? ("," + data) : '') + (children ? ("," + children) : '') + ")";
  3072. }
  3073. // module transforms
  3074. for (var i = 0; i < state.transforms.length; i++) {
  3075. code = state.transforms[i](el, code);
  3076. }
  3077. return code
  3078. }
  3079. }
  3080. // hoist static sub-trees out
  3081. function genStatic (el, state) {
  3082. el.staticProcessed = true;
  3083. state.staticRenderFns.push(("with(this){return " + (genElement(el, state)) + "}"));
  3084. return ("_m(" + (state.staticRenderFns.length - 1) + (el.staticInFor ? ',true' : '') + ")")
  3085. }
  3086. // v-once
  3087. function genOnce (el, state) {
  3088. el.onceProcessed = true;
  3089. if (el.if && !el.ifProcessed) {
  3090. return genIf(el, state)
  3091. } else if (el.staticInFor) {
  3092. var key = '';
  3093. var parent = el.parent;
  3094. while (parent) {
  3095. if (parent.for) {
  3096. key = parent.key;
  3097. break
  3098. }
  3099. parent = parent.parent;
  3100. }
  3101. if (!key) {
  3102. process.env.NODE_ENV !== 'production' && state.warn(
  3103. "v-once can only be used inside v-for that is keyed. "
  3104. );
  3105. return genElement(el, state)
  3106. }
  3107. return ("_o(" + (genElement(el, state)) + "," + (state.onceId++) + "," + key + ")")
  3108. } else {
  3109. return genStatic(el, state)
  3110. }
  3111. }
  3112. function genIf (
  3113. el,
  3114. state,
  3115. altGen,
  3116. altEmpty
  3117. ) {
  3118. el.ifProcessed = true; // avoid recursion
  3119. return genIfConditions(el.ifConditions.slice(), state, altGen, altEmpty)
  3120. }
  3121. function genIfConditions (
  3122. conditions,
  3123. state,
  3124. altGen,
  3125. altEmpty
  3126. ) {
  3127. if (!conditions.length) {
  3128. return altEmpty || '_e()'
  3129. }
  3130. var condition = conditions.shift();
  3131. if (condition.exp) {
  3132. return ("(" + (condition.exp) + ")?" + (genTernaryExp(condition.block)) + ":" + (genIfConditions(conditions, state, altGen, altEmpty)))
  3133. } else {
  3134. return ("" + (genTernaryExp(condition.block)))
  3135. }
  3136. // v-if with v-once should generate code like (a)?_m(0):_m(1)
  3137. function genTernaryExp (el) {
  3138. return altGen
  3139. ? altGen(el, state)
  3140. : el.once
  3141. ? genOnce(el, state)
  3142. : genElement(el, state)
  3143. }
  3144. }
  3145. function genFor (
  3146. el,
  3147. state,
  3148. altGen,
  3149. altHelper
  3150. ) {
  3151. var exp = el.for;
  3152. var alias = el.alias;
  3153. var iterator1 = el.iterator1 ? ("," + (el.iterator1)) : '';
  3154. var iterator2 = el.iterator2 ? ("," + (el.iterator2)) : '';
  3155. if (process.env.NODE_ENV !== 'production' &&
  3156. state.maybeComponent(el) &&
  3157. el.tag !== 'slot' &&
  3158. el.tag !== 'template' &&
  3159. !el.key
  3160. ) {
  3161. state.warn(
  3162. "<" + (el.tag) + " v-for=\"" + alias + " in " + exp + "\">: component lists rendered with " +
  3163. "v-for should have explicit keys. " +
  3164. "See https://vuejs.org/guide/list.html#key for more info.",
  3165. true /* tip */
  3166. );
  3167. }
  3168. el.forProcessed = true; // avoid recursion
  3169. return (altHelper || '_l') + "((" + exp + ")," +
  3170. "function(" + alias + iterator1 + iterator2 + "){" +
  3171. "return " + ((altGen || genElement)(el, state)) +
  3172. '})'
  3173. }
  3174. function genData$2 (el, state) {
  3175. var data = '{';
  3176. // directives first.
  3177. // directives may mutate the el's other properties before they are generated.
  3178. var dirs = genDirectives(el, state);
  3179. if (dirs) { data += dirs + ','; }
  3180. // key
  3181. if (el.key) {
  3182. data += "key:" + (el.key) + ",";
  3183. }
  3184. // ref
  3185. if (el.ref) {
  3186. data += "ref:" + (el.ref) + ",";
  3187. }
  3188. if (el.refInFor) {
  3189. data += "refInFor:true,";
  3190. }
  3191. // pre
  3192. if (el.pre) {
  3193. data += "pre:true,";
  3194. }
  3195. // record original tag name for components using "is" attribute
  3196. if (el.component) {
  3197. data += "tag:\"" + (el.tag) + "\",";
  3198. }
  3199. // module data generation functions
  3200. for (var i = 0; i < state.dataGenFns.length; i++) {
  3201. data += state.dataGenFns[i](el);
  3202. }
  3203. // attributes
  3204. if (el.attrs) {
  3205. data += "attrs:{" + (genProps(el.attrs)) + "},";
  3206. }
  3207. // DOM props
  3208. if (el.props) {
  3209. data += "domProps:{" + (genProps(el.props)) + "},";
  3210. }
  3211. // event handlers
  3212. if (el.events) {
  3213. data += (genHandlers(el.events, false, state.warn)) + ",";
  3214. }
  3215. if (el.nativeEvents) {
  3216. data += (genHandlers(el.nativeEvents, true, state.warn)) + ",";
  3217. }
  3218. // slot target
  3219. // only for non-scoped slots
  3220. if (el.slotTarget && !el.slotScope) {
  3221. data += "slot:" + (el.slotTarget) + ",";
  3222. }
  3223. // scoped slots
  3224. if (el.scopedSlots) {
  3225. data += (genScopedSlots(el.scopedSlots, state)) + ",";
  3226. }
  3227. // component v-model
  3228. if (el.model) {
  3229. data += "model:{value:" + (el.model.value) + ",callback:" + (el.model.callback) + ",expression:" + (el.model.expression) + "},";
  3230. }
  3231. // inline-template
  3232. if (el.inlineTemplate) {
  3233. var inlineTemplate = genInlineTemplate(el, state);
  3234. if (inlineTemplate) {
  3235. data += inlineTemplate + ",";
  3236. }
  3237. }
  3238. data = data.replace(/,$/, '') + '}';
  3239. // v-bind data wrap
  3240. if (el.wrapData) {
  3241. data = el.wrapData(data);
  3242. }
  3243. // v-on data wrap
  3244. if (el.wrapListeners) {
  3245. data = el.wrapListeners(data);
  3246. }
  3247. return data
  3248. }
  3249. function genDirectives (el, state) {
  3250. var dirs = el.directives;
  3251. if (!dirs) { return }
  3252. var res = 'directives:[';
  3253. var hasRuntime = false;
  3254. var i, l, dir, needRuntime;
  3255. for (i = 0, l = dirs.length; i < l; i++) {
  3256. dir = dirs[i];
  3257. needRuntime = true;
  3258. var gen = state.directives[dir.name];
  3259. if (gen) {
  3260. // compile-time directive that manipulates AST.
  3261. // returns true if it also needs a runtime counterpart.
  3262. needRuntime = !!gen(el, dir, state.warn);
  3263. }
  3264. if (needRuntime) {
  3265. hasRuntime = true;
  3266. res += "{name:\"" + (dir.name) + "\",rawName:\"" + (dir.rawName) + "\"" + (dir.value ? (",value:(" + (dir.value) + "),expression:" + (JSON.stringify(dir.value))) : '') + (dir.arg ? (",arg:\"" + (dir.arg) + "\"") : '') + (dir.modifiers ? (",modifiers:" + (JSON.stringify(dir.modifiers))) : '') + "},";
  3267. }
  3268. }
  3269. if (hasRuntime) {
  3270. return res.slice(0, -1) + ']'
  3271. }
  3272. }
  3273. function genInlineTemplate (el, state) {
  3274. var ast = el.children[0];
  3275. if (process.env.NODE_ENV !== 'production' && (
  3276. el.children.length !== 1 || ast.type !== 1
  3277. )) {
  3278. state.warn('Inline-template components must have exactly one child element.');
  3279. }
  3280. if (ast.type === 1) {
  3281. var inlineRenderFns = generate(ast, state.options);
  3282. return ("inlineTemplate:{render:function(){" + (inlineRenderFns.render) + "},staticRenderFns:[" + (inlineRenderFns.staticRenderFns.map(function (code) { return ("function(){" + code + "}"); }).join(',')) + "]}")
  3283. }
  3284. }
  3285. function genScopedSlots (
  3286. slots,
  3287. state
  3288. ) {
  3289. return ("scopedSlots:_u([" + (Object.keys(slots).map(function (key) {
  3290. return genScopedSlot(key, slots[key], state)
  3291. }).join(',')) + "])")
  3292. }
  3293. function genScopedSlot (
  3294. key,
  3295. el,
  3296. state
  3297. ) {
  3298. if (el.for && !el.forProcessed) {
  3299. return genForScopedSlot(key, el, state)
  3300. }
  3301. var fn = "function(" + (String(el.slotScope)) + "){" +
  3302. "return " + (el.tag === 'template'
  3303. ? el.if
  3304. ? ((el.if) + "?" + (genChildren(el, state) || 'undefined') + ":undefined")
  3305. : genChildren(el, state) || 'undefined'
  3306. : genElement(el, state)) + "}";
  3307. return ("{key:" + key + ",fn:" + fn + "}")
  3308. }
  3309. function genForScopedSlot (
  3310. key,
  3311. el,
  3312. state
  3313. ) {
  3314. var exp = el.for;
  3315. var alias = el.alias;
  3316. var iterator1 = el.iterator1 ? ("," + (el.iterator1)) : '';
  3317. var iterator2 = el.iterator2 ? ("," + (el.iterator2)) : '';
  3318. el.forProcessed = true; // avoid recursion
  3319. return "_l((" + exp + ")," +
  3320. "function(" + alias + iterator1 + iterator2 + "){" +
  3321. "return " + (genScopedSlot(key, el, state)) +
  3322. '})'
  3323. }
  3324. function genChildren (
  3325. el,
  3326. state,
  3327. checkSkip,
  3328. altGenElement,
  3329. altGenNode
  3330. ) {
  3331. var children = el.children;
  3332. if (children.length) {
  3333. var el$1 = children[0];
  3334. // optimize single v-for
  3335. if (children.length === 1 &&
  3336. el$1.for &&
  3337. el$1.tag !== 'template' &&
  3338. el$1.tag !== 'slot'
  3339. ) {
  3340. return (altGenElement || genElement)(el$1, state)
  3341. }
  3342. var normalizationType = checkSkip
  3343. ? getNormalizationType(children, state.maybeComponent)
  3344. : 0;
  3345. var gen = altGenNode || genNode;
  3346. return ("[" + (children.map(function (c) { return gen(c, state); }).join(',')) + "]" + (normalizationType ? ("," + normalizationType) : ''))
  3347. }
  3348. }
  3349. // determine the normalization needed for the children array.
  3350. // 0: no normalization needed
  3351. // 1: simple normalization needed (possible 1-level deep nested array)
  3352. // 2: full normalization needed
  3353. function getNormalizationType (
  3354. children,
  3355. maybeComponent
  3356. ) {
  3357. var res = 0;
  3358. for (var i = 0; i < children.length; i++) {
  3359. var el = children[i];
  3360. if (el.type !== 1) {
  3361. continue
  3362. }
  3363. if (needsNormalization(el) ||
  3364. (el.ifConditions && el.ifConditions.some(function (c) { return needsNormalization(c.block); }))) {
  3365. res = 2;
  3366. break
  3367. }
  3368. if (maybeComponent(el) ||
  3369. (el.ifConditions && el.ifConditions.some(function (c) { return maybeComponent(c.block); }))) {
  3370. res = 1;
  3371. }
  3372. }
  3373. return res
  3374. }
  3375. function needsNormalization (el) {
  3376. return el.for !== undefined || el.tag === 'template' || el.tag === 'slot'
  3377. }
  3378. function genNode (node, state) {
  3379. if (node.type === 1) {
  3380. return genElement(node, state)
  3381. } if (node.type === 3 && node.isComment) {
  3382. return genComment(node)
  3383. } else {
  3384. return genText(node)
  3385. }
  3386. }
  3387. function genText (text) {
  3388. return ("_v(" + (text.type === 2
  3389. ? text.expression // no need for () because already wrapped in _s()
  3390. : transformSpecialNewlines(JSON.stringify(text.text))) + ")")
  3391. }
  3392. function genComment (comment) {
  3393. return ("_e(" + (JSON.stringify(comment.text)) + ")")
  3394. }
  3395. function genSlot (el, state) {
  3396. var slotName = el.slotName || '"default"';
  3397. var children = genChildren(el, state);
  3398. var res = "_t(" + slotName + (children ? ("," + children) : '');
  3399. var attrs = el.attrs && ("{" + (el.attrs.map(function (a) { return ((camelize(a.name)) + ":" + (a.value)); }).join(',')) + "}");
  3400. var bind$$1 = el.attrsMap['v-bind'];
  3401. if ((attrs || bind$$1) && !children) {
  3402. res += ",null";
  3403. }
  3404. if (attrs) {
  3405. res += "," + attrs;
  3406. }
  3407. if (bind$$1) {
  3408. res += (attrs ? '' : ',null') + "," + bind$$1;
  3409. }
  3410. return res + ')'
  3411. }
  3412. // componentName is el.component, take it as argument to shun flow's pessimistic refinement
  3413. function genComponent (
  3414. componentName,
  3415. el,
  3416. state
  3417. ) {
  3418. var children = el.inlineTemplate ? null : genChildren(el, state, true);
  3419. return ("_c(" + componentName + "," + (genData$2(el, state)) + (children ? ("," + children) : '') + ")")
  3420. }
  3421. function genProps (props) {
  3422. var res = '';
  3423. for (var i = 0; i < props.length; i++) {
  3424. var prop = props[i];
  3425. res += "\"" + (prop.name) + "\":" + (transformSpecialNewlines(prop.value)) + ",";
  3426. }
  3427. return res.slice(0, -1)
  3428. }
  3429. // #3895, #4268
  3430. function transformSpecialNewlines (text) {
  3431. return text
  3432. .replace(/\u2028/g, '\\u2028')
  3433. .replace(/\u2029/g, '\\u2029')
  3434. }
  3435. /* */
  3436. // these keywords should not appear inside expressions, but operators like
  3437. // typeof, instanceof and in are allowed
  3438. var prohibitedKeywordRE = new RegExp('\\b' + (
  3439. 'do,if,for,let,new,try,var,case,else,with,await,break,catch,class,const,' +
  3440. 'super,throw,while,yield,delete,export,import,return,switch,default,' +
  3441. 'extends,finally,continue,debugger,function,arguments'
  3442. ).split(',').join('\\b|\\b') + '\\b');
  3443. // these unary operators should not be used as property/method names
  3444. var unaryOperatorsRE = new RegExp('\\b' + (
  3445. 'delete,typeof,void'
  3446. ).split(',').join('\\s*\\([^\\)]*\\)|\\b') + '\\s*\\([^\\)]*\\)');
  3447. // check valid identifier for v-for
  3448. var identRE = /[A-Za-z_$][\w$]*/;
  3449. // strip strings in expressions
  3450. var stripStringRE = /'(?:[^'\\]|\\.)*'|"(?:[^"\\]|\\.)*"|`(?:[^`\\]|\\.)*\$\{|\}(?:[^`\\]|\\.)*`|`(?:[^`\\]|\\.)*`/g;
  3451. // detect problematic expressions in a template
  3452. function detectErrors (ast) {
  3453. var errors = [];
  3454. if (ast) {
  3455. checkNode(ast, errors);
  3456. }
  3457. return errors
  3458. }
  3459. function checkNode (node, errors) {
  3460. if (node.type === 1) {
  3461. for (var name in node.attrsMap) {
  3462. if (dirRE.test(name)) {
  3463. var value = node.attrsMap[name];
  3464. if (value) {
  3465. if (name === 'v-for') {
  3466. checkFor(node, ("v-for=\"" + value + "\""), errors);
  3467. } else if (onRE.test(name)) {
  3468. checkEvent(value, (name + "=\"" + value + "\""), errors);
  3469. } else {
  3470. checkExpression(value, (name + "=\"" + value + "\""), errors);
  3471. }
  3472. }
  3473. }
  3474. }
  3475. if (node.children) {
  3476. for (var i = 0; i < node.children.length; i++) {
  3477. checkNode(node.children[i], errors);
  3478. }
  3479. }
  3480. } else if (node.type === 2) {
  3481. checkExpression(node.expression, node.text, errors);
  3482. }
  3483. }
  3484. function checkEvent (exp, text, errors) {
  3485. var stipped = exp.replace(stripStringRE, '');
  3486. var keywordMatch = stipped.match(unaryOperatorsRE);
  3487. if (keywordMatch && stipped.charAt(keywordMatch.index - 1) !== '$') {
  3488. errors.push(
  3489. "avoid using JavaScript unary operator as property name: " +
  3490. "\"" + (keywordMatch[0]) + "\" in expression " + (text.trim())
  3491. );
  3492. }
  3493. checkExpression(exp, text, errors);
  3494. }
  3495. function checkFor (node, text, errors) {
  3496. checkExpression(node.for || '', text, errors);
  3497. checkIdentifier(node.alias, 'v-for alias', text, errors);
  3498. checkIdentifier(node.iterator1, 'v-for iterator', text, errors);
  3499. checkIdentifier(node.iterator2, 'v-for iterator', text, errors);
  3500. }
  3501. function checkIdentifier (ident, type, text, errors) {
  3502. if (typeof ident === 'string' && !identRE.test(ident)) {
  3503. errors.push(("invalid " + type + " \"" + ident + "\" in expression: " + (text.trim())));
  3504. }
  3505. }
  3506. function checkExpression (exp, text, errors) {
  3507. try {
  3508. new Function(("return " + exp));
  3509. } catch (e) {
  3510. var keywordMatch = exp.replace(stripStringRE, '').match(prohibitedKeywordRE);
  3511. if (keywordMatch) {
  3512. errors.push(
  3513. "avoid using JavaScript keyword as property name: " +
  3514. "\"" + (keywordMatch[0]) + "\"\n Raw expression: " + (text.trim())
  3515. );
  3516. } else {
  3517. errors.push(
  3518. "invalid expression: " + (e.message) + " in\n\n" +
  3519. " " + exp + "\n\n" +
  3520. " Raw expression: " + (text.trim()) + "\n"
  3521. );
  3522. }
  3523. }
  3524. }
  3525. /* */
  3526. function createFunction (code, errors) {
  3527. try {
  3528. return new Function(code)
  3529. } catch (err) {
  3530. errors.push({ err: err, code: code });
  3531. return noop
  3532. }
  3533. }
  3534. function createCompileToFunctionFn (compile) {
  3535. var cache = Object.create(null);
  3536. return function compileToFunctions (
  3537. template,
  3538. options,
  3539. vm
  3540. ) {
  3541. options = extend({}, options);
  3542. var warn$$1 = options.warn || warn;
  3543. delete options.warn;
  3544. /* istanbul ignore if */
  3545. if (process.env.NODE_ENV !== 'production') {
  3546. // detect possible CSP restriction
  3547. try {
  3548. new Function('return 1');
  3549. } catch (e) {
  3550. if (e.toString().match(/unsafe-eval|CSP/)) {
  3551. warn$$1(
  3552. 'It seems you are using the standalone build of Vue.js in an ' +
  3553. 'environment with Content Security Policy that prohibits unsafe-eval. ' +
  3554. 'The template compiler cannot work in this environment. Consider ' +
  3555. 'relaxing the policy to allow unsafe-eval or pre-compiling your ' +
  3556. 'templates into render functions.'
  3557. );
  3558. }
  3559. }
  3560. }
  3561. // check cache
  3562. var key = options.delimiters
  3563. ? String(options.delimiters) + template
  3564. : template;
  3565. if (cache[key]) {
  3566. return cache[key]
  3567. }
  3568. // compile
  3569. var compiled = compile(template, options);
  3570. // check compilation errors/tips
  3571. if (process.env.NODE_ENV !== 'production') {
  3572. if (compiled.errors && compiled.errors.length) {
  3573. warn$$1(
  3574. "Error compiling template:\n\n" + template + "\n\n" +
  3575. compiled.errors.map(function (e) { return ("- " + e); }).join('\n') + '\n',
  3576. vm
  3577. );
  3578. }
  3579. if (compiled.tips && compiled.tips.length) {
  3580. compiled.tips.forEach(function (msg) { return tip(msg, vm); });
  3581. }
  3582. }
  3583. // turn code into functions
  3584. var res = {};
  3585. var fnGenErrors = [];
  3586. res.render = createFunction(compiled.render, fnGenErrors);
  3587. res.staticRenderFns = compiled.staticRenderFns.map(function (code) {
  3588. return createFunction(code, fnGenErrors)
  3589. });
  3590. // check function generation errors.
  3591. // this should only happen if there is a bug in the compiler itself.
  3592. // mostly for codegen development use
  3593. /* istanbul ignore if */
  3594. if (process.env.NODE_ENV !== 'production') {
  3595. if ((!compiled.errors || !compiled.errors.length) && fnGenErrors.length) {
  3596. warn$$1(
  3597. "Failed to generate render function:\n\n" +
  3598. fnGenErrors.map(function (ref) {
  3599. var err = ref.err;
  3600. var code = ref.code;
  3601. return ((err.toString()) + " in\n\n" + code + "\n");
  3602. }).join('\n'),
  3603. vm
  3604. );
  3605. }
  3606. }
  3607. return (cache[key] = res)
  3608. }
  3609. }
  3610. /* */
  3611. function createCompilerCreator (baseCompile) {
  3612. return function createCompiler (baseOptions) {
  3613. function compile (
  3614. template,
  3615. options
  3616. ) {
  3617. var finalOptions = Object.create(baseOptions);
  3618. var errors = [];
  3619. var tips = [];
  3620. finalOptions.warn = function (msg, tip) {
  3621. (tip ? tips : errors).push(msg);
  3622. };
  3623. if (options) {
  3624. // merge custom modules
  3625. if (options.modules) {
  3626. finalOptions.modules =
  3627. (baseOptions.modules || []).concat(options.modules);
  3628. }
  3629. // merge custom directives
  3630. if (options.directives) {
  3631. finalOptions.directives = extend(
  3632. Object.create(baseOptions.directives),
  3633. options.directives
  3634. );
  3635. }
  3636. // copy other options
  3637. for (var key in options) {
  3638. if (key !== 'modules' && key !== 'directives') {
  3639. finalOptions[key] = options[key];
  3640. }
  3641. }
  3642. }
  3643. var compiled = baseCompile(template, finalOptions);
  3644. if (process.env.NODE_ENV !== 'production') {
  3645. errors.push.apply(errors, detectErrors(compiled.ast));
  3646. }
  3647. compiled.errors = errors;
  3648. compiled.tips = tips;
  3649. return compiled
  3650. }
  3651. return {
  3652. compile: compile,
  3653. compileToFunctions: createCompileToFunctionFn(compile)
  3654. }
  3655. }
  3656. }
  3657. /* */
  3658. // `createCompilerCreator` allows creating compilers that use alternative
  3659. // parser/optimizer/codegen, e.g the SSR optimizing compiler.
  3660. // Here we just export a default compiler using the default parts.
  3661. var createCompiler = createCompilerCreator(function baseCompile (
  3662. template,
  3663. options
  3664. ) {
  3665. var ast = parse(template.trim(), options);
  3666. optimize(ast, options);
  3667. var code = generate(ast, options);
  3668. return {
  3669. ast: ast,
  3670. render: code.render,
  3671. staticRenderFns: code.staticRenderFns
  3672. }
  3673. });
  3674. /* */
  3675. var ref = createCompiler(baseOptions);
  3676. var compile = ref.compile;
  3677. var compileToFunctions = ref.compileToFunctions;
  3678. /* */
  3679. var isAttr = makeMap(
  3680. 'accept,accept-charset,accesskey,action,align,alt,async,autocomplete,' +
  3681. 'autofocus,autoplay,autosave,bgcolor,border,buffered,challenge,charset,' +
  3682. 'checked,cite,class,code,codebase,color,cols,colspan,content,http-equiv,' +
  3683. 'name,contenteditable,contextmenu,controls,coords,data,datetime,default,' +
  3684. 'defer,dir,dirname,disabled,download,draggable,dropzone,enctype,method,for,' +
  3685. 'form,formaction,headers,height,hidden,high,href,hreflang,http-equiv,' +
  3686. 'icon,id,ismap,itemprop,keytype,kind,label,lang,language,list,loop,low,' +
  3687. 'manifest,max,maxlength,media,method,GET,POST,min,multiple,email,file,' +
  3688. 'muted,name,novalidate,open,optimum,pattern,ping,placeholder,poster,' +
  3689. 'preload,radiogroup,readonly,rel,required,reversed,rows,rowspan,sandbox,' +
  3690. 'scope,scoped,seamless,selected,shape,size,type,text,password,sizes,span,' +
  3691. 'spellcheck,src,srcdoc,srclang,srcset,start,step,style,summary,tabindex,' +
  3692. 'target,title,type,usemap,value,width,wrap'
  3693. );
  3694. /* istanbul ignore next */
  3695. var isRenderableAttr = function (name) {
  3696. return (
  3697. isAttr(name) ||
  3698. name.indexOf('data-') === 0 ||
  3699. name.indexOf('aria-') === 0
  3700. )
  3701. };
  3702. var propsToAttrMap = {
  3703. acceptCharset: 'accept-charset',
  3704. className: 'class',
  3705. htmlFor: 'for',
  3706. httpEquiv: 'http-equiv'
  3707. };
  3708. var ESC = {
  3709. '<': '&lt;',
  3710. '>': '&gt;',
  3711. '"': '&quot;',
  3712. '&': '&amp;'
  3713. };
  3714. function escape (s) {
  3715. return s.replace(/[<>"&]/g, escapeChar)
  3716. }
  3717. function escapeChar (a) {
  3718. return ESC[a] || a
  3719. }
  3720. /* */
  3721. var plainStringRE = /^"(?:[^"\\]|\\.)*"$|^'(?:[^'\\]|\\.)*'$/;
  3722. // let the model AST transform translate v-model into appropriate
  3723. // props bindings
  3724. function applyModelTransform (el, state) {
  3725. if (el.directives) {
  3726. for (var i = 0; i < el.directives.length; i++) {
  3727. var dir = el.directives[i];
  3728. if (dir.name === 'model') {
  3729. state.directives.model(el, dir, state.warn);
  3730. // remove value for textarea as its converted to text
  3731. if (el.tag === 'textarea' && el.props) {
  3732. el.props = el.props.filter(function (p) { return p.name !== 'value'; });
  3733. }
  3734. break
  3735. }
  3736. }
  3737. }
  3738. }
  3739. function genAttrSegments (
  3740. attrs
  3741. ) {
  3742. return attrs.map(function (ref) {
  3743. var name = ref.name;
  3744. var value = ref.value;
  3745. return genAttrSegment(name, value);
  3746. })
  3747. }
  3748. function genDOMPropSegments (
  3749. props,
  3750. attrs
  3751. ) {
  3752. var segments = [];
  3753. props.forEach(function (ref) {
  3754. var name = ref.name;
  3755. var value = ref.value;
  3756. name = propsToAttrMap[name] || name.toLowerCase();
  3757. if (isRenderableAttr(name) &&
  3758. !(attrs && attrs.some(function (a) { return a.name === name; }))
  3759. ) {
  3760. segments.push(genAttrSegment(name, value));
  3761. }
  3762. });
  3763. return segments
  3764. }
  3765. function genAttrSegment (name, value) {
  3766. if (plainStringRE.test(value)) {
  3767. // force double quote
  3768. value = value.replace(/^'|'$/g, '"');
  3769. // force enumerated attr to "true"
  3770. if (isEnumeratedAttr(name) && value !== "\"false\"") {
  3771. value = "\"true\"";
  3772. }
  3773. return {
  3774. type: RAW,
  3775. value: isBooleanAttr(name)
  3776. ? (" " + name + "=\"" + name + "\"")
  3777. : value === '""'
  3778. ? (" " + name)
  3779. : (" " + name + "=" + value)
  3780. }
  3781. } else {
  3782. return {
  3783. type: EXPRESSION,
  3784. value: ("_ssrAttr(" + (JSON.stringify(name)) + "," + value + ")")
  3785. }
  3786. }
  3787. }
  3788. function genClassSegments (
  3789. staticClass,
  3790. classBinding
  3791. ) {
  3792. if (staticClass && !classBinding) {
  3793. return [{ type: RAW, value: (" class=" + staticClass) }]
  3794. } else {
  3795. return [{
  3796. type: EXPRESSION,
  3797. value: ("_ssrClass(" + (staticClass || 'null') + "," + (classBinding || 'null') + ")")
  3798. }]
  3799. }
  3800. }
  3801. function genStyleSegments (
  3802. staticStyle,
  3803. parsedStaticStyle,
  3804. styleBinding,
  3805. vShowExpression
  3806. ) {
  3807. if (staticStyle && !styleBinding && !vShowExpression) {
  3808. return [{ type: RAW, value: (" style=" + (JSON.stringify(staticStyle))) }]
  3809. } else {
  3810. return [{
  3811. type: EXPRESSION,
  3812. value: ("_ssrStyle(" + (parsedStaticStyle || 'null') + "," + (styleBinding || 'null') + ", " + (vShowExpression
  3813. ? ("{ display: (" + vShowExpression + ") ? '' : 'none' }")
  3814. : 'null') + ")")
  3815. }]
  3816. }
  3817. }
  3818. /* */
  3819. /**
  3820. * In SSR, the vdom tree is generated only once and never patched, so
  3821. * we can optimize most element / trees into plain string render functions.
  3822. * The SSR optimizer walks the AST tree to detect optimizable elements and trees.
  3823. *
  3824. * The criteria for SSR optimizability is quite a bit looser than static tree
  3825. * detection (which is designed for client re-render). In SSR we bail only for
  3826. * components/slots/custom directives.
  3827. */
  3828. // optimizability constants
  3829. var optimizability = {
  3830. FALSE: 0, // whole sub tree un-optimizable
  3831. FULL: 1, // whole sub tree optimizable
  3832. SELF: 2, // self optimizable but has some un-optimizable children
  3833. CHILDREN: 3, // self un-optimizable but have fully optimizable children
  3834. PARTIAL: 4 // self un-optimizable with some un-optimizable children
  3835. };
  3836. var isPlatformReservedTag$1;
  3837. function optimize$1 (root, options) {
  3838. if (!root) { return }
  3839. isPlatformReservedTag$1 = options.isReservedTag || no;
  3840. walk(root, true);
  3841. }
  3842. function walk (node, isRoot) {
  3843. if (isUnOptimizableTree(node)) {
  3844. node.ssrOptimizability = optimizability.FALSE;
  3845. return
  3846. }
  3847. // root node or nodes with custom directives should always be a VNode
  3848. var selfUnoptimizable = isRoot || hasCustomDirective(node);
  3849. var check = function (child) {
  3850. if (child.ssrOptimizability !== optimizability.FULL) {
  3851. node.ssrOptimizability = selfUnoptimizable
  3852. ? optimizability.PARTIAL
  3853. : optimizability.SELF;
  3854. }
  3855. };
  3856. if (selfUnoptimizable) {
  3857. node.ssrOptimizability = optimizability.CHILDREN;
  3858. }
  3859. if (node.type === 1) {
  3860. for (var i = 0, l = node.children.length; i < l; i++) {
  3861. var child = node.children[i];
  3862. walk(child);
  3863. check(child);
  3864. }
  3865. if (node.ifConditions) {
  3866. for (var i$1 = 1, l$1 = node.ifConditions.length; i$1 < l$1; i$1++) {
  3867. var block = node.ifConditions[i$1].block;
  3868. walk(block, isRoot);
  3869. check(block);
  3870. }
  3871. }
  3872. if (node.ssrOptimizability == null ||
  3873. (!isRoot && (node.attrsMap['v-html'] || node.attrsMap['v-text']))
  3874. ) {
  3875. node.ssrOptimizability = optimizability.FULL;
  3876. } else {
  3877. node.children = optimizeSiblings(node);
  3878. }
  3879. } else {
  3880. node.ssrOptimizability = optimizability.FULL;
  3881. }
  3882. }
  3883. function optimizeSiblings (el) {
  3884. var children = el.children;
  3885. var optimizedChildren = [];
  3886. var currentOptimizableGroup = [];
  3887. var pushGroup = function () {
  3888. if (currentOptimizableGroup.length) {
  3889. optimizedChildren.push({
  3890. type: 1,
  3891. parent: el,
  3892. tag: 'template',
  3893. attrsList: [],
  3894. attrsMap: {},
  3895. children: currentOptimizableGroup,
  3896. ssrOptimizability: optimizability.FULL
  3897. });
  3898. }
  3899. currentOptimizableGroup = [];
  3900. };
  3901. for (var i = 0; i < children.length; i++) {
  3902. var c = children[i];
  3903. if (c.ssrOptimizability === optimizability.FULL) {
  3904. currentOptimizableGroup.push(c);
  3905. } else {
  3906. // wrap fully-optimizable adjacent siblings inside a template tag
  3907. // so that they can be optimized into a single ssrNode by codegen
  3908. pushGroup();
  3909. optimizedChildren.push(c);
  3910. }
  3911. }
  3912. pushGroup();
  3913. return optimizedChildren
  3914. }
  3915. function isUnOptimizableTree (node) {
  3916. if (node.type === 2 || node.type === 3) { // text or expression
  3917. return false
  3918. }
  3919. return (
  3920. isBuiltInTag(node.tag) || // built-in (slot, component)
  3921. !isPlatformReservedTag$1(node.tag) || // custom component
  3922. !!node.component || // "is" component
  3923. isSelectWithModel(node) // <select v-model> requires runtime inspection
  3924. )
  3925. }
  3926. var isBuiltInDir = makeMap('text,html,show,on,bind,model,pre,cloak,once');
  3927. function hasCustomDirective (node) {
  3928. return (
  3929. node.type === 1 &&
  3930. node.directives &&
  3931. node.directives.some(function (d) { return !isBuiltInDir(d.name); })
  3932. )
  3933. }
  3934. // <select v-model> cannot be optimized because it requires a runtime check
  3935. // to determine proper selected option
  3936. function isSelectWithModel (node) {
  3937. return (
  3938. node.type === 1 &&
  3939. node.tag === 'select' &&
  3940. node.directives != null &&
  3941. node.directives.some(function (d) { return d.name === 'model'; })
  3942. )
  3943. }
  3944. /* */
  3945. // The SSR codegen is essentially extending the default codegen to handle
  3946. // SSR-optimizable nodes and turn them into string render fns. In cases where
  3947. // a node is not optimizable it simply falls back to the default codegen.
  3948. // segment types
  3949. var RAW = 0;
  3950. var INTERPOLATION = 1;
  3951. var EXPRESSION = 2;
  3952. function generate$1 (
  3953. ast,
  3954. options
  3955. ) {
  3956. var state = new CodegenState(options);
  3957. var code = ast ? genSSRElement(ast, state) : '_c("div")';
  3958. return {
  3959. render: ("with(this){return " + code + "}"),
  3960. staticRenderFns: state.staticRenderFns
  3961. }
  3962. }
  3963. function genSSRElement (el, state) {
  3964. if (el.for && !el.forProcessed) {
  3965. return genFor(el, state, genSSRElement)
  3966. } else if (el.if && !el.ifProcessed) {
  3967. return genIf(el, state, genSSRElement)
  3968. } else if (el.tag === 'template' && !el.slotTarget) {
  3969. return el.ssrOptimizability === optimizability.FULL
  3970. ? genChildrenAsStringNode(el, state)
  3971. : genSSRChildren(el, state) || 'void 0'
  3972. }
  3973. switch (el.ssrOptimizability) {
  3974. case optimizability.FULL:
  3975. // stringify whole tree
  3976. return genStringElement(el, state)
  3977. case optimizability.SELF:
  3978. // stringify self and check children
  3979. return genStringElementWithChildren(el, state)
  3980. case optimizability.CHILDREN:
  3981. // generate self as VNode and stringify children
  3982. return genNormalElement(el, state, true)
  3983. case optimizability.PARTIAL:
  3984. // generate self as VNode and check children
  3985. return genNormalElement(el, state, false)
  3986. default:
  3987. // bail whole tree
  3988. return genElement(el, state)
  3989. }
  3990. }
  3991. function genNormalElement (el, state, stringifyChildren) {
  3992. var data = el.plain ? undefined : genData$2(el, state);
  3993. var children = stringifyChildren
  3994. ? ("[" + (genChildrenAsStringNode(el, state)) + "]")
  3995. : genSSRChildren(el, state, true);
  3996. return ("_c('" + (el.tag) + "'" + (data ? ("," + data) : '') + (children ? ("," + children) : '') + ")")
  3997. }
  3998. function genSSRChildren (el, state, checkSkip) {
  3999. return genChildren(el, state, checkSkip, genSSRElement, genSSRNode)
  4000. }
  4001. function genSSRNode (el, state) {
  4002. return el.type === 1
  4003. ? genSSRElement(el, state)
  4004. : genText(el)
  4005. }
  4006. function genChildrenAsStringNode (el, state) {
  4007. return el.children.length
  4008. ? ("_ssrNode(" + (flattenSegments(childrenToSegments(el, state))) + ")")
  4009. : ''
  4010. }
  4011. function genStringElement (el, state) {
  4012. return ("_ssrNode(" + (elementToString(el, state)) + ")")
  4013. }
  4014. function genStringElementWithChildren (el, state) {
  4015. var children = genSSRChildren(el, state, true);
  4016. return ("_ssrNode(" + (flattenSegments(elementToOpenTagSegments(el, state))) + ",\"</" + (el.tag) + ">\"" + (children ? ("," + children) : '') + ")")
  4017. }
  4018. function elementToString (el, state) {
  4019. return ("(" + (flattenSegments(elementToSegments(el, state))) + ")")
  4020. }
  4021. function elementToSegments (el, state) {
  4022. // v-for / v-if
  4023. if (el.for && !el.forProcessed) {
  4024. el.forProcessed = true;
  4025. return [{
  4026. type: EXPRESSION,
  4027. value: genFor(el, state, elementToString, '_ssrList')
  4028. }]
  4029. } else if (el.if && !el.ifProcessed) {
  4030. el.ifProcessed = true;
  4031. return [{
  4032. type: EXPRESSION,
  4033. value: genIf(el, state, elementToString, '"<!---->"')
  4034. }]
  4035. } else if (el.tag === 'template') {
  4036. return childrenToSegments(el, state)
  4037. }
  4038. var openSegments = elementToOpenTagSegments(el, state);
  4039. var childrenSegments = childrenToSegments(el, state);
  4040. var ref = state.options;
  4041. var isUnaryTag = ref.isUnaryTag;
  4042. var close = (isUnaryTag && isUnaryTag(el.tag))
  4043. ? []
  4044. : [{ type: RAW, value: ("</" + (el.tag) + ">") }];
  4045. return openSegments.concat(childrenSegments, close)
  4046. }
  4047. function elementToOpenTagSegments (el, state) {
  4048. applyModelTransform(el, state);
  4049. var binding;
  4050. var segments = [{ type: RAW, value: ("<" + (el.tag)) }];
  4051. // attrs
  4052. if (el.attrs) {
  4053. segments.push.apply(segments, genAttrSegments(el.attrs));
  4054. }
  4055. // domProps
  4056. if (el.props) {
  4057. segments.push.apply(segments, genDOMPropSegments(el.props, el.attrs));
  4058. }
  4059. // v-bind="object"
  4060. if ((binding = el.attrsMap['v-bind'])) {
  4061. segments.push({ type: EXPRESSION, value: ("_ssrAttrs(" + binding + ")") });
  4062. }
  4063. // v-bind.prop="object"
  4064. if ((binding = el.attrsMap['v-bind.prop'])) {
  4065. segments.push({ type: EXPRESSION, value: ("_ssrDOMProps(" + binding + ")") });
  4066. }
  4067. // class
  4068. if (el.staticClass || el.classBinding) {
  4069. segments.push.apply(
  4070. segments,
  4071. genClassSegments(el.staticClass, el.classBinding)
  4072. );
  4073. }
  4074. // style & v-show
  4075. if (el.staticStyle || el.styleBinding || el.attrsMap['v-show']) {
  4076. segments.push.apply(
  4077. segments,
  4078. genStyleSegments(
  4079. el.attrsMap.style,
  4080. el.staticStyle,
  4081. el.styleBinding,
  4082. el.attrsMap['v-show']
  4083. )
  4084. );
  4085. }
  4086. // _scopedId
  4087. if (state.options.scopeId) {
  4088. segments.push({ type: RAW, value: (" " + (state.options.scopeId)) });
  4089. }
  4090. segments.push({ type: RAW, value: ">" });
  4091. return segments
  4092. }
  4093. function childrenToSegments (el, state) {
  4094. var binding;
  4095. if ((binding = el.attrsMap['v-html'])) {
  4096. return [{ type: EXPRESSION, value: ("_s(" + binding + ")") }]
  4097. }
  4098. if ((binding = el.attrsMap['v-text'])) {
  4099. return [{ type: INTERPOLATION, value: ("_s(" + binding + ")") }]
  4100. }
  4101. if (el.tag === 'textarea' && (binding = el.attrsMap['v-model'])) {
  4102. return [{ type: INTERPOLATION, value: ("_s(" + binding + ")") }]
  4103. }
  4104. return el.children
  4105. ? nodesToSegments(el.children, state)
  4106. : []
  4107. }
  4108. function nodesToSegments (
  4109. children,
  4110. state
  4111. ) {
  4112. var segments = [];
  4113. for (var i = 0; i < children.length; i++) {
  4114. var c = children[i];
  4115. if (c.type === 1) {
  4116. segments.push.apply(segments, elementToSegments(c, state));
  4117. } else if (c.type === 2) {
  4118. segments.push({ type: INTERPOLATION, value: c.expression });
  4119. } else if (c.type === 3) {
  4120. segments.push({ type: RAW, value: escape(c.text) });
  4121. }
  4122. }
  4123. return segments
  4124. }
  4125. function flattenSegments (segments) {
  4126. var mergedSegments = [];
  4127. var textBuffer = '';
  4128. var pushBuffer = function () {
  4129. if (textBuffer) {
  4130. mergedSegments.push(JSON.stringify(textBuffer));
  4131. textBuffer = '';
  4132. }
  4133. };
  4134. for (var i = 0; i < segments.length; i++) {
  4135. var s = segments[i];
  4136. if (s.type === RAW) {
  4137. textBuffer += s.value;
  4138. } else if (s.type === INTERPOLATION) {
  4139. pushBuffer();
  4140. mergedSegments.push(("_ssrEscape(" + (s.value) + ")"));
  4141. } else if (s.type === EXPRESSION) {
  4142. pushBuffer();
  4143. mergedSegments.push(("(" + (s.value) + ")"));
  4144. }
  4145. }
  4146. pushBuffer();
  4147. return mergedSegments.join('+')
  4148. }
  4149. /* */
  4150. var createCompiler$1 = createCompilerCreator(function baseCompile (
  4151. template,
  4152. options
  4153. ) {
  4154. var ast = parse(template.trim(), options);
  4155. optimize$1(ast, options);
  4156. var code = generate$1(ast, options);
  4157. return {
  4158. ast: ast,
  4159. render: code.render,
  4160. staticRenderFns: code.staticRenderFns
  4161. }
  4162. });
  4163. /* */
  4164. var ref$1 = createCompiler$1(baseOptions);
  4165. var compile$1 = ref$1.compile;
  4166. var compileToFunctions$1 = ref$1.compileToFunctions;
  4167. /* */
  4168. exports.parseComponent = parseComponent;
  4169. exports.compile = compile;
  4170. exports.compileToFunctions = compileToFunctions;
  4171. exports.ssrCompile = compile$1;
  4172. exports.ssrCompileToFunctions = compileToFunctions$1;