function
Compiler (vm, options) {
var
compiler =
this
,
key, i
compiler.init =
true
compiler.destroyed =
false
options = compiler.options = options || {}
utils.processOptions(options)
extend(compiler, options.compilerOptions)
compiler.repeat = compiler.repeat ||
false
compiler.expCache = compiler.expCache || {}
var
el = compiler.el = compiler.setupElement(options)
utils.log(
'\nnew VM instance: '
+ el.tagName +
'\n'
)
compiler.vm = el.vue_vm = vm
compiler.bindings = utils.hash()
compiler.dirs = []
compiler.deferred = []
compiler.computed = []
compiler.children = []
compiler.emitter =
new
Emitter(vm)
if
(options.methods) {
for
(key
in
options.methods) {
compiler.createBinding(key)
}
}
if
(options.computed) {
for
(key
in
options.computed) {
compiler.createBinding(key)
}
}
vm.$ = {}
vm.$el = el
vm.$options = options
vm.$compiler = compiler
vm.$event =
null
var
parentVM = options.parent
if
(parentVM) {
compiler.parent = parentVM.$compiler
parentVM.$compiler.children.push(compiler)
vm.$parent = parentVM
}
vm.$root = getRoot(compiler).vm
compiler.setupObserver()
var
data = compiler.data = options.data || {},
defaultData = options.defaultData
if
(defaultData) {
for
(key
in
defaultData) {
if
(!hasOwn.call(data, key)) {
data[key] = defaultData[key]
}
}
}
var
params = options.paramAttributes
if
(params) {
i = params.length
while
(i--) {
data[params[i]] = utils.checkNumber(
compiler.eval(
el.getAttribute(params[i])
)
)
}
}
extend(vm, data)
vm.$data = data
compiler.execHook(
'created'
)
data = compiler.data = vm.$data
var
vmProp
for
(key
in
vm) {
vmProp = vm[key]
if
(
key.charAt(0) !==
'$'
&&
data[key] !== vmProp &&
typeof
vmProp !==
'function'
) {
data[key] = vmProp
}
}
compiler.observeData(data)
if
(options.template) {
this
.resolveContent()
}
while
(i--) {
compiler.bindDirective(compiler.deferred[i])
}
compiler.deferred =
null
if
(
this
.computed.length) {
DepsParser.parse(
this
.computed)
}
compiler.init =
false
compiler.execHook(
'ready'
)
}