Skip to content

Commit 0698b62

Browse files
committed
refactor
1 parent a8ef9a0 commit 0698b62

File tree

5 files changed

+23
-82
lines changed

5 files changed

+23
-82
lines changed

lib/coffeescript/grammar.js

Lines changed: 3 additions & 19 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: 9 additions & 10 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: 3 additions & 28 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/grammar.coffee

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -333,11 +333,7 @@ grammar =
333333
Value: [
334334
o 'Assignable'
335335
o 'Literal', -> new Value $1
336-
o 'Parenthetical', ->
337-
if $1.hasParentheses()
338-
new Value $1
339-
else
340-
$1
336+
o 'Parenthetical', -> new Value $1
341337
o 'Range', -> new Value $1
342338
o 'Invocation', -> new Value $1
343339
o 'This'
@@ -601,20 +597,8 @@ grammar =
601597
# where only values are accepted, wrapping it in parentheses will always do
602598
# the trick.
603599
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
600+
o '( Body )', -> new Parens $2
601+
o '( INDENT Body OUTDENT )', -> new Parens $3
618602
]
619603

620604
# The condition portion of a while loop.

src/nodes.coffee

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -388,12 +388,6 @@ exports.Base = class Base
388388
answer = answer.concat fragments
389389
answer
390390

391-
hasStatementLiteral: ->
392-
@contains (n) -> n instanceof StatementLiteral
393-
394-
hasParentheses: ->
395-
@ instanceof Parens
396-
397391
#### HoistTarget
398392

399393
# A **HoistTargetNode** represents the output location in the node tree for a hoisted node.
@@ -869,6 +863,11 @@ exports.Value = class Value extends Base
869863
constructor: (base, props, tag, isDefaultValue = no) ->
870864
super()
871865
return base if not props and base instanceof Value
866+
# When `Parens` block includes a `StatementLiteral` (e.g. `(b; break) for a in arr`),
867+
# it won't compile since `Parens` (`(b; break)`) is compiled as `Value` and
868+
# pure statement (`break`) can't be used in an expression.
869+
# For this reasons, we return `Block` instead of `Parens`.
870+
return base.unwrap() if base instanceof Parens and base.contains (n) -> n instanceof StatementLiteral
872871
@base = base
873872
@properties = props or []
874873
@[tag] = yes if tag

0 commit comments

Comments
 (0)