Permalink
Browse files

removing the ability to force an if/else chain to be compiled as a st…

…atement. Ternaries will now be used as much as possible.
  • Loading branch information...
jashkenas committed Sep 22, 2010
1 parent c50cf23 commit c4356475898af365bc44146c56d552925c3e0f76
Showing with 16 additions and 54 deletions.
  1. +1 −3 lib/browser.js
  2. +1 −3 lib/cake.js
  3. +4 −16 lib/command.js
  4. +1 −1 lib/grammar.js
  5. +4 −20 lib/nodes.js
  6. +2 −2 lib/parser.js
  7. +1 −3 lib/rewriter.js
  8. +1 −1 src/grammar.coffee
  9. +1 −5 src/nodes.coffee
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View
@@ -511,7 +511,7 @@ grammar =
IfBlock: [
o "IF Expression Block", -> new IfNode $2, $3
o "UNLESS Expression Block", -> new IfNode $2, $3, invert: true
- o "IfBlock ELSE IF Expression Block", -> $1.addElse (new IfNode($4, $5)).forceStatement()
+ o "IfBlock ELSE IF Expression Block", -> $1.addElse new IfNode $4, $5
o "IfBlock ELSE Block", -> $1.addElse $3
]
View
@@ -1488,10 +1488,6 @@ exports.IfNode = class IfNode extends BaseNode
bodyNode: -> @body?.unwrap()
elseBodyNode: -> @elseBody?.unwrap()
- forceStatement: ->
- @tags.statement = true
- this
-
# Rewrite a chain of **IfNodes** to add a default case as the final *else*.
addElse: (elseBody, statement) ->
if @isChain
@@ -1504,7 +1500,7 @@ exports.IfNode = class IfNode extends BaseNode
# The **IfNode** only compiles into a statement if either of its bodies needs
# to be a statement. Otherwise a ternary is safe.
isStatement: (o) ->
- @statement or= !!((o and o.top) or @tags.statement or @bodyNode().isStatement(o) or (@elseBody and @elseBodyNode().isStatement(o)))
+ @statement or= !!((o and o.top) or @bodyNode().isStatement(o) or (@elseBody and @elseBodyNode().isStatement(o)))
compileCondition: (o) ->
conditions = flatten [@condition]

0 comments on commit c435647

Please sign in to comment.