Skip to content

vue-template-compiler@2.1.0 parse template error: Cannot read property 'text' of undefined #669

Closed
@clancyz

Description

@clancyz

Hi all! I made a simple project with vue-cli(which use vue-template-compiler@2.1.0), and found this error:

Cannot read property 'text' of undefined
    at Object.chars (eval at <anonymous> (app.js:969), <anonymous>:1385:65)
    at parseHTML (eval at <anonymous> (app.js:969), <anonymous>:537:17)
    at parse (eval at <anonymous> (app.js:969), <anonymous>:1203:3)
    at compile$2 (eval at <anonymous> (app.js:969), <anonymous>:2283:13)
    at compile$1 (eval at <anonymous> (app.js:969), <anonymous>:5739:10)
    at Object.compile$$1 [as compile] (eval at <anonymous> (app.js:969), <anonymous>:5931:18)
    at VueComponent.mounted (eval at <anonymous> (app.js:800), <anonymous>:16:22)
    at callHook (eval at <anonymous> (app.js:735), <anonymous>:2754:19)
    at Object.insert (eval at <anonymous> (app.js:735), <anonymous>:1765:5)
    at invokeInsertHook (eval at <anonymous> (app.js:735), <anonymous>:4474:28)

Here is the case:

const compiler = require('vue-template-compiler');
compiler.compile('<pre>\n<span> <span></span></span>\n</pre>');

or directely write in template of a .vue file:

<template>
   <pre>
      <span> <span></span></span>
   </pre>
</template>

This errors occurs in vue-template-compiler/build.js :1385:65

else if (text !== ' ' || children[children.length - 1].text !== ' ') {
      currentParent.children.push({
            type: 3,
            text: text
      });
 }

In this case children is an empty array, so it happens.

Thank you.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions