build.js 110 KB

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