pugjs / pug

Pug – robust, elegant, feature rich template engine for Node.js
https://pugjs.org
21.54k stars 1.96k forks source link

Inline conditional math not working as expected #3411

Open jstncmorgan opened 1 year ago

jstncmorgan commented 1 year ago

Pug Version: 3.0.2

Node Version: 16.15.0

Pug is being rendered via express The following two blocks of pug code give different results:

each page in paginatorPages
    li(class="page-item" class={"d-none d-sm-flex": page < currentPage - 1 || page > currentPage + 0})
each page in paginatorPages
    li(class="page-item" class={"d-none d-sm-flex": page < currentPage - 1 || page > currentPage})

The only difference is the + 0 near the end of the second line. My actual use case here is that I would like to check page > currentPage + 1, but through experimentation, I discovered that any addition operation in the back half of the second equation results in strange behavior. Resultant HTML is as follows where currentPage == 3 and paginatorPages == [1, 2, 3, 4, 5]:

<li class="page-item d-none d-sm-flex"></li>
<li class="page-item"></li>
<li class="page-item"></li>
<li class="page-item"></li>
<li class="page-item"></li>
<li class="page-item d-none d-sm-flex"></li>
<li class="page-item"></li>
<li class="page-item"></li>
<li class="page-item d-none d-sm-flex"></li>
<li class="page-item d-none d-sm-flex"></li>