Browse Source

avoid marking slot content as static.

dev
Evan You 8 years ago
parent
commit
9931b715cd
  1. 10
      src/compiler/optimizer.js
  2. 3
      test/unit/modules/compiler/codegen.spec.js
  3. 10
      test/unit/modules/compiler/optimizer.spec.js

10
src/compiler/optimizer.js

@ -38,6 +38,16 @@ function genStaticKeys (keys: string): Function {
function markStatic (node: ASTNode) { function markStatic (node: ASTNode) {
node.static = isStatic(node) node.static = isStatic(node)
if (node.type === 1) { if (node.type === 1) {
// do not make component slot content static. this avoids
// 1. components not able to mutate slot nodes
// 2. static slot content fails for hot-reloading
if (
!isPlatformReservedTag(node.tag) &&
node.tag !== 'slot' &&
node.attrsMap['inline-template'] == null
) {
return
}
for (let i = 0, l = node.children.length; i < l; i++) { for (let i = 0, l = node.children.length; i < l; i++) {
const child = node.children[i] const child = node.children[i]
markStatic(child) markStatic(child)

3
test/unit/modules/compiler/codegen.spec.js

@ -272,8 +272,7 @@ describe('codegen', () => {
it('generate component', () => { it('generate component', () => {
assertCodegen( assertCodegen(
'<my-component name="mycomponent1" :msg="msg" @notify="onNotify"><div>hi</div></my-component>', '<my-component name="mycomponent1" :msg="msg" @notify="onNotify"><div>hi</div></my-component>',
`with(this){return _h('my-component',{attrs:{"name":"mycomponent1","msg":msg},on:{"notify":onNotify}},[_m(0)])}`, `with(this){return _h('my-component',{attrs:{"name":"mycomponent1","msg":msg},on:{"notify":onNotify}},[_h('div',["hi"])])}`
[`with(this){return _h('div',["hi"])}`]
) )
}) })

10
test/unit/modules/compiler/optimizer.spec.js

@ -90,14 +90,6 @@ describe('optimizer', () => {
expect(ast.children[0].static).toBe(false) // text node expect(ast.children[0].static).toBe(false) // text node
}) })
it('render tag', () => {
const ast = parse('<render :method="onRender"><p>hello</p></render>', baseOptions)
optimize(ast, baseOptions)
expect(ast.static).toBe(false)
expect(ast.children[0].static).toBe(true)
expect(ast.children[0].children[0].static).toBe(true)
})
it('single slot', () => { it('single slot', () => {
const ast = parse('<slot>hello</slot>', baseOptions) const ast = parse('<slot>hello</slot>', baseOptions)
optimize(ast, baseOptions) optimize(ast, baseOptions)
@ -186,7 +178,7 @@ describe('optimizer', () => {
}) })
it('custom directive', () => { it('custom directive', () => {
const ast = parse('<fom><input type="text" name="field1" :value="msg" v-validate:field1="required"></form>', baseOptions) const ast = parse('<form><input type="text" name="field1" :value="msg" v-validate:field1="required"></form>', baseOptions)
optimize(ast, baseOptions) optimize(ast, baseOptions)
expect(ast.static).toBe(false) expect(ast.static).toBe(false)
expect(ast.children[0].static).toBe(false) expect(ast.children[0].static).toBe(false)

Loading…
Cancel
Save