Skip to content

Can't use together with expressions plugin #68

@cossssmin

Description

@cossssmin

Found a weird issue: if you use posthtml-expressions together with this plugin, it will fail with either a TypeError or a ReferenceError (depending on which one you add to the plugins array first).

So this setup:

const html = `<fetch url="https://jsonplaceholder.typicode.com/users/1">
  {{ response.name }}
</fetch>`

posthtml([
    require('posthtml-expressions')({ locals: { var: 'test' } }),
    require('posthtml-fetch')()
  ])
    .process(html)
    .then(result => result.html)
    .catch(error => { throw error })

Fails with ReferenceError: response is not defined

If you switch plugin order, you get TypeError: nodes.reduce is not a function.

However, if you skip expression parsing with @{{ }}, it works 😵

<fetch url="https://jsonplaceholder.typicode.com/users/1">
  @{{ response.name }}
</fetch>

... that correctly outputs 'Leanne Graham' and the build doesn't break.

@Scrum any ideas? Is my setup wrong or is there a bug in the plugin?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions