prettier / plugin-pug

Prettier Pug Plugin
https://prettier.github.io/plugin-pug
MIT License
197 stars 44 forks source link

Bug: Missing semicolon after 'echo' (php in jade) #257

Open phoshenwen opened 3 years ago

phoshenwen commented 3 years ago

Info

Tool Version
Plugin v1.16.1
Prettier v2.3.2
Framework none
Node v16.5
OS win

Prettier config

{
    "endOfLine": "crlf",
    "printWidth": 100,
    "proseWrap": "always",
    "singleQuote": true,
    "tabWidth": 4
}

Input

- echo get_field("hero_content");

Output or Error

missing semicolon after 'echo'

SyntaxError: Missing semicolon. (1:5)
> 1 | echo get_field("hero_content"); 

Expected Output

no error

Additional Context

I don't know if it makes a difference, but I am using this plugin with .jade as the file extension (rather than .pug).

When running npx prettier --write "./_jade/front-page.jade" I am seeing the error. There should NOT be a semicolon after echo.

PS: Same thing happens with '- require ...'

Shinigami92 commented 3 years ago

The pug lexer can parse this somehow and returns

[
  {"type":"code","loc":{"start":{"line":1,"column":1},"end":{"line":1,"column":34}},"val":"echo get_field(\"hero_content\");","mustEscape":false,"buffer":false},
  {"type":"newline","loc":{"start":{"line":2,"column":1},"end":{"line":2,"column":1}}},
  {"type":"eos","loc":{"start":{"line":2,"column":1},"end":{"line":2,"column":1}}}
]

As you can see it recognize the hot part as type code This code is then passed to the babel prettier processor by my plugin. But echo get_field("hero_content"); is not valid JS (as far as I know) :thinking:

I think it is maybe a deprecated feature from jade? If so I will not support it :slightly_frowning_face: sorry for that.

Otherwise please provide my

  1. A bit more context about this echo
  2. Some more code examples, so I can harden the test suite with these

Nevertheless, it seems that this just produces a warning and not an error, so I assume the rest of the file gets formatted as wanted? So maybe you need to life with that and just ignore the warnings :thinking:

phoshenwen commented 3 years ago

I'm compiling the jade files to PHP via gulp and gulp-jade-php. The echo statement comes from vanilla PHP and prints the result of the get_field() function which is simply a string. Another equivalent example would be a simple line of - require '/test.php';

But I'm getting the feeling that this wasn't meant for php to begin with

Shinigami92 commented 3 years ago

I am really sad that I cannot help you from my part, cause IMO this is not only the special case of the deprecated usage of jade, but also the assumption that php is involved but js syntax is assumed. But if you like, you are welcome to try to create a PR on your own. Maybe you can create an option to toggle a flag or something like that :thinking:

Feel free to close this issue or discuss further with me about how I can help you :slightly_smiling_face: