Skip to content

Commit

Permalink
reverting to 26a28ab behaviour
Browse files Browse the repository at this point in the history
This is only slightly problematic for the most pathological of cases
where a prelude is followed by a set of statements, none of which
generate top-level variables or attempt to return. In these cases, the
non-prelude statements will be indented. See related discussion at
e4b3e83.
  • Loading branch information
michaelficarra committed Dec 16, 2011
1 parent 121009d commit 38b6a43
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 9 deletions.
18 changes: 13 additions & 5 deletions lib/coffee-script/nodes.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 12 additions & 4 deletions src/nodes.coffee
Expand Up @@ -243,12 +243,16 @@ exports.Block = class Block extends Base
# It would be better not to generate them in the first place, but for now,
# clean up obvious double-parentheses.
compileRoot: (o) ->
o.indent = if o.bare then '' else TAB
o.indent = ""
o.scope = new Scope null, this, null
o.level = LEVEL_TOP
@spaced = yes
prelude = ""
unless o.bare
hasReturn = no
@traverseChildren no, (e) ->
hasReturn = yes if e instanceof Return
!hasReturn
if hasReturn or not o.bare
preludeExps = for exp, i in @expressions
e = exp.unwrap()
break unless e instanceof Comment or e instanceof Literal
Expand All @@ -257,9 +261,13 @@ exports.Block = class Block extends Base
@expressions = preludeExps
prelude = "#{@compileNode o}\n" if preludeExps.length
@expressions = rest
# We assume that we will need the safety wrapper.
# This is the best we can do without compiling twice.
o.indent = TAB
code = @compileWithDeclarations o
return prelude + code if o.bare
"#{prelude}(function() {\n#{code}\n}).call(this);\n"
if hasReturn or (not o.bare and o.scope.variables.length > 1)
return "#{prelude}(function() {\n#{code}\n}).call(this);\n"
prelude + code

# Compile the expressions body for the contents of a function, with
# declarations of all inner variables pushed up to the top.
Expand Down

0 comments on commit 38b6a43

Please sign in to comment.