From a1f1afe3ed3d4ef3cbfa63ea899ea2ba01da4c97 Mon Sep 17 00:00:00 2001 From: Michael Ficarra Date: Fri, 17 Jun 2011 11:26:39 -0400 Subject: [PATCH] fixes #1442: javascript literals should increase line count when they contain newlines --- lib/lexer.js | 4 +++- src/lexer.coffee | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/lexer.js b/lib/lexer.js index bf0b38f8..71bf0c34 100644 --- a/lib/lexer.js +++ b/lib/lexer.js @@ -190,7 +190,9 @@ if (!(this.chunk.charAt(0) === '`' && (match = JSTOKEN.exec(this.chunk)))) { return 0; } - this.token('JS', (script = match[0]).slice(1, -1)); + script = match[0]; + this.line += count(script, '\n'); + this.token('JS', script.slice(1, -1)); return script.length; }; Lexer.prototype.regexToken = function() { diff --git a/src/lexer.coffee b/src/lexer.coffee index d4170c57..3e11fc40 100644 --- a/src/lexer.coffee +++ b/src/lexer.coffee @@ -181,7 +181,9 @@ 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 - @token 'JS', (script = match[0]).slice 1, -1 + script = match[0] + @line += count script, '\n' + @token 'JS', script[1...-1] script.length # Matches regular expression literals. Lexing regular expressions is difficult