pugjs / pug

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

SyntaxError: Unexpected token #3281

Open Yaxdraz opened 4 years ago

Yaxdraz commented 4 years ago

Pug Version: 2.0.4

Node Version: 12.0.0 | 12.x

Input Pug

- let account = await db.User.findOne({userID: user.id})
p #{account.description}

Expected HTML

<p>Hello!</p>

Additional Comments

Error:

SyntaxError: Unexpected token (143:20)
    at Parser.pp$4.raise (/rbd/pnpm-volume/549c5828-7472-4601-8db7-45cda2814f52/node_modules/.registry.npmjs.org/acorn/4.0.13/node_modules/acorn/dist/acorn.js:2488:13)
    at Parser.pp.unexpected (/rbd/pnpm-volume/549c5828-7472-4601-8db7-45cda2814f52/node_modules/.registry.npmjs.org/acorn/4.0.13/node_modules/acorn/dist/acorn.js:623:8)
    at Parser.pp.semicolon (/rbd/pnpm-volume/549c5828-7472-4601-8db7-45cda2814f52/node_modules/.registry.npmjs.org/acorn/4.0.13/node_modules/acorn/dist/acorn.js:600:59)
    at Parser.pp$1.parseVarStatement (/rbd/pnpm-volume/549c5828-7472-4601-8db7-45cda2814f52/node_modules/.registry.npmjs.org/acorn/4.0.13/node_modules/acorn/dist/acorn.js:973:8)
    at Parser.pp$1.parseStatement (/rbd/pnpm-volume/549c5828-7472-4601-8db7-45cda2814f52/node_modules/.registry.npmjs.org/acorn/4.0.13/node_modules/acorn/dist/acorn.js:751:17)
    at Parser.pp$1.parseTopLevel (/rbd/pnpm-volume/549c5828-7472-4601-8db7-45cda2814f52/node_modules/.registry.npmjs.org/acorn/4.0.13/node_modules/acorn/dist/acorn.js:672:23)
    at Parser.parse (/rbd/pnpm-volume/549c5828-7472-4601-8db7-45cda2814f52/node_modules/.registry.npmjs.org/acorn/4.0.13/node_modules/acorn/dist/acorn.js:529:15)
    at Object.parse (/rbd/pnpm-volume/549c5828-7472-4601-8db7-45cda2814f52/node_modules/.registry.npmjs.org/acorn/4.0.13/node_modules/acorn/dist/acorn.js:3378:37)
    at reallyParse (/rbd/pnpm-volume/549c5828-7472-4601-8db7-45cda2814f52/node_modules/.registry.npmjs.org/acorn-globals/3.1.0/node_modules/acorn-globals/index.js:22:16)
    at findGlobals (/rbd/pnpm-volume/549c5828-7472-4601-8db7-45cda2814f52/node_modules/.registry.npmjs.org/acorn-globals/3.1.0/node_modules/acorn-globals/index.js:35:11)
    at addWith (/rbd/pnpm-volume/549c5828-7472-4601-8db7-45cda2814f52/node_modules/.registry.npmjs.org/with/5.1.1/node_modules/with/index.js:29:14)
    at Compiler.compile (/rbd/pnpm-volume/549c5828-7472-4601-8db7-45cda2814f52/node_modules/.registry.npmjs.org/pug-code-gen/2.0.2/node_modules/pug-code-gen/index.js:130:12)
    at generateCode (/rbd/pnpm-volume/549c5828-7472-4601-8db7-45cda2814f52/node_modules/.registry.npmjs.org/pug-code-gen/2.0.2/node_modules/pug-code-gen/index.js:32:39)
    at compileBody (/rbd/pnpm-volume/549c5828-7472-4601-8db7-45cda2814f52/node_modules/.registry.npmjs.org/pug/2.0.4/node_modules/pug/lib/index.js:175:12)
    at Object.exports.compile (/rbd/pnpm-volume/549c5828-7472-4601-8db7-45cda2814f52/node_modules/.registry.npmjs.org/pug/2.0.4/node_modules/pug/lib/index.js:242:16)
    at handleTemplateCache (/rbd/pnpm-volume/549c5828-7472-4601-8db7-45cda2814f52/node_modules/.registry.npmjs.org/pug/2.0.4/node_modules/pug/lib/index.js:215:25)

When I add await to the pug file it gives an error but it works when I don't add it. Is there a way to fix it?

trasherdk commented 4 years ago

You need a async function to be able to use await. Look up async/await wrapper function.

Yaxdraz commented 4 years ago

You need a async function to be able to use await. Look up async/await wrapper function.

Don't work.

Code:

- (async function() {
- let account = await db.User.findOne({userID: user.id})
p #{account.description}
- })()

Error:

SyntaxError: Unexpected token (143:7)
    at Parser.pp$4.raise (/rbd/pnpm-volume/549c5828-7472-4601-8db7-45cda2814f52/node_modules/.registry.npmjs.org/acorn/4.0.13/node_modules/acorn/dist/acorn.js:2488:13)
    at Parser.pp.unexpected (/rbd/pnpm-volume/549c5828-7472-4601-8db7-45cda2814f52/node_modules/.registry.npmjs.org/acorn/4.0.13/node_modules/acorn/dist/acorn.js:623:8)
    at Parser.pp.expect (/rbd/pnpm-volume/549c5828-7472-4601-8db7-45cda2814f52/node_modules/.registry.npmjs.org/acorn/4.0.13/node_modules/acorn/dist/acorn.js:617:26)
    at Parser.pp$3.parseParenAndDistinguishExpression (/rbd/pnpm-volume/549c5828-7472-4601-8db7-45cda2814f52/node_modules/.registry.npmjs.org/acorn/4.0.13/node_modules/acorn/dist/acorn.js:2043:38)
    at Parser.pp$3.parseExprAtom (/rbd/pnpm-volume/549c5828-7472-4601-8db7-45cda2814f52/node_modules/.registry.npmjs.org/acorn/4.0.13/node_modules/acorn/dist/acorn.js:1978:41)
    at Parser.pp$3.parseExprSubscripts (/rbd/pnpm-volume/549c5828-7472-4601-8db7-45cda2814f52/node_modules/.registry.npmjs.org/acorn/4.0.13/node_modules/acorn/dist/acorn.js:1872:19)
    at Parser.pp$3.parseMaybeUnary (/rbd/pnpm-volume/549c5828-7472-4601-8db7-45cda2814f52/node_modules/.registry.npmjs.org/acorn/4.0.13/node_modules/acorn/dist/acorn.js:1849:17)
    at Parser.pp$3.parseExprOps (/rbd/pnpm-volume/549c5828-7472-4601-8db7-45cda2814f52/node_modules/.registry.npmjs.org/acorn/4.0.13/node_modules/acorn/dist/acorn.js:1791:19)
    at Parser.pp$3.parseMaybeConditional (/rbd/pnpm-volume/549c5828-7472-4601-8db7-45cda2814f52/node_modules/.registry.npmjs.org/acorn/4.0.13/node_modules/acorn/dist/acorn.js:1774:19)
    at Parser.pp$3.parseMaybeAssign (/rbd/pnpm-volume/549c5828-7472-4601-8db7-45cda2814f52/node_modules/.registry.npmjs.org/acorn/4.0.13/node_modules/acorn/dist/acorn.js:1750:19)
    at Parser.pp$3.parseExpression (/rbd/pnpm-volume/549c5828-7472-4601-8db7-45cda2814f52/node_modules/.registry.npmjs.org/acorn/4.0.13/node_modules/acorn/dist/acorn.js:1722:19)
    at Parser.pp$1.parseStatement (/rbd/pnpm-volume/549c5828-7472-4601-8db7-45cda2814f52/node_modules/.registry.npmjs.org/acorn/4.0.13/node_modules/acorn/dist/acorn.js:777:45)
    at Parser.pp$1.parseTopLevel (/rbd/pnpm-volume/549c5828-7472-4601-8db7-45cda2814f52/node_modules/.registry.npmjs.org/acorn/4.0.13/node_modules/acorn/dist/acorn.js:672:23)
    at Parser.parse (/rbd/pnpm-volume/549c5828-7472-4601-8db7-45cda2814f52/node_modules/.registry.npmjs.org/acorn/4.0.13/node_modules/acorn/dist/acorn.js:529:15)
    at Object.parse (/rbd/pnpm-volume/549c5828-7472-4601-8db7-45cda2814f52/node_modules/.registry.npmjs.org/acorn/4.0.13/node_modules/acorn/dist/acorn.js:3378:37)
    at reallyParse (/rbd/pnpm-volume/549c5828-7472-4601-8db7-45cda2814f52/node_modules/.registry.npmjs.org/acorn-globals/3.1.0/node_modules/acorn-globals/index.js:22:16)
TheChilliPL commented 2 years ago

Any updates? It's been more than a year and that's still an issue