Skip to content

Commit 482bc46

Browse files
committed
Updated JavaScript token regexes per @lydell
1 parent 3200259 commit 482bc46

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

lib/coffee-script/lexer.js

+5-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/lexer.coffee

+7-2
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,8 @@ exports.Lexer = class Lexer
292292

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

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

906-
JSTOKEN = /^```([\s\S]*?)(?:\\`(```)|```)|^`[^\\`]*(?:\\.[^\\`]*)*`/
907+
# JSTOKEN = /^```([\s\S]*?)(?:\\`(```)|```)|^`[^\\`]*(?:\\.[^\\`]*)*`/
908+
JSTOKEN = ///^ `(?!``) ((?: [^`\\] | \\[\s\S] )*) ` ///
909+
HERE_JSTOKEN = ///^ ``` ((?: [^`\\] | \\[\s\S] | `(?!``) )*) ``` ///
910+
911+
907912

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

0 commit comments

Comments
 (0)