plop icon indicating copy to clipboard operation
plop copied to clipboard

Parsing a react.js template, and it gives errors on double quotes.

Open codTango opened this issue 10 years ago • 6 comments

render() {
    return (
      <div style={{ height: '100%', width: '100%' }} />
    );
}

It gives error: Expecting 'CLOSE_RAW_BLOCK', 'CLOSE', 'CLOSE_UNESCAPED', 'STRING', 'NUMBER', 'BOOLEAN', 'OPEN_SEXPR', ' CLOSE_SEXPR', 'ID', 'DATA', got 'INVALID'

In general, this is a piece of my template which is react.js file, so that double quotes are useful to react. In this case, how would I parse that?

codTango avatar Oct 07 '16 13:10 codTango

so the situation is that when you use double quotes in the plop template file it throws an error when you try to generate from that template?

amwmedia avatar Oct 07 '16 14:10 amwmedia

@amwmedia yes, that's the case.

more detail: it complaints this:

...e={{{ height: '100%', width: '100%' }}}
-----------------------^

codTango avatar Oct 07 '16 14:10 codTango

the problem here is the {{ }} handlebars is trying to process this when you really want React to process it. I'd be interested to hear how @mxstbr solved this on his react-boilerplace project. I've solved this for angular projects using a helper that goes something like this...

plop.addHelper('ng', text => `{{ ${text} }}`);

then in your template you would use it like...

render() {
    return (
      <div style={{ ng "height: '100%', width: '100%'" }} />
    );
}

it's a bit of a hack, but it does get the job done.

amwmedia avatar Oct 07 '16 15:10 amwmedia

@amwmedia yea, I have thought that solution, and thought that there might be a better solution. But I guess I will just use a helper for now.

codTango avatar Oct 07 '16 15:10 codTango

I'll post here if I think of something better. maybe someone out there will come up with a better solution. I think the helper might be fine if it were named something better... maybe like escape?

amwmedia avatar Oct 07 '16 15:10 amwmedia

We don't have that issue as we don't have templates with much JSX in it, sorry!

mxstbr avatar Oct 07 '16 17:10 mxstbr