Skip to content

Commit eba271d

Browse files
committed
Merge branch 'master' of github.com:jashkenas/coffeescript into 2
# Conflicts: # lib/coffee-script/rewriter.js # lib/coffeescript/lexer.js
2 parents 2f9ab1d + 51c0657 commit eba271d

File tree

7 files changed

+30
-20
lines changed

7 files changed

+30
-20
lines changed

lib/coffeescript/rewriter.js

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

src/rewriter.coffee

+2-1
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,8 @@ exports.Rewriter = class Rewriter
396396
not (token[0] is 'TERMINATOR' and @tag(i + 1) in EXPRESSION_CLOSE) and
397397
not (token[0] is 'ELSE' and starter isnt 'THEN') and
398398
not (token[0] in ['CATCH', 'FINALLY'] and starter in ['->', '=>']) or
399-
token[0] in CALL_CLOSERS and @tokens[i - 1].newLine
399+
token[0] in CALL_CLOSERS and
400+
(@tokens[i - 1].newLine or @tokens[i - 1][0] is 'OUTDENT')
400401

401402
action = (token, i) ->
402403
@tokens.splice (if @tag(i - 1) is ',' then i - 1 else i), 0, outdent

test/formatting.coffee

+23
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,29 @@ test "#1495, method call chaining", ->
198198
).join ', '
199199
eq 'a, b, c', result
200200

201+
test "chaining should not wrap spilling ternary", ->
202+
throws -> CoffeeScript.compile """
203+
if 0 then 1 else g
204+
a: 42
205+
.h()
206+
"""
207+
208+
test "chaining should wrap calls containing spilling ternary", ->
209+
f = (x) -> h: x
210+
id = (x) -> x
211+
result = f if true then 42 else id
212+
a: 2
213+
.h
214+
eq 42, result
215+
216+
test "chaining should work within spilling ternary", ->
217+
f = (x) -> h: x
218+
id = (x) -> x
219+
result = f if false then 1 else id
220+
a: 3
221+
.a
222+
eq 3, result.h
223+
201224
# Nested blocks caused by paren unwrapping
202225
test "#1492: Nested blocks don't cause double semicolons", ->
203226
js = CoffeeScript.compile '(0;0)'

test/modules.coffee

-6
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,6 @@
3636
# CoffeeScript also supports optional commas within `{ … }`.
3737

3838

39-
# Helper function
40-
toJS = (str) ->
41-
CoffeeScript.compile str, bare: yes
42-
.replace /^\s+|\s+$/g, '' # Trim leading/trailing whitespace
43-
44-
4539
# Import statements
4640

4741
test "backticked import statement", ->

test/regexps.coffee

-6
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,6 @@
66
# * Regexen
77
# * Heregexen
88

9-
# Helper function
10-
toJS = (str) ->
11-
CoffeeScript.compile str, bare: yes
12-
.replace /^\s+|\s+$/g, '' # Trim leading/trailing whitespace
13-
14-
159
test "basic regular expression literals", ->
1610
ok 'a'.match(/a/)
1711
ok 'a'.match /a/

test/strings.coffee

-6
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,6 @@
77
# * Strings
88
# * Heredocs
99

10-
# Helper function
11-
toJS = (str) ->
12-
CoffeeScript.compile str, bare: yes
13-
.replace /^\s+|\s+$/g, '' # Trim leading/trailing whitespace
14-
15-
1610
test "backslash escapes", ->
1711
eq "\\/\\\\", /\/\\/.source
1812

test/support/helpers.coffee

+4
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,7 @@ arrayEgal = (a, b) ->
1515

1616
exports.eq = (a, b, msg) -> ok egal(a, b), msg or "Expected #{a} to equal #{b}"
1717
exports.arrayEq = (a, b, msg) -> ok arrayEgal(a,b), msg or "Expected #{a} to deep equal #{b}"
18+
19+
exports.toJS = (str) ->
20+
CoffeeScript.compile str, bare: yes
21+
.replace /^\s+|\s+$/g, '' # Trim leading/trailing whitespace

0 commit comments

Comments
 (0)