Skip to content

Commit ccc70a9

Browse files
committed
refactor
1 parent a8ef9a0 commit ccc70a9

File tree

5 files changed

+29
-54
lines changed

5 files changed

+29
-54
lines changed

lib/coffeescript/grammar.js

Lines changed: 9 additions & 17 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/coffeescript/nodes.js

Lines changed: 0 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/coffeescript/parser.js

Lines changed: 11 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/grammar.coffee

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -334,10 +334,14 @@ grammar =
334334
o 'Assignable'
335335
o 'Literal', -> new Value $1
336336
o 'Parenthetical', ->
337-
if $1.hasParentheses()
338-
new Value $1
337+
# When `Parens` block includes a `StatementLiteral` (e.g. `(b; break) for a in arr`),
338+
# it won't compile since `Parens` (`(b; break)`) is compiled as `Value` and
339+
# pure statement (`break`) can't be used in an expression.
340+
# For this reasons, we return `Block` instead of `Parens`.
341+
if $1.hasStatementLiteral()
342+
$1.unwrap()
339343
else
340-
$1
344+
new Value $1
341345
o 'Range', -> new Value $1
342346
o 'Invocation', -> new Value $1
343347
o 'This'
@@ -601,20 +605,8 @@ grammar =
601605
# where only values are accepted, wrapping it in parentheses will always do
602606
# the trick.
603607
Parenthetical: [
604-
o '( Body )', ->
605-
# When `Parens` block includes a `StatementLiteral` (e.g. `(b; break) for a in arr`),
606-
# it won't compile since `Parens` (`(b; break)`) is compiled as `Value` and
607-
# pure statement (`break`) can't be used in an expression.
608-
# For this reasons, we return `Block`, which is passed further to `Value` and `Expression`.
609-
if $2.hasStatementLiteral()
610-
LOC(2)(Block.wrap [$2])
611-
else
612-
new Parens $2
613-
o '( INDENT Body OUTDENT )', ->
614-
if $3.hasStatementLiteral()
615-
LOC(3)(Block.wrap [$3])
616-
else
617-
new Parens $3
608+
o '( Body )', -> new Parens $2
609+
o '( INDENT Body OUTDENT )', -> new Parens $3
618610
]
619611

620612
# The condition portion of a while loop.

src/nodes.coffee

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -391,9 +391,6 @@ exports.Base = class Base
391391
hasStatementLiteral: ->
392392
@contains (n) -> n instanceof StatementLiteral
393393

394-
hasParentheses: ->
395-
@ instanceof Parens
396-
397394
#### HoistTarget
398395

399396
# A **HoistTargetNode** represents the output location in the node tree for a hoisted node.

0 commit comments

Comments
 (0)