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

Passing ["foo of bar"] to each causing a syntax error #3275

Closed
WallTack opened this issue Jul 4, 2020 · 0 comments · Fixed by #3274
Closed

Passing ["foo of bar"] to each causing a syntax error #3275

WallTack opened this issue Jul 4, 2020 · 0 comments · Fixed by #3274

Comments

@WallTack
Copy link

WallTack commented Jul 4, 2020

Pug Version:
3.0.0
Node Version:
12.18.0

Input Pug

each string in ["foo of bar"]
    h1= string

Expected HTML

<h1>foo of bar</h1>

Actual HTML

None.

Syntax Error: Unterminated string constant

Full Error

  > 1| each string in ["foo of bar"]
----------------------------------^
    2|     h1= string

Syntax Error: Unterminated string constant
    at makeError (...\app\node_modules\pug-error\index.js:34:13)
    at Lexer.error (...\app\node_modules\pug-lexer\index.js:62:15)
    at Lexer.assertExpression (...\app\node_modules\pug-lexer\index.js:96:12)
    at Lexer.eachOf (...\app\node_modules\pug-lexer\index.js:1090:12)
    at Lexer.callLexerFunction (...\app\node_modules\pug-lexer\index.js:1642:23)
    at Lexer.advance (...\app\node_modules\pug-lexer\index.js:1671:12)
    at Lexer.callLexerFunction (...\app\node_modules\pug-lexer\index.js:1642:23)
    at Lexer.getTokens (...\app\node_modules\pug-lexer\index.js:1701:12)
    at lex (...\app\node_modules\pug-lexer\index.js:12:42)
    at Object.lex (...\app\node_modules\pug\lib\index.js:104:9)

Temporary fix

Assigning the array or object to a variable fixes the problem. For example:

- var testVar = ["foo of bar"]
each string in testVar
    h1= string

Also, don't start your variable name with "of", as mentioned here: #3263

Additional Comments

Seems related to #3263 (the word "of")

The error is caused when the word "of" is in a string that's being passed to an each statement. The string can be in an array as show above, or it can be in an object; both cause the error.

The word "of" must also be after any other character (including whitespace) in the string for the error to occur. For example, passing ["of bar"] instead of ["foo of bar"] will not result in an error.

Passing another string after the "foo of bar" string yields a Syntax Error: Unexpected token rather than a Syntax Error: Unterminated string constant as seen here:

> 1| each string in ["foo of bar", "something else"]
--------------------------------^
  2|     h1=string

Syntax Error: Unexpected token

The rest of the error traceback is identical, so I won't clutter the post by adding it.

@WallTack WallTack changed the title Passing "foo of bar" to each causing a syntax error Passing ["foo of bar"] to each causing a syntax error Jul 4, 2020
error418 added a commit to error418/pug that referenced this issue Jul 9, 2020
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

Successfully merging a pull request may close this issue.

1 participant