From a8c6a641d7130ae69489cc3092da047b2e2cf1c4 Mon Sep 17 00:00:00 2001 From: Jeremy Ashkenas Date: Mon, 16 Aug 2010 22:02:37 -0400 Subject: [PATCH] stop supressing left-hand whitespace in newline'd strings. Make 'em more literal. --- lib/lexer.js | 5 ++--- src/lexer.coffee | 3 +-- test/test_literals.coffee | 4 ++-- 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/lib/lexer.js b/lib/lexer.js index dbe42699..0fc14518 100644 --- a/lib/lexer.js +++ b/lib/lexer.js @@ -1,5 +1,5 @@ (function() { - var ASSIGNED, CALLABLE, CODE, COFFEE_ALIASES, COFFEE_KEYWORDS, COMMENT, COMPARE, COMPOUND_ASSIGN, CONVERSIONS, HEREDOC, HEREDOC_INDENT, IDENTIFIER, JS_CLEANER, JS_FORBIDDEN, JS_KEYWORDS, LAST_DENT, LAST_DENTS, LINE_BREAK, LOGIC, Lexer, MATH, MULTILINER, MULTI_DENT, NEXT_CHARACTER, NOT_REGEX, NO_NEWLINE, NUMBER, OPERATOR, REGEX_END, REGEX_ESCAPE, REGEX_INTERPOLATION, REGEX_START, RESERVED, Rewriter, SHIFT, STRING_NEWLINES, UNARY, WHITESPACE, _a, _b, _c, compact, count, helpers, include, starts; + var ASSIGNED, CALLABLE, CODE, COFFEE_ALIASES, COFFEE_KEYWORDS, COMMENT, COMPARE, COMPOUND_ASSIGN, CONVERSIONS, HEREDOC, HEREDOC_INDENT, IDENTIFIER, JS_CLEANER, JS_FORBIDDEN, JS_KEYWORDS, LAST_DENT, LAST_DENTS, LINE_BREAK, LOGIC, Lexer, MATH, MULTILINER, MULTI_DENT, NEXT_CHARACTER, NOT_REGEX, NO_NEWLINE, NUMBER, OPERATOR, REGEX_END, REGEX_ESCAPE, REGEX_INTERPOLATION, REGEX_START, RESERVED, Rewriter, SHIFT, UNARY, WHITESPACE, _a, _b, _c, compact, count, helpers, include, starts; var __slice = Array.prototype.slice; if (typeof process !== "undefined" && process !== null) { _a = require('./rewriter'); @@ -141,7 +141,7 @@ if (!(string = this.balancedToken(['"', '"'], ['#{', '}']) || this.balancedToken(["'", "'"]))) { return false; } - this.interpolateString(string.replace(STRING_NEWLINES, " \\\n")); + this.interpolateString(string.replace(/\n/g, '\\\n')); this.line += count(string, "\n"); this.i += string.length; return true; @@ -615,7 +615,6 @@ REGEX_ESCAPE = /\\[^\$]/g; JS_CLEANER = /(^`|`$)/g; MULTILINER = /\n/g; - STRING_NEWLINES = /\n[ \t]*/g; NO_NEWLINE = /^([+\*&|\/\-%=<>!.\\][<>=&|]*|and|or|is|isnt|not|delete|typeof|instanceof)$/; HEREDOC_INDENT = /(\n+([ \t]*)|^([ \t]+))/g; ASSIGNED = /^\s*(([a-zA-Z\$_@]\w*|["'][^\r\n]+?["']|\d+)[ \t]*?[:=][^=])/; diff --git a/src/lexer.coffee b/src/lexer.coffee index 95b0c6d5..807c0e8d 100644 --- a/src/lexer.coffee +++ b/src/lexer.coffee @@ -123,7 +123,7 @@ exports.Lexer = class Lexer return false unless string = @balancedToken(['"', '"'], ['#{', '}']) or @balancedToken ["'", "'"] - @interpolateString string.replace STRING_NEWLINES, " \\\n" + @interpolateString string.replace /\n/g, '\\\n' @line += count string, "\n" @i += string.length true @@ -536,7 +536,6 @@ REGEX_ESCAPE = /\\[^\$]/g # Token cleaning regexes. JS_CLEANER = /(^`|`$)/g MULTILINER = /\n/g -STRING_NEWLINES = /\n[ \t]*/g NO_NEWLINE = /^([+\*&|\/\-%=<>!.\\][<>=&|]*|and|or|is|isnt|not|delete|typeof|instanceof)$/ HEREDOC_INDENT = /(\n+([ \t]*)|^([ \t]+))/g ASSIGNED = /^\s*(([a-zA-Z\$_@]\w*|["'][^\r\n]+?["']|\d+)[ \t]*?[:=][^=])/ diff --git a/test/test_literals.coffee b/test/test_literals.coffee index 9bc82071..5ea13297 100644 --- a/test/test_literals.coffee +++ b/test/test_literals.coffee @@ -60,8 +60,8 @@ ok money$ is '\(\(\(dollars\)\)\)' multiline = "one - two - three" + two + three" ok multiline is 'one two three'