@@ -71,8 +71,9 @@ function Compiler (vm, options) {
7171
7272 // set parent VM
7373 // and register child id on parent
74- var childId = utils . attr ( el , 'id' )
74+ var childId = utils . attr ( el , 'component- id' )
7575 if ( parent ) {
76+ parent . childCompilers . push ( compiler )
7677 def ( vm , '$parent' , parent . vm )
7778 if ( childId ) {
7879 compiler . childId = childId
@@ -217,18 +218,20 @@ CompilerProto.setupObserver = function () {
217218 */
218219CompilerProto . compile = function ( node , root ) {
219220
220- var compiler = this
221+ var compiler = this ,
222+ nodeType = node . nodeType ,
223+ tagName = node . tagName
221224
222- if ( node . nodeType === 1 ) { // a normal node
225+ if ( nodeType === 1 && tagName !== 'SCRIPT' ) { // a normal node
223226
224227 // skip anything with v-pre
225228 if ( utils . attr ( node , 'pre' ) !== null ) return
226229
227230 // special attributes to check
228231 var repeatExp ,
229- componentId ,
232+ componentExp ,
230233 partialId ,
231- customElementFn = compiler . getOption ( 'elements' , node . tagName . toLowerCase ( ) )
234+ directive
232235
233236 // It is important that we access these attributes
234237 // procedurally because the order matters.
@@ -242,21 +245,25 @@ CompilerProto.compile = function (node, root) {
242245 if ( repeatExp = utils . attr ( node , 'repeat' ) ) {
243246
244247 // repeat block cannot have v-id at the same time.
245- var directive = Directive . parse ( config . attrs . repeat , repeatExp , compiler , node )
248+ directive = Directive . parse ( config . attrs . repeat , repeatExp , compiler , node )
246249 if ( directive ) {
247250 compiler . bindDirective ( directive )
248251 }
249252
250- // custom elements has 2nd highest priority
251- } else if ( ! root && customElementFn ) {
252-
253- addChild ( customElementFn )
254-
255- // v-component has 3rd highest priority
256- } else if ( ! root && ( componentId = utils . attr ( node , 'component' ) ) ) {
253+ // v-component has 2nd highest priority
254+ } else if ( ! root && ( componentExp = utils . attr ( node , 'component' ) ) ) {
257255
258- var ChildVM = compiler . getOption ( 'components' , componentId )
259- if ( ChildVM ) addChild ( ChildVM )
256+ directive = Directive . parse ( config . attrs . component , componentExp , compiler , node )
257+ if ( directive ) {
258+ // component directive is a bit different from the others.
259+ // when it has no argument, it should be treated as a
260+ // simple directive with its key as the argument.
261+ if ( componentExp . indexOf ( ':' ) === - 1 ) {
262+ directive . isSimple = true
263+ directive . arg = directive . key
264+ }
265+ compiler . bindDirective ( directive )
266+ }
260267
261268 } else {
262269
@@ -277,27 +284,12 @@ CompilerProto.compile = function (node, root) {
277284 compiler . compileNode ( node )
278285 }
279286
280- } else if ( node . nodeType === 3 ) { // text node
287+ } else if ( nodeType === 3 ) { // text node
281288
282289 compiler . compileTextNode ( node )
283290
284291 }
285292
286- function addChild ( Ctor ) {
287- if ( utils . isConstructor ( Ctor ) ) {
288- var child = new Ctor ( {
289- el : node ,
290- child : true ,
291- compilerOptions : {
292- parentCompiler : compiler
293- }
294- } )
295- compiler . childCompilers . push ( child . $compiler )
296- } else {
297- // simply call the function
298- Ctor ( node )
299- }
300- }
301293}
302294
303295/**
@@ -412,13 +404,13 @@ CompilerProto.bindDirective = function (directive) {
412404 binding . instances . push ( directive )
413405 directive . binding = binding
414406
415- var value = binding . value
416407 // invoke bind hook if exists
417408 if ( directive . bind ) {
418- directive . bind ( value )
409+ directive . bind ( )
419410 }
420411
421412 // set initial value
413+ var value = binding . value
422414 if ( value !== undefined ) {
423415 if ( binding . isComputed ) {
424416 directive . refresh ( value )
@@ -454,11 +446,11 @@ CompilerProto.createBinding = function (key, isExp, isFn) {
454446 bindings [ key ] = binding
455447 // make sure the key exists in the object so it can be observed
456448 // by the Observer!
457- Observer . ensurePath ( compiler . vm , key )
458449 if ( binding . root ) {
459450 // this is a root level binding. we need to define getter/setters for it.
460451 compiler . define ( key , binding )
461452 } else {
453+ Observer . ensurePath ( compiler . vm , key )
462454 var parentKey = key . slice ( 0 , key . lastIndexOf ( '.' ) )
463455 if ( ! hasOwn . call ( bindings , parentKey ) ) {
464456 // this is a nested value binding, but the binding for its parent
@@ -488,9 +480,10 @@ CompilerProto.define = function (key, binding) {
488480 // computed property
489481 compiler . markComputed ( binding )
490482 } else if ( type === 'Object' || type === 'Array' ) {
491- // observe objects later, becase there might be more keys
492- // to be added to it. we also want to emit all the set events
493- // after all values are available.
483+ // observe objects later, because there might be more keys
484+ // to be added to it during Observer.ensurePath().
485+ // we also want to emit all the set events after all values
486+ // are available.
494487 compiler . observables . push ( binding )
495488 }
496489
0 commit comments