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

Warn when using inline-template attribute but no children #9361

Closed
ChristianStornowski opened this issue Jan 23, 2019 · 4 comments · Fixed by #9365
Closed

Warn when using inline-template attribute but no children #9361

ChristianStornowski opened this issue Jan 23, 2019 · 4 comments · Fixed by #9365
Labels
feature request good first issue warnings related to development warnings

Comments

@ChristianStornowski
Copy link

Version

2.5.22

Reproduction link

https://codesandbox.io/s/r71q8py7mp

Steps to reproduce

Open https://codesandbox.io/s/r71q8py7mp and read console log

What is expected?

Don't execute following code from genInlineTemplate when el.children.length !== 1 || ast.type !== 1 is true because ast is undefined.

function genInlineTemplate (el, state) {
    var ast = el.children[0];
    if (el.children.length !== 1 || ast.type !== 1) {
      state.warn(
        'Inline-template components must have exactly one child element.',
        { start: el.start }
      );
    }
    if (ast.type === 1) {
      var inlineRenderFns = generate(ast, state.options);
      return ("inlineTemplate:{render:function(){"   (inlineRenderFns.render)   "},staticRenderFns:["   (inlineRenderFns.staticRenderFns.map(function (code) { return ("function(){"   code   "}"); }).join(','))   "]}")
    }
  }

What is actually happening?

Executing

 var inlineRenderFns = generate(ast, state.options);
      return ("inlineTemplate:{render:function(){"   (inlineRenderFns.render)   "},staticRenderFns:["   (inlineRenderFns.staticRenderFns.map(function (code) { return ("function(){"   code   "}"); }).join(','))   "]}")
@posva posva added feature request warnings related to development warnings labels Jan 23, 2019
@posva posva changed the title "Uncaught TypeError: Cannot read property 'type' of undefined" when using inline-template without a child Warn when using inline-template attribute but no children Jan 23, 2019
@posva
Copy link
Member

posva commented Jan 23, 2019

We could emit a dev-only warning for this

@youngkaneda

This comment has been minimized.

@posva

This comment has been minimized.

@youngkaneda
Copy link

youngkaneda commented Jan 23, 2019

@posva very sorry about it, I think I understood it a little wrong, my english is not so good :/, anyway i think i can do this issue if possible

Itisfilipe added a commit to Itisfilipe/vue that referenced this issue Jan 24, 2019
Lostlover pushed a commit to Lostlover/vue that referenced this issue Dec 10, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request good first issue warnings related to development warnings
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants