@@ -1264,45 +1264,45 @@ function proxy(vm, key) {
1264
1264
}
1265
1265
}
1266
1266
1267
- var VNode = function VNode ( tag , data , children , text , elm , ns , context , host , componentOptions ) {
1267
+ var VNode = // hoisted static node
1268
+ // compoennt placeholder node
1269
+ // rendered in this component's scope
1270
+ function VNode ( tag , data , children , text , elm , ns , context , componentOptions ) {
1268
1271
this . tag = tag ;
1269
1272
this . data = data ;
1270
1273
this . children = children ;
1271
1274
this . text = text ;
1272
1275
this . elm = elm ;
1273
1276
this . ns = ns ;
1274
1277
this . context = context ;
1275
- this . host = host ;
1276
1278
this . key = data && data . key ;
1277
1279
this . componentOptions = componentOptions ;
1278
1280
this . child = undefined ;
1279
1281
this . parent = undefined ;
1280
1282
this . raw = false ;
1281
1283
this . isStatic = false ;
1284
+ this . isRootInsert = true ;
1285
+ this . isComment = false ;
1282
1286
// apply construct hook.
1283
1287
// this is applied during render, before patch happens.
1284
1288
// unlike other hooks, this is applied on both client and server.
1285
1289
var constructHook = data && data . hook && data . hook . construct ;
1286
1290
if ( constructHook ) {
1287
1291
constructHook ( this ) ;
1288
1292
}
1289
- } ;
1293
+ } // necessary for enter transition check
1294
+ // contains raw HTML
1295
+ // component instance
1296
+ ;
1290
1297
1291
1298
var emptyVNode = function emptyVNode ( ) {
1292
- return new VNode ( undefined , undefined , undefined , '' ) ;
1299
+ var node = new VNode ( ) ;
1300
+ node . text = '' ;
1301
+ node . isComment = true ;
1302
+ return node ;
1293
1303
} ;
1294
1304
1295
1305
function normalizeChildren ( children , ns ) {
1296
- // Invoke children thunks. Components always receive their children
1297
- // as thunks so that they can perform the actual render inside their
1298
- // own dependency collection cycle. Also, since JSX automatically
1299
- // wraps component children in a thunk, we handle nested thunks to
1300
- // prevent situations such as <MyComponent>{ children }</MyComponent>
1301
- // from failing when it produces a double thunk.
1302
- while ( typeof children === 'function' ) {
1303
- children = children ( ) ;
1304
- }
1305
-
1306
1306
if ( isPrimitive ( children ) ) {
1307
1307
return [ createTextVNode ( children ) ] ;
1308
1308
}
@@ -1317,7 +1317,7 @@ function normalizeChildren(children, ns) {
1317
1317
} else if ( isPrimitive ( c ) ) {
1318
1318
if ( last && last . text ) {
1319
1319
last . text += String ( c ) ;
1320
- } else {
1320
+ } else if ( c !== '' ) {
1321
1321
// convert primitive to vnode
1322
1322
res . push ( createTextVNode ( c ) ) ;
1323
1323
}
@@ -1407,6 +1407,8 @@ function fnInvoker(o) {
1407
1407
} ;
1408
1408
}
1409
1409
1410
+ var activeInstance = null ;
1411
+
1410
1412
function initLifecycle ( vm ) {
1411
1413
var options = vm . $options ;
1412
1414
@@ -1467,13 +1469,16 @@ function lifecycleMixin(Vue) {
1467
1469
callHook ( vm , 'beforeUpdate' ) ;
1468
1470
}
1469
1471
var prevEl = vm . $el ;
1472
+ var prevActiveInstance = activeInstance ;
1473
+ activeInstance = vm ;
1470
1474
if ( ! vm . _vnode ) {
1471
1475
// Vue.prototype.__patch__ is injected in entry points
1472
1476
// based on the rendering backend used.
1473
1477
vm . $el = vm . __patch__ ( vm . $el , vnode , hydrating ) ;
1474
1478
} else {
1475
1479
vm . $el = vm . __patch__ ( vm . _vnode , vnode ) ;
1476
1480
}
1481
+ activeInstance = prevActiveInstance ;
1477
1482
vm . _vnode = vnode ;
1478
1483
// update __vue__ reference
1479
1484
if ( prevEl ) {
@@ -1493,6 +1498,7 @@ function lifecycleMixin(Vue) {
1493
1498
1494
1499
Vue . prototype . _updateFromParent = function ( propsData , listeners , parentVnode , renderChildren ) {
1495
1500
var vm = this ;
1501
+ var hasChildren = ! ! ( vm . $options . _renderChildren || renderChildren ) ;
1496
1502
vm . $options . _parentVnode = parentVnode ;
1497
1503
vm . $options . _renderChildren = renderChildren ;
1498
1504
// update props
@@ -1517,6 +1523,10 @@ function lifecycleMixin(Vue) {
1517
1523
vm . $options . _parentListeners = listeners ;
1518
1524
vm . _updateListeners ( listeners , oldListeners ) ;
1519
1525
}
1526
+ // force udpate if has children
1527
+ if ( hasChildren ) {
1528
+ vm . $forceUpdate ( ) ;
1529
+ }
1520
1530
} ;
1521
1531
1522
1532
Vue . prototype . $forceUpdate = function ( ) {
@@ -1581,12 +1591,7 @@ function callHook(vm, hook) {
1581
1591
var hooks = { init : init , prepatch : prepatch , insert : insert , destroy : destroy } ;
1582
1592
var hooksToMerge = Object . keys ( hooks ) ;
1583
1593
1584
- function createComponent ( Ctor , data , parent , context , host , _children , tag ) {
1585
- // ensure children is a thunk
1586
- if ( process . env . NODE_ENV !== 'production' && _children && typeof _children !== 'function' ) {
1587
- warn ( 'A component\'s children should be a function that returns the ' + 'children array. This allows the component to track the children ' + 'dependencies and optimizes re-rendering.' ) ;
1588
- }
1589
-
1594
+ function createComponent ( Ctor , data , context , children , tag ) {
1590
1595
if ( ! Ctor ) {
1591
1596
return ;
1592
1597
}
@@ -1597,7 +1602,7 @@ function createComponent(Ctor, data, parent, context, host, _children, tag) {
1597
1602
1598
1603
if ( typeof Ctor !== 'function' ) {
1599
1604
if ( process . env . NODE_ENV !== 'production' ) {
1600
- warn ( 'Invalid Component definition: ' + Ctor , parent ) ;
1605
+ warn ( 'Invalid Component definition: ' + Ctor , context ) ;
1601
1606
}
1602
1607
return ;
1603
1608
}
@@ -1609,9 +1614,8 @@ function createComponent(Ctor, data, parent, context, host, _children, tag) {
1609
1614
} else {
1610
1615
Ctor = resolveAsyncComponent ( Ctor , function ( ) {
1611
1616
// it's ok to queue this on every render because
1612
- // $forceUpdate is buffered. this is only called
1613
- // if the
1614
- parent . $forceUpdate ( ) ;
1617
+ // $forceUpdate is buffered by the scheduler.
1618
+ context . $forceUpdate ( ) ;
1615
1619
} ) ;
1616
1620
if ( ! Ctor ) {
1617
1621
// return nothing if this is indeed an async component
@@ -1637,15 +1641,13 @@ function createComponent(Ctor, data, parent, context, host, _children, tag) {
1637
1641
} ) ;
1638
1642
}
1639
1643
return {
1640
- v : Ctor . options . render . call ( null , parent . $createElement , {
1644
+ v : Ctor . options . render . call ( null , context . $createElement , {
1641
1645
props : props ,
1642
- parent : parent ,
1643
1646
data : data ,
1644
- children : function children ( ) {
1645
- return normalizeChildren ( _children ) ;
1646
- } ,
1647
+ parent : context ,
1648
+ children : normalizeChildren ( children ) ,
1647
1649
slots : function slots ( ) {
1648
- return resolveSlots ( _children ) ;
1650
+ return resolveSlots ( children ) ;
1649
1651
}
1650
1652
} )
1651
1653
} ;
@@ -1671,16 +1673,17 @@ function createComponent(Ctor, data, parent, context, host, _children, tag) {
1671
1673
1672
1674
// return a placeholder vnode
1673
1675
var name = Ctor . options . name || tag ;
1674
- 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 : _children } ) ;
1676
+ var vnode = new VNode ( 'vue-component-' + Ctor . cid + ( name ? '-' + name : '' ) , data , undefined , undefined , undefined , undefined , context , { Ctor : Ctor , propsData : propsData , listeners : listeners , tag : tag , children : children } ) ;
1675
1677
return vnode ;
1676
1678
}
1677
1679
1678
- function createComponentInstanceForVnode ( vnode // we know it's MountedComponentVNode but flow doesn't
1680
+ function createComponentInstanceForVnode ( vnode , // we know it's MountedComponentVNode but flow doesn't
1681
+ parent // activeInstance in lifecycle state
1679
1682
) {
1680
1683
var vnodeComponentOptions = vnode . componentOptions ;
1681
1684
var options = {
1682
1685
_isComponent : true ,
1683
- parent : vnodeComponentOptions . parent ,
1686
+ parent : parent ,
1684
1687
propsData : vnodeComponentOptions . propsData ,
1685
1688
_componentTag : vnodeComponentOptions . tag ,
1686
1689
_parentVnode : vnode ,
@@ -1698,7 +1701,7 @@ function createComponentInstanceForVnode(vnode // we know it's MountedComponentV
1698
1701
1699
1702
function init ( vnode , hydrating ) {
1700
1703
if ( ! vnode . child ) {
1701
- var child = vnode . child = createComponentInstanceForVnode ( vnode ) ;
1704
+ var child = vnode . child = createComponentInstanceForVnode ( vnode , activeInstance ) ;
1702
1705
child . $mount ( hydrating ? vnode . elm : undefined , hydrating ) ;
1703
1706
}
1704
1707
}
@@ -1711,10 +1714,6 @@ function prepatch(oldVnode, vnode) {
1711
1714
vnode , // new parent vnode
1712
1715
options . children // new children
1713
1716
) ;
1714
- // always update abstract components.
1715
- if ( child . $options . abstract ) {
1716
- child . $forceUpdate ( ) ;
1717
- }
1718
1717
}
1719
1718
1720
1719
function insert ( vnode ) {
@@ -1853,12 +1852,6 @@ function createElement(tag, data, children) {
1853
1852
}
1854
1853
1855
1854
function _createElement ( context , tag , data , children ) {
1856
- var parent = renderState . activeInstance ;
1857
- var host = context !== parent ? parent : undefined ;
1858
- if ( ! parent ) {
1859
- process . env . NODE_ENV !== 'production' && warn ( 'createElement cannot be called outside of component ' + 'render functions.' ) ;
1860
- return ;
1861
- }
1862
1855
if ( data && data . __ob__ ) {
1863
1856
process . env . NODE_ENV !== 'production' && warn ( 'Avoid using observed data object as vnode data: ' + JSON . stringify ( data ) + '\n' + 'Always create fresh vnode data objects in each render!' , context ) ;
1864
1857
return ;
@@ -1872,26 +1865,22 @@ function _createElement(context, tag, data, children) {
1872
1865
var ns = config . getTagNamespace ( tag ) ;
1873
1866
if ( config . isReservedTag ( tag ) ) {
1874
1867
// platform built-in elements
1875
- return new VNode ( tag , data , normalizeChildren ( children , ns ) , undefined , undefined , ns , context , host ) ;
1868
+ return new VNode ( tag , data , normalizeChildren ( children , ns ) , undefined , undefined , ns , context ) ;
1876
1869
} else if ( Ctor = resolveAsset ( context . $options , 'components' , tag ) ) {
1877
1870
// component
1878
- return createComponent ( Ctor , data , parent , context , host , children , tag ) ;
1871
+ return createComponent ( Ctor , data , context , children , tag ) ;
1879
1872
} else {
1880
1873
// unknown or unlisted namespaced elements
1881
1874
// check at runtime because it may get assigned a namespace when its
1882
1875
// parent normalizes children
1883
- return new VNode ( tag , data , normalizeChildren ( children , ns ) , undefined , undefined , ns , context , host ) ;
1876
+ return new VNode ( tag , data , normalizeChildren ( children , ns ) , undefined , undefined , ns , context ) ;
1884
1877
}
1885
1878
} else {
1886
1879
// direct component options / constructor
1887
- return createComponent ( tag , data , parent , context , host , children ) ;
1880
+ return createComponent ( tag , data , context , children ) ;
1888
1881
}
1889
1882
}
1890
1883
1891
- var renderState = {
1892
- activeInstance : null
1893
- } ;
1894
-
1895
1884
function initRender ( vm ) {
1896
1885
vm . $vnode = null ; // the placeholder node in parent tree
1897
1886
vm . _vnode = null ; // the root of the child tree
@@ -1912,11 +1901,6 @@ function renderMixin(Vue) {
1912
1901
1913
1902
Vue . prototype . _render = function ( ) {
1914
1903
var vm = this ;
1915
-
1916
- // set current active instance
1917
- var prev = renderState . activeInstance ;
1918
- renderState . activeInstance = vm ;
1919
-
1920
1904
var _vm$$options = vm . $options ;
1921
1905
var render = _vm$$options . render ;
1922
1906
var staticRenderFns = _vm$$options . staticRenderFns ;
@@ -1965,8 +1949,6 @@ function renderMixin(Vue) {
1965
1949
}
1966
1950
// set parent
1967
1951
vnode . parent = _parentVnode ;
1968
- // restore render state
1969
- renderState . activeInstance = prev ;
1970
1952
return vnode ;
1971
1953
} ;
1972
1954
@@ -2034,8 +2016,12 @@ function renderMixin(Vue) {
2034
2016
}
2035
2017
var data = vnode . data ;
2036
2018
for ( var key in value ) {
2037
- var hash = asProp || config . mustUseProp ( key ) ? data . domProps || ( data . domProps = { } ) : data . attrs || ( data . attrs = { } ) ;
2038
- hash [ key ] = value [ key ] ;
2019
+ if ( key === 'class' || key === 'style' ) {
2020
+ data [ key ] = value [ key ] ;
2021
+ } else {
2022
+ var hash = asProp || config . mustUseProp ( key ) ? data . domProps || ( data . domProps = { } ) : data . attrs || ( data . attrs = { } ) ;
2023
+ hash [ key ] = value [ key ] ;
2024
+ }
2039
2025
}
2040
2026
}
2041
2027
}
@@ -3730,7 +3716,6 @@ var warn$2 = void 0;
3730
3716
var transforms$1 = void 0 ;
3731
3717
var dataGenFns = void 0 ;
3732
3718
var platformDirectives = void 0 ;
3733
- var isPlatformReservedTag$1 = void 0 ;
3734
3719
var staticRenderFns = void 0 ;
3735
3720
var currentOptions = void 0 ;
3736
3721
@@ -3743,7 +3728,6 @@ function generate(ast, options) {
3743
3728
transforms$1 = pluckModuleFunction ( options . modules , 'transformCode' ) ;
3744
3729
dataGenFns = pluckModuleFunction ( options . modules , 'genData' ) ;
3745
3730
platformDirectives = options . directives || { } ;
3746
- isPlatformReservedTag$1 = options . isReservedTag || no ;
3747
3731
var code = ast ? genElement ( ast ) : '_h("div")' ;
3748
3732
// console.log(code)
3749
3733
staticRenderFns = prevStaticRenderFns ;
@@ -3774,9 +3758,7 @@ function genElement(el) {
3774
3758
code = genComponent ( el ) ;
3775
3759
} else {
3776
3760
var data = genData ( el ) ;
3777
- // if the element is potentially a component,
3778
- // wrap its children as a thunk.
3779
- var children = ! el . inlineTemplate ? genChildren ( el , ! isPlatformReservedTag$1 ( el . tag ) /* asThunk */ ) : null ;
3761
+ var children = el . inlineTemplate ? null : genChildren ( el ) ;
3780
3762
code = '_h(\'' + el . tag + '\'' + ( data ? ',' + data : '' // data
3781
3763
) + ( children ? ',' + children : '' // children
3782
3764
) + ')' ;
@@ -3915,12 +3897,10 @@ function genDirectives(el) {
3915
3897
}
3916
3898
}
3917
3899
3918
- function genChildren ( el , asThunk ) {
3919
- if ( ! el . children . length ) {
3920
- return ;
3900
+ function genChildren ( el ) {
3901
+ if ( el . children . length ) {
3902
+ return '[' + el . children . map ( genNode ) . join ( ',' ) + ']' ;
3921
3903
}
3922
- var code = '[' + el . children . map ( genNode ) . join ( ',' ) + ']' ;
3923
- return asThunk ? 'function(){return ' + code + '}' : code ;
3924
3904
}
3925
3905
3926
3906
function genNode ( node ) {
@@ -3943,7 +3923,7 @@ function genSlot(el) {
3943
3923
}
3944
3924
3945
3925
function genComponent ( el ) {
3946
- var children = genChildren ( el , true ) ;
3926
+ var children = genChildren ( el ) ;
3947
3927
return '_h(' + el . component + ',' + genData ( el ) + ( children ? ',' + children : '' ) + ')' ;
3948
3928
}
3949
3929
@@ -4053,7 +4033,9 @@ function transformNode(el, options) {
4053
4033
warn ( 'class="' + staticClass + '": ' + 'Interpolation inside attributes has been deprecated. ' + 'Use v-bind or the colon shorthand instead.' ) ;
4054
4034
}
4055
4035
}
4056
- el . staticClass = JSON . stringify ( staticClass ) ;
4036
+ if ( staticClass ) {
4037
+ el . staticClass = JSON . stringify ( staticClass ) ;
4038
+ }
4057
4039
var classBinding = getBindingAttr ( el , 'class' , false /* getStatic */ ) ;
4058
4040
if ( classBinding ) {
4059
4041
el . classBinding = classBinding ;
0 commit comments