mirror of
https://github.com/jashkenas/coffeescript.git
synced 2022-11-09 12:23:24 -05:00
Merge branch 'master' of github.com:jashkenas/coffeescript into 2
# Conflicts: # lib/coffee-script/rewriter.js # lib/coffeescript/lexer.js
This commit is contained in:
commit
eba271db5b
7 changed files with 30 additions and 20 deletions
|
@ -395,7 +395,7 @@
|
||||||
starter = indent = outdent = null;
|
starter = indent = outdent = null;
|
||||||
condition = function(token, i) {
|
condition = function(token, i) {
|
||||||
var ref, ref1, ref2, ref3;
|
var ref, ref1, ref2, ref3;
|
||||||
return token[1] !== ';' && (ref = token[0], indexOf.call(SINGLE_CLOSERS, ref) >= 0) && !(token[0] === 'TERMINATOR' && (ref1 = this.tag(i + 1), indexOf.call(EXPRESSION_CLOSE, ref1) >= 0)) && !(token[0] === 'ELSE' && starter !== 'THEN') && !(((ref2 = token[0]) === 'CATCH' || ref2 === 'FINALLY') && (starter === '->' || starter === '=>')) || (ref3 = token[0], indexOf.call(CALL_CLOSERS, ref3) >= 0) && this.tokens[i - 1].newLine;
|
return token[1] !== ';' && (ref = token[0], indexOf.call(SINGLE_CLOSERS, ref) >= 0) && !(token[0] === 'TERMINATOR' && (ref1 = this.tag(i + 1), indexOf.call(EXPRESSION_CLOSE, ref1) >= 0)) && !(token[0] === 'ELSE' && starter !== 'THEN') && !(((ref2 = token[0]) === 'CATCH' || ref2 === 'FINALLY') && (starter === '->' || starter === '=>')) || (ref3 = token[0], indexOf.call(CALL_CLOSERS, ref3) >= 0) && (this.tokens[i - 1].newLine || this.tokens[i - 1][0] === 'OUTDENT');
|
||||||
};
|
};
|
||||||
action = function(token, i) {
|
action = function(token, i) {
|
||||||
return this.tokens.splice((this.tag(i - 1) === ',' ? i - 1 : i), 0, outdent);
|
return this.tokens.splice((this.tag(i - 1) === ',' ? i - 1 : i), 0, outdent);
|
||||||
|
|
|
@ -396,7 +396,8 @@ exports.Rewriter = class Rewriter
|
||||||
not (token[0] is 'TERMINATOR' and @tag(i + 1) in EXPRESSION_CLOSE) and
|
not (token[0] is 'TERMINATOR' and @tag(i + 1) in EXPRESSION_CLOSE) and
|
||||||
not (token[0] is 'ELSE' and starter isnt 'THEN') and
|
not (token[0] is 'ELSE' and starter isnt 'THEN') and
|
||||||
not (token[0] in ['CATCH', 'FINALLY'] and starter in ['->', '=>']) or
|
not (token[0] in ['CATCH', 'FINALLY'] and starter in ['->', '=>']) or
|
||||||
token[0] in CALL_CLOSERS and @tokens[i - 1].newLine
|
token[0] in CALL_CLOSERS and
|
||||||
|
(@tokens[i - 1].newLine or @tokens[i - 1][0] is 'OUTDENT')
|
||||||
|
|
||||||
action = (token, i) ->
|
action = (token, i) ->
|
||||||
@tokens.splice (if @tag(i - 1) is ',' then i - 1 else i), 0, outdent
|
@tokens.splice (if @tag(i - 1) is ',' then i - 1 else i), 0, outdent
|
||||||
|
|
|
@ -198,6 +198,29 @@ test "#1495, method call chaining", ->
|
||||||
).join ', '
|
).join ', '
|
||||||
eq 'a, b, c', result
|
eq 'a, b, c', result
|
||||||
|
|
||||||
|
test "chaining should not wrap spilling ternary", ->
|
||||||
|
throws -> CoffeeScript.compile """
|
||||||
|
if 0 then 1 else g
|
||||||
|
a: 42
|
||||||
|
.h()
|
||||||
|
"""
|
||||||
|
|
||||||
|
test "chaining should wrap calls containing spilling ternary", ->
|
||||||
|
f = (x) -> h: x
|
||||||
|
id = (x) -> x
|
||||||
|
result = f if true then 42 else id
|
||||||
|
a: 2
|
||||||
|
.h
|
||||||
|
eq 42, result
|
||||||
|
|
||||||
|
test "chaining should work within spilling ternary", ->
|
||||||
|
f = (x) -> h: x
|
||||||
|
id = (x) -> x
|
||||||
|
result = f if false then 1 else id
|
||||||
|
a: 3
|
||||||
|
.a
|
||||||
|
eq 3, result.h
|
||||||
|
|
||||||
# Nested blocks caused by paren unwrapping
|
# Nested blocks caused by paren unwrapping
|
||||||
test "#1492: Nested blocks don't cause double semicolons", ->
|
test "#1492: Nested blocks don't cause double semicolons", ->
|
||||||
js = CoffeeScript.compile '(0;0)'
|
js = CoffeeScript.compile '(0;0)'
|
||||||
|
|
|
@ -36,12 +36,6 @@
|
||||||
# CoffeeScript also supports optional commas within `{ … }`.
|
# CoffeeScript also supports optional commas within `{ … }`.
|
||||||
|
|
||||||
|
|
||||||
# Helper function
|
|
||||||
toJS = (str) ->
|
|
||||||
CoffeeScript.compile str, bare: yes
|
|
||||||
.replace /^\s+|\s+$/g, '' # Trim leading/trailing whitespace
|
|
||||||
|
|
||||||
|
|
||||||
# Import statements
|
# Import statements
|
||||||
|
|
||||||
test "backticked import statement", ->
|
test "backticked import statement", ->
|
||||||
|
|
|
@ -6,12 +6,6 @@
|
||||||
# * Regexen
|
# * Regexen
|
||||||
# * Heregexen
|
# * Heregexen
|
||||||
|
|
||||||
# Helper function
|
|
||||||
toJS = (str) ->
|
|
||||||
CoffeeScript.compile str, bare: yes
|
|
||||||
.replace /^\s+|\s+$/g, '' # Trim leading/trailing whitespace
|
|
||||||
|
|
||||||
|
|
||||||
test "basic regular expression literals", ->
|
test "basic regular expression literals", ->
|
||||||
ok 'a'.match(/a/)
|
ok 'a'.match(/a/)
|
||||||
ok 'a'.match /a/
|
ok 'a'.match /a/
|
||||||
|
|
|
@ -7,12 +7,6 @@
|
||||||
# * Strings
|
# * Strings
|
||||||
# * Heredocs
|
# * Heredocs
|
||||||
|
|
||||||
# Helper function
|
|
||||||
toJS = (str) ->
|
|
||||||
CoffeeScript.compile str, bare: yes
|
|
||||||
.replace /^\s+|\s+$/g, '' # Trim leading/trailing whitespace
|
|
||||||
|
|
||||||
|
|
||||||
test "backslash escapes", ->
|
test "backslash escapes", ->
|
||||||
eq "\\/\\\\", /\/\\/.source
|
eq "\\/\\\\", /\/\\/.source
|
||||||
|
|
||||||
|
|
|
@ -15,3 +15,7 @@ arrayEgal = (a, b) ->
|
||||||
|
|
||||||
exports.eq = (a, b, msg) -> ok egal(a, b), msg or "Expected #{a} to equal #{b}"
|
exports.eq = (a, b, msg) -> ok egal(a, b), msg or "Expected #{a} to equal #{b}"
|
||||||
exports.arrayEq = (a, b, msg) -> ok arrayEgal(a,b), msg or "Expected #{a} to deep equal #{b}"
|
exports.arrayEq = (a, b, msg) -> ok arrayEgal(a,b), msg or "Expected #{a} to deep equal #{b}"
|
||||||
|
|
||||||
|
exports.toJS = (str) ->
|
||||||
|
CoffeeScript.compile str, bare: yes
|
||||||
|
.replace /^\s+|\s+$/g, '' # Trim leading/trailing whitespace
|
||||||
|
|
Loading…
Reference in a new issue