Skip to content

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

@JL102

Description

@JL102

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions