function Compiler (vm, options) {

    var compiler = this

    // default state
    compiler.init       = true
    compiler.repeat     = false
    compiler.destroyed  = false
    compiler.delayReady = false

    // process and extend options
    options = compiler.options = options || makeHash()
    utils.processOptions(options)

    // copy data, methods & compiler options
    var data = compiler.data = options.data || {}
    extend(vm, data, true)
    extend(vm, options.methods, true)
    extend(compiler, options.compilerOptions)

    // initialize element
    var el = compiler.el = compiler.setupElement(options)
    log('\nnew VM instance: ' + el.tagName + '\n')

    // set compiler properties
    compiler.vm = el.vue_vm = vm
    compiler.bindings = makeHash()
    compiler.dirs = []
    compiler.deferred = []
    compiler.exps = []
    compiler.computed = []
    compiler.children = []
    compiler.emitter = new Emitter()
    compiler.emitter._ctx = vm
    compiler.delegators = makeHash()

    // set inenumerable VM properties
    def(vm, '$', makeHash())
    def(vm, '$el', el)
    def(vm, '$options', options)
    def(vm, '$compiler', compiler)

    // set parent VM
    // and register child id on parent
    var parentVM = options.parent,
        childId = utils.attr(el, 'ref')
    if (parentVM) {
        compiler.parent = parentVM.$compiler
        parentVM.$compiler.children.push(compiler)
        def(vm, '$parent', parentVM)
        if (childId) {
            compiler.childId = childId
            parentVM.$[childId] = vm
        }
    }

    // set root
    def(vm, '$root', getRoot(compiler).vm)

    // setup observer
    compiler.setupObserver()

    // create bindings for computed properties
    var computed = options.computed
    if (computed) {
        for (var key in computed) {
            compiler.createBinding(key)
        }
    }

    // copy paramAttributes
    if (options.paramAttributes) {
        options.paramAttributes.forEach(function (attr) {
            var val = el.getAttribute(attr)
            vm[attr] = (isNaN(val) || val === null)
                ? val
                : Number(val)
        })
    }

    // beforeCompile hook
    compiler.execHook('created')

    // the user might have set some props on the vm 
    // so copy it back to the data...
    extend(data, vm)

    // observe the data
    compiler.observeData(data)
    
    // for repeated items, create index/key bindings
    // because they are ienumerable
    if (compiler.repeat) {
        compiler.createBinding('$index')
        if (data.$key) compiler.createBinding('$key')
    }

    // now parse the DOM, during which we will create necessary bindings
    // and bind the parsed directives
    compiler.compile(el, true)

    // bind deferred directives (child components)
    compiler.deferred.forEach(compiler.bindDirective, compiler)

    // extract dependencies for computed properties
    compiler.parseDeps()

    // done!
    compiler.rawContent = null
    compiler.init = false

    // post compile / ready hook
    if (!compiler.delayReady) {
        compiler.execHook('ready')
    }
}
/**
 *  The DOM compiler
 *  scans a DOM node and compile bindings for a ViewModel
 */
The DOM compiler
scans a DOM node and compile bindings for a ViewModel
The DOM compiler scans a DOM node and compile bindings for a ViewModel
function Compiler (vm, options) {
    var compiler = this
    compiler.init       = true
    compiler.repeat     = false
    compiler.destroyed  = false
    compiler.delayReady = false
    options = compiler.options = options || makeHash()
    utils.processOptions(options)
    var data = compiler.data = options.data || {}
    extend(vm, data, true)
    extend(vm, options.methods, true)
    extend(compiler, options.compilerOptions)
    var el = compiler.el = compiler.setupElement(options)
    log('\nnew VM instance: ' + el.tagName + '\n')
    compiler.vm = el.vue_vm = vm
    compiler.bindings = makeHash()
    compiler.dirs = []
    compiler.deferred = []
    compiler.exps = []
    compiler.computed = []
    compiler.children = []
    compiler.emitter = new Emitter()
    compiler.emitter._ctx = vm
    compiler.delegators = makeHash()
    def(vm, '$', makeHash())
    def(vm, '$el', el)
    def(vm, '$options', options)
    def(vm, '$compiler', compiler)
    var parentVM = options.parent,
        childId = utils.attr(el, 'ref')
    if (parentVM) {
        compiler.parent = parentVM.$compiler
        parentVM.$compiler.children.push(compiler)
        def(vm, '$parent', parentVM)
        if (childId) {
            compiler.childId = childId
            parentVM.$[childId] = vm
        }
    }
    def(vm, '$root', getRoot(compiler).vm)
    compiler.setupObserver()
    var computed = options.computed
    if (computed) {
        for (var key in computed) {
            compiler.createBinding(key)
        }
    }
    if (options.paramAttributes) {
        options.paramAttributes.forEach(function (attr) {
            var val = el.getAttribute(attr)
            vm[attr] = (isNaN(val) || val === null)
                ? val
                : Number(val)
        })
    }
    compiler.execHook('created')
    extend(data, vm)
    compiler.observeData(data)
    if (compiler.repeat) {
        compiler.createBinding('$index')
        if (data.$key) compiler.createBinding('$key')
    }
    compiler.compile(el, true)
    compiler.deferred.forEach(compiler.bindDirective, compiler)
    compiler.parseDeps()
    compiler.rawContent = null
    compiler.init = false
    if (!compiler.delayReady) {
        compiler.execHook('ready')
    }
}
function Compiler ( vm , options ) { var compiler = this compiler . init = true compiler . repeat = false compiler . destroyed = false compiler . delayReady = false options = compiler . options = options || makeHash ( ) utils . processOptions ( options ) var data = compiler . data = options . data || { } extend ( vm , data , true ) extend ( vm , options . methods , true ) extend ( compiler , options . compilerOptions ) var el = compiler . el = compiler . setupElement ( options ) log ( '\nnew VM instance: ' + el . tagName + '\n' ) compiler . vm = el . vue_vm = vm compiler . bindings = makeHash ( ) compiler . dirs = [ ] compiler . deferred = [ ] compiler . exps = [ ] compiler . computed = [ ] compiler . children = [ ] compiler . emitter = new Emitter ( ) compiler . emitter . _ctx = vm compiler . delegators = makeHash ( ) def ( vm , '$' , makeHash ( ) ) def ( vm , '$el' , el ) def ( vm , '$options' , options ) def ( vm , '$compiler' , compiler ) var parentVM = options . parent , childId = utils . attr ( el , 'ref' ) if ( parentVM ) { compiler . parent = parentVM . $compiler parentVM . $compiler . children . push ( compiler ) def ( vm , '$parent' , parentVM ) if ( childId ) { compiler . childId = childId parentVM . $ [ childId ] = vm } } def ( vm , '$root' , getRoot ( compiler ) . vm ) compiler . setupObserver ( ) var computed = options . computed if ( computed ) { for ( var key in computed ) { compiler . createBinding ( key ) } } if ( options . paramAttributes ) { options . paramAttributes . forEach ( function ( attr ) { var val = el . getAttribute ( attr ) vm [ attr ] = ( isNaN ( val ) || val === null ) ? val : Number ( val ) } ) } compiler . execHook ( 'created' ) extend ( data , vm ) compiler . observeData ( data ) if ( compiler . repeat ) { compiler . createBinding ( '$index' ) if ( data . $key ) compiler . createBinding ( '$key' ) } compiler . compile ( el , true ) compiler . deferred . forEach ( compiler . bindDirective , compiler ) compiler . parseDeps ( ) compiler . rawContent = null compiler . init = false if ( ! compiler . delayReady ) { compiler . execHook ( 'ready' ) } }
The DOM compiler
  scans a DOM node and compile bindings for a ViewModel
The DOM compiler scans a DOM node and compile bindings for a ViewModel
// default state // process and extend options // copy data, methods & compiler options // initialize element // set compiler properties // set inenumerable VM properties // set parent VM // and register child id on parent // set root // setup observer // create bindings for computed properties // copy paramAttributes // beforeCompile hook // the user might have set some props on the vm  // so copy it back to the data... // observe the data // for repeated items, create index/key bindings // because they are ienumerable // now parse the DOM, during which we will create necessary bindings // and bind the parsed directives // bind deferred directives (child components) // extract dependencies for computed properties // done! // post compile / ready hook