Skip to content

Only arrow functions work properly as arguments to Pagination Plugin (normal functions eval to undefined) #1338

@blainehansen

Description

@blainehansen
  • I confirm that this is a issue rather than a question.

Bug report

Version

vuepress/1.0.0-alpha.39

Steps to reproduce

The shortest reproduction is to run these two commands in your developer console:

eval('function f(a) { return a }')
// undefined
eval('(a) => a')
// (a) => a

To see this in the context of vuepress, create a blank project that uses @vuepress/pagination, and then pass a normal function (not an arrow function) to either postsSorter or postsFilter. Since that plugin uses eval to recover those functions:
https://github.com/vuejs/vuepress/blob/master/packages/%40vuepress/plugin-pagination/enhanceAppFile.js#L8

undefined will be returned, and the build will fail, saying that undefined isn't a function.

Similarly, if someone defines their postsSorter or postsFilter as an anonymous normal function, eval will throw a SyntaxError:

eval('function () {}')
// Uncaught SyntaxError: Unexpected token ( at <anonymous>:1:1

What is expected?

The plugin should successfully recover either kind of function.

What is actually happening?

The plugin throws an error, saying that undefined is not a function.

Other relevant information

  • Your OS: Ubuntu 18.04
  • Node.js version: node-v11.8.0
  • Browser version: Chrome 72 on Linux
  • Is this a global or local install? global
  • Which package manager did you use for the install? npm

Metadata

Metadata

Assignees

No one assigned

    Labels

    has PRHas a related PRtopic: pluginsRelates to VuePress pluginstype: bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions