Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ambiguous errors when "let" and "const" rules are violated #33

Open
JL102 opened this issue Mar 10, 2022 · 0 comments
Open

Ambiguous errors when "let" and "const" rules are violated #33

JL102 opened this issue Mar 10, 2022 · 0 comments

Comments

@JL102
Copy link

JL102 commented Mar 10, 2022

Hello,
It took me a while to figure out the cause of this error:

Error: Error parsing body of the with expression
    at addWith (...\node_modules\with\lib\index.js:50:29)
    at Compiler.compile (...\node_modules\pug-code-gen\index.js:139:12)
    at generateCode (...\node_modules\pug-code-gen\index.js:32:37)
    at compileBody (...\node_modules\pug\lib\index.js:199:74)
    at Object.exports.compile (...\node_modules\pug\lib\index.js:269:16)
    at handleTemplateCache (...\node_modules\pug\lib\index.js:242:25)
    at Object.exports.renderFile (...\node_modules\pug\lib\index.js:454:10)
    at Object.exports.renderFile (...\node_modules\pug\lib\index.js:444:21)
    at View.exports.__express [as engine] (...\node_modules\pug\lib\index.js:493:11)
    at View.render (...\node_modules\express\lib\view.js:135:8)

because I had two separate templates in a case/when block, so I didn't think that using let to define variables of the same name would raise an error. Anyways, to reproduce the error, all you have to do is:

- let foo = 'bar';
- let foo = 'bar 2';

or

- const foo = 'bar';
- let foo = 'bar 2';

or

- var foo = 'bar';
- let foo = 'bar 2';

Essentially any combination of variable declarations in the same block, except when using exclusively var, leads to the ambiguous "Error parsing body of the with expression" message. Ideally, something similar to what JS does natively would be great: Identifier 'foo' has already been declared - or at least pointing to the problematic line of code.

I'm using PugJS v3.0.2, which appears to use With v7.0.0.

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant