Skip to content

Commit

Permalink
Making #1050 a syntax error.
Browse files Browse the repository at this point in the history
  • Loading branch information
jashkenas committed Jan 19, 2011
1 parent 7ae284f commit 4b78790
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 9 deletions.
17 changes: 11 additions & 6 deletions lib/lexer.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 8 additions & 3 deletions src/lexer.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -170,11 +170,11 @@ exports.Lexer = class Lexer
commentToken: ->
return 0 unless match = @chunk.match COMMENT
[comment, here] = match
@line += count comment, '\n'
if here
@token 'HERECOMMENT', @sanitizeHeredoc here,
herecomment: true, indent: Array(@indent + 1).join(' ')
@token 'TERMINATOR', '\n'
@line += count comment, '\n'
comment.length

# Matches JavaScript interpolated directly into the source via backticks.
Expand Down Expand Up @@ -343,8 +343,11 @@ exports.Lexer = class Lexer
# erasing all external indentation on the left-hand side.
sanitizeHeredoc: (doc, options) ->
{indent, herecomment} = options
return doc if herecomment and 0 > doc.indexOf '\n'
unless herecomment
if herecomment
if HEREDOC_ILLEGAL.test doc
throw new Error "block comment cannot contain \"*/\", starting on line #{@line + 1}"
return doc if doc.indexOf('\n') <= 0
else
while match = HEREDOC_INDENT.exec doc
attempt = match[1]
indent = attempt if indent is null or 0 < attempt.length < indent.length
Expand Down Expand Up @@ -593,6 +596,8 @@ MULTILINER = /\n/g

HEREDOC_INDENT = /\n+([^\n\S]*)/g

HEREDOC_ILLEGAL = /\*\//

ASSIGNED = /^\s*@?([$A-Za-z_][$\w\x7f-\uffff]*|['"].*['"])[^\n\S]*?[:=][^:=>]/

LINE_CONTINUER = /// ^ \s* (?: , | \??\.(?!\.) | :: ) ///
Expand Down
3 changes: 3 additions & 0 deletions test/compilation.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,6 @@ test "#1026", ->
else
d
'''

test "#1050", ->
cantCompile "### */ ###"

0 comments on commit 4b78790

Please sign in to comment.