Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

no elseBlock in vue-template-compiler 2.1.3 #4317

Closed
mlinquan opened this issue Nov 25, 2016 · 2 comments
Closed

no elseBlock in vue-template-compiler 2.1.3 #4317

mlinquan opened this issue Nov 25, 2016 · 2 comments

Comments

@mlinquan
Copy link

mlinquan commented Nov 25, 2016

Vue.js version(vue-template-compiler)

2.1.3

Code

var compiler = require('vue-template-compiler')
console.log(compiler.compile('<span v-if="abc">abc</span><span v-else>bcd</span>'));

Result

2.0.8 (has elseBlock)

{ ast:
   { type: 1,
     tag: 'span',
     attrsList: [],
     attrsMap: { 'v-if': 'abc' },
     parent: undefined,
     children: [ [Object] ],
     if: 'abc',
     plain: true,
     elseBlock://<--has elseBlock
      { type: 1,
        tag: 'span',
        attrsList: [],
        attrsMap: [Object],
        parent: undefined,
        children: [Object],
        else: true,
        plain: true },
     static: false,
     staticRoot: false,
     ifProcessed: true },
  render: 'with(this){return (abc)?_h(\'span\',["abc"]):_h(\'span\',["bcd"])}',
  staticRenderFns: [],
  errors: [] }

2.1.3 (no elseBlock)

{ ast:
   { type: 1,
     tag: 'span',
     attrsList: [],
     attrsMap: { 'v-if': 'abc' },
     parent: undefined,
     children: [ [Object] ],
     if: 'abc',
     conditions: [],
     plain: true,
     static: false,
     staticRoot: false,
     ifProcessed: true },
  render: 'with(this){return (abc)?_h(\'span\',["abc"]):_h(\'span\',["bcd"])}',
  staticRenderFns: [],
  errors: [] }

What is Expected?

Always able to compile 'elseBlock'.

What is actually happening?

I don't know.

@yyx990803
Copy link
Member

In 2.1.0 all condition branches for v-if/v-else/v-else-if are moved in to the node.conditions array. However the codegen mutated the array while generating the branches so it ended up empty.

I've renamed it to node.ifConditions and avoided the mutation.

/cc @defcc : in the future, we should avoid mutating the AST during codegen.

@defcc
Copy link
Member

defcc commented Nov 25, 2016

Ok, got it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants