diff --git a/lib/lexer.js b/lib/lexer.js index 62a40410..945f11d7 100644 --- a/lib/lexer.js +++ b/lib/lexer.js @@ -436,9 +436,10 @@ stack.push(tok); break; case '(': + case 'CALL_START': if (stack.length) { stack.pop(); - } else { + } else if (tok[0] === '(') { tok[0] = 'PARAM_START'; return this; } @@ -623,7 +624,7 @@ HEREDOC_INDENT = /\n+([^\n\S]*)/g; HEREDOC_ILLEGAL = /\*\//; ASSIGNED = /^\s*@?([$A-Za-z_][$\w\x7f-\uffff]*|['"].*['"])[^\n\S]*?[:=][^:=>]/; - LINE_CONTINUER = /^\s*(?:,|\??\.(?!\.)|::)/; + LINE_CONTINUER = /^\s*(?:,|\??\.(?![.\d])|::)/; TRAILING_SPACES = /\s+$/; NO_NEWLINE = /^(?:[-+*&|\/%=<>!.\\][<>=&|]*|and|or|is(?:nt)?|n(?:ot|ew)|delete|typeof|instanceof)$/; COMPOUND_ASSIGN = ['-=', '+=', '/=', '*=', '%=', '||=', '&&=', '?=', '<<=', '>>=', '>>>=', '&=', '^=', '|=']; diff --git a/lib/nodes.js b/lib/nodes.js index 3ab5c6b1..b9775019 100644 --- a/lib/nodes.js +++ b/lib/nodes.js @@ -41,7 +41,7 @@ } }; Base.prototype.compileClosure = function(o) { - if (this.jumps()) { + if (this.jumps() || this instanceof Throw) { throw SyntaxError('cannot use a pure statement in an expression.'); } o.sharedScope = true; diff --git a/src/lexer.coffee b/src/lexer.coffee index 11990a8d..35196535 100644 --- a/src/lexer.coffee +++ b/src/lexer.coffee @@ -369,9 +369,9 @@ exports.Lexer = class Lexer switch tok[0] when ')' stack.push tok - when '(' + when '(', 'CALL_START' if stack.length then stack.pop() - else + else if tok[0] is '(' tok[0] = 'PARAM_START' return this this @@ -601,7 +601,7 @@ HEREDOC_ILLEGAL = /\*\// ASSIGNED = /^\s*@?([$A-Za-z_][$\w\x7f-\uffff]*|['"].*['"])[^\n\S]*?[:=][^:=>]/ -LINE_CONTINUER = /// ^ \s* (?: , | \??\.(?!\.) | :: ) /// +LINE_CONTINUER = /// ^ \s* (?: , | \??\.(?![.\d]) | :: ) /// TRAILING_SPACES = /\s+$/ diff --git a/src/nodes.coffee b/src/nodes.coffee index b5b3dc3f..00e5ca0f 100644 --- a/src/nodes.coffee +++ b/src/nodes.coffee @@ -48,7 +48,7 @@ exports.Base = class Base # Statements converted into expressions via closure-wrapping share a scope # object with their parent closure, to preserve the expected lexical scope. compileClosure: (o) -> - if @jumps() + if @jumps() or this instanceof Throw throw SyntaxError 'cannot use a pure statement in an expression.' o.sharedScope = yes Closure.wrap(this).compileNode o diff --git a/test/function_literals.coffee b/test/function_literals.coffee index 8e4aede4..64c8a150 100644 --- a/test/function_literals.coffee +++ b/test/function_literals.coffee @@ -148,6 +148,9 @@ test "default values with splatted arguments", -> eq 1, withSplats(1,1,1) eq 2, withSplats(1,1,1,1) +test "default values with function calls", -> + doesNotThrow -> CoffeeScript.compile "(x = f()) ->" + test "arguments vs parameters", -> doesNotThrow -> CoffeeScript.compile "f(x) ->" f = (g) -> g() diff --git a/test/number_literals.coffee b/test/number_literals.coffee index 9d2010f1..ff0abce4 100644 --- a/test/number_literals.coffee +++ b/test/number_literals.coffee @@ -37,3 +37,8 @@ eq Number::toString, .42['toString'] eq Number::toString, 4.2.toString eq Number::toString, .42.toString + +test '#1168: leading floating point suppresses newline', -> + eq 1, do -> + 1 + .5 + 0.5