pugjs / pug-loader

Pug loader module for Webpack
MIT License
425 stars 119 forks source link

Unbuffered Code Issue with variables declared at beginning of pug template when using loader #127

Open Tanisha0494 opened 4 years ago

Tanisha0494 commented 4 years ago

So the issue I'm having is when I try and debug / run my code I get this error:

SyntaxError: Unexpected token 'var'

I have my doc set up correctly. I tested in the sublime text editor it has a pug-lint extension and it runs perfectly.

Here's the code It's getting hung up on:

- var accessories_selected = !{accessories_selected};
- var plan_selected = !{plan_selected};
- var dateNow = new Date();
- var dd = dateNow.getDate();
- var monthSingleDigit = dateNow.getMonth() + 1, mm = monthSingleDigit < 10 ? '0' + monthSingleDigit : monthSingleDigit;
- var yy = dateNow.getFullYear().toString().substr(2);
- var formattedDate = mm + '/' + dd + '/' + yy;

p(style='text-align: center')
  b Testy test test

ul
    br 
    - for(var i=0; i > accessories_selected.length; i++){
        span #{accessories_selected[i].name}
        li #{accessories_selected[i].description}
    - }

Any help would be much appreciated.

Thanks in advance for the help.

michaelalhilly commented 4 years ago

@Tanisha0494 Can you share your webpack config?

webdiscus commented 3 years ago

Two years later...

@Tanisha0494 I corrected your sample and it work fine:

-
    var accessories_selected = [
      {name: 'aaa', description: 'desc1'},
      {name: 'bbb', description: 'desc2'},
      {name: 'ccc', description: 'desc3'},
    ],
    dateNow = new Date(),
    dd = dateNow.getDate(),
    monthSingleDigit = dateNow.getMonth() + 1,
    mm = monthSingleDigit < 10 ? '0' + monthSingleDigit : monthSingleDigit,
    yy = dateNow.getFullYear().toString().substr(2),
    formattedDate = mm + '/' + dd + '/' + yy;

  p
    b Date
    span : #{formattedDate}

  ul
    each item in accessories_selected
      li
        span #{item.name}:
        span #{item.description}

Your error was at first line: - var accessories_selected = !{accessories_selected};, this destroy the array.

Tanisha0494 commented 3 years ago

Lol yea I no longer need this. I figured it out.

Thanks though.

On Wed, Nov 3, 2021, 12:35 PM webdiscus @.***> wrote:

Two years later...

@Tanisha0494 https://github.com/Tanisha0494 I corrected your sample and it work fine:

  • var accessories_selected = [ {name: 'aaa', description: 'desc1'}, {name: 'bbb', description: 'desc2'}, {name: 'ccc', description: 'desc3'}, ], dateNow = new Date(), dd = dateNow.getDate(), monthSingleDigit = dateNow.getMonth() + 1, mm = monthSingleDigit < 10 ? '0' + monthSingleDigit : monthSingleDigit, yy = dateNow.getFullYear().toString().substr(2), formattedDate = mm + '/' + dd + '/' + yy; p b Date span : #{formattedDate} ul each item in accessories_selected li span #{item.name}: span #{item.description}

Your error was at first line: - var accessories_selected = !{accessories_selected};, this destroy the array.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/pugjs/pug-loader/issues/127#issuecomment-959867807, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACMF4M76PL3JODJT36DFGT3UKGFGXANCNFSM4OSWGBQA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.