diff --git a/lib/coffeescript/nodes.js b/lib/coffeescript/nodes.js index e82f508f..07a1dbe3 100644 --- a/lib/coffeescript/nodes.js +++ b/lib/coffeescript/nodes.js @@ -1267,15 +1267,6 @@ if (!props && base instanceof Value) { return base; } - if (base instanceof Parens && base.contains(function(n) { - return n instanceof StatementLiteral; - })) { - // When `Parens` block includes a `StatementLiteral` (e.g. `(b; break) for a in arr`), - // it won't compile since `Parens` (`(b; break)`) is compiled as `Value` and - // pure statement (`break`) can't be used in an expression. - // For this reasons, we return `Block` instead of `Parens`. - return base.unwrap(); - } this.base = base; this.properties = props || []; if (tag) { diff --git a/src/nodes.coffee b/src/nodes.coffee index 8875d31c..05d0f9e6 100644 --- a/src/nodes.coffee +++ b/src/nodes.coffee @@ -863,11 +863,6 @@ exports.Value = class Value extends Base constructor: (base, props, tag, isDefaultValue = no) -> super() return base if not props and base instanceof Value - # When `Parens` block includes a `StatementLiteral` (e.g. `(b; break) for a in arr`), - # it won't compile since `Parens` (`(b; break)`) is compiled as `Value` and - # pure statement (`break`) can't be used in an expression. - # For this reasons, we return `Block` instead of `Parens`. - return base.unwrap() if base instanceof Parens and base.contains (n) -> n instanceof StatementLiteral @base = base @properties = props or [] @[tag] = yes if tag diff --git a/test/control_flow.coffee b/test/control_flow.coffee index c5d31cee..7d994aa2 100644 --- a/test/control_flow.coffee +++ b/test/control_flow.coffee @@ -1112,37 +1112,6 @@ test "#3921: `switch`", -> else "none" eq "five", c -# Issue #3441: Parentheses wrapping expression throw invalid error in `then` clause -test "#3441: `StatementLiteral` in parentheses", -> - i = 0 - r1 = ((i++; break) while i < 10) - arrayEq r1, [] - - i = 0 - r2 = ((i++; continue) while i < 10) - arrayEq r2, [] - - i = 0 - r4 = while i < 10 then (i++; break) - arrayEq r4, [] - - i = 0 - r5 = while i < 10 then (i++; continue) - arrayEq r5, [] - - arr = [0..9] - r6 = ((a; break) for a in arr) - arrayEq r6, [] - - r7 = ((a; continue) for a in arr) - arrayEq r7, [] - - r8 = for a in arr then (a; break) - arrayEq r8, [] - - r9 = for a in arr then (a; continue) - arrayEq r9, [] - # Issue #3909: backslash to break line in `for` loops throw syntax error test "#3909: backslash `for own ... of`", -> diff --git a/test/error_messages.coffee b/test/error_messages.coffee index 5e254769..45b537fe 100644 --- a/test/error_messages.coffee +++ b/test/error_messages.coffee @@ -962,6 +962,42 @@ test "#4097: `yield return` as an expression", -> ^^^^^^^^^^^^ ''' +test "#5013: `await return` as an expression", -> + assertErrorFormat ''' + -> (await return) + ''', ''' + [stdin]:1:5: error: cannot use a pure statement in an expression + -> (await return) + ^^^^^^^^^^^^ + ''' + +test "#5013: `return` as an expression", -> + assertErrorFormat ''' + -> (return) + ''', ''' + [stdin]:1:5: error: cannot use a pure statement in an expression + -> (return) + ^^^^^^ + ''' + +test "#5013: `break` as an expression", -> + assertErrorFormat ''' + (b = 1; break) for b in a + ''', ''' + [stdin]:1:9: error: cannot use a pure statement in an expression + (b = 1; break) for b in a + ^^^^^ + ''' + +test "#5013: `continue` as an expression", -> + assertErrorFormat ''' + (b = 1; continue) for b in a + ''', ''' + [stdin]:1:9: error: cannot use a pure statement in an expression + (b = 1; continue) for b in a + ^^^^^^^^ + ''' + test "`&&=` and `||=` with a space in-between", -> assertErrorFormat ''' a = 0