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

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

Open
Tanisha0494 opened this issue Jul 7, 2020 · 3 comments

Comments

@Tanisha0494
Copy link

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
Copy link

@Tanisha0494 Can you share your webpack config?

@webdiscus
Copy link

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
Copy link
Author

Tanisha0494 commented Nov 3, 2021 via email

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

3 participants