-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Description
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.