1
1
/*!
2
- * Vue.js v2.0.0-alpha.2
2
+ * Vue.js v2.0.0-alpha.3
3
3
* (c) 2014-2016 Evan You
4
4
* Released under the MIT License.
5
5
*/
1279
1279
}
1280
1280
1281
1281
var VNode = function ( ) {
1282
- function VNode ( tag , data , children , text , elm , ns , context , componentOptions ) {
1282
+ function VNode ( tag , data , children , text , elm , ns , context , host , componentOptions ) {
1283
1283
this . tag = tag ;
1284
1284
this . data = data ;
1285
1285
this . children = children ;
1286
1286
this . text = text ;
1287
1287
this . elm = elm ;
1288
1288
this . ns = ns ;
1289
1289
this . context = context ;
1290
+ this . host = host ;
1290
1291
this . key = data && data . key ;
1291
1292
this . componentOptions = componentOptions ;
1292
1293
this . child = undefined ;
1293
1294
this . parent = undefined ;
1295
+ this . raw = false ;
1294
1296
// apply construct hook.
1295
1297
// this is applied during render, before patch happens.
1296
1298
// unlike other hooks, this is applied on both client and server.
1557
1559
var hooks = { init : init , prepatch : prepatch , insert : insert , destroy : destroy } ;
1558
1560
var hooksToMerge = Object . keys ( hooks ) ;
1559
1561
1560
- function createComponent ( Ctor , data , parent , context , tag ) {
1562
+ function createComponent ( Ctor , data , parent , context , host , tag ) {
1561
1563
if ( ! Ctor ) {
1562
1564
return ;
1563
1565
}
1607
1609
1608
1610
// return a placeholder vnode
1609
1611
var name = Ctor . options . name || tag ;
1610
- var vnode = new VNode ( 'vue-component-' + Ctor . cid + ( name ? '-' + name : '' ) , data , undefined , undefined , undefined , undefined , context , { Ctor : Ctor , propsData : propsData , listeners : listeners , parent : parent , tag : tag , children : undefined }
1612
+ var vnode = new VNode ( 'vue-component-' + Ctor . cid + ( name ? '-' + name : '' ) , data , undefined , undefined , undefined , undefined , context , host , { Ctor : Ctor , propsData : propsData , listeners : listeners , parent : parent , tag : tag , children : undefined }
1611
1613
// children to be set later by renderElementWithChildren,
1612
1614
// but before the init hook
1613
1615
) ;
1789
1791
// make sure to expose real self instead of proxy
1790
1792
var context = this . _self ;
1791
1793
var parent = renderState . activeInstance ;
1794
+ var host = context !== parent ? parent : undefined ;
1792
1795
if ( ! parent ) {
1793
1796
"development" !== 'production' && warn ( 'createElement cannot be called outside of component ' + 'render functions.' ) ;
1794
1797
return ;
1800
1803
if ( typeof tag === 'string' ) {
1801
1804
var Ctor = void 0 ;
1802
1805
if ( config . isReservedTag ( tag ) ) {
1803
- return new VNode ( tag , data , undefined , undefined , undefined , namespace , context ) ;
1806
+ return new VNode ( tag , data , undefined , undefined , undefined , namespace , context , host ) ;
1804
1807
} else if ( Ctor = resolveAsset ( context . $options , 'components' , tag ) ) {
1805
- return createComponent ( Ctor , data , parent , context , tag ) ;
1808
+ return createComponent ( Ctor , data , parent , context , host , tag ) ;
1806
1809
} else {
1807
1810
if ( "development" !== 'production' ) {
1808
1811
if ( ! namespace && config . isUnknownElement ( tag ) ) {
1809
1812
warn ( 'Unknown custom element: <' + tag + '> - did you ' + 'register the component correctly? For recursive components, ' + 'make sure to provide the "name" option.' ) ;
1810
1813
}
1811
1814
}
1812
- return new VNode ( tag , data , undefined , undefined , undefined , namespace , context ) ;
1815
+ return new VNode ( tag , data , undefined , undefined , undefined , namespace , context , host ) ;
1813
1816
}
1814
1817
} else {
1815
- return createComponent ( tag , data , parent , context ) ;
1818
+ return createComponent ( tag , data , parent , context , host ) ;
1816
1819
}
1817
1820
}
1818
1821
1821
1824
}
1822
1825
1823
1826
function renderStatic ( index ) {
1824
- return this . _staticTrees [ index ] ;
1827
+ return this . _staticTrees [ index ] || ( this . _staticTrees [ index ] = this . $options . staticRenderFns [ index ] . call ( this . _renderProxy ) ) ;
1825
1828
}
1826
1829
1827
1830
var renderState = {
1861
1864
var _parentVnode = _vm$$options . _parentVnode ;
1862
1865
1863
1866
1864
- if ( staticRenderFns && ! vm . _staticTrees ) {
1865
- // render static sub-trees for once on initial render
1866
- renderStaticTrees ( vm , staticRenderFns ) ;
1867
+ if ( staticRenderFns && ! this . _staticTrees ) {
1868
+ this . _staticTrees = [ ] ;
1867
1869
}
1870
+
1868
1871
// resolve slots. becaues slots are rendered in parent scope,
1869
1872
// we set the activeInstance to parent.
1870
1873
if ( _renderChildren ) {
1950
1953
} ;
1951
1954
}
1952
1955
1953
- function renderStaticTrees ( vm , fns ) {
1954
- var trees = vm . _staticTrees = new Array ( fns . length ) ;
1955
- for ( var i = 0 ; i < fns . length ; i ++ ) {
1956
- trees [ i ] = fns [ i ] . call ( vm . _renderProxy ) ;
1957
- }
1958
- }
1959
-
1960
1956
function resolveSlots ( vm , renderChildren ) {
1961
1957
if ( renderChildren ) {
1962
1958
var children = normalizeChildren ( renderChildren ) ;
2761
2757
}
2762
2758
} ) ;
2763
2759
2764
- Vue . version = '2.0.0-alpha.2 ' ;
2760
+ Vue . version = '2.0.0-alpha.3 ' ;
2765
2761
2766
2762
// attributes that should be using props for binding
2767
2763
var mustUseProp = makeMap ( 'value,selected,checked,muted' ) ;
2770
2766
2771
2767
var isBooleanAttr = makeMap ( 'allowfullscreen,async,autofocus,autoplay,checked,compact,controls,declare,' + 'default,defaultchecked,defaultmuted,defaultselected,defer,disabled,' + 'enabled,formnovalidate,hidden,indeterminate,inert,ismap,itemscope,loop,multiple,' + 'muted,nohref,noresize,noshade,novalidate,nowrap,open,pauseonexit,readonly,' + 'required,reversed,scoped,seamless,selected,sortable,translate,' + 'truespeed,typemustmatch,visible' ) ;
2772
2768
2769
+ var isAttr = makeMap ( 'accept,accept-charset,accesskey,action,align,alt,async,autocomplete,' + 'autofocus,autoplay,autosave,bgcolor,border,buffered,challenge,charset,' + 'checked,cite,class,code,codebase,color,cols,colspan,content,http-equiv,' + 'name,contenteditable,contextmenu,controls,coords,data,datetime,default,' + 'defer,dir,dirname,disabled,download,draggable,dropzone,enctype,method,for,' + 'form,formaction,headers,<th>,height,hidden,high,href,hreflang,http-equiv,' + 'icon,id,ismap,itemprop,keytype,kind,label,lang,language,list,loop,low,' + 'manifest,max,maxlength,media,method,GET,POST,min,multiple,email,file,' + 'muted,name,novalidate,open,optimum,pattern,ping,placeholder,poster,' + 'preload,radiogroup,readonly,rel,required,reversed,rows,rowspan,sandbox,' + 'scope,scoped,seamless,selected,shape,size,type,text,password,sizes,span,' + 'spellcheck,src,srcdoc,srclang,srcset,start,step,style,summary,tabindex,' + 'target,title,type,usemap,value,width,wrap' ) ;
2770
+
2773
2771
var xlinkNS = 'http://www.w3.org/1999/xlink' ;
2774
2772
2775
2773
var isXlink = function isXlink ( name ) {
@@ -3096,6 +3094,9 @@ var nodeOps = Object.freeze({
3096
3094
// of going through the normal attribute patching process.
3097
3095
function setScope ( vnode ) {
3098
3096
var i = void 0 ;
3097
+ if ( isDef ( i = vnode . host ) && isDef ( i = i . $options . _scopeId ) ) {
3098
+ nodeOps . setAttribute ( vnode . elm , i , '' ) ;
3099
+ }
3099
3100
if ( isDef ( i = vnode . context ) && isDef ( i = i . $options . _scopeId ) ) {
3100
3101
nodeOps . setAttribute ( vnode . elm , i , '' ) ;
3101
3102
}
@@ -4751,12 +4752,12 @@ var nodeOps = Object.freeze({
4751
4752
}
4752
4753
4753
4754
var dirRE = / ^ v - | ^ @ | ^ : / ;
4755
+ var forAliasRE = / ( .* ) \s + (?: i n | o f ) \s + ( .* ) / ;
4756
+ var forIteratorRE = / \( ( [ ^ , ] * ) , ( [ ^ , ] * ) (?: , ( [ ^ , ] * ) ) ? \) / ;
4754
4757
var bindRE = / ^ : | ^ v - b i n d : / ;
4755
4758
var onRE = / ^ @ | ^ v - o n : / ;
4756
4759
var argRE = / : ( .* ) $ / ;
4757
4760
var modifierRE = / \. [ ^ \. ] + / g;
4758
- var forAliasRE = / ( .* ) \s + (?: i n | o f ) \s + ( .* ) / ;
4759
- var forIteratorRE = / \( ( [ ^ , ] * ) , ( [ ^ , ] * ) (?: , ( [ ^ , ] * ) ) ? \) / ;
4760
4761
var camelRE = / [ a - z \d ] [ A - Z ] / ;
4761
4762
4762
4763
var decodeHTMLCached = cached ( decodeHTML ) ;
@@ -4782,6 +4783,7 @@ var nodeOps = Object.freeze({
4782
4783
postTransforms = pluckModuleFunction ( options . modules , 'postTransformNode' ) ;
4783
4784
delimiters = options . delimiters ;
4784
4785
var stack = [ ] ;
4786
+ var preserveWhitespace = options . preserveWhitespace !== false ;
4785
4787
var root = void 0 ;
4786
4788
var currentParent = void 0 ;
4787
4789
var inPre = false ;
@@ -4913,7 +4915,7 @@ var nodeOps = Object.freeze({
4913
4915
}
4914
4916
text = currentParent . tag === 'pre' || text . trim ( ) ? decodeHTMLCached ( text )
4915
4917
// only preserve whitespace if its not right after a starting tag
4916
- : currentParent . children . length ? ' ' : '' ;
4918
+ : preserveWhitespace && currentParent . children . length ? ' ' : '' ;
4917
4919
if ( text ) {
4918
4920
var expression = void 0 ;
4919
4921
if ( ! inPre && text !== ' ' && ( expression = parseText ( text , delimiters ) ) ) {
@@ -5344,9 +5346,9 @@ var nodeOps = Object.freeze({
5344
5346
}
5345
5347
5346
5348
function genElement ( el ) {
5347
- if ( el . for ) {
5349
+ if ( el . for && ! el . forProcessed ) {
5348
5350
return genFor ( el ) ;
5349
- } else if ( el . if ) {
5351
+ } else if ( el . if && ! el . ifProcessed ) {
5350
5352
return genIf ( el ) ;
5351
5353
} else if ( el . tag === 'template' && ! el . slotTarget ) {
5352
5354
return genChildren ( el ) || 'void 0' ;
@@ -5388,7 +5390,7 @@ var nodeOps = Object.freeze({
5388
5390
5389
5391
function genIf ( el ) {
5390
5392
var exp = el . if ;
5391
- el . if = null ; // avoid recursion
5393
+ el . ifProcessed = true ; // avoid recursion
5392
5394
return '(' + exp + ')?' + genElement ( el ) + ':' + genElse ( el ) ;
5393
5395
}
5394
5396
@@ -5401,7 +5403,7 @@ var nodeOps = Object.freeze({
5401
5403
var alias = el . alias ;
5402
5404
var iterator1 = el . iterator1 ? ',' + el . iterator1 : '' ;
5403
5405
var iterator2 = el . iterator2 ? ',' + el . iterator2 : '' ;
5404
- el . for = null ; // avoid recursion
5406
+ el . forProcessed = true ; // avoid recursion
5405
5407
return '(' + exp + ')&&_l((' + exp + '),' + ( 'function(' + alias + iterator1 + iterator2 + '){' ) + ( 'return ' + genElement ( el ) ) + '})' ;
5406
5408
}
5407
5409
@@ -5579,7 +5581,10 @@ var nodeOps = Object.freeze({
5579
5581
} ;
5580
5582
}
5581
5583
5582
- var keywordRE = new RegExp ( '\\b' + ( 'do,if,in,for,let,new,try,var,case,else,with,await,break,catch,class,const,' + 'super,throw,while,yield,delete,export,import,return,switch,typeof,default,' + 'extends,finally,continue,debugger,function,arguments,instanceof' ) . split ( ',' ) . join ( '\\b|\\b' ) + '\\b' ) ;
5584
+ // operators like typeof, instanceof and in are allowed
5585
+ var prohibitedKeywordRE = new RegExp ( '\\b' + ( 'do,if,for,let,new,try,var,case,else,with,await,break,catch,class,const,' + 'super,throw,while,yield,delete,export,import,return,switch,default,' + 'extends,finally,continue,debugger,function,arguments' ) . split ( ',' ) . join ( '\\b|\\b' ) + '\\b' ) ;
5586
+ // check valid identifier for v-for
5587
+ var identRE = / [ ^ \w $ \. ] (?: [ A - Z a - z _ $ ] [ \w $ ] * ) / ;
5583
5588
5584
5589
// detect problematic expressions in a template
5585
5590
function detectErrors ( ast ) {
@@ -5596,7 +5601,11 @@ var nodeOps = Object.freeze({
5596
5601
if ( dirRE . test ( name ) ) {
5597
5602
var value = node . attrsMap [ name ] ;
5598
5603
if ( value ) {
5599
- checkExpression ( value , name + '="' + value + '"' , errors ) ;
5604
+ if ( name === 'v-for' ) {
5605
+ checkFor ( node , 'v-for="' + value + '"' , errors ) ;
5606
+ } else {
5607
+ checkExpression ( value , name + '="' + value + '"' , errors ) ;
5608
+ }
5600
5609
}
5601
5610
}
5602
5611
}
@@ -5610,14 +5619,27 @@ var nodeOps = Object.freeze({
5610
5619
}
5611
5620
}
5612
5621
5622
+ function checkFor ( node , text , errors ) {
5623
+ checkExpression ( node . for || '' , text , errors ) ;
5624
+ checkIdentifier ( node . alias , 'v-for alias' , text , errors ) ;
5625
+ checkIdentifier ( node . iterator1 , 'v-for iterator' , text , errors ) ;
5626
+ checkIdentifier ( node . iterator2 , 'v-for iterator' , text , errors ) ;
5627
+ }
5628
+
5629
+ function checkIdentifier ( ident , type , text , errors ) {
5630
+ if ( typeof ident === 'string' && ! identRE . test ( ident ) ) {
5631
+ errors . push ( '- invalid ' + type + ' "' + ident + '" in expression: ' + text ) ;
5632
+ }
5633
+ }
5634
+
5613
5635
function checkExpression ( exp , text , errors ) {
5614
5636
exp = stripToString ( exp ) ;
5615
- var keywordMatch = exp . match ( keywordRE ) ;
5637
+ var keywordMatch = exp . match ( prohibitedKeywordRE ) ;
5616
5638
if ( keywordMatch ) {
5617
5639
errors . push ( '- avoid using JavaScript keyword as property name: ' + ( '"' + keywordMatch [ 0 ] + '" in expression ' + text ) ) ;
5618
5640
} else {
5619
5641
try {
5620
- new Function ( exp ) ;
5642
+ new Function ( 'return ' + exp ) ;
5621
5643
} catch ( e ) {
5622
5644
errors . push ( '- invalid expression: ' + text ) ;
5623
5645
}
0 commit comments