From 4503e2716e75705a6a685c606ee001690a396a6a Mon Sep 17 00:00:00 2001 From: Simon Lydell Date: Wed, 18 Feb 2015 17:40:40 +0100 Subject: [PATCH] Fix single-line heredocs starting with "undefined" --- lib/coffee-script/lexer.js | 4 +++- src/lexer.coffee | 2 +- test/strings.coffee | 3 +++ 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/coffee-script/lexer.js b/lib/coffee-script/lexer.js index 4c4f2850..37ab04ad 100644 --- a/lib/coffee-script/lexer.js +++ b/lib/coffee-script/lexer.js @@ -242,7 +242,9 @@ if (i === $) { value = value.replace(TRAILING_BLANK_LINE, ''); } - value = value.replace(indentRegex, ''); + if (indentRegex) { + value = value.replace(indentRegex, ''); + } return value; }; })(this)); diff --git a/src/lexer.coffee b/src/lexer.coffee index 7bf28be7..ea7e54a8 100644 --- a/src/lexer.coffee +++ b/src/lexer.coffee @@ -217,7 +217,7 @@ exports.Lexer = class Lexer value = @formatString value value = value.replace LEADING_BLANK_LINE, '' if i is 0 value = value.replace TRAILING_BLANK_LINE, '' if i is $ - value = value.replace indentRegex, '' + value = value.replace indentRegex, '' if indentRegex value else @mergeInterpolationTokens tokens, {delimiter}, (value, i) => diff --git a/test/strings.coffee b/test/strings.coffee index 7797b291..6eb314d5 100644 --- a/test/strings.coffee +++ b/test/strings.coffee @@ -342,6 +342,9 @@ eq """ "\\\" """, ' "\\" ' eq ''' <- keep these spaces -> ''', ' <- keep these spaces -> ' +eq '''undefined''', 'undefined' +eq """undefined""", 'undefined' + test "#1046, empty string interpolations", -> eq "#{ }", ''