Permalink
Browse files

Merge branch 'master' into gh-pages

  • Loading branch information...
2 parents f0fba5f + 0b2d852 commit bfe2b280788c829bc4f0853bacfa32674d1eb2f7 @lydell lydell committed Sep 26, 2016
Showing with 17 additions and 7 deletions.
  1. +1 −1 documentation/index.html.js
  2. +4 −4 lib/coffee-script/lexer.js
  3. +2 −2 src/lexer.coffee
  4. +10 −0 test/strings.coffee
View
2 documentation/index.html.js
@@ -1326,7 +1326,7 @@ six = ->
<code>Infinity</code> into <code>2e308</code>.
</li>
<li>
- Bugfix for renamed destrucured parameters with defaults.
+ Bugfix for renamed destructured parameters with defaults.
<code>({a: b = 1}) -&gt;</code> no longer crashes the compiler.
</li>
<li>
View
8 lib/coffee-script/lexer.js
@@ -267,22 +267,22 @@
}
}
if (indent) {
- indentRegex = RegExp("^" + indent, "gm");
+ indentRegex = RegExp("\\n" + indent, "g");
}
this.mergeInterpolationTokens(tokens, {
delimiter: delimiter
}, (function(_this) {
return function(value, i) {
value = _this.formatString(value);
+ if (indentRegex) {
+ value = value.replace(indentRegex, '\n');
+ }
if (i === 0) {
value = value.replace(LEADING_BLANK_LINE, '');
}
if (i === $) {
value = value.replace(TRAILING_BLANK_LINE, '');
}
- if (indentRegex) {
- value = value.replace(indentRegex, '');
- }
return value;
};
})(this));
View
4 src/lexer.coffee
@@ -248,12 +248,12 @@ exports.Lexer = class Lexer
while match = HEREDOC_INDENT.exec doc
attempt = match[1]
indent = attempt if indent is null or 0 < attempt.length < indent.length
- indentRegex = /// ^#{indent} ///gm if indent
+ indentRegex = /// \n#{indent} ///g if indent
@mergeInterpolationTokens tokens, {delimiter}, (value, i) =>
value = @formatString value
+ value = value.replace indentRegex, '\n' if indentRegex
value = value.replace LEADING_BLANK_LINE, '' if i is 0
value = value.replace TRAILING_BLANK_LINE, '' if i is $
- value = value.replace indentRegex, '' if indentRegex
value
else
@mergeInterpolationTokens tokens, {delimiter}, (value, i) =>
View
10 test/strings.coffee
@@ -390,3 +390,13 @@ test "#3795: Escape otherwise invalid characters", ->
eq """#{a}""", 'a\u2029'
eq """#{a}\0\
1""", 'a\0' + '1'
+
+test "#4314: Whitespace less than or equal to stripped indentation", ->
+ # The odd indentation is intentional here, to test 1-space indentation.
+ eq ' ', """
+ #{} #{}
+"""
+
+ eq '1 2 3 4 5 end\na 0 b', """
+ #{1} #{2} #{3} #{4} #{5} end
+ a #{0} b"""

0 comments on commit bfe2b28

Please sign in to comment.