Skip to content

Commit

Permalink
Updated JavaScript token regexes per @lydell
Browse files Browse the repository at this point in the history
  • Loading branch information
GeoffreyBooth committed Nov 15, 2016
1 parent 3200259 commit 45b7193
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
8 changes: 5 additions & 3 deletions lib/coffee-script/lexer.js

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

8 changes: 6 additions & 2 deletions src/lexer.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,8 @@ exports.Lexer = class Lexer

# Matches JavaScript interpolated directly into the source via backticks.
jsToken: ->
return 0 unless @chunk.charAt(0) is '`' and match = JSTOKEN.exec @chunk
return 0 unless @chunk.charAt(0) is '`' and
(match = HERE_JSTOKEN.exec(@chunk) or JSTOKEN.exec(@chunk))
[js] = match
script = if js[0..2] is '```' then js[3...-3] else js[1...-1]
script = script.replace /\\`/g, '`' # Convert escaped backticks to backticks
Expand Down Expand Up @@ -903,7 +904,10 @@ CODE = /^[-=]>/

MULTI_DENT = /^(?:\n[^\n\S]*)+/

JSTOKEN = /^```([\s\S]*?)(?:\\`(```)|```)|^`[^\\`]*(?:\\.[^\\`]*)*`/
JSTOKEN = ///^ `(?!``) ((?: [^`\\] | \\[\s\S] )*) ` ///
HERE_JSTOKEN = ///^ ``` ((?: [^`\\] | \\[\s\S] | `(?!``) )*) ``` ///



# String-matching-regexes.
STRING_START = /^(?:'''|"""|'|")/
Expand Down

0 comments on commit 45b7193

Please sign in to comment.